Inside Bitcoin
Opening the selected file…
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.
1Each recipe consists of 3 main parts: defining identifiers, setting build2variables, and defining build commands.4The package "mylib" will be used here as an example6General tips:7- mylib_foo is written as $(package)_foo in order to make recipes more similar.8- Secondary dependency packages relative to the bitcoin binaries/libraries (i.e.9those not in `ALLOWED_LIBRARIES` in `contrib/guix/symbol-check.py`) don't10need to be shared and should be built statically whenever possible. See11[below](#secondary-dependencies) for more details.13## Identifiers14If package does not define a `$(package)_local_dir` variable, it is required to15define these variables:17$(package)_version:18Version of the upstream library or program. If there is no version, a19placeholder such as 1.0 can be used.21$(package)_download_path:22Location of the upstream source, without the file-name. Usually http, https23or ftp. Secure transmission options like https should be preferred if24available.26$(package)_file_name:27The upstream source filename available at the download path.29$(package)_sha256_hash:30The sha256 hash of the upstream file32If a package does define a `$(package)_local_dir` variable, the above variables33are not required and will be ignored.35These variables are optional:37$(package)_build_subdir:38cd to this dir before running configure/build/stage commands.40$(package)_download_file:41The file-name of the upstream source if it differs from how it should be42stored locally. This can be used to avoid storing file-names with strange43characters.45$(package)_dependencies:46Names of any other packages that this one depends on.48$(package)_patches:49Filenames of any patches needed to build the package51$(package)_extra_sources:52Any extra files that will be fetched via $(package)_fetch_cmds. These are53specified so that they can be fetched and verified via 'make download'.55## Local packages57If a package defines a `$(package)_local_dir` variable, the specified directory58will be treated as a download source, and a tarball of its contents will be59saved to `sources/`. A hash of the tarball will also become part of the package60build id, so if the directory contents change, the package and everything61depending on it will be rebuilt. For efficiency, the tarball is cached once it62has been created, but if the local directory is touched, it will be rebuilt.64Local packages can be useful for using git submodules or subtrees to manage65package sources, or for testing local changes that are not available to66download from an external source.68## Build Variables:69After defining the main identifiers, build variables may be added or customized70before running the build commands. They should be added to a function called71$(package)_set_vars. For example:73define $(package)_set_vars74...75endef77Most variables can be prefixed with the host, architecture, or both, to make78the modifications specific to that case. For example:80Universal: $(package)_cc=gcc81Linux only: $(package)_linux_cc=gcc82x86_64 only: $(package)_x86_64_cc = gcc83x86_64 linux only: $(package)_x86_64_linux_cc = gcc85These variables may be set to override or append their default values.87$(package)_cc88$(package)_cxx89$(package)_objc90$(package)_objcxx91$(package)_ar92$(package)_ranlib93$(package)_nm94$(package)_cflags95$(package)_cxxflags96$(package)_ldflags97$(package)_cppflags98$(package)_config_env99$(package)_build_env100$(package)_stage_env101$(package)_build_opts102$(package)_config_opts104The *_env variables are used to add environment variables to the respective105commands.107Many variables respect a debug/release suffix as well, in order to use them for108only the appropriate build config. For example:110$(package)_cflags_release = -O3111$(package)_cflags_i686_debug = -g112$(package)_config_opts_release = --disable-debug114These will be used in addition to the options that do not specify115debug/release. All builds are considered to be release unless DEBUG=1 is set by116the user. Other variables may be defined as needed.118## Build commands:120For each build, a unique build dir and staging dir are created. For example,121`work/build/mylib/1.0-1adac830f6e` and `work/staging/mylib/1.0-1adac830f6e`.123The following build commands are available for each recipe:125$(package)_fetch_cmds:126Runs from: build dir127Fetch the source file. If undefined, it will be fetched and verified128against its hash.130$(package)_extract_cmds:131Runs from: build dir132Verify the source file against its hash and extract it. If undefined, the133source is assumed to be a tarball.135$(package)_preprocess_cmds:136Runs from: build dir/$(package)_build_subdir137Preprocess the source as necessary. If undefined, does nothing.139$(package)_config_cmds:140Runs from: build dir/$(package)_build_subdir141Configure the source. If undefined, does nothing.143$(package)_build_cmds:144Runs from: build dir/$(package)_build_subdir145Build the source. If undefined, does nothing.147$(package)_stage_cmds:148Runs from: build dir/$(package)_build_subdir149Stage the build results. If undefined, does nothing.151The following variables are available for each recipe:153$(1)_staging_dir: package's destination sysroot path154$(1)_staging_prefix_dir: prefix path inside of the package's staging dir155$(1)_extract_dir: path to the package's extracted sources156$(1)_build_dir: path where configure/build/stage commands will be run157$(1)_patch_dir: path where the package's patches (if any) are found159Notes on build commands:161For packages built with autotools, $($(package)_autoconf) can be used in the162configure step to (usually) correctly configure automatically. Any163$($(package)_config_opts) will be appended.165Most autotools projects can be properly staged using:167$(MAKE) DESTDIR=$($(package)_staging_dir) install169## Build outputs:171In general, the output of a depends package should not contain any libtool172archives or `.pc` (`pkg-config`) files. Instead, the package should output173`.cmake` (CMake) files where possible.175From the [Gentoo Wiki entry](https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Handling_Libtool_Archives):177> Libtool pulls in all direct and indirect dependencies into the .la files it178> creates. This leads to massive overlinking, which is toxic to the Gentoo179> ecosystem, as it leads to a massive number of unnecessary rebuilds.181Where possible, packages are built with Position Independent Code. Either using182the Autotools `--with-pic` flag, or `CMAKE_POSITION_INDEPENDENT_CODE` with CMake.184## Secondary dependencies:186Secondary dependency packages relative to the bitcoin binaries/libraries (i.e.187those not in `ALLOWED_LIBRARIES` in `contrib/guix/symbol-check.py`) don't188need to be shared and should be built statically whenever possible. This189improves general build reliability as illustrated by the following example:191When linking an executable against a shared library `libprimary` that has its192own shared dependency `libsecondary`, we may need to specify the path to193`libsecondary` on the link command using the `-rpath/-rpath-link` options, it is194not sufficient to just say `libprimary`.196For us, it's much easier to just link a static `libsecondary` into a shared197`libprimary`. Especially because in our case, we are linking against a dummy198`libprimary` anyway that we'll throw away. We don't care if the end-user has a199static or dynamic `libsecondary`, that's not our concern. With a static200`libsecondary`, when we need to link `libprimary` into our executable, there's no201dependency chain to worry about as `libprimary` has all the symbols.203## Build targets:205To build an individual package (useful for debugging), following build targets are available.207make ${package}208make ${package}_fetched209make ${package}_extracted210make ${package}_preprocessed211make ${package}_configured212make ${package}_built213make ${package}_staged214make ${package}_postprocessed215make ${package}_cached216make ${package}_cached_checksum
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.