Makefile 2.1 KB
Newer Older
J
Jakub Kicinski 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
include ../../scripts/Makefile.include

include ../../scripts/utilities.mak

ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
srctree := $(patsubst %/,%,$(dir $(srctree)))
#$(info Determined 'srctree' to be $(srctree))
endif

ifneq ($(objtree),)
#$(info Determined 'objtree' to be $(objtree))
endif

ifneq ($(OUTPUT),)
#$(info Determined 'OUTPUT' to be $(OUTPUT))
# Adding $(OUTPUT) as a directory to look for source files,
# because use generated output files as sources dependency
# for flex/bison parsers.
VPATH += $(OUTPUT)
export VPATH
endif

ifeq ($(V),1)
  Q =
else
  Q = @
endif

BPF_DIR	= $(srctree)/tools/lib/bpf/

ifneq ($(OUTPUT),)
  BPF_PATH=$(OUTPUT)
else
  BPF_PATH=$(BPF_DIR)
endif

LIBBPF = $(BPF_PATH)libbpf.a

$(LIBBPF): FORCE
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) $(OUTPUT)libbpf.a FEATURES_DUMP=$(FEATURE_DUMP_EXPORT)

$(LIBBPF)-clean:
	$(call QUIET_CLEAN, libbpf)
	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(OUTPUT) clean >/dev/null

prefix = /usr
49
bash_compdir ?= $(prefix)/share/bash-completion/completions
J
Jakub Kicinski 已提交
50 51 52 53 54

CC = gcc

CFLAGS += -O2
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/
J
Jakub Kicinski 已提交
56 57 58 59 60 61 62
LIBS = -lelf -lbfd -lopcodes $(LIBBPF)

include $(wildcard *.d)

all: $(OUTPUT)bpftool

SRCS=$(wildcard *.c)
63 64 65 66
OBJS=$(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o

$(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
J
Jakub Kicinski 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79

$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
	$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ $(LIBS)

$(OUTPUT)%.o: %.c
	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<

clean: $(LIBBPF)-clean
	$(call QUIET_CLEAN, bpftool)
	$(Q)rm -rf $(OUTPUT)bpftool $(OUTPUT)*.o $(OUTPUT)*.d

install:
	install $(OUTPUT)bpftool $(prefix)/sbin/bpftool
80 81
	install -m 0755 -d $(bash_compdir)
	install -m 0644 bash-completion/bpftool $(bash_compdir)
J
Jakub Kicinski 已提交
82

J
Jakub Kicinski 已提交
83 84 85 86 87 88
doc:
	$(Q)$(MAKE) -C Documentation/

doc-install:
	$(Q)$(MAKE) -C Documentation/ install

J
Jakub Kicinski 已提交
89 90 91 92
FORCE:

.PHONY: all clean FORCE
.DEFAULT_GOAL := all