homebrew-core/Formula/luajit-openresty.rb

79 lines
3.3 KiB
Ruby

class LuajitOpenresty < Formula
desc "OpenResty's Branch of LuaJIT 2"
homepage "https://github.com/openresty/luajit2"
url "https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20220411.tar.gz"
sha256 "d3f2c870f8f88477b01726b32accab30f6e5d57ae59c5ec87374ff73d0794316"
license "MIT"
version_scheme 1
head "https://github.com/openresty/luajit2.git", branch: "v2.1-agentzh"
# The latest LuaJIT release is unstable (2.1.0-beta3, from 2017-05-01) and
# OpenResty is making releases using the latest LuaJIT Git commits. With this
# in mind, the regex below is very permissive and will match any tags
# starting with a numeric version, ensuring that we match unstable versions.
# We should consider restricting the regex to stable versions if it ever
# becomes feasible in the future.
livecheck do
url :stable
regex(/^v?(\d+(?:[.-]\d+)+[^{}]*)/i)
end
bottle do
sha256 cellar: :any, arm64_monterey: "97b49b1612b5579992fe7e825b91f2b192bc0a28433534ac0acc222065b8aeaa"
sha256 cellar: :any, arm64_big_sur: "6cc059ffbc72123fae17b51b47709495f0edd2e737d1fcc9d8cec1ba8cf073b7"
sha256 cellar: :any, monterey: "cb382c21c8e0239aa7a73b031157298670369db20d247adf200ad488d6d3e61e"
sha256 cellar: :any, big_sur: "21bb7476cda22b1fc1265f708a4b357860b238a15ccb9f8866c95a16a98dda10"
sha256 cellar: :any, catalina: "92eadb859be61c3553a79f5b8f00ce9feeb8a0d3d9d898125aae40fce016eeec"
sha256 cellar: :any_skip_relocation, x86_64_linux: "5d4e0b55a6e9f1397b50799fd33b4f0ee86bf749c1f36a595a309ca4b866dd6f"
end
keg_only "it conflicts with the LuaJIT formula"
def install
# 1 - Override the hardcoded gcc.
# 2 - Remove the "-march=i686" so we can set the march in cflags.
# Both changes should persist and were discussed upstream.
inreplace "src/Makefile" do |f|
f.change_make_var! "CC", ENV.cc
f.change_make_var! "CCOPT_x86", ""
end
# Per https://luajit.org/install.html: If MACOSX_DEPLOYMENT_TARGET
# is not set then it's forced to 10.4, which breaks compile on Mojave.
ENV["MACOSX_DEPLOYMENT_TARGET"] = MacOS.version
args = %W[
PREFIX=#{prefix}
XCFLAGS=-DLUAJIT_ENABLE_GC64
]
system "make", "amalg", *args
system "make", "install", *args
# LuaJIT doesn't automatically symlink unversioned libraries:
# https://github.com/Homebrew/homebrew/issues/45854.
lib.install_symlink lib/"libluajit-5.1.dylib" => "libluajit.dylib"
lib.install_symlink lib/"libluajit-5.1.a" => "libluajit.a"
# Fix path in pkg-config so modules are installed
# to permanent location rather than inside the Cellar.
inreplace lib/"pkgconfig/luajit.pc" do |s|
s.gsub! "INSTALL_LMOD=${prefix}/share/lua/${abiver}",
"INSTALL_LMOD=#{HOMEBREW_PREFIX}/share/lua/${abiver}"
s.gsub! "INSTALL_CMOD=${prefix}/${multilib}/lua/${abiver}",
"INSTALL_CMOD=#{HOMEBREW_PREFIX}/${multilib}/lua/${abiver}"
end
# Having an empty Lua dir in lib/share can mess with other Homebrew Luas.
%W[#{lib}/lua #{share}/lua].each { |d| rm_rf d }
end
test do
system "#{bin}/luajit", "-e", <<~EOS
local ffi = require("ffi")
ffi.cdef("int printf(const char *fmt, ...);")
ffi.C.printf("Hello %s!\\n", "#{ENV["USER"]}")
EOS
end
end