This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
AUTHORS update.
[perl5.git] / wince / config_h.PL
1 #
2 use Config;
3 use File::Compare qw(compare);
4 use File::Copy qw(copy);
5 my $name = $0;
6 $name =~ s#^(.*)\.PL$#../$1.SH#;
7 my %opt;
8 while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
9  {
10   $opt{$1}=$2;
11   shift(@ARGV);
12  }
13
14 $opt{CONFIG_H} ||= 'config.h';
15
16 my $patchlevel = $opt{INST_VER};
17 $patchlevel =~ s|^[\\/]||;
18 $patchlevel =~ s|~VERSION~|$Config{version}|g;
19 $patchlevel ||= $Config{version};
20 $patchlevel = qq["$patchlevel"];
21
22 open(SH,"<$name") || die "Cannot open $name:$!";
23 while (<SH>)
24  {
25   last if /^sed/;
26  }
27 ($term,$file,$pat) = /^sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
28
29 $file =~ s/^\$(\w+)$/$opt{$1}/g;
30
31 my $str = "sub munge\n{\n";
32
33 while ($pat =~ s/-e\s+'([^']*)'\s*//)
34  {
35   my $e = $1;
36   $e =~ s/\\([\(\)])/$1/g;
37   $e =~ s/\\(\d)/\$$1/g; 
38   $str .= "$e;\n";
39  }
40 $str .= "}\n";
41
42 eval $str;
43
44 die "$str:$@" if $@;
45
46 open(H,">$file.new") || die "Cannot open $file.new:$!";
47 #binmode H;             # no CRs (which cause a spurious rebuild)
48 while (<SH>)
49  {
50   last if /^$term$/o;
51   s/\$([\w_]+)/Config($1)/eg;
52   s/`([^\`]*)`/BackTick($1)/eg;
53   munge();
54   s/\\\$/\$/g;
55   s#/[ *\*]*\*/#/**/#;
56   if (/^\s*#define\s+(PRIVLIB|SITELIB|VENDORLIB)_EXP/)
57    {
58      $_ = "#define ". $1 . "_EXP (win32_get_". lc($1) . "($patchlevel))\t/**/\n";
59    }
60   # incpush() handles archlibs, so disable them
61   elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
62    {
63      $_ = "/*#define ". $1 . "_EXP \"\"\t/**/\n";
64    }
65   print H;
66  }
67 close(H);
68 close(SH);
69
70
71 chmod(0666,"config.h");
72 copy("$file.new","config.h") || die "Cannot copy:$!";
73 chmod(0444,"config.h");
74
75 if (compare("$file.new",$file))
76  {
77   warn "$file has changed\n";
78   chmod(0666,$file);
79   unlink($file);
80   rename("$file.new",$file);
81   #chmod(0444,$file);
82   exit(1);
83  }
84 else
85  {
86   unlink ("$file.new");
87   exit(0);
88  }
89
90 sub Config
91 {
92  my $var = shift;
93  my $val = $Config{$var};
94  $val = 'undef' unless defined $val;
95  $val =~ s/\\/\\\\/g;
96  return $val;
97 }
98
99 sub BackTick
100 {
101  my $cmd = shift;
102  if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
103   {
104    local ($data,$pat) = ($1,$2);
105    $data =~ s/\s+/ /g;
106    eval "\$data =~ $pat";
107    return $data;
108   }
109  else
110   {
111    die "Cannot handle \`$cmd\`";
112   }
113  return $cmd;
114 }