Daniel Pocock <dan...@pocock.com.au> writes:

> Thanks for that - the sed example appears to be the type of thing I want.

> However, is there a more concise way to do this?  I was thinking there may
> be some way to invoke sed or m4 on a template in much the way that gcc is
> invoked for *.c

Half of that equation would be a more generic script.  Attached is what we
use for INN (which has a bunch of INN-specific bits, but also has the
basic framework for things).

The other half would be to set up a way of automatically running that
script on particular files, and that's something I've never done.  I just
write explicit rules.

-- 
Russ Allbery (r...@stanford.edu)             <http://www.eyrie.org/~eagle/>

#! /bin/sh

##  $Id: fixconfig.in 8471 2009-05-17 08:25:35Z iulius $
##
##  Make variable substitutions in configuration files.
##
##  This script does something very similar to what config.status does, but
##  it fully resolves the various path variables (prefix, exec_prefix, etc.)
##  so that they don't contain any variable substitutions.  It's easier to
##  do this in a separate script than try to use eval or the like to resolve
##  the variable names inside configure, particularly since prefix and
##  exec_prefix aren't set until the end of the script.

# The paths set by configure.
pref...@prefix@
exec_pref...@exec_prefix@
bind...@bindir@
libexecd...@libexecdir@
libd...@libdir@
sbind...@sbindir@
sysconfd...@sysconfdir@

# Additional paths specific to INN.
controld...@controldir@
dbd...@dbdir@
filterd...@filterdir@
httpd...@httpdir@
libperld...@libperldir@
logd...@logdir@
rund...@rundir@
spoold...@spooldir@
tmpd...@tmpdir@

# Additional variables that are substituted into configuration files.
do_pgpveri...@do_pgpverify@
hostna...@hostname@
sendma...@sendmail@

# We can probably just assume sed is on the path, but since we have it, we may
# as well use it.
s...@sed@

input="$1"
if [ -z "$input" ] ; then
    echo "No input file specified" >&2
    exit 1
fi

output="$2"
if [ -z "$output" ] ; then
    output=`echo "$input" | $SED -e 's/\.in$//'`
fi
if [ x"$input" = x"$output" ] ; then
    echo "No output file specified and input file doesn't end in .in" >&2
    exit 1
fi

$SED -e "s,@pref...@],$prefix,g" \
     -e "s,@bind...@],$bindir,g" \
     -e "s,@libexecd...@],$libexecdir,g" \
     -e "s,@libd...@],$libdir,g" \
     -e "s,@sbind...@],$sbindir,g" \
     -e "s,@sysconfd...@],$sysconfdir,g" \
     -e "s,@controld...@],$CONTROLDIR,g" \
     -e "s,@dbd...@],$DBDIR,g" \
     -e "s,@filterd...@],$FILTERDIR,g" \
     -e "s,@httpd...@],$HTTPDIR,g" \
     -e "s,@libperld...@],$LIBPERLDIR,g" \
     -e "s,@logd...@],$LOGDIR,g" \
     -e "s,@rund...@],$RUNDIR,g" \
     -e "s,@spoold...@],$SPOOLDIR,g" \
     -e "s,@tmpd...@],$tmpdir,g" \
     -e "s,@do_pgpveri...@],$DO_PGPVERIFY,g" \
     -e "s,@hostna...@],$HOSTNAME,g" \
     -e "s,@sendma...@],$SENDMAIL,g" < "$input" > "$output"

Reply via email to