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