#!/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 exec_script_line { local script="$1" local line_num="$2" local quiet=$3 myprint_quiet $quiet "${BLUE}reading line $line_num from $script" local line_str="$(sed $line_num'!d' $script)" myprint_quiet $quiet "$line_str" eval "$line_str" } function load_config { local current_config_path="$1" local default_config_path="$2" TASK="$3" local quiet=$4 if [ -z "$current_config_path" ]; then error "current_config_path is null" fi if [ -z "$default_config_path" ]; then error "default_config_path is null" 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 # getting version of default config exec_script_line "$default_config_path" 3 $quiet DEFAULT_CONFIG_VERSION="$CONFIG_VERSION" unset CONFIG_VERSION # undefined task [ -z "$TASK" ] && TASK="no_task" # error on undefined set -u # reading current config or creating default if [ ! -f "$current_config_path" ]; then myprint "${YELLOW}$current_config_path doesn't exist" cp "$default_config_path" "$current_config_path" myprint "${YELLOW}Created copy (${current_config_path}) of default config (${default_config_path})" fi myprint_quiet $quiet "${BLUE}reading $current_config_path" include "$current_config_path" myprint_quiet $quiet "${WHITE}project: ${CYAN}$PROJECT" myprint_quiet $quiet "${WHITE}${current_config_path} cbuild version: ${CYAN}$CBUILD_VERSION" myprint_quiet $quiet "${WHITE}installed cbuild version: ${CYAN}$INSTALLED_CBUILD_VERSION" myprint_quiet $quiet "${WHITE}${current_config_path} version: ${CYAN}$CONFIG_VERSION" myprint_quiet $quiet "${WHITE}${default_config_path} version: ${CYAN}$DEFAULT_CONFIG_VERSION" # checking versions if [ "$CBUILD_VERSION" != "$INSTALLED_CBUILD_VERSION" ]; then error "config was created for outdated cbuild version" fi if [ "$CONFIG_VERSION" != "$DEFAULT_CONFIG_VERSION" ]; then error "current config version doesn't match default config version" fi 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" }