Re-write libdhcpcd to talk to dhcpcd directly and not use DBus.
[dhcpcd-ui] / configure
index 5bfc7d97e52acfbc13f4c244b9a82d36865964e9..cd598facdf4b0ac6f682ccd23fcf9b18a1aa3767 100755 (executable)
--- a/configure
+++ b/configure
@@ -6,6 +6,7 @@ DEBUG=
 LIBDHCPCD=no
 WITH_GTK=
 NOTIFY=yes
+INCLUDEDIR=
 
 for x; do
        opt=${x%%=*}
@@ -17,7 +18,7 @@ for x; do
        --debug) DEBUG=$var;;
        --disable-debug) DEBUG=no;;
        --enable-debug) DEBUG=yes;;
-       --prefix) PREFIX=$var;;
+       --prefix) prefix=$var;;
        --sysconfdir) SYSCONFDIR=$var;;
        --bindir) BINDIR=$var;;
        --libexecdir) LIBEXECDIR=$var;;
@@ -30,7 +31,9 @@ for x; do
        --host) HOST=$var;;
        --target) TARGET=$var;;
        --libdir) LIBDIR=$var;;
+       --includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
        --datadir|--infodir) ;; # ignore autotools
+       --disable-maintainer-mode|--disable-dependency-tracking) ;;
        --icondir) ICONDIR=$var;;
        --with-gtk|--with-gtk+) WITH_GTK=${var:-yes};;
        --without-gtk|--without-gtk+) WITH_GTK=no;;
@@ -44,7 +47,7 @@ done
 : ${INSTALL:=install}
 : ${SED:=sed}
 
-: ${PREFIX:=/usr/local}
+: ${PREFIX:=${prefix:=/usr/local}}
 : ${SYSCONFDIR:=$PREFIX/etc}
 : ${BINDIR:=$PREFIX/bin}
 : ${LIBEXECDIR:=$PREFIX/libexec}
@@ -53,6 +56,14 @@ done
 
 : ${ICONDIR:=$PREFIX/share/dhcpcd/icons}
 
