2021-09-17 14:25:54 +02:00
|
|
|
#* Btop++ makefile v1.2
|
2021-08-22 16:04:01 +02:00
|
|
|
|
2021-09-01 21:40:13 +02:00
|
|
|
BANNER = \n \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m████████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗ \033[38;5;196m██████\033[38;5;240m╗\n \033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗╚══\033[38;5;160m██\033[38;5;239m╔══╝\033[38;5;160m██\033[38;5;239m╔═══\033[38;5;160m██\033[38;5;239m╗\033[38;5;160m██\033[38;5;239m╔══\033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗ \033[38;5;160m██\033[38;5;239m╗\n \033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║ \033[38;5;124m██\033[38;5;238m║\033[38;5;124m██████\033[38;5;238m╔╝ \033[38;5;124m██████\033[38;5;238m╗\033[38;5;124m██████\033[38;5;238m╗\n \033[38;5;88m██\033[38;5;237m╔══\033[38;5;88m██\033[38;5;237m╗ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║ \033[38;5;88m██\033[38;5;237m║\033[38;5;88m██\033[38;5;237m╔═══╝ ╚═\033[38;5;88m██\033[38;5;237m╔═╝╚═\033[38;5;88m██\033[38;5;237m╔═╝\n \033[38;5;52m██████\033[38;5;236m╔╝ \033[38;5;52m██\033[38;5;236m║ ╚\033[38;5;52m██████\033[38;5;236m╔╝\033[38;5;52m██\033[38;5;236m║ ╚═╝ ╚═╝\n \033[38;5;235m╚═════╝ ╚═╝ ╚═════╝ ╚═╝ \033[1;3;38;5;240mMakefile v1.2\033[0m
|
2021-08-22 16:04:01 +02:00
|
|
|
|
2021-09-01 21:40:13 +02:00
|
|
|
override BTOP_VERSION := $(shell head -n100 src/btop.cpp 2>/dev/null | grep "Version =" | cut -f2 -d"\"" || echo " unknown")
|
|
|
|
override TIMESTAMP := $(shell date +%s 2>/dev/null || echo "0")
|
2021-08-22 16:04:01 +02:00
|
|
|
|
2021-09-21 18:57:16 +02:00
|
|
|
ifneq ($(QUIET),true)
|
2021-10-04 20:57:15 +02:00
|
|
|
override PRE := info info-quiet
|
2021-09-21 18:57:16 +02:00
|
|
|
override QUIET := false
|
|
|
|
else
|
|
|
|
override PRE := info-quiet
|
|
|
|
endif
|
|
|
|
|
2021-05-06 20:32:03 +02:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
|
2021-09-01 21:40:13 +02:00
|
|
|
#? NOTICE! Manually set PLATFORM and ARCH if not compiling for host system
|
|
|
|
PLATFORM ?= $(shell uname -s || echo unknown)
|
2021-09-19 06:18:09 +02:00
|
|
|
ARCH ?= $(shell uname -m || echo unknown)
|
2021-09-01 21:40:13 +02:00
|
|
|
|
|
|
|
#? Only enable fcf-protection if on x86_64
|
|
|
|
ifeq ($(ARCH),x86_64)
|
2021-09-17 14:25:54 +02:00
|
|
|
override ADDFLAGS += -fcf-protection
|
2021-09-01 21:40:13 +02:00
|
|
|
endif
|
|
|
|
|
2021-09-18 02:13:35 +02:00
|
|
|
ifeq ($(STATIC),true)
|
2021-10-06 10:47:24 +02:00
|
|
|
override ADDFLAGS += -D STATIC_BUILD -static -static-libgcc -static-libstdc++
|
2021-09-18 02:13:35 +02:00
|
|
|
endif
|
|
|
|
|
2021-09-01 21:40:13 +02:00
|
|
|
#? Make sure PLATFORM Darwin is OSX and not Darwin
|
|
|
|
ifeq ($(PLATFORM),Darwin)
|
|
|
|
ifeq ($(shell sw_vers >/dev/null 2>&1; echo $$?),0)
|
2021-09-12 15:58:23 +02:00
|
|
|
PLATFORM := OSX
|
2021-09-01 21:40:13 +02:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Compiler and Linker
|
2021-08-15 23:20:55 +02:00
|
|
|
CXX ?= g++
|
2021-09-01 21:40:13 +02:00
|
|
|
override CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion || echo 0)
|
2021-06-30 22:28:12 +02:00
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Try to make sure we are using GCC/G++ version 11 or later if not instructed to use g++-10
|
2021-09-25 11:48:33 +02:00
|
|
|
ifeq ($(CXX),g++)
|
2021-09-26 13:46:51 +02:00
|
|
|
V_MAJOR := $(shell echo $(CXX_VERSION) | cut -f1 -d".")
|
|
|
|
ifneq ($(shell test $(V_MAJOR) -ge 11; echo $$?),0)
|
|
|
|
ifeq ($(shell command -v g++-11 >/dev/null; echo $$?),0)
|
|
|
|
override CXX := g++-11
|
|
|
|
override CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion || echo 0)
|
2021-08-15 23:20:55 +02:00
|
|
|
endif
|
2021-06-30 22:28:12 +02:00
|
|
|
endif
|
|
|
|
endif
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-09-12 15:58:23 +02:00
|
|
|
#? Pull in platform specific source files and get thread count
|
|
|
|
ifeq ($(PLATFORM),Linux)
|
|
|
|
PLATFORM_DIR := linux
|
|
|
|
THREADS := $(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)
|
|
|
|
else ifeq ($(PLATFORM),FreeBSD)
|
|
|
|
PLATFORM_DIR := freebsd
|
|
|
|
THREADS := $(shell getconf NPROCESSORS_ONLN 2>/dev/null || echo 1)
|
|
|
|
else ifeq ($(PLATFORM),OSX)
|
|
|
|
PLATFORM_DIR := osx
|
|
|
|
THREADS := $(shell sysctl -n hw.ncpu || echo 1)
|
|
|
|
else
|
|
|
|
$(error $(shell printf "\033[1;91mERROR: \033[97mUnsupported platform ($(PLATFORM))\033[0m"))
|
|
|
|
endif
|
|
|
|
|
2021-08-23 17:35:27 +02:00
|
|
|
#? Use all CPU cores (will only be set if using Make 4.3+)
|
2021-09-01 21:40:13 +02:00
|
|
|
MAKEFLAGS := --jobs=$(THREADS)
|
|
|
|
ifeq ($(THREADS),1)
|
|
|
|
override THREADS := auto
|
|
|
|
endif
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? The Directories, Source, Includes, Objects and Binary
|
2021-06-19 14:57:27 +02:00
|
|
|
SRCDIR := src
|
|
|
|
INCDIR := include
|
|
|
|
BUILDDIR := obj
|
|
|
|
TARGETDIR := bin
|
|
|
|
SRCEXT := cpp
|
|
|
|
DEPEXT := d
|
|
|
|
OBJEXT := o
|
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Flags, Libraries and Includes
|
2021-09-01 21:40:13 +02:00
|
|
|
override REQFLAGS := -std=c++20
|
2021-09-17 14:25:54 +02:00
|
|
|
WARNFLAGS := -Wall -Wextra -pedantic
|
2021-09-01 21:40:13 +02:00
|
|
|
OPTFLAGS ?= -O2 -ftree-loop-vectorize -flto=$(THREADS)
|
2021-09-18 02:13:35 +02:00
|
|
|
LDCXXFLAGS := -pthread -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector -fstack-clash-protection $(ADDFLAGS)
|
2021-08-10 20:20:33 +02:00
|
|
|
override CXXFLAGS += $(REQFLAGS) $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
|
|
|
|
override LDFLAGS += $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
|
|
|
|
INC := -I$(INCDIR) -I$(SRCDIR)
|
2021-08-22 16:04:01 +02:00
|
|
|
SU_USER := root
|
|
|
|
SU_GROUP := root
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-23 22:52:52 +02:00
|
|
|
SOURCES := $(shell find $(SRCDIR) -maxdepth 1 -type f -name *.$(SRCEXT))
|
|
|
|
|
2021-09-01 21:40:13 +02:00
|
|
|
SOURCES += $(shell find $(SRCDIR)/$(PLATFORM_DIR) -type f -name *.$(SRCEXT))
|
|
|
|
|
2021-08-23 22:52:52 +02:00
|
|
|
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Default Make
|
2021-09-21 18:57:16 +02:00
|
|
|
all: $(PRE) directories btop
|
2021-08-22 16:04:01 +02:00
|
|
|
|
2021-09-21 18:57:16 +02:00
|
|
|
info:
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf " $(BANNER)\n"
|
2021-09-01 21:40:13 +02:00
|
|
|
@printf "\033[1;92mPLATFORM \033[1;93m?| \033[0m$(PLATFORM)\n"
|
|
|
|
@printf "\033[1;96mARCH \033[1;93m?| \033[0m$(ARCH)\n"
|
|
|
|
@printf "\033[1;93mCXX \033[1;93m?| \033[0m$(CXX) \033[1;93m(\033[97m$(CXX_VERSION)\033[93m)\n"
|
|
|
|
@printf "\033[1;94mTHREADS \033[1;94m:| \033[0m$(THREADS)\n"
|
|
|
|
@printf "\033[1;92mREQFLAGS \033[1;91m!| \033[0m$(REQFLAGS)\n"
|
|
|
|
@printf "\033[1;91mWARNFLAGS \033[1;94m:| \033[0m$(WARNFLAGS)\n"
|
|
|
|
@printf "\033[1;94mOPTFLAGS \033[1;94m:| \033[0m$(OPTFLAGS)\n"
|
|
|
|
@printf "\033[1;93mLDCXXFLAGS \033[1;94m:| \033[0m$(LDCXXFLAGS)\n"
|
|
|
|
@printf "\033[1;95mCXXFLAGS \033[1;92m+| \033[0;37m\$$(\033[92mREQFLAGS\033[37m) \$$(\033[93mLDCXXFLAGS\033[37m) \$$(\033[94mOPTFLAGS\033[37m) \$$(\033[91mWARNFLAGS\033[37m)\n"
|
|
|
|
@printf "\033[1;95mLDFLAGS \033[1;92m+| \033[0;37m\$$(\033[93mLDCXXFLAGS\033[37m) \$$(\033[94mOPTFLAGS\033[37m) \$$(\033[91mWARNFLAGS\033[37m)\n"
|
|
|
|
|
2021-09-21 18:57:16 +02:00
|
|
|
info-quiet:
|
|
|
|
|
|
|
|
@printf "\n\033[1;92mBuilding btop++ \033[91m(\033[97mv$(BTOP_VERSION)\033[91m) \033[93m$(PLATFORM) \033[96m$(ARCH)\033[0m\n"
|
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
help:
|
2021-09-18 02:13:35 +02:00
|
|
|
@printf " $(BANNER)\n"
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;97mbtop++ makefile\033[0m\n"
|
|
|
|
@printf "usage: make [argument]\n\n"
|
|
|
|
@printf "arguments:\n"
|
|
|
|
@printf " all Compile btop (default argument)\n"
|
|
|
|
@printf " clean Remove built objects\n"
|
|
|
|
@printf " distclean Remove built objects and binaries\n"
|
2021-09-18 02:13:35 +02:00
|
|
|
@printf " install Install btop++ to \$$PREFIX ($(PREFIX))\n"
|
|
|
|
@printf " setuid Set installed binary owner/group to \$$SU_USER/\$$SU_GROUP ($(SU_USER)/$(SU_GROUP)) and set SUID bit\n"
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf " uninstall Uninstall btop++ from \$$PREFIX\n"
|
2021-10-04 20:57:15 +02:00
|
|
|
@printf " info Display information about Environment,compiler and linker flags\n"
|
2021-08-22 16:04:01 +02:00
|
|
|
|
|
|
|
#? Make the Directories
|
2021-06-19 14:57:27 +02:00
|
|
|
directories:
|
|
|
|
@mkdir -p $(TARGETDIR)
|
2021-09-01 21:40:13 +02:00
|
|
|
@mkdir -p $(BUILDDIR)/$(PLATFORM_DIR)
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Clean only Objects
|
2021-06-19 14:57:27 +02:00
|
|
|
clean:
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;91mRemoving: \033[1;97mbuilt objects...\033[0m\n"
|
2021-06-19 14:57:27 +02:00
|
|
|
@rm -rf $(BUILDDIR)
|
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Clean Objects and Binaries
|
2021-06-30 22:28:12 +02:00
|
|
|
distclean: clean
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;91mRemoving: \033[1;97mbuilt binaries...\033[0m\n"
|
2021-06-19 14:57:27 +02:00
|
|
|
@rm -rf $(TARGETDIR)
|
2021-05-06 20:32:03 +02:00
|
|
|
|
|
|
|
install:
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;92mInstalling binary to: \033[1;97m$(DESTDIR)$(PREFIX)/bin/btop\n"
|
2021-05-06 20:32:03 +02:00
|
|
|
@mkdir -p $(DESTDIR)$(PREFIX)/bin
|
2021-07-04 01:18:48 +02:00
|
|
|
@cp -p $(TARGETDIR)/btop $(DESTDIR)$(PREFIX)/bin/btop
|
2021-05-06 20:32:03 +02:00
|
|
|
@chmod 755 $(DESTDIR)$(PREFIX)/bin/btop
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;92mInstalling doc to: \033[1;97m$(DESTDIR)$(PREFIX)/share/btop\n"
|
|
|
|
@mkdir -p $(DESTDIR)$(PREFIX)/share/btop
|
|
|
|
@cp -p README.md $(DESTDIR)$(PREFIX)/share/btop
|
2021-09-21 22:05:03 +02:00
|
|
|
@printf "\033[1;92mInstalling themes to: \033[1;97m$(DESTDIR)$(PREFIX)/share/btop/themes\033[0m\n"
|
2021-08-22 16:04:01 +02:00
|
|
|
@cp -pr themes $(DESTDIR)$(PREFIX)/share/btop
|
2021-05-06 20:32:03 +02:00
|
|
|
|
2021-09-01 21:40:13 +02:00
|
|
|
#? Set SUID bit for btop as $SU_USER in $SU_GROUP
|
2021-08-22 16:04:01 +02:00
|
|
|
setuid:
|
|
|
|
@printf "\033[1;97mFile: $(DESTDIR)$(PREFIX)/bin/btop\n"
|
|
|
|
@printf "\033[1;92mSetting owner \033[1;97m$(SU_USER):$(SU_GROUP)\033[0m\n"
|
|
|
|
@chown $(SU_USER):$(SU_GROUP) $(DESTDIR)$(PREFIX)/bin/btop
|
|
|
|
@printf "\033[1;92mSetting SUID bit\033[0m\n"
|
|
|
|
@chmod u+s $(DESTDIR)$(PREFIX)/bin/btop
|
2021-06-30 22:28:12 +02:00
|
|
|
|
2021-05-06 20:32:03 +02:00
|
|
|
uninstall:
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;91mRemoving: \033[1;97m$(DESTDIR)$(PREFIX)/bin/btop\033[0m\n"
|
2021-05-06 20:32:03 +02:00
|
|
|
@rm -rf $(DESTDIR)$(PREFIX)/bin/btop
|
2021-08-22 16:04:01 +02:00
|
|
|
@printf "\033[1;91mRemoving: \033[1;97m$(DESTDIR)$(PREFIX)/share/btop\033[0m\n"
|
2021-05-06 20:32:03 +02:00
|
|
|
@rm -rf $(DESTDIR)$(PREFIX)/share/btop
|
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Pull in dependency info for *existing* .o files
|
2021-06-19 14:57:27 +02:00
|
|
|
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
|
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Link
|
2021-09-01 21:40:13 +02:00
|
|
|
.ONESHELL:
|
2021-07-04 01:18:48 +02:00
|
|
|
btop: $(OBJECTS)
|
2021-08-22 16:04:01 +02:00
|
|
|
@sleep 0.1 2>/dev/null || true
|
2021-09-01 21:40:13 +02:00
|
|
|
@TSTAMP=$$(date +%s 2>/dev/null || echo "0")
|
2021-09-21 18:57:16 +02:00
|
|
|
@$(QUIET) || printf "\n\033[1;92mLinking and optimizing binary\033[37m...\033[0m\n"
|
2021-09-01 21:40:13 +02:00
|
|
|
@$(CXX) -o $(TARGETDIR)/btop $^ $(LDFLAGS) || exit 1
|
|
|
|
@printf "\033[1;92m-> \033[1;37m$(TARGETDIR)/btop \033[100D\033[35C\033[1;93m(\033[1;97m$$(du -ah $(TARGETDIR)/btop | cut -f1)iB\033[1;93m) \033[92m(\033[97m$$(date -d @$$(expr $$(date +%s 2>/dev/null || echo "0") - $${TSTAMP} 2>/dev/null) -u +%Mm:%Ss 2>/dev/null | sed 's/^00m://' || echo '')\033[92m)\033[0m\n"
|
2021-09-21 18:57:16 +02:00
|
|
|
printf "\n\033[1;92mBuild complete in \033[92m(\033[97m$$(date -d @$$(expr $$(date +%s 2>/dev/null || echo "0") - $(TIMESTAMP) 2>/dev/null) -u +%Mm:%Ss 2>/dev/null | sed 's/^00m://' || echo "unknown")\033[92m)\033[0m\n"
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Compile
|
2021-09-01 21:40:13 +02:00
|
|
|
.ONESHELL:
|
2021-06-19 14:57:27 +02:00
|
|
|
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
|
2021-08-22 16:04:01 +02:00
|
|
|
@sleep 0.1 2>/dev/null || true
|
2021-09-01 21:40:13 +02:00
|
|
|
@TSTAMP=$$(date +%s 2>/dev/null || echo "0")
|
2021-09-21 18:57:16 +02:00
|
|
|
@$(QUIET) || printf "\033[1;97mCompiling $<\033[0m\n"
|
2021-09-01 21:40:13 +02:00
|
|
|
@$(CXX) $(CXXFLAGS) $(INC) -c -o $@ $< || exit 1
|
|
|
|
@$(CXX) $(CXXFLAGS) $(INC) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT) >/dev/null || exit 1
|
2021-06-19 14:57:27 +02:00
|
|
|
@cp -f $(BUILDDIR)/$*.$(DEPEXT) $(BUILDDIR)/$*.$(DEPEXT).tmp
|
|
|
|
@sed -e 's|.*:|$(BUILDDIR)/$*.$(OBJEXT):|' < $(BUILDDIR)/$*.$(DEPEXT).tmp > $(BUILDDIR)/$*.$(DEPEXT)
|
|
|
|
@sed -e 's/.*://' -e 's/\\$$//' < $(BUILDDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(BUILDDIR)/$*.$(DEPEXT)
|
|
|
|
@rm -f $(BUILDDIR)/$*.$(DEPEXT).tmp
|
2021-09-01 21:40:13 +02:00
|
|
|
@printf "\033[1;92m-> \033[1;37m$@ \033[100D\033[35C\033[1;93m(\033[1;97m$$(du -ah $@ | cut -f1)iB\033[1;93m) \033[92m(\033[97m$$(date -d @$$(expr $$(date +%s 2>/dev/null || echo "0") - $${TSTAMP} 2>/dev/null) -u +%Mm:%Ss 2>/dev/null | sed 's/^00m://' || echo '')\033[92m)\033[0m\n"
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-22 16:04:01 +02:00
|
|
|
#? Non-File Targets
|
2021-09-01 21:40:13 +02:00
|
|
|
.PHONY: all msg help pre
|