aboutsummaryrefslogtreecommitdiff
path: root/msvc-mt-common
blob: 25c9c8e799b008ac12d54a7cbcc3305a0d841424 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env bash

# Common mt.exe driver that expects the SDKBIN variable to be set for the
# specific MSVC version/configuration.

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.
#
# Note that we assume mt.exe options start with '-' and are case-sensitive.
#
args=()

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

    # @@ TODO: handle for [;[#]<resource_id>]
    #
    #  -rgs:<file>
    #  -tlb:<file>
    #  -dll:<file>
    #  -replacements:<file>
    #  -managedassemblyname:<file>
    #  -out:<file>
    #  -inputresource:<file>[;[#]<resource_id>]
    #  -outputresource:<file>[;[#]<resource_id>]
    #  -updateresource:<file>[;[#]<resource_id>]
    #  -hashupdate[:<path to the files>]
    # -validate_file_hashes:<file>

    -rgs:* | \
    -tlb:* | \
    -dll:* | \
    -out:*)
      args=("${args[@]}" "$(split_translate 5 $1)")
      shift
      ;;

    -hashupdate:*)
      args=("${args[@]}" "$(split_translate 12 $1)")
      shift
      ;;

    -replacements:*)
      args=("${args[@]}" "$(split_translate 14 $1)")
      shift
      ;;

    -inputresource:*)
      args=("${args[@]}" "$(split_translate 15 $1)")
      shift
      ;;

    -outputresource:* | \
    -updateresource:*)
      args=("${args[@]}" "$(split_translate 16 $1)")
      shift
      ;;

    -managedassemblyname:*)
      args=("${args[@]}" "$(split_translate 21 $1)")
      shift
      ;;

    -validate_file_hashes:*)
      args=("${args[@]}" "$(split_translate 22 $1)")
      shift
      ;;

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

    # None.

    # Handle other options with combined values that could possibly be
    # interpreted as paths.
    #
    -identity:*)
      args=("${args[@]}" "$1")
      shift
      ;;

    # Option or argument.
    #
    *)
      # If starts with a slash, treat it as a path (options start with dash).
      #
      if [[ "$1" == /* ]]; then
	args=("${args[@]}" "$(translate $1)")
      else
	args=("${args[@]}" "$1")
      fi
      shift
      ;;
  esac
done

# mt.exe always sends diagnostics to stdout.
#
msvc_exec 1 "$SDKBIN\\mt.exe" "${args[@]}"