+eval SYSCONFDIR="$SYSCONFDIR"
+eval LIBDIR="$LIBDIR"
+eval LIBEXECDIR="$LIBEXECDIR"
+eval STATEDIR="$STATEDIR"
+eval DBDIR="$DBDIR"
+eval RUNDIR="$RUNDIR"
+eval MANDIR="$MANDIR"
+
 _which()
 {
        x="$(which "$1" 2>/dev/null)"
@@ -75,29 +86,40 @@ CONFIG_H=config.h
 CONFIG_MK=config.mk
 
 if [ -z "$BUILD" ]; then
-       BUILD=`uname -m`-unknown-`uname -s | tr '[:upper:]' '[:lower:]'`
-fi
-if [ -z "$HOST" ]; then
-       [ -z "$TARGET" ] && TARGET=$BUILD
-       HOST=$TARGET
-fi
-if [ -z "$TARGET" ]; then
-       [ -z "$HOST" ] && HOST=$BUILD
-       TARGET=$HOST
+       # autoconf target triplet: cpu-vendor-os
+       BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')
 fi
+: ${HOST:=$BUILD}
 
 if [ -z "$OS" ]; then
-       # Derive OS from cpu-manufacturer-os-kernel
-       CPU=${TARGET%%-*}
-       REST=${TARGET#*-}
-       MANU=${REST%%-*}
-       REST=${REST#*-}
-       OS=${REST%%-*}
-       REST=${REST#*-}
-       KERNEL=${REST%%-*}
+       echo "Deriving operating system from ... $HOST"
+       # Derive OS from cpu-vendor-[kernel-]os
+       CPU=${HOST%%-*}
+       REST=${HOST#*-}
+       if [ "$CPU" != "$REST" ]; then
+               VENDOR=${REST%%-*}
+               REST=${REST#*-}
+               if [ "$VENDOR" != "$REST" ]; then
+                       # Use kernel if given, otherwise os
+                       OS=${REST%%-*}
+               else
+                       # 2 tupple
+                       OS=$VENDOR
+                       VENDOR=
+               fi
+       fi
+
+        # Work with cpu-kernel-os, ie Debian
+       case "$VENDOR" in
+       linux*|kfreebsd*) OS=$VENDOR; VENDOR= ;;
+       esac
+       # Special case
+       case "$OS" in
+       gnu*) OS=hurd;; # No HURD support as yet
+       esac
 fi
 
-echo "Configuring dhcpcd-ui for ... $OS"
+echo "Configuring dhcpcd for ... $OS"
 rm -f $CONFIG_H $CONFIG_MK
 echo "# $OS" >$CONFIG_MK
 echo "/* $OS */" >$CONFIG_H
@@ -116,59 +138,99 @@ for x in PREFIX SYSCONFDIR BINDIR ICONDIR; do
        [ $l -gt 2 ] && t="     "
        echo "#define $x$t      \"$v\"" >>$CONFIG_H
 done
+echo "MANDIR=          ${MANDIR}" >>$CONFIG_MK
 
-if [ -z "$CC" ]; then
-       printf "Looking for compiler ... "
-       for b in $TARGET- ""; do
-               for cc in gcc pcc icc cc; do
-                       if type $b$cc >/dev/null 2>&1; then
-                               CC=$b$cc
-                               echo "$CC"
-                               break
-                       fi
-               done
-               [ -n "$CC" ] && break
-       done
-       if [ -z "$CC" ]; then
-               echo
-               echo "no suitable compiler found - aborting" >&2
-               exit 1
-       fi
+# Always obey CC.
+# However, if CC is not specified and we are given GNU style
+# --host or --build targets the expectation is we try and match that
+# to a compiler.
+if [ -n "$CC" ]; then
+       HOSTCC=
 else
-       echo "Using compiler $CC"
+       CC=cc
+       _COMPILERS="cc clang gcc pcc icc"
+fi
+if [ -n "$HOSTCC" ]; then
+       for _CC in $_COMPILERS; do
+               _CC=$(_which "$HOSTCC$_CC")
+               if [ -x "$_CC" ]; then
+                       CC=$_CC
+                       break
+               fi
+       done
+fi
+if ! type "$CC" >/dev/null 2>&1; then
+       for _CC in $_COMPILERS; do
+               _CC=$(_which "$_CC")
+               if [ -x "$_CC" ]; then
+                       CC=$_CC
+                       break
+               fi
+       done
 fi
-echo "CC=              $CC" >>$CONFIG_MK
 
-if [ -z "$CFLAGS" ]; then
-       CFLAGS="-O2"
+echo "Using compiler .. $CC"
+cat <<EOF >_test.c
+int main(void) {
+       return 0;
+}
+EOF
+_CC=false
+if $CC _test.c -o _test >/dev/null 2>&1; then
+       [ -x _test ] && _CC=true
 fi
-echo "CFLAGS=          $CFLAGS" >>$CONFIG_MK
-if [ -n "$CPPLAGS" ]; then
-       echo "CPPLAGS=          $CPPLAGS" >>$CONFIG_MK
+rm -f _test.c _test
+if ! $_CC; then
+       echo "$CC does not create executables"
+       exit 1
 fi
+[ "$CC" != cc ] && echo "CC=   $CC" >>$CONFIG_MK
+$CC --version | $SED -e '1!d'
 
-if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then
-       echo "Enabling memory debugging"
-       echo "CPPFLAGS+=        -DDEBUG_MEMORY" >>$CONFIG_MK
-elif [ -z "$DEBUG" -a -d .git ]; then
-       printf "Found git ... "
+# Set to blank, then append user config
+# We do this so our SED call to append to XCC remains portable
+if [ -n "$CFLAGS" ]; then
+       echo "CFLAGS=" >>$CONFIG_MK
+       echo "CFLAGS+=  $CFLAGS" >>$CONFIG_MK
+fi
+if [ -n "$CPPFLAGS" ]; then
+       echo "CPPFLAGS=" >>$CONFIG_MK
+       echo "CPPFLAGS+=        $CPPFLAGS" >>$CONFIG_MK
+fi
+if [ -n "$LDFLAGS" ]; then
+       echo "LDFLAGS=" >>$CONFIG_MK
+       echo "LDFLAGS+= $LDFLAGS" >>$CONFIG_MK
+fi
+
+for x in $INCLUDEDIR; do
+       echo "CPPFLAGS+=        -I$x" >>$CONFIG_MK
+done
+
+if [ -z "$DEBUG" -a -f .fslckout ]; then
+       printf "Found fossil checkout ... "
        DEBUG=yes
-       echo "LDADD+=           -Wl,-rpath=../libdhcpcd" >>$CONFIG_MK
 else
        DEBUG=no
 fi
 if [ "$DEBUG" != no -a "$DEBUG" != false ]; then
        echo "Adding debugging CFLAGS"
        cat <<EOF >>$CONFIG_MK
-CFLAGS+=       -Wall -Wextra -Wimplicit -Wshadow -Wformat=2
+CFLAGS+=       -g -Wall -Wextra -Wshadow -Wformat=2
 CFLAGS+=       -Wmissing-prototypes -Wmissing-declarations
 CFLAGS+=       -Wmissing-noreturn -Wmissing-format-attribute
-CFLAGS+=       -Wredundant-decls  -Wnested-externs
+CFLAGS+=       -Wnested-externs
 CFLAGS+=       -Winline -Wwrite-strings -Wcast-align -Wcast-qual
-CFLAGS+=       -Wpointer-arith
-CFLAGS+=       -Wdeclaration-after-statement -Wsequence-point
-CFLAGS+=       -fno-common
+CFLAGS+=       -Wpointer-arith -Wstrict-overflow
+CFLAGS+=       -Wdeclaration-after-statement
+CFLAGS+=       -Wconversion
 EOF
+       case "$OS" in
+       mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers
+       *)              echo "CFLAGS+=  -Wredundant-decls" >>$CONFIG_MK;;
+       esac
+else
+       # Disable assertations
+       echo "CFLAGS+=  -DNDEBUG" >>$CONFIG_MK
 fi
 
 # Add CPPFLAGS and CFLAGS to CC for testing features
@@ -222,17 +284,26 @@ else
 fi
 echo "LIB_DHCPCD=      $x" >>$CONFIG_MK
 
-# Get DBus CFLAGS
-DBUS_CFLAGS=$(pkg-config --cflags dbus-1) || exit 1
-DBUS_LIBS=$(pkg-config --libs dbus-1) || exit 1
-echo "DBus CFLAGS=$DBUS_CFLAGS"
-echo "DBus LIBS=$DBUS_LIBS"
-echo "DBUS_CFLAGS=     $DBUS_CFLAGS" >>$CONFIG_MK
-echo "DBUS_LIBS=       $DBUS_LIBS" >>$CONFIG_MK
+# Due to our use of pkg-config, pass --as-needed to ld so we only link
+# what we actually need.
+echo "LDADD+=  -Wl,--as-needed" >>$CONFIG_MK
 
 UI=
 if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
-       PKG="dbus-1 gtk+-2.0"
+       if pkg-config --cflags gtk+-2.0 >/dev/null 2>&1; then
+               WITH_GTK="gtk+-2.0"
+       elif pkg-config --cflags gtk+-3.0 >/dev/null 2>&1; then
+               WITH_GTK="gtk+-3.0"
+       fi
+elif [ -n "$WITH_GTK" -a "$WITH_GTK" != no ]; then
+       if ! pkg-config --cflags $WITH_GTK >/dev/null; then
+               echo "$0: no suitable GTK+ library has been found" >&2
+               exit 1
+       fi
+fi
+
+if [ -n "$WITH_GTK" ]; then
+       PKG="dbus-1 $WITH_GTK"
        if [ "$NOTIFY" = yes ]; then
                PKG="$PKG${PKG:+ }libnotify"
                echo "NOTIFY=           -DNOTIFY" >>$CONFIG_MK
@@ -249,7 +320,7 @@ if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
 fi
 
 if [ -z "$UI" ]; then
-       echo "no UI is available, not building." >&2
+       echo "$0: no UI is available, not building." >&2
        exit 1
 fi
 echo "UI=              $UI" >>config.mk
@@ -259,6 +330,7 @@ echo "   SYSCONFDIR =               $SYSCONFDIR"
 echo "   BINDIR =              $BINDIR"
 echo "   LIBDIR =              $LIBDIR"
 echo "   ICONDIR =             $ICONDIR"
+echo "   MANDIR =              $MANDIR"
 echo "   UI =                  $UI"
 echo