blob: 9316e648a880db61cad82c399c30218695d7d215 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Hendrik Brueckner618e1652017-12-04 10:56:48 +01002
Mickaël Salaünd498f872017-02-11 23:20:23 +01003LIBDIR := ../../../lib
Zi Shen Lime8f1f342017-03-19 23:03:14 -07004BPFDIR := $(LIBDIR)/bpf
Daniel Borkmann02ea80b2017-03-31 02:24:04 +02005APIDIR := ../../../include/uapi
6GENDIR := ../../../../include/generated
7GENHDR := $(GENDIR)/autoconf.h
Mickaël Salaünd498f872017-02-11 23:20:23 +01008
Daniel Borkmann02ea80b2017-03-31 02:24:04 +02009ifneq ($(wildcard $(GENHDR)),)
10 GENFLAGS := -DHAVE_GENHDR
11endif
12
Daniel Borkmann720f2282017-12-12 02:25:32 +010013CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
David Miller19c832e2017-12-19 15:22:03 -050014LDLIBS += -lcap -lelf -lrt
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020015
David S. Miller18b3ad92017-05-10 11:43:51 -070016TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
Roman Gushchin37f1ba02017-11-05 08:15:34 -050017 test_align test_verifier_log test_dev_cgroup
Alexei Starovoitov68828042017-03-30 21:45:41 -070018
Yonghong Song18f3d6b2017-06-13 15:52:14 -070019TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
Daniel Borkmann22c88522017-09-25 02:25:53 +020020 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
Roman Gushchin37f1ba02017-11-05 08:15:34 -050021 sockmap_verdict_prog.o dev_cgroup.o
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020022
Daniel Borkmann22c88522017-09-25 02:25:53 +020023TEST_PROGS := test_kmod.sh test_xdp_redirect.sh test_xdp_meta.sh
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020024
Zi Shen Lime8f1f342017-03-19 23:03:14 -070025include ../lib.mk
Alexei Starovoitov1da8ac72017-03-10 22:05:55 -080026
Roman Gushchin9d1f1592017-11-05 08:15:33 -050027BPFOBJ := $(OUTPUT)/libbpf.a $(OUTPUT)/cgroup_helpers.c
Zi Shen Lime8f1f342017-03-19 23:03:14 -070028
29$(TEST_GEN_PROGS): $(BPFOBJ)
30
31.PHONY: force
Mickaël Salaünd498f872017-02-11 23:20:23 +010032
Mickaël Salaünd498f872017-02-11 23:20:23 +010033# force a rebuild of BPFOBJ when its dependencies are updated
34force:
35
36$(BPFOBJ): force
Zi Shen Lime8f1f342017-03-19 23:03:14 -070037 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
Alexei Starovoitov68828042017-03-30 21:45:41 -070038
39CLANG ?= clang
Daniel Borkmann22c88522017-09-25 02:25:53 +020040LLC ?= llc
41
Quentin Monnetcd95a892017-12-21 08:52:50 -080042PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
Daniel Borkmann22c88522017-09-25 02:25:53 +020043
44# Let newer LLVM versions transparently probe the kernel for availability
45# of full BPF instruction set.
46ifeq ($(PROBE),)
47 CPU ?= probe
48else
49 CPU ?= generic
50endif
Alexei Starovoitov68828042017-03-30 21:45:41 -070051
52%.o: %.c
David S. Miller0a5539f2017-05-11 12:00:50 -070053 $(CLANG) -I. -I./include/uapi -I../../../include/uapi \
Daniel Borkmann22c88522017-09-25 02:25:53 +020054 -Wno-compare-distinct-pointer-types \
55 -O2 -target bpf -emit-llvm -c $< -o - | \
56 $(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@