Commit 75a141af authored by Daniel Borkmann's avatar Daniel Borkmann

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: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents 12ef9bda ef8ba83b
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
prefix = /usr include ../scripts/Makefile.include
prefix ?= /usr/local
CC = gcc CC = gcc
LEX = flex LEX = flex
YACC = bison YACC = bison
MAKE = make MAKE = make
INSTALL ?= install
CFLAGS += -Wall -O2 CFLAGS += -Wall -O2
CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include CFLAGS += -D__EXPORTED_HEADERS__ -I$(srctree)/include/uapi -I$(srctree)/include
ifeq ($(srctree),) ifeq ($(srctree),)
srctree := $(patsubst %/,%,$(dir $(CURDIR))) srctree := $(patsubst %/,%,$(dir $(CURDIR)))
srctree := $(patsubst %/,%,$(dir $(srctree))) srctree := $(patsubst %/,%,$(dir $(srctree)))
endif endif
ifeq ($(V),1)
Q =
else
Q = @
endif
FEATURE_USER = .bpf FEATURE_USER = .bpf
FEATURE_TESTS = libbfd disassembler-four-args FEATURE_TESTS = libbfd disassembler-four-args
FEATURE_DISPLAY = libbfd disassembler-four-args FEATURE_DISPLAY = libbfd disassembler-four-args
...@@ -38,40 +47,57 @@ ifeq ($(feature-disassembler-four-args), 1) ...@@ -38,40 +47,57 @@ ifeq ($(feature-disassembler-four-args), 1)
CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
endif endif
%.yacc.c: %.y $(OUTPUT)%.yacc.c: $(srctree)/tools/bpf/%.y
$(YACC) -o $@ -d $< $(QUIET_BISON)$(YACC) -o $@ -d $<
%.lex.c: %.l $(OUTPUT)%.lex.c: $(srctree)/tools/bpf/%.l
$(LEX) -o $@ $< $(QUIET_FLEX)$(LEX) -o $@ $<
all: bpf_jit_disasm bpf_dbg bpf_asm bpftool $(OUTPUT)%.o: $(srctree)/tools/bpf/%.c
$(QUIET_CC)$(COMPILE.c) -o $@ $<
bpf_jit_disasm : CFLAGS += -DPACKAGE='bpf_jit_disasm' $(OUTPUT)%.yacc.o: $(OUTPUT)%.yacc.c
bpf_jit_disasm : LDLIBS = -lopcodes -lbfd -ldl $(QUIET_CC)$(COMPILE.c) -o $@ $<
bpf_jit_disasm : bpf_jit_disasm.o $(OUTPUT)%.lex.o: $(OUTPUT)%.lex.c
$(QUIET_CC)$(COMPILE.c) -o $@ $<
bpf_dbg : LDLIBS = -lreadline PROGS = $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg $(OUTPUT)bpf_asm
bpf_dbg : bpf_dbg.o
bpf_asm : LDLIBS = all: $(PROGS) bpftool
bpf_asm : bpf_asm.o bpf_exp.yacc.o bpf_exp.lex.o
bpf_exp.lex.o : bpf_exp.yacc.c
clean: bpftool_clean $(OUTPUT)bpf_jit_disasm: CFLAGS += -DPACKAGE='bpf_jit_disasm'
rm -rf *.o bpf_jit_disasm bpf_dbg bpf_asm bpf_exp.yacc.* bpf_exp.lex.* $(OUTPUT)bpf_jit_disasm: $(OUTPUT)bpf_jit_disasm.o
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lopcodes -lbfd -ldl
install: bpftool_install $(OUTPUT)bpf_dbg: $(OUTPUT)bpf_dbg.o
install bpf_jit_disasm $(prefix)/bin/bpf_jit_disasm $(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^ -lreadline
install bpf_dbg $(prefix)/bin/bpf_dbg
install bpf_asm $(prefix)/bin/bpf_asm $(OUTPUT)bpf_asm: $(OUTPUT)bpf_asm.o $(OUTPUT)bpf_exp.yacc.o $(OUTPUT)bpf_exp.lex.o
$(QUIET_LINK)$(CC) $(CFLAGS) -o $@ $^
$(OUTPUT)bpf_exp.lex.c: $(OUTPUT)bpf_exp.yacc.c
clean: bpftool_clean
$(call QUIET_CLEAN, bpf-progs)
$(Q)rm -rf $(OUTPUT)*.o $(OUTPUT)bpf_jit_disasm $(OUTPUT)bpf_dbg \
$(OUTPUT)bpf_asm $(OUTPUT)bpf_exp.yacc.* $(OUTPUT)bpf_exp.lex.*
install: $(PROGS) bpftool_install
$(call QUIET_INSTALL, bpf_jit_disasm)
$(Q)$(INSTALL) -m 0755 -d $(DESTDIR)$(prefix)/bin
$(Q)$(INSTALL) $(OUTPUT)bpf_jit_disasm $(DESTDIR)$(prefix)/bin/bpf_jit_disasm
$(call QUIET_INSTALL, bpf_dbg)
$(Q)$(INSTALL) $(OUTPUT)bpf_dbg $(DESTDIR)$(prefix)/bin/bpf_dbg
$(call QUIET_INSTALL, bpf_asm)
$(Q)$(INSTALL) $(OUTPUT)bpf_asm $(DESTDIR)$(prefix)/bin/bpf_asm
bpftool: bpftool:
$(MAKE) -C bpftool $(call descend,bpftool)
bpftool_install: bpftool_install:
$(MAKE) -C bpftool install $(call descend,bpftool,install)
bpftool_clean: bpftool_clean:
$(MAKE) -C bpftool clean $(call descend,bpftool,clean)
.PHONY: bpftool FORCE .PHONY: bpftool FORCE
...@@ -38,7 +38,7 @@ bash_compdir ?= /usr/share/bash-completion/completions ...@@ -38,7 +38,7 @@ bash_compdir ?= /usr/share/bash-completion/completions
CC = gcc CC = gcc
CFLAGS += -O2 CFLAGS += -O2
CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow CFLAGS += -W -Wall -Wextra -Wno-unused-parameter -Wshadow -Wno-missing-field-initializers
CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/ CFLAGS += -DPACKAGE='"bpftool"' -D__EXPORTED_HEADERS__ -I$(srctree)/tools/include/uapi -I$(srctree)/tools/include -I$(srctree)/tools/lib/bpf -I$(srctree)/kernel/bpf/
CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"' CFLAGS += -DBPFTOOL_VERSION='"$(BPFTOOL_VERSION)"'
LIBS = -lelf -lbfd -lopcodes $(LIBBPF) LIBS = -lelf -lbfd -lopcodes $(LIBBPF)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment