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"
200 msg "inspecting environment"
202 CFG_OSTYPE=$(uname -s)
203 CFG_CPUTYPE=$(uname -m)
205 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
207 # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
209 if sysctl hw.optional.x86_64 | grep -q ': 1'
215 # The goal here is to come up with the same triple as LLVM would,
216 # at least for the subset of platforms we're willing to target.
221 CFG_OSTYPE=unknown-linux-gnu
225 CFG_OSTYPE=unknown-freebsd
229 CFG_OSTYPE=apple-darwin
233 CFG_OSTYPE=pc-mingw32
237 err "unknown OS type: $CFG_OSTYPE"
244 i386 | i486 | i686 | i786 | x86)
252 x86_64 | x86-64 | x64 | amd64)
257 err "unknown CPU type: $CFG_CPUTYPE"
260 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
261 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
263 file -L "$SHELL" | grep -q "x86[_-]64"
270 DEFAULT_HOST_TRIPLE="${CFG_CPUTYPE}-${CFG_OSTYPE}"
272 CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
273 CFG_BUILD_DIR="$(pwd)/"
274 CFG_SELF=${CFG_SRC_DIR}$(basename $0)
275 CFG_CONFIGURE_ARGS="$@"
279 if [ "$1" = "--help" ]
284 echo "Usage: $CFG_SELF [options]"
289 msg "recreating config.tmp"
292 step_msg "processing $CFG_SELF args"
295 opt sharedstd 1 "build libstd as a shared library"
296 opt valgrind 1 "run tests with valgrind (memcheck by default)"
297 opt helgrind 0 "run tests with helgrind instead of memcheck"
298 opt docs 1 "build documentation"
299 opt optimize 1 "build optimized rust code"
300 opt optimize-cxx 1 "build optimized C++ code"
301 opt optimize-llvm 1 "build optimized LLVM"
302 opt debug 0 "build with extra debug fun"
303 opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
304 opt manage-submodules 1 "let the build manage the git submodules"
305 opt mingw-cross 0 "cross-compile for win32 using mingw"
306 opt clang 0 "prefer clang to gcc for building the runtime"
307 opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
308 opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
309 valopt prefix "/usr/local" "set installation prefix"
310 valopt local-rust-root "/usr/local" "set prefix for local rust binary"
311 valopt llvm-root "" "set LLVM root"
312 valopt host-triple "${DEFAULT_HOST_TRIPLE}" "LLVM host triple"
313 valopt target-triples "${CFG_HOST_TRIPLE}" "LLVM target triples"
322 step_msg "looking for build programs"
324 probe_need CFG_PERL perl
325 probe_need CFG_CURL curl
326 probe_need CFG_PYTHON python2.7 python2.6 python2 python
328 python_version=$($CFG_PYTHON -V 2>&1)
329 if [ $(echo $python_version | grep -c '^Python 2\.[4567]') -ne 1 ]; then
330 err "Found $python_version, but LLVM requires Python 2.4-2.7"
333 # If we have no git directory then we are probably a tarball distribution
334 # and shouldn't attempt to load submodules
335 if [ ! -e ${CFG_SRC_DIR}.git ]
338 msg "git: no git directory. disabling submodules"
339 CFG_DISABLE_MANAGE_SUBMODULES=1
341 probe_need CFG_GIT git
344 probe CFG_CLANG clang++
347 probe CFG_LLVM_CONFIG llvm-config
348 probe CFG_VALGRIND valgrind
351 probe CFG_LLNEXTGEN LLnextgen
352 probe CFG_PANDOC pandoc
353 probe CFG_PDFLATEX pdflatex
354 probe CFG_XETEX xetex
355 probe CFG_LUATEX luatex
356 probe CFG_NODE nodejs node
357 if [ "$CFG_OSTYPE" = "unknown-linux-gnu" ]
359 probe CFG_PAXCTL paxctl /sbin/paxctl
363 if [ ! -z "$CFG_PANDOC" ]
365 PANDOC_VER_LINE=$(pandoc --version | grep '^pandoc ')
366 PANDOC_VER=${PANDOC_VER_LINE#pandoc }
367 PV_MAJOR_MINOR=${PANDOC_VER%.[0-9]}
368 PV_MAJOR=${PV_MAJOR_MINOR%.[0-9]}
369 PV_MINOR=${PV_MAJOR_MINOR#[0-9].}
370 if [ "$PV_MAJOR" -lt "1" ] || [ "$PV_MINOR" -lt "8" ]
372 step_msg "pandoc $PV_MAJOR.$PV_MINOR is too old. disabling"
377 if [ "$CFG_OSTYPE" = "unknown-linux-gnu" ]
379 if [ ! -z "$CFG_ENABLE_PAX_FLAGS" -a -z "$CFG_PAXCTL" ]
381 err "enabled PaX markings but no paxctl binary found"
384 if [ -z "$CFG_DISABLE_PAX_FLAGS" ]
386 # GRSecurity/PaX detection. This can be very flaky.
389 # /dev/grsec only exists if CONFIG_GRKERNSEC_NO_RBAC is not set.
390 # /proc/sys/kernel/grsecurity is not available if ÇONFIG_GRKERNSEC_SYSCTL is not set.
391 if [ -e /dev/grsec -o -d /proc/sys/kernel/grsecurity ]
394 # /proc/config.gz is normally only available to root, and only if CONFIG_IKCONFIG_PROC has been set.
395 elif [ -r /proc/config.gz -a ! -z "$CFG_ZCAT" ]
397 if "$CFG_ZCAT" /proc/config.gz | grep --quiet "CONFIG_GRKERNSEC=y"
402 elif grep --quiet grsec /proc/version
407 if [ ! -z "$GRSEC_DETECTED" ]
409 step_msg "GRSecurity: yes"
410 if [ ! -z "$CFG_PAXCTL" ]
412 CFG_ENABLE_PAX_FLAGS=1
414 warn "GRSecurity kernel detected but no paxctl binary found: not setting CFG_ENABLE_PAX_FLAGS"
417 step_msg "GRSecurity: no"
422 if [ ! -z "$CFG_ENABLE_LOCAL_RUST" ]
424 if [ ! -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc ]
426 err "no local rust to use"
428 LRV=`${CFG_LOCAL_RUST_ROOT}/bin/rustc --version`
429 step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: " $LRV
433 if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
435 err "either clang or gcc is required"
438 if [ ! -z "$CFG_LLVM_ROOT" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ]
440 step_msg "using custom LLVM at $CFG_LLVM_ROOT"
442 LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config"
443 LLVM_VERSION=$($LLVM_CONFIG --version)
445 case $LLVM_VERSION in
446 (3.1svn|3.1|3.0svn|3.0)
447 msg "found ok version of LLVM: $LLVM_VERSION"
450 err "bad LLVM version: $LLVM_VERSION, need >=3.0svn"
455 if [ ! -z "$CFG_ENABLE_CLANG" ]
457 if [ -z "$CFG_CLANG" ]
459 err "clang requested but not found"
461 CFG_CLANG_VERSION=$("$CFG_CLANG" \
464 | sed 's/.*\(version .*\)/\1/' \
467 case $CFG_CLANG_VERSION in
468 (3.0svn | 3.0 | 3.1 | 4.0 | 4.1)
469 step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
470 CFG_C_COMPILER="clang"
473 err "bad CLANG version: $CFG_CLANG_VERSION, need >=3.0svn"
480 # a little post-processing of various config values
482 CFG_PREFIX=${CFG_PREFIX%/}
483 CFG_TARGET_TRIPLES="$(echo $CFG_TARGET_TRIPLES | tr ',' ' ')"
484 case $CFG_TARGET_TRIPLES in
485 (*$CFG_HOST_TRIPLE*) ;;
486 (*) err "Host triple is not among the target triples." ;;
489 if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
491 err "either clang or gcc is required"
494 if [ ! -z "$CFG_PERF" ]
496 HAVE_PERF_LOGFD=`$CFG_PERF stat --log-fd 2>&1 | grep 'unknown option'`
497 if [ -z "$HAVE_PERF_LOGFD" ];
499 CFG_PERF_WITH_LOGFD=1
500 putvar CFG_PERF_WITH_LOGFD
504 step_msg "making directories"
507 doc doc/core doc/std \
514 for t in $CFG_TARGET_TRIPLES
520 for t in $CFG_TARGET_TRIPLES
526 for t in $CFG_TARGET_TRIPLES
530 isaac bigint sync test arch/i386 arch/x86_64 \
531 libuv libuv/src/ares libuv/src/eio libuv/src/ev
537 # On windows we just store the libraries in the bin directory because
540 if [ "$CFG_OSTYPE" = "pc-mingw32" ]
545 for h in $CFG_TARGET_TRIPLES
547 for t in $CFG_TARGET_TRIPLES
552 make_dir $h/stage$i/bin
555 make_dir $h/stage$i/$CFG_LIBDIR
558 make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/bin
561 make_dir $h/stage$i/$CFG_LIBDIR/rustc/$t/$CFG_LIBDIR
565 make_dir $h/test/run-pass
566 make_dir $h/test/run-pass-fulldeps
567 make_dir $h/test/run-fail
568 make_dir $h/test/compile-fail
569 make_dir $h/test/bench
570 make_dir $h/test/perf
571 make_dir $h/test/pretty
572 make_dir $h/test/doc-tutorial
573 make_dir $h/test/doc-tutorial-ffi
574 make_dir $h/test/doc-tutorial-macros
575 make_dir $h/test/doc-tutorial-borrowed-ptr
576 make_dir $h/test/doc-tutorial-tasks
577 make_dir $h/test/doc-ref
580 # Configure submodules
581 step_msg "configuring submodules"
583 # Have to be in the top of src directory for this
584 if [ -z $CFG_DISABLE_MANAGE_SUBMODULES ]
588 msg "git: submodule sync"
589 "${CFG_GIT}" submodule --quiet sync
591 msg "git: submodule update"
592 "${CFG_GIT}" submodule --quiet update --init
595 msg "git: submodule foreach sync"
596 "${CFG_GIT}" submodule --quiet foreach --recursive git submodule sync
599 msg "git: submodule foreach update"
600 "${CFG_GIT}" submodule --quiet update --init --recursive
603 # NB: this is just for the sake of getting the submodule SHA1 values
604 # and status written into the build log.
605 msg "git: submodule status"
606 "${CFG_GIT}" submodule status --recursive
608 msg "git: submodule clobber"
609 "${CFG_GIT}" submodule --quiet foreach --recursive git clean -dxf
611 "${CFG_GIT}" submodule --quiet foreach --recursive git checkout .
617 # Configure llvm, only if necessary
618 step_msg "looking at LLVM"
619 CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm/
620 for t in $CFG_TARGET_TRIPLES
624 if [ -z $CFG_LLVM_ROOT ]
626 LLVM_BUILD_DIR=${CFG_BUILD_DIR}llvm/$t
627 if [ ! -z "$CFG_DISABLE_OPTIMIZE_LLVM" ]
630 # Just use LLVM straight from its build directory to
631 # avoid 'make install' time
632 LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug+Asserts
634 LLVM_DBG_OPTS="--enable-optimized"
635 LLVM_INST_DIR=$LLVM_BUILD_DIR/Release+Asserts
638 msg "not reconfiguring LLVM, external LLVM root"
639 # The user is using their own LLVM
641 LLVM_INST_DIR=$CFG_LLVM_ROOT
646 if [ ${do_reconfigure} -ne 0 ]
648 # because git is hilarious, it might have put the module index
649 # in a couple places.
650 index1="${CFG_SRC_DIR}.git/modules/src/llvm/index"
651 index2="${CFG_SRC_DIR}src/llvm/.git/index"
652 for index in ${index1} ${index2}
654 config_status="${CFG_BUILD_DIR}llvm/$t/config.status"
655 if test -e ${index} -a \
656 -e ${config_status} -a \
657 ${config_status} -nt ${index}
659 msg "not reconfiguring LLVM, config.status is fresh"
665 if [ ${do_reconfigure} -ne 0 ]
667 msg "configuring LLVM for $t"
669 LLVM_TARGETS="--enable-targets=x86,x86_64"
670 LLVM_BUILD="--build=$t"
671 LLVM_HOST="--host=$t"
672 LLVM_TARGET="--target=$t"
674 # Disable unused LLVM features
675 LLVM_OPTS="$LLVM_DBG_OPTS --disable-docs \
676 --enable-bindings=none --disable-threads \
679 if [ "$CFG_C_COMPILER" = "clang" ]
681 LLVM_CXX_32="clang++ -m32"
682 LLVM_CC_32="clang -m32"
684 LLVM_CXX_64="clang++"
687 LLVM_CXX_32="g++ -m32"
688 LLVM_CC_32="gcc -m32"
694 LLVM_CFLAGS_32="-m32"
695 LLVM_CXXFLAGS_32="-m32"
696 LLVM_LDFLAGS_32="-m32"
702 if echo $t | grep -q x86_64
704 LLVM_CXX=$LLVM_CXX_64
706 LLVM_CFLAGS=$LLVM_CFLAGS_64
707 LLVM_CXXFLAGS=$LLVM_CXXFLAGS_64
708 LLVM_LDFLAGS=$LLVM_LDFLAGS_64
710 LLVM_CXX=$LLVM_CXX_32
712 LLVM_CFLAGS=$LLVM_CFLAGS_32
713 LLVM_CXXFLAGS=$LLVM_CXXFLAGS_32
714 LLVM_LDFLAGS=$LLVM_LDFLAGS_32
720 CXXFLAGS=$LLVM_CXXFLAGS
721 LDFLAGS=$LLVM_LDFLAGS
723 LLVM_FLAGS="$LLVM_TARGETS $LLVM_OPTS $LLVM_BUILD \
724 $LLVM_HOST $LLVM_TARGET"
726 msg "configuring LLVM with:"
737 /* | [a-z]:* | [A-Z]:*)
738 ${CFG_LLVM_SRC_DIR}configure $LLVM_FLAGS
741 ${CFG_BUILD_DIR}${CFG_LLVM_SRC_DIR}configure \
745 need_ok "LLVM configure failed"
749 # Construct variables for LLVM build and install directories for
750 # each target. These will be named
751 # CFG_LLVM_BUILD_DIR_${target_triple} but all the hyphens in
752 # target_triple will be converted to underscore, because bash
753 # variables can't contain hyphens. The makefile will then have to
755 CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
756 CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
757 eval ${CFG_LLVM_BUILD_DIR}="'$LLVM_BUILD_DIR'"
758 eval ${CFG_LLVM_INST_DIR}="'$LLVM_INST_DIR'"
762 step_msg "writing configuration"
768 putvar CFG_CONFIGURE_ARGS
770 putvar CFG_TARGET_TRIPLES
771 putvar CFG_C_COMPILER
773 putvar CFG_DISABLE_MANAGE_SUBMODULES
775 if [ ! -z "$CFG_ENABLE_PAX_FLAGS" ]
777 putvar CFG_ENABLE_PAX_FLAGS
781 if [ ! -z $BAD_PANDOC ]
787 if head -n 1 ${CFG_SRC_DIR}src/snapshots.txt | grep -q '^T'
790 putvar CFG_IN_TRANSITION
793 # Valgrind is only reliable on Linux. On Windows it doesn't work at all, and
794 # on the Mac the dynamic linker causes Valgrind to emit a huge stream of
796 if [ $CFG_OSTYPE != unknown-linux-gnu ] && [ $CFG_OSTYPE != apple-darwin ]
799 putvar CFG_BAD_VALGRIND
803 putvar CFG_LLVM_SRC_DIR
805 for t in $CFG_TARGET_TRIPLES
807 CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
808 CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
809 putvar $CFG_LLVM_BUILD_DIR
810 putvar $CFG_LLVM_INST_DIR
813 # Munge any paths that appear in config.mk back to posix-y
814 perl -i.bak -p -e 's@ ([a-zA-Z]):[/\\]@ /\1/@go;' \
815 -e 's@\\@/@go;' config.tmp
819 copy_if_changed ${CFG_SRC_DIR}Makefile.in ./Makefile
820 move_if_changed config.tmp config.mk