curly/Makefile

65 lines
1.3 KiB
Makefile
Raw Normal View History

2020-11-08 13:26:54 +01:00
LDLIBS := -lm -lpthread -lcurl -lsclogging
2020-09-01 16:12:41 +02:00
BIN := $(shell basename $$(pwd))
MANSECTION := 1
MANPAGE := $(BIN).$(MANSECTION)
2020-11-08 13:26:54 +01:00
SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)
2020-09-01 16:12:41 +02:00
2020-11-08 13:26:54 +01:00
BUILDDIR := build/intermediates/
2020-09-01 16:12:41 +02:00
PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin
CONFIGDIR ?= $(PREFIX)/etc
DATADIR ?= $(PREFIX)/share
MANDIR ?= $(DATADIR)/man/man
DOCDIR ?= $(DATADIR)/$(BIN)/doc
2020-11-08 13:26:54 +01:00
CXX ?= g++
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
OUTDIR := build/$(CONFIG)/
2020-11-08 13:26:54 +01:00
vpath %.cpp src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
.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)
2020-11-08 13:26:54 +01:00
$(CXX) $(addprefix $(BUILDDIR),$(OBJS)) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN)
@ln -sf $(OUTDIR)$(BIN) $(BIN)
2020-09-01 16:12:41 +02:00
2020-11-08 13:26:54 +01:00
%.o: %.cpp %.d
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
2020-09-01 16:12:41 +02:00
-include $(BUILDDIR)*.d
2020-09-01 16:12:41 +02:00
2020-11-08 13:26:54 +01:00
%.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)