1#! /bin/sh
2#
3# %CopyrightBegin%
4#
5# Copyright Ericsson AB 2002-2014. All Rights Reserved.
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11#     http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19# %CopyrightEnd%
20#
21
22USE_AUTOCONF_VERSION=2.69
23
24aclocal_dirs="make ./lib/crypto ./lib/erl_interface ./lib/odbc ./lib/wx ./lib/megaco"
25autoconf_aux_dirs="./lib/common_test/priv/auxdir ./lib/erl_interface/src/auxdir ./lib/common_test/test_server ./lib/wx/autoconf"
26
27aclocal_master="./erts/aclocal.m4"
28install_sh_master="./erts/autoconf/install-sh"
29config_guess_master="./erts/autoconf/config.guess"
30config_sub_master="./erts/autoconf/config.sub"
31
32# Global configuration variables
33#
34if [ -z "$ONLY_ERTS" ]; then
35    AUTOCONF_SUBDIRS="lib lib/* lib/common_test/test_server"
36fi
37AUTOCONF_SUBDIRS="$AUTOCONF_SUBDIRS make erts"
38
39# `bootstrap_apps' should include application that are built, or
40# partly built in one of the bootstrap phases. Applications that
41# only get some static includes copied into the bootstrap directory
42# should not be included.
43bootstrap_apps="erts lib/asn1 lib/compiler lib/erl_interface lib/kernel lib/jinterface lib/parsetools lib/sasl lib/snmp lib/stdlib lib/syntax_tools lib/wx"
44
45# We will quote a bit more than needed, but the important thing is that
46# all that needs quoting will be quoted...
47DONT_QUOTE="A-Za-z0-9~/=_+-"
48
49# Utility functions
50usage ()
51{
52    echo "Available commands:"
53    echo "    setup [-a|-s|-t] [<configure parameters>] - does autoconf, configure and boot"
54    echo "    all [-a|-s|-t] <dir> - does autoconf, configure, boot, release"
55    echo "    autoconf - (re)build the configure scripts"
56    echo "    configure [<configure parameters>] - does the actual configuration"
57    echo "    boot [-a|-s|-t] - bootstraps and builds the system (after configure)"
58    echo "    release <target_dir> - creates a small release to <target_dir>"
59    echo "    release [-a|-s|-t] <target_dir> - creates full release to <target_dir>"
60    echo "    tests <dir> - Build testsuites to <dir>"
61    echo ""
62    echo "-a builds all applications"
63    echo "-s builds a small system (default)"
64    echo "-t builds a tiny system"
65    echo ""
66    echo "These are for cleaning up an open source distribution"
67    echo "with prebuilt files, so that it resembles the clean developers"
68    echo "codebase:"
69    echo "    remove_prebuilt_files - create a minimal source tree"
70    echo "    save_bootstrap - recreate primary bootstrap"
71    echo ""
72    echo "Special targets for Windows(tm) build:"
73    echo "    debuginfo_win32 <dir> - adds debug emulator and pdb files to <dir>"
74    echo "    installer_win32 <dir> - creates a windows installer from <dir>"
75    echo ""
76    echo "Before trying to build on windows, consider the following option"
77    echo "    env_win32 [<arch>] - echo environment settings for win32 with visual C++, use with eval"
78    echo "                         The optional <arch> can be x64 for 64bit Windows"
79    echo "                         or x86 for 32bit Windows"
80    echo "    env_win64 - echo environment settings for win32 with visual C++, use with eval"
81    echo "                Note that env_win32 x64 gives the same result, Windows 64bit"
82    echo ""
83    echo "update_primary [--no-commit]      - build and maybe commit a new primary bootstrap"
84    echo "update_preloaded [--no-commit]    - build and maybe commit the preloaded modules"
85    echo "update_deprecations [--no-commit] - build and maybe commit deprecations"
86    echo "update_configure [--no-commit]    - build and maybe commit configure scripts"
87}
88
89hide_vars ()
90{
91    script=
92    for var in "$@"; do
93	if [ "X$var" != "X" ]; then
94	    script="$script test \"X\$$var\" = \"X\" || hidden_$var=\$$var; unset $var;"
95	fi
96    done
97    if [ "X$script" != "X" ]; then
98	eval "$script"
99    fi
100    unset script
101}
102
103restore_vars ()
104{
105    script=
106    for var in "$@"; do
107	if [ "X$var" != "X" ]; then
108	    script="$script unset $var; test \"X\$hidden_$var\" = \"X\" || { $var=\$hidden_$var; export $var; } ; unset hidden_$var;"
109	fi
110    done
111    if [ "X$script" != "X" ]; then
112	eval "$script"
113    fi
114    unset script
115}
116
117
118check_erltop ()
119{
120        ERLTOP_FORCED=false
121	if [ "X$ERL_TOP" = "X" ]; then
122		if [ -f ./otp_build -a -f ./erts/autoconf/config.guess ]; then
123		    ERLTOP_FORCED=true
124		    ERL_TOP=`pwd`
125		    export ERL_TOP
126		else
127		    echo "The environment variable ERL_TOP must be set." >&2
128		    exit 1
129		fi
130	fi
131}
132
133target_contains ()
134{
135	Y=`echo $TARGET | sed "s,$1,,g"`
136	[ X"$Y" != X"$TARGET" ]
137	return $?
138}
139
140determine_version_controller ()
141{
142    version_controller=none
143
144    # The current directory is now $ERL_TOP. Find out whether
145    # this directory is a git repository.
146
147    if { git rev-parse --git-dir; } 2>/dev/null >/dev/null; then
148	version_controller=git
149    fi
150}
151# Execution of the different options
152
153# Special static config flags for certain platforms are set here
154set_config_flags ()
155{
156	#
157	# NOTE! Do not add special flags here without a *very good*
158	#       reason. We normally do not want "./otp_build configure"
159	#       and "./configure" to produce different results.
160	#       However, in the Windows case this does not matter, since
161	#       the only supported way to build on Windows is using
162	#       otp_build.
163	#
164	# * Extra flags to pass to configure are placed in `CONFIG_FLAGS'.
165	# * The command line is no longer added to `CONFIG_FLAGS' by
166	#   `set_config_flags'. It is instead passed directly to
167	#   `run_configure', or added to `CONFIG_FLAGS' at some other
168	#   place.
169	# * `CONFIG_FLAGS' may contain flags when `set_config_flags' is
170	#   called. These flags should survive the call to `set_config_flags'
171	#   (in the cross compilation case the whole command line as well as
172	#   the cross configuration have been moved here).
173
174	if target_contains free_source; then
175		CONFIG_FLAGS="$CONFIG_FLAGS --host=$TARGET"
176	fi
177	if target_contains win32; then
178	    CONFIG_FLAGS="--build=$BUILDSYS build_alias=win32 --host=win32 --target=win32 $CONFIG_FLAGS"
179	fi
180
181
182	if [ "x$OVERRIDE_CONFIG_CACHE" = "x" ]; then
183	    CONFIG_FLAGS="$CONFIG_FLAGS --cache-file=/dev/null"
184	else
185	   CONFIG_FLAGS="$CONFIG_FLAGS --cache-file=$OVERRIDE_CONFIG_CACHE"
186	fi
187
188	env_to_config_flags $erl_build_tool_vars
189
190	export CONFIG_FLAGS;
191}
192
193NL="\
194"
195
196do_update_configure ()
197{
198    get_do_commit $1
199
200    ac_ver_blob=`autoconf --version`
201    if [ $? -ne 0 ]; then
202	echo "ERROR: Failed to check autoconf version! You need to have autoconf of version $USE_AUTOCONF_VERSION in path." 1>&2
203	exit 1
204    fi
205    ac_ver=`echo $ac_ver_blob | sed "s|[^0-9]*\([0-9][^ \t\n]*\).*|\1|"`
206    case $ac_ver in
207	$USE_AUTOCONF_VERSION)
208	    ;;
209	*)
210	    echo "ERROR: autoconf of version $ac_ver found in path! You need to have autoconf of version $USE_AUTOCONF_VERSION in path." 1>&2
211	    exit 1;;
212    esac
213
214    out_files=
215
216    for dir in $aclocal_dirs; do
217	$install_sh_master -m 644 -t "$dir" "$aclocal_master"
218    done
219
220    install_sh=`basename $install_sh_master`
221    config_guess=`basename $config_guess_master`
222    config_sub=`basename $config_sub_master`
223
224    for dir in $autoconf_aux_dirs; do
225	$install_sh_master -d "$dir"
226	$install_sh_master -t "$dir" "$install_sh_master"
227	out_files="$out_files $dir/$install_sh"
228	$install_sh_master -t "$dir" "$config_guess_master"
229	out_files="$out_files $dir/$config_guess"
230	$install_sh_master -t "$dir" "$config_sub_master"
231	out_files="$out_files $dir/$config_sub"
232    done
233
234    hide_vars OVERRIDE_TARGET TARGET
235    TARGET=$BUILDSYS
236    export TARGET
237
238    for d in $AUTOCONF_SUBDIRS; do
239	file="$d/configure.in"
240	[ -f "$file" ] || continue
241	echo ""
242	[ ! -d "$d/autom4te.cache" ] || {
243	    echo "=== cleaning $d/autom4te.cache"
244	    rm -f "$d"/autom4te.cache/*
245	}
246	[ ! -f "$d/configure" ] || {
247	    echo "=== cleaning $d/configure"
248	    rm -f "$d"/configure
249	}
250
251	echo "=== running autoconf in $d"
252	( cd "$d" && autoconf ) || exit 1
253	out_files="$out_files $d/configure"
254	chdr=`cat "$file" | sed -n "s|.*\(AC_CONFIG_HEADER\).*|\1|p"`
255	[ "$chdr" = "AC_CONFIG_HEADER" ] || continue
256	echo "=== running autoheader in $d"
257	( cd "$d" && autoheader ) || exit 1
258	out_files="$out_files $d/config.h.in"
259    done
260
261    echo ""
262    echo "=== creating ./configure"
263    bootstrap_lib_apps=`echo $bootstrap_apps | sed "s|erts||g"`
264    cat "$ERL_TOP/configure.src" \
265	| sed "s|@BOOTSTRAP_LIB_APP_DIRS@|$bootstrap_lib_apps|g" \
266	      > "$ERL_TOP/configure"
267    chmod +x "$ERL_TOP/configure"
268    out_files="./configure $out_files"
269
270    restore_vars OVERRIDE_TARGET TARGET
271
272    if [ $do_commit != true ]; then
273	echo "Updated: $out_files"
274    else
275	git add $out_files
276	if [ $? -ne 0 ]; then
277	    echo "Failed to stage files for commit" 1>&2
278	    exit 1
279	fi
280	git diff --cached --quiet
281	if [ $? -eq 0 ]; then
282	    echo "No files changed, so nothing to commit."
283	else
284            git commit --no-verify -m 'Update configure scripts'
285	    if [ $? -ne 0 ]; then
286		echo "Failed to commit files" 1>&2
287		exit 1
288	    fi
289	    echo "Updated configure scripts!"
290	fi
291    fi
292}
293
294run_configure ()
295{
296    cdir="$ERL_TOP"
297    [ -z "$ONLY_ERTS" ] || {
298	cdir="$ERL_TOP/erts"
299	CONFIG_FLAGS="$CONFIG_FLAGS --no-recursion"
300    }
301
302    echo "$cdir/configure $CONFIG_FLAGS" ${1+"$@"}
303    (cd "$cdir" && $config_eval ./configure $CONFIG_FLAGS ${1+"$@"}) || exit 1
304}
305
306env_to_config_flags ()
307{
308    for env_var in "$@"; do
309	script="echo $env_var=\$$env_var; unset $env_var >/dev/null 2>&1"
310	env_arg=`eval $script`
311	case $env_arg in
312	    "$env_var=")
313		;;
314	    *[!$DONT_QUOTE]*)
315		config_eval=eval
316		new_arg=`echo "X$env_arg" | sed "s|^X||;s|\([^$DONT_QUOTE]\)|\\\\\\\\\1|g"`
317		CONFIG_FLAGS="$CONFIG_FLAGS $new_arg";;
318	    *)
319		CONFIG_FLAGS="$CONFIG_FLAGS $env_arg";;
320	esac
321	eval unset $env_var
322    done
323}
324
325try_cross_configure ()
326{
327    cross_configure=no
328    host_value=
329    build_value=
330
331    # Get `erl_xcomp_vars'
332    . "$ERL_TOP/xcomp/erl-xcomp-vars.sh" || exit 1
333
334    for arg in ${1+"$@"}; do
335	case "$arg" in
336	    --host=*)
337		host_value=`echo $x | sed "s|^--host=\(.*\)|\1|"`;;
338	    --build=*)
339		build_value=`echo $x | sed "s|^--build=\(.*\)|\1|"`;;
340	    --xcomp-conf=*)
341		cross_configure=yes;;
342	    *)
343		;;
344	esac
345    done
346
347    test $cross_configure = yes || {
348
349	test "X$host_value" = "X" || {
350
351	    test "X$build_value" != "X" || build_value="$BUILDSYS"
352
353	    build_sys=`"$ERL_TOP/erts/autoconf/config.sub" "$build_value"` || exit 1
354	    host_sys=`"$ERL_TOP/erts/autoconf/config.sub" "$host_value"` || exit 1
355
356
357	    test "$host_sys" = "$build_sys" || cross_configure=yes
358	}
359    }
360
361    test $cross_configure = yes || return 1
362
363    # cross configure...
364    CONFIG_FLAGS=
365
366    env_to_config_flags $erl_build_tool_vars $erl_xcomp_vars
367
368    for arg in ${1+"$@"}; do
369	case "$arg" in
370	    --host=*)
371		host_value=`echo $x | sed "s|^--host=\(.*\)|\1|"`;;
372	    --build=*)
373		build_value=`echo $x | sed "s|^--build=\(.*\)|\1|"`;;
374	    --xcomp-conf=*)
375		# tilde expansion is not handled by the `configure' script,
376		# but we do it for this argument. This argument is however not
377		# a `configure' argument.
378	        xcomp_conf=`echo "X$arg" | sed "s|^X--xcomp-conf=\(.*\)\$|\1|g;s|\([^$DONT_QUOTE]\)|\\\\\\\\\1|g"`
379		eval "xcomp_conf=$xcomp_conf"
380		test "X$xcomp_conf" != "X" || {
381		    echo "$0: Missing xcomp-conf file name"
382		    exit 1
383		}
384		test -f "$xcomp_conf" || {
385		    echo "$0: Missing xcomp-conf file: $xcomp_conf"
386		    exit 1
387		}
388		. "$xcomp_conf"
389		test $? -eq 0 || {
390		    echo "$0: Failed to read xcomp-conf file: $xcomp_conf"
391		    exit 1
392		}
393		test "X$erl_xcomp_build" = "X" || build_value="$erl_xcomp_build"
394		test "X$erl_xcomp_host" = "X" || host_value="$erl_xcomp_host"
395		unset erl_xcomp_build
396		unset erl_xcomp_host
397		CONFIG_FLAGS="$CONFIG_FLAGS $erl_xcomp_configure_flags"
398		unset erl_xcomp_configure_flags
399		env_to_config_flags $erl_build_tool_vars $erl_xcomp_vars;;
400	    *[!$DONT_QUOTE]*)
401		config_eval=eval
402	        new_arg=`echo "X$arg" | sed "s|^X||;s|\([^$DONT_QUOTE]\)|\\\\\\\\\1|g"`
403		CONFIG_FLAGS="$CONFIG_FLAGS $new_arg";;
404	    *)
405		CONFIG_FLAGS="$CONFIG_FLAGS $arg";;
406	esac
407    done
408
409    CONFIG_FLAGS="--host=$host_value $CONFIG_FLAGS"
410    test "X$build_value" != "Xguess" || build_value="$BUILDSYS"
411    test "X$build_value" = "X" || CONFIG_FLAGS="--build=$build_value $CONFIG_FLAGS"
412
413    # Configure build system for boot strap
414    cat <<EOF
415
416*
417* Configuring the bootstrap build system...
418*
419
420EOF
421
422    # hide build tools environment which is for the cross configure
423    set_config_flags $CONFIG_FLAGS
424    hide_vars CONFIG_FLAGS
425
426    set_config_flags
427    run_configure --enable-bootstrap-only
428
429    # restore the hidden build tools environment for the cross configure
430    restore_vars CONFIG_FLAGS
431
432    COMPFIX=""
433    cat <<EOF
434
435*
436* Configuring the cross host system ($host_value)...
437*
438
439EOF
440    # We don't pass the command line here since we already have moved it
441    # into CONFIG_FLAGS
442    run_configure
443
444    return 0
445}
446
447maybe_copy_static_cache ()
448{
449    if [ '!' -z "$OVERRIDE_CONFIG_CACHE_STATIC" ]; then
450	if [ '!' -z "$OVERRIDE_CONFIG_CACHE" ]; then
451	    echo "Copying static configure cache $OVERRIDE_CONFIG_CACHE_STATIC to $OVERRIDE_CONFIG_CACHE"
452	    cp -f "$OVERRIDE_CONFIG_CACHE_STATIC" "$OVERRIDE_CONFIG_CACHE"
453	fi
454    fi
455}
456
457do_configure ()
458{
459    setup_make
460
461    # Get `erl_build_tool_vars'
462    . "$ERL_TOP/erl-build-tool-vars.sh" || exit 1
463
464    maybe_copy_static_cache
465    try_cross_configure "$@"
466    if [ $cross_configure = no ]; then
467	CONFIG_FLAGS=
468	set_config_flags "$@"
469	run_configure "$@"
470    fi
471}
472
473echo_setenv ()
474{
475    case "$DAILY_BUILD_SCRIPT$SHELL" in
476	true*)
477	    echo "$1=$2";;
478	*ash|*ksh|*/sh|*zsh|*ash)
479	    echo "$1=\"$2\";export $1$3";;
480	*csh)
481	    echo "setenv $1 \"$2\"$3";;
482    esac
483}
484
485echo_env_bootstrap ()
486{
487    boot_bin=$BOOTSTRAP_ROOT/bootstrap/bin
488
489    echo_setenv PATH $boot_bin:$PATH
490}
491
492echo_env_erltop ()
493{
494    if [ X"$ERL_TOP" = X"" -o "$ERLTOP_FORCED" = "true" ]; then
495	if [ -f ./otp_build ]; then
496	    # Seems to be current directory...
497	    echo_setenv ERL_TOP `pwd` ';'
498	else
499	    echo "You need to either set ERL_TOP first or stand in the same" \
500		"directory as this script resides in." >&2
501	    exit 1
502	fi
503    fi
504}
505
506echo_envinfo ()
507{
508    case "$SHELL" in
509	*csh)
510	    return 0
511	    ;;
512	*)
513	    ;;
514    esac
515    if [ X"$DAILY_BUILD_SCRIPT" = X"true" ]; then
516	echo '# Output generated for daily build script only '\
517	     '($DAILY_BUILD_SCRIPT=true)'
518    else
519	echo '# Please note:'
520	echo '# The command you are running is supposed to be run'\
521	     'using the shells'
522	echo '# "eval" builtin, like in:'
523	echo '# $ eval `./otp_build env_<something>`'
524	echo '# If you see this comment, you probably haven'"'"'t done that.'
525    fi
526}
527
528#
529#  Cygwin build without microsoft visual C++ (dead?)
530#
531echo_env_mingw32 ()
532{
533    #echo_envinfo
534    if [ X"$SHELL" = X"" ]; then
535	echo "You need to export the shell variable first," \
536		"for bourne-like shells, type:" >&2
537	echo 'export SHELL' >&2
538	echo "and for csh-like shells, type:" >&2
539	echo 'setenv SHELL $SHELL' >&2
540	echo " - then try again." >&2
541	exit 1
542    fi
543    echo_env_erltop
544    CCYGPATH=`cygpath c:\\`
545    DCYGPATH=`cygpath d:\\`
546    P2=`echo :$PATH | \
547	sed "s,\",,g;s,:[cC]:,:$CCYGPATH,g;s,:[dD]:,:$DCYGPATH,g;s,^:,,"`
548    P3=""
549    save_ifs=$IFS
550    IFS=:
551    for p in $P2; do
552	if [ -d "$p" ]; then
553	    C1="`(cygpath -d $p 2>/dev/null || cygpath -w $p)`" 2> /dev/null
554	    C2=`cygpath "$C1" 2> /dev/null` 2> /dev/null
555	else
556	    C2=""
557	fi
558	if [ ! -z "$C2" ]; then
559	    if [ -z "$P3" ];then
560		P3="$C2"
561	    else
562		P3="$P3:$C2"
563	    fi
564	fi
565    done
566    found=false
567    for p in $P3; do
568	if [ -f "$p/mingw32-gcc.exe" ]; then
569	    found=$p
570	fi
571    done
572    found2=false
573    for p in $P3; do
574	if [ -f "$p/wmc.exe" ]; then
575	    found2=$p
576	fi
577    done
578    IFS=$save_ifs
579    if [ X"$found" = X"false" ]; then
580	echo "Could not find mingw32-gcc in PATH, build with mingw not possible!" >&2
581	return
582    fi
583
584    if [ X"$found2" = X"false" ]; then
585	echo "Could not find wmc.exe in PATH, part of wine for windows, " >&2
586	echo "needed for message file compilation: http://wine.sourceforge.net!!" >&2
587	return
588    fi
589    WIN32_WRAPPER_PATH="$ERL_TOP/erts/etc/win32/cygwin_tools/mingw:$ERL_TOP/erts/etc/win32/cygwin_tools"
590
591
592    echo_setenv OVERRIDE_TARGET win32 ';'
593    echo_setenv MINGW_EXE_PATH $found ';'
594    echo_setenv WINE_EXE_PATH $found2 ';'
595    echo_setenv CC cc.sh ';'
596    echo_setenv CXX cc.sh ';'
597    echo_setenv AR ar.sh ';'
598    echo_setenv RANLIB true ';'
599    echo_setenv WIN32_WRAPPER_PATH "$WIN32_WRAPPER_PATH" ';'
600    echo_setenv PATH "$WIN32_WRAPPER_PATH:$P3" ';'
601    echo_envinfo
602}
603
604# N.B. In Erlang, and the build system, win32 means windows, so we keep
605# everything as terget win32, but add the CONFIG_SUBTYPE win64, which can
606# be handled by configure, setting WINDOWS_64BIT in headers and such
607echo_env_cygwin ()
608{
609    X64=$1
610    #echo_envinfo
611    if [ X"$SHELL" = X"" ]; then
612	echo "You need to export the shell variable first," \
613		"for bourne-like shells, type:" >&2
614	echo 'export SHELL' >&2
615	echo "and for csh-like shells, type:" >&2
616	echo 'setenv SHELL $SHELL' >&2
617	echo " - then try again." >&2
618	exit 1
619    fi
620    echo_env_erltop
621    # Try to cope with paths containing unexpected things like stray
622    # mixed paths (c:/something/bin) and quotes. Only C and D drive
623    # handled.
624    CCYGPATH=`cygpath c:\\`
625    DCYGPATH=`cygpath d:\\`
626    P2=`echo :$PATH | \
627	sed "s,\",,g;s,:[cC]:,:$CCYGPATH,g;s,:[dD]:,:$DCYGPATH,g;s,^:,,"`
628    P3=""
629    save_ifs=$IFS
630    IFS=:
631    for p in $P2; do
632	if [ -d "$p" ]; then
633	    C1="`(cygpath -d $p 2>/dev/null || cygpath -w $p)`" 2> /dev/null
634	    C2=`cygpath "$C1" 2> /dev/null` 2> /dev/null
635	else
636	    C2=""
637	fi
638	if [ ! -z "$C2" ]; then
639	    if [ -z "$P3" ];then
640		P3="$C2"
641	    else
642		P3="$P3:$C2"
643	    fi
644	fi
645    done
646    IFS=$save_ifs
647    WIN32_WRAPPER_PATH="$ERL_TOP/erts/etc/win32/cygwin_tools/vc:$ERL_TOP/erts/etc/win32/cygwin_tools"
648
649    echo_setenv OVERRIDE_TARGET win32 ';'
650    if [ X"$X64" = X"true" ]; then
651        echo_setenv CONFIG_SUBTYPE win64 ';'
652    fi
653    echo_setenv CC cc.sh ';'
654    echo_setenv CXX cc.sh ';'
655    echo_setenv AR ar.sh ';'
656    echo_setenv RANLIB true ';'
657    if [ X"$X64" = X"true" ]; then
658        if [ -f "$ERL_TOP/erts/autoconf/win64.config.cache.static" ]; then
659	    echo_setenv OVERRIDE_CONFIG_CACHE_STATIC  "$ERL_TOP/erts/autoconf/win64.config.cache.static" ';'
660        fi
661        echo_setenv OVERRIDE_CONFIG_CACHE "$ERL_TOP/erts/autoconf/win64.config.cache" ';'
662    else
663        if [ -f "$ERL_TOP/erts/autoconf/win32.config.cache.static" ]; then
664	    echo_setenv OVERRIDE_CONFIG_CACHE_STATIC  "$ERL_TOP/erts/autoconf/win32.config.cache.static" ';'
665        fi
666        echo_setenv OVERRIDE_CONFIG_CACHE "$ERL_TOP/erts/autoconf/win32.config.cache" ';'
667    fi
668    echo_setenv WIN32_WRAPPER_PATH "$WIN32_WRAPPER_PATH" ';'
669    echo_setenv PATH "$WIN32_WRAPPER_PATH:$P3" ';'
670    echo_envinfo
671}
672
673echo_env_msys ()
674{
675    X64=$1
676    #echo_envinfo
677    if [ X"$SHELL" = X"" ]; then
678	echo "You need to export the shell variable first," \
679		"for bourne-like shells, type:" >&2
680	echo 'export SHELL' >&2
681	echo "and for csh-like shells, type:" >&2
682	echo 'setenv SHELL $SHELL' >&2
683	echo " - then try again." >&2
684	exit 1
685    fi
686    echo_env_erltop
687    # Try to cope with paths containing unexpected things like stray
688    # mixed paths (c:/something/bin) and quotes. Only C and D drive
689    # handled.
690    P2=`echo :$PATH | \
691	sed "s,\",,g;s,:\([a-zA-Z]\):,:/\L\1,g;s,^:,,"`
692    P3=""
693    save_pwd=`pwd`
694    save_ifs=$IFS
695    IFS=:
696    for p in $P2; do
697	if [ -d "$p" ]; then
698	    C1=`(cd "$p" && cmd //C "for %i in (".") do @echo %~fsi")`
699	    C2=`echo "$C1" | sed 's,^\([a-zA-Z]\):\\\\,/\L\1/,;s,\\\\,/,g'`
700	else
701	    C2=""
702	fi
703	if [ ! -z "$C2" ]; then
704	    if [ -z "$P3" ];then
705		P3="$C2"
706	    else
707		P3="$P3:$C2"
708	    fi
709	fi
710    done
711    IFS=$save_ifs
712    WIN32_WRAPPER_PATH="$ERL_TOP/erts/etc/win32/msys_tools/vc:$ERL_TOP/erts/etc/win32/msys_tools"
713
714    echo_setenv OVERRIDE_TARGET win32 ';'
715    if [ X"$X64" = X"true" ]; then
716        echo_setenv CONFIG_SUBTYPE win64 ';'
717    fi
718    echo_setenv CC cc.sh ';'
719    echo_setenv CXX cc.sh ';'
720    echo_setenv AR ar.sh ';'
721    echo_setenv RANLIB true ';'
722    if [ X"$X64" = X"true" ]; then
723        if [ -f "$ERL_TOP/erts/autoconf/win64.config.cache.static" ]; then
724	    echo_setenv OVERRIDE_CONFIG_CACHE_STATIC  "$ERL_TOP/erts/autoconf/win64.config.cache.static" ';'
725        fi
726        echo_setenv OVERRIDE_CONFIG_CACHE "$ERL_TOP/erts/autoconf/win64.config.cache" ';'
727    else
728        if [ -f "$ERL_TOP/erts/autoconf/win32.config.cache.static" ]; then
729	    echo_setenv OVERRIDE_CONFIG_CACHE_STATIC  "$ERL_TOP/erts/autoconf/win32.config.cache.static" ';'
730        fi
731        echo_setenv OVERRIDE_CONFIG_CACHE "$ERL_TOP/erts/autoconf/win32.config.cache" ';'
732    fi
733    echo_setenv WIN32_WRAPPER_PATH "$WIN32_WRAPPER_PATH" ';'
734    echo_setenv PATH "$WIN32_WRAPPER_PATH:$P3" ';'
735    echo_envinfo
736}
737
738echo_env_wsl ()
739{
740    X64=$1
741    #echo_envinfo
742    if [ X"$SHELL" = X"" ]; then
743	echo "You need to export the shell variable first," \
744		"for bourne-like shells, type:" >&2
745	echo 'export SHELL' >&2
746	echo "and for csh-like shells, type:" >&2
747	echo 'setenv SHELL $SHELL' >&2
748	echo " - then try again." >&2
749	exit 1
750    fi
751    echo_env_erltop
752
753    WIN32_WRAPPER_PATH="$ERL_TOP/erts/etc/win32/wsl_tools/vc:$ERL_TOP/erts/etc/win32/wsl_tools"
754
755    if [ ! -n "`lookup_prog_in_path cl`" ]; then
756        if [ X"$X64" = X"true" ]; then
757            setup_win32_cl_env "x64" `wslpath -a -m erts/etc/win32/wsl_tools/SetupWSLcross.bat`
758        else
759            setup_win32_cl_env "x86" `wslpath -a -m erts/etc/win32/wsl_tools/SetupWSLcross.bat`
760        fi
761    fi
762    echo_setenv OVERRIDE_TARGET win32 ';'
763    if [ X"$X64" = X"true" ]; then
764        echo_setenv CONFIG_SUBTYPE win64 ';'
765    fi
766    echo_setenv WSLcross true ';'
767    echo_setenv CC cc.sh ';'
768    echo_setenv CXX cc.sh ';'
769    echo_setenv AR ar.sh ';'
770    echo_setenv RANLIB true ';'
771    if [ X"$X64" = X"true" ]; then
772        if [ -f "$ERL_TOP/erts/autoconf/win64.config.cache.static" ]; then
773	    echo_setenv OVERRIDE_CONFIG_CACHE_STATIC  "$ERL_TOP/erts/autoconf/win64.config.cache.static" ';'
774        fi
775        echo_setenv OVERRIDE_CONFIG_CACHE "$ERL_TOP/erts/autoconf/win64.config.cache" ';'
776    else
777        if [ -f "$ERL_TOP/erts/autoconf/win32.config.cache.static" ]; then
778	    echo_setenv OVERRIDE_CONFIG_CACHE_STATIC  "$ERL_TOP/erts/autoconf/win32.config.cache.static" ';'
779        fi
780        echo_setenv OVERRIDE_CONFIG_CACHE "$ERL_TOP/erts/autoconf/win32.config.cache" ';'
781    fi
782    echo_setenv WIN32_WRAPPER_PATH "$WIN32_WRAPPER_PATH" ';'
783    echo_setenv PATH "$WIN32_WRAPPER_PATH:$PATH" ';'
784    echo_envinfo
785}
786
787
788setup_win32_cl_env ()
789{
790    eval `cmd.exe /c $2 $1`
791    echo_setenv INCLUDE "$INCLUDE" ';'
792    echo_setenv LIB "$LIB" ';'
793    echo_setenv LIBPATH "$LIBPATH" ';'
794    echo_setenv VCToolsRedistDir "$VCToolsRedistDir" ';'
795    echo_setenv WSLENV "$WSLENV:WSLPATH/l:CLASSPATH/l" ';'
796
797    save_ifs=$IFS
798    IFS=:
799    WSLPATH=""
800    for p in $PATH; do
801	if [ -d "$p" ]; then
802	    case "$p" in
803		/mnt/c/*)
804		    WSLPATH=$WSLPATH:$p
805		    ;;
806		*)
807		    ;;
808	    esac
809	fi
810    done
811    IFS=$save_ifs
812    echo_setenv WSLPATH "$WSLPATH" ';'
813}
814
815lookup_prog_in_path ()
816{
817    PROG=$1
818    save_ifs=$IFS
819    IFS=:
820    for p in $PATH; do
821	# In cygwin the programs are not always executable and have .exe suffix...
822	if [ "X$TARGET" = "Xwin32" ]; then
823	    if [ -f $p/$PROG.exe ]; then
824		echo $p/$PROG
825		break;
826	    fi
827	else
828	    if [ -x $p/$PROG ]; then
829		echo $p/$PROG
830		break;
831	    fi
832	fi
833    done
834    IFS=$save_ifs
835}
836
837setup_make ()
838{
839    if [ -z "$MAKE" ]; then
840	case $TARGET in
841	    win32)
842		MAKE=make;;
843	    *)
844		if [ -n "`lookup_prog_in_path gmake`" ]; then
845		    MAKE=gmake
846		else
847		    MAKE=make
848		fi;;
849       esac
850    fi
851    export MAKE
852}
853
854get_do_commit ()
855{
856    case $version_controller in
857	git)
858	    if [ "x$1" = "x" ]; then
859		do_commit=true
860	    elif [ "$1" = "--no-commit" ]; then
861		do_commit=false
862	    else
863		echo "Unknown option '$1'" 1>&2
864		exit 1
865	    fi;;
866	none)
867	    do_commit=false;;
868    esac
869}
870
871do_deprecations_git ()
872{
873    get_do_commit $1
874    setup_make
875
876    $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET \
877        deprecations || exit 1;
878
879    $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET \
880        primary_bootstrap || exit 1;
881
882    if [ $do_commit = true ]; then
883        git add -A bootstrap/lib/stdlib/ebin/otp_internal.beam
884        git add -A lib/stdlib/src/otp_internal.erl
885        git commit --no-verify -m 'Update deprecations'
886        echo ""
887        echo "Deprecations updated and committed."
888        echo ""
889    else
890        echo ""
891        echo "Deprecations updated. Use the following commands to stage "
892        echo "changed files:"
893        echo ""
894        echo "$ git add bootstrap/lib/stdlib/ebin/otp_internal.beam"
895        echo "$ git add lib/stdlib/src/otp_internal.erl"
896        echo ""
897    fi
898}
899
900do_primary_git ()
901{
902    get_do_commit $1
903    setup_make
904    if [ "x$OVERRIDE_TARGET" != "x" -a "x$OVERRIDE_TARGET" != "xwin32" ]; then
905	do_primary_cross
906    else
907	$MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET primary_bootstrap || exit 1;
908    fi
909    if [ $do_commit = true ]; then
910	git add -A bootstrap/lib/kernel \
911            bootstrap/lib/stdlib \
912	    bootstrap/lib/compiler \
913	    bootstrap/bin
914	find bootstrap -name egen -o -name '*.script' -o \
915	    -name '*.app' -o -name '*.appup' |
916        xargs git reset HEAD
917	git commit --no-verify -m 'Update primary bootstrap'
918	echo "Primary bootstrap updated and commited."
919    else
920	echo ""
921	echo "Primary bootstrap rebuilt."
922	if [ $version_controller = git ]; then
923	    echo "Use \"git add bootstrap/...\" to stage changed files."
924	fi
925	echo ""
926    fi
927}
928
929do_update_prel_git ()
930{
931    get_do_commit $1
932    setup_make
933    (cd "$ERL_TOP/erts/preloaded/src" && $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET clean)
934    $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET preloaded || exit 1
935    (cd "$ERL_TOP/erts/preloaded/src" && $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET copy)
936    if [ $do_commit = true ]; then
937	git add -A "$ERL_TOP/erts/preloaded/ebin/*.beam"
938	git commit -m 'Update preloaded modules'
939	echo "Preloaded updated and commited."
940    else
941	echo ""
942	echo "Preloaded rebuilt."
943	if [ $version_controller = git ]; then
944	    echo "Use \"git add erts/preloaded/ebin/...\" to stage changed beam files."
945	fi
946	echo ""
947    fi
948}
949
950do_boot ()
951{
952    setup_make
953
954    # Bootstrap if we are cross compiling
955    if [ X`$MAKE is_cross_configured` = Xyes ]; then
956	TARGET=$BUILDSYS
957	$MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT CROSS_COMPILING=no TARGET=$TARGET bootstrap || exit 1
958	TARGET=`$MAKE target_configured`
959    elif [ "x$OVERRIDE_TARGET" != "x" -a "x$OVERRIDE_TARGET" != "xwin32" ]; then
960	hide_vars OVERRIDE_TARGET TARGET
961	TARGET=$BUILDSYS
962	$MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET bootstrap || exit 1
963
964	restore_vars OVERRIDE_TARGET TARGET
965    fi
966
967    # Build it (including bootstrap if not cross compiling)
968    $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET all || exit 1
969}
970
971do_boot_emu ()
972{
973    setup_make
974    if [ X`$MAKE is_cross_configured` = Xyes ]; then
975	TARGET=`$MAKE target_configured`
976    fi
977    $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET emulator || exit 1
978}
979
980do_release ()
981{
982    setup_make
983    if [ X`$MAKE is_cross_configured` = Xyes ]; then
984	TARGET=`$MAKE target_configured`
985    fi
986    $MAKE MAKE="$MAKE" BOOTSTRAP_ROOT=$BOOTSTRAP_ROOT TARGET=$TARGET \
987	RELEASE_ROOT=$1 OTP_STRICT_INSTALL=$OTP_STRICT_INSTALL \
988	release || exit 1
989}
990
991do_tests ()
992{
993    setup_make
994    if [ X`$MAKE is_cross_configured` = Xyes ]; then
995	TARGET=`$MAKE target_configured`
996    fi
997    if [ X"$1" = X"" ]; then
998	$MAKE MAKE="$MAKE" TARGET=$TARGET release_tests || exit 1
999    else
1000	$MAKE MAKE="$MAKE" TARGET=$TARGET TESTSUITE_ROOT=$1 release_tests || exit 1
1001    fi
1002}
1003
1004do_debuginfo_win32 ()
1005{
1006    setup_make
1007    (cd erts/emulator && $MAKE MAKE="$MAKE" TARGET=$TARGET FLAVOR=smp debug &&\
1008	$MAKE MAKE="$MAKE" TARGET=$TARGET FLAVOR=plain debug) || exit 1
1009    if [ -z "$1" ]; then
1010	RELDIR="$ERL_TOP/release/$TARGET"
1011    else
1012	RELDIR="$1"
1013    fi
1014    BINDIR="$ERL_TOP/bin/$TARGET"
1015    EVSN=`grep '^VSN' erts/vsn.mk | sed 's,^VSN.*=[^0-9]*\([0-9].*\)$,@\1,g;s,^[^@].*,,g;s,^@,,g'`
1016    for f in beam.debug.smp.dll beam.smp.pdb beam.debug.smp.dll.pdb erl.pdb werl.pdb erlexec.pdb; do
1017	if [ -f $BINDIR/$f ]; then
1018	    rm -f $RELDIR/erts-$EVSN/bin/$f
1019	    cp $BINDIR/$f $RELDIR/erts-$EVSN/bin/$f
1020	fi
1021    done
1022}
1023
1024do_installer_win32 ()
1025{
1026    setup_make
1027    installer_dir="$ERL_TOP/erts/etc/win32/nsis"
1028    (cd $installer_dir; $MAKE MAKE="$MAKE" TARGET=$TARGET TESTROOT=$1 release) || exit 1
1029}
1030
1031do_copy_primary_bootstrap ()
1032{
1033    if [ "x$1" = "x" ]; then
1034	echo "Missing bootstrap source top" 1>&2
1035	exit 1
1036    fi
1037    if  [ ! -d $1 ]; then
1038	echo "Invalid bootstrap source top" 1>&2
1039	exit 1
1040    fi
1041    if [ "x$2" = "x" ]; then
1042	echo "Missing bootstrap root" 1>&2
1043	exit 1
1044    fi
1045    if  [ ! -d $2 ]; then
1046	echo "Invalid bootstrap root" 1>&2
1047	exit 1
1048    fi
1049
1050    bootstrap=$2/bootstrap
1051    bootstrap_src_top=$1
1052    lib_src=$bootstrap_src_top/lib
1053
1054    # kernel
1055    test -d $bootstrap/lib/kernel/ebin || mkdir -p  $bootstrap/lib/kernel/ebin
1056    test -d $bootstrap/lib/kernel/include || mkdir -p  $bootstrap/lib/kernel/include
1057    cp -f $lib_src/kernel/ebin/*.beam $bootstrap/lib/kernel/ebin
1058    cp -f $lib_src/kernel/include/*.hrl $bootstrap/lib/kernel/include
1059
1060    # stdlib
1061    test -d $bootstrap/lib/stdlib/ebin || mkdir -p  $bootstrap/lib/stdlib/ebin
1062    test -d $bootstrap/lib/stdlib/include || mkdir -p  $bootstrap/lib/stdlib/include
1063    cp -f $lib_src/stdlib/ebin/*.beam $bootstrap/lib/stdlib/ebin
1064    cp -f $lib_src/stdlib/include/*.hrl $bootstrap/lib/stdlib/include
1065
1066    # compiler
1067    test -d $bootstrap/lib/compiler/ebin || mkdir -p  $bootstrap/lib/compiler/ebin
1068    cp -f $lib_src/compiler/ebin/*.beam $bootstrap/lib/compiler/ebin
1069
1070    # bootstrap bin
1071    if [ $bootstrap_src_top != "$ERL_TOP" ]; then
1072	test -d $bootstrap/bin || mkdir -p  $bootstrap/bin
1073	cp -f $bootstrap_src_top/bin/* $bootstrap/bin
1074    fi
1075
1076}
1077
1078do_save_bootstrap ()
1079{
1080    if [ ! -f "$ERL_TOP/prebuilt.files" ]; then
1081	echo "This is not a pre-built source distribution" 1>&2
1082	exit 1
1083    fi
1084    if  [ -d "$ERL_TOP/bootstrap/lib" ]; then
1085	echo "Bootstrap already exist" 1>&2
1086	exit 1
1087    fi
1088
1089    do_copy_primary_bootstrap "$ERL_TOP" "$ERL_TOP"
1090}
1091
1092do_remove_prebuilt_files ()
1093{
1094    do_save_bootstrap
1095    for file in "$ERL_TOP"/`cat "$ERL_TOP/prebuilt.files"` ; do
1096	rm -f $file
1097    done
1098}
1099
1100# main
1101
1102check_erltop
1103
1104cd "$ERL_TOP"
1105
1106determine_version_controller
1107
1108# Unset ERL_FLAGS and ERL_OTP<OTP Release>_FLAGS during bootstrap to
1109# prevent potential problems
1110otp_major_vsn=`cat OTP_VERSION | sed "s|\([0-9]*\).*|\1|"`
1111erl_otp_flags="ERL_OTP${otp_major_vsn}_FLAGS"
1112unset ERL_FLAGS
1113unset ${erl_otp_flags}
1114
1115# Target first guess, won't necessarily hold, may be changed for
1116# certain parameters.
1117if [ X"$TARGET" = X"" ]; then
1118	TARGET=`"$ERL_TOP/erts/autoconf/config.guess"`
1119fi
1120BUILDSYS=$TARGET
1121
1122case $TARGET in
1123    *-cygwin)
1124	if [ X"$BUILD_FOR_CYGWIN" = X"" ]; then
1125	    if [ X"$OVERRIDE_TARGET" = X"" -a X"$1" != X"env_win32" -a X"$1" != X"env_win64" -a  X"$1" != X"env_mingw32" ];then
1126		echo "Building for windows, you should do the " \
1127		    "following first:" >&2
1128		echo 'eval `./otp_build env_win32`' >&2
1129		echo 'please note that there are backticks (``) in' \
1130		    'the command'
1131		exit 1
1132	    fi
1133	fi;;
1134    *-mingw32)
1135	if [ X"$OVERRIDE_TARGET" = X"" -a X"$1" != X"env_win32" -a X"$1" != X"env_msys32" -a X"$1" != X"env_msys64"  ];then
1136	    echo "Building for windows, you should do the " \
1137		"following first:" >&2
1138	    echo 'eval `./otp_build env_win32`' >&2
1139	    echo 'or' >&2
1140	    echo 'eval `./otp_build env_win32 x64`' >&2
1141	    echo 'please note that there are backticks (``) in' \
1142		'the command'
1143	    exit 1
1144	fi;;
1145    *)
1146        if [ -x /bin/wslpath -a X"$OVERRIDE_TARGET" = X"" \
1147                -a X"$1" != X"env_win32" -a X"$1" != X"env_msys32" -a X"$1" != X"env_msys64" ]; then
1148            echo "Building linux binary; if you intended to cross build for win32 (x64) use"  >&2
1149            echo '   eval `./otp_build env_win32 x64`\n' >&2
1150        fi
1151        ;;
1152esac
1153
1154if [ ! -z "$OVERRIDE_TARGET" ]; then
1155    TARGET="$OVERRIDE_TARGET"
1156fi
1157
1158# Setting a bootstrap root is inherently very dangerous now that the bootstrap
1159# is prebuilt, avoid it if not forced by setting FORCE_BOOTSTRAP_ROOT=true!
1160
1161if [ X"$FORCE_BOOTSTRAP_ROOT" != X"true" ]; then
1162    BOOTSTRAP_ROOT="$ERL_TOP"
1163else
1164    if [ -z "$BOOTSTRAP_ROOT" ]; then
1165	BOOTSTRAP_ROOT="$ERL_TOP"
1166    fi
1167fi
1168
1169if [ X"$1" = X"" ]; then
1170	usage
1171	exit 1
1172fi
1173
1174if [ X"$2" = X"-a" ]; then
1175    minus_x_flag=true
1176    OTP_SMALL_BUILD=
1177elif [ X"$2" = X"-s" ]; then
1178    minus_x_flag=true
1179    OTP_SMALL_BUILD=true
1180elif [ X"$2" = X"-t" ]; then
1181    minus_x_flag=true
1182    OTP_TINY_BUILD=true
1183else
1184    minus_x_flag=false
1185    OTP_SMALL_BUILD=true
1186fi
1187export OTP_SMALL_BUILD OTP_TINY_BUILD
1188
1189TYPE=
1190case "$1" in
1191 	all)
1192 		do_configure;
1193 		do_boot;
1194		if [ $minus_x_flag = true ]; then
1195 		    shift
1196 		fi;
1197 		do_release "$2";;
1198	setup)
1199		shift;
1200		if [ $minus_x_flag = true ]; then
1201		    shift
1202		fi;
1203		do_configure "$@";
1204		do_boot;;
1205	autoconf)
1206	    echo ""
1207	    echo "*** It is not necessary to execute './otp_build autoconf' anymore! ***"
1208	    echo ""
1209	    echo "All configure scripts have been committed in the repository and are"
1210	    echo "therefore always available. If you need to update them, execute"
1211	    echo "'./otp_build update_configure [--no-commit]'. Ensure that you have"
1212	    echo "autoconf version $USE_AUTOCONF_VERSION in your PATH before updating the configure"
1213	    echo "scritps."
1214	    echo ""
1215	    echo "The only effect of executing './otp_build autoconf' is printing of this"
1216	    echo "message."
1217	    echo ""
1218	    exit 0;;
1219	configure)
1220		shift;
1221		do_configure "$@";;
1222	opt)
1223		do_boot;;
1224	plain|smp)
1225		if [ $minus_x_flag = false ]; then
1226		    TYPE=opt
1227		fi;
1228		FLAVOR=$1
1229		do_boot;;
1230	update_configure)
1231	    do_update_configure "$2";;
1232	update_deprecations)
1233	        do_deprecations_git "$2";;
1234	update_primary)
1235	        do_primary_git "$2";;
1236	update_preloaded)
1237	        do_update_prel_git "$2";;
1238        primary)
1239	        echo "Primary bootstrap is under version control since R13";
1240		echo "Use update_primary if you really are";
1241		echo "updating the primary bootstrap...";;
1242	boot)
1243		do_boot;;
1244        emulator)
1245	        do_boot_emu;;
1246	release)
1247		if [ $minus_x_flag = true ]; then
1248		    shift
1249		fi;
1250		do_release "$2";;
1251	tests)
1252		if [ $minus_x_flag = true ]; then
1253		    shift
1254		fi;
1255		do_tests "$2";;
1256        remove_prebuilt_files)
1257		do_remove_prebuilt_files;;
1258        save_bootstrap)
1259		do_save_bootstrap;;
1260        copy_primary_bootstrap)
1261		do_copy_primary_bootstrap $2 $3;;
1262	installer_win32)
1263		if [ $minus_x_flag = true ]; then
1264		    shift
1265		fi;
1266		do_installer_win32 "$2";;
1267	debuginfo_win32)
1268		if [ $minus_x_flag = true ]; then
1269		    shift
1270		fi;
1271		do_debuginfo_win32 "$2";;
1272	env_win32)
1273	        if [ x"$2" = x"x64" -o x"$2" = x"amd64" ]; then
1274                    ISX64=true
1275		fi
1276                if [ -x /bin/wslpath ]; then
1277                    echo_env_wsl $ISX64
1278                elif [ -x /usr/bin/msys-?.0.dll ]; then
1279		    echo_env_msys $ISX64
1280		else
1281		    echo_env_cygwin $ISX64
1282		fi;;
1283	env_mingw32)
1284		echo_env_mingw32;;
1285	env_win64)
1286                if [ -x /bin/wslpath ]; then
1287                    echo_env_wsl true
1288                elif [ -x /usr/bin/msys-?.0.dll ]; then
1289		    echo_env_msys true
1290		else
1291		    echo_env_cygwin true
1292		fi;;
1293	env_msys32)
1294		echo_env_msys;;
1295	env_msys64)
1296		echo_env_msys true;;
1297	env_cross)
1298		echo_env_cross "$2";;
1299        env_bootstrap)
1300	        echo_env_bootstrap;;
1301	*)
1302		usage;;
1303esac
1304