151 lines
3.9 KiB
Bash
Executable File
151 lines
3.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
PROJECT_NAME="technetium"
|
|
GCC_ARGUMENTS="-std=c11 -Wall"
|
|
|
|
MODULES=(
|
|
"starter"
|
|
"graphics"
|
|
"resources"
|
|
)
|
|
|
|
PROJECT_ROOT=`pwd`
|
|
|
|
# Arguments:
|
|
# 1) Path to the module
|
|
# 2) Include Statements
|
|
function compile_folder() {
|
|
|
|
mkdir -p .build/archives
|
|
|
|
OBJECTS_FOLDER="$PROJECT_ROOT/.build/objects/$1"
|
|
rm -r $OBJECTS_FOLDER/
|
|
|
|
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 -p $OBJECTS_FOLDER/$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
|
|
|
|
OBJECT_FILES=$(find $OBJECTS_FOLDER/ -type f)
|
|
ar -rvs $PROJECT_ROOT/.build/archives/$PROJECT_NAME-$1.a $OBJECT_FILES
|
|
}
|
|
|
|
function compile_all_modules() {
|
|
|
|
echo "============ CURRENT MODULE: STARTER (starter/) ============"
|
|
compile_folder starter \
|
|
"-I $PROJECT_ROOT/starter/inc/ \
|
|
-I $PROJECT_ROOT/graphics/exports/ \
|
|
-I $PROJECT_ROOT/resources/exports/ \
|
|
-I $PROJECT_ROOT/.build/dependencies/libRR-Core/core/exports"
|
|
|
|
echo "============ CURRENT MODULE: RENDERER (graphics/) ============"
|
|
compile_folder graphics \
|
|
"-I $PROJECT_ROOT/graphics/inc/ \
|
|
-I $PROJECT_ROOT/resources/exports/ \
|
|
-I $PROJECT_ROOT/.build/dependencies/libRR-Core/core/exports"
|
|
cd $PROJECT_ROOT
|
|
|
|
echo "============ CURRENT MODULE: RESOURCE REGISTRY (resources/) ============"
|
|
compile_folder resources \
|
|
"-I $PROJECT_ROOT/resources/inc/ \
|
|
-I $PROJECT_ROOT/resources/exports/ \
|
|
-I $PROJECT_ROOT/resources/dependencies/inc/ \
|
|
-I $PROJECT_ROOT/.build/dependencies/libRR-Core/core/exports"
|
|
cd $PROJECT_ROOT
|
|
}
|
|
|
|
function link_project() {
|
|
|
|
cd $PROJECT_ROOT
|
|
ARCHIVES=`find .build/archives/*.a`
|
|
gcc -o technetium.elf $ARCHIVES $ARCHIVES .build/archives/librr-core.a -lSDL2 -lGL -lm
|
|
}
|
|
|
|
function clone_dependencies() {
|
|
|
|
rm -rf .build/dependencies
|
|
mkdir -p .build/dependencies
|
|
cd .build/dependencies
|
|
|
|
echo " "
|
|
echo "|============================================================|"
|
|
echo "|> CLONING DEPENDENCY: libRR <|"
|
|
echo "|============================================================|"
|
|
echo " "
|
|
|
|
git clone https://git.nerdcult.net/libRR/Core
|
|
mv Core libRR-Core
|
|
}
|
|
|
|
function build_dependencies() {
|
|
|
|
echo " "
|
|
echo "|============================================================|"
|
|
echo "|> BUILDING DEPENDENCY: libRR <|"
|
|
echo "|============================================================|"
|
|
echo " "
|
|
|
|
mkdir -p .build/archives
|
|
cd .build/dependencies
|
|
|
|
cd libRR-Core
|
|
bash build.bash release
|
|
mv .build/librr-core.a $PROJECT_ROOT/.build/archives/
|
|
cd ..
|
|
}
|
|
|
|
case $1 in
|
|
"update-deps")
|
|
clone_dependencies
|
|
;;
|
|
|
|
"dependencies")
|
|
build_dependencies
|
|
;;
|
|
|
|
"release")
|
|
GCC_ARGUMENTS="$GCC_ARGUMENTS -O3"
|
|
compile_all_modules
|
|
link_project
|
|
;;
|
|
|
|
"small")
|
|
GCC_ARGUMENTS="$GCC_ARGUMENTS -Os"
|
|
compile_all_modules
|
|
link_project
|
|
;;
|
|
|
|
"debug")
|
|
GCC_ARGUMENTS="$GCC_ARGUMENTS -p -g3 -Wextra"
|
|
compile_all_modules
|
|
link_project
|
|
;;
|
|
|
|
*)
|
|
echo "Please choose one of the following profiles:"
|
|
echo "[ update-deps | dependencies | release | small | debug ]"
|
|
;;
|
|
esac
|
|
|