513 lines
14 KiB
Bash
Executable File
513 lines
14 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Defaults
|
|
|
|
prefix="/usr/local"
|
|
sysconfdir="$prefix/etc"
|
|
rocks_tree="$prefix"
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# FUNCTION DEFINITIONS
|
|
# ----------------------------------------------------------------------------
|
|
|
|
# Utility functions
|
|
# -----------------
|
|
|
|
# Resolves a full path
|
|
# - alternative to "readlink -f", which is not available on solaris
|
|
# based on https://stackoverflow.com/a/6554854/1793220
|
|
canonicalpath() {
|
|
oldpwd="$PWD"
|
|
if [ -d "$1" ]
|
|
then
|
|
if cd "$1" >/dev/null 2>&1
|
|
then
|
|
echo "$PWD"
|
|
else
|
|
echo "$1"
|
|
fi
|
|
else
|
|
if cd "$(dirname "$1")" >/dev/null 2>&1
|
|
then
|
|
if [ "$PWD" = "/" ]
|
|
then
|
|
echo "/$(basename "$1")"
|
|
else
|
|
echo "$PWD/$(basename "$1")"
|
|
fi
|
|
else
|
|
echo "$1"
|
|
fi
|
|
fi
|
|
cd "$oldpwd" >/dev/null 2>&1 || return
|
|
}
|
|
|
|
find_program() {
|
|
prog=$(command -v "$1" 2>/dev/null)
|
|
if [ -n "$prog" ]
|
|
then
|
|
dirname "$prog"
|
|
fi
|
|
}
|
|
|
|
die() {
|
|
echo "$*"
|
|
echo
|
|
RED "configure failed."
|
|
echo
|
|
echo
|
|
exit 1
|
|
}
|
|
|
|
echo_n() {
|
|
printf "%s" "$*"
|
|
}
|
|
|
|
bold='\033[1m'
|
|
red='\033[1;31m'
|
|
green='\033[1;32m'
|
|
blue='\033[1;36m'
|
|
reset='\033[0m'
|
|
|
|
BOLD() {
|
|
printf "$bold%s$reset" "$*"
|
|
}
|
|
|
|
RED() {
|
|
printf "$red%s$reset" "$*"
|
|
}
|
|
|
|
GREEN() {
|
|
printf "$green%s$reset" "$*"
|
|
}
|
|
|
|
BLUE() {
|
|
printf "$blue%s$reset" "$*"
|
|
}
|
|
|
|
# Help
|
|
# ----
|
|
|
|
show_help() {
|
|
cat <<EOF
|
|
Usage: ./configure [OPTION]...
|
|
|
|
Defaults for the options are specified in brackets.
|
|
|
|
Configuration:
|
|
-h, --help display this help and exit
|
|
|
|
Installation directories:
|
|
--prefix=PREFIX Directory where LuaRocks should be installed
|
|
[/usr/local]
|
|
|
|
By default, \`make install' will install all the files in \`/usr/local',
|
|
\`/usr/local/lib' etc. You can specify an installation prefix other than
|
|
\`/usr/local/' using \`--prefix', for instance \`--prefix=\$HOME'.
|
|
|
|
For better control, use the options below.
|
|
|
|
Fine tuning of the installation directories:
|
|
--sysconfdir=SYSCONFDIR Directory for single-machine config [PREFIX/etc]
|
|
|
|
Where to install files provided by rocks:
|
|
--rocks-tree=DIR Root of the local tree of installed rocks.
|
|
To make files installed in this location
|
|
accessible to Lua and your \$PATH, see
|
|
"luarocks path --help" after installation.
|
|
Avoid using paths controlled by your
|
|
system's package manager, such as /usr.
|
|
- Default is [PREFIX]
|
|
|
|
Where is your Lua interpreter:
|
|
--lua-version=VERSION Use specific Lua version: 5.1, 5.2, 5.3, or 5.4
|
|
- Default is auto-detected.
|
|
--with-lua-bin=LUA_BINDIR Location of your Lua binar(y/ies).
|
|
- Default is the directory of the
|
|
auto-detected Lua interpreter,
|
|
(or DIR/bin if --with-lua is used)
|
|
--with-lua=LUA_DIR Use Lua from given directory. [LUA_BINDIR/..]
|
|
--with-lua-include=DIR Lua's includes dir. [LUA_DIR/include]
|
|
--with-lua-lib=DIR Lua's libraries dir. [LUA_DIR/lib]
|
|
--with-lua-interpreter=NAME Lua interpreter name.
|
|
- Default is to auto-detected
|
|
|
|
For specialized uses of LuaRocks:
|
|
--force-config Force using a single config location.
|
|
Do not honor the \$LUAROCKS_CONFIG_5_x
|
|
or \$LUAROCKS_CONFIG environment
|
|
variable or the user's local config.
|
|
Useful to avoid conflicts when LuaRocks
|
|
is embedded within an application.
|
|
--disable-incdir-check If you do not wish to use "luarocks build",
|
|
(e.g. when only deploying binary packages)
|
|
you do not need lua.h installed. This flag
|
|
skips the check for lua.h in "configure".
|
|
|
|
EOF
|
|
}
|
|
|
|
# Lua detection
|
|
# -------------
|
|
|
|
detect_lua_version() {
|
|
detected_lua=$($1 -e 'print(_VERSION:match(" (5%.[1234])$"))' 2> /dev/null)
|
|
if [ "$detected_lua" != "nil" ]
|
|
then
|
|
if [ "$LUA_VERSION_SET" != "yes" ]
|
|
then
|
|
echo "Lua version detected: $(GREEN "$detected_lua")"
|
|
LUA_VERSION=$detected_lua
|
|
return 0
|
|
elif [ "$LUA_VERSION" = "$detected_lua" ]
|
|
then
|
|
return 0
|
|
fi
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
search_interpreter() {
|
|
name="$1"
|
|
lua_at=""
|
|
if [ "$LUA_BINDIR_SET" = "yes" ]
|
|
then
|
|
lua_at="$LUA_BINDIR"
|
|
elif [ "$LUA_DIR_SET" = "yes" ]
|
|
then
|
|
LUA_BINDIR="$LUA_DIR/bin"
|
|
if [ -f "$LUA_BINDIR/$name" ]
|
|
then
|
|
lua_at="$LUA_BINDIR"
|
|
fi
|
|
else
|
|
lua_at=$(find_program "$name")
|
|
fi
|
|
if [ -n "$lua_at" ] && [ -x "$lua_at/$name" ]
|
|
then
|
|
if detect_lua_version "$lua_at/$name"
|
|
then
|
|
echo "Lua interpreter found: $(GREEN "$lua_at/$name")"
|
|
if [ "$LUA_BINDIR_SET" != "yes" ]
|
|
then
|
|
LUA_BINDIR="$lua_at"
|
|
fi
|
|
if [ "$LUA_DIR_SET" != "yes" ]
|
|
then
|
|
LUA_DIR=$(dirname "$lua_at")
|
|
fi
|
|
LUA_INTERPRETER="$name"
|
|
return 0
|
|
fi
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# 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 "$(RED WARNING:) the '~' sign is not expanded in flags."
|
|
echo "If you mean the home directory, use \$HOME instead."
|
|
echo
|
|
fi
|
|
case "$key" in
|
|
|
|
# Help
|
|
# ----
|
|
-h|--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
|
|
# Where to install LuaRocks:
|
|
# --------------------------
|
|
--prefix)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
prefix="$(canonicalpath "$value")"
|
|
prefix_SET=yes
|
|
;;
|
|
--sysconfdir)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
sysconfdir="$(canonicalpath "$value")"
|
|
sysconfdir_SET=yes
|
|
;;
|
|
|
|
|
|
# Where to install files provided by rocks:
|
|
# -----------------------------------------
|
|
--rocks-tree)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
rocks_tree="$(canonicalpath "$value")"
|
|
rocks_tree_SET=yes
|
|
;;
|
|
|
|
# Where is your Lua interpreter:
|
|
# ------------------------------
|
|
--lua-version|--with-lua-version)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
LUA_VERSION="$value"
|
|
case "$LUA_VERSION" in
|
|
5.1|5.2|5.3|5.4) ;;
|
|
*) die "Invalid Lua version in flag $key."
|
|
esac
|
|
LUA_VERSION_SET=yes
|
|
;;
|
|
--with-lua)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
LUA_DIR="$(canonicalpath "$value")"
|
|
[ -d "$LUA_DIR" ] || die "Bad value for --with-lua: $LUA_DIR is not a valid directory."
|
|
LUA_DIR_SET=yes
|
|
;;
|
|
--with-lua-bin)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
LUA_BINDIR="$(canonicalpath "$value")"
|
|
[ -d "$LUA_BINDIR" ] || die "Bad value for --with-lua-bin: $LUA_BINDIR is not a valid directory."
|
|
LUA_BINDIR_SET=yes
|
|
;;
|
|
--with-lua-include)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
LUA_INCDIR="$(canonicalpath "$value")"
|
|
[ -d "$LUA_INCDIR" ] || die "Bad value for --with-lua-include: $LUA_INCDIR is not a valid directory."
|
|
LUA_INCDIR_SET=yes
|
|
;;
|
|
--with-lua-lib)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
LUA_LIBDIR="$(canonicalpath "$value")"
|
|
[ -d "$LUA_LIBDIR" ] || die "Bad value for --with-lua-lib: $LUA_LIBDIR is not a valid directory."
|
|
LUA_LIBDIR_SET=yes
|
|
;;
|
|
--with-lua-interpreter)
|
|
[ -n "$value" ] || die "Missing value in flag $key."
|
|
LUA_INTERPRETER="$value"
|
|
LUA_INTERPRETER_SET=yes
|
|
;;
|
|
|
|
# For specialized uses of LuaRocks:
|
|
# ---------------------------------
|
|
--force-config)
|
|
FORCE_CONFIG=yes
|
|
;;
|
|
--disable-incdir-check)
|
|
DISABLE_INCDIR_CHECK=yes
|
|
;;
|
|
|
|
# Old options that no longer apply
|
|
# --------------------------------
|
|
--versioned-rocks-dir)
|
|
echo "--versioned-rocks-dir is no longer necessary."
|
|
echo "The rocks tree in LuaRocks 3.0 is always versioned."
|
|
;;
|
|
--lua-suffix)
|
|
echo "--lua-suffix is no longer necessary."
|
|
echo "The suffix is automatically detected."
|
|
;;
|
|
|
|
*)
|
|
die "Error: Unknown flag: $1"
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
echo
|
|
BLUE "Configuring LuaRocks version dev..."
|
|
echo
|
|
echo
|
|
|
|
# ----------------------------------------
|
|
# Derive options from the ones given
|
|
# ----------------------------------------
|
|
|
|
if [ "$prefix_SET" = "yes" ] && [ ! "$sysconfdir_SET" = "yes" ]
|
|
then
|
|
if [ "$prefix" = "/usr" ]
|
|
then sysconfdir=/etc
|
|
else sysconfdir=$prefix/etc
|
|
fi
|
|
sysconfdir_SET=yes
|
|
fi
|
|
|
|
if [ "$prefix_SET" = "yes" ] && [ ! "$rocks_tree_SET" = "yes" ]
|
|
then
|
|
rocks_tree=$prefix
|
|
fi
|
|
|
|
# ----------------------------------------
|
|
# Search for Lua
|
|
# ----------------------------------------
|
|
|
|
lua_interp_found=no
|
|
|
|
case "$LUA_VERSION" in
|
|
5.1)
|
|
names="lua5.1 lua51 lua-5.1 lua-51 luajit lua"
|
|
;;
|
|
5.2)
|
|
names="lua5.2 lua52 lua-5.2 lua-52 lua"
|
|
;;
|
|
5.3)
|
|
names="lua5.3 lua53 lua-5.3 lua-53 lua"
|
|
;;
|
|
5.4)
|
|
names="lua5.4 lua54 lua-5.4 lua-54 lua"
|
|
;;
|
|
*)
|
|
names="lua5.4 lua54 lua-5.4 lua-54 lua5.3 lua53 lua-5.3 lua-53 lua5.2 lua52 lua-5.2 lua-52 lua5.1 lua51 lua-5.1 lua-51 luajit lua"
|
|
;;
|
|
esac
|
|
|
|
if [ "$LUA_INTERPRETER_SET" = "yes" ]
|
|
then
|
|
names="$LUA_INTERPRETER"
|
|
fi
|
|
|
|
for name in $names
|
|
do
|
|
search_interpreter "$name" && {
|
|
lua_interp_found=yes
|
|
break
|
|
}
|
|
done
|
|
|
|
if [ "$lua_interp_found" != "yes" ]
|
|
then
|
|
if [ "$LUA_VERSION_SET" ]
|
|
then
|
|
interp="Lua $LUA_VERSION"
|
|
else
|
|
interp="Lua"
|
|
fi
|
|
if [ "$LUA_DIR_SET" ] || [ "$LUA_BINDIR_SET" ]
|
|
then
|
|
where="$LUA_BINDIR"
|
|
else
|
|
where="\$PATH"
|
|
fi
|
|
echo "$(RED $interp interpreter not found) in $where"
|
|
echo "You may want to use the flags $(BOLD --with-lua), $(BOLD --with-lua-bin) and/or $(BOLD --lua-version)"
|
|
die "Run $(BOLD ./configure --help) for details."
|
|
fi
|
|
|
|
if [ "$LUA_VERSION_SET" = "yes" ]
|
|
then
|
|
echo_n "Checking if $LUA_BINDIR/$LUA_INTERPRETER is Lua version $LUA_VERSION... "
|
|
if detect_lua_version "$LUA_BINDIR/$LUA_INTERPRETER"
|
|
then
|
|
echo "yes"
|
|
else
|
|
echo "no"
|
|
die "You may want to use the flags --with-lua, --with-lua-bin and/or --lua-version. See --help."
|
|
fi
|
|
fi
|
|
|
|
# ----------------------------------------
|
|
# Additional checks
|
|
# ----------------------------------------
|
|
|
|
check_incdir() {
|
|
if [ "$LUA_INCDIR_SET" = "yes" ]
|
|
then
|
|
incdir="$LUA_INCDIR"
|
|
else
|
|
incdir="$LUA_DIR/include"
|
|
fi
|
|
|
|
tried=""
|
|
# Verification of the Lua include path happens at LuaRocks runtime,
|
|
# but we also perform it here just so that the user gets an early failure
|
|
# if they try to install LuaRocks with the Lua interpreter package
|
|
# but not the "development files" that many Linux distros ship separately.
|
|
for lua_h in \
|
|
"$incdir/lua/$LUA_VERSION/lua.h" \
|
|
"$incdir/lua$LUA_VERSION/lua.h" \
|
|
"$incdir/lua-$LUA_VERSION/lua.h" \
|
|
"$incdir/lua$(echo "$LUA_VERSION" | tr -d .)/lua.h" \
|
|
"$incdir/lua.h" \
|
|
$("$LUA_BINDIR/$LUA_INTERPRETER" -e 'print(jit and [['"$incdir"'/luajit-]]..jit.version:match("(%d+%.%d+)")..[[/lua.h]] or "")')
|
|
do
|
|
if [ -f "$lua_h" ]
|
|
then
|
|
grep "LUA_VERSION_NUM.*$LUA_VERSION" "$lua_h" > /dev/null 2> /dev/null && return
|
|
fi
|
|
tried="$tried $lua_h"
|
|
done
|
|
|
|
echo "$(RED "lua.h for Lua $LUA_VERSION not found") (tried$tried)"
|
|
echo
|
|
echo "If the development files for Lua (headers and libraries)"
|
|
echo "are installed in your system, you may need to use the"
|
|
echo "$(BOLD --with-lua) or $(BOLD --with-lua-include) flags to specify their location."
|
|
echo
|
|
echo "If those files are not yet installed, you need to install"
|
|
echo "them using the appropriate method for your operating system."
|
|
echo
|
|
die "Run $(BOLD ./configure --help) for details on flags."
|
|
}
|
|
|
|
if [ "$DISABLE_INCDIR_CHECK" != "yes" ]
|
|
then
|
|
check_incdir
|
|
echo "lua.h found: $(GREEN "$lua_h")"
|
|
fi
|
|
|
|
unzip_found=$(find_program "unzip")
|
|
if [ -n "$unzip_found" ]
|
|
then
|
|
echo "unzip found in PATH: $(GREEN "$unzip_found")"
|
|
else
|
|
RED "Could not find 'unzip'."
|
|
echo
|
|
die "Make sure it is installed and available in your PATH."
|
|
fi
|
|
|
|
# ----------------------------------------
|
|
# Write config
|
|
# ----------------------------------------
|
|
|
|
make clean > /dev/null 2> /dev/null
|
|
|
|
rm -f built
|
|
cat <<EOF > config.unix
|
|
# This file was automatically generated by the configure script.
|
|
# Run "./configure --help" for details.
|
|
|
|
prefix=$prefix
|
|
sysconfdir=$sysconfdir
|
|
rocks_tree=$rocks_tree
|
|
LUA_VERSION=$LUA_VERSION
|
|
LUA_INTERPRETER=$LUA_INTERPRETER
|
|
LUA_DIR=$LUA_DIR
|
|
LUA_BINDIR=$LUA_BINDIR
|
|
LUA_INCDIR=$LUA_INCDIR
|
|
LUA_LIBDIR=$LUA_LIBDIR
|
|
FORCE_CONFIG=$FORCE_CONFIG
|
|
EOF
|
|
|
|
echo
|
|
BLUE "Done configuring."
|
|
echo
|
|
echo
|
|
echo "LuaRocks will be installed at......: $(GREEN "$prefix")"
|
|
echo "LuaRocks will install rocks at.....: $(GREEN "$rocks_tree")"
|
|
echo "LuaRocks configuration directory...: $(GREEN "$sysconfdir/luarocks")"
|
|
echo "Using Lua from.....................: $(GREEN "$LUA_DIR")"
|
|
if [ "$LUA_BINDIR_SET" = "yes" ]; then echo "Lua bin directory..................: $(GREEN "$LUA_BINDIR")" ; fi
|
|
if [ "$LUA_INCDIR_SET" = "yes" ]; then echo "Lua include directory..............: $(GREEN "$LUA_INCDIR")" ; fi
|
|
if [ "$LUA_LIBDIR_SET" = "yes" ]; then echo "Lua lib directory..................: $(GREEN "$LUA_LIBDIR")" ; fi
|
|
echo
|
|
echo "* Type $(BOLD make) and $(BOLD make install):"
|
|
echo " to install to $prefix as usual."
|
|
echo "* Type $(BOLD make bootstrap):"
|
|
echo " to install LuaRocks into $rocks_tree as a rock."
|
|
echo
|