Update to modern project structure
Also, move progress tool into tests.
This commit is contained in:
parent
85a398ff3e
commit
72cc19c1b2
233
Makefile
233
Makefile
@ -1,54 +1,78 @@
|
|||||||
include premake.make
|
include premake.make
|
||||||
|
|
||||||
LIBNAME := $(shell basename $$(pwd))
|
# git commit hash and version for this build
|
||||||
UNAME_S := $(shell uname -s)
|
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
|
PREFIX ?= /usr/local
|
||||||
|
BINDIR ?= $(PREFIX)/bin
|
||||||
CONFIGDIR ?= $(PREFIX)/etc
|
CONFIGDIR ?= $(PREFIX)/etc
|
||||||
INCLUDEDIR ?= $(PREFIX)/include
|
INCLUDEDIR ?= $(PREFIX)/include
|
||||||
LIBDIR ?= $(PREFIX)/lib
|
LIBDIR ?= $(PREFIX)/lib
|
||||||
DATADIR ?= $(PREFIX)/share
|
|
||||||
DOCDIR ?= $(DATADIR)/$(LIBNAME)/doc
|
|
||||||
MANDIR ?= $(PREFIX)/man
|
MANDIR ?= $(PREFIX)/man
|
||||||
|
DATADIR ?= $(PREFIX)/share/$(PROJ)
|
||||||
|
DOCDIR ?= $(DATADIR)/doc
|
||||||
|
|
||||||
ifeq ($(UNAME_S),Darwin)
|
# setup naming and versioning for library product
|
||||||
LINKERNAME := $(LIBNAME).dylib
|
ifeq ($(UNAME_S), Darwin)
|
||||||
SONAME := $(LIBNAME).$(MAJOR).dylib
|
LINKERNAME := $(PROJ).dylib
|
||||||
|
SONAME := $(PROJ).$(MAJOR).dylib
|
||||||
REALNAME := $(LINKERNAME)
|
REALNAME := $(LINKERNAME)
|
||||||
endif
|
else ifeq ($(UNAME_S), OpenBSD)
|
||||||
ifeq ($(UNAME_S),OpenBSD)
|
REALNAME := $(PROJ).so.$(MAJOR).$(MINOR)
|
||||||
REALNAME := $(LIBNAME).so.$(MAJOR).$(MINOR)
|
else ifeq ($(UNAME_S), Linux)
|
||||||
endif
|
LINKERNAME := $(PROJ).so
|
||||||
ifeq ($(UNAME_S),Linux)
|
|
||||||
LINKERNAME := $(LIBNAME).so
|
|
||||||
SONAME := $(LINKERNAME).$(MAJOR)
|
SONAME := $(LINKERNAME).$(MAJOR)
|
||||||
REALNAME := $(SONAME).$(MINOR).$(PATCH)
|
REALNAME := $(SONAME).$(MINOR).$(PATCH)
|
||||||
endif
|
endif
|
||||||
STATICLIB := $(LIBNAME).a
|
STATICLIB := $(PROJ).a
|
||||||
|
|
||||||
|
# select default compiler
|
||||||
CXX ?= g++
|
CXX ?= g++
|
||||||
|
|
||||||
|
# setup compiler flags and build config
|
||||||
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
|
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
|
||||||
CXXFLAGS += -g3 -std=c++17 -fPIC
|
CXXFLAGS += -g3 -fPIC
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG), 1)
|
||||||
CXXFLAGS += -D DEBUG -O0
|
CXXFLAGS += -DDEBUG -O0
|
||||||
CONFIG := debug
|
CONFIG := debug
|
||||||
else
|
else
|
||||||
CXXFLAGS += -D NDEBUG -O3
|
CXXFLAGS += -DNDEBUG -O3
|
||||||
CONFIG := release
|
CONFIG := release
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# setup build locations
|
||||||
OUTDIR := build/$(CONFIG)
|
OUTDIR := build/$(CONFIG)
|
||||||
BUILDDIR := build/obj
|
BUILDDIR := build/obj
|
||||||
|
BIN := $(OUTDIR)/$(PROJ)
|
||||||
|
|
||||||
SRCS := $(notdir $(wildcard src/*.cpp))
|
# define sources and derived files
|
||||||
|
# allow for extra sources defined in premake.make
|
||||||
|
SRCS += $(notdir $(wildcard src/*.cpp))
|
||||||
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
|
OBJS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.o))
|
||||||
DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep))
|
DEPS := $(addprefix $(BUILDDIR)/, $(SRCS:.cpp=.dep))
|
||||||
HDRS ?= $(wildcard src/*.hpp)
|
HDRS ?= $(wildcard src/*.hpp)
|
||||||
MANS := $(addprefix $(PREFIX)/, $(wildcard man/man*/*))
|
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
|
$(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 $<
|
$(CXX) $(CXXFLAGS) -o $@ -MMD -MP -MT $@ -MF $(BUILDDIR)/$*.dep -c $<
|
||||||
|
endif
|
||||||
|
|
||||||
%.dep: ;
|
%.dep: ;
|
||||||
|
|
||||||
@ -61,9 +85,19 @@ $(MANDIR)/man3/%: man/man3/%
|
|||||||
$(MANDIR)/man5/%: man/man5/%
|
$(MANDIR)/man5/%: man/man5/%
|
||||||
install -m 0644 $< $@
|
install -m 0644 $< $@
|
||||||
|
|
||||||
.PHONY: all test clean install
|
# =========================================================== pattern rules
|
||||||
|
|
||||||
all: $(BUILDDIR) $(OUTDIR) $(OUTDIR)/$(REALNAME) $(OUTDIR)/$(STATICLIB)
|
# 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):
|
$(BUILDDIR):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
@ -71,29 +105,74 @@ $(BUILDDIR):
|
|||||||
$(OUTDIR):
|
$(OUTDIR):
|
||||||
mkdir -p $@
|
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)
|
$(OUTDIR)/$(REALNAME): $(OBJS)
|
||||||
|
endif
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
$(CXX) -dynamiclib -o $(OUTDIR)/$(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
endif
|
else ifeq ($(UNAME_S),OpenBSD)
|
||||||
ifeq ($(UNAME_S),OpenBSD)
|
|
||||||
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
$(CXX) -g -shared -Wl,-soname,$(REALNAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
endif
|
else ifeq ($(UNAME_S),Linux)
|
||||||
ifeq ($(UNAME_S),Linux)
|
|
||||||
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(OUTDIR)/$(REALNAME) $(LDFLAGS) $(OBJS) $(LDLIBS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
-include $(DEPS)
|
|
||||||
|
|
||||||
$(OUTDIR)/$(STATICLIB): $(OBJS)
|
$(OUTDIR)/$(STATICLIB): $(OBJS)
|
||||||
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
|
ar r $(OUTDIR)/$(STATICLIB) $(OBJS)
|
||||||
|
|
||||||
ifeq ($(GENERATELIBHEADER),1)
|
ifeq ($(GENERATELIBHEADER),1)
|
||||||
$(OUTDIR)/$(LIBNAME).hpp: $(HDRS)
|
$(OUTDIR)/$(PROJ).hpp: $(HDRS)
|
||||||
@echo updating $(OUTDIR)/$(LIBNAME).hpp
|
@echo updating $(OUTDIR)/$(PROJ).hpp
|
||||||
@cp /dev/null $(OUTDIR)/$(LIBNAME).hpp
|
@cp /dev/null $(OUTDIR)/$(PROJ).hpp
|
||||||
@for h in $(HDRS); \
|
@for h in $(HDRS); \
|
||||||
do \
|
do \
|
||||||
sed '/@exclude/d' $$h >> $(OUTDIR)/$(LIBNAME).hpp; \
|
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
|
done
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -101,8 +180,16 @@ test:
|
|||||||
$(MAKE) -C tests && tests/tests
|
$(MAKE) -C tests && tests/tests
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build
|
rm -rf $(BUILDDIR) tests/build tests/tests tests/src/commit.inc tests/src/version.inc
|
||||||
$(MAKE) -C tests clean
|
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:
|
$(MANDIR)/man1:
|
||||||
install -m 0755 -d $@
|
install -m 0755 -d $@
|
||||||
@ -113,34 +200,94 @@ $(MANDIR)/man3:
|
|||||||
$(MANDIR)/man5:
|
$(MANDIR)/man5:
|
||||||
install -m 0755 -d $@
|
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):
|
$(LIBDIR):
|
||||||
install -m 0755 -d $@
|
install -m 0755 -d $@
|
||||||
|
|
||||||
$(INCLUDEDIR):
|
$(INCLUDEDIR):
|
||||||
install -m 0755 -d $@
|
install -m 0755 -d $@
|
||||||
|
|
||||||
ifeq ($(GENERATELIBHEADER),1)
|
$(INCLUDEDIR)/$(PROJ):
|
||||||
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(OUTDIR)/$(LIBNAME).hpp
|
install -m 0755 -d $@
|
||||||
install -m 0644 $(OUTDIR)/$(LIBNAME).hpp $(INCLUDEDIR)
|
|
||||||
|
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
|
else
|
||||||
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS)
|
install: $(MANDIR)/man1 $(MANDIR)/man3 $(MANDIR)/man5 $(LIBDIR) $(INCLUDEDIR) $(MANS) $(INCLUDEDIR)/$(PROJ) install-data install-plugins
|
||||||
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(LIBNAME)
|
install -m 0644 $(HDRS) $(INCLUDEDIR)/$(PROJ)
|
||||||
endif
|
endif
|
||||||
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
|
install -m 0644 $(OUTDIR)/$(REALNAME) $(LIBDIR)
|
||||||
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
|
install -m 0644 $(OUTDIR)/$(STATICLIB) $(LIBDIR)
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S), Darwin)
|
||||||
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
||||||
endif
|
else ifeq ($(UNAME_S), Linux)
|
||||||
ifeq ($(UNAME_S),Linux)
|
|
||||||
ifeq ($(USER), root)
|
ifeq ($(USER), root)
|
||||||
ldconfig
|
ldconfig
|
||||||
else
|
else
|
||||||
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
||||||
endif
|
endif
|
||||||
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
|
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
|
||||||
endif
|
else ifeq ($(UNAME_S), OpenBSD)
|
||||||
ifeq ($(UNAME_S),OpenBSD)
|
|
||||||
ldconfig -R
|
ldconfig -R
|
||||||
endif
|
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
|
-include postmake.make
|
||||||
|
30
man/man3/libscterm.3
Normal file
30
man/man3/libscterm.3
Normal file
@ -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.
|
30
premake.make
30
premake.make
@ -1,8 +1,36 @@
|
|||||||
LDLIBS := -lscerror -lm
|
# Define linker flags here, like: -lsqlite3 -lpthread
|
||||||
|
LDLIBS := -lscerror -lm
|
||||||
|
|
||||||
|
# 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
|
MAJOR := 1
|
||||||
MINOR := 3
|
MINOR := 3
|
||||||
PATCH := 0
|
PATCH := 0
|
||||||
|
|
||||||
|
# Specify desired C++ standard for this project.
|
||||||
|
CXXFLAGS += -std=c++17
|
||||||
|
|
||||||
|
# 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
|
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
|
||||||
|
1
src/commit.inc
Normal file
1
src/commit.inc
Normal file
@ -0,0 +1 @@
|
|||||||
|
const char* commit = "85a398ff3e70ceb2fd735cf40a90e97bdd36badb";
|
127
src/precomp.hpp
Normal file
127
src/precomp.hpp
Normal 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
19
src/version.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "version.hpp"
|
||||||
|
#include "version.inc"
|
||||||
|
#include "commit.inc"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
std::string libscterm_version() {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "libscterm 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
8
src/version.hpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef VERSION_H_
|
||||||
|
#define VERSION_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
std::string libscterm_version();
|
||||||
|
|
||||||
|
#endif // VERSION_H_
|
1
src/version.inc
Normal file
1
src/version.inc
Normal file
@ -0,0 +1 @@
|
|||||||
|
const char* version = "1.3.0";
|
@ -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
1
tests/Makefile
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../Makefile
|
6
tests/postmake.make
Normal file
6
tests/postmake.make
Normal 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
5
tests/premake.make
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
include ../premake.make
|
||||||
|
LDLIBS += -lboost_unit_test_framework -lsccolor
|
||||||
|
CXXFLAGS += -I../src
|
||||||
|
SRCS := $(notdir $(filter-out ../src/main.cpp,$(wildcard ../src/*.cpp)))
|
||||||
|
PRODUCT := tool
|
1
tests/src/commit.inc
Normal file
1
tests/src/commit.inc
Normal file
@ -0,0 +1 @@
|
|||||||
|
const char* commit = "85a398ff3e70ceb2fd735cf40a90e97bdd36badb";
|
@ -1,8 +1,160 @@
|
|||||||
#define BOOST_TEST_MODULE My Test
|
#include <iostream>
|
||||||
#define BOOST_TEST_DYN_LINK
|
#include <ctime>
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <cstdlib>
|
||||||
|
#include <libscterm.hpp>
|
||||||
|
#include <libsccolor.hpp>
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(first_test)
|
void show_rows_cols(const sc::term& t) {
|
||||||
{
|
std::cout << t.rows() << " rows, " << t.cols() << " cols\n";
|
||||||
BOOST_TEST(1 == 1);
|
}
|
||||||
|
|
||||||
|
void show_progress(const sc::term& t) {
|
||||||
|
struct timespec tm;
|
||||||
|
tm.tv_nsec = 10000000;
|
||||||
|
tm.tv_sec = 0;
|
||||||
|
sc::cursor_hider ch {&std::cerr};
|
||||||
|
for (int i = 0; i < 1000; ++i) {
|
||||||
|
t.progress(12, "progress bar", i, 1000);
|
||||||
|
nanosleep(&tm, nullptr);
|
||||||
|
}
|
||||||
|
std::cerr << sc::io::clear_line(t);
|
||||||
|
std::cerr << "progress bar done.";
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_hue_bar(int top) {
|
||||||
|
int r = top;
|
||||||
|
int g = 0;
|
||||||
|
int b = 0;
|
||||||
|
// red -> yellow
|
||||||
|
while (g <= top) {
|
||||||
|
std::cerr << sc::io::rgbb(r, g++, b) << ' ';
|
||||||
|
}
|
||||||
|
g = top;
|
||||||
|
// yellow -> green
|
||||||
|
while (r >= 0) {
|
||||||
|
std::cerr << sc::io::rgbb(r--, g, b) << ' ';
|
||||||
|
}
|
||||||
|
r = 0;
|
||||||
|
// green -> cyan
|
||||||
|
while (b < top) {
|
||||||
|
std::cerr << sc::io::rgbb(r, g, b++) << ' ';
|
||||||
|
}
|
||||||
|
b = top;
|
||||||
|
// cyan -> blue
|
||||||
|
while (g >= 0) {
|
||||||
|
std::cerr << sc::io::rgbb(r, g--, b) << ' ';
|
||||||
|
}
|
||||||
|
g = 0;
|
||||||
|
// blue -> magenta
|
||||||
|
while (r <= top) {
|
||||||
|
std::cerr << sc::io::rgbb(r++, g, b) << ' ';
|
||||||
|
}
|
||||||
|
r = top;
|
||||||
|
// magenta -> red
|
||||||
|
while (b >= 0) {
|
||||||
|
std::cerr << sc::io::rgbb(r, g, b--) << ' ';
|
||||||
|
}
|
||||||
|
std::cerr << sc::io::reset << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_hue_bars() {
|
||||||
|
for (int top = 1; top < 6; ++top) {
|
||||||
|
show_hue_bar(top);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_grayscale_bar() {
|
||||||
|
for (int i = 0; i < 23; ++i) {
|
||||||
|
std::cerr << sc::io::grayb(i) << ' ';
|
||||||
|
}
|
||||||
|
std::cerr << sc::io::reset << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_words() {
|
||||||
|
std::cout << sc::io::redf << " red ";
|
||||||
|
std::cout << sc::io::greenf << " green ";
|
||||||
|
std::cout << sc::io::bluef << " blue ";
|
||||||
|
std::cout << sc::io::cyanf << " cyan ";
|
||||||
|
std::cout << sc::io::magentaf << " magenta ";
|
||||||
|
std::cout << sc::io::yellowf << " yellow ";
|
||||||
|
std::cout << sc::io::rgbf(5, 2, 0) << " orange ";
|
||||||
|
std::cout << sc::io::reset << std::endl;
|
||||||
|
std::cout << sc::io::blackf;
|
||||||
|
std::cout << sc::io::redb << " red ";
|
||||||
|
std::cout << sc::io::greenb << " green ";
|
||||||
|
std::cout << sc::io::blueb << " blue ";
|
||||||
|
std::cout << sc::io::cyanb << " cyan ";
|
||||||
|
std::cout << sc::io::magentab << " magenta ";
|
||||||
|
std::cout << sc::io::yellowb << " yellow ";
|
||||||
|
std::cout << sc::io::rgbb(5, 2, 0) << " orange ";
|
||||||
|
std::cout << sc::io::reset << std::endl;
|
||||||
|
std::cout << sc::io::bold;
|
||||||
|
std::cout << sc::io::redf << " red ";
|
||||||
|
std::cout << sc::io::greenf << " green ";
|
||||||
|
std::cout << sc::io::bluef << " blue ";
|
||||||
|
std::cout << sc::io::cyanf << " cyan ";
|
||||||
|
std::cout << sc::io::magentaf << " magenta ";
|
||||||
|
std::cout << sc::io::yellowf << " yellow ";
|
||||||
|
std::cout << sc::io::rgbf(5, 2, 0) << " orange ";
|
||||||
|
std::cout << sc::io::reset << std::endl;
|
||||||
|
std::cout << sc::io::blackf << sc::io::bold;
|
||||||
|
std::cout << sc::io::redb << " red ";
|
||||||
|
std::cout << sc::io::greenb << " green ";
|
||||||
|
std::cout << sc::io::blueb << " blue ";
|
||||||
|
std::cout << sc::io::cyanb << " cyan ";
|
||||||
|
std::cout << sc::io::magentab << " magenta ";
|
||||||
|
std::cout << sc::io::yellowb << " yellow ";
|
||||||
|
std::cout << sc::io::rgbb(5, 2, 0) << " orange ";
|
||||||
|
std::cout << sc::io::reset << std::endl;
|
||||||
|
std::cout << sc::io::bold << "bold " << sc::io::reset;
|
||||||
|
std::cout << sc::io::italic << "italic " << sc::io::reset;
|
||||||
|
std::cout << sc::io::underline << "underline" << sc::io::reset << ' ';
|
||||||
|
std::cout << sc::io::strikethru << "strike thru" << sc::io::reset << ' ';
|
||||||
|
std::cout << sc::io::overline << "overline" << sc::io::reset << ' ';
|
||||||
|
std::cout << sc::io::reverse << "reverse" << sc::io::reset << ' ';
|
||||||
|
std::cout << sc::io::blinkslow << "slow-blink" << sc::io::reset << ' ';
|
||||||
|
std::cout << sc::io::blinkfast << "fast-blink" << sc::io::reset;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_truecolor(const sc::term& t) {
|
||||||
|
// check for true color support
|
||||||
|
char* support = getenv("COLORTERM");
|
||||||
|
if (!support || support[0] == '\0') {
|
||||||
|
std::cerr << "this terminal has no true color support\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const char* lhb = u8"\u2584"; // lower half block
|
||||||
|
const double sat = 1.0;
|
||||||
|
for (double bri = 0; bri < 1; bri += 0.2) {
|
||||||
|
for (double hue = 0; hue < 359; hue += 360.0 / t.cols()) {
|
||||||
|
HSB hsbb = {hue, sat, bri};
|
||||||
|
Color bg {hsbb};
|
||||||
|
RGB rgbb = RGB(bg);
|
||||||
|
HSB hsbf = {hue, sat, bri + 0.1};
|
||||||
|
Color fg {hsbf};
|
||||||
|
RGB rgbf = RGB(fg);
|
||||||
|
std::cerr << sc::io::truecolorb(rgbb.r * 255, rgbb.g * 255, rgbb.b * 255);
|
||||||
|
std::cerr << sc::io::truecolorf(rgbf.r * 255, rgbf.g * 255, rgbf.b * 255);
|
||||||
|
std::cerr << lhb;
|
||||||
|
}
|
||||||
|
std::cerr << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
try {
|
||||||
|
sc::term term {STDERR_FILENO};
|
||||||
|
show_rows_cols(term);
|
||||||
|
show_grayscale_bar();
|
||||||
|
show_hue_bars();
|
||||||
|
show_words();
|
||||||
|
show_truecolor(term);
|
||||||
|
show_progress(term);
|
||||||
|
} catch (const std::exception& ex) {
|
||||||
|
std::cerr << sc::io::reset << ex.what() << std::endl;
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
1
tests/src/precomp.hpp
Symbolic link
1
tests/src/precomp.hpp
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
../../src/precomp.hpp
|
1
tests/src/version.inc
Normal file
1
tests/src/version.inc
Normal file
@ -0,0 +1 @@
|
|||||||
|
const char* version = "1.3.0";
|
Loading…
x
Reference in New Issue
Block a user