From 9ef1ffc1c90589f917b8f84d19d4e59bc952aa39 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Fri, 30 Oct 2020 23:24:30 +0100 Subject: [PATCH] replaced Makefile with new one that makes build dir --- Makefile | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 1232333..4a89db7 100644 --- a/Makefile +++ b/Makefile @@ -3,10 +3,11 @@ BIN := $(shell basename $$(pwd)) MANSECTION := 1 MANPAGE := $(BIN).$(MANSECTION) +BUILDDIR := build/intermediates/ + SRCS := $(wildcard *.cpp) -OBJS := $(subst .cpp,.o,$(SRCS)) -DEPS := $(subst .cpp,.d,$(SRCS)) -CODE := $(wildcard code/*.txt) +OBJS := $(addprefix $(BUILDDIR),$(SRCS:.cpp=.o)) +DEPS := $(addprefix $(BUILDDIR),$(SRCS:.cpp=.d)) CXX ?= g++ PKG_CONFIG ?= pkg-config @@ -18,44 +19,45 @@ DATADIR ?= $(PREFIX)/share MANDIR ?= $(DATADIR)/man/man DOCDIR ?= $(DATADIR)/$(BIN)/doc -RM := /bin/rm -f +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 -.PHONY: all sync clean install +OUTDIR := build/$(CONFIG)/ -all: $(BIN) sync +.PHONY: all clean install prebuild -$(BIN): $(OBJS) $(DEPS) - $(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(BIN) +all: prebuild $(OUTDIR)$(BIN) -%.o: %.cpp %.d Makefile - $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< +prebuild: + @mkdir -p $(BUILDDIR) $(OUTDIR) --include *.d +$(OUTDIR)$(BIN): $(OBJS) $(DEPS) + $(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN) + @ln -sf $(OUTDIR)$(BIN) $(BIN) -%.d: ; +$(BUILDDIR)%.o: %.cpp $(BUILDDIR)%.d Makefile + cd $(BUILDDIR) && $(CXX) $(CXXFLAGS) -MMD -MP -MT $(notdir $@) -MF $*.d -c ../../$< && cd ../.. -sync: $(CODE) code/index.html - rsync -av code/ pi@www.swiftcoder.nl:/var/www/html/cpp1/ - @for f in $(CODE) code/index.html ;\ - do \ - curl -nT $$f ftp://student.aii.avans.nl/doc/rpbpolis1/ ;\ - done +-include $(BUILDDIR)*.d + +$(BUILDDIR)%.d: ; clean: - $(RM) $(OBJS) $(DEPS) $(BIN) + $(RM) build $(BIN) -install: $(BIN) +install: $(OUTDIR)$(BIN) $(INSTALL) -d $(BINDIR) - $(INSTALL) $(BIN) $(BINDIR) + $(INSTALL) $(OUTDIR)$(BIN) $(BINDIR) $(INSTALL) -d $(MANDIR)$(MANSECTION) $(INSTALL) $(MANPAGE) $(MANDIR)$(MANSECTION)