Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 1 | NAME := rtla |
| 2 | VERSION := 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. |
| 10 | define allow-override |
| 11 | $(if $(or $(findstring environment,$(origin $(1))),\ |
| 12 | $(findstring command line,$(origin $(1)))),,\ |
| 13 | $(eval $(1) = $(2))) |
| 14 | endef |
| 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 | |
| 24 | INSTALL = install |
| 25 | FOPTS := -flto=auto -ffat-lto-objects -fexceptions -fstack-protector-strong \ |
| 26 | -fasynchronous-unwind-tables -fstack-clash-protection |
| 27 | WOPTS := -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -Wno-maybe-uninitialized |
| 28 | |
| 29 | TRACEFS_HEADERS := $$($(PKG_CONFIG) --cflags libtracefs) |
| 30 | |
| 31 | CFLAGS := -O -g -DVERSION=\"$(VERSION)\" $(FOPTS) $(MOPTS) $(WOPTS) $(TRACEFS_HEADERS) |
| 32 | LDFLAGS := -ggdb |
| 33 | LIBS := $$($(PKG_CONFIG) --libs libtracefs) -lprocps |
| 34 | |
| 35 | SRC := $(wildcard src/*.c) |
| 36 | HDR := $(wildcard src/*.h) |
| 37 | OBJ := $(SRC:.c=.o) |
| 38 | DIRS := src |
| 39 | FILES := Makefile README.txt |
| 40 | CEXT := bz2 |
| 41 | TARBALL := $(NAME)-$(VERSION).tar.$(CEXT) |
| 42 | TAROPTS := -cvjf $(TARBALL) |
| 43 | BINDIR := /usr/bin |
| 44 | DATADIR := /usr/share |
| 45 | DOCDIR := $(DATADIR)/doc |
| 46 | MANDIR := $(DATADIR)/man |
| 47 | LICDIR := $(DATADIR)/licenses |
Daniel Bristot de Oliveira | d40d48e | 2021-12-10 19:11:27 +0100 | [diff] [blame] | 48 | SRCTREE := $(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/. |
| 53 | ifneq ($(wildcard Documentation/.*),) |
| 54 | DOCSRC = Documentation/ |
| 55 | else |
| 56 | DOCSRC = $(SRCTREE)/../../../Documentation/tools/rtla/ |
| 57 | endif |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 58 | |
| 59 | .PHONY: all |
| 60 | all: rtla |
| 61 | |
Shuah Khan | 2201aea | 2022-01-25 17:13:01 -0700 | [diff] [blame] | 62 | rtla: $(OBJ) |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 63 | $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS) |
| 64 | |
| 65 | static: $(OBJ) |
| 66 | $(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl |
| 67 | |
| 68 | .PHONY: install |
Daniel Bristot de Oliveira | d40d48e | 2021-12-10 19:11:27 +0100 | [diff] [blame] | 69 | install: doc_install |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 70 | $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) |
| 71 | $(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR) |
| 72 | $(STRIP) $(DESTDIR)$(BINDIR)/rtla |
Daniel Bristot de Oliveira | 0605bf0 | 2021-12-10 19:11:22 +0100 | [diff] [blame] | 73 | @test ! -f $(DESTDIR)$(BINDIR)/osnoise || rm $(DESTDIR)$(BINDIR)/osnoise |
| 74 | ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/osnoise |
Daniel Bristot de Oliveira | a828cd1 | 2021-12-10 19:11:25 +0100 | [diff] [blame] | 75 | @test ! -f $(DESTDIR)$(BINDIR)/timerlat || rm $(DESTDIR)$(BINDIR)/timerlat |
| 76 | ln -s $(DESTDIR)$(BINDIR)/rtla $(DESTDIR)$(BINDIR)/timerlat |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 77 | |
| 78 | .PHONY: clean tarball |
Daniel Bristot de Oliveira | d40d48e | 2021-12-10 19:11:27 +0100 | [diff] [blame] | 79 | clean: doc_clean |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 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 | |
Daniel Bristot de Oliveira | d40d48e | 2021-12-10 19:11:27 +0100 | [diff] [blame] | 86 | tarball: clean |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 87 | rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION) |
| 88 | cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION) |
Daniel Bristot de Oliveira | d40d48e | 2021-12-10 19:11:27 +0100 | [diff] [blame] | 89 | mkdir $(NAME)-$(VERSION)/Documentation/ |
| 90 | cp -rp $(SRCTREE)/../../../Documentation/tools/rtla/* $(NAME)-$(VERSION)/Documentation/ |
Daniel Bristot de Oliveira | 79ce8f4 | 2021-12-10 19:11:20 +0100 | [diff] [blame] | 91 | tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION) |
| 92 | rm -rf $(NAME)-$(VERSION) |
Daniel Bristot de Oliveira | d40d48e | 2021-12-10 19:11:27 +0100 | [diff] [blame] | 93 | |
| 94 | .PHONY: doc doc_clean doc_install |
| 95 | doc: |
| 96 | $(MAKE) -C $(DOCSRC) |
| 97 | |
| 98 | doc_clean: |
| 99 | $(MAKE) -C $(DOCSRC) clean |
| 100 | |
| 101 | doc_install: |
| 102 | $(MAKE) -C $(DOCSRC) install |