Skip to content

Commit

Permalink
Project wizard with more defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
joergboe committed Dec 13, 2024
1 parent 3e0d6fd commit c4fcc21
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 46 deletions.
2 changes: 1 addition & 1 deletion OneToOne/project_wizard.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

../bin/mktsimple --project-dir . --type otocpp --kate-project --overwrite --no-prompt
../bin/mktsimple --type otocpp --overwrite --no-prompt
2 changes: 1 addition & 1 deletion ProjectInPlaceBuild/project_wizard.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

../bin/mktsimple --project-dir . --type ipbcpp --kate-project --overwrite --no-prompt
../bin/mktsimple --type ipbcpp --overwrite --no-prompt
2 changes: 1 addition & 1 deletion ProjectOutPlaceBuild/project_wizard.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

../bin/mktsimple --project-dir . --type opb --kate-project --overwrite --no-prompt
../bin/mktsimple --type opb --overwrite --no-prompt
2 changes: 1 addition & 1 deletion ProjectOutPlaceBuildC/project_wizard.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

../bin/mktsimple --project-dir . --type opbc --kate-project --overwrite --no-prompt
../bin/mktsimple --type opbc --overwrite --no-prompt
2 changes: 1 addition & 1 deletion ProjectOutPlaceBuildCpp/project_wizard.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

../bin/mktsimple --project-dir . --type opbcpp --kate-project --overwrite --no-prompt
../bin/mktsimple --type opbcpp --overwrite --no-prompt
98 changes: 57 additions & 41 deletions bin/mktsimple
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Usage: ${my_command} [option..]
OPTIONS:
-h|--help : Display this help.
--help=type : Print project type information.
-p|--project-dir VALUE : The base directory of the C/C++ project.
-p|--project-dir VALUE : The base directory of the C/C++ project. Default: current directory.
-y|--type|--project-type VALUE : The type of the project. Valid types are: otocpp, ipbcpp, opbcpp, opbc, opb.
To find out more about the types use option --help=type
-c|--copy-warn : Make a local copy of the warning.mk files in the project directory.
Expand All @@ -35,7 +35,7 @@ OPTIONS:
If header and source files are placed in the source directories, enter an empty string or a single space.
This option may be repeated. The default value is 'include'
--hello-world : Create a hello world project.
-k|--kate-project : Create a kate project.
--no-kate-project : Do not create a kate project.
-o|--overwrite : Overwrite (and backup) existing files in project destination.
-n|--no-prompt|--noprompt : Do not enter the interactive mode and use the command line options only.
--mkts-install-dir VALUE : The base directory of the mktsimple installation. The default
Expand All @@ -50,11 +50,11 @@ EOF
}

readonly mkts='mktsimple'
readonly valid_types='otocpp ipbcpp opbc opbcpp opb'
readonly valid_types='opbcpp opbc opb ipbcpp otocpp'
readonly all_install_files='in_place_cpp.mk in_place_cpp.mk out_place_c.mk out_place_cpp.mk out_place_cpp.mk'
readonly -a pr3=(
'opbc -- C project Out Place Build'$'\n'' Build one executable from all %.c source files in all project source directories.'$'\n'
'opbcpp -- C++ project Out Place Build'$'\n'' Build one executable from all %.cpp and %.cc source files in all project source directories.'$'\n'
'opbc -- C project Out Place Build'$'\n'' Build one executable from all %.c source files in all project source directories.'$'\n'
'opb -- C/C++ project Out Place Build'$'\n'' Build one executable from all C++, C and assembler source files in all project source directories.'$'\n'
'ipbcpp -- C++ project In Place Build'$'\n'' Build one executable from all %.cpp and %.cc source files in the project directory.'$'\n'
'otocpp -- C++ project One To One'$'\n'' Build executable targets from each %.cpp and %.cc source file in the project directory.'$'\n'
Expand Down Expand Up @@ -134,13 +134,18 @@ abort_func() {
# read yes/no form stdin
# $1 - Prompt
# $2 - name of in/output
# $3 - default value
# start over when the referenced value is not empty
read_yes_no() {
local temp
declare -ln ref=$2
while [[ -z ${ref} ]]; do
read -r -p "$1 (^D to exit) [y/n] " || exit 3
temp="${REPLY,,}"
read -r -p "$1 (Enter yes/no or ^D to exit) [$3] " || exit 3
if [[ -z "${REPLY}" ]]; then
temp="$3"
else
temp="${REPLY,,}"
fi
if [[ (${temp} == 'yes') || (${temp} == 'y') ]]; then
ref='true'
break
Expand Down Expand Up @@ -220,7 +225,7 @@ target_name=
src_dirs=
inc_dirs=
hello_world=
kateproject=
no_kateproject=
copy_warn=
overwrite=

Expand Down Expand Up @@ -298,8 +303,8 @@ while [[ $# -gt 0 ]]; do
fi;;
'--hello-world')
hello_world='true';;
'-k'|'--kate-project')
kateproject='true';;
'--no-kate-project')
no_kateproject='true';;
'-o'|'--overwrite')
overwrite='true';;
'-n'|'--no-prompt'|'--noprompt')
Expand Down Expand Up @@ -332,7 +337,9 @@ remove_trailing_slash 'mkts_install_dir'

