blob: 56b1bdd60c966628db225dc07b12d91819f1b8b4 [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
48
49.PHONY: all
50all: rtla
51
52rtla: $(OBJ)
53 $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS)
54
55static: $(OBJ)
56 $(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl
57
58.PHONY: install
59install:
60 $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
61 $(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR)
62 $(STRIP) $(DESTDIR)$(BINDIR)/rtla
63
64.PHONY: clean tarball
65clean:
66 @test ! -f rtla || rm rtla
67 @test ! -f rtla-static || rm rtla-static
68 @test ! -f src/rtla.o || rm src/rtla.o
69 @test ! -f $(TARBALL) || rm -f $(TARBALL)
70 @rm -rf *~ $(OBJ) *.tar.$(CEXT)
71
72tarball: clean
73 rm -rf $(NAME)-$(VERSION) && mkdir $(NAME)-$(VERSION)
74 cp -r $(DIRS) $(FILES) $(NAME)-$(VERSION)
75 tar $(TAROPTS) --exclude='*~' $(NAME)-$(VERSION)
76 rm -rf $(NAME)-$(VERSION)