aboutsummaryrefslogtreecommitdiffstats
path: root/configure
blob: a890cf0dc634e047604ab3001248249c27f75d6b (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/sh
# Try and be like autotools configure, but without autotools

# Ensure that we do not inherit these from env
OS=
BUILD=
HOST=
TARGET=
RESTARTCMD=
RCDIR=
STATUSARG=

for x do
	opt=${x%%=*}
	var=${x#*=}
	case "$opt" in
	--os|OS) OS=$var;;
	--with-cc|CC) CC=$var;;
	--debug) DEBUG=$var;;
	--disable-debug) DEBUG=no;;
	--enable-debug) DEBUG=yes;;
	--prefix) PREFIX=$var;;
	--sysconfdir) SYSCONFDIR=$var;;
	--bindir|--sbindir) SBINDIR=$var;;
	--libexecdir) LIBEXECDIR=$var;;
	--statedir|--localstatedir) STATEDIR=$var;;
	--dbdir) DBDIR=$var;;
	--rundir) RUNDIR=$var;;
	--mandir) MANDIR=$var;;
	--with-ccopts|CFLAGS) CFLAGS=$var;;
	CPPFLAGS) CPPFLAGS=$var;;
	--build) BUILD=$var;;
	--host) HOST=$var;;
	--target) TARGET=$var;;
	--libdir) LIBDIR=$var;;
	--restartcmd) RESTARTCMD=$var;;
	--rcdir) RCDIR=$var;;
	--statusarg) STATUSARG=$var;;
	--includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
	--datadir|--infodir) ;; # ignore autotools
	--disable-maintainer-mode|--disable-dependency-tracking) ;;
	--help) echo "See the README file for available options"; exit 0;;
	*) echo "$0: WARNING: unknown option $opt" >&2;;
	esac
done

if [ -z "$LIBEXECDIR" ]; then
	printf "Checking for directory /libexec ... "
	if [ -d /libexec ]; then
		echo "yes"
		LIBEXECDIR=$PREFIX/libexec/resolvconf
	else
		echo "no"
		LIBEXECDIR=$PREFIX/lib/resolvconf
	fi
fi
if [ -z "$RUNDIR" ]; then
	printf "Checking for directory /run ... "
	if [ -d /run ]; then
		echo "yes"
		RUNDIR=/run
	else
		echo "no"
		RUNDIR=/var/run
	fi
fi	

: ${SED:=sed}

: ${SYSCONFDIR:=$PREFIX/etc}
: ${SBINDIR:=$PREFIX/sbin}
: ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
: ${STATEDIR:=/var}
: ${RUNDIR:=$STATEDIR/run}
: ${MANDIR:=${PREFIX:-/usr}/share/man}

eval SYSCONFDIR="$SYSCONFDIR"
eval SBINDIR="$SBINDIR"
eval LIBEXECDIR="$LIBEXECDIR"
eval VARDIR="$RUNDIR/resolvconf"
eval MANDIR="$MANDIR"

CONFIG_MK=config.mk

if [ -z "$BUILD" ]; then
	# autoconf target triplet: cpu-vendor-os
	BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
fi
: ${HOST:=$BUILD}

if [ -z "$OS" ]; then
	echo "Deriving operating system from ... $HOST"
	# Derive OS from cpu-vendor-[kernel-]os
	CPU=${HOST%%-*}
	REST=${HOST#*-}
	if [ "$CPU" != "$REST" ]; then
		VENDOR=${REST%%-*}
		REST=${REST#*-}
		if [ "$VENDOR" != "$REST" ]; then
			# Use kernel if given, otherwise os
			OS=${REST%%-*}
		else
			# 2 tupple
			OS=$VENDOR
			VENDOR=
		fi
	fi

        # Work with cpu-kernel-os, ie Debian
	case "$VENDOR" in
	linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
	esac
	# Special case
	case "$OS" in
	gnu*) OS=hurd;; # No HURD support as yet
	esac
fi

echo "Configuring openresolv for ... $OS"
rm -rf $CONFIG_MK
echo "# $OS" >$CONFIG_MK

case "$OS" in
freebsd*)
	# On FreeBSD, /etc/init.d/foo status returns 0 if foo is not enabled
	# regardless of if it's not running.
	# So we force onestatus to work around this silly bug.
	if [ -z "$STATUSARG" ]; then
		STATUSARG="onestatus"
	fi
	;;
linux*)
	# cksum does't support -a and netpgp is rare
	echo "CKSUM=		sha256sum --tag" >>$CONFIG_MK
	echo "PGP=		gpg2" >>$CONFIG_MK
	;;
esac

for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
do
	eval v=\$$x
	# Make files look nice for import
	l=$((10 - ${#x}))
	unset t
	[ $l -gt 3 ] && t="	"
	echo "$x=$t	$v" >>$CONFIG_MK
done

echo
echo "   SYSCONFDIR =		$SYSCONFDIR"
echo "   SBINDIR =		$SBINDIR"
echo "   LIBEXECDIR =		$LIBEXECDIR"
echo "   VARDIR =		$RUNDIR"
echo "   MANDIR =		$MANDIR"
echo
echo "   RESTARTCMD =		$RESTARTCMD"
echo "   RCDIR =		$RCDIR"
echo "   STATUSARG =		$STATUSARG"
echo