2021-05-06 20:32:03 +02:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
DOCDIR ?= $(PREFIX)/share/btop/doc
|
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
#Compiler and Linker
|
2021-08-15 23:20:55 +02:00
|
|
|
CXX ?= g++
|
2021-06-30 22:28:12 +02:00
|
|
|
|
2021-08-15 23:20:55 +02:00
|
|
|
#Try to make sure we are using GCC/G++ version 11 or later if not instructed to use g++-10
|
|
|
|
ifneq ($(CXX),g++-10)
|
|
|
|
CXX_VERSION = $(shell $(CXX) -dumpfullversion -dumpversion | cut -f1 -d"." || echo 0)
|
|
|
|
ifneq ($(shell test $(CXX_VERSION) -ge 11; echo $$?),0)
|
|
|
|
ifeq ($(shell command -v g++-11 >/dev/null; echo $$?),0)
|
|
|
|
override CXX = g++-11
|
|
|
|
endif
|
2021-06-30 22:28:12 +02:00
|
|
|
endif
|
|
|
|
endif
|
2021-06-19 14:57:27 +02:00
|
|
|
|
2021-08-15 23:20:55 +02:00
|
|
|
#Only enable fcf-protection if on x86
|
|
|
|
ARCH = $(shell uname -p)
|
|
|
|
ifeq ($(ARCH),x86_64)
|
|
|
|
ADDFLAGS = -fcf-protection
|
|
|
|
endif
|
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
#The Target Binary Program
|
|
|
|
TARGET := btop
|
|
|
|
|
|
|
|
#The Directories, Source, Includes, Objects and Binary
|
|
|
|
SRCDIR := src
|
|
|
|
INCDIR := include
|
|
|
|
BUILDDIR := obj
|
|
|
|
TARGETDIR := bin
|
|
|
|
SRCEXT := cpp
|
|
|
|
DEPEXT := d
|
|
|
|
OBJEXT := o
|
|
|
|
|
|
|
|
#Flags, Libraries and Includes
|
2021-08-10 20:20:33 +02:00
|
|
|
REQFLAGS := -std=c++20
|
|
|
|
WARNFLAGS := -Wall -Wextra -Wno-stringop-overread -pedantic -pedantic-errors -Wfatal-errors
|
|
|
|
OPTFLAGS := -O2 -ftree-loop-vectorize
|
2021-08-15 23:20:55 +02:00
|
|
|
override LDCXXFLAGS += -pthread -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector -fstack-clash-protection -flto $(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-06-19 14:57:27 +02:00
|
|
|
|
|
|
|
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
|
|
|
|
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.$(OBJEXT)))
|
|
|
|
|
|
|
|
#Default Make
|
|
|
|
all: directories $(TARGET)
|
|
|
|
|
|
|
|
#Make the Directories
|
|
|
|
directories:
|
|
|
|
@mkdir -p $(TARGETDIR)
|
|
|
|
@mkdir -p $(BUILDDIR)
|
|
|
|
|
2021-06-30 22:28:12 +02:00
|
|
|
#Clean only Objects
|
2021-06-19 14:57:27 +02:00
|
|
|
clean:
|
|
|
|
@rm -rf $(BUILDDIR)
|
|
|
|
|
|
|
|
#Full Clean, Objects and Binaries
|
2021-06-30 22:28:12 +02:00
|
|
|
distclean: clean
|
2021-06-19 14:57:27 +02:00
|
|
|
@rm -rf $(TARGETDIR)
|
2021-05-06 20:32:03 +02:00
|
|
|
|
|
|
|
install:
|
|
|
|
@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
|
|
|
@mkdir -p $(DESTDIR)$(DOCDIR)
|
|
|
|
@cp -p README.md $(DESTDIR)$(DOCDIR)
|
|
|
|
@cp -pr themes $(DESTDIR)$(PREFIX)/share/btop
|
|
|
|
@chmod 755 $(DESTDIR)$(PREFIX)/bin/btop
|
|
|
|
|
2021-07-04 01:18:48 +02:00
|
|
|
#Set suid bit for btop to root, will make btop run with admin privileges regardless of actual user
|
2021-06-30 22:28:12 +02:00
|
|
|
su-setuid:
|
2021-07-04 01:18:48 +02:00
|
|
|
@su --session-command "chown root:root $(DESTDIR)$(PREFIX)/bin/btop && chmod 4755 $(DESTDIR)$(PREFIX)/bin/btop" root
|
2021-06-30 22:28:12 +02:00
|
|
|
|
2021-05-06 20:32:03 +02:00
|
|
|
uninstall:
|
|
|
|
@rm -rf $(DESTDIR)$(PREFIX)/bin/btop
|
|
|
|
@rm -rf $(DESTDIR)$(DOCDIR)
|
|
|
|
@rm -rf $(DESTDIR)$(PREFIX)/share/btop
|
|
|
|
|
2021-06-19 14:57:27 +02:00
|
|
|
#Pull in dependency info for *existing* .o files
|
|
|
|
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
|
|
|
|
|
|
|
|
#Link
|
2021-07-04 01:18:48 +02:00
|
|
|
btop: $(OBJECTS)
|
2021-08-10 20:20:33 +02:00
|
|
|
$(CXX) -o $(TARGETDIR)/btop $^ $(LDFLAGS)
|
2021-06-19 14:57:27 +02:00
|
|
|
|
|
|
|
#Compile
|
|
|
|
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
|
2021-08-10 20:20:33 +02:00
|
|
|
$(CXX) $(CXXFLAGS) $(INC) -c -o $@ $<
|
|
|
|
@$(CXX) $(CXXFLAGS) $(INC) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
|
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
|
|
|
|
|
|
|
|
#Non-File Targets
|
2021-07-05 22:18:58 +02:00
|
|
|
.PHONY: all
|