Use a configure command instead of working things out in the Makefile.
authorRoy Marples <roy@marples.name>
Thu, 4 Nov 2010 11:40:19 +0000 (11:40 +0000)
committerRoy Marples <roy@marples.name>
Thu, 4 Nov 2010 11:40:19 +0000 (11:40 +0000)
This makes us a little more lean and mean and allows us to add an override
for ArchLinux, fixing #10.

.gitignore
Makefile
configure [new file with mode: 0755]

index a9adcd2dd85e670dadb61a9983afb8ee5064a76d..bc443a4c5304a08dc0d0c8395259b071ef8e3030 100644 (file)
@@ -1,4 +1,5 @@
 *.bz2
+config.mk
 dnsmasq
 libc
 named
index 4d1c89a36368bfb04c30ee19760c8c9f9d4eb1ca..75835dac8f49984e04ab04ed665598f16ac8eaf5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,61 +1,36 @@
+include config.mk
+
 NAME=          openresolv
 VERSION=       3.3.6
 PKG=           ${NAME}-${VERSION}
 
 INSTALL?=      install
 SED?=          sed
-#PREFIX?=      /usr/local
-MANPREFIX?=    /usr/share
-VARBASE?=      /var
 
 BINMODE?=      0755
 DOCMODE?=      0644
 MANMODE?=      0444
 
-SYSCONFDIR?=   ${PREFIX}/etc
-BINDIR=                ${PREFIX}/sbin
-LIBEXECDIR?=   ${PREFIX}/libexec/resolvconf
-VARDIR?=       ${VARBASE}/run/resolvconf
-MANDIR?=       ${MANPREFIX}/man
-
 RESOLVCONF=    resolvconf resolvconf.8 resolvconf.conf.5
 SUBSCRIBERS=   libc dnsmasq named pdnsd unbound
 TARGET=                ${RESOLVCONF} ${SUBSCRIBERS}
 SRCS=          ${TARGET:C,$,.in,} # pmake
 SRCS:=         ${TARGET:=.in} # gmake
 
-# Try to embed correct service restart commands
-_CMD1=         \\1 status >/dev/null 2>\\&1
-_CMD2=         \\1 restart
-_CMD_SH=if [ -x /sbin/rc-service ]; then \
-               printf '/sbin/rc-service -e \\1 \\&\\& /sbin/rc-service \\1 -- -Ds restart'; \
-       elif [ -x /usr/sbin/invoke-rc.d ]; then \
-               printf '/usr/sbin/invoke-rc.d --query --quiet \\1 restart || [ \\\\$$? = 104 ] \\&\\& /usr/sbin/invoke-rc.d ${_CMD2}'; \
-       elif [ -x /sbin/service ]; then \
-               printf '/sbin/service ${_CMD1} \\&\\& /sbin/service ${_CMD2}'; \
-       elif [ -d /usr/local/etc/rc.d ]; then \
-               printf 'if /usr/local/etc/rc.d/${_CMD1}; then'; \
-               printf ' /usr/local/etc/rc.d/${_CMD2}; '; \
-               printf 'elif /etc/rc.d/${_CMD1}; then /etc/rc.d/${_CMD2}; fi'; \
-       elif [ -d /etc/rc.d ]; then \
-               printf '/etc/rc.d/${_CMD1} \\&\\& /etc/rc.d/${_CMD2}'; \
-       elif [ -d /etc/init.d ]; then \
-               printf '/etc/init.d/${_CMD1} \\&\\& /etc/init.d/${_CMD2}'; \
-       fi;
-_CMD!=         ${_CMD_SH}
-RESTARTCMD?=   ${_CMD}$(shell ${_CMD_SH})
+SED_PREFIX=            -e 's:@PREFIX@:${PREFIX}:g'
+SED_SYSCONFDIR=                -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g'
+SED_LIBEXECDIR=                -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g'
+SED_VARDIR=            -e 's:@VARDIR@:${VARDIR}:g'
+SED_RESTARTCMD=                -e 's:@RESTARTCMD \(.*\)@:${RESTARTCMD}:g'
 
 .SUFFIXES: .in
 
 all: ${TARGET}
 
 .in:
