Compare commits
11 Commits
9a754c83fa
...
main
Author | SHA1 | Date | |
---|---|---|---|
e73fa39be1 | |||
1e32445243 | |||
9aaf7bccc1 | |||
7fa2dce9e5 | |||
63d2a2d0e2 | |||
acd78e092f | |||
4480c0a690 | |||
05bf0700b5 | |||
2d551c59e2 | |||
f3c40f4bd7 | |||
63dd34e926 |
103
mkproj.1
103
mkproj.1
@ -1,17 +1,14 @@
|
||||
.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
|
||||
.Nm
|
||||
.Op Fl f | Fl l | Fl s
|
||||
.Op Fl f | Fl l | Fl n | Fl s
|
||||
.Oo
|
||||
.Op Fl d
|
||||
.Fl g Ar gitroot
|
||||
@ -24,6 +21,13 @@ The
|
||||
script creates a C++ project directory structure with some predefined
|
||||
boilerplate files, ready to be built using
|
||||
.Xr make 1 .
|
||||
.Pp
|
||||
Please note that you will need GNU Make to use the supplied Makefiles, which is
|
||||
standard on Linux systems.
|
||||
On BSD systems, use
|
||||
.Xr gmake 1 ,
|
||||
which is usually available through a package manager for the platform.
|
||||
.Pp
|
||||
.Nm
|
||||
can create a directory for a simple project using a single source file; a
|
||||
general project suitable for many source files; a general project setup as a
|
||||
@ -40,37 +44,54 @@ display a version string, containing the
|
||||
.Xr git 1
|
||||
commit hash, after you have built the tool at least once.
|
||||
.Pp
|
||||
The options are as follows:
|
||||
The options for
|
||||
.Nm
|
||||
are as follows:
|
||||
.Ss General Options
|
||||
.Bl -tag -width Ds
|
||||
.It Fl \-version, v
|
||||
Print version info and exit.
|
||||
.It Fl \-gitroot Ar gitroot , Fl g Ar gitroot
|
||||
.It Fl d
|
||||
Save default Git URL to clone from.
|
||||
Will only have any effect when also using the
|
||||
.Fl g
|
||||
option.
|
||||
It will cause the
|
||||
.Ar gitroot
|
||||
argument for
|
||||
.Fl g
|
||||
to be saved into the
|
||||
.Nm
|
||||
configuration file, for later use with the
|
||||
.Fl G
|
||||
option.
|
||||
.It Fl g Ar gitroot
|
||||
Clone a
|
||||
.Xr git 1
|
||||
repo from the supplied git URL.
|
||||
When combined with the
|
||||
.Fl \-default
|
||||
or
|
||||
.Fl d
|
||||
option, the supplied git URL will be saved into the
|
||||
.Nm
|
||||
configuration file.
|
||||
.It Fl \-gitfav , Fl G
|
||||
Use the git URL saved earlier to clone a repo from.
|
||||
.It Fl \-tplroot Ar tplroot , Fl t Ar tplroot
|
||||
.It Fl G
|
||||
Use the Git URL saved earlier to clone a repo from.
|
||||
.It Fl t Ar tplroot
|
||||
Specify the root directory where the project templates can be found.
|
||||
This option is useful when you want to use a modified set of files to base your
|
||||
projects on.
|
||||
.It Fl v
|
||||
Print version info and exit.
|
||||
.El
|
||||
.Ss Project Type Options
|
||||
.Bl -tag -width Ds
|
||||
.It Fl \-filter, f
|
||||
Create a filter project.
|
||||
.It Fl \-library, l
|
||||
.It Fl f
|
||||
Create a filter tool project.
|
||||
.It Fl l
|
||||
Create a library project.
|
||||
.It Fl \-simple, s
|
||||
Create a simple project.
|
||||
.It Fl n
|
||||
Create a normal tool project.
|
||||
This is the default.
|
||||
.It Fl s
|
||||
Create a simple tool project.
|
||||
.El
|
||||
.Pp
|
||||
Without any
|
||||
@ -81,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
|
||||
@ -103,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
|
||||
@ -115,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
|
||||
@ -190,8 +203,9 @@ This is where the C++ standard is defined.
|
||||
Change if needed for your project.
|
||||
Note the
|
||||
.Dq +=
|
||||
operator here, so a possibly defined $CXXFLAGS environment
|
||||
variable will be honored.
|
||||
operator here, so a possibly defined
|
||||
.Ev CXXFLAGS
|
||||
environment variable will be honored.
|
||||
.It PRECOMPILE
|
||||
The project can generate and use a precompiled header.
|
||||
By default, the precomp.hpp file contains the C++ Standard Library headers, but
|
||||
@ -214,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.
|
||||
@ -231,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.
|
||||
@ -243,10 +258,12 @@ 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.
|
||||
When doing this with for the first time, or after doing a
|
||||
When doing this for the first time, or after doing a
|
||||
.Dq make dist-clean ,
|
||||
a
|
||||
.Dq build
|
||||
@ -291,10 +308,16 @@ that is generated using the various
|
||||
invocations.
|
||||
.It make uninstall
|
||||
Remove the files that are installed by the
|
||||
.Sq make install
|
||||
.Dq make install
|
||||
invocation.
|
||||
Please note that no dependency checks are done, so removal could break other
|
||||
tools or libraries that depend on the removed files.
|
||||
.Pp
|
||||
Also, if the install also created standard directories, like
|
||||
.Pa /usr/local/bin ,
|
||||
.Pa /usr/local/lib ,
|
||||
.Pa /usr/local/include ,
|
||||
etc., and they end up empty after the uninstall, they won't be removed.
|
||||
.El
|
||||
.Ss Tool Features, out of the box
|
||||
TODO describe main.cpp and version.cpp here.
|
||||
@ -305,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
|
||||
|
43
mkproj.sh
43
mkproj.sh
@ -2,15 +2,15 @@
|
||||
|
||||
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|-s] [[-d] -g <gitroot>|-G] [-t <tplroot>] PROJECTNAME" >&2
|
||||
echo "usage: $progname [-f|-l|-n|-s] [[-d] -g <gitroot>|-G] [-t <tplroot>] PROJECTNAME" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
@ -30,33 +30,38 @@ check_gitroot() {
|
||||
progname=${0##*/}
|
||||
|
||||
# option processing, using silent mode
|
||||
while getopts :dfGg:lst:v opt
|
||||
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=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
|
||||
;;
|
||||
\?)
|
||||
@ -78,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
|
||||
@ -89,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"
|
||||
@ -97,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
|
||||
|
@ -49,3 +49,5 @@ endif
|
||||
|
||||
uninstall:
|
||||
rm -f $(INSTALLDIR)/$(PLUGIN) $(addprefix $(INSTALLDIR)/, $(EXTRAFILES))
|
||||
|
||||
-include postmake.make
|
||||
|
@ -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}
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user