blob: 735a510230c3f606d8939362e7a718555564b78d [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.
3include ../../../scripts/Kbuild.include
4
Jacob Pan94f69962013-10-14 16:02:27 -07005VERSION = 1.0
6
7BINDIR=usr/bin
8WARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int
Markus Mayerec04aa32017-09-27 16:02:35 -07009CFLAGS+= -O1 ${WARNFLAGS}
10# Add "-fstack-protector" only if toolchain supports it.
11CFLAGS+= $(call cc-option,-fstack-protector)
Markus Mayerc21568f2017-09-27 16:02:36 -070012CC?= $(CROSS_COMPILE)gcc
Markus Mayer501a5c72017-09-27 16:02:37 -070013PKG_CONFIG?= pkg-config
Jacob Pan94f69962013-10-14 16:02:27 -070014
15CFLAGS+=-D VERSION=\"$(VERSION)\"
16LDFLAGS+=
17TARGET=tmon
18
19INSTALL_PROGRAM=install -m 755 -p
20DEL_FILE=rm -f
21
Brian Norris96a0d992015-02-17 18:18:35 -080022# Static builds might require -ltinfo, for instance
23ifneq ($(findstring -static, $(LDFLAGS)),)
24STATIC := --static
25endif
26
27TMON_LIBS=-lm -lpthread
Markus Mayer501a5c72017-09-27 16:02:37 -070028TMON_LIBS += $(shell $(PKG_CONFIG) --libs $(STATIC) panelw ncursesw 2> /dev/null || \
29 $(PKG_CONFIG) --libs $(STATIC) panel ncurses 2> /dev/null || \
Brian Norris96a0d992015-02-17 18:18:35 -080030 echo -lpanel -lncurses)
Jacob Pan94f69962013-10-14 16:02:27 -070031
Markus Mayer501a5c72017-09-27 16:02:37 -070032CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \
33 $(PKG_CONFIG) --cflags $(STATIC) panel ncurses 2> /dev/null)
Olaf Hering809b6ec2015-10-02 09:50:45 +000034
Jacob Pan94f69962013-10-14 16:02:27 -070035OBJS = tmon.o tui.o sysfs.o pid.o
36OBJS +=
37
38tmon: $(OBJS) Makefile tmon.h
Brian Norris96a0d992015-02-17 18:18:35 -080039 $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS)
Jacob Pan94f69962013-10-14 16:02:27 -070040
41valgrind: 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
44install:
45 - mkdir -p $(INSTALL_ROOT)/$(BINDIR)
46 - $(INSTALL_PROGRAM) "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)"
Jacob Pan94f69962013-10-14 16:02:27 -070047
48uninstall:
49 $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)"
Jacob Pan94f69962013-10-14 16:02:27 -070050
51clean:
52 find . -name "*.o" | xargs $(DEL_FILE)
53 rm -f $(TARGET)
54
55dist:
56 git tag v$(VERSION)
57 git archive --format=tar --prefix="$(TARGET)-$(VERSION)/" v$(VERSION) | \
58 gzip > $(TARGET)-$(VERSION).tar.gz