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 export JEXTRACT_HOME=$(dirname $(dirname $(command -v jextract))) 89 else 90 if [[ -z "${JEXTRACT_HOME}" ]]; then 91 echo "No user provided JEXTRACT_HOME var, we will try ~/jextract-22" 92 if [[ -d ~/jextract-22/bin ]]; then 93 export JEXTRACT_HOME=$(realpath ~/jextract-22) 94 echo "We found jextract here ${JEXTRACT_HOME}" 95 fi 96 else 97 echo "Using user supplied JEXTRACT_HOME ${JEXTRACT_HOME}" 98 fi 99 fi 100 101 if [[ -d "${JEXTRACT_HOME}/bin" ]]; then 102 if echo ${PATH} | grep ${JEXTRACT_HOME} >/dev/null ;then 103 echo "PATH already contains \${JEXTRACT_HOME}/bin" 104 else 105 export SAFE_PATH=${PATH} 106 echo "Adding \${JEXTRACT_HOME}/bin prefix to PATH, SAFE_PATH contains previous value" 107 export PATH=${JEXTRACT_HOME}/bin:${PATH} 108 fi 109 else 110 echo 'You will need to add jextract your PATH to be able to build' 111 echo 'Either add it, or JEXTRACT_HOME' 112 fi 113 114 if [[ -d "${BABYLON_JDK_HOME}/build" ]]; then 115 export JAVA_HOME=${BABYLON_JDK_HOME}/build/${ostype}-${archtype}-server-release/jdk 116 if echo ${PATH} | grep ${JAVA_HOME} >/dev/null ;then 117 echo "PATH already contains \${JAVA_HOME}/bin" 118 else 119 export SAFE_PATH=${PATH} 120 echo "Adding \${JAVA_HOME}/bin prefix to PATH, SAFE_PATH contains previous value" 121 export PATH=${JAVA_HOME}/bin:${PATH} 122 fi 123 else 124 echo "We expected either:-" 125 echo " \${PWD} to be in a hat subdir of a compiled babylon jdk build" 126 echo "or" 127 echo " BABYLON_JDK_HOME to be set, to a compiled babylon jdk build" 128 echo "" 129 echo "If you are in a hat subdir make sure babylon jdk is built ;)" 130 echo "" 131 echo "If you are in another dir try " 132 echo " BABYLON_JDK_HOME=<<YOUR_PREBULT_BABYLON>> . ${0}" 133 echo "or" 134 echo " BABYLON_JDK_HOME=<<YOUR_PREBULT_BABYLON>> source ${0}" 135 fi 136 fi 137 fi 138