1 # $Id: Makefile.linux,v 1.53 2011/03/09 15:22:46 nanard Exp $
3 # http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 # Author : Thomas Bernard
5 # for use with GNU Make
8 # $ PREFIX=/dummyinstalldir make -f Makefile.linux install
10 # $ INSTALLPREFIX=/usr/local make -f Makefile.linux install
12 # $ make -f Makefile.linux install
14 # if your system hasn't iptables libiptc headers and binary correctly
15 # installed, you need to get iptables sources from http://netfilter.org/
16 # ./configure them and build them then miniupnpd will build using :
17 # $ IPTABLESPATH=/path/to/iptables-1.4.1 make -f Makefile.linux
19 #CFLAGS = -Wall -O -D_GNU_SOURCE -g -DDEBUG
20 CFLAGS ?= -Wall -Os -D_GNU_SOURCE
27 INSTALLPREFIX ?= $(PREFIX)/usr
28 SBININSTALLDIR = $(INSTALLPREFIX)/sbin
29 ETCINSTALLDIR = $(PREFIX)/etc/miniupnpd
31 BASEOBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
32 upnpreplyparse.o minixml.o \
33 upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
34 options.o upnppermissions.o minissdp.o natpmp.o \
37 LNXOBJS = linux/getifstats.o
38 NETFILTEROBJS = netfilter/iptcrdr.o
40 ALLOBJS = $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS)
43 # the following is better, at least on gentoo with iptables 1.4.6
44 # see http://miniupnp.tuxfamily.org/forum/viewtopic.php?p=1618
47 ARCH ?= $(shell uname -m | grep -q "x86_64" && echo 64)
49 CFLAGS := $(CFLAGS) -I$(IPTABLESPATH)/include/
50 LDFLAGS := $(LDFLAFGS) -L$(IPTABLESPATH)/libiptc/
51 # get iptables version and set IPTABLES_143 macro if needed
52 ifeq ($(TARGET_OPENWRT),)
53 IPTABLESVERSION := $(shell grep "\#define VERSION" $(IPTABLESPATH)/config.h | tr -d \" |cut -d" " -f3 )
54 IPTABLESVERSION1 := $(shell echo $(IPTABLESVERSION) | cut -d. -f1 )
55 IPTABLESVERSION2 := $(shell echo $(IPTABLESVERSION) | cut -d. -f2 )
56 IPTABLESVERSION3 := $(shell echo $(IPTABLESVERSION) | cut -d. -f3 )
57 # test if iptables version >= 1.4.3
58 TEST := $(shell [ \( \( $(IPTABLESVERSION1) -ge 1 \) -a \( $(IPTABLESVERSION2) -ge 4 \) \) -a \( $(IPTABLESVERSION3) -ge 3 \) ] && echo 1 )
60 CFLAGS := $(CFLAGS) -DIPTABLES_143
61 # the following sucks, but works
62 #LIBS = $(IPTABLESPATH)/libiptc/.libs/libip4tc.o
63 LIBS = $(IPTABLESPATH)/libiptc/.libs/libiptc.a
65 LIBS = $(IPTABLESPATH)/libiptc/libiptc.a
68 # check for system-wide iptables files. Test if iptables version >= 1.4.3
69 TEST := $(shell test -f /usr/include/iptables/internal.h && grep -q "\#define IPTABLES_VERSION" /usr/include/iptables/internal.h && echo 1)
71 CFLAGS := $(CFLAGS) -DIPTABLES_143
73 TEST_LIB := $(shell test -f /usr/lib$(ARCH)/libiptc.a && echo 1)
75 LIBS = -liptc /usr/lib$(ARCH)/libiptc.a
81 TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o
83 EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
84 testupnppermissions miniupnpdctl testgetifaddr
86 .PHONY: all clean install depend genuuid
93 $(RM) testupnpdescgen.o testgetifstats.o
94 $(RM) testupnppermissions.o testgetifaddr.o
97 install: miniupnpd genuuid
99 $(INSTALL) -d $(SBININSTALLDIR)
100 $(INSTALL) miniupnpd $(SBININSTALLDIR)
101 $(INSTALL) -d $(ETCINSTALLDIR)
102 $(INSTALL) netfilter/iptables_init.sh $(ETCINSTALLDIR)
103 $(INSTALL) netfilter/iptables_removeall.sh $(ETCINSTALLDIR)
104 $(INSTALL) --mode=0644 -b miniupnpd.conf $(ETCINSTALLDIR)
105 $(INSTALL) -d $(PREFIX)/etc/init.d
106 $(INSTALL) linux/miniupnpd.init.d.script $(PREFIX)/etc/init.d/miniupnpd
108 # genuuid is using the uuidgen CLI tool which is part of libuuid
111 ifeq ($(TARGET_OPENWRT),)
112 sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`(genuuid||uuidgen) 2>/dev/null`/" miniupnpd.conf
114 sed -i -e "s/^uuid=[-0-9a-f]*/uuid=`($(STAGING_DIR_HOST)/bin/genuuid||$(STAGING_DIR_HOST)/bin/uuidgen) 2>/dev/null`/" miniupnpd.conf
117 miniupnpd: $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS) $(LIBS)
119 testupnpdescgen: $(TESTUPNPDESCGENOBJS)
121 testgetifstats: testgetifstats.o linux/getifstats.o
123 testupnppermissions: testupnppermissions.o upnppermissions.o
125 testgetifaddr: testgetifaddr.o getifaddr.o
127 miniupnpdctl: miniupnpdctl.o
129 config.h: genconfig.sh
133 makedepend -f$(MAKEFILE_LIST) -Y \
134 $(ALLOBJS:.o=.c) $(TESTUPNPDESCGENOBJS:.o=.c) \
135 testgetifstats.c 2>/dev/null
139 miniupnpd.o: config.h upnpglobalvars.h upnppermissions.h miniupnpdtypes.h
140 miniupnpd.o: upnphttp.h upnpdescgen.h miniupnpdpath.h getifaddr.h upnpsoap.h
141 miniupnpd.o: options.h minissdp.h upnpredirect.h daemonize.h upnpevents.h
142 miniupnpd.o: natpmp.h commonrdr.h
143 upnphttp.o: config.h upnphttp.h upnpdescgen.h miniupnpdpath.h upnpsoap.h
144 upnphttp.o: upnpevents.h
145 upnpdescgen.o: config.h upnpdescgen.h miniupnpdpath.h upnpglobalvars.h
146 upnpdescgen.o: upnppermissions.h miniupnpdtypes.h upnpdescstrings.h
147 upnpsoap.o: config.h upnpglobalvars.h upnppermissions.h miniupnpdtypes.h
148 upnpsoap.o: upnphttp.h upnpsoap.h upnpreplyparse.h upnpredirect.h getifaddr.h
149 upnpsoap.o: getifstats.h
150 upnpreplyparse.o: upnpreplyparse.h minixml.h
152 upnpredirect.o: config.h upnpredirect.h upnpglobalvars.h upnppermissions.h
153 upnpredirect.o: miniupnpdtypes.h upnpevents.h netfilter/iptcrdr.h commonrdr.h
154 getifaddr.o: getifaddr.h
155 daemonize.o: daemonize.h config.h
156 upnpglobalvars.o: config.h upnpglobalvars.h upnppermissions.h
157 upnpglobalvars.o: miniupnpdtypes.h
158 options.o: options.h config.h upnppermissions.h upnpglobalvars.h
159 options.o: miniupnpdtypes.h
160 upnppermissions.o: config.h upnppermissions.h
161 minissdp.o: config.h upnpdescstrings.h miniupnpdpath.h upnphttp.h
162 minissdp.o: upnpglobalvars.h upnppermissions.h miniupnpdtypes.h minissdp.h
163 minissdp.o: codelength.h
164 natpmp.o: config.h natpmp.h upnpglobalvars.h upnppermissions.h
165 natpmp.o: miniupnpdtypes.h getifaddr.h upnpredirect.h commonrdr.h
166 upnpevents.o: config.h upnpevents.h miniupnpdpath.h upnpglobalvars.h
167 upnpevents.o: upnppermissions.h miniupnpdtypes.h upnpdescgen.h
168 linux/getifstats.o: getifstats.h config.h
169 netfilter/iptcrdr.o: netfilter/iptcrdr.h commonrdr.h config.h
170 netfilter/iptcrdr.o: upnpglobalvars.h upnppermissions.h miniupnpdtypes.h
171 testupnpdescgen.o: config.h upnpdescgen.h
172 upnpdescgen.o: config.h upnpdescgen.h miniupnpdpath.h upnpglobalvars.h
173 upnpdescgen.o: upnppermissions.h miniupnpdtypes.h upnpdescstrings.h
174 testgetifstats.o: getifstats.h