]> git.lizzy.rs Git - rust.git/blob - configure
Auto merge of #39086 - aidanhs:aphs-local-rebuild-no-jemalloc, r=alexcrichton
[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)
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 rustbuild 1 "use the rust and cargo based build system"
648 opt codegen-tests 1 "run the src/test/codegen tests"
649 opt option-checking 1 "complain about unrecognized options in this configure script"
650 opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
651 opt vendor 0 "enable usage of vendored Rust crates"
652
653 # Optimization and debugging options. These may be overridden by the release channel, etc.
654 opt_nosave optimize 1 "build optimized rust code"
655 opt_nosave optimize-cxx 1 "build optimized C++ code"
656 opt_nosave optimize-llvm 1 "build optimized LLVM"
657 opt_nosave llvm-assertions 0 "build LLVM with assertions"
658 opt_nosave debug-assertions 0 "build with debugging assertions"
659 opt_nosave llvm-release-debuginfo 0 "build LLVM with debugger metadata"
660 opt_nosave debuginfo 0 "build with debugger metadata"
661 opt_nosave debuginfo-lines 0 "build with line number debugger metadata"
662 opt_nosave debuginfo-only-std 0 "build only libstd with debugging information"
663 opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill"
664
665 valopt localstatedir "/var/lib" "local state directory"
666 valopt sysconfdir "/etc" "install system configuration files"
667
668 valopt datadir "${CFG_PREFIX}/share" "install data"
669 valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
670 valopt llvm-root "" "set LLVM root"
671 valopt python "" "set path to python"
672 valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located"
673 valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
674 valopt android-cross-path "" "Android NDK standalone path (deprecated)"
675 valopt i686-linux-android-ndk "" "i686-linux-android NDK standalone path"
676 valopt arm-linux-androideabi-ndk "" "arm-linux-androideabi NDK standalone path"
677 valopt armv7-linux-androideabi-ndk "" "armv7-linux-androideabi NDK standalone path"
678 valopt aarch64-linux-android-ndk "" "aarch64-linux-android NDK standalone path"
679 valopt nacl-cross-path  "" "NaCl SDK path (Pepper Canary is recommended). Must be absolute!"
680 valopt musl-root "/usr/local" "MUSL root installation directory (deprecated)"
681 valopt musl-root-x86_64 "" "x86_64-unknown-linux-musl install directory"
682 valopt musl-root-i686 "" "i686-unknown-linux-musl install directory"
683 valopt musl-root-arm "" "arm-unknown-linux-musleabi install directory"
684 valopt musl-root-armhf "" "arm-unknown-linux-musleabihf install directory"
685 valopt musl-root-armv7 "" "armv7-unknown-linux-musleabihf install directory"
686 valopt extra-filename "" "Additional data that is hashed and passed to the -C extra-filename flag"
687
688 if [ -e ${CFG_SRC_DIR}.git ]
689 then
690     valopt release-channel "dev" "the name of the release channel to build"
691 else
692     # If we have no git directory then we are probably a tarball distribution
693     # and should default to stable channel - Issue 28322
694     probe CFG_GIT          git
695     msg "git: no git directory. Changing default release channel to stable"
696     valopt release-channel "stable" "the name of the release channel to build"
697 fi
698
699 # Used on systems where "cc" and "ar" are unavailable
700 valopt default-linker "cc" "the default linker"
701 valopt default-ar     "ar" "the default ar"
702
703 # Many of these are saved below during the "writing configuration" step
704 # (others are conditionally saved).
705 opt_nosave manage-submodules 1 "let the build manage the git submodules"
706 opt_nosave clang 0 "prefer clang to gcc for building the runtime"
707 opt_nosave jemalloc 1 "build liballoc with jemalloc"
708 opt elf-tls 1 "elf thread local storage on platforms where supported"
709 opt full-bootstrap 0 "build three compilers instead of two"
710
711 valopt_nosave prefix "/usr/local" "set installation prefix"
712 valopt_nosave local-rust-root "/usr/local" "set prefix for local rust binary"
713 valopt_nosave host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
714 valopt_nosave target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
715 valopt_nosave mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
716 valopt_nosave docdir "${CFG_PREFIX}/share/doc/rust" "install documentation in PATH"
717
718 # On Windows this determines root of the subtree for target libraries.
719 # Host runtime libs always go to 'bin'.
720 valopt libdir "${CFG_PREFIX}/lib" "install libraries"
721
722 case "$CFG_LIBDIR" in
723     "$CFG_PREFIX"/*) CAT_INC=2;;
724     "$CFG_PREFIX"*)  CAT_INC=1;;
725     *)
726         err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
727 esac
728
729 CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
730
731 if [ $HELP -eq 1 ]
732 then
733     echo
734     exit 0
735 fi
736
737 # Validate Options
738 if [ -z "$CFG_DISABLE_OPTION_CHECKING" ]
739 then
740     step_msg "validating $CFG_SELF args"
741     validate_opt
742 fi
743
744 # Validate the release channel, and configure options
745 case "$CFG_RELEASE_CHANNEL" in
746     nightly )
747         msg "overriding settings for $CFG_RELEASE_CHANNEL"
748         enable_if_not_disabled llvm-assertions
749         # FIXME(stage0) re-enable this on the next stage0 now that #35566 is
750         # fixed
751         case "$CFG_BUILD" in
752           *-pc-windows-gnu)
753             ;;
754           *)
755             CFG_ENABLE_DEBUGINFO_LINES=1
756             CFG_ENABLE_DEBUGINFO_ONLY_STD=1
757             ;;
758         esac
759
760         ;;
761     beta | stable)
762         msg "overriding settings for $CFG_RELEASE_CHANNEL"
763         case "$CFG_BUILD" in
764           *-pc-windows-gnu)
765             ;;
766           *)
767             CFG_ENABLE_DEBUGINFO_LINES=1
768             CFG_ENABLE_DEBUGINFO_ONLY_STD=1
769             ;;
770         esac
771         ;;
772     dev)
773         ;;
774     *)
775         err "release channel must be 'dev', 'nightly', 'beta' or 'stable'"
776         ;;
777 esac
778
779 # Adjust perf and debug options for debug mode
780 if [ -n "$CFG_ENABLE_DEBUG" ]; then
781     msg "debug mode enabled, setting performance options"
782     if [ -z "$CFG_ENABLE_OPTIMIZE_PROVIDED" ]; then
783         msg "optimization not explicitly enabled, disabling optimization"
784         CFG_DISABLE_OPTIMIZE=1
785         CFG_DISABLE_OPTIMIZE_CXX=1
786     fi
787
788     # Set following variables to 1 unless setting already provided
789     enable_if_not_disabled debug-assertions
790     enable_if_not_disabled debug-jemalloc
791     enable_if_not_disabled debuginfo
792     enable_if_not_disabled llvm-assertions
793 fi
794
795 # OK, now write the debugging options
796 if [ -n "$CFG_DISABLE_OPTIMIZE" ]; then putvar CFG_DISABLE_OPTIMIZE; fi
797 if [ -n "$CFG_DISABLE_OPTIMIZE_CXX" ]; then putvar CFG_DISABLE_OPTIMIZE_CXX; fi
798 if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then putvar CFG_DISABLE_OPTIMIZE_LLVM; fi
799 if [ -n "$CFG_ENABLE_LLVM_ASSERTIONS" ]; then putvar CFG_ENABLE_LLVM_ASSERTIONS; fi
800 if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTIONS; fi
801 if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO; fi
802 if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
803 if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES; fi
804 if [ -n "$CFG_ENABLE_DEBUGINFO_ONLY_STD" ]; then putvar CFG_ENABLE_DEBUGINFO_ONLY_STD; fi
805 if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
806
807 step_msg "looking for build programs"
808
809 probe_need CFG_CURL curl
810 if [ -z "$CFG_PYTHON_PROVIDED" ]; then
811     probe_need CFG_PYTHON      python2.7 python2 python
812 fi
813
814 python_version=$($CFG_PYTHON -V 2>&1)
815 if [ $(echo $python_version | grep -c '^Python 2\.7') -ne 1 ]; then
816     err "Found $python_version, but Python 2.7 is required"
817 fi
818
819 # If we have no git directory then we are probably a tarball distribution
820 # and shouldn't attempt to load submodules
821 if [ ! -e ${CFG_SRC_DIR}.git ]
822 then
823     probe CFG_GIT          git
824     msg "git: no git directory. disabling submodules"
825     CFG_DISABLE_MANAGE_SUBMODULES=1
826 else
827     probe_need CFG_GIT     git
828 fi
829
830 # Use `md5sum` on GNU platforms, or `md5 -q` on BSD
831 probe CFG_MD5              md5
832 probe CFG_MD5SUM           md5sum
833 if [ -n "$CFG_MD5" ]
834 then
835     CFG_HASH_COMMAND="$CFG_MD5 -q | cut -c 1-8"
836 elif [ -n "$CFG_MD5SUM" ]
837 then
838     CFG_HASH_COMMAND="$CFG_MD5SUM | cut -c 1-8"
839 else
840     err 'could not find one of: md5 md5sum'
841 fi
842 putvar CFG_HASH_COMMAND
843
844 probe CFG_CLANG            clang++
845 probe CFG_CCACHE           ccache
846 probe CFG_GCC              gcc
847 probe CFG_LD               ld
848 probe CFG_VALGRIND         valgrind
849 probe CFG_PERF             perf
850 probe CFG_ISCC             iscc
851 probe CFG_ANTLR4           antlr4
852 probe CFG_GRUN             grun
853 probe CFG_FLEX             flex
854 probe CFG_BISON            bison
855 probe CFG_GDB              gdb
856 probe CFG_LLDB             lldb
857
858 if [ -n "$CFG_ENABLE_NINJA" ]
859 then
860   probe CFG_NINJA            ninja
861   if [ -z "$CFG_NINJA" ]
862   then
863     # On Debian and Fedora, the `ninja` binary is an IRC bot, so the build tool was
864     # renamed. Handle this case.
865     probe CFG_NINJA            ninja-build
866   fi
867 fi
868
869 # For building LLVM
870 if [ -z "$CFG_LLVM_ROOT" ]
871 then
872   probe_need CFG_CMAKE cmake
873 fi
874
875 # On MacOS X, invoking `javac` pops up a dialog if the JDK is not
876 # installed. Since `javac` is only used if `antlr4` is available,
877 # probe for it only in this case.
878 if [ -n "$CFG_ANTLR4" ]
879 then
880    CFG_ANTLR4_JAR="\"$(find /usr/ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
881    if [ "x" = "x$CFG_ANTLR4_JAR" ]
882    then
883      CFG_ANTLR4_JAR="\"$(find ~ -name antlr-complete.jar 2>/dev/null | head -n 1)\""
884    fi
885    putvar CFG_ANTLR4_JAR      $CFG_ANTLR4_JAR
886    probe CFG_JAVAC            javac
887 fi
888
889 # the valgrind rpass tests will fail if you don't have a valgrind, but they're
890 # only disabled if you opt out.
891 if [ -z "$CFG_VALGRIND" ]
892 then
893     # If the user has explicitly asked for valgrind tests, then fail
894     if [ -n "$CFG_ENABLE_VALGRIND" ] && [ -n "$CFG_ENABLE_VALGRIND_PROVIDED" ]
895     then
896         err "No valgrind present, but valgrind tests explicitly requested"
897     else
898         CFG_DISABLE_VALGRIND_RPASS=1
899         putvar CFG_DISABLE_VALGRIND_RPASS
900     fi
901 fi
902
903 if [ -n "$CFG_LLDB" ]
904 then
905     # Store LLDB's version
906     CFG_LLDB_VERSION=$($CFG_LLDB --version 2>/dev/null | head -1)
907     putvar CFG_LLDB_VERSION
908
909     # If CFG_LLDB_PYTHON_DIR is not already set from the outside and valid, try to read it from
910     # LLDB via the -P commandline options.
911     if [ -z "$CFG_LLDB_PYTHON_DIR" ] || [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
912     then
913         CFG_LLDB_PYTHON_DIR=$($CFG_LLDB -P)
914
915         # If CFG_LLDB_PYTHON_DIR is not a valid directory, set it to something more readable
916         if [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
917         then
918             CFG_LLDB_PYTHON_DIR="LLDB_PYTHON_DIRECTORY_NOT_FOUND"
919         fi
920
921         putvar CFG_LLDB_PYTHON_DIR
922     fi
923 fi
924
925 # LLDB tests on OSX require /usr/bin/python, not something like Homebrew's
926 # /usr/local/bin/python. We're loading a compiled module for LLDB tests which is
927 # only compatible with the system.
928 case $CFG_BUILD in
929     *-apple-darwin)
930         CFG_LLDB_PYTHON=/usr/bin/python
931         ;;
932     *)
933         CFG_LLDB_PYTHON=$CFG_PYTHON
934         ;;
935 esac
936 putvar CFG_LLDB_PYTHON
937
938 # Do some sanity checks if running on buildbot
939 # (these env vars are set by rust-buildbot)
940 if [ -n "$RUST_DIST_SERVER" -a -n "$ALLOW_NONZERO_RLIMIT_CORE" ]; then
941    # Frequently the llvm submodule directory is broken by the build
942    # being killed
943    llvm_lock="${CFG_SRC_DIR}/.git/modules/src/llvm/index.lock"
944    if [ -e "$llvm_lock" ]; then
945        step_msg "removing $llvm_lock"
946        rm -f "$llvm_lock"
947    fi
948 fi
949
950 step_msg "looking for target specific programs"
951
952 probe CFG_ADB        adb
953
954 BIN_SUF=
955 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ]
956 then
957     BIN_SUF=.exe
958 fi
959
960 # --enable-local-rebuild implies --enable-local-rust too
961 if [ -n "$CFG_ENABLE_LOCAL_REBUILD" ]
962 then
963     if [ -z "$CFG_ENABLE_LOCAL_RUST" ]
964     then
965         CFG_ENABLE_LOCAL_RUST=1
966         putvar CFG_ENABLE_LOCAL_RUST
967     fi
968 fi
969
970 if [ -n "$CFG_ENABLE_LOCAL_RUST" ]
971 then
972     system_rustc=$(which rustc)
973     if [ -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} ]
974     then
975         : # everything already configured
976     elif [ -n "$system_rustc" ]
977     then
978         # we assume that rustc is in a /bin directory
979         CFG_LOCAL_RUST_ROOT=${system_rustc%/bin/rustc}
980     else
981         err "no local rust to use"
982     fi
983
984     CMD="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
985     LRV=`LD_LIBRARY_PATH=${CFG_LOCAL_RUST_ROOT}/lib $CMD --version`
986     if [ $? -ne 0 ]
987     then
988         step_msg "failure while running $CMD --version"
989         exit 1
990     fi
991     step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
992     putvar CFG_LOCAL_RUST_ROOT
993 fi
994
995 # Force bitrig to build with clang; gcc doesn't like us there
996 if [ $CFG_OSTYPE = unknown-bitrig ]
997 then
998     step_msg "on Bitrig, forcing use of clang"
999     CFG_ENABLE_CLANG=1
1000 fi
1001
1002 # default gcc version under OpenBSD maybe too old, try using egcc, which is a
1003 # gcc version from ports
1004 if [ $CFG_OSTYPE = unknown-openbsd ]
1005 then
1006     if [ $("$CFG_GCC" --version 2>&1 | grep -c ' 4\.[0-6]') -ne 0 ]; then
1007         step_msg "older GCC found, try with egcc instead"
1008
1009         # probe again but using egcc
1010         probe CFG_GCC egcc
1011
1012         # and use egcc/eg++ for CC/CXX too if it was found
1013         # (but user setting has priority)
1014         if [ -n "$CFG_GCC" ]; then
1015             CC="${CC:-egcc}"
1016             CXX="${CXX:-eg++}"
1017         fi
1018     fi
1019 fi
1020
1021 # OS X 10.9, gcc is actually clang. This can cause some confusion in the build
1022 # system, so if we find that gcc is clang, we should just use clang directly.
1023 if [ $CFG_OSTYPE = apple-darwin -a -z "$CFG_ENABLE_CLANG" ]
1024 then
1025     CFG_OSX_GCC_VERSION=$("$CFG_GCC" --version 2>&1 | grep "Apple LLVM version")
1026     if [ $? -eq 0 ]
1027     then
1028         step_msg "on OS X >=10.9, forcing use of clang"
1029         CFG_ENABLE_CLANG=1
1030     else
1031         if [ $("$CFG_GCC" --version 2>&1 | grep -c ' 4\.[0-6]') -ne 0 ]; then
1032             step_msg "older GCC found, using clang instead"
1033             CFG_ENABLE_CLANG=1
1034         else
1035             # on OS X, with xcode 5 and newer, certain developers may have
1036             # cc, gcc and g++ point to a  mixture of clang and gcc
1037             # if so, this will create very strange build errors
1038             # this last stanza is to detect some such problems and save the future rust
1039             # contributor some time solving that issue.
1040             # this detection could be generalized to other OSes aside from OS X
1041             # but the issue seems most likely to happen on OS X
1042
1043             chk_cc () {
1044                 $1 --version 2> /dev/null | grep -q $2
1045             }
1046             # check that gcc, cc and g++ all point to the same compiler.
1047             # note that for xcode 5, g++ points to clang, not clang++
1048             if !((chk_cc gcc clang  && chk_cc g++ clang) ||
1049                 (chk_cc gcc gcc  &&( chk_cc g++ g++ || chk g++ gcc))); then
1050                 err "the gcc and g++ in your path point to different compilers.
1051     Check which versions are in your path with gcc --version and g++ --version.
1052     To resolve this problem, either fix your PATH  or run configure with --enable-clang"
1053             fi
1054
1055         fi
1056     fi
1057 fi
1058
1059 # If the clang isn't already enabled, check for GCC, and if it is missing, turn
1060 # on clang as a backup.
1061 if [ -z "$CFG_ENABLE_CLANG" ]
1062 then
1063   CFG_GCC_VERSION=$("$CFG_GCC" --version 2>&1)
1064   if [ $? -ne 0 ]
1065   then
1066     step_msg "GCC not installed, will try using Clang"
1067     CFG_ENABLE_CLANG=1
1068   fi
1069 fi
1070
1071 # Okay, at this point, we have made up our minds about whether we are
1072 # going to force CFG_ENABLE_CLANG or not; save the setting if so.
1073 if [ -n "$CFG_ENABLE_CLANG" ]
1074 then
1075     putvar CFG_ENABLE_CLANG
1076 fi
1077
1078 if [ -z "$CFG_DISABLE_LIBCPP" -a -n "$CFG_ENABLE_CLANG" ]
1079 then
1080     CFG_USING_LIBCPP="1"
1081 else
1082     CFG_USING_LIBCPP="0"
1083 fi
1084
1085 # Same with jemalloc.  save the setting here.
1086 if [ -n "$CFG_DISABLE_JEMALLOC" ]
1087 then
1088     putvar CFG_DISABLE_JEMALLOC
1089 fi
1090
1091 if [ -n "$CFG_LLVM_ROOT" -a -z "$CFG_DISABLE_LLVM_VERSION_CHECK" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ]
1092 then
1093     step_msg "using custom LLVM at $CFG_LLVM_ROOT"
1094
1095     LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config"
1096     LLVM_VERSION=$($LLVM_CONFIG --version)
1097
1098     case $LLVM_VERSION in
1099         (3.[7-9]*)
1100             msg "found ok version of LLVM: $LLVM_VERSION"
1101             ;;
1102         (*)
1103             err "bad LLVM version: $LLVM_VERSION, need >=3.7"
1104             ;;
1105     esac
1106
1107     if "$CFG_LLVM_ROOT/bin/llvm-mc" -help | grep -- "-relocation-model"; then
1108         msg "found older llvm-mc"
1109         CFG_LLVM_MC_HAS_RELOCATION_MODEL=1
1110         putvar CFG_LLVM_MC_HAS_RELOCATION_MODEL
1111     fi
1112 fi
1113
1114 # Even when the user overrides the choice of CC, still try to detect
1115 # clang to disable some clang-specific warnings.  We here draw a
1116 # distinction between:
1117 #
1118 #  CFG_ENABLE_CLANG : passed --enable-clang, or host "requires" clang,
1119 #  CFG_USING_CLANG : compiler (clang / gcc / $CC) looks like clang.
1120 #
1121 # This distinction is important because there are some safeguards we
1122 # would prefer to skip when merely CFG_USING_CLANG is set; but when
1123 # CFG_ENABLE_CLANG is set, that indicates that we are opting into
1124 # running such safeguards.
1125
1126 if [ -n "$CC" ]
1127 then
1128     msg "skipping compiler inference steps; using provided CC=$CC"
1129     CFG_CC="$CC"
1130
1131     CFG_OSX_CC_VERSION=$("$CFG_CC" --version 2>&1 | grep "clang")
1132     if [ $? -eq 0 ]
1133     then
1134         step_msg "note, user-provided CC looks like clang; CC=$CC."
1135         CFG_USING_CLANG=1
1136         putvar CFG_USING_CLANG
1137     fi
1138 else
1139     if [ -n "$CFG_ENABLE_CLANG" ]
1140     then
1141         if [ -z "$CFG_CLANG" ]
1142         then
1143             err "clang requested but not found"
1144         fi
1145         CFG_CC="$CFG_CLANG"
1146         CFG_USING_CLANG=1
1147         putvar CFG_USING_CLANG
1148     else
1149         CFG_CC="gcc"
1150     fi
1151 fi
1152
1153 if [ -n "$CFG_ENABLE_CLANG" ]
1154 then
1155     case "$CC" in
1156         (''|*clang)
1157         if [ -z "$CC" ]
1158         then
1159             CFG_CC="clang"
1160             CFG_CXX="clang++"
1161         fi
1162     esac
1163 fi
1164
1165 if [ -n "$CFG_ENABLE_CCACHE" ]
1166 then
1167     if [ -z "$CFG_CCACHE" ]
1168     then
1169         err "ccache requested but not found"
1170     fi
1171
1172     CFG_CC="ccache $CFG_CC"
1173 fi
1174
1175 if [ -z "$CC" -a -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
1176 then
1177     err "either clang or gcc is required"
1178 fi
1179
1180 # All safeguards based on $CFG_ENABLE_CLANG should occur before this
1181 # point in the script; after this point, script logic should inspect
1182 # $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG.
1183
1184 # Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS,LDFLAGS}
1185 envopt CC
1186 envopt CXX
1187 envopt CPP
1188 envopt CFLAGS
1189 envopt CXXFLAGS
1190 envopt LDFLAGS
1191
1192 # stdc++ name in use
1193 # used to manage non-standard name (on OpenBSD for example)
1194 program_transform_name=$($CFG_CC -v 2>&1 | sed -n "s/.*--program-transform-name='\([^']*\)'.*/\1/p")
1195 CFG_STDCPP_NAME=$(echo "stdc++" | sed "${program_transform_name}")
1196 putvar CFG_STDCPP_NAME
1197
1198 # a little post-processing of various config values
1199 CFG_PREFIX=${CFG_PREFIX%/}
1200 CFG_MANDIR=${CFG_MANDIR%/}
1201 CFG_DOCDIR=${CFG_DOCDIR%/}
1202 CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
1203 CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"
1204 CFG_SUPPORTED_TARGET=""
1205 for target_file in ${CFG_SRC_DIR}mk/cfg/*.mk; do
1206   CFG_SUPPORTED_TARGET="${CFG_SUPPORTED_TARGET} $(basename "$target_file" .mk)"
1207 done
1208
1209 # copy build-triples to host-triples so that builds are a subset of hosts
1210 V_TEMP=""
1211 for i in $CFG_BUILD $CFG_HOST;
1212 do
1213    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1214 done
1215 CFG_HOST=$V_TEMP
1216
1217 # copy host-triples to target-triples so that hosts are a subset of targets
1218 V_TEMP=""
1219 for i in $CFG_HOST $CFG_TARGET;
1220 do
1221    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1222 done
1223 CFG_TARGET=$V_TEMP
1224
1225 # check target-specific tool-chains
1226 for i in $CFG_TARGET
1227 do
1228     L_CHECK=false
1229     for j in $CFG_SUPPORTED_TARGET
1230     do
1231         if [ $i = $j ]
1232         then
1233             L_CHECK=true
1234         fi
1235     done
1236
1237     if [ $L_CHECK = false ]
1238     then
1239         err "unsupported target triples \"$i\" found"
1240     fi
1241
1242     case $i in
1243         *android*)
1244             case $i in
1245                 armv7-linux-androideabi)
1246                     cmd_prefix="arm-linux-androideabi"
1247                     ;;
1248                 *)
1249                     cmd_prefix=$i
1250                     ;;
1251             esac
1252
1253             upper_snake_target=$(echo "$i" | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
1254             eval ndk=\$"CFG_${upper_snake_target}_NDK"
1255             if [ -z "$ndk" ]
1256             then
1257                 ndk=$CFG_ANDROID_CROSS_PATH
1258                 eval "CFG_${upper_snake_target}_NDK"=$CFG_ANDROID_CROSS_PATH
1259                 warn "generic/default Android NDK option is deprecated (use --$i-ndk option instead)"
1260             fi
1261
1262             # Perform a basic sanity check of the NDK
1263             for android_ndk_tool in "$ndk/bin/$cmd_prefix-gcc" "$ndk/bin/$cmd_prefix-g++" "$ndk/bin/$cmd_prefix-ar"
1264             do
1265                 if [ ! -f $android_ndk_tool ]
1266                 then
1267                     err "NDK tool $android_ndk_tool not found (bad or missing --$i-ndk option?)"
1268                 fi
1269             done
1270             ;;
1271         *-unknown-nacl)
1272             if [ -z "$CFG_NACL_CROSS_PATH" ]
1273             then
1274                 err "I need the NaCl SDK path! (use --nacl-cross-path)"
1275             fi
1276             ;;
1277         arm-apple-darwin)
1278             if [ $CFG_OSTYPE != apple-darwin ]
1279             then
1280                 err "The iOS target is only supported on Mac OS X"
1281             fi
1282             ;;
1283
1284         *-msvc)
1285             # There are three builds of cmake on windows: MSVC, MinGW and Cygwin
1286             # The Cygwin build does not have generators for Visual Studio, so
1287             # detect that here and error.
1288             if ! "$CFG_CMAKE" --help | sed -n '/^Generators/,$p' | grep 'Visual Studio' > /dev/null
1289             then
1290                 err "
1291
1292 cmake does not support Visual Studio generators.
1293
1294 This is likely due to it being an msys/cygwin build of cmake, \
1295 rather than the required windows version, built using MinGW \
1296 or Visual Studio.
1297
1298 If you are building under msys2 try installing the mingw-w64-x86_64-cmake \
1299 package instead of cmake:
1300
1301 $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
1302 "
1303             fi
1304
1305             # Use the REG program to figure out where VS is installed
1306             # We need to figure out where cl.exe and link.exe are, so we do some
1307             # munging and some probing here. We also look for the default
1308             # INCLUDE and LIB variables for MSVC so we can set those in the
1309             # build system as well.
1310             install=$(cmd //c reg QUERY \
1311                        'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0' \
1312                        -v InstallDir)
1313             if [ -z "$install" ]; then
1314               install=$(cmd //c reg QUERY \
1315                          'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0' \
1316                          -v InstallDir)
1317             fi
1318             need_ok "couldn't find visual studio install root"
1319             CFG_MSVC_ROOT=$(echo "$install" | grep InstallDir | sed 's/.*REG_SZ[ ]*//')
1320             CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
1321             CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
1322             putvar CFG_MSVC_ROOT
1323
1324             case $i in
1325                 x86_64-*)
1326                     bits=x86_64
1327                     msvc_part=amd64
1328                     ;;
1329                 i*86-*)
1330                     bits=i386
1331                     msvc_part=
1332                     ;;
1333                 *)
1334                     err "can only target x86 targets for MSVC"
1335                     ;;
1336             esac
1337             bindir="${CFG_MSVC_ROOT}/VC/bin"
1338             if [ -n "$msvc_part" ]; then
1339                 bindir="$bindir/$msvc_part"
1340             fi
1341             eval CFG_MSVC_BINDIR_$bits="\"$bindir\""
1342             eval CFG_MSVC_CL_$bits="\"$bindir/cl.exe\""
1343             eval CFG_MSVC_LIB_$bits="\"$bindir/lib.exe\""
1344             eval CFG_MSVC_LINK_$bits="\"$bindir/link.exe\""
1345
1346             vcvarsall="${CFG_MSVC_ROOT}/VC/vcvarsall.bat"
1347             include_path=$(cmd //V:ON //c "$vcvarsall" $msvc_part \& echo !INCLUDE!)
1348             need_ok "failed to learn about MSVC's INCLUDE"
1349             lib_path=$(cmd //V:ON //c "$vcvarsall" $msvc_part \& echo !LIB!)
1350             need_ok "failed to learn about MSVC's LIB"
1351
1352             eval CFG_MSVC_INCLUDE_PATH_${bits}="\"$include_path\""
1353             eval CFG_MSVC_LIB_PATH_${bits}="\"$lib_path\""
1354
1355             putvar CFG_MSVC_BINDIR_${bits}
1356             putvar CFG_MSVC_CL_${bits}
1357             putvar CFG_MSVC_LIB_${bits}
1358             putvar CFG_MSVC_LINK_${bits}
1359             putvar CFG_MSVC_INCLUDE_PATH_${bits}
1360             putvar CFG_MSVC_LIB_PATH_${bits}
1361             ;;
1362
1363         *)
1364             ;;
1365     esac
1366 done
1367
1368 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ]
1369 then
1370     # There are some MSYS python builds which will auto-translate
1371     # windows-style paths to MSYS-style paths in Python itself.
1372     # Unfortunately this breaks LLVM's build system as somewhere along
1373     # the line LLVM prints a path into a file from Python and then CMake
1374     # later tries to interpret that path. If Python prints a MSYS path
1375     # and CMake tries to use it as a Windows path, you're gonna have a
1376     # Bad Time.
1377     #
1378     # Consequently here we try to detect when that happens and print an
1379     # error if it does.
1380     if $CFG_PYTHON -c 'import sys; print sys.argv[1]' `pwd` | grep '^/' > /dev/null
1381     then
1382         err "
1383
1384 python is silently translating windows paths to MSYS paths \
1385 and the build will fail if this python is used.
1386
1387 Either an official python install must be used or an \
1388 alternative python package in MinGW must be used.
1389
1390 If you are building under msys2 try installing the mingw-w64-x86_64-python2 \
1391 package instead of python2:
1392
1393 $ pacman -S mingw-w64-x86_64-python2
1394 "
1395     fi
1396 fi
1397
1398 if [ -n "$CFG_PERF" ]
1399 then
1400     HAVE_PERF_LOGFD=`$CFG_PERF stat --log-fd 2>&1 | grep 'unknown option'`
1401     if [ -z "$HAVE_PERF_LOGFD" ];
1402     then
1403         CFG_PERF_WITH_LOGFD=1
1404         putvar CFG_PERF_WITH_LOGFD
1405     fi
1406 fi
1407
1408 if [ -n "$CFG_DISABLE_RUSTBUILD" ]; then
1409
1410   step_msg "making directories"
1411
1412   for i in \
1413       doc doc/std doc/extra \
1414       dl tmp dist
1415   do
1416       make_dir $i
1417   done
1418
1419   for t in $CFG_HOST
1420   do
1421       make_dir $t/llvm
1422   done
1423
1424   for t in $CFG_HOST
1425   do
1426       make_dir $t/rustllvm
1427   done
1428
1429   for t in $CFG_TARGET
1430   do
1431     make_dir $t/rt
1432     for s in 0 1 2 3
1433     do
1434       make_dir $t/rt/stage$s
1435       make_dir $t/rt/jemalloc
1436       make_dir $t/rt/compiler-rt
1437       for i in                                          \
1438         isaac sync test \
1439         arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips arch/powerpc
1440       do
1441         make_dir $t/rt/stage$s/$i
1442       done
1443     done
1444   done
1445
1446   for h in $CFG_HOST
1447   do
1448       for t in $CFG_TARGET
1449       do
1450           # host bin dir stage0
1451           make_dir $h/stage0/bin
1452
1453           # host lib dir stage0
1454           make_dir $h/stage0/lib
1455
1456           # host test dir stage0
1457           make_dir $h/stage0/test
1458
1459           # target bin dir stage0
1460           make_dir $h/stage0/lib/rustlib/$t/bin
1461
1462           # target lib dir stage0
1463           make_dir $h/stage0/lib/rustlib/$t/lib
1464
1465           for i in 1 2 3
1466           do
1467               # host bin dir
1468               make_dir $h/stage$i/bin
1469
1470               # host lib dir
1471               make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE
1472
1473               # host test dir
1474               make_dir $h/stage$i/test
1475
1476               # target bin dir
1477               make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/bin
1478
1479               # target lib dir
1480               make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/lib
1481           done
1482       done
1483
1484       make_dir $h/test/run-pass
1485       make_dir $h/test/run-pass-valgrind
1486       make_dir $h/test/run-pass-fulldeps
1487       make_dir $h/test/run-fail
1488       make_dir $h/test/run-fail-fulldeps
1489       make_dir $h/test/compile-fail
1490       make_dir $h/test/parse-fail
1491       make_dir $h/test/compile-fail-fulldeps
1492       make_dir $h/test/bench
1493       make_dir $h/test/perf
1494       make_dir $h/test/pretty
1495       make_dir $h/test/debuginfo-gdb
1496       make_dir $h/test/debuginfo-lldb
1497       make_dir $h/test/codegen
1498       make_dir $h/test/codegen-units
1499       make_dir $h/test/rustdoc
1500   done
1501
1502 fi
1503
1504 # Configure submodules
1505 step_msg "configuring submodules"
1506
1507 # Have to be in the top of src directory for this
1508 if [ -z "$CFG_DISABLE_MANAGE_SUBMODULES" ] && [ -n "$CFG_DISABLE_RUSTBUILD" ]
1509 then
1510     cd ${CFG_SRC_DIR}
1511
1512     msg "git: submodule sync"
1513     "${CFG_GIT}" submodule sync
1514
1515     msg "git: submodule init"
1516     "${CFG_GIT}" submodule init
1517
1518     # Disable submodules that we're not using
1519     if [ -n "${CFG_LLVM_ROOT}" ]; then
1520         msg "git: submodule deinit src/llvm"
1521         "${CFG_GIT}" submodule deinit src/llvm
1522     fi
1523     if [ -n "${CFG_JEMALLOC_ROOT}" ]; then
1524         msg "git: submodule deinit src/jemalloc"
1525         "${CFG_GIT}" submodule deinit src/jemalloc
1526     fi
1527
1528     msg "git: submodule update"
1529     "${CFG_GIT}" submodule update
1530     need_ok "git failed"
1531
1532     msg "git: submodule foreach sync"
1533     "${CFG_GIT}" submodule foreach --recursive 'if test -e .gitmodules; then git submodule sync; fi'
1534     need_ok "git failed"
1535
1536     msg "git: submodule foreach update"
1537     "${CFG_GIT}" submodule update --recursive
1538     need_ok "git failed"
1539
1540     # NB: this is just for the sake of getting the submodule SHA1 values
1541     # and status written into the build log.
1542     msg "git: submodule status"
1543     "${CFG_GIT}" submodule status --recursive
1544
1545     msg "git: submodule clobber"
1546     "${CFG_GIT}" submodule foreach --recursive git clean -dxf
1547     need_ok "git failed"
1548     "${CFG_GIT}" submodule foreach --recursive git checkout .
1549     need_ok "git failed"
1550
1551     cd ${CFG_BUILD_DIR}
1552 fi
1553
1554 # Do a sanity check that the submodule source exists. Because GitHub
1555 # automatically publishes broken tarballs that can't be disabled, and
1556 # people download them and try to use them.
1557 if [ ! -e "${CFG_SRC_DIR}/src/liblibc" ]; then
1558     err "some submodules are missing. Is this a broken tarball?
1559
1560 If you downloaded this tarball from the GitHub release pages at
1561 https://github.com/rust-lang/rust/releases,
1562 then please delete it and instead download the source from
1563 https://www.rust-lang.org/downloads.html"
1564
1565 fi
1566
1567 # Configure llvm, only if necessary
1568 step_msg "looking at LLVM"
1569 CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm/
1570 for t in $CFG_HOST
1571 do
1572     do_reconfigure=1
1573     is_msvc=0
1574     case "$t" in
1575         (*-msvc)
1576         is_msvc=1
1577         ;;
1578     esac
1579
1580     if [ -z "$CFG_DISABLE_RUSTBUILD" ]
1581     then
1582         msg "not configuring LLVM, rustbuild in use"
1583         do_reconfigure=0
1584     elif [ -z "$CFG_LLVM_ROOT" ]
1585     then
1586         LLVM_BUILD_DIR=${CFG_BUILD_DIR}$t/llvm
1587         LLVM_INST_DIR=$LLVM_BUILD_DIR
1588         # For some weird reason the MSVC output dir is different than Unix
1589         if [ ${is_msvc} -ne 0 ]; then
1590             if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]
1591             then
1592                 # Just use LLVM straight from its build directory to
1593                 # avoid 'make install' time
1594                 LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug
1595             else
1596                 LLVM_INST_DIR=$LLVM_BUILD_DIR/Release
1597             fi
1598         fi
1599     else
1600         msg "not reconfiguring LLVM, external LLVM root"
1601         # The user is using their own LLVM
1602         LLVM_BUILD_DIR=
1603         LLVM_INST_DIR=$CFG_LLVM_ROOT
1604         do_reconfigure=0
1605         # Check that LLVm FileCheck is available. Needed for the tests
1606         if [ -z "$CFG_DISABLE_CODEGEN_TESTS" ]; then
1607             need_cmd $LLVM_INST_DIR/bin/FileCheck
1608         fi
1609     fi
1610
1611     if [ ${do_reconfigure} -ne 0 ]
1612     then
1613     # because git is hilarious, it might have put the module index
1614     # in a couple places.
1615         index1="${CFG_SRC_DIR}.git/modules/src/llvm/index"
1616         index2="${CFG_SRC_DIR}src/llvm/.git/index"
1617         for index in ${index1} ${index2}
1618         do
1619             config_status="${LLVM_BUILD_DIR}/config.status"
1620             if test -e ${index} -a \
1621                     -e ${config_status} -a \
1622                     ${config_status} -nt ${index}
1623             then
1624                 msg "not reconfiguring LLVM, config.status is fresh"
1625                 do_reconfigure=0
1626             fi
1627         done
1628     fi
1629
1630     # We need the generator later on for compiler-rt even if LLVM's not built
1631     if [ -n "$CFG_NINJA" ]
1632     then
1633         generator="Ninja"
1634     elif [ ${is_msvc} -ne 0 ]
1635     then
1636         case "$CFG_MSVC_ROOT" in
1637             *14.0*)
1638                 generator="Visual Studio 14 2015"
1639                 ;;
1640             *12.0*)
1641                 generator="Visual Studio 12 2013"
1642                 ;;
1643             *)
1644                 err "can't determine generator for LLVM cmake"
1645                 ;;
1646         esac
1647         case "$t" in
1648             x86_64-*)
1649                 generator="$generator Win64"
1650                 ;;
1651             i686-*)
1652                 ;;
1653             *)
1654                 err "can only build LLVM for x86 platforms"
1655                 ;;
1656         esac
1657     else
1658         generator="Unix Makefiles"
1659     fi
1660     CFG_CMAKE_GENERATOR=$generator
1661     putvar CFG_CMAKE_GENERATOR
1662
1663     msg "configuring LLVM for $t"
1664
1665     LLVM_CFLAGS_32=""
1666     LLVM_CXXFLAGS_32=""
1667     LLVM_LDFLAGS_32=""
1668     LLVM_CFLAGS_64=""
1669     LLVM_CXXFLAGS_64=""
1670     LLVM_LDFLAGS_64=""
1671
1672     case "$CFG_CC" in
1673         ("ccache clang")
1674             LLVM_CXX_32="ccache"
1675             LLVM_CC_32="ccache"
1676             LLVM_CXX_32_ARG1="clang++"
1677             LLVM_CC_32_ARG1="clang"
1678             LLVM_CFLAGS_32="-Qunused-arguments"
1679             LLVM_CXXFLAGS_32="-Qunused-arguments"
1680
1681             LLVM_CXX_64="ccache"
1682             LLVM_CC_64="ccache"
1683             LLVM_CXX_64_ARG1="clang++"
1684             LLVM_CC_64_ARG1="clang"
1685             LLVM_CFLAGS_64="-Qunused-arguments"
1686             LLVM_CXXFLAGS_64="-Qunused-arguments"
1687             ;;
1688         ("clang")
1689             LLVM_CXX_32="clang++"
1690             LLVM_CC_32="clang"
1691             LLVM_CFLAGS_32="-Qunused-arguments"
1692             LLVM_CXXFLAGS_32="-Qunused-arguments"
1693
1694             LLVM_CXX_64="clang++"
1695             LLVM_CC_64="clang"
1696             LLVM_CFLAGS_64="-Qunused-arguments"
1697             LLVM_CXXFLAGS_64="-Qunused-arguments"
1698             ;;
1699         ("ccache gcc")
1700             LLVM_CXX_32="ccache"
1701             LLVM_CC_32="ccache"
1702             LLVM_CXX_32_ARG1="g++"
1703             LLVM_CC_32_ARG1="gcc"
1704
1705             LLVM_CXX_64="ccache"
1706             LLVM_CC_64="ccache"
1707             LLVM_CXX_64_ARG1="g++"
1708             LLVM_CC_64_ARG1="gcc"
1709             ;;
1710         ("gcc")
1711             if [ -z "$CFG_ENABLE_SCCACHE" ]; then
1712                 LLVM_CXX_32="g++"
1713                 LLVM_CC_32="gcc"
1714
1715                 LLVM_CXX_64="g++"
1716                 LLVM_CC_64="gcc"
1717             else
1718                 LLVM_CXX_32="sccache"
1719                 LLVM_CC_32="sccache"
1720                 LLVM_CXX_32_ARG1="g++"
1721                 LLVM_CC_32_ARG1="gcc"
1722
1723                 LLVM_CXX_64="sccache"
1724                 LLVM_CC_64="sccache"
1725                 LLVM_CXX_64_ARG1="g++"
1726                 LLVM_CC_64_ARG1="gcc"
1727             fi
1728             ;;
1729
1730         (*)
1731             msg "inferring LLVM_CXX/CC from CXX/CC = $CXX/$CC"
1732             if [ -n "$CFG_ENABLE_CCACHE" ]
1733             then
1734                 if [ -z "$CFG_CCACHE" ]
1735                 then
1736                     err "ccache requested but not found"
1737                 fi
1738
1739                 LLVM_CXX_32="ccache"
1740                 LLVM_CC_32="ccache"
1741                 LLVM_CXX_32_ARG1="$CXX"
1742                 LLVM_CC_32_ARG1="$CC"
1743
1744                 LLVM_CXX_64="ccache"
1745                 LLVM_CC_64="ccache"
1746                 LLVM_CXX_64_ARG1="$CXX"
1747                 LLVM_CC_64_ARG1="$CC"
1748             else
1749                 LLVM_CXX_32="$CXX"
1750                 LLVM_CC_32="$CC"
1751
1752                 LLVM_CXX_64="$CXX"
1753                 LLVM_CC_64="$CC"
1754             fi
1755
1756             ;;
1757     esac
1758
1759     case "$CFG_CPUTYPE" in
1760         (x86*)
1761             LLVM_CFLAGS_32="$LLVM_CFLAGS_32 -m32"
1762             LLVM_CXXFLAGS_32="$LLVM_CXXFLAGS_32 -m32"
1763             LLVM_LDFLAGS_32="$LLVM_LDFLAGS_32 -m32"
1764             ;;
1765     esac
1766
1767     if echo $t | grep -q x86_64
1768     then
1769         LLVM_CXX=$LLVM_CXX_64
1770         LLVM_CC=$LLVM_CC_64
1771         LLVM_CXX_ARG1=$LLVM_CXX_64_ARG1
1772         LLVM_CC_ARG1=$LLVM_CC_64_ARG1
1773         LLVM_CFLAGS=$LLVM_CFLAGS_64
1774         LLVM_CXXFLAGS=$LLVM_CXXFLAGS_64
1775         LLVM_LDFLAGS=$LLVM_LDFLAGS_64
1776     else
1777         LLVM_CXX=$LLVM_CXX_32
1778         LLVM_CC=$LLVM_CC_32
1779         LLVM_CXX_ARG1=$LLVM_CXX_32_ARG1
1780         LLVM_CC_ARG1=$LLVM_CC_32_ARG1
1781         LLVM_CFLAGS=$LLVM_CFLAGS_32
1782         LLVM_CXXFLAGS=$LLVM_CXXFLAGS_32
1783         LLVM_LDFLAGS=$LLVM_LDFLAGS_32
1784     fi
1785
1786     if [ "$CFG_USING_LIBCPP" != "0" ]; then
1787         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_LIBCXX=ON"
1788     fi
1789
1790     # Turn off things we don't need
1791     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_INCLUDE_TESTS=OFF"
1792     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_INCLUDE_EXAMPLES=OFF"
1793     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_INCLUDE_DOCS=OFF"
1794     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ZLIB=OFF"
1795     CMAKE_ARGS="$CMAKE_ARGS -DWITH_POLY=OFF"
1796     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_TERMINFO=OFF"
1797     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_LIBEDIT=OFF"
1798
1799     arch="$(echo "$t" | cut -d - -f 1)"
1800
1801     if [ "$arch" = i686 ]; then
1802         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_BUILD_32_BITS=ON"
1803     fi
1804
1805     if [ "$t" != "$CFG_BUILD" ]; then
1806         # see http://llvm.org/docs/HowToCrossCompileLLVM.html
1807         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CROSSCOMPILING=True"
1808         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_TARGET_ARCH=$arch"
1809         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_TABLEGEN=$CFG_BUILD_DIR/$CFG_BUILD/llvm/bin/llvm-tblgen"
1810         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=$t"
1811     fi
1812
1813     # MSVC handles compiler business itself
1814     if [ ${is_msvc} -eq 0 ]; then
1815         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER=$LLVM_CC"
1816         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER=$LLVM_CXX"
1817         CMAKE_ARGS="$CMAKE_ARGS '-DCMAKE_C_FLAGS=$LLVM_CFLAGS'"
1818         CMAKE_ARGS="$CMAKE_ARGS '-DCMAKE_CXX_FLAGS=$LLVM_CXXFLAGS'"
1819         if [ -n "$LLVM_CC_ARG1" ]; then
1820             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_C_COMPILER_ARG1=$LLVM_CC_ARG1"
1821         fi
1822         if [ -n "$LLVM_CXX_ARG1" ]; then
1823             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_COMPILER_ARG1=$LLVM_CXX_ARG1"
1824         fi
1825         # FIXME: What about LDFLAGS?
1826     fi
1827
1828     if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then
1829         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug"
1830     elif [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then
1831         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=RelWithDebInfo"
1832     else
1833         CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release"
1834     fi
1835     if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
1836     then
1837         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=OFF"
1838     else
1839         CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=ON"
1840     fi
1841
1842     CMAKE_ARGS="$CMAKE_ARGS -DLLVM_TARGETS_TO_BUILD='X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc'"
1843     CMAKE_ARGS="$CMAKE_ARGS -G '$CFG_CMAKE_GENERATOR'"
1844     CMAKE_ARGS="$CMAKE_ARGS $CFG_LLVM_SRC_DIR"
1845
1846     if [ ${do_reconfigure} -ne 0 ]
1847     then
1848         msg "configuring LLVM for $t with cmake"
1849
1850         msg "configuring LLVM with:"
1851         msg "$CMAKE_ARGS"
1852
1853         (cd $LLVM_BUILD_DIR && eval "\"$CFG_CMAKE\"" $CMAKE_ARGS)
1854         need_ok "LLVM cmake configure failed"
1855     fi
1856
1857     # Construct variables for LLVM build and install directories for
1858     # each target. These will be named
1859     # CFG_LLVM_BUILD_DIR_${target_triple} but all the hyphens in
1860     # target_triple will be converted to underscore, because bash
1861     # variables can't contain hyphens. The makefile will then have to
1862     # convert back.
1863     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1864     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1865     eval ${CFG_LLVM_BUILD_DIR}="'$LLVM_BUILD_DIR'"
1866     eval ${CFG_LLVM_INST_DIR}="'$LLVM_INST_DIR'"
1867 done
1868
1869
1870 step_msg "writing configuration"
1871
1872 putvar CFG_SRC_DIR
1873 putvar CFG_SRC_DIR_RELATIVE
1874 putvar CFG_BUILD_DIR
1875 putvar CFG_OSTYPE
1876 putvar CFG_CPUTYPE
1877 putvar CFG_CONFIGURE_ARGS
1878 putvar CFG_PREFIX
1879 putvar CFG_HOST
1880 putvar CFG_TARGET
1881 putvar CFG_LIBDIR_RELATIVE
1882 putvar CFG_DISABLE_MANAGE_SUBMODULES
1883 putvar CFG_AARCH64_LINUX_ANDROID_NDK
1884 putvar CFG_ARM_LINUX_ANDROIDEABI_NDK
1885 putvar CFG_ARMV7_LINUX_ANDROIDEABI_NDK
1886 putvar CFG_I686_LINUX_ANDROID_NDK
1887 putvar CFG_NACL_CROSS_PATH
1888 putvar CFG_MANDIR
1889 putvar CFG_DOCDIR
1890 putvar CFG_USING_LIBCPP
1891
1892 # Avoid spurious warnings from clang by feeding it original source on
1893 # ccache-miss rather than preprocessed input.
1894 if [ -n "$CFG_ENABLE_CCACHE" ] && [ -n "$CFG_USING_CLANG" ]
1895 then
1896     CFG_CCACHE_CPP2=1
1897     putvar CFG_CCACHE_CPP2
1898 fi
1899
1900 if [ -n "$CFG_ENABLE_CCACHE" ]
1901 then
1902     CFG_CCACHE_BASEDIR=${CFG_SRC_DIR}
1903     putvar CFG_CCACHE_BASEDIR
1904 fi
1905
1906
1907 putvar CFG_LLVM_SRC_DIR
1908
1909 for t in $CFG_HOST
1910 do
1911     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1912     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1913     putvar $CFG_LLVM_BUILD_DIR
1914     putvar $CFG_LLVM_INST_DIR
1915 done
1916
1917 if [ -z "$CFG_DISABLE_RUSTBUILD" ]
1918 then
1919     INPUT_MAKEFILE=src/bootstrap/mk/Makefile.in
1920 else
1921     INPUT_MAKEFILE=Makefile.in
1922 fi
1923
1924 msg
1925 copy_if_changed ${CFG_SRC_DIR}${INPUT_MAKEFILE} ./Makefile
1926 move_if_changed config.tmp config.mk
1927 rm -f config.tmp
1928 touch config.stamp
1929
1930 if [ -z "$CFG_ENABLE_DEBUG" ]; then
1931     step_msg "configured in release mode. for development consider --enable-debug"
1932 else
1933     step_msg "complete"
1934 fi
1935
1936 if [ "$CFG_SRC_DIR" = `pwd` ]; then
1937     X_PY=x.py
1938 else
1939     X_PY=${CFG_SRC_DIR_RELATIVE}x.py
1940 fi
1941
1942 if [ -z "$CFG_DISABLE_RUSTBUILD" ]; then
1943     msg "NOTE you have now configured rust to use a rewritten build system"
1944     msg "     called rustbuild, and as a result this may have bugs that "
1945     msg "     you did not see before. If you experience any issues you can"
1946     msg "     go back to the old build system with --disable-rustbuild and"
1947     msg "     please feel free to report any bugs!"
1948     msg ""
1949     msg "run \`python ${X_PY} --help\`"
1950 else
1951     warn "the makefile-based build system is deprecated in favor of rustbuild"
1952     msg ""
1953     msg "It is recommended you avoid passing --disable-rustbuild to get your"
1954     msg "build working as the makefiles will be deleted on 2017-02-02. If you"
1955     msg "encounter bugs with rustbuild please file issues against rust-lang/rust"
1956     msg ""
1957     msg "run \`make help\`"
1958 fi
1959
1960 msg