1 # This file fills in a config_h.SH template based on the data
2 # of the file config.def and outputs a config.h.
4 # Written January 24, 2000 by Jarkko Hietaniemi [jhi@iki.fi]
5 # Modified February 2, 2000 by Paul Green [Paul_Green@stratus.com]
8 # Read in the definitions file
11 if (open(CONFIG_DEF, "config.def")) {
12 while (<CONFIG_DEF>) {
13 if (/^([^=]+)='(.*)'$/) {
14 my ($var, $val) = ($1, $2);
17 warn "config.def: $.: illegal line: $_";
21 die "$0: Cannot open config.def: $!";
27 # Open the template input file.
30 unless (open(CONFIG_SH, "config_h.SH_orig")) {
31 die "$0: Cannot open config_h.SH_orig: $!";
35 # Open the output file.
38 unless (open(CONFIG_H, ">config.h.new")) {
39 die "$0: Cannot open config.h.new for output: $!";
43 # Skip lines before the first !GROK!THIS!
47 last if /^sed <<!GROK!THIS!/;
51 # Process the rest of the file, a line at a time.
52 # Stop when the next !GROK!THIS! is found.
56 last if /^!GROK!THIS!/;
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.
62 s@^#(\$\w+)@("$define{$1}" eq "undef")?"/*#define":"#$define{$1}"@e;
65 # There could be multiple $variables on this line.
66 # Find and replace all of them.
69 s/(\$\w+)/(exists $define{$1}) ? $define{$1} : $1/ge;
73 # There are no variables, just print the line out.
80 unless (close (CONFIG_H)) {
81 die "$0: Cannot close config.h.new: $!";