trafgen: ipv4: Do not use user-provided 'ihl' field to calculate csum
[netsniff-ng-new.git] / Makefile
blob7ace9e96f361bd3f8489d40d8bc43b1a3ee71467
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.
6 -include Config
7 -include Cmds
8 -include Extra
9 -include Template
10 -include Misc
12 ifndef CONFIG_OK
13 $(error "Please run `./configure' before `make'")
14 endif
16 VERSION = 0
17 PATCHLEVEL = 6
18 SUBLEVEL = 1
19 EXTRAVERSION =
20 NAME = aisatsana
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.
26 PREFIX ?= /usr/local
28 # Set to use ccache for compilation
29 CCACHE ?=
31 # Location of an alternative destination directory for installation
32 # Useful when cross-compiling and installing in a dedicated target directory
33 DESTDIR=
35 # Location of installation paths.
36 SBINDIR = $(PREFIX)/sbin
37 INCDIR = $(PREFIX)/include
38 ETCDIR ?= /etc
39 ETCDIRE = $(ETCDIR)/netsniff-ng
40 MAN8DIR = $(PREFIX)/share/man/man8
42 # Shut up make, helper warnings, parallel compilation!
43 MAKEFLAGS += --no-print-directory
44 MAKEFLAGS += -rR
45 MAKEFLAGS += --warn-undefined-variables
46 MAKEFLAGS += --jobs=$(shell grep "^processor" /proc/cpuinfo | wc -l)
48 # Debugging option
49 ifeq ("$(origin DEBUG)", "command line")
50 DEBUG := 1
51 else
52 DEBUG := 0
53 endif
55 # Compiler detection
56 ifneq ($(CC),)
57 ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
58 COMPILER := clang
59 else
60 COMPILER := gcc
61 endif
62 export COMPILER
63 endif
65 # For packaging purposes, you might want to call your own:
66 # make CFLAGS="<flags>"
67 CFLAGS_DEF = -std=gnu99
68 CFLAGS_DEF += -pipe
69 CFLAGS_DEF += -O2
71 ifeq ($(DEBUG), 1)
72 CFLAGS_DEF += -g
73 endif
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
81 CFLAGS_DEF += -ftrapv
82 CFLAGS_DEF += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
83 CFLAGS_DEF += -fexceptions
84 endif
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
91 endif
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)\"
101 WFLAGS_DEF = -Wall
103 CPPFLAGS ?=
104 CFLAGS ?= $(CFLAGS_DEF) $(WFLAGS_DEF) $(CPPFLAGS)
105 override CFLAGS += $(CFLAGS_MIN) -I.
107 LEX_FLAGS =
108 YAAC_FLAGS =
110 LDFLAGS ?=
111 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
112 LDFLAGS += -L$(CROSS_LD_LIBRARY_PATH)
113 endif
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)
128 else
129 bold =
130 normal =
131 endif
133 ifneq ("$(CROSS_COMPILE)", "")
134 WHAT := Cross-compiling
135 else
136 WHAT := Building
137 endif
139 build_showinfo:
140 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
141 $(shell $(CCNQ) -dumpmachine)":$(normal)"
142 clean_showinfo:
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)
148 .DEFAULT_GOAL := all
149 .DEFAULT:
150 .FORCE:
152 all: build_showinfo toolkit
153 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
154 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
155 toolkit: $(TOOLS)
156 clean: $(foreach tool,$(TOOLS),$(tool)_clean)
157 distclean: 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)
163 mrproper: distclean
164 $(Q)$(GIT_REM)
166 install: install_all
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)
172 %.yy.o: %.l
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) $<
175 %.tab.o: %.y
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))))
181 %:: ;
183 $(TOOLS):
184 $(LDQ) $(LDFLAGS) -o $@/$@ $(shell LC_ALL=C ls $@/*.o) $($@-libs)