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