blob: 9ddeca947635427323b5480f67baeb39c862eaef [file] [log] [blame]
Jiri Olsafbbb68d2020-07-11 23:53:21 +02001# SPDX-License-Identifier: GPL-2.0-only
2include ../../scripts/Makefile.include
Jiri Olsadc3652d2020-09-23 20:57:35 +02003include ../../scripts/Makefile.arch
Jiri Olsafbbb68d2020-07-11 23:53:21 +02004
Jiri Olsa7962cb92021-02-05 13:40:19 +01005srctree := $(abspath $(CURDIR)/../../../)
Jiri Olsafbbb68d2020-07-11 23:53:21 +02006
7ifeq ($(V),1)
8 Q =
9 msg =
10else
11 Q = @
12 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
13 MAKEFLAGS=--no-print-directory
14endif
15
Jiri Olsa11bb2f72020-07-14 12:25:34 +020016# always use the host compiler
Jiri Olsa11bb2f72020-07-14 12:25:34 +020017AR = $(HOSTAR)
18CC = $(HOSTCC)
19LD = $(HOSTLD)
Jiri Olsadc3652d2020-09-23 20:57:35 +020020ARCH = $(HOSTARCH)
Jiri Olsa7962cb92021-02-05 13:40:19 +010021RM ?= rm
Jean-Philippe Bruckerbf1be902021-12-16 16:38:39 +000022CROSS_COMPILE =
Jiri Olsa11bb2f72020-07-14 12:25:34 +020023
Jiri Olsafbbb68d2020-07-11 23:53:21 +020024OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
25
26LIBBPF_SRC := $(srctree)/tools/lib/bpf/
27SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
28
Jiri Olsafc6b48f2021-02-05 13:40:17 +010029BPFOBJ := $(OUTPUT)/libbpf/libbpf.a
Quentin Monnet0b46b752021-09-08 14:32:26 -070030LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/
Jiri Olsafc6b48f2021-02-05 13:40:17 +010031SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a
Jiri Olsafbbb68d2020-07-11 23:53:21 +020032
Quentin Monnet14789942021-10-07 20:44:30 +010033LIBBPF_DESTDIR := $(LIBBPF_OUT)
34LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include
35
Jiri Olsafbbb68d2020-07-11 23:53:21 +020036BINARY := $(OUTPUT)/resolve_btfids
37BINARY_IN := $(BINARY)-in.o
38
39all: $(BINARY)
40
Quentin Monnet14789942021-10-07 20:44:30 +010041$(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT):
Jiri Olsafbbb68d2020-07-11 23:53:21 +020042 $(call msg,MKDIR,,$@)
Jiri Olsafc6b48f2021-02-05 13:40:17 +010043 $(Q)mkdir -p $(@)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020044
Jiri Olsafc6b48f2021-02-05 13:40:17 +010045$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
46 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020047
Quentin Monnet14789942021-10-07 20:44:30 +010048$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT)
49 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \
50 DESTDIR=$(LIBBPF_DESTDIR) prefix= \
51 $(abspath $@) install_headers
Jiri Olsafbbb68d2020-07-11 23:53:21 +020052
53CFLAGS := -g \
54 -I$(srctree)/tools/include \
55 -I$(srctree)/tools/include/uapi \
Quentin Monnet14789942021-10-07 20:44:30 +010056 -I$(LIBBPF_INCLUDE) \
Jiri Olsafbbb68d2020-07-11 23:53:21 +020057 -I$(SUBCMD_SRC)
58
59LIBS = -lelf -lz
60
61export srctree OUTPUT CFLAGS Q
62include $(srctree)/tools/build/Makefile.include
63
Quentin Monnet0b46b752021-09-08 14:32:26 -070064$(BINARY_IN): $(BPFOBJ) fixdep FORCE | $(OUTPUT)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020065 $(Q)$(MAKE) $(build)=resolve_btfids
66
67$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
68 $(call msg,LINK,$@)
69 $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
70
Jiri Olsaf2313092021-02-05 13:40:18 +010071clean_objects := $(wildcard $(OUTPUT)/*.o \
72 $(OUTPUT)/.*.o.cmd \
73 $(OUTPUT)/.*.o.d \
Quentin Monnet14789942021-10-07 20:44:30 +010074 $(LIBBPF_OUT) \
75 $(LIBBPF_DESTDIR) \
Jiri Olsaf2313092021-02-05 13:40:18 +010076 $(OUTPUT)/libsubcmd \
77 $(OUTPUT)/resolve_btfids)
78
79ifneq ($(clean_objects),)
Jiri Olsafc6b48f2021-02-05 13:40:17 +010080clean: fixdep-clean
Jiri Olsafbbb68d2020-07-11 23:53:21 +020081 $(call msg,CLEAN,$(BINARY))
Jiri Olsaf2313092021-02-05 13:40:18 +010082 $(Q)$(RM) -rf $(clean_objects)
83else
84clean:
85endif
Jiri Olsafbbb68d2020-07-11 23:53:21 +020086
87tags:
88 $(call msg,GEN,,tags)
89 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC)
90
91FORCE:
92
93.PHONY: all FORCE clean tags