-       ${SED} -e 's:@PREFIX@:${PREFIX}:g' \
-               -e 's:@SYSCONFDIR@:${SYSCONFDIR}:g' \
-               -e 's:@LIBEXECDIR@:${LIBEXECDIR}:g' \
-               -e 's:@VARDIR@:${VARDIR}:g' \
-               -e 's:@RESTARTCMD \(.*\)@:${RESTARTCMD}:g' \
-               $@.in > $@
+       ${SED}  ${SED_PREFIX} ${SED_SYSCONFDIR} ${SED_LIBEXECDIR} \
+               ${SED_VARDIR} ${SED_RESTARTCMD} \
+               $< > $@
 
 clean:
        rm -f ${TARGET} openresolv-${VERSION}.tar.bz2
@@ -63,8 +38,8 @@ clean:
 installdirs:
 
 install: ${TARGET}
-       ${INSTALL} -d ${DESTDIR}${BINDIR}
-       ${INSTALL} -m ${BINMODE} resolvconf ${DESTDIR}${BINDIR}
+       ${INSTALL} -d ${DESTDIR}${SBINDIR}
+       ${INSTALL} -m ${BINMODE} resolvconf ${DESTDIR}${SBINDIR}
        ${INSTALL} -d ${DESTDIR}${SYSCONFDIR}
        test -e ${DESTDIR}${SYSCONFDIR}/resolvconf.conf || \
        ${INSTALL} -m ${DOCMODE} resolvconf.conf ${DESTDIR}${SYSCONFDIR}
