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. |
Masahiro Yamada | b61442d | 2021-04-16 22:00:51 +0900 | [diff] [blame] | 3 | include ../../build/Build.include |
Markus Mayer | ec04aa3 | 2017-09-27 16:02:35 -0700 | [diff] [blame] | 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 |
Rolf Eike Beer | b5f7912 | 2021-07-30 13:51:54 +0200 | [diff] [blame] | 13 | PKG_CONFIG?= $(CROSS_COMPILE)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 | TARGET=tmon |
| 17 | |
| 18 | INSTALL_PROGRAM=install -m 755 -p |
| 19 | DEL_FILE=rm -f |
| 20 | |
Brian Norris | 96a0d99 | 2015-02-17 18:18:35 -0800 | [diff] [blame] | 21 | # Static builds might require -ltinfo, for instance |
| 22 | ifneq ($(findstring -static, $(LDFLAGS)),) |
| 23 | STATIC := --static |
| 24 | endif |
| 25 | |
| 26 | TMON_LIBS=-lm -lpthread |
Markus Mayer | 501a5c7 | 2017-09-27 16:02:37 -0700 | [diff] [blame] | 27 | TMON_LIBS += $(shell $(PKG_CONFIG) --libs $(STATIC) panelw ncursesw 2> /dev/null || \ |
| 28 | $(PKG_CONFIG) --libs $(STATIC) panel ncurses 2> /dev/null || \ |
Brian Norris | 96a0d99 | 2015-02-17 18:18:35 -0800 | [diff] [blame] | 29 | echo -lpanel -lncurses) |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 30 | |
Jiri Olsa | ad6b474 | 2018-12-12 11:25:33 +0100 | [diff] [blame] | 31 | override CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \ |
Markus Mayer | 501a5c7 | 2017-09-27 16:02:37 -0700 | [diff] [blame] | 32 | $(PKG_CONFIG) --cflags $(STATIC) panel ncurses 2> /dev/null) |
Olaf Hering | 809b6ec | 2015-10-02 09:50:45 +0000 | [diff] [blame] | 33 | |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 34 | OBJS = tmon.o tui.o sysfs.o pid.o |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 35 | |
| 36 | tmon: $(OBJS) Makefile tmon.h |
Brian Norris | 96a0d99 | 2015-02-17 18:18:35 -0800 | [diff] [blame] | 37 | $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS) |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 38 | |
| 39 | valgrind: tmon |
| 40 | sudo valgrind -v --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes ./$(TARGET) 1> /dev/null |
| 41 | |
| 42 | install: |
Rolf Eike Beer | 99d88c3 | 2021-07-30 13:49:04 +0200 | [diff] [blame] | 43 | - $(INSTALL_PROGRAM) -D "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 44 | |
| 45 | uninstall: |
| 46 | $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 47 | |
| 48 | clean: |
Rolf Eike Beer | 99d88c3 | 2021-07-30 13:49:04 +0200 | [diff] [blame] | 49 | rm -f $(TARGET) $(OBJS) |
Jacob Pan | 94f6996 | 2013-10-14 16:02:27 -0700 | [diff] [blame] | 50 | |
| 51 | dist: |
| 52 | git tag v$(VERSION) |
| 53 | git archive --format=tar --prefix="$(TARGET)-$(VERSION)/" v$(VERSION) | \ |
| 54 | gzip > $(TARGET)-$(VERSION).tar.gz |