2 # Configuration file and script preprocessor
3 # (c) 2004 Martin Mares <mj@ucw.cz>
8 @ARGV == 3 or die "Usage: genconf <src> <dest> <config.mk>";
10 open CF, $ARGV[2] or die "Unable to open $ARGV[2]";
13 /^(CONFIG_\w+)=[^0]/ || next;
18 open IN, $ARGV[0] or die "Unable to open $ARGV[0]";
19 open OUT, ">$ARGV[1]" or die "Unable to create $ARGV[1]";
20 my @ifs = (); # stack of conditions, 1=satisfied, -1=unsatisfied, 0=shadowed
21 my $empty = 0; # last line was empty
23 if (/^#ifdef\s+(\w+)/) {
24 push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (defined $options{$1}) ? 1 : -1;
25 } elsif (/^#ifndef\s+(\w+)/) {
26 push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (defined $options{$1}) ? -1 : 1;
28 defined pop @ifs || die "Improper nesting of conditionals";
31 defined $x || die "Improper nesting of conditionals";
34 @ifs && $ifs[$#ifs] <= 0 && next;
38 } else { $empty = 0; }
42 @ifs && die "Unterminated #ifdef";