blob: 0dae77c88d2eac0d85af2d210a77f49e3e9b50eb [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
Sargun Dhillon9b474ec2016-12-02 02:42:32 -080029hostprogs-y += test_cgrp2_attach2
David Ahernad2805d2016-12-01 08:48:05 -080030hostprogs-y += test_cgrp2_sock
David Ahern554ae6e2016-12-01 08:48:08 -080031hostprogs-y += test_cgrp2_sock2
Brenden Blanco86af8b42016-07-19 12:16:51 -070032hostprogs-y += xdp1
Brenden Blanco764cbcce2016-07-19 12:16:57 -070033hostprogs-y += xdp2
Christina Jacob3e29cd02017-11-05 08:52:30 +053034hostprogs-y += xdp_router_ipv4
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070035hostprogs-y += test_current_task_under_cgroup
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -070036hostprogs-y += trace_event
Brendan Gregg72874412016-09-01 18:37:26 -070037hostprogs-y += sampleip
Martin KaFai Lau90e02892016-11-09 15:36:34 -080038hostprogs-y += tc_l2_redirect
Thomas Graff74599f2016-11-30 17:10:11 +010039hostprogs-y += lwt_len_hist
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -080040hostprogs-y += xdp_tx_iptunnel
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -070041hostprogs-y += test_map_in_map
Chenbo Feng51570a52017-03-22 17:27:36 -070042hostprogs-y += per_socket_stats_example
Lawrence Brakmoae161892017-06-30 20:02:41 -070043hostprogs-y += load_sock_ops
John Fastabend832622e2017-07-17 09:27:28 -070044hostprogs-y += xdp_redirect
John Fastabend9d6e0052017-07-17 09:30:25 -070045hostprogs-y += xdp_redirect_map
Jesper Dangaard Brouerfad39172017-10-16 12:19:49 +020046hostprogs-y += xdp_redirect_cpu
Jesper Dangaard Brouer3ffab542017-08-29 16:38:11 +020047hostprogs-y += xdp_monitor
Jesper Dangaard Brouer0fca9312018-01-03 11:26:19 +010048hostprogs-y += xdp_rxq_info
Yonghong Song1da236b6b2017-08-04 16:00:10 -070049hostprogs-y += syscall_tp
Leo Yanc5350772018-02-26 09:19:12 +080050hostprogs-y += cpustat
Nikita V. Shirokovc6ffd1f2018-04-17 21:42:23 -070051hostprogs-y += xdp_adjust_tail
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +020052hostprogs-y += xdpsock
David Ahernfe616052018-05-09 20:34:27 -070053hostprogs-y += xdp_fwd
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070054
Joe Stringer43371c82016-12-14 14:43:39 -080055# Libbpf dependencies
Jakub Kicinski787360f2018-05-14 22:35:04 -070056LIBBPF = $(TOOLS_PATH)/lib/bpf/libbpf.a
57
Roman Gushchin9d1f1592017-11-05 08:15:33 -050058CGROUP_HELPERS := ../../tools/testing/selftests/bpf/cgroup_helpers.o
Yonghong Song28dbf862018-04-28 22:28:13 -070059TRACE_HELPERS := ../../tools/testing/selftests/bpf/trace_helpers.o
Joe Stringer43371c82016-12-14 14:43:39 -080060
61test_lru_dist-objs := test_lru_dist.o $(LIBBPF)
62sock_example-objs := sock_example.o $(LIBBPF)
63fds_example-objs := bpf_load.o $(LIBBPF) fds_example.o
64sockex1-objs := bpf_load.o $(LIBBPF) sockex1_user.o
65sockex2-objs := bpf_load.o $(LIBBPF) sockex2_user.o
66sockex3-objs := bpf_load.o $(LIBBPF) sockex3_user.o
67tracex1-objs := bpf_load.o $(LIBBPF) tracex1_user.o
68tracex2-objs := bpf_load.o $(LIBBPF) tracex2_user.o
69tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
70tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
71tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
72tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
Josef Bacik965de872017-12-11 11:36:49 -050073tracex7-objs := bpf_load.o $(LIBBPF) tracex7_user.o
Lawrence Brakmoae161892017-06-30 20:02:41 -070074load_sock_ops-objs := bpf_load.o $(LIBBPF) load_sock_ops.o
Joe Stringer43371c82016-12-14 14:43:39 -080075test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
Yonghong Song28dbf862018-04-28 22:28:13 -070076trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o $(TRACE_HELPERS)
Joe Stringer43371c82016-12-14 14:43:39 -080077lathist-objs := bpf_load.o $(LIBBPF) lathist_user.o
Yonghong Song28dbf862018-04-28 22:28:13 -070078offwaketime-objs := bpf_load.o $(LIBBPF) offwaketime_user.o $(TRACE_HELPERS)
79spintest-objs := bpf_load.o $(LIBBPF) spintest_user.o $(TRACE_HELPERS)
Joe Stringer43371c82016-12-14 14:43:39 -080080map_perf_test-objs := bpf_load.o $(LIBBPF) map_perf_test_user.o
81test_overhead-objs := bpf_load.o $(LIBBPF) test_overhead_user.o
Jakub Kicinski5f938052018-05-10 10:24:39 -070082test_cgrp2_array_pin-objs := test_cgrp2_array_pin.o $(LIBBPF)
83test_cgrp2_attach-objs := test_cgrp2_attach.o $(LIBBPF)
84test_cgrp2_attach2-objs := test_cgrp2_attach2.o $(LIBBPF) $(CGROUP_HELPERS)
85test_cgrp2_sock-objs := test_cgrp2_sock.o $(LIBBPF)
Joe Stringer43371c82016-12-14 14:43:39 -080086test_cgrp2_sock2-objs := bpf_load.o $(LIBBPF) test_cgrp2_sock2.o
Jakub Kicinskibe5bca42018-05-10 10:24:43 -070087xdp1-objs := xdp1_user.o $(LIBBPF)
Brenden Blanco764cbcce2016-07-19 12:16:57 -070088# reuse xdp1 source intentionally
Jakub Kicinskibe5bca42018-05-10 10:24:43 -070089xdp2-objs := xdp1_user.o $(LIBBPF)
Christina Jacob3e29cd02017-11-05 08:52:30 +053090xdp_router_ipv4-objs := bpf_load.o $(LIBBPF) xdp_router_ipv4_user.o
Roman Gushchin9d1f1592017-11-05 08:15:33 -050091test_current_task_under_cgroup-objs := bpf_load.o $(LIBBPF) $(CGROUP_HELPERS) \
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -070092 test_current_task_under_cgroup_user.o
Yonghong Song28dbf862018-04-28 22:28:13 -070093trace_event-objs := bpf_load.o $(LIBBPF) trace_event_user.o $(TRACE_HELPERS)
94sampleip-objs := bpf_load.o $(LIBBPF) sampleip_user.o $(TRACE_HELPERS)
Joe Stringer43371c82016-12-14 14:43:39 -080095tc_l2_redirect-objs := bpf_load.o $(LIBBPF) tc_l2_redirect_user.o
96lwt_len_hist-objs := bpf_load.o $(LIBBPF) lwt_len_hist_user.o
97xdp_tx_iptunnel-objs := bpf_load.o $(LIBBPF) xdp_tx_iptunnel_user.o
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -070098test_map_in_map-objs := bpf_load.o $(LIBBPF) test_map_in_map_user.o
Jakub Kicinski5f938052018-05-10 10:24:39 -070099per_socket_stats_example-objs := cookie_uid_helper_example.o $(LIBBPF)
John Fastabend832622e2017-07-17 09:27:28 -0700100xdp_redirect-objs := bpf_load.o $(LIBBPF) xdp_redirect_user.o
John Fastabend9d6e0052017-07-17 09:30:25 -0700101xdp_redirect_map-objs := bpf_load.o $(LIBBPF) xdp_redirect_map_user.o
Jesper Dangaard Brouerfad39172017-10-16 12:19:49 +0200102xdp_redirect_cpu-objs := bpf_load.o $(LIBBPF) xdp_redirect_cpu_user.o
Jesper Dangaard Brouer3ffab542017-08-29 16:38:11 +0200103xdp_monitor-objs := bpf_load.o $(LIBBPF) xdp_monitor_user.o
Jakub Kicinskibe5bca42018-05-10 10:24:43 -0700104xdp_rxq_info-objs := xdp_rxq_info_user.o $(LIBBPF)
Yonghong Song1da236b6b2017-08-04 16:00:10 -0700105syscall_tp-objs := bpf_load.o $(LIBBPF) syscall_tp_user.o
Leo Yanc5350772018-02-26 09:19:12 +0800106cpustat-objs := bpf_load.o $(LIBBPF) cpustat_user.o
Jakub Kicinskibe5bca42018-05-10 10:24:43 -0700107xdp_adjust_tail-objs := xdp_adjust_tail_user.o $(LIBBPF)
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200108xdpsock-objs := bpf_load.o $(LIBBPF) xdpsock_user.o
David Ahernfe616052018-05-09 20:34:27 -0700109xdp_fwd-objs := bpf_load.o $(LIBBPF) xdp_fwd_user.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -0700110
111# Tell kbuild to always build the programs
112always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -0800113always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -0800114always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -0700115always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -0700116always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -0700117always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -0700118always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -0700119always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -0700120always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +0000121always += tracex6_kern.o
Josef Bacik965de872017-12-11 11:36:49 -0500122always += tracex7_kern.o
David Ahern554ae6e2016-12-01 08:48:08 -0800123always += sock_flags_kern.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -0700124always += test_probe_write_user_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -0700125always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -0700126always += tcbpf1_kern.o
Martin KaFai Lau90e02892016-11-09 15:36:34 -0800127always += tc_l2_redirect_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +0200128always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -0800129always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -0800130always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -0800131always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700132always += test_overhead_tp_kern.o
Alexei Starovoitov4662a4e2018-03-28 12:05:39 -0700133always += test_overhead_raw_tp_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700134always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700135always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -0700136always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -0700137always += xdp1_kern.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -0700138always += xdp2_kern.o
Christina Jacob3e29cd02017-11-05 08:52:30 +0530139always += xdp_router_ipv4_kern.o
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -0700140always += test_current_task_under_cgroup_kern.o
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -0700141always += trace_event_kern.o
Brendan Gregg72874412016-09-01 18:37:26 -0700142always += sampleip_kern.o
Thomas Graff74599f2016-11-30 17:10:11 +0100143always += lwt_len_hist_kern.o
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -0800144always += xdp_tx_iptunnel_kern.o
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -0700145always += test_map_in_map_kern.o
Chenbo Feng51570a52017-03-22 17:27:36 -0700146always += cookie_uid_helper_example.o
Lawrence Brakmo61bc4d82017-06-30 20:02:43 -0700147always += tcp_synrto_kern.o
Lawrence Brakmoc4002962017-06-30 20:02:45 -0700148always += tcp_rwnd_kern.o
Lawrence Brakmod99253682017-06-30 20:02:48 -0700149always += tcp_bufs_kern.o
Lawrence Brakmobb56d442017-06-30 20:02:50 -0700150always += tcp_cong_kern.o
Lawrence Brakmo7bc62e22017-06-30 20:02:52 -0700151always += tcp_iw_kern.o
Lawrence Brakmo6c4a01b2017-06-30 20:02:54 -0700152always += tcp_clamp_kern.o
Lawrence Brakmoc8900632017-10-20 11:05:42 -0700153always += tcp_basertt_kern.o
John Fastabend832622e2017-07-17 09:27:28 -0700154always += xdp_redirect_kern.o
John Fastabend9d6e0052017-07-17 09:30:25 -0700155always += xdp_redirect_map_kern.o
Jesper Dangaard Brouerfad39172017-10-16 12:19:49 +0200156always += xdp_redirect_cpu_kern.o
Jesper Dangaard Brouer3ffab542017-08-29 16:38:11 +0200157always += xdp_monitor_kern.o
Jesper Dangaard Brouer0fca9312018-01-03 11:26:19 +0100158always += xdp_rxq_info_kern.o
Jesper Dangaard Brouer36e04a22018-01-10 18:21:44 +0100159always += xdp2skb_meta_kern.o
Yonghong Song1da236b6b2017-08-04 16:00:10 -0700160always += syscall_tp_kern.o
Leo Yanc5350772018-02-26 09:19:12 +0800161always += cpustat_kern.o
Nikita V. Shirokovc6ffd1f2018-04-17 21:42:23 -0700162always += xdp_adjust_tail_kern.o
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200163always += xdpsock_kern.o
David Ahernfe616052018-05-09 20:34:27 -0700164always += xdp_fwd_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -0700165
166HOSTCFLAGS += -I$(objtree)/usr/include
Joe Stringer43371c82016-12-14 14:43:39 -0800167HOSTCFLAGS += -I$(srctree)/tools/lib/
Alexei Starovoitov9bee2942016-11-28 22:07:22 -0800168HOSTCFLAGS += -I$(srctree)/tools/testing/selftests/bpf/
Joe Stringer205c8ad2016-12-08 18:46:19 -0800169HOSTCFLAGS += -I$(srctree)/tools/lib/ -I$(srctree)/tools/include
170HOSTCFLAGS += -I$(srctree)/tools/perf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800171
172HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Jakub Kicinskid0cabbb2018-05-10 10:24:40 -0700173HOSTCFLAGS_trace_helpers.o += -I$(srctree)/tools/lib/bpf/
174
175HOSTCFLAGS_trace_output_user.o += -I$(srctree)/tools/lib/bpf/
176HOSTCFLAGS_offwaketime_user.o += -I$(srctree)/tools/lib/bpf/
177HOSTCFLAGS_spintest_user.o += -I$(srctree)/tools/lib/bpf/
178HOSTCFLAGS_trace_event_user.o += -I$(srctree)/tools/lib/bpf/
179HOSTCFLAGS_sampleip_user.o += -I$(srctree)/tools/lib/bpf/
180
Jakub Kicinski5f938052018-05-10 10:24:39 -0700181HOSTLOADLIBES_test_lru_dist += -lelf
182HOSTLOADLIBES_sock_example += -lelf
Daniel Borkmann42984d72015-10-29 14:58:10 +0100183HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800184HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -0800185HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -0700186HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -0700187HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -0700188HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -0700189HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -0700190HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -0700191HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +0000192HOSTLOADLIBES_tracex6 += -lelf
Josef Bacik965de872017-12-11 11:36:49 -0500193HOSTLOADLIBES_tracex7 += -lelf
Jakub Kicinski5f938052018-05-10 10:24:39 -0700194HOSTLOADLIBES_test_cgrp2_array_pin += -lelf
195HOSTLOADLIBES_test_cgrp2_attach += -lelf
196HOSTLOADLIBES_test_cgrp2_attach2 += -lelf
197HOSTLOADLIBES_test_cgrp2_sock += -lelf
David Ahern554ae6e2016-12-01 08:48:08 -0800198HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
Lawrence Brakmoae161892017-06-30 20:02:41 -0700199HOSTLOADLIBES_load_sock_ops += -lelf
Sargun Dhilloncf9b1192016-07-25 05:55:02 -0700200HOSTLOADLIBES_test_probe_write_user += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -0700201HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +0200202HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -0800203HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -0800204HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -0800205HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -0700206HOSTLOADLIBES_test_overhead += -lelf -lrt
Brenden Blanco86af8b42016-07-19 12:16:51 -0700207HOSTLOADLIBES_xdp1 += -lelf
Brenden Blanco764cbcce2016-07-19 12:16:57 -0700208HOSTLOADLIBES_xdp2 += -lelf
Christina Jacob3e29cd02017-11-05 08:52:30 +0530209HOSTLOADLIBES_xdp_router_ipv4 += -lelf
Sargun Dhillon9e6e60e2016-08-12 08:57:04 -0700210HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
Alexei Starovoitov1c47910e2016-09-01 18:37:25 -0700211HOSTLOADLIBES_trace_event += -lelf
Brendan Gregg72874412016-09-01 18:37:26 -0700212HOSTLOADLIBES_sampleip += -lelf
Martin KaFai Lau90e02892016-11-09 15:36:34 -0800213HOSTLOADLIBES_tc_l2_redirect += -l elf
Thomas Graff74599f2016-11-30 17:10:11 +0100214HOSTLOADLIBES_lwt_len_hist += -l elf
Martin KaFai Lau12d8bb62016-12-07 15:53:14 -0800215HOSTLOADLIBES_xdp_tx_iptunnel += -lelf
Martin KaFai Laufb30d4b2017-03-22 10:00:35 -0700216HOSTLOADLIBES_test_map_in_map += -lelf
Jakub Kicinski5f938052018-05-10 10:24:39 -0700217HOSTLOADLIBES_per_socket_stats_example += -lelf
John Fastabend832622e2017-07-17 09:27:28 -0700218HOSTLOADLIBES_xdp_redirect += -lelf
John Fastabend9d6e0052017-07-17 09:30:25 -0700219HOSTLOADLIBES_xdp_redirect_map += -lelf
Jesper Dangaard Brouerfad39172017-10-16 12:19:49 +0200220HOSTLOADLIBES_xdp_redirect_cpu += -lelf
Jesper Dangaard Brouer3ffab542017-08-29 16:38:11 +0200221HOSTLOADLIBES_xdp_monitor += -lelf
Jesper Dangaard Brouer0fca9312018-01-03 11:26:19 +0100222HOSTLOADLIBES_xdp_rxq_info += -lelf
Yonghong Song1da236b6b2017-08-04 16:00:10 -0700223HOSTLOADLIBES_syscall_tp += -lelf
Leo Yanc5350772018-02-26 09:19:12 +0800224HOSTLOADLIBES_cpustat += -lelf
Nikita V. Shirokovc6ffd1f2018-04-17 21:42:23 -0700225HOSTLOADLIBES_xdp_adjust_tail += -lelf
Magnus Karlssonb4b8faa2018-05-02 13:01:36 +0200226HOSTLOADLIBES_xdpsock += -lelf -pthread
David Ahernfe616052018-05-09 20:34:27 -0700227HOSTLOADLIBES_xdp_fwd += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800228
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200229# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
230# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200231LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200232CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200233
Joel Fernandes876e88e2017-09-20 09:11:57 -0700234# Detect that we're cross compiling and use the cross compiler
235ifdef CROSS_COMPILE
236HOSTCC = $(CROSS_COMPILE)gcc
Abhijit Ayarekar9db95832017-10-13 12:24:06 -0700237CLANG_ARCH_ARGS = -target $(ARCH)
Joel Fernandes876e88e2017-09-20 09:11:57 -0700238endif
239
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200240# Trick to allow make to be run from this directory
Jakub Kicinski787360f2018-05-14 22:35:04 -0700241all:
242 $(MAKE) -C ../../ $(CURDIR)/ BPF_SAMPLES_PATH=$(CURDIR)
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200243
244clean:
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +0100245 $(MAKE) -C ../../ M=$(CURDIR) clean
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200246 @rm -f *~
247
Mickaël Salaünc25ef6a2018-01-26 01:39:30 +0100248$(LIBBPF): FORCE
Jakub Kicinski787360f2018-05-14 22:35:04 -0700249# Fix up variables inherited from Kbuild that tools/ build system won't like
250 $(MAKE) -C $(dir $@) RM='rm -rf' LDFLAGS= srctree=$(BPF_SAMPLES_PATH)/../../ O=
Mickaël Salaünc25ef6a2018-01-26 01:39:30 +0100251
David Daney4b7190e2017-06-13 16:49:38 -0700252$(obj)/syscall_nrs.s: $(src)/syscall_nrs.c
253 $(call if_changed_dep,cc_s_c)
254
255$(obj)/syscall_nrs.h: $(obj)/syscall_nrs.s FORCE
256 $(call filechk,offsets,__SYSCALL_NRS_H__)
257
258clean-files += syscall_nrs.h
259
260FORCE:
261
262
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200263# Verify LLVM compiler tools are available and bpf target is supported by llc
264.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200265
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200266verify_cmds: $(CLANG) $(LLC)
267 @for TOOL in $^ ; do \
268 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
269 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
270 exit 1; \
271 else true; fi; \
272 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200273
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200274verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200275 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
276 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
277 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
278 exit 2; \
279 else true; fi
280
Jakub Kicinski787360f2018-05-14 22:35:04 -0700281$(BPF_SAMPLES_PATH)/*.c: verify_target_bpf $(LIBBPF)
282$(src)/*.c: verify_target_bpf $(LIBBPF)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200283
David Daney4b7190e2017-06-13 16:49:38 -0700284$(obj)/tracex5_kern.o: $(obj)/syscall_nrs.h
285
Naveen N. Rao128d1512016-04-04 22:31:33 +0530286# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
287# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800288# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700289$(obj)/%.o: $(src)/%.c
Yonghong Song00a38552017-06-21 13:48:27 -0700290 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \
Yonghong Song53335022017-07-10 14:04:28 -0700291 -I$(srctree)/tools/testing/selftests/bpf/ \
Abhijit Ayarekar9db95832017-10-13 12:24:06 -0700292 -D__KERNEL__ -Wno-unused-value -Wno-pointer-sign \
Joel Fernandesb655fc12017-09-20 09:11:58 -0700293 -D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \
Alexei Starovoitov69a9d092016-12-01 18:31:12 -0800294 -Wno-gnu-variable-sized-type-not-at-end \
295 -Wno-address-of-packed-member -Wno-tautological-compare \
Abhijit Ayarekar9db95832017-10-13 12:24:06 -0700296 -Wno-unknown-warning-option $(CLANG_ARCH_ARGS) \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200297 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@