Convenience script to create a NetBeans C/C++ project

This commit is contained in:
benn 2025-05-26 19:57:26 +02:00
parent 641453de42
commit 6fc7b48393
2 changed files with 175 additions and 1 deletions

View file

@ -1,3 +1,25 @@
# nb_create
Convenience script to create a C/C++ NetBeans project
Convenience script to create a C/C++ NetBeans project
Usage: nb_create.sh [OPTIONS] params
Convenience script to create C/C++ NetBeans projects.
Create a generic NetBeans project from a Git repo
Project name, file containing main and a Git repo
can be specified using command line options, or
defaults can be used.
Options:
-h [--help]
print this help
-m [--main] <name_of_file_containing_main>
The name of the file that contains the main function
default: name of the project
-p [--project] <propject_name>
Provide a name of the project instead oof the default
default: name of the current directory
-r [--repo] <git_repo>
The Git repo containing the NetBeans generic C/C++ project
Default: /home/benn/share/home/repo/netbeans_proj/netbeans_generic.git

152
nb_create.sh Executable file
View file

@ -0,0 +1,152 @@
#!/usr/bin/env bash
# Convenience script to create a C/C++ NeteBeans project.
# Copyright (C) 26.5.2025 Benny Lyons benny.lyons@gmx.net
#
# nb_create.sh is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <https://www.gnu.org/licenses/>.
#
# Default settings
#
# Default Git repository containing Makefile, NetBeans project file, ...
# Override this using -r my_repo.git; or reset this
DEFAULT_REPO="/home/benn/share/home/repo/netbeans_proj/netbeans_generic.git"
this_script=$(basename -- $0)
USE_PROGRAMME=git
help() {
cat <<EOF
Usage: $this_script [OPTIONS] params
Convenience script to create C/C++ NetBeans projects.
Create a generic NetBeans project from a Git repo.
Project name, file containing main and a Git repo
can be specified using command line options, or
defaults can be used.
Options:
-h [--help]
print this help
-m [--main] <name_of_file_containing_main>
The name of the file that contains the main function
default: name of the project
-p [--project] <propject_name>
Provide a name of the project instead of the default
default: name of the current directory
-r [--repo] <git_repo>
The Git repo containing the NetBeans generic C/C++ project
Default: /home/benn/share/home/repo/netbeans_proj/netbeans_generic.git
Licence:
$this_script Copyright (C) 2025 Benny Lyons.
GNU GPL2 or later; see LICENCE distributed with this file for more details.
EOF
}
main()
{
OPT_ALL="$(getopt -o hm:p:r: -l help,main:,project:,repo: --name "$0" -- "$@")"
eval set -- "$OPT_ALL"
while true ; do
case $1 in
-h | --help) # Call help
help
exit 0
;;
-m | --main)
OPT_MAIN=$2
shift 2
;;
-p | --project)
OPT_PROJECT=$2
shift 2
;;
-r | --repo )
OPT_REPO=$2
shift 2
;;
--)
shift
break
;;
*)
echo "Invalid argument" >&2
exit 1
;;
esac
done
if ! command -v "${USE_PROGRAMME}" > /dev/null; then
echo "ERROR: cannot find " $USE_PROGRAMME
echo " You must install "$USE_PROGRAMME
exit 1
fi
pwd="$PWD"
#
# Set defaults
#
if [ -z $OPT_PROJECT ]; then
PROJECT=$(basename $pwd)
else
PROJECT="$OPT_PROJECT"
fi
if [ -z $OPT_MAIN ]; then
MAIN="$PROJECT"
else
MAIN="$OPT_MAIN"
fi
if [ -z $OPT_REPO ]; then
REPO=$DEFAULT_REPO
else
REPO="$OPT_REPO"
fi
if [ ! -d "$REPO" ]; then
echo "ERROR: can't find: "$REPO
echo "Require a valid Git repository with a NetBeans project"
echo "Use -r <path/to/valid/NB/git/repo to speicify one"
exit 1
fi
#
# Do
#
echo "Checking out repo..."
cd $pwd
$(git clone $REPO .)
cd $pwd/nbproject
sed -i -e "s/\(<name>\).*\(<\/name>\)/<name>$PROJECT<\/name>/g" project.xml
cd "$pwd"/src
if [ -f ./myapp.cpp ]; then
mv myapp.cpp "$MAIN".cpp
fi
}
main $@