xref: /freebsd/contrib/openresolv/configure (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
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
47: ${SED:=sed}
48
49CONFIG_MK=config.mk
50
51if [ -z "$BUILD" ]; then
52	# autoconf target triplet: cpu-vendor-os
53	BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
54fi
55: ${HOST:=$BUILD}
56
57if [ -z "$OS" ]; then
58	echo "Deriving operating system from ... $HOST"
59	# Derive OS from cpu-vendor-[kernel-]os
60	CPU=${HOST%%-*}
61	REST=${HOST#*-}
62	if [ "$CPU" != "$REST" ]; then
63		VENDOR=${REST%%-*}
64		REST=${REST#*-}
65		if [ "$VENDOR" != "$REST" ]; then
66			# Use kernel if given, otherwise os
67			OS=${REST%%-*}
68		else
69			# 2 tupple
70			OS=$VENDOR
71			VENDOR=
72		fi
73	fi
74
75        # Work with cpu-kernel-os, ie Debian
76	case "$VENDOR" in
77	linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
78	esac
79	# Special case
80	case "$OS" in
81	gnu*) OS=hurd;; # No HURD support as yet
82	esac
83fi
84
85echo "Configuring openresolv for ... $OS"
86rm -rf $CONFIG_MK
87echo "# $OS" >$CONFIG_MK
88
89case "$OS" in
90dragonfly*)
91	# This means /usr HAS to be mounted not via dhcpcd
92	: ${LIBEXECDIR:=${PREFIX:-/usr}/libexec/resolvconf}
93	;;
94linux*)
95	# cksum does't support -a and netpgp is rare
96	echo "CKSUM=		sha256sum --tag" >>$CONFIG_MK
97	echo "PGP=		gpg2" >>$CONFIG_MK
98	;;
99esac
100
101case "$OS" in
102dragonfly*|freebsd*)
103	# On FreeBSD, /etc/init.d/foo status returns 0 if foo is not enabled
104	# regardless of if it's not running.
105	# So we force onestatus to work around this silly bug.
106	if [ -z "$STATUSARG" ]; then
107		STATUSARG="onestatus"
108	fi
109	;;
110esac
111
112
113if [ -z "$LIBEXECDIR" ]; then
114	printf "Checking for directory /libexec ... "
115	if [ -d /libexec ]; then
116		echo "yes"
117		LIBEXECDIR=$PREFIX/libexec/resolvconf
118	else
119		echo "no"
120		LIBEXECDIR=$PREFIX/lib/resolvconf
121	fi
122fi
123if [ -z "$RUNDIR" ]; then
124	printf "Checking for directory /run ... "
125	if [ -d /run ]; then
126		echo "yes"
127		RUNDIR=/run
128	else
129		echo "no"
130		RUNDIR=/var/run
131	fi
132fi
133
134: ${SYSCONFDIR:=$PREFIX/etc}
135: ${SBINDIR:=$PREFIX/sbin}
136: ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
137: ${STATEDIR:=/var}
138: ${RUNDIR:=$STATEDIR/run}
139: ${MANDIR:=${PREFIX:-/usr}/share/man}
140
141eval SYSCONFDIR="$SYSCONFDIR"
142eval SBINDIR="$SBINDIR"
143eval LIBEXECDIR="$LIBEXECDIR"
144eval VARDIR="$RUNDIR/resolvconf"
145eval MANDIR="$MANDIR"
146
147for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
148do
149	eval v=\$$x
150	# Make files look nice for import
151	l=$((10 - ${#x}))
152	unset t
153	[ $l -gt 3 ] && t="	"
154	echo "$x=$t	$v" >>$CONFIG_MK
155done
156
157echo
158echo "   SYSCONFDIR =		$SYSCONFDIR"
159echo "   SBINDIR =		$SBINDIR"
160echo "   LIBEXECDIR =		$LIBEXECDIR"
161echo "   VARDIR =		$RUNDIR"
162echo "   MANDIR =		$MANDIR"
163echo
164echo "   RESTARTCMD =		$RESTARTCMD"
165echo "   RCDIR =		$RCDIR"
166echo "   STATUSARG =		$STATUSARG"
167echo
168