cbuild/include/config.sh

74 lines
2.4 KiB
Bash
Executable File

#!/usr/bin/env bash
include "@cbuild/include/myprint.sh"
include "@cbuild/include/functions.sh"
include "@cbuild/include/detect_os.sh"
function load_config {
local proj_conf_file="$1"
TASK="$2"
#true or false
local quiet=$3
if [ -z "$proj_conf_file" ]; then
error "config path is null"
fi
if [ ! -f "$proj_conf_file" ]; then
error "${YELLOW}$proj_conf_file doesn't exist"
fi
# load project user config
local proj_conf_user_file="$proj_conf_file.user"
file_copy_default_if_not_present "$proj_conf_user_file" "$proj_conf_user_file.default"
myprint "${BLUE}loading ${WHITE}'$proj_conf_user_file'"
# throw error on undefined variable usage
set -u
include "$proj_conf_user_file"
# don't throw error on undefined variable usage
set +u
myprint "${BLUE}loading ${WHITE}'$proj_conf_file'"
OS=$(detect_os)
ARCH=$(detect_arch)
myprint_quiet $quiet "${GREEN}detected OS: $OS"
# getting version of cbuild installation
if [ -z "$INSTALLED_CBUILD_VERSION" ]; then
error "couldnt get current cbuild installation version"
fi
# undefined task
[ -z "$TASK" ] && TASK="no_task"
# getting cbuild version from config (CBUILD_VERSION declaration is at line 2)
exec_script_line "$proj_conf_file" 2 $quiet
myprint_quiet $quiet "${WHITE}'${proj_conf_file}' cbuild version: ${CYAN}$CBUILD_VERSION"
myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION"
# checking versions
version_parse $INSTALLED_CBUILD_VERSION installed
version_parse $CBUILD_VERSION config
if [ "$installed_version_major.$installed_version_minor" != "$config_version_major.$config_version_minor" ]; then
error "config was created for cbuild$config_version_major.$config_version_minor, but loaded whith cbuild$installed_version_major.$installed_version_minor which is incompatible"
fi
if [[ $installed_version_patch < $config_version_patch ]]; then
myprint "${YELLOW}New patch for cbuild$installed_version_major.$installed_version_minor is abaliable."
myprint "${YELLOW}Install it to get latest bugfixes."
fi
set -u
include "$proj_conf_file"
mkdir -p "$OUTDIR"
mkdir -p "$OBJDIR/objects"
mkdir -p "$OBJDIR/static_libs"
mkdir -p "$OBJDIR/dynamic_libs"
mkdir -p "$OBJDIR/profile"
set +u
myprint_quiet $quiet "${GREEN}config loading completed"
}