1 #!/bin/sh |
1 #!/bin/sh |
2 |
2 |
3 # |
3 # |
4 # Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. |
4 # Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6 # |
6 # |
7 # This code is free software; you can redistribute it and/or modify it |
7 # This code is free software; you can redistribute it and/or modify it |
8 # under the terms of the GNU General Public License version 2 only, as |
8 # under the terms of the GNU General Public License version 2 only, as |
9 # published by the Free Software Foundation. |
9 # published by the Free Software Foundation. |
25 |
25 |
26 # This file should be used to set the Visual Studio environment |
26 # This file should be used to set the Visual Studio environment |
27 # variables normally set by the vcvars32.bat or vcvars64.bat file or |
27 # variables normally set by the vcvars32.bat or vcvars64.bat file or |
28 # SetEnv.cmd for older SDKs. |
28 # SetEnv.cmd for older SDKs. |
29 |
29 |
30 # Use cygpath? |
|
31 isCygwin="`uname -s | grep CYGWIN`" |
|
32 if [ "${isCygwin}" != "" ] ; then |
|
33 cygpath="/usr/bin/cygpath" |
|
34 cygpath_short="${cygpath} -m -s" |
|
35 cygpath_windows="${cygpath} -w -s" |
|
36 cygpath_path="${cygpath} -p" |
|
37 pathsep=':' |
|
38 else |
|
39 cygpath="dosname" |
|
40 cygpath_short="${cygpath} -s" |
|
41 cygpath_windows="${cygpath} -s" |
|
42 cygpath_path="echo" |
|
43 pathsep=';' |
|
44 fi |
|
45 |
|
46 ######################################################################## |
30 ######################################################################## |
47 # Error functions |
31 # Error functions |
48 msg() # message |
32 msg() # message |
49 { |
33 { |
50 echo "$1" 1>&2 |
34 echo "$1" 1>&2 |
58 { |
42 { |
59 msg "WARNING: $1" |
43 msg "WARNING: $1" |
60 } |
44 } |
61 envpath() # path |
45 envpath() # path |
62 { |
46 { |
63 if [ "${cygpath_short}" != "" -a -d "$1" ] ; then |
47 if [ "${fixpath}" != "" -a -d "$1" ] ; then |
64 ${cygpath_short} "$1" |
48 ${fixpath} "$1" |
65 else |
49 else |
66 echo "$1" |
50 echo "$1" |
67 fi |
51 fi |
68 } |
52 } |
69 ######################################################################## |
53 ######################################################################## |
70 |
54 |
71 |
55 |
72 # Defaults settings |
56 # Defaults settings |
73 debug="false" |
57 debug="false" |
74 verbose="false" |
58 verbose="false" |
|
59 |
|
60 set -e |
|
61 |
|
62 CYGWIN="nodosfilewarning ntsec" |
|
63 export CYGWIN |
|
64 |
|
65 # pathsepIn is always ; because the input strings are coming from |
|
66 # vcvarsxx.bat. This is true under all of MKS, Cygwin, MINGW/msys |
|
67 pathsepIn=';' |
|
68 |
|
69 OS="`uname -s`" |
|
70 case "${OS}" in |
|
71 CYGWIN*) |
|
72 pathflag='-c' |
|
73 devnull=/dev/null |
|
74 pathsepOut=':' |
|
75 ;; |
|
76 |
|
77 MINGW*) |
|
78 pathflag='-m' |
|
79 devnull=/dev/null |
|
80 pathsepOut=':' |
|
81 ;; |
|
82 |
|
83 *) |
|
84 # MKS? |
|
85 # Continue using dosname -s |
|
86 pathflag='-s' |
|
87 fixpath="dosname ${pathflag}" |
|
88 fixpath_windows="${fixpath}" |
|
89 fixpath_path="echo" |
|
90 devnull=NUL |
|
91 pathsepOut=';' |
|
92 ;; |
|
93 esac |
|
94 |
|
95 case "${OS}" in |
|
96 CYGWIN*|MINGW*) |
|
97 t=`dirname ${0}` |
|
98 wd=`cd ${t} 2> ${devnull} && pwd` |
|
99 fixpath_script="${wd}/fixpath.pl" |
|
100 if [ ! -f "${fixpath_script}" ] ; then |
|
101 error "Does not exist: ${fixpath_script}" |
|
102 fi |
|
103 fixpath="perl ${fixpath_script} ${pathflag}" |
|
104 fixpath_windows="perl ${fixpath_script} -d" |
|
105 fixpath_path="${fixpath_windows}" |
|
106 ;; |
|
107 esac |
|
108 |
75 shellStyle="sh" |
109 shellStyle="sh" |
76 parentCsh="` ps -p ${PPID} 2> /dev/null | grep csh `" |
110 ## As far as I can tell from hg history, this has not worked |
77 if [ "${parentCsh}" != "" ] ; then |
111 ## for a long time because PPID is unset. When run under Cygwin |
78 shellStyle="csh" |
112 ## the script quits due to the 1 return from grep. |
79 fi |
113 ##parentCsh="` ps -p ${PPID} 2> ${devnull} | grep csh `" |
80 |
114 ##if [ "${parentCsh}" != "" ] ; then |
81 set -e |
115 ## shellStyle="csh" |
|
116 ##fi |
82 |
117 |
83 # Check environment first |
118 # Check environment first |
84 if [ "${PROGRAMFILES}" != "" ] ; then |
119 if [ "${PROGRAMFILES}" != "" ] ; then |
85 progfiles=`envpath "${PROGRAMFILES}"` |
120 progfiles=`envpath "${PROGRAMFILES}"` |
86 elif [ "${ProgramFiles}" != "" ] ; then |
121 elif [ "${ProgramFiles}" != "" ] ; then |
94 fi |
129 fi |
95 |
130 |
96 # Arch data model |
131 # Arch data model |
97 if [ "${PROCESSOR_IDENTIFIER}" != "" ] ; then |
132 if [ "${PROCESSOR_IDENTIFIER}" != "" ] ; then |
98 arch=`echo "${PROCESSOR_IDENTIFIER}" | cut -d' ' -f1` |
133 arch=`echo "${PROCESSOR_IDENTIFIER}" | cut -d' ' -f1` |
99 elif [ "${MACHTYPE}" != "" ] ; then |
134 else |
100 if [ "`echo ${MACHTYPE} | grep 64`" != "" ] ; then |
135 if [ "${MACHTYPE}" != "" ] ; then |
101 # Assume this is X64, not IA64 |
136 if [ "`echo ${MACHTYPE} | grep 64`" != "" ] ; then |
102 arch="x64" |
137 # Assume this is X64, not IA64 |
|
138 arch="x64" |
|
139 else |
|
140 arch="x86" |
|
141 fi |
103 else |
142 else |
104 arch="x86" |
143 arch="`uname -m`" |
105 fi |
144 fi |
106 else |
145 PROCESSOR_IDENTIFIER="${arch}" |
107 arch="`uname -m`" |
146 export PROCESSOR_IDENTIFIER |
108 fi |
147 fi |
109 if [ "${arch}" = "X86" -o \ |
148 if [ "${arch}" = "X86" -o \ |
110 "${arch}" = "386" -o "${arch}" = "i386" -o \ |
149 "${arch}" = "386" -o "${arch}" = "i386" -o \ |
111 "${arch}" = "486" -o "${arch}" = "i486" -o \ |
150 "${arch}" = "486" -o "${arch}" = "i486" -o \ |
112 "${arch}" = "586" -o "${arch}" = "i586" -o \ |
151 "${arch}" = "586" -o "${arch}" = "i586" -o \ |
119 "${arch}" = "amd64" -o "${arch}" = "AMD64" -o \ |
158 "${arch}" = "amd64" -o "${arch}" = "AMD64" -o \ |
120 "${arch}" = "EM64T" -o "${arch}" = "emt64t" -o \ |
159 "${arch}" = "EM64T" -o "${arch}" = "emt64t" -o \ |
121 "${arch}" = "intel64" -o "${arch}" = "Intel64" -o \ |
160 "${arch}" = "intel64" -o "${arch}" = "Intel64" -o \ |
122 "${arch}" = "64" ] ; then |
161 "${arch}" = "64" ] ; then |
123 arch="x64" |
162 arch="x64" |
124 binarch64="/amd64" |
163 binarch64="\\amd64" |
125 fi |
164 fi |
126 if [ "${arch}" = "IA64" ] ; then |
165 if [ "${arch}" = "IA64" ] ; then |
127 arch="ia64" |
166 arch="ia64" |
128 binarch64="/ia64" |
167 binarch64="\\ia64" |
129 fi |
168 fi |
130 if [ "${arch}" != "x86" -a "${arch}" != "x64" -a "${arch}" != "ia64" ] ; then |
169 if [ "${arch}" != "x86" -a "${arch}" != "x64" -a "${arch}" != "ia64" ] ; then |
131 error "No PROCESSOR_IDENTIFIER or MACHTYPE environment variables and uname -m is not helping" |
170 error "No PROCESSOR_IDENTIFIER or MACHTYPE environment variables and uname -m is not helping" |
132 fi |
171 fi |
133 if [ "${arch}" = "x86" ] ; then |
172 if [ "${arch}" = "x86" ] ; then |
322 fi |
361 fi |
323 done |
362 done |
324 } |
363 } |
325 |
364 |
326 # Remove all duplicate entries |
365 # Remove all duplicate entries |
327 removeDeadDups() # string sep |
366 removeDeadDups() # string sepIn sepOut |
328 { |
367 { |
329 set -e |
368 set -e |
330 sep="$2" |
369 sepIn="$2" |
|
370 sepOut="$3" |
331 pathlist="${tmp}/pathlist" |
371 pathlist="${tmp}/pathlist" |
332 printf "%s\n" "$1" | \ |
372 printf "%s\n" "$1" | \ |
333 sed -e 's@\\@/@g' | \ |
373 sed -e 's@\\@/@g' | \ |
334 sed -e 's@//@/@g' | \ |
374 sed -e 's@//@/@g' | \ |
335 ${awk} -F"${sep}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \ |
375 ${awk} -F"${sepIn}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \ |
336 > ${pathlist} |
376 > ${pathlist} |
337 upaths="${tmp}/upaths" |
377 upaths="${tmp}/upaths" |
338 cat ${pathlist} | while read orig; do |
378 cat ${pathlist} | while read orig; do |
339 p="${orig}" |
379 p="${orig}" |
340 if [ "${cygpath_short}" != "" ] ; then |
380 if [ "${fixpath}" != "" ] ; then |
341 if [ "${p}" != "" ] ; then |
381 if [ "${p}" != "" ] ; then |
342 if [ -d "${p}" ] ; then |
382 if [ -d "${p}" ] ; then |
343 short=`${cygpath_short} "${p}"` |
383 short=`${fixpath} "${p}"` |
344 if [ "${short}" != "" -a -d "${short}" ] ; then |
384 if [ "${short}" != "" -a -d "${short}" ] ; then |
345 p=`${cygpath} "${short}"` |
385 p="${short}" |
346 fi |
386 fi |
347 echo "${p}" >> ${upaths} |
387 echo "${p}" >> ${upaths} |
348 fi |
388 fi |
349 fi |
389 fi |
350 fi |
390 fi |
354 # For some reason, \r characters can get into this |
394 # For some reason, \r characters can get into this |
355 i=`echo "${i}" | tr -d '\r' | sed -e 's@/$@@'` |
395 i=`echo "${i}" | tr -d '\r' | sed -e 's@/$@@'` |
356 if [ "${newpaths}" = "" ] ; then |
396 if [ "${newpaths}" = "" ] ; then |
357 newpaths="${i}" |
397 newpaths="${i}" |
358 else |
398 else |
359 newpaths="${newpaths}${sep}${i}" |
399 newpaths="${newpaths}${sepOut}${i}" |
360 fi |
400 fi |
361 done |
401 done |
362 printf "%s\n" "${newpaths}" | \ |
402 printf "%s\n" "${newpaths}" | \ |
363 ${awk} -F"${sep}" \ |
403 ${awk} -F"${sepOut}" \ |
364 '{a[$1];printf "%s",$1;for(i=2;i<=NF;i++){if(!($i in a)){a[$i];printf "%s%s",FS,$i;}};printf "\n";}' |
404 '{a[$1];printf "%s",$1;for(i=2;i<=NF;i++){if(!($i in a)){a[$i];printf "%s%s",FS,$i;}};printf "\n";}' |
365 } |
405 } |
366 |
406 |
367 # Create bat file to process Visual Studio vcvars*.bat files |
407 # Create bat file to process Visual Studio vcvars*.bat files |
368 createBat() # batfile bindir command |
408 createBat() # batfile bindir command |
386 set DevEnvDir= |
426 set DevEnvDir= |
387 set VCINSTALLDIR= |
427 set VCINSTALLDIR= |
388 set VSINSTALLDIR= |
428 set VSINSTALLDIR= |
389 set WindowsSdkDir= |
429 set WindowsSdkDir= |
390 REM Run the vcvars bat file, send all output to stderr |
430 REM Run the vcvars bat file, send all output to stderr |
391 call `${cygpath_windows} ${bdir}`\\${command} > `${cygpath_windows} "${stdout}"` |
431 call `${fixpath_windows} ${bdir}`\\${command} > `${fixpath_windows} "${stdout}"` |
392 REM Echo out env var settings |
432 REM Echo out env var settings |
393 echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%" |
433 echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%" |
394 echo export VS_VS71COMNTOOLS |
434 echo export VS_VS71COMNTOOLS |
395 echo VS_VS80COMNTOOLS="%VS80COMNTOOLS%" |
435 echo VS_VS80COMNTOOLS="%VS80COMNTOOLS%" |
396 echo export VS_VS80COMNTOOLS |
436 echo export VS_VS80COMNTOOLS |
425 } |
465 } |
426 |
466 |
427 # Create env file |
467 # Create env file |
428 createEnv() # batfile envfile |
468 createEnv() # batfile envfile |
429 { |
469 { |
430 rm -f ${1}.stdout |
470 rm -f ${1}.stdout ${1}.temp1 ${1}.temp2 |
431 cmd.exe /Q /C `${cygpath_short} $1` | \ |
471 batfile=`${fixpath} ${1}` |
432 sed -e 's@\\@/@g' | \ |
472 cmd.exe -Q -C < "$batfile" 1> ${1}.temp1 2> ${1}.temp2 |
|
473 cat ${1}.temp1 | \ |
|
474 sed -e 's@^Microsoft.*@@' \ |
|
475 -e 's@^.*Copyright.*@@' \ |
|
476 -e 's@^.*>REM.*@@' \ |
|
477 -e 's@^.*>set.*@@' \ |
|
478 -e 's@^.*>echo.*@@' \ |
|
479 -e 's@^.*>call.*@@' \ |
|
480 -e 's@^.*>$@@' \ |
|
481 -e 's@\\@/@g' | \ |
433 sed -e 's@//@/@g' > $2 |
482 sed -e 's@//@/@g' > $2 |
434 if [ -f "${1}.stdout" ] ; then |
483 if [ -f "${1}.stdout" ] ; then |
435 cat ${1}.stdout 1>&2 |
484 cat ${1}.stdout 1>&2 |
436 fi |
485 fi |
437 chmod a+x $2 |
486 chmod a+x $2 |
463 } |
512 } |
464 |
513 |
465 ############################################################################# |
514 ############################################################################# |
466 |
515 |
467 # Get Visual Studio settings |
516 # Get Visual Studio settings |
468 if [ "${cygpath}" != "" ] ; then |
517 if [ "${fixpath}" != "" ] ; then |
469 |
518 |
470 # Create bat file to run |
519 # Create bat file to run |
471 batfile="${tmp}/vs-to-env.bat" |
520 batfile="${tmp}/vs-to-env.bat" |
472 if [ ! -d "${vcBinDir}" ] ; then |
521 if [ ! -d "${vcBinDir}" ] ; then |
473 error "Does not exist: ${vcBinDir}" |
522 error "Does not exist: ${vcBinDir}" |
483 |
532 |
484 # Read in the VS_* settings |
533 # Read in the VS_* settings |
485 . ${envfile} |
534 . ${envfile} |
486 |
535 |
487 # Derive unix style path, save old, and define new (remove dups) |
536 # Derive unix style path, save old, and define new (remove dups) |
488 VS_UPATH=`${cygpath_path} "${VS_WPATH}"` |
537 VS_UPATH=`${fixpath_path} "${VS_WPATH}"` |
489 export VS_UPATH |
538 export VS_UPATH |
490 VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'` |
539 VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'` |
491 export VS_OPATH |
540 export VS_OPATH |
492 VS_PATH=`removeDeadDups "${VS_UPATH}${pathsep}${VS_OPATH}" "${pathsep}"` |
541 VS_PATH=`removeDeadDups "${VS_UPATH}${pathsepIn}${VS_OPATH}" "${pathsepIn}" "${pathsepOut}"` |
493 export VS_PATH |
542 export VS_PATH |
494 |
543 |
495 fi |
544 fi |
496 |
545 |
497 # Adjustments due to differences in vcvars*bat files |
546 # Adjustments due to differences in vcvars*bat files |
534 # Check final settings |
583 # Check final settings |
535 if [ "${verbose}" = "true" ] ; then |
584 if [ "${verbose}" = "true" ] ; then |
536 checkPaths "Windows PATH" "${VS_WPATH}" ";" |
585 checkPaths "Windows PATH" "${VS_WPATH}" ";" |
537 checkPaths LIB "${VS_LIB}" ";" |
586 checkPaths LIB "${VS_LIB}" ";" |
538 checkPaths INCLUDE "${VS_INCLUDE}" ";" |
587 checkPaths INCLUDE "${VS_INCLUDE}" ";" |
539 checkPaths PATH "${VS_PATH}" "${pathsep}" |
588 checkPaths PATH "${VS_PATH}" "${pathsepIn}" |
540 fi |
589 fi |
541 |
590 |
542 # Remove all temp files |
591 # Remove all temp files |
543 rm -f -r ${tmp} |
592 if [ "${debug}" != "true" ] ; then |
|
593 rm -f -r ${tmp} |
|
594 fi |
544 |
595 |
545 exit 0 |
596 exit 0 |
546 |
597 |