BIN := $(shell basename $$(pwd)) MANSECTION := 1 MANPAGE := $(BIN).$(MANSECTION) BUILDDIR := build/intermediates/ SRCS := $(wildcard *.cpp) OBJS := $(addprefix $(BUILDDIR),$(SRCS:.cpp=.o)) DEPS := $(addprefix $(BUILDDIR),$(SRCS:.cpp=.d)) CXX ?= g++ PKG_CONFIG ?= pkg-config PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin CONFIGDIR ?= $(PREFIX)/etc DATADIR ?= $(PREFIX)/share MANDIR ?= $(DATADIR)/man/man DOCDIR ?= $(DATADIR)/$(BIN)/doc RM := /bin/rm -rf INSTALL := /usr/bin/install -c CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -pthread ifeq ($(DEBUG),1) CXXFLAGS += -D DEBUG -O0 CONFIG := debug else CXXFLAGS += -D NDEBUG -O3 CONFIG := release endif LDLIBS := -lm -lpthread -lcurl -lsclogging OUTDIR := build/$(CONFIG)/ .PHONY: all clean install prebuild all: prebuild $(OUTDIR)$(BIN) prebuild: @mkdir -p $(BUILDDIR) $(OUTDIR) $(OUTDIR)$(BIN): $(OBJS) $(DEPS) $(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN) @ln -sf $(OUTDIR)$(BIN) $(BIN) $(BUILDDIR)%.o: %.cpp $(BUILDDIR)%.d Makefile cd $(BUILDDIR) && $(CXX) $(CXXFLAGS) -MMD -MP -MT $(notdir $@) -MF $*.d -c ../../$< && cd ../.. -include $(BUILDDIR)*.d $(BUILDDIR)%.d: ; clean: $(RM) build $(BIN) install: $(OUTDIR)$(BIN) $(INSTALL) -d $(BINDIR) $(INSTALL) $(OUTDIR)$(BIN) $(BINDIR) $(INSTALL) -d $(MANDIR)$(MANSECTION) $(INSTALL) $(MANPAGE) $(MANDIR)$(MANSECTION)