-
Notifications
You must be signed in to change notification settings - Fork 1
/
package-subst.in
49 lines (40 loc) · 1.19 KB
/
package-subst.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/sh
#
# Usage in Makefile-files:
#
# foo/bar: foo/bar.in package-subst
# ./package-subst $(srcdir)/foo/bar.in foo/bar [FOO=bar...]
#
# or better (using the interface vars)
#
# foo/bar: foo/bar.in $(PACKAGE_SUBST_DEP)
# $(PACKAGE_SUBST) $(srcdir)/foo/bar.in foo/bar [FOO=bar...]
#
set -e
if test "x$1$2" = "x" || test "x$2" = "x"
then
echo "$(basename "$0"): Usage is \`$(basename "$0") INFILE OUTFILE'" >&2
exit 1
fi
INFILE="$1"
shift
OUTFILE="$1"
shift
# set -x
@MKDIR_P@ "$(dirname "$OUTFILE")"
# Note that the printf(1) is just a hack to print a "-e\n" string in
# any way. ANY way would be OK, but this appears to be the only one,
# as echo(1) insists on interpreting "-e" as a command line option.
IFS='
'
@SED@ \
$(for v in "$@"; do printf -- '-e\n' && echo "$v" | sed -e 's,\([A-Za-z][A-Za-z0-9_-]*\)=\(.*\),s|\[@\]\1@|\2|,'; done) \
-e 's|[@]PACKAGE_NAME@|@PACKAGE_NAME@|g' \
-e 's|[@]PACKAGE_TARNAME@|@PACKAGE_TARNAME@|g' \
-e 's|[@]PACKAGE_VERSION@|@PACKAGE_VERSION@|g' \
< "$INFILE" > "$OUTFILE"
head -n1 < "$OUTFILE" > "$OUTFILE.tmp"
trap "rm -f \"$OUTFILE.tmp\"" EXIT
if grep '^#!' "$OUTFILE.tmp" > /dev/null; then
chmod +x "$OUTFILE"
fi