xref: /openbmc/linux/samples/bpf/Makefile (revision 7211ec63)
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_lru_dist
6hostprogs-y += sock_example
7hostprogs-y += fds_example
8hostprogs-y += sockex1
9hostprogs-y += sockex2
10hostprogs-y += sockex3
11hostprogs-y += tracex1
12hostprogs-y += tracex2
13hostprogs-y += tracex3
14hostprogs-y += tracex4
15hostprogs-y += tracex5
16hostprogs-y += tracex6
17hostprogs-y += test_probe_write_user
18hostprogs-y += trace_output
19hostprogs-y += lathist
20hostprogs-y += offwaketime
21hostprogs-y += spintest
22hostprogs-y += map_perf_test
23hostprogs-y += test_overhead
24hostprogs-y += test_cgrp2_array_pin
25hostprogs-y += test_cgrp2_attach
26hostprogs-y += test_cgrp2_attach2
27hostprogs-y += test_cgrp2_sock
28hostprogs-y += test_cgrp2_sock2
29hostprogs-y += xdp1
30hostprogs-y += xdp2
31hostprogs-y += test_current_task_under_cgroup
32hostprogs-y += trace_event
33hostprogs-y += sampleip
34hostprogs-y += tc_l2_redirect
35hostprogs-y += lwt_len_hist
36hostprogs-y += xdp_tx_iptunnel
37hostprogs-y += test_map_in_map
38hostprogs-y += per_socket_stats_example
39hostprogs-y += load_sock_ops
40hostprogs-y += xdp_redirect
41hostprogs-y += xdp_redirect_map
42hostprogs-y += xdp_monitor
43hostprogs-y += syscall_tp
44
45# Libbpf dependencies
46LIBBPF := ../../tools/lib/bpf/bpf.o
47
48test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
49sock_example-objs := sock_example.o $(LIBBPF)
50fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
51sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
52sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
53sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
54tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
55tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
56tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
57tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
58tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
59tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
60load_sock_ops-objs := bpf_load.o $(LIBBPF) load_sock_ops.o
61test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
62trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
63lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
64offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o
65spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o
66map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
67test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
68test_cgrp2_array_pin-objs := $(LIBBPF) test_cgrp2_array_pin.o
69test_cgrp2_attach-objs := $(LIBBPF) test_cgrp2_attach.o
70test_cgrp2_attach2-objs := $(LIBBPF) test_cgrp2_attach2.o cgroup_helpers.o
71test_cgrp2_sock-objs := $(LIBBPF) test_cgrp2_sock.o
72test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
73xdp1-objs := bpf_load.o $(LIBBPF) xdp1_user.o
74# reuse xdp1 source intentionally
75xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
76test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
77				       test_current_task_under_cgroup_user.o
78trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o
79sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o
80tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
81lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
82xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
83test_map_in_map-objs := bpf_load.o $(LIBBPF) test_map_in_map_user.o
84per_socket_stats_example-objs := $(LIBBPF) cookie_uid_helper_example.o
85xdp_redirect-objs := bpf_load.o $(LIBBPF) xdp_redirect_user.o
86xdp_redirect_map-objs := bpf_load.o $(LIBBPF) xdp_redirect_map_user.o
87xdp_monitor-objs := bpf_load.o $(LIBBPF) xdp_monitor_user.o
88syscall_tp-objs := bpf_load.o $(LIBBPF) syscall_tp_user.o
89
90# Tell kbuild to always build the programs
91always := $(hostprogs-y)
92always += sockex1_kern.o
93always += sockex2_kern.o
94always += sockex3_kern.o
95always += tracex1_kern.o
96always += tracex2_kern.o
97always += tracex3_kern.o
98always += tracex4_kern.o
99always += tracex5_kern.o
100always += tracex6_kern.o
101always += sock_flags_kern.o
102always += test_probe_write_user_kern.o
103always += trace_output_kern.o
104always += tcbpf1_kern.o
105always += tcbpf2_kern.o
106always += tc_l2_redirect_kern.o
107always += lathist_kern.o
108always += offwaketime_kern.o
109always += spintest_kern.o
110always += map_perf_test_kern.o
111always += test_overhead_tp_kern.o
112always += test_overhead_kprobe_kern.o
113always += parse_varlen.o parse_simple.o parse_ldabs.o
114always += test_cgrp2_tc_kern.o
115always += xdp1_kern.o
116always += xdp2_kern.o
117always += test_current_task_under_cgroup_kern.o
118always += trace_event_kern.o
119always += sampleip_kern.o
120always += lwt_len_hist_kern.o
121always += xdp_tx_iptunnel_kern.o
122always += test_map_in_map_kern.o
123always += cookie_uid_helper_example.o
124always += tcp_synrto_kern.o
125always += tcp_rwnd_kern.o
126always += tcp_bufs_kern.o
127always += tcp_cong_kern.o
128always += tcp_iw_kern.o
129always += tcp_clamp_kern.o
130always += xdp_redirect_kern.o
131always += xdp_redirect_map_kern.o
132always += xdp_monitor_kern.o
133always += syscall_tp_kern.o
134
135HOSTCFLAGS += -I$(objtree)/usr/include
136HOSTCFLAGS += -I$(srctree)/tools/lib/
137HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
138HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
139HOSTCFLAGS += -I$(srctree)/tools/perf
140
141HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
142HOSTLOADLIBES_fds_example += -lelf
143HOSTLOADLIBES_sockex1 += -lelf
144HOSTLOADLIBES_sockex2 += -lelf
145HOSTLOADLIBES_sockex3 += -lelf
146HOSTLOADLIBES_tracex1 += -lelf
147HOSTLOADLIBES_tracex2 += -lelf
148HOSTLOADLIBES_tracex3 += -lelf
149HOSTLOADLIBES_tracex4 += -lelf -lrt
150HOSTLOADLIBES_tracex5 += -lelf
151HOSTLOADLIBES_tracex6 += -lelf
152HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
153HOSTLOADLIBES_load_sock_ops += -lelf
154HOSTLOADLIBES_test_probe_write_user += -lelf
155HOSTLOADLIBES_trace_output += -lelf -lrt
156HOSTLOADLIBES_lathist += -lelf
157HOSTLOADLIBES_offwaketime += -lelf
158HOSTLOADLIBES_spintest += -lelf
159HOSTLOADLIBES_map_perf_test += -lelf -lrt
160HOSTLOADLIBES_test_overhead += -lelf -lrt
161HOSTLOADLIBES_xdp1 += -lelf
162HOSTLOADLIBES_xdp2 += -lelf
163HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
164HOSTLOADLIBES_trace_event += -lelf
165HOSTLOADLIBES_sampleip += -lelf
166HOSTLOADLIBES_tc_l2_redirect += -l elf
167HOSTLOADLIBES_lwt_len_hist += -l elf
168HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
169HOSTLOADLIBES_test_map_in_map += -lelf
170HOSTLOADLIBES_xdp_redirect += -lelf
171HOSTLOADLIBES_xdp_redirect_map += -lelf
172HOSTLOADLIBES_xdp_monitor += -lelf
173HOSTLOADLIBES_syscall_tp += -lelf
174
175# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
176#  make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
177LLC ?= llc
178CLANG ?= clang
179
180# Trick to allow make to be run from this directory
181all:
182	$(MAKE) -C ../../ $(CURDIR)/
183
184clean:
185	$(MAKE) -C ../../ M=$(CURDIR) clean
186	@rm -f *~
187
188$(obj)/syscall_nrs.s:	$(src)/syscall_nrs.c
189	$(call if_changed_dep,cc_s_c)
190
191$(obj)/syscall_nrs.h:	$(obj)/syscall_nrs.s FORCE
192	$(call filechk,offsets,__SYSCALL_NRS_H__)
193
194clean-files += syscall_nrs.h
195
196FORCE:
197
198
199# Verify LLVM compiler tools are available and bpf target is supported by llc
200.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
201
202verify_cmds: $(CLANG) $(LLC)
203	@for TOOL in $^ ; do \
204		if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
205			echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
206			exit 1; \
207		else true; fi; \
208	done
209
210verify_target_bpf: verify_cmds
211	@if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
212		echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
213		echo "   NOTICE: LLVM version >= 3.7.1 required" ;\
214		exit 2; \
215	else true; fi
216
217$(src)/*.c: verify_target_bpf
218
219$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
220
221# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
222# But, there is no easy way to fix it, so just exclude it since it is
223# useless for BPF samples.
224$(obj)/%.o: $(src)/%.c
225	$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
226		-I$(srctree)/tools/testing/selftests/bpf/ \
227		-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
228		-Wno-compare-distinct-pointer-types \
229		-Wno-gnu-variable-sized-type-not-at-end \
230		-Wno-address-of-packed-member -Wno-tautological-compare \
231		-Wno-unknown-warning-option \
232		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
233