blob: 42b571cde17781f9951a90b44d9b0f85f37a3a72 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Jakub Kicinski787360f2018-05-14 22:35:04 -07002
3BPF_SAMPLES_PATH ?= $(abspath $(srctree)/$(src))
4TOOLS_PATH := $(BPF_SAMPLES_PATH)/../../tools
5
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -07006# List of programs to build
Martin KaFai Lau5db58fa2016-11-11 10:55:11 -08007hostprogs-y := test_lru_dist
Alexei Starovoitov03f47232014-12-01 15:06:36 -08008hostprogs-y += sock_example
Daniel Borkmann42984d72015-10-29 14:58:10 +01009hostprogs-y += fds_example
Alexei Starovoitova8085782014-12-01 15:06:38 -080010hostprogs-y += sockex1
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080011hostprogs-y += sockex2
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070012hostprogs-y += sockex3
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070013hostprogs-y += tracex1
Alexei Starovoitovd822a192015-03-25 12:49:24 -070014hostprogs-y += tracex2
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070015hostprogs-y += tracex3
Alexei Starovoitov9811e352015-03-25 12:49:26 -070016hostprogs-y += tracex4
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070017hostprogs-y += tracex5
Kaixu Xia47efb302015-08-06 07:02:36 +000018hostprogs-y += tracex6
Josef Bacik965de872017-12-11 11:36:49 -050019hostprogs-y += tracex7
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070020hostprogs-y += test_probe_write_user
Alexei Starovoitov39111692015-10-20 20:02:35 -070021hostprogs-y += trace_output
Daniel Wagner0fb11702015-06-19 16:00:44 +020022hostprogs-y += lathist
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080023hostprogs-y += offwaketime
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080024hostprogs-y += spintest
Alexei Starovoitov26e90932016-03-08 15:07:54 -080025hostprogs-y += map_perf_test
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070026hostprogs-y += test_overhead
Martin KaFai Laua3f74612016-06-30 10:28:45 -070027hostprogs-y += test_cgrp2_array_pin
Daniel Mackd8c5b172016-11-23 16:52:30 +010028hostprogs-y += test_cgrp2_attach
David Ahernad2805d2016-12-01 08:48:05 -080029hostprogs-y += test_cgrp2_sock
David Ahern554ae6e2016-12-01 08:48:08 -080030hostprogs-y += test_cgrp2_sock2
Brenden Blanco86af8b42016-07-19 12:16:51 -070031hostprogs-y += xdp1
Brenden Blanco764cbcce2016-07-19 12:16:57 -070032hostprogs-y += xdp2
Christina Jacob3e29cd02017-11-05 08:52:30 +053033hostprogs-y += xdp_router_ipv4
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070034hostprogs-y += test_current_task_under_cgroup
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070035hostprogs-y += trace_event
Brendan Gregg72874412016-09-01 18:37:26 -070036hostprogs-y += sampleip
Martin KaFai Lau90e02892016-11-09 15:36:34 -080037hostprogs-y += tc_l2_redirect
Thomas Graff74599f2016-11-30 17:10:11 +010038hostprogs-y += lwt_len_hist
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -080039hostprogs-y += xdp_tx_iptunnel
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -070040hostprogs-y += test_map_in_map
Chenbo Feng51570a52017-03-22 17:27:36 -070041hostprogs-y += per_socket_stats_example
John Fastabend832622e2017-07-17 09:27:28 -070042hostprogs-y += xdp_redirect
John Fastabend9d6e0052017-07-17 09:30:25 -070043hostprogs-y += xdp_redirect_map
Jesper Dangaard Brouerfad39172017-10-16 12:19:49 +020044hostprogs-y += xdp_redirect_cpu
Jesper Dangaard Brouer3ffab542017-08-29 16:38:11 +020045hostprogs-y += xdp_monitor
Jesper Dangaard Brouer0fca9312018-01-03 11:26:19 +010046hostprogs-y += xdp_rxq_info
Yonghong Song1da236b6b2017-08-04 16:00:10 -070047hostprogs-y += syscall_tp
Leo Yanc5350772018-02-26 09:19:12 +080048hostprogs-y += cpustat
Nikita V. Shirokovc6ffd1f2018-04-17 21:42:23 -070049hostprogs-y += xdp_adjust_tail
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020050hostprogs-y += xdpsock
David Ahernfe616052018-05-09 20:34:27 -070051hostprogs-y += xdp_fwd
Yonghong Songecb96f72018-05-24 11:21:56 -070052hostprogs-y += task_fd_query
Toke Høiland-Jørgensen1e54ad22018-06-25 14:25:02 +020053hostprogs-y += xdp_sample_pkts
Ira Weiny0ac01fe2019-03-19 14:11:49 -070054hostprogs-y += ibumad
brakmoa1270fe2019-03-01 12:38:49 -080055hostprogs-y += hbm
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070056
Joe Stringer43371c82016-12-14 14:43:39 -080057# Libbpf dependencies
Jakub Kicinski787360f2018-05-14 22:35:04 -070058LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
59
Roman Gushchin9d1f1592017-11-05 08:15:33 -050060CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o
Yonghong Song28dbf862018-04-28 22:28:13 -070061TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o
Joe Stringer43371c82016-12-14 14:43:39 -080062
Jakub Kicinski1a9b2682019-02-27 19:04:13 -080063fds_example-objs := fds_example.o
64sockex1-objs := sockex1_user.o
65sockex2-objs := sockex2_user.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070066sockex3-objs := bpf_load.o sockex3_user.o
67tracex1-objs := bpf_load.o tracex1_user.o
68tracex2-objs := bpf_load.o tracex2_user.o
69tracex3-objs := bpf_load.o tracex3_user.o
70tracex4-objs := bpf_load.o tracex4_user.o
71tracex5-objs := bpf_load.o tracex5_user.o
72tracex6-objs := bpf_load.o tracex6_user.o
73tracex7-objs := bpf_load.o tracex7_user.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070074test_probe_write_user-objs := bpf_load.o test_probe_write_user_user.o
75trace_output-objs := bpf_load.o trace_output_user.o $(TRACE_HELPERS)
76lathist-objs := bpf_load.o lathist_user.o
77offwaketime-objs := bpf_load.o offwaketime_user.o $(TRACE_HELPERS)
78spintest-objs := bpf_load.o spintest_user.o $(TRACE_HELPERS)
79map_perf_test-objs := bpf_load.o map_perf_test_user.o
80test_overhead-objs := bpf_load.o test_overhead_user.o
81test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o
82test_cgrp2_attach-objs := test_cgrp2_attach.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070083test_cgrp2_sock-objs := test_cgrp2_sock.o
84test_cgrp2_sock2-objs := bpf_load.o test_cgrp2_sock2.o
85xdp1-objs := xdp1_user.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070086# reuse xdp1 source intentionally
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070087xdp2-objs := xdp1_user.o
Maciej Fijalkowskibbaf6022019-02-01 22:42:25 +010088xdp_router_ipv4-objs := xdp_router_ipv4_user.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070089test_current_task_under_cgroup-objs := bpf_load.o $(CGROUP_HELPERS) \
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070090 test_current_task_under_cgroup_user.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070091trace_event-objs := bpf_load.o trace_event_user.o $(TRACE_HELPERS)
92sampleip-objs := bpf_load.o sampleip_user.o $(TRACE_HELPERS)
93tc_l2_redirect-objs := bpf_load.o tc_l2_redirect_user.o
94lwt_len_hist-objs := bpf_load.o lwt_len_hist_user.o
Maciej Fijalkowskibbaf6022019-02-01 22:42:25 +010095xdp_tx_iptunnel-objs := xdp_tx_iptunnel_user.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -070096test_map_in_map-objs := bpf_load.o test_map_in_map_user.o
97per_socket_stats_example-objs := cookie_uid_helper_example.o
Maciej Fijalkowskibbaf6022019-02-01 22:42:25 +010098xdp_redirect-objs := xdp_redirect_user.o
99xdp_redirect_map-objs := xdp_redirect_map_user.o
Jakub Kicinski0cc54db2018-05-14 22:35:05 -0700100xdp_redirect_cpu-objs := bpf_load.o xdp_redirect_cpu_user.o
101xdp_monitor-objs := bpf_load.o xdp_monitor_user.o
102xdp_rxq_info-objs := xdp_rxq_info_user.o
103syscall_tp-objs := bpf_load.o syscall_tp_user.o
104cpustat-objs := bpf_load.o cpustat_user.o
105xdp_adjust_tail-objs := xdp_adjust_tail_user.o
Jakub Kicinski67481822018-07-26 14:32:21 -0700106xdpsock-objs := xdpsock_user.o
Jakub Kicinskie1a40ef2018-07-26 14:32:20 -0700107xdp_fwd-objs := xdp_fwd_user.o
Yonghong Songecb96f72018-05-24 11:21:56 -0700108task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
Toke Høiland-Jørgensen1e54ad22018-06-25 14:25:02 +0200109xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
Ira Weiny0ac01fe2019-03-19 14:11:49 -0700110ibumad-objs := bpf_load.o ibumad_user.o $(TRACE_HELPERS)
brakmoa1270fe2019-03-01 12:38:49 -0800111hbm-objs := bpf_load.o hbm.o $(CGROUP_HELPERS)
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -0700112
113# Tell kbuild to always build the programs
114always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -0800115always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -0800116always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -0700117always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -0700118always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -0700119always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -0700120always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -0700121always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -0700122always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +0000123always += tracex6_kern.o
Josef Bacik965de872017-12-11 11:36:49 -0500124always += tracex7_kern.o
David Ahern554ae6e2016-12-01 08:48:08 -0800125always += sock_flags_kern.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -0700126always += test_probe_write_user_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -0700127always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -0700128always += tcbpf1_kern.o
Martin KaFai Lau90e02892016-11-09 15:36:34 -0800129always += tc_l2_redirect_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +0200130always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -0800131always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -0800132always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -0800133always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700134always += test_overhead_tp_kern.o
Alexei Starovoitov4662a4e2018-03-28 12:05:39 -0700135always += test_overhead_raw_tp_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700136always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700137always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -0700138always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -0700139always += xdp1_kern.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -0700140always += xdp2_kern.o
Christina Jacob3e29cd02017-11-05 08:52:30 +0530141always += xdp_router_ipv4_kern.o
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -0700142always += test_current_task_under_cgroup_kern.o
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -0700143always += trace_event_kern.o
Brendan Gregg72874412016-09-01 18:37:26 -0700144always += sampleip_kern.o
Thomas Graff74599f2016-11-30 17:10:11 +0100145always += lwt_len_hist_kern.o
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -0800146always += xdp_tx_iptunnel_kern.o
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -0700147always += test_map_in_map_kern.o
Chenbo Feng51570a52017-03-22 17:27:36 -0700148always += cookie_uid_helper_example.o
Lawrence Brakmo61bc4d82017-06-30 20:02:43 -0700149always += tcp_synrto_kern.o
Lawrence Brakmoc4002962017-06-30 20:02:45 -0700150always += tcp_rwnd_kern.o
Lawrence Brakmod99253682017-06-30 20:02:48 -0700151always += tcp_bufs_kern.o
Lawrence Brakmobb56d442017-06-30 20:02:50 -0700152always += tcp_cong_kern.o
Lawrence Brakmo7bc62e22017-06-30 20:02:52 -0700153always += tcp_iw_kern.o
Lawrence Brakmo6c4a01b2017-06-30 20:02:54 -0700154always += tcp_clamp_kern.o
Lawrence Brakmoc8900632017-10-20 11:05:42 -0700155always += tcp_basertt_kern.o
Nikita V. Shirokovacb4ea92018-08-30 07:51:54 -0700156always += tcp_tos_reflect_kern.o
Stanislav Fomichev39533882019-07-02 09:14:02 -0700157always += tcp_dumpstats_kern.o
John Fastabend832622e2017-07-17 09:27:28 -0700158always += xdp_redirect_kern.o
John Fastabend9d6e0052017-07-17 09:30:25 -0700159always += xdp_redirect_map_kern.o
Jesper Dangaard Brouerfad39172017-10-16 12:19:49 +0200160always += xdp_redirect_cpu_kern.o
Jesper Dangaard Brouer3ffab542017-08-29 16:38:11 +0200161always += xdp_monitor_kern.o
Jesper Dangaard Brouer0fca9312018-01-03 11:26:19 +0100162always += xdp_rxq_info_kern.o
Jesper Dangaard Brouer36e04a22018-01-10 18:21:44 +0100163always += xdp2skb_meta_kern.o
Yonghong Song1da236b6b2017-08-04 16:00:10 -0700164always += syscall_tp_kern.o
Leo Yanc5350772018-02-26 09:19:12 +0800165always += cpustat_kern.o
Nikita V. Shirokovc6ffd1f2018-04-17 21:42:23 -0700166always += xdp_adjust_tail_kern.o
David Ahernfe616052018-05-09 20:34:27 -0700167always += xdp_fwd_kern.o
Yonghong Songecb96f72018-05-24 11:21:56 -0700168always += task_fd_query_kern.o
Toke Høiland-Jørgensen1e54ad22018-06-25 14:25:02 +0200169always += xdp_sample_pkts_kern.o
Ira Weiny0ac01fe2019-03-19 14:11:49 -0700170always += ibumad_kern.o
brakmo187d0732019-03-01 12:38:48 -0800171always += hbm_out_kern.o
brakmo71634d72019-07-02 15:09:52 -0700172always += hbm_edt_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -0700173
Laura Abbott96f14fe2018-07-09 17:45:58 -0700174KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include
Prashant Bholeb552d332019-06-14 15:43:18 +0900175KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/bpf/
Laura Abbott96f14fe2018-07-09 17:45:58 -0700176KBUILD_HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
177KBUILD_HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
178KBUILD_HOSTCFLAGS += -I$(srctree)/tools/perf
Björn Töpel04ec044b2019-10-01 13:33:07 +0200179KBUILD_HOSTCFLAGS += -DHAVE_ATTR_TEST=0
Alexei Starovoitova8085782014-12-01 15:06:38 -0800180
181HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Jakub Kicinskid0cabbb2018-05-10 10:24:40 -0700182
Laura Abbott8377bd22018-07-09 17:46:01 -0700183KBUILD_HOSTLDLIBS += $(LIBBPF) -lelf
184HOSTLDLIBS_tracex4 += -lrt
185HOSTLDLIBS_trace_output += -lrt
186HOSTLDLIBS_map_perf_test += -lrt
187HOSTLDLIBS_test_overhead += -lrt
188HOSTLDLIBS_xdpsock += -pthread
Alexei Starovoitova8085782014-12-01 15:06:38 -0800189
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200190# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
191# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200192LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200193CLANG ?= clang
Taeung Song9778cfd2018-07-26 19:13:44 +0900194LLVM_OBJCOPY ?= llvm-objcopy
195BTF_PAHOLE ?= pahole
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200196
Joel Fernandes876e88e2017-09-20 09:11:57 -0700197# Detect that we're cross compiling and use the cross compiler
198ifdef CROSS_COMPILE
199HOSTCC = $(CROSS_COMPILE)gcc
Abhijit Ayarekar9db95832017-10-13 12:24:06 -0700200CLANG_ARCH_ARGS = -target $(ARCH)
Joel Fernandes876e88e2017-09-20 09:11:57 -0700201endif
202
Jakub Kicinski0ed3cc42019-06-07 10:11:16 -0700203# Don't evaluate probes and warnings if we need to run make recursively
204ifneq ($(src),)
Jakub Kicinski07c3bbd2019-06-05 16:47:22 -0700205HDR_PROBE := $(shell echo "\#include <linux/types.h>\n struct list_head { int a; }; int main() { return 0; }" | \
206 $(HOSTCC) $(KBUILD_HOSTCFLAGS) -x c - -o /dev/null 2>/dev/null && \
207 echo okay)
208
209ifeq ($(HDR_PROBE),)
210$(warning WARNING: Detected possible issues with include path.)
211$(warning WARNING: Please install kernel headers locally (make headers_install).)
212endif
213
Taeung Song9778cfd2018-07-26 19:13:44 +0900214BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
215BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
216BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm')
Yonghong Song9ce6ae22018-11-19 15:29:17 -0800217BTF_LLVM_PROBE := $(shell echo "int main() { return 0; }" | \
218 $(CLANG) -target bpf -O2 -g -c -x c - -o ./llvm_btf_verify.o; \
219 readelf -S ./llvm_btf_verify.o | grep BTF; \
220 /bin/rm -f ./llvm_btf_verify.o)
Taeung Song9778cfd2018-07-26 19:13:44 +0900221
Yonghong Song9ce6ae22018-11-19 15:29:17 -0800222ifneq ($(BTF_LLVM_PROBE),)
223 EXTRA_CFLAGS += -g
224else
Taeung Song9778cfd2018-07-26 19:13:44 +0900225ifneq ($(and $(BTF_LLC_PROBE),$(BTF_PAHOLE_PROBE),$(BTF_OBJCOPY_PROBE)),)
226 EXTRA_CFLAGS += -g
227 LLC_FLAGS += -mattr=dwarfris
228 DWARF2BTF = y
229endif
Yonghong Song9ce6ae22018-11-19 15:29:17 -0800230endif
Jakub Kicinski0ed3cc42019-06-07 10:11:16 -0700231endif
Taeung Song9778cfd2018-07-26 19:13:44 +0900232
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200233# Trick to allow make to be run from this directory
Jakub Kicinski787360f2018-05-14 22:35:04 -0700234all:
235 $(MAKE) -C ../../ $(CURDIR)/ BPF_SAMPLES_PATH=$(CURDIR)
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200236
237clean:
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +0100238 $(MAKE) -C ../../ M=$(CURDIR) clean
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200239 @rm -f *~
240
Mickaël Salaünc25ef6a2018-01-26 01:39:30 +0100241$(LIBBPF): FORCE
Jakub Kicinski787360f2018-05-14 22:35:04 -0700242# Fix up variables inherited from Kbuild that tools/ build system won't like
243 $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O=
Mickaël Salaünc25ef6a2018-01-26 01:39:30 +0100244
David Daney4b7190e2017-06-13 16:49:38 -0700245$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
246 $(call filechk,offsets,__SYSCALL_NRS_H__)
247
Masahiro Yamada2c667d72018-12-22 18:50:34 +0900248targets += syscall_nrs.s
David Daney4b7190e2017-06-13 16:49:38 -0700249clean-files += syscall_nrs.h
250
251FORCE:
252
253
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200254# Verify LLVM compiler tools are available and bpf target is supported by llc
255.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200256
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200257verify_cmds: $(CLANG) $(LLC)
258 @for TOOL in $^ ; do \
259 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
260 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
261 exit 1; \
262 else true; fi; \
263 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200264
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200265verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200266 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
267 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
268 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
269 exit 2; \
270 else true; fi
271
Jakub Kicinski787360f2018-05-14 22:35:04 -0700272$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
273$(src)/*.c: verify_target_bpf $(LIBBPF)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200274
David Daney4b7190e2017-06-13 16:49:38 -0700275$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
brakmo187d0732019-03-01 12:38:48 -0800276$(obj)/hbm_out_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
brakmoa1270fe2019-03-01 12:38:49 -0800277$(obj)/hbm.o: $(src)/hbm.h
brakmo71634d72019-07-02 15:09:52 -0700278$(obj)/hbm_edt_kern.o: $(src)/hbm.h $(src)/hbm_kern.h
David Daney4b7190e2017-06-13 16:49:38 -0700279
Naveen N. Rao128d1512016-04-04 22:31:33 +0530280# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
281# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800282# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700283$(obj)/%.o: $(src)/%.c
Jakub Kicinski768759e2018-05-14 22:35:06 -0700284 @echo " CLANG-bpf " $@
285 $(Q)$(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
Yonghong Song53335022017-07-10 14:04:28 -0700286 -I$(srctree)/tools/testing/selftests/bpf/ \
Alexei Starovoitovb1ae32d2018-05-13 12:32:22 -0700287 -D__KERNEL__ -D__BPF_TRACING__ -Wno-unused-value -Wno-pointer-sign \
Ilya Leoshkevich81f522f2019-07-15 11:11:03 +0200288 -D__TARGET_ARCH_$(SRCARCH) -Wno-compare-distinct-pointer-types \
Alexei Starovoitov69a9d092016-12-01 18:31:12 -0800289 -Wno-gnu-variable-sized-type-not-at-end \
290 -Wno-address-of-packed-member -Wno-tautological-compare \
Abhijit Ayarekar9db95832017-10-13 12:24:06 -0700291 -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
Yonghong Song6bf3bbe2019-01-12 15:04:30 -0800292 -I$(srctree)/samples/bpf/ -include asm_goto_workaround.h \
Taeung Song9778cfd2018-07-26 19:13:44 +0900293 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf $(LLC_FLAGS) -filetype=obj -o $@
294ifeq ($(DWARF2BTF),y)
295 $(BTF_PAHOLE) -J $@
296endif