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 bash3# Usage: env [ CC=... ] [ C_STANDARD=...] [ CXX=... ] [CXX_STANDARD=...] \4# [ CPPFLAGS=... ] [CFLAGS=...] [CXXFLAGS=...] [LDFLAGS=...] \5# [ AR=... ] [ NM=... ] [ RANLIB=... ] [ STRIP=... ] [ DEBUG=... ] \6# [ LTO=... ] ./gen_id [ID_SALT]...7#8# Prints to stdout a SHA256 hash representing the current toolset, used by9# depends/Makefile as a build id for caching purposes (detecting when the10# toolset has changed and the cache needs to be invalidated).11#12# If the DEBUG environment variable is non-empty and the system has `tee`13# available in its $PATH, the pre-image to the SHA256 hash will be printed to14# stderr. This is to help developers debug caching issues in depends.16# This script explicitly does not `set -e` because id determination is mostly17# opportunistic: it is fine that things fail, as long as they fail consistently.19# Command variables (CC/CXX/AR) which can be blank are invoked with `bash -c`,20# because the "command not found" error message printed by shells often include21# the line number, like so:22#23# ./depends/gen_id: line 43: --version: command not found24#25# By invoking with `bash -c`, we ensure that the line number is always 127(28# Redirect stderr to stdout29exec 2>&131# Unset SOURCE_DATE_EPOCH to prevent it from leaking into tool32# outputs and to maximize reuse of the built package cache.33unset SOURCE_DATE_EPOCH35echo "BEGIN ALL"37# Include any ID salts supplied via command line38echo "BEGIN ID SALT"39echo "$@"40echo "END ID SALT"42echo "BEGIN FLAGS"43echo "CPPFLAGS=${CPPFLAGS}"44echo "CFLAGS=${CFLAGS}"45echo "CXXFLAGS=${CXXFLAGS}"46echo "LDFLAGS=${LDFLAGS}"47echo "END FLAGS"49# GCC only prints COLLECT_LTO_WRAPPER when invoked with just "-v", but we want50# the information from "-v -E -" as well, so just include both.51echo "BEGIN CC"52bash -c "${CC} -v"53bash -c "${CC} -v -E -xc -o /dev/null - < /dev/null"54bash -c "${CC} -v -E -xobjective-c -o /dev/null - < /dev/null"55echo "C_STANDARD=${C_STANDARD}"56echo "END CC"58echo "BEGIN CXX"59bash -c "${CXX} -v"60bash -c "${CXX} -v -E -xc++ -o /dev/null - < /dev/null"61bash -c "${CXX} -v -E -xobjective-c++ -o /dev/null - < /dev/null"62echo "CXX_STANDARD=${CXX_STANDARD}"63echo "END CXX"65# We use lld when cross-compiling for macOS, and it's version should66# be tied to LLVM. However someone compiling with GCC and -fuse-ld=lld67# would not see a cache bust if the LLVM toolchain was updated.68echo "BEGIN lld"69bash -c "ld.lld --version"70echo "END lld"72echo "BEGIN mold"73bash -c "mold --version"74echo "END mold"76echo "BEGIN AR"77bash -c "${AR} --version"78env | grep '^AR_'79echo "END AR"81echo "BEGIN NM"82bash -c "${NM} --version"83env | grep '^NM_'84echo "END NM"86echo "BEGIN RANLIB"87bash -c "${RANLIB} --version"88env | grep '^RANLIB_'89echo "END RANLIB"91echo "BEGIN STRIP"92bash -c "${STRIP} --version"93env | grep '^STRIP_'94echo "END STRIP"96echo "BEGIN LTO"97echo "LTO=${LTO}"98echo "END LTO"100echo "END ALL"101) | if [ -n "$DEBUG" ] && command -v tee > /dev/null 2>&1; then102# When debugging and `tee` is available, output the preimage to stderr103# in addition to passing through stdin to stdout104tee >(cat 1>&2)105else106# Otherwise, passthrough stdin to stdout107cat108fi | ${SHA256SUM} - | cut -d' ' -f1
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.