Release openresolv-3.5.1
[openresolv] / configure
1 #!/bin/sh
2 # Try and be like autotools configure, but without autotools
3
4 # Ensure that we do not inherit these from env
5 OS=
6 BUILD=
7 HOST=
8 TARGET=
9 RESTARTCMD=
10 RCDIR=
11
12 for 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
42 done
43
44 : ${SED:=sed}
45
46 : ${PREFIX:=$prefix}
47 : ${SYSCONFDIR:=$PREFIX/etc}
48 : ${SBINDIR:=$PREFIX/sbin}
49 : ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
50 : ${STATEDIR:=/var}
51 : ${RUNDIR:=$STATEDIR/run}
52 : ${MANDIR:=${PREFIX:-/usr}/share/man}
53
54 eval SYSCONFDIR="$SYSCONFDIR"
55 eval SBINDIR="$SBINDIR"
56 eval LIBEXECDIR="$LIBEXECDIR"
57 eval VARDIR="$RUNDIR/resolvconf"
58 eval MANDIR="$MANDIR"
59
60 CONFIG_MK=config.mk
61
62 if [ -z "$BUILD" ]; then
63         BUILD=`uname -m`-`uname -s | tr '[:upper:]' '[:lower:]'`
64 fi
65 if [ -z "$HOST" ]; then
66         [ -z "$TARGET" ] && TARGET=$BUILD
67         HOST=$TARGET
68 fi
69 if [ -z "$TARGET" ]; then
70         [ -z "$HOST" ] && HOST=$BUILD
71         TARGET=$HOST
72 fi
73
74 # Debian and Slackware have linux in different places when dealing with
75 # autoconf, so we deal with that here.
76 if [ -z "$OS" ]; then
77         case "$TARGET" in
78         *-linux-*|linux-*|*-linux|linux) OS=linux;;
79         esac
80 fi
81
82 if [ -z "$OS" ]; then
83         # Derive OS from cpu-manufacturer-os-kernel
84         CPU=${TARGET%%-*}
85         REST=${TARGET#*-}
86         if [ "$CPU" != "$REST" ]; then
87                 MANU=${REST%%-*}
88                 REST=${REST#*-}
89                 if [ "$MANU" != "$REST" ]; then
90                         OS=${REST%%-*}
91                         REST=${REST#*-}
92                         if [ "$OS" != "$REST" ]; then
93                                 KERNEL=${REST%%-*}
94                         else
95                                 # 3 tupple
96                                 KERNEL=$OS
97                                 OS=$MANU
98                                 MANU=
99                         fi
100                 else
101                         # 2 tupple
102                         OS=$MANU
103                         MANU=
104                 fi
105         fi
106 fi
107
108 echo "Configuring openresolv for ... $OS"
109 rm -rf $CONFIG_MK
110 echo "# $OS" >$CONFIG_MK
111
112 for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR; do
113         eval v=\$$x
114         # Make files look nice for import
115         l=$((10 - ${#x}))
116         unset t
117         [ $l -gt 3 ] && t="     "
118         echo "$x=$t     $v" >>$CONFIG_MK
119 done
120
121 if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
122         echo "Overriding service status check for Arch Linux"
123         RCDIR=/etc/rc.d
124         RESTARTCMD="[ -e /var/run/daemons/\1 ] \&\& /etc/rc.d/\1 restart"
125         echo "yes"
126 fi
127
128 if [ -z "$RESTARTCMD" ]; then
129         printf "Checking for OpenRC ... "
130         if [ -x /sbin/rc-service ]; then
131                 RESTARTCMD="/sbin/rc-service -e \1 \&\& /sbin/rc-service \1 -- -Ds restart"
132                 echo "yes"
133         else
134                 echo "no"
135         fi
136 fi
137 if [ -z "$RESTARTCMD" ]; then
138         printf "Checking for invoke-rc.d ... "
139         if [ -x /usr/sbin/invoke-rc.d ]; then
140                 RCDIR=/etc/init.d
141                 RESTARTCMD="/usr/sbin/invoke-rc.d --quiet \1 status >/dev/null 2>\&1 \&\& /usr/sbin/invoke-rc.d \1 restart"
142                 echo "yes"
143         else
144                 echo "no"
145         fi
146 fi
147 if [ -z "$RESTARTCMD" ]; then
148         printf "Checking for service ... "
149         if [ -x /sbin/service ]; then
150                 RCDIR=/etc/init.d
151                 RESTARTCMD="/sbin/service \1 \&\& /sbin/service \1 restart"
152                 echo "yes"
153         else
154                 echo "no"
155         fi
156 fi
157 if [ -z "$RESTARTCMD" ]; then
158         for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
159                 printf "Checking for $x ... "
160                 if [ -d $x ]; then
161                         RCDIR=$x
162                         RESTARTCMD="$x/\1 status >/dev/null 2>\&1 \&\& $x/\1 restart"
163                         echo "yes"
164                         break
165                 else
166                         echo "no"
167                 fi
168         done
169 fi
170
171 if [ -z "$RESTARTCMD" ]; then
172         echo "WARNING! No means of interacting with system services detected!"
173         exit 1
174 fi
175
176 echo "RCDIR=            $RCDIR" >>$CONFIG_MK
177 # Work around bug in the dash shell as "echo 'foo \1'" does bad things
178 printf "%s\n" "RESTARTCMD=      $RESTARTCMD" >>$CONFIG_MK
179
180 echo
181 echo "   SYSCONFDIR =           $SYSCONFDIR"
182 echo "   SBINDIR =              $SBINDIR"
183 echo "   LIBEXECDIR =           $LIBEXECDIR"
184 echo "   VARDIR =               $RUNDIR"
185 echo "   MANDIR =               $MANDIR"
186 echo