blob: d2d2b35c67eb12b308d85724c88f28943d8ea228 [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
Alexei Starovoitov39111692015-10-20 20:02:35 -070017hostprogs-y += trace_output
Daniel Wagner0fb11702015-06-19 16:00:44 +020018hostprogs-y += lathist
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080019hostprogs-y += offwaketime
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080020hostprogs-y += spintest
Alexei Starovoitov26e90932016-03-08 15:07:54 -080021hostprogs-y += map_perf_test
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070022hostprogs-y += test_overhead
Martin KaFai Laua3f74612016-06-30 10:28:45 -070023hostprogs-y += test_cgrp2_array_pin
Brenden Blanco86af8b42016-07-19 12:16:51 -070024hostprogs-y += xdp1
Brenden Blanco764cbcce2016-07-19 12:16:57 -070025hostprogs-y += xdp2
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070026
27test_verifier-objs := test_verifier.o libbpf.o
Alexei Starovoitovffb65f22014-11-13 17:36:48 -080028test_maps-objs := test_maps.o libbpf.o
Alexei Starovoitov03f47232014-12-01 15:06:36 -080029sock_example-objs := sock_example.o libbpf.o
Daniel Borkmann42984d72015-10-29 14:58:10 +010030fds_example-objs := bpf_load.o libbpf.o fds_example.o
Alexei Starovoitova8085782014-12-01 15:06:38 -080031sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080032sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070033sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070034tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070035tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070036tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070037tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070038tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
Kaixu Xia47efb302015-08-06 07:02:36 +000039tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070040trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020041lathist-objs := bpf_load.o libbpf.o lathist_user.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080042offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080043spintest-objs := bpf_load.o libbpf.o spintest_user.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080044map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070045test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070046test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070047xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070048# reuse xdp1 source intentionally
49xdp2-objs := bpf_load.o libbpf.o xdp1_user.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070050
51# Tell kbuild to always build the programs
52always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -080053always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080054always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070055always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070056always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070057always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070058always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070059always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070060always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +000061always += tracex6_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070062always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070063always += tcbpf1_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020064always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080065always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080066always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080067always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070068always += test_overhead_tp_kern.o
69always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -070070always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070071always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070072always += xdp1_kern.o
Brenden Blanco764cbcce2016-07-19 12:16:57 -070073always += xdp2_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070074
75HOSTCFLAGS += -I$(objtree)/usr/include
Alexei Starovoitova8085782014-12-01 15:06:38 -080076
77HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Daniel Borkmann42984d72015-10-29 14:58:10 +010078HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080079HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080080HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070081HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070082HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -070083HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070084HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -070085HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070086HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +000087HOSTLOADLIBES_tracex6 += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -070088HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +020089HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080090HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080091HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -080092HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070093HOSTLOADLIBES_test_overhead += -lelf -lrt
Brenden Blanco86af8b42016-07-19 12:16:51 -070094HOSTLOADLIBES_xdp1 += -lelf
Brenden Blanco764cbcce2016-07-19 12:16:57 -070095HOSTLOADLIBES_xdp2 += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080096
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020097# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
98# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +020099LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200100CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200101
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +0200102# Trick to allow make to be run from this directory
103all:
104 $(MAKE) -C ../../ $$PWD/
105
106clean:
107 $(MAKE) -C ../../ M=$$PWD clean
108 @rm -f *~
109
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200110# Verify LLVM compiler tools are available and bpf target is supported by llc
111.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200112
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200113verify_cmds: $(CLANG) $(LLC)
114 @for TOOL in $^ ; do \
115 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
116 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
117 exit 1; \
118 else true; fi; \
119 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200120
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200121verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200122 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
123 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
124 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
125 exit 2; \
126 else true; fi
127
128$(src)/*.c: verify_target_bpf
129
Naveen N. Rao128d1512016-04-04 22:31:33 +0530130# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
131# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800132# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700133$(obj)/%.o: $(src)/%.c
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200134 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
Yang Shi30b50aa2015-11-12 14:07:46 -0800135 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700136 -Wno-compare-distinct-pointer-types \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200137 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@