78 lines · 2.4 KB · Makefile
RawDownload
# List of programs to buildhostprogs-y := sockmap # Libbpf dependenciesLIBBPF := ../../tools/lib/bpf/bpf.o ../../tools/lib/bpf/nlattr.o HOSTCFLAGS += -I$(objtree)/usr/includeHOSTCFLAGS += -I$(srctree)/tools/lib/HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/includeHOSTCFLAGS += -I$(srctree)/tools/perf sockmap-objs := ../bpf/bpf_load.o $(LIBBPF) sockmap_user.o # Tell kbuild to always build the programsalways := $(hostprogs-y)always += sockmap_kern.o HOSTLOADLIBES_sockmap += -lelf -lpthread # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:#  make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clangLLC ?= llcCLANG ?= clang # Trick to allow make to be run from this directoryall:	$(MAKE) -C ../../ $(CURDIR)/ clean:	$(MAKE) -C ../../ M=$(CURDIR) clean	@rm -f *~ $(obj)/syscall_nrs.s:	$(src)/syscall_nrs.c	$(call if_changed_dep,cc_s_c) $(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE	$(call filechk,offsets,__SYSCALL_NRS_H__) clean-files += syscall_nrs.h FORCE:  # Verify LLVM compiler tools are available and bpf target is supported by llc.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) verify_cmds: $(CLANG) $(LLC)	@for TOOL in $^ ; do \		if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \			echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\			exit 1; \		else true; fi; \	done verify_target_bpf: verify_cmds	@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \		echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\		echo "   NOTICE: LLVM version >= 3.7.1 required" ;\		exit 2; \	else true; fi $(src)/*.c: verify_target_bpf # asm/sysreg.h - inline assembly used by it is incompatible with llvm.# But, there is no easy way to fix it, so just exclude it since it is# useless for BPF samples.## -target bpf option required with SK_MSG programs, this is to ensure#  reading 'void *' data types for data and data_end are __u64 reads.$(obj)/%.o: $(src)/%.c	$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \		-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \		-Wno-compare-distinct-pointer-types \		-Wno-gnu-variable-sized-type-not-at-end \		-Wno-address-of-packed-member -Wno-tautological-compare \		-Wno-unknown-warning-option -O2 -target bpf \		-emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@