aboutsummaryrefslogtreecommitdiff
path: root/msvc-link-common
blob: 64c8a0ce8d5e60e8831d8218a3142220acff45da (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
#! /usr/bin/env bash

# Common link.exe driver that expects the VC and LIB variables to be set for
# the specific MSVC version/configuration set.

trap "{ exit 1; }" ERR
set -o errtrace # Trap in functions.

function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }

source $(dirname $(realpath ${BASH_SOURCE[0]}))/msvc-common

# Translate absolute paths from POSIX to Windows. Use bash array to store
# arguments in case they contain spaces.
#
# This needs to be done for both certain option values and arguments.
# Arguments are tricky in that unless we recognize every option, and option
# may look a lot like an absolute POSIX path (e.g., /nologo). The heuristics
# that we are going to use here is that if the argument starts with / and
# contains at least one more /, then we consider it an argument. Otherwise --
# an options. We will also explicitly recognize certain options which may
# not fit this scheme well.
#
args=()

while [ $# -gt 0 ]; do
  case $1 in

    # /DEF[:filename]
    # /OUT:filename
    #
    [/-]DEF:* | \
    [/-]OUT:*)
      args=("${args[@]}" "$(split_translate 5 $1)")
      shift
      ;;

    # @@ TODO
    #

    # /LIBPATH:dir
    #
    [/-]LIBPATH:*)
      args=("${args[@]}" "$(split_translate 9 $1)")
      shift
      ;;

    # Handle other options with separate values. This makes sure we don't try
    # to path-translate them.
    #

    # @@ TODO

    # Handle other options with combined values that could possibly be
    # interpreted as paths, for example /EXTRACT:foo/bar.obj.
    #

    # @@ TODO

    # Option or argument.
    #
    *)
      # If contains at least two slashes, treat it as a path.
      #
      if [[ "$1" == /*/* ]]; then
	args=("${args[@]}" "$(translate $1)")
      else
	args=("${args[@]}" "$1")
      fi
      shift
      ;;
  esac
done

export LIB

# Link.exe always sends diagnostics to stdout.
#
msvc_exec 1 "$VC\\bin\\link.exe" "${args[@]}"