1 cat >/dev/null<<END_OF_LICENSE 2 /* 3 * Copyright (c) 2024, 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 END_OF_LICENSE 27 28 # First lets check if this script was sourced into a bash compatible shell 29 30 if [ "${BASH_SOURCE[0]}" = "${0}" ]; then 31 # We just bail if it was not sourced.. We want to set AND export PATH and JAVA_HOME... 32 # So we must be sourced. Otherwise we just fork a new shell, set the vars in the temp shell and exit 33 echo "You must source this file ..." 34 echo "Using either " 35 echo " . ${0}" 36 echo "or" 37 echo " source ${0}" 38 exit 1; # exiting here is ONLY ok because we were not sourced. 39 else 40 41 # We were sourced so must not exit below or we will trash the users shell ;) possibly logging them out 42 # We first need to determine the arch an os types so we can construct/test against something like 43 # macosx-aarch64-server-release 44 # ^ ^ 45 # | + ${archtype} 46 # + ${ostype} 47 48 OS=$(uname -s ) 49 if [[ "$OS" == Linux ]]; then 50 export ostype=linux 51 elif [[ "$OS" == Darwin ]]; then 52 export ostype=macosx 53 else 54 # Windows? 55 echo "Could not determine ostype uname -s returned ${OS}" 56 fi 57 58 ARCH=$(uname -m) 59 if [[ "$ARCH" == x86_64 ]]; then 60 export archtype=${ARCH} 61 elif [[ "$ARCH" == aarch64 ]]; then 62 export archtype=aarch64 63 elif [[ "$ARCH" == arm64 ]]; then 64 export archtype=aarch64 65 else 66 #MIPS? 67 echo "Could not determine aarchtype uname -m returned ${ARCH}" 68 fi 69 70 if [[ -z "${archtype}" || -z "${ostype}" ]]; then 71 echo "Can't determine archtype and/or ostype" 72 else 73 # We expect either 74 # The user provided a value for BABYLON_JDK_HOME 75 # or 76 # We can locate one because we are a subdir of BABYLON using ${PWD}/.. 77 78 if [[ -z "${BABYLON_JDK_HOME}" ]]; then 79 echo "No user provided BABYLON_JDK_HOME var, we will try \${PWD}/.. = $(realpath ${PWD}/..)" 80 export BABYLON_JDK_HOME=$(realpath ${PWD}/..) 81 echo "We found a babylon build here ${BABYLON_JDK_HOME}" 82 else 83 echo "Using user supplied BABYLON_JDK_HOME ${BABYLON_JDK_HOME}" 84 fi 85 86 if command -v jextract; then 87 echo 'jextract in your PATH' 88 else 89 if [[ -z "${JEXTRACT_HOME}" ]]; then 90 echo "No user provided JEXTRACT_HOME var, we will try ~/jextract-22" 91 if [[ -d ~/jextract-22/bin ]]; then 92 export JEXTRACT_HOME=$(realpath ~/jextract-22) 93 echo "We found jextract here ${JEXTRACT_HOME}" 94 fi 95 else 96 echo "Using user supplied JEXTRACT_HOME ${JEXTRACT_HOME}" 97 fi 98 fi 99 100 if [[ -d "${JEXTRACT_HOME}/bin" ]]; then 101 if echo ${PATH} | grep ${JEXTRACT_HOME} >/dev/null ;then 102 echo "PATH already contains \${JEXTRACT_HOME}/bin" 103 else 104 export SAFE_PATH=${PATH} 105 echo "Adding \${JEXTRACT_HOME}/bin prefix to PATH, SAFE_PATH contains previous value" 106 export PATH=${JEXTRACT_HOME}/bin:${PATH} 107 fi 108 else 109 echo 'You will need to add jextract to your PATH to be able to build' 110 echo 'Either add it, or JEXTRACT_HOME' 111 fi 112 113 if [[ -d "${BABYLON_JDK_HOME}/build" ]]; then 114 export JAVA_HOME=${BABYLON_JDK_HOME}/build/${ostype}-${archtype}-server-release/jdk 115 if echo ${PATH} | grep ${JAVA_HOME} >/dev/null ;then 116 echo "PATH already contains \${JAVA_HOME}/bin" 117 else 118 export SAFE_PATH=${PATH} 119 echo "Adding \${JAVA_HOME}/bin prefix to PATH, SAFE_PATH contains previous value" 120 export PATH=${JAVA_HOME}/bin:${PATH} 121 fi 122 else 123 echo "We expected either:-" 124 echo " \${PWD} to be in a hat subdir of a compiled babylon jdk build" 125 echo "or" 126 echo " BABYLON_JDK_HOME to be set, to a compiled babylon jdk build" 127 echo "" 128 echo "If you are in a hat subdir make sure babylon jdk is built ;)" 129 echo "" 130 echo "If you are in another dir try " 131 echo " BABYLON_JDK_HOME=<<YOUR_PREBULT_BABYLON>> . ${0}" 132 echo "or" 133 echo " BABYLON_JDK_HOME=<<YOUR_PREBULT_BABYLON>> source ${0}" 134 fi 135 fi 136 fi 137