]> git.proxmox.com Git - rustc.git/blame - configure
New upstream version 1.17.0+dfsg1
[rustc.git] / configure
CommitLineData
223e47cc
LB
1#!/bin/sh
2
7453a54e
SL
3# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/bash is.
4if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
5 POSIX_SHELL="true"
6 export POSIX_SHELL
7 exec /usr/bin/env bash $0 "$@"
8fi
9unset POSIX_SHELL # clear it so if we invoke other scripts, they run as bash as well
10
223e47cc 11msg() {
62682a34 12 echo "configure: $*"
223e47cc
LB
13}
14
15step_msg() {
16 msg
17 msg "$1"
18 msg
19}
20
21warn() {
22 echo "configure: WARNING: $1"
23}
24
25err() {
26 echo "configure: error: $1"
27 exit 1
28}
29
d9579d0f
AL
30run() {
31 msg "$@"
32 "$@"
33}
34
223e47cc
LB
35need_ok() {
36 if [ $? -ne 0 ]
37 then
1a4d82fc 38 err "$1"
223e47cc
LB
39 fi
40}
41
42need_cmd() {
1a4d82fc 43 if command -v $1 >/dev/null 2>&1
62682a34
SL
44 then msg "found program '$1'"
45 else err "program '$1' is missing, please install it"
223e47cc
LB
46 fi
47}
48
49make_dir() {
50 if [ ! -d $1 ]
51 then
d9579d0f 52 run mkdir -p $1
223e47cc
LB
53 fi
54}
55
56copy_if_changed() {
57 if cmp -s $1 $2
58 then
59 msg "leaving $2 unchanged"
60 else
d9579d0f 61 run cp -f $1 $2
223e47cc
LB
62 chmod u-w $2 # make copied artifact read-only
63 fi
64}
65
66move_if_changed() {
67 if cmp -s $1 $2
68 then
69 msg "leaving $2 unchanged"
70 else
d9579d0f 71 run mv -f $1 $2
223e47cc
LB
72 chmod u-w $2 # make moved artifact read-only
73 fi
74}
75
76putvar() {
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
1a4d82fc
JJ
89putpathvar() {
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
223e47cc
LB
107probe() {
108 local V=$1
109 shift
110 local P
111 local T
112 for P
113 do
1a4d82fc 114 T=$(command -v $P 2>&1)
223e47cc
LB
115 if [ $? -eq 0 ]
116 then
d9579d0f
AL
117 VER0=$($P --version 2>/dev/null \
118 | grep -o '[vV]\?[0-9][0-9.][a-z0-9.-]*' | head -1 )
223e47cc
LB
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
1a4d82fc 132 putpathvar $V "$VER"
223e47cc
LB
133}
134
135probe_need() {
223e47cc 136 probe $*
3157f602
XL
137 local V=$1
138 shift
223e47cc
LB
139 eval VV=\$$V
140 if [ -z "$VV" ]
141 then
3157f602 142 err "$V needed, but unable to find any of: $*"
223e47cc
LB
143 fi
144}
145
146validate_opt () {
147 for arg in $CFG_CONFIGURE_ARGS
148 do
149 isArgValid=0
150 for option in $BOOL_OPTIONS
151 do
152 if test --disable-$option = $arg
153 then
154 isArgValid=1
155 fi
156 if test --enable-$option = $arg
157 then
158 isArgValid=1
159 fi
160 done
161 for option in $VAL_OPTIONS
162 do
163 if echo "$arg" | grep -q -- "--$option="
164 then
165 isArgValid=1
166 fi
167 done
168 if [ "$arg" = "--help" ]
169 then
970d7e83 170 echo
223e47cc
LB
171 echo "No more help available for Configure options,"
172 echo "check the Wiki or join our IRC channel"
173 break
174 else
175 if test $isArgValid -eq 0
176 then
177 err "Option '$arg' is not recognized"
178 fi
179 fi
180 done
181}
182
1a4d82fc
JJ
183# `valopt OPTION_NAME DEFAULT DOC` extracts a string-valued option
184# from command line, using provided default value for the option if
185# not present, and saves it to the generated config.mk.
186#
187# `valopt_nosave` is much the same, except that it does not save the
188# result to config.mk (instead the script should use `putvar` itself
189# later on to save it). `valopt_core` is the core upon which the
190# other two are built.
191
192valopt_core() {
193 VAL_OPTIONS="$VAL_OPTIONS $2"
194
195 local SAVE=$1
196 local OP=$2
197 local DEFAULT=$3
198 shift
223e47cc
LB
199 shift
200 shift
201 local DOC="$*"
202 if [ $HELP -eq 0 ]
203 then
204 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
205 local V="CFG_${UOP}"
9346a6ac 206 local V_PROVIDED="${V}_PROVIDED"
223e47cc
LB
207 eval $V="$DEFAULT"
208 for arg in $CFG_CONFIGURE_ARGS
209 do
210 if echo "$arg" | grep -q -- "--$OP="
211 then
212 val=$(echo "$arg" | cut -f2 -d=)
213 eval $V=$val
9346a6ac 214 eval $V_PROVIDED=1
223e47cc
LB
215 fi
216 done
1a4d82fc
JJ
217 if [ "$SAVE" = "save" ]
218 then
219 putvar $V
220 fi
223e47cc
LB
221 else
222 if [ -z "$DEFAULT" ]
223 then
224 DEFAULT="<none>"
225 fi
226 OP="${OP}=[${DEFAULT}]"
227 printf " --%-30s %s\n" "$OP" "$DOC"
228 fi
229}
230
1a4d82fc
JJ
231valopt_nosave() {
232 valopt_core nosave "$@"
233}
223e47cc 234
1a4d82fc
JJ
235valopt() {
236 valopt_core save "$@"
237}
238
239# `opt OPTION_NAME DEFAULT DOC` extracts a boolean-valued option from
240# command line, using the provided default value (0/1) for the option
241# if not present, and saves it to the generated config.mk.
242#
243# `opt_nosave` is much the same, except that it does not save the
244# result to config.mk (instead the script should use `putvar` itself
245# later on to save it). `opt_core` is the core upon which the other
246# two are built.
247
248opt_core() {
249 BOOL_OPTIONS="$BOOL_OPTIONS $2"
250
251 local SAVE=$1
252 local OP=$2
253 local DEFAULT=$3
254 shift
223e47cc
LB
255 shift
256 shift
257 local DOC="$*"
258 local FLAG=""
259
260 if [ $DEFAULT -eq 0 ]
261 then
262 FLAG="enable"
9346a6ac 263 DEFAULT_FLAG="disable"
223e47cc
LB
264 else
265 FLAG="disable"
9346a6ac 266 DEFAULT_FLAG="enable"
223e47cc
LB
267 DOC="don't $DOC"
268 fi
269
270 if [ $HELP -eq 0 ]
271 then
272 for arg in $CFG_CONFIGURE_ARGS
273 do
274 if [ "$arg" = "--${FLAG}-${OP}" ]
275 then
276 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
277 FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
278 local V="CFG_${FLAG}_${OP}"
9346a6ac 279 local V_PROVIDED="CFG_${FLAG}_${OP}_PROVIDED"
223e47cc 280 eval $V=1
9346a6ac 281 eval $V_PROVIDED=1
1a4d82fc
JJ
282 if [ "$SAVE" = "save" ]
283 then
284 putvar $V
285 fi
9346a6ac
AL
286 elif [ "$arg" = "--${DEFAULT_FLAG}-${OP}" ]
287 then
288 OP=$(echo $OP | tr 'a-z-' 'A-Z_')
289 DEFAULT_FLAG=$(echo $DEFAULT_FLAG | tr 'a-z' 'A-Z')
290 local V_PROVIDED="CFG_${DEFAULT_FLAG}_${OP}_PROVIDED"
291 eval $V_PROVIDED=1
223e47cc
LB
292 fi
293 done
294 else
c1a9b12d 295 if [ -n "$META" ]
223e47cc
LB
296 then
297 OP="$OP=<$META>"
298 fi
299 printf " --%-30s %s\n" "$FLAG-$OP" "$DOC"
300 fi
301}
302
1a4d82fc
JJ
303opt_nosave() {
304 opt_core nosave "$@"
305}
306
307opt() {
308 opt_core save "$@"
309}
310
311envopt() {
312 local NAME=$1
313 local V="CFG_${NAME}"
314 eval VV=\$$V
315
316 # If configure didn't set a value already, then check environment.
317 #
318 # (It is recommended that the configure script always check the
319 # environment before setting any values to envopt variables; see
320 # e.g. how CFG_CC is handled, where it first checks `-z "$CC"`,
321 # and issues msg if it ends up employing that provided value.)
322 if [ -z "$VV" ]
323 then
324 eval $V=\$$NAME
325 eval VV=\$$V
326 fi
327
328 # If script or environment provided a value, save it.
c1a9b12d 329 if [ -n "$VV" ]
1a4d82fc
JJ
330 then
331 putvar $V
332 fi
333}
334
c1a9b12d
SL
335enable_if_not_disabled() {
336 local OP=$1
337 local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
338 local ENAB_V="CFG_ENABLE_$UOP"
339 local EXPLICITLY_DISABLED="CFG_DISABLE_${UOP}_PROVIDED"
340 eval VV=\$$EXPLICITLY_DISABLED
341 if [ -z "$VV" ]; then
342 eval $ENAB_V=1
343 fi
344}
345
1a4d82fc
JJ
346to_gnu_triple() {
347 case $1 in
348 i686-pc-windows-gnu) echo i686-w64-mingw32 ;;
349 x86_64-pc-windows-gnu) echo x86_64-w64-mingw32 ;;
350 *) echo $1 ;;
351 esac
352}
353
d9579d0f
AL
354# Prints the absolute path of a directory to stdout
355abs_path() {
356 local _path="$1"
357 # Unset CDPATH because it causes havok: it makes the destination unpredictable
358 # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null
359 # for good measure.
360 (unset CDPATH && cd "$_path" > /dev/null && pwd)
361}
362
9e0c209e
SL
363HELP=0
364for arg; do
365 case "$arg" in
366 --help) HELP=1;;
367 esac
368done
369
223e47cc
LB
370msg "looking for configure programs"
371need_cmd cmp
372need_cmd mkdir
373need_cmd printf
374need_cmd cut
375need_cmd head
376need_cmd grep
377need_cmd xargs
378need_cmd cp
379need_cmd find
380need_cmd uname
381need_cmd date
382need_cmd tr
383need_cmd sed
970d7e83 384need_cmd file
85aaf69f 385need_cmd make
223e47cc 386
d9579d0f 387CFG_SRC_DIR="$(abs_path $(dirname $0))/"
62682a34 388CFG_SRC_DIR_RELATIVE="$(dirname $0)/"
223e47cc 389CFG_BUILD_DIR="$(pwd)/"
1a4d82fc 390CFG_SELF="$0"
223e47cc
LB
391CFG_CONFIGURE_ARGS="$@"
392
92a42be0 393
7453a54e 394case "${CFG_SRC_DIR}" in
92a42be0
SL
395 *\ * )
396 err "The path to the rust source directory contains spaces, which is not supported"
397 ;;
398 *)
399 ;;
400esac
401
402
223e47cc 403OPTIONS=""
9e0c209e 404if [ "$HELP" -eq 1 ]
223e47cc 405then
970d7e83 406 echo
223e47cc 407 echo "Usage: $CFG_SELF [options]"
970d7e83 408 echo
223e47cc 409 echo "Options:"
970d7e83 410 echo
223e47cc
LB
411else
412 msg "recreating config.tmp"
413 echo '' >config.tmp
414
415 step_msg "processing $CFG_SELF args"
416fi
417
418BOOL_OPTIONS=""
419VAL_OPTIONS=""
420
d9579d0f 421opt debug 0 "debug mode; disables optimization unless \`--enable-optimize\` given"
223e47cc
LB
422opt valgrind 0 "run tests with valgrind (memcheck by default)"
423opt helgrind 0 "run tests with helgrind instead of memcheck"
1a4d82fc 424opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind"
c34b1796
AL
425opt docs 1 "build standard library documentation"
426opt compiler-docs 0 "build compiler documentation"
1a4d82fc 427opt optimize-tests 1 "build tests with optimizations"
d9579d0f 428opt debuginfo-tests 0 "build tests with debugger metadata"
c30ab7b3 429opt quiet-tests 0 "enable quieter output when running tests"
3157f602 430opt libcpp 1 "build llvm with libc++ instead of libstdc++ when using clang"
9346a6ac
AL
431opt llvm-assertions 0 "build LLVM with assertions"
432opt debug-assertions 0 "build with debugging assertions"
223e47cc 433opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
970d7e83 434opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
476ff2be 435opt sccache 0 "invoke gcc/clang via sccache to reuse object files between builds"
223e47cc 436opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
5bcae85e 437opt local-rebuild 0 "assume local-rust matches the current version, for rebuilds; implies local-rust, and is implied if local-rust already matches the current version"
1a4d82fc 438opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
476ff2be 439opt llvm-link-shared 0 "prefer shared linking to LLVM (llvm-config --link-shared)"
8bb4bdeb 440opt llvm-clean-rebuild 0 "delete LLVM build directory on rebuild"
9cc50fc6 441opt rpath 1 "build rpaths into rustc itself"
b039eaaf 442opt stage0-landing-pads 1 "enable landing pads during bootstrap with stage0"
1a4d82fc
JJ
443# This is used by the automation to produce single-target nightlies
444opt dist-host-only 0 "only install bins for the host architecture"
445opt inject-std-version 1 "inject the current compiler version of libstd into programs"
62682a34 446opt llvm-version-check 1 "check if the LLVM version is supported, build anyway"
54a0048b 447opt codegen-tests 1 "run the src/test/codegen tests"
a7813a04 448opt option-checking 1 "complain about unrecognized options in this configure script"
5bcae85e 449opt ninja 0 "build LLVM using the Ninja generator (for MSVC, requires building in the correct environment)"
8bb4bdeb 450opt locked-deps 0 "force Cargo.lock to be up to date"
476ff2be 451opt vendor 0 "enable usage of vendored Rust crates"
8bb4bdeb
XL
452opt sanitizers 0 "build the sanitizer runtimes (asan, lsan, msan, tsan)"
453opt dist-src 1 "when building tarballs enables building a source tarball"
454opt cargo-openssl-static 0 "static openssl in cargo"
1a4d82fc 455
9346a6ac
AL
456# Optimization and debugging options. These may be overridden by the release channel, etc.
457opt_nosave optimize 1 "build optimized rust code"
458opt_nosave optimize-cxx 1 "build optimized C++ code"
459opt_nosave optimize-llvm 1 "build optimized LLVM"
460opt_nosave llvm-assertions 0 "build LLVM with assertions"
461opt_nosave debug-assertions 0 "build with debugging assertions"
476ff2be 462opt_nosave llvm-release-debuginfo 0 "build LLVM with debugger metadata"
9346a6ac 463opt_nosave debuginfo 0 "build with debugger metadata"
c30ab7b3 464opt_nosave debuginfo-lines 0 "build with line number debugger metadata"
476ff2be 465opt_nosave debuginfo-only-std 0 "build only libstd with debugging information"
9346a6ac
AL
466opt_nosave debug-jemalloc 0 "build jemalloc with --enable-debug --enable-fill"
467
1a4d82fc
JJ
468valopt localstatedir "/var/lib" "local state directory"
469valopt sysconfdir "/etc" "install system configuration files"
470
471valopt datadir "${CFG_PREFIX}/share" "install data"
472valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
223e47cc 473valopt llvm-root "" "set LLVM root"
62682a34 474valopt python "" "set path to python"
1a4d82fc 475valopt jemalloc-root "" "set directory where libjemalloc_pic.a is located"
8bb4bdeb 476valopt build "" "GNUs ./configure syntax LLVM build triple"
7453a54e 477valopt android-cross-path "" "Android NDK standalone path (deprecated)"
e9174d1e 478valopt i686-linux-android-ndk "" "i686-linux-android NDK standalone path"
c1a9b12d 479valopt arm-linux-androideabi-ndk "" "arm-linux-androideabi NDK standalone path"
a7813a04 480valopt armv7-linux-androideabi-ndk "" "armv7-linux-androideabi NDK standalone path"
c1a9b12d 481valopt aarch64-linux-android-ndk "" "aarch64-linux-android NDK standalone path"
9cc50fc6 482valopt nacl-cross-path "" "NaCl SDK path (Pepper Canary is recommended). Must be absolute!"
c30ab7b3 483valopt musl-root "/usr/local" "MUSL root installation directory (deprecated)"
476ff2be
SL
484valopt musl-root-x86_64 "" "x86_64-unknown-linux-musl install directory"
485valopt musl-root-i686 "" "i686-unknown-linux-musl install directory"
486valopt musl-root-arm "" "arm-unknown-linux-musleabi install directory"
487valopt musl-root-armhf "" "arm-unknown-linux-musleabihf install directory"
488valopt musl-root-armv7 "" "armv7-unknown-linux-musleabihf install directory"
9cc50fc6 489valopt extra-filename "" "Additional data that is hashed and passed to the -C extra-filename flag"
8bb4bdeb 490valopt qemu-armhf-rootfs "" "rootfs in qemu testing, you probably don't want to use this"
223e47cc 491
5bcae85e
SL
492if [ -e ${CFG_SRC_DIR}.git ]
493then
494 valopt release-channel "dev" "the name of the release channel to build"
495else
496 # If we have no git directory then we are probably a tarball distribution
497 # and should default to stable channel - Issue 28322
498 probe CFG_GIT git
499 msg "git: no git directory. Changing default release channel to stable"
500 valopt release-channel "stable" "the name of the release channel to build"
501fi
502
e9174d1e
SL
503# Used on systems where "cc" and "ar" are unavailable
504valopt default-linker "cc" "the default linker"
505valopt default-ar "ar" "the default ar"
506
1a4d82fc
JJ
507# Many of these are saved below during the "writing configuration" step
508# (others are conditionally saved).
509opt_nosave manage-submodules 1 "let the build manage the git submodules"
510opt_nosave clang 0 "prefer clang to gcc for building the runtime"
9346a6ac 511opt_nosave jemalloc 1 "build liballoc with jemalloc"
d9579d0f 512opt elf-tls 1 "elf thread local storage on platforms where supported"
32a655c1
SL
513opt full-bootstrap 0 "build three compilers instead of two"
514opt extended 0 "build an extended rust tool set"
1a4d82fc
JJ
515
516valopt_nosave prefix "/usr/local" "set installation prefix"
517valopt_nosave local-rust-root "/usr/local" "set prefix for local rust binary"
518valopt_nosave host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
519valopt_nosave target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"
520valopt_nosave mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
9e0c209e 521valopt_nosave docdir "${CFG_PREFIX}/share/doc/rust" "install documentation in PATH"
1a4d82fc 522
92a42be0
SL
523# On Windows this determines root of the subtree for target libraries.
524# Host runtime libs always go to 'bin'.
525valopt libdir "${CFG_PREFIX}/lib" "install libraries"
1a4d82fc
JJ
526
527case "$CFG_LIBDIR" in
528 "$CFG_PREFIX"/*) CAT_INC=2;;
529 "$CFG_PREFIX"*) CAT_INC=1;;
530 *)
531 err "libdir must begin with the prefix. Use --prefix to set it accordingly.";;
532esac
533
534CFG_LIBDIR_RELATIVE=`echo ${CFG_LIBDIR} | cut -c$((${#CFG_PREFIX}+${CAT_INC}))-`
535
223e47cc
LB
536if [ $HELP -eq 1 ]
537then
970d7e83 538 echo
223e47cc
LB
539 exit 0
540fi
541
1a4d82fc 542# Validate Options
a7813a04
XL
543if [ -z "$CFG_DISABLE_OPTION_CHECKING" ]
544then
545 step_msg "validating $CFG_SELF args"
546 validate_opt
547fi
1a4d82fc 548
9346a6ac 549# Validate the release channel, and configure options
1a4d82fc 550case "$CFG_RELEASE_CHANNEL" in
9346a6ac
AL
551 nightly )
552 msg "overriding settings for $CFG_RELEASE_CHANNEL"
32a655c1 553 enable_if_not_disabled llvm-assertions
476ff2be
SL
554 # FIXME(stage0) re-enable this on the next stage0 now that #35566 is
555 # fixed
c30ab7b3
SL
556 case "$CFG_BUILD" in
557 *-pc-windows-gnu)
558 ;;
559 *)
476ff2be
SL
560 CFG_ENABLE_DEBUGINFO_LINES=1
561 CFG_ENABLE_DEBUGINFO_ONLY_STD=1
c30ab7b3
SL
562 ;;
563 esac
476ff2be 564
1a4d82fc 565 ;;
c30ab7b3
SL
566 beta | stable)
567 msg "overriding settings for $CFG_RELEASE_CHANNEL"
568 case "$CFG_BUILD" in
569 *-pc-windows-gnu)
570 ;;
571 *)
476ff2be
SL
572 CFG_ENABLE_DEBUGINFO_LINES=1
573 CFG_ENABLE_DEBUGINFO_ONLY_STD=1
c30ab7b3
SL
574 ;;
575 esac
576 ;;
577 dev)
9346a6ac
AL
578 ;;
579 *)
1a4d82fc
JJ
580 err "release channel must be 'dev', 'nightly', 'beta' or 'stable'"
581 ;;
582esac
583
9346a6ac
AL
584# Adjust perf and debug options for debug mode
585if [ -n "$CFG_ENABLE_DEBUG" ]; then
586 msg "debug mode enabled, setting performance options"
587 if [ -z "$CFG_ENABLE_OPTIMIZE_PROVIDED" ]; then
588 msg "optimization not explicitly enabled, disabling optimization"
589 CFG_DISABLE_OPTIMIZE=1
590 CFG_DISABLE_OPTIMIZE_CXX=1
591 fi
c1a9b12d
SL
592
593 # Set following variables to 1 unless setting already provided
594 enable_if_not_disabled debug-assertions
595 enable_if_not_disabled debug-jemalloc
596 enable_if_not_disabled debuginfo
597 enable_if_not_disabled llvm-assertions
1a4d82fc 598fi
9346a6ac
AL
599
600# OK, now write the debugging options
601if [ -n "$CFG_DISABLE_OPTIMIZE" ]; then putvar CFG_DISABLE_OPTIMIZE; fi
602if [ -n "$CFG_DISABLE_OPTIMIZE_CXX" ]; then putvar CFG_DISABLE_OPTIMIZE_CXX; fi
603if [ -n "$CFG_DISABLE_OPTIMIZE_LLVM" ]; then putvar CFG_DISABLE_OPTIMIZE_LLVM; fi
604if [ -n "$CFG_ENABLE_LLVM_ASSERTIONS" ]; then putvar CFG_ENABLE_LLVM_ASSERTIONS; fi
605if [ -n "$CFG_ENABLE_DEBUG_ASSERTIONS" ]; then putvar CFG_ENABLE_DEBUG_ASSERTIONS; fi
476ff2be 606if [ -n "$CFG_ENABLE_LLVM_RELEASE_DEBUGINFO" ]; then putvar CFG_ENABLE_LLVM_RELEASE_DEBUGINFO; fi
9346a6ac 607if [ -n "$CFG_ENABLE_DEBUGINFO" ]; then putvar CFG_ENABLE_DEBUGINFO; fi
c30ab7b3 608if [ -n "$CFG_ENABLE_DEBUGINFO_LINES" ]; then putvar CFG_ENABLE_DEBUGINFO_LINES; fi
476ff2be 609if [ -n "$CFG_ENABLE_DEBUGINFO_ONLY_STD" ]; then putvar CFG_ENABLE_DEBUGINFO_ONLY_STD; fi
9346a6ac 610if [ -n "$CFG_ENABLE_DEBUG_JEMALLOC" ]; then putvar CFG_ENABLE_DEBUG_JEMALLOC; fi
1a4d82fc 611
223e47cc
LB
612step_msg "looking for build programs"
613
3157f602 614probe_need CFG_CURL curl
62682a34 615if [ -z "$CFG_PYTHON_PROVIDED" ]; then
7453a54e 616 probe_need CFG_PYTHON python2.7 python2 python
62682a34 617fi
223e47cc
LB
618
619python_version=$($CFG_PYTHON -V 2>&1)
7453a54e
SL
620if [ $(echo $python_version | grep -c '^Python 2\.7') -ne 1 ]; then
621 err "Found $python_version, but Python 2.7 is required"
223e47cc
LB
622fi
623
d9579d0f
AL
624# the valgrind rpass tests will fail if you don't have a valgrind, but they're
625# only disabled if you opt out.
626if [ -z "$CFG_VALGRIND" ]
627then
628 # If the user has explicitly asked for valgrind tests, then fail
629 if [ -n "$CFG_ENABLE_VALGRIND" ] && [ -n "$CFG_ENABLE_VALGRIND_PROVIDED" ]
630 then
631 err "No valgrind present, but valgrind tests explicitly requested"
632 else
633 CFG_DISABLE_VALGRIND_RPASS=1
634 putvar CFG_DISABLE_VALGRIND_RPASS
635 fi
636fi
637
32a655c1
SL
638# Do some sanity checks if running on buildbot
639# (these env vars are set by rust-buildbot)
640if [ -n "$RUST_DIST_SERVER" -a -n "$ALLOW_NONZERO_RLIMIT_CORE" ]; then
641 # Frequently the llvm submodule directory is broken by the build
642 # being killed
643 llvm_lock="${CFG_SRC_DIR}/.git/modules/src/llvm/index.lock"
644 if [ -e "$llvm_lock" ]; then
645 step_msg "removing $llvm_lock"
646 rm -f "$llvm_lock"
647 fi
648fi
649
1a4d82fc 650BIN_SUF=
62682a34 651if [ "$CFG_OSTYPE" = "pc-windows-gnu" ] || [ "$CFG_OSTYPE" = "pc-windows-msvc" ]
223e47cc 652then
1a4d82fc 653 BIN_SUF=.exe
223e47cc
LB
654fi
655
3157f602
XL
656# --enable-local-rebuild implies --enable-local-rust too
657if [ -n "$CFG_ENABLE_LOCAL_REBUILD" ]
658then
659 if [ -z "$CFG_ENABLE_LOCAL_RUST" ]
660 then
661 CFG_ENABLE_LOCAL_RUST=1
662 putvar CFG_ENABLE_LOCAL_RUST
663 fi
664fi
665
c1a9b12d 666if [ -n "$CFG_ENABLE_LOCAL_RUST" ]
223e47cc 667then
1a4d82fc
JJ
668 system_rustc=$(which rustc)
669 if [ -f ${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF} ]
223e47cc 670 then
1a4d82fc
JJ
671 : # everything already configured
672 elif [ -n "$system_rustc" ]
673 then
674 # we assume that rustc is in a /bin directory
675 CFG_LOCAL_RUST_ROOT=${system_rustc%/bin/rustc}
223e47cc 676 else
1a4d82fc 677 err "no local rust to use"
223e47cc 678 fi
1a4d82fc
JJ
679
680 CMD="${CFG_LOCAL_RUST_ROOT}/bin/rustc${BIN_SUF}"
9e0c209e 681 LRV=`LD_LIBRARY_PATH=${CFG_LOCAL_RUST_ROOT}/lib $CMD --version`
1a4d82fc
JJ
682 if [ $? -ne 0 ]
683 then
684 step_msg "failure while running $CMD --version"
685 exit 1
686 fi
687 step_msg "using rustc at: ${CFG_LOCAL_RUST_ROOT} with version: $LRV"
688 putvar CFG_LOCAL_RUST_ROOT
223e47cc
LB
689fi
690
9346a6ac 691# Same with jemalloc. save the setting here.
c1a9b12d 692if [ -n "$CFG_DISABLE_JEMALLOC" ]
9346a6ac
AL
693then
694 putvar CFG_DISABLE_JEMALLOC
695fi
696
1a4d82fc
JJ
697# All safeguards based on $CFG_ENABLE_CLANG should occur before this
698# point in the script; after this point, script logic should inspect
699# $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG.
700
92a42be0 701# Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS,LDFLAGS}
1a4d82fc
JJ
702envopt CC
703envopt CXX
704envopt CPP
705envopt CFLAGS
706envopt CXXFLAGS
92a42be0 707envopt LDFLAGS
223e47cc 708
1a4d82fc 709# a little post-processing of various config values
223e47cc 710CFG_PREFIX=${CFG_PREFIX%/}
1a4d82fc 711CFG_MANDIR=${CFG_MANDIR%/}
9e0c209e 712CFG_DOCDIR=${CFG_DOCDIR%/}
1a4d82fc
JJ
713CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
714CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"
223e47cc 715
c1a9b12d
SL
716# copy build-triples to host-triples so that builds are a subset of hosts
717V_TEMP=""
718for i in $CFG_BUILD $CFG_HOST;
719do
720 echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
721done
722CFG_HOST=$V_TEMP
723
223e47cc
LB
724# copy host-triples to target-triples so that hosts are a subset of targets
725V_TEMP=""
1a4d82fc 726for i in $CFG_HOST $CFG_TARGET;
223e47cc
LB
727do
728 echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
729done
1a4d82fc 730CFG_TARGET=$V_TEMP
223e47cc 731
223e47cc
LB
732step_msg "writing configuration"
733
734putvar CFG_SRC_DIR
62682a34 735putvar CFG_SRC_DIR_RELATIVE
223e47cc
LB
736putvar CFG_BUILD_DIR
737putvar CFG_OSTYPE
738putvar CFG_CPUTYPE
739putvar CFG_CONFIGURE_ARGS
740putvar CFG_PREFIX
1a4d82fc
JJ
741putvar CFG_HOST
742putvar CFG_TARGET
743putvar CFG_LIBDIR_RELATIVE
223e47cc 744putvar CFG_DISABLE_MANAGE_SUBMODULES
c1a9b12d
SL
745putvar CFG_AARCH64_LINUX_ANDROID_NDK
746putvar CFG_ARM_LINUX_ANDROIDEABI_NDK
a7813a04 747putvar CFG_ARMV7_LINUX_ANDROIDEABI_NDK
e9174d1e 748putvar CFG_I686_LINUX_ANDROID_NDK
9cc50fc6 749putvar CFG_NACL_CROSS_PATH
1a4d82fc 750putvar CFG_MANDIR
9e0c209e 751putvar CFG_DOCDIR
9cc50fc6 752putvar CFG_USING_LIBCPP
223e47cc 753
223e47cc 754msg
8bb4bdeb 755copy_if_changed ${CFG_SRC_DIR}src/bootstrap/mk/Makefile.in ./Makefile
223e47cc
LB
756move_if_changed config.tmp config.mk
757rm -f config.tmp
758touch config.stamp
759
9346a6ac
AL
760if [ -z "$CFG_ENABLE_DEBUG" ]; then
761 step_msg "configured in release mode. for development consider --enable-debug"
762else
763 step_msg "complete"
764fi
765
476ff2be
SL
766if [ "$CFG_SRC_DIR" = `pwd` ]; then
767 X_PY=x.py
768else
769 X_PY=${CFG_SRC_DIR_RELATIVE}x.py
770fi
771
8bb4bdeb 772msg "run \`python ${X_PY} --help\`"
1a4d82fc 773msg