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