blob: a98b780e974ca7e6be3d68b963a75340d177009b [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
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070024
25test_verifier-objs := test_verifier.o libbpf.o
Alexei Starovoitovffb65f22014-11-13 17:36:48 -080026test_maps-objs := test_maps.o libbpf.o
Alexei Starovoitov03f47232014-12-01 15:06:36 -080027sock_example-objs := sock_example.o libbpf.o
Daniel Borkmann42984d72015-10-29 14:58:10 +010028fds_example-objs := bpf_load.o libbpf.o fds_example.o
Alexei Starovoitova8085782014-12-01 15:06:38 -080029sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080030sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070031sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070032tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070033tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070034tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070035tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070036tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
Kaixu Xia47efb302015-08-06 07:02:36 +000037tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070038trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020039lathist-objs := bpf_load.o libbpf.o lathist_user.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080040offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080041spintest-objs := bpf_load.o libbpf.o spintest_user.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080042map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070043test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070044test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070045
46# Tell kbuild to always build the programs
47always := $(hostprogs-y)
Alexei Starovoitova8085782014-12-01 15:06:38 -080048always += sockex1_kern.o
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080049always += sockex2_kern.o
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070050always += sockex3_kern.o
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070051always += tracex1_kern.o
Alexei Starovoitovd822a192015-03-25 12:49:24 -070052always += tracex2_kern.o
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070053always += tracex3_kern.o
Alexei Starovoitov9811e352015-03-25 12:49:26 -070054always += tracex4_kern.o
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070055always += tracex5_kern.o
Kaixu Xia47efb302015-08-06 07:02:36 +000056always += tracex6_kern.o
Alexei Starovoitov39111692015-10-20 20:02:35 -070057always += trace_output_kern.o
Alexei Starovoitov91bc48222015-04-01 17:12:13 -070058always += tcbpf1_kern.o
Daniel Wagner0fb11702015-06-19 16:00:44 +020059always += lathist_kern.o
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080060always += offwaketime_kern.o
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080061always += spintest_kern.o
Alexei Starovoitov26e90932016-03-08 15:07:54 -080062always += map_perf_test_kern.o
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070063always += test_overhead_tp_kern.o
64always += test_overhead_kprobe_kern.o
Alexei Starovoitov65d472f2016-05-05 19:49:14 -070065always += parse_varlen.o parse_simple.o parse_ldabs.o
Martin KaFai Laua3f74612016-06-30 10:28:45 -070066always += test_cgrp2_tc_kern.o
Alexei Starovoitov3c731eb2014-09-26 00:17:07 -070067
68HOSTCFLAGS += -I$(objtree)/usr/include
Alexei Starovoitova8085782014-12-01 15:06:38 -080069
70HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
Daniel Borkmann42984d72015-10-29 14:58:10 +010071HOSTLOADLIBES_fds_example += -lelf
Alexei Starovoitova8085782014-12-01 15:06:38 -080072HOSTLOADLIBES_sockex1 += -lelf
Alexei Starovoitovfbe33102014-12-01 15:06:39 -080073HOSTLOADLIBES_sockex2 += -lelf
Alexei Starovoitov530b2c82015-05-19 16:59:06 -070074HOSTLOADLIBES_sockex3 += -lelf
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070075HOSTLOADLIBES_tracex1 += -lelf
Alexei Starovoitovd822a192015-03-25 12:49:24 -070076HOSTLOADLIBES_tracex2 += -lelf
Alexei Starovoitov5c7fc2d2015-03-25 12:49:25 -070077HOSTLOADLIBES_tracex3 += -lelf
Alexei Starovoitov9811e352015-03-25 12:49:26 -070078HOSTLOADLIBES_tracex4 += -lelf -lrt
Alexei Starovoitov5bacd782015-05-19 16:59:05 -070079HOSTLOADLIBES_tracex5 += -lelf
Kaixu Xia47efb302015-08-06 07:02:36 +000080HOSTLOADLIBES_tracex6 += -lelf
Alexei Starovoitov39111692015-10-20 20:02:35 -070081HOSTLOADLIBES_trace_output += -lelf -lrt
Daniel Wagner0fb11702015-06-19 16:00:44 +020082HOSTLOADLIBES_lathist += -lelf
Alexei Starovoitova6ffe7b2016-02-17 19:58:59 -080083HOSTLOADLIBES_offwaketime += -lelf
Alexei Starovoitov9d8b6122016-03-08 15:07:52 -080084HOSTLOADLIBES_spintest += -lelf
Alexei Starovoitov26e90932016-03-08 15:07:54 -080085HOSTLOADLIBES_map_perf_test += -lelf -lrt
Alexei Starovoitove3edfde2016-04-06 18:43:31 -070086HOSTLOADLIBES_test_overhead += -lelf -lrt
Alexei Starovoitova8085782014-12-01 15:06:38 -080087
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020088# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
89# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +020090LLC ?= llc
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +020091CLANG ?= clang
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +020092
Jesper Dangaard Brouerb62a7962016-04-28 14:21:09 +020093# Trick to allow make to be run from this directory
94all:
95 $(MAKE) -C ../../ $$PWD/
96
97clean:
98 $(MAKE) -C ../../ M=$$PWD clean
99 @rm -f *~
100
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200101# Verify LLVM compiler tools are available and bpf target is supported by llc
102.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200103
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200104verify_cmds: $(CLANG) $(LLC)
105 @for TOOL in $^ ; do \
106 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
107 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
108 exit 1; \
109 else true; fi; \
110 done
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200111
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200112verify_target_bpf: verify_cmds
Jesper Dangaard Brouer7b01dd52016-04-28 14:20:58 +0200113 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
114 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
115 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
116 exit 2; \
117 else true; fi
118
119$(src)/*.c: verify_target_bpf
120
Naveen N. Rao128d1512016-04-04 22:31:33 +0530121# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
122# But, there is no easy way to fix it, so just exclude it since it is
Yang Shi30b50aa2015-11-12 14:07:46 -0800123# useless for BPF samples.
Brenden Blancob88c06e2015-05-11 21:25:51 -0700124$(obj)/%.o: $(src)/%.c
Jesper Dangaard Brouerbdefbbf2016-04-28 14:21:14 +0200125 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
Yang Shi30b50aa2015-11-12 14:07:46 -0800126 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
Alexei Starovoitov65d472f2016-05-05 19:49:14 -0700127 -Wno-compare-distinct-pointer-types \
Jesper Dangaard Brouer6ccfba72016-04-28 14:20:53 +0200128 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@