--- old/Makefile	2012-02-10 10:50:23.000000000 +0100
+++ new/Makefile	2019-07-12 12:00:30.807725876 +0200
@@ -22,7 +22,8 @@
 
 # How to install. If your install program does not support "-p", then you
 # may have to run ranlib on the installed liblua.a (do "make ranlib").
-INSTALL= install -p
+INSTALL?= install -p
+INSTALL_LINK= ln -s
 INSTALL_EXEC= $(INSTALL) -m 0755
 INSTALL_DATA= $(INSTALL) -m 0644
 #
@@ -33,7 +34,7 @@
 
 # Utilities.
 MKDIR= mkdir -p
-RANLIB= ranlib
+RANLIB?= ranlib
 
 # == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========
 
@@ -47,13 +48,17 @@
 TO_MAN= lua.1 luac.1
 
 # Lua version and release.
+M= 5
 V= 5.1
 R= 5.1.5
 
+# Export to sub-make
+export M R
+
 all:	$(PLAT)
 
 $(PLATS) clean:
-	cd src && $(MAKE) $@
+	cd src && $(MKDIR) .libs && $(MAKE) $@
 
 test:	dummy
 	src/lua test/hello.lua
@@ -61,6 +66,8 @@
 install: dummy
 	cd src && $(MKDIR) $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN) $(INSTALL_LMOD) $(INSTALL_CMOD)
 	cd src && $(INSTALL_EXEC) $(TO_BIN) $(INSTALL_BIN)
+	cd src && $(INSTALL_EXEC) $(TO_LIB:.a=.so.$(R)) $(INSTALL_LIB)
+	cd src && $(INSTALL_LINK) $(TO_LIB:.a=.so.$(R)) $(INSTALL_LIB)/$(TO_LIB:.a=.so.$(M))
 	cd src && $(INSTALL_DATA) $(TO_INC) $(INSTALL_INC)
 	cd src && $(INSTALL_DATA) $(TO_LIB) $(INSTALL_LIB)
 	cd doc && $(INSTALL_DATA) $(TO_MAN) $(INSTALL_MAN)
--- old/src/Makefile	2012-02-13 21:41:22.000000000 +0100
+++ new/src/Makefile	2019-07-12 11:31:02.945290602 +0200
@@ -7,12 +7,14 @@
 # Your platform. See PLATS for possible values.
 PLAT= none
 
-CC= gcc
-CFLAGS= -O2 -Wall $(MYCFLAGS)
-AR= ar rcu
-RANLIB= ranlib
+CC?= gcc
+CFLAGS?= -O2 -Wall $(MYCFLAGS)
+SOFLAGS= -shared -fPIC -DPIC -Wl,-O1 -Wl,--as-needed -Wl,-soname -Wl,$(LUA_A:.a=.so.$(M)) $(MYLDFLAGS)
+AR?= ar
+ARFLAGS?= rcu
+RANLIB?= ranlib
 RM= rm -f
-LIBS= -lm $(MYLIBS)
+LIBS?= -lm $(MYLIBS)
 
 MYCFLAGS=
 MYLDFLAGS=
@@ -35,8 +37,11 @@
 LUAC_T=	luac
 LUAC_O=	luac.o print.o
 
-ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O)
-ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T)
+LUAS_T=	$(LUA_A:.a=.so.$(R))
+LUAS_O=	$(addprefix .libs/,$(CORE_O) $(LIB_O) $(LUA_O))
+
+ALL_O= $(CORE_O) $(LIB_O) $(LUA_O) $(LUAC_O) $(LUAS_O)
+ALL_T= $(LUA_A) $(LUA_T) $(LUAC_T) $(LUAS_T)
 ALL_A= $(LUA_A)
 
 default: $(PLAT)
@@ -48,9 +53,12 @@
 a:	$(ALL_A)
 
 $(LUA_A): $(CORE_O) $(LIB_O)
-	$(AR) $@ $(CORE_O) $(LIB_O)	# DLL needs all object files
+	$(AR) $(ARFLAGS) $@ $(CORE_O) $(LIB_O)	# DLL needs all object files
 	$(RANLIB) $@
 
+$(LUAS_T): $(LUAS_O)
+	$(CC) -o $@ $(SOFLAGS) $(LUAS_O) $(LIBS)
+
 $(LUA_T): $(LUA_O) $(LUA_A)
 	$(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
 
@@ -67,7 +75,7 @@
 	@echo "PLAT = $(PLAT)"
 	@echo "CC = $(CC)"
 	@echo "CFLAGS = $(CFLAGS)"
-	@echo "AR = $(AR)"
+	@echo "AR = $(AR) $(ARFLAGS)"
 	@echo "RANLIB = $(RANLIB)"
 	@echo "RM = $(RM)"
 	@echo "MYCFLAGS = $(MYCFLAGS)"
@@ -120,6 +128,9 @@
 
 # DO NOT DELETE
 
+.libs/%o: %c
+	$(CC) $(CFLAGS) -fPIC -DPIC -c -o $@ $<
+
 lapi.o: lapi.c lua.h luaconf.h lapi.h lobject.h llimits.h ldebug.h \
   lstate.h ltm.h lzio.h lmem.h ldo.h lfunc.h lgc.h lstring.h ltable.h \
   lundump.h lvm.h
