From f73fe7fae2b7757cb3d8fe8aec3eb1377670201e Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Wed, 8 Jan 2025 12:30:55 +0100 Subject: [PATCH] Migrate to latest project structure --- Makefile | 13 +-- autogram.1 => man/man1/autogram.1 | 0 premake.make | 4 +- src/main.cpp | 21 ++--- src/precomp.hpp | 127 ++++++++++++++++++++++++++++++ src/version.cpp | 19 +++++ src/version.hpp | 8 ++ tests/Makefile | 52 +----------- tests/postmake.make | 6 ++ tests/premake.make | 5 ++ tests/src/precomp.hpp | 1 + 11 files changed, 181 insertions(+), 75 deletions(-) rename autogram.1 => man/man1/autogram.1 (100%) create mode 100644 src/precomp.hpp create mode 100644 src/version.cpp create mode 100644 src/version.hpp mode change 100644 => 120000 tests/Makefile create mode 100644 tests/postmake.make create mode 100644 tests/premake.make create mode 120000 tests/src/precomp.hpp diff --git a/Makefile b/Makefile index c9e58e4..032d08b 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ 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)\";" +COMMIT := "static const char* commit = \"$(COMMIT-HASH)\";" +VERSION := "static const char* version = \"$(MAJOR).$(MINOR).$(PATCH)\";" # some important install locations PREFIX ?= /usr/local @@ -36,10 +36,10 @@ CXX ?= g++ CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter CXXFLAGS += -g3 -fPIC ifeq ($(DEBUG), 1) - CXXFLAGS += -D DEBUG -O0 + CXXFLAGS += -DDEBUG -O0 CONFIG := debug else - CXXFLAGS += -D NDEBUG -O3 + CXXFLAGS += -DNDEBUG -O3 CONFIG := release endif @@ -53,7 +53,7 @@ BIN := $(OUTDIR)/$(PROJ) SRCS += $(notdir $(wildcard src/*.cpp)) OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o)) DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep)) -HDRS ?= $(wildcard src/*.hpp) +HDRS ?= $(filter-out src/precomp.hpp, $(wildcard src/*.hpp)) MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*)) # if project supports plugins, link to libdl where needed @@ -126,7 +126,8 @@ else $(OUTDIR)/$(REALNAME): $(OBJS) endif ifeq ($(UNAME_S),Darwin) - $(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS) + $(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -install_name $(LIBDIR)/$(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) diff --git a/autogram.1 b/man/man1/autogram.1 similarity index 100% rename from autogram.1 rename to man/man1/autogram.1 diff --git a/premake.make b/premake.make index 296d175..57d8643 100644 --- a/premake.make +++ b/premake.make @@ -1,5 +1,5 @@ # Define linker flags here, like: -lsqlite3 -lpthread -LDLIBS := -lm -lpthread -lsqlite3 +LDLIBS := -lsqlite3 # Dir name becomes product name. PROJ := $(shell basename $$(pwd)) @@ -13,7 +13,7 @@ PRODUCT := tool # Single source of truth for version. MAJOR := 1 MINOR := 0 -PATCH := 0 +PATCH := 1 # Specify desired C++ standard for this project. CXXFLAGS += -std=c++20 diff --git a/src/main.cpp b/src/main.cpp index 1ca60ca..593f543 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,3 @@ -// -// main.cpp -// autogram -// -// Created by Bob Polis at 2020-11-19 -// Copyright (c) 2020 SwiftCoder. All rights reserved. -// - #include #include #include @@ -19,13 +11,14 @@ #include #include "robinsonizer_mode.hpp" #include "engine.hpp" +#include "version.hpp" -void reset_term(int sig) { +static void reset_term(int sig) { std::cerr << "\nbreak\n\x1b[?25h"; // show cursor again exit(0); } -void print_help() { +static void print_help() { std::cout << "usage: autogram [-h|--version] "; std::cout << "[-a ] "; @@ -42,11 +35,7 @@ void print_help() { std::cout << " --version show version number and exit\n"; } -void print_version() { - std::cout << "autogram version 1.0\n"; -} - -void read_nums_from_db(std::vector& numerals, const std::string& db_path, int lang_id) { +static void read_nums_from_db(std::vector& numerals, const std::string& db_path, int lang_id) { sqlite3* db {nullptr}; int rc = sqlite3_open(db_path.c_str(), &db); if (rc) { @@ -102,7 +91,7 @@ int main(int argc, const char * argv[]) { // handle long-only options here switch (opt_val) { case 1: - print_version(); + std::cout << autogram_version() << '\n'; return EXIT_SUCCESS; } break; diff --git a/src/precomp.hpp b/src/precomp.hpp new file mode 100644 index 0000000..182bcb4 --- /dev/null +++ b/src/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/src/version.cpp b/src/version.cpp new file mode 100644 index 0000000..0284077 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,19 @@ +#include "version.hpp" +#include + +std::string autogram_version() { +#include "version.inc" +#include "commit.inc" + std::ostringstream oss; + oss << "autogram 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/src/version.hpp b/src/version.hpp new file mode 100644 index 0000000..4eabf67 --- /dev/null +++ b/src/version.hpp @@ -0,0 +1,8 @@ +#ifndef _AUTOGRAM_VERSION_H_ +#define _AUTOGRAM_VERSION_H_ + +#include + +std::string autogram_version(); + +#endif // _AUTOGRAM_VERSION_H_ diff --git a/tests/Makefile b/tests/Makefile deleted file mode 100644 index 7e524f5..0000000 --- a/tests/Makefile +++ /dev/null @@ -1,51 +0,0 @@ -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 -INSTALL := /usr/bin/install -c - -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) $(DEPS) - $(CXX) $(addprefix $(BUILDDIR),$(OBJS)) $(LDFLAGS) $(LDLIBS) -o $(OUTDIR)$(BIN) - @ln -sf $(OUTDIR)$(BIN) $(BIN) - -%.o: %.cpp %.d - $(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $< - @mv $@ $*.d $(BUILDDIR) - --include $(BUILDDIR)*.d - -%.d: ; - -clean: - $(RM) build $(BIN) diff --git a/tests/Makefile b/tests/Makefile new file mode 120000 index 0000000..d0b0e8e --- /dev/null +++ b/tests/Makefile @@ -0,0 +1 @@ +../Makefile \ No newline at end of file diff --git a/tests/postmake.make b/tests/postmake.make new file mode 100644 index 0000000..39e713a --- /dev/null +++ b/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/tests/premake.make b/tests/premake.make new file mode 100644 index 0000000..d5cfa47 --- /dev/null +++ b/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/tests/src/precomp.hpp b/tests/src/precomp.hpp new file mode 120000 index 0000000..821bca7 --- /dev/null +++ b/tests/src/precomp.hpp @@ -0,0 +1 @@ +../../src/precomp.hpp \ No newline at end of file