homebrew-core/Formula/luajit.rb
2019-11-18 13:51:04 +01:00

70 lines
2.5 KiB
Ruby

class Luajit < Formula
desc "Just-In-Time Compiler (JIT) for the Lua programming language"
homepage "https://luajit.org/luajit.html"
url "https://luajit.org/download/LuaJIT-2.0.5.tar.gz"
sha256 "874b1f8297c697821f561f9b73b57ffd419ed8f4278c82e05b48806d30c1e979"
head "https://luajit.org/git/luajit-2.0.git", :branch => "v2.1"
bottle do
cellar :any
rebuild 2
sha256 "859148159c69b09e70d2c46b40c63f86341d309d8ed73d67b41666a8444d0b39" => :mojave
sha256 "3ee1eeeca03770a402bc429aef0a09467f5b2efcdcb47c9a7d55355af0815c99" => :high_sierra
end
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
# Xcode 11 fix
ENV.append_to_cflags "-fno-stack-check" if DevelopmentTools.clang_build_version >= 1010
# 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
ENV.O2 # Respect the developer's choice.
args = %W[PREFIX=#{prefix}]
# Build with 64-bit support
args << "XCFLAGS=-DLUAJIT_ENABLE_GC64" if build.head?
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}"
unless build.head?
s.gsub! "Libs:",
"Libs: -pagezero_size 10000 -image_base 100000000"
end
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