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