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