blob: be09ec4f03fffdbc008933125001718d9cf5f817 [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
5ifeq ($(srctree),)
6srctree := $(patsubst %/,%,$(dir $(CURDIR)))
7srctree := $(patsubst %/,%,$(dir $(srctree)))
8srctree := $(patsubst %/,%,$(dir $(srctree)))
9endif
10
11ifeq ($(V),1)
12 Q =
13 msg =
14else
15 Q = @
16 msg = @printf ' %-8s %s%s\n' "$(1)" "$(notdir $(2))" "$(if $(3), $(3))";
17 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 Olsa11bb2f72020-07-14 12:25:34 +020025
Jiri Olsafbbb68d2020-07-11 23:53:21 +020026OUTPUT ?= $(srctree)/tools/bpf/resolve_btfids/
27
28LIBBPF_SRC := $(srctree)/tools/lib/bpf/
29SUBCMD_SRC := $(srctree)/tools/lib/subcmd/
30
Jiri Olsafc6b48f2021-02-05 13:40:17 +010031BPFOBJ := $(OUTPUT)/libbpf/libbpf.a
32SUBCMDOBJ := $(OUTPUT)/libsubcmd/libsubcmd.a
Jiri Olsafbbb68d2020-07-11 23:53:21 +020033
34BINARY := $(OUTPUT)/resolve_btfids
35BINARY_IN := $(BINARY)-in.o
36
37all: $(BINARY)
38
Jiri Olsafc6b48f2021-02-05 13:40:17 +010039$(OUTPUT) $(OUTPUT)/libbpf $(OUTPUT)/libsubcmd:
Jiri Olsafbbb68d2020-07-11 23:53:21 +020040 $(call msg,MKDIR,,$@)
Jiri Olsafc6b48f2021-02-05 13:40:17 +010041 $(Q)mkdir -p $(@)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020042
Jiri Olsafc6b48f2021-02-05 13:40:17 +010043$(SUBCMDOBJ): fixdep FORCE | $(OUTPUT)/libsubcmd
44 $(Q)$(MAKE) -C $(SUBCMD_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020045
Jiri Olsafc6b48f2021-02-05 13:40:17 +010046$(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf
Jiri Olsafbbb68d2020-07-11 23:53:21 +020047 $(Q)$(MAKE) $(submake_extras) -C $(LIBBPF_SRC) OUTPUT=$(abspath $(dir $@))/ $(abspath $@)
48
49CFLAGS := -g \
50 -I$(srctree)/tools/include \
51 -I$(srctree)/tools/include/uapi \
52 -I$(LIBBPF_SRC) \
53 -I$(SUBCMD_SRC)
54
55LIBS = -lelf -lz
56
57export srctree OUTPUT CFLAGS Q
58include $(srctree)/tools/build/Makefile.include
59
Jiri Olsafc6b48f2021-02-05 13:40:17 +010060$(BINARY_IN): fixdep FORCE | $(OUTPUT)
Jiri Olsafbbb68d2020-07-11 23:53:21 +020061 $(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 Olsaf2313092021-02-05 13:40:18 +010067clean_objects := $(wildcard $(OUTPUT)/*.o \
68 $(OUTPUT)/.*.o.cmd \
69 $(OUTPUT)/.*.o.d \
70 $(OUTPUT)/libbpf \
71 $(OUTPUT)/libsubcmd \
72 $(OUTPUT)/resolve_btfids)
73
74ifneq ($(clean_objects),)
Jiri Olsafc6b48f2021-02-05 13:40:17 +010075clean: fixdep-clean
Jiri Olsafbbb68d2020-07-11 23:53:21 +020076 $(call msg,CLEAN,$(BINARY))
Jiri Olsaf2313092021-02-05 13:40:18 +010077 $(Q)$(RM) -rf $(clean_objects)
78else
79clean:
80endif
Jiri Olsafbbb68d2020-07-11 23:53:21 +020081
82tags:
83 $(call msg,GEN,,tags)
84 $(Q)ctags -R . $(LIBBPF_SRC) $(SUBCMD_SRC)
85
86FORCE:
87
88.PHONY: all FORCE clean tags