xref: /openbmc/linux/samples/bpf/Makefile (revision 5c7fc2d2)
1# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
5hostprogs-y := test_verifier test_maps
6hostprogs-y += sock_example
7hostprogs-y += sockex1
8hostprogs-y += sockex2
9hostprogs-y += tracex1
10hostprogs-y += tracex2
11hostprogs-y += tracex3
12
13test_verifier-objs := test_verifier.o libbpf.o
14test_maps-objs := test_maps.o libbpf.o
15sock_example-objs := sock_example.o libbpf.o
16sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
17sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
18tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
19tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
20tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
21
22# Tell kbuild to always build the programs
23always := $(hostprogs-y)
24always += sockex1_kern.o
25always += sockex2_kern.o
26always += tracex1_kern.o
27always += tracex2_kern.o
28always += tracex3_kern.o
29
30HOSTCFLAGS += -I$(objtree)/usr/include
31
32HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
33HOSTLOADLIBES_sockex1 += -lelf
34HOSTLOADLIBES_sockex2 += -lelf
35HOSTLOADLIBES_tracex1 += -lelf
36HOSTLOADLIBES_tracex2 += -lelf
37HOSTLOADLIBES_tracex3 += -lelf
38
39# point this to your LLVM backend with bpf support
40LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
41
42%.o: %.c
43	clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
44		-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
45		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
46