curly/Makefile

64 lines
1.4 KiB
Makefile
Raw Normal View History

2020-09-01 16:12:41 +02:00
BIN := $(shell basename $$(pwd))
MANSECTION := 1
MANPAGE := $(BIN).$(MANSECTION)
BUILDDIR := build/intermediates/
2020-09-01 16:12:41 +02:00
SRCS := $(wildcard *.cpp)
OBJS := $(addprefix $(BUILDDIR),$(SRCS:.cpp=.o))
DEPS := $(addprefix $(BUILDDIR),$(SRCS:.cpp=.d))
2020-09-01 16:12:41 +02:00
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
2020-09-01 16:12:41 +02:00
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
2020-09-01 16:12:41 +02:00
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
2020-09-01 16:12:41 +02:00
endif
LDLIBS := -lm -lpthread -lcurl -lsclogging
OUTDIR := build/$(CONFIG)/
.PHONY: all clean install prebuild
2020-09-01 16:12:41 +02:00
all: prebuild $(OUTDIR)$(BIN)
2020-09-01 16:12:41 +02:00
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
2020-09-01 16:12:41 +02:00
$(OUTDIR)$(BIN): $(OBJS) $(DEPS)
$(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN)
@ln -sf $(OUTDIR)$(BIN) $(BIN)
2020-09-01 16:12:41 +02:00
$(BUILDDIR)%.o: %.cpp $(BUILDDIR)%.d Makefile
cd $(BUILDDIR) && $(CXX) $(CXXFLAGS) -MMD -MP -MT $(notdir $@) -MF $*.d -c ../../$< && cd ../..
2020-09-01 16:12:41 +02:00
-include $(BUILDDIR)*.d
2020-09-01 16:12:41 +02:00
$(BUILDDIR)%.d: ;
2020-09-01 16:12:41 +02:00
clean:
$(RM) build $(BIN)
2020-09-01 16:12:41 +02:00
install: $(OUTDIR)$(BIN)
2020-09-01 16:12:41 +02:00
$(INSTALL) -d $(BINDIR)
$(INSTALL) $(OUTDIR)$(BIN) $(BINDIR)
2020-09-01 16:12:41 +02:00
$(INSTALL) -d $(MANDIR)$(MANSECTION)
$(INSTALL) $(MANPAGE) $(MANDIR)$(MANSECTION)