]> git.lizzy.rs Git - rust.git/blob - configure
use a more conservative inhabitableness rule
[rust.git] / configure
1 #!/bin/sh
2
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
5     POSIX_SHELL="true"
6     export POSIX_SHELL
7     exec /usr/bin/env bash $0 "$@"
8 fi
9 unset POSIX_SHELL # clear it so if we invoke other scripts, they run as bash as well
10
11 msg() {
12     echo "configure: $*"
13 }
14
15 step_msg() {
16     msg
17     msg "$1"
18     msg
19 }
20
21 warn() {
22     echo "configure: WARNING: $1"
23 }
24
25 err() {
26     echo "configure: error: $1"
27     exit 1
28 }
29
30 run() {
31     msg "$@"
32     "$@"
33 }
34
35 need_ok() {
36     if [ $? -ne 0 ]
37     then
38         err "$1"
39     fi
40 }
41
42 need_cmd() {
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"
46     fi
47 }
48
49 make_dir() {
50     if [ ! -d $1 ]
51     then
52         run mkdir -p $1
53     fi
54 }
55
56 copy_if_changed() {
57     if cmp -s $1 $2
58     then
59         msg "leaving $2 unchanged"
60     else
61         run cp -f $1 $2
62         chmod u-w $2 # make copied artifact read-only
63     fi
64 }
65
66 move_if_changed() {
67     if cmp -s $1 $2
68     then
69         msg "leaving $2 unchanged"
70     else
71         run mv -f $1 $2
72         chmod u-w $2 # make moved artifact read-only
73     fi
74 }
75
76 putvar() {
77     local T
78     eval T=\$$1
79     eval TLEN=\${#$1}
80     if [ $TLEN -gt 35 ]
81     then
82         printf "configure: %-20s := %.35s ...\n" $1 "$T"
83     else
84         printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
85     fi
86     printf "%-20s := %s\n" $1 "$T" >>config.tmp
87 }
88
89 putpathvar() {
90     local T
91     eval T=\$$1
92     eval TLEN=\${#$1}
93     if [ $TLEN -gt 35 ]
94     then
95         printf "configure: %-20s := %.35s ...\n" $1 "$T"
96     else
97         printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
98     fi
99     if [ -z "$T" ]
100     then
101         printf "%-20s := \n" $1 >>config.tmp
102     else
103         printf "%-20s := \"%s\"\n" $1 "$T" >>config.tmp
104     fi
105 }
106
107 probe() {
108     local V=$1
109     shift
110     local P
111     local T
112     for P
113     do
114         T=$(command -v $P 2>&1)
115         if [ $? -eq 0 ]
116         then
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" ]
120             then
121               VER="($VER0)"
122             else
123               VER=""
124             fi
125             break
126         else
127             VER=""
128             T=""
129         fi
130     done
131     eval $V=\$T
132     putpathvar $V "$VER"
133 }
134
135 probe_need() {
136     probe $*
137     local V=$1
138     shift
139     eval VV=\$$V
140     if [ -z "$VV" ]
141     then
142         err "$V needed, but unable to find any of: $*"
143     fi
144 }
145
146 validate_opt () {
147     for arg in $CFG_CONFIGURE_ARGS
148     do
149         isArgValid=0
150         for option in $BOOL_OPTIONS
151         do
152             if test --disable-$option = $arg
153             then
154                 isArgValid=1
155             fi
156             if test --enable-$option = $arg
157             then
158                 isArgValid=1
159             fi
160         done
161         for option in $VAL_OPTIONS
162         do
163             if echo "$arg" | grep -q -- "--$option="
164             then
165                 isArgValid=1
166             fi
167         done
168         if [ "$arg" = "--help" ]
169         then
170             echo
171             echo "No more help available for Configure options,"
172             echo "check the Wiki or join our IRC channel"
173             break
174         else
175             if test $isArgValid -eq 0
176             then
177                 err "Option '$arg' is not recognized"
178             fi
179         fi
180     done
181 }
182
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.
186 #
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.
191
192 valopt_core() {
193     VAL_OPTIONS="$VAL_OPTIONS $2"
194
195     local SAVE=$1
196     local OP=$2
197     local DEFAULT=$3
198     shift
199     shift
200     shift
201     local DOC="$*"
202     if [ $HELP -eq 0 ]
203     then
204         local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
205         local V="CFG_${UOP}"
206         local V_PROVIDED="${V}_PROVIDED"
207         eval $V="$DEFAULT"
208         for arg in $CFG_CONFIGURE_ARGS
209         do
210             if echo "$arg" | grep -q -- "--$OP="
211             then
212                 val=$(echo "$arg" | cut -f2 -d=)
213                 eval $V=$val
214                 eval $V_PROVIDED=1
215             fi
216         done
217         if [ "$SAVE" = "save" ]
218         then
219             putvar $V
220         fi
221     else
222         if [ -z "$DEFAULT" ]
223         then
224             DEFAULT="<none>"
225         fi
226         OP="${OP}=[${DEFAULT}]"
227         printf "    --%-30s %s\n" "$OP" "$DOC"
228     fi
229 }
230
231 valopt_nosave() {
232     valopt_core nosave "$@"
233 }
234
235 valopt() {
236     valopt_core save "$@"
237 }
238
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.
242 #
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
246 # two are built.
247
248 opt_core() {
249     BOOL_OPTIONS="$BOOL_OPTIONS $2"
250
251     local SAVE=$1
252     local OP=$2
253     local DEFAULT=$3
254     shift
255     shift
256     shift
257     local DOC="$*"
258     local FLAG=""
259
260     if [ $DEFAULT -eq 0 ]
261     then
262         FLAG="enable"
263         DEFAULT_FLAG="disable"
264     else
265         FLAG="disable"
266         DEFAULT_FLAG="enable"
267         DOC="don't $DOC"
268     fi
269
270     if [ $HELP -eq 0 ]
271     then
272         for arg in $CFG_CONFIGURE_ARGS
273         do
274             if [ "$arg" = "--${FLAG}-${OP}" ]
275             then
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"
280                 eval $V=1
281                 eval $V_PROVIDED=1
282                 if [ "$SAVE" = "save" ]
283                 then
284                    putvar $V
285                 fi
286             elif [ "$arg" = "--${DEFAULT_FLAG}-${OP}" ]
287             then
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"
291                 eval $V_PROVIDED=1
292             fi
293         done
294     else
295         if [ -n "$META" ]
296         then
297             OP="$OP=<$META>"
298         fi
299         printf "    --%-30s %s\n" "$FLAG-$OP" "$DOC"
300      fi
301 }
302
303 opt_nosave() {
304     opt_core nosave "$@"
305 }
306
307 opt() {
308     opt_core save "$@"
309 }
310
311 envopt() {
312     local NAME=$1
313     local V="CFG_${NAME}"
314     eval VV=\$$V
315
316     # If configure didn't set a value already, then check environment.
317     #
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.)
322     if [ -z "$VV" ]
323     then
324         eval $V=\$$NAME
325         eval VV=\$$V
326     fi
327
328     # If script or environment provided a value, save it.
329     if [ -n "$VV" ]
330     then
331         putvar $V
332     fi
333 }
334
335 enable_if_not_disabled() {
336     local OP=$1
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
342         eval $ENAB_V=1
343     fi
344 }
345
346 to_gnu_triple() {
347     case $1 in
348         i686-pc-windows-gnu) echo i686-w64-mingw32 ;;
349         x86_64-pc-windows-gnu) echo x86_64-w64-mingw32 ;;
350         *) echo $1 ;;
351     esac
352 }
353
354 # Prints the absolute path of a directory to stdout
355 abs_path() {
356     local _path="$1"
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
359     # for good measure.
360     (unset CDPATH && cd "$_path" > /dev/null && pwd)
361 }
362
363 HELP=0
364 for arg; do
365     case "$arg" in
366         --help) HELP=1;;
367     esac
368 done
369
370 msg "looking for configure programs"
371 need_cmd cmp
372 need_cmd mkdir
373 need_cmd printf
374 need_cmd cut
375 need_cmd head
376 need_cmd grep
377 need_cmd xargs
378 need_cmd cp
379 need_cmd find
380 need_cmd uname
381 need_cmd date
382 need_cmd tr
383 need_cmd sed
384 need_cmd file
385 need_cmd make
386
387 msg "inspecting environment"
388
389 CFG_OSTYPE=$(uname -s)
390 CFG_CPUTYPE=$(uname -m)
391
392 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
393 then
394     # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
395     # instead.
396     if sysctl hw.optional.x86_64 | grep -q ': 1'
397     then
398         CFG_CPUTYPE=x86_64
399     fi
400 fi
401
402 # The goal here is to come up with the same triple as LLVM would,
403 # at least for the subset of platforms we're willing to target.
404
405 case $CFG_OSTYPE in
406
407     Linux)
408         CFG_OSTYPE=unknown-linux-gnu
409         ;;
410
411     FreeBSD)
412         CFG_OSTYPE=unknown-freebsd
413         ;;
414
415     DragonFly)
416         CFG_OSTYPE=unknown-dragonfly
417         ;;
418
419     Bitrig)
420         CFG_OSTYPE=unknown-bitrig
421         ;;
422
423     OpenBSD)
424         CFG_OSTYPE=unknown-openbsd
425        ;;
426
427     NetBSD)
428             CFG_OSTYPE=unknown-netbsd
429             ;;
430
431     Darwin)
432         CFG_OSTYPE=apple-darwin
433         ;;
434
435     SunOS)
436         CFG_OSTYPE=sun-solaris
437         CFG_CPUTYPE=$(isainfo -n)
438         ;;
439
440     Haiku)
441         CFG_OSTYPE=unknown-haiku
442         ;;
443
444     MINGW*)
445         # msys' `uname` does not print gcc configuration, but prints msys
446         # configuration. so we cannot believe `uname -m`:
447         # msys1 is always i686 and msys2 is always x86_64.
448         # instead, msys defines $MSYSTEM which is MINGW32 on i686 and
449         # MINGW64 on x86_64.
450         CFG_CPUTYPE=i686
451         CFG_OSTYPE=pc-windows-gnu
452         if [ "$MSYSTEM" = MINGW64 ]
453         then
454             CFG_CPUTYPE=x86_64
455         fi
456         ;;
457
458     MSYS*)
459         CFG_OSTYPE=pc-windows-gnu
460         ;;
461
462 # Thad's Cygwin identifiers below
463
464 #   Vista 32 bit
465     CYGWIN_NT-6.0)
466         CFG_OSTYPE=pc-windows-gnu
467         CFG_CPUTYPE=i686
468         ;;
469
470 #   Vista 64 bit
471     CYGWIN_NT-6.0-WOW64)
472         CFG_OSTYPE=pc-windows-gnu
473         CFG_CPUTYPE=x86_64
474         ;;
475
476 #   Win 7 32 bit
477     CYGWIN_NT-6.1)
478         CFG_OSTYPE=pc-windows-gnu
479         CFG_CPUTYPE=i686
480         ;;
481
482 #   Win 7 64 bit
483     CYGWIN_NT-6.1-WOW64)
484         CFG_OSTYPE=pc-windows-gnu
485         CFG_CPUTYPE=x86_64
486         ;;
487
488 #   Win 8 # uname -s on 64-bit cygwin does not contain WOW64, so simply use uname -m to detect arch (works in my install)
489     CYGWIN_NT-6.3)
490         CFG_OSTYPE=pc-windows-gnu
491         ;;
492 # We do not detect other OS such as XP/2003 using 64 bit using uname.
493 # If we want to in the future, we will need to use Cygwin - Chuck's csih helper in /usr/lib/csih/winProductName.exe or alternative.
494     *)
495         err "unknown OS type: $CFG_OSTYPE"
496         ;;
497 esac
498
499
500 case $CFG_CPUTYPE in
501
502     i386 | i486 | i686 | i786 | x86)
503         CFG_CPUTYPE=i686
504         ;;
505
506     xscale | arm)
507         CFG_CPUTYPE=arm
508         ;;
509
510     armv6l)
511         CFG_CPUTYPE=arm
512         CFG_OSTYPE="${CFG_OSTYPE}eabihf"
513         ;;
514
515     armv7l)
516         CFG_CPUTYPE=armv7
517         CFG_OSTYPE="${CFG_OSTYPE}eabihf"
518         ;;
519
520     aarch64 | arm64)
521         CFG_CPUTYPE=aarch64
522         ;;
523
524     powerpc | ppc)
525         CFG_CPUTYPE=powerpc
526         ;;
527
528     powerpc64 | ppc64)
529         CFG_CPUTYPE=powerpc64
530         ;;
531
532     powerpc64le | ppc64le)
533         CFG_CPUTYPE=powerpc64le
534         ;;
535
536     s390x)
537         CFG_CPUTYPE=s390x
538         ;;
539
540     x86_64 | x86-64 | x64 | amd64)
541         CFG_CPUTYPE=x86_64
542         ;;
543
544     mips | mips64)
545         if [ "$CFG_CPUTYPE" = "mips64" ]; then
546             CFG_OSTYPE="${CFG_OSTYPE}abi64"
547         fi
548         ENDIAN=$(printf '\1' | od -dAn)
549         if [ "$ENDIAN" -eq 1 ]; then
550             CFG_CPUTYPE="${CFG_CPUTYPE}el"
551         elif [ "$ENDIAN" -ne 256 ]; then
552             err "unknown endianness: $ENDIAN (expecting 1 for little or 256 for big)"
553         fi
554         ;;
555
556     BePC)
557         CFG_CPUTYPE=i686
558         ;;
559
560     *)
561         err "unknown CPU type: $CFG_CPUTYPE"
562 esac
563
564 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
565 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
566 then
567     # $SHELL does not exist in standard 'sh', so probably only exists
568     # if configure is running in an interactive bash shell. /usr/bin/env
569     # exists *everywhere*.
570     BIN_TO_PROBE="$SHELL"
571     if [ ! -r "$BIN_TO_PROBE" ]; then
572         if [ -r "/usr/bin/env" ]; then
573             BIN_TO_PROBE="/usr/bin/env"
574         else
575             warn "Cannot check if the userland is i686 or x86_64"
576         fi
577     fi
578     file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64"
579     if [ $? != 0 ]; then
580         msg "i686 userland on x86_64 Linux kernel"
581         CFG_CPUTYPE=i686
582     fi
583 fi
584
585
586 DEFAULT_BUILD="${CFG_CPUTYPE}-${CFG_OSTYPE}"
587
588 CFG_SRC_DIR="$(abs_path $(dirname $0))/"
589 CFG_SRC_DIR_RELATIVE="$(dirname $0)/"
590 CFG_BUILD_DIR="$(pwd)/"
591 CFG_SELF="$0"
592 CFG_CONFIGURE_ARGS="$@"
593
594
595 case "${CFG_SRC_DIR}" in
596     *\ * )
597         err "The path to the rust source directory contains spaces, which is not supported"
598         ;;
599     *)
600         ;;
601 esac
602
603
604 OPTIONS=""
605 if [ "$HELP" -eq 1 ]
606 then
607     echo
608     echo "Usage: $CFG_SELF [options]"
609     echo
610     echo "Options:"
611     echo
612 else
613     msg "recreating config.tmp"
614     echo '' >config.tmp
615
616     step_msg "processing $CFG_SELF args"
617 fi
618
619 BOOL_OPTIONS=""
620 VAL_OPTIONS=""
621
622 opt debug 0 "debug mode; disables optimization unless \`--enable-optimize\` given"
623 opt valgrind 0 "run tests with valgrind (memcheck by default)"
624 opt helgrind 0 "run tests with helgrind instead of memcheck"
625 opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind"
626 opt docs     1 "build standard library documentation"
627 opt compiler-docs     0 "build compiler documentation"
628 opt optimize-tests 1 "build tests with optimizations"
629 opt debuginfo-tests 0 "build tests with debugger metadata"
630 opt quiet-tests 0 "enable quieter output when running tests"
631 opt libcpp 1 "build llvm with libc++ instead of libstdc++ when using clang"
632 opt llvm-assertions 0 "build LLVM with assertions"
633 opt debug-assertions 0 "build with debugging assertions"
634 opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
635 opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
636 opt sccache 0 "invoke gcc/clang via sccache to reuse object files between builds"
637 opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
638 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"
639 opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
640 opt llvm-link-shared 0 "prefer shared linking to LLVM (llvm-config --link-shared)"
641 opt rpath 1 "build rpaths into rustc itself"
642 opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0"
643 # This is used by the automation to produce single-target nightlies
644 opt dist-host-only 0 "only install bins for the host architecture"
645 opt inject-std-version 1 "inject the current compiler version of libstd into programs"
646 opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
647 opt codegen-tests 1 "run the src/test/codegen tests"
648 opt option-checking 1 "complain about unrecognized options in this configure script"
649 opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
650 opt locked-deps 0 "force Cargo.lock to be up to date"
651 opt vendor 0 "enable usage of vendored Rust crates"
652 opt sanitizers 0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"
653 opt dist-src 1 "when building tarballs enables building a source tarball"
654
655 # Optimization and debugging options. These may be overridden by the release channel, etc.
656 opt_nosave optimize 1 "build optimized rust code"
657 opt_nosave optimize-cxx 1 "build optimized C++ code"
658 opt_nosave optimize-llvm 1 "build optimized LLVM"
659 opt_nosave llvm-assertions 0 "build LLVM with assertions"
660 opt_nosave debug-assertions 0 "build with debugging assertions"
661 opt_nosave llvm-release-debuginfo 0 "build LLVM with debugger metadata"
662 opt_nosave debuginfo 0 "build with debugger metadata"
663 opt_nosave debuginfo-lines 0 "build with line number debugger metadata"
664 opt_nosave debuginfo-only-std 0 "build only libstd with debugging information"
665 opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill"
666
667 valopt localstatedir "/var/lib" "local state directory"
668 valopt sysconfdir "/etc" "install system configuration files"
669
670 valopt datadir "${CFG_PREFIX}/share" "install data"
671 valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
672 valopt llvm-root "" "set LLVM root"
673 valopt python "" "set path to python"
674 valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located"
675 valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
676 valopt android-cross-path "" "Android NDK standalone path (deprecated)"
677 valopt i686-linux-android-ndk "" "i686-linux-android NDK standalone path"
678 valopt arm-linux-androideabi-ndk "" "arm-linux-androideabi NDK standalone path"
679 valopt armv7-linux-androideabi-ndk "" "armv7-linux-androideabi NDK standalone path"
680 valopt aarch64-linux-android-ndk "" "aarch64-linux-android NDK standalone path"
681 valopt nacl-cross-path  "" "NaCl SDK path (Pepper Canary is recommended). Must be absolute!"
682 valopt musl-root "/usr/local" "MUSL root installation directory (deprecated)"
683 valopt musl-root-x86_64 "" "x86_64-unknown-linux-musl install directory"
684 valopt musl-root-i686 "" "i686-unknown-linux-musl install directory"
685 valopt musl-root-arm "" "arm-unknown-linux-musleabi install directory"
686 valopt musl-root-armhf "" "arm-unknown-linux-musleabihf install directory"
687 valopt musl-root-armv7 "" "armv7-unknown-linux-musleabihf install directory"
688 valopt extra-filename "" "Additional data that is hashed and passed to the -C extra-filename flag"
689 valopt qemu-armhf-rootfs "" "rootfs in qemu testing, you probably don't want to use this"
690
691 if [ -e ${CFG_SRC_DIR}.git ]
692 then
693     valopt release-channel "dev" "the name of the release channel to build"
694 else
695     # If we have no git directory then we are probably a tarball distribution
696     # and should default to stable channel - Issue 28322
697     probe CFG_GIT          git
698     msg "git: no git directory. Changing default release channel to stable"
699     valopt release-channel "stable" "the name of the release channel to build"
700 fi
701
702 # Used on systems where "cc" and "ar" are unavailable
703 valopt default-linker "cc" "the default linker"
704 valopt default-ar     "ar" "the default ar"
705
706 # Many of these are saved below during the "writing configuration" step
707 # (others are conditionally saved).
708 opt_nosave manage-submodules 1 "let the build manage the git submodules"
709 opt_nosave clang 0 "prefer clang to gcc for building the runtime"
710 opt_nosave jemalloc 1 "build liballoc with jemalloc"
711 opt elf-tls 1 "elf thread local storage on platforms where supported"
712 opt full-bootstrap 0 "build three compilers instead of two"
713 opt extended 0 "build an extended rust tool set"
714
715 valopt_nosave prefix "/usr/local" "set installation prefix"
716 valopt_nosave local-rust-root "/usr/local" "set prefix for local rust binary"
717 valopt_nosave host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
718 valopt_nosave target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
719 valopt_nosave mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
720 valopt_nosave docdir "${CFG_PREFIX}/share/doc/rust" "install documentation in PATH"
721
722 # On Windows this determines root of the subtree for target libraries.
723 # Host runtime libs always go to 'bin'.
724 valopt libdir "${CFG_PREFIX}/lib" "install libraries"
725
726 case "$CFG_LIBDIR" in
727     "$CFG_PREFIX"/*) CAT_INC=2;;
728     "$CFG_PREFIX"*)  CAT_INC=1;;
729     *)
730         err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
731 esac
732
733 CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
734
735 if [ $HELP -eq 1 ]
736 then
737     echo
738     exit 0
739 fi
740
741 # Validate Options
742 if [ -z "$CFG_DISABLE_OPTION_CHECKING" ]
743 then
744     step_msg "validating $CFG_SELF args"
745     validate_opt
746 fi
747
748 # Validate the release channel, and configure options
749 case "$CFG_RELEASE_CHANNEL" in
750     nightly )
751         msg "overriding settings for $CFG_RELEASE_CHANNEL"
752         enable_if_not_disabled llvm-assertions
753         # FIXME(stage0) re-enable this on the next stage0 now that #35566 is
754         # fixed
755         case "$CFG_BUILD" in
756           *-pc-windows-gnu)
757             ;;
758           *)
759             CFG_ENABLE_DEBUGINFO_LINES=1
760             CFG_ENABLE_DEBUGINFO_ONLY_STD=1
761             ;;
762         esac
763
764         ;;
765     beta | stable)
766         msg "overriding settings for $CFG_RELEASE_CHANNEL"
767         case "$CFG_BUILD" in
768           *-pc-windows-gnu)
769             ;;
770           *)
771             CFG_ENABLE_DEBUGINFO_LINES=1
772             CFG_ENABLE_DEBUGINFO_ONLY_STD=1
773             ;;
774         esac
775         ;;
776     dev)
777         ;;
778     *)
779         err "release channel must be 'dev', 'nightly', 'beta' or 'stable'"
780         ;;
781 esac
782
783 # Adjust perf and debug options for debug mode
784 if [ -n "$CFG_ENABLE_DEBUG" ]; then
785     msg "debug mode enabled, setting performance options"
786     if [ -z "$CFG_ENABLE_OPTIMIZE_PROVIDED" ]; then
787         msg "optimization not explicitly enabled, disabling optimization"
788         CFG_DISABLE_OPTIMIZE=1
789         CFG_DISABLE_OPTIMIZE_CXX=1
790     fi
791
792     # Set following variables to 1 unless setting already provided
793     enable_if_not_disabled debug-assertions
794     enable_if_not_disabled debug-jemalloc
795     enable_if_not_disabled debuginfo
796     enable_if_not_disabled llvm-assertions
797 fi
798
799 # OK, now write the debugging options
800 if [ -n "$CFG_DISABLE_OPTIMIZE" ]; then putvar CFG_DISABLE_OPTIMIZE; fi
801 if [ -n "$CFG_DISABLE_OPTIMIZE_CXX" ]; then putvar CFG_DISABLE_OPTIMIZE_CXX; fi
802 if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then putvar CFG_DISABLE_OPTIMIZE_LLVM; fi
803 if [ -n "$CFG_ENABLE_LLVM_ASSERTIONS" ]; then putvar CFG_ENABLE_LLVM_ASSERTIONS; fi
804 if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTIONS; fi
805 if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO; fi
806 if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
807 if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES; fi
808 if [ -n "$CFG_ENABLE_DEBUGINFO_ONLY_STD" ]; then putvar CFG_ENABLE_DEBUGINFO_ONLY_STD; fi
809 if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
810
811 step_msg "looking for build programs"
812
813 probe_need CFG_CURL curl
814 if [ -z "$CFG_PYTHON_PROVIDED" ]; then
815     probe_need CFG_PYTHON      python2.7 python2 python
816 fi
817
818 python_version=$($CFG_PYTHON -V 2>&1)
819 if [ $(echo $python_version | grep -c '^Python 2\.7') -ne 1 ]; then
820     err "Found $python_version, but Python 2.7 is required"
821 fi
822
823 # If we have no git directory then we are probably a tarball distribution
824 # and shouldn't attempt to load submodules
825 if [ ! -e ${CFG_SRC_DIR}.git ]
826 then
827     probe CFG_GIT          git
828     msg "git: no git directory. disabling submodules"
829     CFG_DISABLE_MANAGE_SUBMODULES=1
830 else
831     probe_need CFG_GIT     git
832 fi
833
834 # Use `md5sum` on GNU platforms, or `md5 -q` on BSD
835 probe CFG_MD5              md5
836 probe CFG_MD5SUM           md5sum
837 if [ -n "$CFG_MD5" ]
838 then
839     CFG_HASH_COMMAND="$CFG_MD5 -q | cut -c 1-8"
840 elif [ -n "$CFG_MD5SUM" ]
841 then
842     CFG_HASH_COMMAND="$CFG_MD5SUM | cut -c 1-8"
843 else
844     err 'could not find one of: md5 md5sum'
845 fi
846 putvar CFG_HASH_COMMAND
847
848 probe CFG_CLANG            clang++
849 probe CFG_CCACHE           ccache
850 probe CFG_GCC              gcc
851 probe CFG_LD               ld
852 probe CFG_VALGRIND         valgrind
853 probe CFG_PERF             perf
854 probe CFG_ISCC             iscc
855 probe CFG_ANTLR4           antlr4
856 probe CFG_GRUN             grun
857 probe CFG_FLEX             flex
858 probe CFG_BISON            bison
859 probe CFG_GDB              gdb
860 probe CFG_LLDB             lldb
861
862 if [ -n "$CFG_ENABLE_NINJA" ]
863 then
864   probe CFG_NINJA            ninja
865   if [ -z "$CFG_NINJA" ]
866   then
867     # On Debian and Fedora, the `ninja` binary is an IRC bot, so the build tool was
868     # renamed. Handle this case.
869     probe CFG_NINJA            ninja-build
870   fi
871 fi
872
873 # For building LLVM
874 if [ -z "$CFG_LLVM_ROOT" ]
875 then
876   probe_need CFG_CMAKE cmake
877 fi
878
879 # On MacOS X, invoking `javac` pops up a dialog if the JDK is not
880 # installed. Since `javac` is only used if `antlr4` is available,
881 # probe for it only in this case.
882 if [ -n "$CFG_ANTLR4" ]
883 then
884    CFG_ANTLR4_JAR="\"$(find /usr/ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
885    if [ "x" = "x$CFG_ANTLR4_JAR" ]
886    then
887      CFG_ANTLR4_JAR="\"$(find ~ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
888    fi
889    putvar CFG_ANTLR4_JAR      $CFG_ANTLR4_JAR
890    probe CFG_JAVAC            javac
891 fi
892
893 # the valgrind rpass tests will fail if you don't have a valgrind, but they're
894 # only disabled if you opt out.
895 if [ -z "$CFG_VALGRIND" ]
896 then
897     # If the user has explicitly asked for valgrind tests, then fail
898     if [ -n "$CFG_ENABLE_VALGRIND" ] && [ -n "$CFG_ENABLE_VALGRIND_PROVIDED" ]
899     then
900         err "No valgrind present, but valgrind tests explicitly requested"
901     else
902         CFG_DISABLE_VALGRIND_RPASS=1
903         putvar CFG_DISABLE_VALGRIND_RPASS
904     fi
905 fi
906
907 if [ -n "$CFG_LLDB" ]
908 then
909     # Store LLDB's version
910     CFG_LLDB_VERSION=$($CFG_LLDB --version 2>/dev/null | head -1)
911     putvar CFG_LLDB_VERSION
912
913     # If CFG_LLDB_PYTHON_DIR is not already set from the outside and valid, try to read it from
914     # LLDB via the -P commandline options.
915     if [ -z "$CFG_LLDB_PYTHON_DIR" ] || [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
916     then
917         CFG_LLDB_PYTHON_DIR=$($CFG_LLDB -P)
918
919         # If CFG_LLDB_PYTHON_DIR is not a valid directory, set it to something more readable
920         if [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
921         then
922             CFG_LLDB_PYTHON_DIR="LLDB_PYTHON_DIRECTORY_NOT_FOUND"
923         fi
924
925         putvar CFG_LLDB_PYTHON_DIR
926     fi
927 fi
928
929 # LLDB tests on OSX require /usr/bin/python, not something like Homebrew's
930 # /usr/local/bin/python. We're loading a compiled module for LLDB tests which is
931 # only compatible with the system.
932 case $CFG_BUILD in
933     *-apple-darwin)
934         CFG_LLDB_PYTHON=/usr/bin/python
935         ;;
936     *)
937         CFG_LLDB_PYTHON=$CFG_PYTHON
938         ;;
939 esac
940 putvar CFG_LLDB_PYTHON
941
942 # Do some sanity checks if running on buildbot
943 # (these env vars are set by rust-buildbot)
944 if [ -n "$RUST_DIST_SERVER" -a -n "$ALLOW_NONZERO_RLIMIT_CORE" ]; then
945    # Frequently the llvm submodule directory is broken by the build
946    # being killed
947    llvm_lock="${CFG_SRC_DIR}/.git/modules/src/llvm/index.lock"
948    if [ -e "$llvm_lock" ]; then
949        step_msg "removing $llvm_lock"
950        rm -f "$llvm_lock"
951    fi
952 fi
953
954 step_msg "looking for target specific programs"
955
956 probe CFG_ADB        adb
957
958 BIN_SUF=
959 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ]
960 then
961     BIN_SUF=.exe
962 fi
963
964 # --enable-local-rebuild implies --enable-local-rust too
965 if [ -n "$CFG_ENABLE_LOCAL_REBUILD" ]
966 then
967     if [ -z "$CFG_ENABLE_LOCAL_RUST" ]
968     then
969         CFG_ENABLE_LOCAL_RUST=1
970         putvar CFG_ENABLE_LOCAL_RUST
971     fi
972 fi
973
974 if [ -n "$CFG_ENABLE_LOCAL_RUST" ]
975 then
976     system_rustc=$(which rustc)
977     if [ -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} ]
978     then
979         : # everything already configured
980     elif [ -n "$system_rustc" ]
981     then
982         # we assume that rustc is in a /bin directory
983         CFG_LOCAL_RUST_ROOT=${system_rustc%/bin/rustc}
984     else
985         err "no local rust to use"
986     fi
987
988     CMD="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
989     LRV=`LD_LIBRARY_PATH=${CFG_LOCAL_RUST_ROOT}/lib $CMD --version`
990     if [ $? -ne 0 ]
991     then
992         step_msg "failure while running $CMD --version"
993         exit 1
994     fi
995     step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
996     putvar CFG_LOCAL_RUST_ROOT
997 fi
998
999 # Same with jemalloc.  save the setting here.
1000 if [ -n "$CFG_DISABLE_JEMALLOC" ]
1001 then
1002     putvar CFG_DISABLE_JEMALLOC
1003 fi
1004
1005 # All safeguards based on $CFG_ENABLE_CLANG should occur before this
1006 # point in the script; after this point, script logic should inspect
1007 # $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG.
1008
1009 # Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS,LDFLAGS}
1010 envopt CC
1011 envopt CXX
1012 envopt CPP
1013 envopt CFLAGS
1014 envopt CXXFLAGS
1015 envopt LDFLAGS
1016
1017 # a little post-processing of various config values
1018 CFG_PREFIX=${CFG_PREFIX%/}
1019 CFG_MANDIR=${CFG_MANDIR%/}
1020 CFG_DOCDIR=${CFG_DOCDIR%/}
1021 CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
1022 CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"
1023 CFG_SUPPORTED_TARGET=""
1024 for target_file in ${CFG_SRC_DIR}mk/cfg/*.mk; do
1025   CFG_SUPPORTED_TARGET="${CFG_SUPPORTED_TARGET} $(basename "$target_file" .mk)"
1026 done
1027
1028 # copy build-triples to host-triples so that builds are a subset of hosts
1029 V_TEMP=""
1030 for i in $CFG_BUILD $CFG_HOST;
1031 do
1032    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1033 done
1034 CFG_HOST=$V_TEMP
1035
1036 # copy host-triples to target-triples so that hosts are a subset of targets
1037 V_TEMP=""
1038 for i in $CFG_HOST $CFG_TARGET;
1039 do
1040    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1041 done
1042 CFG_TARGET=$V_TEMP
1043
1044 step_msg "writing configuration"
1045
1046 putvar CFG_SRC_DIR
1047 putvar CFG_SRC_DIR_RELATIVE
1048 putvar CFG_BUILD_DIR
1049 putvar CFG_OSTYPE
1050 putvar CFG_CPUTYPE
1051 putvar CFG_CONFIGURE_ARGS
1052 putvar CFG_PREFIX
1053 putvar CFG_HOST
1054 putvar CFG_TARGET
1055 putvar CFG_LIBDIR_RELATIVE
1056 putvar CFG_DISABLE_MANAGE_SUBMODULES
1057 putvar CFG_AARCH64_LINUX_ANDROID_NDK
1058 putvar CFG_ARM_LINUX_ANDROIDEABI_NDK
1059 putvar CFG_ARMV7_LINUX_ANDROIDEABI_NDK
1060 putvar CFG_I686_LINUX_ANDROID_NDK
1061 putvar CFG_NACL_CROSS_PATH
1062 putvar CFG_MANDIR
1063 putvar CFG_DOCDIR
1064 putvar CFG_USING_LIBCPP
1065
1066 # Avoid spurious warnings from clang by feeding it original source on
1067 # ccache-miss rather than preprocessed input.
1068 if [ -n "$CFG_ENABLE_CCACHE" ] && [ -n "$CFG_USING_CLANG" ]
1069 then
1070     CFG_CCACHE_CPP2=1
1071     putvar CFG_CCACHE_CPP2
1072 fi
1073
1074 if [ -n "$CFG_ENABLE_CCACHE" ]
1075 then
1076     CFG_CCACHE_BASEDIR=${CFG_SRC_DIR}
1077     putvar CFG_CCACHE_BASEDIR
1078 fi
1079
1080
1081 putvar CFG_LLVM_SRC_DIR
1082
1083 for t in $CFG_HOST
1084 do
1085     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1086     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1087     putvar $CFG_LLVM_BUILD_DIR
1088     putvar $CFG_LLVM_INST_DIR
1089 done
1090
1091 msg
1092 copy_if_changed ${CFG_SRC_DIR}src/bootstrap/mk/Makefile.in ./Makefile
1093 move_if_changed config.tmp config.mk
1094 rm -f config.tmp
1095 touch config.stamp
1096
1097 if [ -z "$CFG_ENABLE_DEBUG" ]; then
1098     step_msg "configured in release mode. for development consider --enable-debug"
1099 else
1100     step_msg "complete"
1101 fi
1102
1103 if [ "$CFG_SRC_DIR" = `pwd` ]; then
1104     X_PY=x.py
1105 else
1106     X_PY=${CFG_SRC_DIR_RELATIVE}x.py
1107 fi
1108
1109 msg "run \`python ${X_PY} --help\`"
1110 msg