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