]> mj.ucw.cz Git - libucw.git/commitdiff
Changed processing of configuration files.
authorMartin Mares <mj@ucw.cz>
Fri, 28 Feb 2003 14:21:24 +0000 (14:21 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 28 Feb 2003 14:21:24 +0000 (14:21 +0000)
run/cf is no longer a symlink to ../cf, I've replaced it by make
rules which generate the configuration files in run/cf by preprocessing
those in cf according to CONFIG_xxx switches in config.mk (in the same
way as we already do in mkdist).

I'd like to migrate many settings local to the Centrum configs to the
main CVS without having to update several separate copies of the config.

*** CAVEAT ***  After updating to this version, you need to either
make distclean or

rm run/cf
mkdir run/cf

manually _before_ running make, else could lose your config files.

build/genconf [new file with mode: 0755]
build/installer

diff --git a/build/genconf b/build/genconf
new file mode 100755 (executable)
index 0000000..2c31478
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+# Configuration file preprocessor
+# (c) 2003 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+@ARGV == 3 or die "Usage: genconf <src> <dest> <config.mk>";
+
+open CF, $ARGV[2] or die "Unable to open $ARGV[2]";
+my %options = ();
+while (<CF>) {
+       /^(CONFIG_\w+)=1/ || next;
+       $options{$1} = 1;
+}
+close CF;
+
+open IN, $ARGV[0] or die "Unable to open $ARGV[0]";
+open OUT, ">$ARGV[1]" or die "Unable to create $ARGV[1]";
+my @ifs = ();  # stack of conditions, 1=satisfied
+my $empty = 0; # last line was empty
+while (<IN>) {
+       if (/^#?ifdef\s+(\w+)/) {
+               push @ifs, !defined $options{$1};
+       } elsif (/^#ifndef\s+(\w+)/) {
+               push @ifs, defined $options{$1};
+       } elsif (/^#?endif/) {
+               defined pop @ifs || die "Improper nesting of conditionals";
+       } elsif (/^#?else/) {
+               my $x = pop @ifs;
+               defined $x || die "Improper nesting of conditionals";
+               push @ifs, !$x;
+       } else {
+               @ifs && $ifs[$#ifs] && next;
+               if (/^$/) {
+                       $empty && next;
+                       $empty = 1;
+               } else { $empty = 0; }
+               print OUT;
+       }
+}
+@ifs && die "Unterminated #ifdef";
+close IN;
+close OUT;
index 12e54772a233e7c5e93b2d54df164a5d9f7256ce..5fdbc9ef3abb5d50c2212996908e2a973226e9d7 100755 (executable)
@@ -13,11 +13,11 @@ cp -aL run/bin/* $DEST/bin/
 cp -aL run/lib/* $DEST/lib/
 echo "Installing config files..."
 for a in cf/* ; do
-       if [ -f $a ] ; then
+       if [ -f run/$a ] ; then
                if [ ! -f $DEST/$a ] ; then
                        echo "$a: new, installed"
-                       cp $a $DEST/$a
-               elif diff -u $DEST/$a $a ; then
+                       cp run/$a $DEST/$a
+               elif diff -u $DEST/$a run/$a ; then
                        echo "$a: no differences"
                else
                        echo -n "$a differs, replace it [Yn]? "
@@ -25,10 +25,10 @@ for a in cf/* ; do
                        if [ -z "$x" -o "$x" == "y" -o "$x" == "Y" ] ; then
                                echo "$a: replacing and keeping the old version as $a.old"
                                mv $DEST/$a $DEST/$a.old
-                               cp $a $DEST/$a
+                               cp run/$a $DEST/$a
                        else
                                echo "$a: installing the new version as $a.dist"
-                               cp $a $DEST/$a.dist
+                               cp run/$a $DEST/$a.dist
                        fi
                fi
        fi