X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=build%2Fgenconf;h=ac9755f4aaa7b28b2495b82baf111cc3d06a30dc;hb=d81211bb8cb5fa357e7a6046e284ba0ff5a6cc28;hp=75c957fe10a9c8490452ac0b16d215e419748be1;hpb=daf489b1c9a3f4dc306c82bf330771540179a1bf;p=libucw.git diff --git a/build/genconf b/build/genconf index 75c957fe..ac9755f4 100755 --- a/build/genconf +++ b/build/genconf @@ -1,6 +1,6 @@ #!/usr/bin/perl # Configuration file and script preprocessor -# (c) 2004 Martin Mares +# (c) 2004--2007 Martin Mares use strict; use warnings; @@ -9,14 +9,22 @@ use warnings; open CF, $ARGV[2] or die "Unable to open $ARGV[2]"; my %options = (); +my %vars = (); while () { - /^(CONFIG_\w+)=[^0]/ || next; - $options{$1} = 1; + chomp; + if (my ($k,$v) = /^(\w+)=(.*)/) { + $v =~ s/\s+$//; + $vars{$k} = $v; + $options{$k} = 1 if ($k =~ /^CONFIG_/); + } } close CF; -my $opt_regex = join("|", keys %options); -sub eval_expr { $_ = "@_"; s/\b($opt_regex)\b/ 1 /g if $opt_regex; s/\bCONFIG_\w+\b/ 0 /g; return eval $_; } +sub eval_expr { + $_ = shift @_; + s/\b(CONFIG_\w+)\b/defined($options{$1}) ? 1 : 0/ge; + return eval $_; +} open IN, $ARGV[0] or die "Unable to open $ARGV[0]"; open OUT, ">$ARGV[1]" or die "Unable to create $ARGV[1]"; @@ -46,8 +54,17 @@ while () { $empty = 1; } else { $empty = 0; } if (/^#pipe\s+(.+)/) { + my $cmd = $1; + my $val = `$cmd`; + die "Piped command '$cmd' failed" if $?; print OUT `$1`; } else { + sub repl ($) { + my $v = shift @_; + exists $vars{$v} or die "Cannot substitute $v: variable not set"; + return $vars{$v}; + } + s/@(\w+)@/repl($1)/ge; print OUT; } }