trafgen: icmpv4: Update csum at runtime if needed
[netsniff-ng-new.git] / Makefile
blobad1c1fcb85946e809d3efa98abbac9c5dee0e972
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 ifeq ($(CONFIG_DEBUG), 1)
53 DEBUG := 1
54 else
55 DEBUG := 0
56 endif
57 endif
59 # Compiler detection
60 ifneq ($(CC),)
61 ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
62 COMPILER := clang
63 else
64 COMPILER := gcc
65 endif
66 export COMPILER
67 endif
69 # For packaging purposes, you might want to call your own:
70 # make CFLAGS="<flags>"
71 CFLAGS_DEF = -std=gnu99
72 CFLAGS_DEF += -pipe
74 ifeq ($(DEBUG), 1)
75 CFLAGS_DEF += -g
76 CFLAGS_DEF += -O0
77 CFLAGS_DEF += -fno-omit-frame-pointer
78 else
79 CFLAGS_DEF += -O2
80 CFLAGS_DEF += -fomit-frame-pointer
81 CFLAGS_DEF += -fno-strict-aliasing
82 CFLAGS_DEF += -fasynchronous-unwind-tables
83 ifneq ($(COMPILER), clang)
84 CFLAGS_DEF += -fno-delete-null-pointer-checks
85 endif
86 endif
88 ifeq ($(HARDENING), 1)
89 CFLAGS_DEF += -fPIE -pie
90 CFLAGS_DEF += -Wl,-z,relro,-z,now
91 CFLAGS_DEF += -fstack-protector-all
92 CFLAGS_DEF += -Wstack-protector
93 CFLAGS_DEF += --param=ssp-buffer-size=4
94 CFLAGS_DEF += -ftrapv
95 CFLAGS_DEF += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
96 CFLAGS_DEF += -fexceptions
97 endif
99 CFLAGS_MIN = -D_REENTRANT
100 CFLAGS_MIN += -D_LARGEFILE_SOURCE
101 CFLAGS_MIN += -D_LARGEFILE64_SOURCE
102 CFLAGS_MIN += -D_FILE_OFFSET_BITS=64
103 CFLAGS_MIN += -DVERSION_STRING=\"$(VERSION_STRING)\"
104 CFLAGS_MIN += -DVERSION_LONG=\"$(VERSION_LONG)\"
105 CFLAGS_MIN += -DETCDIRE_STRING=\"$(ETCDIRE)\"
107 WFLAGS_DEF = -Wall
109 CPPFLAGS ?=
110 CFLAGS ?= $(CFLAGS_DEF) $(WFLAGS_DEF) $(CPPFLAGS)
111 override CFLAGS += $(CFLAGS_MIN) -I.
113 LEX_FLAGS =
114 YAAC_FLAGS =
116 LDFLAGS ?=
117 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
118 LDFLAGS += -L$(CROSS_LD_LIBRARY_PATH)
119 endif
121 CHECKFLAGS = -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix \
122 -Wbitwise -Wnoreturn-void
124 VERSION_SHORT = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
125 VERSION_STRING = "$(VERSION_SHORT)$(CONFIG_RC)"
126 VERSION_LONG = "$(VERSION_SHORT)$(CONFIG_RC) ($(NAME))"
128 export VERSION PATCHLEVEL SUBLEVEL EXTRAVERSION
129 export DEBUG HARDENING
131 ifneq ("$(TERM)", "")
132 bold = $(shell tput bold)
133 normal = $(shell tput sgr0)
134 else
135 bold =
136 normal =
137 endif
139 ifneq ("$(CROSS_COMPILE)", "")
140 WHAT := Cross-compiling
141 else
142 WHAT := Building
143 endif
145 build_showinfo:
146 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
147 $(shell $(CCNQ) -dumpmachine)":$(normal)"
148 clean_showinfo:
149 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
151 .PHONY: all toolkit $(TOOLS) clean %_prehook %_clean %_install %_uninstall tag tags cscope
152 .IGNORE: %_clean_custom %_install_custom
153 .NOTPARALLEL: $(TOOLS)
154 .DEFAULT_GOAL := all
155 .DEFAULT:
156 .FORCE:
158 all: build_showinfo toolkit
159 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
160 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
161 toolkit: $(TOOLS)
162 clean: $(foreach tool,$(TOOLS),$(tool)_clean)
163 distclean: clean
164 $(Q)$(call RM,Config)
165 $(Q)$(call RM,config.h)
166 $(Q)$(call RM,config.log)
167 $(Q)$(call RM,cov-int)
168 $(Q)$(call RM,netsniff-ng-coverity.tgz)
169 mrproper: distclean
170 $(Q)$(GIT_REM)
172 install: install_all
173 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
174 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
175 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
176 uninstall: $(foreach tool,$(TOOLS),$(tool)_uninstall)
178 %.yy.o: %.l
179 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
180 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
181 %.tab.o: %.y
182 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
183 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
185 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
187 %:: ;
189 $(TOOLS):
190 $(LDQ) $(LDFLAGS) -o $@/$@ $(shell LC_ALL=C ls $@/*.o) $($@-libs)