From 24e224dc1debfc180c9a18032dca18cfc618fca2 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Tue, 21 Dec 2021 09:33:09 +0100 Subject: [PATCH] Replaced with new standard Makefile --- Makefile | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index c235a3b..122cbd5 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ include premake.make LIBNAME := $(shell basename $$(pwd)) -MAJOR := 1 -MINOR := 0.0 +MAJOR ?= 1 +MINOR ?= 0 +PATCH ?= 0 UNAME_S := $(shell uname -s) @@ -10,11 +11,16 @@ ifeq ($(UNAME_S),Darwin) LINKERNAME := $(LIBNAME).dylib SONAME := $(LIBNAME).$(MAJOR).dylib REALNAME := $(LINKERNAME) -else +endif +ifeq ($(UNAME_S),OpenBSD) + REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR) +endif +ifeq ($(UNAME_S),Linux) LINKERNAME := $(LIBNAME).so SONAME := $(LINKERNAME).$(MAJOR) - REALNAME := $(SONAME).$(MINOR) + REALNAME := $(SONAME).$(MINOR).$(PATCH) endif +STATICLIB := $(LIBNAME).a BUILDDIR := build/intermediates/ PREFIX ?= /usr/local @@ -33,7 +39,7 @@ HDRS := $(wildcard src/*.hpp) CXX ?= g++ -CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 -fPIC +CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC ifeq ($(DEBUG),1) CXXFLAGS += -D DEBUG -O0 CONFIG := debug @@ -52,20 +58,23 @@ vpath %.o $(BUILDDIR) .PHONY: all clean install prebuild test -all: prebuild $(OUTDIR)$(REALNAME) +all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB) prebuild: @mkdir -p $(BUILDDIR) $(OUTDIR) $(OUTDIR)$(REALNAME): $(OBJS) $(DEPS) ifeq ($(UNAME_S),Darwin) - $(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) \ - -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) -else + $(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) +endif +ifeq ($(UNAME_S),OpenBSD) + $(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) +endif +ifeq ($(UNAME_S),Linux) $(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)$(REALNAME) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS)) endif -%.o: %.cpp %.d +%.o: %.cpp %.d Makefile $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< @mv $@ $*.d $(BUILDDIR) @@ -73,7 +82,10 @@ endif %.d: ; -build/$(LIBNAME).hpp: $(HDRS) +$(OUTDIR)$(STATICLIB): $(OBJS) + ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS)) + +$(LIBNAME).hpp: $(HDRS) @echo updating build/$(LIBNAME).hpp @cp /dev/null build/$(LIBNAME).hpp @for h in $(HDRS); \ @@ -88,14 +100,15 @@ clean: $(RM) build $(MAKE) -C tests clean -install: $(OUTDIR)$(REALNAME) build/$(LIBNAME).hpp +install: $(OUTDIR)$(REALNAME) $(LIBNAME).hpp $(INSTALL) -d $(LIBDIR) $(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR) $(INSTALL) -d $(INCLUDEDIR) $(INSTALL) -m 644 build/$(LIBNAME).hpp $(INCLUDEDIR) ifeq ($(UNAME_S),Darwin) cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME) -else +endif +ifeq ($(UNAME_S),Linux) ldconfig cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME) endif