1 cat >/dev/null<<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 LICENSE
27 
28 function example(){
29    echo $*
30    headless=$1
31    backend=$2
32    example=$3
33    shift 3
34    if test "${backend}" =  "java"; then
35        backend_jar=backends/shared/src/main/resources
36    else
37        backend_jar=maven-build/hat-backend-${backend}-1.0.jar
38    fi
39    echo checking backend_jar = ${backend_jar}
40    if test -f ${backend_jar} -o -d ${backend_jar} ;then
41       example_jar=maven-build/hat-example-${example}-1.0.jar
42       echo checking example_jar = ${example_jar}
43       if test -f ${example_jar} ; then
44          ${JAVA_HOME}/bin/java \
45             --enable-preview --enable-native-access=ALL-UNNAMED \
46             --class-path maven-build/hat-1.0.jar:${example_jar}:${backend_jar} \
47             --add-exports=java.base/jdk.internal=ALL-UNNAMED \
48             -Djava.library.path=maven-build\
49             -Dheadless=${headless} \
50             ${example}.Main
51       else
52          echo no such example example_jar = ${example_jar}
53       fi
54    else
55       echo no such backend backend_jar = ${backend_jar}
56    fi
57 }
58 
59 if [ $# -eq 0 ]; then 
60    echo 'usage:'
61    echo '   bash hatrun.bash [headless] backend package args ...'
62    echo '       headless : Optional passes -Dheadless=true to app'
63    echo '       package  : the examples package (and dirname under hat/examples)'
64    echo '       backend  : opencl|cuda|spirv|ptx|mock'
65    echo '       Class name is assumed to be package.Main '
66 else
67    if [ $1 == headless ]; then 
68       echo headless!
69       shift 1
70       example true $*
71    else
72       example false $*
73    fi
74 fi
75