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