2 # Copyright 2014 The Rust Project Developers. See the COPYRIGHT
3 # file at the top-level directory of this distribution and at
4 # http://rust-lang.org/COPYRIGHT.
6 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
7 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
9 # option. This file may not be copied, modified, or distributed
10 # except according to those terms.
23 echo "install: WARNING: $1"
27 echo "install: error: $1"
44 printf "install: %-20s := %.35s ...\n" $1 "$T"
46 printf "install: %-20s := %s %s\n" $1 "$T" "$2"
51 VAL_OPTIONS="$VAL_OPTIONS $1"
60 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
65 if echo "$arg" | grep -q -- "--$OP="
67 val=$(echo "$arg" | cut -f2 -d=)
77 OP="${OP}=[${DEFAULT}]"
78 printf " --%-30s %s\n" "$OP" "$DOC"
83 BOOL_OPTIONS="$BOOL_OPTIONS $1"
104 if [ "$arg" = "--${FLAG}-${OP}" ]
106 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
107 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
108 local V="CFG_${FLAG}_${OP}"
118 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
123 BOOL_OPTIONS="$BOOL_OPTIONS $1"
133 if [ "$arg" = "--${OP}" ]
135 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
146 printf " --%-30s %s\n" "$OP" "$DOC"
154 for option in $BOOL_OPTIONS
156 if test --disable-$option = $arg
160 if test --enable-$option = $arg
164 if test --$option = $arg
169 for option in $VAL_OPTIONS
171 if echo "$arg" | grep -q -- "--$option="
176 if [ "$arg" = "--help" ]
179 echo "No more help available for Configure options,"
180 echo "check the Wiki or join our IRC channel"
183 if test $isArgValid -eq 0
185 err "Option '$arg' is not recognized"
193 FILE_PATH_DIRNAME="$(dirname ${FILE_PATH})"
194 FILE_PATH_BASENAME="$(basename ${FILE_PATH})"
195 FILE_ABS_PATH="$(cd ${FILE_PATH_DIRNAME} && pwd)"
196 FILE_PATH="${FILE_ABS_PATH}/${FILE_PATH_BASENAME}"
197 # This is the return value
198 ABSOLUTIFIED="${FILE_PATH}"
201 CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
206 if [ "$1" = "--help" ]
211 echo "Usage: $CFG_SELF [options]"
216 step_msg "processing $CFG_SELF args"
223 flag uninstall "only uninstall from the installation prefix"
224 opt verify 1 "verify that the installed binaries run correctly"
225 valopt prefix "/usr/local" "set installation prefix"
226 # NB This isn't quite the same definition as in `configure`.
227 # just using 'lib' instead of CFG_LIBDIR_RELATIVE
228 valopt libdir "${CFG_PREFIX}/lib" "install libraries"
229 valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
237 step_msg "validating $CFG_SELF args"
241 # OK, let's get installing ...
243 # Sanity check: can we run the binaries?
244 if [ -z "${CFG_DISABLE_VERIFY}" ]
246 # Don't do this if uninstalling. Failure here won't help in any way.
247 if [ -z "${CFG_UNINSTALL}" ]
249 msg "verifying platform can run binaries"
250 "${CFG_SRC_DIR}/bin/rustc" --version > /dev/null
253 err "can't execute rustc binary on this platform"
258 # Sanity check: can we can write to the destination?
259 msg "verifying destination is writable"
260 umask 022 && mkdir -p "${CFG_LIBDIR}"
261 need_ok "can't write to destination. consider \`sudo\`."
262 touch "${CFG_LIBDIR}/rust-install-probe" > /dev/null
265 err "can't write to destination. consider \`sudo\`."
267 rm -f "${CFG_LIBDIR}/rust-install-probe"
268 need_ok "failed to remove install probe"
270 # Sanity check: don't install to the directory containing the installer.
271 # That would surely cause chaos.
272 msg "verifying destination is not the same as source"
273 INSTALLER_DIR="$(cd $(dirname $0) && pwd)"
274 PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)"
275 if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
277 err "can't install to same directory as installer"
280 # Using an absolute path to libdir in a few places so that the status
281 # messages are consistently using absolute paths.
282 absolutify "${CFG_LIBDIR}"
283 ABS_LIBDIR="${ABSOLUTIFIED}"
285 # The file name of the manifest we're going to create during install
286 INSTALLED_MANIFEST="${ABS_LIBDIR}/rustlib/manifest"
288 # First, uninstall from the installation prefix.
289 # Errors are warnings - try to rm everything in the manifest even if some fail.
290 if [ -f "${INSTALLED_MANIFEST}" ]
292 # Iterate through installed manifest and remove files
294 # The installed manifest contains absolute paths
301 warn "failed to remove $p"
304 warn "supposedly installed file $p does not exist!"
306 done < "${INSTALLED_MANIFEST}"
308 # If we fail to remove rustlib below, then the installed manifest will
309 # still be full; the installed manifest needs to be empty before install.
310 msg "removing ${INSTALLED_MANIFEST}"
311 rm -f "${INSTALLED_MANIFEST}"
312 # For the above reason, this is a hard error
313 need_ok "failed to remove installed manifest"
315 # Remove 'rustlib' directory
316 msg "removing ${ABS_LIBDIR}/rustlib"
317 rm -Rf "${ABS_LIBDIR}/rustlib"
320 warn "failed to remove rustlib"
323 # There's no manifest. If we were asked to uninstall, then that's a problem.
324 if [ -n "${CFG_UNINSTALL}" ]
326 err "unable to find installation manifest at ${CFG_LIBDIR}/rustlib"
330 # If we're only uninstalling then exit
331 if [ -n "${CFG_UNINSTALL}" ]
334 echo " Rust is uninstalled. Have a nice day."
339 # Create the installed manifest, which we will fill in with absolute file paths
340 mkdir -p "${CFG_LIBDIR}/rustlib"
341 need_ok "failed to create rustlib"
342 touch "${INSTALLED_MANIFEST}"
343 need_ok "failed to create installed manifest"
345 # Now install, iterate through the new manifest and copy files
348 # Decide the destination of the file
349 FILE_INSTALL_PATH="${CFG_PREFIX}/$p"
351 if echo "$p" | grep "^lib/" > /dev/null
353 pp=`echo $p | sed 's/^lib\///'`
354 FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
357 if echo "$p" | grep "^share/man/" > /dev/null
359 pp=`echo $p | sed 's/^share\/man\///'`
360 FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
363 # Make sure there's a directory for it
364 umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
365 need_ok "directory creation failed"
367 # Make the path absolute so we can uninstall it later without
368 # starting from the installation cwd
369 absolutify "${FILE_INSTALL_PATH}"
370 FILE_INSTALL_PATH="${ABSOLUTIFIED}"
373 msg "${FILE_INSTALL_PATH}"
374 if echo "$p" | grep "^bin/" > /dev/null
376 install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
378 install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
380 need_ok "file creation failed"
382 # Update the manifest
383 echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
384 need_ok "failed to update manifest"
386 # The manifest lists all files to install
387 done < "${CFG_SRC_DIR}/lib/rustlib/manifest.in"
389 # Sanity check: can we run the installed binaries?
390 if [ -z "${CFG_DISABLE_VERIFY}" ]
392 msg "verifying installed binaries are executable"
393 "${CFG_PREFIX}/bin/rustc" --version > /dev/null
396 ERR="can't execute installed rustc binary. "
397 ERR="${ERR}installation may be broken. "
398 ERR="${ERR}if this is expected then rerun install.sh with \`--disable-verify\` "
399 ERR="${ERR}or \`make install\` with \`--disable-verify-install\`"
406 echo " Rust is ready to roll."