From 9228a05f980f2e9704fd658e1e68105498383012 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Tue, 5 Apr 2011 14:21:20 +0700 Subject: [PATCH] lua: install a dylib rather than a static liblua. Although other loadable lua modules (such as those from luarocks) should not link against even a dynamic liblua and tie themselves to a particular release and runtime (e.g. breaking luajit capability): Having a statically linked non-pic liblua in the lua binary can and does cause hard to track memory allocation failure aborts due to some minutae of the way '-bundle -undefined dynamic_lookup' objects dlopened by the interpreter interact with the symbols resolved in the static binary. The solution is to always build and install liblua.dylib. It appears that this issue is confined to Snow Leopard and/or the version of gcc it ships with. This thread on the lua list contains the explanation and patch: http://lua-users.org/lists/lua-l/2009-10/msg00145.html Signed-off-by: Adam Vandenberg --- Library/Formula/lua.rb | 69 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/Library/Formula/lua.rb b/Library/Formula/lua.rb index b62ac6db615c..dafd91d3a804 100644 --- a/Library/Formula/lua.rb +++ b/Library/Formula/lua.rb @@ -10,6 +10,13 @@ class Lua < Formula # Skip cleaning both empty folders and bin/libs so external symbols still work. skip_clean :all + # Be sure to build a dylib, or else runtime modules will pull in another static copy of liblua = crashy + # See: https://github.com/mxcl/homebrew/pull/5043 + def patches + DATA + end + + def install # Apply patch-level 2 curl "http://www.lua.org/ftp/patch-lua-5.1.4-3", "-O" @@ -41,3 +48,65 @@ def install (lib+"pkgconfig").install 'etc/lua.pc' end end + +__END__ +diff --git a/Makefile b/Makefile +index 6e78f66..6b48d2b 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.4.dylib + TO_MAN= lua.1 luac.1 + + # Lua version and release. +@@ -64,6 +64,7 @@ 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.4.dylib $(INSTALL_LIB)/liblua.5.1.dylib + + ranlib: + cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB) +diff --git a/src/Makefile b/src/Makefile +index e4a3cd6..e35a1b5 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.4.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) $@ $? +- $(RANLIB) $@ ++ $(CC) -dynamiclib -install_name /usr/local/lib/liblua.5.1.dylib \ ++ -compatibility_version 5.1 -current_version 5.1.4 \ ++ -o liblua.5.1.4.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.4 $(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="-DLUA_USE_LINUX -fno-common" MYLIBS="-lreadline" + # use this on Mac OS X 10.3- + # $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX +