Sat, 03 Nov 2012 16:28:14 -0700
8002220: build-infra: update for mac, solaris 11 issues
8002184: Fixed exclude and includes for jarsigner in new build
Reviewed-by: ohair
1 #!/bin/sh
3 #
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.
6 #
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
9 # published by the Free Software Foundation.
10 #
11 # This code is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # version 2 for more details (a copy is included in the LICENSE file that
15 # accompanied this code).
16 #
17 # You should have received a copy of the GNU General Public License version
18 # 2 along with this work; if not, write to the Free Software Foundation,
19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 #
21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 # or visit www.oracle.com if you need additional information or have any
23 # questions.
24 #
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
28 # SetEnv.cmd for older SDKs.
30 ########################################################################
31 # Error functions
32 msg() # message
33 {
34 echo "$1" 1>&2
35 }
36 error() # message
37 {
38 msg "ERROR: $1"
39 exit 1
40 }
41 warning() # message
42 {
43 msg "WARNING: $1"
44 }
45 envpath() # path
46 {
47 if [ "${fixpath}" != "" -a -d "$1" ] ; then
48 ${fixpath} "$1"
49 else
50 echo "$1"
51 fi
52 }
53 ########################################################################
56 # Defaults settings
57 debug="false"
58 verbose="false"
60 set -e
62 CYGWIN="nodosfilewarning ntsec"
63 export CYGWIN
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=';'
69 OS="`uname -s`"
70 case "${OS}" in
71 CYGWIN*)
72 pathflag='-c'
73 devnull=/dev/null
74 pathsepOut=':'
75 ;;
77 MINGW*)
78 pathflag='-m'
79 devnull=/dev/null
80 pathsepOut=':'
81 ;;
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
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
109 shellStyle="sh"
110 ## As far as I can tell from hg history, this has not worked
111 ## for a long time because PPID is unset. When run under Cygwin
112 ## the script quits due to the 1 return from grep.
113 ##parentCsh="` ps -p ${PPID} 2> ${devnull} | grep csh `"
114 ##if [ "${parentCsh}" != "" ] ; then
115 ## shellStyle="csh"
116 ##fi
118 # Check environment first
119 if [ "${PROGRAMFILES}" != "" ] ; then
120 progfiles=`envpath "${PROGRAMFILES}"`
121 elif [ "${ProgramFiles}" != "" ] ; then
122 progfiles=`envpath "${ProgramFiles}"`
123 elif [ "${SYSTEMDRIVE}" != "" ] ; then
124 progfiles=`envpath "${SYSTEMDRIVE}/Program Files"`
125 elif [ "${SystemDrive}" != "" ] ; then
126 progfiles=`envpath "${SystemDrive}/Program Files"`
127 else
128 error "No PROGRAMFILES or SYSTEMDRIVE defined in environment"
129 fi
131 # Arch data model
132 if [ "${PROCESSOR_IDENTIFIER}" != "" ] ; then
133 arch=`echo "${PROCESSOR_IDENTIFIER}" | cut -d' ' -f1`
134 else
135 if [ "${MACHTYPE}" != "" ] ; then
136 if [ "`echo ${MACHTYPE} | grep 64`" != "" ] ; then
137 # Assume this is X64, not IA64
138 arch="x64"
139 else
140 arch="x86"
141 fi
142 else
143 arch="`uname -m`"
144 fi
145 PROCESSOR_IDENTIFIER="${arch}"
146 export PROCESSOR_IDENTIFIER
147 fi
148 if [ "${arch}" = "X86" -o \
149 "${arch}" = "386" -o "${arch}" = "i386" -o \
150 "${arch}" = "486" -o "${arch}" = "i486" -o \
151 "${arch}" = "586" -o "${arch}" = "i586" -o \
152 "${arch}" = "686" -o "${arch}" = "i686" -o \
153 "${arch}" = "86" ] ; then
154 arch="x86"
155 fi
156 if [ "${arch}" = "X64" -o \
157 "${arch}" = "8664" -o "${arch}" = "i8664" -o \
158 "${arch}" = "amd64" -o "${arch}" = "AMD64" -o \
159 "${arch}" = "EM64T" -o "${arch}" = "emt64t" -o \
160 "${arch}" = "intel64" -o "${arch}" = "Intel64" -o \
161 "${arch}" = "64" ] ; then
162 arch="x64"
163 binarch64="\\amd64"
164 fi
165 if [ "${arch}" = "IA64" ] ; then
166 arch="ia64"
167 binarch64="\\ia64"
168 fi
169 if [ "${arch}" != "x86" -a "${arch}" != "x64" -a "${arch}" != "ia64" ] ; then
170 error "No PROCESSOR_IDENTIFIER or MACHTYPE environment variables and uname -m is not helping"
171 fi
172 if [ "${arch}" = "x86" ] ; then
173 arch_data_model=32
174 progfiles32="${progfiles}"
175 progfiles64="${progfiles}"
176 else
177 arch_data_model=64
178 progfiles32="${progfiles}"
179 if [ "${PROGRAMW6432}" != "" ] ; then
180 progfiles64=`envpath "${PROGRAMW6432}"`
181 else
182 progfiles64=`envpath "C:/Program Files"`
183 fi
184 fi
186 # VS2010 (VC10)
187 if [ "${VS100COMNTOOLS}" = "" ] ; then
188 VS100COMNTOOLS="${progfiles32}/Microsoft Visual Studio 10.0/Common7/Tools/"
189 export VS100COMNTOOLS
190 fi
191 vc10Bin32Dir=`envpath "${VS100COMNTOOLS}"`/../../VC/Bin
192 vc10Bin64Dir="${vc10Bin32Dir}${binarch64}"
193 vc10vars32Bat="vcvars32.bat"
194 vc10vars64Bat="vcvars64.bat"
196 # VS2008 (VC9)
197 if [ "${VS90COMNTOOLS}" = "" ] ; then
198 VS90COMNTOOLS="${progfiles32}/Microsoft Visual Studio 9.0/Common7/Tools/"
199 export VS90COMNTOOLS
200 fi
201 vc9Bin32Dir=`envpath "${VS90COMNTOOLS}"`/../../VC/Bin
202 vc9Bin64Dir="${vc9Bin32Dir}"
203 vc9vars32Bat="vcvars32.bat"
204 vc9vars64Bat="vcvars64.bat"
206 # VS2005 (VC8)
207 if [ "${VS80COMNTOOLS}" = "" ] ; then
208 VS80COMNTOOLS="${progfiles32}/Microsoft Visual Studio 8.0/Common7/Tools/"
209 export VS80COMNTOOLS
210 fi
211 vc8Bin32Dir=`envpath "${VS80COMNTOOLS}"`/../../VC/Bin
212 vc8Bin64Dir="${progfiles64}/Microsoft Platform SDK"
213 vc8vars32Bat="vcvars32.bat"
214 vc8vars64Bat="SetEnv.cmd /X64"
216 # VS2003 (VC7)
217 if [ "${VS71COMNTOOLS}" = "" ] ; then
218 VS71COMNTOOLS="${progfiles32}/Microsoft Visual Studio .NET 2003/Common7/Tools/"
219 export VS71COMNTOOLS
220 fi
221 vc7Bin32Dir=`envpath "${VS71COMNTOOLS}"`/../../VC7/Bin
222 vc7Bin64Dir="${progfiles64}/Microsoft Platform SDK"
223 vc7vars32Bat="vcvars32.bat"
224 vc7vars64Bat="SetEnv.cmd /X64"
226 # Force user to select
227 vcSelection=""
229 # Parse options
230 usage="Usage: $0 [-help] [-debug] [-v] [-c] [-s] [-p] [-v10] [-v9] [-v8] [-v7] [-32] [-64]"
231 while [ $# -gt 0 ] ; do
232 if [ "$1" = "-help" ] ; then
233 msg "${usage}"
234 msg " -help Print out this help message"
235 msg " -debug Print out extra env variables to help debug this script"
236 msg " -v Verbose output warns about missing directories"
237 msg " -c Print out csh style output"
238 msg " -s Print out sh style output"
239 msg " -p Print out properties style output"
240 msg " -v10 Use Visual Studio 10 VS2010"
241 msg " -v9 Use Visual Studio 9 VS2008"
242 msg " -v8 Use Visual Studio 8 VS2005"
243 msg " -v7 Use Visual Studio 7 VS2003"
244 msg " -32 Force 32bit"
245 msg " -64 Force 64bit"
246 exit 0
247 elif [ "$1" = "-debug" ] ; then
248 debug="true"
249 shift
250 elif [ "$1" = "-v" ] ; then
251 verbose="true"
252 shift
253 elif [ "$1" = "-c" ] ; then
254 shellStyle="csh"
255 shift
256 elif [ "$1" = "-s" ] ; then
257 shellStyle="sh"
258 shift
259 elif [ "$1" = "-p" ] ; then
260 shellStyle="props"
261 shift
262 elif [ "$1" = "-v10" ] ; then
263 vcBin32Dir="${vc10Bin32Dir}"
264 vcBin64Dir="${vc10Bin64Dir}"
265 vcvars32Bat="${vc10vars32Bat}"
266 vcvars64Bat="${vc10vars64Bat}"
267 vcSelection="10"
268 shift
269 elif [ "$1" = "-v9" ] ; then
270 vcBin32Dir="${vc9Bin32Dir}"
271 vcBin64Dir="${vc9Bin64Dir}"
272 vcvars32Bat="${vc9vars32Bat}"
273 vcvars64Bat="${vc9vars64Bat}"
274 vcSelection="9"
275 shift
276 elif [ "$1" = "-v8" ] ; then
277 vcBin32Dir="${vc8Bin32Dir}"
278 vcBin64Dir="${vc8Bin64Dir}"
279 vcvars32Bat="${vc8vars32Bat}"
280 vcvars64Bat="${vc8vars64Bat}"
281 vcSelection="8"
282 shift
283 elif [ "$1" = "-v7" ] ; then
284 vcBin32Dir="${vc7Bin32Dir}"
285 vcBin64Dir="${vc7Bin64Dir}"
286 vcvars32Bat="${vc7vars32Bat}"
287 vcvars64Bat="${vc7vars64Bat}"
288 vcSelection="7"
289 shift
290 elif [ "$1" = "-32" ] ; then
291 arch_data_model=32
292 shift
293 elif [ "$1" = "-64" ] ; then
294 arch_data_model=64
295 shift
296 else
297 msg "${usage}"
298 error "Unknown option: $1"
299 fi
300 done
302 # Need to pick
303 if [ "${vcSelection}" = "" ] ; then
304 msg "${usage}"
305 error "You must pick the version"
306 fi
308 # Which vcvars bat file to run
309 if [ "${arch_data_model}" = "32" ] ; then
310 vcBinDir="${vcBin32Dir}"
311 vcvarsBat="${vcvars32Bat}"
312 fi
313 if [ "${arch_data_model}" = "64" ] ; then
314 vcBinDir="${vcBin64Dir}"
315 vcvarsBat="${vcvars64Bat}"
316 fi
318 # Do not allow any error returns
319 set -e
321 # Different systems have different awk's
322 if [ -f /usr/bin/nawk ] ; then
323 awk="nawk"
324 elif [ -f /usr/bin/gawk ] ; then
325 awk="gawk"
326 else
327 awk="awk"
328 fi
330 if [ "${verbose}" = "true" ] ; then
331 echo "# Welcome to verbose mode"
332 set -x
333 fi
335 if [ "${debug}" = "true" ] ; then
336 echo "# Welcome to debug mode"
337 set -x
338 fi
340 # Temp file area
341 tmp="/tmp/vsvars.$$"
342 rm -f -r ${tmp}
343 mkdir -p ${tmp}
345 # Check paths
346 checkPaths() # var path sep
347 {
348 set -e
349 sep="$3"
350 checklist="${tmp}/checklist"
351 printf "%s\n" "$2" | \
352 sed -e 's@\\@/@g' | \
353 sed -e 's@//@/@g' | \
354 ${awk} -F"${sep}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \
355 > ${checklist}
356 cat ${checklist} | while read orig; do
357 if [ "${orig}" != "" ] ; then
358 if [ ! -d "${orig}" ] ; then
359 warning "Directory in $1 does not exist: ${orig}"
360 fi
361 fi
362 done
363 }
365 # Remove all duplicate entries
366 removeDeadDups() # string sepIn sepOut
367 {
368 set -e
369 sepIn="$2"
370 sepOut="$3"
371 pathlist="${tmp}/pathlist"
372 printf "%s\n" "$1" | \
373 sed -e 's@\\@/@g' | \
374 sed -e 's@//@/@g' | \
375 ${awk} -F"${sepIn}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \
376 > ${pathlist}
377 upaths="${tmp}/upaths"
378 cat ${pathlist} | while read orig; do
379 p="${orig}"
380 if [ "${fixpath}" != "" ] ; then
381 if [ "${p}" != "" ] ; then
382 if [ -d "${p}" ] ; then
383 short=`${fixpath} "${p}"`
384 if [ "${short}" != "" -a -d "${short}" ] ; then
385 p="${short}"
386 fi
387 echo "${p}" >> ${upaths}
388 fi
389 fi
390 fi
391 done
392 newpaths=""
393 for i in `cat ${upaths}` ; do
394 # For some reason, \r characters can get into this
395 i=`echo "${i}" | tr -d '\r' | sed -e 's@/$@@'`
396 if [ "${newpaths}" = "" ] ; then
397 newpaths="${i}"
398 else
399 newpaths="${newpaths}${sepOut}${i}"
400 fi
401 done
402 printf "%s\n" "${newpaths}" | \
403 ${awk} -F"${sepOut}" \
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";}'
405 }
407 # Create bat file to process Visual Studio vcvars*.bat files
408 createBat() # batfile bindir command
409 {
410 bat="$1"
411 bindir="$2"
412 command="$3"
413 stdout="${bat}.stdout"
414 rm -f ${bat} ${stdout}
415 echo "Output from: ${command}" > ${stdout}
416 bdir=`envpath "${bindir}"`
417 cat > ${bat} << EOF
418 REM Pick the right vcvars bat file
419 REM Empty these out so we only get the additions we want
420 set INCLUDE=
421 set LIB=
422 set LIBPATH=
423 set MSVCDIR=
424 set MSSdk=
425 set Mstools=
426 set DevEnvDir=
427 set VCINSTALLDIR=
428 set VSINSTALLDIR=
429 set WindowsSdkDir=
430 REM Run the vcvars bat file, send all output to stderr
431 call `${fixpath_windows} ${bdir}`\\${command} > `${fixpath_windows} "${stdout}"`
432 REM Echo out env var settings
433 echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%"
434 echo export VS_VS71COMNTOOLS
435 echo VS_VS80COMNTOOLS="%VS80COMNTOOLS%"
436 echo export VS_VS80COMNTOOLS
437 echo VS_VS90COMNTOOLS="%VS90COMNTOOLS%"
438 echo export VS_VS90COMNTOOLS
439 echo VS_VS100COMNTOOLS="%VS100COMNTOOLS%"
440 echo export VS_VS100COMNTOOLS
441 echo VS_VCINSTALLDIR="%VCINSTALLDIR%"
442 echo export VS_VCINSTALLDIR
443 echo VS_VSINSTALLDIR="%VSINSTALLDIR%"
444 echo export VS_VSINSTALLDIR
445 echo VS_DEVENVDIR="%DevEnvDir%"
446 echo export VS_DEVENVDIR
447 echo VS_MSVCDIR="%MSVCDIR%"
448 echo export VS_MSVCDIR
449 echo VS_MSSDK="%MSSdk%"
450 echo export VS_MSSDK
451 echo VS_MSTOOLS="%Mstools%"
452 echo export VS_MSTOOLS
453 echo VS_WINDOWSSDKDIR="%WindowsSdkDir%"
454 echo export VS_WINDOWSSDKDIR
455 echo VS_INCLUDE="%INCLUDE%"
456 echo export VS_INCLUDE
457 echo VS_LIB="%LIB%"
458 echo export VS_LIB
459 echo VS_LIBPATH="%LIBPATH%"
460 echo export VS_LIBPATH
461 echo VS_WPATH="%PATH%"
462 echo export VS_WPATH
463 EOF
464 chmod a+x ${bat}
465 }
467 # Create env file
468 createEnv() # batfile envfile
469 {
470 rm -f ${1}.stdout ${1}.temp1 ${1}.temp2
471 batfile=`${fixpath} ${1}`
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' | \
482 sed -e 's@//@/@g' > $2
483 if [ -f "${1}.stdout" ] ; then
484 cat ${1}.stdout 1>&2
485 fi
486 chmod a+x $2
487 }
489 printEnv() # name pname vsname val
490 {
491 name="$1"
492 pname="$2"
493 vsname="$3"
494 val="$4"
495 if [ "${val}" != "" ] ; then
496 if [ "${shellStyle}" = "csh" ] ; then
497 if [ "${debug}" = "true" ] ; then
498 echo "setenv ${vsname} \"${val}\";"
499 fi
500 echo "setenv ${name} \"${val}\";"
501 elif [ "${shellStyle}" = "sh" ] ; then
502 if [ "${debug}" = "true" ] ; then
503 echo "${vsname}=\"${val}\";"
504 echo "export ${vsname};"
505 fi
506 echo "${name}=\"${val}\";"
507 echo "export ${name};"
508 elif [ "${shellStyle}" = "props" ] ; then
509 echo "vs.${pname}=${val}"
510 fi
511 fi
512 }
514 #############################################################################
516 # Get Visual Studio settings
517 if [ "${fixpath}" != "" ] ; then
519 # Create bat file to run
520 batfile="${tmp}/vs-to-env.bat"
521 if [ ! -d "${vcBinDir}" ] ; then
522 error "Does not exist: ${vcBinDir}"
523 elif [ "${vcvarsBat}" = "" ] ; then
524 error "No vcvars script: ${vcvarsBat}"
525 else
526 createBat "${batfile}" "${vcBinDir}" "${vcvarsBat}"
527 fi
529 # Run bat file to create environment variable settings
530 envfile="${tmp}/env.sh"
531 createEnv "${batfile}" "${envfile}"
533 # Read in the VS_* settings
534 . ${envfile}
536 # Derive unix style path, save old, and define new (remove dups)
537 VS_UPATH=`${fixpath_path} "${VS_WPATH}"`
538 export VS_UPATH
539 VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'`
540 export VS_OPATH
541 VS_PATH=`removeDeadDups "${VS_UPATH}${pathsepIn}${VS_OPATH}" "${pathsepIn}" "${pathsepOut}"`
542 export VS_PATH
544 fi
546 # Adjustments due to differences in vcvars*bat files
547 if [ "${VS_MSVCDIR}" = "" ] ; then
548 VS_MSVCDIR="${VS_VCINSTALLDIR}"
549 fi
550 if [ "${VS_DEVENVDIR}" = "" ] ; then
551 VS_DEVENVDIR="${VS_VSINSTALLDIR}"
552 fi
554 # Print env settings
555 # env vs.prop vs env value
556 # ------- ------- ---------- -----
557 printEnv INCLUDE include VS_INCLUDE "${VS_INCLUDE}"
558 printEnv LIB lib VS_LIB "${VS_LIB}"
559 printEnv LIBPATH libpath VS_LIBPATH "${VS_LIBPATH}"
560 if [ "${debug}" = "true" ] ; then
561 printEnv UPATH upath VS_UPATH "${VS_UPATH}"
562 printEnv WPATH wpath VS_WPATH "${VS_WPATH}"
563 printEnv OPATH opath VS_OPATH "${VS_OPATH}"
564 fi
565 printEnv PATH path VS_PATH "${VS_PATH}"
566 printEnv VCINSTALLDIR vcinstalldir VS_VCINSTALLDIR "${VS_VCINSTALLDIR}"
567 printEnv VSINSTALLDIR vsinstalldir VS_VSINSTALLDIR "${VS_VSINSTALLDIR}"
568 printEnv MSVCDIR msvcdir VS_MSVCDIR "${VS_MSVCDIR}"
569 printEnv MSSDK mssdk VS_MSSDK "${VS_MSSDK}"
570 printEnv MSTOOLS mstools VS_MSTOOLS "${VS_MSTOOLS}"
571 printEnv DEVENVDIR devenvdir VS_DEVENVDIR "${VS_DEVENVDIR}"
572 printEnv WINDOWSSDKDIR windowssdkdir VS_WINDOWSSDKDIR "${VS_WINDOWSSDKDIR}"
573 if [ "${vcSelection}" = "10" ] ; then
574 printEnv VS100COMNTOOLS vs100comntools VS_VS100COMNTOOLS "${VS_VS100COMNTOOLS}"
575 elif [ "${vcSelection}" = "9" ] ; then
576 printEnv VS90COMNTOOLS vs90comntools VS_VS90COMNTOOLS "${VS_VS90COMNTOOLS}"
577 elif [ "${vcSelection}" = "7" ] ; then
578 printEnv VS71COMNTOOLS vs71comntools VS_VS71COMNTOOLS "${VS_VS71COMNTOOLS}"
579 elif [ "${vcSelection}" = "8" ] ; then
580 printEnv VS80COMNTOOLS vs80comntools VS_VS80COMNTOOLS "${VS_VS80COMNTOOLS}"
581 fi
583 # Check final settings
584 if [ "${verbose}" = "true" ] ; then
585 checkPaths "Windows PATH" "${VS_WPATH}" ";"
586 checkPaths LIB "${VS_LIB}" ";"
587 checkPaths INCLUDE "${VS_INCLUDE}" ";"
588 checkPaths PATH "${VS_PATH}" "${pathsepIn}"
589 fi
591 # Remove all temp files
592 if [ "${debug}" != "true" ] ; then
593 rm -f -r ${tmp}
594 fi
596 exit 0