1*3f584c21SJakub Kicinski# SPDX-License-Identifier: GPL-2.0 2*3f584c21SJakub Kicinski# Rules to generate bpf objs 3*3f584c21SJakub KicinskiCLANG ?= clang 4*3f584c21SJakub KicinskiSCRATCH_DIR := $(OUTPUT)/tools 5*3f584c21SJakub KicinskiBUILD_DIR := $(SCRATCH_DIR)/build 6*3f584c21SJakub KicinskiBPFDIR := $(top_srcdir)/tools/lib/bpf 7*3f584c21SJakub KicinskiAPIDIR := $(top_srcdir)/tools/include/uapi 8*3f584c21SJakub Kicinski 9*3f584c21SJakub KicinskiCCINCLUDE += -I$(selfdir)/bpf 10*3f584c21SJakub KicinskiCCINCLUDE += -I$(top_srcdir)/usr/include/ 11*3f584c21SJakub KicinskiCCINCLUDE += -I$(SCRATCH_DIR)/include 12*3f584c21SJakub Kicinski 13*3f584c21SJakub KicinskiBPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a 14*3f584c21SJakub Kicinski 15*3f584c21SJakub KicinskiMAKE_DIRS := $(BUILD_DIR)/libbpf 16*3f584c21SJakub Kicinski$(MAKE_DIRS): 17*3f584c21SJakub Kicinski $(call msg,MKDIR,,$@) 18*3f584c21SJakub Kicinski $(Q)mkdir -p $@ 19*3f584c21SJakub Kicinski 20*3f584c21SJakub Kicinski# Get Clang's default includes on this system, as opposed to those seen by 21*3f584c21SJakub Kicinski# '--target=bpf'. This fixes "missing" files on some architectures/distros, 22*3f584c21SJakub Kicinski# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. 23*3f584c21SJakub Kicinski# 24*3f584c21SJakub Kicinski# Use '-idirafter': Don't interfere with include mechanics except where the 25*3f584c21SJakub Kicinski# build would have failed anyways. 26*3f584c21SJakub Kicinskidefine get_sys_includes 27*3f584c21SJakub Kicinski$(shell $(1) $(2) -v -E - </dev/null 2>&1 \ 28*3f584c21SJakub Kicinski | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ 29*3f584c21SJakub Kicinski$(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}') 30*3f584c21SJakub Kicinskiendef 31*3f584c21SJakub Kicinski 32*3f584c21SJakub Kicinskiifneq ($(CROSS_COMPILE),) 33*3f584c21SJakub KicinskiCLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%)) 34*3f584c21SJakub Kicinskiendif 35*3f584c21SJakub Kicinski 36*3f584c21SJakub KicinskiCLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH)) 37*3f584c21SJakub Kicinski 38*3f584c21SJakub KicinskiBPF_PROG_OBJS := $(patsubst %.c,$(OUTPUT)/%.o,$(wildcard *.bpf.c)) 39*3f584c21SJakub Kicinski 40*3f584c21SJakub Kicinski$(BPF_PROG_OBJS): $(OUTPUT)/%.o : %.c $(BPFOBJ) | $(MAKE_DIRS) 41*3f584c21SJakub Kicinski $(call msg,BPF_PROG,,$@) 42*3f584c21SJakub Kicinski $(Q)$(CLANG) -O2 -g --target=bpf $(CCINCLUDE) $(CLANG_SYS_INCLUDES) \ 43*3f584c21SJakub Kicinski -c $< -o $@ 44*3f584c21SJakub Kicinski 45*3f584c21SJakub Kicinski$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ 46*3f584c21SJakub Kicinski $(APIDIR)/linux/bpf.h \ 47*3f584c21SJakub Kicinski | $(BUILD_DIR)/libbpf 48*3f584c21SJakub Kicinski $(call msg,MAKE,,$@) 49*3f584c21SJakub Kicinski $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ 50*3f584c21SJakub Kicinski EXTRA_CFLAGS='-g -O0' \ 51*3f584c21SJakub Kicinski DESTDIR=$(SCRATCH_DIR) prefix= all install_headers 52*3f584c21SJakub Kicinski 53*3f584c21SJakub KicinskiEXTRA_CLEAN += $(SCRATCH_DIR) 54