2 # Configuration file preprocessor
3 # (c) 2003 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+)=1/ || 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
21 my $empty = 0; # last line was empty
23 if (/^#?ifdef\s+(\w+)/) {
24 push @ifs, !defined $options{$1};
25 } elsif (/^#ifndef\s+(\w+)/) {
26 push @ifs, defined $options{$1};
27 } elsif (/^#?endif/) {
28 defined pop @ifs || die "Improper nesting of conditionals";
31 defined $x || die "Improper nesting of conditionals";
34 @ifs && $ifs[$#ifs] && next;
38 } else { $empty = 0; }
42 @ifs && die "Unterminated #ifdef";