From e55c019ef014a093202e7ce8d9df80dc875ccbf3 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Mon, 23 Dec 2024 16:18:39 +0100 Subject: [PATCH] Add template files --- tpl/Makefile.plugin | 51 +++++++ tpl/Makefile.simple | 31 ++++ tpl/Makefile.unified | 293 ++++++++++++++++++++++++++++++++++++++ tpl/filter.cpp | 73 ++++++++++ tpl/gitignore | 2 + tpl/lib.3 | 30 ++++ tpl/main.cpp | 57 ++++++++ tpl/main.simple.cpp | 5 + tpl/precomp.hpp | 127 +++++++++++++++++ tpl/premake.lib.make | 36 +++++ tpl/premake.plugin.make | 26 ++++ tpl/premake.tool.make | 31 ++++ tpl/tests/Makefile | 1 + tpl/tests/postmake.make | 6 + tpl/tests/premake.make | 5 + tpl/tests/src/main.cpp | 8 ++ tpl/tests/src/precomp.hpp | 1 + tpl/tool.1 | 59 ++++++++ tpl/version.cpp | 19 +++ tpl/version.hpp | 8 ++ 20 files changed, 869 insertions(+) create mode 100644 tpl/Makefile.plugin create mode 100644 tpl/Makefile.simple create mode 100644 tpl/Makefile.unified create mode 100644 tpl/filter.cpp create mode 100644 tpl/gitignore create mode 100644 tpl/lib.3 create mode 100644 tpl/main.cpp create mode 100644 tpl/main.simple.cpp create mode 100644 tpl/precomp.hpp create mode 100644 tpl/premake.lib.make create mode 100644 tpl/premake.plugin.make create mode 100644 tpl/premake.tool.make create mode 120000 tpl/tests/Makefile create mode 100644 tpl/tests/postmake.make create mode 100644 tpl/tests/premake.make create mode 100644 tpl/tests/src/main.cpp create mode 120000 tpl/tests/src/precomp.hpp create mode 100644 tpl/tool.1 create mode 100644 tpl/version.cpp create mode 100644 tpl/version.hpp diff --git a/tpl/Makefile.plugin b/tpl/Makefile.plugin new file mode 100644 index 0000000..d995ea7 --- /dev/null +++ b/tpl/Makefile.plugin @@ -0,0 +1,51 @@ +include premake.make + +# some important install locations +PREFIX ?= /usr/local +DATADIR ?= $(PREFIX)/share +INSTALLDIR ?= $(DATADIR)/$(INSTALLDIRNAME) + +SRCS := $(wildcard *.cpp) +OBJS := $(SRCS:.cpp=.o) +DEPS := $(SRCS:.cpp=.dep) + +CXX ?= g++ + +CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter +CXXFLAGS += -g3 -fPIC +ifeq ($(DEBUG),1) + CXXFLAGS += -DDEBUG -O0 +else + CXXFLAGS += -DNDEBUG -O3 +endif + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $*.dep -c $< + +%.dep: ; + +.PHONY: clean install uninstall + +$(PLUGIN): $(OBJS) +ifeq ($(UNAME_S),Darwin) + $(CXX) -g3 -dynamiclib -o $(PLUGIN) $(LDFLAGS) $(OBJS) $(LDLIBS) +else + $(CXX) -g3 -shared -o $(PLUGIN) $(LDFLAGS) $(OBJS) $(LDLIBS) +endif + +-include $(DEPS) + +clean: + rm -f $(OBJS) $(DEPS) $(PLUGIN) + +$(INSTALLDIR): + install -m 0755 -d $@ + +install: $(INSTALLDIR) + install -m 0644 $(PLUGIN) $(INSTALLDIR) +ifdef EXTRAFILES + install $(EXTRAFILES) $(INSTALLDIR) +endif + +uninstall: + rm -f $(INSTALLDIR)/$(PLUGIN) $(addprefix $(INSTALLDIR)/, $(EXTRAFILES)) diff --git a/tpl/Makefile.simple b/tpl/Makefile.simple new file mode 100644 index 0000000..305b01c --- /dev/null +++ b/tpl/Makefile.simple @@ -0,0 +1,31 @@ +LDLIBS := + +PROJ := $(shell basename $$(pwd)) + +SRCS := $(wildcard *.cpp) +OBJS := $(SRCS:.cpp=.o) +DEPS := $(SRCS:.cpp=.dep) + +CXX ?= g++ + +CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter +CXXFLAGS += -g3 -std=c++20 +ifeq ($(DEBUG),1) + CXXFLAGS += -DDEBUG -O0 +else + CXXFLAGS += -DNDEBUG -O3 +endif + +%.o: %.cpp + $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.dep -c $< + +%.dep: ; + +$(PROJ): $(OBJS) + $(CXX) $(LDFLAGS) -o $(PROJ) $(OBJS) $(LDLIBS) + +-include $(DEPS) + +.PHONY: clean +clean: + rm -f $(OBJS) $(DEPS) $(PROJ) diff --git a/tpl/Makefile.unified b/tpl/Makefile.unified new file mode 100644 index 0000000..e4e5bdc --- /dev/null +++ b/tpl/Makefile.unified @@ -0,0 +1,293 @@ +include premake.make + +# git commit hash and version for this build +COMMIT-HASH != git log 2>/dev/null | sed -e '1s/^commit //;q' +COMMIT := "const char* commit = \"$(COMMIT-HASH)\";" +VERSION := "const char* version = \"$(MAJOR).$(MINOR).$(PATCH)\";" + +# some important install locations +PREFIX ?= /usr/local +BINDIR ?= $(PREFIX)/bin +CONFIGDIR ?= $(PREFIX)/etc +INCLUDEDIR ?= $(PREFIX)/include +LIBDIR ?= $(PREFIX)/lib +MANDIR ?= $(PREFIX)/man +DATADIR ?= $(PREFIX)/share/$(PROJ) +DOCDIR ?= $(DATADIR)/doc + +# setup naming and versioning for library product +ifeq ($(UNAME_S), Darwin) + LINKERNAME := $(PROJ).dylib + SONAME := $(PROJ).$(MAJOR).dylib + REALNAME := $(LINKERNAME) +else ifeq ($(UNAME_S), OpenBSD) + REALNAME := $(PROJ).so.$(MAJOR).$(MINOR) +else ifeq ($(UNAME_S), Linux) + LINKERNAME := $(PROJ).so + SONAME := $(LINKERNAME).$(MAJOR) + REALNAME := $(SONAME).$(MINOR).$(PATCH) +endif +STATICLIB := $(PROJ).a + +# select default compiler +CXX ?= g++ + +# setup compiler flags and build config +CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter +CXXFLAGS += -g3 -fPIC +ifeq ($(DEBUG), 1) + CXXFLAGS += -DDEBUG -O0 + CONFIG := debug +else + CXXFLAGS += -DNDEBUG -O3 + CONFIG := release +endif + +# setup build locations +OUTDIR := build/$(CONFIG) +BUILDDIR := build/obj +BIN := $(OUTDIR)/$(PROJ) + +# define sources and derived files +# allow for extra sources defined in premake.make +SRCS += $(notdir $(wildcard src/*.cpp)) +OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o)) +DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep)) +HDRS ?= $(wildcard src/*.hpp) +MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*)) + +# if project supports plugins, link to libdl where needed +ifdef PLUGINS +ifeq ($(UNAME_S),Darwin) + LDLIBS += -ldl +else ifeq ($(UNAME_S),Linux) + LDLIBS += -ldl +endif +endif + +# pattern rules =========================================================== + +$(BUILDDIR)/%.o: src/%.cpp +ifeq ($(PRECOMPILE), 1) + $(CXX) $(CXXFLAGS) -o $@ -include precomp.hpp -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< +else + $(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< +endif + +%.dep: ; + +$(MANDIR)/man1/%: man/man1/% + install -m 0644 $< $@ + +$(MANDIR)/man3/%: man/man3/% + install -m 0644 $< $@ + +$(MANDIR)/man5/%: man/man5/% + install -m 0644 $< $@ + +# =========================================================== pattern rules + +# targets ================================================================= + +.PHONY: all commit-hash version plugins test clean dist-clean install-plugins \ +install install-data uninstall-data uninstall-plugins uninstall + +# main target +ifeq ($(PRODUCT), tool) +all: $(BUILDDIR) $(OUTDIR) commit-hash version plugins $(BIN) +else ifeq ($(PRODUCT), lib) +all: $(BUILDDIR) $(OUTDIR) commit-hash version plugins $(OUTDIR)/$(REALNAME) $(OUTDIR)/$(STATICLIB) +endif + +$(BUILDDIR): + mkdir -p $@ + +$(OUTDIR): + mkdir -p $@ + +# product build rules +ifeq ($(PRODUCT), tool) # -------------------------------------------- tool + +ifeq ($(PRECOMPILE), 1) +$(BIN): precomp.hpp.gch $(OBJS) +else +$(BIN): $(OBJS) +endif + $(CXX) -o $(BIN) $(LDFLAGS) $(OBJS) $(LDLIBS) + @ln -sf $(BIN) $(PROJ) + +endif # -------------------------------------------------------------- tool + +ifeq ($(PRODUCT), lib) # ---------------------------------------------- lib + +ifeq ($(PRECOMPILE), 1) +$(OUTDIR)/$(REALNAME): precomp.hpp.gch $(OBJS) +else +$(OUTDIR)/$(REALNAME): $(OBJS) +endif +ifeq ($(UNAME_S),Darwin) + $(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS) +else ifeq ($(UNAME_S),OpenBSD) + $(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS) +else ifeq ($(UNAME_S),Linux) + $(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS) +endif + +$(OUTDIR)/$(STATICLIB): $(OBJS) + ar r $(OUTDIR)/$(STATICLIB) $(OBJS) + +ifeq ($(GENERATELIBHEADER),1) +$(OUTDIR)/$(PROJ).hpp: $(HDRS) + @echo updating $(OUTDIR)/$(PROJ).hpp + @cp /dev/null $(OUTDIR)/$(PROJ).hpp + @for h in $(HDRS); \ + do \ + sed '/@exclude/d' $$h >> $(OUTDIR)/$(PROJ).hpp; \ + done +endif + +endif # --------------------------------------------------------------- lib + +# get generated dependencies, if any +-include $(DEPS) + +commit-hash: + @if ! echo $(COMMIT) | diff -q src/commit.inc - >/dev/null 2>&1 ;\ + then \ + echo $(COMMIT) > src/commit.inc ;\ + fi + +version: + @if ! echo $(VERSION) | diff -q src/version.inc - >/dev/null 2>&1 ;\ + then \ + echo $(VERSION) > src/version.inc ;\ + fi + +$(BUILDDIR)/version.o: src/version.inc src/commit.inc + +precomp.hpp.gch: src/precomp.hpp + $(CXX) $< $(CXXFLAGS) -o $@ + +plugins: +ifdef PLUGINS + @for plug in $(PLUGINS) ;\ + do \ + $(MAKE) -C $$plug ;\ + done +endif + +test: + $(MAKE) -C tests && tests/tests + +clean: + rm -rf $(BUILDDIR) tests/build tests/tests tests/src/commit.inc tests/src/version.inc +ifdef PLUGINS + @for plug in $(PLUGINS) ;\ + do \ + $(MAKE) -C $$plug clean ;\ + done +endif + +dist-clean: clean + rm -rf build $(PROJ) src/commit.inc src/version.inc precomp.hpp.gch + +$(MANDIR)/man1: + install -m 0755 -d $@ + +$(MANDIR)/man3: + install -m 0755 -d $@ + +$(MANDIR)/man5: + install -m 0755 -d $@ + +$(DATADIR): + install -m 0755 -d $@ + +# (un)install targets + +ifdef DATAFILES +install-data: $(DATADIR) + install -m 0644 $(DATAFILES) $(DATADIR) +else +install-data: +endif + +uninstall-data: + rm -rf $(DATADIR) + +install-plugins: +ifdef PLUGINS + @for plug in $(PLUGINS) ;\ + do \ + $(MAKE) -C $$plug install ;\ + done +endif + +uninstall-plugins: +ifdef PLUGINS + @for plug in $(PLUGINS) ;\ + do \ + $(MAKE) -C $$plug uninstall ;\ + done +endif + +ifeq ($(PRODUCT), tool) # -------------------------------------------- tool + +$(BINDIR): + install -m 0755 -d $@ + +install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(BINDIR) $(MANS) install-data install-plugins + install -m 0755 $(BIN) $(BINDIR) + +uninstall: uninstall-data uninstall-plugins + rm -f $(BINDIR)/$(PROJ) $(MANS) + +endif # -------------------------------------------------------------- tool + +ifeq ($(PRODUCT), lib) # ---------------------------------------------- lib + +$(LIBDIR): + install -m 0755 -d $@ + +$(INCLUDEDIR): + install -m 0755 -d $@ + +$(INCLUDEDIR)/$(PROJ): + install -m 0755 -d $@ + +ifeq ($(GENERATELIBHEADER), 1) +install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(OUTDIR)/$(PROJ).hpp install-data install-plugins + install -m 0644 $(OUTDIR)/$(PROJ).hpp $(INCLUDEDIR) +else +install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(INCLUDEDIR)/$(PROJ) install-data install-plugins + install -m 0644 $(HDRS) $(INCLUDEDIR)/$(PROJ) +endif + install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR) + install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR) +ifeq ($(UNAME_S), Darwin) + cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME) +else ifeq ($(UNAME_S), Linux) +ifeq ($(USER), root) + ldconfig +else + cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME) +endif + cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME) +else ifeq ($(UNAME_S), OpenBSD) + ldconfig -R +endif + +uninstall: uninstall-data uninstall-plugins + rm -rf $(INCLUDEDIR)/$(PROJ).hpp $(INCLUDEDIR)/$(PROJ) $(MANS) $(LIBDIR)/$(STATICLIB) $(LIBDIR)/$(REALNAME) $(LIBDIR)/$(SONAME) $(LIBDIR)/$(LINKERNAME) +ifeq ($(UNAME_S), Linux) + ldconfig +else ifeq ($(UNAME_S), OpenBSD) + ldconfig -R +endif + +endif # --------------------------------------------------------------- lib + +# ================================================================= targets + +# project-specific targets go in here +-include postmake.make diff --git a/tpl/filter.cpp b/tpl/filter.cpp new file mode 100644 index 0000000..6083847 --- /dev/null +++ b/tpl/filter.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include +#include +#include +#include "version.hpp" + +void print_help() { + std::cout << "usage: {PROJECT} [-h]\n"; + std::cout << " -h, --help show this help text and exit\n"; + std::cout << " --version show version number and exit\n"; +} + +std::string filter(const std::string& text) { + std::string result; + // your filter code here + result = text; // null-filter + return result; +} + +int main(int argc, char * argv[]) { + try { + int opt_char, opt_val; + struct option long_options[] = { + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, &opt_val, 1}, + {nullptr, 0, nullptr, 0} + }; + while ((opt_char = getopt_long(argc, argv, "h", long_options, nullptr)) != -1) { + switch (opt_char) { + case 0: { + // handle long-only options here + switch (opt_val) { + case 1: + std::cout << {PROJECT}_version() << std::endl; + return EXIT_SUCCESS; + } + break; + } + case 'h': + print_help(); + return EXIT_SUCCESS; + case '?': + throw std::runtime_error("unrecognized option"); + } + } + if (optind == argc) { + // no file args => read lines from stdin + std::string line; + while (getline(std::cin, line)) { + std::cout << filter(line) << '\n'; + } + } + for (int i = optind; i < argc; ++i) { + try { + // process file argv[i] + std::ifstream file {argv[i]}; + std::string line; + while (getline(file, line)) { + std::cout << filter(line) << '\n'; + } + } catch (const std::runtime_error& ex) { + std::cerr << "{PROJECT}: " << ex.what() << '\n'; + } + } + } catch (const std::exception& ex) { + std::cerr << "{PROJECT}: " << ex.what() << '\n'; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/tpl/gitignore b/tpl/gitignore new file mode 100644 index 0000000..44a1a4f --- /dev/null +++ b/tpl/gitignore @@ -0,0 +1,2 @@ +*.inc +{PROJECT} diff --git a/tpl/lib.3 b/tpl/lib.3 new file mode 100644 index 0000000..2091148 --- /dev/null +++ b/tpl/lib.3 @@ -0,0 +1,30 @@ +.Dd $Mdocdate$ +.Dt {PROJECT} 3 +.Os +.Sh NAME +.Nm {PROJECT} +.Nd one line about what it does +.\" .Sh LIBRARY +.\" For sections 2, 3, and 9 only. +.\" Not used in OpenBSD. +.Sh DESCRIPTION +The +.Nm +library ... +.\" .Sh RETURN VALUES +.\" For sections 2, 3, and 9 function return values only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" .Sh ERRORS +.\" For sections 2, 3, 4, and 9 errno settings only. +.\" .Sh SEE ALSO +.\" .Xr foobar 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.Sh AUTHORS +Bob Polis +.\" .Sh CAVEATS +.\" .Sh BUGS +.\" .Sh SECURITY CONSIDERATIONS +.\" Not used in OpenBSD. diff --git a/tpl/main.cpp b/tpl/main.cpp new file mode 100644 index 0000000..a08c721 --- /dev/null +++ b/tpl/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include "version.hpp" + +void print_help() { + std::cout << "usage: {PROJECT} [-h|--version]\n"; + std::cout << " -h, --help show this help text and exit\n"; + std::cout << " --version show version number and exit\n"; +} + +int main(int argc, char* argv[]) { + try { + int opt_char, opt_val; + struct option long_options[] = { + {"help", no_argument, nullptr, 'h'}, + {"version", no_argument, &opt_val, 1}, + {nullptr, 0, nullptr, 0} + }; + while ((opt_char = getopt_long(argc, argv, "h", long_options, nullptr)) != -1) { + std::string arg {optarg ? optarg : ""}; + switch (opt_char) { + case 0: { + // handle long-only options here + switch (opt_val) { + case 1: + std::cout << {PROJECT}_version() << std::endl; + return EXIT_SUCCESS; + } + break; + } + case 'h': + print_help(); + return EXIT_SUCCESS; + case '?': + throw std::runtime_error("unrecognized option"); + } + } + if (optind == argc) { + // here when no file args + } + for (int i = optind; i < argc; ++i) { + try { + // process file argv[i] + } catch (const std::runtime_error& ex) { + std::cerr << "{PROJECT}: " << ex.what() << '\n'; + } + } + std::cout << "hello, {PROJECT}\n"; + } catch (const std::exception& ex) { + std::cerr << "{PROJECT}: " << ex.what() << '\n'; + return EXIT_FAILURE; + } + return EXIT_SUCCESS; +} diff --git a/tpl/main.simple.cpp b/tpl/main.simple.cpp new file mode 100644 index 0000000..7a6dbad --- /dev/null +++ b/tpl/main.simple.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + +} diff --git a/tpl/precomp.hpp b/tpl/precomp.hpp new file mode 100644 index 0000000..182bcb4 --- /dev/null +++ b/tpl/precomp.hpp @@ -0,0 +1,127 @@ +// C++98 (first official C++ standard) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if (__cplusplus >= 201103L) // C++11 +#include +#include +#include +#include +#include +#include // deprecated in C++17, removed in C++26 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++11 + +#if (__cplusplus >= 201402L) // C++14 +#include +#endif // C++14 + +#if (__cplusplus >= 201703L) // C++17 +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++17 + +#if (__cplusplus >= 202002L) // C++20 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include not yet supported by clang 16 +//#include not yet supported by clang 17 +#include +#endif // C++20 + +#if (__cplusplus >= 202302L) // C++23 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // C++23 + +#if (__cplusplus > 202302L) // C++26 +#include +#include +#include +#include +#include +#include +#endif // C++26 diff --git a/tpl/premake.lib.make b/tpl/premake.lib.make new file mode 100644 index 0000000..8d5e0c4 --- /dev/null +++ b/tpl/premake.lib.make @@ -0,0 +1,36 @@ +# Define linker flags here, like: -lsqlite3 -lpthread +LDLIBS := + +# Dir name becomes product name. +PROJ := $(shell basename $$(pwd)) + +# Find out what platform we're on, e.g. Darwin, Linux, OpenBSD. +UNAME_S := $(shell uname -s) + +# We will build a library, not a tool. +PRODUCT := lib + +# Single source of truth for version. +MAJOR := 1 +MINOR := 0 +PATCH := 0 + +# Specify desired C++ standard for this project. +CXXFLAGS += -std=c++20 + +# Set to 1 if you want a precompiled header for the C++ Standard Library. +PRECOMPILE := 0 + +# Set to 0 if you want to create a library header by hand. +# By default, it will concatenate all headers, leaving out +# lines containing: @exclude +GENERATELIBHEADER := 1 + +# List of extra files to be installed in DATADIR (/usr/local/share/$(PROJ) by default) +DATAFILES := + +# Define plugin sub-projects here. Assumption here is a directory "plugins" +# containing plugin sub-projects, each in its own directory. +# Rename and/or repeat accordingly. +PLUGINS := $(wildcard plugins/*) +MAKE += --no-print-directory diff --git a/tpl/premake.plugin.make b/tpl/premake.plugin.make new file mode 100644 index 0000000..ec83504 --- /dev/null +++ b/tpl/premake.plugin.make @@ -0,0 +1,26 @@ +# Define linker flags here, like: -lsqlite3 -lpthread +LDLIBS := + +# Dir name becomes product name. +PROJ := $(shell basename $$(pwd)) + +# Find out what platform we're on, e.g. Darwin, Linux, OpenBSD. +UNAME_S := $(shell uname -s) + +# Change 'plugin' to your desired extension +PLUGIN := $(PROJ).plugin + +# Single source of truth for version (currently unused). +MAJOR := 1 +MINOR := 0 +PATCH := 0 + +# Specify desired C++ standard for this project. +CXXFLAGS += -std=c++20 + +# Change 'app' to product name for which this is a plugin. +# Change 'plugins' to the desired directory name for installed plugins. +INSTALLDIRNAME := app/plugins + +# Specify any other files here that need to be installed alongside the plugin. +EXTRAFILES := diff --git a/tpl/premake.tool.make b/tpl/premake.tool.make new file mode 100644 index 0000000..69cc27e --- /dev/null +++ b/tpl/premake.tool.make @@ -0,0 +1,31 @@ +# Define linker flags here, like: -lsqlite3 -lpthread +LDLIBS := + +# Dir name becomes product name. +PROJ := $(shell basename $$(pwd)) + +# Find out what platform we're on, e.g. Darwin, Linux, OpenBSD. +UNAME_S := $(shell uname -s) + +# We will build a tool, not a library. +PRODUCT := tool + +# Single source of truth for version. +MAJOR := 1 +MINOR := 0 +PATCH := 0 + +# Specify desired C++ standard for this project. +CXXFLAGS += -std=c++20 + +# Set to 1 if you want a precompiled header for the C++ Standard Library. +PRECOMPILE := 0 + +# List of extra files to be installed in DATADIR (/usr/local/share/$(PROJ) by default) +DATAFILES := + +# Define plugin sub-projects here. Assumption here is a directory "plugins" +# containing plugin sub-projects, each in its own directory. +# Rename and/or repeat accordingly. +PLUGINS := $(wildcard plugins/*) +MAKE += --no-print-directory diff --git a/tpl/tests/Makefile b/tpl/tests/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/tpl/tests/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/tpl/tests/postmake.make b/tpl/tests/postmake.make new file mode 100644 index 0000000..39e713a --- /dev/null +++ b/tpl/tests/postmake.make @@ -0,0 +1,6 @@ +$(BUILDDIR)/%.o: ../src/%.cpp +ifeq ($(PRECOMPILE), 1) + $(CXX) $(CXXFLAGS) -o $@ -include precomp.hpp -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< +else + $(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $< +endif diff --git a/tpl/tests/premake.make b/tpl/tests/premake.make new file mode 100644 index 0000000..d5cfa47 --- /dev/null +++ b/tpl/tests/premake.make @@ -0,0 +1,5 @@ +include ../premake.make +LDLIBS += -lboost_unit_test_framework +CXXFLAGS += -I../src +SRCS := $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp))) +PRODUCT := tool diff --git a/tpl/tests/src/main.cpp b/tpl/tests/src/main.cpp new file mode 100644 index 0000000..533ab2a --- /dev/null +++ b/tpl/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); +} diff --git a/tpl/tests/src/precomp.hpp b/tpl/tests/src/precomp.hpp new file mode 120000 index 0000000..821bca7 --- /dev/null +++ b/tpl/tests/src/precomp.hpp @@ -0,0 +1 @@ +../../src/precomp.hpp \ No newline at end of file diff --git a/tpl/tool.1 b/tpl/tool.1 new file mode 100644 index 0000000..cad4890 --- /dev/null +++ b/tpl/tool.1 @@ -0,0 +1,59 @@ +.Dd $Mdocdate$ +.Dt {PROJECT} 1 +.Os +.Sh NAME +.Nm {PROJECT} +.Nd one line about what it does +.\" .Sh LIBRARY +.\" For sections 2, 3, and 9 only. +.\" Not used in OpenBSD. +.Sh SYNOPSIS +.Nm +.Fl h +.Nm +.Fl \-version +.Nm +.Op Ar +.Sh DESCRIPTION +The +.Nm +utility processes files ... +When no file arguments are given, +.Nm +will read from the standard input. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl h, \-help +Print help text and exit. +.It Fl \-version +Print version info and exit. +.El +.\" .Sh CONTEXT +.\" For section 9 functions only. +.\" .Sh IMPLEMENTATION NOTES +.\" Not used in OpenBSD. +.\" .Sh RETURN VALUES +.\" For sections 2, 3, and 9 function return values only. +.\" .Sh ENVIRONMENT +.\" For sections 1, 6, 7, and 8 only. +.\" .Sh FILES +.Sh EXIT STATUS +.\" For sections 1, 6, and 8 only. +.Nm +exits 0 on success, and 1 if an error occurs. +.\" .Sh EXAMPLES +.\" .Sh DIAGNOSTICS +.\" For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only. +.\" .Sh ERRORS +.\" For sections 2, 3, 4, and 9 errno settings only. +.\" .Sh SEE ALSO +.\" .Xr foobar 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.Sh AUTHORS +Bob Polis +.\" .Sh CAVEATS +.\" .Sh BUGS +.\" .Sh SECURITY CONSIDERATIONS +.\" Not used in OpenBSD. diff --git a/tpl/version.cpp b/tpl/version.cpp new file mode 100644 index 0000000..0df3638 --- /dev/null +++ b/tpl/version.cpp @@ -0,0 +1,19 @@ +#include "version.hpp" +#include "version.inc" +#include "commit.inc" +#include + +std::string {PROJECT}_version() { + std::ostringstream oss; + oss << "{PROJECT} version " << version; +#ifdef DEBUG + oss << " DEBUG"; +#endif + oss << '\n'; + if (commit[0] != '\0') { + oss << "build " << commit << ", "; + } + oss << __DATE__ << ", " << __TIME__ << '\n'; + oss << "(c) Bob Polis, all rights reserved"; + return oss.str(); +} diff --git a/tpl/version.hpp b/tpl/version.hpp new file mode 100644 index 0000000..69d4429 --- /dev/null +++ b/tpl/version.hpp @@ -0,0 +1,8 @@ +#ifndef {PROJECT}_VERSION_H_ +#define {PROJECT}_VERSION_H_ + +#include + +std::string {PROJECT}_version(); + +#endif // {PROJECT}_VERSION_H_