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 mausezahn 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 CFLAGS
+= -D__WITH_HARDWARE_TIMESTAMPING
=1
64 CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
69 WFLAGS_EXTRA
+= -Wmissing-prototypes
70 WFLAGS_EXTRA
+= -Wdeclaration-after-statement
71 WFLAGS_EXTRA
+= -Werror-implicit-function-declaration
72 WFLAGS_EXTRA
+= -Wundef
73 WFLAGS_EXTRA
+= -Wstrict-prototypes
74 WFLAGS_EXTRA
+= -Wunused-but-set-variable
76 CFLAGS
+= $(WFLAGS
) -I.
78 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
79 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
84 ALL_CFLAGS
= $(CFLAGS
)
85 ALL_LDFLAGS
= $(LDFLAGS
)
92 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
93 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
94 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
95 CCHK
= echo
-e
" CCHK\t$@" && cppcheck
-q
--std
=c99 \
96 --enable
=style
,performance
,portability
,unusedFunction \
97 --includes-file
=$(NACL_INC_DIR
)
98 MKDIR
= $(Q
)echo
-e
" MKDIR\t$@" && mkdir
102 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
104 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
105 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
106 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
107 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
108 ifeq ("$(origin PREFIX)", "command line")
109 INSTX
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
110 install -C
$(1) $(2)/$(shell basename $(1))
112 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
114 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
115 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
116 GIT_ARCHIVE
= cd ..
&& git archive
--prefix=netsniff-ng-
$(VERSION_STRING
)/ $(VERSION_STRING
) | \
117 $(1) > ..
/netsniff-ng-
$(VERSION_STRING
).
tar.
$(2)
119 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
122 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
123 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
125 TOOLS_MOST
= $(filter-out mausezahn
,$(TOOLS
))
127 bold
= $(shell tput bold
)
128 normal
= $(shell tput sgr0
)
130 # Build NaCl if no environment variables are set!
133 $(info $(bold
)NACL_LIB_DIR
/NACL_INC_DIR is undefined
, building libnacl with curvetun
!$(normal
))
138 ifeq ("$(origin CROSS_COMPILE)", "command line")
139 WHAT
:= Cross compiling
145 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
146 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
148 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
151 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
152 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
154 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
155 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
157 @if
[ -a
$(shell basename $@ .x
).c
]; then
$(CCHK
) $(shell basename $@ .x
).c || true
; fi
159 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install
163 .IGNORE
: %_clean_custom
%_install_custom
164 .NOTPARALLEL
: $(TOOLS
)
166 DOC_FILES
= Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
167 SubmittingPatches CodingStyle logo.png RelNotes
/Notes-
$(VERSION_SHORT
)
169 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf
171 all: build_showinfo toolkit
173 allbutcurvetun
: $(filter-out curvetun
,$(TOOLS
))
174 allbutmausezahn
: $(filter-out mausezahn
,$(TOOLS
))
175 install: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
176 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
177 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
178 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
179 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
180 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
181 $(Q
)$(foreach file
,$(DOC_FILES
),$(call RM
,$(DOCDIRE
)/$(file
));)
182 $(Q
)$(call RMDIR
,$(DOCDIRE
))
183 $(Q
)$(call RMDIR
,$(ETCDIRE
))
184 mrproper
: clean distclean
185 check: $(foreach tool
,$(TOOLS
),$(tool
)_check
)
188 include $(1)/Makefile
189 $(1) $(1)%: BUILD_DIR
:= $(1)
191 $(Q
)echo
"$(bold)$(WHAT) $(1):$(normal)"
193 $(Q
)echo
"$(bold)Checking $(1):$(normal)"
194 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
195 $(1)_clean
: $(1)_clean_custom
196 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1))
197 $(1)_check
: $(1)_prehook_check
$$(patsubst %.o
,%.x
,$$($(1)-objs
))
198 $(1)_install
: $(1)_install_custom
199 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
200 $(Q
)$$(call INST
,..
/Documentation
/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE
))
201 $(1)_distclean
: $(1)_distclean_custom
202 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
203 $(Q
)$$(call RM
,$$(DOCDIRE
)/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'))
204 $(1)/%.yy.o
: $(1)/%.yy.c
205 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
206 $(1)/%.tab.o
: $(1)/%.tab.c
207 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
209 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
212 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
216 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
217 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
218 bpfc
: ALL_CFLAGS
+= -I..
219 curvetun
: ALL_CFLAGS
+= -I NACL_INC_DIR
220 curvetun
: ALL_LDFLAGS
+= -L NACL_LIB_DIR
223 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
224 trafgen_clean_custom
:
225 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
227 netsniff-ng_distclean_custom flowtop_distclean_custom
:
228 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
229 $(Q
)$(call RMDIR
,$(ETCDIRE
))
230 astraceroute_distclean_custom
:
231 $(Q
)$(call RM
,$(ETCDIRE
)/whois.conf
)
232 $(Q
)$(call RM
,$(SBINDIR
)/astraceroute6
)
233 $(Q
)$(call RMDIR
,$(ETCDIRE
))
235 netsniff-ng_install_custom flowtop_install_custom
:
236 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,conf
/$(file
),$(ETCDIRE
));)
237 astraceroute_install_custom
:
238 $(Q
)$(call INST
,conf
/whois.conf
,$(ETCDIRE
))
239 $(Q
)$(call INSTX
,..
/scripts
/astraceroute6
,$(SBINDIR
))
241 $(TOOLS_MOST
): WFLAGS
+= $(WFLAGS_EXTRA
)
243 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
247 $(Q
)..
/scripts
/geoip-database-update
249 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
250 $(Q
)cd curvetun
/ && .
/build_nacl.sh ~
/nacl
253 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
254 $(Q
)cd astraceroute
/ && .
/build_geoip.sh
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
262 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
263 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
264 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
265 $(Q
)echo
" all|toolkit - Build the whole toolkit"
266 $(Q
)echo
" allbutcurvetun - Build all except curvetun"
267 $(Q
)echo
" <toolname> - Build only one of the tools"
268 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
269 $(Q
)echo
" clean|mostlyclean - Remove all build files"
270 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
271 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
272 $(Q
)echo
" install - Install the whole toolkit"
273 $(Q
)echo
" <toolname>_install - Install only one of the tools"
274 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
275 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
276 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
277 $(Q
)echo
"$(bold)Targets for checking the toolkit:$(normal)"
278 $(Q
)echo
" check - Do a static code analysis"
279 $(Q
)echo
" <toolname>_check - Check only one of the tools"
280 $(Q
)echo
"$(bold)Misc targets:$(normal)"
281 $(Q
)echo
" tarball - Generate tarball of latest version"
282 $(Q
)echo
" mrproper - Remove build and install files"
283 $(Q
)echo
" update - Update to the latest GeoIP database"
284 $(Q
)echo
" nacl - Execute the build_nacl script"
285 $(Q
)echo
" geoip - Execute the build_geoip script"
286 $(Q
)echo
" help - Show this help"
287 $(Q
)echo
"$(bold)Available parameters:$(normal)"
288 $(Q
)echo
" DEBUG=1 - Enable debugging"
289 $(Q
)echo
" PREFIX=/path - Install path prefix"
290 $(Q
)echo
" CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
291 $(Q
)echo
" CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
292 $(Q
)echo
" Q= - Show verbose garbage"