@@ -19,24 +19,37 @@ BPF_DIR = $(srctree)/tools/lib/bpf/
1919ifneq ($(OUTPUT ) ,)
2020 LIBBPF_OUTPUT = $(OUTPUT ) /libbpf/
2121 LIBBPF_PATH = $(LIBBPF_OUTPUT )
22+ BOOTSTRAP_OUTPUT = $(OUTPUT ) /bootstrap/
2223else
24+ LIBBPF_OUTPUT =
2325 LIBBPF_PATH = $(BPF_DIR )
26+ BOOTSTRAP_OUTPUT = $(CURDIR ) /bootstrap/
2427endif
2528
2629LIBBPF = $(LIBBPF_PATH ) libbpf.a
30+ LIBBPF_BOOTSTRAP_OUTPUT = $(BOOTSTRAP_OUTPUT ) libbpf/
31+ LIBBPF_BOOTSTRAP = $(LIBBPF_BOOTSTRAP_OUTPUT ) libbpf.a
2732
2833BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
2934
30- $(LIBBPF_OUTPUT ) :
35+ $(LIBBPF_OUTPUT ) $( BOOTSTRAP_OUTPUT ) $( LIBBPF_BOOTSTRAP_OUTPUT ) :
3136 $(QUIET_MKDIR ) mkdir -p $@
3237
3338$(LIBBPF ) : FORCE | $(LIBBPF_OUTPUT )
3439 $(Q )$(MAKE ) -C $(BPF_DIR ) OUTPUT=$(LIBBPF_OUTPUT ) $(LIBBPF_OUTPUT ) libbpf.a
3540
41+ $(LIBBPF_BOOTSTRAP ) : FORCE | $(LIBBPF_BOOTSTRAP_OUTPUT )
42+ $(Q )$(MAKE ) -C $(BPF_DIR ) OUTPUT=$(LIBBPF_BOOTSTRAP_OUTPUT ) \
43+ ARCH= CC=$(HOSTCC ) LD=$(HOSTLD ) $@
44+
3645$(LIBBPF ) -clean : $(LIBBPF_OUTPUT )
3746 $(call QUIET_CLEAN, libbpf)
3847 $(Q )$(MAKE ) -C $(BPF_DIR ) OUTPUT=$(LIBBPF_OUTPUT ) clean > /dev/null
3948
49+ $(LIBBPF_BOOTSTRAP ) -clean : $(LIBBPF_BOOTSTRAP_OUTPUT )
50+ $(call QUIET_CLEAN, libbpf-bootstrap)
51+ $(Q )$(MAKE ) -C $(BPF_DIR ) OUTPUT=$(LIBBPF_BOOTSTRAP_OUTPUT ) clean > /dev/null
52+
4053prefix ?= /usr/local
4154bash_compdir ?= /usr/share/bash-completion/completions
4255
@@ -94,6 +107,7 @@ CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
94107endif
95108
96109LIBS = $(LIBBPF ) -lelf -lz
110+ LIBS_BOOTSTRAP = $(LIBBPF_BOOTSTRAP ) -lelf -lz
97111ifeq ($(feature-libcap ) , 1)
98112CFLAGS += -DUSE_LIBCAP
99113LIBS += -lcap
@@ -120,9 +134,9 @@ CFLAGS += -DHAVE_LIBBFD_SUPPORT
120134SRCS += $(BFD_SRCS )
121135endif
122136
123- BPFTOOL_BOOTSTRAP := $(if $( OUTPUT ) , $( OUTPUT ) bpftool-bootstrap,./bpftool-bootstrap)
137+ BPFTOOL_BOOTSTRAP := $(BOOTSTRAP_OUTPUT ) bpftool
124138
125- BOOTSTRAP_OBJS = $(addprefix $(OUTPUT ) ,main.o common.o json_writer.o gen.o btf.o)
139+ BOOTSTRAP_OBJS = $(addprefix $(BOOTSTRAP_OUTPUT ) ,main.o common.o json_writer.o gen.o btf.o)
126140OBJS = $(patsubst % .c,$(OUTPUT ) % .o,$(SRCS ) ) $(OUTPUT ) disasm.o
127141
128142VMLINUX_BTF_PATHS ?= $(if $(O ) ,$(O ) /vmlinux) \
@@ -169,24 +183,28 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
169183
170184$(OUTPUT ) feature.o : | zdep
171185
172- $(BPFTOOL_BOOTSTRAP ) : $(BOOTSTRAP_OBJS ) $(LIBBPF )
173- $(QUIET_LINK )$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $(BOOTSTRAP_OBJS ) $(LIBS )
186+ $(BPFTOOL_BOOTSTRAP ) : $(BOOTSTRAP_OBJS ) $(LIBBPF_BOOTSTRAP )
187+ $(QUIET_LINK )$(HOSTCC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $(BOOTSTRAP_OBJS ) \
188+ $(LIBS_BOOTSTRAP )
174189
175190$(OUTPUT ) bpftool : $(OBJS ) $(LIBBPF )
176191 $(QUIET_LINK )$(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $(OBJS ) $(LIBS )
177192
193+ $(BOOTSTRAP_OUTPUT ) % .o : % .c | $(BOOTSTRAP_OUTPUT )
194+ $(QUIET_CC )$(HOSTCC ) $(CFLAGS ) -c -MMD -o $@ $<
195+
178196$(OUTPUT ) % .o : % .c
179197 $(QUIET_CC )$(CC ) $(CFLAGS ) -c -MMD -o $@ $<
180198
181199feature-detect-clean :
182200 $(call QUIET_CLEAN, feature-detect)
183201 $(Q )$(MAKE ) -C $(srctree ) /tools/build/feature/ clean > /dev/null
184202
185- clean : $(LIBBPF ) -clean feature-detect-clean
203+ clean : $(LIBBPF ) -clean $( LIBBPF_BOOTSTRAP ) -clean feature-detect-clean
186204 $(call QUIET_CLEAN, bpftool)
187205 $(Q )$(RM ) -- $(OUTPUT ) bpftool $(OUTPUT ) * .o $(OUTPUT ) * .d
188- $(Q )$(RM ) -- $(BPFTOOL_BOOTSTRAP ) $( OUTPUT )* .skel.h $(OUTPUT ) vmlinux.h
189- $(Q )$(RM ) -r -- $(OUTPUT ) libbpf/
206+ $(Q )$(RM ) -- $(OUTPUT ) * .skel.h $(OUTPUT ) vmlinux.h
207+ $(Q )$(RM ) -r -- $(LIBBPF_OUTPUT ) $( BOOTSTRAP_OUTPUT )
190208 $(call QUIET_CLEAN, core-gen)
191209 $(Q )$(RM ) -- $(OUTPUT ) FEATURE-DUMP.bpftool
192210 $(Q )$(RM ) -r -- $(OUTPUT ) feature/
0 commit comments