Replaced with new standard Makefile

This commit is contained in:
Bob Polis 2021-12-21 09:33:09 +01:00
parent 9cdbeb283a
commit 24e224dc1d

View File

@ -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