1 # $Id: Makefile,v 1.88 2016/02/10 20:32:43 nanard Exp $
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
19 #CFLAGS = -pipe -O -g -DDEBUG
23 CFLAGS
+= -Wstrict-prototypes
24 #CFLAGS += -Wdeclaration-after-statement
25 #CFLAGS += -Wno-missing-field-initializers
33 # OSNAME and FWNAME are used for building OS or FW dependent code.
37 #.if exists(/usr/include/net/pfvar.h)
43 .if
$(OSNAME
) == "OpenBSD"
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
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
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
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"
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
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
123 ALLOBJS
+= $(BSDOBJS
)
124 TESTGETIFSTATSOBJS
= testgetifstats.o bsd
/getifstats.o
125 TESTGETROUTEOBJS
= testgetroute.o upnputils.o bsd
/getroute.o
128 .if
$(FWNAME
) == "pf"
130 .elif
$(FWNAME
) == "ipfw"
131 ALLOBJS
+= $(IPFWOBJS
)
133 ALLOBJS
+= $(IPFOBJS
)
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"
153 .if
$(OSNAME
) == "SunOS"
154 LIBS
+= -lsocket
-lnsl
-lkstat
-lresolv
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
169 $(RM
) $(STDOBJS
) $(BSDOBJS
) $(SUNOSOBJS
) $(MACOBJS
) $(EXECUTABLES
) \
171 $(MISCOBJS
) config.h testgetifstats.o testupnppermissions.o \
172 miniupnpdctl.o testgetifaddr.o testgetroute.o testasyncsendto.o \
174 $(PFOBJS
) $(IPFOBJS
) $(IPFWOBJS
)
175 $(RM
) validateupnppermissions validategetifaddr validatessdppktgen
177 install: miniupnpd genuuid
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 \
192 elif which uuid
2>&1 > /dev
/null
; then \
194 else echo
"00000000-0000-0000-0000-000000000000"; \
198 SH
!= which bash || which ksh
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
211 validategetifaddr
: testgetifaddr testgetifaddr.sh
215 validatessdppktgen
: testssdppktgen
220 mkdep
$(ALLOBJS
:.o
=.c
) testupnpdescgen.c testgetifstats.c \
221 testupnppermissions.c miniupnpdctl.c testgetifaddr.c \
222 testgetroute.c testportinuse.c testasyncsendto.c \
225 miniupnpd
: config.h
$(ALLOBJS
)
226 $(CC
) $(LDFLAGS
) -o
$@
$(ALLOBJS
) $(LIBS
)
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
)
256 # $(CC) $(CFLAGS) -o $@ $^
258 # $(CC) $(CFLAGS) -o $@ $>
260 config.h
: genconfig.sh VERSION
261 .
/genconfig.sh
$(CONFIG_OPTIONS
)
265 $(CC
) $(CFLAGS
) -c
-o
$@
$<
267 # $(CC) $(CFLAGS) -c -o $(.TARGET) $(.IMPSRC)