]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - samples/bpf/Makefile
samples/bpf: Remove perf_event_open() declaration
[mirror_ubuntu-focal-kernel.git] / samples / bpf / Makefile
CommitLineData
3c731eba
AS
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
5db58faf 5hostprogs-y := test_lru_dist
03f4723e 6hostprogs-y += sock_example
42984d7c 7hostprogs-y += fds_example
a8085782 8hostprogs-y += sockex1
fbe33108 9hostprogs-y += sockex2
530b2c86 10hostprogs-y += sockex3
b896c4f9 11hostprogs-y += tracex1
d822a192 12hostprogs-y += tracex2
5c7fc2d2 13hostprogs-y += tracex3
9811e353 14hostprogs-y += tracex4
5bacd780 15hostprogs-y += tracex5
47efb302 16hostprogs-y += tracex6
cf9b1199 17hostprogs-y += test_probe_write_user
39111695 18hostprogs-y += trace_output
0fb1170e 19hostprogs-y += lathist
a6ffe7b9 20hostprogs-y += offwaketime
9d8b612d 21hostprogs-y += spintest
26e90931 22hostprogs-y += map_perf_test
e3edfdec 23hostprogs-y += test_overhead
a3f74617 24hostprogs-y += test_cgrp2_array_pin
d8c5b17f 25hostprogs-y += test_cgrp2_attach
9b474ece 26hostprogs-y += test_cgrp2_attach2
ad2805dc 27hostprogs-y += test_cgrp2_sock
554ae6e7 28hostprogs-y += test_cgrp2_sock2
86af8b41 29hostprogs-y += xdp1
764cbcce 30hostprogs-y += xdp2
9e6e60ec 31hostprogs-y += test_current_task_under_cgroup
1c47910e 32hostprogs-y += trace_event
72874418 33hostprogs-y += sampleip
90e02896 34hostprogs-y += tc_l2_redirect
f74599f7 35hostprogs-y += lwt_len_hist
12d8bb64 36hostprogs-y += xdp_tx_iptunnel
3c731eba 37
43371c83
JS
38# Libbpf dependencies
39LIBBPF := libbpf.o ../../tools/lib/bpf/bpf.o
40
41test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
42sock_example-objs := sock_example.o $(LIBBPF)
43fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
44sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
45sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
46sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
47tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
48tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
49tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
50tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
51tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
52tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
53test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
54trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
55lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
56offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
57spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
58map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
59test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
60test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
61test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
62test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o cgroup_helpers.o
63test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
64test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
65xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
764cbcce 66# reuse xdp1 source intentionally
43371c83
JS
67xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
68test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
9e6e60ec 69 test_current_task_under_cgroup_user.o
43371c83
JS
70trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
71sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
72tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
73lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
74xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
3c731eba
AS
75
76# Tell kbuild to always build the programs
77always := $(hostprogs-y)
a8085782 78always += sockex1_kern.o
fbe33108 79always += sockex2_kern.o
530b2c86 80always += sockex3_kern.o
b896c4f9 81always += tracex1_kern.o
d822a192 82always += tracex2_kern.o
5c7fc2d2 83always += tracex3_kern.o
9811e353 84always += tracex4_kern.o
5bacd780 85always += tracex5_kern.o
47efb302 86always += tracex6_kern.o
554ae6e7 87always += sock_flags_kern.o
cf9b1199 88always += test_probe_write_user_kern.o
39111695 89always += trace_output_kern.o
91bc4822 90always += tcbpf1_kern.o
6afb1e28 91always += tcbpf2_kern.o
90e02896 92always += tc_l2_redirect_kern.o
0fb1170e 93always += lathist_kern.o
a6ffe7b9 94always += offwaketime_kern.o
9d8b612d 95always += spintest_kern.o
26e90931 96always += map_perf_test_kern.o
e3edfdec
AS
97always += test_overhead_tp_kern.o
98always += test_overhead_kprobe_kern.o
65d472fb 99always += parse_varlen.o parse_simple.o parse_ldabs.o
a3f74617 100always += test_cgrp2_tc_kern.o
86af8b41 101always += xdp1_kern.o
764cbcce 102always += xdp2_kern.o
9e6e60ec 103always += test_current_task_under_cgroup_kern.o
1c47910e 104always += trace_event_kern.o
72874418 105always += sampleip_kern.o
f74599f7 106always += lwt_len_hist_kern.o
12d8bb64 107always += xdp_tx_iptunnel_kern.o
3c731eba
AS
108
109HOSTCFLAGS += -I$(objtree)/usr/include
43371c83 110HOSTCFLAGS += -I$(srctree)/tools/lib/
9bee294f 111HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
205c8ada
JS
112HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
113HOSTCFLAGS += -I$(srctree)/tools/perf
a8085782
AS
114
115HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
42984d7c 116HOSTLOADLIBES_fds_example += -lelf
a8085782 117HOSTLOADLIBES_sockex1 += -lelf
fbe33108 118HOSTLOADLIBES_sockex2 += -lelf
530b2c86 119HOSTLOADLIBES_sockex3 += -lelf
b896c4f9 120HOSTLOADLIBES_tracex1 += -lelf
d822a192 121HOSTLOADLIBES_tracex2 += -lelf
5c7fc2d2 122HOSTLOADLIBES_tracex3 += -lelf
9811e353 123HOSTLOADLIBES_tracex4 += -lelf -lrt
5bacd780 124HOSTLOADLIBES_tracex5 += -lelf
47efb302 125HOSTLOADLIBES_tracex6 += -lelf
554ae6e7 126HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
cf9b1199 127HOSTLOADLIBES_test_probe_write_user += -lelf
39111695 128HOSTLOADLIBES_trace_output += -lelf -lrt
0fb1170e 129HOSTLOADLIBES_lathist += -lelf
a6ffe7b9 130HOSTLOADLIBES_offwaketime += -lelf
9d8b612d 131HOSTLOADLIBES_spintest += -lelf
26e90931 132HOSTLOADLIBES_map_perf_test += -lelf -lrt
e3edfdec 133HOSTLOADLIBES_test_overhead += -lelf -lrt
86af8b41 134HOSTLOADLIBES_xdp1 += -lelf
764cbcce 135HOSTLOADLIBES_xdp2 += -lelf
9e6e60ec 136HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
1c47910e 137HOSTLOADLIBES_trace_event += -lelf
72874418 138HOSTLOADLIBES_sampleip += -lelf
90e02896 139HOSTLOADLIBES_tc_l2_redirect += -l elf
f74599f7 140HOSTLOADLIBES_lwt_len_hist += -l elf
12d8bb64 141HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
a8085782 142
bdefbbf2
JDB
143# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
144# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
6ccfba75 145LLC ?= llc
bdefbbf2 146CLANG ?= clang
6ccfba75 147
b62a796c
JDB
148# Trick to allow make to be run from this directory
149all:
150 $(MAKE) -C ../../ $$PWD/
151
152clean:
153 $(MAKE) -C ../../ M=$$PWD clean
154 @rm -f *~
155
bdefbbf2
JDB
156# Verify LLVM compiler tools are available and bpf target is supported by llc
157.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
7b01dd57 158
bdefbbf2
JDB
159verify_cmds: $(CLANG) $(LLC)
160 @for TOOL in $^ ; do \
161 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
162 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
163 exit 1; \
164 else true; fi; \
165 done
7b01dd57 166
bdefbbf2 167verify_target_bpf: verify_cmds
7b01dd57
JDB
168 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
169 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
170 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
171 exit 2; \
172 else true; fi
173
174$(src)/*.c: verify_target_bpf
175
128d1514
NR
176# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
177# But, there is no easy way to fix it, so just exclude it since it is
30b50aa6 178# useless for BPF samples.
b88c06e3 179$(obj)/%.o: $(src)/%.c
bdefbbf2 180 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
30b50aa6 181 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
65d472fb 182 -Wno-compare-distinct-pointer-types \
69a9d09b
AS
183 -Wno-gnu-variable-sized-type-not-at-end \
184 -Wno-address-of-packed-member -Wno-tautological-compare \
6ccfba75 185 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@