view luabuild/luarocks-2.0.12/configure @ 1374:b0e33c9686bf

<hagb4rd> learn quote-fromatting "two spaces between quoted lines. only one space on each side of [...] ellipses. no space between nicks and the surrounding <>\'s."
author HackBot
date Fri, 11 Jan 2013 13:00:41 +0000
parents 87f6d05d4b4a
children
line wrap: on
line source

#!/bin/sh

# A basic configure script for LuaRocks.
# Not doing any fancy shell stuff here to keep good compatibility.

# Defaults

PREFIX="/usr/local"
SYSCONFDIR="$PREFIX/etc/luarocks"
ROCKS_TREE="$PREFIX"
LUA_SUFFIX=""
LUA_DIR="/usr"
LUA_BINDIR="/usr/bin"
LUA_INCDIR="/usr/include"
LUA_LIBDIR="/usr/lib"
LUA_VERSION="5.1"

# ----------------------------------------------------------------------------
# FUNCTION DEFINITIONS
# ----------------------------------------------------------------------------

# Help

show_help() {
cat <<EOF
Configure LuaRocks.

--help                      This help.
--prefix=DIR                Prefix where LuaRocks should be installed.
                            Default is $PREFIX
--sysconfdir=DIR            Location where the config file should be installed.
                            Default is \$PREFIX/etc/luarocks

Where to install files installed by rocks, to make the accessible to Lua and
your \$PATH. Beware of clashes between files installed by LuaRocks and by your
system's package manager.

--rocks-tree=FILE           Root of the local tree of installed rocks.
                            Default is \$PREFIX

--lua-version=VERSION       Use specific Lua version: 5.1 or 5.2 (EXPERIMENTAL)
                            Default is "$LUA_VERSION"
--lua-suffix=SUFFIX         Versioning suffix to use in Lua filenames.
                            Default is "$LUA_SUFFIX" (lua$LUA_SUFFIX...)
--with-lua=PREFIX           Use Lua from given prefix.
                            Default is $LUA_DIR
--with-lua-include=DIR      You can also specify Lua's includes dir.
                            Default is \$LUA_DIR/include
--with-lua-lib=DIR          You can also specify Lua's libraries dir.
                            Default is \$LUA_DIR/lib
--with-downloader=TOOL      Which tool to use as a downloader.
                            Valid options are: wget, curl.
                            Default is to auto-detect.
--with-md5-checker=TOOL     Which tool to use as a downloader.
                            Valid options are: md5sum, openssl
                            Default is to auto-detect.
--force-config              Use a single config location. Do not use the
                            \$LUAROCKS_CONFIG variable or the user's home
                            directory. Useful to avoid conflicts when LuaRocks
                            is embedded within an application.
EOF
}

# Helper functions

find_program() {
   path="$PATH"
   item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
   path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
   found="no"
   while [ -n "$item" ]
   do
      if [ -f "$item/$1" ]
      then
         found="yes"
         break
      fi
      item="`echo "$path" | sed 's/\([^:]*\):.*/\1/'`"
      path="`echo "$path" | sed -n 's/[^:]*::*\(.*\)/\1/p'`"
   done
   if [ "$found" = "yes" ]
   then
      echo "$item"
   else
      echo ""
   fi
}

die() {
   echo "$*"
   echo
   echo "configure failed."
   echo
   exit 1
}

find_helper() {
   explanation="$1"
   shift
   tried="$*"
   while [ -n "$1" ]
   do
      found=`find_program "$1"`
      if [ -n "$found" ]
      then
         echo "$1 found at $found"
         HELPER=$1
         return
      fi
      shift
   done
   echo "Could not find a $explanation. Tried: $tried."
   die "Make sure one of them is installed and available in your PATH."
}

case `echo -n x` in
-n*) echo_n_flag='';;
*)   echo_n_flag='-n';;
esac

echo_n() {
   echo $echo_n_flag "$*"
}

# ----------------------------------------------------------------------------
# MAIN PROGRAM
# ----------------------------------------------------------------------------

# Parse options

