docs: moved manpages to man, remove talks from repo
[netsniff-ng.git] / Makefile
blob9f6f989665974f4acb795d3341f692a9dad3a0c7
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 bpfc curvetun
12 # For packaging purposes, prefix can define a different path.
13 PREFIX ?=
15 # Debugging option
16 ifeq ("$(origin DEBUG)", "command line")
17 DEBUG := 1
18 else
19 DEBUG := 0
20 endif
22 # Disable if you don't want it
23 CCACHE = ccache
25 # Location of installation paths.
26 BINDIR = $(PREFIX)/usr/bin
27 SBINDIR = $(PREFIX)/usr/sbin
28 INCDIR = $(PREFIX)/usr/include
29 ETCDIR = $(PREFIX)/etc
30 ETCDIRE = $(ETCDIR)/netsniff-ng
31 DOCDIR = $(PREFIX)/usr/share/doc
32 DOCDIRE = $(DOCDIR)/netsniff-ng
34 # Shut up make, helper warnings, parallel compilation!
35 MAKEFLAGS += --no-print-directory
36 MAKEFLAGS += -rR
37 MAKEFLAGS += --warn-undefined-variables
38 MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l)
40 # For packaging purposes, you might want to disable O3+arch tuning
41 CFLAGS = -fstack-protector
42 ifeq ($(DEBUG), 1)
43 CFLAGS += -g
44 CFLAGS += -O2
45 else
46 CFLAGS += -march=native
47 CFLAGS += -mtune=native
48 CFLAGS += -O3
49 CFLAGS += -fpie
50 CFLAGS += -pipe
51 CFLAGS += -fomit-frame-pointer
52 endif
53 CFLAGS += --param=ssp-buffer-size=4
54 CFLAGS += -fno-strict-aliasing
55 CFLAGS += -fexceptions
56 CFLAGS += -fasynchronous-unwind-tables
57 CFLAGS += -fno-delete-null-pointer-checks
58 CFLAGS += -D_FORTIFY_SOURCE=2
59 CFLAGS += -D_REENTRANT
60 CFLAGS += -D_FILE_OFFSET_BITS=64
61 CFLAGS += -D_LARGEFILE_SOURCE
62 CFLAGS += -D_LARGEFILE64_SOURCE
63 ifneq ($(wildcard /usr/include/linux/net_tstamp.h),)
64 CFLAGS += -D__WITH_HARDWARE_TIMESTAMPING
65 endif
66 CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\"
67 CFLAGS += -std=gnu99
69 WFLAGS = -Wall
70 WFLAGS += -Wformat=2
71 WFLAGS += -Wmissing-prototypes
72 WFLAGS += -Wdeclaration-after-statement
73 WFLAGS += -Werror-implicit-function-declaration
74 WFLAGS += -Wstrict-prototypes
75 WFLAGS += -Wundef
76 WFLAGS += -Wimplicit-int
78 WFLAGS_EXTRA = -Wno-unused-result
79 WFLAGS_EXTRA += -Wmissing-parameter-type
80 WFLAGS_EXTRA += -Wtype-limits
81 WFLAGS_EXTRA += -Wclobbered
82 WFLAGS_EXTRA += -Wmissing-field-initializers
83 WFLAGS_EXTRA += -Woverride-init
84 WFLAGS_EXTRA += -Wold-style-declaration
85 WFLAGS_EXTRA += -Wignored-qualifiers
86 WFLAGS_EXTRA += -Wempty-body
87 WFLAGS_EXTRA += -Wuninitialized
89 CFLAGS += $(WFLAGS) -I.
90 CPPFLAGS =
91 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
92 LDFLAGS = -L$(CROSS_LD_LIBRARY_PATH)
93 else
94 LDFLAGS =
95 endif
97 ALL_CFLAGS = $(CFLAGS)
98 ALL_LDFLAGS = $(LDFLAGS)
99 TARGET_ARCH =
100 LEX_FLAGS =
101 YAAC_FLAGS =
103 Q = @
105 LD = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CROSS_COMPILE)gcc
106 CCNQ = $(CCACHE) $(CROSS_COMPILE)gcc
107 CC = $(Q)echo -e " CC\t$<" && $(CCNQ)
108 CCHK = echo -e " CCHK\t$@" && cppcheck -q --std=c99 \
109 --enable=style,performance,portability,unusedFunction \
110 --includes-file=${NACL_INC_DIR}
111 MKDIR = $(Q)echo -e " MKDIR\t$@" && mkdir
112 ifeq ($(DEBUG), 1)
113 STRIP = $(Q)true
114 else
115 STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip
116 endif
117 LEX = $(Q)echo -e " LEX\t$<" && flex
118 YAAC = $(Q)echo -e " YAAC\t$<" && bison
119 INST = echo -e " INST\t$(1)" && install -d $(2) && \
120 install --mode=644 -DC $(1) $(2)/$(shell basename $(1))
121 ifeq ("$(origin PREFIX)", "command line")
122 INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
123 install -C $(1) $(2)/$(shell basename $(1))
124 else
125 INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
126 endif
127 RM = echo -e " RM\t$(1)" && rm -rf $(1)
128 RMDIR = echo -e " RM\t$(1)" && rmdir --ignore-fail-on-non-empty $(1) 2> /dev/null || true
129 GIT_ARCHIVE = git archive --prefix=netsniff-ng-$(VERSION_STRING)/ $(VERSION_STRING) | \
130 $(1) > ../netsniff-ng-$(VERSION_STRING).tar.$(2)
131 GIT_TAG = git tag -a $(VERSION_STRING) -m "$(VERSION_STRING) release"
133 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
134 export CROSS_COMPILE
136 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
137 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)
139 bold = $(shell tput bold)
140 normal = $(shell tput sgr0)
142 $(shell . ~/.bashrc)
143 # Build NaCl if no environment variables are set!
144 ifndef NACL_LIB_DIR
145 ifndef NACL_INC_DIR
146 $(info $(bold)NACL_LIB_DIR/NACL_INC_DIR is undefined, building libnacl with curvetun!$(normal))
147 curvetun: nacl
148 endif
149 endif
151 ifeq ("$(origin CROSS_COMPILE)", "command line")
152 WHAT := Cross compiling
153 else
154 WHAT := Building
155 endif
157 build_showinfo:
158 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
159 $(shell $(CCNQ) -dumpmachine)":$(normal)"
160 clean_showinfo:
161 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
163 %.yy.o: %.l
164 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
165 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
166 %.tab.o: %.y
167 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
168 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
169 %.x:
170 @if [ -a $(shell basename $@ .x).c ]; then $(CCHK) $(shell basename $@ .x).c || true; fi
172 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install
173 .FORCE:
174 .DEFAULT_GOAL := all
175 .DEFAULT:
176 .IGNORE: %_clean_custom %_install_custom
177 .NOTPARALLEL: $(TOOLS)
179 DOC_FILES = Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
180 SubmittingPatches CodingStyle logo.png RelNotes/Notes-$(VERSION_SHORT)
182 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf
184 all: build_showinfo toolkit
185 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
186 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
187 toolkit: $(TOOLS)
188 install: install_all
189 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
190 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
191 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
192 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
193 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
194 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
195 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
196 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
197 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
198 $(Q)$(call RMDIR,$(DOCDIRE))
199 $(Q)$(call RMDIR,$(ETCDIRE))
200 mrproper: clean distclean
201 check: $(foreach tool,$(TOOLS),$(tool)_check)
203 define TOOL_templ
204 include $(1)/Makefile
205 $(1) $(1)%: BUILD_DIR := $(1)
206 $(1)_prehook:
207 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
208 $(1)_prehook_check:
209 $(Q)echo "$(bold)Checking $(1):$(normal)"
210 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
211 $(1)_clean: $(1)_clean_custom
212 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
213 $(1)_check: $(1)_prehook_check $$(patsubst %.o,%.x,$$($(1)-objs))
214 $(1)_install: $(1)_install_custom
215 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
216 $(Q)$$(call INST,Documentation/$$(shell echo $(1) | sed 's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE))
217 $(1)_distclean: $(1)_distclean_custom
218 $(Q)$$(call RM,$$(SBINDIR)/$(1))
219 $(Q)$$(call RM,$$(DOCDIRE)/$$(shell echo $(1) | sed 's/\([a-z]\)\(.*\)/\u\1\2/g'))
220 $(1)/%.yy.o: $(1)/%.yy.c
221 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
222 $(1)/%.tab.o: $(1)/%.tab.c
223 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
224 $(1)/%.o: %.c
225 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
226 endef
228 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
230 %:: ;
232 netsniff-ng: ALL_CFLAGS += -I$(INCDIR)/libnl3/ -D__WITH_PROTOS -D__WITH_TCPDUMP_LIKE_FILTER
233 trafgen: ALL_CFLAGS += -I.. -I$(INCDIR)/libnl3/ -D__WITH_PROTOS
234 bpfc: ALL_CFLAGS += -I..
235 curvetun: ALL_CFLAGS += -I ${NACL_INC_DIR}
236 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
238 bpfc_clean_custom:
239 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
240 trafgen_clean_custom:
241 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
243 netsniff-ng_distclean_custom flowtop_distclean_custom:
244 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
245 $(Q)$(call RMDIR,$(ETCDIRE))
246 astraceroute_distclean_custom:
247 $(Q)$(call RM,$(ETCDIRE)/whois.conf)
248 $(Q)$(call RM,$(SBINDIR)/astraceroute6)
249 $(Q)$(call RMDIR,$(ETCDIRE))
251 netsniff-ng_install_custom flowtop_install_custom:
252 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,configs/$(file),$(ETCDIRE));)
253 astraceroute_install_custom:
254 $(Q)$(call INST,configs/whois.conf,$(ETCDIRE))
256 $(TOOLS): WFLAGS += $(WFLAGS_EXTRA)
257 $(TOOLS):
258 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
259 $(STRIP) $@/$@
261 update:
262 $(Q)./update-geoip.sh
263 nacl:
264 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
265 $(Q)cd curvetun/ && ./build_nacl.sh ~/nacl
266 $(Q)source ~/.bashrc
267 geoip:
268 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
269 $(Q)cd astraceroute/ && ./build_geoip.sh
271 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
272 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
273 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
274 tarball: tarball.gz tarball.bz2 tarball.xz
276 tag:
277 $(GIT_TAG)
279 help:
280 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
281 $(Q)echo " <toolnames>:={$(TOOLS)}"
282 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
283 $(Q)echo " all|toolkit - Build the whole toolkit"
284 $(Q)echo " allbutcurvetun - Build all except curvetun"
285 $(Q)echo " <toolname> - Build only one of the tools"
286 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
287 $(Q)echo " clean|mostlyclean - Remove all build files"
288 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
289 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
290 $(Q)echo " install - Install the whole toolkit"
291 $(Q)echo " <toolname>_install - Install only one of the tools"
292 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
293 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
294 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
295 $(Q)echo "$(bold)Targets for checking the toolkit:$(normal)"
296 $(Q)echo " check - Do a static code analysis"
297 $(Q)echo " <toolname>_check - Check only one of the tools"
298 $(Q)echo "$(bold)Misc targets:$(normal)"
299 $(Q)echo " tarball - Generate tarball of latest version"
300 $(Q)echo " tag - Generate Git tag of current version"
301 $(Q)echo " mrproper - Remove build and install files"
302 $(Q)echo " update - Update to the latest GeoIP database"
303 $(Q)echo " nacl - Execute the build_nacl script"
304 $(Q)echo " geoip - Execute the build_geoip script"
305 $(Q)echo " help - Show this help"
306 $(Q)echo "$(bold)Available parameters:$(normal)"
307 $(Q)echo " DEBUG=1 - Enable debugging"
308 $(Q)echo " PREFIX=/path - Install path prefix"
309 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
310 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
311 $(Q)echo " Q= - Show verbose garbage"