1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun# We need this for the "cc-option" macro. 3*4882a593Smuzhiyuninclude ../../../scripts/Kbuild.include 4*4882a593Smuzhiyun 5*4882a593SmuzhiyunVERSION = 1.0 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunBINDIR=usr/bin 8*4882a593SmuzhiyunWARNFLAGS=-Wall -Wshadow -W -Wformat -Wimplicit-function-declaration -Wimplicit-int 9*4882a593Smuzhiyunoverride CFLAGS+= $(call cc-option,-O3,-O1) ${WARNFLAGS} 10*4882a593Smuzhiyun# Add "-fstack-protector" only if toolchain supports it. 11*4882a593Smuzhiyunoverride CFLAGS+= $(call cc-option,-fstack-protector-strong) 12*4882a593SmuzhiyunCC?= $(CROSS_COMPILE)gcc 13*4882a593SmuzhiyunPKG_CONFIG?= $(CROSS_COMPILE)pkg-config 14*4882a593Smuzhiyun 15*4882a593Smuzhiyunoverride CFLAGS+=-D VERSION=\"$(VERSION)\" 16*4882a593SmuzhiyunLDFLAGS+= 17*4882a593SmuzhiyunTARGET=tmon 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunINSTALL_PROGRAM=install -m 755 -p 20*4882a593SmuzhiyunDEL_FILE=rm -f 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun# Static builds might require -ltinfo, for instance 23*4882a593Smuzhiyunifneq ($(findstring -static, $(LDFLAGS)),) 24*4882a593SmuzhiyunSTATIC := --static 25*4882a593Smuzhiyunendif 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunTMON_LIBS=-lm -lpthread 28*4882a593SmuzhiyunTMON_LIBS += $(shell $(PKG_CONFIG) --libs $(STATIC) panelw ncursesw 2> /dev/null || \ 29*4882a593Smuzhiyun $(PKG_CONFIG) --libs $(STATIC) panel ncurses 2> /dev/null || \ 30*4882a593Smuzhiyun echo -lpanel -lncurses) 31*4882a593Smuzhiyun 32*4882a593Smuzhiyunoverride CFLAGS += $(shell $(PKG_CONFIG) --cflags $(STATIC) panelw ncursesw 2> /dev/null || \ 33*4882a593Smuzhiyun $(PKG_CONFIG) --cflags $(STATIC) panel ncurses 2> /dev/null) 34*4882a593Smuzhiyun 35*4882a593SmuzhiyunOBJS = tmon.o tui.o sysfs.o pid.o 36*4882a593SmuzhiyunOBJS += 37*4882a593Smuzhiyun 38*4882a593Smuzhiyuntmon: $(OBJS) Makefile tmon.h 39*4882a593Smuzhiyun $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET) $(TMON_LIBS) 40*4882a593Smuzhiyun 41*4882a593Smuzhiyunvalgrind: tmon 42*4882a593Smuzhiyun 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*4882a593Smuzhiyun 44*4882a593Smuzhiyuninstall: 45*4882a593Smuzhiyun - mkdir -p $(INSTALL_ROOT)/$(BINDIR) 46*4882a593Smuzhiyun - $(INSTALL_PROGRAM) "$(TARGET)" "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" 47*4882a593Smuzhiyun 48*4882a593Smuzhiyununinstall: 49*4882a593Smuzhiyun $(DEL_FILE) "$(INSTALL_ROOT)/$(BINDIR)/$(TARGET)" 50*4882a593Smuzhiyun 51*4882a593Smuzhiyunclean: 52*4882a593Smuzhiyun find . -name "*.o" | xargs $(DEL_FILE) 53*4882a593Smuzhiyun rm -f $(TARGET) 54*4882a593Smuzhiyun 55*4882a593Smuzhiyundist: 56*4882a593Smuzhiyun git tag v$(VERSION) 57*4882a593Smuzhiyun git archive --format=tar --prefix="$(TARGET)-$(VERSION)/" v$(VERSION) | \ 58*4882a593Smuzhiyun gzip > $(TARGET)-$(VERSION).tar.gz 59