samples/bpf: Makefile verify LLVM compiler avail and bpf target is supported
authorJesper Dangaard Brouer <brouer@redhat.com>
Thu, 28 Apr 2016 12:20:58 +0000 (14:20 +0200)
committerDavid S. Miller <davem@davemloft.net>
Fri, 29 Apr 2016 18:25:32 +0000 (14:25 -0400)
Make compiling samples/bpf more user friendly, by detecting if LLVM
compiler tool 'llc' is available, and also detect if the 'bpf' target
is available in this version of LLVM.

Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
samples/bpf/Makefile

index 5bae9536f100e3e8ff3984b168b0bff4e32d6916..45859c99f573b6fe1adb450714dba7a2098735d2 100644 (file)
@@ -85,6 +85,24 @@ HOSTLOADLIBES_test_overhead += -lelf -lrt
 #  make samples/bpf/ LLC=~/git/llvm/build/bin/llc
 LLC ?= llc
 
+# Verify LLVM compiler is available and bpf target is supported
+.PHONY: verify_cmd_llc verify_target_bpf
+
+verify_cmd_llc:
+       @if ! (which "${LLC}" > /dev/null 2>&1); then \
+               echo "*** ERROR: Cannot find LLVM tool 'llc' (${LLC})" ;\
+               exit 1; \
+       else true; fi
+
+verify_target_bpf: verify_cmd_llc
+       @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.