]> git.lizzy.rs Git - rust.git/blob - configure
Rollup merge of #33353 - timothy-mcroy:E0502, r=sanxiyn
[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     local V=$1
137     probe $*
138     eval VV=\$$V
139     if [ -z "$VV" ]
140     then
141         err "needed, but unable to find any of: $*"
142     fi
143 }
144
145 validate_opt () {
146     for arg in $CFG_CONFIGURE_ARGS
147     do
148         isArgValid=0
149         for option in $BOOL_OPTIONS
150         do
151             if test --disable-$option = $arg
152             then
153                 isArgValid=1
154             fi
155             if test --enable-$option = $arg
156             then
157                 isArgValid=1
158             fi
159         done
160         for option in $VAL_OPTIONS
161         do
162             if echo "$arg" | grep -q -- "--$option="
163             then
164                 isArgValid=1
165             fi
166         done
167         if [ "$arg" = "--help" ]
168         then
169             echo
170             echo "No more help available for Configure options,"
171             echo "check the Wiki or join our IRC channel"
172             break
173         else
174             if test $isArgValid -eq 0
175             then
176                 err "Option '$arg' is not recognized"
177             fi
178         fi
179     done
180 }
181
182 # `valopt OPTION_NAME DEFAULT DOC` extracts a string-valued option
183 # from command line, using provided default value for the option if
184 # not present, and saves it to the generated config.mk.
185 #
186 # `valopt_nosave` is much the same, except that it does not save the
187 # result to config.mk (instead the script should use `putvar` itself
188 # later on to save it).  `valopt_core` is the core upon which the
189 # other two are built.
190
191 valopt_core() {
192     VAL_OPTIONS="$VAL_OPTIONS $2"
193
194     local SAVE=$1
195     local OP=$2
196     local DEFAULT=$3
197     shift
198     shift
199     shift
200     local DOC="$*"
201     if [ $HELP -eq 0 ]
202     then
203         local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
204         local V="CFG_${UOP}"
205         local V_PROVIDED="${V}_PROVIDED"
206         eval $V="$DEFAULT"
207         for arg in $CFG_CONFIGURE_ARGS
208         do
209             if echo "$arg" | grep -q -- "--$OP="
210             then
211                 val=$(echo "$arg" | cut -f2 -d=)
212                 eval $V=$val
213                 eval $V_PROVIDED=1
214             fi
215         done
216         if [ "$SAVE" = "save" ]
217         then
218             putvar $V
219         fi
220     else
221         if [ -z "$DEFAULT" ]
222         then
223             DEFAULT="<none>"
224         fi
225         OP="${OP}=[${DEFAULT}]"
226         printf "    --%-30s %s\n" "$OP" "$DOC"
227     fi
228 }
229
230 valopt_nosave() {
231     valopt_core nosave "$@"
232 }
233
234 valopt() {
235     valopt_core save "$@"
236 }
237
238 # `opt OPTION_NAME DEFAULT DOC` extracts a boolean-valued option from
239 # command line, using the provided default value (0/1) for the option
240 # if not present, and saves it to the generated config.mk.
241 #
242 # `opt_nosave` is much the same, except that it does not save the
243 # result to config.mk (instead the script should use `putvar` itself
244 # later on to save it).  `opt_core` is the core upon which the other
245 # two are built.
246
247 opt_core() {
248     BOOL_OPTIONS="$BOOL_OPTIONS $2"
249
250     local SAVE=$1
251     local OP=$2
252     local DEFAULT=$3
253     shift
254     shift
255     shift
256     local DOC="$*"
257     local FLAG=""
258
259     if [ $DEFAULT -eq 0 ]
260     then
261         FLAG="enable"
262         DEFAULT_FLAG="disable"
263     else
264         FLAG="disable"
265         DEFAULT_FLAG="enable"
266         DOC="don't $DOC"
267     fi
268
269     if [ $HELP -eq 0 ]
270     then
271         for arg in $CFG_CONFIGURE_ARGS
272         do
273             if [ "$arg" = "--${FLAG}-${OP}" ]
274             then
275                 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
276                 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
277                 local V="CFG_${FLAG}_${OP}"
278                 local V_PROVIDED="CFG_${FLAG}_${OP}_PROVIDED"
279                 eval $V=1
280                 eval $V_PROVIDED=1
281                 if [ "$SAVE" = "save" ]
282                 then
283                    putvar $V
284                 fi
285             elif [ "$arg" = "--${DEFAULT_FLAG}-${OP}" ]
286             then
287                 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
288                 DEFAULT_FLAG=$(echo $DEFAULT_FLAG | tr 'a-z' 'A-Z')
289                 local V_PROVIDED="CFG_${DEFAULT_FLAG}_${OP}_PROVIDED"
290                 eval $V_PROVIDED=1
291             fi
292         done
293     else
294         if [ -n "$META" ]
295         then
296             OP="$OP=<$META>"
297         fi
298         printf "    --%-30s %s\n" "$FLAG-$OP" "$DOC"
299      fi
300 }
301
302 opt_nosave() {
303     opt_core nosave "$@"
304 }
305
306 opt() {
307     opt_core save "$@"
308 }
309
310 envopt() {
311     local NAME=$1
312     local V="CFG_${NAME}"
313     eval VV=\$$V
314
315     # If configure didn't set a value already, then check environment.
316     #
317     # (It is recommended that the configure script always check the
318     # environment before setting any values to envopt variables; see
319     # e.g.  how CFG_CC is handled, where it first checks `-z "$CC"`,
320     # and issues msg if it ends up employing that provided value.)
321     if [ -z "$VV" ]
322     then
323         eval $V=\$$NAME
324         eval VV=\$$V
325     fi
326
327     # If script or environment provided a value, save it.
328     if [ -n "$VV" ]
329     then
330         putvar $V
331     fi
332 }
333
334 enable_if_not_disabled() {
335     local OP=$1
336     local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
337     local ENAB_V="CFG_ENABLE_$UOP"
338     local EXPLICITLY_DISABLED="CFG_DISABLE_${UOP}_PROVIDED"
339     eval VV=\$$EXPLICITLY_DISABLED
340     if [ -z "$VV" ]; then
341         eval $ENAB_V=1
342     fi
343 }
344
345 to_gnu_triple() {
346     case $1 in
347         i686-pc-windows-gnu) echo i686-w64-mingw32 ;;
348         x86_64-pc-windows-gnu) echo x86_64-w64-mingw32 ;;
349         *) echo $1 ;;
350     esac
351 }
352
353 # Prints the absolute path of a directory to stdout
354 abs_path() {
355     local _path="$1"
356     # Unset CDPATH because it causes havok: it makes the destination unpredictable
357     # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
358     # for good measure.
359     (unset CDPATH && cd "$_path" > /dev/null && pwd)
360 }
361
362 msg "looking for configure programs"
363 need_cmd cmp
364 need_cmd mkdir
365 need_cmd printf
366 need_cmd cut
367 need_cmd head
368 need_cmd grep
369 need_cmd xargs
370 need_cmd cp
371 need_cmd find
372 need_cmd uname
373 need_cmd date
374 need_cmd tr
375 need_cmd sed
376 need_cmd file
377 need_cmd make
378
379 msg "inspecting environment"
380
381 CFG_OSTYPE=$(uname -s)
382 CFG_CPUTYPE=$(uname -m)
383
384 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
385 then
386     # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
387     # instead.
388     if sysctl hw.optional.x86_64 | grep -q ': 1'
389     then
390         CFG_CPUTYPE=x86_64
391     fi
392 fi
393
394 # The goal here is to come up with the same triple as LLVM would,
395 # at least for the subset of platforms we're willing to target.
396
397 case $CFG_OSTYPE in
398
399     Linux)
400         CFG_OSTYPE=unknown-linux-gnu
401         ;;
402
403     FreeBSD)
404         CFG_OSTYPE=unknown-freebsd
405         ;;
406
407     DragonFly)
408         CFG_OSTYPE=unknown-dragonfly
409         ;;
410
411     Bitrig)
412         CFG_OSTYPE=unknown-bitrig
413         ;;
414
415     OpenBSD)
416         CFG_OSTYPE=unknown-openbsd
417        ;;
418
419     NetBSD)
420             CFG_OSTYPE=unknown-netbsd
421             ;;
422
423     Darwin)
424         CFG_OSTYPE=apple-darwin
425         ;;
426
427     SunOS)
428         CFG_OSTYPE=sun-solaris
429         CFG_CPUTYPE=$(isainfo -n)
430         ;;
431
432     MINGW*)
433         # msys' `uname` does not print gcc configuration, but prints msys
434         # configuration. so we cannot believe `uname -m`:
435         # msys1 is always i686 and msys2 is always x86_64.
436         # instead, msys defines $MSYSTEM which is MINGW32 on i686 and
437         # MINGW64 on x86_64.
438         CFG_CPUTYPE=i686
439         CFG_OSTYPE=pc-windows-gnu
440         if [ "$MSYSTEM" = MINGW64 ]
441         then
442             CFG_CPUTYPE=x86_64
443         fi
444         ;;
445
446     MSYS*)
447         CFG_OSTYPE=pc-windows-gnu
448         ;;
449
450 # Thad's Cygwin identifiers below
451
452 #   Vista 32 bit
453     CYGWIN_NT-6.0)
454         CFG_OSTYPE=pc-windows-gnu
455         CFG_CPUTYPE=i686
456         ;;
457
458 #   Vista 64 bit
459     CYGWIN_NT-6.0-WOW64)
460         CFG_OSTYPE=pc-windows-gnu
461         CFG_CPUTYPE=x86_64
462         ;;
463
464 #   Win 7 32 bit
465     CYGWIN_NT-6.1)
466         CFG_OSTYPE=pc-windows-gnu
467         CFG_CPUTYPE=i686
468         ;;
469
470 #   Win 7 64 bit
471     CYGWIN_NT-6.1-WOW64)
472         CFG_OSTYPE=pc-windows-gnu
473         CFG_CPUTYPE=x86_64
474         ;;
475
476 #   Win 8 # uname -s on 64-bit cygwin does not contain WOW64, so simply use uname -m to detect arch (works in my install)
477     CYGWIN_NT-6.3)
478         CFG_OSTYPE=pc-windows-gnu
479         ;;
480 # We do not detect other OS such as XP/2003 using 64 bit using uname.
481 # 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.
482     *)
483         err "unknown OS type: $CFG_OSTYPE"
484         ;;
485 esac
486
487
488 case $CFG_CPUTYPE in
489
490     i386 | i486 | i686 | i786 | x86)
491         CFG_CPUTYPE=i686
492         ;;
493
494     xscale | arm)
495         CFG_CPUTYPE=arm
496         ;;
497
498     armv7l)
499         CFG_CPUTYPE=arm
500         CFG_OSTYPE="${CFG_OSTYPE}eabihf"
501         ;;
502
503     aarch64)
504         CFG_CPUTYPE=aarch64
505         ;;
506
507     powerpc | ppc)
508         CFG_CPUTYPE=powerpc
509         ;;
510
511     powerpc64 | ppc64)
512         CFG_CPUTYPE=powerpc64
513         ;;
514
515     powerpc64le | ppc64le)
516         CFG_CPUTYPE=powerpc64le
517         ;;
518
519     x86_64 | x86-64 | x64 | amd64)
520         CFG_CPUTYPE=x86_64
521         ;;
522
523     *)
524         err "unknown CPU type: $CFG_CPUTYPE"
525 esac
526
527 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
528 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
529 then
530     # $SHELL does not exist in standard 'sh', so probably only exists
531     # if configure is running in an interactive bash shell. /usr/bin/env
532     # exists *everywhere*.
533     BIN_TO_PROBE="$SHELL"
534     if [ ! -r "$BIN_TO_PROBE" ]; then
535         if [ -r "/usr/bin/env" ]; then
536             BIN_TO_PROBE="/usr/bin/env"
537         else
538             warn "Cannot check if the userland is i686 or x86_64"
539         fi
540     fi
541     file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64"
542     if [ $? != 0 ]; then
543         msg "i686 userland on x86_64 Linux kernel"
544         CFG_CPUTYPE=i686
545     fi
546 fi
547
548
549 DEFAULT_BUILD="${CFG_CPUTYPE}-${CFG_OSTYPE}"
550
551 CFG_SRC_DIR="$(abs_path $(dirname $0))/"
552 CFG_SRC_DIR_RELATIVE="$(dirname $0)/"
553 CFG_BUILD_DIR="$(pwd)/"
554 CFG_SELF="$0"
555 CFG_CONFIGURE_ARGS="$@"
556
557
558 case "${CFG_SRC_DIR}" in
559     *\ * )
560         err "The path to the rust source directory contains spaces, which is not supported"
561         ;;
562     *)
563         ;;
564 esac
565
566
567 OPTIONS=""
568 HELP=0
569 if [ "$1" = "--help" ]
570 then
571     HELP=1
572     shift
573     echo
574     echo "Usage: $CFG_SELF [options]"
575     echo
576     echo "Options:"
577     echo
578 else
579     msg "recreating config.tmp"
580     echo '' >config.tmp
581
582     step_msg "processing $CFG_SELF args"
583 fi
584
585 BOOL_OPTIONS=""
586 VAL_OPTIONS=""
587
588 opt debug 0 "debug mode; disables optimization unless \`--enable-optimize\` given"
589 opt valgrind 0 "run tests with valgrind (memcheck by default)"
590 opt helgrind 0 "run tests with helgrind instead of memcheck"
591 opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind"
592 opt docs     1 "build standard library documentation"
593 opt compiler-docs     0 "build compiler documentation"
594 opt optimize-tests 1 "build tests with optimizations"
595 opt debuginfo-tests 0 "build tests with debugger metadata"
596 opt libcpp 1 "build with llvm with libc++ instead of libstdc++ when using clang"
597 opt llvm-assertions 0 "build LLVM with assertions"
598 opt debug-assertions 0 "build with debugging assertions"
599 opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
600 opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
601 opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
602 opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
603 opt rpath 1 "build rpaths into rustc itself"
604 opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0"
605 # This is used by the automation to produce single-target nightlies
606 opt dist-host-only 0 "only install bins for the host architecture"
607 opt inject-std-version 1 "inject the current compiler version of libstd into programs"
608 opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
609 opt rustbuild 0 "use the rust and cargo based build system"
610 opt orbit 0 "get MIR where it belongs - everywhere; most importantly, in orbit"
611 opt codegen-tests 1 "run the src/test/codegen tests"
612 opt option-checking 1 "complain about unrecognized options in this configure script"
613
614 # Optimization and debugging options. These may be overridden by the release channel, etc.
615 opt_nosave optimize 1 "build optimized rust code"
616 opt_nosave optimize-cxx 1 "build optimized C++ code"
617 opt_nosave optimize-llvm 1 "build optimized LLVM"
618 opt_nosave llvm-assertions 0 "build LLVM with assertions"
619 opt_nosave debug-assertions 0 "build with debugging assertions"
620 opt_nosave debuginfo 0 "build with debugger metadata"
621 opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill"
622
623 valopt localstatedir "/var/lib" "local state directory"
624 valopt sysconfdir "/etc" "install system configuration files"
625
626 valopt datadir "${CFG_PREFIX}/share" "install data"
627 valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
628 valopt llvm-root "" "set LLVM root"
629 valopt python "" "set path to python"
630 valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located"
631 valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
632 valopt android-cross-path "" "Android NDK standalone path (deprecated)"
633 valopt i686-linux-android-ndk "" "i686-linux-android NDK standalone path"
634 valopt arm-linux-androideabi-ndk "" "arm-linux-androideabi NDK standalone path"
635 valopt armv7-linux-androideabi-ndk "" "armv7-linux-androideabi NDK standalone path"
636 valopt aarch64-linux-android-ndk "" "aarch64-linux-android NDK standalone path"
637 valopt nacl-cross-path  "" "NaCl SDK path (Pepper Canary is recommended). Must be absolute!"
638 valopt release-channel "dev" "the name of the release channel to build"
639 valopt musl-root "/usr/local" "MUSL root installation directory"
640 valopt extra-filename "" "Additional data that is hashed and passed to the -C extra-filename flag"
641
642 # Used on systems where "cc" and "ar" are unavailable
643 valopt default-linker "cc" "the default linker"
644 valopt default-ar     "ar" "the default ar"
645
646 # Many of these are saved below during the "writing configuration" step
647 # (others are conditionally saved).
648 opt_nosave manage-submodules 1 "let the build manage the git submodules"
649 opt_nosave clang 0 "prefer clang to gcc for building the runtime"
650 opt_nosave jemalloc 1 "build liballoc with jemalloc"
651 opt elf-tls 1 "elf thread local storage on platforms where supported"
652
653 valopt_nosave prefix "/usr/local" "set installation prefix"
654 valopt_nosave local-rust-root "/usr/local" "set prefix for local rust binary"
655 valopt_nosave host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
656 valopt_nosave target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
657 valopt_nosave mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
658
659 # On Windows this determines root of the subtree for target libraries.
660 # Host runtime libs always go to 'bin'.
661 valopt libdir "${CFG_PREFIX}/lib" "install libraries"
662
663 case "$CFG_LIBDIR" in
664     "$CFG_PREFIX"/*) CAT_INC=2;;
665     "$CFG_PREFIX"*)  CAT_INC=1;;
666     *)
667         err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
668 esac
669
670 CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
671
672 if [ $HELP -eq 1 ]
673 then
674     echo
675     exit 0
676 fi
677
678 # Validate Options
679 if [ -z "$CFG_DISABLE_OPTION_CHECKING" ]
680 then
681     step_msg "validating $CFG_SELF args"
682     validate_opt
683 fi
684
685 # Validate the release channel, and configure options
686 case "$CFG_RELEASE_CHANNEL" in
687     nightly )
688         msg "overriding settings for $CFG_RELEASE_CHANNEL"
689         CFG_ENABLE_LLVM_ASSERTIONS=1
690         ;;
691     dev | beta | stable)
692         ;;
693     *)
694         err "release channel must be 'dev', 'nightly', 'beta' or 'stable'"
695         ;;
696 esac
697
698 # Adjust perf and debug options for debug mode
699 if [ -n "$CFG_ENABLE_DEBUG" ]; then
700     msg "debug mode enabled, setting performance options"
701     if [ -z "$CFG_ENABLE_OPTIMIZE_PROVIDED" ]; then
702         msg "optimization not explicitly enabled, disabling optimization"
703         CFG_DISABLE_OPTIMIZE=1
704         CFG_DISABLE_OPTIMIZE_CXX=1
705     fi
706
707     # Set following variables to 1 unless setting already provided
708     enable_if_not_disabled debug-assertions
709     enable_if_not_disabled debug-jemalloc
710     enable_if_not_disabled debuginfo
711     enable_if_not_disabled llvm-assertions
712 fi
713
714 # OK, now write the debugging options
715 if [ -n "$CFG_DISABLE_OPTIMIZE" ]; then putvar CFG_DISABLE_OPTIMIZE; fi
716 if [ -n "$CFG_DISABLE_OPTIMIZE_CXX" ]; then putvar CFG_DISABLE_OPTIMIZE_CXX; fi
717 if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then putvar CFG_DISABLE_OPTIMIZE_LLVM; fi
718 if [ -n "$CFG_ENABLE_LLVM_ASSERTIONS" ]; then putvar CFG_ENABLE_LLVM_ASSERTIONS; fi
719 if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTIONS; fi
720 if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
721 if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
722
723 if [ -n "$CFG_ENABLE_ORBIT" ]; then putvar CFG_ENABLE_ORBIT; fi
724
725 step_msg "looking for build programs"
726
727 probe_need CFG_CURLORWGET  curl wget
728 if [ -z "$CFG_PYTHON_PROVIDED" ]; then
729     probe_need CFG_PYTHON      python2.7 python2 python
730 fi
731
732 python_version=$($CFG_PYTHON -V 2>&1)
733 if [ $(echo $python_version | grep -c '^Python 2\.7') -ne 1 ]; then
734     err "Found $python_version, but Python 2.7 is required"
735 fi
736
737 # If we have no git directory then we are probably a tarball distribution
738 # and shouldn't attempt to load submodules
739 if [ ! -e ${CFG_SRC_DIR}.git ]
740 then
741     probe CFG_GIT          git
742     msg "git: no git directory. disabling submodules"
743     CFG_DISABLE_MANAGE_SUBMODULES=1
744 else
745     probe_need CFG_GIT     git
746 fi
747
748 # Use `md5sum` on GNU platforms, or `md5 -q` on BSD
749 probe CFG_MD5              md5
750 probe CFG_MD5SUM           md5sum
751 if [ -n "$CFG_MD5" ]
752 then
753     CFG_HASH_COMMAND="$CFG_MD5 -q | cut -c 1-8"
754 elif [ -n "$CFG_MD5SUM" ]
755 then
756     CFG_HASH_COMMAND="$CFG_MD5SUM | cut -c 1-8"
757 else
758     err 'could not find one of: md5 md5sum'
759 fi
760 putvar CFG_HASH_COMMAND
761
762 probe CFG_CLANG            clang++
763 probe CFG_CCACHE           ccache
764 probe CFG_GCC              gcc
765 probe CFG_LD               ld
766 probe CFG_VALGRIND         valgrind
767 probe CFG_PERF             perf
768 probe CFG_ISCC             iscc
769 probe CFG_ANTLR4           antlr4
770 probe CFG_GRUN             grun
771 probe CFG_FLEX             flex
772 probe CFG_BISON            bison
773 probe CFG_GDB              gdb
774 probe CFG_LLDB             lldb
775
776 # On MacOS X, invoking `javac` pops up a dialog if the JDK is not
777 # installed. Since `javac` is only used if `antlr4` is available,
778 # probe for it only in this case.
779 if [ -n "$CFG_ANTLR4" ]
780 then
781    probe CFG_JAVAC            javac
782 fi
783
784 # the valgrind rpass tests will fail if you don't have a valgrind, but they're
785 # only disabled if you opt out.
786 if [ -z "$CFG_VALGRIND" ]
787 then
788     # If the user has explicitly asked for valgrind tests, then fail
789     if [ -n "$CFG_ENABLE_VALGRIND" ] && [ -n "$CFG_ENABLE_VALGRIND_PROVIDED" ]
790     then
791         err "No valgrind present, but valgrind tests explicitly requested"
792     else
793         CFG_DISABLE_VALGRIND_RPASS=1
794         putvar CFG_DISABLE_VALGRIND_RPASS
795     fi
796 fi
797
798 if [ -n "$CFG_GDB" ]
799 then
800     # Store GDB's version
801     CFG_GDB_VERSION=$($CFG_GDB --version 2>/dev/null | head -1)
802     putvar CFG_GDB_VERSION
803 fi
804
805 if [ -n "$CFG_LLDB" ]
806 then
807     # Store LLDB's version
808     CFG_LLDB_VERSION=$($CFG_LLDB --version 2>/dev/null | head -1)
809     putvar CFG_LLDB_VERSION
810
811     # If CFG_LLDB_PYTHON_DIR is not already set from the outside and valid, try to read it from
812     # LLDB via the -P commandline options.
813     if [ -z "$CFG_LLDB_PYTHON_DIR" ] || [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
814     then
815         CFG_LLDB_PYTHON_DIR=$($CFG_LLDB -P)
816
817         # If CFG_LLDB_PYTHON_DIR is not a valid directory, set it to something more readable
818         if [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
819         then
820             CFG_LLDB_PYTHON_DIR="LLDB_PYTHON_DIRECTORY_NOT_FOUND"
821         fi
822
823         putvar CFG_LLDB_PYTHON_DIR
824     fi
825 fi
826
827 # LLDB tests on OSX require /usr/bin/python, not something like Homebrew's
828 # /usr/local/bin/python. We're loading a compiled module for LLDB tests which is
829 # only compatible with the system.
830 case $CFG_BUILD in
831     *-apple-darwin)
832         CFG_LLDB_PYTHON=/usr/bin/python
833         ;;
834     *)
835         CFG_LLDB_PYTHON=$CFG_PYTHON
836         ;;
837 esac
838 putvar CFG_LLDB_PYTHON
839
840 step_msg "looking for target specific programs"
841
842 probe CFG_ADB        adb
843
844 BIN_SUF=
845 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ]
846 then
847     BIN_SUF=.exe
848 fi
849
850 if [ -n "$CFG_ENABLE_LOCAL_RUST" ]
851 then
852     system_rustc=$(which rustc)
853     if [ -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} ]
854     then
855         : # everything already configured
856     elif [ -n "$system_rustc" ]
857     then
858         # we assume that rustc is in a /bin directory
859         CFG_LOCAL_RUST_ROOT=${system_rustc%/bin/rustc}
860     else
861         err "no local rust to use"
862     fi
863
864     CMD="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
865     LRV=`$CMD --version`
866     if [ $? -ne 0 ]
867     then
868         step_msg "failure while running $CMD --version"
869         exit 1
870     fi
871     step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
872     putvar CFG_LOCAL_RUST_ROOT
873 fi
874
875 # Force bitrig to build with clang; gcc doesn't like us there
876 if [ $CFG_OSTYPE = unknown-bitrig ]
877 then
878     step_msg "on Bitrig, forcing use of clang"
879     CFG_ENABLE_CLANG=1
880 fi
881
882 # default gcc version under OpenBSD maybe too old, try using egcc, which is a
883 # gcc version from ports
884 if [ $CFG_OSTYPE = unknown-openbsd ]
885 then
886     if [ $("$CFG_GCC" --version 2>&1 | grep -c ' 4\.[0-6]') -ne 0 ]; then
887         step_msg "older GCC found, try with egcc instead"
888
889         # probe again but using egcc
890         probe CFG_GCC egcc
891
892         # and use egcc/eg++ for CC/CXX too if it was found
893         # (but user setting has priority)
894         if [ -n "$CFG_GCC" ]; then
895             CC="${CC:-egcc}"
896             CXX="${CXX:-eg++}"
897         fi
898     fi
899 fi
900
901 # OS X 10.9, gcc is actually clang. This can cause some confusion in the build
902 # system, so if we find that gcc is clang, we should just use clang directly.
903 if [ $CFG_OSTYPE = apple-darwin -a -z "$CFG_ENABLE_CLANG" ]
904 then
905     CFG_OSX_GCC_VERSION=$("$CFG_GCC" --version 2>&1 | grep "Apple LLVM version")
906     if [ $? -eq 0 ]
907     then
908         step_msg "on OS X >=10.9, forcing use of clang"
909         CFG_ENABLE_CLANG=1
910     else
911         if [ $("$CFG_GCC" --version 2>&1 | grep -c ' 4\.[0-6]') -ne 0 ]; then
912             step_msg "older GCC found, using clang instead"
913             CFG_ENABLE_CLANG=1
914         else
915             # on OS X, with xcode 5 and newer, certain developers may have
916             # cc, gcc and g++ point to a  mixture of clang and gcc
917             # if so, this will create very strange build errors
918             # this last stanza is to detect some such problems and save the future rust
919             # contributor some time solving that issue.
920             # this detection could be generalized to other OSes aside from OS X
921             # but the issue seems most likely to happen on OS X
922
923             chk_cc () {
924                 $1 --version 2> /dev/null | grep -q $2
925             }
926             # check that gcc, cc and g++ all point to the same compiler.
927             # note that for xcode 5, g++ points to clang, not clang++
928             if !((chk_cc gcc clang  && chk_cc g++ clang) ||
929                 (chk_cc gcc gcc  &&( chk_cc g++ g++ || chk g++ gcc))); then
930                 err "the gcc and g++ in your path point to different compilers.
931     Check which versions are in your path with gcc --version and g++ --version.
932     To resolve this problem, either fix your PATH  or run configure with --enable-clang"
933             fi
934
935         fi
936     fi
937 fi
938
939 # If the clang isn't already enabled, check for GCC, and if it is missing, turn
940 # on clang as a backup.
941 if [ -z "$CFG_ENABLE_CLANG" ]
942 then
943   CFG_GCC_VERSION=$("$CFG_GCC" --version 2>&1)
944   if [ $? -ne 0 ]
945   then
946     step_msg "GCC not installed, will try using Clang"
947     CFG_ENABLE_CLANG=1
948   fi
949 fi
950
951 # Okay, at this point, we have made up our minds about whether we are
952 # going to force CFG_ENABLE_CLANG or not; save the setting if so.
953 if [ -n "$CFG_ENABLE_CLANG" ]
954 then
955     putvar CFG_ENABLE_CLANG
956 fi
957
958 if [ -z "$CFG_DISABLE_LIBCPP" -a -n "$CFG_ENABLE_CLANG" ]
959 then
960     CFG_USING_LIBCPP="1"
961 else
962     CFG_USING_LIBCPP="0"
963 fi
964
965 # Same with jemalloc.  save the setting here.
966 if [ -n "$CFG_DISABLE_JEMALLOC" ]
967 then
968     putvar CFG_DISABLE_JEMALLOC
969 fi
970
971 if [ -n "$CFG_LLVM_ROOT" -a -z "$CFG_DISABLE_LLVM_VERSION_CHECK" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ]
972 then
973     step_msg "using custom LLVM at $CFG_LLVM_ROOT"
974
975     LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config"
976     LLVM_VERSION=$($LLVM_CONFIG --version)
977
978     case $LLVM_VERSION in
979         (3.[6-8]*)
980             msg "found ok version of LLVM: $LLVM_VERSION"
981             ;;
982         (*)
983             err "bad LLVM version: $LLVM_VERSION, need >=3.6"
984             ;;
985     esac
986 fi
987
988 # Even when the user overrides the choice of CC, still try to detect
989 # clang to disable some clang-specific warnings.  We here draw a
990 # distinction between:
991 #
992 #  CFG_ENABLE_CLANG : passed --enable-clang, or host "requires" clang,
993 #  CFG_USING_CLANG : compiler (clang / gcc / $CC) looks like clang.
994 #
995 # This distinction is important because there are some safeguards we
996 # would prefer to skip when merely CFG_USING_CLANG is set; but when
997 # CFG_ENABLE_CLANG is set, that indicates that we are opting into
998 # running such safeguards.
999
1000 if [ -n "$CC" ]
1001 then
1002     msg "skipping compiler inference steps; using provided CC=$CC"
1003     CFG_CC="$CC"
1004
1005     CFG_OSX_CC_VERSION=$("$CFG_CC" --version 2>&1 | grep "clang")
1006     if [ $? -eq 0 ]
1007     then
1008         step_msg "note, user-provided CC looks like clang; CC=$CC."
1009         CFG_USING_CLANG=1
1010         putvar CFG_USING_CLANG
1011     fi
1012 else
1013     if [ -n "$CFG_ENABLE_CLANG" ]
1014     then
1015         if [ -z "$CFG_CLANG" ]
1016         then
1017             err "clang requested but not found"
1018         fi
1019         CFG_CC="$CFG_CLANG"
1020         CFG_USING_CLANG=1
1021         putvar CFG_USING_CLANG
1022     else
1023         CFG_CC="gcc"
1024     fi
1025 fi
1026
1027 if [ -n "$CFG_ENABLE_CLANG" ]
1028 then
1029     case "$CC" in
1030         (''|*clang)
1031         CFG_CLANG_REPORTED_VERSION=$($CFG_CC --version | grep version)
1032
1033         if echo $CFG_CLANG_REPORTED_VERSION | grep -q "(based on LLVM "; then
1034             CFG_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*(based on LLVM \(.*\))/\1/')
1035         elif echo $CFG_CLANG_REPORTED_VERSION | grep -q "Apple LLVM"; then
1036             CFG_OSX_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*version \(.*\) .*/\1/')
1037         else
1038             CFG_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*version \(.*\) .*/\1/')
1039         fi
1040
1041         if [ -n "$CFG_OSX_CLANG_VERSION" ]
1042         then
1043             case $CFG_OSX_CLANG_VERSION in
1044                 (7.0* | 7.1* | 7.2* | 7.3*)
1045                 step_msg "found ok version of APPLE CLANG: $CFG_OSX_CLANG_VERSION"
1046                 ;;
1047                 (*)
1048                 err "bad APPLE CLANG version: $CFG_OSX_CLANG_VERSION, need >=7.0"
1049                 ;;
1050             esac
1051         else
1052             case $CFG_CLANG_VERSION in
1053                 (3.2* | 3.3* | 3.4* | 3.5* | 3.6* | 3.7* | 3.8* | 3.9*)
1054                 step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
1055                 ;;
1056                 (*)
1057                 err "bad CLANG version: $CFG_CLANG_VERSION, need >=3.0svn"
1058                 ;;
1059             esac
1060         fi
1061
1062         if [ -z "$CC" ]
1063         then
1064             CFG_CC="clang"
1065             CFG_CXX="clang++"
1066         fi
1067     esac
1068 fi
1069
1070 if [ -n "$CFG_ENABLE_CCACHE" ]
1071 then
1072     if [ -z "$CFG_CCACHE" ]
1073     then
1074         err "ccache requested but not found"
1075     fi
1076
1077     CFG_CC="ccache $CFG_CC"
1078 fi
1079
1080 if [ -z "$CC" -a -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
1081 then
1082     err "either clang or gcc is required"
1083 fi
1084
1085 # All safeguards based on $CFG_ENABLE_CLANG should occur before this
1086 # point in the script; after this point, script logic should inspect
1087 # $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG.
1088
1089 # Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS,LDFLAGS}
1090 envopt CC
1091 envopt CXX
1092 envopt CPP
1093 envopt CFLAGS
1094 envopt CXXFLAGS
1095 envopt LDFLAGS
1096
1097 # stdc++ name in use
1098 # used to manage non-standard name (on OpenBSD for example)
1099 program_transform_name=$($CFG_CC -v 2>&1 | sed -n "s/.*--program-transform-name='\([^']*\)'.*/\1/p")
1100 CFG_STDCPP_NAME=$(echo "stdc++" | sed "${program_transform_name}")
1101 putvar CFG_STDCPP_NAME
1102
1103 # a little post-processing of various config values
1104 CFG_PREFIX=${CFG_PREFIX%/}
1105 CFG_MANDIR=${CFG_MANDIR%/}
1106 CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
1107 CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"
1108 CFG_SUPPORTED_TARGET=""
1109 for target_file in ${CFG_SRC_DIR}mk/cfg/*.mk; do
1110   CFG_SUPPORTED_TARGET="${CFG_SUPPORTED_TARGET} $(basename "$target_file" .mk)"
1111 done
1112
1113 # copy build-triples to host-triples so that builds are a subset of hosts
1114 V_TEMP=""
1115 for i in $CFG_BUILD $CFG_HOST;
1116 do
1117    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1118 done
1119 CFG_HOST=$V_TEMP
1120
1121 # copy host-triples to target-triples so that hosts are a subset of targets
1122 V_TEMP=""
1123 for i in $CFG_HOST $CFG_TARGET;
1124 do
1125    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1126 done
1127 CFG_TARGET=$V_TEMP
1128
1129 # check target-specific tool-chains
1130 for i in $CFG_TARGET
1131 do
1132     L_CHECK=false
1133     for j in $CFG_SUPPORTED_TARGET
1134     do
1135         if [ $i = $j ]
1136         then
1137             L_CHECK=true
1138         fi
1139     done
1140
1141     if [ $L_CHECK = false ]
1142     then
1143         err "unsupported target triples \"$i\" found"
1144     fi
1145
1146     case $i in
1147         *android*)
1148             case $i in
1149                 armv7-linux-androideabi)
1150                     cmd_prefix="arm-linux-androideabi"
1151                     ;;
1152                 *)
1153                     cmd_prefix=$i
1154                     ;;
1155             esac
1156
1157             upper_snake_target=$(echo "$i" | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
1158             eval ndk=\$"CFG_${upper_snake_target}_NDK"
1159             if [ -z "$ndk" ]
1160             then
1161                 ndk=$CFG_ANDROID_CROSS_PATH
1162                 eval "CFG_${upper_snake_target}_NDK"=$CFG_ANDROID_CROSS_PATH
1163                 warn "generic/default Android NDK option is deprecated (use --$i-ndk option instead)"
1164             fi
1165
1166             # Perform a basic sanity check of the NDK
1167             for android_ndk_tool in "$ndk/bin/$cmd_prefix-gcc" "$ndk/bin/$cmd_prefix-g++" "$ndk/bin/$cmd_prefix-ar"
1168             do
1169                 if [ ! -f $android_ndk_tool ]
1170                 then
1171                     err "NDK tool $android_ndk_tool not found (bad or missing --$i-ndk option?)"
1172                 fi
1173             done
1174             ;;
1175         *-unknown-nacl)
1176             if [ -z "$CFG_NACL_CROSS_PATH" ]
1177             then
1178                 err "I need the NaCl SDK path! (use --nacl-cross-path)"
1179             fi
1180             ;;
1181         arm-apple-darwin)
1182             if [ $CFG_OSTYPE != apple-darwin ]
1183             then
1184                 err "The iOS target is only supported on Mac OS X"
1185             fi
1186             ;;
1187
1188
1189         x86_64-*-musl)
1190             if [ ! -f $CFG_MUSL_ROOT/lib/libc.a ]
1191             then
1192                 err "musl libc $CFG_MUSL_ROOT/lib/libc.a not found"
1193             fi
1194             ;;
1195
1196         *-msvc)
1197             # There are some MSYS python builds which will auto-translate
1198             # windows-style paths to MSYS-style paths in Python itself.
1199             # Unfortunately this breaks LLVM's build system as somewhere along
1200             # the line LLVM prints a path into a file from Python and then CMake
1201             # later tries to interpret that path. If Python prints a MSYS path
1202             # and CMake tries to use it as a Windows path, you're gonna have a
1203             # Bad Time.
1204             #
1205             # Consequently here we try to detect when that happens and print an
1206             # error if it does.
1207             if $CFG_PYTHON -c 'import sys; print sys.argv[1]' `pwd` | grep '^/' > /dev/null
1208             then
1209                 err "
1210
1211 python is silently translating windows paths to MSYS paths \
1212 and the build will fail if this python is used.
1213
1214 Either an official python install must be used or an \
1215 alternative python package in MinGW must be used.
1216
1217 If you are building under msys2 try installing the mingw-w64-x86_64-python2 \
1218 package instead of python2:
1219
1220 $ pacman -R python2 && pacman -S mingw-w64-x86_64-python2
1221 "
1222             fi
1223
1224             # MSVC requires cmake because that's how we're going to build LLVM
1225             probe_need CFG_CMAKE cmake
1226
1227             # There are three builds of cmake on windows: MSVC, MinGW and Cygwin
1228             # The Cygwin build does not have generators for Visual Studio, so
1229             # detect that here and error.
1230             if ! "$CFG_CMAKE" --help | sed -n '/^Generators/,$p' | grep 'Visual Studio' > /dev/null
1231             then
1232                 err "
1233
1234 cmake does not support Visual Studio generators.
1235
1236 This is likely due to it being an msys/cygwin build of cmake, \
1237 rather than the required windows version, built using MinGW \
1238 or Visual Studio.
1239
1240 If you are building under msys2 try installing the mingw-w64-x86_64-cmake \
1241 package instead of cmake:
1242
1243 $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
1244 "
1245             fi
1246
1247             # Use the REG program to figure out where VS is installed
1248             # We need to figure out where cl.exe and link.exe are, so we do some
1249             # munging and some probing here. We also look for the default
1250             # INCLUDE and LIB variables for MSVC so we can set those in the
1251             # build system as well.
1252             install=$(cmd //c reg QUERY \
1253                        'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\14.0' \
1254                        -v InstallDir)
1255             if [ -z "$install" ]; then
1256               install=$(cmd //c reg QUERY \
1257                          'HKLM\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\12.0' \
1258                          -v InstallDir)
1259             fi
1260             need_ok "couldn't find visual studio install root"
1261             CFG_MSVC_ROOT=$(echo "$install" | grep InstallDir | sed 's/.*REG_SZ[ ]*//')
1262             CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
1263             CFG_MSVC_ROOT=$(dirname "$CFG_MSVC_ROOT")
1264             putvar CFG_MSVC_ROOT
1265
1266             case $i in
1267                 x86_64-*)
1268                     bits=x86_64
1269                     msvc_part=amd64
1270                     ;;
1271                 i*86-*)
1272                     bits=i386
1273                     msvc_part=
1274                     ;;
1275                 *)
1276                     err "can only target x86 targets for MSVC"
1277                     ;;
1278             esac
1279             bindir="${CFG_MSVC_ROOT}/VC/bin"
1280             if [ -n "$msvc_part" ]; then
1281                 bindir="$bindir/$msvc_part"
1282             fi
1283             eval CFG_MSVC_BINDIR_$bits="\"$bindir\""
1284             eval CFG_MSVC_CL_$bits="\"$bindir/cl.exe\""
1285             eval CFG_MSVC_LIB_$bits="\"$bindir/lib.exe\""
1286             eval CFG_MSVC_LINK_$bits="\"$bindir/link.exe\""
1287
1288             vcvarsall="${CFG_MSVC_ROOT}/VC/vcvarsall.bat"
1289             include_path=$(cmd //V:ON //c "$vcvarsall" $msvc_part \& echo !INCLUDE!)
1290             need_ok "failed to learn about MSVC's INCLUDE"
1291             lib_path=$(cmd //V:ON //c "$vcvarsall" $msvc_part \& echo !LIB!)
1292             need_ok "failed to learn about MSVC's LIB"
1293
1294             eval CFG_MSVC_INCLUDE_PATH_${bits}="\"$include_path\""
1295             eval CFG_MSVC_LIB_PATH_${bits}="\"$lib_path\""
1296
1297             putvar CFG_MSVC_BINDIR_${bits}
1298             putvar CFG_MSVC_CL_${bits}
1299             putvar CFG_MSVC_LIB_${bits}
1300             putvar CFG_MSVC_LINK_${bits}
1301             putvar CFG_MSVC_INCLUDE_PATH_${bits}
1302             putvar CFG_MSVC_LIB_PATH_${bits}
1303             ;;
1304
1305         *)
1306             ;;
1307     esac
1308 done
1309
1310 if [ -n "$CFG_PERF" ]
1311 then
1312     HAVE_PERF_LOGFD=`$CFG_PERF stat --log-fd 2>&1 | grep 'unknown option'`
1313     if [ -z "$HAVE_PERF_LOGFD" ];
1314     then
1315         CFG_PERF_WITH_LOGFD=1
1316         putvar CFG_PERF_WITH_LOGFD
1317     fi
1318 fi
1319
1320 if [ -z "$CFG_ENABLE_RUSTBUILD" ]; then
1321
1322   step_msg "making directories"
1323
1324   for i in \
1325       doc doc/std doc/extra \
1326       dl tmp dist
1327   do
1328       make_dir $i
1329   done
1330
1331   for t in $CFG_HOST
1332   do
1333       make_dir $t/llvm
1334   done
1335
1336   for t in $CFG_HOST
1337   do
1338       make_dir $t/rustllvm
1339   done
1340
1341   for t in $CFG_TARGET
1342   do
1343     make_dir $t/rt
1344     for s in 0 1 2 3
1345     do
1346       make_dir $t/rt/stage$s
1347       make_dir $t/rt/jemalloc
1348       make_dir $t/rt/compiler-rt
1349       for i in                                          \
1350         isaac sync test \
1351         arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips arch/powerpc
1352       do
1353         make_dir $t/rt/stage$s/$i
1354       done
1355     done
1356   done
1357
1358   for h in $CFG_HOST
1359   do
1360       for t in $CFG_TARGET
1361       do
1362           # host bin dir stage0
1363           make_dir $h/stage0/bin
1364
1365           # host lib dir stage0
1366           make_dir $h/stage0/lib
1367
1368           # host test dir stage0
1369           make_dir $h/stage0/test
1370
1371           # target bin dir stage0
1372           make_dir $h/stage0/lib/rustlib/$t/bin
1373
1374           # target lib dir stage0
1375           make_dir $h/stage0/lib/rustlib/$t/lib
1376
1377           for i in 1 2 3
1378           do
1379               # host bin dir
1380               make_dir $h/stage$i/bin
1381
1382               # host lib dir
1383               make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE
1384
1385               # host test dir
1386               make_dir $h/stage$i/test
1387
1388               # target bin dir
1389               make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/bin
1390
1391               # target lib dir
1392               make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/lib
1393           done
1394       done
1395
1396       make_dir $h/test/run-pass
1397       make_dir $h/test/run-pass-valgrind
1398       make_dir $h/test/run-pass-fulldeps
1399       make_dir $h/test/run-fail
1400       make_dir $h/test/run-fail-fulldeps
1401       make_dir $h/test/compile-fail
1402       make_dir $h/test/parse-fail
1403       make_dir $h/test/compile-fail-fulldeps
1404       make_dir $h/test/bench
1405       make_dir $h/test/perf
1406       make_dir $h/test/pretty
1407       make_dir $h/test/debuginfo-gdb
1408       make_dir $h/test/debuginfo-lldb
1409       make_dir $h/test/codegen
1410       make_dir $h/test/codegen-units
1411       make_dir $h/test/rustdoc
1412   done
1413
1414 fi
1415
1416 # Configure submodules
1417 step_msg "configuring submodules"
1418
1419 # Have to be in the top of src directory for this
1420 if [ -z $CFG_DISABLE_MANAGE_SUBMODULES ] && [ -z $CFG_ENABLE_RUSTBUILD ]
1421 then
1422     cd ${CFG_SRC_DIR}
1423
1424     msg "git: submodule sync"
1425     "${CFG_GIT}" submodule sync
1426
1427     msg "git: submodule init"
1428     "${CFG_GIT}" submodule init
1429
1430     # Disable submodules that we're not using
1431     if [ -n "${CFG_LLVM_ROOT}" ]; then
1432         msg "git: submodule deinit src/llvm"
1433         "${CFG_GIT}" submodule deinit src/llvm
1434     fi
1435     if [ -n "${CFG_JEMALLOC_ROOT}" ]; then
1436         msg "git: submodule deinit src/jemalloc"
1437         "${CFG_GIT}" submodule deinit src/jemalloc
1438     fi
1439
1440     msg "git: submodule update"
1441     "${CFG_GIT}" submodule update
1442     need_ok "git failed"
1443
1444     msg "git: submodule foreach sync"
1445     "${CFG_GIT}" submodule foreach --recursive 'if test -e .gitmodules; then git submodule sync; fi'
1446     need_ok "git failed"
1447
1448     msg "git: submodule foreach update"
1449     "${CFG_GIT}" submodule update --recursive
1450     need_ok "git failed"
1451
1452     # NB: this is just for the sake of getting the submodule SHA1 values
1453     # and status written into the build log.
1454     msg "git: submodule status"
1455     "${CFG_GIT}" submodule status --recursive
1456
1457     msg "git: submodule clobber"
1458     "${CFG_GIT}" submodule foreach --recursive git clean -dxf
1459     need_ok "git failed"
1460     "${CFG_GIT}" submodule foreach --recursive git checkout .
1461     need_ok "git failed"
1462
1463     cd ${CFG_BUILD_DIR}
1464 fi
1465
1466 # Do a sanity check that the submodule source exists. Because GitHub
1467 # automatically publishes broken tarballs that can't be disabled, and
1468 # people download them and try to use them.
1469 if [ ! -e "${CFG_SRC_DIR}/src/liblibc" ]; then
1470     err "some submodules are missing. Is this a broken tarball?
1471
1472 If you downloaded this tarball from the GitHub release pages at
1473 https://github.com/rust-lang/rust/releases,
1474 then please delete it and instead download the source from
1475 https://www.rust-lang.org/downloads.html"
1476
1477 fi
1478
1479 # Configure llvm, only if necessary
1480 step_msg "looking at LLVM"
1481 CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm/
1482 for t in $CFG_HOST
1483 do
1484     do_reconfigure=1
1485     is_msvc=0
1486     case "$t" in
1487         (*-msvc)
1488         is_msvc=1
1489         ;;
1490     esac
1491
1492     if [ -n "$CFG_ENABLE_RUSTBUILD" ]
1493     then
1494         msg "not configuring LLVM, rustbuild in use"
1495         do_reconfigure=0
1496     elif [ -z $CFG_LLVM_ROOT ]
1497     then
1498         LLVM_BUILD_DIR=${CFG_BUILD_DIR}$t/llvm
1499         if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]
1500         then
1501             LLVM_DBG_OPTS="--enable-debug-symbols --disable-optimized"
1502             # Just use LLVM straight from its build directory to
1503             # avoid 'make install' time
1504             LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug
1505         else
1506             LLVM_DBG_OPTS="--enable-optimized"
1507             LLVM_INST_DIR=$LLVM_BUILD_DIR/Release
1508         fi
1509         if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
1510         then
1511             LLVM_ASSERTION_OPTS="--disable-assertions"
1512         else
1513             LLVM_ASSERTION_OPTS="--enable-assertions"
1514
1515             # Apparently even if we request assertions be enabled for MSVC,
1516             # LLVM's CMake build system ignore this and outputs in `Release`
1517             # anyway.
1518             if [ ${is_msvc} -eq 0 ]; then
1519                 LLVM_INST_DIR=${LLVM_INST_DIR}+Asserts
1520             fi
1521         fi
1522     else
1523         msg "not reconfiguring LLVM, external LLVM root"
1524         # The user is using their own LLVM
1525         LLVM_BUILD_DIR=
1526         LLVM_INST_DIR=$CFG_LLVM_ROOT
1527         do_reconfigure=0
1528         # Check that LLVm FileCheck is available. Needed for the tests
1529         if [ -z "$CFG_DISABLE_CODEGEN_TESTS" ]; then
1530             need_cmd $LLVM_INST_DIR/bin/FileCheck
1531         fi
1532     fi
1533
1534     if [ ${do_reconfigure} -ne 0 ]
1535     then
1536     # because git is hilarious, it might have put the module index
1537     # in a couple places.
1538         index1="${CFG_SRC_DIR}.git/modules/src/llvm/index"
1539         index2="${CFG_SRC_DIR}src/llvm/.git/index"
1540         for index in ${index1} ${index2}
1541         do
1542             config_status="${LLVM_BUILD_DIR}/config.status"
1543             if test -e ${index} -a \
1544                     -e ${config_status} -a \
1545                     ${config_status} -nt ${index}
1546             then
1547                 msg "not reconfiguring LLVM, config.status is fresh"
1548                 do_reconfigure=0
1549             fi
1550         done
1551     fi
1552
1553     # We need the generator later on for compiler-rt even if LLVM's not built
1554     if [ ${is_msvc} -ne 0 ]
1555     then
1556         case "$CFG_MSVC_ROOT" in
1557             *14.0*)
1558                 generator="Visual Studio 14 2015"
1559                 ;;
1560             *12.0*)
1561                 generator="Visual Studio 12 2013"
1562                 ;;
1563             *)
1564                 err "can't determine generator for LLVM cmake"
1565                 ;;
1566         esac
1567         case "$t" in
1568             x86_64-*)
1569                 generator="$generator Win64"
1570                 ;;
1571             i686-*)
1572                 ;;
1573             *)
1574                 err "can only build LLVM for x86 platforms"
1575                 ;;
1576         esac
1577         CFG_CMAKE_GENERATOR=$generator
1578         putvar CFG_CMAKE_GENERATOR
1579     fi
1580
1581     if [ ${do_reconfigure} -ne 0 ] && [ ${is_msvc} -ne 0 ]
1582     then
1583         msg "configuring LLVM for $t with cmake"
1584
1585         CMAKE_ARGS="-DLLVM_INCLUDE_TESTS=OFF"
1586         if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then
1587             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug"
1588         else
1589             CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release"
1590         fi
1591         if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
1592         then
1593             CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=OFF"
1594         else
1595             CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=ON"
1596         fi
1597
1598         msg "configuring LLVM with:"
1599         msg "$CMAKE_ARGS"
1600
1601         (cd $LLVM_BUILD_DIR && "$CFG_CMAKE" $CFG_LLVM_SRC_DIR \
1602                                             -G "$CFG_CMAKE_GENERATOR" \
1603                                             $CMAKE_ARGS)
1604         need_ok "LLVM cmake configure failed"
1605     fi
1606
1607     if [ ${do_reconfigure} -ne 0 ] && [ ${is_msvc} -eq 0 ]
1608     then
1609         # LLVM's configure doesn't recognize the new Windows triples yet
1610         gnu_t=$(to_gnu_triple $t)
1611
1612         msg "configuring LLVM for $gnu_t"
1613
1614         LLVM_TARGETS="--enable-targets=x86,x86_64,arm,aarch64,mips,powerpc"
1615         LLVM_BUILD="--build=$gnu_t"
1616         LLVM_HOST="--host=$gnu_t"
1617         LLVM_TARGET="--target=$gnu_t"
1618
1619         # Disable unused LLVM features
1620         LLVM_OPTS="$LLVM_DBG_OPTS $LLVM_ASSERTION_OPTS --disable-docs --enable-bindings=none"
1621         # Disable term-info, linkage of which comes in multiple forms,
1622         # making our snapshots incompatible (#9334)
1623         LLVM_OPTS="$LLVM_OPTS --disable-terminfo"
1624         # Try to have LLVM pull in as few dependencies as possible (#9397)
1625         LLVM_OPTS="$LLVM_OPTS --disable-zlib --disable-libffi"
1626
1627         # Use win32 native thread/lock apis instead of pthread wrapper.
1628         # (llvm's configure tries to find pthread first, so we have to disable it explicitly.)
1629         # Also note that pthreads works badly on mingw-w64 systems: #8996
1630         case "$CFG_BUILD" in
1631             (*-windows-gnu)
1632             LLVM_OPTS="$LLVM_OPTS --disable-pthreads"
1633             ;;
1634         esac
1635
1636         case "$CFG_CC" in
1637             ("ccache clang")
1638             LLVM_CXX_32="ccache clang++ -Qunused-arguments"
1639             LLVM_CC_32="ccache clang -Qunused-arguments"
1640
1641             LLVM_CXX_64="ccache clang++ -Qunused-arguments"
1642             LLVM_CC_64="ccache clang -Qunused-arguments"
1643             ;;
1644             ("clang")
1645             LLVM_CXX_32="clang++ -Qunused-arguments"
1646             LLVM_CC_32="clang -Qunused-arguments"
1647
1648             LLVM_CXX_64="clang++ -Qunused-arguments"
1649             LLVM_CC_64="clang -Qunused-arguments"
1650             ;;
1651             ("ccache gcc")
1652             LLVM_CXX_32="ccache g++"
1653             LLVM_CC_32="ccache gcc"
1654
1655             LLVM_CXX_64="ccache g++"
1656             LLVM_CC_64="ccache gcc"
1657             ;;
1658             ("gcc")
1659             LLVM_CXX_32="g++"
1660             LLVM_CC_32="gcc"
1661
1662             LLVM_CXX_64="g++"
1663             LLVM_CC_64="gcc"
1664             ;;
1665
1666             (*)
1667             msg "inferring LLVM_CXX/CC from CXX/CC = $CXX/$CC"
1668             if [ -n "$CFG_ENABLE_CCACHE" ]
1669             then
1670                 if [ -z "$CFG_CCACHE" ]
1671                 then
1672                     err "ccache requested but not found"
1673                 fi
1674
1675                 LLVM_CXX_32="ccache $CXX"
1676                 LLVM_CC_32="ccache $CC"
1677
1678                 LLVM_CXX_64="ccache $CXX"
1679                 LLVM_CC_64="ccache $CC"
1680             else
1681                 LLVM_CXX_32="$CXX"
1682                 LLVM_CC_32="$CC"
1683
1684                 LLVM_CXX_64="$CXX"
1685                 LLVM_CC_64="$CC"
1686             fi
1687
1688             ;;
1689         esac
1690
1691         case "$CFG_CPUTYPE" in
1692             (x86*)
1693                 LLVM_CXX_32="$LLVM_CXX_32 -m32"
1694                 LLVM_CC_32="$LLVM_CC_32 -m32"
1695
1696                 LLVM_CFLAGS_32="-m32"
1697                 LLVM_CXXFLAGS_32="-m32"
1698                 LLVM_LDFLAGS_32="-m32"
1699
1700                 LLVM_CFLAGS_64=""
1701                 LLVM_CXXFLAGS_64=""
1702                 LLVM_LDFLAGS_64=""
1703
1704                 LLVM_CXX_32="$LLVM_CXX_32 -m32"
1705                 LLVM_CC_32="$LLVM_CC_32 -m32"
1706                 ;;
1707
1708             (*)
1709                 LLVM_CFLAGS_32=""
1710                 LLVM_CXXFLAGS_32=""
1711                 LLVM_LDFLAGS_32=""
1712
1713                 LLVM_CFLAGS_64=""
1714                 LLVM_CXXFLAGS_64=""
1715                 LLVM_LDFLAGS_64=""
1716                 ;;
1717         esac
1718
1719         if echo $t | grep -q x86_64
1720         then
1721             LLVM_CXX=$LLVM_CXX_64
1722             LLVM_CC=$LLVM_CC_64
1723             LLVM_CFLAGS=$LLVM_CFLAGS_64
1724             LLVM_CXXFLAGS=$LLVM_CXXFLAGS_64
1725             LLVM_LDFLAGS=$LLVM_LDFLAGS_64
1726         else
1727             LLVM_CXX=$LLVM_CXX_32
1728             LLVM_CC=$LLVM_CC_32
1729             LLVM_CFLAGS=$LLVM_CFLAGS_32
1730             LLVM_CXXFLAGS=$LLVM_CXXFLAGS_32
1731             LLVM_LDFLAGS=$LLVM_LDFLAGS_32
1732         fi
1733
1734         CXX=$LLVM_CXX
1735         CC=$LLVM_CC
1736         CFLAGS="$CFLAGS $LLVM_CFLAGS"
1737         CXXFLAGS="$CXXFLAGS $LLVM_CXXFLAGS"
1738         LDFLAGS="$LDFLAGS $LLVM_LDFLAGS"
1739
1740         if [ "$CFG_USING_LIBCPP" != "0" ]; then
1741             LLVM_OPTS="$LLVM_OPTS --enable-libcpp"
1742         fi
1743
1744         LLVM_FLAGS="$LLVM_TARGETS $LLVM_OPTS $LLVM_BUILD \
1745                         $LLVM_HOST $LLVM_TARGET --with-python=$CFG_PYTHON"
1746
1747         msg "configuring LLVM with:"
1748         msg "$LLVM_FLAGS"
1749
1750         export CXX
1751         export CC
1752         export CFLAGS
1753         export CXXFLAGS
1754         export LDFLAGS
1755
1756         cd $LLVM_BUILD_DIR
1757         case $CFG_SRC_DIR in
1758             /* | [a-z]:* | [A-Z]:*)
1759                 ${CFG_LLVM_SRC_DIR}configure $LLVM_FLAGS
1760                 ;;
1761             *)
1762                 ${CFG_BUILD_DIR}${CFG_LLVM_SRC_DIR}configure \
1763                     $LLVM_FLAGS
1764                 ;;
1765         esac
1766         need_ok "LLVM configure failed"
1767
1768         cd $CFG_BUILD_DIR
1769     fi
1770
1771     # Construct variables for LLVM build and install directories for
1772     # each target. These will be named
1773     # CFG_LLVM_BUILD_DIR_${target_triple} but all the hyphens in
1774     # target_triple will be converted to underscore, because bash
1775     # variables can't contain hyphens. The makefile will then have to
1776     # convert back.
1777     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1778     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1779     eval ${CFG_LLVM_BUILD_DIR}="'$LLVM_BUILD_DIR'"
1780     eval ${CFG_LLVM_INST_DIR}="'$LLVM_INST_DIR'"
1781 done
1782
1783
1784 step_msg "writing configuration"
1785
1786 putvar CFG_SRC_DIR
1787 putvar CFG_SRC_DIR_RELATIVE
1788 putvar CFG_BUILD_DIR
1789 putvar CFG_OSTYPE
1790 putvar CFG_CPUTYPE
1791 putvar CFG_CONFIGURE_ARGS
1792 putvar CFG_PREFIX
1793 putvar CFG_HOST
1794 putvar CFG_TARGET
1795 putvar CFG_LIBDIR_RELATIVE
1796 putvar CFG_DISABLE_MANAGE_SUBMODULES
1797 putvar CFG_AARCH64_LINUX_ANDROID_NDK
1798 putvar CFG_ARM_LINUX_ANDROIDEABI_NDK
1799 putvar CFG_ARMV7_LINUX_ANDROIDEABI_NDK
1800 putvar CFG_I686_LINUX_ANDROID_NDK
1801 putvar CFG_NACL_CROSS_PATH
1802 putvar CFG_MANDIR
1803 putvar CFG_USING_LIBCPP
1804
1805 # Avoid spurious warnings from clang by feeding it original source on
1806 # ccache-miss rather than preprocessed input.
1807 if [ -n "$CFG_ENABLE_CCACHE" ] && [ -n "$CFG_USING_CLANG" ]
1808 then
1809     CFG_CCACHE_CPP2=1
1810     putvar CFG_CCACHE_CPP2
1811 fi
1812
1813 if [ -n "$CFG_ENABLE_CCACHE" ]
1814 then
1815     CFG_CCACHE_BASEDIR=${CFG_SRC_DIR}
1816     putvar CFG_CCACHE_BASEDIR
1817 fi
1818
1819
1820 putvar CFG_LLVM_SRC_DIR
1821
1822 for t in $CFG_HOST
1823 do
1824     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1825     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1826     putvar $CFG_LLVM_BUILD_DIR
1827     putvar $CFG_LLVM_INST_DIR
1828 done
1829
1830 if [ -n "$CFG_ENABLE_RUSTBUILD" ]
1831 then
1832     INPUT_MAKEFILE=src/bootstrap/mk/Makefile.in
1833 else
1834     INPUT_MAKEFILE=Makefile.in
1835 fi
1836
1837 msg
1838 copy_if_changed ${CFG_SRC_DIR}${INPUT_MAKEFILE} ./Makefile
1839 move_if_changed config.tmp config.mk
1840 rm -f config.tmp
1841 touch config.stamp
1842
1843 if [ -z "$CFG_ENABLE_DEBUG" ]; then
1844     step_msg "configured in release mode. for development consider --enable-debug"
1845 else
1846     step_msg "complete"
1847 fi
1848
1849 msg "run \`make help\`"
1850 msg