Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Markus Mayer | ec04aa3 | 2017-09-27 16:02:35 -0700 | [diff] [blame] | 2 | # We need this for the "cc-option" macro. |
| 3 | include ../../../scripts/Kbuild.include |
| 4 | |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 5 | VERSION = 1.0 |
| 6 | |
| 7 | BINDIR=usr/bin |
| 8 | WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int |
Jiri Olsa | 302df34 | 2019-01-03 17:13:49 +0100 | [diff] [blame] | 9 | override CFLAGS+= $(call cc-option,-O3,-O1) ${WARNFLAGS} |
Markus Mayer | ec04aa3 | 2017-09-27 16:02:35 -0700 | [diff] [blame] | 10 | # Add "-fstack-protector" only if toolchain supports it. |
Jiri Olsa | ad6b474 | 2018-12-12 11:25:33 +0100 | [diff] [blame] | 11 | override CFLAGS+= $(call cc-option,-fstack-protector-strong) |
Markus Mayer | c21568f | 2017-09-27 16:02:36 -0700 | [diff] [blame] | 12 | CC?= $(CROSS_COMPILE)gcc |
Markus Mayer | 501a5c7 | 2017-09-27 16:02:37 -0700 | [diff] [blame] | 13 | PKG_CONFIG?= pkg-config |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 14 | |
Jiri Olsa | ad6b474 | 2018-12-12 11:25:33 +0100 | [diff] [blame] | 15 | override CFLAGS+=-D VERSION=\"$(VERSION)\" |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 16 | LDFLAGS+= |
| 17 | TARGET=tmon |
| 18 | |
| 19 | INSTALL_PROGRAM=install -m 755 -p |
| 20 | DEL_FILE=rm -f |
| 21 | |
Brian Norris | 96a0d99 | 2015-02-17 18:18:35 -0800 | [diff] [blame] | 22 | # Static builds might require -ltinfo, for instance |
| 23 | ifneq ($(findstring -static, $(LDFLAGS)),) |
| 24 | STATIC := --static |
| 25 | endif |
| 26 | |
| 27 | TMON_LIBS=-lm -lpthread |
Markus Mayer | 501a5c7 | 2017-09-27 16:02:37 -0700 | [diff] [blame] | 28 | TMON_LIBS += $(shell $(PKG_CONFIG) --libs $(STATIC) panelw ncursesw 2> /dev/null || \ |
| 29 | $(PKG_CONFIG) --libs $(STATIC) panel ncurses 2> /dev/null || \ |
Brian Norris | 96a0d99 | 2015-02-17 18:18:35 -0800 | [diff] [blame] | 30 | echo -lpanel -lncurses) |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 31 | |
Jiri Olsa | ad6b474 | 2018-12-12 11:25:33 +0100 | [diff] [blame] | 32 | override CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \ |
Markus Mayer | 501a5c7 | 2017-09-27 16:02:37 -0700 | [diff] [blame] | 33 | $(PKG_CONFIG) --cflags $(STATIC) panel ncurses 2> /dev/null) |
Olaf Hering | 809b6ec | 2015-10-02 09:50:45 +0000 | [diff] [blame] | 34 | |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 35 | OBJS = tmon.o tui.o sysfs.o pid.o |
| 36 | OBJS += |
| 37 | |
| 38 | tmon: $(OBJS) Makefile tmon.h |
Brian Norris | 96a0d99 | 2015-02-17 18:18:35 -0800 | [diff] [blame] | 39 | $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS) |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 40 | |
| 41 | valgrind: tmon |
| 42 | sudo valgrind -v --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./$(TARGET) 1> /dev/null |
| 43 | |
| 44 | install: |
| 45 | - mkdir -p $(INSTALL_ROOT)/$(BINDIR) |
| 46 | - $(INSTALL_PROGRAM) "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 47 | |
| 48 | uninstall: |
| 49 | $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 50 | |
| 51 | clean: |
| 52 | find . -name "*.o" | xargs $(DEL_FILE) |
| 53 | rm -f $(TARGET) |
| 54 | |
| 55 | dist: |
| 56 | git tag v$(VERSION) |
| 57 | git archive --format=tar --prefix="$(TARGET)-$(VERSION)/" v$(VERSION) | \ |
| 58 | gzip > $(TARGET)-$(VERSION).tar.gz |