Corrected spinning loop potential in getrandombytes
[netsniff-ng-old.git] / Makefile
bloba211137eb6c664631d326a222c2f44003efd1596
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) -m "$(VERSION_STRING) release"
131 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
132 export CROSS_COMPILE
134 VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
135 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)
137 bold = $(shell tput bold)
138 normal = $(shell tput sgr0)
140 ifndef NACL_LIB_DIR
141 ifndef NACL_INC_DIR
142 $(info $(bold)NACL_LIB_DIR/NACL_INC_DIR is undefined, build libnacl first for curvetun!$(normal))
143 endif
144 endif
146 ifeq ("$(origin CROSS_COMPILE)", "command line")
147 WHAT := Cross compiling
148 else
149 WHAT := Building
150 endif
152 build_showinfo:
153 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
154 $(shell $(CCNQ) -dumpmachine)":$(normal)"
155 clean_showinfo:
156 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
158 %.yy.o: %.l
159 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
160 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
161 %.tab.o: %.y
162 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
163 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
165 .PHONY: all toolkit $(TOOLS) clean %_prehook %_distclean %_clean %_install tag tags cscope
166 .FORCE:
167 .DEFAULT_GOAL := all
168 .DEFAULT:
169 .IGNORE: %_clean_custom %_install_custom
170 .NOTPARALLEL: $(TOOLS)
172 DOC_FILES = Summary RelatedWork Performance KnownIssues Sponsors SubmittingPatches CodingStyle
174 NCONF_FILES = ether.conf tcp.conf udp.conf oui.conf geoip.conf
176 all: build_showinfo toolkit
177 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
178 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
179 toolkit: $(TOOLS)
180 install: install_all
181 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
182 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
183 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
184 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
185 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
186 $(Q)$(foreach file,$(DOC_FILES),$(call INST,Documentation/$(file),$(DOCDIRE));)
187 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
188 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
189 $(Q)$(foreach file,$(DOC_FILES),$(call RM,$(DOCDIRE)/$(file));)
190 $(Q)$(call RMDIR,$(DOCDIRE))
191 $(Q)$(call RMDIR,$(ETCDIRE))
192 mrproper: clean distclean
194 define TOOL_templ
195 include $(1)/Makefile
196 $(1) $(1)%: BUILD_DIR := $(1)
197 $(1)_prehook:
198 $(Q)echo "$(bold)$(WHAT) $(1):$(normal)"
199 $(1): $(1)_prehook $$($(1)-lex) $$($(1)-yaac) $$(patsubst %.o,$(1)/%.o,$$($(1)-objs))
200 $(1)_clean: $(1)_clean_custom
201 $(Q)$$(call RM,$(1)/*.o $(1)/$(1))
202 $(1)_install: $(1)_install_custom
203 $(Q)$$(call INSTX,$(1)/$(1),$$(SBINDIR))
204 $(1)_distclean: $(1)_distclean_custom
205 $(Q)$$(call RM,$$(SBINDIR)/$(1))
206 $(1)/%.yy.o: $(1)/%.yy.c
207 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
208 $(1)/%.tab.o: $(1)/%.tab.c
209 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
210 $(1)/%.o: %.c
211 $$(CC) $$(ALL_CFLAGS) -o $$@ -c $$<
212 endef
214 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
216 %:: ;
218 netsniff-ng: ALL_CFLAGS += -I$(INCDIR)/libnl3/ -D__WITH_PROTOS -D__WITH_TCPDUMP_LIKE_FILTER
219 trafgen: ALL_CFLAGS += -I.. -I$(INCDIR)/libnl3/ -D__WITH_PROTOS
220 bpfc: ALL_CFLAGS += -I..
221 curvetun: ALL_CFLAGS += -I ${NACL_INC_DIR}
222 curvetun: ALL_LDFLAGS += -L ${NACL_LIB_DIR}
224 bpfc_clean_custom:
225 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
226 trafgen_clean_custom:
227 $(Q)$(call RM,$(BUILD_DIR)/*.h $(BUILD_DIR)/*.c)
229 netsniff-ng_distclean_custom flowtop_distclean_custom:
230 $(Q)$(foreach file,$(NCONF_FILES),$(call RM,$(ETCDIRE)/$(file));)
231 $(Q)$(call RMDIR,$(ETCDIRE))
232 trafgen_distclean_custom:
233 $(Q)$(call RM,$(ETCDIRE)/stddef.h)
234 $(Q)$(call RMDIR,$(ETCDIRE))
235 astraceroute_distclean_custom:
236 $(Q)$(call RM,$(ETCDIRE)/geoip.conf)
237 $(Q)$(call RMDIR,$(ETCDIRE))
239 netsniff-ng_install_custom flowtop_install_custom:
240 $(Q)$(foreach file,$(NCONF_FILES),$(call INST,configs/$(file),$(ETCDIRE));)
241 trafgen_install_custom:
242 $(Q)$(call INST,configs/stddef.h,$(ETCDIRE))
243 astraceroute_install_custom:
244 $(Q)$(call INST,configs/geoip.conf,$(ETCDIRE))
246 $(TOOLS): WFLAGS += $(WFLAGS_EXTRA)
247 $(TOOLS):
248 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
249 $(STRIP) $@/$@
251 nacl:
252 $(Q)echo "$(bold)$(WHAT) $@:$(normal)"
253 $(Q)cd curvetun/ && ./build_nacl.sh ~/nacl
254 $(Q)source ~/.bashrc
256 tarball.gz: ; $(call GIT_ARCHIVE,gzip,gz)
257 tarball.bz2: ; $(call GIT_ARCHIVE,bzip2,bz2)
258 tarball.xz: ; $(call GIT_ARCHIVE,xz,xz)
259 tarball: tarball.gz tarball.bz2 tarball.xz
261 tag:
262 $(GIT_TAG)
264 FIND_SOURCE_FILES = ( git ls-files '*.[hcS]' 2>/dev/null || \
265 find . \( -name .git -type d -prune \) \
266 -o \( -name '*.[hcS]' -type f -print \) )
268 tags ctags:
269 $(Q)$(call RM,tags)
270 $(FIND_SOURCE_FILES) | xargs ctags -a
272 cscope:
273 $(Q)$(call RM,cscope*)
274 $(FIND_SOURCE_FILES) | xargs cscope -b
276 help:
277 $(Q)echo "$(bold)Available tools from the toolkit:$(normal)"
278 $(Q)echo " <toolnames>:={$(TOOLS)}"
279 $(Q)echo "$(bold)Targets for building the toolkit:$(normal)"
280 $(Q)echo " all|toolkit - Build the whole toolkit"
281 $(Q)echo " allbutcurvetun - Build all except curvetun"
282 $(Q)echo " <toolname> - Build only one of the tools"
283 $(Q)echo "$(bold)Targets for cleaning the toolkit's build files:$(normal)"
284 $(Q)echo " clean|mostlyclean - Remove all build files"
285 $(Q)echo " <toolname>_clean - Remove only one of the tool's files"
286 $(Q)echo "$(bold)Targets for installing the toolkit:$(normal)"
287 $(Q)echo " install - Install the whole toolkit"
288 $(Q)echo " <toolname>_install - Install only one of the tools"
289 $(Q)echo "$(bold)Targets for removing the toolkit:$(normal)"
290 $(Q)echo " realclean|distclean|clobber - Remove the whole toolkit from the system"
291 $(Q)echo " <toolname>_distclean - Remove only one of the tools"
292 $(Q)echo " mrproper - Remove build and install files"
293 $(Q)echo "$(bold)Hacking/development targets:$(normal)"
294 $(Q)echo " tag - Generate Git tag of current version"
295 $(Q)echo " tarball - Generate tarball of latest version"
296 $(Q)echo " tags - Generate sparse ctags"
297 $(Q)echo " cscope - Generate cscope files"
298 $(Q)echo "$(bold)Misc targets:$(normal)"
299 $(Q)echo " nacl - Execute the build_nacl script"
300 $(Q)echo " help - Show this help"
301 $(Q)echo "$(bold)Available parameters:$(normal)"
302 $(Q)echo " DEBUG=1 - Enable debugging"
303 $(Q)echo " PREFIX=/path - Install path prefix"
304 $(Q)echo " CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
305 $(Q)echo " CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
306 $(Q)echo " CC=cgcc - Use sparse compiler wrapper"
307 $(Q)echo " Q= - Show verbose garbage"