xref: /openbmc/linux/tools/tracing/rtla/Makefile (revision 72113d0a)
1NAME	:=	rtla
2VERSION	:=	0.5
3
4# From libtracefs:
5# Makefiles suck: This macro sets a default value of $(2) for the
6# variable named by $(1), unless the variable has been set by
7# environment or command line. This is necessary for CC and AR
8# because make sets default values, so the simpler ?= approach
9# won't work as expected.
10define allow-override
11  $(if $(or $(findstring environment,$(origin $(1))),\
12            $(findstring command line,$(origin $(1)))),,\
13    $(eval $(1) = $(2)))
14endef
15
16# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
17$(call allow-override,CC,$(CROSS_COMPILE)gcc)
18$(call allow-override,AR,$(CROSS_COMPILE)ar)
19$(call allow-override,STRIP,$(CROSS_COMPILE)strip)
20$(call allow-override,PKG_CONFIG,pkg-config)
21$(call allow-override,LD_SO_CONF_PATH,/etc/ld.so.conf.d/)
22$(call allow-override,LDCONFIG,ldconfig)
23
24INSTALL	=	install
25FOPTS	:=	-flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \
26		-fasynchronous-unwind-tables -fstack-clash-protection
27WOPTS	:= 	-Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized
28
29TRACEFS_HEADERS	:= $$($(PKG_CONFIG) --cflags libtracefs)
30
31CFLAGS	:=	-O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS)
32LDFLAGS	:=	-ggdb
33LIBS	:=	$$($(PKG_CONFIG) --libs libtracefs) -lprocps
34
35SRC	:=	$(wildcard src/*.c)
36HDR	:=	$(wildcard src/*.h)
37OBJ	:=	$(SRC:.c=.o)
38DIRS	:=	src
39FILES	:=	Makefile README.txt
40CEXT	:=	bz2
41TARBALL	:=	$(NAME)-$(VERSION).tar.$(CEXT)
42TAROPTS	:=	-cvjf $(TARBALL)
43BINDIR	:=	/usr/bin
44DATADIR	:=	/usr/share
45DOCDIR	:=	$(DATADIR)/doc
46MANDIR	:=	$(DATADIR)/man
47LICDIR	:=	$(DATADIR)/licenses
48SRCTREE	:=	$(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
49
50# If running from the tarball, man pages are stored in the Documentation
51# dir. If running from the kernel source, man pages are stored in
52# Documentation/tools/rtla/.
53ifneq ($(wildcard Documentation/.*),)
54DOCSRC	=	Documentation/
55else
56DOCSRC	=	$(SRCTREE)/../../../Documentation/tools/rtla/
57endif
58
59.PHONY:	all
60all:	rtla
61
62rtla: $(OBJ)
63	$(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS)
64
65static: $(OBJ)
66	$(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl
67
68.PHONY: install
69install: doc_install
70	$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
71	$(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR)
72	$(STRIP) $(DESTDIR)$(BINDIR)/rtla
73	@test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise
74	ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/osnoise
75	@test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat
76	ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/timerlat
77
78.PHONY: clean tarball
79clean: doc_clean
80	@test ! -f rtla || rm rtla
81	@test ! -f rtla-static || rm rtla-static
82	@test ! -f src/rtla.o || rm src/rtla.o
83	@test ! -f $(TARBALL) || rm -f $(TARBALL)
84	@rm -rf *~ $(OBJ) *.tar.$(CEXT)
85
86tarball: clean
87	rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
88	cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
89	mkdir $(NAME)-$(VERSION)/Documentation/
90	cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/
91	tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
92	rm -rf $(NAME)-$(VERSION)
93
94.PHONY: doc doc_clean doc_install
95doc:
96	$(MAKE) -C $(DOCSRC)
97
98doc_clean:
99	$(MAKE) -C $(DOCSRC) clean
100
101doc_install:
102	$(MAKE) -C $(DOCSRC) install
103