xref: /openbmc/linux/tools/tracing/rtla/Makefile (revision c595db6d7c8bcf87ef42204391fa890e5950e566)
179ce8f43SDaniel Bristot de OliveiraNAME	:=	rtla
28619e328SDaniel Bristot de Oliveira# Follow the kernel version
3c7d8a598SDaniel Bristot de OliveiraVERSION :=	$(shell cat VERSION 2> /dev/null || make -sC ../../.. kernelversion | grep -v make)
479ce8f43SDaniel Bristot de Oliveira
579ce8f43SDaniel Bristot de Oliveira# From libtracefs:
679ce8f43SDaniel Bristot de Oliveira# Makefiles suck: This macro sets a default value of $(2) for the
779ce8f43SDaniel Bristot de Oliveira# variable named by $(1), unless the variable has been set by
879ce8f43SDaniel Bristot de Oliveira# environment or command line. This is necessary for CC and AR
979ce8f43SDaniel Bristot de Oliveira# because make sets default values, so the simpler ?= approach
1079ce8f43SDaniel Bristot de Oliveira# won't work as expected.
1179ce8f43SDaniel Bristot de Oliveiradefine allow-override
1279ce8f43SDaniel Bristot de Oliveira  $(if $(or $(findstring environment,$(origin $(1))),\
1379ce8f43SDaniel Bristot de Oliveira            $(findstring command line,$(origin $(1)))),,\
1479ce8f43SDaniel Bristot de Oliveira    $(eval $(1) = $(2)))
1579ce8f43SDaniel Bristot de Oliveiraendef
1679ce8f43SDaniel Bristot de Oliveira
1779ce8f43SDaniel Bristot de Oliveira# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
1879ce8f43SDaniel Bristot de Oliveira$(call allow-override,CC,$(CROSS_COMPILE)gcc)
1979ce8f43SDaniel Bristot de Oliveira$(call allow-override,AR,$(CROSS_COMPILE)ar)
2079ce8f43SDaniel Bristot de Oliveira$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
2179ce8f43SDaniel Bristot de Oliveira$(call allow-override,PKG_CONFIG,pkg-config)
2279ce8f43SDaniel Bristot de Oliveira$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
2379ce8f43SDaniel Bristot de Oliveira$(call allow-override,LDCONFIG,ldconfig)
2479ce8f43SDaniel Bristot de Oliveira
2579ce8f43SDaniel Bristot de OliveiraINSTALL	=	install
2639c3d84cSJohn KacurMKDIR	=	mkdir
2779ce8f43SDaniel Bristot de OliveiraFOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
2879ce8f43SDaniel Bristot de Oliveira		-fasynchronous-unwind-tables -fstack-clash-protection
2979ce8f43SDaniel Bristot de OliveiraWOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
3079ce8f43SDaniel Bristot de Oliveira
31*02afaeb6SDaniel Bristot de Oliveiraifeq ($(CC),clang)
32*02afaeb6SDaniel Bristot de Oliveira  FOPTS := $(filter-out -ffat-lto-objects, $(FOPTS))
33*02afaeb6SDaniel Bristot de Oliveira  WOPTS := $(filter-out -Wno-maybe-uninitialized, $(WOPTS))
34*02afaeb6SDaniel Bristot de Oliveiraendif
35*02afaeb6SDaniel Bristot de Oliveira
3679ce8f43SDaniel Bristot de OliveiraTRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
3779ce8f43SDaniel Bristot de Oliveira
381a7b22abSBen HutchingsCFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) $(EXTRA_CFLAGS)
39*02afaeb6SDaniel Bristot de OliveiraLDFLAGS	:=	-flto=auto -ggdb $(EXTRA_LDFLAGS)
40dada03dbSDaniel Bristot de OliveiraLIBS	:=	$$($(PKG_CONFIG) --libs libtracefs)
4179ce8f43SDaniel Bristot de Oliveira
4279ce8f43SDaniel Bristot de OliveiraSRC	:=	$(wildcard src/*.c)
4379ce8f43SDaniel Bristot de OliveiraHDR	:=	$(wildcard src/*.h)
4479ce8f43SDaniel Bristot de OliveiraOBJ	:=	$(SRC:.c=.o)
4579ce8f43SDaniel Bristot de OliveiraDIRS	:=	src
4679ce8f43SDaniel Bristot de OliveiraFILES	:=	Makefile README.txt
4779ce8f43SDaniel Bristot de OliveiraCEXT	:=	bz2
4879ce8f43SDaniel Bristot de OliveiraTARBALL	:=	$(NAME)-$(VERSION).tar.$(CEXT)
4979ce8f43SDaniel Bristot de OliveiraTAROPTS	:=	-cvjf $(TARBALL)
5079ce8f43SDaniel Bristot de OliveiraBINDIR	:=	/usr/bin
5179ce8f43SDaniel Bristot de OliveiraDATADIR	:=	/usr/share
5279ce8f43SDaniel Bristot de OliveiraDOCDIR	:=	$(DATADIR)/doc
5379ce8f43SDaniel Bristot de OliveiraMANDIR	:=	$(DATADIR)/man
5479ce8f43SDaniel Bristot de OliveiraLICDIR	:=	$(DATADIR)/licenses
555c816641SMasahiro YamadaSRCTREE	:=	$(or $(BUILD_SRC),$(CURDIR))
56d40d48e1SDaniel Bristot de Oliveira
57d40d48e1SDaniel Bristot de Oliveira# If running from the tarball, man pages are stored in the Documentation
58d40d48e1SDaniel Bristot de Oliveira# dir. If running from the kernel source, man pages are stored in
59d40d48e1SDaniel Bristot de Oliveira# Documentation/tools/rtla/.
60d40d48e1SDaniel Bristot de Oliveiraifneq ($(wildcard Documentation/.*),)
61d40d48e1SDaniel Bristot de OliveiraDOCSRC	=	Documentation/
62d40d48e1SDaniel Bristot de Oliveiraelse
63d40d48e1SDaniel Bristot de OliveiraDOCSRC	=	$(SRCTREE)/../../../Documentation/tools/rtla/
64d40d48e1SDaniel Bristot de Oliveiraendif
6579ce8f43SDaniel Bristot de Oliveira
66fe4d0d5dSDaniel Bristot de OliveiraLIBTRACEEVENT_MIN_VERSION = 1.5
67fe4d0d5dSDaniel Bristot de OliveiraLIBTRACEFS_MIN_VERSION = 1.3
68fe4d0d5dSDaniel Bristot de Oliveira
6920aec89aSSteven Rostedt (Google).PHONY:	all warnings show_warnings
7020aec89aSSteven Rostedt (Google)all:	warnings rtla
7120aec89aSSteven Rostedt (Google)
72fe4d0d5dSDaniel Bristot de OliveiraTEST_LIBTRACEEVENT = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 || echo n")
73fe4d0d5dSDaniel Bristot de Oliveiraifeq ("$(TEST_LIBTRACEEVENT)", "n")
7420aec89aSSteven Rostedt (Google)WARNINGS = show_warnings
7520aec89aSSteven Rostedt (Google)MISSING_LIBS += echo "**   libtraceevent version $(LIBTRACEEVENT_MIN_VERSION) or higher";
7620aec89aSSteven Rostedt (Google)MISSING_PACKAGES += "libtraceevent-devel"
7720aec89aSSteven Rostedt (Google)MISSING_SOURCE += echo "**  https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ ";
78fe4d0d5dSDaniel Bristot de Oliveiraendif
79fe4d0d5dSDaniel Bristot de Oliveira
80fe4d0d5dSDaniel Bristot de OliveiraTEST_LIBTRACEFS = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) libtracefs > /dev/null 2>&1 || echo n")
81fe4d0d5dSDaniel Bristot de Oliveiraifeq ("$(TEST_LIBTRACEFS)", "n")
8220aec89aSSteven Rostedt (Google)WARNINGS = show_warnings
8320aec89aSSteven Rostedt (Google)MISSING_LIBS += echo "**   libtracefs version $(LIBTRACEFS_MIN_VERSION) or higher";
8420aec89aSSteven Rostedt (Google)MISSING_PACKAGES += "libtracefs-devel"
8520aec89aSSteven Rostedt (Google)MISSING_SOURCE += echo "**  https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ ";
86fe4d0d5dSDaniel Bristot de Oliveiraendif
87fe4d0d5dSDaniel Bristot de Oliveira
8820aec89aSSteven Rostedt (Google)define show_dependencies
8920aec89aSSteven Rostedt (Google)	@echo "********************************************";				\
9020aec89aSSteven Rostedt (Google)	echo "** NOTICE: Failed build dependencies";					\
9120aec89aSSteven Rostedt (Google)	echo "**";									\
9220aec89aSSteven Rostedt (Google)	echo "** Required Libraries:";							\
9320aec89aSSteven Rostedt (Google)	$(MISSING_LIBS)									\
9420aec89aSSteven Rostedt (Google)	echo "**";									\
9520aec89aSSteven Rostedt (Google)	echo "** Consider installing the latest libtracefs from your";			\
9620aec89aSSteven Rostedt (Google)	echo "** distribution, e.g., 'dnf install $(MISSING_PACKAGES)' on Fedora,";	\
9720aec89aSSteven Rostedt (Google)	echo "** or from source:";							\
9820aec89aSSteven Rostedt (Google)	echo "**";									\
9920aec89aSSteven Rostedt (Google)	$(MISSING_SOURCE)								\
10020aec89aSSteven Rostedt (Google)	echo "**";									\
10120aec89aSSteven Rostedt (Google)	echo "********************************************"
10220aec89aSSteven Rostedt (Google)endef
10320aec89aSSteven Rostedt (Google)
10420aec89aSSteven Rostedt (Google)show_warnings:
10520aec89aSSteven Rostedt (Google)	$(call show_dependencies);
10620aec89aSSteven Rostedt (Google)
10720aec89aSSteven Rostedt (Google)ifneq ("$(WARNINGS)", "")
10820aec89aSSteven Rostedt (Google)ERROR_OUT = $(error Please add the necessary dependencies)
10920aec89aSSteven Rostedt (Google)
11020aec89aSSteven Rostedt (Google)warnings: $(WARNINGS)
11120aec89aSSteven Rostedt (Google)	$(ERROR_OUT)
11220aec89aSSteven Rostedt (Google)endif
11379ce8f43SDaniel Bristot de Oliveira
1142201aea1SShuah Khanrtla: $(OBJ)
11579ce8f43SDaniel Bristot de Oliveira	$(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS)
11679ce8f43SDaniel Bristot de Oliveira
11779ce8f43SDaniel Bristot de Oliveirastatic: $(OBJ)
11879ce8f43SDaniel Bristot de Oliveira	$(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl
11979ce8f43SDaniel Bristot de Oliveira
12079ce8f43SDaniel Bristot de Oliveira.PHONY: install
121d40d48e1SDaniel Bristot de Oliveirainstall: doc_install
12239c3d84cSJohn Kacur	$(MKDIR) -p $(DESTDIR)$(BINDIR)
12379ce8f43SDaniel Bristot de Oliveira	$(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR)
12479ce8f43SDaniel Bristot de Oliveira	$(STRIP) $(DESTDIR)$(BINDIR)/rtla
1250605bf00SDaniel Bristot de Oliveira	@test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise
126ff5a55dcSBen Hutchings	ln -s rtla $(DESTDIR)$(BINDIR)/osnoise
1271f428356SDaniel Bristot de Oliveira	@test ! -f $(DESTDIR)$(BINDIR)/hwnoise || rm $(DESTDIR)$(BINDIR)/hwnoise
1281f428356SDaniel Bristot de Oliveira	ln -s rtla $(DESTDIR)$(BINDIR)/hwnoise
129a828cd18SDaniel Bristot de Oliveira	@test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat
130ff5a55dcSBen Hutchings	ln -s rtla $(DESTDIR)$(BINDIR)/timerlat
13179ce8f43SDaniel Bristot de Oliveira
13279ce8f43SDaniel Bristot de Oliveira.PHONY: clean tarball
133d40d48e1SDaniel Bristot de Oliveiraclean: doc_clean
13479ce8f43SDaniel Bristot de Oliveira	@test ! -f rtla || rm rtla
13579ce8f43SDaniel Bristot de Oliveira	@test ! -f rtla-static || rm rtla-static
13679ce8f43SDaniel Bristot de Oliveira	@test ! -f src/rtla.o || rm src/rtla.o
13779ce8f43SDaniel Bristot de Oliveira	@test ! -f $(TARBALL) || rm -f $(TARBALL)
13879ce8f43SDaniel Bristot de Oliveira	@rm -rf *~ $(OBJ) *.tar.$(CEXT)
13979ce8f43SDaniel Bristot de Oliveira
14079ce8f43SDaniel Bristot de Oliveiratarball: clean
14179ce8f43SDaniel Bristot de Oliveira	rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
1428619e328SDaniel Bristot de Oliveira	echo $(VERSION) > $(NAME)-$(VERSION)/VERSION
14379ce8f43SDaniel Bristot de Oliveira	cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
144d40d48e1SDaniel Bristot de Oliveira	mkdir $(NAME)-$(VERSION)/Documentation/
145d40d48e1SDaniel Bristot de Oliveira	cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/
14679ce8f43SDaniel Bristot de Oliveira	tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
14779ce8f43SDaniel Bristot de Oliveira	rm -rf $(NAME)-$(VERSION)
148d40d48e1SDaniel Bristot de Oliveira
149d40d48e1SDaniel Bristot de Oliveira.PHONY: doc doc_clean doc_install
150d40d48e1SDaniel Bristot de Oliveiradoc:
151d40d48e1SDaniel Bristot de Oliveira	$(MAKE) -C $(DOCSRC)
152d40d48e1SDaniel Bristot de Oliveira
153d40d48e1SDaniel Bristot de Oliveiradoc_clean:
154d40d48e1SDaniel Bristot de Oliveira	$(MAKE) -C $(DOCSRC) clean
155d40d48e1SDaniel Bristot de Oliveira
156d40d48e1SDaniel Bristot de Oliveiradoc_install:
157d40d48e1SDaniel Bristot de Oliveira	$(MAKE) -C $(DOCSRC) install
158