xref: /freebsd/contrib/openresolv/configure (revision ea825d02749f382c3f7e17f28247f20a48733eab)
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
123case "$OS" in
124freebsd*)
125	# On FreeBSD, /etc/init.d/foo status returns 0 if foo is not enabled
126	# regardless of if it's not running.
127	# So we force onestatus to work around this silly bug.
128	if [ -z "$STATUSARG" ]; then
129		STATUSARG="onestatus"
130	fi
131	;;
132linux*)
133	# cksum does't support -a and netpgp is rare
134	echo "CKSUM=		sha256sum --tag" >>$CONFIG_MK
135	echo "PGP=		gpg2" >>$CONFIG_MK
136	;;
137esac
138
139for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
140do
141	eval v=\$$x
142	# Make files look nice for import
143	l=$((10 - ${#x}))
144	unset t
145	[ $l -gt 3 ] && t="	"
146	echo "$x=$t	$v" >>$CONFIG_MK
147done
148
149echo
150echo "   SYSCONFDIR =		$SYSCONFDIR"
151echo "   SBINDIR =		$SBINDIR"
152echo "   LIBEXECDIR =		$LIBEXECDIR"
153echo "   VARDIR =		$RUNDIR"
154echo "   MANDIR =		$MANDIR"
155echo
156echo "   RESTARTCMD =		$RESTARTCMD"
157echo "   RCDIR =		$RCDIR"
158echo "   STATUSARG =		$STATUSARG"
159echo
160