This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Changes USE_THREADS to USE_5005THREADS in the entire source.
[perl5.git] / NetWare / 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 my %opt;
9 while (@ARGV && $ARGV[0] =~ /^([\w_]+)=(.*)$/)
10  {
11   $opt{$1}=$2;
12   shift(@ARGV);
13  }
14  
15  $opt{CONFIG_H} ||= 'config.h';
16  
17 my $patchlevel = $opt{INST_VER};
18 $patchlevel =~ s|^[\\/]||;
19 $patchlevel =~ s|~VERSION~|$Config{version}|g;
20 $patchlevel ||= $Config{version};
21 $patchlevel = qq["$patchlevel"];
22
23 open(SH,"<$name") || die "Cannot open $name:$!";
24 while (<SH>)
25  {
26   last if /^sed/;
27  }
28 ($term,$file,$pat) = /^sed\s+<<(\S+)\s+>(\S+)\s+(.*)$/;
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+(SITELIB|VENDORLIB)_EXP/)
57    {
58      $_ = "#define ". $1 . "_EXP (nw_get_". lc($1) . "($patchlevel))\t/**/\n";
59    }
60   # Added for NetWare and removed PRIVLIB from the above, the same thing might have
61   # to be done for other as well
62   elsif (/^\s*#define\s+(PRIVLIB)_EXP/)
63    {
64      $_ = "#define ". $1 . "_EXP (fnNwGetEnvironmentStr(\"PRIVLIB\", PRIVLIB))\t/**/\n";
65    }
66   # incpush() handles archlibs, so disable them
67   elsif (/^\s*#define\s+(ARCHLIB|SITEARCH|VENDORARCH)_EXP/)
68    {
69      $_ = "/*#define ". $1 . "_EXP \"\"\t/**/\n";
70    }
71   print H;
72  }
73 close(H);
74 close(SH);
75
76
77 chmod(0666,"../lib/CORE/config.h");
78 copy("$file.new","../lib/CORE/config.h") || die "Cannot copy:$!";
79 chmod(0444,"../lib/CORE/config.h");
80
81 if (!$OBJ && compare("$file.new",$file))
82  {
83   warn "$file has changed\n";
84   chmod(0666,$file);
85   unlink($file);
86   rename("$file.new",$file);
87   #chmod(0444,$file);
88   exit(1);
89  }
90 else
91  {
92   unlink ("$file.new");
93   exit(0);
94  }
95
96 sub Config
97 {
98  my $var = shift;
99  my $val = $Config{$var};
100  $val = 'undef' unless defined $val;
101  $val =~ s/\\/\\\\/g;
102  return $val;
103 }
104
105 sub BackTick
106 {
107  my $cmd = shift;
108  if ($cmd =~ /^echo\s+(.*?)\s*\|\s+sed\s+'(.*)'\s*$/)
109   {
110    local ($data,$pat) = ($1,$2);
111    $data =~ s/\s+/ /g;
112    eval "\$data =~ $pat";
113    return $data;
114   }
115  else
116   {
117    die "Cannot handle \`$cmd\`";
118   }
119  return $cmd;
120 }