]> git.lizzy.rs Git - rust.git/blob - configure
`bitflags!` is no longer used in `std`
[rust.git] / configure
1 #!/bin/sh
2
3 msg() {
4     echo "configure: $1"
5 }
6
7 step_msg() {
8     msg
9     msg "$1"
10     msg
11 }
12
13 warn() {
14     echo "configure: WARNING: $1"
15 }
16
17 err() {
18     echo "configure: error: $1"
19     exit 1
20 }
21
22 need_ok() {
23     if [ $? -ne 0 ]
24     then
25         err "$1"
26     fi
27 }
28
29 need_cmd() {
30     if command -v $1 >/dev/null 2>&1
31     then msg "found program $1"
32     else err "need program $1"
33     fi
34 }
35
36 make_dir() {
37     if [ ! -d $1 ]
38     then
39         msg "mkdir -p $1"
40         mkdir -p $1
41     fi
42 }
43
44 copy_if_changed() {
45     if cmp -s $1 $2
46     then
47         msg "leaving $2 unchanged"
48     else
49         msg "cp $1 $2"
50         cp -f $1 $2
51         chmod u-w $2 # make copied artifact read-only
52     fi
53 }
54
55 move_if_changed() {
56     if cmp -s $1 $2
57     then
58         msg "leaving $2 unchanged"
59     else
60         msg "mv $1 $2"
61         mv -f $1 $2
62         chmod u-w $2 # make moved artifact read-only
63     fi
64 }
65
66 putvar() {
67     local T
68     eval T=\$$1
69     eval TLEN=\${#$1}
70     if [ $TLEN -gt 35 ]
71     then
72         printf "configure: %-20s := %.35s ...\n" $1 "$T"
73     else
74         printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
75     fi
76     printf "%-20s := %s\n" $1 "$T" >>config.tmp
77 }
78
79 putpathvar() {
80     local T
81     eval T=\$$1
82     eval TLEN=\${#$1}
83     if [ $TLEN -gt 35 ]
84     then
85         printf "configure: %-20s := %.35s ...\n" $1 "$T"
86     else
87         printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
88     fi
89     if [ -z "$T" ]
90     then
91         printf "%-20s := \n" $1 >>config.tmp
92     else
93         printf "%-20s := \"%s\"\n" $1 "$T" >>config.tmp
94     fi
95 }
96
97 probe() {
98     local V=$1
99     shift
100     local P
101     local T
102     for P
103     do
104         T=$(command -v $P 2>&1)
105         if [ $? -eq 0 ]
106         then
107             VER0=$($P --version 2>/dev/null | head -1 \
108                 |  sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
109             if [ $? -eq 0 -a "x${VER0}" != "x" ]
110             then
111               VER="($VER0)"
112             else
113               VER=""
114             fi
115             break
116         else
117             VER=""
118             T=""
119         fi
120     done
121     eval $V=\$T
122     putpathvar $V "$VER"
123 }
124
125 probe_need() {
126     local V=$1
127     probe $*
128     eval VV=\$$V
129     if [ -z "$VV" ]
130     then
131         err "needed, but unable to find any of: $*"
132     fi
133 }
134
135 validate_opt () {
136     for arg in $CFG_CONFIGURE_ARGS
137     do
138         isArgValid=0
139         for option in $BOOL_OPTIONS
140         do
141             if test --disable-$option = $arg
142             then
143                 isArgValid=1
144             fi
145             if test --enable-$option = $arg
146             then
147                 isArgValid=1
148             fi
149         done
150         for option in $VAL_OPTIONS
151         do
152             if echo "$arg" | grep -q -- "--$option="
153             then
154                 isArgValid=1
155             fi
156         done
157         if [ "$arg" = "--help" ]
158         then
159             echo
160             echo "No more help available for Configure options,"
161             echo "check the Wiki or join our IRC channel"
162             break
163         else
164             if test $isArgValid -eq 0
165             then
166                 err "Option '$arg' is not recognized"
167             fi
168         fi
169     done
170 }
171
172 # `valopt OPTION_NAME DEFAULT DOC` extracts a string-valued option
173 # from command line, using provided default value for the option if
174 # not present, and saves it to the generated config.mk.
175 #
176 # `valopt_nosave` is much the same, except that it does not save the
177 # result to config.mk (instead the script should use `putvar` itself
178 # later on to save it).  `valopt_core` is the core upon which the
179 # other two are built.
180
181 valopt_core() {
182     VAL_OPTIONS="$VAL_OPTIONS $2"
183
184     local SAVE=$1
185     local OP=$2
186     local DEFAULT=$3
187     shift
188     shift
189     shift
190     local DOC="$*"
191     if [ $HELP -eq 0 ]
192     then
193         local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
194         local V="CFG_${UOP}"
195         local V_PROVIDED="${V}_PROVIDED"
196         eval $V="$DEFAULT"
197         for arg in $CFG_CONFIGURE_ARGS
198         do
199             if echo "$arg" | grep -q -- "--$OP="
200             then
201                 val=$(echo "$arg" | cut -f2 -d=)
202                 eval $V=$val
203                 eval $V_PROVIDED=1
204             fi
205         done
206         if [ "$SAVE" = "save" ]
207         then
208             putvar $V
209         fi
210     else
211         if [ -z "$DEFAULT" ]
212         then
213             DEFAULT="<none>"
214         fi
215         OP="${OP}=[${DEFAULT}]"
216         printf "    --%-30s %s\n" "$OP" "$DOC"
217     fi
218 }
219
220 valopt_nosave() {
221     valopt_core nosave "$@"
222 }
223
224 valopt() {
225     valopt_core save "$@"
226 }
227
228 # `opt OPTION_NAME DEFAULT DOC` extracts a boolean-valued option from
229 # command line, using the provided default value (0/1) for the option
230 # if not present, and saves it to the generated config.mk.
231 #
232 # `opt_nosave` is much the same, except that it does not save the
233 # result to config.mk (instead the script should use `putvar` itself
234 # later on to save it).  `opt_core` is the core upon which the other
235 # two are built.
236
237 opt_core() {
238     BOOL_OPTIONS="$BOOL_OPTIONS $2"
239
240     local SAVE=$1
241     local OP=$2
242     local DEFAULT=$3
243     shift
244     shift
245     shift
246     local DOC="$*"
247     local FLAG=""
248
249     if [ $DEFAULT -eq 0 ]
250     then
251         FLAG="enable"
252         DEFAULT_FLAG="disable"
253     else
254         FLAG="disable"
255         DEFAULT_FLAG="enable"
256         DOC="don't $DOC"
257     fi
258
259     if [ $HELP -eq 0 ]
260     then
261         for arg in $CFG_CONFIGURE_ARGS
262         do
263             if [ "$arg" = "--${FLAG}-${OP}" ]
264             then
265                 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
266                 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
267                 local V="CFG_${FLAG}_${OP}"
268                 local V_PROVIDED="CFG_${FLAG}_${OP}_PROVIDED"
269                 eval $V=1
270                 eval $V_PROVIDED=1
271                 if [ "$SAVE" = "save" ]
272                 then
273                    putvar $V
274                 fi
275             elif [ "$arg" = "--${DEFAULT_FLAG}-${OP}" ]
276             then
277                 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
278                 DEFAULT_FLAG=$(echo $DEFAULT_FLAG | tr 'a-z' 'A-Z')
279                 local V_PROVIDED="CFG_${DEFAULT_FLAG}_${OP}_PROVIDED"
280                 eval $V_PROVIDED=1
281             fi
282         done
283     else
284         if [ ! -z "$META" ]
285         then
286             OP="$OP=<$META>"
287         fi
288         printf "    --%-30s %s\n" "$FLAG-$OP" "$DOC"
289      fi
290 }
291
292 opt_nosave() {
293     opt_core nosave "$@"
294 }
295
296 opt() {
297     opt_core save "$@"
298 }
299
300 envopt() {
301     local NAME=$1
302     local V="CFG_${NAME}"
303     eval VV=\$$V
304
305     # If configure didn't set a value already, then check environment.
306     #
307     # (It is recommended that the configure script always check the
308     # environment before setting any values to envopt variables; see
309     # e.g.  how CFG_CC is handled, where it first checks `-z "$CC"`,
310     # and issues msg if it ends up employing that provided value.)
311     if [ -z "$VV" ]
312     then
313         eval $V=\$$NAME
314         eval VV=\$$V
315     fi
316
317     # If script or environment provided a value, save it.
318     if [ ! -z "$VV" ]
319     then
320         putvar $V
321     fi
322 }
323
324 to_llvm_triple() {
325     case $1 in
326         i686-w64-mingw32) echo i686-pc-windows-gnu ;;
327         x86_64-w64-mingw32) echo x86_64-pc-windows-gnu ;;
328         *) echo $1 ;;
329     esac
330 }
331
332 to_gnu_triple() {
333     case $1 in
334         i686-pc-windows-gnu) echo i686-w64-mingw32 ;;
335         x86_64-pc-windows-gnu) echo x86_64-w64-mingw32 ;;
336         *) echo $1 ;;
337     esac
338 }
339
340 # Prints the absolute path of a directory to stdout
341 abs_path() {
342     local _path="$1"
343     # Unset CDPATH because it causes havok: it makes the destination unpredictable
344     # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
345     # for good measure.
346     (unset CDPATH && cd "$_path" > /dev/null && pwd)
347 }
348
349 msg "looking for configure programs"
350 need_cmd cmp
351 need_cmd mkdir
352 need_cmd printf
353 need_cmd cut
354 need_cmd head
355 need_cmd grep
356 need_cmd xargs
357 need_cmd cp
358 need_cmd find
359 need_cmd uname
360 need_cmd date
361 need_cmd tr
362 need_cmd sed
363 need_cmd file
364 need_cmd make
365
366 msg "inspecting environment"
367
368 CFG_OSTYPE=$(uname -s)
369 CFG_CPUTYPE=$(uname -m)
370
371 if [ $CFG_OSTYPE = Darwin -a $CFG_CPUTYPE = i386 ]
372 then
373     # Darwin's `uname -s` lies and always returns i386. We have to use sysctl
374     # instead.
375     if sysctl hw.optional.x86_64 | grep -q ': 1'
376     then
377         CFG_CPUTYPE=x86_64
378     fi
379 fi
380
381 # The goal here is to come up with the same triple as LLVM would,
382 # at least for the subset of platforms we're willing to target.
383
384 case $CFG_OSTYPE in
385
386     Linux)
387         CFG_OSTYPE=unknown-linux-gnu
388         ;;
389
390     FreeBSD)
391         CFG_OSTYPE=unknown-freebsd
392         ;;
393
394     DragonFly)
395         CFG_OSTYPE=unknown-dragonfly
396         ;;
397
398     Bitrig)
399         CFG_OSTYPE=unknown-bitrig
400         ;;
401
402     OpenBSD)
403         CFG_OSTYPE=unknown-openbsd
404        ;;
405
406     Darwin)
407         CFG_OSTYPE=apple-darwin
408         ;;
409
410     MINGW*)
411         # msys' `uname` does not print gcc configuration, but prints msys
412         # configuration. so we cannot believe `uname -m`:
413         # msys1 is always i686 and msys2 is always x86_64.
414         # instead, msys defines $MSYSTEM which is MINGW32 on i686 and
415         # MINGW64 on x86_64.
416         CFG_CPUTYPE=i686
417         CFG_OSTYPE=pc-windows-gnu
418         if [ "$MSYSTEM" = MINGW64 ]
419         then
420             CFG_CPUTYPE=x86_64
421         fi
422         ;;
423
424     MSYS*)
425         CFG_OSTYPE=pc-windows-gnu
426         ;;
427
428 # Thad's Cygwin identifiers below
429
430 #   Vista 32 bit
431     CYGWIN_NT-6.0)
432         CFG_OSTYPE=pc-windows-gnu
433         CFG_CPUTYPE=i686
434         ;;
435
436 #   Vista 64 bit
437     CYGWIN_NT-6.0-WOW64)
438         CFG_OSTYPE=pc-windows-gnu
439         CFG_CPUTYPE=x86_64
440         ;;
441
442 #   Win 7 32 bit
443     CYGWIN_NT-6.1)
444         CFG_OSTYPE=pc-windows-gnu
445         CFG_CPUTYPE=i686
446         ;;
447
448 #   Win 7 64 bit
449     CYGWIN_NT-6.1-WOW64)
450         CFG_OSTYPE=pc-windows-gnu
451         CFG_CPUTYPE=x86_64
452         ;;
453
454 #   Win 8 # uname -s on 64-bit cygwin does not contain WOW64, so simply use uname -m to detect arch (works in my install)
455     CYGWIN_NT-6.3)
456         CFG_OSTYPE=pc-windows-gnu
457         ;;
458 # We do not detect other OS such as XP/2003 using 64 bit using uname.
459 # 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.
460     *)
461         err "unknown OS type: $CFG_OSTYPE"
462         ;;
463 esac
464
465
466 case $CFG_CPUTYPE in
467
468     i386 | i486 | i686 | i786 | x86)
469         CFG_CPUTYPE=i686
470         ;;
471
472     xscale | arm)
473         CFG_CPUTYPE=arm
474         ;;
475
476     armv7l)
477         CFG_CPUTYPE=arm
478         CFG_OSTYPE="${CFG_OSTYPE}eabihf"
479         ;;
480
481     aarch64)
482         CFG_CPUTYPE=aarch64
483         ;;
484
485     # At some point, when ppc64[le] support happens, this will need to do
486     # something clever. For now it's safe to assume that we're only ever
487     # interested in building 32 bit.
488     powerpc | ppc | ppc64)
489         CFG_CPUTYPE=powerpc
490         ;;
491
492     x86_64 | x86-64 | x64 | amd64)
493         CFG_CPUTYPE=x86_64
494         ;;
495
496     *)
497         err "unknown CPU type: $CFG_CPUTYPE"
498 esac
499
500 # Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
501 if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
502 then
503     # $SHELL does not exist in standard 'sh', so probably only exists
504     # if configure is running in an interactive bash shell. /usr/bin/env
505     # exists *everywhere*.
506     BIN_TO_PROBE="$SHELL"
507     if [ -z "$BIN_TO_PROBE" -a -e "/usr/bin/env" ]; then
508        BIN_TO_PROBE="/usr/bin/env"
509     fi
510     if [ -n "$BIN_TO_PROBE" ]; then
511        file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64"
512        if [ $? != 0 ]; then
513             CFG_CPUTYPE=i686
514        fi
515      fi
516 fi
517
518
519 DEFAULT_BUILD="${CFG_CPUTYPE}-${CFG_OSTYPE}"
520
521 CFG_SRC_DIR="$(abs_path $(dirname $0))/"
522 CFG_BUILD_DIR="$(pwd)/"
523 CFG_SELF="$0"
524 CFG_CONFIGURE_ARGS="$@"
525
526 OPTIONS=""
527 HELP=0
528 if [ "$1" = "--help" ]
529 then
530     HELP=1
531     shift
532     echo
533     echo "Usage: $CFG_SELF [options]"
534     echo
535     echo "Options:"
536     echo
537 else
538     msg "recreating config.tmp"
539     echo '' >config.tmp
540
541     step_msg "processing $CFG_SELF args"
542 fi
543
544 BOOL_OPTIONS=""
545 VAL_OPTIONS=""
546
547 opt debug 0 "debug mode"
548 opt valgrind 0 "run tests with valgrind (memcheck by default)"
549 opt helgrind 0 "run tests with helgrind instead of memcheck"
550 opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind"
551 opt docs     1 "build standard library documentation"
552 opt compiler-docs     0 "build compiler documentation"
553 opt optimize-tests 1 "build tests with optimizations"
554 opt libcpp 1 "build with llvm with libc++ instead of libstdc++ when using clang"
555 opt llvm-assertions 0 "build LLVM with assertions"
556 opt debug-assertions 0 "build with debugging assertions"
557 opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
558 opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
559 opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
560 opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
561 opt rpath 0 "build rpaths into rustc itself"
562 # This is used by the automation to produce single-target nightlies
563 opt dist-host-only 0 "only install bins for the host architecture"
564 opt inject-std-version 1 "inject the current compiler version of libstd into programs"
565 opt llvm-version-check 1 "don't check if the LLVM version is supported, build anyway"
566
567 # Optimization and debugging options. These may be overridden by the release channel, etc.
568 opt_nosave optimize 1 "build optimized rust code"
569 opt_nosave optimize-cxx 1 "build optimized C++ code"
570 opt_nosave optimize-llvm 1 "build optimized LLVM"
571 opt_nosave llvm-assertions 0 "build LLVM with assertions"
572 opt_nosave debug-assertions 0 "build with debugging assertions"
573 opt_nosave debuginfo 0 "build with debugger metadata"
574 opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill"
575
576 valopt localstatedir "/var/lib" "local state directory"
577 valopt sysconfdir "/etc" "install system configuration files"
578
579 valopt datadir "${CFG_PREFIX}/share" "install data"
580 valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
581 valopt llvm-root "" "set LLVM root"
582 valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located"
583 valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
584 valopt android-cross-path "/opt/ndk_standalone" "Android NDK standalone path"
585 valopt release-channel "dev" "the name of the release channel to build"
586 valopt musl-root "/usr/local" "MUSL root installation directory"
587
588 # Many of these are saved below during the "writing configuration" step
589 # (others are conditionally saved).
590 opt_nosave manage-submodules 1 "let the build manage the git submodules"
591 opt_nosave clang 0 "prefer clang to gcc for building the runtime"
592 opt_nosave jemalloc 1 "build liballoc with jemalloc"
593
594 valopt_nosave prefix "/usr/local" "set installation prefix"
595 valopt_nosave local-rust-root "/usr/local" "set prefix for local rust binary"
596 valopt_nosave host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
597 valopt_nosave target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
598 valopt_nosave mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
599
600 # Temporarily support old triples until buildbots get updated
601 CFG_BUILD=$(to_llvm_triple $CFG_BUILD)
602 putvar CFG_BUILD # Yes, this creates a duplicate entry, but the last one wins.
603 CFG_HOST=$(to_llvm_triple $CFG_HOST)
604 CFG_TARGET=$(to_llvm_triple $CFG_TARGET)
605
606 # On windows we just store the libraries in the bin directory because
607 # there's no rpath. This is where the build system itself puts libraries;
608 # --libdir is used to configure the installation directory.
609 # FIXME: This needs to parameterized over target triples. Do it in platform.mk
610 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ]
611 then
612     CFG_LIBDIR_RELATIVE=bin
613 else
614     CFG_LIBDIR_RELATIVE=lib
615 fi
616
617 valopt libdir "${CFG_PREFIX}/${CFG_LIBDIR_RELATIVE}" "install libraries (do not set it on windows platform)"
618
619 case "$CFG_LIBDIR" in
620     "$CFG_PREFIX"/*) CAT_INC=2;;
621     "$CFG_PREFIX"*)  CAT_INC=1;;
622     *)
623         err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
624 esac
625
626 CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
627
628 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] && [ "$CFG_LIBDIR_RELATIVE" != "bin" ]; then
629     err "libdir on windows should be set to 'bin'"
630 fi
631
632 if [ $HELP -eq 1 ]
633 then
634     echo
635     exit 0
636 fi
637
638 # Validate Options
639 step_msg "validating $CFG_SELF args"
640 validate_opt
641
642 # Validate the release channel, and configure options
643 case "$CFG_RELEASE_CHANNEL" in
644     nightly )
645         msg "overriding settings for $CFG_RELEASE_CHANNEL"
646         CFG_ENABLE_LLVM_ASSERTIONS=1
647         ;;
648     dev | beta | stable)
649         ;;
650     *)
651         err "release channel must be 'dev', 'nightly', 'beta' or 'stable'"
652         ;;
653 esac
654
655 # Adjust perf and debug options for debug mode
656 if [ -n "$CFG_ENABLE_DEBUG" ]; then
657     msg "debug mode enabled, setting performance options"
658     if [ -z "$CFG_ENABLE_OPTIMIZE_PROVIDED" ]; then
659         msg "optimization not explicitly enabled, disabling optimization"
660         CFG_DISABLE_OPTIMIZE=1
661         CFG_DISABLE_OPTIMIZE_CXX=1
662     fi
663     CFG_ENABLE_DEBUG_ASSERTIONS=1
664     CFG_ENABLE_DEBUG_JEMALLOC=1
665     CFG_ENABLE_DEBUGINFO=1
666     CFG_ENABLE_LLVM_ASSERTIONS=1
667 fi
668
669 # OK, now write the debugging options
670 if [ -n "$CFG_DISABLE_OPTIMIZE" ]; then putvar CFG_DISABLE_OPTIMIZE; fi
671 if [ -n "$CFG_DISABLE_OPTIMIZE_CXX" ]; then putvar CFG_DISABLE_OPTIMIZE_CXX; fi
672 if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then putvar CFG_DISABLE_OPTIMIZE_LLVM; fi
673 if [ -n "$CFG_ENABLE_LLVM_ASSERTIONS" ]; then putvar CFG_ENABLE_LLVM_ASSERTIONS; fi
674 if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTIONS; fi
675 if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
676 if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
677
678 # A magic value that allows the compiler to use unstable features
679 # during the bootstrap even when doing so would normally be an error
680 # because of feature staging or because the build turns on
681 # warnings-as-errors and unstable features default to warnings.  The
682 # build has to match this key in an env var. Meant to be a mild
683 # deterrent from users just turning on unstable features on the stable
684 # channel.
685 # Basing CFG_BOOTSTRAP_KEY on CFG_BOOTSTRAP_KEY lets it get picked up
686 # during a Makefile reconfig.
687 CFG_BOOTSTRAP_KEY="${CFG_BOOTSTRAP_KEY-`date +%H:%M:%S`}"
688 putvar CFG_BOOTSTRAP_KEY
689
690 step_msg "looking for build programs"
691
692 probe_need CFG_CURLORWGET  curl wget
693 probe_need CFG_PYTHON      python2.7 python2.6 python2 python
694
695 python_version=$($CFG_PYTHON -V 2>&1)
696 if [ $(echo $python_version | grep -c '^Python 2\.[4567]') -ne 1 ]; then
697     err "Found $python_version, but LLVM requires Python 2.4-2.7"
698 fi
699
700 # If we have no git directory then we are probably a tarball distribution
701 # and shouldn't attempt to load submodules
702 if [ ! -e ${CFG_SRC_DIR}.git ]
703 then
704     probe CFG_GIT          git
705     msg "git: no git directory. disabling submodules"
706     CFG_DISABLE_MANAGE_SUBMODULES=1
707 else
708     probe_need CFG_GIT     git
709 fi
710
711 probe CFG_CLANG            clang++
712 probe CFG_CCACHE           ccache
713 probe CFG_GCC              gcc
714 probe CFG_LD               ld
715 probe CFG_VALGRIND         valgrind
716 probe CFG_PERF             perf
717 probe CFG_ISCC             iscc
718 probe CFG_ANTLR4           antlr4
719 probe CFG_GRUN             grun
720 probe CFG_FLEX             flex
721 probe CFG_BISON            bison
722 probe CFG_PANDOC           pandoc
723 probe CFG_XELATEX          xelatex
724 probe CFG_GDB              gdb
725 probe CFG_LLDB             lldb
726
727 # On MacOS X, invoking `javac` pops up a dialog if the JDK is not
728 # installed. Since `javac` is only used if `antlr4` is available,
729 # probe for it only in this case.
730 if [ ! -z "$CFG_ANTLR4" ]
731 then
732    probe CFG_JAVAC            javac
733 fi
734
735 if [ ! -z "$CFG_GDB" ]
736 then
737     # Store GDB's version
738     CFG_GDB_VERSION=$($CFG_GDB --version 2>/dev/null | head -1)
739     putvar CFG_GDB_VERSION
740 fi
741
742 if [ ! -z "$CFG_LLDB" ]
743 then
744     # Store LLDB's version
745     CFG_LLDB_VERSION=$($CFG_LLDB --version 2>/dev/null | head -1)
746     putvar CFG_LLDB_VERSION
747
748     # If CFG_LLDB_PYTHON_DIR is not already set from the outside and valid, try to read it from
749     # LLDB via the -P commandline options.
750     if [ -z "$CFG_LLDB_PYTHON_DIR" ] || [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
751     then
752         CFG_LLDB_PYTHON_DIR=$($CFG_LLDB -P)
753
754         # If CFG_LLDB_PYTHON_DIR is not a valid directory, set it to something more readable
755         if [ ! -d "$CFG_LLDB_PYTHON_DIR" ]
756         then
757             CFG_LLDB_PYTHON_DIR="LLDB_PYTHON_DIRECTORY_NOT_FOUND"
758         fi
759
760         putvar CFG_LLDB_PYTHON_DIR
761     fi
762 fi
763
764 step_msg "looking for target specific programs"
765
766 probe CFG_ADB        adb
767
768 if [ ! -z "$CFG_PANDOC" ]
769 then
770     # Extract "MAJOR MINOR" from Pandoc's version number
771     PV_MAJOR_MINOR=$(pandoc --version | grep '^pandoc' |
772         sed -E 's/pandoc(.exe)? ([0-9]+)\.([0-9]+).*/\2 \3/')
773
774     MIN_PV_MAJOR="1"
775     MIN_PV_MINOR="9"
776
777     # these patterns are shell globs, *not* regexps
778     PV_MAJOR=${PV_MAJOR_MINOR% *}
779     PV_MINOR=${PV_MAJOR_MINOR#* }
780
781     if [ "$PV_MAJOR" -lt "$MIN_PV_MAJOR" ] || [ "$PV_MINOR" -lt "$MIN_PV_MINOR" ]
782     then
783         step_msg "pandoc $PV_MAJOR.$PV_MINOR is too old. Need at least $MIN_PV_MAJOR.$MIN_PV_MINOR. Disabling"
784         BAD_PANDOC=1
785     fi
786 fi
787
788 BIN_SUF=
789 if [ "$CFG_OSTYPE" = "pc-windows-gnu" ]
790 then
791     BIN_SUF=.exe
792 fi
793
794 if [ ! -z "$CFG_ENABLE_LOCAL_RUST" ]
795 then
796     system_rustc=$(which rustc)
797     if [ -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} ]
798     then
799         : # everything already configured
800     elif [ -n "$system_rustc" ]
801     then
802         # we assume that rustc is in a /bin directory
803         CFG_LOCAL_RUST_ROOT=${system_rustc%/bin/rustc}
804     else
805         err "no local rust to use"
806     fi
807
808     CMD="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
809     LRV=`$CMD --version`
810     if [ $? -ne 0 ]
811     then
812         step_msg "failure while running $CMD --version"
813         exit 1
814     fi
815     step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
816     putvar CFG_LOCAL_RUST_ROOT
817 fi
818
819 # Force freebsd to build with clang; gcc doesn't like us there
820 if [ $CFG_OSTYPE = unknown-freebsd ]
821 then
822     step_msg "on FreeBSD, forcing use of clang"
823     CFG_ENABLE_CLANG=1
824 fi
825
826 # Force bitrig to build with clang; gcc doesn't like us there
827 if [ $CFG_OSTYPE = unknown-bitrig ]
828 then
829     step_msg "on Bitrig, forcing use of clang, disabling jemalloc"
830     CFG_ENABLE_CLANG=1
831     CFG_DISABLE_JEMALLOC=1
832 fi
833
834 if [ -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
835 then
836     err "either clang or gcc is required"
837 fi
838
839 # OS X 10.9, gcc is actually clang. This can cause some confusion in the build
840 # system, so if we find that gcc is clang, we should just use clang directly.
841 if [ $CFG_OSTYPE = apple-darwin -a -z "$CFG_ENABLE_CLANG" ]
842 then
843     CFG_OSX_GCC_VERSION=$("$CFG_GCC" --version 2>&1 | grep "Apple LLVM version")
844     if [ $? -eq 0 ]
845     then
846         step_msg "on OS X 10.9, forcing use of clang"
847         CFG_ENABLE_CLANG=1
848     else
849         if [ $("$CFG_GCC" --version 2>&1 | grep -c ' 4\.[0-6]') -ne 0 ]; then
850             step_msg "older GCC found, using clang instead"
851             CFG_ENABLE_CLANG=1
852         else
853             # on OS X, with xcode 5 and newer, certain developers may have
854             # cc, gcc and g++ point to a  mixture of clang and gcc
855             # if so, this will create very strange build errors
856             # this last stanza is to detect some such problems and save the future rust
857             # contributor some time solving that issue.
858             # this detection could be generalized to other OSes aside from OS X
859             # but the issue seems most likely to happen on OS X
860
861             chk_cc () {
862                 $1 --version 2> /dev/null | grep -q $2
863             }
864             # check that gcc, cc and g++ all point to the same compiler.
865             # note that for xcode 5, g++ points to clang, not clang++
866             if !((chk_cc gcc clang  && chk_cc g++ clang) ||
867                 (chk_cc gcc gcc  &&( chk_cc g++ g++ || chk g++ gcc))); then
868                 err "the gcc and g++ in your path point to different compilers.
869     Check which versions are in your path with gcc --version and g++ --version.
870     To resolve this problem, either fix your PATH  or run configure with --enable-clang"
871             fi
872
873         fi
874     fi
875 fi
876
877 # Okay, at this point, we have made up our minds about whether we are
878 # going to force CFG_ENABLE_CLANG or not; save the setting if so.
879 if [ ! -z "$CFG_ENABLE_CLANG" ]
880 then
881     putvar CFG_ENABLE_CLANG
882 fi
883
884 # Same with jemalloc.  save the setting here.
885 if [ ! -z "$CFG_DISABLE_JEMALLOC" ]
886 then
887     putvar CFG_DISABLE_JEMALLOC
888 fi
889
890 if [ ! -z "$CFG_LLVM_ROOT" -a -z "$CFG_DISABLE_LLVM_VERSION_CHECK" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ]
891 then
892     step_msg "using custom LLVM at $CFG_LLVM_ROOT"
893
894     LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config"
895     LLVM_VERSION=$($LLVM_CONFIG --version)
896
897     case $LLVM_VERSION in
898         (3.[5-6]*)
899             msg "found ok version of LLVM: $LLVM_VERSION"
900             ;;
901         (*)
902             err "bad LLVM version: $LLVM_VERSION, need >=3.5"
903             ;;
904     esac
905 fi
906
907 # Even when the user overrides the choice of CC, still try to detect
908 # clang to disable some clang-specific warnings.  We here draw a
909 # distinction between:
910 #
911 #  CFG_ENABLE_CLANG : passed --enable-clang, or host "requires" clang,
912 #  CFG_USING_CLANG : compiler (clang / gcc / $CC) looks like clang.
913 #
914 # This distinction is important because there are some safeguards we
915 # would prefer to skip when merely CFG_USING_CLANG is set; but when
916 # CFG_ENABLE_CLANG is set, that indicates that we are opting into
917 # running such safeguards.
918
919 if [ ! -z "$CC" ]
920 then
921     msg "skipping compiler inference steps; using provided CC=$CC"
922     CFG_CC="$CC"
923
924     CFG_OSX_CC_VERSION=$("$CFG_CC" --version 2>&1 | grep "clang")
925     if [ $? -eq 0 ]
926     then
927         step_msg "note, user-provided CC looks like clang; CC=$CC."
928         CFG_USING_CLANG=1
929         putvar CFG_USING_CLANG
930     fi
931 else
932     if [ ! -z "$CFG_ENABLE_CLANG" ]
933     then
934         if [ -z "$CFG_CLANG" ]
935         then
936             err "clang requested but not found"
937         fi
938         CFG_CC="$CFG_CLANG"
939         CFG_USING_CLANG=1
940         putvar CFG_USING_CLANG
941     else
942         CFG_CC="gcc"
943     fi
944 fi
945
946 if [ ! -z "$CFG_ENABLE_CLANG" ]
947 then
948     if [ -z "$CC" ] || [[ $CC == *clang ]]
949     then
950         CFG_CLANG_VERSION=$($CFG_CC \
951             --version \
952             | grep version \
953             | sed 's/.*\(version .*\)/\1/; s/.*based on \(LLVM .*\))/\1/' \
954             | cut -d ' ' -f 2)
955
956         case $CFG_CLANG_VERSION in
957             (3.2* | 3.3* | 3.4* | 3.5* | 3.6*)
958             step_msg "found ok version of CLANG: $CFG_CLANG_VERSION"
959             if [ -z "$CC" ]
960             then
961                 CFG_CC="clang"
962                 CFG_CXX="clang++"
963             fi
964             ;;
965             (*)
966             err "bad CLANG version: $CFG_CLANG_VERSION, need >=3.0svn"
967             ;;
968         esac
969     else
970         msg "skipping CFG_ENABLE_CLANG version check; provided CC=$CC"
971     fi
972 fi
973
974 if [ ! -z "$CFG_ENABLE_CCACHE" ]
975 then
976     if [ -z "$CC" ]
977     then
978         if [ -z "$CFG_CCACHE" ]
979         then
980             err "ccache requested but not found"
981         fi
982
983         CFG_CC="ccache $CFG_CC"
984     fi
985 fi
986
987 if [ -z "$CC" -a -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ]
988 then
989     err "either clang or gcc is required"
990 fi
991
992 # All safeguards based on $CFG_ENABLE_CLANG should occur before this
993 # point in the script; after this point, script logic should inspect
994 # $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG.
995
996 # Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS}
997 envopt CC
998 envopt CXX
999 envopt CPP
1000 envopt CFLAGS
1001 envopt CXXFLAGS
1002
1003 # a little post-processing of various config values
1004 CFG_PREFIX=${CFG_PREFIX%/}
1005 CFG_MANDIR=${CFG_MANDIR%/}
1006 CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
1007 CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"
1008 CFG_SUPPORTED_TARGET=""
1009 for target_file in ${CFG_SRC_DIR}mk/cfg/*.mk; do
1010   CFG_SUPPORTED_TARGET="${CFG_SUPPORTED_TARGET} $(basename "$target_file" .mk)"
1011 done
1012
1013 # copy host-triples to target-triples so that hosts are a subset of targets
1014 V_TEMP=""
1015 for i in $CFG_HOST $CFG_TARGET;
1016 do
1017    echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
1018 done
1019 CFG_TARGET=$V_TEMP
1020
1021 # check target-specific tool-chains
1022 for i in $CFG_TARGET
1023 do
1024     L_CHECK=false
1025     for j in $CFG_SUPPORTED_TARGET
1026     do
1027         if [ $i = $j ]
1028         then
1029             L_CHECK=true
1030         fi
1031     done
1032
1033     if [ $L_CHECK = false ]
1034     then
1035         err "unsupported target triples \"$i\" found"
1036     fi
1037
1038     case $i in
1039         arm-linux-androideabi)
1040
1041             if [ ! -f $CFG_ANDROID_CROSS_PATH/bin/arm-linux-androideabi-gcc ]
1042             then
1043                 err "NDK $CFG_ANDROID_CROSS_PATH/bin/arm-linux-androideabi-gcc not found"
1044             fi
1045             if [ ! -f $CFG_ANDROID_CROSS_PATH/bin/arm-linux-androideabi-g++ ]
1046             then
1047                 err "NDK $CFG_ANDROID_CROSS_PATH/bin/arm-linux-androideabi-g++ not found"
1048             fi
1049             if [ ! -f $CFG_ANDROID_CROSS_PATH/bin/arm-linux-androideabi-ar ]
1050             then
1051                 err "NDK $CFG_ANDROID_CROSS_PATH/bin/arm-linux-androideabi-ar not found"
1052             fi
1053             ;;
1054
1055         arm-apple-darwin)
1056             if [ $CFG_OSTYPE != apple-darwin ]
1057             then
1058                 err "The iOS target is only supported on Mac OS X"
1059             fi
1060             ;;
1061
1062
1063         *-musl)
1064             if [ ! -f $CFG_MUSL_ROOT/lib/libc.a ]
1065             then
1066                 err "musl libc $CFG_MUSL_ROOT/lib/libc.a not found"
1067             fi
1068             ;;
1069         *)
1070             ;;
1071     esac
1072 done
1073
1074 if [ ! -z "$CFG_PERF" ]
1075 then
1076     HAVE_PERF_LOGFD=`$CFG_PERF stat --log-fd 2>&1 | grep 'unknown option'`
1077     if [ -z "$HAVE_PERF_LOGFD" ];
1078     then
1079         CFG_PERF_WITH_LOGFD=1
1080         putvar CFG_PERF_WITH_LOGFD
1081     fi
1082 fi
1083
1084 step_msg "making directories"
1085
1086 for i in \
1087     doc doc/std doc/extra \
1088     dl tmp dist
1089 do
1090     make_dir $i
1091 done
1092
1093 for t in $CFG_HOST
1094 do
1095     make_dir $t/llvm
1096 done
1097
1098 for t in $CFG_HOST
1099 do
1100     make_dir $t/rustllvm
1101 done
1102
1103 for t in $CFG_TARGET
1104 do
1105   make_dir $t/rt
1106   for s in 0 1 2 3
1107   do
1108     make_dir $t/rt/stage$s
1109     make_dir $t/rt/jemalloc
1110     for i in                                          \
1111       isaac sync test \
1112       arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips arch/powerpc
1113     do
1114       make_dir $t/rt/stage$s/$i
1115     done
1116   done
1117 done
1118
1119 for h in $CFG_HOST
1120 do
1121     for t in $CFG_TARGET
1122     do
1123         # host lib dir stage0
1124         make_dir $h/stage0/lib
1125
1126         # target bin dir stage0
1127         make_dir $h/stage0/lib/rustlib/$t/bin
1128
1129         # target lib dir stage0
1130         make_dir $h/stage0/lib/rustlib/$t/lib
1131
1132         for i in 0 1 2 3
1133         do
1134             # host bin dir
1135             make_dir $h/stage$i/bin
1136
1137             # host lib dir
1138             make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE
1139
1140             # host test dir
1141             make_dir $h/stage$i/test
1142
1143             # target bin dir
1144             make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/bin
1145
1146             # target lib dir
1147             make_dir $h/stage$i/$CFG_LIBDIR_RELATIVE/rustlib/$t/lib
1148         done
1149     done
1150
1151     make_dir $h/test/run-pass
1152     make_dir $h/test/run-pass-valgrind
1153     make_dir $h/test/run-pass-fulldeps
1154     make_dir $h/test/run-fail
1155     make_dir $h/test/run-fail-fulldeps
1156     make_dir $h/test/compile-fail
1157     make_dir $h/test/parse-fail
1158     make_dir $h/test/compile-fail-fulldeps
1159     make_dir $h/test/bench
1160     make_dir $h/test/perf
1161     make_dir $h/test/pretty
1162     make_dir $h/test/debuginfo-gdb
1163     make_dir $h/test/debuginfo-lldb
1164     make_dir $h/test/codegen
1165     make_dir $h/test/rustdoc
1166 done
1167
1168 # Configure submodules
1169 step_msg "configuring submodules"
1170
1171 # Have to be in the top of src directory for this
1172 if [ -z $CFG_DISABLE_MANAGE_SUBMODULES ]
1173 then
1174     cd ${CFG_SRC_DIR}
1175
1176     msg "git: submodule sync"
1177     "${CFG_GIT}" submodule sync
1178
1179     msg "git: submodule init"
1180     "${CFG_GIT}" submodule init
1181
1182     # Disable submodules that we're not using
1183     if [ ! -z "${CFG_LLVM_ROOT}" ]; then
1184         msg "git: submodule deinit src/llvm"
1185         "${CFG_GIT}" submodule deinit src/llvm
1186     fi
1187     if [ ! -z "${CFG_JEMALLOC_ROOT}" ]; then
1188         msg "git: submodule deinit src/jemalloc"
1189         "${CFG_GIT}" submodule deinit src/jemalloc
1190     fi
1191
1192     msg "git: submodule update"
1193     "${CFG_GIT}" submodule update
1194     need_ok "git failed"
1195
1196     msg "git: submodule foreach sync"
1197     "${CFG_GIT}" submodule foreach --recursive 'if test -e .gitmodules; then git submodule sync; fi'
1198     need_ok "git failed"
1199
1200     msg "git: submodule foreach update"
1201     "${CFG_GIT}" submodule update --recursive
1202     need_ok "git failed"
1203
1204     # NB: this is just for the sake of getting the submodule SHA1 values
1205     # and status written into the build log.
1206     msg "git: submodule status"
1207     "${CFG_GIT}" submodule status --recursive
1208
1209     msg "git: submodule clobber"
1210     "${CFG_GIT}" submodule foreach --recursive git clean -dxf
1211     need_ok "git failed"
1212     "${CFG_GIT}" submodule foreach --recursive git checkout .
1213     need_ok "git failed"
1214
1215     cd ${CFG_BUILD_DIR}
1216 fi
1217
1218 # Configure llvm, only if necessary
1219 step_msg "looking at LLVM"
1220 CFG_LLVM_SRC_DIR=${CFG_SRC_DIR}src/llvm/
1221 for t in $CFG_HOST
1222 do
1223     do_reconfigure=1
1224
1225     if [ -z $CFG_LLVM_ROOT ]
1226     then
1227         LLVM_BUILD_DIR=${CFG_BUILD_DIR}$t/llvm
1228         if [ ! -z "$CFG_DISABLE_OPTIMIZE_LLVM" ]
1229         then
1230             LLVM_DBG_OPTS="--enable-debug-symbols --disable-optimized"
1231             # Just use LLVM straight from its build directory to
1232             # avoid 'make install' time
1233             LLVM_INST_DIR=$LLVM_BUILD_DIR/Debug
1234         else
1235             LLVM_DBG_OPTS="--enable-optimized"
1236             LLVM_INST_DIR=$LLVM_BUILD_DIR/Release
1237         fi
1238         if [ -z "$CFG_ENABLE_LLVM_ASSERTIONS" ]
1239         then
1240             LLVM_ASSERTION_OPTS="--disable-assertions"
1241         else
1242             LLVM_ASSERTION_OPTS="--enable-assertions"
1243             LLVM_INST_DIR=${LLVM_INST_DIR}+Asserts
1244         fi
1245     else
1246         msg "not reconfiguring LLVM, external LLVM root"
1247         # The user is using their own LLVM
1248         LLVM_BUILD_DIR=
1249         LLVM_INST_DIR=$CFG_LLVM_ROOT
1250         do_reconfigure=0
1251     fi
1252
1253
1254     if [ ${do_reconfigure} -ne 0 ]
1255     then
1256     # because git is hilarious, it might have put the module index
1257     # in a couple places.
1258         index1="${CFG_SRC_DIR}.git/modules/src/llvm/index"
1259         index2="${CFG_SRC_DIR}src/llvm/.git/index"
1260         for index in ${index1} ${index2}
1261         do
1262             config_status="${LLVM_BUILD_DIR}/config.status"
1263             if test -e ${index} -a \
1264                     -e ${config_status} -a \
1265                     ${config_status} -nt ${index}
1266             then
1267                 msg "not reconfiguring LLVM, config.status is fresh"
1268                 do_reconfigure=0
1269             fi
1270         done
1271     fi
1272
1273     if [ ${do_reconfigure} -ne 0 ]
1274     then
1275         # LLVM's configure doesn't recognize the new Windows triples yet
1276         gnu_t=$(to_gnu_triple $t)
1277
1278         msg "configuring LLVM for $gnu_t"
1279
1280         LLVM_TARGETS="--enable-targets=x86,x86_64,arm,aarch64,mips,powerpc"
1281         LLVM_BUILD="--build=$gnu_t"
1282         LLVM_HOST="--host=$gnu_t"
1283         LLVM_TARGET="--target=$gnu_t"
1284
1285         # Disable unused LLVM features
1286         LLVM_OPTS="$LLVM_DBG_OPTS $LLVM_ASSERTION_OPTS --disable-docs --enable-bindings=none"
1287         # Disable term-info, linkage of which comes in multiple forms,
1288         # making our snapshots incompatible (#9334)
1289         LLVM_OPTS="$LLVM_OPTS --disable-terminfo"
1290         # Try to have LLVM pull in as few dependencies as possible (#9397)
1291         LLVM_OPTS="$LLVM_OPTS --disable-zlib --disable-libffi"
1292
1293         # Use win32 native thread/lock apis instead of pthread wrapper.
1294         # (llvm's configure tries to find pthread first, so we have to disable it explicitly.)
1295         # Also note that pthreads works badly on mingw-w64 systems: #8996
1296         case "$CFG_BUILD" in
1297             (*-windows-*)
1298             LLVM_OPTS="$LLVM_OPTS --disable-pthreads"
1299             ;;
1300         esac
1301
1302         case "$CFG_CC" in
1303             ("ccache clang")
1304             LLVM_CXX_32="ccache clang++ -Qunused-arguments"
1305             LLVM_CC_32="ccache clang -Qunused-arguments"
1306
1307             LLVM_CXX_64="ccache clang++ -Qunused-arguments"
1308             LLVM_CC_64="ccache clang -Qunused-arguments"
1309             ;;
1310             ("clang")
1311             LLVM_CXX_32="clang++ -Qunused-arguments"
1312             LLVM_CC_32="clang -Qunused-arguments"
1313
1314             LLVM_CXX_64="clang++ -Qunused-arguments"
1315             LLVM_CC_64="clang -Qunused-arguments"
1316             ;;
1317             ("ccache gcc")
1318             LLVM_CXX_32="ccache g++"
1319             LLVM_CC_32="ccache gcc"
1320
1321             LLVM_CXX_64="ccache g++"
1322             LLVM_CC_64="ccache gcc"
1323             ;;
1324             ("gcc")
1325             LLVM_CXX_32="g++"
1326             LLVM_CC_32="gcc"
1327
1328             LLVM_CXX_64="g++"
1329             LLVM_CC_64="gcc"
1330             ;;
1331
1332             (*)
1333             msg "inferring LLVM_CXX/CC from CXX/CC = $CXX/$CC"
1334             LLVM_CXX_32="$CXX"
1335             LLVM_CC_32="$CC"
1336
1337             LLVM_CXX_64="$CXX"
1338             LLVM_CC_64="$CC"
1339             ;;
1340         esac
1341
1342         case "$CFG_CPUTYPE" in
1343             (x86*)
1344                 LLVM_CXX_32="$LLVM_CXX_32 -m32"
1345                 LLVM_CC_32="$LLVM_CC_32 -m32"
1346
1347                 LLVM_CFLAGS_32="-m32"
1348                 LLVM_CXXFLAGS_32="-m32"
1349                 LLVM_LDFLAGS_32="-m32"
1350
1351                 LLVM_CFLAGS_64=""
1352                 LLVM_CXXFLAGS_64=""
1353                 LLVM_LDFLAGS_64=""
1354
1355                 LLVM_CXX_32="$LLVM_CXX_32 -m32"
1356                 LLVM_CC_32="$LLVM_CC_32 -m32"
1357                 ;;
1358
1359             (*)
1360                 LLVM_CFLAGS_32=""
1361                 LLVM_CXXFLAGS_32=""
1362                 LLVM_LDFLAGS_32=""
1363
1364                 LLVM_CFLAGS_64=""
1365                 LLVM_CXXFLAGS_64=""
1366                 LLVM_LDFLAGS_64=""
1367                 ;;
1368         esac
1369
1370         if echo $t | grep -q x86_64
1371         then
1372             LLVM_CXX=$LLVM_CXX_64
1373             LLVM_CC=$LLVM_CC_64
1374             LLVM_CFLAGS=$LLVM_CFLAGS_64
1375             LLVM_CXXFLAGS=$LLVM_CXXFLAGS_64
1376             LLVM_LDFLAGS=$LLVM_LDFLAGS_64
1377         else
1378             LLVM_CXX=$LLVM_CXX_32
1379             LLVM_CC=$LLVM_CC_32
1380             LLVM_CFLAGS=$LLVM_CFLAGS_32
1381             LLVM_CXXFLAGS=$LLVM_CXXFLAGS_32
1382             LLVM_LDFLAGS=$LLVM_LDFLAGS_32
1383         fi
1384
1385         CXX=$LLVM_CXX
1386         CC=$LLVM_CC
1387         CFLAGS=$LLVM_CFLAGS
1388         CXXFLAGS=$LLVM_CXXFLAGS
1389         LDFLAGS=$LLVM_LDFLAGS
1390
1391         if [ -z "$CFG_DISABLE_LIBCPP" ] && [ -n "$CFG_USING_CLANG" ]; then
1392             LLVM_OPTS="$LLVM_OPTS --enable-libcpp"
1393         fi
1394
1395         LLVM_FLAGS="$LLVM_TARGETS $LLVM_OPTS $LLVM_BUILD \
1396                         $LLVM_HOST $LLVM_TARGET --with-python=$CFG_PYTHON"
1397
1398         msg "configuring LLVM with:"
1399         msg "$LLVM_FLAGS"
1400
1401         export CXX
1402         export CC
1403         export CFLAGS
1404         export CXXFLAGS
1405         export LDFLAGS
1406
1407         cd $LLVM_BUILD_DIR
1408         case $CFG_SRC_DIR in
1409             /* | [a-z]:* | [A-Z]:*)
1410                 ${CFG_LLVM_SRC_DIR}configure $LLVM_FLAGS
1411                 ;;
1412             *)
1413                 ${CFG_BUILD_DIR}${CFG_LLVM_SRC_DIR}configure \
1414                     $LLVM_FLAGS
1415                 ;;
1416         esac
1417         need_ok "LLVM configure failed"
1418
1419         cd $CFG_BUILD_DIR
1420     fi
1421
1422     # Construct variables for LLVM build and install directories for
1423     # each target. These will be named
1424     # CFG_LLVM_BUILD_DIR_${target_triple} but all the hyphens in
1425     # target_triple will be converted to underscore, because bash
1426     # variables can't contain hyphens. The makefile will then have to
1427     # convert back.
1428     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1429     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1430     eval ${CFG_LLVM_BUILD_DIR}="'$LLVM_BUILD_DIR'"
1431     eval ${CFG_LLVM_INST_DIR}="'$LLVM_INST_DIR'"
1432 done
1433
1434
1435 step_msg "writing configuration"
1436
1437 putvar CFG_SRC_DIR
1438 putvar CFG_BUILD_DIR
1439 putvar CFG_OSTYPE
1440 putvar CFG_CPUTYPE
1441 putvar CFG_CONFIGURE_ARGS
1442 putvar CFG_PREFIX
1443 putvar CFG_HOST
1444 putvar CFG_TARGET
1445 putvar CFG_LIBDIR_RELATIVE
1446 putvar CFG_DISABLE_MANAGE_SUBMODULES
1447 putvar CFG_ANDROID_CROSS_PATH
1448 putvar CFG_MANDIR
1449
1450 # Avoid spurious warnings from clang by feeding it original source on
1451 # ccache-miss rather than preprocessed input.
1452 if [ ! -z "$CFG_ENABLE_CCACHE" ] && [ ! -z "$CFG_USING_CLANG" ]
1453 then
1454     CFG_CCACHE_CPP2=1
1455     putvar CFG_CCACHE_CPP2
1456 fi
1457
1458 if [ ! -z "$CFG_ENABLE_CCACHE" ]
1459 then
1460     CFG_CCACHE_BASEDIR=${CFG_SRC_DIR}
1461     putvar CFG_CCACHE_BASEDIR
1462 fi
1463
1464
1465 if [ ! -z $BAD_PANDOC ]
1466 then
1467     CFG_PANDOC=
1468     putvar CFG_PANDOC
1469 fi
1470
1471 putvar CFG_LLVM_SRC_DIR
1472
1473 for t in $CFG_HOST
1474 do
1475     CFG_LLVM_BUILD_DIR=$(echo CFG_LLVM_BUILD_DIR_${t} | tr - _)
1476     CFG_LLVM_INST_DIR=$(echo CFG_LLVM_INST_DIR_${t} | tr - _)
1477     putvar $CFG_LLVM_BUILD_DIR
1478     putvar $CFG_LLVM_INST_DIR
1479 done
1480
1481 # Munge any paths that appear in config.mk back to posix-y
1482 cp config.tmp config.tmp.bak
1483 sed -e 's@ \([a-zA-Z]\):[/\\]@ /\1/@g;' <config.tmp.bak >config.tmp
1484 rm -f config.tmp.bak
1485
1486 msg
1487 copy_if_changed ${CFG_SRC_DIR}Makefile.in ./Makefile
1488 move_if_changed config.tmp config.mk
1489 rm -f config.tmp
1490 touch config.stamp
1491
1492 if [ -z "$CFG_ENABLE_DEBUG" ]; then
1493     step_msg "configured in release mode. for development consider --enable-debug"
1494 else
1495     step_msg "complete"
1496 fi
1497
1498 msg "run \`make help\`"
1499 msg