aboutsummaryrefslogtreecommitdiffstats
path: root/configure
blob: 39bdddb65412d2b2e988e812e0fb8c925103f096 (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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/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=

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;;
	--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

: ${SED:=sed}

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

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

CONFIG_MK=config.mk

if [ -z "$BUILD" ]; then
	BUILD=`uname -m`-`uname -s | tr '[:upper:]' '[:lower:]'`
fi
if [ -z "$HOST" ]; then
	[ -z "$TARGET" ] && TARGET=$BUILD
	HOST=$TARGET
fi
if [ -z "$TARGET" ]; then
	[ -z "$HOST" ] && HOST=$BUILD
	TARGET=$HOST
fi

# Debian and Slackware have linux in different places when dealing with
# autoconf, so we deal with that here.
if [ -z "$OS" ]; then
	case "$TARGET" in
	*-linux-*|linux-*|*-linux|linux) OS=linux;;
	esac
fi

if [ -z "$OS" ]; then
	# Derive OS from cpu-manufacturer-os-kernel
	CPU=${TARGET%%-*}
	REST=${TARGET#*-}
	if [ "$CPU" != "$REST" ]; then
		MANU=${REST%%-*}
		REST=${REST#*-}
		if [ "$MANU" != "$REST" ]; then
			OS=${REST%%-*}
			REST=${REST#*-}
			if [ "$OS" != "$REST" ]; then
				KERNEL=${REST%%-*}
			else
				# 3 tupple
				KERNEL=$OS
				OS=$MANU
				MANU=
			fi
		else
			# 2 tupple
			OS=$MANU
			MANU=
		fi
	fi
fi

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

for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR; 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

if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
	echo "Overriding service status check for Arch Linux"
	RCDIR=/etc/rc.d
	RESTARTCMD="[ -e /var/run/daemons/\1 ] \&\& /etc/rc.d/\1 restart"
	echo "yes"
fi

if [ -z "$RESTARTCMD" ]; then
	printf "Checking for OpenRC ... "
	if [ -x /sbin/rc-service ]; then
		RESTARTCMD="/sbin/rc-service -e \1 \&\& /sbin/rc-service \1 -- -Ds restart"
		echo "yes"
	else
		echo "no"
	fi
fi
if [ -z "$RESTARTCMD" ]; then
	printf "Checking for invoke-rc.d ... "
	if [ -x /usr/sbin/invoke-rc.d ]; then
		RCDIR=/etc/init.d
		RESTARTCMD="/usr/sbin/invoke-rc.d --quiet \1 status >/dev/null 2>\&1 \&\& /usr/sbin/invoke-rc.d \1 restart"
		echo "yes"
	else
		echo "no"
	fi
fi
if [ -z "$RESTARTCMD" ]; then
	printf "Checking for service ... "
	if [ -x /sbin/service ]; then
		RCDIR=/etc/init.d
		RESTARTCMD="/sbin/service \1 \&\& /sbin/service \1 restart"
		echo "yes"
	else
		echo "no"
	fi
fi
if [ -z "$RESTARTCMD" ]; then
	for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
		printf "Checking for $x ... "
		if [ -d $x ]; then
			RCDIR=$x
			RESTARTCMD="$x/\1 status >/dev/null 2>\&1 \&\& $x/\1 restart"
			echo "yes"
			break
		else
			echo "no"
		fi
	done
fi

if [ -z "$RESTARTCMD" ]; then
	echo "WARNING! No means of interacting with system services detected!"
	exit 1
fi

echo "RCDIR=		$RCDIR" >>$CONFIG_MK
# Work around bug in the dash shell as "echo 'foo \1'" does bad things
printf "%s\n" "RESTARTCMD=	$RESTARTCMD" >>$CONFIG_MK

echo
echo "   SYSCONFDIR =		$SYSCONFDIR"
echo "   SBINDIR =		$SBINDIR"
echo "   LIBEXECDIR =		$LIBEXECDIR"
echo "   VARDIR =		$RUNDIR"
echo "   MANDIR =		$MANDIR"
echo