# request and validate project directory
if [[ -z ${no_prompt} ]]; then
read_value "Enter the project directory" 'project_dir' 'project1' 'check_project_dir'
read_value "Enter the project directory" 'project_dir' '.' 'check_project_dir'
else
[[ -z "${project_dir}" ]] && project_dir='.'
fi
! check_project_dir "${project_dir}" >&2 && exit 2

Expand Down Expand Up @@ -442,17 +449,23 @@ fi

# request copy warnings local option
if [[ -z "${no_prompt}" && -z "${copy_warn}" ]]; then
read_yes_no "Make a local copy of the warning files in the project directory?" 'copy_warn'
read_yes_no "Make a local copy of the warning files in the project directory?" 'copy_warn' 'no'
fi

# request hello world
if [[ -z "${no_prompt}" && -z "${hello_world}" ]]; then
read_yes_no "Create a hello world project?" 'hello_world'
read_yes_no "Create a hello world project?" 'hello_world' 'no'
fi

# request kateproject
if [[ -z "${no_prompt}" && -z "${kateproject}" ]]; then
read_yes_no "Create a Kate project file?" 'kateproject'
if [[ -z "${no_prompt}" && -z "${no_kateproject}" ]]; then
kateproject=
read_yes_no "Create a Kate project file?" 'kateproject' 'yes'
if [[ -z ${kateproject} ]]; then
no_kateproject='true'
else
no_kateproject=
fi
fi

# check src dir and project type
Expand Down Expand Up @@ -528,11 +541,16 @@ overwrite_necessary=
[[ -n "${project_mk_required}" && -a "${project_mk_name}" ]] && overwrite_project_mk='true'
[[ -n "${hello_world}" && -a "${module_name}" ]] && overwrite_module='true'
[[ -n "${copy_warn}" && -d "${warndir_name}" ]] && overwrite_warn_dir='true'
[[ -n "${kateproject}" && -a "${kateproject_name}" ]] && overwrite_kateproject='true'
[[ -z "${no_kateproject}" && -a "${kateproject_name}" ]] && overwrite_kateproject='true'
[[ -n ${overwrite_makefile} || -n ${overwrite_project_mk} || -n ${overwrite_module} || -n ${overwrite_warn_dir} || -n ${overwrite_kateproject} ]] && overwrite_necessary='true'
if [[ -z "${no_prompt}" ]]; then
if [[ -n ${overwrite_necessary} ]]; then
read_yes_no "Some files already exists. Overwite?" 'overwrite'
if [[ -n ${overwrite_necessary} ]]; then
[[ -n "${overwrite_makefile}" ]] && echo "Request backup makefile ${makefile_name} !"
[[ -n "${overwrite_project_mk}" ]] && echo "Request backup project file ${project_mk_name} !"
[[ -n "${overwrite_module}" ]] && echo "Request backup modul ${module_name} !"
[[ -n "${overwrite_warn_dir}" ]] && echo "Request overwrite warnings in dir ${warndir_name} !"
[[ -n "${overwrite_kateproject}" ]] && echo "Request backup kate project file ${kateproject_name} !"
if [[ -z "${no_prompt}" ]]; then
read_yes_no "Some files already exists. Overwite?" 'overwrite' 'no'
fi
fi
if [[ -z ${overwrite} && -n ${overwrite_necessary} ]]; then
Expand Down Expand Up @@ -572,20 +590,14 @@ if [[ -n ${out_place_project_type} ]]; then
fi
[[ -n "${hello_world}" ]] && echo "Create hello world program module ${module_name}"
[[ -n "${copy_warn}" ]] && echo "Copy warnings into project directory."
[[ -n "${kateproject}" ]] && echo "Create a Kate project file ${kateproject_name}"
[[ -z "${no_kateproject}" ]] && echo "Create a Kate project file ${kateproject_name}"
temp='no'
[[ -n ${overwrite} ]] && temp='yes'
echo "Overwrite and backup existing files: $temp"

