#! /usr/bin/env bash # Note: shouldn't be executed directly, src_exe and src_dir must be set. # The filename in src_exe should be in the -- form. # Based on that set some defaults, load the corresponding config file, and # then continue with one of the msvc--common scripts. trap "{ exit 1; }" ERR set -o errtrace # Trap in functions. function info () { echo "$*" 1>&2; } function error () { info "$*"; exit 1; } # Split the argument. The itself should be [minor] where # is digit-only and minor should start with the dot (e.g., .0). # arg=($(echo "$(basename "$src_exe")" | \ sed -n -e 's/^\([^-]*\)-\([0-9]*\)\(\.[^-]\{1,\}\)\{0,1\}-\([^-]*\)$/\1 \4 \2 \3/p')) tool="${arg[0]}" target="${arg[1]}" major="${arg[2]}" minor="${arg[3]}" MAJOR="${major^^}" MINOR="${minor^^}" if [ -z "$tool" -o -z "$major" -o -z "$target" ]; then error "invalid top-level script name" fi # For the minor version used in variable names replace dots with underscores. # MINOR="$(echo "$MINOR" | sed -e 's/\./_/g')" # Calculate MSVC_{WINEPREFIX,INSTALLDIR,SDKVERSION}. # # We have the following environment variable name hierarchy: # # MSVC__* # MSVC__* # MSVC_* # # And we always reduce these to just MSVC_* which are used further down. # function lookup_value() # { local n="MSVC_${MAJOR}${MINOR}_$1" local v="${!n}" if [ -z "$v" ]; then n="MSVC_${MAJOR}_$1" v="${!n}" if [ -z "$v" ]; then n="MSVC_$1" v="${!n}" fi fi echo "$v" } MSVC_WINEPREFIX="$(lookup_value "WINEPREFIX")" MSVC_INSTALLDIR="$(lookup_value "INSTALLDIR")" MSVC_SDKVERSION="$(lookup_value "SDKVERSION")" # Set an alternative .wine directory if requested. WINEPREFIX environment # variable is recognized by wine and winepath programs. # if [ -n "$MSVC_WINEPREFIX" ]; then export WINEPREFIX="$MSVC_WINEPREFIX" fi # Load the configuration. # source "$src_dir/msvc-$major/msvc-$major$minor-$target" # Dispatch to the tool. # source "$src_dir/msvc-common/msvc-$tool-common"