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.
15 # Disable if you don't want it
18 # Location of installation paths.
19 BINDIR
= $(PREFIX
)/usr
/bin
20 SBINDIR
= $(PREFIX
)/usr
/sbin
21 INCDIR
= $(PREFIX
)/usr
/include
22 ETCDIR
= $(PREFIX
)/etc
23 ETCDIRE
= $(ETCDIR
)/netsniff-ng
24 DOCDIR
= $(PREFIX
)/usr
/share
/doc
25 DOCDIRE
= $(DOCDIR
)/netsniff-ng
27 # Shut up make, helper warnings, parallel compilation!
28 MAKEFLAGS
+= --no-print-directory
30 MAKEFLAGS
+= --warn-undefined-variables
31 MAKEFLAGS
+= --jobs
=$(shell grep
"^processor" /proc
/cpuinfo | wc
-l
)
33 # For packaging purposes, you might want to disable O3+arch tuning
34 CFLAGS
= -fstack-protector
35 CFLAGS
+= --param
=ssp-buffer-size
=4
37 CFLAGS
+= -fno-strict-aliasing
38 CFLAGS
+= -fexceptions
39 CFLAGS
+= -fasynchronous-unwind-tables
40 CFLAGS
+= -fno-delete-null-pointer-checks
41 CFLAGS
+= -D_FORTIFY_SOURCE
=2
42 CFLAGS
+= -D_REENTRANT
43 CFLAGS
+= -D_FILE_OFFSET_BITS
=64
44 CFLAGS
+= -D_LARGEFILE_SOURCE
45 CFLAGS
+= -D_LARGEFILE64_SOURCE
46 CFLAGS
+= -D__WITH_HARDWARE_TIMESTAMPING
47 CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
49 CFLAGS
+= -march
=native
50 CFLAGS
+= -mtune
=native
54 # Should be commented in after the mausezahn mess is cleaned
56 #WFLAGS += -Wmissing-prototypes
57 #WFLAGS += -Wdeclaration-after-statement
58 #WFLAGS += -Werror-implicit-function-declaration
60 #WFLAGS += -Wstrict-prototypes
61 #WFLAGS += -Wunused-but-set-variable
65 CFLAGS
+= $(WFLAGS
) -I.
67 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
68 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
73 ALL_CFLAGS
= $(CFLAGS
)
74 ALL_LDFLAGS
= $(LDFLAGS
)
81 LD
= $(Q
)echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
82 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
83 CC
= $(Q
)echo
-e
" CC\t$<" && $(CCNQ
)
84 MKDIR
= $(Q
)echo
-e
" MKDIR\t$@" && mkdir
85 STRIP
= $(Q
)echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
86 LEX
= $(Q
)echo
-e
" LEX\t$<" && flex
87 YAAC
= $(Q
)echo
-e
" YAAC\t$<" && bison
88 INST
= echo
-e
" INST\t$(1)" && install -d
$(2) && \
89 install --mode
=644 -DC
$(1) $(2)/$(shell basename $(1))
90 INSTX
= echo
-e
" INST\t$(1)" && install -C
$(1) $(2)/$(shell basename $(1))
91 RM
= echo
-e
" RM\t$(1)" && rm -rf
$(1)
92 RMDIR
= echo
-e
" RM\t$(1)" && rmdir
--ignore-fail-on-non-empty
$(1) 2> /dev
/null || true
94 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
95 export CROSS_COMPILE LD CC STRIP
97 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
98 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)
100 bold
= $(shell tput bold
)
101 normal
= $(shell tput sgr0
)
104 $(Q
)echo
"$(bold)Building netsniff-ng toolkit ($(VERSION_STRING)) for" \
105 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
107 $(Q
)echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
110 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
111 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
113 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
114 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
116 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install
119 .IGNORE
: %_clean_custom
%_install_custom
120 .NOTPARALLEL
: $(TOOLS
) %.y
%.l
%.tab.o
%.yy.o
122 DOC_FILES
= Summary RelatedWork Performance KnownIssues IPv6Notes Sponsors \
123 SubmittingPatches CodingStyle logo.png RelNotes
/Notes-
$(VERSION_SHORT
)
125 NCONF_FILES
= ether.conf tcp.conf udp.conf oui.conf
127 all: build_showinfo toolkit
129 install: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
130 $(Q
)$(foreach file
,$(DOC_FILES
),$(call INST
,..
/Documentation
/$(file
),$(DOCDIRE
));)
131 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
132 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
133 $(Q
)$(foreach file
,$(DOC_FILES
),$(call RM
,$(DOCDIRE
)/$(file
));)
134 $(Q
)$(call RMDIR
,$(DOCDIRE
))
135 $(Q
)$(call RMDIR
,$(ETCDIRE
))
136 mrproper
: clean distclean
140 include $(1)/Makefile
141 $(1) $(1)%: BUILD_DIR
:= $(1)
143 $(Q
)echo
"$(bold)Building $(1):$(normal)"
144 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
))
145 $(1)_clean
: $(1)_clean_custom
146 $(Q
)$$(call RM
,$(1)/*.o
$(1)/$(1))
147 $(1)_install
: $(1)_install_custom
148 $(Q
)$$(call INSTX
,$(1)/$(1),$$(SBINDIR
))
149 $(Q
)$$(call INST
,..
/Documentation
/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'),$$(DOCDIRE
))
150 $(1)_distclean
: $(1)_distclean_custom
151 $(Q
)$$(call RM
,$$(SBINDIR
)/$(1))
152 $(Q
)$$(call RM
,$$(DOCDIRE
)/$$(shell echo
$(1) | sed
's/\([a-z]\)\(.*\)/\u\1\2/g'))
154 $$(CC
) $$(ALL_CFLAGS
) -o
$(1)/$$(shell basename $$< .c
).o
-c
$$<
157 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
159 # Target specific flag additions ...
160 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
161 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ -D__WITH_PROTOS
162 bpfc
: ALL_CFLAGS
+= -I..
163 curvetun
: ALL_CFLAGS
+= -I
$(NACL_INCLUDE_DIR
)
164 curvetun
: ALL_LDFLAGS
+= -L
$(NACL_LIB_DIR
)
166 # Target specific cleaning ...
167 netsniff-ng_clean_custom astraceroute_clean_custom flowtop_clean_custom
:
168 ifpps_clean_custom mausezahn_clean_custom
:
170 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
171 curvetun_clean_custom
:
172 trafgen_clean_custom
:
173 $(Q
)$(call RM
,$(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
)
175 netsniff-ng_distclean_custom flowtop_distclean_custom
:
176 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call RM
,$(ETCDIRE
)/$(file
));)
177 $(Q
)$(call RMDIR
,$(ETCDIRE
))
178 astraceroute_distclean_custom
:
179 $(Q
)$(call RM
,$(ETCDIRE
)/whois.conf
)
180 $(Q
)$(call RM
,$(SBINDIR
)/astraceroute6
)
181 $(Q
)$(call RMDIR
,$(ETCDIRE
))
182 ifpps_distclean_custom mausezahn_distclean_custom
:
183 bpfc_distclean_custom curvetun_distclean_custom trafgen_distclean_custom
:
185 # Target specific installs ...
186 netsniff-ng_install_custom flowtop_install_custom
:
187 $(Q
)$(foreach file
,$(NCONF_FILES
),$(call INST
,conf
/$(file
),$(ETCDIRE
));)
188 astraceroute_install_custom
:
189 $(Q
)$(call INST
,conf
/whois.conf
,$(ETCDIRE
))
190 $(Q
)$(call INSTX
,..
/scripts
/astraceroute6
,$(SBINDIR
))
191 ifpps_install_custom mausezahn_install_custom bpfc_install_custom
:
192 curvetun_install_custom trafgen_install_custom
:
195 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)
199 $(Q
)..
/scripts
/geoip-database-update
201 $(Q
)cd curvetun
/ && .
/build_nacl.sh ~
/nacl
203 $(Q
)cd astraceroute
/ && .
/build_geoip.sh
205 $(Q
)echo
"$(bold)Available tools from the toolkit:$(normal)"
206 $(Q
)echo
" <toolnames>:={$(TOOLS)}"
207 $(Q
)echo
"$(bold)Targets for building the toolkit:$(normal)"
208 $(Q
)echo
" all|toolkit - Build the whole toolkit"
209 $(Q
)echo
" <toolname> - Build only one of the tools"
210 $(Q
)echo
"$(bold)Targets for cleaning the toolkit's build files:$(normal)"
211 $(Q
)echo
" clean|mostlyclean - Remove all build files"
212 $(Q
)echo
" <toolname>_clean - Remove only one of the tool's files"
213 $(Q
)echo
"$(bold)Targets for installing the toolkit:$(normal)"
214 $(Q
)echo
" install - Install the whole toolkit"
215 $(Q
)echo
" <toolname>_install - Install only one of the tools"
216 $(Q
)echo
"$(bold)Targets for removing the toolkit:$(normal)"
217 $(Q
)echo
" realclean|distclean|clobber - Remove the whole toolkit from the system"
218 $(Q
)echo
" <toolname>_distclean - Remove only one of the tools"
219 $(Q
)echo
"$(bold)Misc targets:$(normal)"
220 $(Q
)echo
" mrproper - Remove build and install files"
221 $(Q
)echo
" update - Update to the latest GeoIP database"
222 $(Q
)echo
" nacl - Execute the build_nacl script"
223 $(Q
)echo
" geoip - Execute the build_geoip script"
224 $(Q
)echo
" help - Show this help"