build: add make release target
[netsniff-ng.git] / Makefile
blob339d05edcc2f337869db06550d1b44b935b69017
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 += -std=gnu99
70 WFLAGS = -Wall
71 WFLAGS += -Wformat=2
72 WFLAGS += -Wmissing-prototypes
73 WFLAGS += -Wdeclaration-after-statement
74 WFLAGS += -Werror-implicit-function-declaration
75 WFLAGS += -Wstrict-prototypes
76 WFLAGS += -Wundef
77 WFLAGS += -Wimplicit-int
79 WFLAGS_EXTRA = -Wno-unused-result
80 WFLAGS_EXTRA += -Wmissing-parameter-type
81 WFLAGS_EXTRA += -Wtype-limits
82 WFLAGS_EXTRA += -Wclobbered
83 WFLAGS_EXTRA += -Wmissing-field-initializers
84 WFLAGS_EXTRA += -Woverride-init
85 WFLAGS_EXTRA += -Wold-style-declaration
86 WFLAGS_EXTRA += -Wignored-qualifiers
87 WFLAGS_EXTRA += -Wempty-body
88 WFLAGS_EXTRA += -Wuninitialized
90 CFLAGS += $(WFLAGS) -I.
91 CPPFLAGS =
92 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
93 LDFLAGS = -L$(CROSS_LD_LIBRARY_PATH)
94 else
95 LDFLAGS =
96 endif
98 ALL_CFLAGS = $(CFLAGS)
99 ALL_LDFLAGS = $(LDFLAGS)
100 TARGET_ARCH =
101 LEX_FLAGS =
102 YAAC_FLAGS =
104 Q = @
106 LD = $(Q)echo -e " LD\t$@" && $(CCACHE) $(CROSS_COMPILE)gcc
107 CCNQ = $(CCACHE) $(CROSS_COMPILE)gcc
108 CC = $(Q)echo -e " CC\t$<" && $(CCNQ)
109 MKDIR = $(Q)echo -e " MKDIR\t$@" && mkdir
110 ifeq ($(DEBUG), 1)
111 STRIP = $(Q)true
112 else
113 STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip
114 endif
115 LEX = $(Q)echo -e " LEX\t$<" && flex
116 YAAC = $(Q)echo -e " YAAC\t$<" && bison
117 INST = echo -e " INST\t$(1)" && install -d $(2) && \
118 install --mode=644 -DC $(1) $(2)/$(shell basename $(1))
119 ifeq ("$(origin PREFIX)", "command line")
120 INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
121 install -C $(1) $(2)/$(shell basename $(1))
122 else
123 INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
124 endif
125 RM = echo -e " RM\t$(1)" && rm -rf $(1)
126 RMDIR = echo -e " RM\t$(1)" && rmdir --ignore-fail-on-non-empty $(1) 2> /dev/null || true
127 GIT_ARCHIVE = git archive --prefix=netsniff-ng-$(VERSION_STRING)/ $(VERSION_STRING) | \
128 $(1) > ../netsniff-ng-$(VERSION_STRING).tar.$(2)
129 GIT_TAG = git tag -a $(VERSION_STRING) -s -m "tools: $(VERSION_STRING) release"
130 GIT_LOG = git shortlog -n
132 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
133 export CROSS_COMPILE
135 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
136 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)
138 bold = $(shell tput bold)
139 normal = $(shell tput sgr0)
141 ifndef NACL_LIB_DIR
142 ifndef NACL_INC_DIR
143 $(info $(bold)NACL_LIB_DIR/NACL_INC_DIR is undefined, build libnacl first for curvetun!$(normal))
144 endif
145 endif
147 ifeq ("$(origin CROSS_COMPILE)", "command line")
148 WHAT := Cross compiling
149 else
150 WHAT := Building
151 endif
153 build_showinfo:
154 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
155 $(shell $(CCNQ) -dumpmachine)":$(normal)"
156 clean_showinfo:
157 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
159 %.yy.o: %.l
160 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
161 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
162 %.tab.o: %.y
163 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
164 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
166 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install tag tags cscope
167 .FORCE:
168 .DEFAULT_GOAL := all
169 .DEFAULT:
170 .IGNORE: %_clean_custom %_install_custom
171 .NOTPARALLEL: $(TOOLS)
173 DOC_FILES = Summary RelatedWork Performance KnownIssues Sponsors SubmittingPatches CodingStyle
175 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf geoip.conf
177 all: build_showinfo toolkit
178 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
179 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
180 toolkit: $(TOOLS)
181 install: install_all
182 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
183 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
184 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
185 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
186 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
187 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
188 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
189 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
190 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
191 $(Q)$(call RMDIR,$(DOCDIRE))
192 $(Q)$(call RMDIR,$(ETCDIRE))
193 mrproper: clean distclean
195 define TOOL_templ
196 include $(1)/Makefile
197 $(1) $(1)%: BUILD_DIR := $(1)
198 $(1)_prehook:
199 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
200 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
201 $(1)_clean: $(1)_clean_custom
202 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
203 $(1)_install: $(1)_install_custom
204 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
205 $(1)_distclean: $(1)_distclean_custom
206 $(Q)$$(call RM,$$(SBINDIR)/$(1))
207 $(1)/%.yy.o: $(1)/%.yy.c
208 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
209 $(1)/%.tab.o: $(1)/%.tab.c
210 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
211 $(1)/%.o: %.c
212 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
213 endef
215 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
217 %:: ;
219 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
220 trafgen: ALL_CFLAGS += -I.. $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) -D__WITH_PROTOS
221 ifpps: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
222 flowtop: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
223 bpfc: ALL_CFLAGS += -I..
224 curvetun: ALL_CFLAGS += -I ${NACL_INC_DIR}
225 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
227 bpfc_clean_custom:
228 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
229 trafgen_clean_custom:
230 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
232 netsniff-ng_distclean_custom flowtop_distclean_custom:
233 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
234 $(Q)$(call RMDIR,$(ETCDIRE))
235 trafgen_distclean_custom:
236 $(Q)$(call RM,$(ETCDIRE)/stddef.h)
237 $(Q)$(call RMDIR,$(ETCDIRE))
238 astraceroute_distclean_custom:
239 $(Q)$(call RM,$(ETCDIRE)/geoip.conf)
240 $(Q)$(call RMDIR,$(ETCDIRE))
242 netsniff-ng_install_custom flowtop_install_custom:
243 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,configs/$(file),$(ETCDIRE));)
244 trafgen_install_custom:
245 $(Q)$(call INST,configs/stddef.h,$(ETCDIRE))
246 astraceroute_install_custom:
247 $(Q)$(call INST,configs/geoip.conf,$(ETCDIRE))
249 $(TOOLS): WFLAGS += $(WFLAGS_EXTRA)
250 $(TOOLS):
251 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
252 $(STRIP) $@/$@
254 nacl:
255 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
256 $(Q)cd curvetun/ && ./build_nacl.sh ~/nacl
257 $(Q)source ~/.bashrc
259 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
260 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
261 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
262 tarball: tarball.gz tarball.bz2 tarball.xz
264 tag:
265 $(GIT_TAG)
267 announcement:
268 $(Q)echo -e "netsniff-ng $(VERSION_STRING) has been released to the public (http://netsniff-ng.org/).\n" > .MAIL_MSG
269 $(Q)echo -e "It can be fetched via Git, through:\n" >> .MAIL_MSG
270 $(Q)echo -e " git clone git://github.com/borkmann/netsniff-ng.git" >> .MAIL_MSG
271 $(Q)echo -e " git checkout $(VERSION_STRING)\n" >> .MAIL_MSG
272 $(Q)echo -e "Or via HTTP, through:\n" >> .MAIL_MSG
273 $(Q)echo -e " wget http://pub.netsniff-ng.org/netsniff-ng/netsniff-ng-$(VERSION_STRING).tar.gz\n" >> .MAIL_MSG
274 $(Q)echo -e "The release be verified via Git, through (see Documentation/Workflow):\n" >> .MAIL_MSG
275 $(Q)echo -e " git tag -v $(VERSION_STRING)\n" >> .MAIL_MSG
276 $(Q)echo -e "Major high-level changes since the last release are:\n" >> .MAIL_MSG
277 $(Q)echo -e " *** BLURB HERE ***\n" >> .MAIL_MSG
278 $(Q)echo -e "Git changelog since the last release:\n" >> .MAIL_MSG
279 $(GIT_LOG) >> .MAIL_MSG
281 release: tag tarball announcement
282 $(Q)echo "Released $(bold)$(VERSION_STRING)$(normal)"
284 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
285 find . \( -name .git -type d -prune \) \
286 -o \( -name '*.[hcS]' -type f -print \) )
288 tags ctags:
289 $(Q)$(call RM,tags)
290 $(FIND_SOURCE_FILES) | xargs ctags -a
292 cscope:
293 $(Q)$(call RM,cscope*)
294 $(FIND_SOURCE_FILES) | xargs cscope -b
296 help:
297 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
298 $(Q)echo " <toolnames>:={$(TOOLS)}"
299 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
300 $(Q)echo " all|toolkit - Build the whole toolkit"
301 $(Q)echo " allbutcurvetun - Build all except curvetun"
302 $(Q)echo " <toolname> - Build only one of the tools"
303 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
304 $(Q)echo " clean|mostlyclean - Remove all build files"
305 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
306 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
307 $(Q)echo " install - Install the whole toolkit"
308 $(Q)echo " <toolname>_install - Install only one of the tools"
309 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
310 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
311 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
312 $(Q)echo " mrproper - Remove build and install files"
313 $(Q)echo "$(bold)Hacking/development targets:$(normal)"
314 $(Q)echo " tag - Generate Git tag of current version"
315 $(Q)echo " tarball - Generate tarball of latest version"
316 $(Q)echo " release - Generate a new release"
317 $(Q)echo " tags - Generate sparse ctags"
318 $(Q)echo " cscope - Generate cscope files"
319 $(Q)echo "$(bold)Misc targets:$(normal)"
320 $(Q)echo " nacl - Execute the build_nacl script"
321 $(Q)echo " help - Show this help"
322 $(Q)echo "$(bold)Available parameters:$(normal)"
323 $(Q)echo " DEBUG=1 - Enable debugging"
324 $(Q)echo " PREFIX=/path - Install path prefix"
325 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
326 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
327 $(Q)echo " CC=cgcc - Use sparse compiler wrapper"
328 $(Q)echo " Q= - Show verbose garbage"