while [ -n "$1" ]
do
   value="`echo $1 | sed 's/[^=]*.\(.*\)/\1/'`"
   key="`echo $1 | sed 's/=.*//'`"
   if `echo "$value" | grep "~" >/dev/null 2>/dev/null`
   then
      echo
      echo '*WARNING*: the "~" sign is not expanded in flags.'
      echo 'If you mean the home directory, use $HOME instead.'
      echo
   fi
   case "$key" in
   --help)
      show_help
      exit 0
      ;;
   --prefix)
      [ -n "$value" ] || die "Missing value in flag $key."
      PREFIX="$value"
      PREFIX_SET=yes
      ;;
   --sysconfdir)
      [ -n "$value" ] || die "Missing value in flag $key."
      SYSCONFDIR="$value"
      SYSCONFDIR_SET=yes
      ;;
   --rocks-tree)
      [ -n "$value" ] || die "Missing value in flag $key."
      ROCKS_TREE="$value"
      ROCKS_TREE_SET=yes
      ;;
   --force-config)
      FORCE_CONFIG=yes
      ;;
   --lua-suffix)
      [ -n "$value" ] || die "Missing value in flag $key."
      LUA_SUFFIX="$value"
      LUA_SUFFIX_SET=yes
      ;;
   --lua-version)
      [ -n "$value" ] || die "Missing value in flag $key."
      LUA_VERSION="$value"
      [ "$LUA_VERSION" = "5.1" -o "$LUA_VERSION" = "5.2" ] || die "Invalid Lua version in flag $key."
      LUA_VERSION_SET=yes
      ;;
   --with-lua)
      [ -n "$value" ] || die "Missing value in flag $key."
      LUA_DIR="$value"
      LUA_DIR_SET=yes
      ;;
   --with-lua-include)
      [ -n "$value" ] || die "Missing value in flag $key."
      LUA_INCDIR="$value"
      LUA_INCDIR_SET=yes
      ;;
   --with-lua-lib)
      [ -n "$value" ] || die "Missing value in flag $key."
      LUA_LIBDIR="$value"
      LUA_LIBDIR_SET=yes
      ;;
   --with-downloader)
      [ -n "$value" ] || die "Missing value in flag $key."
      case "$value" in
      wget|curl) LUAROCKS_DOWNLOADER="$value" ;;
      *) die "Invalid option: $value. See --help." ;;
      esac
      LUAROCKS_DOWNLOADER_SET=yes
      ;;
   --with-md5-checker)
      [ -n "$value" ] || die "Missing value in flag $key."
      case "$value" in
      md5sum|openssl|md5) LUAROCKS_MD5CHECKER="$value" ;;
      *) die "Invalid option: $value. See --help." ;;
      esac
      LUAROCKS_MD5CHECKER_SET=yes
      ;;
   *)
      die "Error: Unknown flag: $1"
      ;;
   esac
   shift
done

if [ "$PREFIX_SET" = "yes" -a ! "$SYSCONFDIR_SET" = "yes" ]
then
   if [ "$PREFIX" = "/usr" ]
   then SYSCONFDIR=/etc/luarocks
   else SYSCONFDIR=$PREFIX/etc/luarocks
   fi
fi


if [ "$PREFIX_SET" = "yes" -a ! "$ROCKS_TREE_SET" = "yes" ]
then
   ROCKS_TREE=$PREFIX
fi

detect_lua_version() {
   detected_lua=`$1 -e 'print(_VERSION:sub(5))' 2> /dev/null`
   if [ "$detected_lua" = "5.1" -o "$detected_lua" = "5.2" ]
   then
      echo "Lua version detected: $detected_lua"
      if [ "$LUA_VERSION_SET" != "yes" ]
      then
         LUA_VERSION=$detected_lua
      elif [ "$LUA_VERSION" != "$detected_lua" ]
      then
         die "This clashes with the value of --with-lua-version. Please check your configuration."
      fi
   fi
}

search_interpreter() {
   LUA_SUFFIX="$1"
   if [ "$LUA_DIR_SET" = "yes" ]
   then
      if [ -f "$LUA_DIR/bin/lua$suffix" ]
      then
         find_lua="$LUA_DIR/bin"
      fi
   else
      find_lua=`find_program lua$suffix`
   fi
   if [ -n "$find_lua" ]
   then
      echo "Lua interpreter found: $find_lua/lua$suffix..."
      detect_lua_version "$find_lua/lua$suffix"
      return 0
   fi
   return 1
}

