Skip to content

Instantly share code, notes, and snippets.

@gvvaughan
Last active December 18, 2015 19:19
Show Gist options
  • Save gvvaughan/5832455 to your computer and use it in GitHub Desktop.
Save gvvaughan/5832455 to your computer and use it in GitHub Desktop.
Patch upstream lua-5.1.5 for building on Mac OS X by Homebrew.
## Patch upstream lua-5.1.5 for building on Mac OS X by Homebrew.
1. An extension of my earlier in-formula shared library compilation patch for earlier
releases.
2. Install binaries, headers, manual pages and library with 5.1 suffixes to enable
parallel installation with other versions of lua.
3. At the moment, lua 5.2.2 is the latest release, so we don't symlink the suffixed
versions to the usual locations of the binaries and man pages for 5.1.5 which must
be accessed by the suffixed files only.
diff --git a/Makefile b/Makefile
index 209a132..0a9961c 100644
--- a/etc/lua.pc
+++ b/etc/lua.pc
@@ -10,9 +10,9 @@
# grep '^INSTALL_.*=' ../Makefile | sed 's/INSTALL_TOP/prefix/'
prefix= /usr/local
INSTALL_BIN= ${prefix}/bin
-INSTALL_INC= ${prefix}/include
+INSTALL_INC= ${prefix}/include/lua-${V}
INSTALL_LIB= ${prefix}/lib
-INSTALL_MAN= ${prefix}/man/man1
+INSTALL_MAN= ${prefix}/share/man/man1
INSTALL_LMOD= ${prefix}/share/lua/${V}
INSTALL_CMOD= ${prefix}/lib/lua/${V}
@@ -19,13 +19,13 @@
# canonical vars
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
-includedir=${prefix}/include
+includedir=${prefix}/include/lua-${V}
Name: Lua
Description: An Extensible Extension Language
Version: ${R}
Requires:
-Libs: -L${libdir} -llua -lm
+Libs: -L${libdir} -llua.${V} -lm
Cflags: -I${includedir}
# (end of lua.pc)
diff --git a/Makefile b/Makefile
index 209a132..0a9961c 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,8 @@ PLAT= none
# so take care if INSTALL_TOP is not an absolute path.
INSTALL_TOP= /usr/local
INSTALL_BIN= $(INSTALL_TOP)/bin
-INSTALL_INC= $(INSTALL_TOP)/include
+INSTALL_INC= $(INSTALL_TOP)/include/lua-$V
INSTALL_LIB= $(INSTALL_TOP)/lib
+INSTALL_LIBEXEC= $(INSTALL_TOP)/libexec
INSTALL_MAN= $(INSTALL_TOP)/man/man1
#
@@ -41,10 +42,10 @@ RANLIB= ranlib
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
# What to install.
-TO_BIN= lua luac
+TO_LIBEXEC= lua$V luac$V
TO_INC= lua.h luaconf.h lualib.h lauxlib.h ../etc/lua.hpp
-TO_LIB= liblua.a
-TO_MAN= lua.1 luac.1
+TO_LIB= liblua.$R.dylib
+TO_MAN= lua-$V.1 luac-$V.1
# Lua version and release.
V= 5.1
@@ -53,17 +54,20 @@ R= 5.1.5
all: $(PLAT)
$(PLATS) clean:
- cd src && $(MAKE) $@
+ cd src && $(MAKE) $@ V=$V R=$R
test: dummy
src/lua test/hello.lua
install: dummy
- cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
+ cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_LIBEXEC) $(INSTALL_LIB)/pkgconfig $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
- cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
+ cd src && $(INSTALL_EXEC) $(TO_LIBEXEC) $(INSTALL_LIBEXEC)
cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
- cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
+ cd etc && $(INSTALL_DATA) lua.pc $(INSTALL_LIB)/pkgconfig/lua5.1.pc
+ cd doc && $(INSTALL_DATA) lua.1 $(INSTALL_MAN)/lua-$V.1
+ cd doc && $(INSTALL_DATA) luac.1 $(INSTALL_MAN)/luac-$V.1
+ ln -s -f liblua.$R.dylib $(INSTALL_LIB)/liblua.$V.dylib
ranlib:
cd src && cd $(INSTALL_LIB) && $(RANLIB) $(TO_LIB)
diff --git a/src/Makefile b/src/Makefile
index e0d4c9f..8ce37ac 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -22,17 +22,17 @@ MYLIBS=
PLATS= aix ansi bsd freebsd generic linux macosx mingw posix solaris
-LUA_A= liblua.a
+LUA_A= liblua.$R.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
LIB_O= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \
lstrlib.o loadlib.o linit.o
-LUA_T= lua
+LUA_T= lua$V
LUA_O= lua.o
-LUAC_T= luac
+LUAC_T= luac$V
LUAC_O= luac.o print.o
ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
@@ -48,11 +48,13 @@ o: $(ALL_O)
a: $(ALL_A)
$(LUA_A): $(CORE_O) $(LIB_O)
- $(AR) $@ $(CORE_O) $(LIB_O) # DLL needs all object files
- $(RANLIB) $@
+ $(CC) -dynamiclib -install_name /usr/local/lib/liblua.$V.dylib \
+ -compatibility_version $V -current_version $R \
+ -o liblua.$R.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.$R $(LIBS)
$(LUAC_T): $(LUAC_O) $(LUA_A)
$(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
@@ -81,39 +83,39 @@ none:
@echo " $(PLATS)"
aix:
- $(MAKE) all CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
+ $(MAKE) all V="$V" R="$R" CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl" MYLDFLAGS="-brtl -bexpall"
ansi:
- $(MAKE) all MYCFLAGS=-DLUA_ANSI
+ $(MAKE) all V="$V" R="$R" MYCFLAGS=-DLUA_ANSI
bsd:
- $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
+ $(MAKE) all V="$V" R="$R" MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-Wl,-E"
freebsd:
- $(MAKE) all MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
+ $(MAKE) all V="$V" R="$R" MYCFLAGS="-DLUA_USE_LINUX" MYLIBS="-Wl,-E -lreadline"
generic:
- $(MAKE) all MYCFLAGS=
+ $(MAKE) all V="$V" R="$R" MYCFLAGS=
linux:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
+ $(MAKE) all V="$V" R="$R" MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-Wl,-E -ldl -lreadline -lhistory -lncurses"
macosx:
- $(MAKE) all MYCFLAGS=-DLUA_USE_LINUX MYLIBS="-lreadline"
+ $(MAKE) all V="$V" R="$R" MYCFLAGS="-fno-common -DLUA_USE_LINUX" MYLIBS="-lreadline"
# use this on Mac OS X 10.3-
# $(MAKE) all MYCFLAGS=-DLUA_USE_MACOSX
mingw:
- $(MAKE) "LUA_A=lua51.dll" "LUA_T=lua.exe" \
+ $(MAKE) V="$V" R="$R" "LUA_A=lua51.dll" "LUA_T=lua.exe" \
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
"MYCFLAGS=-DLUA_BUILD_AS_DLL" "MYLIBS=" "MYLDFLAGS=-s" lua.exe
$(MAKE) "LUAC_T=luac.exe" luac.exe
posix:
- $(MAKE) all MYCFLAGS=-DLUA_USE_POSIX
+ $(MAKE) all V="$V" R="$R" MYCFLAGS=-DLUA_USE_POSIX
solaris:
- $(MAKE) all MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"
+ $(MAKE) all V="$V" R="$R" MYCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" MYLIBS="-ldl"
# list targets that do not create files (but not all makes understand .PHONY)
.PHONY: all $(PLATS) default o a clean depend echo none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment