1 # $Id: Makefile.linux,v 1.91 2015/10/26 16:53:25 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
30 CFLAGS += -Wextra -Wstrict-prototypes -Wdeclaration-after-statement
31 #CFLAGS += -Wno-missing-field-initializers
32 #CFLAGS += -ansi # iptables headers does use typeof which is a gcc extension
37 PKG_CONFIG ?= pkg-config
41 INSTALLPREFIX ?= $(PREFIX)/usr
42 SBININSTALLDIR = $(INSTALLPREFIX)/sbin
43 ETCINSTALLDIR = $(PREFIX)/etc/miniupnpd
44 MANINSTALLDIR = $(INSTALLPREFIX)/share/man/man8
46 BASEOBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
47 upnpreplyparse.o minixml.o portinuse.o \
48 upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
49 options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \
50 upnpevents.o upnputils.o getconnstatus.o \
51 upnppinhole.o pcplearndscp.o asyncsendto.o
53 LNXOBJS = linux/getifstats.o linux/ifacewatcher.o linux/getroute.o
54 NETFILTEROBJS = netfilter/iptcrdr.o netfilter/iptpinhole.o netfilter/nfct_get.o
56 ALLOBJS = $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS)
58 PCFILE_FOUND := $(shell $(PKG_CONFIG) --exists libiptc; echo $$?)
60 ifeq (${PCFILE_FOUND},0)
62 IPTABLESVERSION := $(shell $(PKG_CONFIG) --modversion libiptc)
63 IPTABLESVERSION1 := $(shell echo $(IPTABLESVERSION) | cut -d. -f1 )
64 IPTABLESVERSION2 := $(shell echo $(IPTABLESVERSION) | cut -d. -f2 )
65 IPTABLESVERSION3 := $(shell echo $(IPTABLESVERSION) | cut -d. -f3 )
66 # test if iptables version >= 1.4.3
67 TEST := $(shell [ \( \( $(IPTABLESVERSION1) -ge 1 \) -a \( $(IPTABLESVERSION2) -ge 4 \) \) -a \( $(IPTABLESVERSION3) -ge 3 \) ] && echo 1 )
69 CPPFLAGS += -DIPTABLES_143
72 CFLAGS += $(shell $(PKG_CONFIG) --cflags libiptc)
73 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libiptc)
74 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libiptc)
75 LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-other libiptc)
78 ifeq "$(wildcard /etc/gentoo-release )" ""
81 # the following is better, at least on gentoo with iptables 1.4.6
82 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1618
83 # and http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=2183
85 CPPFLAGS := -DIPTABLES_143 $(CPPFLAGS)
88 ARCH ?= $(shell uname -m | grep -q "x86_64" && echo 64)
90 CPPFLAGS := $(CPPFLAGS) -I$(IPTABLESPATH)/include/
91 LDFLAGS := $(LDFLAFGS) -L$(IPTABLESPATH)/libiptc/
92 # get iptables version and set IPTABLES_143 macro if needed
93 ifeq ($(TARGET_OPENWRT),)
94 IPTABLESVERSION := $(shell grep "\#define VERSION" $(IPTABLESPATH)/config.h | tr -d \" |cut -d" " -f3 )
95 IPTABLESVERSION1 := $(shell echo $(IPTABLESVERSION) | cut -d. -f1 )
96 IPTABLESVERSION2 := $(shell echo $(IPTABLESVERSION) | cut -d. -f2 )
97 IPTABLESVERSION3 := $(shell echo $(IPTABLESVERSION) | cut -d. -f3 )
98 # test if iptables version >= 1.4.3
99 TEST := $(shell [ \( \( $(IPTABLESVERSION1) -ge 1 \) -a \( $(IPTABLESVERSION2) -ge 4 \) \) -a \( $(IPTABLESVERSION3) -ge 3 \) ] && echo 1 )
101 CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
102 # the following sucks, but works
103 LDLIBS = $(IPTABLESPATH)/libiptc/.libs/libip4tc.o
104 #LDLIBS = $(IPTABLESPATH)/libiptc/.libs/libiptc.a
105 else # ifeq ($(TEST), 1)
106 LDLIBS = $(IPTABLESPATH)/libiptc/libiptc.a
107 endif # ifeq ($(TEST), 1)
108 else # ($(TARGET_OPENWRT),)
110 # check for system-wide iptables files. Test if iptables version >= 1.4.3
111 # the following test has to be verified :
112 TEST := $(shell test -f /usr/include/iptables/internal.h && grep -q "\#define IPTABLES_VERSION" /usr/include/iptables/internal.h && echo 1)
114 CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
117 TEST_LIB := $(shell test -f /usr/lib$(ARCH)/libiptc.a && echo 1)
118 ifeq ($(TEST_LIB), 1)
119 LDLIBS = -liptc /usr/lib$(ARCH)/libiptc.a
120 endif # ($(TEST_LIB), 1)
121 endif # ($(TARGET_OPENWRT),)
122 else # ifdef IPTABLESPATH
123 # IPTABLESPATH not defined
124 # the following test has to be verified :
125 TEST := $(shell test -f /usr/include/xtables.h && grep -q "XTABLES_VERSION_CODE" /usr/include/xtables.h && echo 1)
127 CPPFLAGS := $(CPPFLAGS) -DIPTABLES_143
129 TESTIP4TC := $(shell test -f /lib/libip4tc.so && echo 1)
130 ifeq ($(TESTIP4TC), 1)
131 LDLIBS := $(LDLIBS) -lip4tc
132 endif # ($(TESTIP4TC), 1)
133 TESTIP6TC := $(shell test -f /lib/libip6tc.so && echo 1)
134 ifeq ($(TESTIP6TC), 1)
135 LDLIBS := $(LDLIBS) -lip6tc
136 endif # ($(TESTIP6TC), 1)
138 endif # ifdef IPTABLESPATH
139 endif # ifdef PCFILE_FOUND
141 #LDLIBS += -lnfnetlink
143 TEST := $(shell $(PKG_CONFIG) --atleast-version=1.0.2 libnetfilter_conntrack && $(PKG_CONFIG) --atleast-version=1.0.3 libmnl && echo 1)
145 CPPFLAGS += -DUSE_NFCT
146 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libmnl)
147 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libnetfilter_conntrack)
150 LDLIBS += $(shell $(PKG_CONFIG) --static --libs-only-l libssl)
152 TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o
154 EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
155 testupnppermissions miniupnpdctl testgetifaddr \
156 testgetroute testasyncsendto testportinuse \
159 .PHONY: all clean install depend genuuid
166 $(RM) testupnpdescgen.o testgetifstats.o
167 $(RM) testupnppermissions.o testgetifaddr.o
168 $(RM) testgetroute.o testasyncsendto.o
169 $(RM) testportinuse.o
171 $(RM) validateupnppermissions validategetifaddr validatessdppktgen
173 install: miniupnpd miniupnpd.8 miniupnpd.conf genuuid \
174 netfilter/iptables_init.sh netfilter/iptables_removeall.sh \
175 netfilter/ip6tables_init.sh netfilter/ip6tables_removeall.sh \
176 linux/miniupnpd.init.d.script
178 $(INSTALL) -d $(DESTDIR)$(SBININSTALLDIR)
179 $(INSTALL) miniupnpd $(DESTDIR)$(SBININSTALLDIR)
180 $(INSTALL) -d $(DESTDIR)$(ETCINSTALLDIR)
181 $(INSTALL) netfilter/iptables_init.sh $(DESTDIR)$(ETCINSTALLDIR)
182 $(INSTALL) netfilter/iptables_removeall.sh $(DESTDIR)$(ETCINSTALLDIR)
183 $(INSTALL) netfilter/ip6tables_init.sh $(DESTDIR)$(ETCINSTALLDIR)
184 $(INSTALL) netfilter/ip6tables_removeall.sh $(DESTDIR)$(ETCINSTALLDIR)
185 $(INSTALL) --mode=0644 -b miniupnpd.conf $(DESTDIR)$(ETCINSTALLDIR)
186 $(INSTALL) -d $(DESTDIR)$(PREFIX)/etc/init.d
187 $(INSTALL) linux/miniupnpd.init.d.script $(DESTDIR)$(PREFIX)/etc/init.d/miniupnpd
188 $(INSTALL) -d $(DESTDIR)$(MANINSTALLDIR)
189 $(INSTALL) --mode=0644 miniupnpd.8 $(DESTDIR)$(MANINSTALLDIR)
190 gzip -f $(DESTDIR)$(MANINSTALLDIR)/miniupnpd.8
192 # genuuid is using the uuidgen CLI tool which is part of libuuid
194 # 'cat /proc/sys/kernel/random/uuid' could be also used
196 ifeq ($(TARGET_OPENWRT),)
197 sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`(genuuid||uuidgen||uuid) 2>/dev/null`/" miniupnpd.conf
199 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
202 check: validateupnppermissions validategetifaddr validatessdppktgen
204 validateupnppermissions: testupnppermissions testupnppermissions.sh
205 ./testupnppermissions.sh
208 validategetifaddr: testgetifaddr testgetifaddr.sh
212 validatessdppktgen: testssdppktgen
216 miniupnpd: $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS)
218 testupnpdescgen: $(TESTUPNPDESCGENOBJS)
220 testgetifstats: testgetifstats.o linux/getifstats.o
222 testupnppermissions: testupnppermissions.o upnppermissions.o
224 testgetifaddr: testgetifaddr.o getifaddr.o
226 testgetroute: testgetroute.o linux/getroute.o upnputils.o
228 testssdppktgen: testssdppktgen.o
230 testasyncsendto: testasyncsendto.o asyncsendto.o upnputils.o \
233 testportinuse: testportinuse.o portinuse.o getifaddr.o \
236 miniupnpdctl: miniupnpdctl.o
238 config.h: genconfig.sh VERSION
239 ./genconfig.sh $(CONFIG_OPTIONS)
242 makedepend -f$(MAKEFILE_LIST) -Y \
243 $(ALLOBJS:.o=.c) $(TESTUPNPDESCGENOBJS:.o=.c) \
244 testgetifstats.c testupnppermissions.c testgetifaddr.c \
245 testgetroute.c testasyncsendto.c testportinuse.c \
246 miniupnpdctl.c testssdppktgen.c 2>/dev/null
250 miniupnpd.o: config.h macros.h upnpglobalvars.h upnppermissions.h
251 miniupnpd.o: miniupnpdtypes.h upnphttp.h upnpdescgen.h miniupnpdpath.h
252 miniupnpd.o: getifaddr.h upnpsoap.h options.h minissdp.h upnpredirect.h
253 miniupnpd.o: upnppinhole.h daemonize.h upnpevents.h asyncsendto.h natpmp.h
254 miniupnpd.o: pcpserver.h commonrdr.h upnputils.h ifacewatcher.h
255 upnphttp.o: config.h upnphttp.h upnpdescgen.h miniupnpdpath.h upnpsoap.h
256 upnphttp.o: upnpevents.h upnputils.h
257 upnpdescgen.o: config.h getifaddr.h upnpredirect.h upnpdescgen.h
258 upnpdescgen.o: miniupnpdpath.h upnpglobalvars.h upnppermissions.h
259 upnpdescgen.o: miniupnpdtypes.h upnpdescstrings.h upnpurns.h getconnstatus.h
260 upnpsoap.o: macros.h config.h upnpglobalvars.h upnppermissions.h
261 upnpsoap.o: miniupnpdtypes.h upnphttp.h upnpsoap.h upnpreplyparse.h
262 upnpsoap.o: upnpredirect.h upnppinhole.h getifaddr.h getifstats.h
263 upnpsoap.o: getconnstatus.h upnpurns.h
264 upnpreplyparse.o: upnpreplyparse.h minixml.h
266 portinuse.o: macros.h config.h upnpglobalvars.h upnppermissions.h
267 portinuse.o: miniupnpdtypes.h getifaddr.h portinuse.h netfilter/iptcrdr.h
268 portinuse.o: commonrdr.h
269 upnpredirect.o: macros.h config.h upnpredirect.h upnpglobalvars.h
270 upnpredirect.o: upnppermissions.h miniupnpdtypes.h upnpevents.h portinuse.h
271 upnpredirect.o: netfilter/iptcrdr.h commonrdr.h
272 getifaddr.o: config.h getifaddr.h
273 daemonize.o: daemonize.h config.h
274 upnpglobalvars.o: config.h upnpglobalvars.h upnppermissions.h
275 upnpglobalvars.o: miniupnpdtypes.h upnpdescstrings.h
276 options.o: config.h options.h upnppermissions.h upnpglobalvars.h
277 options.o: miniupnpdtypes.h
278 upnppermissions.o: config.h upnppermissions.h
279 minissdp.o: config.h upnpdescstrings.h miniupnpdpath.h upnphttp.h
280 minissdp.o: upnpglobalvars.h upnppermissions.h miniupnpdtypes.h minissdp.h
281 minissdp.o: upnputils.h getroute.h asyncsendto.h codelength.h
282 natpmp.o: macros.h config.h natpmp.h upnpglobalvars.h upnppermissions.h
283 natpmp.o: miniupnpdtypes.h getifaddr.h upnpredirect.h commonrdr.h upnputils.h
284 natpmp.o: portinuse.h asyncsendto.h
285 pcpserver.o: config.h pcpserver.h macros.h upnpglobalvars.h upnppermissions.h
286 pcpserver.o: miniupnpdtypes.h pcplearndscp.h upnpredirect.h commonrdr.h
287 pcpserver.o: getifaddr.h asyncsendto.h pcp_msg_struct.h netfilter/iptcrdr.h
288 pcpserver.o: commonrdr.h
289 upnpevents.o: config.h upnpevents.h miniupnpdpath.h upnpglobalvars.h
290 upnpevents.o: upnppermissions.h miniupnpdtypes.h upnpdescgen.h upnputils.h
291 upnputils.o: config.h upnputils.h upnpglobalvars.h upnppermissions.h
292 upnputils.o: miniupnpdtypes.h getroute.h
293 getconnstatus.o: getconnstatus.h getifaddr.h
294 upnppinhole.o: macros.h config.h upnpredirect.h upnpglobalvars.h
295 upnppinhole.o: upnppermissions.h miniupnpdtypes.h upnpevents.h
296 upnppinhole.o: netfilter/iptpinhole.h
297 pcplearndscp.o: config.h upnpglobalvars.h upnppermissions.h miniupnpdtypes.h
298 pcplearndscp.o: pcplearndscp.h
299 asyncsendto.o: asyncsendto.h
300 linux/getifstats.o: config.h getifstats.h
301 linux/ifacewatcher.o: config.h ifacewatcher.h config.h minissdp.h
302 linux/ifacewatcher.o: miniupnpdtypes.h getifaddr.h upnpglobalvars.h
303 linux/ifacewatcher.o: upnppermissions.h natpmp.h
304 linux/getroute.o: getroute.h upnputils.h
305 netfilter/iptcrdr.o: macros.h config.h netfilter/iptcrdr.h commonrdr.h
306 netfilter/iptcrdr.o: config.h upnpglobalvars.h upnppermissions.h
307 netfilter/iptcrdr.o: miniupnpdtypes.h
308 netfilter/iptpinhole.o: config.h netfilter/iptpinhole.h upnpglobalvars.h
309 netfilter/iptpinhole.o: upnppermissions.h config.h miniupnpdtypes.h
310 testupnpdescgen.o: macros.h config.h upnpdescgen.h upnpdescstrings.h
311 testupnpdescgen.o: getifaddr.h
312 upnpdescgen.o: config.h getifaddr.h upnpredirect.h upnpdescgen.h
313 upnpdescgen.o: miniupnpdpath.h upnpglobalvars.h upnppermissions.h
314 upnpdescgen.o: miniupnpdtypes.h upnpdescstrings.h upnpurns.h getconnstatus.h
315 testgetifstats.o: getifstats.h
316 testupnppermissions.o: upnppermissions.h config.h
317 testgetifaddr.o: config.h getifaddr.h
318 testgetroute.o: getroute.h upnputils.h upnpglobalvars.h upnppermissions.h
319 testgetroute.o: config.h miniupnpdtypes.h
320 testasyncsendto.o: miniupnpdtypes.h config.h upnputils.h asyncsendto.h
321 testportinuse.o: macros.h config.h portinuse.h
322 miniupnpdctl.o: macros.h
323 testssdppktgen.o: macros.h config.h miniupnpdpath.h upnphttp.h