make: default match, thus we can remove empty rules
[netsniff-ng.git] / src / Makefile
blob20d7589f40a9aeda3fd1df60843a6911eb473b8a
1 # netsniff-ng build system, part of netsniff-ng.
2 # Copyright 2012 Daniel Borkmann <borkmann@gnumaniacs.org>
3 # Subject to the GNU GPL, version 2.
5 VERSION = 0
6 PATCHLEVEL = 5
7 SUBLEVEL = 8
8 EXTRAVERSION = -rc0
10 TOOLS = netsniff-ng trafgen astraceroute flowtop ifpps mausezahn bpfc curvetun
12 # For packaging purposes, prefix can define a different path.
13 PREFIX ?=
15 # Disable if you don't want it
16 CCACHE = ccache
18 # Location of installation paths.
19 BINDIR = $(PREFIX)/usr/bin
20 SBINDIR = $(PREFIX)/usr/sbin
21 INCDIR = $(PREFIX)/usr/include
22 ETCDIR = $(PREFIX)/etc
23 ETCDIRE = $(ETCDIR)/netsniff-ng
24 DOCDIR = $(PREFIX)/usr/share/doc
25 DOCDIRE = $(DOCDIR)/netsniff-ng
27 # Shut up make, helper warnings, parallel compilation!
28 MAKEFLAGS += --no-print-directory
29 MAKEFLAGS += -rR
30 MAKEFLAGS += --warn-undefined-variables
31 MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l)
33 # For packaging purposes, you might want to disable O3+arch tuning
34 CFLAGS = -fstack-protector
35 CFLAGS += --param=ssp-buffer-size=4
36 CFLAGS += -fpie
37 CFLAGS += -fno-strict-aliasing
38 CFLAGS += -fexceptions
39 CFLAGS += -fasynchronous-unwind-tables
40 CFLAGS += -fno-delete-null-pointer-checks
41 CFLAGS += -D_FORTIFY_SOURCE=2
42 CFLAGS += -D_REENTRANT
43 CFLAGS += -D_FILE_OFFSET_BITS=64
44 CFLAGS += -D_LARGEFILE_SOURCE
45 CFLAGS += -D_LARGEFILE64_SOURCE
46 #CFLAGS += -D__WITH_HARDWARE_TIMESTAMPING
47 CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\"
48 CFLAGS += -std=gnu99
49 CFLAGS += -march=native
50 CFLAGS += -mtune=native
51 CFLAGS += -O3
52 CFLAGS += -g
54 # Should be commented in after the mausezahn mess is cleaned
55 WFLAGS = -Wall
56 #WFLAGS += -Wmissing-prototypes
57 #WFLAGS += -Wdeclaration-after-statement
58 #WFLAGS += -Werror-implicit-function-declaration
59 #WFLAGS += -Wundef
60 #WFLAGS += -Wstrict-prototypes
61 #WFLAGS += -Wunused-but-set-variable
62 #WFLAGS += -Werror
63 WFLAGS += -Wformat=2
65 CFLAGS += $(WFLAGS) -I.
66 CPPFLAGS =
67 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
68 LDFLAGS = -L$(CROSS_LD_LIBRARY_PATH)
69 else
70 LDFLAGS =
71 endif
73 ALL_CFLAGS = $(CFLAGS)
74 ALL_LDFLAGS = $(LDFLAGS)
75 TARGET_ARCH =
76 LEX_FLAGS =
77 YAAC_FLAGS =
79 Q = @
81 LD = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CROSS_COMPILE)gcc
82 CCNQ = $(CCACHE) $(CROSS_COMPILE)gcc
83 CC = $(Q)echo -e " CC\t$<" && $(CCNQ)
84 MKDIR = $(Q)echo -e " MKDIR\t$@" && mkdir
85 STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip
86 LEX = $(Q)echo -e " LEX\t$<" && flex
87 YAAC = $(Q)echo -e " YAAC\t$<" && bison
88 INST = echo -e " INST\t$(1)" && install -d $(2) && \
89 install --mode=644 -DC $(1) $(2)/$(shell basename $(1))
90 INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
91 RM = echo -e " RM\t$(1)" && rm -rf $(1)
92 RMDIR = echo -e " RM\t$(1)" && rmdir --ignore-fail-on-non-empty $(1) 2> /dev/null || true
94 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
95 export CROSS_COMPILE LD CC STRIP
97 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
98 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)
100 bold = $(shell tput bold)
101 normal = $(shell tput sgr0)
103 build_showinfo:
104 $(Q)echo "$(bold)Building netsniff-ng toolkit ($(VERSION_STRING)) for" \
105 $(shell $(CCNQ) -dumpmachine)":$(normal)"
106 clean_showinfo:
107 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
109 %.yy.o: %.l
110 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
111 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
112 %.tab.o: %.y
113 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
114 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
116 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install
117 .FORCE:
118 .DEFAULT_GOAL := all
119 .DEFAULT:
120 .IGNORE: %_clean_custom %_install_custom
121 .NOTPARALLEL: $(TOOLS)
123 DOC_FILES = Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
124 SubmittingPatches CodingStyle logo.png RelNotes/Notes-$(VERSION_SHORT)
126 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf
128 all: build_showinfo toolkit
129 toolkit: $(TOOLS)
130 install: $(foreach tool,$(TOOLS),$(tool)_install)
131 $(Q)$(foreach file,$(DOC_FILES),$(call INST,../Documentation/$(file),$(DOCDIRE));)
132 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
133 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
134 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
135 $(Q)$(call RMDIR,$(DOCDIRE))
136 $(Q)$(call RMDIR,$(ETCDIRE))
137 mrproper: clean distclean
139 define TOOL_templ
140 include $(1)/Makefile
141 $(1) $(1)%: BUILD_DIR := $(1)
142 $(1)_prehook:
143 $(Q)echo "$(bold)Building $(1):$(normal)"
144 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
145 $(1)_clean: $(1)_clean_custom
146 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
147 $(1)_install: $(1)_install_custom
148 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
149 $(Q)$$(call INST,../Documentation/$$(shell echo $(1) | sed 's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE))
150 $(1)_distclean: $(1)_distclean_custom
151 $(Q)$$(call RM,$$(SBINDIR)/$(1))
152 $(Q)$$(call RM,$$(DOCDIRE)/$$(shell echo $(1) | sed 's/\([a-z]\)\(.*\)/\u\1\2/g'))
153 $(1)/%.yy.o: $(1)/%.yy.c
154 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
155 $(1)/%.tab.o: $(1)/%.tab.c
156 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
157 $(1)/%.o: %.c
158 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
159 endef
161 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
163 %:: ;
165 netsniff-ng: ALL_CFLAGS += -I$(INCDIR)/libnl3/ -D__WITH_PROTOS
166 trafgen: ALL_CFLAGS += -I.. -I$(INCDIR)/libnl3/ -D__WITH_PROTOS
167 bpfc: ALL_CFLAGS += -I..
168 curvetun: ALL_CFLAGS += -I$(NACL_INCLUDE_DIR)
169 curvetun: ALL_LDFLAGS += -L$(NACL_LIB_DIR)
171 bpfc_clean_custom:
172 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
173 trafgen_clean_custom:
174 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
176 netsniff-ng_distclean_custom flowtop_distclean_custom:
177 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
178 $(Q)$(call RMDIR,$(ETCDIRE))
179 astraceroute_distclean_custom:
180 $(Q)$(call RM,$(ETCDIRE)/whois.conf)
181 $(Q)$(call RM,$(SBINDIR)/astraceroute6)
182 $(Q)$(call RMDIR,$(ETCDIRE))
184 netsniff-ng_install_custom flowtop_install_custom:
185 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,conf/$(file),$(ETCDIRE));)
186 astraceroute_install_custom:
187 $(Q)$(call INST,conf/whois.conf,$(ETCDIRE))
188 $(Q)$(call INSTX,../scripts/astraceroute6,$(SBINDIR))
190 $(TOOLS):
191 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
192 $(STRIP) $@/$@
194 update:
195 $(Q)../scripts/geoip-database-update
196 nacl:
197 $(Q)cd curvetun/ && ./build_nacl.sh ~/nacl
198 geoip:
199 $(Q)cd astraceroute/ && ./build_geoip.sh
201 help:
202 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
203 $(Q)echo " <toolnames>:={$(TOOLS)}"
204 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
205 $(Q)echo " all|toolkit - Build the whole toolkit"
206 $(Q)echo " <toolname> - Build only one of the tools"
207 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
208 $(Q)echo " clean|mostlyclean - Remove all build files"
209 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
210 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
211 $(Q)echo " install - Install the whole toolkit"
212 $(Q)echo " <toolname>_install - Install only one of the tools"
213 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
214 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
215 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
216 $(Q)echo "$(bold)Misc targets:$(normal)"
217 $(Q)echo " mrproper - Remove build and install files"
218 $(Q)echo " update - Update to the latest GeoIP database"
219 $(Q)echo " nacl - Execute the build_nacl script"
220 $(Q)echo " geoip - Execute the build_geoip script"
221 $(Q)echo " help - Show this help"