trafgen: update help description
[netsniff-ng.git] / Makefile
blob2781c0042f0608ed9eb5299177d6a320bf2112c5
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)
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 ifndef NACL_LIB_DIR
143 ifndef NACL_INC_DIR
144 $(info $(bold)NACL_LIB_DIR/NACL_INC_DIR is undefined, build libnacl first for curvetun!$(normal))
145 endif
146 endif
148 ifeq ("$(origin CROSS_COMPILE)", "command line")
149 WHAT := Cross compiling
150 else
151 WHAT := Building
152 endif
154 build_showinfo:
155 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
156 $(shell $(CCNQ) -dumpmachine)":$(normal)"
157 clean_showinfo:
158 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
160 %.yy.o: %.l
161 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
162 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
163 %.tab.o: %.y
164 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
165 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
167 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install tag tags cscope
168 .FORCE:
169 .DEFAULT_GOAL := all
170 .DEFAULT:
171 .IGNORE: %_clean_custom %_install_custom
172 .NOTPARALLEL: $(TOOLS)
174 DOC_FILES = Summary RelatedWork Performance KnownIssues Sponsors SubmittingPatches CodingStyle
176 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf geoip.conf
178 all: build_showinfo toolkit
179 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
180 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
181 toolkit: $(TOOLS)
182 install: install_all
183 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
184 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
185 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
186 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
187 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
188 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
189 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
190 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
191 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
192 $(Q)$(call RMDIR,$(DOCDIRE))
193 $(Q)$(call RMDIR,$(ETCDIRE))
194 mrproper: clean distclean
196 define TOOL_templ
197 include $(1)/Makefile
198 $(1) $(1)%: BUILD_DIR := $(1)
199 $(1)_prehook:
200 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
201 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
202 $(1)_clean: $(1)_clean_custom
203 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
204 $(1)_install: $(1)_install_custom
205 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
206 $(1)_distclean: $(1)_distclean_custom
207 $(Q)$$(call RM,$$(SBINDIR)/$(1))
208 $(1)/%.yy.o: $(1)/%.yy.c
209 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
210 $(1)/%.tab.o: $(1)/%.tab.c
211 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
212 $(1)/%.o: %.c
213 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
214 endef
216 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
218 %:: ;
220 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
221 trafgen: ALL_CFLAGS += -I.. $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) -D__WITH_PROTOS
222 ifpps: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
223 flowtop: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
224 bpfc: ALL_CFLAGS += -I..
225 curvetun: ALL_CFLAGS += -I ${NACL_INC_DIR}
226 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
228 bpfc_clean_custom:
229 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
230 trafgen_clean_custom:
231 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
233 netsniff-ng_distclean_custom flowtop_distclean_custom:
234 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
235 $(Q)$(call RMDIR,$(ETCDIRE))
236 trafgen_distclean_custom:
237 $(Q)$(call RM,$(ETCDIRE)/stddef.h)
238 $(Q)$(call RMDIR,$(ETCDIRE))
239 astraceroute_distclean_custom:
240 $(Q)$(call RM,$(ETCDIRE)/geoip.conf)
241 $(Q)$(call RMDIR,$(ETCDIRE))
243 netsniff-ng_install_custom flowtop_install_custom:
244 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,configs/$(file),$(ETCDIRE));)
245 trafgen_install_custom:
246 $(Q)$(call INST,configs/stddef.h,$(ETCDIRE))
247 astraceroute_install_custom:
248 $(Q)$(call INST,configs/geoip.conf,$(ETCDIRE))
250 $(TOOLS): WFLAGS += $(WFLAGS_EXTRA)
251 $(TOOLS):
252 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
253 $(STRIP) $@/$@
255 nacl:
256 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
257 $(Q)cd curvetun/ && ./nacl_build.sh ~/nacl
258 $(Q)source ~/.bashrc
260 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
261 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
262 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
263 tarball: tarball.gz tarball.bz2 tarball.xz
265 tag:
266 $(GIT_TAG)
268 announcement:
269 $(Q)echo -e "netsniff-ng $(VERSION_STRING) has been released to the public (http://netsniff-ng.org/).\n" > .MAIL_MSG
270 $(Q)echo -e "It can be fetched via Git, through:\n" >> .MAIL_MSG
271 $(Q)echo -e " git clone git://github.com/borkmann/netsniff-ng.git" >> .MAIL_MSG
272 $(Q)echo -e " git checkout $(VERSION_STRING)\n" >> .MAIL_MSG
273 $(Q)echo -e "Or via HTTP, through:\n" >> .MAIL_MSG
274 $(Q)echo -e " wget http://pub.netsniff-ng.org/netsniff-ng/netsniff-ng-$(VERSION_STRING).tar.gz\n" >> .MAIL_MSG
275 $(Q)echo -e "The release be verified via Git, through (see Documentation/Workflow):\n" >> .MAIL_MSG
276 $(Q)echo -e " git tag -v $(VERSION_STRING)\n" >> .MAIL_MSG
277 $(Q)echo -e "Major high-level changes since the last release are:\n" >> .MAIL_MSG
278 $(Q)echo -e " *** BLURB HERE ***\n" >> .MAIL_MSG
279 $(Q)echo -e "Git changelog since the last release:\n" >> .MAIL_MSG
280 $(GIT_LOG) >> .MAIL_MSG
282 release: announcement tag tarball
283 $(Q)echo "Released $(bold)$(VERSION_STRING)$(normal)"
285 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
286 find . \( -name .git -type d -prune \) \
287 -o \( -name '*.[hcS]' -type f -print \) )
289 tags ctags:
290 $(Q)$(call RM,tags)
291 $(FIND_SOURCE_FILES) | xargs ctags -a
293 cscope:
294 $(Q)$(call RM,cscope*)
295 $(FIND_SOURCE_FILES) | xargs cscope -b
297 help:
298 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
299 $(Q)echo " <toolnames>:={$(TOOLS)}"
300 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
301 $(Q)echo " all|toolkit - Build the whole toolkit"
302 $(Q)echo " allbutcurvetun - Build all except curvetun"
303 $(Q)echo " <toolname> - Build only one of the tools"
304 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
305 $(Q)echo " clean|mostlyclean - Remove all build files"
306 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
307 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
308 $(Q)echo " install - Install the whole toolkit"
309 $(Q)echo " <toolname>_install - Install only one of the tools"
310 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
311 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
312 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
313 $(Q)echo " mrproper - Remove build and install files"
314 $(Q)echo "$(bold)Hacking/development targets:$(normal)"
315 $(Q)echo " tag - Generate Git tag of current version"
316 $(Q)echo " tarball - Generate tarball of latest version"
317 $(Q)echo " release - Generate a new release"
318 $(Q)echo " tags - Generate sparse ctags"
319 $(Q)echo " cscope - Generate cscope files"
320 $(Q)echo "$(bold)Misc targets:$(normal)"
321 $(Q)echo " nacl - Execute the build_nacl script"
322 $(Q)echo " help - Show this help"
323 $(Q)echo "$(bold)Available parameters:$(normal)"
324 $(Q)echo " DEBUG=1 - Enable debugging"
325 $(Q)echo " PREFIX=/path - Install path prefix"
326 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
327 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
328 $(Q)echo " CC=cgcc - Use sparse compiler wrapper"
329 $(Q)echo " Q= - Show verbose garbage"