blob: 2d52ff0bff7dadbd1154ed58395e9dd9922cca31 [file] [log] [blame]
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +01001NAME := 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
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010048SRCTREE := $(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
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010058
59.PHONY: all
60all: rtla
61
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010062rtla: $(OBJ) doc
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010063 $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS)
64
65static: $(OBJ)
66 $(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl
67
68.PHONY: install
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010069install: doc_install
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010070 $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
71 $(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR)
72 $(STRIP) $(DESTDIR)$(BINDIR)/rtla
Daniel Bristot de Oliveira0605bf02021-12-10 19:11:22 +010073 @test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise
74 ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/osnoise
Daniel Bristot de Oliveiraa828cd12021-12-10 19:11:25 +010075 @test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat
76 ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/timerlat
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010077
78.PHONY: clean tarball
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010079clean: doc_clean
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010080 @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
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010086tarball: clean
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010087 rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
88 cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010089 mkdir $(NAME)-$(VERSION)/Documentation/
90 cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/
Daniel Bristot de Oliveira79ce8f42021-12-10 19:11:20 +010091 tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
92 rm -rf $(NAME)-$(VERSION)
Daniel Bristot de Oliveirad40d48e2021-12-10 19:11:27 +010093
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