1 /* vim: set ft=java: 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 27 import static bldr.Bldr.*; 28 29 void main(String[] args) { 30 31 var hatDir = Dir.current(); 32 var hatLibDir = assertExists(hatDir.dir("hat")); 33 var backends = assertExists(hatDir.dir("backends")); 34 var examples = assertExists(hatDir.dir("examples")); 35 var buildDir =BuildDir.of(hatDir.path("build")).create(); 36 37 38 var hatJar = jar($->$ 39 .jar(buildDir.jarFile("hat-1.0.jar")) 40 .javac($$->$$ 41 .opts( 42 "--source", "24", 43 "--add-modules", "jdk.incubator.code", 44 "--enable-preview", 45 "--add-exports=java.base/jdk.internal=ALL-UNNAMED", 46 "--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED" 47 ) 48 .class_dir(buildDir.classDir("hat-1.0.jar.classes")) 49 .source_path(hatLibDir.dir("src/main/java")) 50 ) 51 ); 52 53 backends.forEachSubDirectory("opencl", "ptx").forEach(backend -> 54 jar($->$ 55 .jar(buildDir.jarFile("hat-backend-" + backend.name() + "-1.0.jar")) 56 .javac($$ -> $$ 57 .opts( 58 "--source", "24", 59 "--enable-preview", 60 "--add-exports=java.base/jdk.internal=ALL-UNNAMED", 61 "--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED" 62 ) 63 .class_dir(buildDir.classDir("hat-backend-" + backend.name() + "-1.0.jar.classes")) 64 .class_path(hatJar) 65 .source_path(backend.dir("src/main/java")) 66 ) 67 .dir_list(dir->dir.exists(),backend.dir("src/main/resources")) 68 ) 69 ); 70 71 var cmakeBuildDir = buildDir.cMakeBuildDir("cmake-build-debug"); 72 73 if (!cmakeBuildDir.exists()) { 74 cmake($ -> $.source_dir(backends).build_dir(cmakeBuildDir).copy_to(buildDir)); 75 } 76 77 cmake($->$.build(cmakeBuildDir)); 78 79 examples.forEachSubDirectory("blackscholes", "mandel", "squares", "heal", "violajones", "life").forEach(example -> 80 jar($->$ 81 .jar(buildDir.jarFile("hat-example-" + example.name() + "-1.0.jar")) 82 .javac($$->$$ 83 .opts( 84 "--source", "24", 85 "--enable-preview", 86 "--add-exports=java.base/jdk.internal=ALL-UNNAMED", 87 "--add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED" 88 ) 89 .class_dir(buildDir.classDir("hat-example-" + example.name() + "-1.0.jar.classes")) 90 .class_path(hatJar) 91 .source_path(example.dir("src/main/java")) 92 ) 93 .dir_list(dir->dir.exists(),example.dir("src/main/resources")) 94 ) 95 ); 96 }