From ca92730e1860119c95b7699de878f603b793136b Mon Sep 17 00:00:00 2001 From: dotnet-bot Date: Tue, 21 Jul 2015 14:33:46 -0700 Subject: [PATCH] Copy build scripts from dotnet/coreclr Commit migrated from https://github.com/dotnet/corefx/commit/1f42d12ea7898b9dbd46bb454d05de0eed65e36b --- src/libraries/Native/build.sh | 228 +++++++++++++++++++++ src/libraries/Native/gen-buildsys-clang.sh | 115 +++++++++++ 2 files changed, 343 insertions(+) create mode 100755 src/libraries/Native/build.sh create mode 100755 src/libraries/Native/gen-buildsys-clang.sh diff --git a/src/libraries/Native/build.sh b/src/libraries/Native/build.sh new file mode 100755 index 00000000000..fe5577cba48 --- /dev/null +++ b/src/libraries/Native/build.sh @@ -0,0 +1,228 @@ +#!/usr/bin/env bash + +usage() +{ + echo "Usage: $0 [BuildArch] [BuildType] [clean] [verbose] [clangx.y]" + echo "BuildArch can be: x64" + echo "BuildType can be: Debug, Release" + echo "clean - optional argument to force a clean build." + echo "verbose - optional argument to enable verbose build output." + echo "clangx.y - optional argument to build using clang version x.y." + + exit 1 +} + +setup_dirs() +{ + echo Setting up directories for build + + mkdir -p "$__RootBinDir" + mkdir -p "$__BinDir" + mkdir -p "$__LogsDir" + mkdir -p "$__IntermediatesDir" +} + +# Performs "clean build" type actions (deleting and remaking directories) + +clean() +{ + echo Cleaning previous output for the selected configuration + rm -rf "$__BinDir" + rm -rf "$__IntermediatesDir" + + rm -rf "$__TestWorkingDir" + rm -rf "$__TestIntermediatesDir" + + rm -rf "$__LogsDir/*_$__BuildOS__$__BuildArch__$__BuildType.*" +} + +# Check the system to ensure the right pre-reqs are in place + +check_prereqs() +{ + echo "Checking pre-requisites..." + + # Check presence of CMake on the path + hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } + + # Check for clang + 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; } + +} + +build_coreclr() +{ + # All set to commence the build + + echo "Commencing build of native components for $__BuildOS.$__BuildArch.$__BuildType" + cd "$__IntermediatesDir" + + # Regenerate the CMake solution + echo "Invoking cmake with arguments: \"$__ProjectRoot\" $__CMakeArgs" + "$__ProjectRoot/src/pal/tools/gen-buildsys-clang.sh" "$__ProjectRoot" $__ClangMajorVersion $__ClangMinorVersion $__CMakeArgs + + # Check that the makefiles were created. + + if [ ! -f "$__IntermediatesDir/Makefile" ]; then + echo "Failed to generate native component build project!" + exit 1 + fi + + # Get the number of processors available to the scheduler + # Other techniques such as `nproc` only get the number of + # processors available to a single process. + if [ `uname` = "FreeBSD" ]; then + NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'` + else + NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) + fi + + # Build CoreCLR + + echo "Executing make install -j $NumProc $__UnprocessedBuildArgs" + + make install -j $NumProc $__UnprocessedBuildArgs + if [ $? != 0 ]; then + echo "Failed to build coreclr components." + exit 1 + fi +} + +echo "Commencing CoreCLR Repo build" + +# Argument types supported by this script: +# +# Build architecture - valid value is: x64. +# Build Type - valid values are: Debug, Release +# +# Set the default arguments for build + +# Obtain the location of the bash script to figure out whether the root of the repo is. +__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +__BuildArch=x64 +# Use uname to determine what the OS is. +OSName=$(uname -s) +case $OSName in + Linux) + __BuildOS=Linux + ;; + + Darwin) + __BuildOS=OSX + ;; + + FreeBSD) + __BuildOS=FreeBSD + ;; + + OpenBSD) + __BuildOS=OpenBSD + ;; + + NetBSD) + __BuildOS=NetBSD + ;; + + *) + echo "Unsupported OS $OSName detected, configuring as if for Linux" + __BuildOS=Linux + ;; +esac +__MSBuildBuildArch=x64 +__BuildType=Debug +__CMakeArgs=DEBUG + +# Set the various build properties here so that CMake and MSBuild can pick them up +__ProjectDir="$__ProjectRoot" +__SourceDir="$__ProjectDir/src" +__PackagesDir="$__ProjectDir/packages" +__RootBinDir="$__ProjectDir/bin" +__LogsDir="$__RootBinDir/Logs" +__UnprocessedBuildArgs= +__MSBCleanBuildArgs= +__CleanBuild=false +__VerboseBuild=false +__ClangMajorVersion=3 +__ClangMinorVersion=5 + +for i in "$@" + do + lowerI="$(echo $i | awk '{print tolower($0)}')" + case $lowerI in + -?|-h|--help) + usage + exit 1 + ;; + x64) + __BuildArch=x64 + __MSBuildBuildArch=x64 + ;; + debug) + __BuildType=Debug + ;; + release) + __BuildType=Release + __CMakeArgs=RELEASE + ;; + clean) + __CleanBuild=1 + ;; + verbose) + __VerboseBuild=1 + ;; + clang3.5) + __ClangMajorVersion=3 + __ClangMinorVersion=5 + ;; + clang3.6) + __ClangMajorVersion=3 + __ClangMinorVersion=6 + ;; + clang3.7) + __ClangMajorVersion=3 + __ClangMinorVersion=7 + ;; + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $i" + esac +done + +# Set the remaining variables based upon the determined build configuration +__BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType" +__PackagesBinDir="$__BinDir/.nuget" +__ToolsDir="$__RootBinDir/tools" +__TestWorkingDir="$__RootBinDir/tests/$__BuildOS.$__BuildArch.$__BuildType" +__IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType" +__TestIntermediatesDir="$__RootBinDir/tests/obj/$__BuildOS.$__BuildArch.$__BuildType" + +# Specify path to be set for CMAKE_INSTALL_PREFIX. +# This is where all built CoreClr libraries will copied to. +export __CMakeBinDir="$__BinDir" + +# Configure environment if we are doing a clean build. +if [ $__CleanBuild == 1 ]; then + clean +fi + +# Configure environment if we are doing a verbose build +if [ $__VerboseBuild == 1 ]; then + export VERBOSE=1 +fi + +# Make the directories necessary for build if they don't exist + +setup_dirs + +# Check prereqs. + +check_prereqs + +# Build the coreclr (native) components. + +build_coreclr + +# Build complete + +echo "Repo successfully built." +echo "Product binaries are available at $__BinDir" +exit 0 diff --git a/src/libraries/Native/gen-buildsys-clang.sh b/src/libraries/Native/gen-buildsys-clang.sh new file mode 100755 index 00000000000..91ac5c821a0 --- /dev/null +++ b/src/libraries/Native/gen-buildsys-clang.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# +# This file invokes cmake and generates the build system for gcc. +# + +if [ $# -lt 3 -o $# -gt 4 ] +then + echo "Usage..." + echo "gen-buildsys-clang.sh [build flavor]" + echo "Specify the path to the top level CMake file - /src/NDP" + echo "Specify the clang version to use, split into major and minor version" + echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG." + exit 1 +fi + +# Set up the environment to be used for building with clang. +if which "clang-$2.$3" > /dev/null 2>&1 + then + export CC="$(which clang-$2.$3)" + export CXX="$(which clang++-$2.$3)" +elif which "clang$2$3" > /dev/null 2>&1 + then + export CC="$(which clang$2$3)" + export CXX="$(which clang++$2$3)" +elif which clang > /dev/null 2>&1 + then + export CC="$(which clang)" + export CXX="$(which clang++)" +else + echo "Unable to find Clang Compiler" + exit 1 +fi + +# Possible build types are DEBUG, RELEASE, RELWITHDEBINFO, MINSIZEREL. +# Default to DEBUG +if [ -z "$4" ] +then + echo "Defaulting to DEBUG build." + buildtype="DEBUG" +else + buildtype="$4" +fi + +OS=`uname` + +# Locate llvm +# This can be a little complicated, because the common use-case of Ubuntu with +# llvm-3.5 installed uses a rather unusual llvm installation with the version +# number postfixed (i.e. llvm-ar-3.5), so we check for that first. +# On FreeBSD the version number is appended without point and dash (i.e. +# llvm-ar35). +# Additionally, OSX doesn't use the llvm- prefix. +if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" ]; then + llvm_prefix="llvm-" +elif [ $OS = "Darwin" ]; then + llvm_prefix="" +else + echo "Unable to determine build platform" + exit 1 +fi + +desired_llvm_major_version=$2 +desired_llvm_minor_version=$3 +if [ $OS = "FreeBSD" ]; then + desired_llvm_version="$desired_llvm_major_version$desired_llvm_minor_version" +elif [ $OS = "OpenBSD" ]; then + desired_llvm_version="" +elif [ $OS = "NetBSD" ]; then + desired_llvm_version="" +else + desired_llvm_version="-$desired_llvm_major_version.$desired_llvm_minor_version" +fi +locate_llvm_exec() { + if which "$llvm_prefix$1$desired_llvm_version" > /dev/null 2>&1 + then + echo "$(which $llvm_prefix$1$desired_llvm_version)" + elif which "$llvm_prefix$1" > /dev/null 2>&1 + then + echo "$(which $llvm_prefix$1)" + else + exit 1 + fi +} + +llvm_ar="$(locate_llvm_exec ar)" +[[ $? -eq 0 ]] || { echo "Unable to locate llvm-ar"; exit 1; } +llvm_link="$(locate_llvm_exec link)" +[[ $? -eq 0 ]] || { echo "Unable to locate llvm-link"; exit 1; } +llvm_nm="$(locate_llvm_exec nm)" +[[ $? -eq 0 ]] || { echo "Unable to locate llvm-nm"; exit 1; } +llvm_ranlib="$(locate_llvm_exec ranlib)" +[[ $? -eq 0 ]] || { echo "Unable to locate llvm-ranlib"; exit 1; } +if [ $OS = "Linux" -o $OS = "FreeBSD" -o $OS = "OpenBSD" -o $OS = "NetBSD" ]; then + llvm_objdump="$(locate_llvm_exec objdump)" + [[ $? -eq 0 ]] || { echo "Unable to locate llvm-objdump"; exit 1; } +fi + +cmake_extra_defines= +if [[ -n "$LLDB_LIB_DIR" ]]; then + cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_LIBS=$LLDB_LIB_DIR" +fi +if [[ -n "$LLDB_INCLUDE_DIR" ]]; then + cmake_extra_defines="$cmake_extra_defines -DWITH_LLDB_INCLUDES=$LLDB_INCLUDE_DIR" +fi + +cmake \ + "-DCMAKE_USER_MAKE_RULES_OVERRIDE=$1/src/pal/tools/clang-compiler-override.txt" \ + "-DCMAKE_AR=$llvm_ar" \ + "-DCMAKE_LINKER=$llvm_link" \ + "-DCMAKE_NM=$llvm_nm" \ + "-DCMAKE_OBJDUMP=$llvm_objdump" \ + "-DCMAKE_RANLIB=$llvm_ranlib" \ + "-DCMAKE_BUILD_TYPE=$buildtype" \ + $cmake_extra_defines \ + "$1" -- GitLab