blob: 90ebf7d35c070cf93a076774c988168a459df13a [file] [log] [blame]
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -07001# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
Alexei Starovoitovffb65f22014-11-13 17:36:48 -08005hostprogs-y := test_verifier test_maps
Alexei Starovoitov03f47232014-12-01 15:06:36 -08006hostprogs-y += sock_example
Daniel Borkmann42984d72015-10-29 14:58:10 +01007hostprogs-y += fds_example
Alexei Starovoitova8085782014-12-01 15:06:38 -08008hostprogs-y += sockex1
Alexei Starovoitovfbe33102014-12-01 15:06:39 -08009hostprogs-y += sockex2
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070010hostprogs-y += sockex3
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070011hostprogs-y += tracex1
Alexei Starovoitovd822a192015-03-25 12:49:24 -070012hostprogs-y += tracex2
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070013hostprogs-y += tracex3
Alexei Starovoitov9811e352015-03-25 12:49:26 -070014hostprogs-y += tracex4
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070015hostprogs-y += tracex5
Kaixu Xia47efb302015-08-06 07:02:36 +000016hostprogs-y += tracex6
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070017hostprogs-y += test_probe_write_user
Alexei Starovoitov39111692015-10-20 20:02:35 -070018hostprogs-y += trace_output
Daniel Wagner0fb11702015-06-19 16:00:44 +020019hostprogs-y += lathist
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080020hostprogs-y += offwaketime
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080021hostprogs-y += spintest
Alexei Starovoitov26e90932016-03-08 15:07:54 -080022hostprogs-y += map_perf_test
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070023hostprogs-y += test_overhead
Martin KaFai Laua3f74612016-06-30 10:28:45 -070024hostprogs-y += test_cgrp2_array_pin
Brenden Blanco86af8b42016-07-19 12:16:51 -070025hostprogs-y += xdp1
Brenden Blanco764cbcce2016-07-19 12:16:57 -070026hostprogs-y += xdp2
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070027
28test_verifier-objs := test_verifier.o libbpf.o
Alexei Starovoitovffb65f22014-11-13 17:36:48 -080029test_maps-objs := test_maps.o libbpf.o
Alexei Starovoitov03f47232014-12-01 15:06:36 -080030sock_example-objs := sock_example.o libbpf.o
Daniel Borkmann42984d72015-10-29 14:58:10 +010031fds_example-objs := bpf_load.o libbpf.o fds_example.o
Alexei Starovoitova8085782014-12-01 15:06:38 -080032sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080033sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070034sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070035tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070036tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070037tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070038tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070039tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
Kaixu Xia47efb302015-08-06 07:02:36 +000040tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070041test_probe_write_user-objs := bpf_load.o libbpf.o test_probe_write_user_user.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070042trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020043lathist-objs := bpf_load.o libbpf.o lathist_user.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080044offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080045spintest-objs := bpf_load.o libbpf.o spintest_user.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080046map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070047test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070048test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070049xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070050# reuse xdp1 source intentionally
51xdp2-objs := bpf_load.o libbpf.o xdp1_user.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070052
53# Tell kbuild to always build the programs
54always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -080055always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080056always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070057always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070058always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070059always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070060always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070061always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070062always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +000063always += tracex6_kern.o
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070064always += test_probe_write_user_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070065always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070066always += tcbpf1_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020067always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080068always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080069always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080070always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070071always += test_overhead_tp_kern.o
72always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -070073always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070074always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070075always += xdp1_kern.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070076always += xdp2_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070077
78HOSTCFLAGS += -I$(objtree)/usr/include
Alexei Starovoitova8085782014-12-01 15:06:38 -080079
80HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Daniel Borkmann42984d72015-10-29 14:58:10 +010081HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080082HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080083HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070084HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070085HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -070086HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070087HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -070088HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070089HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +000090HOSTLOADLIBES_tracex6 += -lelf
Sargun Dhilloncf9b1192016-07-25 05:55:02 -070091HOSTLOADLIBES_test_probe_write_user += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -070092HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +020093HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080094HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080095HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -080096HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070097HOSTLOADLIBES_test_overhead += -lelf -lrt
Brenden Blanco86af8b42016-07-19 12:16:51 -070098HOSTLOADLIBES_xdp1 += -lelf
Brenden Blanco764cbcce2016-07-19 12:16:57 -070099HOSTLOADLIBES_xdp2 += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -0800100
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200101# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
102# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200103LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200104CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200105
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200106# Trick to allow make to be run from this directory
107all:
108 $(MAKE) -C ../../ $$PWD/
109
110clean:
111 $(MAKE) -C ../../ M=$$PWD clean
112 @rm -f *~
113
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200114# Verify LLVM compiler tools are available and bpf target is supported by llc
115.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200116
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200117verify_cmds: $(CLANG) $(LLC)
118 @for TOOL in $^ ; do \
119 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
120 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
121 exit 1; \
122 else true; fi; \
123 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200124
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200125verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200126 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
127 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
128 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
129 exit 2; \
130 else true; fi
131
132$(src)/*.c: verify_target_bpf
133
Naveen N. Rao128d1512016-04-04 22:31:33 +0530134# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
135# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800136# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700137$(obj)/%.o: $(src)/%.c
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200138 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
Yang Shi30b50aa2015-11-12 14:07:46 -0800139 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700140 -Wno-compare-distinct-pointer-types \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200141 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@