homebrew-core/Formula/luajit-openresty.rb

66 lines
2.5 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/v2.1-20201229.tar.gz"
sha256 "4275bf97356d713826e7195d1c330568b6089ff1fd4c6954f998e0f60a2baa30"
license "MIT"
revision 1
head "https://github.com/openresty/luajit2.git", branch: "v2.1-agentzh"
bottle do
sha256 cellar: :any, arm64_big_sur: "d9700884c04219e458886ba68abdfc980a5ba40cdc073edb2ac70e63a4283e26"
sha256 cellar: :any, big_sur: "969786cd904fce0a2ec3cdeba2348603d767fff7b8a954194228ff05e151518d"
sha256 cellar: :any, catalina: "f6c7e24c8ba0faaeb9b831851c50175c942acccb2c916127e409214edd5bbf7d"
sha256 cellar: :any, mojave: "3efbb3a071c3ec6a2a9bdb9aa3724a1c8f36634e8377a27751b89d1c26e40fe8"
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