xref: /openbmc/linux/samples/bpf/Makefile (revision 8730046c)
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
37
38# Libbpf dependencies
39LIBBPF := ../../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
66# reuse xdp1 source intentionally
67xdp2-objs := bpf_load.o $(LIBBPF) xdp1_user.o
68test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) cgroup_helpers.o \
69				       test_current_task_under_cgroup_user.o
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
75
76# Tell kbuild to always build the programs
77always := $(hostprogs-y)
78always += sockex1_kern.o
79always += sockex2_kern.o
80always += sockex3_kern.o
81always += tracex1_kern.o
82always += tracex2_kern.o
83always += tracex3_kern.o
84always += tracex4_kern.o
85always += tracex5_kern.o
86always += tracex6_kern.o
87always += sock_flags_kern.o
88always += test_probe_write_user_kern.o
89always += trace_output_kern.o
90always += tcbpf1_kern.o
91always += tcbpf2_kern.o
92always += tc_l2_redirect_kern.o
93always += lathist_kern.o
94always += offwaketime_kern.o
95always += spintest_kern.o
96always += map_perf_test_kern.o
97always += test_overhead_tp_kern.o
98always += test_overhead_kprobe_kern.o
99always += parse_varlen.o parse_simple.o parse_ldabs.o
100always += test_cgrp2_tc_kern.o
101always += xdp1_kern.o
102always += xdp2_kern.o
103always += test_current_task_under_cgroup_kern.o
104always += trace_event_kern.o
105always += sampleip_kern.o
106always += lwt_len_hist_kern.o
107always += xdp_tx_iptunnel_kern.o
108
109HOSTCFLAGS += -I$(objtree)/usr/include
110HOSTCFLAGS += -I$(srctree)/tools/lib/
111HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
112HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
113HOSTCFLAGS += -I$(srctree)/tools/perf
114
115HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
116HOSTLOADLIBES_fds_example += -lelf
117HOSTLOADLIBES_sockex1 += -lelf
118HOSTLOADLIBES_sockex2 += -lelf
119HOSTLOADLIBES_sockex3 += -lelf
120HOSTLOADLIBES_tracex1 += -lelf
121HOSTLOADLIBES_tracex2 += -lelf
122HOSTLOADLIBES_tracex3 += -lelf
123HOSTLOADLIBES_tracex4 += -lelf -lrt
124HOSTLOADLIBES_tracex5 += -lelf
125HOSTLOADLIBES_tracex6 += -lelf
126HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
127HOSTLOADLIBES_test_probe_write_user += -lelf
128HOSTLOADLIBES_trace_output += -lelf -lrt
129HOSTLOADLIBES_lathist += -lelf
130HOSTLOADLIBES_offwaketime += -lelf
131HOSTLOADLIBES_spintest += -lelf
132HOSTLOADLIBES_map_perf_test += -lelf -lrt
133HOSTLOADLIBES_test_overhead += -lelf -lrt
134HOSTLOADLIBES_xdp1 += -lelf
135HOSTLOADLIBES_xdp2 += -lelf
136HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
137HOSTLOADLIBES_trace_event += -lelf
138HOSTLOADLIBES_sampleip += -lelf
139HOSTLOADLIBES_tc_l2_redirect += -l elf
140HOSTLOADLIBES_lwt_len_hist += -l elf
141HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
142
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
145LLC ?= llc
146CLANG ?= clang
147
148# Trick to allow make to be run from this directory
149all:
150	$(MAKE) -C ../../ $(CURDIR)/
151
152clean:
153	$(MAKE) -C ../../ M=$(CURDIR) clean
154	@rm -f *~
155
156# Verify LLVM compiler tools are available and bpf target is supported by llc
157.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
158
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
166
167verify_target_bpf: verify_cmds
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
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
178# useless for BPF samples.
179$(obj)/%.o: $(src)/%.c
180	$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
181		-D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
182		-Wno-compare-distinct-pointer-types \
183		-Wno-gnu-variable-sized-type-not-at-end \
184		-Wno-address-of-packed-member -Wno-tautological-compare \
185		-O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
186