xref: /openbmc/linux/samples/bpf/Makefile (revision 65ee8aeb)
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
12hostprogs-y += tracex4
13
14test_verifier-objs := test_verifier.o libbpf.o
15test_maps-objs := test_maps.o libbpf.o
16sock_example-objs := sock_example.o libbpf.o
17sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
18sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
19tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
20tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
21tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
22tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
23
24# Tell kbuild to always build the programs
25always := $(hostprogs-y)
26always += sockex1_kern.o
27always += sockex2_kern.o
28always += tracex1_kern.o
29always += tracex2_kern.o
30always += tracex3_kern.o
31always += tracex4_kern.o
32always += tcbpf1_kern.o
33
34HOSTCFLAGS += -I$(objtree)/usr/include
35
36HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
37HOSTLOADLIBES_sockex1 += -lelf
38HOSTLOADLIBES_sockex2 += -lelf
39HOSTLOADLIBES_tracex1 += -lelf
40HOSTLOADLIBES_tracex2 += -lelf
41HOSTLOADLIBES_tracex3 += -lelf
42HOSTLOADLIBES_tracex4 += -lelf -lrt
43
44# point this to your LLVM backend with bpf support
45LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
46
47%.o: %.c
48	clang $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
49		-D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
50		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
51