2021-05-07 06:32:03 +12:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
DOCDIR ?= $(PREFIX)/share/btop/doc
|
|
|
|
|
2021-06-20 00:57:27 +12:00
|
|
|
#Compiler and Linker
|
2021-07-01 08:28:12 +12:00
|
|
|
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
|
2021-06-20 00:57:27 +12: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
|
|
|
|
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)
|
|
|
|
|
2021-07-01 08:28:12 +12:00
|
|
|
#Clean only Objects
|
2021-06-20 00:57:27 +12:00
|
|
|
clean:
|
|
|
|
@rm -rf $(BUILDDIR)
|
|
|
|
|
|
|
|
#Full Clean, Objects and Binaries
|
2021-07-01 08:28:12 +12:00
|
|
|
distclean: clean
|
2021-06-20 00:57:27 +12:00
|
|
|
@rm -rf $(TARGETDIR)
|
2021-05-07 06:32:03 +12:00
|
|
|
|
|
|
|
install:
|
|
|
|
@mkdir -p $(DESTDIR)$(PREFIX)/bin
|
2021-07-04 11:18:48 +12:00
|
|
|
@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
|
|
|
|
|
2021-07-04 11:18:48 +12:00
|
|
|
#Set suid bit for btop to root, will make btop run with admin privileges regardless of actual user
|
2021-07-01 08:28:12 +12:00
|
|
|
su-setuid:
|
2021-07-04 11:18:48 +12:00
|
|
|
@su --session-command "chown root:root $(DESTDIR)$(PREFIX)/bin/btop && chmod 4755 $(DESTDIR)$(PREFIX)/bin/btop" root
|
2021-07-01 08:28:12 +12:00
|
|
|
|
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
|
|
|
|
|
2021-06-20 00:57:27 +12:00
|
|
|
#Pull in dependency info for *existing* .o files
|
|
|
|
-include $(OBJECTS:.$(OBJEXT)=.$(DEPEXT))
|
|
|
|
|
|
|
|
#Link
|
2021-07-04 11:18:48 +12:00
|
|
|
btop: $(OBJECTS)
|
|
|
|
$(CXX) -o $(TARGETDIR)/btop $^
|
2021-06-20 00:57:27 +12:00
|
|
|
|
|
|
|
#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
|