blob: 0e4ab3a9dfa93c0398146ab5d42a0370a2d5e92f [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
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070025
26test_verifier-objs := test_verifier.o libbpf.o
Alexei Starovoitovffb65f22014-11-13 17:36:48 -080027test_maps-objs := test_maps.o libbpf.o
Alexei Starovoitov03f47232014-12-01 15:06:36 -080028sock_example-objs := sock_example.o libbpf.o
Daniel Borkmann42984d72015-10-29 14:58:10 +010029fds_example-objs := bpf_load.o libbpf.o fds_example.o
Alexei Starovoitova8085782014-12-01 15:06:38 -080030sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080031sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070032sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070033tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070034tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070035tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070036tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070037tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
Kaixu Xia47efb302015-08-06 07:02:36 +000038tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070039trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020040lathist-objs := bpf_load.o libbpf.o lathist_user.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080041offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080042spintest-objs := bpf_load.o libbpf.o spintest_user.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080043map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070044test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070045test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070046xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070047
48# Tell kbuild to always build the programs
49always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -080050always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080051always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070052always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070053always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070054always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070055always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070056always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070057always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +000058always += tracex6_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070059always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070060always += tcbpf1_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020061always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080062always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080063always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080064always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070065always += test_overhead_tp_kern.o
66always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -070067always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070068always += test_cgrp2_tc_kern.o
Brenden Blanco86af8b42016-07-19 12:16:51 -070069always += xdp1_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070070
71HOSTCFLAGS += -I$(objtree)/usr/include
Alexei Starovoitova8085782014-12-01 15:06:38 -080072
73HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Daniel Borkmann42984d72015-10-29 14:58:10 +010074HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080075HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080076HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070077HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070078HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -070079HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070080HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -070081HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070082HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +000083HOSTLOADLIBES_tracex6 += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -070084HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +020085HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080086HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080087HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -080088HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070089HOSTLOADLIBES_test_overhead += -lelf -lrt
Brenden Blanco86af8b42016-07-19 12:16:51 -070090HOSTLOADLIBES_xdp1 += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080091
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020092# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
93# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +020094LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020095CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +020096
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +020097# Trick to allow make to be run from this directory
98all:
99 $(MAKE) -C ../../ $$PWD/
100
101clean:
102 $(MAKE) -C ../../ M=$$PWD clean
103 @rm -f *~
104
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200105# Verify LLVM compiler tools are available and bpf target is supported by llc
106.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200107
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200108verify_cmds: $(CLANG) $(LLC)
109 @for TOOL in $^ ; do \
110 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
111 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
112 exit 1; \
113 else true; fi; \
114 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200115
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200116verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200117 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
118 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
119 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
120 exit 2; \
121 else true; fi
122
123$(src)/*.c: verify_target_bpf
124
Naveen N. Rao128d1512016-04-04 22:31:33 +0530125# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
126# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800127# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700128$(obj)/%.o: $(src)/%.c
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200129 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
Yang Shi30b50aa2015-11-12 14:07:46 -0800130 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700131 -Wno-compare-distinct-pointer-types \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200132 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@