xref: /freebsd/contrib/openresolv/configure (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
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=
11STATUSARG=
12
13for x do
14	opt=${x%%=*}
15	var=${x#*=}
16	case "$opt" in
17	--os|OS) OS=$var;;
18	--with-cc|CC) CC=$var;;
19	--debug) DEBUG=$var;;
20	--disable-debug) DEBUG=no;;
21	--enable-debug) DEBUG=yes;;
22	--prefix) PREFIX=$var;;
23	--sysconfdir) SYSCONFDIR=$var;;
24	--bindir|--sbindir) SBINDIR=$var;;
25	--libexecdir) LIBEXECDIR=$var;;
26	--statedir|--localstatedir) STATEDIR=$var;;
27	--dbdir) DBDIR=$var;;
28	--rundir) RUNDIR=$var;;
29	--mandir) MANDIR=$var;;
30	--with-ccopts|CFLAGS) CFLAGS=$var;;
31	CPPFLAGS) CPPFLAGS=$var;;
32	--build) BUILD=$var;;
33	--host) HOST=$var;;
34	--target) TARGET=$var;;
35	--libdir) LIBDIR=$var;;
36	--restartcmd) RESTARTCMD=$var;;
37	--rcdir) RCDIR=$var;;
38	--statusarg) STATUSARG=$var;;
39	--includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
40	--datadir|--infodir) ;; # ignore autotools
41	--disable-maintainer-mode|--disable-dependency-tracking) ;;
42	--help) echo "See the README file for available options"; exit 0;;
43	*) echo "$0: WARNING: unknown option $opt" >&2;;
44	esac
45done
46
47if [ -z "$LIBEXECDIR" ]; then
48	printf "Checking for directory /libexec ... "
49	if [ -d /libexec ]; then
50		echo "yes"
51		LIBEXECDIR=$PREFIX/libexec/resolvconf
52	else
53		echo "no"
54		LIBEXECDIR=$PREFIX/lib/resolvconf
55	fi
56fi
57if [ -z "$RUNDIR" ]; then
58	printf "Checking for directory /run ... "
59	if [ -d /run ]; then
60		echo "yes"
61		RUNDIR=/run
62	else
63		echo "no"
64		RUNDIR=/var/run
65	fi
66fi
67
68: ${SED:=sed}
69
70: ${SYSCONFDIR:=$PREFIX/etc}
71: ${SBINDIR:=$PREFIX/sbin}
72: ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
73: ${STATEDIR:=/var}
74: ${RUNDIR:=$STATEDIR/run}
75: ${MANDIR:=${PREFIX:-/usr}/share/man}
76
77eval SYSCONFDIR="$SYSCONFDIR"
78eval SBINDIR="$SBINDIR"
79eval LIBEXECDIR="$LIBEXECDIR"
80eval VARDIR="$RUNDIR/resolvconf"
81eval MANDIR="$MANDIR"
82
83CONFIG_MK=config.mk
84
85if [ -z "$BUILD" ]; then
86	# autoconf target triplet: cpu-vendor-os
87	BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
88fi
89: ${HOST:=$BUILD}
90
91if [ -z "$OS" ]; then
92	echo "Deriving operating system from ... $HOST"
93	# Derive OS from cpu-vendor-[kernel-]os
94	CPU=${HOST%%-*}
95	REST=${HOST#*-}
96	if [ "$CPU" != "$REST" ]; then
97		VENDOR=${REST%%-*}
98		REST=${REST#*-}
99		if [ "$VENDOR" != "$REST" ]; then
100			# Use kernel if given, otherwise os
101			OS=${REST%%-*}
102		else
103			# 2 tupple
104			OS=$VENDOR
105			VENDOR=
106		fi
107	fi
108
109        # Work with cpu-kernel-os, ie Debian
110	case "$VENDOR" in
111	linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
112	esac
113	# Special case
114	case "$OS" in
115	gnu*) OS=hurd;; # No HURD support as yet
116	esac
117fi
118
119echo "Configuring openresolv for ... $OS"
120rm -rf $CONFIG_MK
121echo "# $OS" >$CONFIG_MK
122
123# On FreeBSD, /etc/init.d/foo status returns 0 if foo is not enabled
124# regardless of if it's not running.
125# So we force onestatus to work around this silly bug.
126if [ -z "$STATUSARG" ]; then
127	case "$OS" in
128	freebsd*)	STATUSARG="onestatus";;
129	esac
130fi
131
132for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
133do
134	eval v=\$$x
135	# Make files look nice for import
136	l=$((10 - ${#x}))
137	unset t
138	[ $l -gt 3 ] && t="	"
139	echo "$x=$t	$v" >>$CONFIG_MK
140done
141
142echo
143echo "   SYSCONFDIR =		$SYSCONFDIR"
144echo "   SBINDIR =		$SBINDIR"
145echo "   LIBEXECDIR =		$LIBEXECDIR"
146echo "   VARDIR =		$RUNDIR"
147echo "   MANDIR =		$MANDIR"
148echo
149echo "   RESTARTCMD =		$RESTARTCMD"
150echo "   RCDIR =		$RCDIR"
151echo "   STATUSARG =		$STATUSARG"
152echo
153