diff mbox

[v1] samples/bpf: Add a .gitignore for binaries

Message ID 20170517081844.GA4447@gmail.com
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

Alexander Alemayhu May 17, 2017, 8:18 a.m. UTC
On Tue, May 16, 2017 at 04:27:36PM -0700, David Ahern wrote:
> 
> The problem stems from the fact that bpf samples do not really fall into
> the 'hostprogs' category (see "4 Host Program support" in
> Documentation/kbuild/makefiles.txt). Fixing samples/bpf to not rely on
> it is the better long term solution. Building of tools/ for example does
> not rely on it so there is an existing example of leveraging kernel
> headers without the overhead.
+1

I have looked into this but found it to be not easy and all attempts to
change the Makefile has resulted in obscure errors :/

Getting clang to output in a different directory was easy[0], but I guess
this is not the right approach either. Have you tried making the change?


[0]:

Comments

David Ahern May 18, 2017, 8:03 p.m. UTC | #1
On 5/17/17 1:18 AM, Alexander Alemayhu wrote:
> I have looked into this but found it to be not easy and all attempts to
> change the Makefile has resulted in obscure errors :/
> 
> Getting clang to output in a different directory was easy[0], but I guess
> this is not the right approach either. Have you tried making the change?

spent an hour so a few weeks back. It is not trivial, but someone needs
to find to fix it now.

perf is the example to use: you can build it from both top level kernel
directory (e.g, make -C tools/perf O=/tmp/perf) and the perf directory
(cd tools/perf; make O=/tmp/perf). Both are wanted for samples/bpf and
it would be nice to keep the O= option as well.

I don't have the time for the next few weeks. Perhaps mid-June I can
take a look.
diff mbox

Patch

diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile
index 6c7468eb3684..79268d310ba5 100644
--- a/samples/bpf/Makefile
+++ b/samples/bpf/Makefile
@@ -1,6 +1,13 @@ 
 # kbuild trick to avoid linker error. Can be omitted if a module is built.
 obj- := dummy.o
 
+ifndef O
+  OUTPUT := $(shell pwd)/samples/bpf/_build/
+else
+  OUTPUT := $O/
+endif
+$(shell mkdir -p $(OUTPUT))
+
 # List of programs to build
 hostprogs-y := test_lru_dist
 hostprogs-y += sock_example
@@ -190,4 +197,4 @@  $(obj)/%.o: $(src)/%.c
 		-Wno-gnu-variable-sized-type-not-at-end \
 		-Wno-address-of-packed-member -Wno-tautological-compare \
 		-Wno-unknown-warning-option \
-		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
+		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $(OUTPUT)$(shell basename $@)