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 python32# Copyright (c) 2022-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5import os6import re7import subprocess8import sys9import tempfile10import argparse12BINARIES = [13'bin/bitcoin',14'bin/bitcoind',15'bin/bitcoin-cli',16'bin/bitcoin-tx',17'bin/bitcoin-wallet',18'bin/bitcoin-util',19'bin/bitcoin-qt',20]22parser = argparse.ArgumentParser(23formatter_class=argparse.RawDescriptionHelpFormatter,24)25parser.add_argument(26"-s",27"--skip-missing-binaries",28action="store_true",29default=False,30help="skip generation for binaries that are not found in the build path",31)32args = parser.parse_args()34# Paths to external utilities.35git = os.getenv('GIT', 'git')36help2man = os.getenv('HELP2MAN', 'help2man')38# If not otherwise specified, get top directory from git.39topdir = os.getenv('TOPDIR')40if not topdir:41r = subprocess.run([git, 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE, check=True, text=True)42topdir = r.stdout.rstrip()44# Get input and output directories.45builddir = os.getenv('BUILDDIR', os.path.join(topdir, 'build'))46mandir = os.getenv('MANDIR', os.path.join(topdir, 'doc/man'))48# Verify that all the required binaries are usable, and extract copyright49# message in a first pass.50versions = []51for relpath in BINARIES:52abspath = os.path.join(builddir, relpath)53# Prevent QT from emitting a localized version string for --version and --help54is_qt = relpath == "bin/bitcoin-qt"55try:56cmd_args = ["--version"]57if is_qt:58cmd_args.append("--lang=en")59r = subprocess.run([abspath, *cmd_args], stdout=subprocess.PIPE, check=True, text=True)60except IOError:61if(args.skip_missing_binaries):62print(f'{abspath} not found or not an executable. Skipping...', file=sys.stderr)63continue64else:65print(f'{abspath} not found or not an executable', file=sys.stderr)66sys.exit(1)67# take first line (which must contain version)68output = r.stdout.splitlines()[0]69# find the version e.g. v30.99.0-ce771726f3e770search = re.search(r"v[0-9]\S+", output)71assert search72verstr = search.group(0)73# remaining lines are copyright74copyright = r.stdout.split('\n')[1:]75assert copyright[0].startswith('Copyright (C)')77versions.append((abspath, verstr, copyright, is_qt))79if not versions:80print(f'No binaries found in {builddir}. Please ensure the binaries are present in {builddir}, or set another build path using the BUILDDIR env variable.')81sys.exit(1)83if any(verstr.endswith('-dirty') for (_, verstr, _, _) in versions):84print("WARNING: Binaries were built from a dirty tree.")85print('man pages generated from dirty binaries should NOT be committed.')86print('To properly generate man pages, please commit your changes (or discard them), rebuild, then run this script again.')87print()89with tempfile.NamedTemporaryFile('w', suffix='.h2m') as footer:90# Create copyright footer, and write it to a temporary include file.91# Copyright is the same for all binaries, so just use the first.92footer.write('[COPYRIGHT]\n')93footer.write('\n'.join(versions[0][2]).strip())94# Create SEE ALSO section95footer.write('\n[SEE ALSO]\n')96footer.write(', '.join(s.rpartition('/')[2] + '(1)' for s in BINARIES))97footer.write('\n')98footer.flush()100# Call the binaries through help2man to produce a manual page for each of them.101for (abspath, verstr, _, is_qt) in versions:102outname = os.path.join(mandir, os.path.basename(abspath) + '.1')103help_option = '--help-option=--help' + (' --lang=en' if is_qt else '')104print(f'Generating {outname}…')105subprocess.run([106help2man,107'-N',108'--version-string=' + verstr,109'--include=' + footer.name,110'-o', outname,111help_option,112abspath,113], check=True)
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.