--- /dev/null
+#!/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;
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]? "
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