Merge branch 'copy.names' of github.com:jamesqo/coreclr into copy.names
[platform/upstream/coreclr.git] / build.sh
1 #!/usr/bin/env bash
2
3 # resolve python-version to use
4 if [ "$PYTHON" == "" ] ; then
5     if which python >/dev/null 2>&1
6     then
7        PYTHON=python
8     elif which python2 >/dev/null 2>&1
9     then
10        PYTHON=python2
11     elif which python2.7 >/dev/null 2>&1
12     then
13        PYTHON=python2.7
14     else
15        echo "Unable to locate build-dependency python2.x!" 1>&2
16        exit 1
17     fi
18 fi
19
20 # validate python-dependency
21 # useful in case of explicitly set option.
22 if ! which $PYTHON > /dev/null 2>&1
23 then
24    echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
25    exit 1
26 fi
27
28 usage()
29 {
30     echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [configureonly] [skipconfigure] [skipnative] [skipmscorlib] [skiptests] [cmakeargs] [bindir]"
31     echo "BuildArch can be: x64, x86, arm, arm-softfp, arm64"
32     echo "BuildType can be: debug, checked, release"
33     echo "coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)."
34     echo "ninja - target ninja instead of GNU make"
35     echo "clangx.y - optional argument to build using clang version x.y."
36     echo "cross - optional argument to signify cross compilation,"
37     echo "      - will use ROOTFS_DIR environment variable if set."
38     echo "pgoinstrument - generate instrumented code for profile guided optimization enabled binaries."
39     echo "configureonly - do not perform any builds; just configure the build."
40     echo "skipconfigure - skip build configuration."
41     echo "skipnative - do not build native components."
42     echo "skipmscorlib - do not build mscorlib.dll."
43     echo "skiptests - skip the tests in the 'tests' subdirectory."
44     echo "skipnuget - skip building nuget packages."
45     echo "portableLinux - build for Portable Linux Distribution"
46     echo "verbose - optional argument to enable verbose build output."
47     echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)."
48         echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib."
49         echo "-sequential: force a non-parallel build ^(default is to build in parallel"
50         echo "   using all processors^)."
51         echo "-officialbuildid=^<ID^>: specify the official build ID to be used by this build."
52         echo "-Rebuild: passes /t:rebuild to the build projects."
53     echo "skipgenerateversion - disable version generation even if MSBuild is supported."
54     echo "cmakeargs - user-settable additional arguments passed to CMake."
55     echo "bindir - output directory (defaults to $__ProjectRoot/bin)"
56
57     exit 1
58 }
59
60 initHostDistroRid()
61 {
62     if [ "$__HostOS" == "Linux" ]; then
63         if [ ! -e /etc/os-release ]; then
64             echo "WARNING: Can not determine runtime id for current distro."
65             __HostDistroRid=""
66         else
67             source /etc/os-release
68             __HostDistroRid="$ID.$VERSION_ID-$__HostArch"
69         fi
70     fi
71 }
72
73 initTargetDistroRid()
74 {
75     if [ $__CrossBuild == 1 ]; then
76         if [ "$__BuildOS" == "Linux" ]; then
77             if [ ! -e $ROOTFS_DIR/etc/os-release ]; then
78                 echo "WARNING: Can not determine runtime id for current distro."
79                 export __DistroRid=""
80             else
81                 source $ROOTFS_DIR/etc/os-release
82                 export __DistroRid="$ID.$VERSION_ID-$__BuildArch"
83             fi
84         fi
85     else
86         export __DistroRid="$__HostDistroRid"
87     fi
88
89     # Portable builds target the base RID only for Linux based platforms
90     if [ $__PortableLinux == 1 ]; then
91         export __DistroRid="linux-$__BuildArch"
92     fi
93 }
94
95 setup_dirs()
96 {
97     echo Setting up directories for build
98
99     mkdir -p "$__RootBinDir"
100     mkdir -p "$__BinDir"
101     mkdir -p "$__LogsDir"
102     mkdir -p "$__IntermediatesDir"
103
104     if [ $__CrossBuild == 1 ]; then
105         mkdir -p "$__CrossComponentBinDir"
106         mkdir -p "$__CrossCompIntermediatesDir"
107     fi
108 }
109
110 # Check the system to ensure the right prereqs are in place
111
112 check_prereqs()
113 {
114     echo "Checking prerequisites..."
115
116     # Check presence of CMake on the path
117     hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; }
118
119     # Check for clang
120     hash clang-$__ClangMajorVersion.$__ClangMinorVersion 2>/dev/null ||  hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null ||  hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; }
121
122 }
123
124
125 generate_event_logging_sources()
126 {
127     if [ $__SkipCoreCLR == 1 ]; then
128         return
129     fi
130
131 # Event Logging Infrastructure
132    __GeneratedIntermediate="$__IntermediatesDir/Generated"
133    __GeneratedIntermediateEventProvider="$__GeneratedIntermediate/eventprovider_new"
134     if [[ -d "$__GeneratedIntermediateEventProvider" ]]; then
135         rm -rf  "$__GeneratedIntermediateEventProvider"
136     fi
137
138     if [[ ! -d "$__GeneratedIntermediate/eventprovider" ]]; then
139         mkdir -p "$__GeneratedIntermediate/eventprovider"
140     fi
141
142     mkdir -p "$__GeneratedIntermediateEventProvider"
143     if [[ $__SkipCoreCLR == 0 || $__ConfigureOnly == 1 ]]; then
144         echo "Laying out dynamically generated files consumed by the build system "
145         echo "Laying out dynamically generated Event Logging Test files"
146         $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatEventing.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --exc "$__ProjectRoot/src/vm/ClrEtwAllMeta.lst" --testdir "$__GeneratedIntermediateEventProvider/tests"
147
148         if  [[ $? != 0 ]]; then
149             exit
150         fi
151
152         #determine the logging system
153         case $__BuildOS in
154             Linux)
155                 echo "Laying out dynamically generated Event Logging Implementation of Lttng"
156                 $PYTHON -B -Wall -Werror "$__ProjectRoot/src/scripts/genXplatLttng.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__GeneratedIntermediateEventProvider"
157                 if  [[ $? != 0 ]]; then
158                     exit
159                 fi
160                 ;;
161             *)
162                 ;;
163         esac
164     fi
165
166     echo "Cleaning the temp folder of dynamically generated Event Logging files"
167     $PYTHON -B -Wall -Werror -c "import sys;sys.path.insert(0,\"$__ProjectRoot/src/scripts\"); from Utilities import *;UpdateDirectory(\"$__GeneratedIntermediate/eventprovider\",\"$__GeneratedIntermediateEventProvider\")"
168     if  [[ $? != 0 ]]; then
169         exit
170     fi
171
172     rm -rf "$__GeneratedIntermediateEventProvider"
173 }
174
175 build_native()
176 {
177     skipCondition=$1
178     platformArch="$2"
179     intermediatesForBuild="$3"
180     extraCmakeArguments="$4"
181     message="$5"
182
183     if [ $skipCondition == 1 ]; then
184         echo "Skipping $message build."
185         return
186     fi
187
188     # All set to commence the build
189     echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild"
190
191     generator=""
192     buildFile="Makefile"
193     buildTool="make"
194     if [ $__UseNinja == 1 ]; then
195         generator="ninja"
196         buildFile="build.ninja"
197         if which ninja >/dev/null 2>&1; then
198             buildTool="ninja"
199         elif which ninja-build >/dev/null 2>&1; then
200             buildTool="ninja-build"
201         else
202            echo "Unable to locate ninja!" 1>&2
203            exit 1
204         fi
205     fi
206
207     if [ $__SkipConfigure == 0 ]; then
208         # if msbuild is not supported, then set __SkipGenerateVersion to 1
209         if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi
210         # Drop version.cpp file
211         __versionSourceFile="$intermediatesForBuild/version.cpp"
212         if [ $__SkipGenerateVersion == 0 ]; then
213             pwd
214             "$__ProjectRoot/run.sh" build -Project=$__ProjectDir/build.proj -generateHeaderUnix -NativeVersionSourceFile=$__versionSourceFile $__RunArgs $__UnprocessedBuildArgs
215         else
216             # Generate the dummy version.cpp, but only if it didn't exist to make sure we don't trigger unnecessary rebuild
217             __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";"
218             if [ -e $__versionSourceFile ]; then
219                 read existingVersionSourceLine < $__versionSourceFile
220             fi
221             if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then
222                 echo $__versionSourceLine > $__versionSourceFile
223             fi
224         fi
225
226         pushd "$intermediatesForBuild"
227         # Regenerate the CMake solution
228         echo "Invoking \"$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh\" \"$__ProjectRoot\" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator $extraCmakeArguments $__cmakeargs"
229         "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $platformArch $__BuildType $__CodeCoverage $__IncludeTests $generator "$extraCmakeArguments" "$__cmakeargs"
230         popd
231     fi
232
233     if [ ! -f "$intermediatesForBuild/$buildFile" ]; then
234         echo "Failed to generate $message build project!"
235         exit 1
236     fi
237     
238     # Get the number of processors available to the scheduler
239     # Other techniques such as `nproc` only get the number of
240     # processors available to a single process.
241     if [ `uname` = "FreeBSD" ]; then
242         NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
243     elif [ `uname` = "NetBSD" ]; then
244         NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
245     else
246         NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
247     fi
248
249     # Build
250     if [ $__ConfigureOnly == 1 ]; then
251         echo "Finish configuration & skipping $message build."
252         return
253     fi
254
255     # Check that the makefiles were created.
256     pushd "$intermediatesForBuild"
257
258     echo "Executing $buildTool install -j $NumProc"
259
260     $buildTool install -j $NumProc
261     if [ $? != 0 ]; then
262         echo "Failed to build $message."
263         exit 1
264     fi
265
266     popd
267 }
268
269 isMSBuildOnNETCoreSupported()
270 {
271     # This needs to be updated alongwith corresponding changes to netci.groovy.
272     __isMSBuildOnNETCoreSupported=0
273
274     if [ "$__HostArch" == "x64" ]; then
275         if [ "$__HostOS" == "Linux" ]; then
276             case "$__HostDistroRid" in
277                 "centos.7-x64")
278                     __isMSBuildOnNETCoreSupported=1
279                     ;;
280                 "debian.8-x64")
281                     __isMSBuildOnNETCoreSupported=1
282                     ;;
283                 "fedora.23-x64")
284                     __isMSBuildOnNETCoreSupported=1
285                     ;;
286                 "fedora.24-x64")
287                     __isMSBuildOnNETCoreSupported=1
288                     ;;
289                 "opensuse.13.2-x64")
290                     __isMSBuildOnNETCoreSupported=1
291                     ;;
292                 "opensuse.42.1-x64")
293                     __isMSBuildOnNETCoreSupported=1
294                     ;;
295                 "rhel.7.2-x64")
296                     __isMSBuildOnNETCoreSupported=1
297                     ;;
298                 "ubuntu.14.04-x64")
299                     __isMSBuildOnNETCoreSupported=1
300                     ;;
301                 "ubuntu.16.04-x64")
302                     __isMSBuildOnNETCoreSupported=1
303                     ;;
304                 "ubuntu.16.10-x64")
305                     __isMSBuildOnNETCoreSupported=1
306                     ;;
307                 "alpine.3.4.3-x64")
308                     __isMSBuildOnNETCoreSupported=1
309                     ;;
310                 *)
311             esac
312         elif [ "$__HostOS" == "OSX" ]; then
313             __isMSBuildOnNETCoreSupported=1
314         fi
315     fi
316 }
317
318 build_CoreLib_ni()
319 {
320     if [ $__SkipCoreCLR == 0 -a -e $__BinDir/crossgen ]; then
321         echo "Generating native image for System.Private.CoreLib."
322         $__BinDir/crossgen $__BinDir/System.Private.CoreLib.dll
323         if [ $? -ne 0 ]; then
324             echo "Failed to generate native image for System.Private.CoreLib."
325             exit 1
326         fi
327
328         echo "Generating native image for MScorlib Facade."
329         $__BinDir/crossgen $__BinDir/mscorlib.dll
330         if [ $? -ne 0 ]; then
331             echo "Failed to generate native image for mscorlib facade."
332             exit 1
333         fi
334
335         if [ "$__BuildOS" == "Linux" ]; then
336             echo "Generating symbol file for System.Private.CoreLib."
337             $__BinDir/crossgen /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.ni.dll
338             if [ $? -ne 0 ]; then
339                 echo "Failed to generate symbol file for System.Private.CoreLib."
340                 exit 1
341             fi
342         fi
343     fi
344 }
345
346 build_CoreLib()
347 {
348
349     if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
350         echo "System.Private.CoreLib.dll build unsupported."
351         return
352     fi
353
354     if [ $__SkipMSCorLib == 1 ]; then
355        echo "Skipping building System.Private.CoreLib."
356        return
357     fi
358
359     echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType"
360
361     # Invoke MSBuild
362     $__ProjectRoot/run.sh build -Project=$__ProjectDir/build.proj -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__UnprocessedBuildArgs
363
364     if [ $? -ne 0 ]; then
365         echo "Failed to build managed components."
366         exit 1
367     fi
368
369     # The cross build generates a crossgen with the target architecture.
370     if [ $__CrossBuild != 1 ]; then
371        # The architecture of host pc must be same architecture with target.
372        if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then
373            build_CoreLib_ni
374        elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then
375            build_CoreLib_ni
376        elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then
377            build_CoreLib_ni
378        else 
379            exit 1
380        fi
381     fi 
382 }
383
384 generate_NugetPackages()
385 {
386     # We can only generate nuget package if we also support building mscorlib as part of this build.
387     if [ $__isMSBuildOnNETCoreSupported == 0 ]; then
388         echo "Nuget package generation unsupported."
389         return
390     fi
391
392     # Since we can build mscorlib for this OS, did we build the native components as well?
393     if [ $__SkipCoreCLR == 1 ]; then
394         echo "Unable to generate nuget packages since native components were not built."
395         return
396     fi
397
398     echo "Generating nuget packages for "$__BuildOS
399
400     # Build the packages
401     $__ProjectRoot/run.sh build -Project=$__SourceDir/.nuget/packages.builds -MsBuildLog="/flp:Verbosity=normal;LogFile=$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.log" -BuildTarget -__IntermediatesDir=$__IntermediatesDir -__RootBinDir=$__RootBinDir -BuildNugetPackage=false -UseSharedCompilation=false $__RunArgs $__UnprocessedBuildArgs
402
403     if [ $? -ne 0 ]; then
404         echo "Failed to generate Nuget packages."
405         exit 1
406     fi
407 }
408
409 echo "Commencing CoreCLR Repo build"
410
411 # Argument types supported by this script:
412 #
413 # Build architecture - valid values are: x64, ARM.
414 # Build Type         - valid values are: Debug, Checked, Release
415 #
416 # Set the default arguments for build
417
418 # Obtain the location of the bash script to figure out where the root of the repo is.
419 __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
420
421 # Use uname to determine what the CPU is.
422 CPUName=$(uname -p)
423 # Some Linux platforms report unknown for platform, but the arch for machine.
424 if [ "$CPUName" == "unknown" ]; then
425     CPUName=$(uname -m)
426 fi
427
428 case $CPUName in
429     i686)
430         echo "Unsupported CPU $CPUName detected, build might not succeed!"
431         __BuildArch=x86
432         __HostArch=x86
433         ;;
434
435     x86_64)
436         __BuildArch=x64
437         __HostArch=x64
438         ;;
439
440     armv7l)
441         echo "Unsupported CPU $CPUName detected, build might not succeed!"
442         __BuildArch=arm
443         __HostArch=arm
444         ;;
445
446     aarch64)
447         echo "Unsupported CPU $CPUName detected, build might not succeed!"
448         __BuildArch=arm64
449         __HostArch=arm64
450         ;;
451
452     *)
453         echo "Unknown CPU $CPUName detected, configuring as if for x64"
454         __BuildArch=x64
455         __HostArch=x64
456         ;;
457 esac
458
459 # Use uname to determine what the OS is.
460 OSName=$(uname -s)
461 case $OSName in
462     Linux)
463         __BuildOS=Linux
464         __HostOS=Linux
465         ;;
466
467     Darwin)
468         __BuildOS=OSX
469         __HostOS=OSX
470         ;;
471
472     FreeBSD)
473         __BuildOS=FreeBSD
474         __HostOS=FreeBSD
475         ;;
476
477     OpenBSD)
478         __BuildOS=OpenBSD
479         __HostOS=OpenBSD
480         ;;
481
482     NetBSD)
483         __BuildOS=NetBSD
484         __HostOS=NetBSD
485         ;;
486
487     SunOS)
488         __BuildOS=SunOS
489         __HostOS=SunOS
490         ;;
491
492     *)
493         echo "Unsupported OS $OSName detected, configuring as if for Linux"
494         __BuildOS=Linux
495         __HostOS=Linux
496         ;;
497 esac
498
499 __BuildType=Debug
500 __CodeCoverage=
501 __IncludeTests=Include_Tests
502
503 # Set the various build properties here so that CMake and MSBuild can pick them up
504 __ProjectDir="$__ProjectRoot"
505 __SourceDir="$__ProjectDir/src"
506 __PackagesDir="$__ProjectDir/packages"
507 __RootBinDir="$__ProjectDir/bin"
508 __UnprocessedBuildArgs=
509 __RunArgs=
510 __MSBCleanBuildArgs=
511 __UseNinja=0
512 __VerboseBuild=0
513 __PgoInstrument=0
514 __ConfigureOnly=0
515 __SkipConfigure=0
516 __SkipRestore=""
517 __SkipNuget=0
518 __SkipCoreCLR=0
519 __SkipMSCorLib=0
520 __CrossBuild=0
521 __ClangMajorVersion=0
522 __ClangMinorVersion=0
523 __NuGetPath="$__PackagesDir/NuGet.exe"
524 __HostDistroRid=""
525 __DistroRid=""
526 __cmakeargs=""
527 __SkipGenerateVersion=0
528 __DoCrossArchBuild=0
529 __PortableLinux=0
530
531 while :; do
532     if [ $# -le 0 ]; then
533         break
534     fi
535
536     lowerI="$(echo $1 | awk '{print tolower($0)}')"
537     case $lowerI in
538         -\?|-h|--help)
539             usage
540             exit 1
541             ;;
542
543         x86)
544             __BuildArch=x86
545             ;;
546
547         x64)
548             __BuildArch=x64
549             ;;
550
551         arm)
552             __BuildArch=arm
553             ;;
554
555         arm-softfp)
556             __BuildArch=arm-softfp
557             ;;
558
559         arm64)
560             __BuildArch=arm64
561             ;;
562
563         debug)
564             __BuildType=Debug
565             ;;
566
567         checked)
568             __BuildType=Checked
569             ;;
570
571         release)
572             __BuildType=Release
573             ;;
574
575         coverage)
576             __CodeCoverage=Coverage
577             ;;
578
579         cross)
580             __CrossBuild=1
581             ;;
582             
583                 portablelinux)
584             if [ "$__BuildOS" == "Linux" ]; then
585                 __PortableLinux=1
586             else
587                 echo "ERROR: portableLinux not supported for non-Linux platforms."
588                 exit 1
589             fi
590             ;;
591             
592         verbose)
593         __VerboseBuild=1
594         ;;
595
596         clang3.5)
597             __ClangMajorVersion=3
598             __ClangMinorVersion=5
599             ;;
600
601         clang3.6)
602             __ClangMajorVersion=3
603             __ClangMinorVersion=6
604             ;;
605
606         clang3.7)
607             __ClangMajorVersion=3
608             __ClangMinorVersion=7
609             ;;
610
611         clang3.8)
612             __ClangMajorVersion=3
613             __ClangMinorVersion=8
614             ;;
615
616         clang3.9)
617             __ClangMajorVersion=3
618             __ClangMinorVersion=9
619             ;;
620
621         ninja)
622             __UseNinja=1
623             ;;
624
625         pgoinstrument)
626             __PgoInstrument=1
627             ;;
628
629         configureonly)
630             __ConfigureOnly=1
631             __SkipMSCorLib=1
632             __SkipNuget=1
633             ;;
634
635         skipconfigure)
636             __SkipConfigure=1
637             ;;
638
639         skipnative)
640             # Use "skipnative" to use the same option name as build.cmd.
641             __SkipCoreCLR=1
642             ;;
643
644         skipcoreclr)
645             # Accept "skipcoreclr" for backwards-compatibility.
646             __SkipCoreCLR=1
647             ;;
648
649         crosscomponent)
650             __DoCrossArchBuild=1
651             ;;
652
653         skipmscorlib)
654             __SkipMSCorLib=1
655             ;;
656
657         skipgenerateversion)
658             __SkipGenerateVersion=1
659             ;;
660
661         includetests)
662             ;;
663
664         skiptests)
665             __IncludeTests=
666             ;;
667
668         skipnuget)
669             __SkipNuget=1
670             ;;
671
672         cmakeargs)
673             if [ -n "$2" ]; then
674                 __cmakeargs="$2"
675                 shift
676             else
677                 echo "ERROR: 'cmakeargs' requires a non-empty option argument"
678                 exit 1
679             fi
680             ;;
681
682         bindir)
683             if [ -n "$2" ]; then
684                 __RootBinDir="$2"
685                 if [ ! -d $__RootBinDir ]; then
686                     mkdir $__RootBinDir
687                 fi
688                 __RootBinParent=$(dirname $__RootBinDir)
689                 __RootBinName=${__RootBinDir##*/}
690                 __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)"
691                 shift
692             else
693                 echo "ERROR: 'bindir' requires a non-empty option argument"
694                 exit 1
695             fi
696             ;;
697
698         *)
699             __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1"
700             ;;
701     esac
702
703     shift
704 done
705
706 __RunArgs="-BuildArch=$__BuildArch -BuildType=$__BuildType -BuildOS=$__BuildOS"
707
708 # Configure environment if we are doing a verbose build
709 if [ $__VerboseBuild == 1 ]; then
710     export VERBOSE=1
711         __RunArgs="$__RunArgs -verbose"
712 fi
713
714 # Set default clang version
715 if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then
716     if [ $__CrossBuild == 1 ]; then
717         __ClangMajorVersion=3
718         __ClangMinorVersion=6
719     else
720         __ClangMajorVersion=3
721         __ClangMinorVersion=5
722     fi
723 fi
724
725 # Set dependent variables
726 __LogsDir="$__RootBinDir/Logs"
727
728 # init the host distro name
729 initHostDistroRid
730
731 # Set the remaining variables based upon the determined build configuration
732 __BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType"
733 __PackagesBinDir="$__BinDir/.nuget"
734 __ToolsDir="$__RootBinDir/tools"
735 __TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType"
736 export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType"
737 __TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType"
738 __isMSBuildOnNETCoreSupported=0
739 __CrossComponentBinDir="$__BinDir"
740 __CrossCompIntermediatesDir="$__IntermediatesDir/crossgen"
741
742 __CrossArch="$__HostArch"
743 if [[ "$__HostArch" == "x64" && "$__BuildArch" == "arm" ]]; then
744     __CrossArch="x86"
745 fi
746 if [ $__CrossBuild == 1 ]; then
747     __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch"
748 fi
749 __CrossgenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$BuildArch.$__BuildType.log"
750 __CrossgenExe="$__CrossComponentBinDir/crossgen"
751
752 # Init if MSBuild for .NET Core is supported for this platform
753 isMSBuildOnNETCoreSupported
754
755 # CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set.
756 # This is needed by CLI to function.
757 if [ -z "$HOME" ]; then
758     if [ ! -d "$__ProjectDir/temp_home" ]; then
759         mkdir temp_home
760     fi
761     export HOME=$__ProjectDir/temp_home
762     echo "HOME not defined; setting it to $HOME"
763 fi
764
765 # Specify path to be set for CMAKE_INSTALL_PREFIX.
766 # This is where all built CoreClr libraries will copied to.
767 export __CMakeBinDir="$__BinDir"
768
769 # Configure environment if we are doing a cross compile.
770 if [ $__CrossBuild == 1 ]; then
771     export CROSSCOMPILE=1
772     if ! [[ -n "$ROOTFS_DIR" ]]; then
773         export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch"
774     fi
775 fi
776
777 # init the target distro name
778 initTargetDistroRid
779
780 # Make the directories necessary for build if they don't exist
781 setup_dirs
782
783 # Check prereqs.
784 check_prereqs
785
786 # Generate event logging infrastructure sources
787 generate_event_logging_sources
788
789 # Build the coreclr (native) components.
790 __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
791 build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component"
792
793 # Build cross-architecture components
794 if [ $__CrossBuild == 1 ]; then
795     __SkipCrossArchBuild=1
796     if [ $__DoCrossArchBuild == 1 ]; then
797         # build cross-architecture components for x86-host/arm-target
798         if [[ "$__BuildArch" == "arm" && "$__CrossArch" == "x86" ]]; then
799             __SkipCrossArchBuild=0
800         fi
801     fi
802
803     export __CMakeBinDir="$__CrossComponentBinDir"
804     export CROSSCOMPONENT=1
805     __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_TARGET_OS=$__BuildOS -DCLR_CMAKE_PACKAGES_DIR=$__PackagesDir -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument"
806     build_native $__SkipCrossArchBuild "$__CrossArch" "$__CrossCompIntermediatesDir" "$__ExtraCmakeArgs" "cross-architecture component"
807 fi
808
809 # Build System.Private.CoreLib.
810
811 build_CoreLib
812
813 # Generate nuget packages
814 if [ $__SkipNuget != 1 ]; then
815     generate_NugetPackages
816 fi
817
818
819 # Build complete
820
821 echo "Repo successfully built."
822 echo "Product binaries are available at $__BinDir"
823 exit 0