1 # netsniff-ng build system
2 # Copyright 2012 - 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
3 # Subject to the GNU GPL, version 2.
11 TOOLS
= netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun
13 # For packaging purposes, prefix can define a different path.
17 ifeq ("$(origin DEBUG)", "command line")
23 # Disable if you don't want it
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
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
47 CFLAGS
+= -march
=native
48 CFLAGS
+= -mtune
=native
52 CFLAGS
+= -fomit-frame-pointer
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
67 CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
72 WFLAGS
+= -Wmissing-prototypes
73 WFLAGS
+= -Wdeclaration-after-statement
74 WFLAGS
+= -Werror-implicit-function-declaration
75 WFLAGS
+= -Wstrict-prototypes
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.
92 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
93 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
98 ALL_CFLAGS
= $(CFLAGS
)
99 ALL_LDFLAGS
= $(LDFLAGS
)
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
113 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
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))
123 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
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
134 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
135 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
137 bold
= $(shell tput bold
)
138 normal
= $(shell tput sgr0
)
142 $(info $(bold
)NACL_LIB_DIR
/NACL_INC_DIR is undefined
, build libnacl first for curvetun
!$(normal
))
146 ifeq ("$(origin CROSS_COMPILE)", "command line")
147 WHAT
:= Cross compiling
153 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
154 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
156 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
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
) $<
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
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
))
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
195 include $(1)/Makefile
196 $(1) $(1)%: BUILD_DIR
:= $(1)
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
$$<
211 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
214 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
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}
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
)
248 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
252 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
253 $(Q
)cd curvetun
/ && .
/build_nacl.sh ~
/nacl
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
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 \
) )
270 $(FIND_SOURCE_FILES
) | xargs ctags
-a
273 $(Q
)$(call RM
,cscope
*)
274 $(FIND_SOURCE_FILES
) | xargs cscope
-b
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"