Moved versioning to premake; added OpenBSD support

This commit is contained in:
Bob Polis 2021-12-21 10:45:00 +01:00
parent 713289ffd9
commit 027c74171a
2 changed files with 64 additions and 33 deletions

View File

@ -1,84 +1,110 @@
LIBNAME := $(shell basename $$(pwd)) include premake.make
MAJOR := 1
MINOR := 0.0
LIBNAME := $(shell basename $$(pwd))
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib SONAME := $(LIBNAME).$(MAJOR).dylib
REALNAME := $(LINKERNAME) REALNAME := $(LINKERNAME)
else endif
ifeq ($(UNAME_S),OpenBSD)
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
endif
ifeq ($(UNAME_S),Linux)
LINKERNAME := $(LIBNAME).so LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR) SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR) REALNAME := $(SONAME).$(MINOR).$(PATCH)
endif endif
STATICLIB := $(LIBNAME).a
BUILDDIR := build/intermediates/
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR ?= $(PREFIX)/bin BINDIR ?= $(PREFIX)/bin
LIBDIR ?= $(PREFIX)/lib CONFIGDIR ?= $(PREFIX)/etc
INCLUDEDIR ?= $(PREFIX)/include INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
DATADIR ?= $(PREFIX)/share DATADIR ?= $(PREFIX)/share
MANDIR ?= $(DATADIR)/man MANDIR ?= $(DATADIR)/man
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
SRCS := $(wildcard *.cpp) SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(subst .cpp,.o,$(SRCS)) OBJS := $(SRCS:.cpp=.o)
DEPS := $(subst .cpp,.d,$(SRCS)) DEPS := $(SRCS:.cpp=.d)
HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp)) HDRS := $(wildcard src/*.hpp)
CXX ?= g++ 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) ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0 CXXFLAGS += -D DEBUG -O0
CONFIG := debug
else else
CXXFLAGS += -D NDEBUG -O3 CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif endif
OUTDIR := build/$(CONFIG)/
LDLIBS := RM := /bin/rm -rf
RM := /bin/rm -f
INSTALL := /usr/bin/install -c INSTALL := /usr/bin/install -c
all: $(REALNAME) vpath %.cpp src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
$(REALNAME): $(OBJS) $(DEPS) .PHONY: all clean install prebuild test
all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
$(OUTDIR)$(REALNAME): $(OBJS) $(DEPS)
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
$(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS) $(CXX) -dynamiclib -o $(OUTDIR)$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
else endif
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS) 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 endif
%.o: %.cpp %.d Makefile %.o: %.cpp %.d Makefile
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
-include *.d -include $(BUILDDIR)*.d
%.d: ; %.d: ;
$(OUTDIR)$(STATICLIB): $(OBJS)
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
$(LIBNAME).hpp: $(HDRS) $(LIBNAME).hpp: $(HDRS)
@echo updating $(LIBNAME).hpp @echo updating build/$(LIBNAME).hpp
@cp /dev/null $(LIBNAME).hpp @cp /dev/null build/$(LIBNAME).hpp
@for h in $(HDRS); \ @for h in $(HDRS); \
do \ do \
cat $$h >> $(LIBNAME).hpp; \ cat $$h >> build/$(LIBNAME).hpp; \
done done
.PHONY: test clean install
test: test:
make -C tester clean $(MAKE) -C tests && tests/tests
make -C tester && tester/tester
clean: clean:
$(RM) $(OBJS) $(DEPS) $(REALNAME) $(LIBNAME).hpp $(RM) build
$(MAKE) -C tests clean
install: $(REALNAME) $(LIBNAME).hpp install: $(OUTDIR)$(REALNAME) $(LIBNAME).hpp
$(INSTALL) -m 644 $(REALNAME) $(LIBDIR) $(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(LIBNAME).hpp $(INCLUDEDIR) $(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
$(INSTALL) -d $(INCLUDEDIR)
$(INSTALL) -m 644 build/$(LIBNAME).hpp $(INCLUDEDIR)
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME) cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
else endif
ifeq ($(UNAME_S),Linux)
ldconfig ldconfig
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME) cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
endif endif

5
premake.make Normal file
View File

@ -0,0 +1,5 @@
LDLIBS :=
MAJOR := 1
MINOR := 0
PATCH := 0