John Fastabend | 69e8cc1 | 2017-08-15 22:33:32 -0700 | [diff] [blame] | 1 | # kbuild trick to avoid linker error. Can be omitted if a module is built. |
| 2 | obj- := dummy.o |
| 3 | |
| 4 | # List of programs to build |
| 5 | hostprogs-y := sockmap |
| 6 | |
| 7 | # Libbpf dependencies |
| 8 | LIBBPF := ../../tools/lib/bpf/bpf.o |
| 9 | |
| 10 | HOSTCFLAGS += -I$(objtree)/usr/include |
| 11 | HOSTCFLAGS += -I$(srctree)/tools/lib/ |
| 12 | HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/ |
| 13 | HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include |
| 14 | HOSTCFLAGS += -I$(srctree)/tools/perf |
| 15 | |
| 16 | sockmap-objs := ../bpf/bpf_load.o $(LIBBPF) sockmap_user.o |
| 17 | |
| 18 | # Tell kbuild to always build the programs |
| 19 | always := $(hostprogs-y) |
| 20 | always += sockmap_kern.o |
| 21 | |
| 22 | HOSTLOADLIBES_sockmap += -lelf -lpthread |
| 23 | |
| 24 | # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: |
| 25 | # make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang |
| 26 | LLC ?= llc |
| 27 | CLANG ?= clang |
| 28 | |
| 29 | # Trick to allow make to be run from this directory |
| 30 | all: |
| 31 | $(MAKE) -C ../../ $(CURDIR)/ |
| 32 | |
| 33 | clean: |
| 34 | $(MAKE) -C ../../ M=$(CURDIR) clean |
| 35 | @rm -f *~ |
| 36 | |
| 37 | $(obj)/syscall_nrs.s: $(src)/syscall_nrs.c |
| 38 | $(call if_changed_dep,cc_s_c) |
| 39 | |
| 40 | $(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE |
| 41 | $(call filechk,offsets,__SYSCALL_NRS_H__) |
| 42 | |
| 43 | clean-files += syscall_nrs.h |
| 44 | |
| 45 | FORCE: |
| 46 | |
| 47 | |
| 48 | # Verify LLVM compiler tools are available and bpf target is supported by llc |
| 49 | .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) |
| 50 | |
| 51 | verify_cmds: $(CLANG) $(LLC) |
| 52 | @for TOOL in $^ ; do \ |
| 53 | if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \ |
| 54 | echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\ |
| 55 | exit 1; \ |
| 56 | else true; fi; \ |
| 57 | done |
| 58 | |
| 59 | verify_target_bpf: verify_cmds |
| 60 | @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \ |
| 61 | echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\ |
| 62 | echo " NOTICE: LLVM version >= 3.7.1 required" ;\ |
| 63 | exit 2; \ |
| 64 | else true; fi |
| 65 | |
| 66 | $(src)/*.c: verify_target_bpf |
| 67 | |
| 68 | # asm/sysreg.h - inline assembly used by it is incompatible with llvm. |
| 69 | # But, there is no easy way to fix it, so just exclude it since it is |
| 70 | # useless for BPF samples. |
| 71 | $(obj)/%.o: $(src)/%.c |
| 72 | $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \ |
| 73 | -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ |
| 74 | -Wno-compare-distinct-pointer-types \ |
| 75 | -Wno-gnu-variable-sized-type-not-at-end \ |
| 76 | -Wno-address-of-packed-member -Wno-tautological-compare \ |
| 77 | -Wno-unknown-warning-option \ |
| 78 | -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@ |