xref: /openbmc/linux/tools/tracing/rtla/Makefile (revision 3a9a6f3d)
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
26FOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
27		-fasynchronous-unwind-tables -fstack-clash-protection
28WOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
29
30TRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
31
32CFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS)
33LDFLAGS	:=	-ggdb
34LIBS	:=	$$($(PKG_CONFIG) --libs libtracefs) -lprocps
35
36SRC	:=	$(wildcard src/*.c)
37HDR	:=	$(wildcard src/*.h)
38OBJ	:=	$(SRC:.c=.o)
39DIRS	:=	src
40FILES	:=	Makefile README.txt
41CEXT	:=	bz2
42TARBALL	:=	$(NAME)-$(VERSION).tar.$(CEXT)
43TAROPTS	:=	-cvjf $(TARBALL)
44BINDIR	:=	/usr/bin
45DATADIR	:=	/usr/share
46DOCDIR	:=	$(DATADIR)/doc
47MANDIR	:=	$(DATADIR)/man
48LICDIR	:=	$(DATADIR)/licenses
49SRCTREE	:=	$(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
50
51# If running from the tarball, man pages are stored in the Documentation
52# dir. If running from the kernel source, man pages are stored in
53# Documentation/tools/rtla/.
54ifneq ($(wildcard Documentation/.*),)
55DOCSRC	=	Documentation/
56else
57DOCSRC	=	$(SRCTREE)/../../../Documentation/tools/rtla/
58endif
59
60.PHONY:	all
61all:	rtla
62
63rtla: $(OBJ)
64	$(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS)
65
66static: $(OBJ)
67	$(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl
68
69.PHONY: install
70install: doc_install
71	$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
72	$(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR)
73	$(STRIP) $(DESTDIR)$(BINDIR)/rtla
74	@test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise
75	ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/osnoise
76	@test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat
77	ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/timerlat
78
79.PHONY: clean tarball
80clean: doc_clean
81	@test ! -f rtla || rm rtla
82	@test ! -f rtla-static || rm rtla-static
83	@test ! -f src/rtla.o || rm src/rtla.o
84	@test ! -f $(TARBALL) || rm -f $(TARBALL)
85	@rm -rf *~ $(OBJ) *.tar.$(CEXT)
86
87tarball: clean
88	rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
89	echo $(VERSION) > $(NAME)-$(VERSION)/VERSION
90	cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
91	mkdir $(NAME)-$(VERSION)/Documentation/
92	cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/
93	tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
94	rm -rf $(NAME)-$(VERSION)
95
96.PHONY: doc doc_clean doc_install
97doc:
98	$(MAKE) -C $(DOCSRC)
99
100doc_clean:
101	$(MAKE) -C $(DOCSRC) clean
102
103doc_install:
104	$(MAKE) -C $(DOCSRC) install
105