Build Configuration and Packaging
Overview
This area owns BFGMiner's autotools build, generated version metadata, release packaging, platform-specific package recipes, and operator-facing setup documentation. The build begins with autogen.sh, which initializes git submodules unless NOSUBMODULES is set, clears stale autotools cache files, runs autoreconf -if, and refreshes version.h through gen-version.sh. gen-version.sh derives BFG_GIT_DESCRIBE from git describe when a git tree is available, falls back to the existing version.h, and finally emits VERSION for version.c; version.c exposes the package/version strings consumed by the program.
configure.ac is the central feature matrix. It defines the package version, emits config.h, selects platform traits for Windows, Cygwin, Darwin, and x86 bitness, and turns configure options into USE_*, NEED_*, and HAVE_* automake conditionals. The BFG_ALGO and BFG_DRIVER macros encode algorithm and driver defaults plus dependency chains: for example SHA256d is enabled by default, Keccak and scrypt are opt-in, many ASIC/FPGA drivers default to auto/on, while CPU mining, OpenCL, Bitmain, KnC, Titan, and several specialist drivers are disabled by default. The same file probes required libraries such as libcurl, jansson, pthreads, and uthash; optional interfaces such as curses, libusb, libudev, hidapi, libevent, libmicrohttpd, sensors, VFIO/UIO, i2c, yasm, and SSE2; and prints the final enabled/disabled lowlevel, driver, algorithm, and option lists.
Makefile.am consumes the conditionals from configure.ac to assemble the actual targets. It builds bfgminer from common sources, links lib/libgnu.a, ccan.bfg/libccan.a, optional bundled libbase58 and libblkmaker, then appends driver, lowlevel, algorithm, OpenCL kernel, documentation, udev-rule, helper-script, and bfgminer-rpc sources according to the configured features. It also defines the update-version rule, test-bfgminer.sh as the automake test, installs start-bfgminer.sh on non-Windows builds, and installs setup-vfio only when lowlevel PCI plus VFIO support is selected.
The m4/** macros are mostly gnulib support and BFGMiner-specific autotools helpers. m4/gnulib-cache.m4 records the imported gnulib modules (memmem, sigaction, signal, strtok_r) and the libgnu source/m4 layout. m4/bundled_lib.m4 implements the BFG_BUNDLED_LIB path used by configure.ac for libbase58 and libblkmaker: it prefers or rejects system pkg-config packages based on configure flags, wires bundled include/library paths with $ORIGIN rpath support, and injects recursive build rules into Makefile.am. m4/custom_subdirs.m4 delays recursive subdir configuration so bundled libraries can receive inherited and forced configure arguments after top-level output.
Device access setup is generated from the configured feature set. 70-bfgminer.rules.in is substituted into 70-bfgminer.rules only when enabled drivers need udev rules and a rules directory is available; its @USE_*@ and @BROAD_UDEVRULES_*@ substitutions ensure only built drivers contribute USB matches, with group ownership controlled by --with-udevrules-group. setup-vfio is an installed operator helper for PCI mining devices: it loads vfio-pci, finds PCI devices matching the requested vendor/device IDs, warns about other devices in the same IOMMU group, optionally enables unsafe interrupts, binds the whole group to VFIO, and can chown /dev/vfio/<group> to a user.
Packaging is split by target platform. debian/control, debian/rules, and debian/bfgminer.docs define a Debian/Ubuntu package that runs NOSUBMODULES=1 ./autogen.sh, configures with broad driver/algorithm support plus system libblkmaker, installs into the debhelper staging directory, and ships user docs and API examples. openwrt/bfgminer/Makefile packages the release tarball for OpenWrt/LEDE, exposes menu options for curses, proxy libraries, libusb, Bitmain, Keccak, and scrypt, reruns NOSUBMODULES=1 ./autogen.sh during cross builds, disables libudev/sensors, uses bundled libbase58, fetches uthash separately, and installs both bfgminer and bfgminer-rpc plus bundled shared libraries. openwrt/multibuild.sh automates building across OpenWrt vanilla configs, copies resulting .ipk packages into a repository tree, symlinks expected bitstream packages, and regenerates Packages indexes.
Release automation is handled by make-release. Given a tag, it creates source .zip and .txz archives from the tag and submodules, regenerates version.h, runs autogen.sh without submodule/configure steps, removes autotools caches, and then cross-builds win32 and win64 packages with a fixed set of configure options. The Windows package path converts docs to CRLF .txt, configures with OpenCL, selected FPGA/ASIC drivers, Keccak and scrypt, bundles system DLL dependencies discovered with target objdump, copies kernels/examples/docs, and zips each package.
CI and operator documentation mirror these build paths. .travis.yml defines a broad matrix across GCC/Clang, pkgconf, MinGW, dependency-disabled builds, algorithm subsets, OpenCL-only/CPU-only builds, and individual drivers; .travis.deps mutates the CI system package sources and installs distro or cross-binpkg dependencies; .travis.script runs autogen.sh, configure, make, make check, and make install for native builds. README is the primary operator entry point for dependency lists, configure flags, and basic Unix/Mac/Windows build commands; windows-build.txt gives native MinGW setup; README.OpenWrt explains consuming published OpenWrt packages; linux-usb-bfgminer documents an older USB-boot mining setup; start-bfgminer.sh starts or resets a screen session around bfgminer; and test-bfgminer.sh runs the built binary's unit-test mode with auto scanning disabled.
Coverage
configure.acMakefile.amm4/**- autogen.sh
- gen-version.sh
make-release- version.c
debian/**openwrt/**- windows-build.txt
setup-vfiolinux-usb-bfgminer70-bfgminer.rules.in- start-bfgminer.sh
- test-bfgminer.sh
- .travis.yml
.travis.deps.travis.scriptREADMEREADME.*HACKINGNEWSChangeLogAUTHORSCOPYINGLICENSE
Coupling
- If a driver or algorithm configure option changes in
configure.ac, update the matchingMakefile.amconditional sources and the option list inREADME; the build can otherwise configure successfully but omit the implementation or document an option that no longer exists. - If a driver needs USB udev access, update both its
BFG_DRIVERblock inconfigure.acto sethave_udevrules=trueand70-bfgminer.rules.into add a conditional match; otherwise packaged installs may build the driver but leave ordinary users unable to access the device. - If lowlevel PCI/VFIO behavior changes in
configure.acorMakefile.am, verifysetup-vfio; it is installed only under theNEED_BFG_LOWL_PCIandUSE_VFIOconditionals and assumes Linux sysfs paths plusvfio-pcibinding semantics. - If bundled-library policy changes in
configure.ac, also checkm4/bundled_lib.m4,m4/custom_subdirs.m4,Makefile.am,debian/rules,openwrt/bfgminer/Makefile, andmake-release; each path makes different assumptions about whenlibbase58andlibblkmakerare system packages versus bundled subdir builds. - If the project version changes, synchronize
configure.ac,debian/changelog, andopenwrt/bfgminer/Makefile; release archives and package metadata do not derive all versions from a single source. - If dependency detection in
configure.acchanges, update .travis.yml,.travis.deps,README, windows-build.txt,debian/control, andopenwrt/bfgminer/Makefile; CI, distro packages, and operator instructions maintain their dependency lists separately. - If autogen.sh or gen-version.sh changes, verify
Makefile.am'supdate-versionrule,debian/rules,openwrt/bfgminer/Makefile,.travis.script, windows-build.txt, andmake-release; all invoke the scripts with slightly different assumptions about submodules and source-directory location.
Risks
make-releaseis fragile around Windows DLL packaging: recent history includesmake-release: Add crypt32.dll to OS-provided library list, and the script manually parses targetobjdumpoutput and copies DLLs from/usr/$machine/usr/{lib,bin}. If a MinGW runtime dependency naming pattern changes, the produced zip can miss a DLL and fail only on a user's Windows machine.openwrt/bfgminer/Makefilehas option drift risk: recent history includesBugfix: openwrt: Fix bitmain option, and the OpenWrt recipe maps menu booleans to top-level configure flags by hand. If a configure flag is renamed or a dependency becomes mandatory, OpenWrt packages may silently build without the intended feature.configure.acinclude-path probing is delicate: recent history includesconfigure: BFG_FIND_INCLUDE_PATH: Handle more unusual syntax correctly. The custom preprocessor parsing feeds headers such as libusb, curses, and Windows DDK paths into generated CFLAGS; unusual compiler dependency output can make configuration fail or choose the wrong include directory..travis.depsdeliberately rewrites/etc/apt/sources.listand deletes/etc/apt/sources.list.dafter requiring the literalI-am-okay-with-destroying-my-systemargument. Running it outside disposable CI can damage the host package configuration.