xref: /linux/tools/tracing/rtla/Makefile (revision 5525aebd4e0c6f7d92ec1cb074218bbcf3d46f13)
1# SPDX-License-Identifier: GPL-2.0-only
2
3ifeq ($(srctree),)
4  srctree	:= $(patsubst %/,%,$(dir $(CURDIR)))
5  srctree	:= $(patsubst %/,%,$(dir $(srctree)))
6  srctree	:= $(patsubst %/,%,$(dir $(srctree)))
7endif
8
9include $(srctree)/tools/scripts/Makefile.include
10
11# O is an alias for OUTPUT
12OUTPUT          := $(O)
13
14ifeq ($(OUTPUT),)
15  OUTPUT        := $(CURDIR)
16else
17  # subdir is used by the ../Makefile in $(call descend,)
18  ifneq ($(subdir),)
19    OUTPUT        := $(OUTPUT)/$(subdir)
20  endif
21endif
22
23ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
24  OUTPUT        := $(OUTPUT)/
25endif
26
27RTLA		:= $(OUTPUT)rtla
28RTLA_IN		:= $(RTLA)-in.o
29
30VERSION		:= $(shell sh -c "make -sC ../../.. kernelversion | grep -v make")
31DOCSRC		:= ../../../Documentation/tools/rtla/
32
33FEATURE_TESTS	:= libtraceevent
34FEATURE_TESTS	+= libtracefs
35FEATURE_TESTS	+= libcpupower
36FEATURE_TESTS	+= libbpf
37FEATURE_TESTS	+= clang-bpf-co-re
38FEATURE_TESTS	+= bpftool-skeletons
39FEATURE_DISPLAY	:= libtraceevent
40FEATURE_DISPLAY	+= libtracefs
41FEATURE_DISPLAY	+= libcpupower
42FEATURE_DISPLAY	+= libbpf
43FEATURE_DISPLAY	+= clang-bpf-co-re
44FEATURE_DISPLAY	+= bpftool-skeletons
45
46all: $(RTLA)
47
48include $(srctree)/tools/build/Makefile.include
49include Makefile.rtla
50
51# check for dependencies only on required targets
52NON_CONFIG_TARGETS := clean install tarball doc doc_clean doc_install
53
54config		:= 1
55ifdef MAKECMDGOALS
56ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
57 config		:= 0
58endif
59endif
60
61ifeq ($(config),1)
62  include $(srctree)/tools/build/Makefile.feature
63  include Makefile.config
64endif
65
66CFLAGS		+= $(INCLUDES) $(LIB_INCLUDES)
67
68export CFLAGS OUTPUT srctree
69
70ifeq ($(BUILD_BPF_SKEL),1)
71src/timerlat.bpf.o: src/timerlat.bpf.c
72	$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
73
74src/timerlat.skel.h: src/timerlat.bpf.o
75	$(QUIET_GENSKEL)$(SYSTEM_BPFTOOL) gen skeleton $< > $@
76
77example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
78	$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
79
80tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.c
81	$(QUIET_CLANG)$(CLANG) -g -O2 -target bpf -c $(filter %.c,$^) -o $@
82else
83src/timerlat.skel.h:
84	$(Q)echo '/* BPF skeleton is disabled */' > src/timerlat.skel.h
85
86example/timerlat_bpf_action.o: example/timerlat_bpf_action.c
87	$(Q)echo "BPF skeleton support is disabled, skipping example/timerlat_bpf_action.o"
88
89tests/bpf/bpf_action_map.o: tests/bpf/bpf_action_map.c
90	$(Q)echo "BPF skeleton support is disabled, skipping tests/bpf/bpf_action_map.o"
91endif
92
93$(RTLA): $(RTLA_IN)
94	$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(EXTLIBS)
95
96static: $(RTLA_IN)
97	$(eval LDFLAGS += -static)
98	$(QUIET_LINK)$(CC) -static $(LDFLAGS) -o $(RTLA)-static $(RTLA_IN)  $(EXTLIBS)
99
100rtla.%: fixdep FORCE
101	make -f $(srctree)/tools/build/Makefile.build dir=. $@
102
103$(RTLA_IN): fixdep FORCE src/timerlat.skel.h
104	make $(build)=rtla
105
106clean: doc_clean fixdep-clean
107	$(call QUIET_CLEAN, rtla)
108	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
109	$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
110	$(Q)rm -rf feature
111	$(Q)rm -f src/timerlat.bpf.o src/timerlat.skel.h example/timerlat_bpf_action.o
112check: $(RTLA) tests/bpf/bpf_action_map.o
113	RTLA=$(RTLA) BPFTOOL=$(SYSTEM_BPFTOOL) prove -o -f tests/
114examples: example/timerlat_bpf_action.o
115.PHONY: FORCE clean check
116