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
)\"
67 # Should be commented in after the mausezahn mess is cleaned
69 #WFLAGS += -Wmissing-prototypes
70 #WFLAGS += -Wdeclaration-after-statement
71 #WFLAGS += -Werror-implicit-function-declaration
73 #WFLAGS += -Wstrict-prototypes
74 #WFLAGS += -Wunused-but-set-variable
78 CFLAGS
+= $(WFLAGS
) -I.
80 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
81 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
86 ALL_CFLAGS
= $(CFLAGS
)
87 ALL_LDFLAGS
= $(LDFLAGS
)
94 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
95 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
96 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
97 MKDIR
= $(Q
)echo
-e
" MKDIR\t$@" && mkdir
101 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
103 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
104 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
105 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
106 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
107 ifeq ("$(origin PREFIX)", "command line")
108 INSTX
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
109 install -C
$(1) $(2)/$(shell basename $(1))
111 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
113 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
114 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
116 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
119 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
120 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
122 bold
= $(shell tput bold
)
123 normal
= $(shell tput sgr0
)
125 # Build NaCl if no environment variables are set!
128 $(info $(bold
)NACL_LIB_DIR
/NACL_INC_DIR is undefined
, building libnacl with curvetun
!$(normal
))
133 ifeq ("$(origin CROSS_COMPILE)", "command line")
134 WHAT
:= Cross compiling
140 $(Q
)echo
"$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
141 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
143 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
146 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
147 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
149 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
150 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
152 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install
156 .IGNORE
: %_clean_custom
%_install_custom
157 .NOTPARALLEL
: $(TOOLS
)
159 DOC_FILES
= Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
160 SubmittingPatches CodingStyle logo.png RelNotes
/Notes-
$(VERSION_SHORT
)
162 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf
164 all: build_showinfo toolkit
166 allbutcurvetun
: $(filter-out curvetun
,$(TOOLS
))
167 install: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
168 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
169 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
170 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
171 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
172 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
173 $(Q
)$(foreach file
,$(DOC_FILES
),$(call RM
,$(DOCDIRE
)/$(file
));)
174 $(Q
)$(call RMDIR
,$(DOCDIRE
))
175 $(Q
)$(call RMDIR
,$(ETCDIRE
))
176 mrproper
: clean distclean
179 include $(1)/Makefile
180 $(1) $(1)%: BUILD_DIR
:= $(1)
182 $(Q
)echo
"$(bold)$(WHAT) $(1):$(normal)"
183 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
184 $(1)_clean
: $(1)_clean_custom
185 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1))
186 $(1)_install
: $(1)_install_custom
187 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
188 $(Q
)$$(call INST
,..
/Documentation
/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE
))
189 $(1)_distclean
: $(1)_distclean_custom
190 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
191 $(Q
)$$(call RM
,$$(DOCDIRE
)/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'))
192 $(1)/%.yy.o
: $(1)/%.yy.c
193 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
194 $(1)/%.tab.o
: $(1)/%.tab.c
195 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
197 $$(CC
) $$(ALL_CFLAGS
) -o
$$@
-c
$$<
200 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
204 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
205 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
206 bpfc
: ALL_CFLAGS
+= -I..
207 curvetun
: ALL_CFLAGS
+= -I NACL_INC_DIR
208 curvetun
: ALL_LDFLAGS
+= -L NACL_LIB_DIR
211 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
212 trafgen_clean_custom
:
213 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
215 netsniff-ng_distclean_custom flowtop_distclean_custom
:
216 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
217 $(Q
)$(call RMDIR
,$(ETCDIRE
))
218 astraceroute_distclean_custom
:
219 $(Q
)$(call RM
,$(ETCDIRE
)/whois.conf
)
220 $(Q
)$(call RM
,$(SBINDIR
)/astraceroute6
)
221 $(Q
)$(call RMDIR
,$(ETCDIRE
))
223 netsniff-ng_install_custom flowtop_install_custom
:
224 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,conf
/$(file
),$(ETCDIRE
));)
225 astraceroute_install_custom
:
226 $(Q
)$(call INST
,conf
/whois.conf
,$(ETCDIRE
))
227 $(Q
)$(call INSTX
,..
/scripts
/astraceroute6
,$(SBINDIR
))
230 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
234 $(Q
)..
/scripts
/geoip-database-update
236 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
237 $(Q
)cd curvetun
/ && .
/build_nacl.sh ~
/nacl
240 $(Q
)echo
"$(bold)$(WHAT) $@:$(normal)"
241 $(Q
)cd astraceroute
/ && .
/build_geoip.sh
244 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
245 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
246 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
247 $(Q
)echo
" all|toolkit - Build the whole toolkit"
248 $(Q
)echo
" allbutcurvetun - Build all except curvetun"
249 $(Q
)echo
" <toolname> - Build only one of the tools"
250 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
251 $(Q
)echo
" clean|mostlyclean - Remove all build files"
252 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
253 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
254 $(Q
)echo
" install - Install the whole toolkit"
255 $(Q
)echo
" <toolname>_install - Install only one of the tools"
256 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
257 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
258 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
259 $(Q
)echo
"$(bold)Misc targets:$(normal)"
260 $(Q
)echo
" mrproper - Remove build and install files"
261 $(Q
)echo
" update - Update to the latest GeoIP database"
262 $(Q
)echo
" nacl - Execute the build_nacl script"
263 $(Q
)echo
" geoip - Execute the build_geoip script"
264 $(Q
)echo
" help - Show this help"
265 $(Q
)echo
"$(bold)Available parameters:$(normal)"
266 $(Q
)echo
" DEBUG=1 - Enable debugging"
267 $(Q
)echo
" PREFIX=/path - Install path prefix"
268 $(Q
)echo
" CROSS_COMPILE=/path-prefix - Kernel-like cross-compiling prefix"
269 $(Q
)echo
" CROSS_LD_LIBRARY_PATH=/path - Library search path for cross-compiling"