xref: /openbmc/linux/tools/tracing/rtla/Makefile (revision 5860800e)
1NAME	:=	rtla
2# Follow the kernel version
3VERSION :=	$(shell cat VERSION 2> /dev/null || make -sC ../../.. kernelversion)
4
5# From libtracefs:
6# Makefiles suck: This macro sets a default value of $(2) for the
7# variable named by $(1), unless the variable has been set by
8# environment or command line. This is necessary for CC and AR
9# because make sets default values, so the simpler ?= approach
10# won't work as expected.
11define allow-override
12  $(if $(or $(findstring environment,$(origin $(1))),\
13            $(findstring command line,$(origin $(1)))),,\
14    $(eval $(1) = $(2)))
15endef
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
25INSTALL	=	install
26MKDIR	=	mkdir
27FOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
28		-fasynchronous-unwind-tables -fstack-clash-protection
29WOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
30
31TRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
32
33CFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS)
34LDFLAGS	:=	-ggdb
35LIBS	:=	$$($(PKG_CONFIG) --libs libtracefs)
36
37SRC	:=	$(wildcard src/*.c)
38HDR	:=	$(wildcard src/*.h)
39OBJ	:=	$(SRC:.c=.o)
40DIRS	:=	src
41FILES	:=	Makefile README.txt
42CEXT	:=	bz2
43TARBALL	:=	$(NAME)-$(VERSION).tar.$(CEXT)
44TAROPTS	:=	-cvjf $(TARBALL)
45BINDIR	:=	/usr/bin
46DATADIR	:=	/usr/share
47DOCDIR	:=	$(DATADIR)/doc
48MANDIR	:=	$(DATADIR)/man
49LICDIR	:=	$(DATADIR)/licenses
50SRCTREE	:=	$(or $(BUILD_SRC),$(CURDIR))
51
52# If running from the tarball, man pages are stored in the Documentation
53# dir. If running from the kernel source, man pages are stored in
54# Documentation/tools/rtla/.
55ifneq ($(wildcard Documentation/.*),)
56DOCSRC	=	Documentation/
57else
58DOCSRC	=	$(SRCTREE)/../../../Documentation/tools/rtla/
59endif
60
61LIBTRACEEVENT_MIN_VERSION = 1.5
62LIBTRACEFS_MIN_VERSION = 1.3
63
64TEST_LIBTRACEEVENT = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEEVENT_MIN_VERSION) libtraceevent > /dev/null 2>&1 || echo n")
65ifeq ("$(TEST_LIBTRACEEVENT)", "n")
66.PHONY: warning_traceevent
67warning_traceevent:
68	@echo "********************************************"
69	@echo "** NOTICE: libtraceevent version $(LIBTRACEEVENT_MIN_VERSION) or higher not found"
70	@echo "**"
71	@echo "** Consider installing the latest libtraceevent from your"
72	@echo "** distribution, e.g., 'dnf install libtraceevent' on Fedora,"
73	@echo "** or from source:"
74	@echo "**"
75	@echo "**  https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git/ "
76	@echo "**"
77	@echo "********************************************"
78endif
79
80TEST_LIBTRACEFS = $(shell sh -c "$(PKG_CONFIG) --atleast-version $(LIBTRACEFS_MIN_VERSION) libtracefs > /dev/null 2>&1 || echo n")
81ifeq ("$(TEST_LIBTRACEFS)", "n")
82.PHONY: warning_tracefs
83warning_tracefs:
84	@echo "********************************************"
85	@echo "** NOTICE: libtracefs version $(LIBTRACEFS_MIN_VERSION) or higher not found"
86	@echo "**"
87	@echo "** Consider installing the latest libtracefs from your"
88	@echo "** distribution, e.g., 'dnf install libtracefs' on Fedora,"
89	@echo "** or from source:"
90	@echo "**"
91	@echo "**  https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/ "
92	@echo "**"
93	@echo "********************************************"
94endif
95
96.PHONY:	all
97all:	rtla
98
99rtla: $(OBJ)
100	$(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS)
101
102static: $(OBJ)
103	$(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl
104
105.PHONY: install
106install: doc_install
107	$(MKDIR) -p $(DESTDIR)$(BINDIR)
108	$(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR)
109	$(STRIP) $(DESTDIR)$(BINDIR)/rtla
110	@test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise
111	ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/osnoise
112	@test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat
113	ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/timerlat
114
115.PHONY: clean tarball
116clean: doc_clean
117	@test ! -f rtla || rm rtla
118	@test ! -f rtla-static || rm rtla-static
119	@test ! -f src/rtla.o || rm src/rtla.o
120	@test ! -f $(TARBALL) || rm -f $(TARBALL)
121	@rm -rf *~ $(OBJ) *.tar.$(CEXT)
122
123tarball: clean
124	rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
125	echo $(VERSION) > $(NAME)-$(VERSION)/VERSION
126	cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
127	mkdir $(NAME)-$(VERSION)/Documentation/
128	cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/
129	tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
130	rm -rf $(NAME)-$(VERSION)
131
132.PHONY: doc doc_clean doc_install
133doc:
134	$(MAKE) -C $(DOCSRC)
135
136doc_clean:
137	$(MAKE) -C $(DOCSRC) clean
138
139doc_install:
140	$(MAKE) -C $(DOCSRC) install
141