]> mj.ucw.cz Git - libucw.git/blobdiff - build/genconf
Split autoconf.cfg
[libucw.git] / build / genconf
index 29565a9c48a9d3bc2e34c442cbd3b8b9c457b690..30e8896c3a58901e5085880ed6628d0e5600665d 100755 (executable)
@@ -10,18 +10,28 @@ use warnings;
 open CF, $ARGV[2] or die "Unable to open $ARGV[2]";
 my %options = ();
 my %vars = ();
 open CF, $ARGV[2] or die "Unable to open $ARGV[2]";
 my %options = ();
 my %vars = ();
+sub opt {
+       my ($k,$v) = @_;
+       $vars{$k} = $v;
+       $options{$k} = 1 if ($k =~ /^CONFIG_/);
+}
+foreach my $k (keys %ENV) {
+       opt($k, $ENV{$k});
+}
 while (<CF>) {
        chomp;
        if (my ($k,$v) = /^(\w+)=(.*)/) {
                $v =~ s/\s+$//;
 while (<CF>) {
        chomp;
        if (my ($k,$v) = /^(\w+)=(.*)/) {
                $v =~ s/\s+$//;
-               $vars{$k} = $v;
-               $options{$k} = 1 if ($k =~ /^CONFIG_/);
+               opt($k, $v);
        }
 }
 close CF;
 
        }
 }
 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]";
 
 open IN, $ARGV[0] or die "Unable to open $ARGV[0]";
 open OUT, ">$ARGV[1]" or die "Unable to create $ARGV[1]";
@@ -56,10 +66,13 @@ while (<IN>) {
                        die "Piped command '$cmd' failed" if $?;
                        print OUT `$1`;
                } else {
                        die "Piped command '$cmd' failed" if $?;
                        print OUT `$1`;
                } else {
-                       sub repl ($) {
+                       sub repl($);
+                       sub repl($) {
                                my $v = shift @_;
                                exists $vars{$v} or die "Cannot substitute $v: variable not set";
                                my $v = shift @_;
                                exists $vars{$v} or die "Cannot substitute $v: variable not set";
-                               return $vars{$v};
+                               my $x = $vars{$v};
+                               while ($x =~ s/\$\((\w+)\)/repl($1)/ge) { }
+                               return $x;
                        }
                        s/@(\w+)@/repl($1)/ge;
                        print OUT;
                        }
                        s/@(\w+)@/repl($1)/ge;
                        print OUT;