2009-07-14 21:59:30 +08:00
|
|
|
#!/bin/sh
|
|
|
|
# Try and be like autotools configure, but without autotools
|
|
|
|
|
|
|
|
for x; do
|
|
|
|
opt=${x%%=*}
|
|
|
|
var=${x#*=}
|
|
|
|
case "$opt" in
|
2009-07-27 03:29:37 +08:00
|
|
|
--os|OS) OS=$var;;
|
2009-07-14 21:59:30 +08:00
|
|
|
--with-cc|CC) CC=$var;;
|
|
|
|
--debug) DEBUG=$var;;
|
|
|
|
--disable-debug) DEBUG=no;;
|
|
|
|
--enable-debug) DEBUG=yes;;
|
|
|
|
--fork) FORK=$var;;
|
|
|
|
--disable-fork) FORK=no;;
|
|
|
|
--enable-fork) FORK=yes;;
|
|
|
|
--prefix) PREFIX=$var;;
|
|
|
|
--sysconfdir) SYSCONFDIR=$var;;
|
2009-09-03 20:18:03 +08:00
|
|
|
--bindir|--sbindir) SBINDIR=$var;;
|
2009-07-14 21:59:30 +08:00
|
|
|
--libexecdir) LIBEXECDIR=$var;;
|
2009-07-27 01:26:18 +08:00
|
|
|
--statedir|--localstatedir) STATEDIR=$var;;
|
2009-07-14 21:59:30 +08:00
|
|
|
--dbdir) DBDIR=$var;;
|
|
|
|
--rundir) RUNDIR=$var;;
|
|
|
|
--mandir) MANDIR=$var;;
|
|
|
|
--with-ccopts|CFLAGS) CFLAGS=$var;;
|
|
|
|
CPPFLAGS) CPPFLAGS=$var;;
|
2009-07-27 03:37:46 +08:00
|
|
|
--with-hook) HOOKSCRIPTS="$HOOKSCRIPTS${HOOKSCRIPTS:+ }$var";;
|
2009-07-27 03:29:37 +08:00
|
|
|
--with-hooks|HOOKSCRIPTS) HOOKSCRIPTS=$var;;
|
|
|
|
--build) BUILD=$var;;
|
|
|
|
--host) HOST=$var;;
|
|
|
|
--target) TARGET=$var;;
|
|
|
|
--libdir) LIBDIR=$var;;
|
|
|
|
--datadir|--infodir) ;; # ignore autotools
|
2009-09-03 20:18:03 +08:00
|
|
|
--help) echo "See the README file for available options"; exit 0;;
|
2009-07-27 00:40:47 +08:00
|
|
|
*) echo "$0: WARNING: unknown option $opt" >&2;;
|
2009-07-14 21:59:30 +08:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2009-09-03 18:10:51 +08:00
|
|
|
: ${SED:=sed}
|
|
|
|
|
2009-07-14 21:59:30 +08:00
|
|
|
: ${FORK:=yes}
|
|
|
|
: ${PREFIX:=}
|
|
|
|
: ${SYSCONFDIR:=$PREFIX/etc}
|
|
|
|
: ${SBINDIR:=$PREFIX/sbin}
|
2009-07-27 03:29:37 +08:00
|
|
|
: ${LIBDIR:=$PREFIX/lib}
|
2009-07-14 21:59:30 +08:00
|
|
|
: ${LIBEXECDIR:=$PREFIX/libexec}
|
|
|
|
: ${STATEDIR:=/var}
|
|
|
|
: ${DBDIR:=$STATEDIR/db}
|
|
|
|
: ${RUNDIR:=$STATEDIR/run}
|
|
|
|
: ${MANDIR:=${PREFIX:-/usr}/share/man}
|
|
|
|
|
|
|
|
CONFIG_H=config.h
|
|
|
|
CONFIG_MK=config.mk
|
|
|
|
|
2009-07-27 03:29:37 +08:00
|
|
|
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
|
|
|
|
fi
|
2009-07-14 21:59:30 +08:00
|
|
|
|
2009-07-27 03:29:37 +08:00
|
|
|
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%%-*}
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Configuring dhcpcd for ... $OS"
|
|
|
|
rm -f $CONFIG_H $CONFIG_MK
|
|
|
|
echo "# $OS" >$CONFIG_MK
|
|
|
|
echo "/* $OS */" >$CONFIG_H
|
2009-07-14 21:59:30 +08:00
|
|
|
|
2009-07-15 17:36:43 +08:00
|
|
|
for x in SYSCONFDIR SBINDIR LIBEXECDIR DBDIR RUNDIR; do
|
|
|
|
# Make files look nice for import
|
|
|
|
l=$((10 - ${#x}))
|
2009-07-27 03:29:37 +08:00
|
|
|
if [ $l -gt 3 ]; then
|
2009-07-15 17:36:43 +08:00
|
|
|
t=" "
|
|
|
|
else
|
|
|
|
t=
|
|
|
|
fi
|
2009-07-14 21:59:30 +08:00
|
|
|
eval v=\$$x
|
2009-07-15 17:36:43 +08:00
|
|
|
echo "$x=$t $v" >>$CONFIG_MK
|
|
|
|
echo "#define $x$t \"$v\"" >>$CONFIG_H
|
2009-07-14 21:59:30 +08:00
|
|
|
done
|
2009-07-27 03:29:37 +08:00
|
|
|
echo "LIBDIR= $LIBDIR" >>$CONFIG_MK
|
2009-07-15 17:36:43 +08:00
|
|
|
echo "MANDIR= $MANDIR" >>$CONFIG_MK
|
2009-07-14 21:59:30 +08:00
|
|
|
|
2009-07-27 03:29:37 +08:00
|
|
|
if [ -z "$CC" ]; then
|
|
|
|
printf "Looking for compiler ... "
|
|
|
|
for b in $TARGET- ""; do
|
2009-08-06 04:36:31 +08:00
|
|
|
for cc in gcc pcc icc cc; do
|
2009-07-27 03:29:37 +08:00
|
|
|
if type $b$cc >/dev/null 2>&1; then
|
|
|
|
CC=$b$cc
|
|
|
|
echo "$CC"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
[ -n "$CC" ] && break
|
|
|
|
done
|
2009-07-27 03:37:46 +08:00
|
|
|
if [ -z "$CC" ]; then
|
|
|
|
echo
|
|
|
|
echo "no suitable compiler found - aborting" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2009-07-27 03:29:37 +08:00
|
|
|
else
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "Using compiler $CC"
|
|
|
|
fi
|
2009-07-27 03:29:37 +08:00
|
|
|
echo "CC= $CC" >>$CONFIG_MK
|
2009-07-14 21:59:30 +08:00
|
|
|
|
|
|
|
if [ -n "$CFLAGS" ]; then
|
|
|
|
echo "CFLAGS= $CFLAGS" >>$CONFIG_MK
|
|
|
|
fi
|
|
|
|
if [ -n "$CPPLAGS" ]; then
|
|
|
|
echo "CPPLAGS= $CPPLAGS" >>$CONFIG_MK
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DEBUG" != no -a "$DEBUG" != false ]; then
|
2009-07-15 05:01:59 +08:00
|
|
|
echo "Enabling memory debugging"
|
|
|
|
echo "CPPFLAGS+= -DDEBUG_MEMORY" >>$CONFIG_MK
|
2009-08-06 04:36:31 +08:00
|
|
|
elif [ -z "$DEBUG" -a -d .git ]; then
|
2009-07-15 05:01:59 +08:00
|
|
|
printf "Found git ... "
|
|
|
|
DEBUG=yes
|
2009-08-06 04:36:31 +08:00
|
|
|
else
|
|
|
|
DEBUG=no
|
2009-07-15 05:01:59 +08:00
|
|
|
fi
|
2009-08-06 04:36:31 +08:00
|
|
|
if [ "$DEBUG" != no -a "$DEBUG" != false ]; then
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "Adding debugging CFLAGS"
|
|
|
|
cat <<EOF >>$CONFIG_MK
|
|
|
|
CFLAGS+= -Wall -Wextra -Wimplicit -Wshadow -Wformat=2
|
|
|
|
CFLAGS+= -Wmissing-prototypes -Wmissing-declarations
|
|
|
|
CFLAGS+= -Wmissing-noreturn -Wmissing-format-attribute
|
|
|
|
CFLAGS+= -Wredundant-decls -Wnested-externs
|
|
|
|
CFLAGS+= -Winline -Wwrite-strings -Wcast-align -Wcast-qual
|
|
|
|
CFLAGS+= -Wpointer-arith
|
|
|
|
CFLAGS+= -Wdeclaration-after-statement -Wsequence-point
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$FORK" -a "$FORK" != yes -a "$FORK" != true ]; then
|
|
|
|
echo "There is no fork"
|
|
|
|
echo "CPPFLAGS+= -DTHERE_IS_NO_FORK" >>$CONFIG_MK
|
|
|
|
fi
|
|
|
|
|
2009-07-27 03:29:37 +08:00
|
|
|
case "$OS" in
|
|
|
|
linux)
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "CPPFLAGS+= -D_BSD_SOURCE -D_XOPEN_SOURCE=600" >>$CONFIG_MK
|
|
|
|
echo "SRCS+= if-linux.c if-linux-wireless.c lpf.c" >>$CONFIG_MK
|
|
|
|
echo "LDADD+= -lrt" >>$CONFIG_MK
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "SRCS+= bpf.c if-bsd.c" >>$CONFIG_MK
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-07-14 23:10:09 +08:00
|
|
|
# Even if we build for $PREFIX, the clueless user might move us to /
|
|
|
|
LDELF=/libexec/ld.elf_so
|
|
|
|
if [ -e "$LDELF" ]; then
|
|
|
|
echo "Linking against $LDELF"
|
2009-07-15 17:36:43 +08:00
|
|
|
echo "LDFLAGS+= -Wl,-dynamic-linker=$LDELF" >>$CONFIG_MK
|
2009-07-14 23:10:09 +08:00
|
|
|
fi
|
|
|
|
|
2009-09-03 18:10:51 +08:00
|
|
|
# Add CPPFLAGS and CFLAGS to CC for testing features
|
|
|
|
XCC="$CC `$SED -n -e 's/CPPLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
|
|
|
|
XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`"
|
|
|
|
|
2009-07-22 04:07:13 +08:00
|
|
|
abort=false
|
2009-07-18 19:31:56 +08:00
|
|
|
# We require the libc to support non standard functions, like getifaddrs
|
2009-07-27 05:56:43 +08:00
|
|
|
printf "Testing for getifaddrs ... "
|
2009-07-18 19:31:56 +08:00
|
|
|
cat <<EOF >_getifaddrs.c
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <ifaddrs.h>
|
|
|
|
int main(void) {
|
|
|
|
struct ifaddrs *ifap;
|
|
|
|
return getifaddrs(&ifap);
|
|
|
|
}
|
|
|
|
EOF
|
2009-09-03 18:10:51 +08:00
|
|
|
if $XCC _getifaddrs.c -o _getifaddrs 2>/dev/null; then
|
2009-07-18 19:31:56 +08:00
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no"
|
|
|
|
echo "libc support for getifaddrs is required - aborting" >&2
|
2009-07-22 04:07:13 +08:00
|
|
|
abort=true
|
2009-07-18 19:31:56 +08:00
|
|
|
fi
|
2009-07-22 04:07:13 +08:00
|
|
|
rm -f _getifaddrs.c _getifaddrs
|
|
|
|
$abort && exit 1
|
2009-07-18 19:31:56 +08:00
|
|
|
|
2009-07-27 05:56:43 +08:00
|
|
|
printf "Testing for arc4random ... "
|
2009-07-14 21:59:30 +08:00
|
|
|
cat <<EOF >_arc4random.c
|
|
|
|
#include <stdlib.h>
|
|
|
|
int main(void) {
|
2009-07-14 23:10:09 +08:00
|
|
|
uint32_t r = arc4random();
|
2009-07-14 21:59:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
2009-09-03 18:10:51 +08:00
|
|
|
if $XCC _arc4random.c -o _arc4random 2>/dev/null; then
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no"
|
|
|
|
echo "SRCS+= compat/arc4random.c" >>$CONFIG_MK
|
|
|
|
echo "#include \"compat/arc4random.h\"" >>$CONFIG_H
|
|
|
|
fi
|
|
|
|
rm -f _arc4random.c _arc4random
|
|
|
|
|
2009-07-27 05:56:43 +08:00
|
|
|
printf "Testing for closefrom ... "
|
2009-07-14 21:59:30 +08:00
|
|
|
cat <<EOF >_closefrom.c
|
|
|
|
#include <unistd.h>
|
|
|
|
int main(void) {
|
2009-07-14 23:10:09 +08:00
|
|
|
int r = closefrom(3);
|
2009-07-14 21:59:30 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
2009-09-03 18:10:51 +08:00
|
|
|
if $XCC _closefrom.c -o _closefrom 2>/dev/null; then
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no"
|
|
|
|
echo "SRCS+= compat/closefrom.c" >>$CONFIG_MK
|
|
|
|
echo "#include \"compat/closefrom.h\"" >>$CONFIG_H
|
|
|
|
fi
|
|
|
|
rm -f _closefrom.c _closefrom
|
|
|
|
|
2009-07-27 05:56:43 +08:00
|
|
|
printf "Testing for getline ... "
|
2009-07-14 21:59:30 +08:00
|
|
|
cat <<EOF >_getline.c
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <stdio.h>
|
|
|
|
int main(void) {
|
|
|
|
char *buf = NULL;
|
|
|
|
size_t n = 0;
|
|
|
|
getline(&buf, &n, stdin);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
2009-09-03 18:10:51 +08:00
|
|
|
if $XCC _getline.c -o _getline 2>/dev/null; then
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no"
|
|
|
|
echo "SRCS+= compat/getline.c" >>$CONFIG_MK
|
|
|
|
echo "#include \"compat/getline.h\"" >>$CONFIG_H
|
|
|
|
fi
|
|
|
|
rm -f _getline.c _getline
|
|
|
|
|
2009-07-27 05:56:43 +08:00
|
|
|
printf "Testing for strlcpy ... "
|
2009-07-14 21:59:30 +08:00
|
|
|
cat <<EOF >_strlcpy.c
|
|
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
|
|
const char s1[] = "foo";
|
|
|
|
char s2[10];
|
|
|
|
strlcpy(s2, s1, sizeof(s2));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EOF
|
2009-09-03 18:10:51 +08:00
|
|
|
if $XCC _strlcpy.c -o _strlcpy 2>/dev/null; then
|
2009-07-14 21:59:30 +08:00
|
|
|
echo "yes"
|
|
|
|
else
|
|
|
|
echo "no"
|
|
|
|
echo "SRCS+= compat/strlcpy.c" >>$CONFIG_MK
|
|
|
|
echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H
|
|
|
|
fi
|
|
|
|
rm -f _strlcpy.c _strlcpy
|
2009-07-15 05:01:59 +08:00
|
|
|
|
|
|
|
cd dhcpcd-hooks
|
|
|
|
HOOKS=
|
|
|
|
for x in $HOOKSCRIPTS; do
|
|
|
|
printf "Finding hook $x ... "
|
|
|
|
for h in [0-9][0-9]"-$x" [0-9][0-9]"-$x.sh" [0-9][0-9]"-$x.conf"; do
|
|
|
|
[ -e "$h" ] && break
|
|
|
|
done
|
|
|
|
if [ ! -e "$h" ]; then
|
|
|
|
echo "no"
|
|
|
|
else
|
|
|
|
echo "$h"
|
|
|
|
HOOKS="$HOOKS${HOOKS:+ }$h"
|
|
|
|
fi
|
|
|
|
done
|
2009-07-22 04:51:00 +08:00
|
|
|
cd ..
|
2009-07-15 05:01:59 +08:00
|
|
|
echo "HOOKSCRIPTS= $HOOKS" >>$CONFIG_MK
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo " SYSCONFDIR = $SYSCONFDIR"
|
|
|
|
echo " SBINDIR = $SBINDIR"
|
2009-07-27 03:29:37 +08:00
|
|
|
echo " LIBDIR = $LIBDIR"
|
2009-07-15 05:01:59 +08:00
|
|
|
echo " LIBEXECDIR = $LIBEXECDIR"
|
|
|
|
echo " DBDIR = $DBDIR"
|
|
|
|
echo " RUNDIR = $RUNDIR"
|
|
|
|
echo " MANDIR = $MANDIR"
|
|
|
|
echo " HOOKSCRIPTS = $HOOKSCRIPTS"
|
|
|
|
echo
|