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"
39 if command -v $1 >/dev/null 2>&1
51 printf "install: %-20s := %.35s ...\n" $1 "$T"
53 printf "install: %-20s := %s %s\n" $1 "$T" "$2"
58 VAL_OPTIONS="$VAL_OPTIONS $1"
67 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
72 if echo "$arg" | grep -q -- "--$OP="
74 val=$(echo "$arg" | cut -f2 -d=)
84 OP="${OP}=[${DEFAULT}]"
85 printf " --%-30s %s\n" "$OP" "$DOC"
90 BOOL_OPTIONS="$BOOL_OPTIONS $1"
111 if [ "$arg" = "--${FLAG}-${OP}" ]
113 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
114 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
115 local V="CFG_${FLAG}_${OP}"
125 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
130 BOOL_OPTIONS="$BOOL_OPTIONS $1"
140 if [ "$arg" = "--${OP}" ]
142 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
153 printf " --%-30s %s\n" "$OP" "$DOC"
161 for option in $BOOL_OPTIONS
163 if test --disable-$option = $arg
167 if test --enable-$option = $arg
171 if test --$option = $arg
176 for option in $VAL_OPTIONS
178 if echo "$arg" | grep -q -- "--$option="
183 if [ "$arg" = "--help" ]
186 echo "No more help available for Configure options,"
187 echo "check the Wiki or join our IRC channel"
190 if test $isArgValid -eq 0
192 err "Option '$arg' is not recognized"
200 FILE_PATH_DIRNAME="$(dirname ${FILE_PATH})"
201 FILE_PATH_BASENAME="$(basename ${FILE_PATH})"
202 FILE_ABS_PATH="$(cd ${FILE_PATH_DIRNAME} && pwd)"
203 FILE_PATH="${FILE_ABS_PATH}/${FILE_PATH_BASENAME}"
204 # This is the return value
205 ABSOLUTIFIED="${FILE_PATH}"
208 msg "looking for install programs"
217 CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
222 if [ "$1" = "--help" ]
227 echo "Usage: $CFG_SELF [options]"
232 step_msg "processing $CFG_SELF args"
235 # Check for mingw or cygwin in order to special case $CFG_LIBDIR_RELATIVE.
236 # This logic is duplicated from configure in order to get the correct libdir
237 # for Windows installs.
238 CFG_OSTYPE=$(uname -s)
243 CFG_OSTYPE=pc-mingw32
247 # msys2, MSYSTEM=MINGW64
248 CFG_OSTYPE=w64-mingw32
251 # Thad's Cygwin identifers below
255 CFG_OSTYPE=pc-mingw32
260 CFG_OSTYPE=w64-mingw32
265 CFG_OSTYPE=pc-mingw32
270 CFG_OSTYPE=w64-mingw32
278 # On windows we just store the libraries in the bin directory because
279 # there's no rpath. This is where the build system itself puts libraries;
280 # --libdir is used to configure the installation directory.
281 # FIXME: Thise needs to parameterized over target triples. Do it in platform.mk
282 CFG_LIBDIR_RELATIVE=lib
283 if [ "$CFG_OSTYPE" = "pc-mingw32" ] || [ "$CFG_OSTYPE" = "w64-mingw32" ]
285 CFG_LIBDIR_RELATIVE=bin
288 flag uninstall "only uninstall from the installation prefix"
289 opt verify 1 "verify that the installed binaries run correctly"
290 valopt prefix "/usr/local" "set installation prefix"
291 # NB This isn't quite the same definition as in `configure`.
292 # just using 'lib' instead of CFG_LIBDIR_RELATIVE
293 valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries"
294 valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
302 step_msg "validating $CFG_SELF args"
306 # OK, let's get installing ...
308 # Sanity check: can we run the binaries?
309 if [ -z "${CFG_DISABLE_VERIFY}" ]
311 # Don't do this if uninstalling. Failure here won't help in any way.
312 if [ -z "${CFG_UNINSTALL}" ]
314 msg "verifying platform can run binaries"
315 "${CFG_SRC_DIR}/bin/rustc" --version > /dev/null
318 err "can't execute rustc binary on this platform"
323 # Sanity check: can we can write to the destination?
324 msg "verifying destination is writable"
325 umask 022 && mkdir -p "${CFG_LIBDIR}"
326 need_ok "can't write to destination. consider \`sudo\`."
327 touch "${CFG_LIBDIR}/rust-install-probe" > /dev/null
330 err "can't write to destination. consider \`sudo\`."
332 rm -f "${CFG_LIBDIR}/rust-install-probe"
333 need_ok "failed to remove install probe"
335 # Sanity check: don't install to the directory containing the installer.
336 # That would surely cause chaos.
337 msg "verifying destination is not the same as source"
338 INSTALLER_DIR="$(cd $(dirname $0) && pwd)"
339 PREFIX_DIR="$(cd ${CFG_PREFIX} && pwd)"
340 if [ "${INSTALLER_DIR}" = "${PREFIX_DIR}" ]
342 err "can't install to same directory as installer"
345 # Using an absolute path to libdir in a few places so that the status
346 # messages are consistently using absolute paths.
347 absolutify "${CFG_LIBDIR}"
348 ABS_LIBDIR="${ABSOLUTIFIED}"
350 # The file name of the manifest we're going to create during install
351 INSTALLED_MANIFEST="${ABS_LIBDIR}/rustlib/manifest"
353 # First, uninstall from the installation prefix.
354 # Errors are warnings - try to rm everything in the manifest even if some fail.
355 if [ -f "${INSTALLED_MANIFEST}" ]
357 # Iterate through installed manifest and remove files
359 # The installed manifest contains absolute paths
366 warn "failed to remove $p"
369 warn "supposedly installed file $p does not exist!"
371 done < "${INSTALLED_MANIFEST}"
373 # If we fail to remove rustlib below, then the installed manifest will
374 # still be full; the installed manifest needs to be empty before install.
375 msg "removing ${INSTALLED_MANIFEST}"
376 rm -f "${INSTALLED_MANIFEST}"
377 # For the above reason, this is a hard error
378 need_ok "failed to remove installed manifest"
380 # Remove 'rustlib' directory
381 msg "removing ${ABS_LIBDIR}/rustlib"
382 rm -Rf "${ABS_LIBDIR}/rustlib"
385 warn "failed to remove rustlib"
388 # There's no manifest. If we were asked to uninstall, then that's a problem.
389 if [ -n "${CFG_UNINSTALL}" ]
391 err "unable to find installation manifest at ${CFG_LIBDIR}/rustlib"
395 # If we're only uninstalling then exit
396 if [ -n "${CFG_UNINSTALL}" ]
399 echo " Rust is uninstalled. Have a nice day."
404 # Create the installed manifest, which we will fill in with absolute file paths
405 mkdir -p "${CFG_LIBDIR}/rustlib"
406 need_ok "failed to create rustlib"
407 touch "${INSTALLED_MANIFEST}"
408 need_ok "failed to create installed manifest"
410 # Now install, iterate through the new manifest and copy files
413 # Decide the destination of the file
414 FILE_INSTALL_PATH="${CFG_PREFIX}/$p"
416 if echo "$p" | grep "^lib/" > /dev/null
418 pp=`echo $p | sed 's/^lib\///'`
419 FILE_INSTALL_PATH="${CFG_LIBDIR}/$pp"
422 if echo "$p" | grep "^share/man/" > /dev/null
424 pp=`echo $p | sed 's/^share\/man\///'`
425 FILE_INSTALL_PATH="${CFG_MANDIR}/$pp"
428 # Make sure there's a directory for it
429 umask 022 && mkdir -p "$(dirname ${FILE_INSTALL_PATH})"
430 need_ok "directory creation failed"
432 # Make the path absolute so we can uninstall it later without
433 # starting from the installation cwd
434 absolutify "${FILE_INSTALL_PATH}"
435 FILE_INSTALL_PATH="${ABSOLUTIFIED}"
438 msg "${FILE_INSTALL_PATH}"
439 if echo "$p" | grep "^bin/" > /dev/null
441 install -m755 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
443 install -m644 "${CFG_SRC_DIR}/$p" "${FILE_INSTALL_PATH}"
445 need_ok "file creation failed"
447 # Update the manifest
448 echo "${FILE_INSTALL_PATH}" >> "${INSTALLED_MANIFEST}"
449 need_ok "failed to update manifest"
451 # The manifest lists all files to install
452 done < "${CFG_SRC_DIR}/${CFG_LIBDIR_RELATIVE}/rustlib/manifest.in"
454 # Sanity check: can we run the installed binaries?
455 if [ -z "${CFG_DISABLE_VERIFY}" ]
457 msg "verifying installed binaries are executable"
458 "${CFG_PREFIX}/bin/rustc" --version > /dev/null
461 ERR="can't execute installed rustc binary. "
462 ERR="${ERR}installation may be broken. "
463 ERR="${ERR}if this is expected then rerun install.sh with \`--disable-verify\` "
464 ERR="${ERR}or \`make install\` with \`--disable-verify-install\`"
471 echo " Rust is ready to roll."