Match copyright in other subscribers
[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
11 for x; do
12         opt=${x%%=*}
13         var=${x#*=}
14         case "$opt" in
15         --os|OS) OS=$var;;
16         --with-cc|CC) CC=$var;;
17         --debug) DEBUG=$var;;
18         --disable-debug) DEBUG=no;;
19         --enable-debug) DEBUG=yes;;
20         --prefix) prefix=$var;;
21         --sysconfdir) SYSCONFDIR=$var;;
22         --bindir|--sbindir) SBINDIR=$var;;
23         --libexecdir) LIBEXECDIR=$var;;
24         --statedir|--localstatedir) STATEDIR=$var;;
25         --dbdir) DBDIR=$var;;
26         --rundir) RUNDIR=$var;;
27         --mandir) MANDIR=$var;;
28         --with-ccopts|CFLAGS) CFLAGS=$var;;
29         CPPFLAGS) CPPFLAGS=$var;;
30         --build) BUILD=$var;;
31         --host) HOST=$var;;
32         --target) TARGET=$var;;
33         --libdir) LIBDIR=$var;;
34         --restartcmd) RESTARTCMD=$var;;
35         --includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
36         --datadir|--infodir) ;; # ignore autotools
37         --disable-maintainer-mode|--disable-dependency-tracking) ;;
38         --help) echo "See the README file for available options"; exit 0;;
39         *) echo "$0: WARNING: unknown option $opt" >&2;;
40         esac
41 done
42
43 : ${SED:=sed}
44
45 : ${PREFIX:=$prefix}
46 : ${SYSCONFDIR:=$PREFIX/etc}
47 : ${SBINDIR:=$PREFIX/sbin}
48 : ${LIBEXECDIR:=$PREFIX/libexec}
49 : ${STATEDIR:=/var}
50 : ${RUNDIR:=$STATEDIR/run}
51 : ${MANDIR:=${PREFIX:-/usr}/share/man}
52
53 eval SYSCONFDIR="$SYSCONFDIR"
54 eval SBINDIR="$SBINDIR"
55 eval LIBEXECDIR="$LIBEXECDIR/resolvconf"
56 eval VARDIR="$RUNDIR/resolvconf"
57 eval MANDIR="$MANDIR"
58
59 CONFIG_MK=config.mk
60
61 if [ -z "$BUILD" ]; then
62         BUILD=`uname -m`-`uname -s | tr '[:upper:]' '[:lower:]'`
63 fi
64 if [ -z "$HOST" ]; then
65         [ -z "$TARGET" ] && TARGET=$BUILD
66         HOST=$TARGET
67 fi
68 if [ -z "$TARGET" ]; then
69         [ -z "$HOST" ] && HOST=$BUILD
70         TARGET=$HOST
71 fi
72
73 # Debian and Slackware have linux in different places when dealing with
74 # autoconf, so we deal with that here.
75 if [ -z "$OS" ]; then
76         case "$TARGET" in
77         *-linux-*|linux-*|*-linux|linux) OS=linux;;
78         esac
79 fi
80
81 if [ -z "$OS" ]; then
82         # Derive OS from cpu-manufacturer-os-kernel
83         CPU=${TARGET%%-*}
84         REST=${TARGET#*-}
85         if [ "$CPU" != "$REST" ]; then
86                 MANU=${REST%%-*}
87                 REST=${REST#*-}
88                 if [ "$MANU" != "$REST" ]; then
89                         OS=${REST%%-*}
90                         REST=${REST#*-}
91                         if [ "$OS" != "$REST" ]; then
92                                 KERNEL=${REST%%-*}
93                         else
94                                 # 3 tupple
95                                 KERNEL=$OS
96                                 OS=$MANU
97                                 MANU=
98                         fi
99                 else
100                         # 2 tupple
101                         OS=$MANU
102                         MANU=
103                 fi
104         fi
105 fi
106
107 echo "Configuring openresolv for ... $OS"
108 rm -rf $CONFIG_MK
109 echo "# $OS" >$CONFIG_MK
110
111 for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR; do
112         eval v=\$$x
113         # Make files look nice for import
114         l=$((10 - ${#x}))
115         unset t
116         [ $l -gt 3 ] && t="     "
117         echo "$x=$t     $v" >>$CONFIG_MK
118 done
119
120 if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
121         echo "Overriding service status check for Arch Linux"
122         RESTARTCMD="[ -e /var/run/daemons/\1 ] && /etc/rc.d/\1 restart"
123         echo "yes"
124 fi
125
126 if [ -z "$RESTARTCMD" ]; then
127         printf "Checking for OpenRC ... "
128         if [ -x /sbin/rc-service ]; then
129                 RESTARTCMD="/sbin/rc-service -e \1 && /sbin/rc-service \1 -Ds restart"
130                 echo "yes"
131         else
132                 echo "no"
133         fi
134 fi
135 if [ -z "$RESTARTCMD" ]; then
136         printf "Checking for invoke-rc.d ... "
137         if [ -x /usr/sbin/invoke-rc.d ]; then
138                 RESTARTCMD="/usr/sbin/invoke-rc.d --query --quiet \1 restart || [ \\$? = 104 ] && /usr/sbin/invoke-rc.d \1 restart"
139                 echo "yes"
140         else
141                 echo "no"
142         fi
143 fi
144 if [ -z "$RESTARTCMD" ]; then
145         printf "Checking for service ... "
146         if [ -x /sbin/service ]; then
147                 RESTARTCMD="/sbin/service \1 && /sbin/service \1 restart"
148                 echo "yes"
149         else
150                 echo "no"
151         fi
152 fi
153 if [ -z "$RESTARTCMD" ]; then
154         for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
155                 printf "Checking for $x ... "
156                 if [ -d $x ]; then
157                         RESTARTCMD="$x/\1 status >/dev/null 2>&1 && $x/\1 restart"
158                         echo "yes"
159                         break
160                 else
161                         echo "no"
162                 fi
163         done
164 fi
165
166 if [ -z "$RESTARTCMD" ]; then
167         echo "WARNING! No means of interacting with system services detected!"
168         exit 1
169 fi
170 # Transform for a make file
171 RESTARTCMD=$(echo "$RESTARTCMD" | $SED \
172         -e 's:\&:\\\&:g' \
173         -e 's:\$:\$\$:g' \
174 )
175 echo "RESTARTCMD=       ${RESTARTCMD}" >>$CONFIG_MK
176
177 echo
178 echo "   SYSCONFDIR =           $SYSCONFDIR"
179 echo "   SBINDIR =              $SBINDIR"
180 echo "   LIBEXECDIR =           $LIBEXECDIR"
181 echo "   VARDIR =               $RUNDIR"
182 echo "   MANDIR =               $MANDIR"
183 echo