1 # SPDX-License-Identifier: GPL-2.0-only !! 1 NAME := rtla 2 !! 2 # Follow the kernel version 3 ifeq ($(srctree),) !! 3 VERSION := $(shell cat VERSION 2> /dev/null || make -sC ../../.. kernelversion | grep -v make) 4 srctree := $(patsubst %/,%,$(dir $(CUR !! 4 5 srctree := $(patsubst %/,%,$(dir $(src !! 5 # From libtracefs: 6 srctree := $(patsubst %/,%,$(dir $(src !! 6 # Makefiles suck: This macro sets a default value of $(2) for the 7 endif !! 7 # variable named by $(1), unless the variable has been set by 8 !! 8 # environment or command line. This is necessary for CC and AR 9 include $(srctree)/tools/scripts/Makefile.incl !! 9 # because make sets default values, so the simpler ?= approach 10 !! 10 # won't work as expected. 11 # O is an alias for OUTPUT !! 11 define allow-override 12 OUTPUT := $(O) !! 12 $(if $(or $(findstring environment,$(origin $(1))),\ 13 !! 13 $(findstring command line,$(origin $(1)))),,\ 14 ifeq ($(OUTPUT),) !! 14 $(eval $(1) = $(2))) 15 OUTPUT := $(CURDIR) !! 15 endef >> 16 >> 17 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. >> 18 $(call allow-override,CC,$(CROSS_COMPILE)gcc) >> 19 $(call allow-override,AR,$(CROSS_COMPILE)ar) >> 20 $(call allow-override,STRIP,$(CROSS_COMPILE)strip) >> 21 $(call allow-override,PKG_CONFIG,pkg-config) >> 22 $(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/) >> 23 $(call allow-override,LDCONFIG,ldconfig) >> 24 >> 25 INSTALL = install >> 26 MKDIR = mkdir >> 27 FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ >> 28 -fasynchronous-unwind-tables -fstack-clash-protection >> 29 WOPTS := -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized >> 30 >> 31 ifeq ($(CC),clang) >> 32 FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS)) >> 33 WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS)) >> 34 endif >> 35 >> 36 TRACEFS_HEADERS := $$($(PKG_CONFIG) --cflags libtracefs) >> 37 >> 38 CFLAGS := -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) $(EXTRA_CFLAGS) >> 39 LDFLAGS := -flto=auto -ggdb $(EXTRA_LDFLAGS) >> 40 LIBS := $$($(PKG_CONFIG) --libs libtracefs) >> 41 >> 42 SRC := $(wildcard src/*.c) >> 43 HDR := $(wildcard src/*.h) >> 44 OBJ := $(SRC:.c=.o) >> 45 DIRS := src >> 46 FILES := Makefile README.txt >> 47 CEXT := bz2 >> 48 TARBALL := $(NAME)-$(VERSION).tar.$(CEXT) >> 49 TAROPTS := -cvjf $(TARBALL) >> 50 BINDIR := /usr/bin >> 51 DATADIR := /usr/share >> 52 DOCDIR := $(DATADIR)/doc >> 53 MANDIR := $(DATADIR)/man >> 54 LICDIR := $(DATADIR)/licenses >> 55 SRCTREE := $(or $(BUILD_SRC),$(CURDIR)) >> 56 >> 57 # If running from the tarball, man pages are stored in the Documentation >> 58 # dir. If running from the kernel source, man pages are stored in >> 59 # Documentation/tools/rtla/. >> 60 ifneq ($(wildcard Documentation/.*),) >> 61 DOCSRC = Documentation/ 16 else 62 else 17 # subdir is used by the ../Makefile in $(cal !! 63 DOCSRC = $(SRCTREE)/../../../Documentation/tools/rtla/ 18 ifneq ($(subdir),) << 19 OUTPUT := $(OUTPUT)/$(subdir) << 20 endif << 21 endif << 22 << 23 ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),) << 24 OUTPUT := $(OUTPUT)/ << 25 endif 64 endif 26 65 27 RTLA := $(OUTPUT)rtla !! 66 LIBTRACEEVENT_MIN_VERSION = 1.5 28 RTLA_IN := $(RTLA)-in.o !! 67 LIBTRACEFS_MIN_VERSION = 1.3 29 << 30 VERSION := $(shell sh -c "make -sC ../ << 31 DOCSRC := ../../../Documentation/tool << 32 << 33 FEATURE_TESTS := libtraceevent << 34 FEATURE_TESTS += libtracefs << 35 FEATURE_DISPLAY := libtraceevent << 36 FEATURE_DISPLAY += libtracefs << 37 << 38 ifeq ($(V),1) << 39 Q = << 40 else << 41 Q = @ << 42 endif << 43 << 44 all: $(RTLA) << 45 << 46 include $(srctree)/tools/build/Makefile.includ << 47 include Makefile.rtla << 48 << 49 # check for dependencies only on required targ << 50 NON_CONFIG_TARGETS := clean install tarball do << 51 << 52 config := 1 << 53 ifdef MAKECMDGOALS << 54 ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAK << 55 config := 0 << 56 endif << 57 endif << 58 << 59 ifeq ($(config),1) << 60 include $(srctree)/tools/build/Makefile.feat << 61 include Makefile.config << 62 endif << 63 << 64 CFLAGS += $(INCLUDES) $(LIB_INCLUDES) << 65 << 66 export CFLAGS OUTPUT srctree << 67 << 68 $(RTLA): $(RTLA_IN) << 69 $(QUIET_LINK)$(CC) $(LDFLAGS) -o $(RTL << 70 68 71 static: $(RTLA_IN) !! 69 .PHONY: all warnings show_warnings 72 $(eval LDFLAGS += -static) !! 70 all: warnings rtla 73 $(QUIET_LINK)$(CC) -static $(LDFLAGS) << 74 71 75 rtla.%: fixdep FORCE !! 72 TEST_LIBTRACEEVENT = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 || echo n") 76 make -f $(srctree)/tools/build/Makefil !! 73 ifeq ("$(TEST_LIBTRACEEVENT)", "n") >> 74 WARNINGS = show_warnings >> 75 MISSING_LIBS += echo "** libtraceevent version $(LIBTRACEEVENT_MIN_VERSION) or higher"; >> 76 MISSING_PACKAGES += "libtraceevent-devel" >> 77 MISSING_SOURCE += echo "** https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ "; >> 78 endif >> 79 >> 80 TEST_LIBTRACEFS = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) libtracefs > /dev/null 2>&1 || echo n") >> 81 ifeq ("$(TEST_LIBTRACEFS)", "n") >> 82 WARNINGS = show_warnings >> 83 MISSING_LIBS += echo "** libtracefs version $(LIBTRACEFS_MIN_VERSION) or higher"; >> 84 MISSING_PACKAGES += "libtracefs-devel" >> 85 MISSING_SOURCE += echo "** https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ "; >> 86 endif >> 87 >> 88 define show_dependencies >> 89 @echo "********************************************"; \ >> 90 echo "** NOTICE: Failed build dependencies"; \ >> 91 echo "**"; \ >> 92 echo "** Required Libraries:"; \ >> 93 $(MISSING_LIBS) \ >> 94 echo "**"; \ >> 95 echo "** Consider installing the latest libtracefs from your"; \ >> 96 echo "** distribution, e.g., 'dnf install $(MISSING_PACKAGES)' on Fedora,"; \ >> 97 echo "** or from source:"; \ >> 98 echo "**"; \ >> 99 $(MISSING_SOURCE) \ >> 100 echo "**"; \ >> 101 echo "********************************************" >> 102 endef >> 103 >> 104 show_warnings: >> 105 $(call show_dependencies); >> 106 >> 107 ifneq ("$(WARNINGS)", "") >> 108 ERROR_OUT = $(error Please add the necessary dependencies) >> 109 >> 110 warnings: $(WARNINGS) >> 111 $(ERROR_OUT) >> 112 endif >> 113 >> 114 rtla: $(OBJ) >> 115 $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS) >> 116 >> 117 static: $(OBJ) >> 118 $(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl >> 119 >> 120 .PHONY: install >> 121 install: doc_install >> 122 $(MKDIR) -p $(DESTDIR)$(BINDIR) >> 123 $(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR) >> 124 $(STRIP) $(DESTDIR)$(BINDIR)/rtla >> 125 @test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise >> 126 ln -s rtla $(DESTDIR)$(BINDIR)/osnoise >> 127 @test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat >> 128 ln -s rtla $(DESTDIR)$(BINDIR)/timerlat >> 129 >> 130 .PHONY: clean tarball >> 131 clean: doc_clean >> 132 @test ! -f rtla || rm rtla >> 133 @test ! -f rtla-static || rm rtla-static >> 134 @test ! -f src/rtla.o || rm src/rtla.o >> 135 @test ! -f $(TARBALL) || rm -f $(TARBALL) >> 136 @rm -rf *~ $(OBJ) *.tar.$(CEXT) >> 137 >> 138 tarball: clean >> 139 rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION) >> 140 echo $(VERSION) > $(NAME)-$(VERSION)/VERSION >> 141 cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION) >> 142 mkdir $(NAME)-$(VERSION)/Documentation/ >> 143 cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/ >> 144 tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION) >> 145 rm -rf $(NAME)-$(VERSION) >> 146 >> 147 .PHONY: doc doc_clean doc_install >> 148 doc: >> 149 $(MAKE) -C $(DOCSRC) 77 150 78 $(RTLA_IN): fixdep FORCE !! 151 doc_clean: 79 make $(build)=rtla !! 152 $(MAKE) -C $(DOCSRC) clean 80 153 81 clean: doc_clean fixdep-clean !! 154 doc_install: 82 $(call QUIET_CLEAN, rtla) !! 155 $(MAKE) -C $(DOCSRC) install 83 $(Q)find . -name '*.o' -delete -o -nam << 84 $(Q)rm -f rtla rtla-static fixdep FEAT << 85 $(Q)rm -rf feature << 86 .PHONY: FORCE clean <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.