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