From 10b3fb47df4ee828465a51da24eb317def602672 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Tue, 23 Jan 2024 15:42:16 +0100 Subject: [PATCH] First commit --- .gitignore | 2 + Makefile | 125 +++++++++++++++++++++++++++++++++++++++++++++ premake.make | 7 +++ tests/Makefile | 51 ++++++++++++++++++ tests/src/main.cpp | 8 +++ 5 files changed, 193 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 premake.make create mode 100644 tests/Makefile create mode 100644 tests/src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b399883 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.inc +libsctimer diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ed1a0f4 --- /dev/null +++ b/Makefile @@ -0,0 +1,125 @@ +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 +CXXFLAGS += -g3 -std=c++20 -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 + +-include postmake.make diff --git a/premake.make b/premake.make new file mode 100644 index 0000000..e9bdcf6 --- /dev/null +++ b/premake.make @@ -0,0 +1,7 @@ +LDLIBS := + +MAJOR := 1 +MINOR := 0 +PATCH := 0 + +GENERATELIBHEADER := 1 diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..0762090 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,51 @@ +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 -Wno-unused-parameter +CXXFLAGS += -g3 -std=c++20 -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) + +-include postmake.make diff --git a/tests/src/main.cpp b/tests/src/main.cpp new file mode 100644 index 0000000..533ab2a --- /dev/null +++ b/tests/src/main.cpp @@ -0,0 +1,8 @@ +#define BOOST_TEST_MODULE My Test +#define BOOST_TEST_DYN_LINK +#include + +BOOST_AUTO_TEST_CASE(first_test) +{ + BOOST_TEST(1 == 1); +}