make: also credit involved people in mail message
[netsniff-ng.git] / Makefile
blobab74a32c4272318bba4907e785b2a041984b293e
1 # netsniff-ng build system
2 # Copyright 2012 - 2013 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
9 NAME = Ziggomatic
11 TOOLS = netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun
13 # For packaging purposes, prefix can define a different path.
14 PREFIX ?=
16 # Debugging option
17 ifeq ("$(origin DEBUG)", "command line")
18 DEBUG := 1
19 else
20 DEBUG := 0
21 endif
23 # Disable if you don't want it
24 CCACHE = ccache
26 # Location of installation paths.
27 BINDIR = $(PREFIX)/usr/bin
28 SBINDIR = $(PREFIX)/usr/sbin
29 INCDIR = $(PREFIX)/usr/include
30 ETCDIR = $(PREFIX)/etc
31 ETCDIRE = $(ETCDIR)/netsniff-ng
32 DOCDIR = $(PREFIX)/usr/share/doc
33 DOCDIRE = $(DOCDIR)/netsniff-ng
35 # Shut up make, helper warnings, parallel compilation!
36 MAKEFLAGS += --no-print-directory
37 MAKEFLAGS += -rR
38 MAKEFLAGS += --warn-undefined-variables
39 MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l)
41 # For packaging purposes, you might want to disable O3+arch tuning
42 CFLAGS = -fstack-protector
43 ifeq ($(DEBUG), 1)
44 CFLAGS += -g
45 CFLAGS += -O2
46 else
47 CFLAGS += -march=native
48 CFLAGS += -mtune=native
49 CFLAGS += -O3
50 CFLAGS += -fpie
51 CFLAGS += -pipe
52 CFLAGS += -fomit-frame-pointer
53 endif
54 CFLAGS += --param=ssp-buffer-size=4
55 CFLAGS += -fno-strict-aliasing
56 CFLAGS += -fexceptions
57 CFLAGS += -fasynchronous-unwind-tables
58 CFLAGS += -fno-delete-null-pointer-checks
59 CFLAGS += -D_FORTIFY_SOURCE=2
60 CFLAGS += -D_REENTRANT
61 CFLAGS += -D_FILE_OFFSET_BITS=64
62 CFLAGS += -D_LARGEFILE_SOURCE
63 CFLAGS += -D_LARGEFILE64_SOURCE
64 ifneq ($(wildcard /usr/include/linux/net_tstamp.h),)
65 CFLAGS += -D__WITH_HARDWARE_TIMESTAMPING
66 endif
67 CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\"
68 CFLAGS += -DPREFIX_STRING=\"$(PREFIX)\"
69 CFLAGS += -std=gnu99
71 WFLAGS = -Wall
72 WFLAGS += -Wformat=2
73 WFLAGS += -Wmissing-prototypes
74 WFLAGS += -Wdeclaration-after-statement
75 WFLAGS += -Werror-implicit-function-declaration
76 WFLAGS += -Wstrict-prototypes
77 WFLAGS += -Wundef
78 WFLAGS += -Wimplicit-int
80 WFLAGS_EXTRA = -Wno-unused-result
81 WFLAGS_EXTRA += -Wmissing-parameter-type
82 WFLAGS_EXTRA += -Wtype-limits
83 WFLAGS_EXTRA += -Wclobbered
84 WFLAGS_EXTRA += -Wmissing-field-initializers
85 WFLAGS_EXTRA += -Woverride-init
86 WFLAGS_EXTRA += -Wold-style-declaration
87 WFLAGS_EXTRA += -Wignored-qualifiers
88 WFLAGS_EXTRA += -Wempty-body
89 WFLAGS_EXTRA += -Wuninitialized
91 CFLAGS += $(WFLAGS) -I.
92 CPPFLAGS =
93 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
94 LDFLAGS = -L$(CROSS_LD_LIBRARY_PATH)
95 else
96 LDFLAGS =
97 endif
99 ALL_CFLAGS = $(CFLAGS)
100 ALL_LDFLAGS = $(LDFLAGS)
101 TARGET_ARCH =
102 LEX_FLAGS =
103 YAAC_FLAGS =
105 Q = @
107 LD = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CROSS_COMPILE)gcc
108 CCNQ = $(CCACHE) $(CROSS_COMPILE)gcc
109 CC = $(Q)echo -e " CC\t$<" && $(CCNQ)
110 MKDIR = $(Q)echo -e " MKDIR\t$@" && mkdir
111 ifeq ($(DEBUG), 1)
112 STRIP = $(Q)true
113 else
114 STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip
115 endif
116 LEX = $(Q)echo -e " LEX\t$<" && flex
117 YAAC = $(Q)echo -e " YAAC\t$<" && bison
118 INST = echo -e " INST\t$(1)" && install -d $(2) && \
119 install --mode=644 -DC $(1) $(2)/$(shell basename $(1))
120 ifeq ("$(origin PREFIX)", "command line")
121 INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
122 install -C $(1) $(2)/$(shell basename $(1))
123 else
124 INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
125 endif
126 RM = echo -e " RM\t$(1)" && rm -rf $(1)
127 RMDIR = echo -e " RM\t$(1)" && rmdir --ignore-fail-on-non-empty $(1) 2> /dev/null || true
128 GIT_ARCHIVE = git archive --prefix=netsniff-ng-$(VERSION_STRING)/ $(VERSION_STRING) | \
129 $(1) > ../netsniff-ng-$(VERSION_STRING).tar.$(2)
130 GIT_TAG = git tag -a $(VERSION_STRING) -s -m "tools: $(VERSION_STRING) release"
131 GIT_LOG = git shortlog -n --not $(shell git describe --abbrev=0 --tags)
132 GIT_REM = git ls-files -o | xargs rm -rf
133 GIT_PEOPLE = git log --no-merges $(VERSION_STRING)..HEAD | grep Author: | cut -d: -f2 | \
134 cut -d\< -f1 | sort | uniq -c | sort -nr
136 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
137 export CROSS_COMPILE
139 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
140 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)
142 bold = $(shell tput bold)
143 normal = $(shell tput sgr0)
145 ifndef NACL_LIB_DIR
146 ifndef NACL_INC_DIR
147 $(info $(bold)NACL_LIB_DIR/NACL_INC_DIR is undefined, build libnacl first for curvetun!$(normal))
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 $<
170 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install tag tags cscope
171 .FORCE:
172 .DEFAULT_GOAL := all
173 .DEFAULT:
174 .IGNORE: %_clean_custom %_install_custom
175 .NOTPARALLEL: $(TOOLS)
177 DOC_FILES = Summary RelatedWork Performance KnownIssues Sponsors SubmittingPatches CodingStyle
179 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf geoip.conf
181 all: build_showinfo toolkit
182 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
183 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
184 toolkit: $(TOOLS)
185 install: install_all
186 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
187 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
188 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
189 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
190 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
191 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
192 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
193 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
194 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
195 $(Q)$(call RMDIR,$(DOCDIRE))
196 $(Q)$(call RMDIR,$(ETCDIRE))
197 mrproper: clean distclean
198 $(Q)$(GIT_REM)
200 define TOOL_templ
201 include $(1)/Makefile
202 $(1) $(1)%: BUILD_DIR := $(1)
203 $(1)_prehook:
204 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
205 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
206 $(1)_clean: $(1)_clean_custom
207 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
208 $(1)_install: $(1)_install_custom
209 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
210 $(1)_distclean: $(1)_distclean_custom
211 $(Q)$$(call RM,$$(SBINDIR)/$(1))
212 $(1)/%.yy.o: $(1)/%.yy.c
213 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
214 $(1)/%.tab.o: $(1)/%.tab.c
215 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
216 $(1)/%.o: %.c
217 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
218 endef
220 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
222 %:: ;
224 netsniff-ng: ALL_CFLAGS += $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) -D__WITH_PROTOS -D__WITH_TCPDUMP_LIKE_FILTER
225 trafgen: ALL_CFLAGS += -I.. $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) -D__WITH_PROTOS
226 ifpps: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
227 flowtop: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
228 bpfc: ALL_CFLAGS += -I..
229 curvetun: ALL_CFLAGS += -I ${NACL_INC_DIR}
230 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
232 bpfc_clean_custom:
233 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
234 trafgen_clean_custom:
235 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
237 netsniff-ng_distclean_custom flowtop_distclean_custom:
238 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
239 $(Q)$(call RMDIR,$(ETCDIRE))
240 trafgen_distclean_custom:
241 $(Q)$(call RM,$(ETCDIRE)/stddef.h)
242 $(Q)$(call RMDIR,$(ETCDIRE))
243 astraceroute_distclean_custom:
244 $(Q)$(call RM,$(ETCDIRE)/geoip.conf)
245 $(Q)$(call RMDIR,$(ETCDIRE))
247 netsniff-ng_install_custom flowtop_install_custom:
248 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,configs/$(file),$(ETCDIRE));)
249 trafgen_install_custom:
250 $(Q)$(call INST,configs/stddef.h,$(ETCDIRE))
251 astraceroute_install_custom:
252 $(Q)$(call INST,configs/geoip.conf,$(ETCDIRE))
254 $(TOOLS): WFLAGS += $(WFLAGS_EXTRA)
255 $(TOOLS):
256 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
257 $(STRIP) $@/$@
259 nacl:
260 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
261 $(Q)cd curvetun/ && ./nacl_build.sh ~/nacl
262 $(Q)source ~/.bashrc
264 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
265 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
266 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
267 tarball: tarball.gz tarball.bz2 tarball.xz
269 tag:
270 $(GIT_TAG)
272 announcement:
273 $(Q)echo -e "netsniff-ng $(VERSION_STRING) has been released to the public (http://netsniff-ng.org/).\n" > .MAIL_MSG
274 $(Q)echo -e "It can be fetched via Git, through:\n" >> .MAIL_MSG
275 $(Q)echo -e " git clone git://github.com/borkmann/netsniff-ng.git" >> .MAIL_MSG
276 $(Q)echo -e " git checkout $(VERSION_STRING)\n" >> .MAIL_MSG
277 $(Q)echo -e "Or via HTTP, through:\n" >> .MAIL_MSG
278 $(Q)echo -e " wget http://pub.netsniff-ng.org/netsniff-ng/netsniff-ng-$(VERSION_STRING).tar.gz\n" >> .MAIL_MSG
279 $(Q)echo -e "The release be verified via Git, through (see Documentation/Workflow):\n" >> .MAIL_MSG
280 $(Q)echo -e " git tag -v $(VERSION_STRING)\n" >> .MAIL_MSG
281 $(Q)echo -e "Major high-level changes since the last release are:\n" >> .MAIL_MSG
282 $(Q)echo -e " *** BLURB HERE ***\n" >> .MAIL_MSG
283 $(Q)echo -e "Contributors since last release:\n" >> .MAIL_MSG
284 $(GIT_PEOPLE) >> .MAIL_MSG
285 $(Q)echo -e "Git changelog since the last release:\n" >> .MAIL_MSG
286 $(GIT_LOG) >> .MAIL_MSG
288 release: announcement tag tarball
289 $(Q)echo "Released $(bold)$(VERSION_STRING)$(normal)"
291 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
292 find . \( -name .git -type d -prune \) \
293 -o \( -name '*.[hcS]' -type f -print \) )
295 tags ctags:
296 $(Q)$(call RM,tags)
297 $(FIND_SOURCE_FILES) | xargs ctags -a
299 cscope:
300 $(Q)$(call RM,cscope*)
301 $(FIND_SOURCE_FILES) | xargs cscope -b
303 help:
304 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
305 $(Q)echo " <toolnames>:={$(TOOLS)}"
306 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
307 $(Q)echo " all|toolkit - Build the whole toolkit"
308 $(Q)echo " allbutcurvetun - Build all except curvetun"
309 $(Q)echo " <toolname> - Build only one of the tools"
310 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
311 $(Q)echo " clean|mostlyclean - Remove all build files"
312 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
313 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
314 $(Q)echo " install - Install the whole toolkit"
315 $(Q)echo " <toolname>_install - Install only one of the tools"
316 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
317 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
318 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
319 $(Q)echo " mrproper - Remove build and install files"
320 $(Q)echo "$(bold)Hacking/development targets:$(normal)"
321 $(Q)echo " tag - Generate Git tag of current version"
322 $(Q)echo " tarball - Generate tarball of latest version"
323 $(Q)echo " release - Generate a new release"
324 $(Q)echo " tags - Generate sparse ctags"
325 $(Q)echo " cscope - Generate cscope files"
326 $(Q)echo "$(bold)Misc targets:$(normal)"
327 $(Q)echo " nacl - Execute the build_nacl script"
328 $(Q)echo " help - Show this help"
329 $(Q)echo "$(bold)Available parameters:$(normal)"
330 $(Q)echo " DEBUG=1 - Enable debugging"
331 $(Q)echo " PREFIX=/path - Install path prefix"
332 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
333 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
334 $(Q)echo " CC=cgcc - Use sparse compiler wrapper"
335 $(Q)echo " Q= - Show verbose garbage"