|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +usage() |
| 4 | +{ |
| 5 | + echo "Usage: $0 [BuildArch] [BuildType] [clean] [verbose] [clangx.y]" |
| 6 | + echo "BuildArch can be: x64" |
| 7 | + echo "BuildType can be: Debug, Release" |
| 8 | + echo "clean - optional argument to force a clean build." |
| 9 | + echo "verbose - optional argument to enable verbose build output." |
| 10 | + echo "clangx.y - optional argument to build using clang version x.y." |
| 11 | + |
| 12 | + exit 1 |
| 13 | +} |
| 14 | + |
| 15 | +setup_dirs() |
| 16 | +{ |
| 17 | + echo Setting up directories for build |
| 18 | + |
| 19 | + mkdir -p "$__RootBinDir" |
| 20 | + mkdir -p "$__BinDir" |
| 21 | + mkdir -p "$__LogsDir" |
| 22 | + mkdir -p "$__IntermediatesDir" |
| 23 | +} |
| 24 | + |
| 25 | +# Performs "clean build" type actions (deleting and remaking directories) |
| 26 | + |
| 27 | +clean() |
| 28 | +{ |
| 29 | + echo Cleaning previous output for the selected configuration |
| 30 | + rm -rf "$__BinDir" |
| 31 | + rm -rf "$__IntermediatesDir" |
| 32 | + |
| 33 | + rm -rf "$__TestWorkingDir" |
| 34 | + rm -rf "$__TestIntermediatesDir" |
| 35 | + |
| 36 | + rm -rf "$__LogsDir/*_$__BuildOS__$__BuildArch__$__BuildType.*" |
| 37 | +} |
| 38 | + |
| 39 | +# Check the system to ensure the right pre-reqs are in place |
| 40 | + |
| 41 | +check_prereqs() |
| 42 | +{ |
| 43 | + echo "Checking pre-requisites..." |
| 44 | + |
| 45 | + # Check presence of CMake on the path |
| 46 | + hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } |
| 47 | + |
| 48 | + # Check for clang |
| 49 | + hash clang-$__ClangMajorVersion.$__ClangMinorVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang before running this script"; exit 1; } |
| 50 | + |
| 51 | +} |
| 52 | + |
| 53 | +build_coreclr() |
| 54 | +{ |
| 55 | + # All set to commence the build |
| 56 | + |
| 57 | + echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType" |
| 58 | + cd "$__IntermediatesDir" |
| 59 | + |
| 60 | + # Regenerate the CMake solution |
| 61 | + echo "Invoking cmake with arguments: \"$__ProjectRoot\" $__CMakeArgs" |
| 62 | + "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__CMakeArgs |
| 63 | + |
| 64 | + # Check that the makefiles were created. |
| 65 | + |
| 66 | + if [ ! -f "$__IntermediatesDir/Makefile" ]; then |
| 67 | + echo "Failed to generate native component build project!" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + |
| 71 | + # Get the number of processors available to the scheduler |
| 72 | + # Other techniques such as `nproc` only get the number of |
| 73 | + # processors available to a single process. |
| 74 | + if [ `uname` = "FreeBSD" ]; then |
| 75 | + NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'` |
| 76 | + else |
| 77 | + NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) |
| 78 | + fi |
| 79 | + |
| 80 | + # Build CoreCLR |
| 81 | + |
| 82 | + echo "Executing make install -j $NumProc $__UnprocessedBuildArgs" |
| 83 | + |
| 84 | + make install -j $NumProc $__UnprocessedBuildArgs |
| 85 | + if [ $? != 0 ]; then |
| 86 | + echo "Failed to build coreclr components." |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +} |
| 90 | + |
| 91 | +echo "Commencing CoreCLR Repo build" |
| 92 | + |
| 93 | +# Argument types supported by this script: |
| 94 | +# |
| 95 | +# Build architecture - valid value is: x64. |
| 96 | +# Build Type - valid values are: Debug, Release |
| 97 | +# |
| 98 | +# Set the default arguments for build |
| 99 | + |
| 100 | +# Obtain the location of the bash script to figure out whether the root of the repo is. |
| 101 | +__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 102 | +__BuildArch=x64 |
| 103 | +# Use uname to determine what the OS is. |
| 104 | +OSName=$(uname -s) |
| 105 | +case $OSName in |
| 106 | + Linux) |
| 107 | + __BuildOS=Linux |
| 108 | + ;; |
| 109 | + |
| 110 | + Darwin) |
| 111 | + __BuildOS=OSX |
| 112 | + ;; |
| 113 | + |
| 114 | + FreeBSD) |
| 115 | + __BuildOS=FreeBSD |
| 116 | + ;; |
| 117 | + |
| 118 | + OpenBSD) |
| 119 | + __BuildOS=OpenBSD |
| 120 | + ;; |
| 121 | + |
| 122 | + NetBSD) |
| 123 | + __BuildOS=NetBSD |
| 124 | + ;; |
| 125 | + |
| 126 | + *) |
| 127 | + echo "Unsupported OS $OSName detected, configuring as if for Linux" |
| 128 | + __BuildOS=Linux |
| 129 | + ;; |
| 130 | +esac |
| 131 | +__MSBuildBuildArch=x64 |
| 132 | +__BuildType=Debug |
| 133 | +__CMakeArgs=DEBUG |
| 134 | + |
| 135 | +# Set the various build properties here so that CMake and MSBuild can pick them up |
| 136 | +__ProjectDir="$__ProjectRoot" |
| 137 | +__SourceDir="$__ProjectDir/src" |
| 138 | +__PackagesDir="$__ProjectDir/packages" |
| 139 | +__RootBinDir="$__ProjectDir/bin" |
| 140 | +__LogsDir="$__RootBinDir/Logs" |
| 141 | +__UnprocessedBuildArgs= |
| 142 | +__MSBCleanBuildArgs= |
| 143 | +__CleanBuild=false |
| 144 | +__VerboseBuild=false |
| 145 | +__ClangMajorVersion=3 |
| 146 | +__ClangMinorVersion=5 |
| 147 | + |
| 148 | +for i in "$@" |
| 149 | + do |
| 150 | + lowerI="$(echo $i | awk '{print tolower($0)}')" |
| 151 | + case $lowerI in |
| 152 | + -?|-h|--help) |
| 153 | + usage |
| 154 | + exit 1 |
| 155 | + ;; |
| 156 | + x64) |
| 157 | + __BuildArch=x64 |
| 158 | + __MSBuildBuildArch=x64 |
| 159 | + ;; |
| 160 | + debug) |
| 161 | + __BuildType=Debug |
| 162 | + ;; |
| 163 | + release) |
| 164 | + __BuildType=Release |
| 165 | + __CMakeArgs=RELEASE |
| 166 | + ;; |
| 167 | + clean) |
| 168 | + __CleanBuild=1 |
| 169 | + ;; |
| 170 | + verbose) |
| 171 | + __VerboseBuild=1 |
| 172 | + ;; |
| 173 | + clang3.5) |
| 174 | + __ClangMajorVersion=3 |
| 175 | + __ClangMinorVersion=5 |
| 176 | + ;; |
| 177 | + clang3.6) |
| 178 | + __ClangMajorVersion=3 |
| 179 | + __ClangMinorVersion=6 |
| 180 | + ;; |
| 181 | + clang3.7) |
| 182 | + __ClangMajorVersion=3 |
| 183 | + __ClangMinorVersion=7 |
| 184 | + ;; |
| 185 | + *) |
| 186 | + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i" |
| 187 | + esac |
| 188 | +done |
| 189 | + |
| 190 | +# Set the remaining variables based upon the determined build configuration |
| 191 | +__BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType" |
| 192 | +__PackagesBinDir="$__BinDir/.nuget" |
| 193 | +__ToolsDir="$__RootBinDir/tools" |
| 194 | +__TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType" |
| 195 | +__IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType" |
| 196 | +__TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType" |
| 197 | + |
| 198 | +# Specify path to be set for CMAKE_INSTALL_PREFIX. |
| 199 | +# This is where all built CoreClr libraries will copied to. |
| 200 | +export __CMakeBinDir="$__BinDir" |
| 201 | + |
| 202 | +# Configure environment if we are doing a clean build. |
| 203 | +if [ $__CleanBuild == 1 ]; then |
| 204 | + clean |
| 205 | +fi |
| 206 | + |
| 207 | +# Configure environment if we are doing a verbose build |
| 208 | +if [ $__VerboseBuild == 1 ]; then |
| 209 | + export VERBOSE=1 |
| 210 | +fi |
| 211 | + |
| 212 | +# Make the directories necessary for build if they don't exist |
| 213 | + |
| 214 | +setup_dirs |
| 215 | + |
| 216 | +# Check prereqs. |
| 217 | + |
| 218 | +check_prereqs |
| 219 | + |
| 220 | +# Build the coreclr (native) components. |
| 221 | + |
| 222 | +build_coreclr |
| 223 | + |
| 224 | +# Build complete |
| 225 | + |
| 226 | +echo "Repo successfully built." |
| 227 | +echo "Product binaries are available at $__BinDir" |
| 228 | +exit 0 |
0 commit comments