homebrew-core/Formula/lua.rb

122 lines
4.5 KiB
Ruby

class Lua < Formula
desc "Powerful, lightweight programming language"
homepage "https://www.lua.org/"
url "https://www.lua.org/ftp/lua-5.4.3.tar.gz"
sha256 "f8612276169e3bfcbcfb8f226195bfc6e466fe13042f1076cbde92b7ec96bbfb"
license "MIT"
livecheck do
url "https://www.lua.org/ftp/"
regex(/href=.*?lua[._-]v?(\d+(?:\.\d+)+)\.t/i)
end
bottle do
rebuild 2
sha256 cellar: :any, arm64_big_sur: "2a9741ed654f1062394c3431072711bd3aaa39c1fb45ccf3468ace915a7cd843"
sha256 cellar: :any, big_sur: "b47b9174126bc9bdabb694db4c61cc4d705b06cf7b6f5c19771f447992863bb4"
sha256 cellar: :any, catalina: "8503086f7311c0c05a12fbad5c49561d066efb8abef9ed3b66c8b35f17e6a5a0"
sha256 cellar: :any, mojave: "e075a5333160b570cb0532f7124061c44ae58fe33cad382ad2dbbf9f87675712"
sha256 cellar: :any_skip_relocation, x86_64_linux: "0ed70cbfb305766e0b80ed8fb9a8ac077246908194342edf8cfd108fb0f3d672"
end
uses_from_macos "unzip" => :build
on_macos do
# Be sure to build a dylib, or else runtime modules will pull in another static copy of liblua = crashy
# See: https://github.com/Homebrew/legacy-homebrew/pull/5043
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/11c8360432f471f74a9b2d76e012e3b36f30b871/lua/lua-dylib.patch"
sha256 "a39e2ae1066f680e5c8bf1749fe09b0e33a0215c31972b133a73d43b00bf29dc"
end
end
on_linux do
depends_on "readline"
# Add shared library for linux. Equivalent to the mac patch above.
# Inspired from http://www.linuxfromscratch.org/blfs/view/cvs/general/lua.html
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/0dcd11880c7d63eb395105a5cdddc1ca05b40f4a/lua/lua-so.patch"
sha256 "522dc63a0c1d87bf127c992dfdf73a9267890fd01a5a17e2bcf06f7eb2782942"
end
end
def install
if OS.linux?
# Fix: /usr/bin/ld: lapi.o: relocation R_X86_64_32 against `luaO_nilobject_' can not be used
# when making a shared object; recompile with -fPIC
# See http://www.linuxfromscratch.org/blfs/view/cvs/general/lua.html
ENV.append_to_cflags "-fPIC"
end
# Substitute formula prefix in `src/Makefile` for install name (dylib ID).
# Use our CC/CFLAGS to compile.
inreplace "src/Makefile" do |s|
s.gsub! "@OPT_LIB@", opt_lib if OS.mac?
s.remove_make_var! "CC"
s.change_make_var! "MYCFLAGS", ENV.cflags
s.change_make_var! "MYLDFLAGS", ENV.ldflags
end
# Fix path in the config header
inreplace "src/luaconf.h", "/usr/local", HOMEBREW_PREFIX
os = if OS.mac?
"macosx"
else
"linux"
end
system "make", os, "INSTALL_TOP=#{prefix}"
system "make", "install", "INSTALL_TOP=#{prefix}"
# We ship our own pkg-config file as Lua no longer provide them upstream.
libs = %w[-llua -lm]
libs << "-ldl" if OS.linux?
(lib/"pkgconfig/lua.pc").write <<~EOS
V= #{version.major_minor}
R= #{version}
prefix=#{HOMEBREW_PREFIX}
INSTALL_BIN= ${prefix}/bin
INSTALL_INC= ${prefix}/include/lua
INSTALL_LIB= ${prefix}/lib
INSTALL_MAN= ${prefix}/share/man/man1
INSTALL_LMOD= ${prefix}/share/lua/${V}
INSTALL_CMOD= ${prefix}/lib/lua/${V}
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/lua
Name: Lua
Description: An Extensible Extension Language
Version: #{version}
Requires:
Libs: -L${libdir} #{libs.join(" ")}
Cflags: -I${includedir}
EOS
# Fix some software potentially hunting for different pc names.
bin.install_symlink "lua" => "lua#{version.major_minor}"
bin.install_symlink "lua" => "lua-#{version.major_minor}"
bin.install_symlink "luac" => "luac#{version.major_minor}"
bin.install_symlink "luac" => "luac-#{version.major_minor}"
(include/"lua#{version.major_minor}").install_symlink Dir[include/"lua/*"]
lib.install_symlink shared_library("liblua", version.major_minor) => shared_library("liblua#{version.major_minor}")
(lib/"pkgconfig").install_symlink "lua.pc" => "lua#{version.major_minor}.pc"
(lib/"pkgconfig").install_symlink "lua.pc" => "lua-#{version.major_minor}.pc"
lib.install Dir[shared_library("src/liblua", "*")] if OS.linux?
end
def caveats
<<~EOS
You may also want luarocks:
brew install luarocks
EOS
end
test do
assert_match "Homebrew is awesome!", shell_output("#{bin}/lua -e \"print ('Homebrew is awesome!')\"")
end
end