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 .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
@ -105,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
@ -127,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
@ -139,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
@ -239,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.
@ -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. 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.
@ -268,6 +258,8 @@ 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.
@ -336,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

View File

@ -2,12 +2,12 @@
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|-n|-s] [[-d] -g <gitroot>|-G] [-t <tplroot>] PROJECTNAME" >&2 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 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) n)
mainfile=main.cpp mainfile=main.cpp
library=0 library=false
simple=0 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
;; ;;
\?) \?)
@ -83,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
@ -94,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"
@ -102,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

View File

@ -49,3 +49,5 @@ endif
uninstall: uninstall:
rm -f $(INSTALLDIR)/$(PLUGIN) $(addprefix $(INSTALLDIR)/, $(EXTRAFILES)) 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 += -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}

View File

@ -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.