2024-01-26 19:30:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-01-19 00:37:36 +00:00
|
|
|
|
|
|
|
cd $(dirname "$(pwd)/$0")
|
|
|
|
REPOSITORY_FOLDER=$(pwd)
|
|
|
|
|
|
|
|
|
|
|
|
PROJECT_NAME="maintree"
|
2024-01-30 21:31:31 +00:00
|
|
|
DEBUG_CC_OPTIONS="-g3 -Wall -Wextra -Wpedantic"
|
2024-01-19 00:37:36 +00:00
|
|
|
RELEASE_CC_OPTIONS="-O3 -Wall"
|
|
|
|
|
2024-01-30 21:31:31 +00:00
|
|
|
MAIN_OBJECTS_FOLDER="$REPOSITORY_FOLDER/.build/objects"
|
2024-01-19 00:37:36 +00:00
|
|
|
CONFIG_FILE_INCLUDE_PATHS="build-config/include_paths.txt"
|
|
|
|
|
|
|
|
function clone_dependencies {
|
|
|
|
echo "================ Cloning Dependencies! ================"
|
|
|
|
mkdir -p .build/depends/libRR
|
|
|
|
cd .build/depends/libRR/
|
2024-01-26 19:30:06 +00:00
|
|
|
if [[ -d "Core" ]]
|
|
|
|
then
|
|
|
|
rm -rf Core
|
|
|
|
fi
|
2024-01-19 00:37:36 +00:00
|
|
|
git clone --depth=1 https://git.nerdcult.net/libRR/Core/
|
|
|
|
|
|
|
|
cd "$REPOSITORY_FOLDER"
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_dependencies {
|
|
|
|
echo "================ Building Dependencies! ================"
|
|
|
|
|
|
|
|
mkdir -p "$REPOSITORY_FOLDER/.build/output"
|
|
|
|
|
|
|
|
cd .build/depends/libRR/Core/
|
|
|
|
bash build.bash release
|
2024-01-28 16:13:00 +00:00
|
|
|
cp .build/librr-core.a "$REPOSITORY_FOLDER/.build/"
|
|
|
|
cp .build/librr-platform.a "$REPOSITORY_FOLDER/.build/"
|
2024-01-19 00:37:36 +00:00
|
|
|
|
|
|
|
cd "$REPOSITORY_FOLDER"
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_include_path_configuration {
|
|
|
|
MODULE_NAME=$1
|
|
|
|
|
|
|
|
INCLUDE_CONFIG_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/$CONFIG_FILE_INCLUDE_PATHS"
|
|
|
|
INCLUDE_STATEMENTS="-I $REPOSITORY_FOLDER/$MODULE_NAME/inc-c/"
|
|
|
|
if [[ ! -f $INCLUDE_CONFIG_PATH ]]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
for LINE in $(cat $INCLUDE_CONFIG_PATH)
|
|
|
|
do
|
2024-01-19 19:29:57 +00:00
|
|
|
INCLUDE_STATEMENTS="$INCLUDE_STATEMENTS -I $REPOSITORY_FOLDER/$LINE"
|
2024-01-19 00:37:36 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function compile_module_c_sources {
|
|
|
|
MODULE_NAME=$1
|
|
|
|
|
|
|
|
get_include_path_configuration $MODULE_NAME
|
|
|
|
|
|
|
|
MODULE_SOURCE_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/src-c/"
|
2024-01-28 13:19:49 +00:00
|
|
|
MODULE_OBJECTS_FOLDER="$MAIN_OBJECTS_FOLDER/$MODULE_NAME/"
|
2024-01-29 18:48:56 +00:00
|
|
|
rm -r $MODULE_OBJECTS_FOLDER
|
2024-01-19 00:37:36 +00:00
|
|
|
mkdir -p $MODULE_OBJECTS_FOLDER
|
|
|
|
|
|
|
|
# Loop through all files in the 'src-c'-folder and hand them over to GCC
|
|
|
|
|
|
|
|
cd $MODULE_SOURCE_PATH
|
|
|
|
MODULE_SOURCES=$(find . -mindepth 1)
|
|
|
|
for SOURCE_FOLDER_ITEM in $MODULE_SOURCES
|
|
|
|
do
|
|
|
|
# Cut away the dot-slash given by 'find' as abbrevation for the working directory
|
|
|
|
RELATIVE_SOURCE_PATH=$(echo $SOURCE_FOLDER_ITEM | cut -c "3-")
|
|
|
|
|
|
|
|
# If this folder item is a folder, it must be created as an
|
|
|
|
# output-folder for the object files to be placed in
|
|
|
|
|
|
|
|
if [[ -d $RELATIVE_SOURCE_PATH ]]
|
|
|
|
then
|
|
|
|
mkdir -p "$MODULE_OBJECTS_FOLDER/$RELATIVE_SOURCE_PATH/"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if this is a C source file by checking the last 2 characters (the ending),
|
|
|
|
# and if it isn't, continue with the next file.
|
|
|
|
|
|
|
|
LEN_SOURCE_FILE_NAME=${#RELATIVE_SOURCE_PATH}
|
|
|
|
let PENULTIMATE_OFFSET=$LEN_SOURCE_FILE_NAME-1
|
|
|
|
LAST_2_CHARACTERS=$(echo $RELATIVE_SOURCE_PATH | cut -c "$PENULTIMATE_OFFSET-")
|
|
|
|
if [[ $LAST_2_CHARACTERS != ".c" ]]; then continue; fi
|
|
|
|
|
|
|
|
# Status Message
|
|
|
|
echo "==> File: $RELATIVE_SOURCE_PATH"
|
|
|
|
|
|
|
|
# Finally, call GCC to compile the C-file and let it place the file in the
|
|
|
|
# objects folder or one of the possible subfolders which now could exist.
|
|
|
|
|
|
|
|
gcc -c $CC_OPTIONS -o \
|
|
|
|
"$MODULE_OBJECTS_FOLDER/$RELATIVE_SOURCE_PATH.o" \
|
|
|
|
"$MODULE_SOURCE_PATH/$RELATIVE_SOURCE_PATH" \
|
|
|
|
$INCLUDE_STATEMENTS
|
|
|
|
done
|
|
|
|
|
|
|
|
ar -rvs $REPOSITORY_FOLDER/.build/$PROJECT_NAME-$MODULE_NAME.a $MODULE_OBJECTS_FOLDER/*
|
|
|
|
cd $REPOSITORY_FOLDER
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_in_debug_profile {
|
|
|
|
echo "================ Building in Debug Profile! ================"
|
|
|
|
CC_OPTIONS=$DEBUG_CC_OPTIONS
|
|
|
|
compile_module_c_sources core
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_in_release_profile {
|
|
|
|
echo "================ Building in Release Profile! ================"
|
|
|
|
CC_OPTIONS=$RELEASE_CC_OPTIONS
|
|
|
|
compile_module_c_sources core
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
"d" | "dbg" | "debug")
|
|
|
|
build_in_debug_profile
|
|
|
|
;;
|
|
|
|
|
|
|
|
"r" | "release")
|
|
|
|
build_in_release_profile
|
|
|
|
;;
|
|
|
|
|
|
|
|
"c" | "clone-dependencies")
|
|
|
|
clone_dependencies
|
|
|
|
;;
|
|
|
|
|
|
|
|
"b" | "build-dependencies")
|
|
|
|
build_dependencies
|
|
|
|
;;
|
2024-01-19 19:29:57 +00:00
|
|
|
"h" | "help")
|
|
|
|
echo "Known Actions:"
|
|
|
|
echo "[ d | dbg | debug ]: Build in the debug profile; build with debug symbols."
|
|
|
|
echo "[ r | release ]: Build for a release, with speed optimizations."
|
|
|
|
echo "[ c | clone-dependencies]: Clone the dependencies using Git (network required)."
|
2024-01-26 19:30:06 +00:00
|
|
|
echo "[ b | build-dependencies]: Build the dependencies (which must have been cloned first!)."
|
2024-01-19 19:29:57 +00:00
|
|
|
echo "[ h | help ]: Display this message."
|
|
|
|
echo ""
|
|
|
|
echo "Note: Before being able to build (debug-profile / release-profile), cloning and building the dependencies is required!"
|
|
|
|
;;
|
2024-01-19 00:37:36 +00:00
|
|
|
*)
|
2024-01-19 19:29:57 +00:00
|
|
|
echo "Unknown action, try '$0 help' or '$0 h'."
|
2024-01-19 00:37:36 +00:00
|
|
|
;;
|
|
|
|
esac
|