1.NOTPARALLEL : 2 3# Pattern rule to print variables, e.g. make print-top_srcdir 4print-%: FORCE 5 @echo '$*'='$($*)' 6 7# When invoking a sub-make, keep only the command line variable definitions 8# matching the pattern in the filter function. 9# 10# e.g. invoking: 11# $ make A=1 C=1 print-MAKEOVERRIDES print-MAKEFLAGS 12# 13# with the following in the Makefile: 14# MAKEOVERRIDES := $(filter A=% B=%,$(MAKEOVERRIDES)) 15# 16# will print: 17# MAKEOVERRIDES = A=1 18# MAKEFLAGS = -- A=1 19# 20# this is because as the GNU make manual says: 21# The command line variable definitions really appear in the variable 22# MAKEOVERRIDES, and MAKEFLAGS contains a reference to this variable. 23# 24# and since the GNU make manual also says: 25# variables defined on the command line are passed to the sub-make through 26# MAKEFLAGS 27# 28# this means that sub-makes will be invoked as if: 29# $(MAKE) A=1 blah blah 30MAKEOVERRIDES := $(filter V=%,$(MAKEOVERRIDES)) 31SOURCES_PATH ?= $(BASEDIR)/sources 32WORK_PATH = $(BASEDIR)/work 33BASE_CACHE ?= $(BASEDIR)/built 34SDK_PATH ?= $(BASEDIR)/SDKs 35NO_QT ?= 36NO_QR ?= 37NO_BDB ?= 38NO_SQLITE ?= 39NO_WALLET ?= 40NO_ZMQ ?= 41NO_UPNP ?= 42NO_NATPMP ?= 43MULTIPROCESS ?= 44FALLBACK_DOWNLOAD_PATH ?= https://bitcoincore.org/depends-sources 45 46BUILD = $(shell ./config.guess) 47HOST ?= $(BUILD) 48PATCHES_PATH = $(BASEDIR)/patches 49BASEDIR = $(CURDIR) 50HASH_LENGTH:=11 51DOWNLOAD_CONNECT_TIMEOUT:=30 52DOWNLOAD_RETRIES:=3 53HOST_ID_SALT ?= salt 54BUILD_ID_SALT ?= salt 55 56host:=$(BUILD) 57ifneq ($(HOST),) 58host:=$(HOST) 59endif 60 61ifneq ($(DEBUG),) 62release_type=debug 63else 64release_type=release 65endif 66 67base_build_dir=$(WORK_PATH)/build 68base_staging_dir=$(WORK_PATH)/staging 69base_download_dir=$(WORK_PATH)/download 70canonical_host:=$(shell ./config.sub $(HOST)) 71build:=$(shell ./config.sub $(BUILD)) 72 73build_arch =$(firstword $(subst -, ,$(build))) 74build_vendor=$(word 2,$(subst -, ,$(build))) 75full_build_os:=$(subst $(build_arch)-$(build_vendor)-,,$(build)) 76build_os:=$(findstring linux,$(full_build_os)) 77build_os+=$(findstring darwin,$(full_build_os)) 78build_os:=$(strip $(build_os)) 79ifeq ($(build_os),) 80build_os=$(full_build_os) 81endif 82 83host_arch=$(firstword $(subst -, ,$(canonical_host))) 84host_vendor=$(word 2,$(subst -, ,$(canonical_host))) 85full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host)) 86host_os:=$(findstring linux,$(full_host_os)) 87host_os+=$(findstring darwin,$(full_host_os)) 88host_os+=$(findstring mingw32,$(full_host_os)) 89 90ifeq (android,$(findstring android,$(full_host_os))) 91host_os:=android 92endif 93 94host_os:=$(strip $(host_os)) 95ifeq ($(host_os),) 96host_os=$(full_host_os) 97endif 98 99$(host_arch)_$(host_os)_prefix=$(BASEDIR)/$(host) 100$(host_arch)_$(host_os)_host=$(host) 101host_prefix=$($(host_arch)_$(host_os)_prefix) 102build_prefix=$(host_prefix)/native 103build_host=$(build) 104 105AT_$(V):= 106AT_:=@ 107AT:=$(AT_$(V)) 108 109all: install 110 111include hosts/$(host_os).mk 112include hosts/default.mk 113include builders/$(build_os).mk 114include builders/default.mk 115include packages/packages.mk 116 117# Previously, we directly invoked the well-known programs using $(shell ...) 118# to contruct build_id_string. However, that was problematic because: 119# 120# 1. When invoking a shell, GNU Make special-cases exit code 127 (command not 121# found) by not capturing the output but instead passing it through. This is 122# not done for any other exit code. 123# 124# 2. Characters like '#' (from these programs' output) would end up in make 125# variables like build_id_string, which would be wrongly interpreted by make 126# when these variables were used. 127# 128# Therefore, we should avoid having arbitrary strings in make variables where 129# possible. The gen_id script used here hashes the output to construct a 130# "make-safe" id. 131# 132# Also note that these lines need to be: 133# 134# 1. After including {hosts,builders}/*.mk, since they rely on the tool 135# variables (e.g. build_CC, host_STRIP, etc.) to be set. 136# 137# 2. Before including packages/*.mk (excluding packages/packages.mk), since 138# they rely on the build_id variables 139# 140build_id:=$(shell env CC='$(build_CC)' CXX='$(build_CXX)' AR='$(build_AR)' RANLIB='$(build_RANLIB)' STRIP='$(build_STRIP)' SHA256SUM='$(build_SHA256SUM)' DEBUG='$(DEBUG)' ./gen_id '$(BUILD_ID_SALT)' 'GUIX_ENVIRONMENT=$(realpath $(GUIX_ENVIRONMENT))') 141$(host_arch)_$(host_os)_id:=$(shell env CC='$(host_CC)' CXX='$(host_CXX)' AR='$(host_AR)' RANLIB='$(host_RANLIB)' STRIP='$(host_STRIP)' SHA256SUM='$(build_SHA256SUM)' DEBUG='$(DEBUG)' ./gen_id '$(HOST_ID_SALT)' 'GUIX_ENVIRONMENT=$(realpath $(GUIX_ENVIRONMENT))') 142 143qrencode_packages_$(NO_QR) = $(qrencode_packages) 144 145qt_packages_$(NO_QT) = $(qt_packages) $(qt_$(host_os)_packages) $(qt_$(host_arch)_$(host_os)_packages) $(qrencode_packages_) 146 147bdb_packages_$(NO_BDB) = $(bdb_packages) 148sqlite_packages_$(NO_SQLITE) = $(sqlite_packages) 149wallet_packages_$(NO_WALLET) = $(bdb_packages_) $(sqlite_packages_) 150 151upnp_packages_$(NO_UPNP) = $(upnp_packages) 152natpmp_packages_$(NO_NATPMP) = $(natpmp_packages) 153 154zmq_packages_$(NO_ZMQ) = $(zmq_packages) 155multiprocess_packages_$(MULTIPROCESS) = $(multiprocess_packages) 156 157packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_) $(natpmp_packages_) 158native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages) 159 160ifneq ($(zmq_packages_),) 161packages += $(zmq_packages) 162endif 163 164ifeq ($(multiprocess_packages_),) 165packages += $(multiprocess_packages) 166native_packages += $(multiprocess_native_packages) 167endif 168 169all_packages = $(packages) $(native_packages) 170 171meta_depends = Makefile funcs.mk builders/default.mk hosts/default.mk hosts/$(host_os).mk builders/$(build_os).mk 172 173$(host_arch)_$(host_os)_native_binutils?=$($(host_os)_native_binutils) 174$(host_arch)_$(host_os)_native_toolchain?=$($(host_os)_native_toolchain) 175 176include funcs.mk 177 178final_build_id_long+=$(shell $(build_SHA256SUM) config.site.in) 179final_build_id+=$(shell echo -n "$(final_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH)) 180$(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages) 181 $(AT)rm -rf $(@D) 182 $(AT)mkdir -p $(@D) 183 $(AT)echo copying packages: $^ 184 $(AT)echo to: $(@D) 185 $(AT)cd $(@D); $(foreach package,$^, tar xf $($(package)_cached); ) 186 $(AT)touch $@ 187 188# $PATH is not preserved between ./configure and make by convention. Its 189# modification and overriding at ./configure time is (as I understand it) 190# supposed to be captured by the AC_{PROG_{,OBJ}CXX,PATH_{PROG,TOOL}} macros, 191# which will expand the program names to their full absolute paths. The notable 192# exception is command line overriding: ./configure CC=clang, which skips the 193# program name expansion step, and works because the user implicitly indicates 194# with CC=clang that clang will be available in $PATH at all times, and is most 195# likely part of the user's system. 196# 197# Therefore, when we "seed the autoconf cache"/"override well-known program 198# vars" by setting AR=<blah> in our config.site, either one of two things needs 199# to be true for the build system to work correctly: 200# 201# 1. If we refer to the program by name (e.g. AR=riscv64-gnu-linux-ar), the 202# tool needs to be available in $PATH at all times. 203# 204# 2. If the tool is _**not**_ expected to be available in $PATH at all times 205# (such as is the case for our native_cctools binutils tools), it needs to 206# be referred to by its absolute path, such as would be output by the 207# AC_PATH_{PROG,TOOL} macros. 208# 209# Minor note: it is also okay to refer to tools by their absolute path even if 210# we expect them to be available in $PATH at all times, more specificity does 211# not hurt. 212$(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_build_id) 213 $(AT)@mkdir -p $(@D) 214 $(AT)sed -e 's|@HOST@|$(host)|' \ 215 -e 's|@CC@|$(host_CC)|' \ 216 -e 's|@CXX@|$(host_CXX)|' \ 217 -e 's|@AR@|$(host_AR)|' \ 218 -e 's|@RANLIB@|$(host_RANLIB)|' \ 219 -e 's|@NM@|$(host_NM)|' \ 220 -e 's|@STRIP@|$(host_STRIP)|' \ 221 -e 's|@build_os@|$(build_os)|' \ 222 -e 's|@host_os@|$(host_os)|' \ 223 -e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \ 224 -e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS) $(host_$(release_type)_CXXFLAGS))|' \ 225 -e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \ 226 -e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \ 227 -e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \ 228 -e 's|@no_qt@|$(NO_QT)|' \ 229 -e 's|@no_qr@|$(NO_QR)|' \ 230 -e 's|@no_zmq@|$(NO_ZMQ)|' \ 231 -e 's|@no_wallet@|$(NO_WALLET)|' \ 232 -e 's|@no_bdb@|$(NO_BDB)|' \ 233 -e 's|@no_sqlite@|$(NO_SQLITE)|' \ 234 -e 's|@no_upnp@|$(NO_UPNP)|' \ 235 -e 's|@no_natpmp@|$(NO_NATPMP)|' \ 236 -e 's|@multiprocess@|$(MULTIPROCESS)|' \ 237 -e 's|@debug@|$(DEBUG)|' \ 238 $< > $@ 239 $(AT)touch $@ 240 241 242define check_or_remove_cached 243 mkdir -p $(BASE_CACHE)/$(host)/$(package) && cd $(BASE_CACHE)/$(host)/$(package); \ 244 $(build_SHA256SUM) -c $($(package)_cached_checksum) >/dev/null 2>/dev/null || \ 245 ( rm -f $($(package)_cached_checksum); \ 246 if test -f "$($(package)_cached)"; then echo "Checksum mismatch for $(package). Forcing rebuild.."; rm -f $($(package)_cached_checksum) $($(package)_cached); fi ) 247endef 248 249define check_or_remove_sources 250 mkdir -p $($(package)_source_dir); cd $($(package)_source_dir); \ 251 test -f $($(package)_fetched) && ( $(build_SHA256SUM) -c $($(package)_fetched) >/dev/null 2>/dev/null || \ 252 ( echo "Checksum missing or mismatched for $(package) source. Forcing re-download."; \ 253 rm -f $($(package)_all_sources) $($(1)_fetched))) || true 254endef 255 256check-packages: 257 @$(foreach package,$(all_packages),$(call check_or_remove_cached,$(package));) 258check-sources: 259 @$(foreach package,$(all_packages),$(call check_or_remove_sources,$(package));) 260 261$(host_prefix)/share/config.site: check-packages 262 263check-packages: check-sources 264 265clean-all: clean 266 @rm -rf $(SOURCES_PATH) x86_64* i686* mips* arm* aarch64* powerpc* riscv32* riscv64* s390x* 267 268clean: 269 @rm -rf $(WORK_PATH) $(BASE_CACHE) $(BUILD) 270 271install: check-packages $(host_prefix)/share/config.site 272 273 274download-one: check-sources $(all_sources) 275 276download-osx: 277 @$(MAKE) -s HOST=x86_64-apple-darwin download-one 278download-linux: 279 @$(MAKE) -s HOST=x86_64-unknown-linux-gnu download-one 280download-win: 281 @$(MAKE) -s HOST=x86_64-w64-mingw32 download-one 282download: download-osx download-linux download-win 283 284$(foreach package,$(all_packages),$(eval $(call ext_add_stages,$(package)))) 285 286.PHONY: install cached clean clean-all download-one download-osx download-linux download-win download check-packages check-sources 287.PHONY: FORCE 288