First commit

This commit is contained in:
Bob Polis 2023-11-05 00:07:19 +00:00
commit 5e3c8d10c3
4 changed files with 186 additions and 0 deletions

123
Makefile Normal file
View File

@ -0,0 +1,123 @@
include premake.make
LIBNAME := $(shell basename $$(pwd))
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINKERNAME := $(LIBNAME).dylib
SONAME := $(LIBNAME).$(MAJOR).dylib
REALNAME := $(LINKERNAME)
endif
ifeq ($(UNAME_S),OpenBSD)
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
endif
ifeq ($(UNAME_S),Linux)
LINKERNAME := $(LIBNAME).so
SONAME := $(LINKERNAME).$(MAJOR)
REALNAME := $(SONAME).$(MINOR).$(PATCH)
endif
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
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
SRCS := $(notdir $(wildcard src/*.cpp))
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)
HDRS ?= $(wildcard src/*.hpp)
CXX ?= g++
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter -Wno-unused-variable
CXXFLAGS += -g3 -std=c++17 -fPIC
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif
OUTDIR := build/$(CONFIG)/
RM := /bin/rm -rf
INSTALL := /usr/bin/install -c
vpath %.cpp src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
.PHONY: all clean install prebuild test
all: prebuild $(OUTDIR)$(REALNAME) $(OUTDIR)$(STATICLIB)
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
$(OUTDIR)$(REALNAME): $(OBJS)
ifeq ($(UNAME_S),Darwin)
$(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 %.d: %.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
-include $(addprefix $(BUILDDIR), $(DEPS))
$(OUTDIR)$(STATICLIB): $(OBJS)
ar r $(OUTDIR)$(STATICLIB) $(addprefix $(BUILDDIR),$(OBJS))
ifeq ($(GENERATELIBHEADER),1)
$(LIBNAME).hpp: $(HDRS)
@echo updating build/$(LIBNAME).hpp
@cp /dev/null build/$(LIBNAME).hpp
@for h in $(HDRS); \
do \
sed '/@exclude/d' $$h >> build/$(LIBNAME).hpp; \
done
HEADERSRCDIR := build
else
HEADERSRCDIR := src
INCLUDEDIR := $(INCLUDEDIR)/$(LIBNAME)
endif
test:
$(MAKE) -C tests && tests/tests
clean:
$(RM) build
$(MAKE) -C tests clean
ifeq ($(GENERATELIBHEADER),1)
install: $(LIBNAME).hpp
else
install:
endif
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -m 644 $(OUTDIR)$(REALNAME) $(LIBDIR)
$(INSTALL) -m 644 $(OUTDIR)$(STATICLIB) $(LIBDIR)
$(INSTALL) -d $(INCLUDEDIR)
$(INSTALL) -m 644 $(HEADERSRCDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
ifeq ($(UNAME_S),Darwin)
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
endif
ifeq ($(UNAME_S),Linux)
ldconfig
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
endif
ifeq ($(UNAME_S),OpenBSD)
ldconfig -R
endif

7
premake.make Normal file
View File

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

48
tests/Makefile Normal file
View File

@ -0,0 +1,48 @@
include ../premake.make
LDLIBS += -lboost_unit_test_framework
BIN := $(shell basename $$(pwd))
SRCS := $(notdir $(wildcard src/*.cpp))
SRCS += $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp)))
OBJS := $(SRCS:.cpp=.o)
DEPS := $(SRCS:.cpp=.d)
BUILDDIR := build/intermediates/
CXX ?= g++
RM := /bin/rm -rf
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -g -std=c++17 -I../src
ifeq ($(DEBUG),1)
CXXFLAGS += -D DEBUG -O0
CONFIG := debug
else
CXXFLAGS += -D NDEBUG -O3
CONFIG := release
endif
OUTDIR := build/$(CONFIG)/
vpath %.cpp src ../src
vpath %.d $(BUILDDIR)
vpath %.o $(BUILDDIR)
.PHONY: all clean prebuild
all: prebuild $(OUTDIR)$(BIN)
prebuild:
@mkdir -p $(BUILDDIR) $(OUTDIR)
$(OUTDIR)$(BIN): $(OBJS)
$(CXX) $(addprefix $(BUILDDIR),$(OBJS)) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN)
@ln -sf $(OUTDIR)$(BIN) $(BIN)
%.o %.d: %.cpp
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
@mv $@ $*.d $(BUILDDIR)
-include $(addprefix $(BUILDDIR), $(DEPS))
clean:
$(RM) build $(BIN)

8
tests/src/main.cpp Normal file
View File

@ -0,0 +1,8 @@
#define BOOST_TEST_MODULE My Test
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(first_test)
{
BOOST_TEST(1 == 1);
}