From 1f8ff01c81808d7e7e11b28a7118186974f4edcf Mon Sep 17 00:00:00 2001 From: Eric-Paul Ickhorn Date: Fri, 1 Dec 2023 21:57:17 +0100 Subject: [PATCH] Added the first version of build.bash --- build.bash | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 build.bash diff --git a/build.bash b/build.bash new file mode 100644 index 0000000..10c0391 --- /dev/null +++ b/build.bash @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +PROJECT_ROOT=`pwd` +GCC_ARGUMENTS="-std=c11 -Wall" + +MODULES=( + "core" +) + +# Arguments: +# 1) Path to the module +# 2) Include Statements +function compile_folder() { + + OBJECTS_FOLDER="$PROJECT_ROOT/.build/objects/$1" + mkdir -p $OBJECTS_FOLDER + cd $PROJECT_ROOT/$1 + + cd src-c/ + for SOURCE_FILE in $(find .) + do + # Create every folder except of the source root folder (src-c/). + if [[ $SOURCE_FILE != "." ]] then + if [[ -d $SOURCE_FILE ]] then + mkdir $SOURCE_FILE + continue + fi + fi + + if [[ ! -f $SOURCE_FILE ]] then + continue + fi + + # Cut out the ./ at the front of the path + SOURCE_FILE=$(echo $SOURCE_FILE | cut -c 3-) + + echo "==== Building '$SOURCE_FILE' ====" + gcc -c $GCC_ARGUMENTS -o $OBJECTS_FOLDER/$SOURCE_FILE.o $SOURCE_FILE $2 + done +} + +function compile_all_modules() { + for MODULE in $MODULES + do + echo "============ CURRENT MODULE: $MODULE ============" + compile_folder "$MODULE" "-I $PROJECT_ROOT/$MODULE/exports/" + done +} + +case $1 in + "release") + GCC_ARGUMENTS="$GCC_ARGUMENTS -O3" + compile_all_modules + ;; + + "small") + GCC_ARGUMENTS="$GCC_ARGUMENTS -Os" + compile_all_modules + ;; + + "debug") + GCC_ARGUMENTS="$GCC_ARGUMENTS -p -g3 -Wextra" + compile_all_modules + ;; + + *) + echo "Please choose one of the following profiles:" + echo "[ release | small | debug ]" + ;; +esac