1 #!/bin/bash
   2 #
   3 # Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
   4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 #
   6 # This code is free software; you can redistribute it and/or modify it
   7 # under the terms of the GNU General Public License version 2 only, as
   8 # published by the Free Software Foundation.
   9 #
  10 # This code is distributed in the hope that it will be useful, but WITHOUT
  11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13 # version 2 for more details (a copy is included in the LICENSE file that
  14 # accompanied this code).
  15 #
  16 # You should have received a copy of the GNU General Public License version
  17 # 2 along with this work; if not, write to the Free Software Foundation,
  18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 #
  20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21 # or visit www.oracle.com if you need additional information or have any
  22 # questions.
  23 #
  24 
  25 # Must be bash, but that is ok since we are running from cygwin.
  26 # The first argument is the vcvarsall.bat file to run.
  27 # The second argument is the arch arg to give to vcvars.
  28 VCVARSALL="$1"
  29 ARCH_ARG="$2"
  30 
  31 # Cannot use the VS10 setup script directly (since it only updates the DOS subshell environment)
  32 # but calculate the difference in Cygwin environment before/after running it and then
  33 # apply the diff.
  34 _vs10varsall=`cygpath -a -m -s "$VCVARSALL"`
  35 _dosvs10varsall=`cygpath -a -w -s $_vs10varsall`
  36 _dosbash=`cygpath -a -w -s \`which bash\`.*`
  37 
  38 # generate the set of exported vars before/after the vs10 setup
  39 echo "@echo off" > localdevenvtmp.bat
  40 echo "$_dosbash -c \"export -p\" > localdevenvtmp.export0" >> localdevenvtmp.bat
  41 echo "call $_dosvs10varsall $ARCH_ARG" >> localdevenvtmp.bat
  42 echo "$_dosbash -c \"export -p\" > localdevenvtmp.export1" >> localdevenvtmp.bat
  43 cmd /c localdevenvtmp.bat
  44 
  45 # apply the diff (less some non-vs10 vars named by "!")
  46 sort localdevenvtmp.export0 |grep -v "!" > localdevenvtmp.export0.sort
  47 sort localdevenvtmp.export1 |grep -v "!" > localdevenvtmp.export1.sort
  48 comm -1 -3 localdevenvtmp.export0.sort localdevenvtmp.export1.sort > localdevenv.sh
  49 cat localdevenv.sh | sed 's/declare -x /export /g' | sed 's/="/:="/g' | sed 's/\\\\/\\/g' | sed 's/"//g' | \
  50     sed 's/#/\$\(HASH\)/g' > localdevenv.gmk
  51 
  52 # cleanup
  53 rm -f localdevenvtmp*