--- Makefile.orig	Wed Nov  3 09:44:36 2004
+++ Makefile	Wed Nov  3 10:50:34 2004
@@ -22,7 +22,10 @@
 
 # simple test to see Lua working
 test:	all
-	bin/lua test/hello.lua
+	@for ltest in `ls test/*.lua | grep -v life.lua`; do \
+		echo "Running $$ltest ..."; \
+		bin/lua $$ltest; \
+	done
 
 # remove debug information from binaries
 strip:
@@ -30,11 +33,11 @@
 
 # official installation
 install: all strip
-	mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN)
-	$(INSTALL_EXEC) bin/* $(INSTALL_BIN)
-	$(INSTALL_DATA) include/*.h $(INSTALL_INC)
-	$(INSTALL_DATA) lib/*.a $(INSTALL_LIB)
-	$(INSTALL_DATA) doc/*.1 $(INSTALL_MAN)
+	mkdir -p $(DESTDIR)$(INSTALL_BIN) $(DESTDIR)$(INSTALL_INC) $(DESTDIR)$(INSTALL_LIB) $(DESTDIR)$(INSTALL_MAN)
+	$(INSTALL_EXEC) bin/* $(DESTDIR)$(INSTALL_BIN)
+	$(INSTALL_DATA) include/*.h $(DESTDIR)$(INSTALL_INC)
+	$(INSTALL_DATA) lib/*.a $(DESTDIR)$(INSTALL_LIB)
+	$(INSTALL_DATA) doc/*.1 $(DESTDIR)$(INSTALL_MAN)
 
 # shared libraries (for Linux)
 so:
@@ -42,21 +45,35 @@
 	ld -o lib/liblualib.so.$V -shared src/lib/*.o
 	cd lib; ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so
 
+# shared libraries (for Darwin)
+dylib:
+	$(CC) -dynamiclib -flat_namespace -undefined suppress -o lib/liblua.$V.$@ src/*.o -install_name $(INSTALL_LIB)/liblua.$V.$@ -compatibility_version $V -current_version $V
+	$(CC) -dynamiclib -flat_namespace -undefined suppress -o lib/liblualib.$V.$@ src/lib/*.o -install_name $(INSTALL_LIB)/liblualib.$V.$@ -compatibility_version $V -current_version $V
+	cd lib; ln -fs liblua.$V.$@ liblua.$@; ln -fs liblualib.$V.$@ liblualib.$@; ln -fs liblua.$V.$@ liblua.$(V:%.0=%).$@; ln -fs liblualib.$V.$@ liblualib.$(V:%.0=%).$@
+
 # binaries using shared libraries
-sobin:
+sobin dylibbin:
 	rm -f bin/*
 	cd src/lua; $(MAKE)
 	cd src/luac; $(MAKE)
 
 # install shared libraries
 soinstall:
-	$(INSTALL_EXEC) lib/*.so.* $(INSTALL_LIB)
-	cd $(INSTALL_LIB); ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so
+	$(INSTALL_EXEC) lib/*.so.* $(DESTDIR)$(INSTALL_LIB)
+	cd $(DESTDIR)$(INSTALL_LIB); ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so
+
+dylibinstall:
+	$(INSTALL_EXEC) lib/*.dylib $(DESTDIR)$(INSTALL_LIB)/
+	cd $(DESTDIR)$(INSTALL_LIB)/; ln -fs liblua.$V.dylib liblua.dylib; ln -fs liblualib.$V.dylib liblualib.dylib
+	cd $(DESTDIR)$(INSTALL_LIB)/; ln -fs liblua.$V.dylib liblua.$(V:%.0=%).dylib; ln -fs liblualib.$V.dylib liblualib.$(V:%.0=%).dylib
 
 # clean shared libraries
 soclean:
 	rm -f lib/*.so* bin/*
 
+dylibclean:
+	rm -f lib/*.dylib bin/*
+
 # echo config parameters
 echo:
 	@echo ""
@@ -77,6 +94,7 @@
 	@echo "AR = $(AR)"
 	@echo "RANLIB = $(RANLIB)"
 	@echo "STRIP = $(STRIP)"
+	@echo "DESTDIR = $(DESTDIR)"
 	@echo "INSTALL_ROOT = $(INSTALL_ROOT)"
 	@echo "INSTALL_BIN = $(INSTALL_BIN)"
 	@echo "INSTALL_INC = $(INSTALL_INC)"
