]> git.proxmox.com Git - libgit2.git/blob - ci/build.sh
5a51f925ad0a602cf6278d095840477782b81b1a
[libgit2.git] / ci / build.sh
1 #!/usr/bin/env bash
2 #
3 # Environment variables:
4 #
5 # SOURCE_DIR: Set to the directory of the libgit2 source (optional)
6 # If not set, it will be derived relative to this script.
7
8 set -e
9
10 SOURCE_DIR=${SOURCE_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" && dirname $( pwd ) )}
11 BUILD_DIR=$(pwd)
12 BUILD_PATH=${BUILD_PATH:=$PATH}
13 CMAKE=$(which cmake)
14 CMAKE_GENERATOR=${CMAKE_GENERATOR:-Unix Makefiles}
15
16 if [[ "$(uname -s)" == MINGW* ]]; then
17 BUILD_PATH=$(cygpath "$BUILD_PATH")
18 fi
19
20 indent() { sed "s/^/ /"; }
21
22 echo "Source directory: ${SOURCE_DIR}"
23 echo "Build directory: ${BUILD_DIR}"
24 echo ""
25
26 if [ "$(uname -s)" = "Darwin" ]; then
27 echo "macOS version:"
28 sw_vers | indent
29 fi
30
31 if [ -f "/etc/debian_version" ]; then
32 echo "Debian version:"
33 (source /etc/lsb-release && echo "${DISTRIB_DESCRIPTION}") | indent
34 fi
35
36 CORES=$(getconf _NPROCESSORS_ONLN || true)
37 echo "Number of cores: ${CORES:-(Unknown)}"
38
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 "${CC}" --version 2>&1 | indent
48 fi
49 echo "Environment:"
50 if test -n "${CC}"; then
51 echo "CC=${CC}" | indent
52 fi
53 if test -n "${CFLAGS}"; then
54 echo "CFLAGS=${CFLAGS}" | indent
55 fi
56 echo ""
57
58 echo "##############################################################################"
59 echo "## Configuring build environment"
60 echo "##############################################################################"
61
62 echo cmake -DENABLE_WERROR=ON -DBUILD_EXAMPLES=ON -DBUILD_FUZZERS=ON -DUSE_STANDALONE_FUZZERS=ON -G \"${CMAKE_GENERATOR}\" ${CMAKE_OPTIONS} -S \"${SOURCE_DIR}\"
63 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 echo ""
66 echo "##############################################################################"
67 echo "## Building libgit2"
68 echo "##############################################################################"
69
70 # Determine parallelism; newer cmake supports `--build --parallel` but
71 # we cannot yet rely on that.
72 if [ "${CMAKE_GENERATOR}" = "Unix Makefiles" -a "${CORES}" != "" ]; then
73 BUILDER=(make -j ${CORES})
74 else
75 BUILDER=("${CMAKE}" --build .)
76 fi
77
78 env PATH="${BUILD_PATH}" "${BUILDER[@]}"