2023-11-26 20:00:32 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
INCLUDE_STATEMENTS="-I code/inc/ -I code/exports/"
|
|
|
|
INVOCATION_PATH=`pwd`
|
|
|
|
|
|
|
|
function build_checks() {
|
|
|
|
if [[ ! -f $INVOCATION_PATH/.build/libparcel.a ]] then
|
|
|
|
build_debug
|
|
|
|
fi
|
|
|
|
cd checks/
|
|
|
|
for check_folder in $(ls)
|
|
|
|
do
|
|
|
|
if [[ -f $check_folder ]] then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd $check_folder
|
|
|
|
gcc src/*.c $INVOCATION_PATH/.build/libparcel.a -o check.elf -I $INVOCATION_PATH/code/inc/
|
2023-11-28 14:35:19 +00:00
|
|
|
cd ..
|
2023-11-26 20:00:32 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function create_archive() {
|
|
|
|
ar -rvs .build/libparcel.a .build/objects/*.o
|
|
|
|
}
|
|
|
|
|
|
|
|
function compile_sources() {
|
|
|
|
|
|
|
|
rm -r .build/objects/
|
|
|
|
rm .build/libparcel.a
|
|
|
|
mkdir -p .build/objects
|
|
|
|
for source_file in $(find "code/src/")
|
|
|
|
do
|
|
|
|
if [[ ! -f $source_file ]] then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Cut out the prefix (code/src/)
|
|
|
|
BASENAME=`echo $source_file | cut -c '10-'`
|
|
|
|
echo "==== COMPILING $source_file ===="
|
|
|
|
gcc -c $COMPILATION_FLAGS -o .build/objects/$BASENAME.o $source_file $INCLUDE_STATEMENTS
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_debug() {
|
|
|
|
COMPILATION_FLAGS="-g2 -Wall -Wextra -D__PAC_DEBUG__"
|
|
|
|
compile_sources
|
|
|
|
create_archive
|
|
|
|
}
|
|
|
|
|
|
|
|
function build_release() {
|
|
|
|
COMPILATION_FLAGS="-O2 -Wall -D__PAC_RELEASE__"
|
|
|
|
compile_sources
|
|
|
|
create_archive
|
|
|
|
}
|
|
|
|
|
|
|
|
function clean() {
|
|
|
|
rm -R .build/objects/*.o
|
|
|
|
rm .build/libparcel.a
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
|
|
|
"clean")
|
|
|
|
clean
|
|
|
|
;;
|
|
|
|
"debug")
|
|
|
|
build_debug
|
|
|
|
;;
|
|
|
|
"release")
|
|
|
|
build_release
|
|
|
|
;;
|
|
|
|
"checks")
|
|
|
|
build_checks
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown action '$1'. Possible Actions are:"
|
|
|
|
echo "[ clean | debug | release | checks ]"
|
|
|
|
esac
|