Skip to content

Instantly share code, notes, and snippets.

@jprjr
Last active January 3, 2016 14:29
Show Gist options
  • Save jprjr/8476378 to your computer and use it in GitHub Desktop.
Save jprjr/8476378 to your computer and use it in GitHub Desktop.
build_package_shared() {
local package_name="$1"
# patch the makefile for a shared library
curl -L https://gist.github.com/jprjr/8476378/raw/lua51-shared-library.patch | patch -p 1
if [ "${MAKEOPTS+defined}" ]; then
MAKE_OPTS="$MAKEOPTS"
elif [ -z "${MAKE_OPTS+defined}" ]; then
MAKE_OPTS="-j 2"
fi
local os_name=$(uname -s | tr '[A-Z]' '[a-z]')
local platform
[ "$os_name" == darwin ] && platform=macosx
[ "$os_name" == *cygwin* ] && platform=posix
[ "$os_name" == *mingw* ] && platform=mingw
[ "$os_name" == *bsd* ] && platform=bsd
[ "$os_name" == *freebsd* ] && platform=freebsd
[ "$os_name" == linux ] && platform=linux
[ "$os_name" == *sunos* ] && platform=solaris
[ "$os_name" == *aix* ] && platform=aix
{ mv src/luaconf.h src/luaconf.h.orig
sed -e "s:LUA_ROOT[ ]*\"/usr/local/\":LUA_ROOT \"${PREFIX_PATH}/\":g" src/luaconf.h.orig > src/luaconf.h
"$MAKE" $MAKE_OPTS "${platform:-posix}" INSTALL_TOP="$PREFIX_PATH" INSTALL_MAN="$PREFIX_PATH/share/man/man1"
"$MAKE" TO_LIB="liblua.a liblua.so liblua.so.5.1 liblua.so.5.1.5" $MAKE_OPTS install INSTALL_TOP="$PREFIX_PATH" INSTALL_MAN="$PREFIX_PATH/share/man/man1"
} >&4 2>&1
}
install_package "lua-5.1.5" "http://www.lua.org/ftp/lua-5.1.5.tar.gz#2e115fe26e435e33b0d5c022e4490567" shared
diff -ru lua-5.1.5/Makefile lua-5.1.5-new/Makefile
--- lua-5.1.5/Makefile 2012-02-10 03:50:23.000000000 -0600
+++ lua-5.1.5-new/Makefile 2014-01-17 10:25:17.000000000 -0600
@@ -53,7 +53,7 @@
all: $(PLAT)
$(PLATS) clean:
- cd src && $(MAKE) $@
+ cd src && $(MAKE) $@ V=$(V) R=$(R)
test: dummy
src/lua test/hello.lua
diff -ru lua-5.1.5/src/Makefile lua-5.1.5-new/src/Makefile
--- lua-5.1.5/src/Makefile 2012-02-13 14:41:22.000000000 -0600
+++ lua-5.1.5-new/src/Makefile 2014-01-17 10:50:21.000000000 -0600
@@ -8,7 +8,7 @@
PLAT= none
CC= gcc
-CFLAGS= -O2 -Wall $(MYCFLAGS)
+CFLAGS= -fPIC -O2 -Wall $(MYCFLAGS)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
@@ -23,6 +23,7 @@
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
LUA_A= liblua.a
+LUA_SO= liblua.so
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
@@ -36,7 +37,7 @@
LUAC_O= luac.o print.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+ALL_T= $(LUA_A) $(LUA_SO) $(LUA_T) $(LUAC_T)
ALL_A= $(LUA_A)
default: $(PLAT)
@@ -51,6 +52,11 @@
$(AR) $@ $(CORE_O) $(LIB_O) # DLL needs all object files
$(RANLIB) $@
+$(LUA_SO): $(CORE_O) $(LIB_O)
+ $(CC) -shared -ldl -Wl,-soname,$(LUA_SO).$(V) -o $@.$(R) $? -lm $(MYLDFLAGS)
+ ln -sf $(LUA_SO).$(R) $(LUA_SO).$(V)
+ ln -sf $(LUA_SO).$(R) $(LUA_SO)
+
$(LUA_T): $(LUA_O) $(LUA_A)
$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment