1 # $Id: Makefile.linux,v 1.94 2016/04/18 09:06:42 nanard Exp $
3 # (c) 2006-2015 Thomas Bernard
4 # http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5 # Author : Thomas Bernard
6 # for use with GNU Make
8 # options can be passed to genconfig.sh through CONFIG_OPTIONS :
9 # $ CONFIG_OPTIONS="--ipv6 --igd2" make -f Makefile.linux
12 # $ DESTDIR=/dummyinstalldir make -f Makefile.linux install
14 # $ INSTALLPREFIX=/usr/local make -f Makefile.linux install
16 # $ make -f Makefile.linux install
17 # (default INSTALLPREFIX is /usr)
19 # if your system hasn't iptables libiptc headers and binary correctly
20 # installed, you need to get iptables sources from http://netfilter.org/
21 # ./configure them and build them then miniupnpd will build using :
22 # $ IPTABLESPATH=/path/to/iptables-1.4.1 make -f Makefile.linux
24 #CFLAGS = -O -g -DDEBUG
26 CFLAGS += -fno-strict-aliasing
28 CPPFLAGS += -D_GNU_SOURCE
29 CFLAGS += $(EXTRACFLAGS)
31 CFLAGS += -Wextra -Wstrict-prototypes -Wdeclaration-after-statement
32 #CFLAGS += -Wno-missing-field-initializers
33 #CFLAGS += -ansi # iptables headers does use typeof which is a gcc extension
38 PKG_CONFIG ?= pkg-config
42 INSTALLPREFIX ?= $(PREFIX)/usr
43 SBININSTALLDIR = $(INSTALLPREFIX)/sbin
44 ETCINSTALLDIR = $(PREFIX)/etc/miniupnpd
45 MANINSTALLDIR = $(INSTALLPREFIX)/share/man/man8
47 BASEOBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
48 upnpreplyparse.o minixml.o portinuse.o \
49 upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
50 options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \
51 upnpevents.o upnputils.o getconnstatus.o \
52 upnppinhole.o pcplearndscp.o asyncsendto.o
54 LNXOBJS = linux/getifstats.o linux/ifacewatcher.o linux/getroute.o
55 NETFILTEROBJS = netfilter/iptcrdr.o netfilter/iptpinhole.o netfilter/nfct_get.o
57 ALLOBJS = $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS)
59 PCFILE_FOUND := $(shell $(PKG_CONFIG) --exists libiptc; echo $$?)
61 ifeq (${PCFILE_FOUND},0)
63 IPTABLESVERSION := $(shell $(PKG_CONFIG) --modversion libiptc)
64 IPTVER1 := $(shell echo $(IPTABLESVERSION) | cut -d. -f1 )
65 IPTVER2 := $(shell echo $(IPTABLESVERSION) | cut -d. -f2 )
66 IPTVER3 := $(shell echo $(IPTABLESVERSION) | cut -d. -f3 )
67 # test if iptables version >= 1.4.3
68 TEST := $(shell [ $(IPTVER1) -gt 1 ] || \
69 [ \( $(IPTVER1) -eq 1 \) -a \
70 \( \( $(IPTVER2) -gt 4 \) -o \
71 \( \( $(IPTVER2) -eq 4 \) -a \( $(IPTVER3) -ge 3 \) \) \) ] && echo 1 )
73 CPPFLAGS += -DIPTABLES_143
76 CFLAGS += $(shell $(PKG_CONFIG) --cflags libiptc)
77 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libiptc)
78 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libiptc)
79 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-other libiptc)
82 ifeq "$(wildcard /etc/gentoo-release )" ""
85 # the following is better, at least on gentoo with iptables 1.4.6
86 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1618
87 # and http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=2183
89 CPPFLAGS := -DIPTABLES_143 $(CPPFLAGS)
92 ARCH ?= $(shell uname -m | grep -q "x86_64" && echo 64)
94 CPPFLAGS := $(CPPFLAGS) -I$(IPTABLESPATH)/include/
95 LDFLAGS := $(LDFLAFGS) -L$(IPTABLESPATH)/libiptc/
96 # get iptables version and set IPTABLES_143 macro if needed
97 ifeq ($(TARGET_OPENWRT),)
98 IPTABLESVERSION := $(shell grep "\#define VERSION" $(IPTABLESPATH)/config.h | tr -d \" |cut -d" " -f3 )
99 IPTVER1 := $(shell echo $(IPTABLESVERSION) | cut -d. -f1 )
100 IPTVER2 := $(shell echo $(IPTABLESVERSION) | cut -d. -f2 )
101 IPTVER3 := $(shell echo $(IPTABLESVERSION) | cut -d. -f3 )
102 # test if iptables version >= 1.4.3
103 TEST := $(shell [ $(IPTVER1) -gt 1 ] || \
104 [ \( $(IPTVER1) -eq 1 \) -a \
105 \( \( $(IPTVER2) -gt 4 \) -o \
106 \( \( $(IPTVER2) -eq 4 \) -a \( $(IPTVER3) -ge 3 \) \) \) ] && echo 1 )
108 CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
109 # the following sucks, but works
110 LDLIBS = $(IPTABLESPATH)/libiptc/.libs/libip4tc.o
111 #LDLIBS = $(IPTABLESPATH)/libiptc/.libs/libiptc.a
112 else # ifeq ($(TEST), 1)
113 LDLIBS = $(IPTABLESPATH)/libiptc/libiptc.a
114 endif # ifeq ($(TEST), 1)
115 else # ($(TARGET_OPENWRT),)
117 # check for system-wide iptables files. Test if iptables version >= 1.4.3
118 # the following test has to be verified :
119 TEST := $(shell test -f /usr/include/iptables/internal.h && grep -q "\#define IPTABLES_VERSION" /usr/include/iptables/internal.h && echo 1)
121 CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
124 TEST_LIB := $(shell test -f /usr/lib$(ARCH)/libiptc.a && echo 1)
125 ifeq ($(TEST_LIB), 1)
126 LDLIBS = -liptc /usr/lib$(ARCH)/libiptc.a
127 endif # ($(TEST_LIB), 1)
128 endif # ($(TARGET_OPENWRT),)
129 else # ifdef IPTABLESPATH
130 # IPTABLESPATH not defined
131 # the following test has to be verified :
132 TEST := $(shell test -f /usr/include/xtables.h && grep -q "XTABLES_VERSION_CODE" /usr/include/xtables.h && echo 1)
134 CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
136 TESTIP4TC := $(shell test -f /lib/libip4tc.so && echo 1)
137 ifeq ($(TESTIP4TC), 1)
138 LDLIBS := $(LDLIBS) -lip4tc
139 endif # ($(TESTIP4TC), 1)
140 TESTIP6TC := $(shell test -f /lib/libip6tc.so && echo 1)
141 ifeq ($(TESTIP6TC), 1)
142 LDLIBS := $(LDLIBS) -lip6tc
143 endif # ($(TESTIP6TC), 1)
145 endif # ifdef IPTABLESPATH
146 endif # ifdef PCFILE_FOUND
148 #LDLIBS += -lnfnetlink
150 TEST := $(shell $(PKG_CONFIG) --atleast-version=1.0.2 libnetfilter_conntrack && $(PKG_CONFIG) --atleast-version=1.0.3 libmnl && echo 1)
152 CPPFLAGS += -DUSE_NFCT
153 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libmnl)
154 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libnetfilter_conntrack)
157 #LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libssl)
159 TEST := $(shell $(PKG_CONFIG) --exists uuid && echo 1)
161 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l uuid)
163 $(info please install uuid-dev package / libuuid)
166 TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o
168 EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
169 testupnppermissions miniupnpdctl testgetifaddr \
170 testgetroute testasyncsendto testportinuse \
173 .PHONY: all clean install depend genuuid
180 $(RM) testupnpdescgen.o testgetifstats.o
181 $(RM) testupnppermissions.o testgetifaddr.o
182 $(RM) testgetroute.o testasyncsendto.o
183 $(RM) testportinuse.o
185 $(RM) validateupnppermissions validategetifaddr validatessdppktgen
187 install: miniupnpd miniupnpd.8 miniupnpd.conf genuuid \
188 netfilter/iptables_init.sh netfilter/iptables_removeall.sh \
189 netfilter/ip6tables_init.sh netfilter/ip6tables_removeall.sh \
190 linux/miniupnpd.init.d.script
192 $(INSTALL) -d $(DESTDIR)$(SBININSTALLDIR)
193 $(INSTALL) miniupnpd $(DESTDIR)$(SBININSTALLDIR)
194 $(INSTALL) -d $(DESTDIR)$(ETCINSTALLDIR)
195 $(INSTALL) netfilter/iptables_init.sh $(DESTDIR)$(ETCINSTALLDIR)
196 $(INSTALL) netfilter/iptables_removeall.sh $(DESTDIR)$(ETCINSTALLDIR)
197 $(INSTALL) netfilter/ip6tables_init.sh $(DESTDIR)$(ETCINSTALLDIR)
198 $(INSTALL) netfilter/ip6tables_removeall.sh $(DESTDIR)$(ETCINSTALLDIR)
199 $(INSTALL) --mode=0644 -b miniupnpd.conf $(DESTDIR)$(ETCINSTALLDIR)
200 $(INSTALL) -d $(DESTDIR)$(PREFIX)/etc/init.d
201 $(INSTALL) linux/miniupnpd.init.d.script $(DESTDIR)$(PREFIX)/etc/init.d/miniupnpd
202 $(INSTALL) -d $(DESTDIR)$(MANINSTALLDIR)
203 $(INSTALL) --mode=0644 miniupnpd.8 $(DESTDIR)$(MANINSTALLDIR)
204 gzip -f $(DESTDIR)$(MANINSTALLDIR)/miniupnpd.8
206 # genuuid is using the uuidgen CLI tool which is part of libuuid
208 # 'cat /proc/sys/kernel/random/uuid' could be also used
210 ifeq ($(TARGET_OPENWRT),)
211 sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`(genuuid||uuidgen||uuid) 2>/dev/null`/" miniupnpd.conf
213 sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`($(STAGING_DIR_HOST)/bin/genuuid||$(STAGING_DIR_HOST)/bin/uuidgen||$(STAGING_DIR_HOST)/bin/uuid) 2>/dev/null`/" miniupnpd.conf
216 check: validateupnppermissions validategetifaddr validatessdppktgen
218 validateupnppermissions: testupnppermissions testupnppermissions.sh
219 ./testupnppermissions.sh
222 validategetifaddr: testgetifaddr testgetifaddr.sh
226 validatessdppktgen: testssdppktgen
230 miniupnpd: $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS)
232 testupnpdescgen: $(TESTUPNPDESCGENOBJS)
234 testgetifstats: testgetifstats.o linux/getifstats.o
236 testupnppermissions: testupnppermissions.o upnppermissions.o
238 testgetifaddr: testgetifaddr.o getifaddr.o
240 testgetroute: testgetroute.o linux/getroute.o upnputils.o
242 testssdppktgen: testssdppktgen.o
244 testasyncsendto: testasyncsendto.o asyncsendto.o upnputils.o \
247 testportinuse: testportinuse.o portinuse.o getifaddr.o \
250 miniupnpdctl: miniupnpdctl.o
252 config.h: genconfig.sh VERSION
253 ./genconfig.sh $(CONFIG_OPTIONS)
256 makedepend -f$(MAKEFILE_LIST) -Y \
257 $(ALLOBJS:.o=.c) $(TESTUPNPDESCGENOBJS:.o=.c) \
258 testgetifstats.c testupnppermissions.c testgetifaddr.c \
259 testgetroute.c testasyncsendto.c testportinuse.c \
260 miniupnpdctl.c testssdppktgen.c 2>/dev/null
264 miniupnpd.o: config.h macros.h upnpglobalvars.h upnppermissions.h
265 miniupnpd.o: miniupnpdtypes.h upnphttp.h upnpdescgen.h miniupnpdpath.h
266 miniupnpd.o: getifaddr.h upnpsoap.h options.h minissdp.h upnpredirect.h
267 miniupnpd.o: upnppinhole.h daemonize.h upnpevents.h asyncsendto.h natpmp.h
268 miniupnpd.o: pcpserver.h commonrdr.h upnputils.h ifacewatcher.h
269 upnphttp.o: config.h upnphttp.h upnpdescgen.h miniupnpdpath.h upnpsoap.h
270 upnphttp.o: upnpevents.h upnputils.h
271 upnpdescgen.o: config.h getifaddr.h upnpredirect.h upnpdescgen.h
272 upnpdescgen.o: miniupnpdpath.h upnpglobalvars.h upnppermissions.h
273 upnpdescgen.o: miniupnpdtypes.h upnpdescstrings.h upnpurns.h getconnstatus.h
274 upnpsoap.o: macros.h config.h upnpglobalvars.h upnppermissions.h
275 upnpsoap.o: miniupnpdtypes.h upnphttp.h upnpsoap.h upnpreplyparse.h
276 upnpsoap.o: upnpredirect.h upnppinhole.h getifaddr.h getifstats.h
277 upnpsoap.o: getconnstatus.h upnpurns.h
278 upnpreplyparse.o: upnpreplyparse.h minixml.h
280 portinuse.o: macros.h config.h upnpglobalvars.h upnppermissions.h
281 portinuse.o: miniupnpdtypes.h getifaddr.h portinuse.h netfilter/iptcrdr.h
282 portinuse.o: commonrdr.h
283 upnpredirect.o: macros.h config.h upnpredirect.h upnpglobalvars.h
284 upnpredirect.o: upnppermissions.h miniupnpdtypes.h upnpevents.h portinuse.h
285 upnpredirect.o: netfilter/iptcrdr.h commonrdr.h
286 getifaddr.o: config.h getifaddr.h
287 daemonize.o: daemonize.h config.h
288 upnpglobalvars.o: config.h upnpglobalvars.h upnppermissions.h
289 upnpglobalvars.o: miniupnpdtypes.h upnpdescstrings.h
290 options.o: config.h options.h upnppermissions.h upnpglobalvars.h
291 options.o: miniupnpdtypes.h
292 upnppermissions.o: config.h upnppermissions.h
293 minissdp.o: config.h upnpdescstrings.h miniupnpdpath.h upnphttp.h
294 minissdp.o: upnpglobalvars.h upnppermissions.h miniupnpdtypes.h minissdp.h
295 minissdp.o: upnputils.h getroute.h asyncsendto.h codelength.h
296 natpmp.o: macros.h config.h natpmp.h upnpglobalvars.h upnppermissions.h
297 natpmp.o: miniupnpdtypes.h getifaddr.h upnpredirect.h commonrdr.h upnputils.h
298 natpmp.o: portinuse.h asyncsendto.h
299 pcpserver.o: config.h pcpserver.h macros.h upnpglobalvars.h upnppermissions.h
300 pcpserver.o: miniupnpdtypes.h pcplearndscp.h upnpredirect.h commonrdr.h
301 pcpserver.o: getifaddr.h asyncsendto.h pcp_msg_struct.h netfilter/iptcrdr.h
302 pcpserver.o: commonrdr.h
303 upnpevents.o: config.h upnpevents.h miniupnpdpath.h upnpglobalvars.h
304 upnpevents.o: upnppermissions.h miniupnpdtypes.h upnpdescgen.h upnputils.h
305 upnputils.o: config.h upnputils.h upnpglobalvars.h upnppermissions.h
306 upnputils.o: miniupnpdtypes.h getroute.h
307 getconnstatus.o: getconnstatus.h getifaddr.h
308 upnppinhole.o: macros.h config.h upnpredirect.h upnpglobalvars.h
309 upnppinhole.o: upnppermissions.h miniupnpdtypes.h upnpevents.h
310 upnppinhole.o: netfilter/iptpinhole.h
311 pcplearndscp.o: config.h upnpglobalvars.h upnppermissions.h miniupnpdtypes.h
312 pcplearndscp.o: pcplearndscp.h
313 asyncsendto.o: asyncsendto.h
314 linux/getifstats.o: config.h getifstats.h
315 linux/ifacewatcher.o: config.h ifacewatcher.h config.h minissdp.h
316 linux/ifacewatcher.o: miniupnpdtypes.h getifaddr.h upnpglobalvars.h
317 linux/ifacewatcher.o: upnppermissions.h natpmp.h
318 linux/getroute.o: getroute.h upnputils.h
319 netfilter/iptcrdr.o: macros.h config.h netfilter/iptcrdr.h commonrdr.h
320 netfilter/iptcrdr.o: config.h upnpglobalvars.h upnppermissions.h
321 netfilter/iptcrdr.o: miniupnpdtypes.h
322 netfilter/iptpinhole.o: config.h netfilter/iptpinhole.h upnpglobalvars.h
323 netfilter/iptpinhole.o: upnppermissions.h config.h miniupnpdtypes.h
324 testupnpdescgen.o: macros.h config.h upnpdescgen.h upnpdescstrings.h
325 testupnpdescgen.o: getifaddr.h
326 upnpdescgen.o: config.h getifaddr.h upnpredirect.h upnpdescgen.h
327 upnpdescgen.o: miniupnpdpath.h upnpglobalvars.h upnppermissions.h
328 upnpdescgen.o: miniupnpdtypes.h upnpdescstrings.h upnpurns.h getconnstatus.h
329 testgetifstats.o: getifstats.h
330 testupnppermissions.o: upnppermissions.h config.h
331 testgetifaddr.o: config.h getifaddr.h
332 testgetroute.o: getroute.h upnputils.h upnpglobalvars.h upnppermissions.h
333 testgetroute.o: config.h miniupnpdtypes.h
334 testasyncsendto.o: miniupnpdtypes.h config.h upnputils.h asyncsendto.h
335 testportinuse.o: macros.h config.h portinuse.h
336 miniupnpdctl.o: macros.h
337 testssdppktgen.o: macros.h config.h miniupnpdpath.h upnphttp.h