WIP. Reorganize src build directories

This commit is contained in:
Thomas Bernard 2021-08-11 16:53:35 +02:00
parent 874a3aba9e
commit 92b1c8198d
No known key found for this signature in database
GPG Key ID: DB511043A31ACAAF
40 changed files with 114 additions and 131 deletions

View File

@ -27,6 +27,11 @@ endif
HAVE_IPV6 ?= yes
export HAVE_IPV6
# directories
INCDIR = include
SRCDIR = src
BUILD = build
CC ?= gcc
#AR = gar
#CFLAGS = -O -g
@ -39,6 +44,7 @@ CFLAGS ?= -O
CFLAGS += -Wall
CFLAGS += -W -Wstrict-prototypes
CFLAGS += -fno-common
CPPFLAGS += -I$(BUILD)
CPPFLAGS += -DMINIUPNPC_SET_SOCKET_TIMEOUT
CPPFLAGS += -DMINIUPNPC_GET_SRC_ADDR
CPPFLAGS += -D_BSD_SOURCE
@ -53,6 +59,9 @@ endif
#CFLAGS += -ansi
#CPPFLAGS += -DNO_GETADDRINFO
DEPFLAGS = -MM -MG
MKDIR = mkdir -p
INSTALL = install
SH = /bin/sh
JAVA = java
@ -77,72 +86,65 @@ endif
# APIVERSION is used to build SONAME
APIVERSION = 17
SRCS = igd_desc_parse.c miniupnpc.c minixml.c minisoap.c miniwget.c \
upnpc.c upnpcommands.c upnpreplyparse.c testminixml.c \
minixmlvalid.c testupnpreplyparse.c minissdpc.c \
upnperrors.c testigddescparse.c testminiwget.c \
connecthostport.c portlistingparse.c receivedata.c \
upnpdev.c testportlistingparse.c miniupnpcmodule.c \
minihttptestserver.c addr_is_reserved.c testaddr_is_reserved.c \
listdevices.c
SRCS = $(wildcard $(SRCDIR)/*.c)
LIBOBJS = miniwget.o minixml.o igd_desc_parse.o minisoap.o \
LIBOBJS = $(addprefix $(BUILD)/,miniwget.o minixml.o igd_desc_parse.o minisoap.o \
miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o \
connecthostport.o portlistingparse.o receivedata.o upnpdev.o \
addr_is_reserved.o
addr_is_reserved.o)
ifeq (, $(findstring amiga, $(OS)))
ifeq (, $(findstring mingw, $(OS))$(findstring cygwin, $(OS))$(findstring msys, $(OS)))
CFLAGS := -fPIC $(CFLAGS)
endif
LIBOBJS := $(LIBOBJS) minissdpc.o
endif
BUILDINCLUDES = $(addprefix $(BUILD)/, miniupnpcstrings.h)
OBJS = $(patsubst %.c,%.o,$(SRCS))
OBJS = $(patsubst $(SRCDIR)/%.c,$(BUILD)/%.o,$(SRCS))
DEPS = $(patsubst $(SRCDIR)/%.c,$(BUILD)/%.d,$(SRCS))
# HEADERS to install
CPPFLAGS += -Iinclude/
HEADERS = $(wildcard include/*.h)
CPPFLAGS += -I$(INCDIR)
HEADERS = $(wildcard $(INCDIR)/*.h)
# library names
LIBRARY = libminiupnpc.a
LIBRARY = $(BUILD)/libminiupnpc.a
ifneq (, $(findstring darwin, $(OS)))
SHAREDLIBRARY = libminiupnpc.dylib
SONAME = $(basename $(SHAREDLIBRARY)).$(APIVERSION).dylib
SHAREDLIBRARY = $(BUILD)/libminiupnpc.dylib
SONAME = $(notdir $(basename $(SHAREDLIBRARY))).$(APIVERSION).dylib
CPPFLAGS += -D_DARWIN_C_SOURCE
else
ifeq ($(JARSUFFIX), win32)
SHAREDLIBRARY = miniupnpc.dll
SHAREDLIBRARY = $(BUILD)/miniupnpc.dll
else
# Linux/BSD/etc.
SHAREDLIBRARY = libminiupnpc.so
SONAME = $(SHAREDLIBRARY).$(APIVERSION)
SHAREDLIBRARY = $(BUILD)/libminiupnpc.so
SONAME = $(notdir $(SHAREDLIBRARY)).$(APIVERSION)
endif
endif
EXECUTABLES = upnpc-static listdevices
EXECUTABLES_ADDTESTS = testminixml minixmlvalid testupnpreplyparse \
testigddescparse testminiwget testportlistingparse
EXECUTABLES = $(addprefix $(BUILD)/, upnpc-static listdevices)
EXECUTABLES_ADDTESTS = $(addprefix $(BUILD)/, testminixml minixmlvalid \
testupnpreplyparse testigddescparse testminiwget testportlistingparse)
TESTMINIXMLOBJS = minixml.o igd_desc_parse.o testminixml.o
TESTMINIXMLOBJS = $(addprefix $(BUILD)/, minixml.o igd_desc_parse.o testminixml.o)
TESTMINIWGETOBJS = miniwget.o testminiwget.o connecthostport.o receivedata.o
TESTMINIWGETOBJS = $(addprefix $(BUILD)/, miniwget.o testminiwget.o connecthostport.o receivedata.o)
TESTUPNPREPLYPARSE = testupnpreplyparse.o minixml.o upnpreplyparse.o
TESTUPNPREPLYPARSE = $(addprefix $(BUILD)/, testupnpreplyparse.o minixml.o upnpreplyparse.o)
TESTPORTLISTINGPARSE = testportlistingparse.o minixml.o portlistingparse.o
TESTPORTLISTINGPARSE = $(addprefix $(BUILD)/, testportlistingparse.o minixml.o portlistingparse.o)
TESTADDR_IS_RESERVED = testaddr_is_reserved.o addr_is_reserved.o
TESTADDR_IS_RESERVED = $(addprefix $(BUILD)/, testaddr_is_reserved.o addr_is_reserved.o)
TESTIGDDESCPARSE = testigddescparse.o igd_desc_parse.o minixml.o \
TESTIGDDESCPARSE = $(addprefix $(BUILD)/, testigddescparse.o igd_desc_parse.o minixml.o \
miniupnpc.o miniwget.o upnpcommands.o upnpreplyparse.o \
minisoap.o connecthostport.o receivedata.o \
portlistingparse.o addr_is_reserved.o
portlistingparse.o addr_is_reserved.o)
ifeq (, $(findstring amiga, $(OS)))
EXECUTABLES := $(EXECUTABLES) upnpc-shared
TESTMINIWGETOBJS := $(TESTMINIWGETOBJS) minissdpc.o
TESTIGDDESCPARSE := $(TESTIGDDESCPARSE) minissdpc.o
ifeq (, $(findstring mingw, $(OS))$(findstring cygwin, $(OS))$(findstring msys, $(OS)))
CFLAGS += -fPIC
endif
EXECUTABLES += $(BUILD)/upnpc-shared
TESTMINIWGETOBJS += $(BUILD)/minissdpc.o
TESTIGDDESCPARSE += $(BUILD)/minissdpc.o
LIBOBJS += $(BUILD)/minissdpc.o
endif
LIBDIR ?= lib
@ -160,13 +162,12 @@ PKGCONFIGDIR = $(INSTALLDIRLIB)/pkgconfig
FILESTOINSTALL = $(LIBRARY) $(EXECUTABLES)
ifeq (, $(findstring amiga, $(OS)))
FILESTOINSTALL := $(FILESTOINSTALL) $(SHAREDLIBRARY) miniupnpc.pc
FILESTOINSTALL += $(SHAREDLIBRARY) miniupnpc.pc
endif
.PHONY: install clean depend all check test everything \
installpythonmodule updateversion
# validateminixml validateminiwget
all: $(LIBRARY) $(EXECUTABLES)
@ -177,53 +178,53 @@ check: validateminixml validateminiwget validateupnpreplyparse \
everything: all $(EXECUTABLES_ADDTESTS)
pythonmodule: $(LIBRARY) miniupnpcmodule.c setup.py
pythonmodule: $(LIBRARY) $(SRCDIR)/miniupnpcmodule.c setup.py
MAKE=$(MAKE) python setup.py build
touch $@
installpythonmodule: pythonmodule
MAKE=$(MAKE) python setup.py install
pythonmodule3: $(LIBRARY) miniupnpcmodule.c setup.py
pythonmodule3: $(LIBRARY) $(SRCDIR)/miniupnpcmodule.c setup.py
MAKE=$(MAKE) python3 setup.py build
touch $@
installpythonmodule3: pythonmodule3
MAKE=$(MAKE) python3 setup.py install
validateminixml: minixmlvalid
validateminixml: $(BUILD)/minixmlvalid
@echo "minixml validation test"
./minixmlvalid
./$<
touch $@
validateminiwget: testminiwget minihttptestserver testminiwget.sh
validateminiwget: testminiwget.sh $(BUILD)/testminiwget $(BUILD)/minihttptestserver
@echo "miniwget validation test"
./testminiwget.sh
./$<
touch $@
validateupnpreplyparse: testupnpreplyparse testupnpreplyparse.sh
validateupnpreplyparse: testupnpreplyparse.sh $(BUILD)/testupnpreplyparse
@echo "upnpreplyparse validation test"
./testupnpreplyparse.sh
./$<
touch $@
validateportlistingparse: testportlistingparse
validateportlistingparse: $(BUILD)/testportlistingparse
@echo "portlistingparse validation test"
./testportlistingparse
./$<
touch $@
validateigddescparse: testigddescparse
validateigddescparse: $(BUILD)/testigddescparse
@echo "igd desc parse validation test"
./testigddescparse testdesc/new_LiveBox_desc.xml testdesc/new_LiveBox_desc.values
./testigddescparse testdesc/linksys_WAG200G_desc.xml testdesc/linksys_WAG200G_desc.values
./$< testdesc/new_LiveBox_desc.xml testdesc/new_LiveBox_desc.values
./$< testdesc/linksys_WAG200G_desc.xml testdesc/linksys_WAG200G_desc.values
touch $@
validateaddr_is_reserved: testaddr_is_reserved
validateaddr_is_reserved: $(BUILD)/testaddr_is_reserved
@echo "addr_is_reserved() validation test"
./testaddr_is_reserved
./$<
touch $@
clean:
$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h
$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) $(BUILDINCLUDES)
$(RM) $(EXECUTABLES_ADDTESTS)
# clean python stuff
$(RM) pythonmodule pythonmodule3
@ -281,7 +282,8 @@ cleaninstall:
$(RM) $(DESTDIR)$(INSTALLDIRLIB)/$(LIBRARY)
$(RM) $(DESTDIR)$(INSTALLDIRLIB)/$(SHAREDLIBRARY)
miniupnpc.pc: VERSION
$(BUILD)/miniupnpc.pc: VERSION
@$(MKDIR) $(BUILD)
$(RM) $@
echo "prefix=$(INSTALLPREFIX)" >> $@
echo "exec_prefix=\$${prefix}" >> $@
@ -294,8 +296,7 @@ miniupnpc.pc: VERSION
echo "Libs: -L\$${libdir} -lminiupnpc" >> $@
echo "Cflags: -I\$${includedir}" >> $@
depend:
makedepend -Y -- $(CFLAGS) $(CPPFLAGS) -- $(SRCS) 2>/dev/null
depend: $(DEPS)
$(LIBRARY): $(LIBOBJS)
ifneq (, $(findstring darwin, $(OS)))
@ -312,30 +313,39 @@ else
$(CC) -shared $(LDFLAGS) -Wl,-soname,$(SONAME) -o $@ $^
endif
upnpc-static: upnpc.o $(LIBRARY)
$(BUILD)/%.o: $(SRCDIR)/%.c $(BUILD)/%.d
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
$(DEPS): $(BUILDINCLUDES)
$(BUILD)/%.d: $(SRCDIR)/%.c
@$(MKDIR) $(@D)
$(CC) $(CPPFLAGS) $(DEPFLAGS) -MT $@ -o $@ $<
$(BUILD)/upnpc-static: $(BUILD)/upnpc.o $(LIBRARY)
$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
upnpc-shared: upnpc.o $(SHAREDLIBRARY)
$(BUILD)/upnpc-shared: $(BUILD)/upnpc.o $(SHAREDLIBRARY)
$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
listdevices: listdevices.o $(LIBRARY)
$(BUILD)/listdevices: $(BUILD)/listdevices.o $(LIBRARY)
testminixml: $(TESTMINIXMLOBJS)
$(BUILD)/testminixml: $(TESTMINIXMLOBJS)
testminiwget: $(TESTMINIWGETOBJS)
$(BUILD)/testminiwget: $(TESTMINIWGETOBJS)
minixmlvalid: minixml.o minixmlvalid.o
$(BUILD)/minixmlvalid: $(addprefix $(BUILD)/, minixml.o minixmlvalid.o)
testupnpreplyparse: $(TESTUPNPREPLYPARSE)
$(BUILD)/testupnpreplyparse: $(TESTUPNPREPLYPARSE)
testigddescparse: $(TESTIGDDESCPARSE)
$(BUILD)/testigddescparse: $(TESTIGDDESCPARSE)
testportlistingparse: $(TESTPORTLISTINGPARSE)
$(BUILD)/testportlistingparse: $(TESTPORTLISTINGPARSE)
testaddr_is_reserved: $(TESTADDR_IS_RESERVED)
$(BUILD)/testaddr_is_reserved: $(TESTADDR_IS_RESERVED)
miniupnpcstrings.h: miniupnpcstrings.h.in updateminiupnpcstrings.sh VERSION
$(SH) updateminiupnpcstrings.sh
$(BUILD)/miniupnpcstrings.h: miniupnpcstrings.h.in updateminiupnpcstrings.sh VERSION
$(SH) updateminiupnpcstrings.sh $@ $<
# ftp tool supplied with OpenBSD can download files from http.
jnaerator-%.jar:
@ -375,51 +385,9 @@ ideb:
minihttptestserver: minihttptestserver.o
# DO NOT DELETE THIS LINE -- make depend depends on it.
print-%:
@echo "$* = $($*)"
igd_desc_parse.o: include/igd_desc_parse.h
miniupnpc.o: include/miniupnpc.h include/miniupnpc_declspec.h
miniupnpc.o: include/igd_desc_parse.h include/upnpdev.h minissdpc.h
miniupnpc.o: include/miniwget.h miniwget_private.h miniupnpc_socketdef.h
miniupnpc.o: minisoap.h minixml.h include/upnpcommands.h
miniupnpc.o: include/miniupnpctypes.h connecthostport.h addr_is_reserved.h
minixml.o: minixml.h
minisoap.o: minisoap.h miniupnpc_socketdef.h miniupnpcstrings.h
miniwget.o: miniupnpcstrings.h include/miniwget.h
miniwget.o: include/miniupnpc_declspec.h connecthostport.h
miniwget.o: miniupnpc_socketdef.h receivedata.h
upnpc.o: include/miniwget.h include/miniupnpc_declspec.h include/miniupnpc.h
upnpc.o: include/igd_desc_parse.h include/upnpdev.h include/upnpcommands.h
upnpc.o: include/miniupnpctypes.h include/portlistingparse.h
upnpc.o: include/upnperrors.h miniupnpcstrings.h
upnpcommands.o: include/upnpcommands.h include/miniupnpc_declspec.h
upnpcommands.o: include/miniupnpctypes.h include/miniupnpc.h
upnpcommands.o: include/igd_desc_parse.h include/upnpdev.h
upnpcommands.o: include/portlistingparse.h include/upnpreplyparse.h
upnpreplyparse.o: include/upnpreplyparse.h minixml.h
testminixml.o: minixml.h include/igd_desc_parse.h
minixmlvalid.o: minixml.h
testupnpreplyparse.o: include/upnpreplyparse.h
minissdpc.o: miniupnpc_socketdef.h minissdpc.h include/miniupnpc_declspec.h
minissdpc.o: include/upnpdev.h include/miniupnpc.h include/igd_desc_parse.h
minissdpc.o: receivedata.h codelength.h
upnperrors.o: include/upnperrors.h include/miniupnpc_declspec.h
upnperrors.o: include/upnpcommands.h include/miniupnpctypes.h
upnperrors.o: include/miniupnpc.h include/igd_desc_parse.h include/upnpdev.h
testigddescparse.o: include/igd_desc_parse.h minixml.h include/miniupnpc.h
testigddescparse.o: include/miniupnpc_declspec.h include/upnpdev.h
testminiwget.o: include/miniwget.h include/miniupnpc_declspec.h
connecthostport.o: connecthostport.h miniupnpc_socketdef.h
portlistingparse.o: include/portlistingparse.h include/miniupnpc_declspec.h
portlistingparse.o: include/miniupnpctypes.h minixml.h
receivedata.o: receivedata.h miniupnpc_socketdef.h
upnpdev.o: include/upnpdev.h include/miniupnpc_declspec.h
testportlistingparse.o: include/portlistingparse.h
testportlistingparse.o: include/miniupnpc_declspec.h include/miniupnpctypes.h
miniupnpcmodule.o: include/miniupnpc.h include/miniupnpc_declspec.h
miniupnpcmodule.o: include/igd_desc_parse.h include/upnpdev.h
miniupnpcmodule.o: include/upnpcommands.h include/miniupnpctypes.h
miniupnpcmodule.o: include/upnperrors.h
testaddr_is_reserved.o: addr_is_reserved.h
listdevices.o: include/miniupnpc.h include/miniupnpc_declspec.h
listdevices.o: include/igd_desc_parse.h include/upnpdev.h
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif

View File

@ -13,7 +13,7 @@ from setuptools.command import build_ext
import subprocess
import os
EXT = ['libminiupnpc.a']
EXT = ['build/libminiupnpc.a']
class make_then_build_ext(build_ext.build_ext):
def run(self):
@ -29,7 +29,7 @@ setup(name="miniupnpc",
description='miniUPnP client',
cmdclass={'build_ext': make_then_build_ext},
ext_modules=[
Extension(name="miniupnpc", sources=["miniupnpcmodule.c"],
Extension(name="miniupnpc", sources=["src/miniupnpcmodule.c"],
include_dirs=['include'], extra_objects=EXT)
])

View File

@ -17,6 +17,8 @@
# it should now also run with dash
TMPD=`mktemp -d -t miniwgetXXXXXXXXXX`
TESTSERVER=./build/minihttptestserver
TESTMINIWGET=./build/testminiwget
HTTPSERVEROUT="${TMPD}/httpserverout"
EXPECTEDFILE="${TMPD}/expectedfile"
DOWNLOADEDFILE="${TMPD}/downloadedfile"
@ -50,11 +52,15 @@ case "$HAVE_IPV6" in
esac
#make minihttptestserver
#make testminiwget
if [ ! -x "$TESTSERVER" ] || [ ! -x "$TESTMINIWGET" ] ; then
echo "Please build $TESTSERVER and $TESTMINIWGET"
#make minihttptestserver
#make testminiwget
exit 1
fi
# launching the test HTTP server
./minihttptestserver $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
$TESTSERVER $SERVERARGS -e $EXPECTEDFILE > $HTTPSERVEROUT &
SERVERPID=$!
while [ -z "$PORT" ]; do
sleep 1
@ -74,7 +80,7 @@ URL3="http://$ADDR:$PORT/addcrap"
URL4="http://$ADDR:$PORT/malformed"
echo "standard test ..."
./testminiwget $URL1 "${DOWNLOADEDFILE}.1"
$TESTMINIWGET $URL1 "${DOWNLOADEDFILE}.1"
if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.1" ; then
echo "ok"
else
@ -83,7 +89,7 @@ else
fi
echo "chunked transfert encoding test ..."
./testminiwget $URL2 "${DOWNLOADEDFILE}.2"
$TESTMINIWGET $URL2 "${DOWNLOADEDFILE}.2"
if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.2" ; then
echo "ok"
else
@ -92,7 +98,7 @@ else
fi
echo "response too long test ..."
./testminiwget $URL3 "${DOWNLOADEDFILE}.3"
$TESTMINIWGET $URL3 "${DOWNLOADEDFILE}.3"
if cmp $EXPECTEDFILE "${DOWNLOADEDFILE}.3" ; then
echo "ok"
else
@ -101,7 +107,7 @@ else
fi
echo "malformed response test ..."
./testminiwget $URL4 "${DOWNLOADEDFILE}.4"
$TESTMINIWGET $URL4 "${DOWNLOADEDFILE}.4"
# kill the test HTTP server
kill $SERVERPID

View File

@ -1,8 +1,10 @@
#!/bin/sh
TESTUPNPREPLYPARSE=./build/testupnpreplyparse
for f in testreplyparse/*.xml ; do
bf="`dirname $f`/`basename $f .xml`"
if ./testupnpreplyparse $f $bf.namevalue ; then
if $TESTUPNPREPLYPARSE $f $bf.namevalue ; then
echo "$f : passed"
else
echo "$f : FAILED"

View File

@ -1,12 +1,19 @@
#! /bin/sh
# $Id: updateminiupnpcstrings.sh,v 1.7 2011/01/04 11:41:53 nanard Exp $
# project miniupnp : http://miniupnp.free.fr/
# (c) 2009 Thomas Bernard
# (c) 2009-2021 Thomas Bernard
FILE=miniupnpcstrings.h
TMPFILE=miniupnpcstrings.h.tmp
TEMPLATE_FILE=${FILE}.in
if [ -n "$1" ] ; then
FILE="$1"
fi
if [ -n "$2" ] ; then
TEMPLATE_FILE="$2"
fi
TMPFILE=`mktemp -t miniupnpcstrings`
# detecting the OS name and version
OS_NAME=`uname -s`
OS_VERSION=`uname -r`
@ -49,5 +56,5 @@ sed -e "$EXPR" < $TEMPLATE_FILE > $TMPFILE
EXPR="s|MINIUPNPC_VERSION_STRING \".*\"|MINIUPNPC_VERSION_STRING \"${MINIUPNPC_VERSION}\"|"
echo "setting MINIUPNPC_VERSION_STRING macro value to ${MINIUPNPC_VERSION} in $FILE."
sed -e "$EXPR" < $TMPFILE > $FILE
rm $TMPFILE
rm -v $TMPFILE