Made the build script more advanced and configurable

This commit is contained in:
Eric-Paul Ickhorn 2024-01-19 21:28:46 +01:00
parent eab3989878
commit dcbd9555d5
Signed by: epickh
GPG Key ID: F5EBBE013924D95F
3 changed files with 68 additions and 25 deletions

2
build-config/modules.txt Normal file
View File

@ -0,0 +1,2 @@
core
platform

View File

@ -1,34 +1,71 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Get the absolute repository root path and go there
cd $(dirname "$(pwd)/$0")
REPOSITORY_FOLDER=$(pwd)
# Configuration Values start here
PROJECT_NAME="librr" PROJECT_NAME="librr"
PROJECT_ROOT=`pwd`
GCC_ARGUMENTS="-std=c11 -Wall" GCC_ARGUMENTS="-std=c11 -Wall"
MODULES=( MAIN_OBJECTS_FOLDER="$REPOSITORY_FOLDER/.build/objects"
"core"
"platform" # End of configuration values
)
# Constants not meant for configuration
CONFIG_FILE_INCLUDE_PATHS="build-config/include_paths.txt"
MODULE_LIST_PATH="build-config/modules.txt"
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/ -I $REPOSITORY_FOLDER/$MODULE_NAME/exports/"
if [[ ! -f $INCLUDE_CONFIG_PATH ]]
then
return
fi
for LINE in $(cat $INCLUDE_CONFIG_PATH)
do
INCLUDE_STATEMENTS="$INCLUDE_STATEMENTS -I $REPOSITORY_FOLDER/$LINE"
done
}
# Arguments: # Arguments:
# 1) Path to the module # 1) Module name / folder name in project root (May not include slashes)
# 2) Include Statements function compile_single_module() {
function compile_folder() { MODULE_NAME=$1
OBJECTS_FOLDER="$PROJECT_ROOT/.build/objects/$1" ENTRY_WORKING_DIR=$(pwd)
mkdir -p $OBJECTS_FOLDER printf "\n\n\n"
cd $PROJECT_ROOT/$1 echo "|================> Module Separator <================|"
echo "> Name: $MODULE_NAME "
echo "> Path: $REPOSITORY_FOLDER/$MODULE_NAME"
echo " "
get_include_path_configuration $MODULE_NAME
MODULE_OBJECTS_FOLDER="$MAIN_OBJECTS_FOLDER/$MODULE_NAME"
mkdir -p $MODULE_OBJECTS_FOLDER
cd $REPOSITORY_FOLDER/$1
cd src-c/ cd src-c/
for SOURCE_FILE in $(find .) for SOURCE_FILE in $(find . -mindepth 1)
do do
# Create every folder except of the source root folder (src-c/). # Create all subfolders of this module's source folder
if [[ $SOURCE_FILE != "." ]] then
if [[ -d $SOURCE_FILE ]] then if [[ -d $SOURCE_FILE ]] then
mkdir $SOURCE_FILE mkdir -p $MODULE_OBJECTS_FOLDER/$SOURCE_FILE
continue continue
fi fi
fi
# If this is not a regular file, quietly ignore it.
if [[ ! -f $SOURCE_FILE ]] then if [[ ! -f $SOURCE_FILE ]] then
continue continue
fi fi
@ -36,17 +73,20 @@ function compile_folder() {
# Cut out the ./ at the front of the path # Cut out the ./ at the front of the path
SOURCE_FILE=$(echo $SOURCE_FILE | cut -c 3-) SOURCE_FILE=$(echo $SOURCE_FILE | cut -c 3-)
echo "==== Building '$SOURCE_FILE' ====" echo "==> File: $SOURCE_FILE"
gcc -c $GCC_ARGUMENTS -o $OBJECTS_FOLDER/$SOURCE_FILE.o $SOURCE_FILE $2 gcc -c $GCC_ARGUMENTS -o $MODULE_OBJECTS_FOLDER/$SOURCE_FILE.o $SOURCE_FILE $INCLUDE_STATEMENTS
done done
ar -rvs $PROJECT_ROOT/.build/$PROJECT_NAME-$1.a $OBJECTS_FOLDER/*.o OBJECT_FILES=$(find $MODULE_OBJECTS_FOLDER -mindepth 1 -type f)
cd $PROJECT_ROOT ar -rvs $REPOSITORY_FOLDER/.build/$PROJECT_NAME-$MODULE_NAME.a $OBJECT_FILES
cd $ENTRY_WORKING_DIR
} }
function compile_all_modules() { function compile_all_modules() {
compile_folder "core" "-I $PROJECT_ROOT/core/exports/" for MODULE_PATH in $(cat $MODULE_LIST_PATH)
compile_folder "platform" "-I $PROJECT_ROOT/core/exports/ -I $PROJECT_ROOT/platform/exports/" do
compile_single_module $MODULE_PATH
done
} }
case $1 in case $1 in

View File

@ -0,0 +1 @@
core/exports/