summary refs log tree commit diff
path: root/configure
blob: 938db10e294f4c7aeccbbb4b6c48976b247b23ba (plain) (blame)
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
50
51
52
#!/bin/sh

# SPDX-License-Identifier: GPL-2.0-or-later
# SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>

set -ue

prefix=/usr/local
bindir=

unrecognized=

for arg; do
	if [ "$arg" = "--help" ]; then
		cat <<EOF
Usage: $0 [OPTION]..."

Options:
  -h, --help
  --prefix=PREFIX         Default: /usr/local
  --bindir=BINDIR         Default: PREFIX/bin
EOF
		exit
	fi
done

for arg; do
	if printf "%s" "$arg" | grep -q "^--prefix="; then
		prefix="$(printf "%s" "$arg" | cut -d= -f2-)"
	elif printf "%s" "$arg" | grep -q "^--bindir="; then
		bindir="$(printf "%s" "$arg" | cut -d= -f2-)"
	elif printf "%s" "$arg" | grep -q "^--"; then
		unrecognized="$unrecognized $arg"
	else
		echo "Error: unexpected argument: $arg" >&2
		exit 64 # EX_USAGE
	fi
done

bindir="${bindir:-$prefix/bin}"

echo "// Generated by $0${*:+ $*}" > config.h.tmp
echo "#define PREFIX \"$prefix\"" >> config.h.tmp
echo "#define BINDIR \"$bindir\"" >> config.h.tmp
mv config.h.tmp config.h

sed -e "s#@PREFIX@#$prefix#g" -e "s#@BINDIR@#$bindir#g" Makefile.in > Makefile.tmp
mv Makefile.tmp Makefile

if [ -n "$unrecognized" ]; then
	echo "Warning: unrecognized options:$unrecognized" >&2
fi