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 # Location of installation paths.
16 BINDIR
= $(PREFIX
)/usr
/bin
17 SBINDIR
= $(PREFIX
)/usr
/sbin
18 INCDIR
= $(PREFIX
)/usr
/include
19 ETCDIR
= $(PREFIX
)/etc
21 # Shut up make, helper warnings, parallel compilation!
22 MAKEFLAGS
+= --no-print-directory
-rR
--warn-undefined-variables \
23 --jobs
=$(shell grep
"^processor" /proc
/cpuinfo | wc
-l
)
25 CFLAGS
= -fstack-protector \
26 --param
=ssp-buffer-size
=4 \
28 -fno-strict-aliasing \
30 -fasynchronous-unwind-tables \
31 -fno-delete-null-pointer-checks \
34 -D_FILE_OFFSET_BITS
=64 \
36 -D_LARGEFILE64_SOURCE \
37 -DVERSION_STRING
=\"$(VERSION_STRING
)\" \
45 -Wmissing-prototypes \
46 -Wdeclaration-after-statement \
47 -Werror-implicit-function-declaration \
51 CFLAGS
+= $(WFLAGS
) -I.
53 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
54 LDFLAGS
= -L
$(CROSS_LD_LIBRARY_PATH
)
59 ALL_CFLAGS
= $(CFLAGS
)
60 ALL_LDFLAGS
= $(LDFLAGS
)
65 LD
= @echo
-e
" LD\t$@" && $(CROSS_COMPILE
)gcc
66 CCNQ
= $(CROSS_COMPILE
)gcc
67 CC
= @echo
-e
" CC\t$<" && $(CCNQ
)
68 RM
= @echo
-e
" EXEC\t$@" && rm
69 MKDIR
= @echo
-e
" MKDIR\t$@" && mkdir
70 STRIP
= @echo
-e
" STRIP\t$@" && $(CROSS_COMPILE
)strip
71 LEX
= @echo
-e
" LEX\t$<" && flex
72 YAAC
= @echo
-e
" YAAC\t$<" && bison
74 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
75 export CROSS_COMPILE LD CC STRIP
77 VERSION_STRING
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
79 bold
= $(shell tput bold
)
80 normal
= $(shell tput sgr0
)
83 @echo
"$(bold)Building netsniff-ng toolkit ($(VERSION_STRING)) for" \
84 $(shell $(CCNQ
) -dumpmachine
)":$(normal)"
86 @echo
"$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
89 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
90 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
92 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
93 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
95 $(CC
) $(ALL_CFLAGS
) -o
$(BUILD_DIR
)/$(shell basename $< .c
).o
-c
$<
100 all: build_showinfo toolkit
102 clean mostlyclean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
103 realclean distclean clobber: $(foreach tool
,$(TOOLS
),$(tool
)_distclean
)
106 include $(1)/Makefile
107 $(1) $(1)%: BUILD_DIR
:= $(1)
109 @echo
"$(bold)Building $(1):$(normal)"
110 $(1): $(1)_prehook
$$($(1)-lex) $$($(1)-yaac
) $$($(1)-objs
) $$($(1)-libs
)
111 $(1)_clean
: $(1)_clean_custom
112 @
rm -rf
$$(BUILD_DIR
)/*.o
$$(BUILD_DIR
)/$(1)
114 @
install -D
$$(BUILD_DIR
)/$(1) $$(SBINDIR
)/$(1)
119 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
121 # Target specific additions ... will become less redundant when
122 # mausezahn is cleaned up
124 netsniff-ng
: ALL_CFLAGS
+= -I
$(INCDIR
)/libnl3
/ \
125 -Wstrict-prototypes \
126 -Wframe-larger-than
=2048 \
128 #-D__WITH_HARDWARE_TIMESTAMPING
129 trafgen
: ALL_CFLAGS
+= -I..
-I
$(INCDIR
)/libnl3
/ \
130 -Wstrict-prototypes \
131 -Wframe-larger-than
=2048 \
133 #-D__WITH_HARDWARE_TIMESTAMPING
134 trafgen_clean_custom
:
135 @
rm $(BUILD_DIR
)/*.h
$(BUILD_DIR
)/*.c
136 astraceroute
: ALL_CFLAGS
+= -Wstrict-prototypes
-Wframe-larger-than
=2048
137 flowtop
: ALL_CFLAGS
+= -Wstrict-prototypes
-Wframe-larger-than
=2048
138 ifpps
: ALL_CFLAGS
+= -Wstrict-prototypes
-Wframe-larger-than
=2048
139 bpfc
: ALL_CFLAGS
+= -I..
-Wstrict-prototypes
-Wframe-larger-than
=2048
140 curvetun
: ALL_CFLAGS
+= -Wstrict-prototypes
-Wframe-larger-than
=2048
143 $(LD
) $(ALL_LDFLAGS
) -o
$@
/$@
$@
/*.o
$($@
-libs
)