Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env bash2# Copyright (c) The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or https://opensource.org/license/mit.5export LC_ALL=C.UTF-86set -o errexit -o pipefail8# Environment variables for determinism9export TAR_OPTIONS="--no-same-owner --owner=0 --group=0 --numeric-owner --mtime='@${SOURCE_DATE_EPOCH}' --sort=name"10export TZ=UTC12# 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 `guix14# 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 the16# time-machine to a commit which includes the aforementioned change, we can17# remove this line.18#19# This line should be placed before any commands which creates files.20umask 002222if [ -n "$V" ]; then23# Print both unexpanded (-v) and expanded (-x) forms of commands as they are24# read from this file.25set -vx26# Set VERBOSE for CMake-based builds27export VERBOSE="$V"28fi30# Check that required environment variables are set31cat << EOF32Required environment variables as seen inside the container:33DIST_ARCHIVE_BASE: ${DIST_ARCHIVE_BASE:?not set}34DISTNAME: ${DISTNAME:?not set}35HOST: ${HOST:?not set}36SOURCE_DATE_EPOCH: ${SOURCE_DATE_EPOCH:?not set}37JOBS: ${JOBS:?not set}38DISTSRC: ${DISTSRC:?not set}39OUTDIR: ${OUTDIR:?not set}40EOF42export ACTUAL_OUTDIR="${OUTDIR}"43export OUTDIR="${DISTSRC}/output"44export INSTALLPATH="${DISTSRC}/installed/${DISTNAME}"46#####################47# Environment Setup #48#####################50# The depends folder also serves as a base-prefix for depends packages for51# $HOSTs after successfully building.52export BASEPREFIX="${PWD}/depends"54# Given a package name and an output name, return the path of that output in our55# current guix environment56store_path() {57grep --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}64# Sanity check CROSS_*_PATH directories65check_cross_paths() {66local p paths67IFS=':' read -ra paths <<< "$1"68for p in "${paths[@]}"; do69if [ -n "$p" ] && [ ! -d "$p" ]; then70echo "'$p' doesn't exist or isn't a directory... Aborting..." >&271return 172fi73done74}76# Given a hostname, determine the correct value for -Wl,--dynamic-linker.77glibc_dynamic_linker() {78case "$1" in79x86_64-linux-gnu) echo /lib64/ld-linux-x86-64.so.2 ;;80arm-linux-gnueabihf) echo /lib/ld-linux-armhf.so.3 ;;81aarch64-linux-gnu) echo /lib/ld-linux-aarch64.so.1 ;;82riscv64-linux-gnu) echo /lib/ld-linux-riscv64-lp64d.so.1 ;;83powerpc64-linux-gnu) echo /lib64/ld64.so.1 ;;84powerpc64le-linux-gnu) echo /lib64/ld64.so.2 ;;85*) exit 1 ;;86esac87}89gcc_toolchain() {90# Set environment variables to point the NATIVE toolchain to the right91# includes/libs92local NATIVE_GCC NATIVE_GCC_STATIC CROSS_GLIBC CROSS_GLIBC_STATIC CROSS_KERNEL CROSS_GCC CROSS_GCC_LIB_STORE CROSS_GCC_LIBS CROSS_GCC_LIB94NATIVE_GCC="$(store_path gcc-toolchain)"96# Set native toolchain97export build_CC="${NATIVE_GCC}/bin/gcc -isystem ${NATIVE_GCC}/include"98export build_CXX="${NATIVE_GCC}/bin/g++ -isystem ${NATIVE_GCC}/include/c++ -isystem ${NATIVE_GCC}/include"100NATIVE_GCC_STATIC="$(store_path gcc-toolchain static)"101export LIBRARY_PATH="${NATIVE_GCC}/lib:${NATIVE_GCC_STATIC}/lib"103# Set environment variables to point the CROSS toolchain to the right104# includes/libs for $HOST105CROSS_GLIBC="$(store_path "glibc-cross-${HOST}")"106CROSS_GLIBC_STATIC="$(store_path "glibc-cross-${HOST}" static)"107CROSS_KERNEL="$(store_path "linux-libre-headers-cross-${HOST}")"108CROSS_GCC="$(store_path "gcc-cross-${HOST}")"109CROSS_GCC_LIB_STORE="$(store_path "gcc-cross-${HOST}" lib)"110CROSS_GCC_LIBS=( "${CROSS_GCC_LIB_STORE}/lib/gcc/${HOST}"/* ) # This expands to an array of directories...111CROSS_GCC_LIB="${CROSS_GCC_LIBS[0]}" # ...we just want the first one (there should only be one)113export CROSS_C_INCLUDE_PATH="${CROSS_GCC_LIB}/include:${CROSS_GCC_LIB}/include-fixed:${CROSS_GLIBC}/include:${CROSS_KERNEL}/include"114export CROSS_CPLUS_INCLUDE_PATH="${CROSS_GCC}/include/c++:${CROSS_GCC}/include/c++/${HOST}:${CROSS_GCC}/include/c++/backward:${CROSS_C_INCLUDE_PATH}"115export CROSS_LIBRARY_PATH="${CROSS_GCC_LIB_STORE}/lib:${CROSS_GCC_LIB}:${CROSS_GLIBC}/lib:${CROSS_GLIBC_STATIC}/lib"117check_cross_paths "${CROSS_C_INCLUDE_PATH}:${CROSS_CPLUS_INCLUDE_PATH}:${CROSS_LIBRARY_PATH}"118}120llvm_toolchain() {121local CLANG_TOOLCHAIN LIB_CXX123CLANG_TOOLCHAIN="$(store_path clang-toolchain)"124LIB_CXX="$(store_path libcxx)"126export build_CC="${CLANG_TOOLCHAIN}/bin/clang -isystem ${CLANG_TOOLCHAIN}/include"127export build_CXX="${CLANG_TOOLCHAIN}/bin/clang++ -stdlib=libc++ -isystem ${LIB_CXX}/include/c++/v1 -isystem ${CLANG_TOOLCHAIN}/include"128export build_LDFLAGS="-fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind -L${LIB_CXX}/lib -Wl,-rpath,${LIB_CXX}/lib"129export build_AR="${CLANG_TOOLCHAIN}/bin/llvm-ar"130export build_RANLIB="${CLANG_TOOLCHAIN}/bin/llvm-ranlib"131export build_OBJDUMP="${CLANG_TOOLCHAIN}/bin/llvm-objdump"132export build_NM="${CLANG_TOOLCHAIN}/bin/llvm-nm"133export build_STRIP="${CLANG_TOOLCHAIN}/bin/llvm-strip"134}136mingw_w64_toolchain() {137# Set environment variables to point the NATIVE toolchain to the right138# includes/libs139local NATIVE_GCC CROSS_GLIBC CROSS_GCC CROSS_GCC_LIB_STORE CROSS_GCC_LIBS CROSS_GCC_LIB141NATIVE_GCC="$(store_path gcc-toolchain)"143# Set native toolchain144export build_CC="${NATIVE_GCC}/bin/gcc -isystem ${NATIVE_GCC}/include"145export build_CXX="${NATIVE_GCC}/bin/g++ -isystem ${NATIVE_GCC}/include/c++ -isystem ${NATIVE_GCC}/include"147# Set environment variables to point the CROSS toolchain to the right148# includes/libs for $HOST149# Determine output paths to use in CROSS_* environment variables150CROSS_GLIBC="$(store_path "mingw-w64-x86_64-winpthreads")"151CROSS_GCC="$(store_path "gcc-cross-${HOST}")"152CROSS_GCC_LIB_STORE="$(store_path "gcc-cross-${HOST}" lib)"153CROSS_GCC_LIBS=( "${CROSS_GCC_LIB_STORE}/lib/gcc/${HOST}"/* ) # This expands to an array of directories...154CROSS_GCC_LIB="${CROSS_GCC_LIBS[0]}" # ...we just want the first one (there should only be one)156# The search path ordering is generally:157# 1. gcc-related search paths158# 2. libc-related search paths159# 2. kernel-header-related search paths (not applicable to mingw-w64 hosts)160export CROSS_C_INCLUDE_PATH="${CROSS_GCC_LIB}/include:${CROSS_GCC_LIB}/include-fixed:${CROSS_GLIBC}/include"161export CROSS_CPLUS_INCLUDE_PATH="${CROSS_GCC}/include/c++:${CROSS_GCC}/include/c++/${HOST}:${CROSS_GCC}/include/c++/backward:${CROSS_C_INCLUDE_PATH}"162export CROSS_LIBRARY_PATH="${CROSS_GCC_LIB_STORE}/lib:${CROSS_GCC_LIB}:${CROSS_GLIBC}/lib"164check_cross_paths "${CROSS_C_INCLUDE_PATH}:${CROSS_CPLUS_INCLUDE_PATH}:${CROSS_LIBRARY_PATH}"165}167# Disable Guix ld auto-rpath behavior168export GUIX_LD_WRAPPER_DISABLE_RPATH=yes170# Make /usr/bin if it doesn't exist171[ -e /usr/bin ] || mkdir -p /usr/bin173# Symlink env to a conventional path174[ -e /usr/bin/env ] || ln -s --no-dereference "$(command -v env)" /usr/bin/env176###########################177# Source Tarball Building #178###########################180GIT_ARCHIVE="${DIST_ARCHIVE_BASE}/${DISTNAME}.tar.gz"182# Create the source tarball if not already there183if [ ! -e "$GIT_ARCHIVE" ]; then184mkdir -p "$(dirname "$GIT_ARCHIVE")"185git archive --prefix="${DISTNAME}/" --output="$GIT_ARCHIVE" HEAD186fi188mkdir -p "$OUTDIR"190unset LIBRARY_PATH191unset CPATH192unset C_INCLUDE_PATH193unset CPLUS_INCLUDE_PATH194unset OBJC_INCLUDE_PATH195unset OBJCPLUS_INCLUDE_PATH
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.