if [ "$LUA_SUFFIX_SET" != "yes" ]
then
   if [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.1" ]
   then
      suffixes="5.1 51"
   elif [ "$LUA_VERSION_SET" = "yes" -a "$LUA_VERSION" = "5.2" ]
   then
      suffixes="5.2 52"
   else
      suffixes="5.2 52 5.1 51"
   fi
   for suffix in "" `echo $suffixes` ""
   do
      search_interpreter "$suffix" && break
   done
fi

if [ "$LUA_VERSION" = "5.2" ]
then
   echo "******************************"
   echo "WARNING: Lua 5.2 support is still experimental."
   echo "Bug reports, patches and pull requests are welcome"
   echo "at the GitHub project:"
   echo "http://github.com/keplerproject/luarocks"
   echo "and the mailing list:"
   echo "https://lists.sourceforge.net/lists/listinfo/luarocks-developers"
   echo "******************************"
fi

if [ "$LUA_DIR_SET" != "yes" ]
then
   echo_n "Looking for Lua... "
   if [ ! -n "$find_lua" ]
   then
      find_lua=`find_program lua$LUA_SUFFIX`
   fi

   if [ -n "$find_lua" ]
   then
      LUA_DIR=`dirname $find_lua`
      LUA_BINDIR="$find_lua"
      echo "lua$LUA_SUFFIX found in \$PATH: $find_lua"
   else
      echo "lua$LUA_SUFFIX not found in \$PATH."
      die "You may want to use the flags --with-lua and/or --lua-suffix. See --help."
   fi
fi

if [ "$LUA_INCDIR_SET" != "yes" ]
then
   LUA_INCDIR="$LUA_DIR/include"
fi

if [ "$LUA_LIBDIR_SET" != "yes" ]
then
   LUA_LIBDIR="$LUA_DIR/lib"
fi

if [ "$LUA_DIR_SET" = "yes" ]
then
   LUA_BINDIR="$LUA_DIR/bin"
fi

echo_n "Checking Lua includes... "
lua_h="$LUA_INCDIR/lua.h"
if [ -f "$lua_h" ]
then
   echo "lua.h found in $lua_h"
else
   LUA_INCDIR="$LUA_INCDIR/lua/$LUA_VERSION"
   d_lua_h="$LUA_INCDIR/lua.h"
   if [ -f "$d_lua_h" ]
   then
      echo "lua.h found in $d_lua_h"
   else
      LUA_INCDIR="$LUA_INCDIR/lua$LUA_VERSION"
      d_lua_h="$LUA_INCDIR/lua.h"
      if [ -f "$d_lua_h" ]
      then
         echo "lua.h found in $d_lua_h (Debian/Ubuntu)"
      else
         echo "lua.h not found (looked in $lua_h)"
         die "You may want to use the flag --with-lua-include. See --help."
      fi
   fi
fi

if [ "$LUAROCKS_DOWNLOADER_SET" != "yes" ]
then
   find_helper "downloader helper program" wget curl fetch
   LUAROCKS_DOWNLOADER=$HELPER
fi

if [ "$LUAROCKS_MD5CHECKER_SET" != "yes" ]
then
   find_helper "MD5 checksum calculator" md5sum openssl md5
   LUAROCKS_MD5CHECKER=$HELPER
fi

echo_n "Configuring for system... "
if uname -s
then
   LUAROCKS_UNAME_S=`uname -s`
else
   die "Could not determine operating system. 'uname -s' failed."
fi
echo_n "Configuring for architecture... "
if uname -m
then
   LUAROCKS_UNAME_M=`uname -m`
else
   die "Could not determine processor architecture. 'uname -m' failed."
fi

if [ -f config.unix ]; then
   rm -f config.unix
fi

# Write config

echo "Writing configuration..."
echo

rm -f built
cat <<EOF > config.unix
# This file was automatically generated by the configure script.
# Run "./configure --help" for details.

LUA_VERSION=$LUA_VERSION
PREFIX=$PREFIX
SYSCONFDIR=$SYSCONFDIR
ROCKS_TREE=$ROCKS_TREE
LUA_SUFFIX=$LUA_SUFFIX
LUA_DIR=$LUA_DIR
LUA_DIR_SET=$LUA_DIR_SET
LUA_INCDIR=$LUA_INCDIR
LUA_LIBDIR=$LUA_LIBDIR
LUA_BINDIR=$LUA_BINDIR
FORCE_CONFIG=$FORCE_CONFIG
LUAROCKS_UNAME_M=$LUAROCKS_UNAME_M
LUAROCKS_UNAME_S=$LUAROCKS_UNAME_S
LUAROCKS_DOWNLOADER=$LUAROCKS_DOWNLOADER
LUAROCKS_MD5CHECKER=$LUAROCKS_MD5CHECKER

EOF

echo "Installation prefix: $PREFIX"
echo "LuaRocks configuration directory: $SYSCONFDIR"
echo "Using Lua from: $LUA_DIR"

make clean > /dev/null 2> /dev/null

echo
echo "Done. You can now run 'make' to build."
echo