From 2600ba2ab4a4c12ee35f66439670a771f9c7b622 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 28 Feb 2003 14:21:24 +0000 Subject: [PATCH] Changed processing of configuration files. 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 | 44 ++++++++++++++++++++++++++++++++++++++++++++ build/installer | 10 +++++----- 2 files changed, 49 insertions(+), 5 deletions(-) create mode 100755 build/genconf diff --git a/build/genconf b/build/genconf new file mode 100755 index 00000000..2c314786 --- /dev/null +++ b/build/genconf @@ -0,0 +1,44 @@ +#!/usr/bin/perl +# Configuration file preprocessor +# (c) 2003 Martin Mares + +use strict; +use warnings; + +@ARGV == 3 or die "Usage: genconf "; + +open CF, $ARGV[2] or die "Unable to open $ARGV[2]"; +my %options = (); +while () { + /^(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 () { + 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; diff --git a/build/installer b/build/installer index 12e54772..5fdbc9ef 100755 --- a/build/installer +++ b/build/installer @@ -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 -- 2.39.5