proto_80211_mac_hdr.c: add some more elements
[netsniff-ng.git] / src / Makefile
blobcef3cb2eb7cb122df85622987202ff14e4779410
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 --param=ssp-buffer-size=4 \
27 -fpie \
28 -fno-strict-aliasing \
29 -fexceptions \
30 -fasynchronous-unwind-tables \
31 -fno-delete-null-pointer-checks \
32 -D_FORTIFY_SOURCE=2 \
33 -D_REENTRANT \
34 -D_FILE_OFFSET_BITS=64 \
35 -D_LARGEFILE_SOURCE \
36 -D_LARGEFILE64_SOURCE \
37 -DVERSION_STRING=\"$(VERSION_STRING)\" \
38 -std=gnu99 \
39 -march=native \
40 -mtune=native \
41 -O3 \
44 WFLAGS = -Wall \
45 -Wmissing-prototypes \
46 -Wdeclaration-after-statement \
47 -Werror-implicit-function-declaration \
48 -Wundef \
49 -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 -Wframe-larger-than=2048 \
127 -D__WITH_PROTOS \
128 #-D__WITH_HARDWARE_TIMESTAMPING
129 trafgen: ALL_CFLAGS += -I.. -I$(INCDIR)/libnl3/ \
130 -Wstrict-prototypes \
131 -Wframe-larger-than=2048 \
132 -D__WITH_PROTOS \
133 #-D__WITH_HARDWARE_TIMESTAMPING
134 trafgen_clean_custom:
135 @rm $(BUILD_DIR)/*.h $(BUILD_DIR)/*.c
136 astraceroute: ALL_CFLAGS += -Wstrict-prototypes -Wframe-larger-than=2048
137 flowtop: ALL_CFLAGS += -Wstrict-prototypes -Wframe-larger-than=2048
138 ifpps: ALL_CFLAGS += -Wstrict-prototypes -Wframe-larger-than=2048
139 bpfc: ALL_CFLAGS += -I.. -Wstrict-prototypes -Wframe-larger-than=2048
140 curvetun: ALL_CFLAGS += -Wstrict-prototypes -Wframe-larger-than=2048
142 $(TOOLS):
143 $(LD) $(ALL_LDFLAGS) -o $@/$@ $@/*.o $($@-libs)
144 $(STRIP) $@/$@