#! /usr/bin/env bash # file : msvc-common/msvc-lib-common # license : MIT; see accompanying LICENSE file # Note: shouldn't be executed directly, src_dir must be set. # Common lib.exe driver that expects the VCBIN and LIB variables to be set for # the specific MSVC version/configuration. # # It's not clear/documented why we need LIB or what the /LIBPATH option is # for. Perhaps for link-time code generation (/LTCG). source "$src_dir/msvc-common/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 # Uppercase for case-insensitive comparison. # /DEF[:filename] # /OUT:filename # [/-]DEF:* | \ [/-]OUT:*) args=("${args[@]}" "$(split_translate 5 $1)") shift ;; # /LIST[:filename] # /NAME:filename # [/-]LIST:* | \ [/-]NAME:*) args=("${args[@]}" "$(split_translate 6 $1)") shift ;; # /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. # # Aren't any. # Handle other options with combined values that could possibly be # interpreted as paths, for example /EXTRACT:foo/bar.obj. # [/-]EXPORT:* | \ [/-]EXTRACT:* | \ [/-]INCLUDE:* | \ [/-]REMOVE:*) args=("${args[@]}" "$1") shift ;; # 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 may need to run other tools (/LTCG). # export WINEPATH="$VCBIN;$VCDLL;$SDKBIN;$WINEPATH" # lib.exe always sends diagnostics to stdout. # msvc_exec 1 "$VCBIN\\lib.exe" "${args[@]}"