make/scripts/vsvars.sh
changeset 14069 2ca7a2522cb4
parent 7361 f412b1d9549b
child 14277 e03d509a553e
--- a/make/scripts/vsvars.sh	Wed Jul 05 18:26:11 2017 +0200
+++ b/make/scripts/vsvars.sh	Tue Oct 23 10:10:49 2012 -0700
@@ -1,7 +1,7 @@
 #!/bin/sh
 
 #
-# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -27,22 +27,6 @@
 #   variables normally set by the vcvars32.bat or vcvars64.bat file or
 #   SetEnv.cmd for older SDKs.
 
-# Use cygpath?
-isCygwin="`uname -s | grep CYGWIN`"
-if [ "${isCygwin}" != "" ] ; then
-  cygpath="/usr/bin/cygpath"
-  cygpath_short="${cygpath} -m -s"
-  cygpath_windows="${cygpath} -w -s"
-  cygpath_path="${cygpath} -p"
-  pathsep=':'
-else
-  cygpath="dosname"
-  cygpath_short="${cygpath} -s"
-  cygpath_windows="${cygpath} -s"
-  cygpath_path="echo"
-  pathsep=';'
-fi
-
 ########################################################################
 # Error functions
 msg() # message
@@ -60,8 +44,8 @@
 }
 envpath() # path
 {
-  if [ "${cygpath_short}" != "" -a -d "$1" ] ; then
-    ${cygpath_short} "$1"
+  if [ "${fixpath}" != "" -a -d "$1" ] ; then
+    ${fixpath} "$1"
   else
     echo "$1"
   fi
@@ -72,14 +56,65 @@
 # Defaults settings
 debug="false"
 verbose="false"
-shellStyle="sh"
-parentCsh="` ps -p ${PPID} 2> /dev/null | grep csh `"
-if [ "${parentCsh}" != "" ] ; then
-  shellStyle="csh"
-fi
 
 set -e
 
+CYGWIN="nodosfilewarning ntsec"
+export CYGWIN
+
+# pathsepIn is always ; because the input strings are coming from
+# vcvarsxx.bat.  This is true under all of MKS, Cygwin, MINGW/msys
+pathsepIn=';'
+
+OS="`uname -s`"
+case "${OS}" in
+  CYGWIN*)
+    pathflag='-c'
+    devnull=/dev/null
+    pathsepOut=':'
+  ;;
+
+  MINGW*)
+    pathflag='-m'
+    devnull=/dev/null
+    pathsepOut=':'
+  ;;
+
+  *)
+    # MKS?
+    # Continue using dosname -s
+    pathflag='-s'
+    fixpath="dosname ${pathflag}"
+    fixpath_windows="${fixpath}"
+    fixpath_path="echo"
+    devnull=NUL
+    pathsepOut=';'
+  ;;
+esac
+
+case "${OS}" in
+  CYGWIN*|MINGW*)
+    t=`dirname ${0}`
+    wd=`cd ${t} 2> ${devnull} && pwd`
+    fixpath_script="${wd}/fixpath.pl"
+    if [ ! -f "${fixpath_script}" ] ; then
+        error "Does not exist: ${fixpath_script}"
+    fi
+    fixpath="perl ${fixpath_script} ${pathflag}"
+    fixpath_windows="perl ${fixpath_script} -d"
+    fixpath_path="${fixpath_windows}"
+  ;;
+esac
+
+shellStyle="sh"
+## As far as I can tell from hg history, this has not worked
+## for a long time because PPID is unset.  When run under Cygwin
+## the script quits due to the 1 return from grep.
+##parentCsh="` ps -p ${PPID} 2> ${devnull} | grep csh `"
+##if [ "${parentCsh}" != "" ] ; then
+##  shellStyle="csh"
+##fi
+
 # Check environment first
 if [ "${PROGRAMFILES}" != "" ] ; then
   progfiles=`envpath "${PROGRAMFILES}"`
@@ -96,15 +131,19 @@
 # Arch data model
 if [ "${PROCESSOR_IDENTIFIER}" != "" ] ; then
   arch=`echo "${PROCESSOR_IDENTIFIER}" | cut -d' ' -f1`
-elif [ "${MACHTYPE}" != "" ] ; then
-  if [ "`echo ${MACHTYPE} | grep 64`" != "" ] ; then
-    # Assume this is X64, not IA64
-    arch="x64"
+else
+  if [ "${MACHTYPE}" != "" ] ; then
+    if [ "`echo ${MACHTYPE} | grep 64`" != "" ] ; then
+      # Assume this is X64, not IA64
+      arch="x64"
+    else
+      arch="x86"
+    fi
   else
-    arch="x86"
+   arch="`uname -m`"
   fi
-else
- arch="`uname -m`"
+  PROCESSOR_IDENTIFIER="${arch}"
+  export PROCESSOR_IDENTIFIER
 fi
 if [ "${arch}" = "X86" -o \
      "${arch}" = "386" -o "${arch}" = "i386" -o \
@@ -121,11 +160,11 @@
      "${arch}" = "intel64" -o "${arch}" = "Intel64" -o \
      "${arch}" = "64" ] ; then
   arch="x64"
-  binarch64="/amd64"
+  binarch64="\\amd64"
 fi
 if [ "${arch}" = "IA64" ] ; then
   arch="ia64"
