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
+= -Wmissing-prototypes
70 WFLAGS
+= -Wdeclaration-after-statement
71 WFLAGS
+= -Werror-implicit-function-declaration
72 WFLAGS
+= -Wstrict-prototypes
74 WFLAGS
+= -Wimplicit-int
76 WFLAGS_EXTRA
= -Wno-unused-result
77 WFLAGS_EXTRA
+= -Wmissing-parameter-type
78 WFLAGS_EXTRA
+= -Wunused-but-set-parameter
79 WFLAGS_EXTRA
+= -Wtype-limits
80 WFLAGS_EXTRA
+= -Wclobbered
81 WFLAGS_EXTRA
+= -Wmissing-field-initializers
82 WFLAGS_EXTRA
+= -Woverride-init
83 WFLAGS_EXTRA
+= -Wold-style-declaration
84 WFLAGS_EXTRA
+= -Wignored-qualifiers
85 WFLAGS_EXTRA
+= -Wempty-body
86 WFLAGS_EXTRA
+= -Wuninitialized
88 CFLAGS
+= $(WFLAGS
) -I.
90 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
91 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
96 ALL_CFLAGS
= $(CFLAGS
)
97 ALL_LDFLAGS
= $(LDFLAGS
)
104 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
105 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
106 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
107 CCHK
= echo
-e
" CCHK\t$@" && cppcheck
-q
--std
=c99 \
108 --enable
=style
,performance
,portability
,unusedFunction \
109 --includes-file
=${NACL_INC_DIR}
110 MKDIR
= $(Q
)echo
-e
" MKDIR\t$@" && mkdir
114 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
116 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
117 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
118 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
119 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
120 ifeq ("$(origin PREFIX)", "command line")
121 INSTX
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
122 install -C
$(1) $(2)/$(shell basename $(1))
124 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
126 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
127 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
128 GIT_ARCHIVE
= cd ..
&& git archive
--prefix=netsniff-ng-
$(VERSION_STRING
)/ $(VERSION_STRING
) | \
129 $(1) > ..
/netsniff-ng-
$(VERSION_STRING
).
tar.
$(2)
131 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
134 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
135 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
137 TOOLS_MOST
= $(filter-out mausezahn
,$(TOOLS
))
139 bold
= $(shell tput bold
)
140 normal
= $(shell tput sgr0
)
142 # Build NaCl if no environment variables are set!
145 $(info $(bold
)NACL_LIB_DIR
/NACL_INC_DIR is undefined
, building libnacl with curvetun
!$(normal
))
150 ifeq ("$(origin CROSS_COMPILE)", "command line")
151 WHAT
:= Cross compiling
157 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
158 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
160 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
163 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
164 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
166 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
167 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
169 @if
[ -a
$(shell basename $@ .x
).c
]; then
$(CCHK
) $(shell basename $@ .x
).c || true
; fi
171 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install
175 .IGNORE
: %_clean_custom
%_install_custom
176 .NOTPARALLEL
: $(TOOLS
)
178 DOC_FILES
= Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
179 SubmittingPatches CodingStyle logo.png RelNotes
/Notes-
$(VERSION_SHORT
)
181 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf
183 all: build_showinfo toolkit
184 toolkit
: allbutmausezahn
185 allbutcurvetun
: $(filter-out mausezahn
,$(filter-out curvetun
,$(TOOLS
)))
186 allbutmausezahn
: $(filter-out mausezahn
,$(TOOLS
))
187 install: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
188 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
189 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
190 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
191 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
192 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
193 $(Q
)$(foreach file
,$(DOC_FILES
),$(call RM
,$(DOCDIRE
)/$(file
));)
194 $(Q
)$(call RMDIR
,$(DOCDIRE
))
195 $(Q
)$(call RMDIR
,$(ETCDIRE
))
196 mrproper
: clean distclean
197 check: $(foreach tool
,$(TOOLS
),$(tool
)_check
)
200 include $(1)/Makefile
201 $(1) $(1)%: BUILD_DIR
:= $(1)
203 $(Q
)echo
"$(bold)$(WHAT) $(1):$(normal)"
205 $(Q
)echo
"$(bold)Checking $(1):$(normal)"
206 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
207 $(1)_clean
: $(1)_clean_custom
208 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1))
209 $(1)_check
: $(1)_prehook_check
$$(patsubst %.o
,%.x
,$$($(1)-objs
))
210 $(1)_install
: $(1)_install_custom
211 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
212 $(Q
)$$(call INST
,..
/Documentation
/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE
))
213 $(1)_distclean
: $(1)_distclean_custom
214 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
215 $(Q
)$$(call RM
,$$(DOCDIRE
)/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'))
216 $(1)/%.yy.o
: $(1)/%.yy.c
217 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
218 $(1)/%.tab.o
: $(1)/%.tab.c
219 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
221 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
224 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
228 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
229 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
230 bpfc
: ALL_CFLAGS
+= -I..
231 curvetun
: ALL_CFLAGS
+= -I
${NACL_INC_DIR}
232 curvetun
: ALL_LDFLAGS
+= -L
${NACL_LIB_DIR}
235 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
236 trafgen_clean_custom
:
237 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
239 netsniff-ng_distclean_custom flowtop_distclean_custom
:
240 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
241 $(Q
)$(call RMDIR
,$(ETCDIRE
))
242 astraceroute_distclean_custom
:
243 $(Q
)$(call RM
,$(ETCDIRE
)/whois.conf
)
244 $(Q
)$(call RM
,$(SBINDIR
)/astraceroute6
)
245 $(Q
)$(call RMDIR
,$(ETCDIRE
))
247 netsniff-ng_install_custom flowtop_install_custom
:
248 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,conf
/$(file
),$(ETCDIRE
));)
249 astraceroute_install_custom
:
250 $(Q
)$(call INST
,conf
/whois.conf
,$(ETCDIRE
))
251 $(Q
)$(call INSTX
,..
/scripts
/astraceroute6
,$(SBINDIR
))
253 $(TOOLS
): WFLAGS
+= $(WFLAGS_EXTRA
)
255 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
259 $(Q
)..
/scripts
/geoip-database-update
261 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
262 $(Q
)cd curvetun
/ && .
/build_nacl.sh ~
/nacl
265 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
266 $(Q
)cd astraceroute
/ && .
/build_geoip.sh
268 tarball.gz
: ; $(call GIT_ARCHIVE
,gzip
,gz
)
269 tarball.bz2
: ; $(call GIT_ARCHIVE
,bzip2
,bz2
)
270 tarball.xz
: ; $(call GIT_ARCHIVE
,xz
,xz
)
271 tarball
: tarball.gz tarball.bz2 tarball.xz
274 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
275 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
276 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
277 $(Q
)echo
" all|toolkit - Build the whole toolkit"
278 $(Q
)echo
" allbutcurvetun - Build all except curvetun"
279 $(Q
)echo
" <toolname> - Build only one of the tools"
280 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
281 $(Q
)echo
" clean|mostlyclean - Remove all build files"
282 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
283 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
284 $(Q
)echo
" install - Install the whole toolkit"
285 $(Q
)echo
" <toolname>_install - Install only one of the tools"
286 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
287 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
288 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
289 $(Q
)echo
"$(bold)Targets for checking the toolkit:$(normal)"
290 $(Q
)echo
" check - Do a static code analysis"
291 $(Q
)echo
" <toolname>_check - Check only one of the tools"
292 $(Q
)echo
"$(bold)Misc targets:$(normal)"
293 $(Q
)echo
" tarball - Generate tarball of latest version"
294 $(Q
)echo
" mrproper - Remove build and install files"
295 $(Q
)echo
" update - Update to the latest GeoIP database"
296 $(Q
)echo
" nacl - Execute the build_nacl script"
297 $(Q
)echo
" geoip - Execute the build_geoip script"
298 $(Q
)echo
" help - Show this help"
299 $(Q
)echo
"$(bold)Available parameters:$(normal)"
300 $(Q
)echo
" DEBUG=1 - Enable debugging"
301 $(Q
)echo
" PREFIX=/path - Install path prefix"
302 $(Q
)echo
" CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
303 $(Q
)echo
" CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
304 $(Q
)echo
" Q= - Show verbose garbage"