Base/build.bash

76 lines
1.7 KiB
Bash
Raw Normal View History

2023-12-01 20:57:17 +00:00
#!/usr/bin/env bash
PROJECT_NAME="librr"
2023-12-01 20:57:17 +00:00
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
ar -rvs $PROJECT_ROOT/.build/$PROJECT_NAME-$1.a $OBJECTS_FOLDER/*.o
2023-12-01 20:57:17 +00:00
}
function compile_all_modules() {
for MODULE in $MODULES
do
echo "============ CURRENT MODULE: $MODULE ============"
compile_folder \
"$MODULE" \
"-I $PROJECT_ROOT/$MODULE/exports/"
2023-12-01 20:57:17 +00:00
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