make: use "+=" in flags
[netsniff-ng.git] / src / Makefile
blob8c630fbef44274b032f8dd39049e9cd8af57003d
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.
5 VERSION = 0
6 PATCHLEVEL = 5
7 SUBLEVEL = 8
8 EXTRAVERSION = -rc0
10 TOOLS = netsniff-ng trafgen astraceroute flowtop ifpps mausezahn bpfc curvetun
12 # For packaging purposes, prefix can define a different path.
13 PREFIX ?=
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 CFLAGS += --param=ssp-buffer-size=4
27 CFLAGS += -fpie
28 CFLAGS += -fno-strict-aliasing
29 CFLAGS += -fexceptions
30 CFLAGS += -fasynchronous-unwind-tables
31 CFLAGS += -fno-delete-null-pointer-checks
32 CFLAGS += -D_FORTIFY_SOURCE=2
33 CFLAGS += -D_REENTRANT
34 CFLAGS += -D_FILE_OFFSET_BITS=64
35 CFLAGS += -D_LARGEFILE_SOURCE
36 CFLAGS += -D_LARGEFILE64_SOURCE
37 CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\"
38 CFLAGS += -std=gnu99
39 CFLAGS += -march=native
40 CFLAGS += -mtune=native
41 CFLAGS += -O3
42 CFLAGS += -g
44 WFLAGS = -Wall
45 #WFLAGS += -Wmissing-prototypes
46 #WFLAGS += -Wdeclaration-after-statement
47 #WFLAGS += -Werror-implicit-function-declaration
48 #WFLAGS += -Wundef
49 WFLAGS += -Wformat=2
51 CFLAGS += $(WFLAGS) -I.
52 CPPFLAGS =
53 ifeq ("$(origin CROSS_LD_LIBRARY_PATH)", "command line")
54 LDFLAGS = -L$(CROSS_LD_LIBRARY_PATH)
55 else
56 LDFLAGS =
57 endif
59 ALL_CFLAGS = $(CFLAGS)
60 ALL_LDFLAGS = $(LDFLAGS)
61 TARGET_ARCH =
62 LEX_FLAGS =
63 YAAC_FLAGS =
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)
82 build_showinfo:
83 @echo "$(bold)Building netsniff-ng toolkit ($(VERSION_STRING)) for" \
84 $(shell $(CCNQ) -dumpmachine)":$(normal)"
85 clean_showinfo:
86 @echo "$(bold)Cleaning netsniff-ng toolkit ($(VERSION_STRING)):$(normal)"
88 %.yy.o: %.l
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) $<
91 %.tab.o: %.y
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 $<
94 %.o: %.c
95 $(CC) $(ALL_CFLAGS) -o $(BUILD_DIR)/$(shell basename $< .c).o -c $<
97 .PHONY: all
98 .DEFAULT_GOAL := all
100 all: build_showinfo toolkit
101 toolkit: $(TOOLS)
102 clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean)
103 realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean)
105 define TOOL_templ
106 include $(1)/Makefile
107 $(1) $(1)%: BUILD_DIR := $(1)
108 $(1)_prehook:
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)
113 $(1)_install:
114 @install -D $$(BUILD_DIR)/$(1) $$(SBINDIR)/$(1)
115 $(1)_distclean:
116 @rm $$(SBINDIR)/$(1)
117 endef
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 -D__WITH_PROTOS \
127 #-D__WITH_HARDWARE_TIMESTAMPING
128 trafgen: ALL_CFLAGS += -I.. -I$(INCDIR)/libnl3/ \
129 -Wstrict-prototypes \
130 -D__WITH_PROTOS \
131 #-D__WITH_HARDWARE_TIMESTAMPING
132 trafgen_clean_custom:
133 @rm $(BUILD_DIR)/*.h $(BUILD_DIR)/*.c
134 astraceroute: ALL_CFLAGS += -Wstrict-prototypes
135 flowtop: ALL_CFLAGS += -Wstrict-prototypes
136 ifpps: ALL_CFLAGS += -Wstrict-prototypes
137 bpfc: ALL_CFLAGS += -I.. -Wstrict-prototypes
138 curvetun: ALL_CFLAGS += -Wstrict-prototypes
140 $(TOOLS):
141 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
142 $(STRIP) $@/$@