Merge branch 'master' into ffast-math
[mono-project.git] / netcore / build.sh
blobcd9fa818794e503223fc5ffc434ffd96586ee4c3
1 #!/usr/bin/env bash
3 # Stop script if unbound variable found (use ${var:-} if intentional)
4 set -u
6 # Stop script if command returns non-zero exit code.
7 # Prevents hidden errors caused by missing error code propagation.
8 set -e
10 usage()
12 echo "Common settings:"
13 echo " --configuration <value> Build configuration: 'Debug' or 'Release' (short: -c)"
14 echo " --help Print help and exit (short: -h)"
15 echo ""
17 echo "Actions:"
18 echo " --pack Package build outputs into NuGet packages"
19 echo " --test Run all unit tests in the solution (short: -t)"
20 echo " --rebuild Run ../.autogen.sh"
21 echo " --llvm Enable LLVM support"
22 echo " --skipnative Do not build runtime"
23 echo " --skipmscorlib Do not build System.Private.CoreLib"
24 echo ""
26 echo "Command line arguments starting with '/p:' are passed through to MSBuild."
27 echo "Arguments can also be passed in with a single hyphen."
30 pack=false
31 configuration='Debug'
32 properties=''
33 force_rebuild=false
34 test=false
35 skipmscorlib=false
36 skipnative=false
37 autogen_params=''
39 while [[ $# > 0 ]]; do
40 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
41 case "$opt" in
42 -help|-h)
43 usage
44 exit 0
46 -configuration|-c)
47 properties="$properties $1 $2"
48 configuration=$2
49 shift
51 -pack)
52 pack=true
54 -test|-t)
55 test=true
57 -rebuild)
58 force_rebuild=true
60 -skipmscorlib)
61 skipmscorlib=true
63 -skipnative)
64 skipnative=true
66 -llvm)
67 autogen_params="$autogen_params --enable-llvm"
69 -p:*|/p:*)
70 properties="$properties $1"
72 -m:*|/m:*)
73 properties="$properties $1"
75 -bl:*|/bl:*)
76 properties="$properties $1"
78 -dl:*|/dl:*)
79 properties="$properties $1"
82 echo "Invalid argument: $1"
83 usage
84 exit 1
86 esac
88 shift
89 done
91 CPU_COUNT=$(getconf _NPROCESSORS_ONLN || echo 4)
93 if [[ "$configuration" == "Debug" ]]; then
94 EXTRA_CFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
95 EXTRA_CXXFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
96 elif [[ "$configuration" == "Release" ]]; then
97 EXTRA_CFLAGS="-O2 -g"
98 EXTRA_CXXFLAGS="-O2 -g"
101 # run .././autogen.sh only once or if "--rebuild" argument is provided
102 if [[ "$force_rebuild" == "true" || ! -f .configured ]]; then
103 (cd .. && ./autogen.sh --with-core=only $autogen_params CFLAGS="$EXTRA_CFLAGS" CXXFLAGS="$EXTRA_CXXFLAGS")
104 touch .configured
107 # build mono runtime
108 if [ "$skipnative" = "false" ]; then
109 make runtime -j$CPU_COUNT
112 # build System.Private.CoreLib (../mcs/class/System.Private.CoreLib)
113 if [ "$skipmscorlib" = "false" ]; then
114 make bcl CORLIB_BUILD_FLAGS="$properties"
117 # create a nupkg with runtime and System.Private.CoreLib
118 if [ "$pack" = "true" ]; then
119 make nupkg
122 # run all xunit tests
123 if [ "$test" = "true" ]; then
124 make update-tests-corefx
125 for testdir in corefx/tests/extracted/*; do
126 ../scripts/ci/./run-step.sh --label=$(basename $testdir) --timeout=15m make run-tests-corefx-$(basename $testdir)
127 done