Skip to content

Commit 75a141a

Browse files
committed
Merge branch 'bpf-tools-makefile-improvements'
Jiri Benc says: ==================== Currently, 'make bpf' in the tools/ directory does not provide the standard quiet output except for bpftool (which is however listed with a wrong directory). Worse, it does not respect the build output directory. The 'make bpf_install' does not work as one would expect, either. It installs unconditionally to /usr/bin without respecting DESTDIR and prefix. This patchset improves that behavior. ==================== Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
2 parents 12ef9bd + ef8ba83 commit 75a141a

File tree

2 files changed

+51
-25
lines changed

2 files changed

+51
-25
lines changed

tools/bpf/Makefile

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
prefix = /usr
2+
include ../scripts/Makefile.include
3+
4+
prefix ?= /usr/local
35

46
CC = gcc
57
LEX = flex
68
YACC = bison
79
MAKE = make
10+
INSTALL ?= install
811

912
CFLAGS += -Wall -O2
10-
CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
13+
CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
1114

1215
ifeq ($(srctree),)
1316
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
1417
srctree := $(patsubst %/,%,$(dir $(srctree)))
1518
endif
1619

20+
ifeq ($(V),1)
21+
Q =
22+
else
23+
Q = @
24+
endif
25+
1726
FEATURE_USER = .bpf
1827
FEATURE_TESTS = libbfd disassembler-four-args
1928
FEATURE_DISPLAY = libbfd disassembler-four-args
@@ -38,40 +47,57 @@ ifeq ($(feature-disassembler-four-args), 1)
3847
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
3948
endif
4049

41-
%.yacc.c: %.y
42-
$(YACC) -o $@ -d $<
50+
$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
51+
$(QUIET_BISON)$(YACC) -o $@ -d $<
4352

44-
%.lex.c: %.l
45-
$(LEX) -o $@ $<
53+
$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
54+
$(QUIET_FLEX)$(LEX) -o $@ $<
4655

47-
all: bpf_jit_disasm bpf_dbg bpf_asm bpftool
56+
$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
57+
$(QUIET_CC)$(COMPILE.c) -o $@ $<
4858

49-
bpf_jit_disasm : CFLAGS += -DPACKAGE='bpf_jit_disasm'
50-
bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl
51-
bpf_jit_disasm : bpf_jit_disasm.o
59+
$(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
60+
$(QUIET_CC)$(COMPILE.c) -o $@ $<
61+
$(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
62+
$(QUIET_CC)$(COMPILE.c) -o $@ $<
5263

53-
bpf_dbg : LDLIBS = -lreadline
54-
bpf_dbg : bpf_dbg.o
64+
PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
5565

56-
bpf_asm : LDLIBS =
57-
bpf_asm : bpf_asm.o bpf_exp.yacc.o bpf_exp.lex.o
58-
bpf_exp.lex.o : bpf_exp.yacc.c
66+
all: $(PROGS) bpftool
5967

60-
clean: bpftool_clean
61-
rm -rf *.o bpf_jit_disasm bpf_dbg bpf_asm bpf_exp.yacc.* bpf_exp.lex.*
68+
$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
69+
$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
70+
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
6271

63-
install: bpftool_install
64-
install bpf_jit_disasm $(prefix)/bin/bpf_jit_disasm
65-
install bpf_dbg $(prefix)/bin/bpf_dbg
66-
install bpf_asm $(prefix)/bin/bpf_asm
72+
$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
73+
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
74+
75+
$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
76+
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
77+
78+
$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
79+
80+
clean: bpftool_clean
81+
$(call QUIET_CLEAN, bpf-progs)
82+
$(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
83+
$(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
84+
85+
install: $(PROGS) bpftool_install
86+
$(call QUIET_INSTALL, bpf_jit_disasm)
87+
$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
88+
$(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
89+
$(call QUIET_INSTALL, bpf_dbg)
90+
$(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
91+
$(call QUIET_INSTALL, bpf_asm)
92+
$(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
6793

6894
bpftool:
69-
$(MAKE) -C bpftool
95+
$(call descend,bpftool)
7096

7197
bpftool_install:
72-
$(MAKE) -C bpftool install
98+
$(call descend,bpftool,install)
7399

74100
bpftool_clean:
75-
$(MAKE) -C bpftool clean
101+
$(call descend,bpftool,clean)
76102

77103
.PHONY: bpftool FORCE

tools/bpf/bpftool/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ bash_compdir ?= /usr/share/bash-completion/completions
3838
CC = gcc
3939

4040
CFLAGS += -O2
41-
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow
41+
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
4242
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
4343
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
4444
LIBS = -lelf -lbfd -lopcodes $(LIBBPF)

0 commit comments

Comments
 (0)