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