blob: 320a88ac28c996402fc5c609ec7ac1c2b2ca2314 [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 = @
Nathan Chancellor7f3bdbc2022-02-01 14:25:04 -070012 ifeq ($(silent),1)
13 msg =
14 else
15 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
16 endif
Jiri Olsafbbb68d2020-07-11 23:53:21 +020017 MAKEFLAGS=--no-print-directory
18endif
19
Jiri Olsa11bb2f72020-07-14 12:25:34 +020020# always use the host compiler
Jiri Olsa11bb2f72020-07-14 12:25:34 +020021AR = $(HOSTAR)
22CC = $(HOSTCC)
23LD = $(HOSTLD)
Jiri Olsadc3652d2020-09-23 20:57:35 +020024ARCH = $(HOSTARCH)
Jiri Olsa7962cb92021-02-05 13:40:19 +010025RM ?= rm
Jean-Philippe Bruckerbf1be902021-12-16 16:38:39 +000026CROSS_COMPILE =
Jiri Olsa11bb2f72020-07-14 12:25:34 +020027
Jiri Olsafbbb68d2020-07-11 23:53:21 +020028OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
29
30LIBBPF_SRC := $(srctree)/tools/lib/bpf/
31SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
32
Jiri Olsafc6b48f2021-02-05 13:40:17 +010033BPFOBJ := $(OUTPUT)/libbpf/libbpf.a
Quentin Monnet0b46b752021-09-08 14:32:26 -070034LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/
Jiri Olsafc6b48f2021-02-05 13:40:17 +010035SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a
Jiri Olsafbbb68d2020-07-11 23:53:21 +020036
Quentin Monnet14789942021-10-07 20:44:30 +010037LIBBPF_DESTDIR := $(LIBBPF_OUT)
38LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include
39
Jiri Olsafbbb68d2020-07-11 23:53:21 +020040BINARY := $(OUTPUT)/resolve_btfids
41BINARY_IN := $(BINARY)-in.o
42
43all: $(BINARY)
44
Quentin Monnet14789942021-10-07 20:44:30 +010045$(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT):
Jiri Olsafbbb68d2020-07-11 23:53:21 +020046 $(call msg,MKDIR,,$@)
Jiri Olsafc6b48f2021-02-05 13:40:17 +010047 $(Q)mkdir -p $(@)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020048
Jiri Olsafc6b48f2021-02-05 13:40:17 +010049$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
50 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020051
Quentin Monnet14789942021-10-07 20:44:30 +010052$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OUT)
53 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(LIBBPF_OUT) \
54 DESTDIR=$(LIBBPF_DESTDIR) prefix= \
55 $(abspath $@) install_headers
Jiri Olsafbbb68d2020-07-11 23:53:21 +020056
57CFLAGS := -g \
58 -I$(srctree)/tools/include \
59 -I$(srctree)/tools/include/uapi \
Quentin Monnet14789942021-10-07 20:44:30 +010060 -I$(LIBBPF_INCLUDE) \
Jiri Olsafbbb68d2020-07-11 23:53:21 +020061 -I$(SUBCMD_SRC)
62
63LIBS = -lelf -lz
64
65export srctree OUTPUT CFLAGS Q
66include $(srctree)/tools/build/Makefile.include
67
Quentin Monnet0b46b752021-09-08 14:32:26 -070068$(BINARY_IN): $(BPFOBJ) fixdep FORCE | $(OUTPUT)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020069 $(Q)$(MAKE) $(build)=resolve_btfids
70
71$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
72 $(call msg,LINK,$@)
73 $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
74
Jiri Olsaf2313092021-02-05 13:40:18 +010075clean_objects := $(wildcard $(OUTPUT)/*.o \
76 $(OUTPUT)/.*.o.cmd \
77 $(OUTPUT)/.*.o.d \
Quentin Monnet14789942021-10-07 20:44:30 +010078 $(LIBBPF_OUT) \
79 $(LIBBPF_DESTDIR) \
Jiri Olsaf2313092021-02-05 13:40:18 +010080 $(OUTPUT)/libsubcmd \
81 $(OUTPUT)/resolve_btfids)
82
83ifneq ($(clean_objects),)
Jiri Olsafc6b48f2021-02-05 13:40:17 +010084clean: fixdep-clean
Jiri Olsafbbb68d2020-07-11 23:53:21 +020085 $(call msg,CLEAN,$(BINARY))
Jiri Olsaf2313092021-02-05 13:40:18 +010086 $(Q)$(RM) -rf $(clean_objects)
87else
88clean:
89endif
Jiri Olsafbbb68d2020-07-11 23:53:21 +020090
91tags:
92 $(call msg,GEN,,tags)
93 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC)
94
95FORCE:
96
97.PHONY: all FORCE clean tags