require 'formula' class Lua < Formula # 5.2 is not fully backwards compatible, and breaks e.g. luarocks. # It is available in Homebrew-versions for the time being. homepage 'http://www.lua.org/' url 'http://www.lua.org/ftp/lua-5.1.5.tar.gz' sha1 'b3882111ad02ecc6b972f8c1241647905cb2e3fc' bottle do cellar :any sha1 "dcc3b430fd59fd3c16774ecc159d82256ac587db" => :mavericks sha1 "4ddadaaeaca408964255de43761a7f12b7457bb5" => :mountain_lion sha1 "212b1a9a5822afd9796fefb42bab63c6466e6faa" => :lion end fails_with :llvm do build 2326 cause "Lua itself compiles with LLVM, but may fail when other software tries to link." end option :universal option 'with-completion', 'Enables advanced readline support' option 'without-sigaction', 'Revert to ANSI signal instead of improved POSIX sigaction' # Be sure to build a dylib, or else runtime modules will pull in another static copy of liblua = crashy # See: https://github.com/Homebrew/homebrew/pull/5043 patch :DATA # sigaction provided by posix signalling power patch from # http://lua-users.org/wiki/LuaPowerPatches patch do url "http://lua-users.org/files/wiki_insecure/power_patches/5.1/sig_catch.patch" sha1 "19f361f0c590f80fccd033486cbee6c9dc8616c8" end if build.with? "sigaction" # completion provided by advanced readline power patch from # http://lua-users.org/wiki/LuaPowerPatches patch do url "http://luajit.org/patches/lua-5.1.4-advanced_readline.patch" sha1 "3cfe2eb027b51202923d20042ae37f3249508664" end if build.with? "completion" def install ENV.universal_binary if build.universal? # Use our CC/CFLAGS to compile. inreplace 'src/Makefile' do |s| s.remove_make_var! 'CC' s.change_make_var! 'CFLAGS', "#{ENV.cflags} $(MYCFLAGS)" s.change_make_var! 'MYLDFLAGS', ENV.ldflags s.sub! 'MYCFLAGS_VAL', "-fno-common -DLUA_USE_LINUX" end # Fix path in the config header inreplace 'src/luaconf.h', '/usr/local', HOMEBREW_PREFIX # Fix paths in the .pc inreplace 'etc/lua.pc' do |s| s.gsub! "prefix= /usr/local", "prefix=#{HOMEBREW_PREFIX}" s.gsub! "INSTALL_MAN= ${prefix}/man/man1", "INSTALL_MAN= ${prefix}/share/man/man1" end # this ensures that this symlinking for lua starts at lib/lua/5.1 and not # below that, thus making luarocks work (HOMEBREW_PREFIX/"lib/lua"/version.to_s.split('.')[0..1].join('.')).mkpath system "make", "macosx", "INSTALL_TOP=#{prefix}", "INSTALL_MAN=#{man1}" system "make", "install", "INSTALL_TOP=#{prefix}", "INSTALL_MAN=#{man1}" (lib+"pkgconfig").install 'etc/lua.pc' end test do output = `#{bin}/lua -e "for i=0,9 do io.write(i) end"` assert_equal "0123456789", output assert_equal 0, $?.exitstatus end end __END__ diff --git a/Makefile b/Makefile index 209a132..9387b09 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris # What to install. TO_BIN= lua luac TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp -TO_LIB= liblua.a +TO_LIB= liblua.5.1.5.dylib TO_MAN= lua.1 luac.1 # Lua version and release. @@ -64,6 +64,8 @@ install: dummy cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC) cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB) cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN) + ln -s -f liblua.5.1.5.dylib $(INSTALL_LIB)/liblua.5.1.dylib + ln -s -f liblua.5.1.dylib $(INSTALL_LIB)/liblua.dylib ranlib: cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB) diff --git a/src/Makefile b/src/Makefile index e0d4c9f..4477d7b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -22,7 +22,7 @@ MYLIBS= PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris -LUA_A= liblua.a +LUA_A= liblua.5.1.5.dylib CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \ lundump.o lvm.o lzio.o @@ -48,11 +48,13 @@ o: $(ALL_O) a: $(ALL_A) $(LUA_A): $(CORE_O) $(LIB_O) - $(AR) $@ $(CORE_O) $(LIB_O) # DLL needs all object files - $(RANLIB) $@ + $(CC) -dynamiclib -install_name HOMEBREW_PREFIX/lib/liblua.5.1.dylib \ + -compatibility_version 5.1 -current_version 5.1.5 \ + -o liblua.5.1.5.dylib $^ $(LUA_T): $(LUA_O) $(LUA_A) - $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS) + $(CC) -fno-common $(MYLDFLAGS) \ + -o $@ $(LUA_O) $(LUA_A) -L. -llua.5.1.5 $(LIBS) $(LUAC_T): $(LUAC_O) $(LUA_A) $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS) @@ -99,7 +101,7 @@ linux: $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses" macosx: - $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline" + $(MAKE) all MYCFLAGS="MYCFLAGS_VAL" MYLIBS="-lreadline" # use this on Mac OS X 10.3- # $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX