1 # netsniff-ng build system
2 # Copyright 2012 - 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
3 # Copyright 2013 - 2015 Tobias Klauser <tklauser@distanz.ch>
4 # Subject to the GNU GPL, version 2.
13 $(error
"Please run `./configure' before `make'")
22 TOOLS ?
= $(CONFIG_TOOLS
)
23 TOOLS ?
= netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn
25 # For packaging purposes, prefix can define a different path.
28 # Set to use ccache for compilation
31 # Location of an alternative destination directory for installation
32 # Useful when cross-compiling and installing in a dedicated target directory
35 # Location of installation paths.
36 SBINDIR
= $(PREFIX
)/sbin
37 INCDIR
= $(PREFIX
)/include
39 ETCDIRE
= $(ETCDIR
)/netsniff-ng
40 MAN8DIR
= $(PREFIX
)/share
/man
/man8
42 # Shut up make, helper warnings, parallel compilation!
43 MAKEFLAGS
+= --no-print-directory
45 MAKEFLAGS
+= --warn-undefined-variables
46 MAKEFLAGS
+= --jobs
=$(shell grep
"^processor" /proc
/cpuinfo | wc
-l
)
49 ifeq ("$(origin DEBUG)", "command line")
57 ifeq ($(shell $(CC
) -v
2>&1 | grep
-c
"clang version"), 1)
65 # For packaging purposes, you might want to call your own:
66 # make CFLAGS="<flags>"
67 CFLAGS_DEF
= -std
=gnu99
75 ifeq ($(HARDENING
), 1)
76 CFLAGS_DEF
+= -fPIE
-pie
77 CFLAGS_DEF
+= -Wl
,-z
,relro
,-z
,now
78 CFLAGS_DEF
+= -fstack-protector-all
79 CFLAGS_DEF
+= -Wstack-protector
80 CFLAGS_DEF
+= --param
=ssp-buffer-size
=4
82 CFLAGS_DEF
+= -U_FORTIFY_SOURCE
-D_FORTIFY_SOURCE
=2
83 CFLAGS_DEF
+= -fexceptions
86 CFLAGS_DEF
+= -fomit-frame-pointer
87 CFLAGS_DEF
+= -fno-strict-aliasing
88 CFLAGS_DEF
+= -fasynchronous-unwind-tables
89 ifneq ($(COMPILER
), clang
)
90 CFLAGS_DEF
+= -fno-delete-null-pointer-checks
93 CFLAGS_MIN
= -D_REENTRANT
94 CFLAGS_MIN
+= -D_LARGEFILE_SOURCE
95 CFLAGS_MIN
+= -D_LARGEFILE64_SOURCE
96 CFLAGS_MIN
+= -D_FILE_OFFSET_BITS
=64
97 CFLAGS_MIN
+= -DVERSION_STRING
=\"$(VERSION_STRING
)\"
98 CFLAGS_MIN
+= -DVERSION_LONG
=\"$(VERSION_LONG
)\"
99 CFLAGS_MIN
+= -DETCDIRE_STRING
=\"$(ETCDIRE
)\"
104 CFLAGS ?
= $(CFLAGS_DEF
) $(WFLAGS_DEF
) $(CPPFLAGS
)
105 override CFLAGS
+= $(CFLAGS_MIN
) -I.
111 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
112 LDFLAGS
+= -L
$(CROSS_LD_LIBRARY_PATH
)
115 CHECKFLAGS
= -D__linux__
-Dlinux
-D__STDC__
-Dunix
-D__unix \
116 -Wbitwise
-Wnoreturn-void
118 VERSION_SHORT
= $(VERSION
).
$(PATCHLEVEL
).
$(SUBLEVEL
)$(EXTRAVERSION
)
119 VERSION_STRING
= "$(VERSION_SHORT)$(CONFIG_RC)"
120 VERSION_LONG
= "$(VERSION_SHORT)$(CONFIG_RC) ($(NAME))"
122 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
123 export DEBUG HARDENING
125 ifneq ("$(TERM)", "")
126 bold
= $(shell tput bold
)
127 normal
= $(shell tput sgr0
)
133 ifneq ("$(CROSS_COMPILE)", "")
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)"
145 .PHONY
: all toolkit
$(TOOLS
) clean %_prehook
%_clean
%_install
%_uninstall tag
tags cscope
146 .IGNORE
: %_clean_custom
%_install_custom
147 .NOTPARALLEL
: $(TOOLS
)
152 all: build_showinfo toolkit
153 allbutcurvetun
: $(filter-out curvetun
,$(TOOLS
))
154 allbutmausezahn
: $(filter-out mausezahn
,$(TOOLS
))
156 clean: $(foreach tool
,$(TOOLS
),$(tool
)_clean
)
158 $(Q
)$(call RM
,Config
)
159 $(Q
)$(call RM
,config.h
)
160 $(Q
)$(call RM
,config.log
)
161 $(Q
)$(call RM
,cov-int
)
162 $(Q
)$(call RM
,netsniff-ng-coverity.tgz
)
167 install_all
: $(foreach tool
,$(TOOLS
),$(tool
)_install
)
168 install_allbutcurvetun
: $(foreach tool
,$(filter-out curvetun
,$(TOOLS
)),$(tool
)_install
)
169 install_allbutmausezahn
: $(foreach tool
,$(filter-out mausezahn
,$(TOOLS
)),$(tool
)_install
)
170 uninstall: $(foreach tool
,$(TOOLS
),$(tool
)_uninstall
)
173 $(LEX
) -P
$(shell perl
-wlne
'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
174 -o
$(BUILD_DIR
)/$(shell basename $< .l
).yy.c
$(LEX_FLAGS
) $<
176 $(YAAC
) -p
$(shell perl
-wlne
'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
177 -o
$(BUILD_DIR
)/$(shell basename $< .y
).tab.c
$(YAAC_FLAGS
) -d
$<
179 $(foreach tool
,$(TOOLS
),$(eval
$(call TOOL_templ
,$(tool
))))
184 $(LDQ
) $(LDFLAGS
) -o
$@
/$@
$(shell LC_ALL
=C ls
$@
/*.o
) $($@
-libs
)