Makefile.am: Ship `debian/compat'.
[cfd] / confsubst.in
CommitLineData
ba4d97a4
MW
1#! /bin/sh
2### -*-sh-*-
3###
4### Make autoconf-like substitutions in files
5###
6### (c) 2008 Mark Wooding
7###
8
9###----- Licensing notice ---------------------------------------------------
10###
11### This file is part of the Common Files Distribution (`common').
12###
13### `Common' is free software; you can redistribute it and/or modify
14### it under the terms of the GNU General Public License as published by
15### the Free Software Foundation; either version 2 of the License, or
16### (at your option) any later version.
17###
18### `Common' is distributed in the hope that it will be useful,
19### but WITHOUT ANY WARRANTY; without even the implied warranty of
20### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21### GNU General Public License for more details.
22###
23### You should have received a copy of the GNU General Public License
24### along with `common'; if not, write to the Free Software Foundation,
25### Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
27set -e
ba4d97a4
MW
28VERSION="@VERSION@"
29
30###--------------------------------------------------------------------------
31### Parse command line arguments.
32
33while [ $# -gt 0 ]; do
34 case $1 in
35 -h | --h | --he | --hel | --help)
36 cat <<EOF
37Usage: confsubst FILE TAG=VALUE...
38
39Replaces occurrences of @TAG@ in FILE with VALUE, and writes the result to
40standard output.
41EOF
42 exit 0
43 ;;
44 -v | --v | --ve | --ver | --vers | --versi | --versio | --version)
45 echo "confsubst: Common Files Distribution version $VERSION"
46 exit 0
47 ;;
48 --)
49 shift
50 break
51 ;;
52 -)
53 break
54 ;;
55 -*)
56 echo "confsubst: unknown option \`$1'" >&2
57 exit 1
58 ;;
59 *)
60 break
61 ;;
62 esac
63 shift
64done
65
66if [ $# -lt 1 ]; then
67 echo >&2 "Usage: confsubst FILE TAG=VALUE..."
68 exit 1
69fi
70file=$1; shift
71
72###--------------------------------------------------------------------------
73### Main code.
74
75subst=""
76for fixup; do
77 case "$fixup" in
78 *?=*?) ;;
79 *) echo >&2 "$0: bad substitution: $fixup"; exit 1 ;;
80 esac
81 tag=$(echo "$fixup" | sed 's/=.*$//') && \
82 value=$(echo "$fixup" | sed 's/^[^=]*=//') && \
83 subst="$subst s\a@$tag@\a$value\ag;"
84done
85
86sed "$subst" $file || exit $?
87
88###----- That's all, folks --------------------------------------------------