xref: /freebsd/contrib/openresolv/configure (revision 86c9d9918f1db7cdd968b60f8902466887bcd9e9)
1#!/bin/sh
2# Try and be like autotools configure, but without autotools
3
4# Ensure that we do not inherit these from env
5OS=
6BUILD=
7HOST=
8TARGET=
9RESTARTCMD=
10RCDIR=
11
12for x do
13	opt=${x%%=*}
14	var=${x#*=}
15	case "$opt" in
16	--os|OS) OS=$var;;
17	--with-cc|CC) CC=$var;;
18	--debug) DEBUG=$var;;
19	--disable-debug) DEBUG=no;;
20	--enable-debug) DEBUG=yes;;
21	--prefix) PREFIX=$var;;
22	--sysconfdir) SYSCONFDIR=$var;;
23	--bindir|--sbindir) SBINDIR=$var;;
24	--libexecdir) LIBEXECDIR=$var;;
25	--statedir|--localstatedir) STATEDIR=$var;;
26	--dbdir) DBDIR=$var;;
27	--rundir) RUNDIR=$var;;
28	--mandir) MANDIR=$var;;
29	--with-ccopts|CFLAGS) CFLAGS=$var;;
30	CPPFLAGS) CPPFLAGS=$var;;
31	--build) BUILD=$var;;
32	--host) HOST=$var;;
33	--target) TARGET=$var;;
34	--libdir) LIBDIR=$var;;
35	--restartcmd) RESTARTCMD=$var;;
36	--includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
37	--datadir|--infodir) ;; # ignore autotools
38	--disable-maintainer-mode|--disable-dependency-tracking) ;;
39	--help) echo "See the README file for available options"; exit 0;;
40	*) echo "$0: WARNING: unknown option $opt" >&2;;
41	esac
42done
43
44if [ -z "$LIBEXECDIR" ]; then
45	printf "Checking for directory /libexec ... "
46	if [ -d /libexec ]; then
47		echo "yes"
48		LIBEXECDIR=$PREFIX/libexec/resolvconf
49	else
50		echo "no"
51		LIBEXECDIR=$PREFIX/lib/resolvconf
52	fi
53fi
54if [ -z "$RUNDIR" ]; then
55	printf "Checking for directory /run ... "
56	if [ -d /run ]; then
57		echo "yes"
58		RUNDIR=/run
59	else
60		echo "no"
61		RUNDIR=/var/run
62	fi
63fi
64
65: ${SED:=sed}
66
67: ${SYSCONFDIR:=$PREFIX/etc}
68: ${SBINDIR:=$PREFIX/sbin}
69: ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
70: ${STATEDIR:=/var}
71: ${RUNDIR:=$STATEDIR/run}
72: ${MANDIR:=${PREFIX:-/usr}/share/man}
73
74eval SYSCONFDIR="$SYSCONFDIR"
75eval SBINDIR="$SBINDIR"
76eval LIBEXECDIR="$LIBEXECDIR"
77eval VARDIR="$RUNDIR/resolvconf"
78eval MANDIR="$MANDIR"
79
80CONFIG_MK=config.mk
81
82if [ -z "$BUILD" ]; then
83	# autoconf target triplet: cpu-vendor-os
84	BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
85fi
86: ${HOST:=$BUILD}
87
88if [ -z "$OS" ]; then
89	echo "Deriving operating system from ... $HOST"
90	# Derive OS from cpu-vendor-[kernel-]os
91	CPU=${HOST%%-*}
92	REST=${HOST#*-}
93	if [ "$CPU" != "$REST" ]; then
94		VENDOR=${REST%%-*}
95		REST=${REST#*-}
96		if [ "$VENDOR" != "$REST" ]; then
97			# Use kernel if given, otherwise os
98			OS=${REST%%-*}
99		else
100			# 2 tupple
101			OS=$VENDOR
102			VENDOR=
103		fi
104	fi
105
106        # Work with cpu-kernel-os, ie Debian
107	case "$VENDOR" in
108	linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
109	esac
110	# Special case
111	case "$OS" in
112	gnu*) OS=hurd;; # No HURD support as yet
113	esac
114fi
115
116echo "Configuring openresolv for ... $OS"
117rm -rf $CONFIG_MK
118echo "# $OS" >$CONFIG_MK
119
120for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR; do
121	eval v=\$$x
122	# Make files look nice for import
123	l=$((10 - ${#x}))
124	unset t
125	[ $l -gt 3 ] && t="	"
126	echo "$x=$t	$v" >>$CONFIG_MK
127done
128
129if [ -z "$RESTARTCMD" ]; then
130	printf "Checking for systemd ... "
131	if [ -x /bin/systemctl ]; then
132		RESTARTCMD="/bin/systemctl try-restart \1"
133		echo "yes"
134	elif [ -x /usr/bin/systemctl ]; then
135		RESTARTCMD="/usr/bin/systemctl try-restart \1"
136		echo "yes"
137	else
138		echo "no"
139	fi
140fi
141
142# Arch upgraded to systemd, so this check has to be just after systemd
143# but higher than the others
144if [ -z "$RESTARTCMD" ]; then
145	printf "Checking for Arch ... "
146	if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
147		RCDIR=/etc/rc.d
148		RESTARTCMD="[ -e /var/run/daemons/\1 ] \&\& /etc/rc.d/\1 restart"
149		echo "yes"
150	else
151		echo "no"
152	fi
153fi
154
155if [ -z "$RESTARTCMD" ]; then
156	printf "Checking for OpenRC ... "
157	if [ -x /sbin/rc-service ]; then
158		RESTARTCMD="if /sbin/rc-service -e \1; then /sbin/rc-service \1 -- -Ds restart; fi"
159		echo "yes"
160	else
161		echo "no"
162	fi
163fi
164if [ -z "$RESTARTCMD" ]; then
165	printf "Checking for invoke-rc.d ... "
166	if [ -x /usr/sbin/invoke-rc.d ]; then
167		RCDIR=/etc/init.d
168		RESTARTCMD="if /usr/sbin/invoke-rc.d --quiet \1 status >/dev/null 2>\&1; then /usr/sbin/invoke-rc.d \1 restart; fi"
169		echo "yes"
170	else
171		echo "no"
172	fi
173fi
174if [ -z "$RESTARTCMD" ]; then
175	printf "Checking for service ... "
176	if [ -x /sbin/service ]; then
177		RCDIR=/etc/init.d
178		RESTARTCMD="if /sbin/service \1; then /sbin/service \1 restart; fi"
179		echo "yes"
180	else
181		echo "no"
182	fi
183fi
184if [ -z "$RESTARTCMD" ]; then
185	printf "Checking for runit... "
186	if [ -x /bin/sv ]; then
187		RESTARTCMD="/bin/sv try-restart \1"
188		echo "yes"
189	elif [ -x /usr/bin/sv ]; then
190		RESTARTCMD="/usr/bin/sv try-restart \1"
191		echo "yes"
192	else
193		echo "no"
194	fi
195fi
196if [ -z "$RESTARTCMD" ]; then
197	for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
198		printf "Checking for $x ... "
199		if [ -d $x ]; then
200			RCDIR=$x
201			RESTARTCMD="if $x/\1 status >/dev/null 2>\&1; then $x/\1 restart; fi"
202			echo "yes"
203			break
204		else
205			echo "no"
206		fi
207	done
208fi
209
210if [ -z "$RESTARTCMD" ]; then
211	echo "$0: WARNING: No means of interacting with system services detected!"
212	exit 1
213fi
214
215echo "RCDIR=		$RCDIR" >>$CONFIG_MK
216# Work around bug in the dash shell as "echo 'foo \1'" does bad things
217printf "%s\n" "RESTARTCMD=	$RESTARTCMD" >>$CONFIG_MK
218
219echo
220echo "   SYSCONFDIR =		$SYSCONFDIR"
221echo "   SBINDIR =		$SBINDIR"
222echo "   LIBEXECDIR =		$LIBEXECDIR"
223echo "   VARDIR =		$RUNDIR"
224echo "   MANDIR =		$MANDIR"
225echo
226