2014-03-01 23:38:13 -06:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
# file at the top-level directory of this distribution and at
|
|
|
|
# http://rust-lang.org/COPYRIGHT.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
# option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
|
|
|
|
|
|
|
msg() {
|
|
|
|
echo "install: $1"
|
|
|
|
}
|
|
|
|
|
|
|
|
step_msg() {
|
|
|
|
msg
|
|
|
|
msg "$1"
|
|
|
|
msg
|
|
|
|
}
|
|
|
|
|
|
|
|
warn() {
|
|
|
|
echo "install: WARNING: $1"
|
|
|
|
}
|
|
|
|
|
|
|
|
err() {
|
|
|
|
echo "install: error: $1"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
need_ok() {
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
err "$1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
putvar() {
|
|
|
|
local T
|
|
|
|
eval T=\$$1
|
|
|
|
eval TLEN=\${#$1}
|
|
|
|
if [ $TLEN -gt 35 ]
|
|
|
|
then
|
|
|
|
printf "install: %-20s := %.35s ...\n" $1 "$T"
|
|
|
|
else
|
|
|
|
printf "install: %-20s := %s %s\n" $1 "$T" "$2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
valopt() {
|
|
|
|
VAL_OPTIONS="$VAL_OPTIONS $1"
|
|
|
|
|
|
|
|
local OP=$1
|
|
|
|
local DEFAULT=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
local DOC="$*"
|
|
|
|
if [ $HELP -eq 0 ]
|
|
|
|
then
|
|
|
|
local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
|
|
|
|
local V="CFG_${UOP}"
|
|
|
|
eval $V="$DEFAULT"
|
|
|
|
for arg in $CFG_ARGS
|
|
|
|
do
|
|
|
|
if echo "$arg" | grep -q -- "--$OP="
|
|
|
|
then
|
|
|
|
val=$(echo "$arg" | cut -f2 -d=)
|
|
|
|
eval $V=$val
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
putvar $V
|
|
|
|
else
|
|
|
|
if [ -z "$DEFAULT" ]
|
|
|
|
then
|
|
|
|
DEFAULT="<none>"
|
|
|
|
fi
|
|
|
|
OP="${OP}=[${DEFAULT}]"
|
|
|
|
printf " --%-30s %s\n" "$OP" "$DOC"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
opt() {
|
|
|
|
BOOL_OPTIONS="$BOOL_OPTIONS $1"
|
|
|
|
|
|
|
|
local OP=$1
|
|
|
|
local DEFAULT=$2
|
|
|
|
shift
|
|
|
|
shift
|
|
|
|
local DOC="$*"
|
|
|
|
local FLAG=""
|
|
|
|
|
|
|
|
if [ $DEFAULT -eq 0 ]
|
|
|
|
then
|
|
|
|
FLAG="enable"
|
|
|
|
else
|
|
|
|
FLAG="disable"
|
|
|
|
DOC="don't $DOC"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $HELP -eq 0 ]
|
|
|
|
then
|
|
|
|
for arg in $CFG_ARGS
|
|
|
|
do
|
|
|
|
if [ "$arg" = "--${FLAG}-${OP}" ]
|
|
|
|
then
|
|
|
|
OP=$(echo $OP | tr 'a-z-' 'A-Z_')
|
|
|
|
FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
|
|
|
|
local V="CFG_${FLAG}_${OP}"
|
|
|
|
eval $V=1
|
|
|
|
putvar $V
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
if [ ! -z "$META" ]
|
|
|
|
then
|
|
|
|
OP="$OP=<$META>"
|
|
|
|
fi
|
|
|
|
printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
flag() {
|
|
|
|
BOOL_OPTIONS="$BOOL_OPTIONS $1"
|
|
|
|
|
|
|
|
local OP=$1
|
|
|
|
shift
|
|
|
|
local DOC="$*"
|
|
|
|
|
|
|
|
if [ $HELP -eq 0 ]
|
|
|
|
then
|
|
|
|
for arg in $CFG_ARGS
|
|
|
|
do
|
|
|
|
if [ "$arg" = "--${OP}" ]
|
|
|
|
then
|
|
|
|
OP=$(echo $OP | tr 'a-z-' 'A-Z_')
|
|
|
|
local V="CFG_${OP}"
|
|
|
|
eval $V=1
|
|
|
|
putvar $V
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
if [ ! -z "$META" ]
|
|
|
|
then
|
|
|
|
OP="$OP=<$META>"
|
|
|
|
fi
|
|
|
|
printf " --%-30s %s\n" "$OP" "$DOC"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
validate_opt () {
|
|
|
|
for arg in $CFG_ARGS
|
|
|
|
do
|
|
|
|
isArgValid=0
|
|
|
|
for option in $BOOL_OPTIONS
|
|
|
|
do
|
|
|
|
if test --disable-$option = $arg
|
|
|
|
then
|
|
|
|
isArgValid=1
|
|
|
|
fi
|
|
|
|
if test --enable-$option = $arg
|
|
|
|
then
|
|
|
|
isArgValid=1
|
|
|
|
fi
|
|
|
|
if test --$option = $arg
|
|
|
|
then
|
|
|
|
isArgValid=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for option in $VAL_OPTIONS
|
|
|
|
do
|
|
|
|
if echo "$arg" | grep -q -- "--$option="
|
|
|
|
then
|
|
|
|
isArgValid=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ "$arg" = "--help" ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
echo "No more help available for Configure options,"
|
|
|
|
echo "check the Wiki or join our IRC channel"
|
|
|
|
break
|
|
|
|
else
|
|
|
|
if test $isArgValid -eq 0
|
|
|
|
then
|
|
|
|
err "Option '$arg' is not recognized"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-03-28 17:48:49 -05:00
|
|
|
absolutify() {
|
|
|
|
FILE_PATH="${1}"
|
|
|
|
FILE_PATH_DIRNAME="$(dirname ${FILE_PATH})"
|
|
|
|
FILE_PATH_BASENAME="$(basename ${FILE_PATH})"
|
|
|
|
FILE_ABS_PATH="$(cd ${FILE_PATH_DIRNAME} && pwd)"
|
|
|
|
FILE_PATH="${FILE_ABS_PATH}/${FILE_PATH_BASENAME}"
|
|
|
|
# This is the return value
|
|
|
|
ABSOLUTIFIED="${FILE_PATH}"
|
|
|
|
}
|
|
|
|
|
2014-03-01 23:38:13 -06:00
|
|
|
CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
|
|
|
|
CFG_SELF="$0"
|
|
|
|
CFG_ARGS="$@"
|
|
|
|
|
|
|
|
HELP=0
|
|
|
|
if [ "$1" = "--help" ]
|
|
|
|
then
|
|
|
|
HELP=1
|
|
|
|
shift
|
|
|
|
echo
|
|
|
|
echo "Usage: $CFG_SELF [options]"
|
|
|
|
echo
|
|
|
|
echo "Options:"
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
step_msg "processing $CFG_SELF args"
|
|
|
|
fi
|
|
|
|
|
|
|
|
OPTIONS=""
|
|
|
|
BOOL_OPTIONS=""
|
|
|
|
VAL_OPTIONS=""
|
|
|
|
|
|
|
|
flag uninstall "only uninstall from the installation prefix"
|
2014-03-28 04:43:31 -05:00
|
|
|
opt verify 1 "verify that the installed binaries run correctly"
|
2014-03-01 23:38:13 -06:00
|
|
|
valopt prefix "/usr/local" "set installation prefix"
|
2014-03-25 23:25:43 -05:00
|
|
|
# NB This isn't quite the same definition as in `configure`.
|
|
|
|
# just using 'lib' instead of CFG_LIBDIR_RELATIVE
|
|
|
|
valopt libdir "${CFG_PREFIX}/lib" "install libraries"
|
|
|
|
valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
|
2014-03-01 23:38:13 -06:00
|
|
|
|
|
|
|
if [ $HELP -eq 1 ]
|
|
|
|
then
|
|
|
|
echo
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
step_msg "validating $CFG_SELF args"
|
|
|
|
validate_opt
|
|
|
|
|
2014-03-26 20:51:55 -05:00
|
|
|
|
|
|
|
# OK, let's get installing ...
|
|
|
|
|
2014-03-28 04:43:31 -05:00
|
|
|
# Sanity check: can we run the binaries?
|
|
|
|
if [ -z "${CFG_DISABLE_VERIFY}" ]
|
|
|
|
then
|
2014-03-28 16:57:08 -05:00
|
|
|
# Don't do this if uninstalling. Failure here won't help in any way.
|
|
|
|
if [ -z "${CFG_UNINSTALL}" ]
|
|
|
|
then
|
|
|
|
msg "verifying platform can run binaries"
|
|
|
|
"${CFG_SRC_DIR}/bin/rustc" --version > /dev/null
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
err "can't execute rustc binary on this platform"
|
|
|
|
fi
|
|
|
|
fi
|
2014-03-28 04:43:31 -05:00
|
|
|
fi
|
|
|
|
|
2014-03-09 16:16:41 -05:00
|
|
|
# Sanity check: can we can write to the destination?
|
2014-03-28 04:43:31 -05:00
|
|
|
msg "verifying destination is writable"
|
2014-03-25 23:25:43 -05:00
|
|
|
umask 022 && mkdir -p "${CFG_LIBDIR}"
|
2014-03-28 04:43:31 -05:00
|
|
|
need_ok "can't write to destination. consider \`sudo\`."
|
|
|
|
touch "${CFG_LIBDIR}/rust-install-probe" > /dev/null
|
2014-03-09 16:16:41 -05:00
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2014-03-28 04:43:31 -05:00
|
|
|
err "can't write to destination. consider \`sudo\`."
|
2014-03-09 16:16:41 -05:00
|
|
|
fi
|
2014-03-28 16:57:08 -05:00
|
|
|
rm -f "${CFG_LIBDIR}/rust-install-probe"
|
2014-03-09 16:16:41 -05:00
|
|
|
need_ok "failed to remove install probe"
|
|
|
|
|
2014-03-26 20:51:55 -05:00
|
|
|
# Sanity check: don't install to the directory containing the installer.
|
|
|
|
# That would surely cause chaos.
|
2014-03-28 04:43:31 -05:00
|
|
|
msg "verifying destination is not the same as source"
|
2014-03-26 20:51:55 -05:00
|
|
|
INSTALLER_DIR="$(cd $(dirname $0) && pwd)"
|
|
|
|
PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)"
|
|
|
|
if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
|
|
|
|
then
|
|
|
|
err "can't install to same directory as installer"
|
|
|
|
fi
|
|
|
|
|
2014-03-28 17:48:49 -05:00
|
|
|
# Using an absolute path to libdir in a few places so that the status
|
|
|
|
# messages are consistently using absolute paths.
|
|
|
|
absolutify "${CFG_LIBDIR}"
|
|
|
|
ABS_LIBDIR="${ABSOLUTIFIED}"
|
|
|
|
|
2014-03-26 14:06:35 -05:00
|
|
|
# The file name of the manifest we're going to create during install
|
2014-03-28 17:48:49 -05:00
|
|
|
INSTALLED_MANIFEST="${ABS_LIBDIR}/rustlib/manifest"
|
2014-03-21 19:31:18 -05:00
|
|
|
|
2014-03-21 22:12:51 -05:00
|
|
|
# First, uninstall from the installation prefix.
|
|
|
|
# Errors are warnings - try to rm everything in the manifest even if some fail.
|
2014-03-25 23:25:43 -05:00
|
|
|
if [ -f "${INSTALLED_MANIFEST}" ]
|
2014-03-01 23:38:13 -06:00
|
|
|
then
|
2014-03-21 22:12:51 -05:00
|
|
|
# Iterate through installed manifest and remove files
|
2014-03-09 16:56:37 -05:00
|
|
|
while read p; do
|
2014-03-25 23:25:43 -05:00
|
|
|
# The installed manifest contains absolute paths
|
|
|
|
msg "removing $p"
|
|
|
|
if [ -f "$p" ]
|
2014-03-21 22:12:51 -05:00
|
|
|
then
|
2014-03-28 16:57:08 -05:00
|
|
|
rm -f "$p"
|
2014-03-21 22:12:51 -05:00
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2014-03-25 23:25:43 -05:00
|
|
|
warn "failed to remove $p"
|
2014-03-21 22:12:51 -05:00
|
|
|
fi
|
|
|
|
else
|
2014-03-25 23:25:43 -05:00
|
|
|
warn "supposedly installed file $p does not exist!"
|
2014-03-21 22:12:51 -05:00
|
|
|
fi
|
2014-03-25 23:25:43 -05:00
|
|
|
done < "${INSTALLED_MANIFEST}"
|
2014-03-01 23:38:13 -06:00
|
|
|
|
2014-03-28 16:57:08 -05:00
|
|
|
# If we fail to remove rustlib below, then the installed manifest will
|
|
|
|
# still be full; the installed manifest needs to be empty before install.
|
2014-03-28 17:48:49 -05:00
|
|
|
msg "removing ${INSTALLED_MANIFEST}"
|
|
|
|
rm -f "${INSTALLED_MANIFEST}"
|
2014-03-28 16:57:08 -05:00
|
|
|
# For the above reason, this is a hard error
|
|
|
|
need_ok "failed to remove installed manifest"
|
2014-03-28 04:43:31 -05:00
|
|
|
|
2014-03-01 23:38:13 -06:00
|
|
|
# Remove 'rustlib' directory
|
2014-03-28 17:48:49 -05:00
|
|
|
msg "removing ${ABS_LIBDIR}/rustlib"
|
|
|
|
rm -Rf "${ABS_LIBDIR}/rustlib"
|
2014-03-21 22:12:51 -05:00
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
warn "failed to remove rustlib"
|
|
|
|
fi
|
2014-03-21 19:31:18 -05:00
|
|
|
else
|
2014-03-26 14:06:35 -05:00
|
|
|
# There's no manifest. If we were asked to uninstall, then that's a problem.
|
2014-03-21 19:31:18 -05:00
|
|
|
if [ -n "${CFG_UNINSTALL}" ]
|
|
|
|
then
|
2014-03-25 23:25:43 -05:00
|
|
|
err "unable to find installation manifest at ${CFG_LIBDIR}/rustlib"
|
2014-03-21 19:31:18 -05:00
|
|
|
fi
|
2014-03-01 23:38:13 -06:00
|
|
|
fi
|
|
|
|
|
|
|
|
# If we're only uninstalling then exit
|
|
|
|
if [ -n "${CFG_UNINSTALL}" ]
|
|
|
|
then
|
2014-03-21 22:12:51 -05:00
|
|
|
echo
|
|
|
|
echo " Rust is uninstalled. Have a nice day."
|
|
|
|
echo
|
2014-03-09 16:56:37 -05:00
|
|
|
exit 0
|
2014-03-01 23:38:13 -06:00
|
|
|
fi
|
|
|
|
|
2014-03-25 23:25:43 -05:00
|
|
|
# Create the installed manifest, which we will fill in with absolute file paths
|
|
|
|
mkdir -p "${CFG_LIBDIR}/rustlib"
|
2014-03-28 17:59:20 -05:00
|
|
|
need_ok "failed to create rustlib"
|
2014-03-25 23:25:43 -05:00
|
|
|
touch "${INSTALLED_MANIFEST}"
|
2014-03-28 17:48:49 -05:00
|
|
|
need_ok "failed to create installed manifest"
|
2014-03-21 22:12:51 -05:00
|
|
|
|
|
|
|
# Now install, iterate through the new manifest and copy files
|
2014-03-01 23:38:13 -06:00
|
|
|
while read p; do
|
|
|
|
|
2014-03-25 23:25:43 -05:00
|
|
|
# Decide the destination of the file
|
|
|
|
FILE_INSTALL_PATH="${CFG_PREFIX}/$p"
|
|
|
|
|
|
|
|
if echo "$p" | grep "^lib/" > /dev/null
|
|
|
|
then
|
|
|
|
pp=`echo $p | sed 's/^lib\///'`
|
|
|
|
FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if echo "$p" | grep "^share/man/" > /dev/null
|
|
|
|
then
|
|
|
|
pp=`echo $p | sed 's/^share\/man\///'`
|
|
|
|
FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
|
|
|
|
fi
|
|
|
|
|
2014-03-26 14:06:35 -05:00
|
|
|
# Make sure there's a directory for it
|
2014-03-25 23:25:43 -05:00
|
|
|
umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
|
2014-03-09 16:56:37 -05:00
|
|
|
need_ok "directory creation failed"
|
|
|
|
|
2014-03-25 23:25:43 -05:00
|
|
|
# Make the path absolute so we can uninstall it later without
|
|
|
|
# starting from the installation cwd
|
2014-03-28 17:48:49 -05:00
|
|
|
absolutify "${FILE_INSTALL_PATH}"
|
|
|
|
FILE_INSTALL_PATH="${ABSOLUTIFIED}"
|
2014-03-25 23:25:43 -05:00
|
|
|
|
|
|
|
# Install the file
|
|
|
|
msg "${FILE_INSTALL_PATH}"
|
|
|
|
if echo "$p" | grep "^bin/" > /dev/null
|
2014-03-09 16:56:37 -05:00
|
|
|
then
|
2014-03-25 23:25:43 -05:00
|
|
|
install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
|
2014-03-09 16:56:37 -05:00
|
|
|
else
|
2014-03-25 23:25:43 -05:00
|
|
|
install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
|
2014-03-09 16:56:37 -05:00
|
|
|
fi
|
|
|
|
need_ok "file creation failed"
|
2014-03-01 23:38:13 -06:00
|
|
|
|
2014-03-25 23:25:43 -05:00
|
|
|
# Update the manifest
|
|
|
|
echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
|
|
|
|
need_ok "failed to update manifest"
|
|
|
|
|
2014-03-01 23:38:13 -06:00
|
|
|
# The manifest lists all files to install
|
2014-03-26 14:06:35 -05:00
|
|
|
done < "${CFG_SRC_DIR}/lib/rustlib/manifest.in"
|
2014-03-09 16:16:41 -05:00
|
|
|
|
2014-03-28 04:43:31 -05:00
|
|
|
# Sanity check: can we run the installed binaries?
|
|
|
|
if [ -z "${CFG_DISABLE_VERIFY}" ]
|
|
|
|
then
|
|
|
|
msg "verifying installed binaries are executable"
|
|
|
|
"${CFG_PREFIX}/bin/rustc" --version > /dev/null
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
2014-03-28 17:02:46 -05:00
|
|
|
ERR="can't execute installed rustc binary. "
|
|
|
|
ERR="${ERR}installation may be broken. "
|
|
|
|
ERR="${ERR}if this is expected then rerun install.sh with \`--disable-verify\` "
|
|
|
|
ERR="${ERR}or \`make install\` with \`--disable-verify-install\`"
|
|
|
|
err "${ERR}"
|
2014-03-28 04:43:31 -05:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2014-03-09 16:16:41 -05:00
|
|
|
echo
|
|
|
|
echo " Rust is ready to roll."
|
|
|
|
echo
|
|
|
|
|
|
|
|
|