miniupnpd: move many scripts from Makefile.linux to configure

This commit is contained in:
Thomas Bernard 2020-05-02 18:08:59 +02:00
parent 1833a538ef
commit 55d2535a6f
No known key found for this signature in database
GPG Key ID: 0FF11B67A5C0863C
3 changed files with 67 additions and 59 deletions

View File

@ -82,7 +82,8 @@ To Build and install :
- Build the daemon - Build the daemon
> make > make
If not using iptables from your system, If not using iptables from your system,
> IPTABLESPATH=/path/to/iptables-1.4.1 make > ./configure --iptablespath=/path/to/iptables-1.4.1
> make
- install as root using : - install as root using :
> make install > make install
- A miniupnpd script should be installed to /etc/init.d - A miniupnpd script should be installed to /etc/init.d
@ -108,7 +109,8 @@ How to get libiptc with its headers on debian :
> ./configure --enable-static > ./configure --enable-static
> make > make
- it is now possible to compile miniupnpd using the following command : - it is now possible to compile miniupnpd using the following command :
> IPTABLESPATH=/path/to/iptables-x.x.x make > ./configure --iptablespath=/path/to/iptables-x.x.x
> make
======================== Linux/netfilter nftables ========================= ======================== Linux/netfilter nftables =========================

View File

