Correct issue with dragonfly libexecdir
[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 freebsd*)
95         # On FreeBSD, /etc/init.d/foo status returns 0 if foo is not enabled
96         # regardless of if it's not running.
97         # So we force onestatus to work around this silly bug.
98         if [ -z "$STATUSARG" ]; then
99                 STATUSARG="onestatus"
100         fi
101         ;;
102 linux*)
103         # cksum does't support -a and netpgp is rare
104         echo "CKSUM=            sha256sum --tag" >>$CONFIG_MK
105         echo "PGP=              gpg2" >>$CONFIG_MK
106         ;;
107 esac
108
109
110 if [ -z "$LIBEXECDIR" ]; then
111         printf "Checking for directory /libexec ... "
112         if [ -d /libexec ]; then
113                 echo "yes"
114                 LIBEXECDIR=$PREFIX/libexec/resolvconf
115         else
116                 echo "no"
117                 LIBEXECDIR=$PREFIX/lib/resolvconf
118         fi
119 fi
120 if [ -z "$RUNDIR" ]; then
121         printf "Checking for directory /run ... "
122         if [ -d /run ]; then
123                 echo "yes"
124                 RUNDIR=/run
125         else
126                 echo "no"
127                 RUNDIR=/var/run
128         fi
129 fi
130
131 : ${SYSCONFDIR:=$PREFIX/etc}
132 : ${SBINDIR:=$PREFIX/sbin}
133 : ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
134 : ${STATEDIR:=/var}
135 : ${RUNDIR:=$STATEDIR/run}
136 : ${MANDIR:=${PREFIX:-/usr}/share/man}
137
138 eval SYSCONFDIR="$SYSCONFDIR"
139 eval SBINDIR="$SBINDIR"
140 eval LIBEXECDIR="$LIBEXECDIR"
141 eval VARDIR="$RUNDIR/resolvconf"
142 eval MANDIR="$MANDIR"
143
144 for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
145 do
146         eval v=\$$x
147         # Make files look nice for import
148         l=$((10 - ${#x}))
149         unset t
150         [ $l -gt 3 ] && t="     "
151         echo "$x=$t     $v" >>$CONFIG_MK
152 done
153
154 echo
155 echo "   SYSCONFDIR =           $SYSCONFDIR"
156 echo "   SBINDIR =              $SBINDIR"
157 echo "   LIBEXECDIR =           $LIBEXECDIR"
158 echo "   VARDIR =               $RUNDIR"
159 echo "   MANDIR =               $MANDIR"
160 echo
161 echo "   RESTARTCMD =           $RESTARTCMD"
162 echo "   RCDIR =                $RCDIR"
163 echo "   STATUSARG =            $STATUSARG"
164 echo