1 #!/usr/bin/env bash
2 # Copyright (c) The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or https://opensource.org/license/mit.
5 export LC_ALL=C
6 set -e -o pipefail
7 8 # Environment variables for determinism
9 export TAR_OPTIONS="--no-same-owner --owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"
10 export TZ=UTC
11 12 # Although Guix _does_ set umask when building its own packages (in our case,
13 # this is all packages in manifest.scm), it does not set it for `guix
14 # shell`. It does make sense for at least `guix shell --container`
15 # to set umask, so if that change gets merged upstream and we bump the
16 # time-machine to a commit which includes the aforementioned change, we can
17 # remove this line.
18 #
19 # This line should be placed before any commands which creates files.
20 umask 0022
21 22 if [ -n "$V" ]; then
23 # Print both unexpanded (-v) and expanded (-x) forms of commands as they are
24 # read from this file.
25 set -vx
26 # Set VERBOSE for CMake-based builds
27 export VERBOSE="$V"
28 fi
29 30 # Check that required environment variables are set
31 cat << EOF
32 Required environment variables as seen inside the container:
33 DIST_ARCHIVE_BASE: ${DIST_ARCHIVE_BASE:?not set}
34 DISTNAME: ${DISTNAME:?not set}
35 HOST: ${HOST:?not set}
36 SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH:?not set}
37 JOBS: ${JOBS:?not set}
38 DISTSRC: ${DISTSRC:?not set}
39 OUTDIR: ${OUTDIR:?not set}
40 EOF
41 42 export ACTUAL_OUTDIR="${OUTDIR}"
43 export OUTDIR="${DISTSRC}/output"
44 export INSTALLPATH="${DISTSRC}/installed/${DISTNAME}"
45 46 #####################
47 # Environment Setup #
48 #####################
49 50 # The depends folder also serves as a base-prefix for depends packages for
51 # $HOSTs after successfully building.
52 export BASEPREFIX="${PWD}/depends"
53 54 # Given a package name and an output name, return the path of that output in our
55 # current guix environment
56 store_path() {
57 grep --extended-regexp "/[^-]{32}-${1}-[^-]+${2:+-${2}}" "${GUIX_ENVIRONMENT}/manifest" \
58 | head --lines=1 \
59 | sed --expression='s|\x29*$||' \
60 --expression='s|^[[:space:]]*"||' \
61 --expression='s|"[[:space:]]*$||'
62 }
63 64 # Disable Guix ld auto-rpath behavior
65 export GUIX_LD_WRAPPER_DISABLE_RPATH=yes
66 67 # Make /usr/bin if it doesn't exist
68 [ -e /usr/bin ] || mkdir -p /usr/bin
69 70 # Symlink env to a conventional path
71 [ -e /usr/bin/env ] || ln -s --no-dereference "$(command -v env)" /usr/bin/env
72 73 ###########################
74 # Source Tarball Building #
75 ###########################
76 77 GIT_ARCHIVE="${DIST_ARCHIVE_BASE}/${DISTNAME}.tar.gz"
78 79 # Create the source tarball if not already there
80 if [ ! -e "$GIT_ARCHIVE" ]; then
81 mkdir -p "$(dirname "$GIT_ARCHIVE")"
82 git archive --prefix="${DISTNAME}/" --output="$GIT_ARCHIVE" HEAD
83 fi
84 85 mkdir -p "$OUTDIR"
86 87 unset LIBRARY_PATH
88 unset CPATH
89 unset C_INCLUDE_PATH
90 unset CPLUS_INCLUDE_PATH
91 unset OBJC_INCLUDE_PATH
92 unset OBJCPLUS_INCLUDE_PATH
93