Release openresolv-3.12.0
[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 STATUSARG=
12
13 for 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
45 done
46
47 : ${SED:=sed}
48
49 CONFIG_MK=config.mk
50
51 if [ -z "$BUILD" ]; then
52         # autoconf target triplet: cpu-vendor-os
53         BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
54 fi
55 : ${HOST:=$BUILD}
56
57 if [ -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
83 fi
84
85 echo "Configuring openresolv for ... $OS"
86 rm -rf $CONFIG_MK
87 echo "# $OS" >$CONFIG_MK
88
89 case "$OS" in
90 dragonfly*)
91         # This means /usr HAS to be mounted not via dhcpcd
92         : ${LIBEXECDIR:=${PREFIX:-/usr}/libexec/resolvconf}
93         ;;
94 linux*)
95         # cksum does't support -a and netpgp is rare
96         echo "CKSUM=            sha256sum --tag" >>$CONFIG_MK
97         echo "PGP=              gpg2" >>$CONFIG_MK
98         ;;
99 esac
100
101 case "$OS" in
102 dragonfly*|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         ;;
110 esac
111
112
113 if [ -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
122 fi
123 if [ -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
132 fi
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
141 eval SYSCONFDIR="$SYSCONFDIR"
142 eval SBINDIR="$SBINDIR"
143 eval LIBEXECDIR="$LIBEXECDIR"
144 eval VARDIR="$RUNDIR/resolvconf"
145 eval MANDIR="$MANDIR"
146
147 for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
148 do
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
155 done
156
157 echo
158 echo "   SYSCONFDIR =           $SYSCONFDIR"
159 echo "   SBINDIR =              $SBINDIR"
160 echo "   LIBEXECDIR =           $LIBEXECDIR"
161 echo "   VARDIR =               $RUNDIR"
162 echo "   MANDIR =               $MANDIR"
163 echo
164 echo "   RESTARTCMD =           $RESTARTCMD"
165 echo "   RCDIR =                $RCDIR"
166 echo "   STATUSARG =            $STATUSARG"
167 echo