Compare commits

...

9 Commits

5 changed files with 45 additions and 63 deletions

View File

@ -1,12 +1,9 @@
.Dd December 27, 2024
.Dd December 31, 2024
.Dt mkproj 1
.Os
.Sh NAME
.Nm mkproj
.Nd Create C++ project directory with predefined templates
.\" .Sh LIBRARY
.\" For sections 2, 3, and 9 only.
.\" Not used in OpenBSD.
.Sh SYNOPSIS
.Nm
.Fl v
@ -105,12 +102,6 @@ created.
The
.Sx Project Type Options
are mutually exclusive.
.\" .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
@ -127,7 +118,6 @@ Since it is shell syntax, paths should be properly quoted, and comments are
allowed.
.El
.Sh EXIT STATUS
.\" For sections 1, 6, and 8 only.
.Nm
exits 0 on success, and 1 if an error occurs.
.\" .Sh EXAMPLES
@ -139,9 +129,8 @@ exits 0 on success, and 1 if an error occurs.
The project created by
.Nm
has the following features.
.Ss Without Project Type Options
Without any options, a full-featured project for a tool will be created, with
the following layout:
.Ss Normal Tool Project
This creates a full-featured project for a tool, with the following layout:
.Bd -literal
mytool
|-- Makefile
@ -239,13 +228,13 @@ below for more information.
.It tests directory
Subdirectory for unit tests, using the Boost Unit Test Framework.
.El
.Ss Filter Project Type
The filter project has an identical structure as the normal type, but adds some
functionality to make the tool behave as a real UNIX filter.
.Ss Filter Tool Project
The filter tool project has an identical structure as the normal type, but adds
some functionality to make the tool behave as a real UNIX filter.
See
.Sx Tool Features
below for more information.
.Ss Library Project Type
.Ss Library Project
The library project has been set up to produce a static and dynamic library from
your sources.
Its directory structure is almost identical to that of a tool.
@ -256,8 +245,9 @@ When building the library, a static and dynamic library are produced, containing
by default a single function which can return a version string.
.Pp
TODO describe lib header generation, honoring @exclude
.Ss Simple Project Type
The simple project is just a directory with a single source file and a Makefile.
.Ss Simple Tool Project
The simple tool project is just a directory with a single source file and a
Makefile.
The idea is that you use this for simple, quick proof-of-concept tools.
Here, the source file has the same name as the project, and is almost empty, so
nothing is in the way to make it do what you want.
@ -268,6 +258,8 @@ as well as a
but no more.
Possible library dependencies should be added to the Makefile.
.Ss Makefile targets
The description below is valid for all project types, except the simple tool
project.
.Bl -tag -width Ds
.It make
Use this to compile and link your tool.
@ -336,7 +328,7 @@ TODO describe main.cpp and version.cpp here.
.\" .Sh STANDARDS
.\" .Sh HISTORY
.Sh AUTHORS
Bob Polis
.An Bob Polis
.\" .Sh CAVEATS
.Sh BUGS
.Nm

View File

@ -2,12 +2,12 @@
config=$HOME/.config/mkprojrc
source $config
default=0
default=false
mainfile=main.cpp
gitfav=0
library=0
simple=0
usegitroot=0
gitfav=false
library=false
simple=false
usegitroot=false
usage() {
echo "usage: $progname [-f|-l|-n|-s] [[-d] -g <gitroot>|-G] [-t <tplroot>] PROJECTNAME" >&2
@ -34,34 +34,34 @@ while getopts :dfGg:lnst:v opt
do
case $opt in
d)
default=1
default=true
;;
f)
mainfile=filter.cpp
;;
G)
gitfav=1
gitfav=true
;;
g)
gitroot=$OPTARG
usegitroot=1
usegitroot=true
;;
l)
library=1
library=true
;;
n)
mainfile=main.cpp
library=0
simple=0
library=false
simple=false
;;
s)
simple=1
simple=true
;;
t)
tplroot=$OPTARG
;;
v)
echo "$progname version 2.0.0"
echo "$progname version 2.0.1"
exit 0
;;
\?)
@ -83,7 +83,7 @@ shift $(( OPTIND - 1 ))
proj=${1//[- ]/_} # replace all spaces and dashes with underscores
if [ $default = 1 ]
if $default
then
check_gitroot
if grep -q gitroot $config
@ -94,7 +94,7 @@ then
fi
fi
if [ $gitfav = 1 ] || [ $usegitroot = 1 ]
if $gitfav || $usegitroot
then
check_gitroot
git clone "$gitroot/$proj.git" || die "not an existing repo: $proj"
@ -102,20 +102,20 @@ else
mkdir -p "$proj"
fi
if [ $simple = 1 ]
if $simple
then
cp $tplroot/Makefile.simple $proj/Makefile
sed -e "s/{PROJECT}/$proj/g" $tplroot/Makefile.simple > $proj/Makefile
cp $tplroot/main.simple.cpp $proj/$proj.cpp
else
mkdir -p $proj/src
cp $tplroot/Makefile.unified $proj/Makefile
cp $tplroot/precomp.hpp $proj/src
cp -r $tplroot/tests $proj/
cp -a $tplroot/tests $proj/
uproj=$(echo $proj | tr '[:lower:]' '[:upper:]')
sed -e "s/{PROJECT}/$proj/" -e "s/{PROJ}/$uproj/" $tplroot/version.hpp > $proj/src/version.hpp
sed -e "s/{PROJECT}/$proj/" $tplroot/version.cpp > $proj/src/version.cpp
if [ $library = 1 ]
if $library
then
mkdir -p $proj/man/man3
sed -e "s/{PROJECT}/$proj/" $tplroot/lib.3 > $proj/man/man3/$proj.3

View File

@ -49,3 +49,5 @@ endif
uninstall:
rm -f $(INSTALLDIR)/$(PLUGIN) $(addprefix $(INSTALLDIR)/, $(EXTRAFILES))
-include postmake.make

View File

@ -1,31 +1,18 @@
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)
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
%.o: %.cpp
c++ $(CXXFLAGS) -c $<
{PROJECT}: {PROJECT}.o
c++ -o {PROJECT} {PROJECT}.o
clean:
rm -f $(OBJS) $(DEPS) $(PROJ)
rm -f {PROJECT}.o {PROJECT}

View File

@ -16,7 +16,8 @@ MINOR := 0
PATCH := 0
# Specify desired C++ standard for this project.
CXXFLAGS += -std=c++20
# Include main project's src dir for header searching.
CXXFLAGS += -std=c++20 -I../../src
# Change 'app' to product name for which this is a plugin.
# Change 'plugins' to the desired directory name for installed plugins.