diff --git a/configure b/configure
new file mode 100755 (executable)
index 0000000..d3dda45
--- /dev/null
+++ b/configure
@@ -0,0 +1,183 @@
+#!/bin/sh
+# Try and be like autotools configure, but without autotools
+
+# Ensure that we do not inherit these from env
+OS=
+BUILD=
+HOST=
+TARGET=
+RESTARTCMD=
+
+for x; do
+       opt=${x%%=*}
+       var=${x#*=}
+       case "$opt" in
+       --os|OS) OS=$var;;
+       --with-cc|CC) CC=$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) RUNDIR=$var;;
+       --mandir) MANDIR=$var;;
+       --with-ccopts|CFLAGS) CFLAGS=$var;;
+       CPPFLAGS) CPPFLAGS=$var;;
+       --build) BUILD=$var;;
+       --host) HOST=$var;;
+       --target) TARGET=$var;;
+       --libdir) LIBDIR=$var;;
+       --restartcmd) RESTARTCMD=$var;;
+       --includedir) eval INCLUDEDIR="$INCLUDEDIR${INCLUDEDIR:+ }$var";;
+       --datadir|--infodir) ;; # ignore autotools
+       --disable-maintainer-mode|--disable-dependency-tracking) ;;
+       --help) echo "See the README file for available options"; exit 0;;
+       *) echo "$0: WARNING: unknown option $opt" >&2;;
+       esac
+done
+
+: ${SED:=sed}
+
+: ${PREFIX:=$prefix}
+: ${SYSCONFDIR:=$PREFIX/etc}
+: ${SBINDIR:=$PREFIX/sbin}
+: ${LIBEXECDIR:=$PREFIX/libexec}
+: ${STATEDIR:=/var}
+: ${RUNDIR:=$STATEDIR/run}
+: ${MANDIR:=${PREFIX:-/usr}/share/man}
+
+eval SYSCONFDIR="$SYSCONFDIR"
+eval SBINDIR="$SBINDIR"
+eval LIBEXECDIR="$LIBEXECDIR/resolvconf"
+eval VARDIR="$RUNDIR/resolvconf"
+eval MANDIR="$MANDIR"
+
+CONFIG_MK=config.mk
+
+if [ -z "$BUILD" ]; then
+       BUILD=`uname -m`-`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
+
+# Debian and Slackware have linux in different places when dealing with
+# autoconf, so we deal with that here.
+if [ -z "$OS" ]; then
+       case "$TARGET" in
+       *-linux-*|linux-*|*-linux|linux) OS=linux;;
+       esac
+fi
+
+if [ -z "$OS" ]; then
+       # Derive OS from cpu-manufacturer-os-kernel
+       CPU=${TARGET%%-*}
+       REST=${TARGET#*-}
+       if [ "$CPU" != "$REST" ]; then
+               MANU=${REST%%-*}
+               REST=${REST#*-}
+               if [ "$MANU" != "$REST" ]; then
+                       OS=${REST%%-*}
+                       REST=${REST#*-}
+                       if [ "$OS" != "$REST" ]; then
+                               KERNEL=${REST%%-*}
+                       else
+                               # 3 tupple
+                               KERNEL=$OS
+                               OS=$MANU
+                               MANU=
+                       fi
+               else
+                       # 2 tupple
+                       OS=$MANU
+                       MANU=
+               fi
+       fi
+fi
+
+echo "Configuring openresolv for ... $OS"
+rm -rf $CONFIG_MK
+echo "# $OS" >$CONFIG_MK
+
+for x in SYSCONFDIR SBINDIR LIBEXECDIR VARDIR MANDIR; 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
+done
+
+if [ -e /etc/arch-release -a -d /etc/rc.d ]; then
+       echo "Overriding service status check for Arch Linux"
+       RESTARTCMD="[ -e /var/run/daemons/\1 ] && /etc/rc.d/\1 restart"
+       echo "yes"
+fi
+
+if [ -z "$RESTARTCMD" ]; then
+       printf "Checking for OpenRC ... "
+       if [ -x /sbin/rc-service ]; then
+               RESTARTCMD="/sbin/rc-service -e \1 && /sbin/rc-service \1 -Ds restart"
+               echo "yes"
+       else
+               echo "no"
+       fi
+fi
+if [ -z "$RESTARTCMD" ]; then
+       printf "Checking for invoke-rc.d ... "
+       if [ -x /usr/sbin/invoke-rc.d ]; then
+               RESTARTCMD="/usr/sbin/invoke-rc.d --query --quiet \1 restart || [ \\$? = 104 ] && /usr/sbin/invoke-rc.d \1 restart"
+               echo "yes"
+       else
+               echo "no"
+       fi
+fi
+if [ -z "$RESTARTCMD" ]; then
+       printf "Checking for service ... "
+       if [ -x /sbin/service ]; then
+               RESTARTCMD="/sbin/service \1 && /sbin/service \1 restart"
+               echo "yes"
+       else
+               echo "no"
+       fi
+fi
+if [ -z "$RESTARTCMD" ]; then
+       for x in /etc/init.d/rc.d /etc/rc.d /etc/init.d; do
+               printf "Checking for $x ... "
+               if [ -d $x ]; then
+                       RESTARTCMD="$x/\1 status >/dev/null 2>&1 && $x/\1 restart"
+                       echo "yes"
+                       break
+               else
+                       echo "no"
+               fi
+       done
+fi
+
+if [ -z "$RESTARTCMD" ]; then
+       echo "WARNING! No means of interacting with system services detected!"
+       exit 1
+fi
+# Transform for a make file
+RESTARTCMD=$(echo "$RESTARTCMD" | $SED \
+       -e 's:\&:\\\&:g' \
+       -e 's:\$:\$\$:g' \
+)
+echo "RESTARTCMD=      ${RESTARTCMD}" >>$CONFIG_MK
+
+echo
+echo "   SYSCONFDIR =          $SYSCONFDIR"
+echo "   SBINDIR =             $SBINDIR"
+echo "   LIBEXECDIR =          $LIBEXECDIR"
+echo "   VARDIR =              $RUNDIR"
+echo "   MANDIR =              $MANDIR"
+echo