trafgen: Print min packet size in error message
[netsniff-ng.git] / Makefile
blob6550e0573b17ea9b8e32dfe83de0aa2253fbecfd
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 = 5
18 SUBLEVEL = 9
19 EXTRAVERSION =
20 NAME = Cilonen
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 bold = $(shell tput bold)
126 normal = $(shell tput sgr0)
128 ifneq ("$(CROSS_COMPILE)", "")
129 WHAT := Cross-compiling
130 else
131 WHAT := Building
132 endif
134 build_showinfo:
135 $(Q)echo "$(bold)$(WHAT) netsniff-ng toolkit ($(VERSION_STRING)) for" \
136 $(shell $(CCNQ) -dumpmachine)":$(normal)"
137 clean_showinfo:
138 $(Q)echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
140 .PHONY: all toolkit $(TOOLS) clean %_prehook %_clean %_install %_uninstall tag tags cscope
141 .IGNORE: %_clean_custom %_install_custom
142 .NOTPARALLEL: $(TOOLS)
143 .DEFAULT_GOAL := all
144 .DEFAULT:
145 .FORCE:
147 all: build_showinfo toolkit
148 allbutcurvetun: $(filter-out curvetun,$(TOOLS))
149 allbutmausezahn: $(filter-out mausezahn,$(TOOLS))
150 toolkit: $(TOOLS)
151 clean: $(foreach tool,$(TOOLS),$(tool)_clean)
152 distclean: clean
153 $(Q)$(call RM,Config)
154 $(Q)$(call RM,config.h)
155 $(Q)$(call RM,config.log)
156 $(Q)$(call RM,cov-int)
157 $(Q)$(call RM,netsniff-ng-coverity.tgz)
158 mrproper: distclean
159 $(Q)$(GIT_REM)
161 install: install_all
162 install_all: $(foreach tool,$(TOOLS),$(tool)_install)
163 install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install)
164 install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install)
165 uninstall: $(foreach tool,$(TOOLS),$(tool)_uninstall)
167 %.yy.o: %.l
168 $(LEX) -P $(shell perl -wlne 'print $$1 if /lex-func-prefix:\s([a-z]+)/' $<) \
169 -o $(BUILD_DIR)/$(shell basename $< .l).yy.c $(LEX_FLAGS) $<
170 %.tab.o: %.y
171 $(YAAC) -p $(shell perl -wlne 'print $$1 if /yaac-func-prefix:\s([a-z]+)/' $<) \
172 -o $(BUILD_DIR)/$(shell basename $< .y).tab.c $(YAAC_FLAGS) -d $<
174 $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
176 %:: ;
178 $(TOOLS):
179 $(LDQ) $(LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
180 $(STRIPQ) $@/$@