aboutsummaryrefslogtreecommitdiff
path: root/msvc-dispatch
blob: 51804876eae4c34af8dddbd2af189af5f3082fa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /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 <tool>-<version>-<target> form.
# Based on that set some defaults, load the corresponding config file, and
# then continue with one of the msvc-<tool>-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 <version> itself should be <major>[minor] where
# <major> is digit-dot-only and minor should start with a non-digit-dot (e.g.,
# u1, rc1, etc).
#
arg=($(echo "$(basename "$src_exe")" | \
  sed -n -e 's/^\([^-]*\)-\([0-9.]*\)\([^-]*\)-\([^-]*\)$/\1 \4 \2 \3/p'))
tool="${arg[0]}"
target="${arg[1]}"

major="${arg[2]}"
minor="${arg[3]}"

MAJOR="${arg[2]^^}"
MINOR="${arg[3]^^}"

if [ -z "$tool" -o -z "$major" -o -z "$target" ]; then
  error "invalid top-level script name"
fi

# Calculate MSVC_{WINEPREFIX,INSTALLDIR,SDKVERSION}.
#
# We have the following environment variable name hierarchy:
#
# MSVC_<MAJOR><MINOR>_*
# MSVC_<MAJOR>_*
# MSVC_*
#
# And we always reduce these to just MSVC_* which are used further down.
#
function lookup_value() # <name>
{
  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"