[netcore] Add libc name transition
[mono-project.git] / netcore / build.sh
blob5e83023d6755ba0e99c22841e0ec67180c072a37
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 llvm=false
38 autogen_params=''
40 while [[ $# > 0 ]]; do
41 opt="$(echo "${1/#--/-}" | awk '{print tolower($0)}')"
42 case "$opt" in
43 -help|-h)
44 usage
45 exit 0
47 -configuration|-c)
48 properties="$properties $1 $2"
49 configuration=$2
50 shift
52 -pack)
53 pack=true
55 -test|-t)
56 test=true
58 -rebuild)
59 force_rebuild=true
61 -skipmscorlib)
62 skipmscorlib=true
64 -skipnative)
65 skipnative=true
67 -llvm)
68 llvm=true
70 -p:*|/p:*)
71 properties="$properties $1"
73 -m:*|/m:*)
74 properties="$properties $1"
76 -bl:*|/bl:*)
77 properties="$properties $1"
79 -dl:*|/dl:*)
80 properties="$properties $1"
83 echo "Invalid argument: $1"
84 usage
85 exit 1
87 esac
89 shift
90 done
92 CPU_COUNT=$(getconf _NPROCESSORS_ONLN || echo 4)
94 if [[ "$configuration" == "Debug" ]]; then
95 EXTRA_CFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
96 EXTRA_CXXFLAGS="-O0 -ggdb3 -fno-omit-frame-pointer"
97 elif [[ "$configuration" == "Release" ]]; then
98 EXTRA_CFLAGS="-O2 -g"
99 EXTRA_CXXFLAGS="-O2 -g"
102 if [ "$llvm" = "true" ]; then
103 git submodule update --init -- ../external/llvm
104 autogen_params="$autogen_params --enable-llvm"
107 # run .././autogen.sh only once or if "--rebuild" argument is provided
108 if [[ "$force_rebuild" == "true" || ! -f .configured ]]; then
109 (cd .. && ./autogen.sh --with-core=only $autogen_params CFLAGS="$EXTRA_CFLAGS" CXXFLAGS="$EXTRA_CXXFLAGS")
110 touch .configured
113 # build mono runtime
114 if [ "$skipnative" = "false" ]; then
115 make runtime -j$CPU_COUNT
118 # build System.Private.CoreLib (../mcs/class/System.Private.CoreLib)
119 if [ "$skipmscorlib" = "false" ]; then
120 make bcl CORLIB_BUILD_FLAGS="$properties"
123 # create a nupkg with runtime and System.Private.CoreLib
124 if [ "$pack" = "true" ]; then
125 make nupkg
128 # run all xunit tests
129 if [ "$test" = "true" ]; then
130 make update-tests-corefx
131 for testdir in corefx/tests/extracted/*; do
132 ../scripts/ci/./run-step.sh --label=$(basename $testdir) --timeout=15m make run-tests-corefx-$(basename $testdir)
133 done