[asperl] add AS patch#15
[p5sagit/p5-mst-13.2.git] / win32 / config_h.PL
1 #
2 use Config;
3 use File::Compare qw(compare);
4 use File::Copy qw(copy);
5 my $OBJ   = 1 if $Config{'ccflags'} =~ /PERL_OBJECT/i;
6 my $name = $0;
7 $name =~ s#^(.*)\.PL$#../$1.SH#;
8 open(SH,"<$name") || die "Cannot open $name:$!";
9 while (<SH>)
10  {
11   last if /^sed/;
12  }
13 ($term,$file,$pat) = /^sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
14
15 my $str = "sub munge\n{\n";
16
17 while ($pat =~ s/-e\s+'([^']*)'\s*//)
18  {
19   my $e = $1;
20   $e =~ s/\\([\(\)])/$1/g;
21   $e =~ s/\\(\d)/\$$1/g; 
22   $str .= "$e;\n";
23  }
24 $str .= "}\n";
25
26 eval $str;
27
28 die "$str:$@" if $@;
29
30 open(H,">$file.new") || die "Cannot open $file.new:$!";
31 binmode H;              # no CRs (which cause a spurious rebuild)
32 while (<SH>)
33  {
34   last if /^$term$/o;
35   s/\$([\w_]+)/Config($1)/eg;
36   s/`([^\`]*)`/BackTick($1)/eg;
37   munge();
38   s/\\\$/\$/g;
39   s#/[ *\*]*\*/#/**/#;
40   # if (/^\s*#define\s+ARCHLIB_EXP/)
41   #  {
42   #    $_ = "#define ARCHLIB_EXP (win32_perllib_path(ARCHNAME,NULL))\t/**/\n";
43   #  }
44   if (/^\s*#define\s+PRIVLIB_EXP/)
45    {
46      $_ = "#define PRIVLIB_EXP (win32_get_stdlib(patchlevel))\t/**/\n"
47    }
48   # if (/^\s*#define\s+SITEARCH_EXP/)
49   #  {
50   #    $_ = "#define SITEARCH_EXP (win32_perllib_path(\"site\",ARCHNAME,NULL))\t/**/\n";
51   #  }
52   if (/^\s*#define\s+SITELIB_EXP/)
53    {
54      $_ = "#define SITELIB_EXP (win32_get_sitelib(patchlevel))\t/**/\n";
55    }
56   print H;
57  }
58 print H "#include <win32.h>
59 ";
60 close(H);
61 close(SH);
62
63
64 chmod(0666,"../lib/CORE/config.h");
65 copy("$file.new","../lib/CORE/config.h") || die "Cannot copy:$!";
66 chmod(0444,"../lib/CORE/config.h");
67
68 if (!$OBJ && compare("$file.new",$file))
69  {
70   warn "$file has changed\n";
71   chmod(0666,$file);
72   unlink($file);
73   rename("$file.new",$file);
74   #chmod(0444,$file);
75   exit(1);
76  }
77 else
78  {
79   unlink ("$file.new");
80   exit(0);
81  }
82
83 sub Config
84 {
85  my $var = shift;
86  my $val = $Config{$var};
87  $val = 'undef' unless defined $val;
88  $val =~ s/\\/\\\\/g;
89  return $val;
90 }
91
92 sub BackTick
93 {
94  my $cmd = shift;
95  if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
96   {
97    local ($data,$pat) = ($1,$2);
98    $data =~ s/\s+/ /g;
99    eval "\$data =~ $pat";
100    return $data;
101   }
102  else
103   {
104    die "Cannot handle \`$cmd\`";
105   }
106  return $cmd;
107 }