File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / miniupnpd / miniupnpc / Makefile
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Sep 27 11:25:11 2023 UTC (18 months, 1 week ago) by misho
Branches: miniupnpd, MAIN
CVS tags: v2_3_3p0, HEAD
Version 2.3.3p0

    1: # $Id: Makefile,v 1.1.1.1 2023/09/27 11:25:11 misho Exp $
    2: # MiniUPnP Project
    3: # http://miniupnp.free.fr/
    4: # https://miniupnp.tuxfamily.org/
    5: # https://github.com/miniupnp/miniupnp
    6: # (c) 2005-2022 Thomas Bernard
    7: # to install use :
    8: # $ make DESTDIR=/tmp/dummylocation install
    9: # or
   10: # $ INSTALLPREFIX=/usr/local make install
   11: # or
   12: # $ make install (default INSTALLPREFIX is /usr)
   13: OS = $(shell $(CC) -dumpmachine)
   14: VERSION = $(shell cat VERSION)
   15: 
   16: ifneq (, $(findstring darwin, $(OS)))
   17: JARSUFFIX=mac
   18: LIBTOOL ?= $(shell which libtool)
   19: endif
   20: ifneq (, $(findstring linux, $(OS)))
   21: JARSUFFIX=linux
   22: endif
   23: ifneq (, $(findstring mingw, $(OS))$(findstring cygwin, $(OS))$(findstring msys, $(OS)))
   24: JARSUFFIX=win32
   25: endif
   26: 
   27: HAVE_IPV6 ?= yes
   28: export HAVE_IPV6
   29: 
   30: # directories
   31: INCDIR = include
   32: SRCDIR = src
   33: BUILD = build
   34: 
   35: CC ?= gcc
   36: #AR = gar
   37: #CFLAGS = -O -g
   38: # to debug :
   39: ASANFLAGS = -fsanitize=address -fsanitize=undefined -fsanitize=leak
   40: #CFLAGS = -g -ggdb -O0 $(ASANFLAGS) -fno-omit-frame-pointer
   41: #CPPFLAGS += -DDEBUG
   42: #LDFLAGS += $(ASANFLAGS)
   43: CFLAGS ?= -O
   44: CFLAGS += -Wall
   45: CFLAGS += -W -Wstrict-prototypes
   46: CFLAGS += -fno-common
   47: CPPFLAGS += -I$(BUILD)
   48: CPPFLAGS += -DMINIUPNPC_SET_SOCKET_TIMEOUT
   49: CPPFLAGS += -DMINIUPNPC_GET_SRC_ADDR
   50: CPPFLAGS += -D_BSD_SOURCE
   51: CPPFLAGS += -D_DEFAULT_SOURCE
   52: ifneq (, $(findstring netbsd, $(OS)))
   53: CPPFLAGS += -D_NETBSD_SOURCE
   54: endif
   55: ifeq (, $(findstring freebsd, $(OS))$(findstring darwin, $(OS)))
   56: #CPPFLAGS += -D_POSIX_C_SOURCE=200112L
   57: CPPFLAGS += -D_XOPEN_SOURCE=600
   58: endif
   59: #CFLAGS += -ansi
   60: #CPPFLAGS += -DNO_GETADDRINFO
   61: 
   62: DEPFLAGS = -MM -MG
   63: 
   64: MKDIR = mkdir -p
   65: INSTALL = install
   66: SH = /bin/sh
   67: JAVA = java
   68: # see http://code.google.com/p/jnaerator/
   69: #JNAERATOR = jnaerator-0.9.7.jar
   70: #JNAERATOR = jnaerator-0.9.8-shaded.jar
   71: #JNAERATORARGS = -library miniupnpc
   72: #JNAERATOR = jnaerator-0.10-shaded.jar
   73: #JNAERATOR = jnaerator-0.11-shaded.jar
   74: # https://repo1.maven.org/maven2/com/nativelibs4java/jnaerator/0.12/jnaerator-0.12-shaded.jar
   75: JNAERATOR = jnaerator-0.12-shaded.jar
   76: JNAERATORARGS = -mode StandaloneJar -runtime JNAerator -library miniupnpc
   77: #JNAERATORBASEURL = http://jnaerator.googlecode.com/files/
   78: JNAERATORBASEURL = https://repo1.maven.org/maven2/com/nativelibs4java/jnaerator/0.12
   79: 
   80: ifneq (, $(findstring sun, $(OS))$(findstring solaris, $(OS)))
   81:   LDLIBS=-lsocket -lnsl -lresolv
   82:   CPPFLAGS += -D__EXTENSIONS__
   83:   CFLAGS += -std=c99
   84: endif
   85: 
   86: # APIVERSION is used to build SONAME
   87: APIVERSION = 17
   88: 
   89: SRCS = $(wildcard $(SRCDIR)/*.c)
   90: 
   91: LIBOBJS = $(addprefix $(BUILD)/,miniwget.o minixml.o igd_desc_parse.o minisoap.o \
   92:           miniupnpc.o upnpreplyparse.o upnpcommands.o upnperrors.o \
   93:           connecthostport.o portlistingparse.o receivedata.o upnpdev.o \
   94:           addr_is_reserved.o)
   95: 
   96: BUILDINCLUDES = $(addprefix $(BUILD)/, miniupnpcstrings.h)
   97: 
   98: OBJS = $(patsubst $(SRCDIR)/%.c,$(BUILD)/%.o,$(SRCS))
   99: DEPS = $(patsubst $(SRCDIR)/%.c,$(BUILD)/%.d,$(SRCS))
  100: 
  101: # HEADERS to install
  102: CPPFLAGS += -I$(INCDIR)
  103: HEADERS = $(wildcard $(INCDIR)/*.h)
  104: 
  105: # library names
  106: LIBRARY = $(BUILD)/libminiupnpc.a
  107: ifneq (, $(findstring darwin, $(OS)))
  108:   SHAREDLIBRARY = $(BUILD)/libminiupnpc.dylib
  109:   SONAME = $(notdir $(basename $(SHAREDLIBRARY))).$(APIVERSION).dylib
  110:   CPPFLAGS += -D_DARWIN_C_SOURCE
  111: else
  112: ifeq ($(JARSUFFIX), win32)
  113:   SHAREDLIBRARY = $(BUILD)/miniupnpc.dll
  114: else
  115:   # Linux/BSD/etc.
  116:   SHAREDLIBRARY = $(BUILD)/libminiupnpc.so
  117:   SONAME = $(notdir $(SHAREDLIBRARY)).$(APIVERSION)
  118: endif
  119: endif
  120: 
  121: EXECUTABLES = $(addprefix $(BUILD)/, upnpc-static listdevices)
  122: EXECUTABLES_ADDTESTS = $(addprefix $(BUILD)/, testminixml minixmlvalid \
  123:     testupnpreplyparse testigddescparse testminiwget testportlistingparse)
  124: 
  125: TESTMINIXMLOBJS = $(addprefix $(BUILD)/, minixml.o igd_desc_parse.o testminixml.o)
  126: 
  127: TESTMINIWGETOBJS = $(addprefix $(BUILD)/, miniwget.o testminiwget.o connecthostport.o receivedata.o)
  128: 
  129: TESTUPNPREPLYPARSE = $(addprefix $(BUILD)/, testupnpreplyparse.o minixml.o upnpreplyparse.o)
  130: 
  131: TESTPORTLISTINGPARSE = $(addprefix $(BUILD)/, testportlistingparse.o minixml.o portlistingparse.o)
  132: 
  133: TESTADDR_IS_RESERVED = $(addprefix $(BUILD)/, testaddr_is_reserved.o addr_is_reserved.o)
  134: 
  135: TESTIGDDESCPARSE = $(addprefix $(BUILD)/, testigddescparse.o igd_desc_parse.o minixml.o \
  136:                    miniupnpc.o miniwget.o upnpcommands.o upnpreplyparse.o \
  137:                    minisoap.o connecthostport.o receivedata.o \
  138:                    portlistingparse.o addr_is_reserved.o)
  139: 
  140: ifeq (, $(findstring amiga, $(OS)))
  141: ifeq (, $(findstring mingw, $(OS))$(findstring cygwin, $(OS))$(findstring msys, $(OS)))
  142: CFLAGS += -fPIC
  143: endif
  144: EXECUTABLES += $(BUILD)/upnpc-shared
  145: TESTMINIWGETOBJS += $(BUILD)/minissdpc.o
  146: TESTIGDDESCPARSE += $(BUILD)/minissdpc.o
  147: LIBOBJS += $(BUILD)/minissdpc.o
  148: endif
  149: 
  150: LIBDIR ?= lib
  151: # install directories
  152: ifeq ($(strip $(PREFIX)),)
  153: INSTALLPREFIX ?= /usr
  154: else
  155: INSTALLPREFIX ?= $(PREFIX)
  156: endif
  157: INSTALLDIRINC = $(INSTALLPREFIX)/include/miniupnpc
  158: INSTALLDIRLIB = $(INSTALLPREFIX)/$(LIBDIR)
  159: INSTALLDIRBIN = $(INSTALLPREFIX)/bin
  160: INSTALLDIRMAN = $(INSTALLPREFIX)/share/man
  161: PKGCONFIGDIR = $(INSTALLDIRLIB)/pkgconfig
  162: 
  163: FILESTOINSTALL = $(LIBRARY) $(EXECUTABLES)
  164: ifeq (, $(findstring amiga, $(OS)))
  165: FILESTOINSTALL += $(SHAREDLIBRARY) $(BUILD)/miniupnpc.pc
  166: endif
  167: 
  168: 
  169: .PHONY:	install clean depend all check test everything \
  170: 	installpythonmodule updateversion
  171: 
  172: all:	$(LIBRARY) $(EXECUTABLES)
  173: 
  174: test:	check
  175: 
  176: check:	validateminixml validateminiwget validateupnpreplyparse \
  177: 	validateportlistingparse validateigddescparse validateaddr_is_reserved
  178: 
  179: everything:	all $(EXECUTABLES_ADDTESTS)
  180: 
  181: pythonmodule:	$(LIBRARY) $(SRCDIR)/miniupnpcmodule.c setup.py
  182: 	MAKE=$(MAKE) python setup.py build
  183: 	touch $@
  184: 
  185: installpythonmodule:	pythonmodule
  186: 	MAKE=$(MAKE) python setup.py install
  187: 
  188: pythonmodule3:	$(LIBRARY) $(SRCDIR)/miniupnpcmodule.c setup.py
  189: 	MAKE=$(MAKE) python3 setup.py build
  190: 	touch $@
  191: 
  192: installpythonmodule3:	pythonmodule3
  193: 	MAKE=$(MAKE) python3 setup.py install
  194: 
  195: validateminixml:	$(BUILD)/minixmlvalid
  196: 	@echo "minixml validation test"
  197: 	./$<
  198: 	touch $@
  199: 
  200: validateminiwget:	testminiwget.sh $(BUILD)/testminiwget $(BUILD)/minihttptestserver
  201: 	@echo "miniwget validation test"
  202: 	./$<
  203: 	touch $@
  204: 
  205: validateupnpreplyparse:	testupnpreplyparse.sh $(BUILD)/testupnpreplyparse
  206: 	@echo "upnpreplyparse validation test"
  207: 	./$<
  208: 	touch $@
  209: 
  210: validateportlistingparse:	$(BUILD)/testportlistingparse
  211: 	@echo "portlistingparse validation test"
  212: 	./$<
  213: 	touch $@
  214: 
  215: validateigddescparse:	$(BUILD)/testigddescparse
  216: 	@echo "igd desc parse validation test"
  217: 	./$< testdesc/new_LiveBox_desc.xml testdesc/new_LiveBox_desc.values
  218: 	./$< testdesc/linksys_WAG200G_desc.xml testdesc/linksys_WAG200G_desc.values
  219: 	touch $@
  220: 
  221: validateaddr_is_reserved:	$(BUILD)/testaddr_is_reserved
  222: 	@echo "addr_is_reserved() validation test"
  223: 	./$<
  224: 	touch $@
  225: 
  226: clean:
  227: 	$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) $(BUILDINCLUDES)
  228: 	$(RM) $(EXECUTABLES_ADDTESTS)
  229: 	# clean python stuff
  230: 	$(RM) pythonmodule pythonmodule3
  231: 	$(RM) validateminixml validateminiwget validateupnpreplyparse
  232: 	$(RM) validateigddescparse
  233: 	$(RM) minihttptestserver
  234: 	$(RM) testaddr_is_reserved
  235: 	$(RM) -r build/ dist/
  236: 	#python setup.py clean
  237: 	# clean jnaerator stuff
  238: 	$(RM) _jnaerator.* java/miniupnpc_$(OS).jar
  239: 
  240: distclean: clean
  241: 	$(RM) $(JNAERATOR) java/*.jar java/*.class out.errors.txt
  242: 
  243: updateversion:	include/miniupnpc.h
  244: 	cp $< $<.bak
  245: 	sed 's/\(.*MINIUPNPC_API_VERSION\s\+\)[0-9]\+/\1$(APIVERSION)/' < $<.bak > $<
  246: 
  247: install:	updateversion $(FILESTOINSTALL)
  248: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRINC)
  249: 	$(INSTALL) -m 644 $(HEADERS) $(DESTDIR)$(INSTALLDIRINC)
  250: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRLIB)
  251: 	$(INSTALL) -m 644 $(LIBRARY) $(DESTDIR)$(INSTALLDIRLIB)
  252: ifeq (, $(findstring amiga, $(OS)))
  253: 	$(INSTALL) -m 644 $(SHAREDLIBRARY) $(DESTDIR)$(INSTALLDIRLIB)/$(SONAME)
  254: 	ln -fs $(SONAME) $(DESTDIR)$(INSTALLDIRLIB)/$(notdir $(SHAREDLIBRARY))
  255: 	$(INSTALL) -d $(DESTDIR)$(PKGCONFIGDIR)
  256: 	$(INSTALL) -m 644 $(BUILD)/miniupnpc.pc $(DESTDIR)$(PKGCONFIGDIR)
  257: endif
  258: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRBIN)
  259: ifneq (, $(findstring amiga, $(OS)))
  260: 	$(INSTALL) -m 755 $(BUILD)/upnpc-static $(DESTDIR)$(INSTALLDIRBIN)/upnpc
  261: else
  262: 	$(INSTALL) -m 755 $(BUILD)/upnpc-shared $(DESTDIR)$(INSTALLDIRBIN)/upnpc
  263: endif
  264: 	$(INSTALL) -m 755 external-ip.sh $(DESTDIR)$(INSTALLDIRBIN)/external-ip
  265: ifeq (, $(findstring amiga, $(OS)))
  266: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRMAN)/man3
  267: 	$(INSTALL) -m 644 man3/miniupnpc.3 $(DESTDIR)$(INSTALLDIRMAN)/man3/miniupnpc.3
  268: ifneq (, $(findstring linux, $(OS)))
  269: 	gzip -f $(DESTDIR)$(INSTALLDIRMAN)/man3/miniupnpc.3
  270: endif
  271: endif
  272: 
  273: install-static:	updateversion $(FILESTOINSTALL)
  274: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRINC)
  275: 	$(INSTALL) -m 644 $(HEADERS) $(DESTDIR)$(INSTALLDIRINC)
  276: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRLIB)
  277: 	$(INSTALL) -m 644 $(LIBRARY) $(DESTDIR)$(INSTALLDIRLIB)
  278: 	$(INSTALL) -d $(DESTDIR)$(INSTALLDIRBIN)
  279: 	$(INSTALL) -m 755 external-ip.sh $(DESTDIR)$(INSTALLDIRBIN)/external-ip
  280: 
  281: cleaninstall:
  282: 	$(RM) -r $(DESTDIR)$(INSTALLDIRINC)
  283: 	$(RM) $(DESTDIR)$(INSTALLDIRLIB)/$(LIBRARY)
  284: 	$(RM) $(DESTDIR)$(INSTALLDIRLIB)/$(SHAREDLIBRARY)
  285: 
  286: $(BUILD)/miniupnpc.pc:	VERSION
  287: 	@$(MKDIR) $(@D)
  288: 	$(RM) $@
  289: 	echo "prefix=$(INSTALLPREFIX)" >> $@
  290: 	echo "exec_prefix=\$${prefix}" >> $@
  291: 	echo "libdir=\$${exec_prefix}/$(LIBDIR)" >> $@
  292: 	echo "includedir=\$${prefix}/include" >> $@
  293: 	echo "" >> $@
  294: 	echo "Name: miniUPnPc" >> $@
  295: 	echo "Description: UPnP IGD client lightweight library" >> $@
  296: 	echo "URL: https://miniupnp.tuxfamily.org/" >> $@
  297: 	echo "Version: $(VERSION)" >> $@
  298: 	echo "Libs: -L\$${libdir} -lminiupnpc" >> $@
  299: 	echo "Cflags: -I\$${includedir}" >> $@
  300: 
  301: depend:	$(DEPS)
  302: 
  303: $(LIBRARY):	$(LIBOBJS)
  304: ifneq (, $(findstring darwin, $(OS)))
  305: 	$(LIBTOOL) -static -o $@ $?
  306: else
  307: 	$(AR) crs $@ $?
  308: endif
  309: 
  310: $(SHAREDLIBRARY):	$(LIBOBJS)
  311: ifneq (, $(findstring darwin, $(OS)))
  312: #	$(CC) -dynamiclib $(LDFLAGS) -Wl,-install_name,$(SONAME) -o $@ $^
  313: 	$(CC) -dynamiclib $(LDFLAGS) -Wl,-install_name,$(INSTALLDIRLIB)/$(SONAME) -o $@ $^
  314: else
  315: 	$(CC) -shared $(LDFLAGS) -Wl,-soname,$(SONAME) -o $@ $^
  316: endif
  317: 
  318: $(BUILD)/%.o:	$(SRCDIR)/%.c $(BUILD)/%.d
  319: 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
  320: 
  321: $(DEPS):	$(BUILDINCLUDES)
  322: 
  323: $(BUILD)/%.d:	$(SRCDIR)/%.c
  324: 	@$(MKDIR) $(@D)
  325: 	$(CC) $(CPPFLAGS) $(DEPFLAGS) -MT $@ -o $@ $<
  326: 
  327: $(BUILD)/upnpc-static:	$(BUILD)/upnpc.o $(LIBRARY)
  328: 	$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
  329: 
  330: $(BUILD)/upnpc-shared:	$(BUILD)/upnpc.o $(SHAREDLIBRARY)
  331: 	$(CC) $(LDFLAGS) -o $@ $^ $(LOADLIBES) $(LDLIBS)
  332: 
  333: $(BUILD)/listdevices:	$(BUILD)/listdevices.o $(LIBRARY)
  334: 
  335: $(BUILD)/testminixml:	$(TESTMINIXMLOBJS)
  336: 
  337: $(BUILD)/testminiwget:	$(TESTMINIWGETOBJS)
  338: 
  339: $(BUILD)/minixmlvalid:	$(addprefix $(BUILD)/, minixml.o minixmlvalid.o)
  340: 
  341: $(BUILD)/testupnpreplyparse:	$(TESTUPNPREPLYPARSE)
  342: 
  343: $(BUILD)/testigddescparse:	$(TESTIGDDESCPARSE)
  344: 
  345: $(BUILD)/testportlistingparse:	$(TESTPORTLISTINGPARSE)
  346: 
  347: $(BUILD)/testaddr_is_reserved:	$(TESTADDR_IS_RESERVED)
  348: 
  349: $(BUILD)/miniupnpcstrings.h:	miniupnpcstrings.h.in updateminiupnpcstrings.sh VERSION
  350: 	@$(MKDIR) $(@D)
  351: 	$(SH) updateminiupnpcstrings.sh $@ $<
  352: 
  353: # ftp tool supplied with OpenBSD can download files from http.
  354: jnaerator-%.jar:
  355: 	wget $(JNAERATORBASEURL)/$@ || \
  356: 	curl -o $@ $(JNAERATORBASEURL)/$@ || \
  357: 	ftp $(JNAERATORBASEURL)/$@
  358: 
  359: jar: $(SHAREDLIBRARY)  $(JNAERATOR)
  360: 	$(JAVA) -jar $(JNAERATOR) $(JNAERATORARGS) \
  361: 	miniupnpc.h miniupnpc_declspec.h upnpcommands.h upnpreplyparse.h \
  362: 	igd_desc_parse.h miniwget.h upnperrors.h $(SHAREDLIBRARY) \
  363: 	-package fr.free.miniupnp -o . -jar java/miniupnpc_$(JARSUFFIX).jar -v
  364: 
  365: mvn_install:
  366: 	mvn install:install-file -Dfile=java/miniupnpc_$(JARSUFFIX).jar \
  367: 	 -DgroupId=com.github \
  368: 	 -DartifactId=miniupnp \
  369: 	 -Dversion=$(VERSION) \
  370: 	 -Dpackaging=jar \
  371: 	 -Dclassifier=$(JARSUFFIX) \
  372: 	 -DgeneratePom=true \
  373: 	 -DcreateChecksum=true
  374: 
  375: # make .deb packages
  376: deb: /usr/share/pyshared/stdeb all
  377: 	(python setup.py --command-packages=stdeb.command bdist_deb)
  378: 
  379: # install .deb packages
  380: ideb:
  381: 	(sudo dpkg -i deb_dist/*.deb)
  382: 
  383: /usr/share/pyshared/stdeb: /usr/share/doc/python-all-dev
  384: 	(sudo apt-get install python-stdeb)
  385: 
  386: /usr/share/doc/python-all-dev:
  387: 	(sudo apt-get install python-all-dev)
  388: 
  389: minihttptestserver:	minihttptestserver.o
  390: 
  391: print-%:
  392: 	@echo "$* = $($*)"
  393: 
  394: ifneq ($(MAKECMDGOALS),clean)
  395: -include $(DEPS)
  396: endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>