blob: f9c52b7fab7bcc9b15f3e7aa09702f64b8eee75b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Markus Mayerec04aa32017-09-27 16:02:35 -07002# We need this for the "cc-option" macro.
Masahiro Yamadab61442d2021-04-16 22:00:51 +09003include ../../build/Build.include
Markus Mayerec04aa32017-09-27 16:02:35 -07004
Jacob Pan94f69962013-10-14 16:02:27 -07005VERSION = 1.0
6
7BINDIR=usr/bin
8WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int
Jiri Olsa302df342019-01-03 17:13:49 +01009override CFLAGS+= $(call cc-option,-O3,-O1) ${WARNFLAGS}
Markus Mayerec04aa32017-09-27 16:02:35 -070010# Add "-fstack-protector" only if toolchain supports it.
Jiri Olsaad6b4742018-12-12 11:25:33 +010011override CFLAGS+= $(call cc-option,-fstack-protector-strong)
Markus Mayerc21568f2017-09-27 16:02:36 -070012CC?= $(CROSS_COMPILE)gcc
Rolf Eike Beerb5f79122021-07-30 13:51:54 +020013PKG_CONFIG?= $(CROSS_COMPILE)pkg-config
Jacob Pan94f69962013-10-14 16:02:27 -070014
Jiri Olsaad6b4742018-12-12 11:25:33 +010015override CFLAGS+=-D VERSION=\"$(VERSION)\"
Jacob Pan94f69962013-10-14 16:02:27 -070016TARGET=tmon
17
18INSTALL_PROGRAM=install -m 755 -p
19DEL_FILE=rm -f
20
Brian Norris96a0d992015-02-17 18:18:35 -080021# Static builds might require -ltinfo, for instance
22ifneq ($(findstring -static, $(LDFLAGS)),)
23STATIC := --static
24endif
25
26TMON_LIBS=-lm -lpthread
Markus Mayer501a5c72017-09-27 16:02:37 -070027TMON_LIBS += $(shell $(PKG_CONFIG) --libs $(STATIC) panelw ncursesw 2> /dev/null || \
28 $(PKG_CONFIG) --libs $(STATIC) panel ncurses 2> /dev/null || \
Brian Norris96a0d992015-02-17 18:18:35 -080029 echo -lpanel -lncurses)
Jacob Pan94f69962013-10-14 16:02:27 -070030
Jiri Olsaad6b4742018-12-12 11:25:33 +010031override CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \
Markus Mayer501a5c72017-09-27 16:02:37 -070032 $(PKG_CONFIG) --cflags $(STATIC) panel ncurses 2> /dev/null)
Olaf Hering809b6ec2015-10-02 09:50:45 +000033
Jacob Pan94f69962013-10-14 16:02:27 -070034OBJS = tmon.o tui.o sysfs.o pid.o
Jacob Pan94f69962013-10-14 16:02:27 -070035
36tmon: $(OBJS) Makefile tmon.h
Brian Norris96a0d992015-02-17 18:18:35 -080037 $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS)
Jacob Pan94f69962013-10-14 16:02:27 -070038
39valgrind: 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
42install:
Rolf Eike Beer99d88c32021-07-30 13:49:04 +020043 - $(INSTALL_PROGRAM) -D "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)"
Jacob Pan94f69962013-10-14 16:02:27 -070044
45uninstall:
46 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)"
Jacob Pan94f69962013-10-14 16:02:27 -070047
48clean:
Rolf Eike Beer99d88c32021-07-30 13:49:04 +020049 rm -f $(TARGET) $(OBJS)
Jacob Pan94f69962013-10-14 16:02:27 -070050
51dist:
52 git tag v$(VERSION)
53 git archive --format=tar --prefix="$(TARGET)-$(VERSION)/" v$(VERSION) | \
54 gzip > $(TARGET)-$(VERSION).tar.gz