1 # netsniff-ng build system, part of netsniff-ng.
2 # Copyright 2012 Daniel Borkmann <borkmann@gnumaniacs.org>
3 # Subject to the GNU GPL, version 2.
10 TOOLS
= netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun
12 # For packaging purposes, prefix can define a different path.
16 ifeq ("$(origin DEBUG)", "command line")
22 # Disable if you don't want it
25 # Location of installation paths.
26 BINDIR
= $(PREFIX
)/usr
/bin
27 SBINDIR
= $(PREFIX
)/usr
/sbin
28 INCDIR
= $(PREFIX
)/usr
/include
29 ETCDIR
= $(PREFIX
)/etc
30 ETCDIRE
= $(ETCDIR
)/netsniff-ng
31 DOCDIR
= $(PREFIX
)/usr
/share
/doc
32 DOCDIRE
= $(DOCDIR
)/netsniff-ng
34 # Shut up make, helper warnings, parallel compilation!
35 MAKEFLAGS
+= --no-print-directory
37 MAKEFLAGS
+= --warn-undefined-variables
38 MAKEFLAGS
+= --jobs
=$(shell grep
"^processor" /proc
/cpuinfo | wc
-l
)
40 # For packaging purposes, you might want to disable O3+arch tuning
41 CFLAGS
= -fstack-protector
46 CFLAGS
+= -march
=native
47 CFLAGS
+= -mtune
=native
51 CFLAGS
+= -fomit-frame-pointer
53 CFLAGS
+= --param
=ssp-buffer-size
=4
54 CFLAGS
+= -fno-strict-aliasing
55 CFLAGS
+= -fexceptions
56 CFLAGS
+= -fasynchronous-unwind-tables
57 CFLAGS
+= -fno-delete-null-pointer-checks
58 CFLAGS
+= -D_FORTIFY_SOURCE
=2
59 CFLAGS
+= -D_REENTRANT
60 CFLAGS
+= -D_FILE_OFFSET_BITS
=64
61 CFLAGS
+= -D_LARGEFILE_SOURCE
62 CFLAGS
+= -D_LARGEFILE64_SOURCE
63 ifneq ($(wildcard /usr
/include/linux
/net_tstamp.h
),)
64 CFLAGS
+= -D__WITH_HARDWARE_TIMESTAMPING
66 CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
71 WFLAGS
+= -Wmissing-prototypes
72 WFLAGS
+= -Wdeclaration-after-statement
73 WFLAGS
+= -Werror-implicit-function-declaration
74 WFLAGS
+= -Wstrict-prototypes
76 WFLAGS
+= -Wimplicit-int
78 WFLAGS_EXTRA
= -Wno-unused-result
79 WFLAGS_EXTRA
+= -Wmissing-parameter-type
80 WFLAGS_EXTRA
+= -Wtype-limits
81 WFLAGS_EXTRA
+= -Wclobbered
82 WFLAGS_EXTRA
+= -Wmissing-field-initializers
83 WFLAGS_EXTRA
+= -Woverride-init
84 WFLAGS_EXTRA
+= -Wold-style-declaration
85 WFLAGS_EXTRA
+= -Wignored-qualifiers
86 WFLAGS_EXTRA
+= -Wempty-body
87 WFLAGS_EXTRA
+= -Wuninitialized
89 CFLAGS
+= $(WFLAGS
) -I.
91 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
92 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
97 ALL_CFLAGS
= $(CFLAGS
)
98 ALL_LDFLAGS
= $(LDFLAGS
)
105 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
106 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
107 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
108 CCHK
= echo
-e
" CCHK\t$@" && cppcheck
-q
--std
=c99 \
109 --enable
=style
,performance
,portability
,unusedFunction \
110 --includes-file
=${NACL_INC_DIR}
111 MKDIR
= $(Q
)echo
-e
" MKDIR\t$@" && mkdir
115 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
117 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
118 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
119 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
120 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
121 ifeq ("$(origin PREFIX)", "command line")
122 INSTX
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
123 install -C
$(1) $(2)/$(shell basename $(1))
125 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
127 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
128 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
129 GIT_ARCHIVE
= git archive
--prefix=netsniff-ng-
$(VERSION_STRING
)/ $(VERSION_STRING
) | \
130 $(1) > ..
/netsniff-ng-
$(VERSION_STRING
).
tar.
$(2)
131 GIT_TAG
= git tag
-a
$(VERSION_STRING
) -m
"$(VERSION_STRING) release"
133 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
136 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
137 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
139 bold
= $(shell tput bold
)
140 normal
= $(shell tput sgr0
)
143 # Build NaCl if no environment variables are set!
146 $(info $(bold
)NACL_LIB_DIR
/NACL_INC_DIR is undefined
, building libnacl with curvetun
!$(normal
))
151 ifeq ("$(origin CROSS_COMPILE)", "command line")
152 WHAT
:= Cross compiling
158 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
159 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
161 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
164 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
165 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
167 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
168 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
170 @if
[ -a
$(shell basename $@ .x
).c
]; then
$(CCHK
) $(shell basename $@ .x
).c || true
; fi
172 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install
176 .IGNORE
: %_clean_custom
%_install_custom
177 .NOTPARALLEL
: $(TOOLS
)
179 DOC_FILES
= Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
180 SubmittingPatches CodingStyle logo.png RelNotes
/Notes-
$(VERSION_SHORT
)
182 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf
184 all: build_showinfo toolkit
185 allbutcurvetun
: $(filter-out curvetun
,$(TOOLS
))
186 allbutmausezahn
: $(filter-out mausezahn
,$(TOOLS
))
189 install_all
: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
190 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,Documentation
/$(file
),$(DOCDIRE
));)
191 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
192 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,Documentation
/$(file
),$(DOCDIRE
));)
193 install_allbutmausezahn
: $(foreach tool
,$(filter-out mausezahn
,$(TOOLS
)),$(tool
)_install
)
194 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,Documentation
/$(file
),$(DOCDIRE
));)
195 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
196 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
197 $(Q
)$(foreach file
,$(DOC_FILES
),$(call RM
,$(DOCDIRE
)/$(file
));)
198 $(Q
)$(call RMDIR
,$(DOCDIRE
))
199 $(Q
)$(call RMDIR
,$(ETCDIRE
))
200 mrproper
: clean distclean
201 check: $(foreach tool
,$(TOOLS
),$(tool
)_check
)
204 include $(1)/Makefile
205 $(1) $(1)%: BUILD_DIR
:= $(1)
207 $(Q
)echo
"$(bold)$(WHAT) $(1):$(normal)"
209 $(Q
)echo
"$(bold)Checking $(1):$(normal)"
210 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
211 $(1)_clean
: $(1)_clean_custom
212 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1))
213 $(1)_check
: $(1)_prehook_check
$$(patsubst %.o
,%.x
,$$($(1)-objs
))
214 $(1)_install
: $(1)_install_custom
215 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
216 $(Q
)$$(call INST
,Documentation
/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE
))
217 $(1)_distclean
: $(1)_distclean_custom
218 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
219 $(Q
)$$(call RM
,$$(DOCDIRE
)/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'))
220 $(1)/%.yy.o
: $(1)/%.yy.c
221 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
222 $(1)/%.tab.o
: $(1)/%.tab.c
223 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
225 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
228 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
232 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
-D__WITH_TCPDUMP_LIKE_FILTER
233 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
234 bpfc
: ALL_CFLAGS
+= -I..
235 curvetun
: ALL_CFLAGS
+= -I
${NACL_INC_DIR}
236 curvetun
: ALL_LDFLAGS
+= -L
${NACL_LIB_DIR}
239 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
240 trafgen_clean_custom
:
241 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
243 netsniff-ng_distclean_custom flowtop_distclean_custom
:
244 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
245 $(Q
)$(call RMDIR
,$(ETCDIRE
))
246 astraceroute_distclean_custom
:
247 $(Q
)$(call RM
,$(ETCDIRE
)/whois.conf
)
248 $(Q
)$(call RM
,$(SBINDIR
)/astraceroute6
)
249 $(Q
)$(call RMDIR
,$(ETCDIRE
))
251 netsniff-ng_install_custom flowtop_install_custom
:
252 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,configs
/$(file
),$(ETCDIRE
));)
253 astraceroute_install_custom
:
254 $(Q
)$(call INST
,configs
/whois.conf
,$(ETCDIRE
))
256 $(TOOLS
): WFLAGS
+= $(WFLAGS_EXTRA
)
258 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
262 $(Q
).
/update-geoip.sh
264 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
265 $(Q
)cd curvetun
/ && .
/build_nacl.sh ~
/nacl
268 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
269 $(Q
)cd astraceroute
/ && .
/build_geoip.sh
271 tarball.gz
: ; $(call GIT_ARCHIVE
,gzip
,gz
)
272 tarball.bz2
: ; $(call GIT_ARCHIVE
,bzip2
,bz2
)
273 tarball.xz
: ; $(call GIT_ARCHIVE
,xz
,xz
)
274 tarball
: tarball.gz tarball.bz2 tarball.xz
280 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
281 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
282 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
283 $(Q
)echo
" all|toolkit - Build the whole toolkit"
284 $(Q
)echo
" allbutcurvetun - Build all except curvetun"
285 $(Q
)echo
" <toolname> - Build only one of the tools"
286 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
287 $(Q
)echo
" clean|mostlyclean - Remove all build files"
288 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
289 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
290 $(Q
)echo
" install - Install the whole toolkit"
291 $(Q
)echo
" <toolname>_install - Install only one of the tools"
292 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
293 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
294 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
295 $(Q
)echo
"$(bold)Targets for checking the toolkit:$(normal)"
296 $(Q
)echo
" check - Do a static code analysis"
297 $(Q
)echo
" <toolname>_check - Check only one of the tools"
298 $(Q
)echo
"$(bold)Misc targets:$(normal)"
299 $(Q
)echo
" tarball - Generate tarball of latest version"
300 $(Q
)echo
" tag - Generate Git tag of current version"
301 $(Q
)echo
" mrproper - Remove build and install files"
302 $(Q
)echo
" update - Update to the latest GeoIP database"
303 $(Q
)echo
" nacl - Execute the build_nacl script"
304 $(Q
)echo
" geoip - Execute the build_geoip script"
305 $(Q
)echo
" help - Show this help"
306 $(Q
)echo
"$(bold)Available parameters:$(normal)"
307 $(Q
)echo
" DEBUG=1 - Enable debugging"
308 $(Q
)echo
" PREFIX=/path - Install path prefix"
309 $(Q
)echo
" CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
310 $(Q
)echo
" CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
311 $(Q
)echo
" Q= - Show verbose garbage"