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