Updated otto.sh to be OS aware, also added more automation.

This commit is contained in:
Jake Goodwin 2026-07-20 19:36:52 -07:00
parent 8ef0f8307b
commit 07fb8b48da

View file

@ -12,8 +12,26 @@ TEMPLATE_FILES=".template_files"
MODULE_DIR="${TEMPLATE_FILES}/modules"
TEST_MODULE_DIR="${TEMPLATE_FILES}/test_module"
IS_FREEBSD=0
IS_LINUX=0
PROJECT_NAME="template"
check_os() {
if [[ "${OSTYPE}" == *"freebsd"* ]]; then
IS_FREEBSD=1
IS_LINUX=0
elif [[ "${OSTYPE}" == *"linux"* ]]; then
IS_FREEBSD=0
IS_LINUX=1
else
echo "Error, unknown OS type!"
IS_FREEBSD=0
IS_LINUX=0
fi
}
run_uc_tags() {
uctags --recurse=yes \
--languages=C,C++,Asm \
@ -115,19 +133,32 @@ add_module_to_cmakes () {
echo "add_subdirectory(${basename})" >> ./src/CMakeLists.txt
# Tests cmake file needs to be edited in place.
# sed -i'' "s/# TEST_DIRS.*$/# TEST_DIRS\r\nadd_subdirectory(${basename})/g" ./tests/CMakeLists.txt
# sed -i'' "s/# TEST_LINKS.*$/# TEST_LINKS\r\n\t${basename}/g" ./tests/CMakeLists.txt
if [ $IS_FREEBSD -eq 1 ]; then
sed -i '' -e "s|# TEST_DIRS.*$|# TEST_DIRS\nadd_subdirectory(${basename})|" ./tests/CMakeLists.txt
sed -i '' -e "s|# TEST_LINKS.*$|# TEST_LINKS\ntest_${basename}|" ./tests/CMakeLists.txt
sed -i '' -e "s|# TEST_LINKS.*$|# TEST_LINKS\n\ttest_${basename}|" ./tests/CMakeLists.txt
elif [ $IS_LINUX -eq 1 ]; then
sed -i -e "s|# TEST_DIRS.*$|# TEST_DIRS\nadd_subdirectory(${basename})|" ./tests/CMakeLists.txt
sed -i -e "s|# TEST_LINKS.*$|# TEST_LINKS\n\ttest_${basename}|" ./tests/CMakeLists.txt
fi
}
remove_module_from_cmakes () {
local basename="$1"
if [ $IS_FREEBSD -eq 1 ]; then
sed -i '' "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt
sed -i '' "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt
sed -i '' "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt
# sed -i'' "s/^.*test_${basename}.*$//g" ./tests/CMakeLists.txt
sed -i '' "s/^.*${basename}.*$//g" ./tests/AllTests.cpp
elif [ $IS_LINUX -eq 1 ]; then
sed -i "s/^.*add_subdirectory(${basename}).*$//g" ./src/CMakeLists.txt
sed -i "s/^.*add_subdirectory(${basename}).*$//g" ./tests/CMakeLists.txt
sed -i "s/^.*${basename}.*$//g" ./tests/CMakeLists.txt
sed -i "s/^.*${basename}.*$//g" ./tests/AllTests.cpp
fi
}
git_add_module () {
@ -190,7 +221,7 @@ add_new_module () {
exit
fi
modname_cap=$(echo $modname | sed 's/[a-z]/\U&/g')
modname_cap=$( printf '%s' "$modname" | tr '[:lower:]' '[:upper:]' )
modsrc_dir="./src/${modname}"
modtest_dir="./tests/${modname}"
@ -211,7 +242,7 @@ add_new_module () {
case $lanuage_selection in
1)
echo "You selected Option 1"
add_c_mdoule
add_c_module
;;
2)
echo "You selected Option 2"
@ -228,8 +259,9 @@ add_new_module () {
}
add_c_mdoule () {
add_c_module () {
if [ $IS_FREEBSD -eq 1 ]; then
sed -e "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
sed -i '' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
@ -241,6 +273,28 @@ add_c_mdoule () {
sed -e "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
sed -e "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
#Add module to Alltests.
sed -i '' -e "s/\/\/ImportTestGroups/\/\/ImportTestGroups\nIMPORT_TEST_GROUP(tg_${modname});/" ./tests/AllTests.cpp
elif [ $IS_LINUX -eq 1 ]; then
sed -e "s/module_name/${modname}/" $MODULE_DIR/module_name.c > $modsrc_dir/${modname}.c
sed -i '' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.c
sed -e "s/module_name/${modname_cap}/" $MODULE_DIR/module_name.h > $modsrc_dir/${modname}.h
sed -i '' -e "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.h
sed -e "s/module_name/${modname}/" $MODULE_DIR/CMakeLists.txt > $modsrc_dir/CMakeLists.txt
sed -e "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
sed -e "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
#Add module to Alltests.
sed -i '' -e "s/\/\/ImportTestGroups/\/\/ImportTestGroups\nIMPORT_TEST_GROUP(tg_${modname});/" ./tests/AllTests.cpp
else
printf "Error unknown OS!\r\n"
exit -1
fi
# Add the module to the cmake lists files.
add_module_to_cmakes "${modname}"
@ -252,6 +306,7 @@ add_c_mdoule () {
add_cpp_module () {
if [ $IS_FREEBSD -eq 1 ]; then
sed "s/module_name/${modname}/" $MODULE_DIR/module_name.cpp > $modsrc_dir/${modname}.cpp
sed -i'' "3s/todays_date/$(date +%Y)/" $modsrc_dir/${modname}.cpp
@ -263,6 +318,13 @@ add_cpp_module () {
sed "s/module_name/${modname}/" $MODULE_DIR/test_module_name.cpp > $modtest_dir/test_${modname}.cpp
sed "s/module_name/${modname}/" $MODULE_DIR/TestCMakeLists.txt > $modtest_dir/CMakeLists.txt
elif [ $IS_LINUX -eq 1 ]; then
echo "Not yet implimented"
else
printf "Error unknown OS!\r\n"
exit -1
fi
# Add the module to the cmake lists files.
add_module_to_cmakes "${modname}"
@ -342,6 +404,7 @@ print_menu () {
main() {
check_os
add_compile_commands
valid_choice=false