First commit
This commit is contained in:
commit
4048e831bd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.inc
|
||||||
|
termage
|
79
Makefile
Normal file
79
Makefile
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
include premake.make
|
||||||
|
|
||||||
|
BIN := $(shell basename $$(pwd))
|
||||||
|
COMMIT != git log 2>/dev/null | sed -e '1s/^commit //;q'
|
||||||
|
|
||||||
|
MANSECTION ?= 1
|
||||||
|
MANPAGE := $(BIN).$(MANSECTION)
|
||||||
|
|
||||||
|
SRCS := $(notdir $(wildcard src/*.cpp))
|
||||||
|
OBJS := $(SRCS:.cpp=.o)
|
||||||
|
DEPS := $(SRCS:.cpp=.dep)
|
||||||
|
|
||||||
|
BUILDDIR := build/intermediates/
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
BINDIR ?= $(PREFIX)/bin
|
||||||
|
MANDIR ?= $(PREFIX)/man/man
|
||||||
|
CONFIGDIR ?= $(PREFIX)/etc
|
||||||
|
DATADIR ?= $(PREFIX)/share
|
||||||
|
DOCDIR ?= $(DATADIR)/$(BIN)/doc
|
||||||
|
|
||||||
|
CXX ?= g++
|
||||||
|
RM := /bin/rm -rf
|
||||||
|
INSTALL := /usr/bin/install -c
|
||||||
|
|
||||||
|
CXXFLAGS += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
|
||||||
|
CXXFLAGS += -g3 -std=c++20
|
||||||
|
ifeq ($(DEBUG),1)
|
||||||
|
CXXFLAGS += -D DEBUG -O0
|
||||||
|
CONFIG := debug
|
||||||
|
else
|
||||||
|
CXXFLAGS += -D NDEBUG -O3
|
||||||
|
CONFIG := release
|
||||||
|
endif
|
||||||
|
OUTDIR := build/$(CONFIG)/
|
||||||
|
|
||||||
|
vpath %.cpp src
|
||||||
|
vpath %.dep $(BUILDDIR)
|
||||||
|
vpath %.o $(BUILDDIR)
|
||||||
|
|
||||||
|
.PHONY: all clean install prebuild test dist-clean
|
||||||
|
|
||||||
|
all: prebuild $(OUTDIR)$(BIN)
|
||||||
|
|
||||||
|
prebuild: src/commit.inc
|
||||||
|
@mkdir -p $(BUILDDIR) $(OUTDIR)
|
||||||
|
sed -i.bak -e '1s/".*"/"$(COMMIT)"/' src/commit.inc
|
||||||
|
@rm src/commit.inc.bak
|
||||||
|
|
||||||
|
src/commit.inc:
|
||||||
|
echo 'const char* commit = "";' > $@
|
||||||
|
|
||||||
|
$(OUTDIR)$(BIN): $(OBJS)
|
||||||
|
$(CXX) -o $(OUTDIR)$(BIN) $(LDFLAGS) $(LDLIBS) $(addprefix $(BUILDDIR),$(OBJS))
|
||||||
|
@ln -sf $(OUTDIR)$(BIN) $(BIN)
|
||||||
|
|
||||||
|
%.o %.dep: %.cpp
|
||||||
|
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.dep -c $<
|
||||||
|
@mv $@ $*.dep $(BUILDDIR)
|
||||||
|
|
||||||
|
-include $(addprefix $(BUILDDIR), $(DEPS))
|
||||||
|
|
||||||
|
test:
|
||||||
|
$(MAKE) -C tests && tests/tests
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) $(BUILDDIR)
|
||||||
|
$(MAKE) -C tests clean
|
||||||
|
|
||||||
|
dist-clean:
|
||||||
|
$(RM) build $(BIN) src/commit.inc
|
||||||
|
$(MAKE) -C tests clean
|
||||||
|
|
||||||
|
install:
|
||||||
|
$(INSTALL) -d $(BINDIR)
|
||||||
|
$(INSTALL) $(OUTDIR)$(BIN) $(BINDIR)
|
||||||
|
$(INSTALL) -d $(MANDIR)$(MANSECTION)
|
||||||
|
$(INSTALL) -m 0644 $(MANPAGE) $(MANDIR)$(MANSECTION)
|
||||||
|
|
||||||
|
-include postmake.make
|
2
premake.make
Normal file
2
premake.make
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
LDLIBS :=
|
||||||
|
MANSECTION := 1
|
65
src/main.cpp
Normal file
65
src/main.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <string>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include "commit.inc"
|
||||||
|
|
||||||
|
void print_help() {
|
||||||
|
std::cout << "usage: termage [-h|--version]\n";
|
||||||
|
std::cout << " -h, --help show this help text and exit\n";
|
||||||
|
std::cout << " --version show version number and exit\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_version() {
|
||||||
|
std::cout << "termage version 1.0";
|
||||||
|
if (commit[0] != '\0') {
|
||||||
|
std::cout << ", build " << commit;
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
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:
|
||||||
|
print_version();
|
||||||
|
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 << "termage: " << ex.what() << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "hello, termage\n";
|
||||||
|
} catch (const std::exception& ex) {
|
||||||
|
std::cerr << "termage: " << ex.what() << '\n';
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
59
termage.1
Normal file
59
termage.1
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
.Dd $Mdocdate$
|
||||||
|
.Dt termage 1
|
||||||
|
.Os
|
||||||
|
.Sh NAME
|
||||||
|
.Nm termage
|
||||||
|
.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.
|
51
tests/Makefile
Normal file
51
tests/Makefile
Normal file
@ -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
|
8
tests/src/main.cpp
Normal file
8
tests/src/main.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#define BOOST_TEST_MODULE My Test
|
||||||
|
#define BOOST_TEST_DYN_LINK
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(first_test)
|
||||||
|
{
|
||||||
|
BOOST_TEST(1 == 1);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user