Merge tag 'batadv-net-for-davem-20171215' of git://git.open-mesh.org/linux-merge
[sfrench/cifs-2.6.git] / tools / bpf / bpftool / Makefile
1 include ../../scripts/Makefile.include
2
3 include ../../scripts/utilities.mak
4
5 ifeq ($(srctree),)
6 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7 srctree := $(patsubst %/,%,$(dir $(srctree)))
8 srctree := $(patsubst %/,%,$(dir $(srctree)))
9 #$(info Determined 'srctree' to be $(srctree))
10 endif
11
12 ifneq ($(objtree),)
13 #$(info Determined 'objtree' to be $(objtree))
14 endif
15
16 ifneq ($(OUTPUT),)
17 #$(info Determined 'OUTPUT' to be $(OUTPUT))
18 # Adding $(OUTPUT) as a directory to look for source files,
19 # because use generated output files as sources dependency
20 # for flex/bison parsers.
21 VPATH += $(OUTPUT)
22 export VPATH
23 endif
24
25 ifeq ($(V),1)
26   Q =
27 else
28   Q = @
29 endif
30
31 BPF_DIR = $(srctree)/tools/lib/bpf/
32
33 ifneq ($(OUTPUT),)
34   BPF_PATH=$(OUTPUT)
35 else
36   BPF_PATH=$(BPF_DIR)
37 endif
38
39 LIBBPF = $(BPF_PATH)libbpf.a
40
41 $(LIBBPF): FORCE
42         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)
43
44 $(LIBBPF)-clean:
45         $(call QUIET_CLEAN, libbpf)
46         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null
47
48 prefix = /usr/local
49 bash_compdir ?= /usr/share/bash-completion/completions
50
51 CC = gcc
52
53 CFLAGS += -O2
54 CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow
55 CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
56 LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
57
58 include $(wildcard *.d)
59
60 all: $(OUTPUT)bpftool
61
62 SRCS=$(wildcard *.c)
63 OBJS=$(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
64
65 $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
66         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
67
68 $(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
69         $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
70
71 $(OUTPUT)%.o: %.c
72         $(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
73
74 clean: $(LIBBPF)-clean
75         $(call QUIET_CLEAN, bpftool)
76         $(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d
77
78 install:
79         install -m 0755 -d $(prefix)/sbin
80         install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
81         install -m 0755 -d $(bash_compdir)
82         install -m 0644 bash-completion/bpftool $(bash_compdir)
83
84 doc:
85         $(Q)$(MAKE) -C Documentation/
86
87 doc-install:
88         $(Q)$(MAKE) -C Documentation/ install
89
90 FORCE:
91
92 .PHONY: all clean FORCE install doc doc-install
93 .DEFAULT_GOAL := all