Add a man page for dhcpcd-gtk.
[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         --enable-notification) NOTIFY=yes;;
41         --disable-notification) NOTIFY=no;;
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 : ${INSTALL:=install}
48 : ${SED:=sed}
49
50 : ${PREFIX:=${prefix:=/usr/local}}
51 : ${SYSCONFDIR:=$PREFIX/etc}
52 : ${BINDIR:=$PREFIX/bin}
53 : ${LIBEXECDIR:=$PREFIX/libexec}
54 : ${STATEDIR:=/var}
55 : ${MANDIR:=${PREFIX:-/usr}/share/man}
56
57 : ${ICONDIR:=$PREFIX/share/dhcpcd/icons}
58
59 eval SYSCONFDIR="$SYSCONFDIR"
60 eval LIBDIR="$LIBDIR"
61 eval LIBEXECDIR="$LIBEXECDIR"
62 eval STATEDIR="$STATEDIR"
63 eval DBDIR="$DBDIR"
64 eval RUNDIR="$RUNDIR"
65 eval MANDIR="$MANDIR"
66
67 _which()
68 {
69         x="$(which "$1" 2>/dev/null)"
70         if [ -n "$x" ]; then
71                 echo "$x"
72                 return 0
73         fi
74         for x in /sbin/"$1" /usr/sbin/"$1" \
75                 /usr/pkg/sbin/"$1" /usr/local/sbin/"$1"
76         do
77                 if [ -e "$x" ]; then
78                         echo "$x"
79                         return 0
80                 fi
81         done
82         return 1
83 }
84
85 CONFIG_H=config.h
86 CONFIG_MK=config.mk
87
88 if [ -z "$BUILD" ]; then
89         BUILD=`uname -m`-unknown-`uname -s | tr '[:upper:]' '[:lower:]'`
90 fi
91 if [ -z "$HOST" ]; then
92         [ -z "$TARGET" ] && TARGET=$BUILD
93         HOST=$TARGET
94 fi
95 if [ -z "$TARGET" ]; then
96         [ -z "$HOST" ] && HOST=$BUILD
97         TARGET=$HOST
98 fi
99
100 if [ -z "$OS" ]; then
101         # Derive OS from cpu-manufacturer-os-kernel
102         CPU=${TARGET%%-*}
103         REST=${TARGET#*-}
104         if [ "$CPU" != "$REST" ]; then
105                 MANU=${REST%%-*}
106                 REST=${REST#*-}
107                 if [ "$MANU" != "$REST" ]; then
108                         OS=${REST%%-*}
109                         REST=${REST#*-}
110                         if [ "$OS" != "$REST" ]; then
111                                 KERNEL=${REST%%-*}
112                         else
113                                 # 3 tupple
114                                 KERNEL=$OS
115                                 OS=$MANU
116                                 MANU=
117                         fi
118                 else
119                         # 2 tupple
120                         OS=$MANU
121                         MANU=
122                 fi
123         fi
124 fi
125
126 echo "Configuring dhcpcd-ui for ... $OS"
127 rm -f $CONFIG_H $CONFIG_MK
128 echo "# $OS" >$CONFIG_MK
129 echo "/* $OS */" >$CONFIG_H
130
131 VERSION=$($SED -ne 's/VERSION=  //p' Makefile)
132 echo "#define VERSION \"$VERSION\"" >>$CONFIG_H
133
134 for x in PREFIX SYSCONFDIR BINDIR ICONDIR; do
135         eval v=\$$x
136         # Make files look nice for import
137         l=$((10 - ${#x}))
138         unset t
139         [ $l -gt 3 ] && t="     "
140         echo "$x=$t     $v" >>$CONFIG_MK
141         unset t
142         [ $l -gt 2 ] && t="     "
143         echo "#define $x$t      \"$v\"" >>$CONFIG_H
144 done
145 echo "MANDIR=           ${MANDIR}" >>$CONFIG_MK
146
147 if [ -z "$CC" ]; then
148         printf "Looking for compiler ... "
149         for b in $TARGET- ""; do
150                 for cc in gcc pcc icc cc; do
151                         if type $b$cc >/dev/null 2>&1; then
152                                 CC=$b$cc
153                                 echo "$CC"
154                                 break
155                         fi
156                 done
157                 [ -n "$CC" ] && break
158         done
159         if [ -z "$CC" ]; then
160                 echo
161                 echo "no suitable compiler found - aborting" >&2
162                 exit 1
163         fi
164 else
165         echo "Using compiler $CC"
166 fi
167 echo "CC=               $CC" >>$CONFIG_MK
168
169 if [ -z "$CFLAGS" ]; then
170         CFLAGS="-O2"
171 fi
172 echo "CFLAGS=           $CFLAGS" >>$CONFIG_MK
173 if [ -n "$CPPLAGS" ]; then
174         echo "CPPLAGS=          $CPPLAGS" >>$CONFIG_MK
175 fi
176 for x in $INCLUDEDIR; do
177         echo "CPPFLAGS+=        -I$x" >>$CONFIG_MK
178 done
179
180 if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then
181         echo "Enabling memory debugging"
182         echo "CPPFLAGS+=        -DDEBUG_MEMORY" >>$CONFIG_MK
183 elif [ -z "$DEBUG" -a -d .git ]; then
184         printf "Found git ... "
185         DEBUG=yes
186         echo "LDADD+=           -Wl,-rpath=../libdhcpcd" >>$CONFIG_MK
187 else
188         DEBUG=no
189 fi
190 if [ "$DEBUG" != no -a "$DEBUG" != false ]; then
191         echo "Adding debugging CFLAGS"
192         cat <<EOF >>$CONFIG_MK
193 CFLAGS+=        -Wall -Wextra -Wimplicit -Wshadow -Wformat=2
194 CFLAGS+=        -Wmissing-prototypes -Wmissing-declarations
195 CFLAGS+=        -Wmissing-noreturn -Wmissing-format-attribute
196 CFLAGS+=        -Wredundant-decls  -Wnested-externs
197 CFLAGS+=        -Winline -Wwrite-strings -Wcast-align -Wcast-qual
198 CFLAGS+=        -Wpointer-arith
199 CFLAGS+=        -Wdeclaration-after-statement -Wsequence-point
200 CFLAGS+=        -fno-common
201 EOF
202 fi
203
204 # Add CPPFLAGS and CFLAGS to CC for testing features
205 XCC="$CC `$SED -n -e 's/CPPLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
206 XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
207
208 if [ -z "$STRLCPY" ]; then
209         printf "Testing for strlcpy ... "
210         cat <<EOF >_strlcpy.c
211 #include <string.h>
212 int main(void) {
213         const char s1[] = "foo";
214         char s2[10];
215         strlcpy(s2, s1, sizeof(s2));
216         return 0;
217 }
218 EOF
219         if $XCC _strlcpy.c -o _strlcpy 2>/dev/null; then
220                 STRLCPY=yes
221         else
222                 STRLCPY=no
223         fi
224         echo "$STRLCPY"
225         rm -f _strlcpy.c _strlcpy
226 fi
227 if [ "$STRLCPY" = no ]; then
228         echo "#define strlcpy(dst, src, n) snprintf(dst, n, \"%s\", src)" \
229         >>$CONFIG_H
230 fi
231
232 if [ -z "$LIBDIR" ]; then
233         printf "lib directory name ... "
234         case `readlink /lib` in
235                 "") LIBNAME="lib";;
236                 *) LIBNAME=$(basename `readlink /lib`);;
237         esac
238         echo "$LIBNAME"
239         echo "LIBNAME=  $LIBNAME" >>$CONFIG_MK
240         LIBDIR=${PREFIX}/${LIBNAME}
241         echo "LIBDIR=           \${PREFIX}/\${LIBNAME}" >>$CONFIG_MK
242 else
243         echo "LIBDIR=   $LIBDIR" >>$CONFIG_MK
244 fi
245
246 # We normally want to build in the static library
247 if [ "$LIBDHCPCD" = yes ]; then
248         x="-ldhcpcd"
249         echo "LIB_DHCPCD_INSTALL=       _libinstall" >>$CONFIG_MK
250 else
251         x="-Wl,-Bstatic -ldhcpcd -Wl,-Bdynamic"
252 fi
253 echo "LIB_DHCPCD=       $x" >>$CONFIG_MK
254
255 # Due to our use of pkg-config, pass --as-needed to ld so we only link
256 # what we actually need.
257 echo "LDADD+=   -Wl,--as-needed" >>$CONFIG_MK
258
259 # Get DBus CFLAGS
260 DBUS_CFLAGS=$(pkg-config --cflags dbus-1) || exit 1
261 DBUS_LIBS=$(pkg-config --libs dbus-1) || exit 1
262 echo "DBus CFLAGS=$DBUS_CFLAGS"
263 echo "DBus LIBS=$DBUS_LIBS"
264 echo "DBUS_CFLAGS=      $DBUS_CFLAGS" >>$CONFIG_MK
265 echo "DBUS_LIBS=        $DBUS_LIBS" >>$CONFIG_MK
266
267 UI=
268 if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
269         PKG="dbus-1 gtk+-2.0"
270         if [ "$NOTIFY" = yes ]; then
271                 PKG="$PKG${PKG:+ }libnotify"
272                 echo "NOTIFY=           -DNOTIFY" >>$CONFIG_MK
273         fi
274         GTK_CFLAGS=$(pkg-config --cflags $PKG)
275         [ $? != 0 -a "$WITH_GTK" = yes ] && exit 1
276         GTK_LIBS=$(pkg-config --libs $PKG)
277         [ $? != 0 -a "$WITH_GTK" = yes ] && exit 1
278         echo "GTK+ CFLAGS=$GTK_CFLAGS"
279         echo "GTK+ LIBS=$GTK_LIBS"
280         echo "GTK_CFLAGS=       $GTK_CFLAGS" >>$CONFIG_MK
281         echo "GTK_LIBS= $GTK_LIBS" >>$CONFIG_MK
282         UI="$UI${UI:+ }dhcpcd-gtk"
283 fi
284
285 if [ -z "$UI" ]; then
286         echo "no UI is available, not building." >&2
287         exit 1
288 fi
289 echo "UI=               $UI" >>config.mk
290
291 echo
292 echo "   SYSCONFDIR =           $SYSCONFDIR"
293 echo "   BINDIR =               $BINDIR"
294 echo "   LIBDIR =               $LIBDIR"
295 echo "   ICONDIR =              $ICONDIR"
296 echo "   MANDIR =               $MANDIR"
297 echo "   UI =                   $UI"
298 echo
299
300 echo "MKDIR=            \${TOPDIR}/mk" >>$CONFIG_MK