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    echo "You must source this file ..."
 33    echo "Using either "
 34    echo "    . ${0}"
 35    echo "or"
 36    echo "    source ${0}"
 37    exit 1;  # this is ok because we were not sourced 
 38 else
 39 
 40   # We were indeed sourced so don't exit below here or we will trash the users shell ;)
 41   #    possibly loging them out 
 42 
 43   OS=$(uname -s )
 44   if [[ "$OS" == Linux ]]; then
 45     export ostype=linux
 46   elif  [[ "$OS" == Darwin ]]; then
 47     export ostype=macosx
 48   else
 49     echo "Could not determine ostype uname -s returned ${OS}"
 50   fi
 51 
 52   ARCH=$(uname -m)
 53   if [[ "$ARCH" == x86_64 ]]; then
 54     export archtype=${ARCH}
 55   elif  [[ "$ARCH" ==  aarch64 ]]; then
 56     export archtype=aarch64
 57   elif  [[ "$ARCH" == arm64 ]]; then
 58     export archtype=aarch64
 59   else
 60     echo "Could not determine aarchtype uname -m returned ${ARCH}"
 61   fi
 62 
 63   if [[ -z "${archtype}" || -z "${ostype}" ]]; then 
 64      echo "Can't determine archtype and/or ostype"
 65   else
 66     # We expect either 
 67     #   The user provided a value for BABYLON_JDK_HOME
 68     # or
 69     #   We can locate one because we are a subdir of BABYLON using ${PWD}/..
 70 
 71     # export BABYLON_JDK_HOME=${BABYLON_JDK_HOME:-$(realpath ${PWD}/..)}
 72 
 73     if [[ -z "${BABYLON_JDK_HOME}" ]]; then 
 74        echo "No user provided BABYLON_JDK_HOME var, we will try \${PWD}/.. = $(realpath ${PWD}/..)"
 75        export BABYLON_JDK_HOME=$(realpath ${PWD}/..)
 76     else
 77        echo "Using user supplied BABYLON_JDK_HOME ${BABYLON_JDK_HOME}"
 78     fi
 79 
 80 
 81     if [[ -d "${BABYLON_JDK_HOME}/build" ]]; then
 82       #echo "\${BABYLON_JDK_HOME}/build seems ok!"
 83       export JAVA_HOME=${BABYLON_JDK_HOME}/build/${ostype}-${archtype}-server-release/jdk
 84       #echo "exporting JAVA_HOME=${JAVA_HOME}"
 85       if echo ${PATH} | grep ${JAVA_HOME} >/dev/null ;then
 86          echo "PATH already contains \${JAVA_HOME}/bin"
 87       else
 88          export SAFE_PATH=${PATH}
 89          echo "Adding \${JAVA_HOME}/bin prefix to PATH, SAFE_PATH contains previous value"
 90          export PATH=${JAVA_HOME}/bin:${PATH}
 91       fi
 92 
 93       if [[ ${1} = "clean" ]]; then 
 94          rm -rf build maven-build thirdparty repoDir
 95       fi 
 96       if [[ ! -e bldr/Bldr.java ]]; then 
 97          ln -s src/main/java/bldr/Bldr.java bldr/Bldr.java
 98          echo "Created a symlink bldr/Bldr.java "
 99       fi 
100       echo "SUCCESS!"
101     else
102       echo "We expected either:-"
103       echo "    \${PWD} to be in a hat subdir of a compiled babylon jdk build" 
104       echo "or" 
105       echo "    BABYLON_JDK_HOME to be set, to a compiled babylon jdk build"
106       echo ""
107       echo "If you are in a hat subdir make sure babylon jdk is built ;)"
108       echo ""
109       echo "If you are in another dir try  "
110       echo "    BABYLON_JDK_HOME=<<YOUR_PREBULT_BABYLON>> . ${0}"
111       echo "or"
112       echo "    BABYLON_JDK_HOME=<<YOUR_PREBULT_BABYLON>> source ${0}"
113     fi
114   fi
115 fi
116