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
|
.Dt mkproj 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
.Nm mkproj
|
.Nm mkproj
|
||||||
.Nd Create C++ project directory with predefined templates
|
.Nd Create C++ project directory with predefined templates
|
||||||
.\" .Sh LIBRARY
|
|
||||||
.\" For sections 2, 3, and 9 only.
|
|
||||||
.\" Not used in OpenBSD.
|
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Fl v
|
.Fl v
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl f | Fl l | Fl s
|
.Op Fl f | Fl l | Fl n | Fl s
|
||||||
.Oo
|
.Oo
|
||||||
.Op Fl d
|
.Op Fl d
|
||||||
.Fl g Ar gitroot
|
.Fl g Ar gitroot
|
||||||
@ -24,6 +21,13 @@ The
|
|||||||
script creates a C++ project directory structure with some predefined
|
script creates a C++ project directory structure with some predefined
|
||||||
boilerplate files, ready to be built using
|
boilerplate files, ready to be built using
|
||||||
.Xr make 1 .
|
.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
|
.Nm
|
||||||
can create a directory for a simple project using a single source file; a
|
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
|
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
|
.Xr git 1
|
||||||
commit hash, after you have built the tool at least once.
|
commit hash, after you have built the tool at least once.
|
||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options for
|
||||||
|
.Nm
|
||||||
|
are as follows:
|
||||||
.Ss General Options
|
.Ss General Options
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl \-version, v
|
.It Fl d
|
||||||
Print version info and exit.
|
Save default Git URL to clone from.
|
||||||
.It Fl \-gitroot Ar gitroot , Fl g Ar gitroot
|
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
|
Clone a
|
||||||
.Xr git 1
|
.Xr git 1
|
||||||
repo from the supplied git URL.
|
repo from the supplied git URL.
|
||||||
When combined with the
|
When combined with the
|
||||||
.Fl \-default
|
|
||||||
or
|
|
||||||
.Fl d
|
.Fl d
|
||||||
option, the supplied git URL will be saved into the
|
option, the supplied git URL will be saved into the
|
||||||
.Nm
|
.Nm
|
||||||
configuration file.
|
configuration file.
|
||||||
.It Fl \-gitfav , Fl G
|
.It Fl G
|
||||||
Use the git URL saved earlier to clone a repo from.
|
Use the Git URL saved earlier to clone a repo from.
|
||||||
.It Fl \-tplroot Ar tplroot , Fl t Ar tplroot
|
.It Fl t Ar tplroot
|
||||||
Specify the root directory where the project templates can be found.
|
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
|
This option is useful when you want to use a modified set of files to base your
|
||||||
projects on.
|
projects on.
|
||||||
|
.It Fl v
|
||||||
|
Print version info and exit.
|
||||||
.El
|
.El
|
||||||
.Ss Project Type Options
|
.Ss Project Type Options
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl \-filter, f
|
.It Fl f
|
||||||
Create a filter project.
|
Create a filter tool project.
|
||||||
.It Fl \-library, l
|
.It Fl l
|
||||||
Create a library project.
|
Create a library project.
|
||||||
.It Fl \-simple, s
|
.It Fl n
|
||||||
Create a simple project.
|
Create a normal tool project.
|
||||||
|
This is the default.
|
||||||
|
.It Fl s
|
||||||
|
Create a simple tool project.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Without any
|
Without any
|
||||||
@ -81,12 +102,6 @@ created.
|
|||||||
The
|
The
|
||||||
.Sx Project Type Options
|
.Sx Project Type Options
|
||||||
are mutually exclusive.
|
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
|
.\" .Sh ENVIRONMENT
|
||||||
.\" For sections 1, 6, 7, and 8 only.
|
.\" For sections 1, 6, 7, and 8 only.
|
||||||
.Sh FILES
|
.Sh FILES
|
||||||
@ -103,7 +118,6 @@ Since it is shell syntax, paths should be properly quoted, and comments are
|
|||||||
allowed.
|
allowed.
|
||||||
.El
|
.El
|
||||||
.Sh EXIT STATUS
|
.Sh EXIT STATUS
|
||||||
.\" For sections 1, 6, and 8 only.
|
|
||||||
.Nm
|
.Nm
|
||||||
exits 0 on success, and 1 if an error occurs.
|
exits 0 on success, and 1 if an error occurs.
|
||||||
.\" .Sh EXAMPLES
|
.\" .Sh EXAMPLES
|
||||||
@ -115,9 +129,8 @@ exits 0 on success, and 1 if an error occurs.
|
|||||||
The project created by
|
The project created by
|
||||||
.Nm
|
.Nm
|
||||||
has the following features.
|
has the following features.
|
||||||
.Ss Without Project Type Options
|
.Ss Normal Tool Project
|
||||||
Without any options, a full-featured project for a tool will be created, with
|
This creates a full-featured project for a tool, with the following layout:
|
||||||
the following layout:
|
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
mytool
|
mytool
|
||||||
|-- Makefile
|
|-- Makefile
|
||||||
@ -190,8 +203,9 @@ This is where the C++ standard is defined.
|
|||||||
Change if needed for your project.
|
Change if needed for your project.
|
||||||
Note the
|
Note the
|
||||||
.Dq +=
|
.Dq +=
|
||||||
operator here, so a possibly defined $CXXFLAGS environment
|
operator here, so a possibly defined
|
||||||
variable will be honored.
|
.Ev CXXFLAGS
|
||||||
|
environment variable will be honored.
|
||||||
.It PRECOMPILE
|
.It PRECOMPILE
|
||||||
The project can generate and use a precompiled header.
|
The project can generate and use a precompiled header.
|
||||||
By default, the precomp.hpp file contains the C++ Standard Library headers, but
|
By default, the precomp.hpp file contains the C++ Standard Library headers, but
|
||||||
@ -214,13 +228,13 @@ below for more information.
|
|||||||
.It tests directory
|
.It tests directory
|
||||||
Subdirectory for unit tests, using the Boost Unit Test Framework.
|
Subdirectory for unit tests, using the Boost Unit Test Framework.
|
||||||
.El
|
.El
|
||||||
.Ss Filter Project Type
|
.Ss Filter Tool Project
|
||||||
The filter project has an identical structure as the normal type, but adds some
|
The filter tool project has an identical structure as the normal type, but adds
|
||||||
functionality to make the tool behave as a real UNIX filter.
|
some functionality to make the tool behave as a real UNIX filter.
|
||||||
See
|
See
|
||||||
.Sx Tool Features
|
.Sx Tool Features
|
||||||
below for more information.
|
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
|
The library project has been set up to produce a static and dynamic library from
|
||||||
your sources.
|
your sources.
|
||||||
Its directory structure is almost identical to that of a tool.
|
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.
|
by default a single function which can return a version string.
|
||||||
.Pp
|
.Pp
|
||||||
TODO describe lib header generation, honoring @exclude
|
TODO describe lib header generation, honoring @exclude
|
||||||
.Ss Simple Project Type
|
.Ss Simple Tool Project
|
||||||
The simple project is just a directory with a single source file and a Makefile.
|
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.
|
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
|
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.
|
nothing is in the way to make it do what you want.
|
||||||
@ -243,10 +258,12 @@ as well as a
|
|||||||
but no more.
|
but no more.
|
||||||
Possible library dependencies should be added to the Makefile.
|
Possible library dependencies should be added to the Makefile.
|
||||||
.Ss Makefile targets
|
.Ss Makefile targets
|
||||||
|
The description below is valid for all project types, except the simple tool
|
||||||
|
project.
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It make
|
.It make
|
||||||
Use this to compile and link your tool.
|
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 ,
|
.Dq make dist-clean ,
|
||||||
a
|
a
|
||||||
.Dq build
|
.Dq build
|
||||||
@ -291,10 +308,16 @@ that is generated using the various
|
|||||||
invocations.
|
invocations.
|
||||||
.It make uninstall
|
.It make uninstall
|
||||||
Remove the files that are installed by the
|
Remove the files that are installed by the
|
||||||
.Sq make install
|
.Dq make install
|
||||||
invocation.
|
invocation.
|
||||||
Please note that no dependency checks are done, so removal could break other
|
Please note that no dependency checks are done, so removal could break other
|
||||||
tools or libraries that depend on the removed files.
|
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
|
.El
|
||||||
.Ss Tool Features, out of the box
|
.Ss Tool Features, out of the box
|
||||||
TODO describe main.cpp and version.cpp here.
|
TODO describe main.cpp and version.cpp here.
|
||||||
@ -305,7 +328,7 @@ TODO describe main.cpp and version.cpp here.
|
|||||||
.\" .Sh STANDARDS
|
.\" .Sh STANDARDS
|
||||||
.\" .Sh HISTORY
|
.\" .Sh HISTORY
|
||||||
.Sh AUTHORS
|
.Sh AUTHORS
|
||||||
Bob Polis
|
.An Bob Polis
|
||||||
.\" .Sh CAVEATS
|
.\" .Sh CAVEATS
|
||||||
.Sh BUGS
|
.Sh BUGS
|
||||||
.Nm
|
.Nm
|
||||||
|
43
mkproj.sh
43
mkproj.sh
@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
config=$HOME/.config/mkprojrc
|
config=$HOME/.config/mkprojrc
|
||||||
source $config
|
source $config
|
||||||
default=0
|
default=false
|
||||||
mainfile=main.cpp
|
mainfile=main.cpp
|
||||||
gitfav=0
|
gitfav=false
|
||||||
library=0
|
library=false
|
||||||
simple=0
|
simple=false
|
||||||
usegitroot=0
|
usegitroot=false
|
||||||
|
|
||||||
usage() {
|
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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,33 +30,38 @@ check_gitroot() {
|
|||||||
progname=${0##*/}
|
progname=${0##*/}
|
||||||
|
|
||||||
# option processing, using silent mode
|
# option processing, using silent mode
|
||||||
while getopts :dfGg:lst:v opt
|
while getopts :dfGg:lnst:v opt
|
||||||
do
|
do
|
||||||
case $opt in
|
case $opt in
|
||||||
d)
|
d)
|
||||||
default=1
|
default=true
|
||||||
;;
|
;;
|
||||||
f)
|
f)
|
||||||
mainfile=filter.cpp
|
mainfile=filter.cpp
|
||||||
;;
|
;;
|
||||||
G)
|
G)
|
||||||
gitfav=1
|
gitfav=true
|
||||||
;;
|
;;
|
||||||
g)
|
g)
|
||||||
gitroot=$OPTARG
|
gitroot=$OPTARG
|
||||||
usegitroot=1
|
usegitroot=true
|
||||||
;;
|
;;
|
||||||
l)
|
l)
|
||||||
library=1
|
library=true
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
mainfile=main.cpp
|
||||||
|
library=false
|
||||||
|
simple=false
|
||||||
;;
|
;;
|
||||||
s)
|
s)
|
||||||
simple=1
|
simple=true
|
||||||
;;
|
;;
|
||||||
t)
|
t)
|
||||||
tplroot=$OPTARG
|
tplroot=$OPTARG
|
||||||
;;
|
;;
|
||||||
v)
|
v)
|
||||||
echo "$progname version 2.0.0"
|
echo "$progname version 2.0.1"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
\?)
|
\?)
|
||||||
@ -78,7 +83,7 @@ shift $(( OPTIND - 1 ))
|
|||||||
|
|
||||||
proj=${1//[- ]/_} # replace all spaces and dashes with underscores
|
proj=${1//[- ]/_} # replace all spaces and dashes with underscores
|
||||||
|
|
||||||
if [ $default = 1 ]
|
if $default
|
||||||
then
|
then
|
||||||
check_gitroot
|
check_gitroot
|
||||||
if grep -q gitroot $config
|
if grep -q gitroot $config
|
||||||
@ -89,7 +94,7 @@ then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $gitfav = 1 ] || [ $usegitroot = 1 ]
|
if $gitfav || $usegitroot
|
||||||
then
|
then
|
||||||
check_gitroot
|
check_gitroot
|
||||||
git clone "$gitroot/$proj.git" || die "not an existing repo: $proj"
|
git clone "$gitroot/$proj.git" || die "not an existing repo: $proj"
|
||||||
@ -97,20 +102,20 @@ else
|
|||||||
mkdir -p "$proj"
|
mkdir -p "$proj"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $simple = 1 ]
|
if $simple
|
||||||
then
|
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
|
cp $tplroot/main.simple.cpp $proj/$proj.cpp
|
||||||
else
|
else
|
||||||
mkdir -p $proj/src
|
mkdir -p $proj/src
|
||||||
cp $tplroot/Makefile.unified $proj/Makefile
|
cp $tplroot/Makefile.unified $proj/Makefile
|
||||||
cp $tplroot/precomp.hpp $proj/src
|
cp $tplroot/precomp.hpp $proj/src
|
||||||
cp -r $tplroot/tests $proj/
|
cp -a $tplroot/tests $proj/
|
||||||
uproj=$(echo $proj | tr '[:lower:]' '[:upper:]')
|
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/" -e "s/{PROJ}/$uproj/" $tplroot/version.hpp > $proj/src/version.hpp
|
||||||
sed -e "s/{PROJECT}/$proj/" $tplroot/version.cpp > $proj/src/version.cpp
|
sed -e "s/{PROJECT}/$proj/" $tplroot/version.cpp > $proj/src/version.cpp
|
||||||
|
|
||||||
if [ $library = 1 ]
|
if $library
|
||||||
then
|
then
|
||||||
mkdir -p $proj/man/man3
|
mkdir -p $proj/man/man3
|
||||||
sed -e "s/{PROJECT}/$proj/" $tplroot/lib.3 > $proj/man/man3/$proj.3
|
sed -e "s/{PROJECT}/$proj/" $tplroot/lib.3 > $proj/man/man3/$proj.3
|
||||||
|
@ -49,3 +49,5 @@ endif
|
|||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(INSTALLDIR)/$(PLUGIN) $(addprefix $(INSTALLDIR)/, $(EXTRAFILES))
|
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 += -Wshadow -Wall -Wpedantic -Wextra -Wno-unused-parameter
|
||||||
CXXFLAGS += -g3 -std=c++20
|
CXXFLAGS += -g3 -std=c++20
|
||||||
ifeq ($(DEBUG),1)
|
ifeq ($(DEBUG), 1)
|
||||||
CXXFLAGS += -DDEBUG -O0
|
CXXFLAGS += -DDEBUG -O0
|
||||||
else
|
else
|
||||||
CXXFLAGS += -DNDEBUG -O3
|
CXXFLAGS += -DNDEBUG -O3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
%.o: %.cpp
|
|
||||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.dep -c $<
|
|
||||||
|
|
||||||
%.dep: ;
|
|
||||||
|
|
||||||
$(PROJ): $(OBJS)
|
|
||||||
$(CXX) $(LDFLAGS) -o $(PROJ) $(OBJS) $(LDLIBS)
|
|
||||||
|
|
||||||
-include $(DEPS)
|
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
|
%.o: %.cpp
|
||||||
|
c++ $(CXXFLAGS) -c $<
|
||||||
|
|
||||||
|
{PROJECT}: {PROJECT}.o
|
||||||
|
c++ -o {PROJECT} {PROJECT}.o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(OBJS) $(DEPS) $(PROJ)
|
rm -f {PROJECT}.o {PROJECT}
|
||||||
|
@ -16,7 +16,8 @@ MINOR := 0
|
|||||||
PATCH := 0
|
PATCH := 0
|
||||||
|
|
||||||
# Specify desired C++ standard for this project.
|
# 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 'app' to product name for which this is a plugin.
|
||||||
# Change 'plugins' to the desired directory name for installed plugins.
|
# Change 'plugins' to the desired directory name for installed plugins.
|
||||||
|
Reference in New Issue
Block a user