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 |
340 fi |
379 fi |
341 done |
380 done |
342 } |
381 } |
343 |
382 |
344 # Remove all duplicate entries |
383 # Remove all duplicate entries |
345 removeDeadDups() # string sep |
384 removeDeadDups() # string sepIn sepOut |
346 { |
385 { |
347 set -e |
386 set -e |
348 sep="$2" |
387 sepIn="$2" |
|
388 sepOut="$3" |
349 pathlist="${tmp}/pathlist" |
389 pathlist="${tmp}/pathlist" |
350 printf "%s\n" "$1" | \ |
390 printf "%s\n" "$1" | \ |
351 sed -e 's@\\@/@g' | \ |
391 sed -e 's@\\@/@g' | \ |
352 sed -e 's@//@/@g' | \ |
392 sed -e 's@//@/@g' | \ |
353 ${awk} -F"${sep}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \ |
393 ${awk} -F"${sepIn}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \ |
354 > ${pathlist} |
394 > ${pathlist} |
355 upaths="${tmp}/upaths" |
395 upaths="${tmp}/upaths" |
356 cat ${pathlist} | while read orig; do |
396 cat ${pathlist} | while read orig; do |
357 p="${orig}" |
397 p="${orig}" |
358 if [ "${cygpath_short}" != "" ] ; then |
398 if [ "${fixpath}" != "" ] ; then |
359 if [ "${p}" != "" ] ; then |
399 if [ "${p}" != "" ] ; then |
360 if [ -d "${p}" ] ; then |
400 if [ -d "${p}" ] ; then |
361 short=`${cygpath_short} "${p}"` |
401 short=`${fixpath} "${p}"` |
362 if [ "${short}" != "" -a -d "${short}" ] ; then |
402 if [ "${short}" != "" -a -d "${short}" ] ; then |
363 p=`${cygpath} "${short}"` |
403 p="${short}" |
364 fi |
404 fi |
365 echo "${p}" >> ${upaths} |
405 echo "${p}" >> ${upaths} |
366 fi |
406 fi |
367 fi |
407 fi |
368 fi |
408 fi |
372 # For some reason, \r characters can get into this |
412 # For some reason, \r characters can get into this |
373 i=`echo "${i}" | tr -d '\r' | sed -e 's@/$@@'` |
413 i=`echo "${i}" | tr -d '\r' | sed -e 's@/$@@'` |
374 if [ "${newpaths}" = "" ] ; then |
414 if [ "${newpaths}" = "" ] ; then |
375 newpaths="${i}" |
415 newpaths="${i}" |
376 else |
416 else |
377 newpaths="${newpaths}${sep}${i}" |
417 newpaths="${newpaths}${sepOut}${i}" |
378 fi |
418 fi |
379 done |
419 done |
380 printf "%s\n" "${newpaths}" | \ |
420 printf "%s\n" "${newpaths}" | \ |
381 ${awk} -F"${sep}" \ |
421 ${awk} -F"${sepOut}" \ |
382 '{a[$1];printf "%s",$1;for(i=2;i<=NF;i++){if(!($i in a)){a[$i];printf "%s%s",FS,$i;}};printf "\n";}' |
422 '{a[$1];printf "%s",$1;for(i=2;i<=NF;i++){if(!($i in a)){a[$i];printf "%s%s",FS,$i;}};printf "\n";}' |
383 } |
423 } |
384 |
424 |
385 # Create bat file to process Visual Studio vcvars*.bat files |
425 # Create bat file to process Visual Studio vcvars*.bat files |
386 createBat() # batfile bindir command |
426 createBat() # batfile bindir command |
404 set DevEnvDir= |
444 set DevEnvDir= |
405 set VCINSTALLDIR= |
445 set VCINSTALLDIR= |
406 set VSINSTALLDIR= |
446 set VSINSTALLDIR= |
407 set WindowsSdkDir= |
447 set WindowsSdkDir= |
408 REM Run the vcvars bat file, send all output to stderr |
448 REM Run the vcvars bat file, send all output to stderr |
409 call `${cygpath_windows} ${bdir}`\\${command} > `${cygpath_windows} "${stdout}"` |
449 call `${fixpath_windows} ${bdir}`\\${command} > `${fixpath_windows} "${stdout}"` |
410 REM Echo out env var settings |
450 REM Echo out env var settings |
411 echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%" |
451 echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%" |
412 echo export VS_VS71COMNTOOLS |
452 echo export VS_VS71COMNTOOLS |
413 echo VS_VS80COMNTOOLS="%VS80COMNTOOLS%" |
453 echo VS_VS80COMNTOOLS="%VS80COMNTOOLS%" |
414 echo export VS_VS80COMNTOOLS |
454 echo export VS_VS80COMNTOOLS |
445 } |
485 } |
446 |
486 |
447 # Create env file |
487 # Create env file |
448 createEnv() # batfile envfile |
488 createEnv() # batfile envfile |
449 { |
489 { |
450 rm -f ${1}.stdout |
490 rm -f ${1}.stdout ${1}.temp1 ${1}.temp2 |
451 cmd.exe /Q /C `${cygpath_short} $1` | \ |
491 batfile=`${fixpath} ${1}` |
452 sed -e 's@\\@/@g' | \ |
492 cmd.exe -Q -C < "$batfile" 1> ${1}.temp1 2> ${1}.temp2 |
|
493 cat ${1}.temp1 | \ |
|
494 sed -e 's@^Microsoft.*@@' \ |
|
495 -e 's@^.*Copyright.*@@' \ |
|
496 -e 's@^.*>REM.*@@' \ |
|
497 -e 's@^.*>set.*@@' \ |
|
498 -e 's@^.*>echo.*@@' \ |
|
499 -e 's@^.*>call.*@@' \ |
|
500 -e 's@^.*>$@@' \ |
|
501 -e 's@\\@/@g' | \ |
453 sed -e 's@//@/@g' > $2 |
502 sed -e 's@//@/@g' > $2 |
454 if [ -f "${1}.stdout" ] ; then |
503 if [ -f "${1}.stdout" ] ; then |
455 cat ${1}.stdout 1>&2 |
504 cat ${1}.stdout 1>&2 |
456 fi |
505 fi |
457 chmod a+x $2 |
506 chmod a+x $2 |
483 } |
532 } |
484 |
533 |
485 ############################################################################# |
534 ############################################################################# |
486 |
535 |
487 # Get Visual Studio settings |
536 # Get Visual Studio settings |
488 if [ "${cygpath}" != "" ] ; then |
537 if [ "${fixpath}" != "" ] ; then |
489 |
538 |
490 # Create bat file to run |
539 # Create bat file to run |
491 batfile="${tmp}/vs-to-env.bat" |
540 batfile="${tmp}/vs-to-env.bat" |
492 if [ ! -d "${vcBinDir}" ] ; then |
541 if [ ! -d "${vcBinDir}" ] ; then |
493 error "Does not exist: ${vcBinDir}" |
542 error "Does not exist: ${vcBinDir}" |
503 |
552 |
504 # Read in the VS_* settings |
553 # Read in the VS_* settings |
505 . ${envfile} |
554 . ${envfile} |
506 |
555 |
507 # Derive unix style path, save old, and define new (remove dups) |
556 # Derive unix style path, save old, and define new (remove dups) |
508 VS_UPATH=`${cygpath_path} "${VS_WPATH}"` |
557 VS_UPATH=`${fixpath_path} "${VS_WPATH}"` |
509 export VS_UPATH |
558 export VS_UPATH |
510 VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'` |
559 VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'` |
511 export VS_OPATH |
560 export VS_OPATH |
512 VS_PATH=`removeDeadDups "${VS_UPATH}${pathsep}${VS_OPATH}" "${pathsep}"` |
561 VS_PATH=`removeDeadDups "${VS_UPATH}${pathsepIn}${VS_OPATH}" "${pathsepIn}" "${pathsepOut}"` |
513 export VS_PATH |
562 export VS_PATH |
514 |
563 |
515 fi |
564 fi |
516 |
565 |
517 # Adjustments due to differences in vcvars*bat files |
566 # Adjustments due to differences in vcvars*bat files |
556 # Check final settings |
605 # Check final settings |
557 if [ "${verbose}" = "true" ] ; then |
606 if [ "${verbose}" = "true" ] ; then |
558 checkPaths "Windows PATH" "${VS_WPATH}" ";" |
607 checkPaths "Windows PATH" "${VS_WPATH}" ";" |
559 checkPaths LIB "${VS_LIB}" ";" |
608 checkPaths LIB "${VS_LIB}" ";" |
560 checkPaths INCLUDE "${VS_INCLUDE}" ";" |
609 checkPaths INCLUDE "${VS_INCLUDE}" ";" |
561 checkPaths PATH "${VS_PATH}" "${pathsep}" |
610 checkPaths PATH "${VS_PATH}" "${pathsepIn}" |
562 fi |
611 fi |
563 |
612 |
564 # Remove all temp files |
613 # Remove all temp files |
565 rm -f -r ${tmp} |
614 if [ "${debug}" != "true" ] ; then |
|
615 rm -f -r ${tmp} |
|
616 fi |
566 |
617 |
567 exit 0 |
618 exit 0 |
568 |
619 |