diff options
| author | Roy Marples <roy@marples.name> | 2019-10-07 12:04:37 +0100 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2019-10-07 12:04:37 +0100 |
| commit | 23fc13917666ba579c8242d05d2febda825d41a5 (patch) | |
| tree | 76342107c12122b279bdef527b68b6ce76aa573e | |
| parent | bfc5f6daa209807385ce73dd58446e6c31a84c23 (diff) | |
| download | parpd-23fc13917666ba579c8242d05d2febda825d41a5.tar.xz | |
build: Use configure rather than mk stubs
Makes things easier, taken from dhcpcd.
| -rw-r--r-- | Makefile | 106 | ||||
| -rw-r--r-- | Makefile.inc | 22 | ||||
| -rw-r--r-- | compat/queue.h (renamed from queue.h) | 0 | ||||
| -rw-r--r-- | config-null.mk | 3 | ||||
| -rwxr-xr-x | configure | 637 | ||||
| -rw-r--r-- | iconfig.mk | 8 | ||||
| -rw-r--r-- | mk/cc.mk | 24 | ||||
| -rw-r--r-- | mk/depend.mk | 12 | ||||
| -rw-r--r-- | mk/dist.mk | 65 | ||||
| -rw-r--r-- | mk/man.mk | 19 | ||||
| -rw-r--r-- | mk/os-BSD.mk | 4 | ||||
| -rw-r--r-- | mk/os-Linux.mk | 4 | ||||
| -rw-r--r-- | mk/os.mk | 5 | ||||
| -rw-r--r-- | mk/prog.mk | 35 | ||||
| -rw-r--r-- | mk/sys.mk | 13 | ||||
| -rw-r--r-- | src/GNUmakefile | 12 | ||||
| -rw-r--r-- | src/Makefile | 39 | ||||
| -rw-r--r-- | src/bpf-filter.h (renamed from bpf-filter.h) | 0 | ||||
| -rw-r--r-- | src/bpf.c (renamed from bpf.c) | 0 | ||||
| -rw-r--r-- | src/eloop.c (renamed from eloop.c) | 0 | ||||
| -rw-r--r-- | src/eloop.h (renamed from eloop.h) | 0 | ||||
| -rw-r--r-- | src/lpf.c (renamed from lpf.c) | 0 | ||||
| -rw-r--r-- | src/parpd.8.in (renamed from parpd.8.in) | 0 | ||||
| -rw-r--r-- | src/parpd.c (renamed from parpd.c) | 0 | ||||
| -rw-r--r-- | src/parpd.conf.5 (renamed from parpd.conf.5) | 0 | ||||
| -rw-r--r-- | src/parpd.h (renamed from parpd.h) | 15 |
26 files changed, 814 insertions, 209 deletions
@@ -1,21 +1,95 @@ -# Makefile based on BSD make. -# Our mk stubs also work with GNU make. -# Copyright (c) 2008 Roy Marples <roy@marples.name> +SUBDIRS= src -PROG= parpd -SRCS= parpd.c eloop.c ${SRC_PF} +VERSION!= sed -n 's/\#define VERSION[[:space:]]*"\(.*\)".*/\1/p' src/parpd.h -BINDIR= ${PREFIX}/sbin +DIST!= if test -d .git; then echo "dist-git"; \ + else echo "dist-inst"; fi +GITREF?= HEAD -MAN= parpd.conf.5 parpd.8 -CLEANFILES= parpd.8 +DISTSUFFIX= +DISTPREFIX?= parpd-${VERSION}${DISTSUFFIX} +DISTFILEGZ?= ${DISTPREFIX}.tar.gz +DISTFILE?= ${DISTPREFIX}.tar.xz +DISTINFO= ${DISTFILE}.distinfo +DISTINFOSIGN= ${DISTINFO}.asc -CPPFLAGS+= -DSYSCONFDIR=\"${SYSCONFDIR}\" -.SUFFIXES: .in -.in: - ${SED} -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' $< >$@ +CLEANFILES+= *.tar.xz -MK= mk -include ${MK}/sys.mk -include ${MK}/os.mk -include ${MK}/prog.mk +all: config.h + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +depend: config.h + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +eginstall: + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +install: + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +proginstall: + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +clean: + rm -rf cov-int parpd.xz + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +distclean: clean + rm -f config.h config.mk config.log \ + ${DISTFILE} ${DISTFILEGZ} ${DISTINFO} ${DISTINFOSIGN} + rm -f *.diff *.patch *.orig *.rej + for x in ${SUBDIRS}; do cd $$x; ${MAKE} $@ || exit $$?; cd ..; done + +dist-git: + git archive --prefix=${DISTPREFIX}/ ${GITREF} | xz >${DISTFILE} + +dist-inst: + mkdir /tmp/${DISTPREFIX} + cp -RPp * /tmp/${DISTPREFIX} + (cd /tmp/${DISTPREFIX}; make clean) + tar -cvjpf ${DISTFILE} -C /tmp ${DISTPREFIX} + rm -rf /tmp/${DISTPREFIX} + +dist: ${DIST} + +distinfo: dist + rm -f ${DISTINFO} ${DISTINFOSIGN} + ${CKSUM} ${DISTFILE} >${DISTINFO} + #printf "SIZE (${DISTFILE}) = %s\n" $$(wc -c <${DISTFILE}) >>${DISTINFO} + ${PGP} --clearsign --output=${DISTINFOSIGN} ${DISTINFO} + chmod 644 ${DISTINFOSIGN} + ls -l ${DISTFILE} ${DISTINFO} ${DISTINFOSIGN} + +snapshot: + rm -rf /tmp/${DISTPREFIX} + ${INSTALL} -d /tmp/${DISTPREFIX} + cp -RPp * /tmp/${DISTPREFIX} + ${MAKE} -C /tmp/${DISTPREFIX} distclean + tar cf - -C /tmp ${DISTPREFIX} | xz >${DISTFILE} + ls -l ${DISTFILE} + +_import: dist + rm -rf ${DESTDIR}/* + ${INSTALL} -d ${DESTDIR} + tar xvpf ${DISTFILE} -C ${DESTDIR} --strip 1 + @${ECHO} + @${ECHO} "=============================================================" + @${ECHO} "parpd-${VERSION} imported to ${DESTDIR}" + +import: + ${MAKE} _import DESTDIR=`if [ -n "${DESTDIR}" ]; then echo "${DESTDIR}"; else echo /tmp/${DISTPREFIX}; fi` + + +_import-src: + rm -rf ${DESTDIR}/* + ${INSTALL} -d ${DESTDIR} + cp LICENSE README.md ${DESTDIR}; + for x in ${SUBDIRS}; do cd $$x; ${MAKE} DESTDIR=${DESTDIR} $@ || exit $$?; cd ..; done + @${ECHO} + @${ECHO} "=============================================================" + @${ECHO} "parpd-${VERSION} imported to ${DESTDIR}" + +import-src: + ${MAKE} _import-src DESTDIR=`if [ -n "${DESTDIR}" ]; then echo "${DESTDIR}"; else echo /tmp/${DISTPREFIX}; fi` + +include Makefile.inc diff --git a/Makefile.inc b/Makefile.inc new file mode 100644 index 0000000..0e76bdf --- /dev/null +++ b/Makefile.inc @@ -0,0 +1,22 @@ +# System definitions + +PICFLAG?= -fPIC + +BINMODE?= 0555 +NONBINMODE?= 0444 +MANMODE?= ${NONBINMODE} +CONFMODE?= 0644 + +CC?= cc +ECHO?= echo +INSTALL?= install +LINT?= lint +SED?= sed +HOST_SH?= /bin/sh + +# This isn't very portable, but I generaly make releases from NetBSD +CKSUM?= cksum -a SHA256 +PGP?= netpgp + +SED_RUNDIR= -e 's:@RUNDIR@:${RUNDIR}:g' +SED_SYS= -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' diff --git a/config-null.mk b/config-null.mk new file mode 100644 index 0000000..c7a8de3 --- /dev/null +++ b/config-null.mk @@ -0,0 +1,3 @@ +# This space left intentionally blank + +DHCPCD_SRCS+= dhcpcd-embedded.c diff --git a/configure b/configure new file mode 100755 index 0000000..9f11edf --- /dev/null +++ b/configure @@ -0,0 +1,637 @@ +#!/bin/sh +# Try and be like autotools configure, but without autotools + +echo "configure args: $*" +exec 3>config.log + +# Ensure that we do not inherit these from env +RBTREE= +OS= +BUILD= +HOST= +HOSTCC= +TARGET= +PREFIX=/usr +INCLUDEDIR= +DEBUG= +POLL= + +for x do + opt=${x%%=*} + var=${x#*=} + case "$opt" in + --os|OS) OS=$var;; + --debug) DEBUG=$var;; + --disable-debug) DEBUG=no;; + --enable-debug) DEBUG=yes;; + --prefix) PREFIX=$var;; + --sysconfdir) SYSCONFDIR=$var;; + --bindir|--sbindir) SBINDIR=$var;; + --libexecdir) LIBEXECDIR=$var;; + --statedir|--localstatedir) STATEDIR=$var;; + --dbdir) DBDIR=$var;; + --rundir|--runstatedir) RUNDIR=$var;; + --mandir) MANDIR=$var;; + --datadir) DATADIR=$var;; + --with-ccopts|CFLAGS) CFLAGS=$var;; + -I|--includedir) INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }-I$var";; + CC) CC=$var;; + CPPFLAGS) CPPFLAGS=$var;; + PKG_CONFIG) PKG_CONFIG=$var;; + --with-hook) HOOKSCRIPTS="$HOOKSCRIPTS${HOOKSCRIPTS:+ }$var";; + --with-hooks|HOOKSCRIPTS) HOOKSCRIPTS=$var; HOOKSET=true;; + --build) BUILD=$var;; + --host) HOST=$var; HOSTCC=$var-;; + --target) TARGET=$var;; + --libdir) LIBDIR=$var;; + --with-poll) POLL="$var";; + --infodir) ;; # ignore autotools + --disable-maintainer-mode|--disable-dependency-tracking) ;; + --disable-silent-rules) ;; + -V|--version) + v=$(sed -ne 's/.*VERSION[[:space:]]*"\([^"]*\).*/\1/p' defs.h); + c=$(sed -ne 's/^.*copyright\[\] = "\([^"]*\).*/\1/p' dhcpcd.c); + echo "dhcpcd-$v $c"; + exit 0;; + -h|--help) cat <<EOF +\`configure' configures this package to adapt to many kinds of systems. + +Usage: configure [OPTION]... [VAR=VALUE]... + +To assign environment variables (e.g., CC, CFLAGS...), specify them as +VAR=VALUE. See below for descriptions of some of the useful variables. + +Defaults for the options are specified in brackets. + +Configuration: + -h, --help display this help and exit + --help=short display options specific to this package + -V, --version display version information and exit + +Installation directories: + --prefix=PREFIX install architecture-independent files in PREFIX [/] + +By default, \`make install' will install all the files in \'/sbin', +\`/libexec', etc. You can specify +an installation prefix other than \`/' using \`--prefix', +for instance \`--prefix=$HOME'. + +For better control, use the options below. + +Fine tuning of the installation directories: + --bindir=DIR user executables [PREFIX/bin] + --sbindir=DIR system admin executables [PREFIX/sbin] + --libexecdir=DIR program executables [PREFIX/libexec] + --sysconfdir=DIR read-only single-machine data [PREFIX/etc] + --localstatedir=DIR modifiable single-machine data [/var] + --libdir=DIR object code libraries [PREFIX/lib] + --includedir=DIR C header files [PREFIX/include] + --mandir=DIR man documentation [PREFIX/man] + +System types: + --build=BUILD configure for building on BUILD [guessed] + --host=HOST build programs to run on HOST [BUILD] + --target=TARGET configure for building compilers for TARGET [HOST] + +Optional Features: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + +Some influential environment variables: + CC C compiler command + CFLAGS C compiler flags + LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a + nonstandard directory <lib dir> + CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have + headers in a nonstandard directory <include dir> + CPP C preprocessor + PKG_CONFIG pkg-config executable + +Use these variables to override the choices made by \`configure' or to help +it to find libraries and programs with nonstandard names/locations. +EOF +exit 0 +;; + *) echo "$0: WARNING: unknown option $opt" >&2;; + esac +done + +: ${SED:=sed} +: ${GREP:=grep} +: ${PKG_CONFIG:=pkg-config} +: ${WC:=wc} + +_which() +{ + x="$(which "$1" 2>/dev/null)" + if [ $? = 0 -a -n "$x" ]; then + echo "$x" + return 0 + fi + for x in /sbin/"$1" /usr/sbin/"$1" \ + /usr/pkg/sbin/"$1" /usr/local/sbin/"$1" + do + if [ -e "$x" ]; then + echo "$x" + return 0 + fi + done + return 1 +} + +CONFIG_H=config.h +CONFIG_MK=config.mk + +if [ -z "$BUILD" ]; then + # autoconf target triplet: cpu-vendor-os + BUILD=$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]') +fi +: ${HOST:=$BUILD} + +if [ -z "$OS" ]; then + 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 + case "$REST" in + gnu/kfreebsd*) OS="kfreebsd"; VENDOR= ;; + esac + # Special case + case "$OS" in + dragonfly*) + # This means /usr HAS to be mounted not via dhcpcd + : ${LIBEXECDIR:=${PREFIX:-/usr}/libexec} + ;; + gnu*) OS=hurd;; # No HURD support as yet + esac +fi + +echo "Configuring parpd for ... $OS" +rm -f $CONFIG_H $CONFIG_MK +echo "# $OS" >$CONFIG_MK +echo "/* $OS */" >$CONFIG_H + +if [ "$PREFIX" = /usr ]; then + : ${SYSCONFDIR:=/etc} +else + : ${SYSCONFDIR:=$PREFIX/etc} +fi +: ${SBINDIR:=$PREFIX/sbin} +: ${STATEDIR:=/var} +: ${RUNDIR:=$STATEDIR/run} +: ${MANDIR:=${PREFIX:-/usr}/share/man} + +eval SYSCONFDIR="$SYSCONFDIR" +eval SBINDIR="$SBINDIR" +eval RUNDIR="$RUNDIR" +eval MANDIR="$MANDIR" + +echo "#ifndef SYSCONFDIR" >>$CONFIG_H +for x in SYSCONFDIR SBINDIR RUNDIR; do + eval v=\$$x + # Make files look nice for import + l=$((10 - ${#x})) + unset t + [ $l -gt 3 ] && t=" " + echo "$x=$t $v" >>$CONFIG_MK + unset t + [ $l -gt 2 ] && t=" " + echo "#define $x$t \"$v\"" >>$CONFIG_H +done +echo "#endif" >>$CONFIG_H + +echo "MANDIR= $MANDIR" >>$CONFIG_MK + +# Always obey CC. +if [ -n "$CC" ]; then + HOSTCC= +else + CC=cc + _COMPILERS="cc clang gcc pcc icc" +fi +# Only look for a cross compiler if --host and --build are not the same +if [ -n "$HOSTCC" -a "$BUILD" != "$HOST" ]; 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 + +# 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 "$INCLUDEDIR" ]; then + echo "CPPFLAGS+= $INCLUDEDIR" >>$CONFIG_MK +fi +if [ -n "$LDFLAGS" ]; then + echo "LDFLAGS=" >>$CONFIG_MK + echo "LDFLAGS+= $LDFLAGS" >>$CONFIG_MK +fi + +echo "CPPFLAGS+= -DHAVE_CONFIG_H" >>$CONFIG_MK + +if [ "$STATIC" = yes ]; then + echo "LDFLAGS+= -static" >>$CONFIG_MK +fi + +if [ -z "$DEBUG" -a -d .git ]; then + printf "Found git checkout ... " + DEBUG=yes +fi +if [ -n "$DEBUG" -a "$DEBUG" != no -a "$DEBUG" != false ]; then + echo "Adding debugging CFLAGS" + cat <<EOF >>$CONFIG_MK +CFLAGS+= -g -Wall -Wextra +CFLAGS+= -Wmissing-prototypes -Wmissing-declarations +CFLAGS+= -Wmissing-format-attribute -Wnested-externs +CFLAGS+= -Winline -Wcast-align -Wcast-qual -Wpointer-arith +CFLAGS+= -Wreturn-type -Wswitch -Wshadow +CFLAGS+= -Wcast-qual -Wwrite-strings +CFLAGS+= -Wformat=2 +CFLAGS+= -Wpointer-sign -Wmissing-noreturn +EOF + case "$OS" in + mirbsd*|openbsd*);; # OpenBSD has many redundant decs in system headers + bitrig*|solaris*|sunos*) + echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK + ;; # Bitrig spouts many conversion errors with htons + # sunos has many as well + *) echo "CFLAGS+= -Wredundant-decls" >>$CONFIG_MK + echo "CFLAGS+= -Wconversion" >>$CONFIG_MK + ;; + esac + + case "$OS" in + solaris*|sunos*);; + *) echo "CFLAGS+= -Wstrict-overflow" >>$CONFIG_MK;; + esac + + # Turn on extra per compiler debugging + case "$CC" in + *gcc*) echo "CFLAGS+= -Wlogical-op" >>$CONFIG_MK;; + esac +else + echo "CPPFLAGS+= -DNDEBUG" >>$CONFIG_MK +fi + +case "$OS" in +linux*) + echo "SRC_PF= lpf.c" >>$CONFIG_MK + ;; +*) + echo "SRC_PF= bpf.c" >>$CONFIG_MK + ;; +esac + +echo "Using compiler .. $CC" +# Add CPPFLAGS and CFLAGS to CC for testing features +XCC="$CC `$SED -n -e 's/CPPFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`" +XCC="$XCC `$SED -n -e 's/CFLAGS+=*\(.*\)/\1/p' $CONFIG_MK`" + +# When running tests, treat all warnings as errors. +# This avoids the situation where we link to a libc symbol +# without the correct header because it might be hidden behind +# a _*_SOURCE #define guard. +XCC="$XCC -Wall -Werror" + +# Now test we can use the compiler with our CFLAGS +cat <<EOF >_test.c +int main(void) { + return 0; +} +EOF +_CC=false +if $XCC _test.c -o _test >/dev/null 2>&3; then + [ -x _test ] && _CC=true +fi +rm -f _test.c _test +if ! $_CC; then + echo "$CC does not create executables" >&2 + exit 1 +fi +[ "$CC" != cc ] && echo "CC= $CC" >>$CONFIG_MK +$CC --version | $SED -e '1!d' + +abort=false +# We require the libc to support non standard functions, like getifaddrs +printf "Testing for getifaddrs ... " +cat <<EOF >_getifaddrs.c +#include <sys/types.h> +#include <ifaddrs.h> +int main(void) { + struct ifaddrs *ifap; + return getifaddrs(&ifap); +} +EOF +LIBSOCKET= +if $XCC _getifaddrs.c -o _getifaddrs 2>&3; then + echo "yes" +elif $XCC _getifaddrs.c -o _getifaddrs -lsocket 2>&3; then + LIBSOCKET=-lsocket + echo "yes (-lsocket)" + echo "LDADD+= -lsocket" >>$CONFIG_MK +else + echo "no" + echo "libc support for getifaddrs is required - aborting" >&2 + abort=true +fi +rm -f _getifaddrs.c _getifaddrs +$abort && exit 1 + +printf "Testing for clock_gettime ... " +cat <<EOF >_clock_gettime.c +#include <time.h> +int main(void) { + struct timespec ts; + return clock_gettime(CLOCK_MONOTONIC, &ts); +} +EOF +if $XCC _clock_gettime.c -o _clock_gettime 2>&3; then + echo "yes" +elif $XCC _clock_gettime.c -lrt -o _clock_gettime 2>&3; then + echo "yes (-lrt)" + echo "LDADD+= -lrt" >>$CONFIG_MK +else + echo "no" + echo "libc support for clock_getttime is required - aborting" >&2 + abort=true +fi +rm -f _clock_gettime.c _clock_gettime +$abort && exit 1 + +printf "Testing for inet_ntoa ... " +cat <<EOF >_inet_ntoa.c +#include <netinet/in.h> +#include <arpa/inet.h> +int main(void) { + struct in_addr in = { .s_addr = 0 }; + inet_ntoa(in); + return 0; +} +EOF +if $XCC _inet_ntoa.c -o _inet_ntoa 2>&3; then + echo "yes" +elif $XCC _inet_ntoa.c -lnsl -o _inet_ntoa 2>&3; then + echo "yes (-lnsl)" + echo "LDADD+= -lnsl" >>$CONFIG_MK +elif $XCC _inet_ntoa.c -lsocket -o _inet_ntoa 2>&3; then + echo "yes (-lsocket)" + echo "LDADD+= -lsocket" >>$CONFIG_MK +else + echo "no" + echo "libc support for inet_ntoa is required - aborting" >&2 + abort=true +fi +rm -f _inet_ntoa.c _inet_ntoa +$abort && exit 1 + +if [ -z "$STRLCPY" ]; then + printf "Testing for strlcpy ... " + 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 + if $XCC _strlcpy.c -o _strlcpy 2>&3; then + STRLCPY=yes + else + STRLCPY=no + fi + echo "$STRLCPY" + rm -f _strlcpy.c _strlcpy +fi +if [ "$STRLCPY" = no ]; then + echo "COMPAT_SRCS+= compat/strlcpy.c" >>$CONFIG_MK + echo "#include \"compat/strlcpy.h\"" >>$CONFIG_H +fi + +if [ -z "$STRTOI" ]; then + printf "Testing for strtoi ... " + cat <<EOF >_strtoi.c +#include <stdlib.h> +#include <limits.h> +#include <inttypes.h> +int main(void) { + int e; + strtoi("1234", NULL, 0, 0, INT32_MAX, &e); + return 0; +} +EOF + if $XCC _strtoi.c -o _strtoi 2>&3; then + STRTOI=yes + else + STRTOI=no + fi + echo "$STRTOI" + rm -f _strtoi.c _strtoi +fi +if [ "$STRTOI" = no ]; then + echo "COMPAT_SRCS+= compat/strtoi.c compat/strtou.c" >>$CONFIG_MK + echo "#include \"compat/strtoi.h\"" >>$CONFIG_H +fi + +if [ -z "$TAILQ_FOREACH" ]; then + printf "Testing for TAILQ_FOREACH ... " + cat <<EOF >_queue.c +#include <sys/queue.h> +int main(void) { +#ifndef TAILQ_FOREACH +#error TAILQ_FOREACH +#endif + return 0; +} +EOF + if $XCC _queue.c -o _queue 2>&3; then + TAILQ_FOREACH=yes + else + TAILQ_FOREACH=no + fi + echo "$TAILQ_FOREACH" + rm -f _queue.c _queue +fi +if [ "$TAILQ_FOREACH" = no ]; then + echo "#include \"compat/queue.h\"">>$CONFIG_H +else + echo "#define HAVE_SYS_QUEUE_H" >>$CONFIG_H +fi + +if [ -z "$RBTREE" ]; then + printf "Testing for rb_tree_init ... " + cat <<EOF >_rbtree.c +#include <sys/rbtree.h> +static rb_tree_ops_t ops; +int main(void) { + rb_tree_t tree; + rb_tree_init(&tree, &ops); + return 0; +} +EOF + if $XCC _rbtree.c -o _rbtree 2>&3; then + RBTREE=yes + else + RBTREE=no + fi + echo "$RBTREE" + rm -f _rbtree.c _rbtree +fi +if [ "$RBTREE" = no ]; then + echo "#define RBTEST" >>$CONFIG_H + echo "COMPAT_SRCS+= compat/rb.c" >>$CONFIG_MK + echo "#include \"compat/rbtree.h\"" >>$CONFIG_H +else + echo "#define HAVE_SYS_RBTREE_H" >>$CONFIG_H +fi + +if [ -z "$POLL" ]; then + printf "Testing for kqueue1 ... " + cat <<EOF >_kqueue.c +#include <sys/types.h> +#include <sys/event.h> +int main(void) { + return kqueue1(0); +} +EOF + if $XCC _kqueue.c -o _kqueue 2>&3; then + POLL=kqueue1 + echo "yes" + else + echo "no" + fi + rm -f _kqueue.c _kqueue +fi +if [ -z "$POLL" ]; then + printf "Testing for kqueue ... " + cat <<EOF >_kqueue.c +#include <sys/types.h> +#include <sys/event.h> +int main(void) { + return kqueue(); +} +EOF + if $XCC _kqueue.c -o _kqueue 2>&3; then + POLL=kqueue + echo "yes" + else + echo "no" + fi + rm -f _kqueue.c _kqueue +fi +if [ -z "$POLL" ]; then + printf "Testing for epoll ... " + cat <<EOF >_epoll.c +#ifdef __linux__ +#include <linux/version.h> +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37) +#error kernel has buggy epoll_wait timeout +#endif +#endif + +#include <sys/epoll.h> +#include <unistd.h> +int main(void) { + epoll_create1(EPOLL_CLOEXEC); + epoll_pwait(-1, NULL, 0, 0, NULL); + return 0; +} +EOF + if $XCC _epoll.c -o _epoll 2>&3; then + POLL=epoll + echo "#define HAVE_EPOLL" >>$CONFIG_MK + echo "yes" + else + echo "no" + fi + rm -f _epoll.c _epoll +fi +if [ -z "$POLL" ]; then + printf "Testing for pselect ... " + cat <<EOF >_pselect.c +#include <sys/select.h> +#include <stdlib.h> +int main(void) { + pselect(0, NULL, NULL, NULL, NULL, NULL); + return 0; +} +EOF + if $XCC _pselect.c -o _pselect 2>&3; then + POLL=pselect + echo "yes" + else + echo "no" + fi + rm -f _pselect.c _pselect +fi +case "$POLL" in +kqueue1) + echo "#define HAVE_KQUEUE" >>$CONFIG_H + echo "#define HAVE_KQUEUE1" >>$CONFIG_H + ;; +kqueue) + echo "#define HAVE_KQUEUE" >>$CONFIG_H + ;; +epoll) + echo "#define HAVE_EPOLL" >>$CONFIG_H + ;; +pollts) + echo "#define HAVE_POLLTS" >>$CONFIG_H + ;; +ppoll) + echo "#define HAVE_PPOLL" >>$CONFIG_H + ;; +pselect) + echo "#define HAVE_PSELECT" >>$CONFIG_H + ;; +*) + echo "No suitable polling function is available, not even pselect" >&2 + exit 1 + ;; +esac + +echo +echo " SYSCONFDIR = $SYSCONFDIR" +echo " SBINDIR = $SBINDIR" +echo " RUNDIR = $RUNDIR" +echo " MANDIR = $MANDIR" +echo + +rm -f parpd diff --git a/iconfig.mk b/iconfig.mk new file mode 100644 index 0000000..50c5034 --- /dev/null +++ b/iconfig.mk @@ -0,0 +1,8 @@ +# Nasty hack so that make clean works without configure being run +TOP?= . +_CONFIG_MK!= test -e ${TOP}/config.mk && \ + echo config.mk || echo config-null.mk +_CONFIG_MK?= $(shell test -e ${TOP}/config.mk && \ + echo config.mk || echo config-null.mk) +CONFIG_MK?= ${_CONFIG_MK} +include ${TOP}/${CONFIG_MK} diff --git a/mk/cc.mk b/mk/cc.mk deleted file mode 100644 index cdac1b7..0000000 --- a/mk/cc.mk +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2008 Roy Marples <roy@marples.name> - -# Setup some good default CFLAGS -CFLAGS?= -O2 - -# Try and use some good cc flags if we're building from git -# We don't use -pedantic as it will warn about our perfectly valid -# use of %m in our logger. -_CCFLAGS= -g -Wall -Wextra -_CCFLAGS+= -Wmissing-prototypes -Wmissing-declarations -_CCFLAGS+= -Wmissing-format-attribute -Wnested-externs -_CCFLAGS+= -Winline -Wcast-align -Wcast-qual -Wpointer-arith -_CCFLAGS+= -Wreturn-type -Wswitch -Wshadow -_CCCFLAGS+= -Wcast-qual -Wwrite-strings -_CCFLAGS+= -Wformat=2 -_CCFLAGS+= -Wpointer-sign -Wmissing-noreturn - -_CC_FLAGS!= if ! test -f .fslckout && ! test -d .git && ! test -d .svn; \ - then echo ""; else for f in ${_CCFLAGS}; do \ - if echo "int main(void) { return 0;} " | \ - ${CC} $$f -S -xc -o /dev/null - ; \ - then printf "%s" "$$f "; fi \ - done; fi -CFLAGS+= ${_CC_FLAGS} diff --git a/mk/depend.mk b/mk/depend.mk deleted file mode 100644 index 849d12e..0000000 --- a/mk/depend.mk +++ /dev/null @@ -1,12 +0,0 @@ -# This only works for make implementations that always include a .depend if -# it exists. Only GNU make does not do this. - -# Copyright 2008 Roy Marples <roy@marples.name> - -CLEANFILES+= .depend - -.depend: ${SRCS} - rm -f .depend - ${CC} ${CFLAGS} -MM ${SRCS} > .depend - -depend: .depend diff --git a/mk/dist.mk b/mk/dist.mk deleted file mode 100644 index a3bbe45..0000000 --- a/mk/dist.mk +++ /dev/null @@ -1,65 +0,0 @@ -# rules to make a distribution tarball -# Copyright 2008 Roy Marples <roy@marples.name> - -VERSION!= sed -n 's/\#define VERSION[[:space:]]*"\(.*\)".*/\1/p' parpd.h - -PACKAGE?= ${PROG} -PKG?= ${PACKAGE}-${VERSION} - -FOSSILID?= current -GITREF?= HEAD -DISTPREFIX?= ${PKG} -DISTFILEGZ?= ${DISTPREFIX}.tar.gz -DISTFILE?= ${DISTPREFIX}.tar.xz -DISTINFO= ${DISTFILE}.distinfo -DISTINFOSIGN= ${DISTINFO}.asc -CKSUM?= cksum -a SHA256 -PGP?= netpgp - -CLEANFILES+= *.tar.bz2 - -SNAP!= date -u +%Y%m%d%H%M -SNAPDIR= ${DISTPREFIX}-${SNAP} -SNAPFILE= ${SNAPDIR}.tar.xz - -DIST!= if test -f .fslckout; then echo "dist-fossil"; \ - elif test -d .git; then echo "dist-git"; \ - else echo "dist-inst"; fi - -dist-fossil: - fossil tarball --name ${DISTPREFIX} ${FOSSILID} ${DISTFILEGZ} - gunzip -c ${DISTFILEGZ} | xz >${DISTFILE} - rm ${DISTFILEGZ} - -dist-git: - git archive --prefix=${DISTPREFIX}/ ${GITREF} | xz >${DISTFILE} - -dist-inst: - mkdir /tmp/${DISTPREFIX} - cp -RPp * /tmp/${DISTPREFIX} - (cd /tmp/${DISTPREFIX}; make clean) - tar -cvjpf ${DISTFILE} -C /tmp ${DISTPREFIX} - rm -rf /tmp/${DISTPREFIX} - -dist: ${DIST} - -distinfo: dist - rm -f ${DISTINFO} ${DISTINFOSIGN} - ${CKSUM} ${DISTFILE} >${DISTINFO} - #printf "SIZE (${DISTFILE}) = %s\n" $$(wc -c <${DISTFILE}) >>${DISTINFO} - ${PGP} --clearsign --output=${DISTINFOSIGN} ${DISTINFO} - chmod 644 ${DISTINFOSIGN} - ls -l ${DISTFILE} ${DISTINFO} ${DISTINFOSIGN} - -distclean: clean - rm -f *.bz2 *.xz *.distinfo *.asc - -snapshot: distclean - mkdir /tmp/${SNAPDIR} - cp -RPp * /tmp/${SNAPDIR} - (cd /tmp/${SNAPDIR}; make clean) - tar -cvjpf ${SNAPFILE} -C /tmp ${SNAPDIR} - rm -rf /tmp/${SNAPDIR} - ls -l ${SNAPFILE} - -snap: snapshot diff --git a/mk/man.mk b/mk/man.mk deleted file mode 100644 index d04dbcd..0000000 --- a/mk/man.mk +++ /dev/null @@ -1,19 +0,0 @@ -# rules to install manpages -# Copyright 2008 Roy Marples <roy@marples.name> - -_MANPREFIX!= if test "${PREFIX}" = "/usr"; then echo "/usr/share"; else echo "${PREFIX}"; fi -MANPREFIX?= ${_MANPREFIX} - -MANDIR?= ${MANPREFIX}/man/man -MANMODE?= 0444 - -MAN5!= for man in ${MAN}; do case $$man in *.5) echo $$man;; esac; done -MAN8!= for man in ${MAN}; do case $$man in *.8) echo $$man;; esac; done - -_man: ${MAN} - -_maninstall: _man - ${INSTALL} -d ${DESTDIR}${MANDIR}5 - ${INSTALL} -m ${MANMODE} ${MAN5} ${DESTDIR}${MANDIR}5 - ${INSTALL} -d ${DESTDIR}${MANDIR}8 - ${INSTALL} -m ${MANMODE} ${MAN8} ${DESTDIR}${MANDIR}8 diff --git a/mk/os-BSD.mk b/mk/os-BSD.mk deleted file mode 100644 index e5c6057..0000000 --- a/mk/os-BSD.mk +++ /dev/null @@ -1,4 +0,0 @@ -# Setup OS specific variables -# Copyright 2008 Roy Marples <roy@marples.name> - -SRC_PF= bpf.c
\ No newline at end of file diff --git a/mk/os-Linux.mk b/mk/os-Linux.mk deleted file mode 100644 index c03c01a..0000000 --- a/mk/os-Linux.mk +++ /dev/null @@ -1,4 +0,0 @@ -# Setup OS specific variables -# Copyright 2008 Roy Marples <roy@marples.name> - -SRC_PF= lpf.c
\ No newline at end of file diff --git a/mk/os.mk b/mk/os.mk deleted file mode 100644 index 5787e3d..0000000 --- a/mk/os.mk +++ /dev/null @@ -1,5 +0,0 @@ -# Setup OS specific variables -# Copyright 2008 Roy Marples <roy@marples.name> - -OS!= case `uname -s` in Linux) echo "Linux";; *) echo "BSD";; esac -include ${MK}/os-${OS}.mk diff --git a/mk/prog.mk b/mk/prog.mk deleted file mode 100644 index 7af378d..0000000 --- a/mk/prog.mk +++ /dev/null @@ -1,35 +0,0 @@ -# rules to build a program -# based on FreeBSD's bsd.prog.mk - -# Copyright 2008 Roy Marples <roy@marples.name> - -include ${MK}/cc.mk - -OBJS+= ${SRCS:.c=.o} - -all: ${PROG} ${SCRIPTS} _man - -.c.o: - ${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@ - -${PROG}: ${OBJS} - ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD} - -_proginstall: ${PROG} - ${INSTALL} -d ${DESTDIR}${BINDIR} - ${INSTALL} -m ${BINMODE} ${PROG} ${DESTDIR}${BINDIR} - -include ${MK}/depend.mk -include ${MK}/man.mk -include ${MK}/dist.mk - -install: _proginstall _maninstall - -clean: - rm -f ${OBJS} ${PROG} ${PROG}.core ${CLEANFILES} - -LINTFLAGS?= -hx -LINTFLAGS+= -X 159,247,352 - -lint: ${SRCS:.c=.c} - ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} $^ ${.ALLSRC} diff --git a/mk/sys.mk b/mk/sys.mk deleted file mode 100644 index 7a8ee7a..0000000 --- a/mk/sys.mk +++ /dev/null @@ -1,13 +0,0 @@ -# Simple defaults - -PREFIX?= /usr -BINDIR?= ${PREFIX}/bin -BINMODE?= 0755 -NONBINMODE?= 0644 - -_SYSCONFDIR!= if test "${PREFIX}" = "/usr"; then \ - echo ""; else echo "${PREFIX}"; fi -SYSCONFDIR?= ${_SYSCONFDIR}/etc - -INSTALL?= install -SED?= sed diff --git a/src/GNUmakefile b/src/GNUmakefile new file mode 100644 index 0000000..f66ad94 --- /dev/null +++ b/src/GNUmakefile @@ -0,0 +1,12 @@ +# GNU Make does not automagically include .depend +# Luckily it does read GNUmakefile over Makefile so we can work around it + +# Nasty hack so that make clean works without configure being run +TOP?= .. +CONFIG_MK?= $(shell test -e ${TOP}/config.mk && \ + echo config.mk || echo config-null.mk) + +include Makefile +ifneq ($(wildcard .depend), ) +include .depend +endif diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..78cce49 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,39 @@ +PROG= parpd +SRCS= parpd.c eloop.c ${SRC_PF} + +BINDIR= ${PREFIX}/sbin + +MAN= parpd.conf.5 parpd.8 +CLEANFILES= parpd.8 + +TOP?= .. +include ${TOP}/iconfig.mk +CPPFLAGS+= -I${TOP} -I${TOP}/src + +OBJS= ${SRCS:.c=.o} + +.SUFFIXES: .in +.in: + ${SED} -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' $< >$@ + +.c.o: + ${CC} ${CFLAGS} ${CPPFLAGS} -c $< -o $@ + +all: ${TOP}/config.h ${PROG} ${MAN} + +${PROG}: ${DEPEND} ${OBJS} + ${CC} ${LDFLAGS} -o $@ ${OBJS} ${LDADD} + +clean: + rm -f ${OBJS} ${PROG} ${PROG}.core ${CLEANFILES} + +distclean: clean + +proginstall: + ${INSTALL} -d ${DESTDIR}${SBINDIR} + +_import-src: ${SRCS} + ${INSTALL} -d ${DESTDIR}/src + cp parpd.h ${SRCS} ${SRC_PF} parpd.conf.5 parpd.8.in ${DESTDIR}/src + +include ${TOP}/Makefile.inc diff --git a/bpf-filter.h b/src/bpf-filter.h index 9be7a3c..9be7a3c 100644 --- a/bpf-filter.h +++ b/src/bpf-filter.h diff --git a/parpd.8.in b/src/parpd.8.in index e6ba4c3..e6ba4c3 100644 --- a/parpd.8.in +++ b/src/parpd.8.in diff --git a/parpd.conf.5 b/src/parpd.conf.5 index f90fe6f..f90fe6f 100644 --- a/parpd.conf.5 +++ b/src/parpd.conf.5 @@ -30,10 +30,9 @@ #include <net/if.h> -#define VERSION "1.7" -#ifndef SYSCONFDIR -# define SYSCONFDIR "/etc" -#endif +#include "config.h" + +#define VERSION "1.99" #define PARPD_CONF SYSCONFDIR "/parpd.conf" #define HWADDR_LEN 20 @@ -71,12 +70,4 @@ ssize_t bpf_read(struct interface *, void *, size_t); #define UNCONST(a) ((void *)(unsigned long)(const void *)(a)) -/* Only GLIBC doesn't support strlcpy */ -#ifdef __GLIBC__ -# if !defined(__UCLIBC__) && !defined (__dietlibc__) -# include <stdio.h> -# define strlcpy(dst, src, len) snprintf(dst, len, "%s", src) -# endif -#endif - #endif |
