build.sh 2.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#!/usr/bin/env bash
#
# Environment variables:
#
# SOURCE_DIR: Set to the directory of the libgit2 source (optional)
#     If not set, it will be derived relative to this script.

set -e

SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
BUILD_DIR=$(pwd)
12 13
BUILD_PATH=${BUILD_PATH:=$PATH}
CMAKE=$(which cmake)
14
CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}
15

16 17 18 19
if [[ "$(uname -s)" == MINGW* ]]; then
	BUILD_PATH=$(cygpath "$BUILD_PATH")
fi

20 21 22 23 24
indent() { sed "s/^/    /"; }

echo "Source directory: ${SOURCE_DIR}"
echo "Build directory:  ${BUILD_DIR}"
echo ""
25 26 27 28 29 30 31 32

if [ "$(uname -s)" = "Darwin" ]; then
	echo "macOS version:"
	sw_vers | indent
fi

if [ -f "/etc/debian_version" ]; then
	echo "Debian version:"
33
	(source /etc/lsb-release && echo "${DISTRIB_DESCRIPTION}") | indent
34 35
fi

36 37 38
CORES=$(getconf _NPROCESSORS_ONLN || true)
echo "Number of cores: ${CORES:-(Unknown)}"

39
echo "Kernel version:"
40
uname -a 2>&1 | indent
41

42
echo "CMake version:"
43
env PATH="${BUILD_PATH}" "${CMAKE}" --version 2>&1 | indent
44

45
if test -n "${CC}"; then
46
	echo "Compiler version:"
47 48 49 50 51 52 53 54
	"${CC}" --version 2>&1 | indent
fi
echo "Environment:"
if test -n "${CC}"; then
	echo "CC=${CC}" | indent
fi
if test -n "${CFLAGS}"; then
	echo "CFLAGS=${CFLAGS}" | indent
55
fi
56 57 58 59 60 61
echo ""

echo "##############################################################################"
echo "## Configuring build environment"
echo "##############################################################################"

62 63
echo cmake -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\"
env PATH="${BUILD_PATH}" "${CMAKE}" -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G "${CMAKE_GENERATOR}" ${CMAKE_OPTIONS} -S "${SOURCE_DIR}"
64 65 66 67 68 69

echo ""
echo "##############################################################################"
echo "## Building libgit2"
echo "##############################################################################"

70 71 72 73 74 75 76 77 78
# Determine parallelism; newer cmake supports `--build --parallel` but
# we cannot yet rely on that.
if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" ]; then
	BUILDER=(make -j ${CORES})
else
	BUILDER=("${CMAKE}" --build .)
fi

env PATH="${BUILD_PATH}" "${BUILDER[@]}"