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 | |
| 5 | ifeq ($(srctree),) |
| 6 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 7 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 8 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 9 | endif |
| 10 | |
| 11 | ifeq ($(V),1) |
| 12 | Q = |
| 13 | msg = |
| 14 | else |
| 15 | Q = @ |
| 16 | msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))"; |
| 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 | 11bb2f7 | 2020-07-14 12:25:34 +0200 | [diff] [blame] | 25 | |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 26 | OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/ |
| 27 | |
| 28 | LIBBPF_SRC := $(srctree)/tools/lib/bpf/ |
| 29 | SUBCMD_SRC := $(srctree)/tools/lib/subcmd/ |
| 30 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 31 | BPFOBJ := $(OUTPUT)/libbpf/libbpf.a |
| 32 | SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 33 | |
| 34 | BINARY := $(OUTPUT)/resolve_btfids |
| 35 | BINARY_IN := $(BINARY)-in.o |
| 36 | |
| 37 | all: $(BINARY) |
| 38 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 39 | $(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd: |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 40 | $(call msg,MKDIR,,$@) |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 41 | $(Q)mkdir -p $(@) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 42 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 43 | $(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd |
| 44 | $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 45 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 46 | $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 47 | $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@) |
| 48 | |
| 49 | CFLAGS := -g \ |
| 50 | -I$(srctree)/tools/include \ |
| 51 | -I$(srctree)/tools/include/uapi \ |
| 52 | -I$(LIBBPF_SRC) \ |
| 53 | -I$(SUBCMD_SRC) |
| 54 | |
| 55 | LIBS = -lelf -lz |
| 56 | |
| 57 | export srctree OUTPUT CFLAGS Q |
| 58 | include $(srctree)/tools/build/Makefile.include |
| 59 | |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 60 | $(BINARY_IN): fixdep FORCE | $(OUTPUT) |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 61 | $(Q)$(MAKE) $(build)=resolve_btfids |
| 62 | |
| 63 | $(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN) |
| 64 | $(call msg,LINK,$@) |
| 65 | $(Q)$(CC) $(BINARY_IN) $(LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS) |
| 66 | |
Jiri Olsa | f231309 | 2021-02-05 13:40:18 +0100 | [diff] [blame^] | 67 | clean_objects := $(wildcard $(OUTPUT)/*.o \ |
| 68 | $(OUTPUT)/.*.o.cmd \ |
| 69 | $(OUTPUT)/.*.o.d \ |
| 70 | $(OUTPUT)/libbpf \ |
| 71 | $(OUTPUT)/libsubcmd \ |
| 72 | $(OUTPUT)/resolve_btfids) |
| 73 | |
| 74 | ifneq ($(clean_objects),) |
Jiri Olsa | fc6b48f | 2021-02-05 13:40:17 +0100 | [diff] [blame] | 75 | clean: fixdep-clean |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 76 | $(call msg,CLEAN,$(BINARY)) |
Jiri Olsa | f231309 | 2021-02-05 13:40:18 +0100 | [diff] [blame^] | 77 | $(Q)$(RM) -rf $(clean_objects) |
| 78 | else |
| 79 | clean: |
| 80 | endif |
Jiri Olsa | fbbb68d | 2020-07-11 23:53:21 +0200 | [diff] [blame] | 81 | |
| 82 | tags: |
| 83 | $(call msg,GEN,,tags) |
| 84 | $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC) |
| 85 | |
| 86 | FORCE: |
| 87 | |
| 88 | .PHONY: all FORCE clean tags |