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
24 # Shut up make, helper warnings, parallel compilation!
25 MAKEFLAGS
+= --no-print-directory
27 MAKEFLAGS
+= --warn-undefined-variables
28 MAKEFLAGS
+= --jobs
=$(shell grep
"^processor" /proc
/cpuinfo | wc
-l
)
30 # For packaging purposes, you might want to disable O3+arch tuning
31 CFLAGS
= -fstack-protector
32 CFLAGS
+= --param
=ssp-buffer-size
=4
34 CFLAGS
+= -fno-strict-aliasing
35 CFLAGS
+= -fexceptions
36 CFLAGS
+= -fasynchronous-unwind-tables
37 CFLAGS
+= -fno-delete-null-pointer-checks
38 CFLAGS
+= -D_FORTIFY_SOURCE
=2
39 CFLAGS
+= -D_REENTRANT
40 CFLAGS
+= -D_FILE_OFFSET_BITS
=64
41 CFLAGS
+= -D_LARGEFILE_SOURCE
42 CFLAGS
+= -D_LARGEFILE64_SOURCE
43 CFLAGS
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
45 CFLAGS
+= -march
=native
46 CFLAGS
+= -mtune
=native
50 # Should be commented in after the mausezahn mess is cleaned
52 #WFLAGS += -Wmissing-prototypes
53 #WFLAGS += -Wdeclaration-after-statement
54 #WFLAGS += -Werror-implicit-function-declaration
56 #WFLAGS += -Wstrict-prototypes
57 #WFLAGS += -Wunused-but-set-variable
61 CFLAGS
+= $(WFLAGS
) -I.
63 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
64 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
69 ALL_CFLAGS
= $(CFLAGS
)
70 ALL_LDFLAGS
= $(LDFLAGS
)
75 LD
= @echo
-e
" LD\t$@" && $(CCACHE
) $(CROSS_COMPILE
)gcc
76 CCNQ
= $(CCACHE
) $(CROSS_COMPILE
)gcc
77 CC
= @echo
-e
" CC\t$<" && $(CCNQ
)
78 RM
= @echo
-e
" EXEC\t$@" && rm
79 MKDIR
= @echo
-e
" MKDIR\t$@" && mkdir
80 STRIP
= @echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
81 LEX
= @echo
-e
" LEX\t$<" && flex
82 YAAC
= @echo
-e
" YAAC\t$<" && bison
84 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
85 export CROSS_COMPILE LD CC STRIP
87 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
89 bold
= $(shell tput bold
)
90 normal
= $(shell tput sgr0
)
93 @echo
"$(bold)Building netsniff-ng toolkit ($(VERSION_STRING)) for" \
94 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
96 @echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
99 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
100 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
102 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
103 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
105 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_distclean
%_clean
%_install
108 .IGNORE
: %_clean_custom
109 .NOTPARALLEL
: $(TOOLS
)
111 all: build_showinfo toolkit
113 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
114 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
118 include $(1)/Makefile
119 $(1) $(1)%: BUILD_DIR
:= $(1)
121 @echo
"$(bold)Building $(1):$(normal)"
122 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$(patsubst %.o
,$(1)/%.o
,$$($(1)-objs
)) $$($(1)-libs
)
124 @
rm -rf
$(1)/*.o
$(1)/$(1)
126 @
install -D
$(1)/$(1) $$(SBINDIR
)/$(1)
130 $$(CC
) $$(ALL_CFLAGS
) -o
$(1)/$$(shell basename $$< .c
).o
-c
$$<
133 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
135 # Target specific additions ...
136 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ \
138 #-D__WITH_HARDWARE_TIMESTAMPING
139 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ \
141 #-D__WITH_HARDWARE_TIMESTAMPING
142 #trafgen_clean_custom:
143 # @rm $(BUILD_DIR)/*.h $(BUILD_DIR)/*.c
144 bpfc
: ALL_CFLAGS
+= -I..
147 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)