1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
# $Id: Makefile.linux,v 1.114 2025/04/21 21:48:56 nanard Exp $
# MiniUPnP project
# (c) 2006-2025 Thomas Bernard
# http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
# Author : Thomas Bernard
# for use with GNU Make
#
# options can be passed to configure through CONFIG_OPTIONS :
# $ CONFIG_OPTIONS="--ipv6 --igd2" make
#
# To install use :
# $ DESTDIR=/dummyinstalldir make install
# or :
# $ INSTALLPREFIX=/usr/local make install
# or :
# $ make install
# (default INSTALLPREFIX is /usr)
#
# if your system hasn't iptables libiptc headers and binary correctly
# installed, you need to get iptables sources from http://netfilter.org/
# ./configure them and build them then miniupnpd will build using :
# $ IPTABLESPATH=/path/to/iptables-1.4.1 make
#
CONFIG_OPTIONS ?= $(shell cat .configure.cache)
ifeq ($(filter --firewall=iptables,$(CONFIG_OPTIONS)),)
CONFIG_OPTIONS += --firewall=iptables
endif
# Make sucks, prove me wrong
, := ,
ifeq ($(filter -D_FORTIFY_SOURCE=% -Wp$(,)-D_FORTIFY_SOURCE=%,$(CPPFLAGS) $(CFLAGS)),)
CPPFLAGS += -D_FORTIFY_SOURCE=2
endif
CPPFLAGS += -D_GNU_SOURCE
#CFLAGS = -O -g -DDEBUG
CFLAGS ?= -Os
CFLAGS += -fno-strict-aliasing
CFLAGS += -fno-common
CFLAGS += -fstack-protector -fPIE
CFLAGS += -Wall
CFLAGS += -Wextra -Wstrict-prototypes -Wdeclaration-after-statement
#CFLAGS += -Wno-missing-field-initializers
#CFLAGS += -ansi # iptables headers does use typeof which is a gcc extension
LDFLAGS += -Wl,-z,now -Wl,-z,relro -pie
CC ?= gcc
RM = rm -f
INSTALL = install
STRIP ?= strip
CP = cp
DOXYGEN ?= doxygen
DEPDIR := .depend
DEPFLAGS = -MMD -MP -MF $(@:%.o=$(DEPDIR)/%.d) -MT $@
# -M : with system headers, -MM : without
INSTALLPREFIX ?= $(PREFIX)/usr
ETCDIR ?= $(PREFIX)/etc
SBINDIR ?= $(INSTALLPREFIX)/sbin
MANDIR ?= $(INSTALLPREFIX)/share/man
LIBDIR ?= $(INSTALLPREFIX)/lib
CONFIGDIR = $(ETCDIR)/miniupnpd
INITDIR = $(ETCDIR)/init.d
SYSTEMDUNITDIR = $(LIBDIR)/systemd/system
include config.mk
#include $(SRCDIR)/gitrev.mk
include $(SRCDIR)/objects.mk
# sources in netfilter/ directory
NETFILTEROBJS = iptcrdr.o iptpinhole.o nfct_get.o
ALLOBJS = $(BASEOBJS) $(LNXOBJS) $(NETFILTEROBJS) $(OTHEROBJS)
NETFILTER_SCRIPTS = $(addprefix $(SRCDIR)/netfilter/, \
iptables_init.sh iptables_removeall.sh \
ip6tables_init.sh ip6tables_removeall.sh \
miniupnpd_functions.sh)
#LDLIBS += -lnfnetlink
EXECUTABLES = miniupnpd miniupnpdctl
ifeq ($(TESTS), 1)
EXECUTABLES += testupnpdescgen testgetifstats \
testupnppermissions testgetifaddr \
testgetroute testasyncsendto testportinuse \
testssdppktgen testminissdp testifacewatcher
endif
.PHONY: all clean install dox
all: $(EXECUTABLES)
clean:
$(RM) $(ALLOBJS)
$(RM) -r $(DEPDIR)
$(RM) $(EXECUTABLES)
$(RM) validateupnppermissions validategetifaddr validatessdppktgen
$(RM) validateversion
$(RM) -r dox/
install: $(SRCDIR)/miniupnpd.8 $(SRCDIR)/miniupnpd.conf \
$(NETFILTER_SCRIPTS) \
$(SRCDIR)/linux/miniupnpd.init.d.script \
$(SRCDIR)/linux/miniupnpd.iptables.service
$(INSTALL) -D -m 0755 $(NETFILTER_SCRIPTS) -t $(DESTDIR)$(CONFIGDIR)
$(INSTALL) -D -m 0644 -b $(SRCDIR)/miniupnpd.conf -t $(DESTDIR)$(CONFIGDIR)
sed -i -e "s/^uuid=[-0-9a-f]*/uuid=$(shell $(UUIDBIN))/" $(DESTDIR)$(CONFIGDIR)/miniupnpd.conf
ifneq ($(USE_SYSTEMD),)
$(INSTALL) -D -m 0644 $(SRCDIR)/linux/miniupnpd.iptables.service $(DESTDIR)$(SYSTEMDUNITDIR)/miniupnpd.service
sed -r \
-e "s|%BINDIR%|$(SBINDIR)|" \
-e "s|%CONFIGDIR%|$(CONFIGDIR)|" \
-i $(DESTDIR)/$(SYSTEMDUNITDIR)/miniupnpd.service
sed -r \
-e "s|(#lease_file)=.*|\1=/var/lib/miniupnpd/upnp.leases|" \
-i $(DESTDIR)/$(CONFIGDIR)/miniupnpd.conf
else
$(INSTALL) -D -m 0755 $(SRCDIR)/linux/miniupnpd.init.d.script $(DESTDIR)$(INITDIR)/miniupnpd
endif
$(INSTALL) -D -m 0644 $(SRCDIR)/miniupnpd.8 -t $(DESTDIR)$(MANDIR)/man8
gzip -f $(DESTDIR)$(MANDIR)/man8/miniupnpd.8
include $(SRCDIR)/check.mk
include $(SRCDIR)/common.mk
testportinuse: testportinuse.o portinuse.o getifaddr.o \
iptcrdr.o upnputils.o getroute.o
config.mk config.h: $(SRCDIR)/configure $(SRCDIR)/VERSION
$(SHELL) $< $(CONFIG_OPTIONS)
%.o: $(SRCDIR)/%.c $(DEPDIR)/%.d | $(DEPDIR)
$(CC) -c $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o: $(SRCDIR)/linux/%.c $(DEPDIR)/%.d | $(DEPDIR)
$(CC) -c $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@
%.o: $(SRCDIR)/netfilter/%.c $(DEPDIR)/%.d | $(DEPDIR)
$(CC) -c $(DEPFLAGS) $(CFLAGS) $(CPPFLAGS) $< -o $@
DEPFILES := $(ALLOBJS:%.o=$(DEPDIR)/%.d)
$(DEPDIR): ; @mkdir -p $@
$(DEPFILES):
-include $(wildcard $(DEPFILES))
|