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
= -fstack-protector
46 CFLAGS_DEF
+= -march
=native
47 CFLAGS_DEF
+= -mtune
=native
51 CFLAGS_DEF
+= -fomit-frame-pointer
53 CFLAGS_DEF
+= --param
=ssp-buffer-size
=4
54 CFLAGS_DEF
+= -fno-strict-aliasing
55 CFLAGS_DEF
+= -fexceptions
56 CFLAGS_DEF
+= -fasynchronous-unwind-tables
57 CFLAGS_DEF
+= -fno-delete-null-pointer-checks
58 CFLAGS_DEF
+= -D_FORTIFY_SOURCE
=2
59 CFLAGS_DEF
+= -D_REENTRANT
60 CFLAGS_DEF
+= -D_FILE_OFFSET_BITS
=64
61 CFLAGS_DEF
+= -D_LARGEFILE_SOURCE
62 CFLAGS_DEF
+= -D_LARGEFILE64_SOURCE
63 CFLAGS_DEF
+= -std
=gnu99
66 WFLAGS_DEF
+= -Wformat
=2
67 WFLAGS_DEF
+= -Wmissing-prototypes
68 WFLAGS_DEF
+= -Wdeclaration-after-statement
69 WFLAGS_DEF
+= -Werror-implicit-function-declaration
70 WFLAGS_DEF
+= -Wstrict-prototypes
72 WFLAGS_DEF
+= -Wimplicit-int
74 WFLAGS_EXTRA
= -Wno-unused-result
75 WFLAGS_EXTRA
+= -Wmissing-parameter-type
76 WFLAGS_EXTRA
+= -Wtype-limits
77 WFLAGS_EXTRA
+= -Wclobbered
78 WFLAGS_EXTRA
+= -Wmissing-field-initializers
79 WFLAGS_EXTRA
+= -Woverride-init
80 WFLAGS_EXTRA
+= -Wold-style-declaration
81 WFLAGS_EXTRA
+= -Wignored-qualifiers
82 WFLAGS_EXTRA
+= -Wempty-body
83 WFLAGS_EXTRA
+= -Wuninitialized
85 WFLAGS_DEF
+= $(WFLAGS_EXTRA
)
86 CFLAGS_DEF
+= $(WFLAGS_DEF
)
88 CFLAGS ?
= $(CFLAGS_DEF
)
90 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
91 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
96 ALL_CFLAGS
= $(CFLAGS
) -I.
97 ALL_CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
98 ALL_CFLAGS
+= -DPREFIX_STRING
=\"$(PREFIX
)\"
99 ifneq ($(wildcard /usr
/include/linux
/net_tstamp.h
),)
100 ALL_CFLAGS
+= -D__WITH_HARDWARE_TIMESTAMPING
102 ALL_LDFLAGS
= $(LDFLAGS
)
106 # Be quite and do not echo the cmd
109 # Some command definitions
110 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
111 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
112 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
113 MKDIR
= $(Q
)echo
-e
" MKDIR\t$@" && mkdir
117 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
119 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
120 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
121 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
122 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
123 ifeq ("$(origin PREFIX)", "command line")
124 INSTX
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
125 install -C
$(1) $(2)/$(shell basename $(1))
127 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
129 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
130 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
131 GIT_ARCHIVE
= git archive
--prefix=netsniff-ng-
$(VERSION_STRING
)/ $(VERSION_STRING
) | \
132 $(1) > ..
/netsniff-ng-
$(VERSION_STRING
).
tar.
$(2)
133 GIT_TAG
= git tag
-a
$(VERSION_STRING
) -s
-m
"tools: $(VERSION_STRING) release"
134 GIT_LOG
= git shortlog
-n
--not
$(shell git describe
--abbrev
=0 --tags)
135 GIT_REM
= git ls-files
-o | xargs
rm -rf
136 GIT_PEOPLE
= git log
--no-merges
$(VERSION_STRING
)..HEAD | grep Author
: | cut
-d
: -f2 | \
137 cut
-d\
< -f1 |
sort | uniq
-c |
sort -nr
138 GZIP
= gzip
--best
-c
140 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
143 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
144 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
146 bold
= $(shell tput bold
)
147 normal
= $(shell tput sgr0
)
151 $(info $(bold
)NACL_LIB_DIR
/NACL_INC_DIR is undefined
, build libnacl first for curvetun
!$(normal
))
155 ifeq ("$(origin CROSS_COMPILE)", "command line")
156 WHAT
:= Cross compiling
162 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
163 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
165 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
168 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
169 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
171 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
172 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
174 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install tag
tags cscope
178 .IGNORE
: %_clean_custom
%_install_custom
179 .NOTPARALLEL
: $(TOOLS
)
181 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf geoip.conf
183 all: build_showinfo toolkit
184 allbutcurvetun
: $(filter-out curvetun
,$(TOOLS
))
185 allbutmausezahn
: $(filter-out mausezahn
,$(TOOLS
))
188 install_all
: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
189 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
190 install_allbutmausezahn
: $(foreach tool
,$(filter-out mausezahn
,$(TOOLS
)),$(tool
)_install
)
191 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
192 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
193 $(Q
)$(call RMDIR
,$(ETCDIRE
))
194 mrproper
: clean distclean
198 include $(1)/Makefile
199 $(1) $(1)%: BUILD_DIR
:= $(1)
201 $(Q
)echo
"$(bold)$(WHAT) $(1):$(normal)"
202 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
203 $(1)_clean
: $(1)_clean_custom
204 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1) $(1)/*.gz
)
205 $(1)_install
: $(1)_install_custom
206 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
207 $(Q
)$(GZIP
) $(1).8 > $(1)/$(1).8.gz
208 $(Q
)$$(call INSTX
,$(1)/$(1).8.gz
,$$(MAN8DIR
))
209 $(1)_distclean
: $(1)_distclean_custom
210 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
211 $(Q
)$$(call RM
,$$(MAN8DIR
)/$(1).8.gz
)
212 $(1)/%.yy.o
: $(1)/%.yy.c
213 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
214 $(1)/%.tab.o
: $(1)/%.tab.c
215 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
217 $$(CC
) $$(ALL_CFLAGS
) -o
$(1)/$$(shell basename $$@
) -c
$$<
220 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
224 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
225 trafgen
: ALL_CFLAGS
+= -I..
$(shell pkg-config
--cflags libnl-3.0
) $(shell pkg-config
--cflags libnl-genl-3.0
) -D__WITH_PROTOS
226 ifpps
: ALL_CFLAGS
+= $(shell pkg-config
--cflags ncurses
)
227 flowtop
: ALL_CFLAGS
+= $(shell pkg-config
--cflags ncurses
)
228 bpfc
: ALL_CFLAGS
+= -I..
229 curvetun
: ALL_CFLAGS
+= -I
${NACL_INC_DIR}
230 curvetun
: ALL_LDFLAGS
+= -L
${NACL_LIB_DIR}
231 # This gets some extra treatment here until the code looks properly
232 mausezahn
: ALL_CFLAGS
= -O2
-I.
-I..
-DVERSION_STRING
=\"$(VERSION_STRING
)\" -DPREFIX_STRING
=\"$(PREFIX
)\"
235 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
236 trafgen_clean_custom
:
237 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
238 netsniff-ng_distclean_custom flowtop_distclean_custom
:
239 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
240 $(Q
)$(call RMDIR
,$(ETCDIRE
))
241 trafgen_distclean_custom
:
242 $(Q
)$(call RM
,$(ETCDIRE
)/stddef.h
)
243 $(Q
)$(call RMDIR
,$(ETCDIRE
))
244 astraceroute_distclean_custom
:
245 $(Q
)$(call RM
,$(ETCDIRE
)/geoip.conf
)
246 $(Q
)$(call RMDIR
,$(ETCDIRE
))
248 netsniff-ng_install_custom flowtop_install_custom
:
249 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,$(file
),$(ETCDIRE
));)
250 trafgen_install_custom
:
251 $(Q
)$(call INST
,trafgen_stddef.h
,$(ETCDIRE
))
252 $(Q
)ln
-fs
$(ETCDIRE
)/trafgen_stddef.h
$(ETCDIRE
)/stddef.h
253 astraceroute_install_custom
:
254 $(Q
)$(call INST
,geoip.conf
,$(ETCDIRE
))
257 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
261 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
262 $(Q
)cd curvetun
/ && .
/nacl_build.sh ~
/nacl
265 tarball.gz
: ; $(call GIT_ARCHIVE
,gzip
,gz
)
266 tarball.bz2
: ; $(call GIT_ARCHIVE
,bzip2
,bz2
)
267 tarball.xz
: ; $(call GIT_ARCHIVE
,xz
,xz
)
268 tarball
: tarball.gz tarball.bz2 tarball.xz
274 $(Q
)echo
-e
"netsniff-ng $(VERSION_STRING) has been released to the public (http://netsniff-ng.org/).\n" > .MAIL_MSG
275 $(Q
)echo
-e
"It can be fetched via Git, through:\n" >> .MAIL_MSG
276 $(Q
)echo
-e
" git clone git://github.com/borkmann/netsniff-ng.git" >> .MAIL_MSG
277 $(Q
)echo
-e
" git checkout $(VERSION_STRING)\n" >> .MAIL_MSG
278 $(Q
)echo
-e
"Or via HTTP, through:\n" >> .MAIL_MSG
279 $(Q
)echo
-e
" wget http://pub.netsniff-ng.org/netsniff-ng/netsniff-ng-$(VERSION_STRING).tar.gz\n" >> .MAIL_MSG
280 $(Q
)echo
-e
"The release be verified via Git, through (see README):\n" >> .MAIL_MSG
281 $(Q
)echo
-e
" git tag -v $(VERSION_STRING)\n" >> .MAIL_MSG
282 $(Q
)echo
-e
"Major high-level changes since the last release are:\n" >> .MAIL_MSG
283 $(Q
)echo
-e
" *** BLURB HERE ***\n" >> .MAIL_MSG
284 $(Q
)echo
-e
"Contributors since last release:\n" >> .MAIL_MSG
285 $(GIT_PEOPLE
) >> .MAIL_MSG
286 $(Q
)echo
-e
"Git changelog since the last release:\n" >> .MAIL_MSG
287 $(GIT_LOG
) >> .MAIL_MSG
289 release
: announcement tag tarball
290 $(Q
)echo
"Released $(bold)$(VERSION_STRING)$(normal)"
292 FIND_SOURCE_FILES
= ( git ls-files
'*.[hcS]' 2>/dev
/null || \
293 find . \
( -name .git
-type d
-prune \
) \
294 -o \
( -name
'*.[hcS]' -type f
-print \
) )
298 $(FIND_SOURCE_FILES
) | xargs ctags
-a
301 $(Q
)$(call RM
,cscope
*)
302 $(FIND_SOURCE_FILES
) | xargs cscope
-b
305 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
306 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
307 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
308 $(Q
)echo
" all|toolkit - Build the whole toolkit"
309 $(Q
)echo
" allbutcurvetun - Build all except curvetun"
310 $(Q
)echo
" allbutmausezahn - Build all except mausezahn"
311 $(Q
)echo
" <toolname> - Build only one of the tools"
312 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
313 $(Q
)echo
" clean|mostlyclean - Remove all build files"
314 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
315 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
316 $(Q
)echo
" install - Install the whole toolkit"
317 $(Q
)echo
" <toolname>_install - Install only one of the tools"
318 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
319 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
320 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
321 $(Q
)echo
" mrproper - Remove build and install files"
322 $(Q
)echo
"$(bold)Hacking/development targets:$(normal)"
323 $(Q
)echo
" tag - Generate Git tag of current version"
324 $(Q
)echo
" tarball - Generate tarball of latest version"
325 $(Q
)echo
" release - Generate a new release"
326 $(Q
)echo
" tags - Generate sparse ctags"
327 $(Q
)echo
" cscope - Generate cscope files"
328 $(Q
)echo
"$(bold)Misc targets:$(normal)"
329 $(Q
)echo
" nacl - Execute the build_nacl script"
330 $(Q
)echo
" help - Show this help"
331 $(Q
)echo
"$(bold)Available parameters:$(normal)"
332 $(Q
)echo
" DEBUG=1 - Enable debugging"
333 $(Q
)echo
" PREFIX=/path - Install path prefix"
334 $(Q
)echo
" CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
335 $(Q
)echo
" CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"
336 $(Q
)echo
" CC=cgcc - Use sparse compiler wrapper"
337 $(Q
)echo
" CFLAGS="-O2
-Wall
" - Overwrite CFLAGS for compilation"
338 $(Q
)echo
" CCACHE= - Do not use ccache for compilation"
339 $(Q
)echo
" Q= - Show verbose garbage"