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 |
| 48 | |
| 49 | .PHONY: all |
| 50 | all: rtla |
| 51 | |
| 52 | rtla: $(OBJ) |
| 53 | $(CC) -o rtla $(LDFLAGS) $(OBJ) $(LIBS) |
| 54 | |
| 55 | static: $(OBJ) |
| 56 | $(CC) -o rtla-static $(LDFLAGS) --static $(OBJ) $(LIBS) -lpthread -ldl |
| 57 | |
| 58 | .PHONY: install |
| 59 | install: |
| 60 | $(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR) |
| 61 | $(INSTALL) rtla -m 755 $(DESTDIR)$(BINDIR) |
| 62 | $(STRIP) $(DESTDIR)$(BINDIR)/rtla |
| 63 | |
| 64 | .PHONY: clean tarball |
| 65 | clean: |
| 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 | |
| 72 | tarball: 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) |