0002-shared-libs-for-lua.patch 2.4 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. @@ -42,6 +42,7 @@
  11. TO_BIN= lua luac
  12. TO_INC= lua.h luaconf.h lualib.h lauxlib.h 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. @@ -57,6 +58,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. @@ -33,6 +33,7 @@
  31. PLATS= guess aix bsd c89 freebsd generic linux linux-readline macosx mingw posix solaris
  32. LUA_A= liblua.a
  33. +LUA_SO= liblua.so
  34. CORE_O= lapi.o lcode.o lctype.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
  35. LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o
  36. BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
  37. @@ -44,8 +45,13 @@
  38. LUAC_O= luac.o
  39. ALL_O= $(BASE_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. # Targets start here.
  48. default: $(PLAT)
  49. @@ -56,12 +62,23 @@
  50. a: $(ALL_A)
  51. +so: $(ALL_SO)
  52. +
  53. $(LUA_A): $(BASE_O)
  54. $(AR) $@ $(BASE_O)
  55. $(RANLIB) $@
  56. +$(LUA_SO): $(CORE_O) $(LIB_O)
  57. + $(CC) -o $@.$(PKG_VERSION) -shared -Wl,-soname="$@.$(PKG_VERSION)" $?
  58. + ln -fs $@.$(PKG_VERSION) $@
  59. +
  60. +ifneq (dynamic,$(BUILDMODE))
  61. $(LUA_T): $(LUA_O) $(LUA_A)
  62. $(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
  63. +else
  64. +$(LUA_T): $(LUA_O) $(LUA_SO)
  65. + $(CC) -o $@ -L. $(LDFLAGS) $(LUA_O) -llua $(LIBS)
  66. +endif
  67. $(LUAC_T): $(LUAC_O) $(LUA_A)
  68. $(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)