proto_none: minor: make hex/chr conform with the rest
[netsniff-ng.git] / Makefile
blobb252a1391dbb936371cb8625ad0f563ee07faee4
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 CCHK = echo -e " CCHK\t$@" && cppcheck -q --std=c99 \
110 --enable=style,performance,portability,unusedFunction \
111 --includes-file=${NACL_INC_DIR}
112 MKDIR = $(Q)echo -e " MKDIR\t$@" && mkdir
113 ifeq ($(DEBUG), 1)
114 STRIP = $(Q)true
115 else
116 STRIP = $(Q)echo -e " STRIP\t$@" && $(CROSS_COMPILE)strip
117 endif
118 LEX = $(Q)echo -e " LEX\t$<" && flex
119 YAAC = $(Q)echo -e " YAAC\t$<" && bison
120 INST = echo -e " INST\t$(1)" && install -d $(2) && \
121 install --mode=644 -DC $(1) $(2)/$(shell basename $(1))
122 ifeq ("$(origin PREFIX)", "command line")
123 INSTX = echo -e " INST\t$(1)" && install -d $(2) && \
124 install -C $(1) $(2)/$(shell basename $(1))
125 else
126 INSTX = echo -e " INST\t$(1)" && install -C $(1) $(2)/$(shell basename $(1))
127 endif
128 RM = echo -e " RM\t$(1)" && rm -rf $(1)
129 RMDIR = echo -e " RM\t$(1)" && rmdir --ignore-fail-on-non-empty $(1) 2> /dev/null || true
130 GIT_ARCHIVE = git archive --prefix=netsniff-ng-$(VERSION_STRING)/ $(VERSION_STRING) | \
131 $(1) > ../netsniff-ng-$(VERSION_STRING).tar.$(2)
132 GIT_TAG = git tag -a $(VERSION_STRING) -m "$(VERSION_STRING) release"
134 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
135 export CROSS_COMPILE
137 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
138 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)
140 bold = $(shell tput bold)
141 normal = $(shell tput sgr0)
143 $(shell . ~/.bashrc)
144 # Build NaCl if no environment variables are set!
145 ifndef NACL_LIB_DIR
146 ifndef NACL_INC_DIR
147 $(info $(bold)NACL_LIB_DIR/NACL_INC_DIR is undefined, building libnacl with curvetun!$(normal))
148 curvetun: nacl
149 endif
150 endif
152 ifeq ("$(origin CROSS_COMPILE)", "command line")
153 WHAT := Cross compiling
154 else
155 WHAT := Building
156 endif
158 build_showinfo:
159 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
160 $(shell $(CCNQ) -dumpmachine)":$(normal)"
161 clean_showinfo:
162 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
164 %.yy.o: %.l
165 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
166 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
167 %.tab.o: %.y
168 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
169 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
170 %.x:
171 @if [ -a $(shell basename $@ .x).c ]; then $(CCHK) $(shell basename $@ .x).c || true; fi
173 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install
174 .FORCE:
175 .DEFAULT_GOAL := all
176 .DEFAULT:
177 .IGNORE: %_clean_custom %_install_custom
178 .NOTPARALLEL: $(TOOLS)
180 DOC_FILES = Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
181 SubmittingPatches CodingStyle logo.png RelNotes/Notes-$(VERSION_SHORT)
183 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf
185 all: build_showinfo toolkit
186 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
187 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
188 toolkit: $(TOOLS)
189 install: install_all
190 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
191 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
192 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
193 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
194 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
195 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
196 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
197 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
198 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
199 $(Q)$(call RMDIR,$(DOCDIRE))
200 $(Q)$(call RMDIR,$(ETCDIRE))
201 mrproper: clean distclean
202 check: $(foreach tool,$(TOOLS),$(tool)_check)
204 define TOOL_templ
205 include $(1)/Makefile
206 $(1) $(1)%: BUILD_DIR := $(1)
207 $(1)_prehook:
208 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
209 $(1)_prehook_check:
210 $(Q)echo "$(bold)Checking $(1):$(normal)"
211 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
212 $(1)_clean: $(1)_clean_custom
213 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
214 $(1)_check: $(1)_prehook_check $$(patsubst %.o,%.x,$$($(1)-objs))
215 $(1)_install: $(1)_install_custom
216 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
217 $(Q)$$(call INST,Documentation/$$(shell echo $(1) | sed 's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE))
218 $(1)_distclean: $(1)_distclean_custom
219 $(Q)$$(call RM,$$(SBINDIR)/$(1))
220 $(Q)$$(call RM,$$(DOCDIRE)/$$(shell echo $(1) | sed 's/\([a-z]\)\(.*\)/\u\1\2/g'))
221 $(1)/%.yy.o: $(1)/%.yy.c
222 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
223 $(1)/%.tab.o: $(1)/%.tab.c
224 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
225 $(1)/%.o: %.c
226 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
227 endef
229 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
231 %:: ;
233 netsniff-ng: ALL_CFLAGS += -I$(INCDIR)/libnl3/ -D__WITH_PROTOS -D__WITH_TCPDUMP_LIKE_FILTER
234 trafgen: ALL_CFLAGS += -I.. -I$(INCDIR)/libnl3/ -D__WITH_PROTOS
235 bpfc: ALL_CFLAGS += -I..
236 curvetun: ALL_CFLAGS += -I ${NACL_INC_DIR}
237 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
239 bpfc_clean_custom:
240 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
241 trafgen_clean_custom:
242 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
244 netsniff-ng_distclean_custom flowtop_distclean_custom:
245 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
246 $(Q)$(call RMDIR,$(ETCDIRE))
247 astraceroute_distclean_custom:
248 $(Q)$(call RM,$(ETCDIRE)/whois.conf)
249 $(Q)$(call RM,$(SBINDIR)/astraceroute6)
250 $(Q)$(call RMDIR,$(ETCDIRE))
252 netsniff-ng_install_custom flowtop_install_custom:
253 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,configs/$(file),$(ETCDIRE));)
254 astraceroute_install_custom:
255 $(Q)$(call INST,configs/whois.conf,$(ETCDIRE))
257 $(TOOLS): WFLAGS += $(WFLAGS_EXTRA)
258 $(TOOLS):
259 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
260 $(STRIP) $@/$@
262 update:
263 $(Q)./update-geoip.sh
264 nacl:
265 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
266 $(Q)cd curvetun/ && ./build_nacl.sh ~/nacl
267 $(Q)source ~/.bashrc
268 geoip:
269 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
270 $(Q)cd astraceroute/ && ./build_geoip.sh
272 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
273 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
274 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
275 tarball: tarball.gz tarball.bz2 tarball.xz
277 tag:
278 $(GIT_TAG)
280 help:
281 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
282 $(Q)echo " <toolnames>:={$(TOOLS)}"
283 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
284 $(Q)echo " all|toolkit - Build the whole toolkit"
285 $(Q)echo " allbutcurvetun - Build all except curvetun"
286 $(Q)echo " <toolname> - Build only one of the tools"
287 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
288 $(Q)echo " clean|mostlyclean - Remove all build files"
289 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
290 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
291 $(Q)echo " install - Install the whole toolkit"
292 $(Q)echo " <toolname>_install - Install only one of the tools"
293 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
294 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
295 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
296 $(Q)echo "$(bold)Targets for checking the toolkit:$(normal)"
297 $(Q)echo " check - Do a static code analysis"
298 $(Q)echo " <toolname>_check - Check only one of the tools"
299 $(Q)echo "$(bold)Misc targets:$(normal)"
300 $(Q)echo " tarball - Generate tarball of latest version"
301 $(Q)echo " tag - Generate Git tag of current version"
302 $(Q)echo " mrproper - Remove build and install files"
303 $(Q)echo " update - Update to the latest GeoIP database"
304 $(Q)echo " nacl - Execute the build_nacl script"
305 $(Q)echo " geoip - Execute the build_geoip script"
306 $(Q)echo " help - Show this help"
307 $(Q)echo "$(bold)Available parameters:$(normal)"
308 $(Q)echo " DEBUG=1 - Enable debugging"
309 $(Q)echo " PREFIX=/path - Install path prefix"
310 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
311 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
312 $(Q)echo " Q= - Show verbose garbage"