source: trunk/openjdk/make/scripts/vsvars.sh@ 361

Last change on this file since 361 was 309, checked in by dmik, 14 years ago

trunk: Merged in openjdk6 b24 from branches/vendor/oracle.

  • Property svn:eol-style set to native
File size: 14.9 KB
Line 
1#!/bin/sh
2
3#
4# Copyright (c) 2009, 2011, 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#
25
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.
29
30# Use cygpath?
31isCygwin="`uname -s | grep CYGWIN`"
32if [ "${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=':'
38else
39 cygpath="dosname"
40 cygpath_short="${cygpath} -s"
41 cygpath_windows="${cygpath} -s"
42 cygpath_path="echo"
43 pathsep=';'
44fi
45
46########################################################################
47# Error functions
48msg() # message
49{
50 echo "$1" 1>&2
51}
52error() # message
53{
54 msg "ERROR: $1"
55 exit 1
56}
57warning() # message
58{
59 msg "WARNING: $1"
60}
61envpath() # path
62{
63 if [ "${cygpath_short}" != "" -a -d "$1" ] ; then
64 ${cygpath_short} "$1"
65 else
66 echo "$1"
67 fi
68}
69########################################################################
70
71
72# Defaults settings
73debug="false"
74verbose="false"
75shellStyle="sh"
76parentCsh="` ps -p ${PPID} 2> /dev/null | grep csh `"
77if [ "${parentCsh}" != "" ] ; then
78 shellStyle="csh"
79fi
80
81set -e
82
83# Check environment first
84if [ "${PROGRAMFILES}" != "" ] ; then
85 progfiles=`envpath "${PROGRAMFILES}"`
86elif [ "${ProgramFiles}" != "" ] ; then
87 progfiles=`envpath "${ProgramFiles}"`
88elif [ "${SYSTEMDRIVE}" != "" ] ; then
89 progfiles=`envpath "${SYSTEMDRIVE}/Program Files"`
90elif [ "${SystemDrive}" != "" ] ; then
91 progfiles=`envpath "${SystemDrive}/Program Files"`
92else
93 error "No PROGRAMFILES or SYSTEMDRIVE defined in environment"
94fi
95
96# Arch data model
97if [ "${PROCESSOR_IDENTIFIER}" != "" ] ; then
98 arch=`echo "${PROCESSOR_IDENTIFIER}" | cut -d' ' -f1`
99elif [ "${MACHTYPE}" != "" ] ; then
100 if [ "`echo ${MACHTYPE} | grep 64`" != "" ] ; then
101 # Assume this is X64, not IA64
102 arch="x64"
103 else
104 arch="x86"
105 fi
106else
107 arch="`uname -m`"
108fi
109if [ "${arch}" = "X86" -o \
110 "${arch}" = "386" -o "${arch}" = "i386" -o \
111 "${arch}" = "486" -o "${arch}" = "i486" -o \
112 "${arch}" = "586" -o "${arch}" = "i586" -o \
113 "${arch}" = "686" -o "${arch}" = "i686" -o \
114 "${arch}" = "86" ] ; then
115 arch="x86"
116fi
117if [ "${arch}" = "X64" -o \
118 "${arch}" = "8664" -o "${arch}" = "i8664" -o \
119 "${arch}" = "amd64" -o "${arch}" = "AMD64" -o \
120 "${arch}" = "EM64T" -o "${arch}" = "emt64t" -o \
121 "${arch}" = "intel64" -o "${arch}" = "Intel64" -o \
122 "${arch}" = "64" ] ; then
123 arch="x64"
124 binarch64="/amd64"
125fi
126if [ "${arch}" = "IA64" ] ; then
127 arch="ia64"
128 binarch64="/ia64"
129fi
130if [ "${arch}" != "x86" -a "${arch}" != "x64" -a "${arch}" != "ia64" ] ; then
131 error "No PROCESSOR_IDENTIFIER or MACHTYPE environment variables and uname -m is not helping"
132fi
133if [ "${arch}" = "x86" ] ; then
134 arch_data_model=32
135 progfiles32="${progfiles}"
136 progfiles64="${progfiles}"
137else
138 arch_data_model=64
139 progfiles32="${progfiles}"
140 if [ "${PROGRAMW6432}" != "" ] ; then
141 progfiles64=`envpath "${PROGRAMW6432}"`
142 else
143 progfiles64=`envpath "C:/Program Files"`
144 fi
145fi
146
147# VS2010 (VC10)
148if [ "${VS100COMNTOOLS}" = "" ] ; then
149 VS100COMNTOOLS="${progfiles32}/Microsoft Visual Studio 10.0/Common7/Tools/"
150 export VS100COMNTOOLS
151fi
152vc10Bin32Dir=`envpath "${VS100COMNTOOLS}"`/../../VC/Bin
153vc10Bin64Dir="${vc10Bin32Dir}${binarch64}"
154vc10vars32Bat="vcvars32.bat"
155vc10vars64Bat="vcvars64.bat"
156
157# VS2008 (VC9)
158if [ "${VS90COMNTOOLS}" = "" ] ; then
159 VS90COMNTOOLS="${progfiles32}/Microsoft Visual Studio 9.0/Common7/Tools/"
160 export VS90COMNTOOLS
161fi
162vc9Bin32Dir=`envpath "${VS90COMNTOOLS}"`/../../VC/Bin
163vc9Bin64Dir="${vc9Bin32Dir}"
164vc9vars32Bat="vcvars32.bat"
165vc9vars64Bat="vcvars64.bat"
166
167# VS2005 (VC8)
168if [ "${VS80COMNTOOLS}" = "" ] ; then
169 VS80COMNTOOLS="${progfiles32}/Microsoft Visual Studio 8.0/Common7/Tools/"
170 export VS80COMNTOOLS
171fi
172vc8Bin32Dir=`envpath "${VS80COMNTOOLS}"`/../../VC/Bin
173vc8Bin64Dir="${progfiles64}/Microsoft Platform SDK"
174vc8vars32Bat="vcvars32.bat"
175vc8vars64Bat="SetEnv.cmd /X64"
176
177# VS2003 (VC7)
178if [ "${VS71COMNTOOLS}" = "" ] ; then
179 VS71COMNTOOLS="${progfiles32}/Microsoft Visual Studio .NET 2003/Common7/Tools/"
180 export VS71COMNTOOLS
181fi
182vc7Bin32Dir=`envpath "${VS71COMNTOOLS}"`/../../VC7/Bin
183vc7Bin64Dir="${progfiles64}/Microsoft Platform SDK"
184vc7vars32Bat="vcvars32.bat"
185vc7vars64Bat="SetEnv.cmd /X64"
186
187# Force user to select
188vcSelection=""
189
190# Parse options
191usage="Usage: $0 [-help] [-debug] [-v] [-c] [-s] [-p] [-v10] [-v9] [-v8] [-v7] [-32] [-64]"
192while [ $# -gt 0 ] ; do
193 if [ "$1" = "-help" ] ; then
194 msg "${usage}"
195 msg " -help Print out this help message"
196 msg " -debug Print out extra env variables to help debug this script"
197 msg " -v Verbose output warns about missing directories"
198 msg " -c Print out csh style output"
199 msg " -s Print out sh style output"
200 msg " -p Print out properties style output"
201 msg " -v10 Use Visual Studio 10 VS2010"
202 msg " -v9 Use Visual Studio 9 VS2008"
203 msg " -v8 Use Visual Studio 8 VS2005"
204 msg " -v7 Use Visual Studio 7 VS2003"
205 msg " -32 Force 32bit"
206 msg " -64 Force 64bit"
207 exit 0
208 elif [ "$1" = "-debug" ] ; then
209 debug="true"
210 shift
211 elif [ "$1" = "-v" ] ; then
212 verbose="true"
213 shift
214 elif [ "$1" = "-c" ] ; then
215 shellStyle="csh"
216 shift
217 elif [ "$1" = "-s" ] ; then
218 shellStyle="sh"
219 shift
220 elif [ "$1" = "-p" ] ; then
221 shellStyle="props"
222 shift
223 elif [ "$1" = "-v10" ] ; then
224 vcBin32Dir="${vc10Bin32Dir}"
225 vcBin64Dir="${vc10Bin64Dir}"
226 vcvars32Bat="${vc10vars32Bat}"
227 vcvars64Bat="${vc10vars64Bat}"
228 vcSelection="10"
229 shift
230 elif [ "$1" = "-v9" ] ; then
231 vcBin32Dir="${vc9Bin32Dir}"
232 vcBin64Dir="${vc9Bin64Dir}"
233 vcvars32Bat="${vc9vars32Bat}"
234 vcvars64Bat="${vc9vars64Bat}"
235 vcSelection="9"
236 shift
237 elif [ "$1" = "-v8" ] ; then
238 vcBin32Dir="${vc8Bin32Dir}"
239 vcBin64Dir="${vc8Bin64Dir}"
240 vcvars32Bat="${vc8vars32Bat}"
241 vcvars64Bat="${vc8vars64Bat}"
242 vcSelection="8"
243 shift
244 elif [ "$1" = "-v7" ] ; then
245 vcBin32Dir="${vc7Bin32Dir}"
246 vcBin64Dir="${vc7Bin64Dir}"
247 vcvars32Bat="${vc7vars32Bat}"
248 vcvars64Bat="${vc7vars64Bat}"
249 vcSelection="7"
250 shift
251 elif [ "$1" = "-32" ] ; then
252 arch_data_model=32
253 shift
254 elif [ "$1" = "-64" ] ; then
255 arch_data_model=64
256 shift
257 else
258 msg "${usage}"
259 error "Unknown option: $1"
260 fi
261done
262
263# Need to pick
264if [ "${vcSelection}" = "" ] ; then
265 msg "${usage}"
266 error "You must pick the version"
267fi
268
269# Which vcvars bat file to run
270if [ "${arch_data_model}" = "32" ] ; then
271 vcBinDir="${vcBin32Dir}"
272 vcvarsBat="${vcvars32Bat}"
273fi
274if [ "${arch_data_model}" = "64" ] ; then
275 vcBinDir="${vcBin64Dir}"
276 vcvarsBat="${vcvars64Bat}"
277fi
278
279# Do not allow any error returns
280set -e
281
282# Different systems have different awk's
283if [ -f /usr/bin/nawk ] ; then
284 awk="nawk"
285elif [ -f /usr/bin/gawk ] ; then
286 awk="gawk"
287else
288 awk="awk"
289fi
290
291if [ "${verbose}" = "true" ] ; then
292 echo "# Welcome to verbose mode"
293 set -x
294fi
295
296if [ "${debug}" = "true" ] ; then
297 echo "# Welcome to debug mode"
298 set -x
299fi
300
301# Temp file area
302tmp="/tmp/vsvars.$$"
303rm -f -r ${tmp}
304mkdir -p ${tmp}
305
306# Check paths
307checkPaths() # var path sep
308{
309 set -e
310 sep="$3"
311 checklist="${tmp}/checklist"
312 printf "%s\n" "$2" | \
313 sed -e 's@\\@/@g' | \
314 sed -e 's@//@/@g' | \
315 ${awk} -F"${sep}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \
316 > ${checklist}
317 cat ${checklist} | while read orig; do
318 if [ "${orig}" != "" ] ; then
319 if [ ! -d "${orig}" ] ; then
320 warning "Directory in $1 does not exist: ${orig}"
321 fi
322 fi
323 done
324}
325
326# Remove all duplicate entries
327removeDeadDups() # string sep
328{
329 set -e
330 sep="$2"
331 pathlist="${tmp}/pathlist"
332 printf "%s\n" "$1" | \
333 sed -e 's@\\@/@g' | \
334 sed -e 's@//@/@g' | \
335 ${awk} -F"${sep}" '{for(i=1;i<=NF;i++){printf "%s\n",$i;}}' \
336 > ${pathlist}
337 upaths="${tmp}/upaths"
338 cat ${pathlist} | while read orig; do
339 p="${orig}"
340 if [ "${cygpath_short}" != "" ] ; then
341 if [ "${p}" != "" ] ; then
342 if [ -d "${p}" ] ; then
343 short=`${cygpath_short} "${p}"`
344 if [ "${short}" != "" -a -d "${short}" ] ; then
345 p=`${cygpath} "${short}"`
346 fi
347 echo "${p}" >> ${upaths}
348 fi
349 fi
350 fi
351 done
352 newpaths=""
353 for i in `cat ${upaths}` ; do
354 # For some reason, \r characters can get into this
355 i=`echo "${i}" | tr -d '\r' | sed -e 's@/$@@'`
356 if [ "${newpaths}" = "" ] ; then
357 newpaths="${i}"
358 else
359 newpaths="${newpaths}${sep}${i}"
360 fi
361 done
362 printf "%s\n" "${newpaths}" | \
363 ${awk} -F"${sep}" \
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";}'
365}
366
367# Create bat file to process Visual Studio vcvars*.bat files
368createBat() # batfile bindir command
369{
370 bat="$1"
371 bindir="$2"
372 command="$3"
373 stdout="${bat}.stdout"
374 rm -f ${bat} ${stdout}
375 echo "Output from: ${command}" > ${stdout}
376 bdir=`envpath "${bindir}"`
377 cat > ${bat} << EOF
378REM Pick the right vcvars bat file
379REM Empty these out so we only get the additions we want
380set INCLUDE=
381set LIB=
382set LIBPATH=
383set MSVCDIR=
384set MSSdk=
385set Mstools=
386set DevEnvDir=
387set VCINSTALLDIR=
388set VSINSTALLDIR=
389set WindowsSdkDir=
390REM Run the vcvars bat file, send all output to stderr
391call `${cygpath_windows} ${bdir}`\\${command} > `${cygpath_windows} "${stdout}"`
392REM Echo out env var settings
393echo VS_VS71COMNTOOLS="%VS71COMNTOOLS%"
394echo export VS_VS71COMNTOOLS
395echo VS_VS80COMNTOOLS="%VS80COMNTOOLS%"
396echo export VS_VS80COMNTOOLS
397echo VS_VS90COMNTOOLS="%VS90COMNTOOLS%"
398echo export VS_VS90COMNTOOLS
399echo VS_VS100COMNTOOLS="%VS100COMNTOOLS%"
400echo export VS_VS100COMNTOOLS
401echo VS_VCINSTALLDIR="%VCINSTALLDIR%"
402echo export VS_VCINSTALLDIR
403echo VS_VSINSTALLDIR="%VSINSTALLDIR%"
404echo export VS_VSINSTALLDIR
405echo VS_DEVENVDIR="%DevEnvDir%"
406echo export VS_DEVENVDIR
407echo VS_MSVCDIR="%MSVCDIR%"
408echo export VS_MSVCDIR
409echo VS_MSSDK="%MSSdk%"
410echo export VS_MSSDK
411echo VS_MSTOOLS="%Mstools%"
412echo export VS_MSTOOLS
413echo VS_WINDOWSSDKDIR="%WindowsSdkDir%"
414echo export VS_WINDOWSSDKDIR
415echo VS_INCLUDE="%INCLUDE%"
416echo export VS_INCLUDE
417echo VS_LIB="%LIB%"
418echo export VS_LIB
419echo VS_LIBPATH="%LIBPATH%"
420echo export VS_LIBPATH
421echo VS_WPATH="%PATH%"
422echo export VS_WPATH
423EOF
424 chmod a+x ${bat}
425}
426
427# Create env file
428createEnv() # batfile envfile
429{
430 rm -f ${1}.stdout
431 cmd.exe /Q /C `${cygpath_short} $1` | \
432 sed -e 's@\\@/@g' | \
433 sed -e 's@//@/@g' > $2
434 if [ -f "${1}.stdout" ] ; then
435 cat ${1}.stdout 1>&2
436 fi
437 chmod a+x $2
438}
439
440printEnv() # name pname vsname val
441{
442 name="$1"
443 pname="$2"
444 vsname="$3"
445 val="$4"
446 if [ "${val}" != "" ] ; then
447 if [ "${shellStyle}" = "csh" ] ; then
448 if [ "${debug}" = "true" ] ; then
449 echo "setenv ${vsname} \"${val}\";"
450 fi
451 echo "setenv ${name} \"${val}\";"
452 elif [ "${shellStyle}" = "sh" ] ; then
453 if [ "${debug}" = "true" ] ; then
454 echo "${vsname}=\"${val}\";"
455 echo "export ${vsname};"
456 fi
457 echo "${name}=\"${val}\";"
458 echo "export ${name};"
459 elif [ "${shellStyle}" = "props" ] ; then
460 echo "vs.${pname}=${val}"
461 fi
462 fi
463}
464
465#############################################################################
466
467# Get Visual Studio settings
468if [ "${cygpath}" != "" ] ; then
469
470 # Create bat file to run
471 batfile="${tmp}/vs-to-env.bat"
472 if [ ! -d "${vcBinDir}" ] ; then
473 error "Does not exist: ${vcBinDir}"
474 elif [ "${vcvarsBat}" = "" ] ; then
475 error "No vcvars script: ${vcvarsBat}"
476 else
477 createBat "${batfile}" "${vcBinDir}" "${vcvarsBat}"
478 fi
479
480 # Run bat file to create environment variable settings
481 envfile="${tmp}/env.sh"
482 createEnv "${batfile}" "${envfile}"
483
484 # Read in the VS_* settings
485 . ${envfile}
486
487 # Derive unix style path, save old, and define new (remove dups)
488 VS_UPATH=`${cygpath_path} "${VS_WPATH}"`
489 export VS_UPATH
490 VS_OPATH=`printf "%s" "${PATH}" | sed -e 's@\\\\@/@g'`
491 export VS_OPATH
492 VS_PATH=`removeDeadDups "${VS_UPATH}${pathsep}${VS_OPATH}" "${pathsep}"`
493 export VS_PATH
494
495fi
496
497# Adjustments due to differences in vcvars*bat files
498if [ "${VS_MSVCDIR}" = "" ] ; then
499 VS_MSVCDIR="${VS_VCINSTALLDIR}"
500fi
501if [ "${VS_DEVENVDIR}" = "" ] ; then
502 VS_DEVENVDIR="${VS_VSINSTALLDIR}"
503fi
504
505# Print env settings
506# env vs.prop vs env value
507# ------- ------- ---------- -----
508printEnv INCLUDE include VS_INCLUDE "${VS_INCLUDE}"
509printEnv LIB lib VS_LIB "${VS_LIB}"
510printEnv LIBPATH libpath VS_LIBPATH "${VS_LIBPATH}"
511if [ "${debug}" = "true" ] ; then
512 printEnv UPATH upath VS_UPATH "${VS_UPATH}"
513 printEnv WPATH wpath VS_WPATH "${VS_WPATH}"
514 printEnv OPATH opath VS_OPATH "${VS_OPATH}"
515fi
516printEnv PATH path VS_PATH "${VS_PATH}"
517printEnv VCINSTALLDIR vcinstalldir VS_VCINSTALLDIR "${VS_VCINSTALLDIR}"
518printEnv VSINSTALLDIR vsinstalldir VS_VSINSTALLDIR "${VS_VSINSTALLDIR}"
519printEnv MSVCDIR msvcdir VS_MSVCDIR "${VS_MSVCDIR}"
520printEnv MSSDK mssdk VS_MSSDK "${VS_MSSDK}"
521printEnv MSTOOLS mstools VS_MSTOOLS "${VS_MSTOOLS}"
522printEnv DEVENVDIR devenvdir VS_DEVENVDIR "${VS_DEVENVDIR}"
523printEnv WINDOWSSDKDIR windowssdkdir VS_WINDOWSSDKDIR "${VS_WINDOWSSDKDIR}"
524if [ "${vcSelection}" = "10" ] ; then
525 printEnv VS100COMNTOOLS vs100comntools VS_VS100COMNTOOLS "${VS_VS100COMNTOOLS}"
526elif [ "${vcSelection}" = "9" ] ; then
527 printEnv VS90COMNTOOLS vs90comntools VS_VS90COMNTOOLS "${VS_VS90COMNTOOLS}"
528elif [ "${vcSelection}" = "7" ] ; then
529 printEnv VS71COMNTOOLS vs71comntools VS_VS71COMNTOOLS "${VS_VS71COMNTOOLS}"
530elif [ "${vcSelection}" = "8" ] ; then
531 printEnv VS80COMNTOOLS vs80comntools VS_VS80COMNTOOLS "${VS_VS80COMNTOOLS}"
532fi
533
534# Check final settings
535if [ "${verbose}" = "true" ] ; then
536 checkPaths "Windows PATH" "${VS_WPATH}" ";"
537 checkPaths LIB "${VS_LIB}" ";"
538 checkPaths INCLUDE "${VS_INCLUDE}" ";"
539 checkPaths PATH "${VS_PATH}" "${pathsep}"
540fi
541
542# Remove all temp files
543rm -f -r ${tmp}
544
545exit 0
546
Note: See TracBrowser for help on using the repository browser.