summaryrefslogtreecommitdiff
path: root/configure
blob: 5e99fa68893f4d9ecc86c3d5193f4cc9ab98b7aa (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
name='configure' # Luke's configuration script
#version='1.0'
#  Copyright (C) 2009, 2016 Luke Shumaker
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License as
#  published by the Free Software Foundation; either version 2 of the
#  License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#  General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program;  see the file COPYING.
#  If not, see <http://www.gnu.org/licenses>.

srcdir="$(dirname -- "$0")"
outdir="."

error() {
	echo "$name: $1" >&2
	exit 1
}

if [ "${srcdir:0:1}" = / ]; then
	topsrcdir=$srcdir
else
	topsrcdir="&/$srcdir"
fi
topsrcdir="${topsrcdir%/.}"

edit=(sed -E -e "s|^topsrcdir := .*|$topsrcdir|")
setvar() {
	edit+=(-e "s@^(\s*$1\s*:?=).*@\1 $2@")
}

vars=($(<"$srcdir/config.mk.in" sed -n 's/^\([ 	a-z_-]*\)=.*/\1/p'))

printf -v lopt '%s:,' "${vars[@]}"
lopt+='enable-autodeps,disable-autodeps'

sopt=''

args=$(getopt -n "$name" -o "${sopt}" -l "${lopt}" -- "$@") || exit $?
eval set -- "$args"
while [ $# -gt 0 ]; do
	case "$1" in
		--) break;;
		--enable-autodeps) setvar AUTODEPS t;;
		--disable-autodeps) setvar AUTODEPS '';;
		--*) setvar "${1#--}" "$2" shift;;
		*) error "unrecognized option \`$1'";
	esac
	shift
done

"${edit[@]}" < "$srcdir/config.mk.in" > "$outdir/config.mk"

Makefiles=($(find "$srcdir/" -name 'Makefile') "$srcdir"/modules/module.mk "$srcdir"/modules/*/Makefile.inc.mk)
for src in "${Makefiles[@]}"; do
	out="$outdir/${src#$srcdir/}"
	mkdir -p -- $(dirname -- "$out")
	if ! test "$src" -ef "$out"; then
		cp -fT -- "$src" "$out"
	fi
done