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