btop/Makefile

98 lines
2.9 KiB
Makefile
Raw Normal View History

2021-05-07 06:32:03 +12:00
PREFIX ?= /usr/local
DOCDIR ?= $(PREFIX)/share/btop/doc
#Compiler and Linker
CXX ?= g++
#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
endif
endif
#Only enable fcf-protection if on x86
ARCH = $(shell uname -p)
ifeq ($(ARCH),x86_64)
ADDFLAGS = -fcf-protection
endif
#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-11 06:20:33 +12:00
REQFLAGS := -std=c++20
WARNFLAGS := -Wall -Wextra -Wno-stringop-overread -pedantic -pedantic-errors -Wfatal-errors
OPTFLAGS := -O2 -ftree-loop-vectorize
override LDCXXFLAGS += -pthread -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector -fstack-clash-protection -flto $(ADDFLAGS)
2021-08-11 06:20:33 +12:00
override CXXFLAGS += $(REQFLAGS) $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
override LDFLAGS += $(LDCXXFLAGS) $(OPTFLAGS) $(WARNFLAGS)
INC := -I$(INCDIR) -I$(SRCDIR)
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)
#Clean only Objects
clean:
@rm -rf $(BUILDDIR)
#Full Clean, Objects and Binaries
distclean: clean
@rm -rf $(TARGETDIR)
2021-05-07 06:32:03 +12:00
install:
@mkdir -p $(DESTDIR)$(PREFIX)/bin
@cp -p $(TARGETDIR)/btop $(DESTDIR)$(PREFIX)/bin/btop
2021-05-07 06:32:03 +12:00
@mkdir -p $(DESTDIR)$(DOCDIR)
@cp -p README.md $(DESTDIR)$(DOCDIR)
@cp -pr themes $(DESTDIR)$(PREFIX)/share/btop
@chmod 755 $(DESTDIR)$(PREFIX)/bin/btop
#Set suid bit for btop to root, will make btop run with admin privileges regardless of actual user
su-setuid:
@su --session-command "chown root:root $(DESTDIR)$(PREFIX)/bin/btop && chmod 4755 $(DESTDIR)$(PREFIX)/bin/btop" root
2021-05-07 06:32:03 +12:00
uninstall:
@rm -rf $(DESTDIR)$(PREFIX)/bin/btop
@rm -rf $(DESTDIR)$(DOCDIR)
@rm -rf $(DESTDIR)$(PREFIX)/share/btop
#Pull in dependency info for *existing* .o files
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
#Link
btop: $(OBJECTS)
2021-08-11 06:20:33 +12:00
$(CXX) -o $(TARGETDIR)/btop $^ $(LDFLAGS)
#Compile
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
2021-08-11 06:20:33 +12:00
$(CXX) $(CXXFLAGS) $(INC) -c -o $@ $<
@$(CXX) $(CXXFLAGS) $(INC) -MM $(SRCDIR)/$*.$(SRCEXT) > $(BUILDDIR)/$*.$(DEPEXT)
@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-06 08:18:58 +12:00
.PHONY: all