1
+#!/usr/bin/env bash
2
+# SPDX-License-Identifier: GPL-3.0-or-later
3
+
4
+# Can’t do libunwind on ppc64le with musl, so skip it.
5
+[ "${BUILDARCH}" = "ppc64le" ] && exit 0
6
+
7
+# shellcheck source=packaging/makeself/functions.sh
8
+. "$(dirname "${0}")/../functions.sh" "${@}" || exit 1
9
+# Source of truth for all the packages we bundle in static builds
10
+. "$(dirname "${0}")/../bundled-packages.version"
11
+# shellcheck disable=SC2015
12
+[ "${GITHUB_ACTIONS}" = "true" ] && echo "::group::Building libunwind" || true
13
+
14
+export CFLAGS="${TUNING_FLAGS} -fno-lto -pipe"
15
+export CXXFLAGS="${CFLAGS}"
16
+export LDFLAGS="-static"
17
+export PKG_CONFIG="pkg-config --static"
18
+
19
+if [ -d "${NETDATA_MAKESELF_PATH}/tmp/libunwind" ]; then
20
+ rm -rf "${NETDATA_MAKESELF_PATH}/tmp/libunwind"
21
+fi
22
+
23
+cache="${NETDATA_SOURCE_PATH}/artifacts/cache/${BUILDARCH}/libunwind"
24
+
25
+if [ -d "${cache}" ]; then
26
+ echo "Found cached copy of build directory for libunwind, using it."
27
+ cp -a "${cache}/libunwind" "${NETDATA_MAKESELF_PATH}/tmp/"
28
+ CACHE_HIT=1
29
+else
30
+ echo "No cached copy of build directory for libunwind found, fetching sources instead."
31
+ run git clone "${LIBUNWIND_SOURCE}" "${NETDATA_MAKESELF_PATH}/tmp/libunwind"
32
+ cd "${NETDATA_MAKESELF_PATH}/tmp/libunwind" && run git checkout "${LIBUNWIND_VERSION}"
33
+ CACHE_HIT=0
34
+fi
35
+
36
+cd "${NETDATA_MAKESELF_PATH}/tmp/libunwind" || exit 1
37
+
38
+if [ "${CACHE_HIT:-0}" -eq 0 ]; then
39
+ run autoreconf -ivf
40
+
41
+ run ./configure \
42
+ --prefix=/libunwind-static \
43
+ --build="$(gcc -dumpmachine)" \
44
+ --disable-cxx-exceptions \
45
+ --disable-documentation \
46
+ --disable-tests \
47
+ --disable-shared \
48
+ --enable-static \
49
+ --disable-dependency-tracking
50
+
51
+ run make -j "$(nproc)"
52
+fi
53
+
54
+run make -j "$(nproc)" install
55
+
56
+store_cache libunwind "${NETDATA_MAKESELF_PATH}/tmp/libunwind"
57
+
58
+# shellcheck disable=SC2015
59
+[ "${GITHUB_ACTIONS}" = "true" ] && echo "::endgroup::" || true