homebrew-core/Formula/openjdk.rb

145 lines
4.8 KiB
Ruby

class Openjdk < Formula
desc "Development kit for the Java programming language"
homepage "https://openjdk.java.net/"
url "https://github.com/openjdk/jdk17u/archive/jdk-17.0.2-ga.tar.gz"
sha256 "f7b1540b12d72ca4710376292b6084fac13819a90bcaa1e5e81734c1b3b09517"
license "GPL-2.0-only" => { with: "Classpath-exception-2.0" }
livecheck do
url :stable
regex(/^jdk[._-]v?(\d+(?:\.\d+)*)-ga$/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "3f099ba19adf82555e67ffc0d370d1560bc94b0f3d794091ef190e439c25247d"
sha256 cellar: :any, arm64_big_sur: "62a165e05ba267cda9576e2c72ac71b86c02974964b02de97d4658aedc71c4fd"
sha256 cellar: :any, monterey: "29512989f1140e3bc65419933d71b21d690cb6236347cdbcd8d1d4da4b0ae37f"
sha256 cellar: :any, big_sur: "2376255643d9acce5ccead1be9aecd137fda743320d1d5e56972b479950b766f"
sha256 cellar: :any, catalina: "67b74b88e883e0e13c44a2c502880cec03c97ced164ec6e51cabb1a64d2b63ff"
sha256 x86_64_linux: "424bbd4492c56bd8eb56086d4c6844d27409162d76b5d41103d4a2ff5c53aaf5"
end
keg_only :shadowed_by_macos
depends_on "autoconf" => :build
on_linux do
depends_on "pkg-config" => :build
depends_on "alsa-lib"
depends_on "cups"
depends_on "fontconfig"
depends_on "gcc"
depends_on "libx11"
depends_on "libxext"
depends_on "libxrandr"
depends_on "libxrender"
depends_on "libxt"
depends_on "libxtst"
depends_on "unzip"
depends_on "zip"
ignore_missing_libraries "libjvm.so"
end
fails_with gcc: "5"
# From https://jdk.java.net/archive/
resource "boot-jdk" do
on_macos do
if Hardware::CPU.arm?
url "https://download.java.net/java/GA/jdk17/0d483333a00540d886896bac774ff48b/35/GPL/openjdk-17_macos-aarch64_bin.tar.gz"
sha256 "b5bf6377aabdc935bd72b36c494e178b12186b0e1f4be50f35134daa33bda052"
else
url "https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_osx-x64_bin.tar.gz"
sha256 "e65f2437585f16a01fa8e10139d0d855e8a74396a1dfb0163294ed17edd704b8"
end
end
on_linux do
url "https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz"
sha256 "6c714ded7d881ca54970ec949e283f43d673a142fda1de79b646ddd619da9c0c"
end
end
def install
boot_jdk = Pathname.pwd/"boot-jdk"
resource("boot-jdk").stage boot_jdk
boot_jdk /= "Contents/Home" if OS.mac?
java_options = ENV.delete("_JAVA_OPTIONS")
args = %W[
--disable-warnings-as-errors
--with-boot-jdk-jvmargs=#{java_options}
--with-boot-jdk=#{boot_jdk}
--with-debug-level=release
--with-jvm-variants=server
--with-native-debug-symbols=none
--with-vendor-bug-url=#{tap.issues_url}
--with-vendor-name=#{tap.user}
--with-vendor-url=#{tap.issues_url}
--with-vendor-version-string=#{tap.user}
--with-vendor-vm-bug-url=#{tap.issues_url}
--with-version-build=#{revision}
--without-version-opt
--without-version-pre
]
args += if OS.mac?
%W[
--enable-dtrace
--with-extra-ldflags=-headerpad_max_install_names
--with-sysroot=#{MacOS.sdk_path}
]
else
%W[
--with-x=#{HOMEBREW_PREFIX}
--with-cups=#{HOMEBREW_PREFIX}
--with-fontconfig=#{HOMEBREW_PREFIX}
]
end
chmod 0755, "configure"
system "./configure", *args
ENV["MAKEFLAGS"] = "JOBS=#{ENV.make_jobs}"
system "make", "images"
if OS.mac?
jdk = Dir["build/*/images/jdk-bundle/*"].first
libexec.install jdk => "openjdk.jdk"
bin.install_symlink Dir[libexec/"openjdk.jdk/Contents/Home/bin/*"]
include.install_symlink Dir[libexec/"openjdk.jdk/Contents/Home/include/*.h"]
include.install_symlink Dir[libexec/"openjdk.jdk/Contents/Home/include/darwin/*.h"]
man1.install_symlink Dir[libexec/"openjdk.jdk/Contents/Home/man/man1/*"]
else
libexec.install Dir["build/linux-x86_64-server-release/images/jdk/*"]
bin.install_symlink Dir[libexec/"bin/*"]
include.install_symlink Dir[libexec/"include/*.h"]
include.install_symlink Dir[libexec/"include/linux/*.h"]
man1.install_symlink Dir[libexec/"man/man1/*"]
end
end
def caveats
on_macos do
<<~EOS
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn #{opt_libexec}/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
EOS
end
end
test do
(testpath/"HelloWorld.java").write <<~EOS
class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello, world!");
}
}
EOS
system bin/"javac", "HelloWorld.java"
assert_match "Hello, world!", shell_output("#{bin}/java HelloWorld")
end
end