Migrate to latest project structure

This commit is contained in:
Bob Polis 2025-01-08 12:30:55 +01:00
parent c3106d9ebc
commit f73fe7fae2
11 changed files with 181 additions and 75 deletions

View File

@ -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
@ -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)

View File

@ -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

View File

@ -1,11 +1,3 @@
//
// main.cpp
// autogram
//
// Created by Bob Polis at 2020-11-19
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include <iostream>
#include <cstdlib>
#include <string>
@ -19,13 +11,14 @@
#include <sc/integer_locale.hpp>
#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 <relaxed|strict|pangram] ";
std::cout << "[-i <number>] ";
@ -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<std::string>& numerals, const std::string& db_path, int lang_id) {
static void read_nums_from_db(std::vector<std::string>& 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;

127
src/precomp.hpp Normal file
View File

@ -0,0 +1,127 @@
// C++98 (first official C++ standard)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if (__cplusplus >= 201103L) // C++11
#include <array>
#include <atomic>
#include <cfenv>
#include <chrono>
#include <cinttypes>
#include <codecvt> // deprecated in C++17, removed in C++26
#include <condition_variable>
#include <cstdint>
#include <cuchar>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif // C++11
#if (__cplusplus >= 201402L) // C++14
#include <shared_mutex>
#endif // C++14
#if (__cplusplus >= 201703L) // C++17
#include <any>
#include <charconv>
#include <execution>
#include <filesystem>
#include <memory_resource>
#include <optional>
#include <string_view>
#include <variant>
#endif // C++17
#if (__cplusplus >= 202002L) // C++20
#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#include <coroutine>
#include <format>
#include <latch>
#include <numbers>
#include <ranges>
#include <semaphore>
#include <source_location>
#include <span>
//#include <stop_token> not yet supported by clang 16
//#include <syncstream> not yet supported by clang 17
#include <version>
#endif // C++20
#if (__cplusplus >= 202302L) // C++23
#include <expected>
#include <flat_map>
#include <flat_set>
#include <generator>
#include <mdspan>
#include <print>
#include <spanstream>
#include <stacktrace>
#include <stdfloat>
#endif // C++23
#if (__cplusplus > 202302L) // C++26
#include <debugging>
#include <hazard_pointer>
#include <inplace_vector>
#include <linalg>
#include <rcu>
#include <text_encoding>
#endif // C++26

19
src/version.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "version.hpp"
#include <sstream>
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();
}

8
src/version.hpp Normal file
View File

@ -0,0 +1,8 @@
#ifndef _AUTOGRAM_VERSION_H_
#define _AUTOGRAM_VERSION_H_
#include <string>
std::string autogram_version();
#endif // _AUTOGRAM_VERSION_H_

View File

@ -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)

1
tests/Makefile Symbolic link
View File

@ -0,0 +1 @@
../Makefile

6
tests/postmake.make Normal file
View File

@ -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

5
tests/premake.make Normal file
View File

@ -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

1
tests/src/precomp.hpp Symbolic link
View File

@ -0,0 +1 @@
../../src/precomp.hpp