Add LICENSE.
[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 if [ -z "$LIBEXECDIR" ]; then
48         printf "Checking for directory /libexec ... "
49         if [ -d /libexec ]; then
50                 echo "yes"
51                 LIBEXECDIR=$PREFIX/libexec/resolvconf
52         else
53                 echo "no"
54                 LIBEXECDIR=$PREFIX/lib/resolvconf
55         fi
56 fi
57 if [ -z "$RUNDIR" ]; then
58         printf "Checking for directory /run ... "
59         if [ -d /run ]; then
60                 echo "yes"
61                 RUNDIR=/run
62         else
63                 echo "no"
64                 RUNDIR=/var/run
65         fi
66 fi      
67
68 : ${SED:=sed}
69
70 : ${SYSCONFDIR:=$PREFIX/etc}
71 : ${SBINDIR:=$PREFIX/sbin}
72 : ${LIBEXECDIR:=$PREFIX/libexec/resolvconf}
73 : ${STATEDIR:=/var}
74 : ${RUNDIR:=$STATEDIR/run}
75 : ${MANDIR:=${PREFIX:-/usr}/share/man}
76
77 eval SYSCONFDIR="$SYSCONFDIR"
78 eval SBINDIR="$SBINDIR"
79 eval LIBEXECDIR="$LIBEXECDIR"
80 eval VARDIR="$RUNDIR/resolvconf"
81 eval MANDIR="$MANDIR"
82
83 CONFIG_MK=config.mk
84
85 if [ -z "$BUILD" ]; then
86         # autoconf target triplet: cpu-vendor-os
87         BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
88 fi
89 : ${HOST:=$BUILD}
90
91 if [ -z "$OS" ]; then
92         echo "Deriving operating system from ... $HOST"
93         # Derive OS from cpu-vendor-[kernel-]os
94         CPU=${HOST%%-*}
95         REST=${HOST#*-}
96         if [ "$CPU" != "$REST" ]; then
97                 VENDOR=${REST%%-*}
98                 REST=${REST#*-}
99                 if [ "$VENDOR" != "$REST" ]; then
100                         # Use kernel if given, otherwise os
101                         OS=${REST%%-*}
102                 else
103                         # 2 tupple
104                         OS=$VENDOR
105                         VENDOR=
106                 fi
107         fi
108
109         # Work with cpu-kernel-os, ie Debian
110         case "$VENDOR" in
111         linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
112         esac
113         # Special case
114         case "$OS" in
115         gnu*) OS=hurd;; # No HURD support as yet
116         esac
117 fi
118
119 echo "Configuring openresolv for ... $OS"
120 rm -rf $CONFIG_MK
121 echo "# $OS" >$CONFIG_MK
122
123 case "$OS" in
124 freebsd*)
125         # On FreeBSD, /etc/init.d/foo status returns 0 if foo is not enabled
126         # regardless of if it's not running.
127         # So we force onestatus to work around this silly bug.
128         if [ -z "$STATUSARG" ]; then
129                 STATUSARG="onestatus"
130         fi
131         ;;
132 linux*)
133         # cksum does't support -a and netpgp is rare
134         echo "CKSUM=            sha256sum --tag" >>$CONFIG_MK
135         echo "PGP=              gpg2" >>$CONFIG_MK
136         ;;
137 esac
138
139 for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR RESTARTCMD RCDIR STATUSARG
140 do
141         eval v=\$$x
142         # Make files look nice for import
143         l=$((10 - ${#x}))
144         unset t
145         [ $l -gt 3 ] && t="     "
146         echo "$x=$t     $v" >>$CONFIG_MK
147 done
148
149 echo
150 echo "   SYSCONFDIR =           $SYSCONFDIR"
151 echo "   SBINDIR =              $SBINDIR"
152 echo "   LIBEXECDIR =           $LIBEXECDIR"
153 echo "   VARDIR =               $RUNDIR"
154 echo "   MANDIR =               $MANDIR"
155 echo
156 echo "   RESTARTCMD =           $RESTARTCMD"
157 echo "   RCDIR =                $RCDIR"
158 echo "   STATUSARG =            $STATUSARG"
159 echo