Move init system detection from configure to resolvconf.
[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
10 for x do
11         opt=${x%%=*}
12         var=${x#*=}
13         case "$opt" in
14         --os|OS) OS=$var;;
15         --with-cc|CC) CC=$var;;
16         --debug) DEBUG=$var;;
17         --disable-debug) DEBUG=no;;
18         --enable-debug) DEBUG=yes;;
19         --prefix) PREFIX=$var;;
20         --sysconfdir) SYSCONFDIR=$var;;
21         --bindir|--sbindir) SBINDIR=$var;;
22         --libexecdir) LIBEXECDIR=$var;;
23         --statedir|--localstatedir) STATEDIR=$var;;
24         --dbdir) DBDIR=$var;;
25         --rundir) RUNDIR=$var;;
26         --mandir) MANDIR=$var;;
27         --with-ccopts|CFLAGS) CFLAGS=$var;;
28         CPPFLAGS) CPPFLAGS=$var;;
29         --build) BUILD=$var;;
30         --host) HOST=$var;;
31         --target) TARGET=$var;;
32         --libdir) LIBDIR=$var;;
33         --restartcmd) RESTARTCMD=$var;;
34         --includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
35         --datadir|--infodir) ;; # ignore autotools
36         --disable-maintainer-mode|--disable-dependency-tracking) ;;
37         --help) echo "See the README file for available options"; exit 0;;
38         *) echo "$0: WARNING: unknown option $opt" >&2;;
39         esac
40 done
41
42 if [ -z "$LIBEXECDIR" ]; then
43         printf "Checking for directory /libexec ... "
44         if [ -d /libexec ]; then
45                 echo "yes"
46                 LIBEXECDIR=$PREFIX/libexec/resolvconf
47         else
48                 echo "no"
49                 LIBEXECDIR=$PREFIX/lib/resolvconf
50         fi
51 fi
52 if [ -z "$RUNDIR" ]; then
53         printf "Checking for directory /run ... "
54         if [ -d /run ]; then
55                 echo "yes"
56                 RUNDIR=/run
57         else
58                 echo "no"
59                 RUNDIR=/var/run
60         fi
61 fi      
62
63 : ${SED:=sed}
64
65 : ${SYSCONFDIR:=$PREFIX/etc}
66 : ${SBINDIR:=$PREFIX/sbin}
67 : ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
68 : ${STATEDIR:=/var}
69 : ${RUNDIR:=$STATEDIR/run}
70 : ${MANDIR:=${PREFIX:-/usr}/share/man}
71
72 eval SYSCONFDIR="$SYSCONFDIR"
73 eval SBINDIR="$SBINDIR"
74 eval LIBEXECDIR="$LIBEXECDIR"
75 eval VARDIR="$RUNDIR/resolvconf"
76 eval MANDIR="$MANDIR"
77
78 CONFIG_MK=config.mk
79
80 if [ -z "$BUILD" ]; then
81         # autoconf target triplet: cpu-vendor-os
82         BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
83 fi
84 : ${HOST:=$BUILD}
85
86 if [ -z "$OS" ]; then
87         echo "Deriving operating system from ... $HOST"
88         # Derive OS from cpu-vendor-[kernel-]os
89         CPU=${HOST%%-*}
90         REST=${HOST#*-}
91         if [ "$CPU" != "$REST" ]; then
92                 VENDOR=${REST%%-*}
93                 REST=${REST#*-}
94                 if [ "$VENDOR" != "$REST" ]; then
95                         # Use kernel if given, otherwise os
96                         OS=${REST%%-*}
97                 else
98                         # 2 tupple
99                         OS=$VENDOR
100                         VENDOR=
101                 fi
102         fi
103
104         # Work with cpu-kernel-os, ie Debian
105         case "$VENDOR" in
106         linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
107         esac
108         # Special case
109         case "$OS" in
110         gnu*) OS=hurd;; # No HURD support as yet
111         esac
112 fi
113
114 echo "Configuring openresolv for ... $OS"
115 rm -rf $CONFIG_MK
116 echo "# $OS" >$CONFIG_MK
117
118 for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR; do
119         eval v=\$$x
120         # Make files look nice for import
121         l=$((10 - ${#x}))
122         unset t
123         [ $l -gt 3 ] && t="     "
124         echo "$x=$t     $v" >>$CONFIG_MK
125 done
126
127 echo
128 echo "   SYSCONFDIR =           $SYSCONFDIR"
129 echo "   SBINDIR =              $SBINDIR"
130 echo "   LIBEXECDIR =           $LIBEXECDIR"
131 echo "   VARDIR =               $RUNDIR"
132 echo "   MANDIR =               $MANDIR"
133 echo
134 echo "   RESTARTCMD =           $RESTARTCMD"
135 echo "   RCDIR =                $RCDIR"
136 echo