Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | include ../scripts/Makefile.include |
| 3 | |
| 4 | prefix ?= /usr/local |
| 5 | |
| 6 | CC = gcc |
| 7 | LEX = flex |
| 8 | YACC = bison |
| 9 | MAKE = make |
| 10 | INSTALL ?= install |
| 11 | |
| 12 | CFLAGS += -Wall -O2 |
| 13 | CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include |
| 14 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 15 | # This will work when bpf is built in tools env. where srctree |
| 16 | # isn't set and when invoked from selftests build, where srctree |
| 17 | # is set to ".". building_out_of_srctree is undefined for in srctree |
| 18 | # builds |
| 19 | ifndef building_out_of_srctree |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 20 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 21 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 22 | endif |
| 23 | |
| 24 | ifeq ($(V),1) |
| 25 | Q = |
| 26 | else |
| 27 | Q = @ |
| 28 | endif |
| 29 | |
| 30 | FEATURE_USER = .bpf |
| 31 | FEATURE_TESTS = libbfd disassembler-four-args |
| 32 | FEATURE_DISPLAY = libbfd disassembler-four-args |
| 33 | |
| 34 | check_feat := 1 |
| 35 | NON_CHECK_FEAT_TARGETS := clean bpftool_clean |
| 36 | ifdef MAKECMDGOALS |
| 37 | ifeq ($(filter-out $(NON_CHECK_FEAT_TARGETS),$(MAKECMDGOALS)),) |
| 38 | check_feat := 0 |
| 39 | endif |
| 40 | endif |
| 41 | |
| 42 | ifeq ($(check_feat),1) |
| 43 | ifeq ($(FEATURES_DUMP),) |
| 44 | include $(srctree)/tools/build/Makefile.feature |
| 45 | else |
| 46 | include $(FEATURES_DUMP) |
| 47 | endif |
| 48 | endif |
| 49 | |
| 50 | ifeq ($(feature-disassembler-four-args), 1) |
| 51 | CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE |
| 52 | endif |
| 53 | |
| 54 | $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y |
| 55 | $(QUIET_BISON)$(YACC) -o $@ -d $< |
| 56 | |
| 57 | $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l |
| 58 | $(QUIET_FLEX)$(LEX) -o $@ $< |
| 59 | |
| 60 | $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c |
| 61 | $(QUIET_CC)$(COMPILE.c) -o $@ $< |
| 62 | |
| 63 | $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c |
| 64 | $(QUIET_CC)$(COMPILE.c) -o $@ $< |
| 65 | $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c |
| 66 | $(QUIET_CC)$(COMPILE.c) -o $@ $< |
| 67 | |
| 68 | PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm |
| 69 | |
| 70 | all: $(PROGS) bpftool |
| 71 | |
| 72 | $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm' |
| 73 | $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o |
| 74 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl |
| 75 | |
| 76 | $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o |
| 77 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline |
| 78 | |
| 79 | $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o |
| 80 | $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ |
| 81 | |
| 82 | $(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c |
| 83 | $(OUTPUT)bpf_exp.yacc.o: $(OUTPUT)bpf_exp.yacc.c |
| 84 | $(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.lex.c |
| 85 | |
| 86 | clean: bpftool_clean |
| 87 | $(call QUIET_CLEAN, bpf-progs) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 88 | $(Q)$(RM) -r -- $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 89 | $(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.* |
| 90 | $(call QUIET_CLEAN, core-gen) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 91 | $(Q)$(RM) -- $(OUTPUT)FEATURE-DUMP.bpf |
| 92 | $(Q)$(RM) -r -- $(OUTPUT)feature |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 93 | |
| 94 | install: $(PROGS) bpftool_install |
| 95 | $(call QUIET_INSTALL, bpf_jit_disasm) |
| 96 | $(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin |
| 97 | $(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm |
| 98 | $(call QUIET_INSTALL, bpf_dbg) |
| 99 | $(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg |
| 100 | $(call QUIET_INSTALL, bpf_asm) |
| 101 | $(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm |
| 102 | |
| 103 | bpftool: |
| 104 | $(call descend,bpftool) |
| 105 | |
| 106 | bpftool_install: |
| 107 | $(call descend,bpftool,install) |
| 108 | |
| 109 | bpftool_clean: |
| 110 | $(call descend,bpftool,clean) |
| 111 | |
| 112 | .PHONY: all install clean bpftool bpftool_install bpftool_clean |