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 mausezahn
13 # For packaging purposes, prefix can define a different path.
16 # Disable if you don't want it
19 # Location of installation paths.
20 SBINDIR
= $(PREFIX
)/usr
/sbin
21 INCDIR
= $(PREFIX
)/usr
/include
22 ETCDIR
= $(PREFIX
)/etc
23 ETCDIRE
= $(ETCDIR
)/netsniff-ng
24 MAN8DIR
= $(PREFIX
)/usr
/share
/man
/man8
26 # Shut up make, helper warnings, parallel compilation!
27 MAKEFLAGS
+= --no-print-directory
29 MAKEFLAGS
+= --warn-undefined-variables
30 MAKEFLAGS
+= --jobs
=$(shell grep
"^processor" /proc
/cpuinfo | wc
-l
)
33 ifeq ("$(origin DEBUG)", "command line")
39 # For packaging purposes, you might want to call your own:
40 # make CFLAGS="<flags>"
41 CFLAGS_DEF
= -std
=gnu99
51 CFLAGS_DEF
+= -march
=native
52 CFLAGS_DEF
+= -mtune
=native
56 ifeq ($(HARDENING
), 1)
57 CFLAGS_DEF
+= -fPIE
-pie
58 CFLAGS_DEF
+= -Wl
,-z
,relro
,-z
,now
59 CFLAGS_DEF
+= -fstack-protector-all
60 CFLAGS_DEF
+= -Wstack-protector
61 CFLAGS_DEF
+= --param
=ssp-buffer-size
=4
63 CFLAGS_DEF
+= -D_FORTIFY_SOURCE
=2
64 CFLAGS_DEF
+= -fexceptions
67 CFLAGS_DEF
+= -fomit-frame-pointer
68 CFLAGS_DEF
+= -fno-strict-aliasing
69 CFLAGS_DEF
+= -fasynchronous-unwind-tables
70 CFLAGS_DEF
+= -fno-delete-null-pointer-checks
72 CFLAGS_DEF
+= -D_REENTRANT
73 CFLAGS_DEF
+= -D_LARGEFILE_SOURCE
74 CFLAGS_DEF
+= -D_LARGEFILE64_SOURCE
75 CFLAGS_DEF
+= -D_FILE_OFFSET_BITS
=64
78 WFLAGS_DEF
+= -Wformat
=2
79 WFLAGS_DEF
+= -Wmissing-prototypes
80 WFLAGS_DEF
+= -Wdeclaration-after-statement
81 WFLAGS_DEF
+= -Werror-implicit-function-declaration
82 WFLAGS_DEF
+= -Wstrict-prototypes
83 WFLAGS_DEF
+= -Wimplicit-int
86 WFLAGS_EXTRA
= -Wno-unused-result
87 WFLAGS_EXTRA
+= -Wmissing-parameter-type
88 WFLAGS_EXTRA
+= -Wtype-limits
89 WFLAGS_EXTRA
+= -Wclobbered
90 WFLAGS_EXTRA
+= -Wmissing-field-initializers
91 WFLAGS_EXTRA
+= -Woverride-init
92 WFLAGS_EXTRA
+= -Wold-style-declaration
93 WFLAGS_EXTRA
+= -Wignored-qualifiers
94 WFLAGS_EXTRA
+= -Wempty-body
95 WFLAGS_EXTRA
+= -Wuninitialized
97 WFLAGS_DEF
+= $(WFLAGS_EXTRA
)
98 CFLAGS_DEF
+= $(WFLAGS_DEF
)
100 CFLAGS ?
= $(CFLAGS_DEF
)
105 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
106 LDFLAGS
+= -L
$(CROSS_LD_LIBRARY_PATH
)
109 ALL_LDFLAGS
= $(LDFLAGS
)
110 ALL_CFLAGS
= $(CFLAGS
) $(CPPFLAGS
) -I.
111 ALL_CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
112 ALL_CFLAGS
+= -DVERSION_LONG
=\"$(VERSION_LONG
)\"
113 ALL_CFLAGS
+= -DPREFIX_STRING
=\"$(PREFIX
)\"
114 ifneq ($(wildcard /usr
/include/linux
/net_tstamp.h
),)
115 ALL_CFLAGS
+= -D__WITH_HARDWARE_TIMESTAMPING
118 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
119 VERSION_LONG
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)~
$(NAME
)
121 # Be quite and do not echo the cmd
125 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
126 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
127 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
131 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
135 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
136 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
138 # Installation related
139 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
140 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
142 ifeq ("$(origin PREFIX)", "command line")
143 INSTX
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
144 install -C
$(1) $(2)/$(shell basename $(1))
146 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
149 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
150 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
152 GZIP
= gzip
--best
-c
155 GIT_ARCHIVE
= git archive
--prefix=netsniff-ng-
$(VERSION_STRING
)/ $(VERSION_STRING
) | \
156 $(1) > ..
/netsniff-ng-
$(VERSION_STRING
).
tar.
$(2)
157 GIT_TAG
= git tag
-a
$(VERSION_STRING
) -s
-m
"tools: $(VERSION_STRING) release"
158 GIT_LOG
= git shortlog
-n
--not
$(shell git describe
--abbrev
=0 --tags)
159 GIT_REM
= git ls-files
-o | xargs
rm -rf
160 GIT_PEOPLE
= git log
--no-merges
$(VERSION_STRING
)..HEAD | grep Author
: | cut
-d
: -f2 | \
161 cut
-d\
< -f1 |
sort | uniq
-c |
sort -nr
163 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
166 bold
= $(shell tput bold
)
167 normal
= $(shell tput sgr0
)
169 ifeq ("$(origin CROSS_COMPILE)", "command line")
170 WHAT
:= Cross compiling
176 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
177 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
179 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
182 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
183 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
185 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
186 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
188 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install tag
tags cscope
192 .IGNORE
: %_clean_custom
%_install_custom
193 .NOTPARALLEL
: $(TOOLS
)
195 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf geoip.conf
197 all: build_showinfo toolkit
198 allbutcurvetun
: $(filter-out curvetun
,$(TOOLS
))
199 allbutmausezahn
: $(filter-out mausezahn
,$(TOOLS
))
202 install_all
: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
203 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
204 install_allbutmausezahn
: $(foreach tool
,$(filter-out mausezahn
,$(TOOLS
)),$(tool
)_install
)
205 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
206 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
207 $(Q
)$(call RMDIR
,$(ETCDIRE
))
208 mrproper
: clean distclean
212 include $(1)/Makefile
213 $(1) $(1)%: BUILD_DIR
:= $(1)
215 $(Q
)echo
"$(bold)$(WHAT) $(1):$(normal)"
216 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
217 $(1)_clean
: $(1)_clean_custom
218 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1) $(1)/*.gz
)
219 $(1)_install
: $(1)_install_custom
220 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
221 $(Q
)$(GZIP
) $(1).8 > $(1)/$(1).8.gz
222 $(Q
)$$(call INSTX
,$(1)/$(1).8.gz
,$$(MAN8DIR
))
223 $(1)_distclean
: $(1)_distclean_custom
224 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
225 $(Q
)$$(call RM
,$$(MAN8DIR
)/$(1).8.gz
)
226 $(1)/%.yy.o
: $(1)/%.yy.c
227 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
228 $(1)/%.tab.o
: $(1)/%.tab.c
229 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
231 $$(CC
) $$(ALL_CFLAGS
) -o
$(1)/$$(shell basename $$@
) -c
$$<
234 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
238 netsniff-ng
: ALL_CFLAGS
+= $(shell pkg-config
--cflags libnl-3.0
) $(shell pkg-config
--cflags libnl-genl-3.0
) -D__WITH_PROTOS
-D__WITH_TCPDUMP_LIKE_FILTER
239 trafgen
: ALL_CFLAGS
+= -I..
$(shell pkg-config
--cflags libnl-3.0
) $(shell pkg-config
--cflags libnl-genl-3.0
) -D__WITH_PROTOS
240 ifpps
: ALL_CFLAGS
+= $(shell pkg-config
--cflags ncurses
)
241 flowtop
: ALL_CFLAGS
+= $(shell pkg-config
--cflags ncurses
)
242 bpfc
: ALL_CFLAGS
+= -I..
243 curvetun
: ALL_CFLAGS
+= -I
${NACL_INC_DIR}
244 curvetun
: ALL_LDFLAGS
+= -L
${NACL_LIB_DIR}
245 # This gets some extra treatment here until the code looks properly
246 mausezahn
: ALL_CFLAGS
= -O2
-I.
-I..
-DVERSION_STRING
=\"$(VERSION_STRING
)\" -DPREFIX_STRING
=\"$(PREFIX
)\" -DVERSION_LONG
=\"$(VERSION_LONG
)\"
249 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
250 trafgen_clean_custom
:
251 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
252 netsniff-ng_distclean_custom flowtop_distclean_custom
:
253 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
254 $(Q
)$(call RMDIR
,$(ETCDIRE
))
255 trafgen_distclean_custom
:
256 $(Q
)$(call RM
,$(ETCDIRE
)/stddef.h
)
257 $(Q
)$(call RMDIR
,$(ETCDIRE
))
258 astraceroute_distclean_custom
:
259 $(Q
)$(call RM
,$(ETCDIRE
)/geoip.conf
)
260 $(Q
)$(call RMDIR
,$(ETCDIRE
))
262 netsniff-ng_install_custom flowtop_install_custom
:
263 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,$(file
),$(ETCDIRE
));)
264 trafgen_install_custom
:
265 $(Q
)$(call INST
,trafgen_stddef.h
,$(ETCDIRE
))
266 $(Q
)ln
-fs
$(ETCDIRE
)/trafgen_stddef.h
$(ETCDIRE
)/stddef.h
267 astraceroute_install_custom
:
268 $(Q
)$(call INST
,geoip.conf
,$(ETCDIRE
))
271 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
275 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
276 $(Q
)cd curvetun
/ && .
/nacl_build.sh ~
/nacl
279 tarball.gz
: ; $(call GIT_ARCHIVE
,gzip
,gz
)
280 tarball.bz2
: ; $(call GIT_ARCHIVE
,bzip2
,bz2
)
281 tarball.xz
: ; $(call GIT_ARCHIVE
,xz
,xz
)
282 tarball
: tarball.gz tarball.bz2 tarball.xz
288 $(Q
)echo
-e
"netsniff-ng $(VERSION_STRING) has been released to the public (http://netsniff-ng.org/).\n" > .MAIL_MSG
289 $(Q
)echo
-e
"It can be fetched via Git, through:\n" >> .MAIL_MSG
290 $(Q
)echo
-e
" git clone git://github.com/borkmann/netsniff-ng.git" >> .MAIL_MSG
291 $(Q
)echo
-e
" git checkout $(VERSION_STRING)\n" >> .MAIL_MSG
292 $(Q
)echo
-e
"Or via HTTP, through:\n" >> .MAIL_MSG
293 $(Q
)echo
-e
" wget http://pub.netsniff-ng.org/netsniff-ng/netsniff-ng-$(VERSION_STRING).tar.gz\n" >> .MAIL_MSG
294 $(Q
)echo
-e
"The release be verified via Git, through (see README):\n" >> .MAIL_MSG
295 $(Q
)echo
-e
" git tag -v $(VERSION_STRING)\n" >> .MAIL_MSG
296 $(Q
)echo
-e
"Major high-level changes since the last release are:\n" >> .MAIL_MSG
297 $(Q
)echo
-e
" *** BLURB HERE ***\n" >> .MAIL_MSG
298 $(Q
)echo
-e
"Contributors since last release:\n" >> .MAIL_MSG
299 $(GIT_PEOPLE
) >> .MAIL_MSG
300 $(Q
)echo
-e
"Git changelog since the last release:\n" >> .MAIL_MSG
301 $(GIT_LOG
) >> .MAIL_MSG
303 release
: announcement tag tarball
304 $(Q
)echo
"Released $(bold)$(VERSION_STRING)$(normal)"
306 FIND_SOURCE_FILES
= ( git ls-files
'*.[hcS]' 2>/dev
/null || \
307 find . \
( -name .git
-type d
-prune \
) \
308 -o \
( -name
'*.[hcS]' -type f
-print \
) )
312 $(FIND_SOURCE_FILES
) | xargs ctags
-a
315 $(Q
)$(call RM
,cscope
*)
316 $(FIND_SOURCE_FILES
) | xargs cscope
-b
319 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
320 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
321 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
322 $(Q
)echo
" all|toolkit - Build the whole toolkit"
323 $(Q
)echo
" allbutcurvetun - Build all except curvetun"
324 $(Q
)echo
" allbutmausezahn - Build all except mausezahn"
325 $(Q
)echo
" <toolname> - Build only one of the tools"
326 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
327 $(Q
)echo
" clean|mostlyclean - Remove all build files"
328 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
329 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
330 $(Q
)echo
" install - Install the whole toolkit"
331 $(Q
)echo
" <toolname>_install - Install only one of the tools"
332 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
333 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
334 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
335 $(Q
)echo
" mrproper - Remove build and install files"
336 $(Q
)echo
"$(bold)Hacking/development targets:$(normal)"
337 $(Q
)echo
" tag - Generate Git tag of current version"
338 $(Q
)echo
" tarball - Generate tarball of latest version"
339 $(Q
)echo
" release - Generate a new release"
340 $(Q
)echo
" tags - Generate sparse ctags"
341 $(Q
)echo
" cscope - Generate cscope files"
342 $(Q
)echo
"$(bold)Misc targets:$(normal)"
343 $(Q
)echo
" nacl - Execute the build_nacl script"
344 $(Q
)echo
" help - Show this help"
345 $(Q
)echo
"$(bold)Available parameters:$(normal)"
346 $(Q
)echo
" DEBUG=1 / DISTRO=1 - Enable debugging / Build for distros"
347 $(Q
)echo
" HARDENING=1 - Enable GCC hardening of executables"
348 $(Q
)echo
" PREFIX=/path - Install path prefix"
349 $(Q
)echo
" CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
350 $(Q
)echo
" CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
351 $(Q
)echo
" CC=cgcc - Use sparse compiler wrapper"
352 $(Q
)echo
" CFLAGS=\"-O2 -Wall ...\" - Overwrite CFLAGS for compilation"
353 $(Q
)echo
" CPPFLAGS=\"-I <path> ...\" - Additional CFLAGS for compilation"
354 $(Q
)echo
" LDFLAGS=\"-L <path> ...\" - Additional LDFLAGS for compilation"
355 $(Q
)echo
" CCACHE= - Do not use ccache for compilation"
356 $(Q
)echo
" Q= - Show verbose garbage"