This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
final touches for lexical warnings (from Paul Marquess)
[perl5.git] / vos / config.pl
CommitLineData
c287c78d 1# This file fills in a config_h.SH template based on the data
24e8e380
GS
2# of the file config.def and outputs a config.h.
3#
4# Written January 24, 2000 by Jarkko Hietaniemi [jhi@iki.fi]
5# Modified February 2, 2000 by Paul Green [Paul_Green@stratus.com]
6
7#
8# Read in the definitions file
9#
c287c78d
JH
10
11if (open(CONFIG_DEF, "config.def")) {
12 while (<CONFIG_DEF>) {
24e8e380
GS
13 if (/^([^=]+)='(.*)'$/) {
14 my ($var, $val) = ($1, $2);
15 $define{$var} = $val;
16 } else {
17 warn "config.def: $.: illegal line: $_";
18 }
c287c78d
JH
19 }
20} else {
21 die "$0: Cannot open config.def: $!";
22}
23
24e8e380
GS
24close (CONFIG_DEF);
25
26#
27# Open the template input file.
28#
29
30unless (open(CONFIG_SH, "config_h.SH_orig")) {
31 die "$0: Cannot open config_h.SH_orig: $!";
32}
33
34#
35# Open the output file.
36#
37
38unless (open(CONFIG_H, ">config.h.new")) {
39 die "$0: Cannot open config.h.new for output: $!";
40}
41
42#
43# Skip lines before the first !GROK!THIS!
44#
45
46while (<CONFIG_SH>) {
47 last if /^sed <<!GROK!THIS!/;
48}
49
50#
51# Process the rest of the file, a line at a time.
52# Stop when the next !GROK!THIS! is found.
53#
54
55while (<CONFIG_SH>) {
56 last if /^!GROK!THIS!/;
57#
58# The case of #$d_foo at the BOL has to be handled carefully.
59# If $d_foo is "undef", then we must first comment out the entire line.
60#
61 if (/^#\$\w+/) {
62 s@^#(\$\w+)@("$define{$1}" eq "undef")?"/*#define":"#$define{$1}"@e;
c287c78d 63 }
24e8e380
GS
64#
65# There could be multiple $variables on this line.
66# Find and replace all of them.
67#
68 if (/(\$\w+)/) {
69 s/(\$\w+)/(exists $define{$1}) ? $define{$1} : $1/ge;
70 print CONFIG_H;
71 }
72#
73# There are no variables, just print the line out.
74#
75 else {
76 print CONFIG_H;
c287c78d 77 }
c287c78d 78}
24e8e380
GS
79
80unless (close (CONFIG_H)) {
81 die "$0: Cannot close config.h.new: $!";
82 }
83
84close (CONFIG_SH);