@ -75,60 +75,6 @@ LDLIBS ?= -lip4tc
CPPFLAGS := -DIPTABLES_143 $(CPPFLAGS) CPPFLAGS := -DIPTABLES_143 $(CPPFLAGS)
endif endif
ARCH ?= $(shell uname -m | grep -q "x86_64" && echo 64)
ifdef IPTABLESPATH
CPPFLAGS := $(CPPFLAGS) -I$(IPTABLESPATH)/include/
LDFLAGS := $(LDFLAGS) -L$(IPTABLESPATH)/libiptc/
# get iptables version and set IPTABLES_143 macro if needed
ifeq ($(TARGET_OPENWRT),)
IPTABLESVERSION := $(shell grep "\#define VERSION" $(IPTABLESPATH)/config.h | tr -d \" |cut -d" " -f3 )
IPTVER1 := $(shell echo $(IPTABLESVERSION) | cut -d. -f1 )
IPTVER2 := $(shell echo $(IPTABLESVERSION) | cut -d. -f2 )
IPTVER3 := $(shell echo $(IPTABLESVERSION) | cut -d. -f3 )
# test if iptables version >= 1.4.3
TEST := $(shell [ $(IPTVER1) -gt 1 ] || \
[ \( $(IPTVER1) -eq 1 \) -a \
\( \( $(IPTVER2) -gt 4 \) -o \
\( \( $(IPTVER2) -eq 4 \) -a \( $(IPTVER3) -ge 3 \) \) \) ] && echo 1 )
ifeq ($(TEST), 1)
CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
# the following sucks, but works
LDLIBS = $(IPTABLESPATH)/libiptc/.libs/libip4tc.o
#LDLIBS = $(IPTABLESPATH)/libiptc/.libs/libiptc.a
else # ifeq ($(TEST), 1)
LDLIBS = $(IPTABLESPATH)/libiptc/libiptc.a
endif # ifeq ($(TEST), 1)
else # ($(TARGET_OPENWRT),)
# openWRT :
# check for system-wide iptables files. Test if iptables version >= 1.4.3
# the following test has to be verified :
TEST := $(shell test -f /usr/include/iptables/internal.h && grep -q "\#define IPTABLES_VERSION" /usr/include/iptables/internal.h && echo 1)
ifeq ($(TEST), 1)
CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
LDLIBS = -liptc
endif # ($(TEST), 1)
TEST_LIB := $(shell test -f /usr/lib$(ARCH)/libiptc.a && echo 1)
ifeq ($(TEST_LIB), 1)
LDLIBS = -liptc /usr/lib$(ARCH)/libiptc.a
endif # ($(TEST_LIB), 1)
endif # ($(TARGET_OPENWRT),)
else # ifdef IPTABLESPATH
# IPTABLESPATH not defined
# the following test has to be verified :
TEST := $(shell test -f /usr/include/xtables.h && grep -q "XTABLES_VERSION_CODE" /usr/include/xtables.h && echo 1)
ifeq ($(TEST), 1)
CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
LDLIBS = -liptc
TESTIP4TC := $(shell test -f /lib/libip4tc.so && echo 1)
ifeq ($(TESTIP4TC), 1)
LDLIBS := $(LDLIBS) -lip4tc
endif # ($(TESTIP4TC), 1)
TESTIP6TC := $(shell test -f /lib/libip6tc.so && echo 1)
ifeq ($(TESTIP6TC), 1)
LDLIBS := $(LDLIBS) -lip6tc
endif # ($(TESTIP6TC), 1)
endif # ($(TEST), 1)
endif # ifdef IPTABLESPATH
endif # ifneq ($(IPTABLES_PCFILE_FOUND),1) endif # ifneq ($(IPTABLES_PCFILE_FOUND),1)
#LDLIBS += -lnfnetlink #LDLIBS += -lnfnetlink
@ -164,6 +110,9 @@ EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
all: $(EXECUTABLES) all: $(EXECUTABLES)
config.mk: configure
./configure $(CONFIG_OPTIONS)
clean: clean:
$(RM) config.h $(RM) config.h
$(RM) $(ALLOBJS) $(RM) $(ALLOBJS)

63
miniupnpd/configure vendored
View File

@ -13,6 +13,11 @@
UPNP_VERSION_MAJOR=1 UPNP_VERSION_MAJOR=1
UPNP_VERSION_MINOR=1 UPNP_VERSION_MINOR=1
# input environment variables :
# IPV6, IGD2, STRICT, DEBUG, LEASFILE, VENDORCFG, PCP_PEER,
# PORTINUSE, DISABLEPPPCONN, FW, IPTABLESPATH, TARGET_OPENWRT,
# PKG_CONFIG
for argv; do for argv; do
case "$argv" in case "$argv" in
--ipv6) IPV6=1 ;; --ipv6) IPV6=1 ;;
@ -35,6 +40,8 @@ case "$argv" in
--disable-pppconn) DISABLEPPPCONN=1 ;; --disable-pppconn) DISABLEPPPCONN=1 ;;
--firewall=*) --firewall=*)
FW=$(echo $argv | cut -d= -f2) ;; FW=$(echo $argv | cut -d= -f2) ;;
--iptablespath=*)
IPTABLESPATH=$(echo $argv | cut -d= -f2) ;;
--help|-h) --help|-h)
echo "Usage : $0 [options]" echo "Usage : $0 [options]"
echo " --ipv6 enable IPv6" echo " --ipv6 enable IPv6"
@ -48,6 +55,7 @@ case "$argv" in
echo " --uda-version=x.x set advertised UPnP version (default to ${UPNP_VERSION_MAJOR}.${UPNP_VERSION_MINOR})" echo " --uda-version=x.x set advertised UPnP version (default to ${UPNP_VERSION_MAJOR}.${UPNP_VERSION_MINOR})"
echo " --disable-pppconn disable WANPPPConnection" echo " --disable-pppconn disable WANPPPConnection"
echo " --firewall=<name> force the firewall type (nftables, iptables, pf, ipf, ipfw)" echo " --firewall=<name> force the firewall type (nftables, iptables, pf, ipf, ipfw)"
echo " --iptablespath=/path/to/iptables use a specific version of iptables"
exit 1 exit 1
;; ;;
*) *)
@ -78,6 +86,7 @@ LOG_MINIUPNPD="LOG_DAEMON"
# detecting the OS name and version # detecting the OS name and version
OS_NAME=`uname -s` OS_NAME=`uname -s`
OS_VERSION=`uname -r` OS_VERSION=`uname -r`
OS_MACHINE=`uname -m`
# Makefile to use # Makefile to use
MAKEFILE= MAKEFILE=
@ -424,15 +433,14 @@ case $FW in
;; ;;
iptables) iptables)
MAKEFILE=Makefile.linux MAKEFILE=Makefile.linux
touch config.mk
echo "#define USE_NETFILTER 1" >> ${CONFIGFILE} echo "#define USE_NETFILTER 1" >> ${CONFIGFILE}
echo "#define USE_IPTABLES 1" >> ${CONFIGFILE} echo "#define USE_IPTABLES 1" >> ${CONFIGFILE}
echo "# generated by $0 on `date`" > config.mk
if [ "$PKG_CONFIG" ] ; then if [ "$PKG_CONFIG" ] ; then
echo "# generated by $0 on `date`" > config.mk
if ${PKG_CONFIG} --exists libiptc ; then if ${PKG_CONFIG} --exists libiptc ; then
IPTABLESVERSION=`${PKG_CONFIG} --modversion libiptc` IPTABLESVERSION=`${PKG_CONFIG} --modversion libiptc`
echo "detected libiptc version $IPTABLESVERSION" echo "detected libiptc version $IPTABLESVERSION"
echo "# libiptc version $IPTABLESVERSION" >> config.mk echo "# detected libiptc version $IPTABLESVERSION" >> config.mk
echo "IPTABLES_PCFILE_FOUND = 1" >> config.mk echo "IPTABLES_PCFILE_FOUND = 1" >> config.mk
IPTVER1=`echo $IPTABLESVERSION | cut -d. -f1` IPTVER1=`echo $IPTABLESVERSION | cut -d. -f1`
IPTVER2=`echo $IPTABLESVERSION | cut -d. -f2` IPTVER2=`echo $IPTABLESVERSION | cut -d. -f2`
@ -452,6 +460,55 @@ case $FW in
echo "LDLIBS += `${PKG_CONFIG} --static --libs-only-l libmnl libnetfilter_conntrack`" >> config.mk echo "LDLIBS += `${PKG_CONFIG} --static --libs-only-l libmnl libnetfilter_conntrack`" >> config.mk
fi fi
fi fi
if [ "$IPTABLESPATH" ] ; then
echo "CPPFLAGS += -I${IPTABLESPATH}/include/" >> config.mk
echo "LDFLAGS += -L${IPTABLESPATH}/libiptc/" >> config.mk
# to test : change the following test to [ "$OS_NAME" != "OpenWRT" ]
if [ -z "$TARGET_OPENWRT" ] ; then
IPTABLESVERSION=`grep "\#define VERSION" ${IPTABLESPATH}/config.h | tr -d \" |cut -d" " -f3`
echo "detected libiptc version $IPTABLESVERSION"
echo "# detected libiptc version $IPTABLESVERSION" >> config.mk
IPTVER1=`echo $IPTABLESVERSION | cut -d. -f1`
IPTVER2=`echo $IPTABLESVERSION | cut -d. -f2`
IPTVER3=`echo $IPTABLESVERSION | cut -d. -f3`
if [ $IPTVER1 -gt 1 ] || \
[ \( $IPTVER1 -eq 1 \) -a \( \( $IPTVER2 -gt 4 \) \
-o \( \( $IPTVER2 -eq 4 \) -a \( $IPTVER3 -ge 3 \) \) \) ] ; then
IPTABLES_143=1
fi
if [ "$IPTABLES_143" -eq 1 ] ; then
echo "LDLIBS += ${IPTABLESPATH}/libiptc/.libs/libip4tc.o" >> config.mk
else
echo "LDLIBS += ${IPTABLESPATH}/libiptc/libiptc.a" >> config.mk
fi
else
# OpenWRT
# check for system-wide iptables files. Test if iptables version >= 1.4.3
# the following test has to be verified :
if test -f /usr/include/iptables/internal.h && \
grep -q "\#define IPTABLES_VERSION" /usr/include/iptables/internal.h ; then
IPTABLES_143=1
echo "LDLIBS += -liptc" >> config.mk
fi
arch=`echo $OS_MACHINE | grep -q x86_64 && echo 64`
if test -f /usr/lib${arch}/libiptc.a ; then
echo "LDLIBS += -liptc /usr/lib${arch}/libiptc.a" >> config.mk
fi
fi
elif [ -z "${PKG_CONFIG}" ] ; then
# IPTABLESPATH not defined and no pkg-config
if test -f /usr/include/xtables.h && \
grep -q "XTABLES_VERSION_CODE" /usr/include/xtables.h ; then
IPTABLES_143=1
echo "LDLIBS += -liptc" >> config.mk
if test -f /lib/libip4tc.so ; then
echo "LDLIBS += -lip4tc" >> config.mk
fi
if test -f /lib/libip6tc.so ; then
echo "LDLIBS += -lip6tc" >> config.mk
fi
fi
fi
echo "/* when IPTABLES_143 is defined, miniupnpd uses the new API" >> ${CONFIGFILE} echo "/* when IPTABLES_143 is defined, miniupnpd uses the new API" >> ${CONFIGFILE}
echo " * from libiptc 1.4.3+ */ " >> ${CONFIGFILE} echo " * from libiptc 1.4.3+ */ " >> ${CONFIGFILE}
if [ "$IPTABLES_143" -eq 1 ] ; then if [ "$IPTABLES_143" -eq 1 ] ; then