Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 <flangy@gmail.com>
  • Loading branch information...
commit 9228a05f980f2e9704fd658e1e68105498383012 1 parent cf63fef
Gary V. Vaughan gvvaughan authored adamv committed

Showing 1 changed file with 69 additions and 0 deletions. Show diff stats Hide diff stats

  1. +69 0 Library/Formula/lua.rb
69 Library/Formula/lua.rb
@@ -10,6 +10,13 @@ class Lua < Formula
10 10 # Skip cleaning both empty folders and bin/libs so external symbols still work.
11 11 skip_clean :all
12 12
  13 + # Be sure to build a dylib, or else runtime modules will pull in another static copy of liblua = crashy
  14 + # See: https://github.com/mxcl/homebrew/pull/5043
  15 + def patches
  16 + DATA
  17 + end
  18 +
  19 +
13 20 def install
14 21 # Apply patch-level 2
15 22 curl "http://www.lua.org/ftp/patch-lua-5.1.4-3", "-O"
@@ -41,3 +48,65 @@ def install
41 48 (lib+"pkgconfig").install 'etc/lua.pc'
42 49 end
43 50 end
  51 +
  52 +__END__
  53 +diff --git a/Makefile b/Makefile
  54 +index 6e78f66..6b48d2b 100644
  55 +--- a/Makefile
  56 ++++ b/Makefile
  57 +@@ -43,7 +43,7 @@ PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
  58 + # What to install.
  59 + TO_BIN= lua luac
  60 + TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
  61 +-TO_LIB= liblua.a
  62 ++TO_LIB= liblua.5.1.4.dylib
  63 + TO_MAN= lua.1 luac.1
  64 +
  65 + # Lua version and release.
  66 +@@ -64,6 +64,7 @@ install: dummy
  67 + cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
  68 + cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
  69 + cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
  70 ++ ln -s -f liblua.5.1.4.dylib $(INSTALL_LIB)/liblua.5.1.dylib
  71 +
  72 + ranlib:
  73 + cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB)
  74 +diff --git a/src/Makefile b/src/Makefile
  75 +index e4a3cd6..e35a1b5 100644
  76 +--- a/src/Makefile
  77 ++++ b/src/Makefile
  78 +@@ -22,7 +22,7 @@ MYLIBS=
  79 +
  80 + PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
  81 +
  82 +-LUA_A= liblua.a
  83 ++LUA_A= liblua.5.1.4.dylib
  84 + CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
  85 + lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
  86 + lundump.o lvm.o lzio.o
  87 +@@ -48,11 +48,13 @@ o: $(ALL_O)
  88 + a: $(ALL_A)
  89 +
  90 + $(LUA_A): $(CORE_O) $(LIB_O)
  91 +- $(AR) $@ $?
  92 +- $(RANLIB) $@
  93 ++ $(CC) -dynamiclib -install_name /usr/local/lib/liblua.5.1.dylib \
  94 ++ -compatibility_version 5.1 -current_version 5.1.4 \
  95 ++ -o liblua.5.1.4.dylib $^
  96 +
  97 + $(LUA_T): $(LUA_O) $(LUA_A)
  98 +- $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
  99 ++ $(CC) -fno-common $(MYLDFLAGS) \
  100 ++ -o $@ $(LUA_O) $(LUA_A) -L. -llua.5.1.4 $(LIBS)
  101 +
  102 + $(LUAC_T): $(LUAC_O) $(LUA_A)
  103 + $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
  104 +@@ -99,7 +101,7 @@ linux:
  105 + $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
  106 +
  107 + macosx:
  108 +- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
  109 ++ $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX -fno-common" MYLIBS="-lreadline"
  110 + # use this on Mac OS X 10.3-
  111 + # $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
  112 +

0 comments on commit 9228a05

Please sign in to comment.
Something went wrong with that request. Please try again.