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