| 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 |
FALLBACK_DOWNLOAD_PATH ?= https://featherwallet.org/files/sources |
| 35 |
|
| 36 |
CXX_STANDARD ?= c++17 |
| 37 |
|
| 38 |
BUILD = $(shell ./config.guess) |
| 39 |
HOST ?= $(BUILD) |
| 40 |
PATCHES_PATH = $(BASEDIR)/patches |
| 41 |
BASEDIR = $(CURDIR) |
| 42 |
HASH_LENGTH:=11 |
| 43 |
DOWNLOAD_CONNECT_TIMEOUT:=30 |
| 44 |
DOWNLOAD_RETRIES:=3 |
| 45 |
HOST_ID_SALT ?= salt |
| 46 |
BUILD_ID_SALT ?= salt |
| 47 |
|
| 48 |
host:=$(BUILD) |
| 49 |
ifneq ($(HOST),) |
| 50 |
host:=$(HOST) |
| 51 |
endif |
| 52 |
|
| 53 |
ifneq ($(DEBUG),) |
| 54 |
release_type=Debug |
| 55 |
else |
| 56 |
release_type=Release |
| 57 |
endif |
| 58 |
|
| 59 |
ifneq ($(TESTS),) |
| 60 |
build_tests=ON |
| 61 |
release_type=Debug |
| 62 |
else |
| 63 |
build_tests=OFF |
| 64 |
endif |
| 65 |
|
| 66 |
base_build_dir=$(WORK_PATH)/build |
| 67 |
base_staging_dir=$(WORK_PATH)/staging |
| 68 |
base_download_dir=$(WORK_PATH)/download |
| 69 |
canonical_host:=$(shell ./config.sub $(HOST)) |
| 70 |
build:=$(shell ./config.sub $(BUILD)) |
| 71 |
|
| 72 |
build_arch =$(firstword $(subst -, ,$(build))) |
| 73 |
build_vendor=$(word 2,$(subst -, ,$(build))) |
| 74 |
full_build_os:=$(subst $(build_arch)-$(build_vendor)-,,$(build)) |
| 75 |
build_os:=$(findstring linux,$(full_build_os)) |
| 76 |
build_os+=$(findstring darwin,$(full_build_os)) |
| 77 |
build_os:=$(strip $(build_os)) |
| 78 |
ifeq ($(build_os),) |
| 79 |
build_os=$(full_build_os) |
| 80 |
endif |
| 81 |
|
| 82 |
host_arch=$(firstword $(subst -, ,$(canonical_host))) |
| 83 |
host_vendor=$(word 2,$(subst -, ,$(canonical_host))) |
| 84 |
full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host)) |
| 85 |
host_os:=$(findstring android,$(full_host_os)) |
| 86 |
ifeq ($(host_os),) |
| 87 |
host_os:=$(findstring linux,$(full_host_os)) |
| 88 |
endif |
| 89 |
host_os+=$(findstring darwin,$(full_host_os)) |
| 90 |
host_os+=$(findstring freebsd,$(full_host_os)) |
| 91 |
host_os+=$(findstring mingw32,$(full_host_os)) |
| 92 |
host_os:=$(strip $(host_os)) |
| 93 |
ifeq ($(host_os),) |
| 94 |
host_os=$(full_host_os) |
| 95 |
endif |
| 96 |
|
| 97 |
$(host_arch)_$(host_os)_prefix=$(BASEDIR)/$(host) |
| 98 |
$(host_arch)_$(host_os)_host=$(host) |
| 99 |
host_prefix=$($(host_arch)_$(host_os)_prefix) |
| 100 |
build_prefix=$(host_prefix)/native |
| 101 |
ifeq ($(host_os),mingw32) |
| 102 |
host_cmake=Windows |
| 103 |
endif |
| 104 |
ifeq ($(host_os),linux) |
| 105 |
host_cmake=Linux |
| 106 |
endif |
| 107 |
ifeq ($(host_os),freebsd) |
| 108 |
host_cmake=FreeBSD |
| 109 |
endif |
| 110 |
ifeq ($(host_os),darwin) |
| 111 |
host_cmake=Darwin |
| 112 |
endif |
| 113 |
ifeq ($(host_os),android) |
| 114 |
host_cmake=Android |
| 115 |
endif |
| 116 |
|
| 117 |
AT_$(V):= |
| 118 |
AT_:=@ |
| 119 |
AT:=$(AT_$(V)) |
| 120 |
build_host=$(build) |
| 121 |
|
| 122 |
all: install |
| 123 |
|
| 124 |
include hosts/$(host_os).mk |
| 125 |
include hosts/default.mk |
| 126 |
include builders/$(build_os).mk |
| 127 |
include builders/default.mk |
| 128 |
include packages/packages.mk |
| 129 |
|
| 130 |
build_id_string:=$(realpath $(GUIX_ENVIRONMENT)) |
| 131 |
$(host_arch)_$(host_os)_id_string:=$(realpath $(GUIX_ENVIRONMENT)) |
| 132 |
|
| 133 |
qt_packages_$(NO_QT) = $(qt_packages) $(qt_$(host_os)_packages) $(qt_$(host_arch)_$(host_os)_packages) $(qrencode_packages_) |
| 134 |
tor_packages_$(NO_TOR) = $(tor_packages) $(tor_$(host_os)_packages) |
| 135 |
|
| 136 |
packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(tor_packages_) |
| 137 |
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages) |
| 138 |
|
| 139 |
all_packages = $(packages) $(native_packages) |
| 140 |
|
| 141 |
meta_depends = Makefile funcs.mk builders/default.mk hosts/default.mk hosts/$(host_os).mk builders/$(build_os).mk |
| 142 |
|
| 143 |
$(host_arch)_$(host_os)_native_binutils?=$($(host_os)_native_binutils) |
| 144 |
$(host_arch)_$(host_os)_native_toolchain?=$($(host_os)_native_toolchain) |
| 145 |
|
| 146 |
include funcs.mk |
| 147 |
|
| 148 |
CONF_PKGS := cmake-conf mxe-conf |
| 149 |
|
| 150 |
build-only-$(1)_$(3): CMAKE_RUNRESULT_FILE = $(PREFIX)/share/cmake/modules/TryRunResults.cmake |
| 151 |
build-only-$(1)_$(3): CMAKE_TOOLCHAIN_FILE = $(PREFIX)/$(3)/share/cmake/mxe-conf.cmake |
| 152 |
build-only-$(1)_$(3): CMAKE_TOOLCHAIN_DIR = $(PREFIX)/$(3)/share/cmake/mxe-conf.d |
| 153 |
build-only-$(1)_$(3): CMAKE_STATIC_BOOL = $(if $(findstring shared,$(3)),OFF,ON) |
| 154 |
build-only-$(1)_$(3): CMAKE_SHARED_BOOL = $(if $(findstring shared,$(3)),ON,OFF) |
| 155 |
|
| 156 |
|
| 157 |
toolchain_path=$($($(host_arch)_$(host_os)_native_toolchain)_prefixbin) |
| 158 |
final_build_id_long+=:[sha256sum]:$(shell $(build_SHA256SUM) toolchain.cmake.in) |
| 159 |
final_build_id+=$(shell echo -n "$(final_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH)) |
| 160 |
$(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages) |
| 161 |
rm -rf $(@D) |
| 162 |
mkdir -p $(@D) |
| 163 |
echo copying packages: $^ |
| 164 |
echo to: $(@D) |
| 165 |
cd $(@D); $(foreach package,$^, $(build_TAR) xf $($(package)_cached); ) |
| 166 |
touch $@ |
| 167 |
|
| 168 |
# $PATH is not preserved between ./configure and make by convention. Its |
| 169 |
# modification and overriding at ./configure time is (as I understand it) |
| 170 |
# supposed to be captured by the AC_{PROG_{,OBJ}CXX,PATH_{PROG,TOOL}} macros, |
| 171 |
# which will expand the program names to their full absolute paths. The notable |
| 172 |
# exception is command line overriding: ./configure CC=clang, which skips the |
| 173 |
# program name expansion step, and works because the user implicitly indicates |
| 174 |
# with CC=clang that clang will be available in $PATH at all times, and is most |
| 175 |
# likely part of the user's system. |
| 176 |
# |
| 177 |
# Therefore, when we "seed the autoconf cache"/"override well-known program |
| 178 |
# vars" by setting AR=<blah> in our config.site, either one of two things needs |
| 179 |
# to be true for the build system to work correctly: |
| 180 |
# |
| 181 |
# 1. If we refer to the program by name (e.g. AR=riscv64-gnu-linux-ar), the |
| 182 |
# tool needs to be available in $PATH at all times. |
| 183 |
# |
| 184 |
# 2. If the tool is _**not**_ expected to be available in $PATH at all times |
| 185 |
# (such as is the case for our native_cctools binutils tools), it needs to |
| 186 |
# be referred to by its absolute path, such as would be output by the |
| 187 |
# AC_PATH_{PROG,TOOL} macros. |
| 188 |
# |
| 189 |
# Minor note: it is also okay to refer to tools by their absolute path even if |
| 190 |
# we expect them to be available in $PATH at all times, more specificity does |
| 191 |
# not hurt. |
| 192 |
$(host_prefix)/share/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_$(final_build_id) |
| 193 |
@mkdir -p $(@D) |
| 194 |
sed -e 's|@HOST@|$(host)|' \ |
| 195 |
-e 's|@CC@|$(host_CC)|' \ |
| 196 |
-e 's|@CXX@|$(host_CXX)|' \ |
| 197 |
-e 's|@AR@|$(toolchain_path)$(host_AR)|' \ |
| 198 |
-e 's|@RANLIB@|$(toolchain_path)$(host_RANLIB)|' \ |
| 199 |
-e 's|@NM@|$(toolchain_path)$(host_NM)|' \ |
| 200 |
-e 's|@STRIP@|$(toolchain_path)$(host_STRIP)|' \ |
| 201 |
-e 's|@CMAKE_INSTALL_NAME_TOOL@|$(host_INSTALL_NAME_TOOL)|' \ |
| 202 |
-e 's|@OTOOL@|$(host_OTOOL)|' \ |
| 203 |
-e 's|@build_os@|$(build_os)|' \ |
| 204 |
-e 's|@host_os@|$(host_os)|' \ |
| 205 |
-e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \ |
| 206 |
-e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS) $(host_$(release_type)_CXXFLAGS))|' \ |
| 207 |
-e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \ |
| 208 |
-e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \ |
| 209 |
-e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \ |
| 210 |
-e 's|@debug@|$(DEBUG)|' \ |
| 211 |
-e 's|@release_type@|$(release_type)|' \ |
| 212 |
-e 's|@build_tests@|$(build_tests)|' \ |
| 213 |
-e 's|@depends@|$(host_cmake)|' \ |
| 214 |
-e 's|@prefix@|$($(host_arch)_$(host_os)_prefix)|'\ |
| 215 |
-e 's|@arch@|$(host_arch)|'\ |
| 216 |
-e 's|@guix_ldflags@|$(guix_ldflags)|'\ |
| 217 |
-e 's|@tor_version@|$(tor_$(host_os)_version)|'\ |
| 218 |
$< > $@ |
| 219 |
touch $@ |
| 220 |
|
| 221 |
define check_or_remove_cached |
| 222 |
mkdir -p $(BASE_CACHE)/$(host)/$(package) && cd $(BASE_CACHE)/$(host)/$(package); \ |
| 223 |
$(build_SHA256SUM) -c $($(package)_cached_checksum) >/dev/null 2>/dev/null || \ |
| 224 |
( rm -f $($(package)_cached_checksum); \ |
| 225 |
if test -f "$($(package)_cached)"; then echo "Checksum mismatch for $(package). Forcing rebuild.."; rm -f $($(package)_cached_checksum) $($(package)_cached); fi ) |
| 226 |
endef |
| 227 |
|
| 228 |
define check_or_remove_sources |
| 229 |
mkdir -p $($(package)_source_dir); cd $($(package)_source_dir); \ |
| 230 |
test -f $($(package)_fetched) && ( $(build_SHA256SUM) -c $($(package)_fetched) >/dev/null 2>/dev/null || \ |
| 231 |
( echo "Checksum missing or mismatched for $(package) source. Forcing re-download."; \ |
| 232 |
rm -f $($(package)_all_sources) $($(1)_fetched))) || true |
| 233 |
endef |
| 234 |
|
| 235 |
check-packages: |
| 236 |
@$(foreach package,$(all_packages),$(call check_or_remove_cached,$(package));) |
| 237 |
check-sources: |
| 238 |
@$(foreach package,$(all_packages),$(call check_or_remove_sources,$(package));) |
| 239 |
|
| 240 |
$(host_prefix)/share/config.site: check-packages |
| 241 |
$(host_prefix)/share/toolchain.cmake: check-packages |
| 242 |
|
| 243 |
check-packages: check-sources |
| 244 |
|
| 245 |
clean-all: clean |
| 246 |
@rm -rf $(SOURCES_PATH) x86_64* i686* mips* arm* aarch64* |
| 247 |
|
| 248 |
clean: |
| 249 |
@rm -rf $(WORK_PATH) $(BASE_CACHE) $(BUILD) *.log |
| 250 |
|
| 251 |
install: check-packages $(host_prefix)/share/config.site |
| 252 |
install: check-packages $(host_prefix)/share/toolchain.cmake |
| 253 |
|
| 254 |
download-one: check-sources $(all_sources) |
| 255 |
|
| 256 |
download-osx: |
| 257 |
@$(MAKE) -s HOST=x86_64-apple-darwin download-one |
| 258 |
download-linux: |
| 259 |
@$(MAKE) -s HOST=x86_64-unknown-linux-gnu download-one |
| 260 |
download-win: |
| 261 |
@$(MAKE) -s HOST=x86_64-w64-mingw32 download-one |
| 262 |
download: download-osx download-linux download-win |
| 263 |
|
| 264 |
$(foreach package,$(all_packages),$(eval $(call ext_add_stages,$(package)))) |
| 265 |
|
| 266 |
.PHONY: install cached clean clean-all download-one download-osx download-linux download-win download check-packages check-sources |
| 267 |
.PHONY: FORCE |
| 268 |
$(V).SILENT: |