]> git.lizzy.rs Git - metalua.git/blobdiff - src/make.sh
spelling fixes to the documentation
[metalua.git] / src / make.sh
old mode 100644 (file)
new mode 100755 (executable)
index 7c90869..188af3d
@@ -1,3 +1,5 @@
+#! /bin/sh
+
 # --- BEGINNING OF USER-EDITABLE PART ---
 
 # Metalua sources
@@ -5,13 +7,30 @@ BASE=${PWD}
 
 # Temporary building location.
 # Upon installation, everything will be moved to ${INSTALL_LIB} and ${INSTALL_BIN}
-BUILD=/tmp/metalua-build
-BUILD_BIN=${BUILD}/bin
-BUILD_LIB=${BUILD}/lib
+
+if [ -z "${BUILD}" ]; then
+  BUILD=$(mkdir -p ../build; cd ../build; pwd)
+fi
+
+if [ -z "${BUILD_BIN}" ]; then
+  BUILD_BIN=${BUILD}/bin
+fi
+
+if [ -z "${BUILD_LIB}" ]; then
+  BUILD_LIB=${BUILD}/lib
+fi
 
 # Where to place the final results
-INSTALL_BIN=/usr/local/bin
-INSTALL_LIB=/usr/local/lib/lua/5.1
+# DESTDIR=
+# INSTALL_BIN=/usr/local/bin
+# INSTALL_LIB=/usr/local/lib/lua/5.1
+if [ -z "${INSTALL_BIN}" ]; then
+  INSTALL_BIN=~/local/bin
+fi
+
+if [ -z "${INSTALL_LIB}" ]; then
+  INSTALL_LIB=~/local/lib/lua
+fi
 
 # Where to find Lua executables.
 # On many Debian-based systems, those can be installed with "sudo apt-get install lua5.1"
@@ -20,6 +39,12 @@ LUAC=$(which luac)
 
 # --- END OF USER-EDITABLE PART ---
 
+if [ -z ${LUA}  ] ; then echo "Error: no lua interpreter found"; fi
+if [ -z ${LUAC} ] ; then echo "Error: no lua compiler found"; fi
+
+if [ -f ~/.metaluabuildrc ] ; then . ~/.metaluabuildrc; fi
+
+if [ -z "$LINEREADER" ] && which -s rlwrap; then LINEREADER=rlwrap; fi
 
 echo '*** Lua paths setup ***'
 
@@ -30,8 +55,8 @@ echo '*** Create the distribution directories, populate them with lib sources **
 
 mkdir -p ${BUILD_BIN}
 mkdir -p ${BUILD_LIB}
-cp -R lib/* ${BUILD_LIB}/
-cp -R bin/* ${BUILD_BIN}/
+cp -Rp lib/* ${BUILD_LIB}/
+# cp -Rp bin/* ${BUILD_BIN}/ # No binaries provided for unix (for now)
 
 echo '*** Generate a callable metalua shell script ***'
 
@@ -77,20 +102,27 @@ cat > make-install.sh <<EOF2
 #!/bin/sh
 mkdir -p ${INSTALL_BIN}
 mkdir -p ${INSTALL_LIB}
-
-cat > ${INSTALL_BIN}/metalua <<EOF
+if [ -n "${DESTDIR}" ]; then
+    mkdir -p ${DESTDIR}${INSTALL_BIN}
+    mkdir -p ${DESTDIR}${INSTALL_LIB}
+fi
+cat > ${DESTDIR}${INSTALL_BIN}/metalua <<EOF
 #!/bin/sh
-export LUA_PATH='?.luac;?.lua;${INSTALL_LIB}/?.luac;${INSTALL_LIB}/?.lua'
-export LUA_MPATH='?.mlua;${INSTALL_LIB}/?.mlua'
-${LUA} ${INSTALL_LIB}/metalua.luac \$*
+METALUA_LIB=${INSTALL_LIB}
+export LUA_PATH="?.luac;?.lua;\\\${METALUA_LIB}/?.luac;\\\${METALUA_LIB}/?.lua"
+export LUA_MPATH="?.mlua;\\\${METALUA_LIB}/?.mlua"
+exec ${LINEREADER} ${LUA} \\\${METALUA_LIB}/metalua.luac "\\\$@"
 EOF
 
-chmod a+x ${INSTALL_BIN}/metalua
+chmod a+x ${DESTDIR}${INSTALL_BIN}/metalua
 
-cp -R ${BUILD_LIB}/* ${INSTALL_LIB}/
+cp -pR ${BUILD_LIB}/* ${DESTDIR}${INSTALL_LIB}/
+
+echo "metalua libs installed in ${INSTALL_LIB};"
+echo "metalua executable in ${INSTALL_BIN}."
 EOF2
 chmod a+x make-install.sh
 
 echo
 echo "Build completed, proceed to installation with './make-install.sh' or 'sudo ./make-install.sh'"
-echo
\ No newline at end of file
+echo