[[ -n "${overwrite_makefile}" ]] && echo "Backup makefile ${makefile_name} !"
[[ -n "${overwrite_project_mk}" ]] && echo "Backup project file ${project_mk_name} !"
[[ -n "${overwrite_module}" ]] && echo "Backup modul ${module_name} !"
[[ -n "${overwrite_warn_dir}" ]] && echo "Overwrite warnings in dir ${warndir_name} !"
[[ -n "${overwrite_kateproject}" ]] && echo "Overwrite kate project file ${kateproject_name} !"
echo '**********************************************************************************'
execute_all=
if [[ -z "${no_prompt}" ]]; then
read_yes_no 'Proceed?' 'execute_all'
read_yes_no 'Proceed?' 'execute_all' 'no'
else
execute_all='true'
fi
Expand Down Expand Up @@ -658,7 +670,7 @@ if [[ -n ${execute_all} ]]; then
fi

# kateproject
if [[ -n "${kateproject}" ]]; then
if [[ -z "${no_kateproject}" ]]; then
invocation_opt=
if [[ "${mkts_install_dir}" != '/usr/local' && -z "${copy_warn}" ]]; then
invocation_opt="-I ${mkts_install_dir}/include "
Expand Down Expand Up @@ -696,23 +708,27 @@ if [[ -n ${execute_all} ]]; then
"install": "make install",
"targets": [
{
"name": "Build debug config",
"build_cmd": "make ${invocation_opt}-j ${number_cores} --output-sync=target all"${run_cmd_deb}
"name": "Serial build, debug config",
"build_cmd": "make ${invocation_opt}all"${run_cmd_deb}
},
{
"name": "Clean debug config",
"name": "Build, debug config",
"build_cmd": "make ${invocation_opt}--jobs=${number_cores} --output-sync=target --keep-going all"${run_cmd_deb}
},
{
"name": "Cleanup, debug config",
"build_cmd": "make ${invocation_opt}clean"
},
{
"name": "Clean Build debug config",
"build_cmd": "make ${invocation_opt}clean; make ${invocation_opt}-j ${number_cores} --output-sync=target all"${run_cmd_deb}
"name": "Clean build, debug config",
"build_cmd": "make ${invocation_opt}clean; make ${invocation_opt}--jobs=${number_cores} --output-sync=target --keep-going all"${run_cmd_deb}
},
{
"name": "Build run config",
"build_cmd": "make ${invocation_opt}clean; make ${invocation_opt}BUILD_MODE=run -j ${number_cores} --output-sync=target all"${run_cmd_run}
"name": "Build, run config",
"build_cmd": "make ${invocation_opt}clean; make ${invocation_opt}BUILD_MODE=run --jobs=${number_cores} --output-sync=target --keep-going all"${run_cmd_run}
},
{
"name": "Clean run config",
"name": "Cleanup, run config",
"build_cmd": "make ${invocation_opt}BUILD_MODE=run clean"
},
{
Expand All @@ -724,20 +740,20 @@ if [[ -n ${execute_all} ]]; then
"build_cmd": "make ${invocation_opt}dec_warn_level"
},
{
"name": "Purge",
"build_cmd": "make ${invocation_opt}purge"
},
{
"name": "Project Info debug config",
"name": "Project info, debug config",
"build_cmd": "make ${invocation_opt}show"
},
{
"name": "Project Info run config",
"name": "Project info, run config",
"build_cmd": "make ${invocation_opt}BUILD_MODE=run show"
},
{
"name": "Help",
"build_cmd": "make ${invocation_opt}help"
},
{
"name": "Purge",
"build_cmd": "make ${invocation_opt}purge"
}
]
}
Expand Down

0 comments on commit c4fcc21

Please sign in to comment.