Parcel/build.bash

120 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
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/core-parser/inc/
cd ..
done
}
function compile_utility() {
echo "======== COMPILING UTILITY LIBRARY ========"
rm -r .build/objects/utility/
mkdir -p .build/objects/utility/
for source_file in $(find "utility/src/")
do
if [[ ! -f $source_file ]] then
continue
fi
# Cut out the prefix (utility/src/)
BASENAME=`echo $source_file | cut -c '13-'`
echo "---- Compiling '$source_file' ----"
gcc -c $COMPILATION_FLAGS \
-o .build/objects/utility/$BASENAME.o $source_file \
\
-I utility/inc/ -I utility/exports/
done
}
function compile_core_parser() {
echo "======== COMPILING CORE PARSER LIBRARY ========"
rm -r .build/objects/core-parser
rm .build/libparcel-parser.a
mkdir -p .build/objects/core-parser/
for source_file in $(find "core-parser/src/")
do
if [[ ! -f $source_file ]] then
continue
fi
# Cut out the prefix (core-parser/src/)
BASENAME=`echo $source_file | cut -c '17-'`
echo "---- Compiling '$source_file' ----"
gcc -c $COMPILATION_FLAGS \
-o .build/objects/core-parser/$BASENAME.o $source_file \
\
-I core-parser/inc/ -I core-parser/exports/ \
-I utility/exports/
done
}
function build_debug() {
COMPILATION_FLAGS="-g2 -Wall -Wextra -D__PAC_DEBUG__"
compile_utility
compile_core_parser
ar -rvs .build/libparcel-parser.a \
.build/objects/core-parser/*.o
ar -rvs .build/libparcel-utility.a \
.build/objects/utility/*.o
}
function build_release() {
COMPILATION_FLAGS="-O2 -Wall -D__PAC_RELEASE__"
compile_utility
compile_core_parser
ar -rvs .build/libparcel.a \
.build/objects/core-parser/*.o \
ar -rvs .build/libparcel-utility.a \
.build/objects/utility/*.o
}
function clean() {
rm -R .build/objects/*.o
rm .build/libparcel-parser.a
rm .build/libparcel-utility.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