cbuild/config.sh
2024-07-19 00:13:12 +03:00

78 lines
2.4 KiB
Bash

#!/usr/bin/env bash
include cbuild/myprint.sh
include cbuild/functions.sh
include cbuild/detect_os.sh
function myprint_quiet {
local quiet=$1
local text="$2"
if [ "$quiet" != true ]; then
myprint "$text"
fi
}
function load_config {
local project_config_path="$1"
TASK="$2"
local quiet=$3
myprint "${BLUE}loading config '$(realpath $project_config_path)'"
if [ -z "$project_config_path" ]; then
error "config path is null"
fi
if [ ! -f "$project_config_path" ]; then
error "${YELLOW}$project_config_path doesn't exist"
fi
OS=$(detect_os)
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 "$project_config_path" 2 $quiet
myprint_quiet $quiet "${WHITE}${project_config_path} 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_major=$version_major
installed_version_minor=$version_minor
installed_version_patch=$version_patch
version_parse $CBUILD_VERSION
config_version_major=$version_major
config_version_minor=$version_minor
config_version_patch=$version_patch
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
# throw error on undefined variable usage
set -u
include "$project_config_path"
mkdir -p "$OUTDIR"
mkdir -p "$OBJDIR/objects"
mkdir -p "$OBJDIR/static_libs"
mkdir -p "$OBJDIR/dynamic_libs"
mkdir -p "$OBJDIR/profile"
# dont thorw error on undefined variable
set +u
myprint_quiet $quiet "${GREEN}loaded cbuild config"
}