0002-shared-libs-for-lua.patch 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. Add the compilation of a shared library.
  2. Compile the lua binary with the shared library.
  3. And install the shared library.
  4. The variable BUILDMODE allows to switch between static and dynamic mode.
  5. Signed-off-by: Francois Perrad <francois.perrad@gadz.org>
  6. Index: b/Makefile
  7. ===================================================================
  8. --- a/Makefile
  9. +++ b/Makefile
  10. @@ -44,6 +44,7 @@
  11. TO_BIN= lua luac
  12. TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
  13. TO_LIB= liblua.a
  14. +TO_SOLIB = liblua.so.$(R)
  15. TO_MAN= lua.1 luac.1
  16. # Lua version and release.
  17. @@ -61,6 +62,8 @@
  18. install: dummy
  19. cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
  20. cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
  21. + test -f src/$(TO_SOLIB) && cd src && $(INSTALL_EXEC) $(TO_SOLIB) $(INSTALL_LIB) || :
  22. + test -f src/$(TO_SOLIB) && ln -sf $(TO_SOLIB) $(INSTALL_LIB)/liblua.so || :
  23. cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
  24. cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
  25. cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
  26. Index: b/src/Makefile
  27. ===================================================================
  28. --- a/src/Makefile
  29. +++ b/src/Makefile
  30. @@ -23,6 +23,7 @@
  31. PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
  32. LUA_A= liblua.a
  33. +LUA_SO= liblua.so
  34. CORE_O= lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \
  35. lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \
  36. lundump.o lvm.o lzio.o
  37. @@ -36,8 +37,13 @@
  38. LUAC_O= luac.o print.o
  39. ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
  40. +ifneq (dynamic,$(BUILDMODE))
  41. ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
  42. +else
  43. +ALL_T= $(LUA_A) $(LUA_SO) $(LUA_T) $(LUAC_T)
  44. +endif
  45. ALL_A= $(LUA_A)
  46. +ALL_SO= $(LUA_SO)
  47. default: $(PLAT)
  48. @@ -47,12 +53,23 @@
  49. a: $(ALL_A)
  50. +so: $(ALL_SO)
  51. +
  52. $(LUA_A): $(CORE_O) $(LIB_O)
  53. $(AR) $@ $(CORE_O) $(LIB_O) # DLL needs all object files
  54. $(RANLIB) $@
  55. +$(LUA_SO): $(CORE_O) $(LIB_O)
  56. + $(CC) -o $@.$(PKG_VERSION) -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
  57. + ln -fs $@.$(PKG_VERSION) $@
  58. +
  59. +ifneq (dynamic,$(BUILDMODE))
  60. $(LUA_T): $(LUA_O) $(LUA_A)
  61. $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
  62. +else
  63. +$(LUA_T): $(LUA_O) $(LUA_SO)
  64. + $(CC) -o $@ -L. $(MYLDFLAGS) $(LUA_O) -llua $(LIBS)
  65. +endif
  66. $(LUAC_T): $(LUAC_O) $(LUA_A)
  67. $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)