aboutsummaryrefslogtreecommitdiff
path: root/msvc-dispatch
blob: 984a1a53d4cc7eb64bf2fa0dac519ba8d6584f1c (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
80
81
82
#! /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-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_<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"