From 46423ff493169fbc2fde3f0cbfbdc383b47e834d Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 9 Feb 2023 18:58:59 +0100 Subject: [PATCH] Modernized Makefile --- Makefile | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3042fef..f7026f1 100644 --- a/Makefile +++ b/Makefile @@ -21,21 +21,20 @@ STATICLIB := $(LIBNAME).a BUILDDIR := build/intermediates/ PREFIX ?= /usr/local BINDIR ?= $(PREFIX)/bin +MANDIR ?= $(PREFIX)/man CONFIGDIR ?= $(PREFIX)/etc INCLUDEDIR ?= $(PREFIX)/include LIBDIR ?= $(PREFIX)/lib DATADIR ?= $(PREFIX)/share -MANDIR ?= $(DATADIR)/man DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc SRCS := $(notdir $(wildcard src/*.cpp)) OBJS := $(SRCS:.cpp=.o) -DEPS := $(SRCS:.cpp=.d) -HDRS := $(wildcard src/*.hpp) +HDRS ?= $(wildcard src/*.hpp) CXX ?= g++ -CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC +CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 -fPIC ifeq ($(DEBUG),1) CXXFLAGS += -D DEBUG -O0 CONFIG := debug @@ -70,11 +69,11 @@ ifeq ($(UNAME_S),Linux) $(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) endif -%.o %d: %.cpp +%.o %.d: %.cpp $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< @mv $@ $*.d $(BUILDDIR) --include $(BUILDDIR)$(DEPS) +-include $(BUILDDIR)$(SRCS:.cpp=.d) $(OUTDIR)$(STATICLIB): $(OBJS) ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS)) @@ -85,7 +84,7 @@ $(LIBNAME).hpp: $(HDRS) @cp /dev/null build/$(LIBNAME).hpp @for h in $(HDRS); \ do \ - cat $$h >> build/$(LIBNAME).hpp; \ + sed '/@exclude/d' $$h >> build/$(LIBNAME).hpp; \ done HEADERSRCDIR := build else @@ -106,7 +105,7 @@ install: endif $(INSTALL) -d $(LIBDIR) $(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR) - $(INSTALL) -d $(INCLUDEDIR) + $(INSTALL) -d $(INCLUDEDIR)/$(LIBNAME) $(INSTALL) -m 644 $(HEADERSRCDIR)/$(LIBNAME).hpp $(INCLUDEDIR) ifeq ($(UNAME_S),Darwin) cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)