-  binarch64="/ia64"
+  binarch64="\\ia64"
 fi
 if [ "${arch}" != "x86" -a "${arch}" != "x64" -a "${arch}" != "ia64" ] ; then
  error "No PROCESSOR_IDENTIFIER or MACHTYPE environment variables and uname -m is not helping"
@@ -324,25 +363,26 @@
 }
 
 # Remove all duplicate entries
-removeDeadDups() # string sep
+removeDeadDups() # string sepIn sepOut
 {
   set -e
-  sep="$2"
+  sepIn="$2"
+  sepOut="$3"
   pathlist="${tmp}/pathlist"
   printf "%s\n" "$1" | \
     sed -e 's@\\@/@g' | \
     sed -e 's@//@/@g' | \
-    ${awk} -F"${sep}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}'  \
+    ${awk} -F"${sepIn}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}'  \
       > ${pathlist}
   upaths="${tmp}/upaths"
   cat ${pathlist} | while read orig; do
     p="${orig}"
-    if [ "${cygpath_short}" != "" ] ; then
+    if [ "${fixpath}" != "" ] ; then
       if [ "${p}" != "" ] ; then
         if [ -d "${p}" ] ; then
-          short=`${cygpath_short} "${p}"`
+          short=`${fixpath} "${p}"`
           if [ "${short}" != "" -a -d "${short}" ] ; then
-            p=`${cygpath} "${short}"`
+            p="${short}"
           fi
           echo "${p}" >> ${upaths}
         fi
@@ -356,11 +396,11 @@
     if [ "${newpaths}" = "" ] ; then
       newpaths="${i}"
     else
-      newpaths="${newpaths}${sep}${i}"
+      newpaths="${newpaths}${sepOut}${i}"
     fi
   done
   printf "%s\n" "${newpaths}" | \
-    ${awk} -F"${sep}" \
+    ${awk} -F"${sepOut}" \
        '{a[$1];printf "%s",$1;for(i=2;i<=NF;i++){if(!($i in a)){a[$i];printf "%s%s",FS,$i;}};printf "\n";}'
 }
 
@@ -388,7 +428,7 @@
 set VSINSTALLDIR=
 set WindowsSdkDir=
 REM Run the vcvars bat file, send all output to stderr
-call `${cygpath_windows} ${bdir}`\\${command} > `${cygpath_windows} "${stdout}"`
+call `${fixpath_windows} ${bdir}`\\${command} > `${fixpath_windows} "${stdout}"`
 REM Echo out env var settings
 echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%"
 echo export VS_VS71COMNTOOLS
@@ -427,9 +467,18 @@
 # Create env file
 createEnv() # batfile envfile
 {
-  rm -f ${1}.stdout
-  cmd.exe /Q /C `${cygpath_short} $1` | \
-    sed -e 's@\\@/@g' | \
+  rm -f ${1}.stdout ${1}.temp1 ${1}.temp2
+  batfile=`${fixpath} ${1}`
+  cmd.exe -Q -C < "$batfile" 1> ${1}.temp1 2> ${1}.temp2
+  cat ${1}.temp1 | \
+    sed -e 's@^Microsoft.*@@' \
+        -e 's@^.*Copyright.*@@' \
+        -e 's@^.*>REM.*@@' \
+        -e 's@^.*>set.*@@' \
+        -e 's@^.*>echo.*@@' \
+        -e 's@^.*>call.*@@' \
+        -e 's@^.*>$@@' \
+        -e 's@\\@/@g' | \
     sed -e 's@//@/@g' > $2
   if [ -f "${1}.stdout" ] ; then
     cat ${1}.stdout 1>&2
@@ -465,7 +514,7 @@
 #############################################################################
 
 # Get Visual Studio settings
-if [ "${cygpath}" != "" ] ; then
+if [ "${fixpath}" != "" ] ; then
 
   # Create bat file to run
   batfile="${tmp}/vs-to-env.bat"
@@ -485,11 +534,11 @@
   . ${envfile}
 
   # Derive unix style path, save old, and define new (remove dups)
-  VS_UPATH=`${cygpath_path} "${VS_WPATH}"`
+  VS_UPATH=`${fixpath_path} "${VS_WPATH}"`
   export VS_UPATH
   VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'`
   export VS_OPATH
-  VS_PATH=`removeDeadDups "${VS_UPATH}${pathsep}${VS_OPATH}" "${pathsep}"`
+  VS_PATH=`removeDeadDups "${VS_UPATH}${pathsepIn}${VS_OPATH}" "${pathsepIn}" "${pathsepOut}"`
   export VS_PATH
 
 fi
@@ -536,11 +585,13 @@
   checkPaths "Windows PATH" "${VS_WPATH}" ";"
   checkPaths LIB "${VS_LIB}" ";"
   checkPaths INCLUDE "${VS_INCLUDE}" ";"
-  checkPaths PATH "${VS_PATH}" "${pathsep}"
+  checkPaths PATH "${VS_PATH}" "${pathsepIn}"
 fi
 
 # Remove all temp files
-rm -f -r ${tmp}
+if [ "${debug}" != "true" ] ; then
+  rm -f -r ${tmp}
+fi
 
 exit 0