termage/Makefile
2024-01-18 20:22:29 +01:00

80 lines
1.7 KiB
Makefile

include premake.make
BIN := $(shell basename $$(pwd))
COMMIT != git log 2>/dev/null | sed -e '1s/^commit //;q'
MANSECTION ?= 1
MANPAGE := $(BIN).$(MANSECTION)
SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.dep)
BUILDDIR := build/intermediates/
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
MANDIR ?= $(PREFIX)/man/man
CONFIGDIR ?= $(PREFIX)/etc
DATADIR ?= $(PREFIX)/share
DOCDIR ?= $(DATADIR)/$(BIN)/doc
CXX ?= g++
RM := /bin/rm -rf
INSTALL := /usr/bin/install -c
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
CXXFLAGS += -g3 -std=c++20
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif
OUTDIR := build/$(CONFIG)/
vpath %.cpp src
vpath %.dep $(BUILDDIR)
vpath %.o $(BUILDDIR)
.PHONY: all clean install prebuild test dist-clean
all: prebuild $(OUTDIR)$(BIN)
prebuild: src/commit.inc
@mkdir -p $(BUILDDIR) $(OUTDIR)
sed -i.bak -e '1s/".*"/"$(COMMIT)"/' src/commit.inc
@rm src/commit.inc.bak
src/commit.inc:
echo 'const char* commit = "";' > $@
$(OUTDIR)$(BIN): $(OBJS)
$(CXX) -o $(OUTDIR)$(BIN) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
@ln -sf $(OUTDIR)$(BIN) $(BIN)
%.o %.dep: %.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.dep -c $<
@mv $@ $*.dep $(BUILDDIR)
-include $(addprefix $(BUILDDIR), $(DEPS))
test:
$(MAKE) -C tests && tests/tests
clean:
$(RM) $(BUILDDIR)
$(MAKE) -C tests clean
dist-clean:
$(RM) build $(BIN) src/commit.inc
$(MAKE) -C tests clean
install:
$(INSTALL) -d $(BINDIR)
$(INSTALL) $(OUTDIR)$(BIN) $(BINDIR)
$(INSTALL) -d $(MANDIR)$(MANSECTION)
$(INSTALL) -m 0644 $(MANPAGE) $(MANDIR)$(MANSECTION)
-include postmake.make