1 #!/bin/bash 
 2 cat >/dev/null<<LICENSE
 3 /*
 4  * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
 5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 6  *
 7  * This code is free software; you can redistribute it and/or modify it
 8  * under the terms of the GNU General Public License version 2 only, as
 9  * published by the Free Software Foundation.  Oracle designates this
10  * particular file as subject to the "Classpath" exception as provided
11  * by Oracle in the LICENSE file that accompanied this code.
12  *
13  * This code is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16  * version 2 for more details (a copy is included in the LICENSE file that
17  * accompanied this code).
18  *
19  * You should have received a copy of the GNU General Public License version
20  * 2 along with this work; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22  *
23  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
24  * or visit www.oracle.com if you need additional information or have any
25  * questions.
26  */
27 LICENSE
28 
29 
30 
31 if [ $# -eq 0 ]; then
32    echo 'usage:'
33    echo '   bash hatrun.bash [headless] backend package args ...'
34    echo '       headless : Optional passes -Dheadless=true to app'
35    echo '       backend  : opencl|cuda|spirv|ptx|mock'
36    echo '       package  : the examples package (and dirname under hat/examples)'
37    echo '       Class name is assumed to be package.Main '
38 elif [[ -d build ]] ; then
39    export OPTS="" 
40    export VMOPTS=""
41    export JARS="" 
42 
43    export VMOPTS="${VMOPTS} --enable-preview"
44    export VMOPTS="${VMOPTS} --enable-native-access=ALL-UNNAMED"
45    export VMOPTS="${VMOPTS} --add-exports=java.base/jdk.internal=ALL-UNNAMED"
46 
47    export HEADLESS="${1}"
48    if [[ "${HEADLESS}" = "headless" ]] ; then
49       echo HEADLESS=${HEADLESS}
50       shift 1  
51       export OPTS="${OPTS} -Dheadless=true"
52    else 
53       echo "Not headless"
54    fi
55 
56    export BACKEND="${1}"
57    echo BACKEND=${BACKEND}
58    if [[ -d backends/$1 || "$1" = "java" ]] ; then
59       export JARS=build/hat-1.0.jar
60       if [[ "$1" = "java" ]] ; then 
61          export BACKEND_JAR_or_DIR=backends/shared/src/main/resources
62          echo BACKEND_JAR_or_DIR=${BACKEND_JAR_or_DIR}
63       else
64          export BACKEND_JAR_or_DIR=build/hat-backend-${BACKEND}-1.0.jar
65          echo BACKEND_JAR_or_DIR=${BACKEND_JAR_or_DIR}
66          if [[ ! -f ${BACKEND_JAR_or_DIR} ]] ;then
67             echo "no backend ${BACKEND_JAR_or_DIR}"
68             exit 1
69          fi
70       fi
71       export JARS=${JARS}:${BACKEND_JAR_or_DIR}
72       if [[ "$1" = "spirv" ]] ;then 
73          export JARS=${JARS}:build/levelzero.jar:build/beehive-spirv-lib-0.0.4.jar;
74       fi
75       export OPTS="${OPTS} -Djava.library.path=build:/usr/local/lib"
76       shift 1
77    fi
78 
79    export EXAMPLE="${1}"
80    echo EXAMPLE=${EXAMPLE}
81    export EXAMPLE_JAR=build/hat-example-${EXAMPLE}-1.0.jar
82    if [[  -f ${EXAMPLE_JAR} ]] ;then
83       export JARS=${JARS}:${EXAMPLE_JAR}
84       shift 1
85    else
86       echo "no example build/${EXAMPLE_JAR}"
87       exit 1
88    fi  
89    echo JARS=${JARS}
90    echo VMOPTS=${VMOPTS}
91    echo OPTS=${OPTS}
92    echo java \${VMOPTS} \${OPTS} --class-path \${JARS} \${EXAMPLE}.Main $*
93    echo java ${VMOPTS} ${OPTS} --class-path ${JARS} ${EXAMPLE}.Main $*
94    java ${VMOPTS} ${OPTS} --class-path ${JARS} ${EXAMPLE}.Main $*
95 else
96    echo No build dir
97    exit 1
98 fi