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_DISPLAY	:= libtraceevent
37FEATURE_DISPLAY	+= libtracefs
38FEATURE_DISPLAY	+= libcpupower
39
40all: $(RTLA)
41
42include $(srctree)/tools/build/Makefile.include
43include Makefile.rtla
44
45# check for dependencies only on required targets
46NON_CONFIG_TARGETS := clean install tarball doc doc_clean doc_install
47
48config		:= 1
49ifdef MAKECMDGOALS
50ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
51 config		:= 0
52endif
53endif
54
55ifeq ($(config),1)
56  include $(srctree)/tools/build/Makefile.feature
57  include Makefile.config
58endif
59
60CFLAGS		+= $(INCLUDES) $(LIB_INCLUDES)
61
62export CFLAGS OUTPUT srctree
63
64$(RTLA): $(RTLA_IN)
65	$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTLA) $(RTLA_IN) $(EXTLIBS)
66
67static: $(RTLA_IN)
68	$(eval LDFLAGS += -static)
69	$(QUIET_LINK)$(CC) -static $(LDFLAGS) -o $(RTLA)-static $(RTLA_IN)  $(EXTLIBS)
70
71rtla.%: fixdep FORCE
72	make -f $(srctree)/tools/build/Makefile.build dir=. $@
73
74$(RTLA_IN): fixdep FORCE
75	make $(build)=rtla
76
77clean: doc_clean fixdep-clean
78	$(call QUIET_CLEAN, rtla)
79	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
80	$(Q)rm -f rtla rtla-static fixdep FEATURE-DUMP rtla-*
81	$(Q)rm -rf feature
82check: $(RTLA)
83	RTLA=$(RTLA) prove -o -f tests/
84.PHONY: FORCE clean check
85