Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0-only |
| 2 | include ../../scripts/Makefile.include |
Jiri Olsa | dc3652d | 2020-09-23 20:57:35 +0200 | [diff] [blame] | 3 | include ../../scripts/Makefile.arch |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 4 | |
Jiri Olsa | 7962cb9 | 2021-02-05 13:40:19 +0100 | [diff] [blame] | 5 | srctree := $(abspath $(CURDIR)/../../../) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 6 | |
| 7 | ifeq ($(V),1) |
| 8 | Q = |
| 9 | msg = |
| 10 | else |
| 11 | Q = @ |
| 12 | msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; |
| 13 | MAKEFLAGS=--no-print-directory |
| 14 | endif |
| 15 | |
Jiri Olsa | 11bb2f7 | 2020-07-14 12:25:34 +0200 | [diff] [blame] | 16 | # always use the host compiler |
Jiri Olsa | 11bb2f7 | 2020-07-14 12:25:34 +0200 | [diff] [blame] | 17 | AR = $(HOSTAR) |
| 18 | CC = $(HOSTCC) |
| 19 | LD = $(HOSTLD) |
Jiri Olsa | dc3652d | 2020-09-23 20:57:35 +0200 | [diff] [blame] | 20 | ARCH = $(HOSTARCH) |
Jiri Olsa | 7962cb9 | 2021-02-05 13:40:19 +0100 | [diff] [blame] | 21 | RM ?= rm |
Jean-Philippe Brucker | bf1be90 | 2021-12-16 16:38:39 +0000 | [diff] [blame] | 22 | CROSS_COMPILE = |
Jiri Olsa | 11bb2f7 | 2020-07-14 12:25:34 +0200 | [diff] [blame] | 23 | |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 24 | OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ |
| 25 | |
| 26 | LIBBPF_SRC := $(srctree)/tools/lib/bpf/ |
| 27 | SUBCMD_SRC := $(srctree)/tools/lib/subcmd/ |
| 28 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 29 | BPFOBJ := $(OUTPUT)/libbpf/libbpf.a |
Quentin Monnet | 0b46b75 | 2021-09-08 14:32:26 -0700 | [diff] [blame] | 30 | LIBBPF_OUT := $(abspath $(dir $(BPFOBJ)))/ |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 31 | SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 32 | |
Quentin Monnet | 1478994 | 2021-10-07 20:44:30 +0100 | [diff] [blame] | 33 | LIBBPF_DESTDIR := $(LIBBPF_OUT) |
| 34 | LIBBPF_INCLUDE := $(LIBBPF_DESTDIR)include |
| 35 | |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 36 | BINARY := $(OUTPUT)/resolve_btfids |
| 37 | BINARY_IN := $(BINARY)-in.o |
| 38 | |
| 39 | all: $(BINARY) |
| 40 | |
Quentin Monnet | 1478994 | 2021-10-07 20:44:30 +0100 | [diff] [blame] | 41 | $(OUTPUT) $(OUTPUT)/libsubcmd $(LIBBPF_OUT): |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 42 | $(call msg,MKDIR,,$@) |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 43 | $(Q)mkdir -p $(@) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 44 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 45 | $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd |
| 46 | $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 47 | |
Quentin Monnet | 1478994 | 2021-10-07 20:44:30 +0100 | [diff] [blame] | 48 | $(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 Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 52 | |
| 53 | CFLAGS := -g \ |
| 54 | -I$(srctree)/tools/include \ |
| 55 | -I$(srctree)/tools/include/uapi \ |
Quentin Monnet | 1478994 | 2021-10-07 20:44:30 +0100 | [diff] [blame] | 56 | -I$(LIBBPF_INCLUDE) \ |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 57 | -I$(SUBCMD_SRC) |
| 58 | |
| 59 | LIBS = -lelf -lz |
| 60 | |
| 61 | export srctree OUTPUT CFLAGS Q |
| 62 | include $(srctree)/tools/build/Makefile.include |
| 63 | |
Quentin Monnet | 0b46b75 | 2021-09-08 14:32:26 -0700 | [diff] [blame] | 64 | $(BINARY_IN): $(BPFOBJ) fixdep FORCE | $(OUTPUT) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 65 | $(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 Olsa | f231309 | 2021-02-05 13:40:18 +0100 | [diff] [blame] | 71 | clean_objects := $(wildcard $(OUTPUT)/*.o \ |
| 72 | $(OUTPUT)/.*.o.cmd \ |
| 73 | $(OUTPUT)/.*.o.d \ |
Quentin Monnet | 1478994 | 2021-10-07 20:44:30 +0100 | [diff] [blame] | 74 | $(LIBBPF_OUT) \ |
| 75 | $(LIBBPF_DESTDIR) \ |
Jiri Olsa | f231309 | 2021-02-05 13:40:18 +0100 | [diff] [blame] | 76 | $(OUTPUT)/libsubcmd \ |
| 77 | $(OUTPUT)/resolve_btfids) |
| 78 | |
| 79 | ifneq ($(clean_objects),) |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 80 | clean: fixdep-clean |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 81 | $(call msg,CLEAN,$(BINARY)) |
Jiri Olsa | f231309 | 2021-02-05 13:40:18 +0100 | [diff] [blame] | 82 | $(Q)$(RM) -rf $(clean_objects) |
| 83 | else |
| 84 | clean: |
| 85 | endif |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 86 | |
| 87 | tags: |
| 88 | $(call msg,GEN,,tags) |
| 89 | $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC) |
| 90 | |
| 91 | FORCE: |
| 92 | |
| 93 | .PHONY: all FORCE clean tags |