3 # /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/bash is.
4 if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
7 exec /usr
/bin
/env bash
$0 "$@"
9 unset POSIX_SHELL
# clear it so if we invoke other scripts, they run as bash as well
22 echo "configure: WARNING: $1"
26 echo "configure: error: $1"
43 if command -v $1 >/dev
/null
2>&1
44 then msg
"found program '$1'"
45 else err
"program '$1' is missing, please install it"
59 msg
"leaving $2 unchanged"
62 chmod u-w
$2 # make copied artifact read-only
69 msg
"leaving $2 unchanged"
72 chmod u-w
$2 # make moved artifact read-only
82 printf "configure: %-20s := %.35s ...\n" $1 "$T"
84 printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
86 printf "%-20s := %s\n" $1 "$T" >>config.tmp
95 printf "configure: %-20s := %.35s ...\n" $1 "$T"
97 printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
101 printf "%-20s := \n" $1 >>config.tmp
103 printf "%-20s := \"%s\"\n" $1 "$T" >>config.tmp
114 T
=$
(command -v $P 2>&1)
117 VER0
=$
($P --version 2>/dev
/null \
118 |
grep -o '[vV]\?[0-9][0-9.][a-z0-9.-]*' |
head -1 )
119 if [ $?
-eq 0 -a "x${VER0}" != "x" ]
142 err
"$V needed, but unable to find any of: $*"
147 for arg
in $CFG_CONFIGURE_ARGS
150 for option
in $BOOL_OPTIONS
152 if test --disable-$option = $arg
156 if test --enable-$option = $arg
161 for option
in $VAL_OPTIONS
163 if echo "$arg" |
grep -q -- "--$option="
168 if [ "$arg" = "--help" ]
171 echo "No more help available for Configure options,"
172 echo "check the Wiki or join our IRC channel"
175 if test $isArgValid -eq 0
177 err
"Option '$arg' is not recognized"
183 # `valopt OPTION_NAME DEFAULT DOC` extracts a string-valued option
184 # from command line, using provided default value for the option if
185 # not present, and saves it to the generated config.mk.
187 # `valopt_nosave` is much the same, except that it does not save the
188 # result to config.mk (instead the script should use `putvar` itself
189 # later on to save it). `valopt_core` is the core upon which the
190 # other two are built.
193 VAL_OPTIONS
="$VAL_OPTIONS $2"
204 local UOP
=$
(echo $OP |
tr '[:lower:]' '[:upper:]' |
tr '\-' '\_')
206 local V_PROVIDED
="${V}_PROVIDED"
208 for arg
in $CFG_CONFIGURE_ARGS
210 if echo "$arg" |
grep -q -- "--$OP="
212 val
=$
(echo "$arg" | cut
-f2 -d=)
217 if [ "$SAVE" = "save" ]
226 OP
="${OP}=[${DEFAULT}]"
227 printf " --%-30s %s\n" "$OP" "$DOC"
232 valopt_core nosave
"$@"
236 valopt_core save
"$@"
239 # `opt OPTION_NAME DEFAULT DOC` extracts a boolean-valued option from
240 # command line, using the provided default value (0/1) for the option
241 # if not present, and saves it to the generated config.mk.
243 # `opt_nosave` is much the same, except that it does not save the
244 # result to config.mk (instead the script should use `putvar` itself
245 # later on to save it). `opt_core` is the core upon which the other
249 BOOL_OPTIONS
="$BOOL_OPTIONS $2"
260 if [ $DEFAULT -eq 0 ]
263 DEFAULT_FLAG
="disable"
266 DEFAULT_FLAG
="enable"
272 for arg
in $CFG_CONFIGURE_ARGS
274 if [ "$arg" = "--${FLAG}-${OP}" ]
276 OP
=$
(echo $OP |
tr 'a-z-' 'A-Z_')
277 FLAG
=$
(echo $FLAG |
tr 'a-z' 'A-Z')
278 local V
="CFG_${FLAG}_${OP}"
279 local V_PROVIDED
="CFG_${FLAG}_${OP}_PROVIDED"
282 if [ "$SAVE" = "save" ]
286 elif [ "$arg" = "--${DEFAULT_FLAG}-${OP}" ]
288 OP
=$
(echo $OP |
tr 'a-z-' 'A-Z_')
289 DEFAULT_FLAG
=$
(echo $DEFAULT_FLAG |
tr 'a-z' 'A-Z')
290 local V_PROVIDED
="CFG_${DEFAULT_FLAG}_${OP}_PROVIDED"
299 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
313 local V
="CFG_${NAME}"
316 # If configure didn't set a value already, then check environment.
318 # (It is recommended that the configure script always check the
319 # environment before setting any values to envopt variables; see
320 # e.g. how CFG_CC is handled, where it first checks `-z "$CC"`,
321 # and issues msg if it ends up employing that provided value.)
328 # If script or environment provided a value, save it.
335 enable_if_not_disabled
() {
337 local UOP
=$
(echo $OP |
tr '[:lower:]' '[:upper:]' |
tr '\-' '\_')
338 local ENAB_V
="CFG_ENABLE_$UOP"
339 local EXPLICITLY_DISABLED
="CFG_DISABLE_${UOP}_PROVIDED"
340 eval VV
=\$
$EXPLICITLY_DISABLED
341 if [ -z "$VV" ]; then
348 i686-pc-windows-gnu
) echo i686-w64-mingw32
;;
349 x86_64-pc-windows-gnu
) echo x86_64-w64-mingw32
;;
354 # Prints the absolute path of a directory to stdout
357 # Unset CDPATH because it causes havok: it makes the destination unpredictable
358 # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
360 (unset CDPATH
&& cd "$_path" > /dev
/null
&& pwd)
370 msg
"looking for configure programs"
387 CFG_SRC_DIR
="$(abs_path $(dirname $0))/"
388 CFG_SRC_DIR_RELATIVE
="$(dirname $0)/"
389 CFG_BUILD_DIR
="$(pwd)/"
391 CFG_CONFIGURE_ARGS
="$@"
394 case "${CFG_SRC_DIR}" in
396 err
"The path to the rust source directory contains spaces, which is not supported"
407 echo "Usage: $CFG_SELF [options]"
412 msg
"recreating config.tmp"
415 step_msg
"processing $CFG_SELF args"
421 opt debug
0 "debug mode; disables optimization unless \`--enable-optimize\` given"
422 opt valgrind
0 "run tests with valgrind (memcheck by default)"
423 opt helgrind
0 "run tests with helgrind instead of memcheck"
424 opt valgrind-rpass
1 "run rpass-valgrind tests with valgrind"
425 opt docs
1 "build standard library documentation"
426 opt compiler-docs
0 "build compiler documentation"
427 opt optimize-tests
1 "build tests with optimizations"
428 opt debuginfo-tests
0 "build tests with debugger metadata"
429 opt quiet-tests
0 "enable quieter output when running tests"
430 opt libcpp
1 "build llvm with libc++ instead of libstdc++ when using clang"
431 opt llvm-assertions
0 "build LLVM with assertions"
432 opt debug-assertions
0 "build with debugging assertions"
433 opt fast-make
0 "use .gitmodules as timestamp for submodule deps"
434 opt ccache
0 "invoke gcc/clang via ccache to reuse object files between builds"
435 opt sccache
0 "invoke gcc/clang via sccache to reuse object files between builds"
436 opt local-rust
0 "use an installed rustc rather than downloading a snapshot"
437 opt local-rebuild
0 "assume local-rust matches the current version, for rebuilds; implies local-rust, and is implied if local-rust already matches the current version"
438 opt llvm-static-stdcpp
0 "statically link to libstdc++ for LLVM"
439 opt llvm-link-shared
0 "prefer shared linking to LLVM (llvm-config --link-shared)"
440 opt llvm-clean-rebuild
0 "delete LLVM build directory on rebuild"
441 opt rpath
1 "build rpaths into rustc itself"
442 opt stage0-landing-pads
1 "enable landing pads during bootstrap with stage0"
443 # This is used by the automation to produce single-target nightlies
444 opt dist-host-only
0 "only install bins for the host architecture"
445 opt inject-std-version
1 "inject the current compiler version of libstd into programs"
446 opt llvm-version-check
1 "check if the LLVM version is supported, build anyway"
447 opt codegen-tests
1 "run the src/test/codegen tests"
448 opt option-checking
1 "complain about unrecognized options in this configure script"
449 opt ninja
0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
450 opt locked-deps
0 "force Cargo.lock to be up to date"
451 opt vendor
0 "enable usage of vendored Rust crates"
452 opt sanitizers
0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"
453 opt dist-src
1 "when building tarballs enables building a source tarball"
454 opt cargo-openssl-static
0 "static openssl in cargo"
455 opt profiler
0 "build the profiler runtime"
457 # Optimization and debugging options. These may be overridden by the release channel, etc.
458 opt_nosave optimize
1 "build optimized rust code"
459 opt_nosave optimize-cxx
1 "build optimized C++ code"
460 opt_nosave optimize-llvm
1 "build optimized LLVM"
461 opt_nosave llvm-assertions
0 "build LLVM with assertions"
462 opt_nosave debug-assertions
0 "build with debugging assertions"
463 opt_nosave llvm-release-debuginfo
0 "build LLVM with debugger metadata"
464 opt_nosave debuginfo
0 "build with debugger metadata"
465 opt_nosave debuginfo-lines
0 "build with line number debugger metadata"
466 opt_nosave debuginfo-only-std
0 "build only libstd with debugging information"
467 opt_nosave debug-jemalloc
0 "build jemalloc with --enable-debug --enable-fill"
469 valopt localstatedir
"/var/lib" "local state directory"
470 valopt sysconfdir
"/etc" "install system configuration files"
472 valopt datadir
"${CFG_PREFIX}/share" "install data"
473 valopt infodir
"${CFG_PREFIX}/share/info" "install additional info"
474 valopt llvm-root
"" "set LLVM root"
475 valopt python
"" "set path to python"
476 valopt jemalloc-root
"" "set directory where libjemalloc_pic.a is located"
477 valopt build
"" "GNUs ./configure syntax LLVM build triple"
478 valopt android-cross-path
"" "Android NDK standalone path (deprecated)"
479 valopt i686-linux-android-ndk
"" "i686-linux-android NDK standalone path"
480 valopt arm-linux-androideabi-ndk
"" "arm-linux-androideabi NDK standalone path"
481 valopt armv7-linux-androideabi-ndk
"" "armv7-linux-androideabi NDK standalone path"
482 valopt aarch64-linux-android-ndk
"" "aarch64-linux-android NDK standalone path"
483 valopt x86_64-linux-android-ndk
"" "x86_64-linux-android NDK standalone path"
484 valopt nacl-cross-path
"" "NaCl SDK path (Pepper Canary is recommended). Must be absolute!"
485 valopt musl-root
"/usr/local" "MUSL root installation directory (deprecated)"
486 valopt musl-root-x86_64
"" "x86_64-unknown-linux-musl install directory"
487 valopt musl-root-i686
"" "i686-unknown-linux-musl install directory"
488 valopt musl-root-arm
"" "arm-unknown-linux-musleabi install directory"
489 valopt musl-root-armhf
"" "arm-unknown-linux-musleabihf install directory"
490 valopt musl-root-armv7
"" "armv7-unknown-linux-musleabihf install directory"
491 valopt extra-filename
"" "Additional data that is hashed and passed to the -C extra-filename flag"
492 valopt qemu-armhf-rootfs
"" "rootfs in qemu testing, you probably don't want to use this"
493 valopt experimental-targets
"" "experimental LLVM targets to build"
495 if [ -e ${CFG_SRC_DIR}.git
]
497 valopt release-channel
"dev" "the name of the release channel to build"
499 # If we have no git directory then we are probably a tarball distribution
500 # and should default to stable channel - Issue 28322
502 msg
"git: no git directory. Changing default release channel to stable"
503 valopt release-channel
"stable" "the name of the release channel to build"
506 # Used on systems where "cc" and "ar" are unavailable
507 valopt default-linker
"cc" "the default linker"
508 valopt default-ar
"ar" "the default ar"
510 # Many of these are saved below during the "writing configuration" step
511 # (others are conditionally saved).
512 opt_nosave manage-submodules
1 "let the build manage the git submodules"
513 opt_nosave clang
0 "prefer clang to gcc for building the runtime"
514 opt_nosave jemalloc
1 "build liballoc with jemalloc"
515 opt full-bootstrap
0 "build three compilers instead of two"
516 opt extended
0 "build an extended rust tool set"
518 valopt_nosave prefix
"/usr/local" "set installation prefix"
519 valopt_nosave local-rust-root
"/usr/local" "set prefix for local rust binary"
520 valopt_nosave
host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
521 valopt_nosave target
"${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
522 valopt_nosave mandir
"${CFG_PREFIX}/share/man" "install man pages in PATH"
523 valopt_nosave docdir
"${CFG_PREFIX}/share/doc/rust" "install documentation in PATH"
524 valopt_nosave bindir
"${CFG_PREFIX}/bin" "install binaries"
526 # On Windows this determines root of the subtree for target libraries.
527 # Host runtime libs always go to 'bin'.
528 valopt libdir
"${CFG_PREFIX}/lib" "install libraries"
530 case "$CFG_LIBDIR" in
531 "$CFG_PREFIX"/*) CAT_INC
=2;;
532 "$CFG_PREFIX"*) CAT_INC
=1;;
534 err
"libdir must begin with the prefix. Use --prefix to set it accordingly.";;
537 CFG_LIBDIR_RELATIVE
=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
546 if [ -z "$CFG_DISABLE_OPTION_CHECKING" ]
548 step_msg
"validating $CFG_SELF args"
552 # Validate the release channel, and configure options
553 case "$CFG_RELEASE_CHANNEL" in
555 msg
"overriding settings for $CFG_RELEASE_CHANNEL"
556 enable_if_not_disabled llvm-assertions
557 # FIXME(stage0) re-enable this on the next stage0 now that #35566 is
563 CFG_ENABLE_DEBUGINFO_LINES
=1
564 CFG_ENABLE_DEBUGINFO_ONLY_STD
=1
570 msg
"overriding settings for $CFG_RELEASE_CHANNEL"
575 CFG_ENABLE_DEBUGINFO_LINES
=1
576 CFG_ENABLE_DEBUGINFO_ONLY_STD
=1
583 err
"release channel must be 'dev', 'nightly', 'beta' or 'stable'"
587 # Adjust perf and debug options for debug mode
588 if [ -n "$CFG_ENABLE_DEBUG" ]; then
589 msg
"debug mode enabled, setting performance options"
590 if [ -z "$CFG_ENABLE_OPTIMIZE_PROVIDED" ]; then
591 msg
"optimization not explicitly enabled, disabling optimization"
592 CFG_DISABLE_OPTIMIZE
=1
593 CFG_DISABLE_OPTIMIZE_CXX
=1
596 # Set following variables to 1 unless setting already provided
597 enable_if_not_disabled debug-assertions
598 enable_if_not_disabled debug-jemalloc
599 enable_if_not_disabled debuginfo
600 enable_if_not_disabled llvm-assertions
603 # OK, now write the debugging options
604 if [ -n "$CFG_DISABLE_OPTIMIZE" ]; then putvar CFG_DISABLE_OPTIMIZE
; fi
605 if [ -n "$CFG_DISABLE_OPTIMIZE_CXX" ]; then putvar CFG_DISABLE_OPTIMIZE_CXX
; fi
606 if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then putvar CFG_DISABLE_OPTIMIZE_LLVM
; fi
607 if [ -n "$CFG_ENABLE_LLVM_ASSERTIONS" ]; then putvar CFG_ENABLE_LLVM_ASSERTIONS
; fi
608 if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTIONS
; fi
609 if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO
; fi
610 if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO
; fi
611 if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES
; fi
612 if [ -n "$CFG_ENABLE_DEBUGINFO_ONLY_STD" ]; then putvar CFG_ENABLE_DEBUGINFO_ONLY_STD
; fi
613 if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC
; fi
615 step_msg
"looking for build programs"
617 probe_need CFG_CURL curl
618 if [ -z "$CFG_PYTHON_PROVIDED" ]; then
619 probe_need CFG_PYTHON python2.7 python2 python
622 python_version
=$
($CFG_PYTHON -V 2>&1)
623 if [ $
(echo $python_version |
grep -c '^Python 2\.7') -ne 1 ]; then
624 err
"Found $python_version, but Python 2.7 is required"
627 # the valgrind rpass tests will fail if you don't have a valgrind, but they're
628 # only disabled if you opt out.
629 if [ -z "$CFG_VALGRIND" ]
631 # If the user has explicitly asked for valgrind tests, then fail
632 if [ -n "$CFG_ENABLE_VALGRIND" ] && [ -n "$CFG_ENABLE_VALGRIND_PROVIDED" ]
634 err
"No valgrind present, but valgrind tests explicitly requested"
636 CFG_DISABLE_VALGRIND_RPASS
=1
637 putvar CFG_DISABLE_VALGRIND_RPASS
641 # Do some sanity checks if running on buildbot
642 # (these env vars are set by rust-buildbot)
643 if [ -n "$RUST_DIST_SERVER" -a -n "$ALLOW_NONZERO_RLIMIT_CORE" ]; then
644 # Frequently the llvm submodule directory is broken by the build
646 llvm_lock
="${CFG_SRC_DIR}/.git/modules/src/llvm/index.lock"
647 if [ -e "$llvm_lock" ]; then
648 step_msg
"removing $llvm_lock"
654 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] ||
[ "$CFG_OSTYPE" = "pc-windows-msvc" ]
659 # --enable-local-rebuild implies --enable-local-rust too
660 if [ -n "$CFG_ENABLE_LOCAL_REBUILD" ]
662 if [ -z "$CFG_ENABLE_LOCAL_RUST" ]
664 CFG_ENABLE_LOCAL_RUST
=1
665 putvar CFG_ENABLE_LOCAL_RUST
669 if [ -n "$CFG_ENABLE_LOCAL_RUST" ]
671 system_rustc
=$
(which rustc
)
672 if [ -f ${CFG_LOCAL_RUST_ROOT}/bin
/rustc
${BIN_SUF} ]
674 : # everything already configured
675 elif [ -n "$system_rustc" ]
677 # we assume that rustc is in a /bin directory
678 CFG_LOCAL_RUST_ROOT
=${system_rustc%/bin/rustc}
680 err
"no local rust to use"
683 CMD
="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
684 LRV
=`LD_LIBRARY_PATH=${CFG_LOCAL_RUST_ROOT}/lib $CMD --version`
687 step_msg
"failure while running $CMD --version"
690 step_msg
"using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
691 putvar CFG_LOCAL_RUST_ROOT
694 # Same with jemalloc. save the setting here.
695 if [ -n "$CFG_DISABLE_JEMALLOC" ]
697 putvar CFG_DISABLE_JEMALLOC
700 # All safeguards based on $CFG_ENABLE_CLANG should occur before this
701 # point in the script; after this point, script logic should inspect
702 # $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG.
704 # Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS,LDFLAGS}
712 # a little post-processing of various config values
713 CFG_PREFIX
=${CFG_PREFIX%/}
714 CFG_MANDIR
=${CFG_MANDIR%/}
715 CFG_DOCDIR
=${CFG_DOCDIR%/}
716 CFG_BINDIR
=${CFG_BINDIR%/}
717 CFG_HOST
="$(echo $CFG_HOST | tr ',' ' ')"
718 CFG_TARGET
="$(echo $CFG_TARGET | tr ',' ' ')"
720 # copy build-triples to host-triples so that builds are a subset of hosts
722 for i
in $CFG_BUILD $CFG_HOST;
724 echo "$V_TEMP" |
grep -qF $i || V_TEMP
="$V_TEMP${V_TEMP:+ }$i"
728 # copy host-triples to target-triples so that hosts are a subset of targets
730 for i
in $CFG_HOST $CFG_TARGET;
732 echo "$V_TEMP" |
grep -qF $i || V_TEMP
="$V_TEMP${V_TEMP:+ }$i"
736 step_msg
"writing configuration"
739 putvar CFG_SRC_DIR_RELATIVE
743 putvar CFG_CONFIGURE_ARGS
747 putvar CFG_LIBDIR_RELATIVE
748 putvar CFG_DISABLE_MANAGE_SUBMODULES
749 putvar CFG_AARCH64_LINUX_ANDROID_NDK
750 putvar CFG_ARM_LINUX_ANDROIDEABI_NDK
751 putvar CFG_ARMV7_LINUX_ANDROIDEABI_NDK
752 putvar CFG_I686_LINUX_ANDROID_NDK
753 putvar CFG_X86_64_LINUX_ANDROID_NDK
754 putvar CFG_NACL_CROSS_PATH
758 putvar CFG_USING_LIBCPP
761 copy_if_changed
${CFG_SRC_DIR}src
/bootstrap
/mk
/Makefile.
in .
/Makefile
762 move_if_changed config.tmp config.mk
766 if [ -z "$CFG_ENABLE_DEBUG" ]; then
767 step_msg
"configured in release mode. for development consider --enable-debug"
772 if [ "$CFG_SRC_DIR" = `pwd` ]; then
775 X_PY
=${CFG_SRC_DIR_RELATIVE}x.py
778 msg
"run \`python ${X_PY} --help\`"