Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2015, 2018, 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. Oracle designates this |
| 9 | # particular file as subject to the "Classpath" exception as provided |
| 10 | # by Oracle in the LICENSE file that accompanied this code. |
| 11 | # |
| 12 | # This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | # version 2 for more details (a copy is included in the LICENSE file that |
| 16 | # accompanied this code). |
| 17 | # |
| 18 | # You should have received a copy of the GNU General Public License version |
| 19 | # 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | # |
| 22 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | # or visit www.oracle.com if you need additional information or have any |
| 24 | # questions. |
| 25 | # |
| 26 | |
| 27 | # This script copies parts of a Visual Studio installation into a devkit |
| 28 | # suitable for building OpenJDK and OracleJDK. Needs to run in Cygwin. |
| 29 | # erik.joelsson@oracle.com |
| 30 | |
| 31 | VS_VERSION="2017" |
| 32 | VS_VERSION_NUM_NODOT="150" |
| 33 | VS_DLL_VERSION="140" |
| 34 | SDK_VERSION="10" |
Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 35 | MSVC_DIR="Microsoft.VC141.CRT" |
| 36 | |
| 37 | SCRIPT_DIR="$(cd "$(dirname $0)" > /dev/null && pwd)" |
| 38 | BUILD_DIR="${SCRIPT_DIR}/../../build/devkit" |
| 39 | |
| 40 | ################################################################################ |
| 41 | # Prepare settings |
| 42 | |
| 43 | # Work around the insanely named ProgramFiles(x86) env variable |
| 44 | PROGRAMFILES_X86="$(cygpath "$(env | sed -n 's/^ProgramFiles(x86)=//p')")" |
| 45 | |
| 46 | # Find Visual Studio installation dir |
| 47 | eval VSNNNCOMNTOOLS="\"\${VS${VS_VERSION_NUM_NODOT}COMNTOOLS}\"" |
| 48 | if [ -d "$VSNNNCOMNTOOLS" ]; then |
| 49 | VS_INSTALL_DIR="$(cygpath "$VSNNNCOMNTOOLS/../..")" |
| 50 | else |
| 51 | VS_INSTALL_DIR="${PROGRAMFILES_X86}/Microsoft Visual Studio/2017" |
| 52 | VS_INSTALL_DIR="$(ls -d "${VS_INSTALL_DIR}/"{Community,Professional} 2>/dev/null | head -n1)" |
| 53 | VS_INSTALL_DIR="$(cygpath "$VS_INSTALL_DIR")" |
| 54 | fi |
| 55 | echo "VS_INSTALL_DIR: $VS_INSTALL_DIR" |
| 56 | |
| 57 | # Extract semantic version |
| 58 | POTENTIAL_INI_FILES="Common7\IDE\wdexpress.isolation.ini Common7\IDE\devenv.isolation.ini" |
| 59 | for f in $POTENTIAL_INI_FILES; do |
| 60 | if [ -f "$VS_INSTALL_DIR/$f" ]; then |
| 61 | VS_VERSION_SP="$(grep ^SemanticVersion= "$VS_INSTALL_DIR/$f")" |
| 62 | # Remove SemnaticVersion= |
| 63 | VS_VERSION_SP="${VS_VERSION_SP#*=}" |
| 64 | # Remove suffix of too detailed numbering starting with + |
| 65 | VS_VERSION_SP="${VS_VERSION_SP%+*}" |
| 66 | break |
| 67 | fi |
| 68 | done |
| 69 | if [ -z "$VS_VERSION_SP" ]; then |
| 70 | echo "Failed to find SP version" |
| 71 | exit 1 |
| 72 | fi |
| 73 | echo "Found Version SP: $VS_VERSION_SP" |
| 74 | |
| 75 | # Setup output dirs |
| 76 | DEVKIT_ROOT="${BUILD_DIR}/VS${VS_VERSION}-${VS_VERSION_SP}-devkit" |
| 77 | DEVKIT_BUNDLE="${DEVKIT_ROOT}.tar.gz" |
| 78 | |
| 79 | echo "Creating devkit in $DEVKIT_ROOT" |
| 80 | |
| 81 | MSVCR_DLL=${MSVC_DIR}/vcruntime${VS_DLL_VERSION}.dll |
| 82 | MSVCP_DLL=${MSVC_DIR}/msvcp${VS_DLL_VERSION}.dll |
| 83 | |
| 84 | ################################################################################ |
| 85 | # Copy Visual Studio files |
| 86 | |
| 87 | if [ ! -d $DEVKIT_ROOT/VC ]; then |
| 88 | VC_SUBDIR="VC/Tools/MSVC/14.12.25827" |
| 89 | REDIST_SUBDIR="VC/Redist/MSVC/14.12.25810" |
| 90 | echo "Copying VC..." |
| 91 | mkdir -p $DEVKIT_ROOT/VC/bin |
| 92 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/bin/Hostx64/x64" $DEVKIT_ROOT/VC/bin/ |
| 93 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/bin/Hostx86/x86" $DEVKIT_ROOT/VC/bin/ |
| 94 | mkdir -p $DEVKIT_ROOT/VC/lib |
| 95 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/lib/x64" $DEVKIT_ROOT/VC/lib/ |
| 96 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/lib/x86" $DEVKIT_ROOT/VC/lib/ |
| 97 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/include" $DEVKIT_ROOT/VC/ |
| 98 | mkdir -p $DEVKIT_ROOT/VC/atlmfc/lib |
| 99 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/atlmfc/lib/x64" $DEVKIT_ROOT/VC/atlmfc/lib/ |
| 100 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/atlmfc/lib/x86" $DEVKIT_ROOT/VC/atlmfc/lib/ |
| 101 | cp -r "$VS_INSTALL_DIR/${VC_SUBDIR}/atlmfc/include" $DEVKIT_ROOT/VC/atlmfc/ |
| 102 | mkdir -p $DEVKIT_ROOT/VC/Auxiliary |
| 103 | cp -r "$VS_INSTALL_DIR/VC/Auxiliary/Build" $DEVKIT_ROOT/VC/Auxiliary/ |
| 104 | mkdir -p $DEVKIT_ROOT/VC/redist |
| 105 | cp -r "$VS_INSTALL_DIR/$REDIST_SUBDIR/x64" $DEVKIT_ROOT/VC/redist/ |
| 106 | cp -r "$VS_INSTALL_DIR/$REDIST_SUBDIR/x86" $DEVKIT_ROOT/VC/redist/ |
| 107 | |
| 108 | # The redist runtime libs are needed to run the compiler but may not be |
| 109 | # installed on the machine where the devkit will be used. |
Erik Joelsson | 354bddb | 2018-05-29 21:01:13 +0200 | [diff] [blame] | 110 | cp $DEVKIT_ROOT/VC/redist/x86/$MSVCR_DLL $DEVKIT_ROOT/VC/bin/x86 |
| 111 | cp $DEVKIT_ROOT/VC/redist/x86/$MSVCP_DLL $DEVKIT_ROOT/VC/bin/x86 |
Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 112 | cp $DEVKIT_ROOT/VC/redist/x64/$MSVCR_DLL $DEVKIT_ROOT/VC/bin/x64 |
| 113 | cp $DEVKIT_ROOT/VC/redist/x64/$MSVCP_DLL $DEVKIT_ROOT/VC/bin/x64 |
| 114 | fi |
| 115 | |
| 116 | ################################################################################ |
| 117 | # Copy SDK files |
| 118 | |
| 119 | SDK_INSTALL_DIR="$(cygpath "$PROGRAMFILES_X86/Windows Kits/$SDK_VERSION")" |
| 120 | echo "SDK_INSTALL_DIR: $SDK_INSTALL_DIR" |
| 121 | |
Erik Joelsson | 0f4c61d | 2019-10-11 06:31:52 -0700 | [diff] [blame] | 122 | SDK_FULL_VERSION="$(ls "$SDK_INSTALL_DIR/bin" | sort -r -n | head -n1)" |
| 123 | echo "Found SDK version: $SDK_FULL_VERSION" |
| 124 | |
Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 125 | if [ ! -d $DEVKIT_ROOT/$SDK_VERSION ]; then |
| 126 | echo "Copying SDK..." |
| 127 | mkdir -p $DEVKIT_ROOT/$SDK_VERSION/bin |
| 128 | cp -r "$SDK_INSTALL_DIR/bin/$SDK_FULL_VERSION/x64" $DEVKIT_ROOT/$SDK_VERSION/bin/ |
| 129 | cp -r "$SDK_INSTALL_DIR/bin/$SDK_FULL_VERSION/x86" $DEVKIT_ROOT/$SDK_VERSION/bin/ |
| 130 | mkdir -p $DEVKIT_ROOT/$SDK_VERSION/lib |
| 131 | cp -r "$SDK_INSTALL_DIR/lib/$SDK_FULL_VERSION/um/x64" $DEVKIT_ROOT/$SDK_VERSION/lib/ |
| 132 | cp -r "$SDK_INSTALL_DIR/lib/$SDK_FULL_VERSION/um/x86" $DEVKIT_ROOT/$SDK_VERSION/lib/ |
| 133 | cp -r "$SDK_INSTALL_DIR/lib/$SDK_FULL_VERSION/ucrt/x64" $DEVKIT_ROOT/$SDK_VERSION/lib/ |
| 134 | cp -r "$SDK_INSTALL_DIR/lib/$SDK_FULL_VERSION/ucrt/x86" $DEVKIT_ROOT/$SDK_VERSION/lib/ |
Erik Joelsson | f9e285b | 2018-05-09 19:50:30 +0200 | [diff] [blame] | 135 | mkdir -p $DEVKIT_ROOT/$SDK_VERSION/Redist |
| 136 | cp -r "$SDK_INSTALL_DIR/Redist/ucrt" $DEVKIT_ROOT/$SDK_VERSION/Redist/ |
Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 137 | mkdir -p $DEVKIT_ROOT/$SDK_VERSION/include |
| 138 | cp -r "$SDK_INSTALL_DIR/include/$SDK_FULL_VERSION/"* $DEVKIT_ROOT/$SDK_VERSION/include/ |
| 139 | fi |
| 140 | |
| 141 | ################################################################################ |
| 142 | # Generate devkit.info |
| 143 | |
| 144 | echo-info() { |
| 145 | echo "$1" >> $DEVKIT_ROOT/devkit.info |
| 146 | } |
| 147 | |
| 148 | echo "Generating devkit.info..." |
| 149 | rm -f $DEVKIT_ROOT/devkit.info |
| 150 | echo-info "# This file describes to configure how to interpret the contents of this devkit" |
| 151 | echo-info "DEVKIT_NAME=\"Microsoft Visual Studio $VS_VERSION $VS_VERSION_SP (devkit)\"" |
| 152 | echo-info "DEVKIT_VS_VERSION=\"$VS_VERSION\"" |
| 153 | echo-info "" |
| 154 | echo-info "DEVKIT_TOOLCHAIN_PATH_x86=\"\$DEVKIT_ROOT/VC/bin/x86:\$DEVKIT_ROOT/$SDK_VERSION/bin/x86\"" |
| 155 | echo-info "DEVKIT_VS_INCLUDE_x86=\"\$DEVKIT_ROOT/VC/include;\$DEVKIT_ROOT/VC/atlmfc/include;\$DEVKIT_ROOT/$SDK_VERSION/include/shared;\$DEVKIT_ROOT/$SDK_VERSION/include/ucrt;\$DEVKIT_ROOT/$SDK_VERSION/include/um;\$DEVKIT_ROOT/$SDK_VERSION/include/winrt\"" |
| 156 | echo-info "DEVKIT_VS_LIB_x86=\"\$DEVKIT_ROOT/VC/lib/x86;\$DEVKIT_ROOT/VC/atlmfc/lib/x86;\$DEVKIT_ROOT/$SDK_VERSION/lib/x86\"" |
| 157 | echo-info "DEVKIT_MSVCR_DLL_x86=\"\$DEVKIT_ROOT/VC/redist/x86/$MSVCR_DLL\"" |
| 158 | echo-info "DEVKIT_MSVCP_DLL_x86=\"\$DEVKIT_ROOT/VC/redist/x86/$MSVCP_DLL\"" |
Erik Joelsson | f9e285b | 2018-05-09 19:50:30 +0200 | [diff] [blame] | 159 | echo-info "DEVKIT_UCRT_DLL_DIR_x86=\"\$DEVKIT_ROOT/10/Redist/ucrt/DLLs/x86\"" |
Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 160 | echo-info "" |
| 161 | echo-info "DEVKIT_TOOLCHAIN_PATH_x86_64=\"\$DEVKIT_ROOT/VC/bin/x64:\$DEVKIT_ROOT/$SDK_VERSION/bin/x64:\$DEVKIT_ROOT/$SDK_VERSION/bin/x86\"" |
| 162 | echo-info "DEVKIT_VS_INCLUDE_x86_64=\"\$DEVKIT_ROOT/VC/include;\$DEVKIT_ROOT/VC/atlmfc/include;\$DEVKIT_ROOT/$SDK_VERSION/include/shared;\$DEVKIT_ROOT/$SDK_VERSION/include/ucrt;\$DEVKIT_ROOT/$SDK_VERSION/include/um;\$DEVKIT_ROOT/$SDK_VERSION/include/winrt\"" |
| 163 | echo-info "DEVKIT_VS_LIB_x86_64=\"\$DEVKIT_ROOT/VC/lib/x64;\$DEVKIT_ROOT/VC/atlmfc/lib/x64;\$DEVKIT_ROOT/$SDK_VERSION/lib/x64\"" |
| 164 | echo-info "DEVKIT_MSVCR_DLL_x86_64=\"\$DEVKIT_ROOT/VC/redist/x64/$MSVCR_DLL\"" |
| 165 | echo-info "DEVKIT_MSVCP_DLL_x86_64=\"\$DEVKIT_ROOT/VC/redist/x64/$MSVCP_DLL\"" |
Erik Joelsson | f9e285b | 2018-05-09 19:50:30 +0200 | [diff] [blame] | 166 | echo-info "DEVKIT_UCRT_DLL_DIR_x86_64=\"\$DEVKIT_ROOT/10/Redist/ucrt/DLLs/x64\"" |
Erik Joelsson | 9392abc | 2018-01-29 17:58:12 +0100 | [diff] [blame] | 167 | |
| 168 | ################################################################################ |
| 169 | # Copy this script |
| 170 | |
| 171 | echo "Copying this script..." |
| 172 | cp $0 $DEVKIT_ROOT/ |
| 173 | |
| 174 | ################################################################################ |
| 175 | # Create bundle |
| 176 | |
| 177 | echo "Creating bundle: $DEVKIT_BUNDLE" |
| 178 | (cd "$DEVKIT_ROOT" && tar zcf "$DEVKIT_BUNDLE" .) |