btop/Makefile

95 lines
2.5 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++
#If using g++ try to make sure we are using version 11 or 10
ifeq ($(CXX),g++)
CXX_VERSION = $(shell $(CXX) -dumpversion)
ifneq ($(shell test $(CXX_VERSION) -ge 11; echo $$?),0)
ifneq ($(shell command -v g++-11),)
CXX := g++-11
else ifneq ($(shell test $(CXX_VERSION) -eq 10; echo $$?),0)
ifneq ($(shell command -v g++-10),)
CXX := g++-10
endif
endif
endif
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
CXXFLAGS := -std=c++20 -pthread -O3 -Wall -Wextra -Wno-stringop-overread -pedantic
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
2021-05-09 00:56:48 +12:00
@cp -p bin/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 as root regardless of actual user
su-setuid:
@su --session-command "make as-root-setuid" root
as-root-setuid:
@chown root:root $(DESTDIR)$(PREFIX)/bin/btop
@chmod 4755 $(DESTDIR)$(PREFIX)/bin/btop
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
$(TARGET): $(OBJECTS)
$(CXX) -o $(TARGETDIR)/$(TARGET) $^
#Compile
$(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
$(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
.PHONY: all clean dist-clean uninstall