Update man pages and allow dhcpcd-qt to actually be installed now.
[dhcpcd-ui] / 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 DEBUG=
6 LIBDHCPCD=no
7 WITH_GTK=
8 NOTIFY=yes
9 INCLUDEDIR=
10
11 for x; do
12         opt=${x%%=*}
13         var=${x#*=}
14         [ "$var" = "$opt" ] && var=
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) BINDIR=$var;;
24         --libexecdir) LIBEXECDIR=$var;;
25         --statedir|--localstatedir) STATEDIR=$var;;
26         --rundir) RUNDIR=$var;;
27         --mandir) MANDIR=$var;;
28         --with-ccopts|CFLAGS) CFLAGS=$var;;
29         CPPFLAGS) CPPFLAGS=$var;;
30         --build) BUILD=$var;;
31         --host) HOST=$var;;
32         --target) TARGET=$var;;
33         --libdir) LIBDIR=$var;;
34         --includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
35         --datadir|--infodir) ;; # ignore autotools
36         --disable-maintainer-mode|--disable-dependency-tracking) ;;
37         --icondir) ICONDIR=$var;;
38         --with-gtk|--with-gtk+) WITH_GTK=${var:-yes};;
39         --without-gtk|--without-gtk+) WITH_GTK=no;;
40         --with-qt) WITH_QT=${var:-yes};;
41         --without-qt) WITH_QT=no;;
42         --enable-notification) NOTIFY=yes;;
43         --disable-notification) NOTIFY=no;;
44         --help) echo "See the README file for available options"; exit 0;;
45         *) echo "$0: WARNING: unknown option $opt" >&2;;
46         esac
47 done
48
49 : ${INSTALL:=install}
50 : ${SED:=sed}
51
52 : ${PREFIX:=${prefix:=/usr/local}}
53 : ${SYSCONFDIR:=$PREFIX/etc}
54 : ${BINDIR:=$PREFIX/bin}
55 : ${LIBEXECDIR:=$PREFIX/libexec}
56 : ${STATEDIR:=/var}
57 : ${MANDIR:=${PREFIX:-/usr}/share/man}
58
59 : ${ICONDIR:=$PREFIX/share/dhcpcd/icons}
60
61 eval SYSCONFDIR="$SYSCONFDIR"
62 eval LIBDIR="$LIBDIR"
63 eval LIBEXECDIR="$LIBEXECDIR"
64 eval STATEDIR="$STATEDIR"
65 eval DBDIR="$DBDIR"
66 eval RUNDIR="$RUNDIR"
67 eval MANDIR="$MANDIR"
68
69 _which()
70 {
71         x="$(which "$1" 2>/dev/null)"
72         if [ -n "$x" ]; then
73                 echo "$x"
74                 return 0
75         fi
76         for x in /sbin/"$1" /usr/sbin/"$1" \
77                 /usr/pkg/sbin/"$1" /usr/local/sbin/"$1"
78         do
79                 if [ -e "$x" ]; then
80                         echo "$x"
81                         return 0
82                 fi
83         done
84         return 1
85 }
86
87 CONFIG_H=config.h
88 CONFIG_MK=config.mk
89
90 if [ -z "$BUILD" ]; then
91         # autoconf target triplet: cpu-vendor-os
92         BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
93 fi
94 : ${HOST:=$BUILD}
95
96 if [ -z "$OS" ]; then
97         echo "Deriving operating system from ... $HOST"
98         # Derive OS from cpu-vendor-[kernel-]os
99         CPU=${HOST%%-*}
100         REST=${HOST#*-}
101         if [ "$CPU" != "$REST" ]; then
102                 VENDOR=${REST%%-*}
103                 REST=${REST#*-}
104                 if [ "$VENDOR" != "$REST" ]; then
105                         # Use kernel if given, otherwise os
106                         OS=${REST%%-*}
107                 else
108                         # 2 tupple
109                         OS=$VENDOR
110                         VENDOR=
111                 fi
112         fi
113
114         # Work with cpu-kernel-os, ie Debian
115         case "$VENDOR" in
116         linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
117         esac
118         # Special case
119         case "$OS" in
120         gnu*) OS=hurd;; # No HURD support as yet
121         esac
122 fi
123
124 echo "Configuring dhcpcd for ... $OS"
125 rm -f $CONFIG_H $CONFIG_MK
126 echo "# $OS" >$CONFIG_MK
127 echo "/* $OS */" >$CONFIG_H
128
129 VERSION=$($SED -ne 's/VERSION=  //p' Makefile)
130 echo "#define VERSION \"$VERSION\"" >>$CONFIG_H
131
132 for x in PREFIX SYSCONFDIR BINDIR ICONDIR; do
133         eval v=\$$x
134         # Make files look nice for import
135         l=$((10 - ${#x}))
136         unset t
137         [ $l -gt 3 ] && t="     "
138         echo "$x=$t     $v" >>$CONFIG_MK
139         unset t
140         [ $l -gt 2 ] && t="     "
141         echo "#define $x$t      \"$v\"" >>$CONFIG_H
142 done
143 echo "MANDIR=           ${MANDIR}" >>$CONFIG_MK
144
145 # Always obey CC.
146 # However, if CC is not specified and we are given GNU style
147 # --host or --build targets the expectation is we try and match that
148 # to a compiler.
149 if [ -n "$CC" ]; then
150         HOSTCC=
151 else
152         CC=cc
153         _COMPILERS="cc clang gcc pcc icc"
154 fi
155 if [ -n "$HOSTCC" ]; then
156         for _CC in $_COMPILERS; do
157                 _CC=$(_which "$HOSTCC$_CC")
158                 if [ -x "$_CC" ]; then
159                         CC=$_CC
160                         break
161                 fi
162         done
163 fi
164 if ! type "$CC" >/dev/null 2>&1; then
165         for _CC in $_COMPILERS; do
166                 _CC=$(_which "$_CC")
167                 if [ -x "$_CC" ]; then
168                         CC=$_CC
169                         break
170                 fi
171         done
172 fi
173
174 echo "Using compiler .. $CC"
175 cat <<EOF >_test.c
176 int main(void) {
177         return 0;
178 }
179 EOF
180 _CC=false
181 if $CC _test.c -o _test >/dev/null 2>&1; then
182         [ -x _test ] && _CC=true
183 fi
184 rm -f _test.c _test
185 if ! $_CC; then
186         echo "$CC does not create executables"
187         exit 1
188 fi
189 [ "$CC" != cc ] && echo "CC=    $CC" >>$CONFIG_MK
190 $CC --version | $SED -e '1!d'
191
192 # Set to blank, then append user config
193 # We do this so our SED call to append to XCC remains portable
194 if [ -n "$CFLAGS" ]; then
195         echo "CFLAGS=" >>$CONFIG_MK
196         echo "CFLAGS+=  $CFLAGS" >>$CONFIG_MK
197 fi
198 if [ -n "$CPPFLAGS" ]; then
199         echo "CPPFLAGS=" >>$CONFIG_MK
200         echo "CPPFLAGS+=        $CPPFLAGS" >>$CONFIG_MK
201 fi
202 if [ -n "$LDFLAGS" ]; then
203         echo "LDFLAGS=" >>$CONFIG_MK
204         echo "LDFLAGS+= $LDFLAGS" >>$CONFIG_MK
205 fi
206
207 for x in $INCLUDEDIR; do
208         echo "CPPFLAGS+=        -I$x" >>$CONFIG_MK
209 done
210
211 if [ -z "$DEBUG" -a -f .fslckout ]; then
212         printf "Found fossil checkout ... "
213         DEBUG=yes
214 else
215         DEBUG=no
216 fi
217 if [ "$DEBUG" != no -a "$DEBUG" != false ]; then
218         echo "Adding debugging CFLAGS"
219         cat <<EOF >>$CONFIG_MK
220 CFLAGS+=        -g -Wall -Wextra -Wshadow -Wformat=2
221 CFLAGS+=        -Wmissing-prototypes -Wmissing-declarations
222 CFLAGS+=        -Wmissing-noreturn -Wmissing-format-attribute
223 CFLAGS+=        -Wnested-externs
224 CFLAGS+=        -Winline -Wwrite-strings -Wcast-align -Wcast-qual
225 CFLAGS+=        -Wpointer-arith -Wstrict-overflow
226 CFLAGS+=        -Wdeclaration-after-statement
227 CFLAGS+=        -Wconversion
228 EOF
229         case "$OS" in
230         mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers
231         *)              echo "CFLAGS+=  -Wredundant-decls" >>$CONFIG_MK;;
232         esac
233 else
234         # Disable assertations
235         echo "CFLAGS+=  -DNDEBUG" >>$CONFIG_MK
236 fi
237
238 # Add CPPFLAGS and CFLAGS to CC for testing features
239 XCC="$CC `$SED -n -e 's/CPPLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
240 XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
241
242 if [ -z "$GETTEXT" ]; then
243         printf "Testing for gettext ... "
244         cat <<EOF >_gettext.c
245 #include <libintl.h>
246 int main(void) {
247         gettext("foo");
248         return 0;
249 }
250 EOF
251         LIB_INTL=
252         if $XCC _gettext.c -o _gettext 2>/dev/null; then
253                 GETTEXT=yes
254         elif $XCC _gettext.c -o _gettext -lintl 2>/dev/null; then
255                 GETTEXT="yes (-lintl)"
256                 LIB_INTL=-lintl
257                 QMAKE_CONFIG="CONFIG+=has_libintl"
258         else
259                 GETTEXT=no
260         fi
261         echo "$GETTEXT"
262         rm -f _gettext.c _gettext
263 fi
264 if [ "$GETTEXT" != no ]; then
265         echo "#define HAS_GETTEXT" >>$CONFIG_H
266         echo "LIB_INTL= $LIB_INTL" >>$CONFIG_MK
267 fi
268
269 if [ -z "$STRLCPY" ]; then
270         printf "Testing for strlcpy ... "
271         cat <<EOF >_strlcpy.c
272 #include <string.h>
273 int main(void) {
274         const char s1[] = "foo";
275         char s2[10];
276         strlcpy(s2, s1, sizeof(s2));
277         return 0;
278 }
279 EOF
280         if $XCC _strlcpy.c -o _strlcpy 2>/dev/null; then
281                 STRLCPY=yes
282         else
283                 STRLCPY=no
284         fi
285         echo "$STRLCPY"
286         rm -f _strlcpy.c _strlcpy
287 fi
288 if [ "$STRLCPY" = no ]; then
289         echo "#define strlcpy(dst, src, n) " \
290             "((size_t)snprintf(dst, n, \"%s\", src))" \
291             >>$CONFIG_H
292 fi
293
294 if [ -z "$LIBDIR" ]; then
295         printf "lib directory name ... "
296         case `readlink /lib` in
297                 "") LIBNAME="lib";;
298                 *) LIBNAME=$(basename `readlink /lib`);;
299         esac
300         echo "$LIBNAME"
301         echo "LIBNAME=  $LIBNAME" >>$CONFIG_MK
302         LIBDIR=${PREFIX}/${LIBNAME}
303         echo "LIBDIR=           \${PREFIX}/\${LIBNAME}" >>$CONFIG_MK
304 else
305         echo "LIBDIR=   $LIBDIR" >>$CONFIG_MK
306 fi
307
308 # We normally want to build in the static library
309 if [ "$LIBDHCPCD" = yes ]; then
310         x="-ldhcpcd"
311         echo "LIB_DHCPCD_INSTALL=       _libinstall" >>$CONFIG_MK
312 else
313         x="-Wl,-Bstatic -ldhcpcd -Wl,-Bdynamic"
314 fi
315 echo "LIB_DHCPCD=       $x" >>$CONFIG_MK
316
317 # Due to our use of pkg-config, pass --as-needed to ld so we only link
318 # what we actually need.
319 echo "LDADD+=           -Wl,--as-needed" >>$CONFIG_MK
320
321 UI=
322 if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
323         if pkg-config --cflags gtk+-2.0 >/dev/null 2>&1; then
324                 WITH_GTK="gtk+-2.0"
325         elif pkg-config --cflags gtk+-3.0 >/dev/null 2>&1; then
326                 WITH_GTK="gtk+-3.0"
327         fi
328 elif [ -n "$WITH_GTK" -a "$WITH_GTK" != no ]; then
329         if ! pkg-config --cflags $WITH_GTK >/dev/null; then
330                 echo "$0: no suitable GTK+ library has been found" >&2
331                 exit 1
332         fi
333 fi
334         
335 if [ -n "$WITH_GTK" -a "$WITH_GTK" != no ]; then
336         PKG="$WITH_GTK"
337         if [ "$NOTIFY" = yes ]; then
338                 PKG="$PKG${PKG:+ }libnotify"
339                 echo "NOTIFY=           -DNOTIFY" >>$CONFIG_MK
340         fi
341         GTK_CFLAGS=$(pkg-config --cflags $PKG)
342         [ $? != 0 -a "$WITH_GTK" = yes ] && exit 1
343         GTK_LIBS=$(pkg-config --libs $PKG)
344         [ $? != 0 -a "$WITH_GTK" = yes ] && exit 1
345         echo "GTK+ CFLAGS=$GTK_CFLAGS"
346         echo "GTK+ LIBS=$GTK_LIBS"
347         echo "GTK_CFLAGS=       $GTK_CFLAGS" >>$CONFIG_MK
348         echo "GTK_LIBS= $GTK_LIBS" >>$CONFIG_MK
349         UI="$UI${UI:+ }dhcpcd-gtk"
350 fi
351
352 DHCPCD_QT=false
353 if [ "WITH_QT" = yes -o -z "$WITH_QT" ]; then
354         if type qmake >/dev/null 2>&1; then
355                 UI="$UI${UI+ }dhcpcd-qt"
356                 DHCPCD_QT=true
357         fi
358 elif [ -n "$WITH_QT" -a "$WITH_QT" != no ]; then
359         if type qmake >/dev/null 2>&1; then
360                 UI="$UI${UI+ }dhcpcd-qt"
361                 DHCPCD_QT=true
362         else
363                 echo "$0: no suitable QT library has been found" >&2
364                 exit 1
365         fi
366 fi
367
368 if [ -n "$UI" ]; then
369         echo "ICONS=            icons" >>$CONFIG_MK
370 fi
371 echo "UI=               $UI" >>$CONFIG_MK
372
373 echo
374 echo "   SYSCONFDIR =           $SYSCONFDIR"
375 echo "   BINDIR =               $BINDIR"
376 echo "   LIBDIR =               $LIBDIR"
377 echo "   ICONDIR =              $ICONDIR"
378 echo "   MANDIR =               $MANDIR"
379 echo "   UI =                   $UI"
380 echo
381
382 echo "MKDIR=            \${TOPDIR}/mk" >>$CONFIG_MK
383
384 if $DHCPCD_QT; then
385         QMAKE_CONFIG="$QMAKE_CONFIG PREFIX=$PREFIX MANDIR=$MANDIR"
386         if ! (cd src/dhcpcd-qt; qmake $QMAKE_CONFIG dhcpcd-qt.pro); then
387                 echo "$0: failed to configure dhcpcd-qt" >&2
388                 exit 1
389         fi
390 fi