homebrew-core/Formula/luajit.rb
2017-11-01 07:17:26 -07:00

89 lines
3.2 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"
bottle do
sha256 "4848129fc7affc5949c240f571c5e8d0684bbd142f8dc2e18176b3a8f165b2bb" => :high_sierra
sha256 "bdebedd2ab2bea98e10591308a5246c81aa7628ee7d17a0f20aeebeebf8bec22" => :sierra
sha256 "1d7aaa71d670da1e52b92e6db270ba935b9047e08e5cda52c70b14623d1b5bdf" => :el_capitan
sha256 "a96de1c4d07aac2ee35f8df2498e305da7466fed04ae291d42bd63c24e8dc658" => :yosemite
end
devel do
url "https://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz"
sha256 "1ad2e34b111c802f9d0cdf019e986909123237a28c746b21295b63c9e785d9c3"
option "with-gc64", "Build with 64-bit support"
end
head do
url "https://luajit.org/git/luajit-2.0.git", :branch => "v2.1"
option "with-gc64", "Build with 64-bit support"
end
deprecated_option "enable-debug" => "with-debug"
option "with-debug", "Build with debugging symbols"
option "with-52compat", "Build with additional Lua 5.2 compatibility"
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
ENV.O2 # Respect the developer's choice.
args = %W[PREFIX=#{prefix}]
cflags = []
cflags << "-DLUAJIT_ENABLE_LUA52COMPAT" if build.with? "52compat"
cflags << "-DLUAJIT_ENABLE_GC64" if !build.stable? && build.with?("gc64")
args << "XCFLAGS=#{cflags.join(" ")}" unless cflags.empty?
# This doesn't yet work under superenv because it removes "-g"
args << "CCDEBUG=-g" if build.with? "debug"
# The development branch of LuaJIT normally does not install "luajit".
args << "INSTALL_TNAME=luajit" if build.devel?
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}"
if build.without? "gc64"
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