sparse: netsniff-ng, trafgen: fix remaining time(0) warnings
[netsniff-ng.git] / Makefile
blob7b3e85c6dc6112f65878ecd08c64e09b32c68011
1 # netsniff-ng build system
2 # Copyright 2012 - 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
3 # Copyright 2013 Tobias Klauser <tklauser@distanz.ch>
4 # Subject to the GNU GPL, version 2.
6 -include Config
7 ifndef CONFIG_OK
8 $(error "Please run `./configure' before `make'")
9 endif
11 VERSION = 0
12 PATCHLEVEL = 5
13 SUBLEVEL = 8
14 EXTRAVERSION = -rc0
15 NAME = Ziggomatic
17 TOOLS ?= $(CONFIG_TOOLS)
18 TOOLS ?= netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn
20 # For packaging purposes, prefix can define a different path.
21 PREFIX ?=
23 # Disable if you don't want it
24 CCACHE ?= $(CONFIG_CCACHE)
26 # Location of installation paths.
27 SBINDIR = $(PREFIX)/usr/sbin
28 INCDIR = $(PREFIX)/usr/include
29 ETCDIR = $(PREFIX)/etc
30 ETCDIRE = $(ETCDIR)/netsniff-ng
31 MAN8DIR = $(PREFIX)/usr/share/man/man8
33 # Shut up make, helper warnings, parallel compilation!
34 MAKEFLAGS += --no-print-directory
35 MAKEFLAGS += -rR
36 MAKEFLAGS += --warn-undefined-variables
37 MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l)
39 # Debugging option
40 ifeq ("$(origin DEBUG)", "command line")
41 DEBUG := 1
42 else
43 DEBUG := 0
44 endif
46 # For packaging purposes, you might want to call your own:
47 # make CFLAGS="<flags>"
48 CFLAGS_DEF = -std=gnu99
49 CFLAGS_DEF += -pipe
51 ifeq ($(DEBUG), 1)
52 CFLAGS_DEF += -O2
53 CFLAGS_DEF += -g
54 else
55 ifeq ($(DISTRO), 1)
56 CFLAGS_DEF += -O2
57 else
58 CFLAGS_DEF += -march=native
59 CFLAGS_DEF += -mtune=native
60 CFLAGS_DEF += -O3
61 endif
62 endif
63 ifeq ($(HARDENING), 1)
64 CFLAGS_DEF += -fPIE -pie
65 CFLAGS_DEF += -Wl,-z,relro,-z,now
66 CFLAGS_DEF += -fstack-protector-all
67 CFLAGS_DEF += -Wstack-protector
68 CFLAGS_DEF += --param=ssp-buffer-size=4
69 CFLAGS_DEF += -ftrapv
70 CFLAGS_DEF += -D_FORTIFY_SOURCE=2
71 CFLAGS_DEF += -fexceptions
72 endif
74 CFLAGS_DEF += -fomit-frame-pointer
75 CFLAGS_DEF += -fno-strict-aliasing
76 CFLAGS_DEF += -fasynchronous-unwind-tables
77 CFLAGS_DEF += -fno-delete-null-pointer-checks
79 CFLAGS_DEF += -D_REENTRANT
80 CFLAGS_DEF += -D_LARGEFILE_SOURCE
81 CFLAGS_DEF += -D_LARGEFILE64_SOURCE
82 CFLAGS_DEF += -D_FILE_OFFSET_BITS=64
84 WFLAGS_DEF = -Wall
85 WFLAGS_DEF += -Wformat=2
86 WFLAGS_DEF += -Wmissing-prototypes
87 WFLAGS_DEF += -Wdeclaration-after-statement
88 WFLAGS_DEF += -Werror-implicit-function-declaration
89 WFLAGS_DEF += -Wstrict-prototypes
90 WFLAGS_DEF += -Wimplicit-int
91 WFLAGS_DEF += -Wundef
93 WFLAGS_EXTRA = -Wno-unused-result
94 WFLAGS_EXTRA += -Wmissing-parameter-type
95 WFLAGS_EXTRA += -Wtype-limits
96 WFLAGS_EXTRA += -Wclobbered
97 WFLAGS_EXTRA += -Wmissing-field-initializers
98 WFLAGS_EXTRA += -Woverride-init
99 WFLAGS_EXTRA += -Wold-style-declaration
100 WFLAGS_EXTRA += -Wignored-qualifiers
101 WFLAGS_EXTRA += -Wempty-body
102 WFLAGS_EXTRA += -Wuninitialized
104 WFLAGS_DEF += $(WFLAGS_EXTRA)
105 CFLAGS_DEF += $(WFLAGS_DEF)
107 CFLAGS ?= $(CFLAGS_DEF)
108 CPPFLAGS ?=
109 LEX_FLAGS =
110 YAAC_FLAGS =
111 LDFLAGS ?=
112 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
113 LDFLAGS += -L$(CROSS_LD_LIBRARY_PATH)
114 endif
116 ALL_LDFLAGS = $(LDFLAGS)
117 ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) -I.
118 ALL_CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\"
119 ALL_CFLAGS += -DVERSION_LONG=\"$(VERSION_LONG)\"
120 ALL_CFLAGS += -DPREFIX_STRING=\"$(PREFIX)\"
122 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
123 VERSION_LONG = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)~$(NAME)
125 # Be quite and do not echo the cmd
126 Q = @
128 # GCC related stuff
129 LD = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CROSS_COMPILE)gcc
130 CCNQ = $(CCACHE) $(CROSS_COMPILE)gcc
131 CC = $(Q)echo -e " CC\t$<" && $(CCNQ)
132 ifeq ($(DEBUG), 1)
133 STRIP = $(Q)true
134 else
135 STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip
136 endif
138 # Flex/bison related
139 LEX = $(Q)echo -e " LEX\t$<" && flex
140 YAAC = $(Q)echo -e " YAAC\t$<" && bison
142 # Installation related
143 INST = echo -e " INST\t$(1)" && install -d $(2) && \
144 install --mode=644 -DC $(1) $(2)/$(shell basename $(1))
146 ifeq ("$(origin PREFIX)", "command line")
147 INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
148 install -C $(1) $(2)/$(shell basename $(1))
149 else
150 INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
151 endif
153 RM = echo -e " RM\t$(1)" && rm -rf $(1)
154 RMDIR = echo -e " RM\t$(1)" && rmdir --ignore-fail-on-non-empty $(1) 2> /dev/null || true
156 GZIP = gzip --best -c
158 # Git related
159 GIT_ARCHIVE = git archive --prefix=netsniff-ng-$(VERSION_STRING)/ $(VERSION_STRING) | \
160 $(1) > ../netsniff-ng-$(VERSION_STRING).tar.$(2)
161 GIT_TAG = git tag -a $(VERSION_STRING) -s -m "tools: $(VERSION_STRING) release"
162 GIT_LOG = git shortlog -n --not $(shell git describe --abbrev=0 --tags)
163 GIT_REM = git ls-files -o | xargs rm -rf
164 GIT_PEOPLE = git log --no-merges $(VERSION_STRING)..HEAD | grep Author: | cut -d: -f2 | \
165 cut -d\< -f1 | sort | uniq -c | sort -nr
167 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
168 export CROSS_COMPILE
170 bold = $(shell tput bold)
171 normal = $(shell tput sgr0)
173 ifeq ("$(origin CROSS_COMPILE)", "command line")
174 WHAT := Cross compiling
175 else
176 WHAT := Building
177 endif
179 build_showinfo:
180 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
181 $(shell $(CCNQ) -dumpmachine)":$(normal)"
182 clean_showinfo:
183 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
185 %.yy.o: %.l
186 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
187 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
188 %.tab.o: %.y
189 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
190 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
192 .PHONY: all toolkit $(TOOLS) clean %_prehook %_clean %_install %_uninstall tag tags cscope
193 .DEFAULT_GOAL := all
194 .FORCE:
195 .DEFAULT:
196 .IGNORE: %_clean_custom %_install_custom
197 .NOTPARALLEL: $(TOOLS)
199 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf geoip.conf
201 #XXX: for an -rcX release ship it without curvetun as this needs
202 # to be fixed until a non-rc release though, therefore do not
203 # apply ''all: toolkit'' for now. However, we still let people
204 # build it by hand if they need to for some reasons.
205 all: build_showinfo allbutcurvetun
206 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
207 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
208 toolkit: $(TOOLS)
209 clean: $(foreach tool,$(TOOLS),$(tool)_clean)
210 distclean: clean
211 $(Q)$(call RM,Config)
212 $(Q)$(call RM,config.h)
213 $(Q)$(call RM,config.log)
214 mrproper: distclean
215 $(Q)$(GIT_REM)
217 #XXX: same here, instead of "install: install_all" we ignore curvetun
218 # for the moment
219 install: install_allbutcurvetun
220 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
221 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
222 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
223 uninstall: $(foreach tool,$(TOOLS),$(tool)_uninstall)
224 $(Q)$(call RMDIR,$(ETCDIRE))
226 define TOOL_templ
227 include $(1)/Makefile
228 $(1) $(1)%: BUILD_DIR := $(1)
229 $(1) $(1)%: ALL_CFLAGS += $$($(1)-eflags)
230 $(1)_prehook:
231 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
232 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
233 $(1)_clean: $(1)_clean_custom
234 $(Q)$$(call RM,$(1)/*.o $(1)/$(1) $(1)/*.gz)
235 $(1)_install: $(1)_install_custom
236 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
237 $(Q)$(GZIP) $(1).8 > $(1)/$(1).8.gz
238 $(Q)$$(call INSTX,$(1)/$(1).8.gz,$$(MAN8DIR))
239 $(1)_uninstall: $(1)_uninstall_custom
240 $(Q)$$(call RM,$$(SBINDIR)/$(1))
241 $(Q)$$(call RM,$$(MAN8DIR)/$(1).8.gz)
242 $(1)/%.yy.o: $(1)/%.yy.c
243 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
244 $(1)/%.tab.o: $(1)/%.tab.c
245 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
246 $(1)/%.o: %.c
247 $$(CC) $$(ALL_CFLAGS) -o $(1)/$$(shell basename $$@) -c $$<
248 endef
250 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
252 %:: ;
254 # Here are two special treatments for now
255 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
256 mausezahn: ALL_CFLAGS = $(mausezahn-eflags)
258 bpfc_clean_custom:
259 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
260 trafgen_clean_custom:
261 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
263 netsniff-ng_install_custom flowtop_install_custom:
264 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,$(file),$(ETCDIRE));)
265 trafgen_install_custom:
266 $(Q)$(call INST,trafgen_stddef.h,$(ETCDIRE))
267 $(Q)ln -fs $(ETCDIRE)/trafgen_stddef.h $(ETCDIRE)/stddef.h
268 astraceroute_install_custom:
269 $(Q)$(call INST,geoip.conf,$(ETCDIRE))
270 netsniff-ng_uninstall_custom flowtop_uninstall_custom:
271 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
272 $(Q)$(call RMDIR,$(ETCDIRE))
273 trafgen_uninstall_custom:
274 $(Q)$(call RM,$(ETCDIRE)/stddef.h)
275 $(Q)$(call RMDIR,$(ETCDIRE))
276 astraceroute_uninstall_custom:
277 $(Q)$(call RM,$(ETCDIRE)/geoip.conf)
278 $(Q)$(call RMDIR,$(ETCDIRE))
280 $(TOOLS):
281 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
282 $(STRIP) $@/$@
284 nacl:
285 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
286 $(Q)cd curvetun/ && ./nacl_build.sh ~/nacl
287 $(Q)source ~/.bashrc
289 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
290 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
291 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
292 tarball: tarball.gz tarball.bz2 tarball.xz
294 tag:
295 $(GIT_TAG)
297 announcement:
298 $(Q)echo -e "netsniff-ng $(VERSION_STRING) has been released to the public (http://netsniff-ng.org/).\n" > .MAIL_MSG
299 $(Q)echo -e "It can be fetched via Git, through:\n" >> .MAIL_MSG
300 $(Q)echo -e " git clone git://github.com/borkmann/netsniff-ng.git" >> .MAIL_MSG
301 $(Q)echo -e " git checkout $(VERSION_STRING)\n" >> .MAIL_MSG
302 $(Q)echo -e "Or via HTTP, through:\n" >> .MAIL_MSG
303 $(Q)echo -e " wget http://pub.netsniff-ng.org/netsniff-ng/netsniff-ng-$(VERSION_STRING).tar.gz\n" >> .MAIL_MSG
304 $(Q)echo -e "The release be verified via Git, through (see README):\n" >> .MAIL_MSG
305 $(Q)echo -e " git tag -v $(VERSION_STRING)\n" >> .MAIL_MSG
306 $(Q)echo -e "Major high-level changes since the last release are:\n" >> .MAIL_MSG
307 $(Q)echo -e " *** BLURB HERE ***\n" >> .MAIL_MSG
308 $(Q)echo -e "Contributors since last release:\n" >> .MAIL_MSG
309 $(GIT_PEOPLE) >> .MAIL_MSG
310 $(Q)echo -e "Git changelog since the last release:\n" >> .MAIL_MSG
311 $(GIT_LOG) >> .MAIL_MSG
313 release: announcement tag tarball
314 $(Q)echo "Released $(bold)$(VERSION_STRING)$(normal)"
316 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
317 find . \( -name .git -type d -prune \) \
318 -o \( -name '*.[hcS]' -type f -print \) )
320 tags ctags:
321 $(Q)$(call RM,tags)
322 $(FIND_SOURCE_FILES) | xargs ctags -a
324 cscope:
325 $(Q)$(call RM,cscope*)
326 $(FIND_SOURCE_FILES) | xargs cscope -b
328 help:
329 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
330 $(Q)echo " <tool>:={$(TOOLS)}"
331 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
332 $(Q)echo " all|toolkit - Build the whole toolkit"
333 $(Q)echo " allbutcurvetun - Build all except curvetun"
334 $(Q)echo " allbutmausezahn - Build all except mausezahn"
335 $(Q)echo " <tool> - Build only one of the tools"
336 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
337 $(Q)echo " clean - Remove all build files"
338 $(Q)echo " <tool>_clean - Remove only one of the tool's files"
339 $(Q)echo " distclean - Remove all build and build config files"
340 $(Q)echo " mrproper - Remove all files not in source distribution"
341 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
342 $(Q)echo " install - Install the whole toolkit"
343 $(Q)echo " <tool>_install - Install only one of the tools"
344 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
345 $(Q)echo " uninstall - Remove the whole toolkit from the system"
346 $(Q)echo " <toolname>_uninstall - Remove only one of the tools"
347 $(Q)echo "$(bold)Hacking/development targets:$(normal)"
348 $(Q)echo " tag - Generate Git tag of current version"
349 $(Q)echo " tarball - Generate tarball of latest version"
350 $(Q)echo " release - Generate a new release"
351 $(Q)echo " tags - Generate sparse ctags"
352 $(Q)echo " cscope - Generate cscope files"
353 $(Q)echo "$(bold)Misc targets:$(normal)"
354 $(Q)echo " nacl - Execute the build_nacl script"
355 $(Q)echo " help - Show this help"
356 $(Q)echo "$(bold)Available parameters:$(normal)"
357 $(Q)echo " DEBUG=1 / DISTRO=1 - Enable debugging / Build for distros"
358 $(Q)echo " HARDENING=1 - Enable GCC hardening of executables"
359 $(Q)echo " PREFIX=/path - Install path prefix"
360 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
361 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
362 $(Q)echo " CC=cgcc - Use sparse compiler wrapper"
363 $(Q)echo " CFLAGS=\"-O2 -Wall ...\" - Overwrite CFLAGS for compilation"
364 $(Q)echo " CPPFLAGS=\"-I <path> ...\" - Additional CFLAGS for compilation"
365 $(Q)echo " LDFLAGS=\"-L <path> ...\" - Additional LDFLAGS for compilation"
366 $(Q)echo " CCACHE= - Do not use ccache for compilation"
367 $(Q)echo " Q= - Show verbose garbage"