14 echo "configure: WARNING: $1"
18 echo "configure: error: $1"
30 if which $1 >/dev/null 2>&1
47 msg "leaving $2 unchanged"
51 chmod u-w $2 # make copied artifact read-only
58 msg "leaving $2 unchanged"
62 chmod u-w $2 # make moved artifact read-only
72 printf "configure: %-20s := %.35s ...\n" $1 "$T"
74 printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
76 printf "%-20s := %s\n" $1 "$T" >>config.tmp
89 VER0=$($P --version 2>/dev/null | head -1 \
90 | sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
91 if [ $? -eq 0 -a "x${VER0}" != "x" ]
113 err "needed, but unable to find any of: $*"
125 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
128 for arg in $CFG_CONFIGURE_ARGS
130 if echo "$arg" | grep -q -- "--$OP="
132 val=$(echo "$arg" | cut -f2 -d=)
142 OP="${OP}=[${DEFAULT}]"
143 printf " --%-30s %s\n" "$OP" "$DOC"
155 if [ $DEFAULT -eq 0 ]
165 for arg in $CFG_CONFIGURE_ARGS
167 if [ "$arg" = "--${FLAG}-${OP}" ]
169 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
170 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
171 local V="CFG_${FLAG}_${OP}"
181 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
185 msg "looking for configure programs"
201 msg "inspecting environment"
203 CFG_OSTYPE=$(uname -s)
204 CFG_CPUTYPE=$(uname -m)
206 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
208 # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
210 if sysctl hw.optional.x86_64 | grep -q ': 1'
216 # The goal here is to come up with the same triple as LLVM would,
217 # at least for the subset of platforms we're willing to target.
222 CFG_OSTYPE=unknown-linux-gnu
226 CFG_OSTYPE=unknown-freebsd
230 CFG_OSTYPE=apple-darwin
234 CFG_OSTYPE=pc-mingw32
238 err "unknown OS type: $CFG_OSTYPE"
245 i386 | i486 | i686 | i786 | x86)
253 x86_64 | x86-64 | x64 | amd64)
258 err "unknown CPU type: $CFG_CPUTYPE"
261 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
262 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
264 file -L "$SHELL" | grep -q "x86[_-]64"
271 DEFAULT_HOST_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"
273 CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
274 CFG_BUILD_DIR="$(pwd)/"
275 CFG_SELF=${CFG_SRC_DIR}$(basename $0)
276 CFG_CONFIGURE_ARGS="$@"
280 if [ "$1" = "--help" ]
285 echo "Usage: $CFG_SELF [options]"
290 msg "recreating config.tmp"
293 step_msg "processing $CFG_SELF args"
296 opt sharedstd 1 "build libstd as a shared library"
297 opt valgrind 0 "run tests with valgrind (memcheck by default)"
298 opt helgrind 0 "run tests with helgrind instead of memcheck"
299 opt docs 1 "build documentation"
300 opt optimize 1 "build optimized rust code"
301 opt optimize-cxx 1 "build optimized C++ code"
302 opt optimize-llvm 1 "build optimized LLVM"
303 opt debug 0 "build with extra debug fun"
304 opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
305 opt manage-submodules 1 "let the build manage the git submodules"
306 opt mingw-cross 0 "cross-compile for win32 using mingw"
307 opt clang 0 "prefer clang to gcc for building the runtime"
308 opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
309 opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
310 valopt prefix "/usr/local" "set installation prefix"
311 valopt local-rust-root "/usr/local" "set prefix for local rust binary"
312 valopt llvm-root "" "set LLVM root"
313 valopt host-triple "${DEFAULT_HOST_TRIPLE}" "LLVM host triple"
314 valopt target-triples "${CFG_HOST_TRIPLE}" "LLVM target triples"
323 step_msg "looking for build programs"
325 probe_need CFG_PERL perl
326 probe_need CFG_CURL curl
327 probe_need CFG_PYTHON python2.7 python2.6 python2 python
329 python_version=$($CFG_PYTHON -V 2>&1)
330 if [ $(echo $python_version | grep -c '^Python 2\.[4567]') -ne 1 ]; then
331 err "Found $python_version, but LLVM requires Python 2.4-2.7"
334 # If we have no git directory then we are probably a tarball distribution
335 # and shouldn't attempt to load submodules
336 if [ ! -e ${CFG_SRC_DIR}.git ]
339 msg "git: no git directory. disabling submodules"
340 CFG_DISABLE_MANAGE_SUBMODULES=1
342 probe_need CFG_GIT git
345 probe CFG_CLANG clang++
348 probe CFG_LLVM_CONFIG llvm-config
349 probe CFG_VALGRIND valgrind
352 probe CFG_LLNEXTGEN LLnextgen
353 probe CFG_PANDOC pandoc
354 probe CFG_PDFLATEX pdflatex
355 probe CFG_XETEX xetex
356 probe CFG_LUATEX luatex
357 probe CFG_NODE nodejs node
358 if [ "$CFG_OSTYPE" = "unknown-linux-gnu" ]
360 probe CFG_PAXCTL paxctl /sbin/paxctl
364 if [ ! -z "$CFG_PANDOC" ]
366 PANDOC_VER_LINE=$(pandoc --version | grep '^pandoc ')
367 PANDOC_VER=${PANDOC_VER_LINE#pandoc }
368 PV_MAJOR_MINOR=${PANDOC_VER%.[0-9]*}
369 PV_MAJOR=${PV_MAJOR_MINOR%%[.][0-9]*}
370 PV_MINOR=${PV_MAJOR_MINOR#[0-9]*[.]}
371 PV_MINOR=${PV_MINOR%%[.][0-9]*}
372 if [ "$PV_MAJOR" -lt "1" ] || [ "$PV_MINOR" -lt "8" ]
374 step_msg "pandoc $PV_MAJOR.$PV_MINOR is too old. disabling"
379 if [ "$CFG_OSTYPE" = "unknown-linux-gnu" ]
381 if [ ! -z "$CFG_ENABLE_PAX_FLAGS" -a -z "$CFG_PAXCTL" ]
383 err "enabled PaX markings but no paxctl binary found"
386 if [ -z "$CFG_DISABLE_PAX_FLAGS" ]
388 # GRSecurity/PaX detection. This can be very flaky.
391 # /dev/grsec only exists if CONFIG_GRKERNSEC_NO_RBAC is not set.
392 # /proc/sys/kernel/grsecurity is not available if ÇONFIG_GRKERNSEC_SYSCTL is not set.
393 if [ -e /dev/grsec -o -d /proc/sys/kernel/grsecurity ]
396 # /proc/config.gz is normally only available to root, and only if CONFIG_IKCONFIG_PROC has been set.
397 elif [ -r /proc/config.gz -a ! -z "$CFG_ZCAT" ]
399 if "$CFG_ZCAT" /proc/config.gz | grep --quiet "CONFIG_GRKERNSEC=y"
404 elif grep --quiet grsec /proc/version
409 if [ ! -z "$GRSEC_DETECTED" ]
411 step_msg "GRSecurity: yes"
412 if [ ! -z "$CFG_PAXCTL" ]
414 CFG_ENABLE_PAX_FLAGS=1
416 warn "GRSecurity kernel detected but no paxctl binary found: not setting CFG_ENABLE_PAX_FLAGS"
419 step_msg "GRSecurity: no"
424 if [ ! -z "$CFG_ENABLE_LOCAL_RUST" ]
426 if [ ! -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc ]
428 err "no local rust to use"
430 LRV=`${CFG_LOCAL_RUST_ROOT}/bin/rustc --version`
431 step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: " $LRV
435 if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
437 err "either clang or gcc is required"
440 if [ ! -z "$CFG_LLVM_ROOT" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ]
442 step_msg "using custom LLVM at $CFG_LLVM_ROOT"
444 LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config"
445 LLVM_VERSION=$($LLVM_CONFIG --version)
447 case $LLVM_VERSION in
448 (3.1svn|3.1|3.0svn|3.0)
449 msg "found ok version of LLVM: $LLVM_VERSION"
452 err "bad LLVM version: $LLVM_VERSION, need >=3.0svn"
457 if [ ! -z "$CFG_ENABLE_CLANG" ]
459 if [ -z "$CFG_CLANG" ]
461 err "clang requested but not found"
463 CFG_CLANG_VERSION=$("$CFG_CLANG" \
466 | sed 's/.*\(version .*\)/\1/' \
469 case $CFG_CLANG_VERSION in
470 (3.0svn | 3.0 | 3.1 | 4.0 | 4.1)
471 step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
472 CFG_C_COMPILER="clang"
475 err "bad CLANG version: $CFG_CLANG_VERSION, need >=3.0svn"
482 # a little post-processing of various config values
484 CFG_PREFIX=${CFG_PREFIX%/}
485 CFG_TARGET_TRIPLES="$(echo $CFG_TARGET_TRIPLES | tr ',' ' ')"
486 case $CFG_TARGET_TRIPLES in
487 (*$CFG_HOST_TRIPLE*) ;;
488 (*) err "Host triple is not among the target triples." ;;
491 if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
493 err "either clang or gcc is required"
496 if [ ! -z "$CFG_PERF" ]
498 HAVE_PERF_LOGFD=`$CFG_PERF stat --log-fd 2>&1 | grep 'unknown option'`
499 if [ -z "$HAVE_PERF_LOGFD" ];
501 CFG_PERF_WITH_LOGFD=1
502 putvar CFG_PERF_WITH_LOGFD
506 step_msg "making directories"
509 doc doc/core doc/std \
516 for t in $CFG_TARGET_TRIPLES
522 for t in $CFG_TARGET_TRIPLES
528 for t in $CFG_TARGET_TRIPLES
532 isaac linenoise bigint sync test arch/i386 arch/x86_64 \
533 libuv libuv/src/ares libuv/src/eio libuv/src/ev
539 # On windows we just store the libraries in the bin directory because
542 if [ "$CFG_OSTYPE" = "pc-mingw32" ]
547 for h in $CFG_TARGET_TRIPLES
549 for t in $CFG_TARGET_TRIPLES
554 make_dir $h/stage$i/bin
557 make_dir $h/stage$i/$CFG_LIBDIR
560 make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/bin
563 make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/$CFG_LIBDIR
567 make_dir $h/test/run-pass
568 make_dir $h/test/run-pass-fulldeps
569 make_dir $h/test/run-fail
570 make_dir $h/test/compile-fail
571 make_dir $h/test/bench
572 make_dir $h/test/perf
573 make_dir $h/test/pretty
574 make_dir $h/test/doc-tutorial
575 make_dir $h/test/doc-tutorial-ffi
576 make_dir $h/test/doc-tutorial-macros
577 make_dir $h/test/doc-tutorial-borrowed-ptr
578 make_dir $h/test/doc-tutorial-tasks
579 make_dir $h/test/doc-ref
582 # Configure submodules
583 step_msg "configuring submodules"
585 # Have to be in the top of src directory for this
586 if [ -z $CFG_DISABLE_MANAGE_SUBMODULES ]
590 msg "git: submodule sync"
591 "${CFG_GIT}" submodule --quiet sync
593 msg "git: submodule update"
594 "${CFG_GIT}" submodule --quiet update --init
597 msg "git: submodule foreach sync"
598 "${CFG_GIT}" submodule --quiet foreach --recursive 'if test -e .gitmodules; then git submodule sync; fi'
601 msg "git: submodule foreach update"
602 "${CFG_GIT}" submodule --quiet update --init --recursive
605 # NB: this is just for the sake of getting the submodule SHA1 values
606 # and status written into the build log.
607 msg "git: submodule status"
608 "${CFG_GIT}" submodule status --recursive
610 msg "git: submodule clobber"
611 "${CFG_GIT}" submodule --quiet foreach --recursive git clean -dxf
613 "${CFG_GIT}" submodule --quiet foreach --recursive git checkout .
619 # Configure llvm, only if necessary
620 step_msg "looking at LLVM"
621 CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm/
622 for t in $CFG_TARGET_TRIPLES
626 if [ -z $CFG_LLVM_ROOT ]
628 LLVM_BUILD_DIR=${CFG_BUILD_DIR}llvm/$t
629 if [ ! -z "$CFG_DISABLE_OPTIMIZE_LLVM" ]
632 # Just use LLVM straight from its build directory to
633 # avoid 'make install' time
634 LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug+Asserts
636 LLVM_DBG_OPTS="--enable-optimized"
637 LLVM_INST_DIR=$LLVM_BUILD_DIR/Release+Asserts
640 msg "not reconfiguring LLVM, external LLVM root"
641 # The user is using their own LLVM
643 LLVM_INST_DIR=$CFG_LLVM_ROOT
648 if [ ${do_reconfigure} -ne 0 ]
650 # because git is hilarious, it might have put the module index
651 # in a couple places.
652 index1="${CFG_SRC_DIR}.git/modules/src/llvm/index"
653 index2="${CFG_SRC_DIR}src/llvm/.git/index"
654 for index in ${index1} ${index2}
656 config_status="${CFG_BUILD_DIR}llvm/$t/config.status"
657 if test -e ${index} -a \
658 -e ${config_status} -a \
659 ${config_status} -nt ${index}
661 msg "not reconfiguring LLVM, config.status is fresh"
667 if [ ${do_reconfigure} -ne 0 ]
669 msg "configuring LLVM for $t"
671 LLVM_TARGETS="--enable-targets=x86,x86_64"
672 LLVM_BUILD="--build=$t"
673 LLVM_HOST="--host=$t"
674 LLVM_TARGET="--target=$t"
676 # Disable unused LLVM features
677 LLVM_OPTS="$LLVM_DBG_OPTS --disable-docs \
678 --enable-bindings=none --disable-threads \
681 if [ "$CFG_C_COMPILER" = "clang" ]
683 LLVM_CXX_32="clang++ -m32"
684 LLVM_CC_32="clang -m32"
686 LLVM_CXX_64="clang++"
689 LLVM_CXX_32="g++ -m32"
690 LLVM_CC_32="gcc -m32"
696 LLVM_CFLAGS_32="-m32"
697 LLVM_CXXFLAGS_32="-m32"
698 LLVM_LDFLAGS_32="-m32"
704 if echo $t | grep -q x86_64
706 LLVM_CXX=$LLVM_CXX_64
708 LLVM_CFLAGS=$LLVM_CFLAGS_64
709 LLVM_CXXFLAGS=$LLVM_CXXFLAGS_64
710 LLVM_LDFLAGS=$LLVM_LDFLAGS_64
712 LLVM_CXX=$LLVM_CXX_32
714 LLVM_CFLAGS=$LLVM_CFLAGS_32
715 LLVM_CXXFLAGS=$LLVM_CXXFLAGS_32
716 LLVM_LDFLAGS=$LLVM_LDFLAGS_32
722 CXXFLAGS=$LLVM_CXXFLAGS
723 LDFLAGS=$LLVM_LDFLAGS
725 LLVM_FLAGS="$LLVM_TARGETS $LLVM_OPTS $LLVM_BUILD \
726 $LLVM_HOST $LLVM_TARGET"
728 msg "configuring LLVM with:"
739 /* | [a-z]:* | [A-Z]:*)
740 ${CFG_LLVM_SRC_DIR}configure $LLVM_FLAGS
743 ${CFG_BUILD_DIR}${CFG_LLVM_SRC_DIR}configure \
747 need_ok "LLVM configure failed"
751 # Construct variables for LLVM build and install directories for
752 # each target. These will be named
753 # CFG_LLVM_BUILD_DIR_${target_triple} but all the hyphens in
754 # target_triple will be converted to underscore, because bash
755 # variables can't contain hyphens. The makefile will then have to
757 CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
758 CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
759 eval ${CFG_LLVM_BUILD_DIR}="'$LLVM_BUILD_DIR'"
760 eval ${CFG_LLVM_INST_DIR}="'$LLVM_INST_DIR'"
764 step_msg "writing configuration"
770 putvar CFG_CONFIGURE_ARGS
772 putvar CFG_TARGET_TRIPLES
773 putvar CFG_C_COMPILER
775 putvar CFG_DISABLE_MANAGE_SUBMODULES
777 if [ ! -z "$CFG_ENABLE_PAX_FLAGS" ]
779 putvar CFG_ENABLE_PAX_FLAGS
783 if [ ! -z $BAD_PANDOC ]
789 if head -n 1 ${CFG_SRC_DIR}src/snapshots.txt | grep -q '^T'
792 putvar CFG_IN_TRANSITION
795 # Valgrind is only reliable on Linux. On Windows it doesn't work at all, and
796 # on the Mac the dynamic linker causes Valgrind to emit a huge stream of
798 if [ $CFG_OSTYPE != unknown-linux-gnu ] && [ $CFG_OSTYPE != apple-darwin ]
801 putvar CFG_BAD_VALGRIND
805 putvar CFG_LLVM_SRC_DIR
807 for t in $CFG_TARGET_TRIPLES
809 CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
810 CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
811 putvar $CFG_LLVM_BUILD_DIR
812 putvar $CFG_LLVM_INST_DIR
815 # Munge any paths that appear in config.mk back to posix-y
816 perl -i.bak -p -e 's@ ([a-zA-Z]):[/\\]@ /\1/@go;' \
817 -e 's@\\@/@go;' config.tmp
821 copy_if_changed ${CFG_SRC_DIR}Makefile.in ./Makefile
822 move_if_changed config.tmp config.mk