Skip to content

Commit 5a8997f

Browse files
Jiri Bencborkmann
authored andcommitted
tools: bpf: respect output directory during build
Currently, the programs under tools/bpf (with the notable exception of bpftool) do not respect the output directory (make O=dir). Fix that. Signed-off-by: Jiri Benc <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 72ab55e commit 5a8997f

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

tools/bpf/Makefile

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

46
CC = gcc
@@ -7,7 +9,7 @@ YACC = bison
79
MAKE = make
810

911
CFLAGS += -Wall -O2
10-
CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include
12+
CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
1113

1214
ifeq ($(srctree),)
1315
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
@@ -38,32 +40,36 @@ ifeq ($(feature-disassembler-four-args), 1)
3840
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
3941
endif
4042

41-
%.yacc.c: %.y
43+
$(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
4244
$(YACC) -o $@ -d $<
4345

44-
%.lex.c: %.l
46+
$(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
4547
$(LEX) -o $@ $<
4648

47-
all: bpf_jit_disasm bpf_dbg bpf_asm bpftool
49+
$(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
50+
$(COMPILE.c) -o $@ $<
51+
52+
all: $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm bpftool
4853

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
54+
$(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
55+
$(OUTPUT)bpf_jit_disasm: LDLIBS = -lopcodes -lbfd -ldl
56+
$(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
5257

53-
bpf_dbg : LDLIBS = -lreadline
54-
bpf_dbg : bpf_dbg.o
58+
$(OUTPUT)bpf_dbg: LDLIBS = -lreadline
59+
$(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
5560

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
61+
$(OUTPUT)bpf_asm: LDLIBS =
62+
$(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
63+
$(OUTPUT)bpf_exp.lex.o: $(OUTPUT)bpf_exp.yacc.c
5964

6065
clean: bpftool_clean
61-
rm -rf *.o bpf_jit_disasm bpf_dbg bpf_asm bpf_exp.yacc.* bpf_exp.lex.*
66+
rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
67+
$(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
6268

6369
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
70+
install $(OUTPUT)bpf_jit_disasm $(prefix)/bin/bpf_jit_disasm
71+
install $(OUTPUT)bpf_dbg $(prefix)/bin/bpf_dbg
72+
install $(OUTPUT)bpf_asm $(prefix)/bin/bpf_asm
6773

6874
bpftool:
6975
$(MAKE) -C bpftool

0 commit comments

Comments
 (0)