TOR: fix compilation
[tomato.git] / release / src / router / miniupnpd / Makefile
blobe858a04d73ca8305bc141b9be0dff03d7fb740c9
1 # $Id: Makefile,v 1.88 2016/02/10 20:32:43 nanard Exp $
2 # MiniUPnP project
3 # http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
4 # Author: Thomas Bernard
6 # Makefile for miniupnpd (MiniUPnP daemon)
8 # This Makefile should work for *BSD and SunOS/Solaris.
9 # On Mac OS X, use "bsdmake" to build.
10 # This Makefile is NOT compatible with GNU Make.
11 # Linux users, please use Makefile.linux :
12 # make -f Makefile.linux
14 # options can be passed to genconfig.sh through CONFIG_OPTIONS :
15 # $ CONFIG_OPTIONS="--ipv6 --igd2" make
18 CFLAGS ?= -pipe -Os
19 #CFLAGS = -pipe -O -g -DDEBUG
20 #CFLAGS += -ansi
21 CFLAGS += -Wall
22 CFLAGS += -W
23 CFLAGS += -Wstrict-prototypes
24 #CFLAGS += -Wdeclaration-after-statement
25 #CFLAGS += -Wno-missing-field-initializers
26 CFLAGS += -fno-common
27 CC ?= gcc
28 RM = rm -f
29 MV = mv
30 INSTALL = install
31 STRIP = strip
33 # OSNAME and FWNAME are used for building OS or FW dependent code.
34 OSNAME != uname -s
35 ARCH != uname -m
36 .ifndef FWNAME
37 #.if exists(/usr/include/net/pfvar.h)
38 #FWNAME = pf
39 #.else
40 #FWNAME = ipf
41 #.endif
43 .if $(OSNAME) == "OpenBSD"
44 FWNAME = pf
45 .endif
47 # better way to find if we are using ipf or pf
48 .if $(OSNAME) == "FreeBSD"
49 .if exists(/etc/rc.subr) && exists(/etc/rc.conf)
50 FWNAME != . /etc/rc.subr; . /etc/rc.conf; \
51 if checkyesno ipfilter_enable; then \
52 echo "ipf"; elif checkyesno pf_enable; then \
53 echo "pf"; elif checkyesno firewall_enable; then \
54 echo "ipfw"; else echo "pf"; fi
55 .else
56 FWNAME = pf
57 .endif
58 .endif
60 .if $(OSNAME) == "NetBSD"
61 .if exists(/etc/rc.subr) && exists(/etc/rc.conf)
62 FWNAME != . /etc/rc.subr; . /etc/rc.conf; \
63 if checkyesno pf; then \
64 echo "pf"; elif checkyesno ipfilter; then \
65 echo "ipf"; else echo "pf"; fi
66 .else
67 FWNAME = pf
68 .endif
69 .endif
71 .if $(OSNAME) == "DragonFly"
72 .if exists(/etc/rc.subr) && exists(/etc/rc.conf)
73 FWNAME != . /etc/rc.subr; . /etc/rc.conf; \
74 if checkyesno pf; then \
75 echo "pf"; elif checkyesno ipfilter; then \
76 echo "ipf"; else echo "pf"; fi
77 .else
78 FWNAME = pf
79 .endif
80 .endif
82 .if $(OSNAME) == "Darwin"
83 # Firewall is ipfw up to OS X 10.6 Snow Leopard
84 # and pf since OS X 10.7 Lion (Darwin 11.0)
85 FWNAME != [ `uname -r | cut -d. -f1` -ge 11 ] && echo "pf" || echo "ipfw"
86 .endif
88 .endif
90 # Solaris specific CFLAGS
91 .if $(OSNAME) == "SunOS"
92 CFLAGS += -DSOLARIS2=`uname -r | cut -d. -f2`
93 .if $(ARCH) == "amd64"
94 CFLAGS += -m64 -mcmodel=kernel -mno-red-zone -ffreestanding
95 .elif $(ARCH) == "sparc64"
96 CFLAGS += -m64 -mcmodel=medlow
97 .endif
98 .endif
100 STDOBJS = miniupnpd.o upnphttp.o upnpdescgen.o upnpsoap.o \
101 upnpredirect.o getifaddr.o daemonize.o upnpglobalvars.o \
102 options.o upnppermissions.o minissdp.o natpmp.o pcpserver.o \
103 upnpevents.o upnputils.o getconnstatus.o \
104 upnppinhole.o asyncsendto.o portinuse.o
105 BSDOBJS = bsd/getifstats.o bsd/ifacewatcher.o bsd/getroute.o
106 SUNOSOBJS = solaris/getifstats.o bsd/ifacewatcher.o bsd/getroute.o
107 MACOBJS = mac/getifstats.o bsd/ifacewatcher.o bsd/getroute.o
108 PFOBJS = pf/obsdrdr.o pf/pfpinhole.o
109 IPFOBJS = ipf/ipfrdr.o
110 IPFWOBJS = ipfw/ipfwrdr.o ipfw/ipfwaux.o
111 MISCOBJS = upnpreplyparse.o minixml.o
113 ALLOBJS = $(STDOBJS) $(MISCOBJS)
114 .if $(OSNAME) == "SunOS"
115 ALLOBJS += $(SUNOSOBJS)
116 TESTGETIFSTATSOBJS = testgetifstats.o solaris/getifstats.o
117 TESTGETROUTEOBJS = testgetroute.o upnputils.o bsd/getroute.o
118 .elif $(OSNAME) == "Darwin"
119 ALLOBJS += $(MACOBJS)
120 TESTGETIFSTATSOBJS = testgetifstats.o mac/getifstats.o
121 TESTGETROUTEOBJS = testgetroute.o upnputils.o bsd/getroute.o
122 .else
123 ALLOBJS += $(BSDOBJS)
124 TESTGETIFSTATSOBJS = testgetifstats.o bsd/getifstats.o
125 TESTGETROUTEOBJS = testgetroute.o upnputils.o bsd/getroute.o
126 .endif
128 .if $(FWNAME) == "pf"
129 ALLOBJS += $(PFOBJS)
130 .elif $(FWNAME) == "ipfw"
131 ALLOBJS += $(IPFWOBJS)
132 .else
133 ALLOBJS += $(IPFOBJS)
134 .endif
136 TESTUPNPDESCGENOBJS = testupnpdescgen.o upnpdescgen.o
137 TESTUPNPPERMISSIONSOBJS = testupnppermissions.o upnppermissions.o
138 TESTGETIFADDROBJS = testgetifaddr.o getifaddr.o
139 MINIUPNPDCTLOBJS = miniupnpdctl.o
140 TESTASYNCSENDTOOBJS = testasyncsendto.o asyncsendto.o upnputils.o bsd/getroute.o
141 TESTPORTINUSEOBJS = testportinuse.o portinuse.o getifaddr.o
143 EXECUTABLES = miniupnpd testupnpdescgen testgetifstats \
144 testupnppermissions miniupnpdctl \
145 testgetifaddr testgetroute testasyncsendto \
146 testportinuse testssdppktgen
148 .if $(OSNAME) == "Darwin"
149 LIBS =
150 .else
151 LIBS = -lkvm
152 .endif
153 .if $(OSNAME) == "SunOS"
154 LIBS += -lsocket -lnsl -lkstat -lresolv
155 .endif
157 LIBS += -lssl -lcrypto
159 # set PREFIX variable to install in the wanted place
161 INSTALLBINDIR = $(PREFIX)/sbin
162 INSTALLETCDIR = $(PREFIX)/etc
163 # INSTALLMANDIR = $(PREFIX)/man
164 INSTALLMANDIR = /usr/share/man
166 all: $(EXECUTABLES)
168 clean:
169 $(RM) $(STDOBJS) $(BSDOBJS) $(SUNOSOBJS) $(MACOBJS) $(EXECUTABLES) \
170 testupnpdescgen.o \
171 $(MISCOBJS) config.h testgetifstats.o testupnppermissions.o \
172 miniupnpdctl.o testgetifaddr.o testgetroute.o testasyncsendto.o \
173 testportinuse.o \
174 $(PFOBJS) $(IPFOBJS) $(IPFWOBJS)
175 $(RM) validateupnppermissions validategetifaddr validatessdppktgen
177 install: miniupnpd genuuid
178 $(STRIP) miniupnpd
179 $(INSTALL) -d $(DESTDIR)$(INSTALLBINDIR)
180 $(INSTALL) -m 755 miniupnpd $(DESTDIR)$(INSTALLBINDIR)
181 $(INSTALL) -d $(DESTDIR)$(INSTALLETCDIR)
182 $(INSTALL) -b miniupnpd.conf $(DESTDIR)$(INSTALLETCDIR)
183 # TODO : install man page correctly
184 # $(INSTALL) -d $(INSTALLMANDIR)
185 # $(INSTALL) miniupnpd.8 $(INSTALLMANDIR)/cat8/miniupnpd.0
187 # genuuid is using the uuid cli tool available under OpenBSD 4.0 in
188 # the uuid-1.5.0 package
189 # any other cli tool returning a uuid on stdout should work.
190 UUID != if which uuidgen 2>&1 > /dev/null; then \
191 echo `uuidgen` ; \
192 elif which uuid 2>&1 > /dev/null; then \
193 echo `uuid` ; \
194 else echo "00000000-0000-0000-0000-000000000000"; \
197 # bash or ksh
198 SH != which bash || which ksh
200 genuuid:
201 $(MV) miniupnpd.conf miniupnpd.conf.before
202 sed -e "s/^uuid=[-0-9a-fA-F]*/uuid=$(UUID)/" miniupnpd.conf.before > miniupnpd.conf
203 $(RM) miniupnpd.conf.before
205 check: validateupnppermissions validategetifaddr validatessdppktgen
207 validateupnppermissions: testupnppermissions testupnppermissions.sh
208 $(SH) ./testupnppermissions.sh
209 touch $@
211 validategetifaddr: testgetifaddr testgetifaddr.sh
212 ./testgetifaddr.sh
213 touch $@
215 validatessdppktgen: testssdppktgen
216 ./testssdppktgen
217 touch $@
219 depend: config.h
220 mkdep $(ALLOBJS:.o=.c) testupnpdescgen.c testgetifstats.c \
221 testupnppermissions.c miniupnpdctl.c testgetifaddr.c \
222 testgetroute.c testportinuse.c testasyncsendto.c \
223 testssdppktgen.c
225 miniupnpd: config.h $(ALLOBJS)
226 $(CC) $(LDFLAGS) -o $@ $(ALLOBJS) $(LIBS)
228 # BSDmake :
229 # $(CC) $(LDFLAGS) -o $@ $> $(LIBS)
231 miniupnpdctl: config.h $(MINIUPNPDCTLOBJS)
232 $(CC) $(LDFLAGS) -o $@ $(MINIUPNPDCTLOBJS)
234 testupnpdescgen: config.h $(TESTUPNPDESCGENOBJS)
235 $(CC) $(LDFLAGS) -o $@ $(TESTUPNPDESCGENOBJS) $(LIBS)
237 testgetifstats: config.h $(TESTGETIFSTATSOBJS)
238 $(CC) $(LDFLAGS) -o $@ $(TESTGETIFSTATSOBJS) $(LIBS)
240 testgetifaddr: config.h $(TESTGETIFADDROBJS)
241 $(CC) $(LDFLAGS) -o $@ $(TESTGETIFADDROBJS) $(LIBS)
243 testupnppermissions: config.h $(TESTUPNPPERMISSIONSOBJS)
244 $(CC) $(LDFLAGS) -o $@ $(TESTUPNPPERMISSIONSOBJS) $(LIBS)
246 testgetroute: config.h $(TESTGETROUTEOBJS)
247 $(CC) $(LDFLAGS) -o $@ $(TESTGETROUTEOBJS) $(LIBS)
249 testasyncsendto: config.h $(TESTASYNCSENDTOOBJS)
250 $(CC) $(LDFLAGS) -o $@ $(TESTASYNCSENDTOOBJS)
252 testportinuse: config.h $(TESTPORTINUSEOBJS)
253 $(CC) $(LDFLAGS) -o $@ $(TESTPORTINUSEOBJS) $(LIBS)
255 # gmake :
256 # $(CC) $(CFLAGS) -o $@ $^
257 # BSDmake :
258 # $(CC) $(CFLAGS) -o $@ $>
260 config.h: genconfig.sh VERSION
261 ./genconfig.sh $(CONFIG_OPTIONS)
263 .SUFFIXES: .o .c
264 .c.o:
265 $(CC) $(CFLAGS) -c -o $@ $<
267 # $(CC) $(CFLAGS) -c -o $(.TARGET) $(.IMPSRC)