Made the build script more advanced and configurable
This commit is contained in:
parent
eab3989878
commit
dcbd9555d5
|
@ -0,0 +1,2 @@
|
|||
core
|
||||
platform
|
88
build.bash
88
build.bash
|
@ -1,34 +1,71 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Get the absolute repository root path and go there
|
||||
cd $(dirname "$(pwd)/$0")
|
||||
REPOSITORY_FOLDER=$(pwd)
|
||||
|
||||
|
||||
# Configuration Values start here
|
||||
|
||||
PROJECT_NAME="librr"
|
||||
PROJECT_ROOT=`pwd`
|
||||
GCC_ARGUMENTS="-std=c11 -Wall"
|
||||
|
||||
MODULES=(
|
||||
"core"
|
||||
"platform"
|
||||
)
|
||||
MAIN_OBJECTS_FOLDER="$REPOSITORY_FOLDER/.build/objects"
|
||||
|
||||
# End of configuration values
|
||||
|
||||
|
||||
|
||||
# Constants not meant for configuration
|
||||
|
||||
CONFIG_FILE_INCLUDE_PATHS="build-config/include_paths.txt"
|
||||
MODULE_LIST_PATH="build-config/modules.txt"
|
||||
|
||||
|
||||
|
||||
function get_include_path_configuration {
|
||||
MODULE_NAME=$1
|
||||
|
||||
INCLUDE_CONFIG_PATH="$REPOSITORY_FOLDER/$MODULE_NAME/$CONFIG_FILE_INCLUDE_PATHS"
|
||||
INCLUDE_STATEMENTS="-I $REPOSITORY_FOLDER/$MODULE_NAME/inc-c/ -I $REPOSITORY_FOLDER/$MODULE_NAME/exports/"
|
||||
if [[ ! -f $INCLUDE_CONFIG_PATH ]]
|
||||
then
|
||||
return
|
||||
fi
|
||||
|
||||
for LINE in $(cat $INCLUDE_CONFIG_PATH)
|
||||
do
|
||||
INCLUDE_STATEMENTS="$INCLUDE_STATEMENTS -I $REPOSITORY_FOLDER/$LINE"
|
||||
done
|
||||
}
|
||||
|
||||
# Arguments:
|
||||
# 1) Path to the module
|
||||
# 2) Include Statements
|
||||
function compile_folder() {
|
||||
# 1) Module name / folder name in project root (May not include slashes)
|
||||
function compile_single_module() {
|
||||
MODULE_NAME=$1
|
||||
|
||||
OBJECTS_FOLDER="$PROJECT_ROOT/.build/objects/$1"
|
||||
mkdir -p $OBJECTS_FOLDER
|
||||
cd $PROJECT_ROOT/$1
|
||||
ENTRY_WORKING_DIR=$(pwd)
|
||||
printf "\n\n\n"
|
||||
echo "|================> Module Separator <================|"
|
||||
echo "> Name: $MODULE_NAME "
|
||||
echo "> Path: $REPOSITORY_FOLDER/$MODULE_NAME"
|
||||
echo " "
|
||||
get_include_path_configuration $MODULE_NAME
|
||||
|
||||
MODULE_OBJECTS_FOLDER="$MAIN_OBJECTS_FOLDER/$MODULE_NAME"
|
||||
mkdir -p $MODULE_OBJECTS_FOLDER
|
||||
cd $REPOSITORY_FOLDER/$1
|
||||
|
||||
cd src-c/
|
||||
for SOURCE_FILE in $(find .)
|
||||
for SOURCE_FILE in $(find . -mindepth 1)
|
||||
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
|
||||
# Create all subfolders of this module's source folder
|
||||
if [[ -d $SOURCE_FILE ]] then
|
||||
mkdir -p $MODULE_OBJECTS_FOLDER/$SOURCE_FILE
|
||||
continue
|
||||
fi
|
||||
|
||||
# If this is not a regular file, quietly ignore it.
|
||||
if [[ ! -f $SOURCE_FILE ]] then
|
||||
continue
|
||||
fi
|
||||
|
@ -36,17 +73,20 @@ function compile_folder() {
|
|||
# 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
|
||||
echo "==> File: $SOURCE_FILE"
|
||||
gcc -c $GCC_ARGUMENTS -o $MODULE_OBJECTS_FOLDER/$SOURCE_FILE.o $SOURCE_FILE $INCLUDE_STATEMENTS
|
||||
done
|
||||
|
||||
ar -rvs $PROJECT_ROOT/.build/$PROJECT_NAME-$1.a $OBJECTS_FOLDER/*.o
|
||||
cd $PROJECT_ROOT
|
||||
OBJECT_FILES=$(find $MODULE_OBJECTS_FOLDER -mindepth 1 -type f)
|
||||
ar -rvs $REPOSITORY_FOLDER/.build/$PROJECT_NAME-$MODULE_NAME.a $OBJECT_FILES
|
||||
cd $ENTRY_WORKING_DIR
|
||||
}
|
||||
|
||||
function compile_all_modules() {
|
||||
compile_folder "core" "-I $PROJECT_ROOT/core/exports/"
|
||||
compile_folder "platform" "-I $PROJECT_ROOT/core/exports/ -I $PROJECT_ROOT/platform/exports/"
|
||||
for MODULE_PATH in $(cat $MODULE_LIST_PATH)
|
||||
do
|
||||
compile_single_module $MODULE_PATH
|
||||
done
|
||||
}
|
||||
|
||||
case $1 in
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
core/exports/
|
Loading…
Reference in New Issue