diff options
author | Jesper Dangaard Brouer <brouer@redhat.com> | 2016-04-28 08:21:14 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-04-29 14:26:08 -0400 |
commit | bdefbbf2ecff6efcd253767179a60961aebed9dc (patch) | |
tree | 101cead89daccb56ee9bcf050e9a6537406e17ce /samples | |
parent | b62a796c109ca0be3e49de620a8ea8248412446d (diff) |
samples/bpf: like LLC also verify and allow redefining CLANG command
Users are likely to manually compile both LLVM 'llc' and 'clang'
tools. Thus, also allow redefining CLANG and verify command exist.
Makefile implementation wise, the target that verify the command have
been generalized.
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>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/bpf/Makefile | 25 | ||||
-rw-r--r-- | samples/bpf/README.rst | 6 |
2 files changed, 17 insertions, 14 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index dd63521832d8..66897e61232c 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile | |||
@@ -81,9 +81,10 @@ HOSTLOADLIBES_spintest += -lelf | |||
81 | HOSTLOADLIBES_map_perf_test += -lelf -lrt | 81 | HOSTLOADLIBES_map_perf_test += -lelf -lrt |
82 | HOSTLOADLIBES_test_overhead += -lelf -lrt | 82 | HOSTLOADLIBES_test_overhead += -lelf -lrt |
83 | 83 | ||
84 | # Allows pointing LLC to a LLVM backend with bpf support, redefine on cmdline: | 84 | # Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline: |
85 | # make samples/bpf/ LLC=~/git/llvm/build/bin/llc | 85 | # make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang |
86 | LLC ?= llc | 86 | LLC ?= llc |
87 | CLANG ?= clang | ||
87 | 88 | ||
88 | # Trick to allow make to be run from this directory | 89 | # Trick to allow make to be run from this directory |
89 | all: | 90 | all: |
@@ -93,16 +94,18 @@ clean: | |||
93 | $(MAKE) -C ../../ M=$$PWD clean | 94 | $(MAKE) -C ../../ M=$$PWD clean |
94 | @rm -f *~ | 95 | @rm -f *~ |
95 | 96 | ||
96 | # Verify LLVM compiler is available and bpf target is supported | 97 | # Verify LLVM compiler tools are available and bpf target is supported by llc |
97 | .PHONY: verify_cmd_llc verify_target_bpf | 98 | .PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC) |
98 | 99 | ||
99 | verify_cmd_llc: | 100 | verify_cmds: $(CLANG) $(LLC) |
100 | @if ! (which "${LLC}" > /dev/null 2>&1); then \ | 101 | @for TOOL in $^ ; do \ |
101 | echo "*** ERROR: Cannot find LLVM tool 'llc' (${LLC})" ;\ | 102 | if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \ |
102 | exit 1; \ | 103 | echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\ |
103 | else true; fi | 104 | exit 1; \ |
105 | else true; fi; \ | ||
106 | done | ||
104 | 107 | ||
105 | verify_target_bpf: verify_cmd_llc | 108 | verify_target_bpf: verify_cmds |
106 | @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \ | 109 | @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \ |
107 | echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\ | 110 | echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\ |
108 | echo " NOTICE: LLVM version >= 3.7.1 required" ;\ | 111 | echo " NOTICE: LLVM version >= 3.7.1 required" ;\ |
@@ -115,6 +118,6 @@ $(src)/*.c: verify_target_bpf | |||
115 | # But, there is no easy way to fix it, so just exclude it since it is | 118 | # But, there is no easy way to fix it, so just exclude it since it is |
116 | # useless for BPF samples. | 119 | # useless for BPF samples. |
117 | $(obj)/%.o: $(src)/%.c | 120 | $(obj)/%.o: $(src)/%.c |
118 | clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \ | 121 | $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \ |
119 | -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ | 122 | -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ |
120 | -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@ | 123 | -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@ |
diff --git a/samples/bpf/README.rst b/samples/bpf/README.rst index e36687d900c8..a43eae3f0551 100644 --- a/samples/bpf/README.rst +++ b/samples/bpf/README.rst | |||
@@ -60,7 +60,7 @@ Quick sniplet for manually compiling LLVM and clang | |||
60 | $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86" | 60 | $ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86" |
61 | $ make -j $(getconf _NPROCESSORS_ONLN) | 61 | $ make -j $(getconf _NPROCESSORS_ONLN) |
62 | 62 | ||
63 | It is also possible to point make to the newly compiled 'llc' command | 63 | It is also possible to point make to the newly compiled 'llc' or |
64 | via redefining LLC on the make command line:: | 64 | 'clang' command via redefining LLC or CLANG on the make command line:: |
65 | 65 | ||
66 | make samples/bpf/ LLC=~/git/llvm/build/bin/llc | 66 | make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang |