| 1 | .NOTPARALLEL : |
| 2 | |
| 3 | SOURCES_PATH ?= $(BASEDIR)/sources |
| 4 | BASE_CACHE ?= $(BASEDIR)/built |
| 5 | FALLBACK_DOWNLOAD_PATH ?= https://downloads.getmonero.org/depends-sources |
| 6 | |
| 7 | BUILD = $(shell ./config.guess) |
| 8 | HOST ?= $(BUILD) |
| 9 | PATCHES_PATH = $(BASEDIR)/patches |
| 10 | BASEDIR = $(CURDIR) |
| 11 | HASH_LENGTH:=11 |
| 12 | DOWNLOAD_CONNECT_TIMEOUT:=30 |
| 13 | DOWNLOAD_RETRIES:=5 |
| 14 | HOST_ID_SALT ?= salt |
| 15 | BUILD_ID_SALT ?= salt |
| 16 | |
| 17 | host:=$(BUILD) |
| 18 | ifneq ($(HOST),) |
| 19 | host:=$(HOST) |
| 20 | host_toolchain:=$(HOST)- |
| 21 | endif |
| 22 | |
| 23 | ifneq ($(DEBUG),) |
| 24 | release_type=debug |
| 25 | else |
| 26 | release_type=release |
| 27 | endif |
| 28 | |
| 29 | ifneq ($(TESTS),) |
| 30 | build_tests=ON |
| 31 | release_type=debug |
| 32 | else |
| 33 | build_tests=OFF |
| 34 | endif |
| 35 | |
| 36 | ifeq ($(release_type),debug) |
| 37 | cmake_release_type=Debug |
| 38 | else |
| 39 | cmake_release_type=Release |
| 40 | endif |
| 41 | |
| 42 | base_build_dir=$(BASEDIR)/work/build |
| 43 | base_staging_dir=$(BASEDIR)/work/staging |
| 44 | base_download_dir=$(BASEDIR)/work/download |
| 45 | canonical_host:=$(shell ./config.sub $(HOST)) |
| 46 | build:=$(shell ./config.sub $(BUILD)) |
| 47 | |
| 48 | build_arch =$(firstword $(subst -, ,$(build))) |
| 49 | build_vendor=$(word 2,$(subst -, ,$(build))) |
| 50 | full_build_os:=$(subst $(build_arch)-$(build_vendor)-,,$(build)) |
| 51 | build_os:=$(findstring linux,$(full_build_os)) |
| 52 | build_os+=$(findstring darwin,$(full_build_os)) |
| 53 | build_os:=$(strip $(build_os)) |
| 54 | ifeq ($(build_os),) |
| 55 | build_os=$(full_build_os) |
| 56 | endif |
| 57 | |
| 58 | host_arch=$(firstword $(subst -, ,$(canonical_host))) |
| 59 | host_vendor=$(word 2,$(subst -, ,$(canonical_host))) |
| 60 | full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host)) |
| 61 | host_os:=$(findstring android,$(full_host_os)) |
| 62 | ifeq ($(host_os),) |
| 63 | host_os:=$(findstring linux,$(full_host_os)) |
| 64 | endif |
| 65 | host_os+=$(findstring darwin,$(full_host_os)) |
| 66 | host_os+=$(findstring freebsd,$(full_host_os)) |
| 67 | host_os+=$(findstring mingw32,$(full_host_os)) |
| 68 | host_os:=$(strip $(host_os)) |
| 69 | ifeq ($(host_os),) |
| 70 | host_os=$(full_host_os) |
| 71 | endif |
| 72 | |
| 73 | $(host_arch)_$(host_os)_prefix=$(BASEDIR)/$(host) |
| 74 | $(host_arch)_$(host_os)_host=$(host) |
| 75 | host_prefix=$($(host_arch)_$(host_os)_prefix) |
| 76 | build_prefix=$(host_prefix)/native |
| 77 | ifeq ($(host_os),mingw32) |
| 78 | host_cmake=Windows |
| 79 | endif |
| 80 | ifeq ($(host_os),linux) |
| 81 | host_cmake=Linux |
| 82 | endif |
| 83 | ifeq ($(host_os),freebsd) |
| 84 | host_cmake=FreeBSD |
| 85 | endif |
| 86 | ifeq ($(host_os),darwin) |
| 87 | host_cmake=Darwin |
| 88 | endif |
| 89 | ifeq ($(host_os),android) |
| 90 | host_cmake=Android |
| 91 | endif |
| 92 | |
| 93 | AT_$(V):= |
| 94 | AT_:=@ |
| 95 | AT:=$(AT_$(V)) |
| 96 | |
| 97 | all: install |
| 98 | |
| 99 | include hosts/$(host_os).mk |
| 100 | include hosts/default.mk |
| 101 | include builders/$(build_os).mk |
| 102 | include builders/default.mk |
| 103 | include packages/packages.mk |
| 104 | |
| 105 | build_id_string:=$(BUILD_ID_SALT) |
| 106 | build_id_string+=$(shell $(build_CC) --version 2>/dev/null) |
| 107 | build_id_string+=$(shell $(build_AR) --version 2>/dev/null) |
| 108 | build_id_string+=$(shell $(build_CXX) --version 2>/dev/null) |
| 109 | build_id_string+=$(shell $(build_RANLIB) --version 2>/dev/null) |
| 110 | build_id_string+=$(shell $(build_STRIP) --version 2>/dev/null) |
| 111 | |
| 112 | $(host_arch)_$(host_os)_id_string:=$(HOST_ID_SALT) |
| 113 | $(host_arch)_$(host_os)_id_string+=$(shell $(host_CC) --version 2>/dev/null) |
| 114 | $(host_arch)_$(host_os)_id_string+=$(shell $(host_AR) --version 2>/dev/null) |
| 115 | $(host_arch)_$(host_os)_id_string+=$(shell $(host_CXX) --version 2>/dev/null) |
| 116 | $(host_arch)_$(host_os)_id_string+=$(shell $(host_RANLIB) --version 2>/dev/null) |
| 117 | $(host_arch)_$(host_os)_id_string+=$(shell $(host_STRIP) --version 2>/dev/null) |
| 118 | |
| 119 | packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) |
| 120 | native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages) |
| 121 | |
| 122 | all_packages = $(packages) $(native_packages) |
| 123 | |
| 124 | meta_depends = Makefile funcs.mk builders/default.mk hosts/default.mk hosts/$(host_os).mk builders/$(build_os).mk |
| 125 | |
| 126 | $(host_arch)_$(host_os)_native_toolchain?=$($(host_os)_native_toolchain) |
| 127 | |
| 128 | include funcs.mk |
| 129 | |
| 130 | CONF_PKGS := cmake-conf mxe-conf |
| 131 | |
| 132 | build-only-$(1)_$(3): CMAKE_RUNRESULT_FILE = $(PREFIX)/share/cmake/modules/TryRunResults.cmake |
| 133 | build-only-$(1)_$(3): CMAKE_TOOLCHAIN_FILE = $(PREFIX)/$(3)/share/cmake/mxe-conf.cmake |
| 134 | build-only-$(1)_$(3): CMAKE_TOOLCHAIN_DIR = $(PREFIX)/$(3)/share/cmake/mxe-conf.d |
| 135 | build-only-$(1)_$(3): CMAKE_STATIC_BOOL = $(if $(findstring shared,$(3)),OFF,ON) |
| 136 | build-only-$(1)_$(3): CMAKE_SHARED_BOOL = $(if $(findstring shared,$(3)),ON,OFF) |
| 137 | |
| 138 | |
| 139 | toolchain_path=$($($(host_arch)_$(host_os)_native_toolchain)_prefixbin) |
| 140 | final_build_id_long+=$(shell $(build_SHA256SUM) config.site.in) |
| 141 | final_build_id_long+=$(shell $(build_SHA256SUM) toolchain.cmake.in) |
| 142 | final_build_id+=$(shell echo -n "$(final_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH)) |
| 143 | $(host_prefix)/.stamp_$(final_build_id): $(native_packages) $(packages) |
| 144 | $(AT)rm -rf $(@D) |
| 145 | $(AT)mkdir -p $(@D) |
| 146 | $(AT)echo copying packages: $^ |
| 147 | $(AT)echo to: $(@D) |
| 148 | $(AT)cd $(@D); $(foreach package,$^, tar xf $($(package)_cached); ) |
| 149 | $(AT)touch $@ |
| 150 | |
| 151 | $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_build_id) |
| 152 | $(AT)@mkdir -p $(@D) |
| 153 | $(AT)sed -e 's|@HOST@|$(host)|' \ |
| 154 | -e 's|@CC@|$(toolchain_path)$(host_CC)|' \ |
| 155 | -e 's|@CXX@|$(toolchain_path)$(host_CXX)|' \ |
| 156 | -e 's|@AR@|$(toolchain_path)$(host_AR)|' \ |
| 157 | -e 's|@RANLIB@|$(toolchain_path)$(host_RANLIB)|' \ |
| 158 | -e 's|@NM@|$(toolchain_path)$(host_NM)|' \ |
| 159 | -e 's|@STRIP@|$(toolchain_path)$(host_STRIP)|' \ |
| 160 | -e 's|@build_os@|$(build_os)|' \ |
| 161 | -e 's|@host_os@|$(host_os)|' \ |
| 162 | -e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \ |
| 163 | -e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS) $(host_$(release_type)_CXXFLAGS))|' \ |
| 164 | -e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \ |
| 165 | -e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \ |
| 166 | -e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \ |
| 167 | -e 's|@debug@|$(DEBUG)|' \ |
| 168 | $< > $@ |
| 169 | $(AT)touch $@ |
| 170 | |
| 171 | $(host_prefix)/share/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_$(final_build_id) |
| 172 | $(AT)@mkdir -p $(@D) |
| 173 | $(AT)sed -e 's|@HOST@|$(host)|' \ |
| 174 | -e 's|@CC@|$(toolchain_path)$(host_CC)|' \ |
| 175 | -e 's|@CXX@|$(toolchain_path)$(host_CXX)|' \ |
| 176 | -e 's|@AR@|$(toolchain_path)$(host_AR)|' \ |
| 177 | -e 's|@RANLIB@|$(toolchain_path)$(host_RANLIB)|' \ |
| 178 | -e 's|@NM@|$(toolchain_path)$(host_NM)|' \ |
| 179 | -e 's|@STRIP@|$(toolchain_path)$(host_STRIP)|' \ |
| 180 | -e 's|@build_os@|$(build_os)|' \ |
| 181 | -e 's|@host_os@|$(host_os)|' \ |
| 182 | -e 's|@CFLAGS@|$(strip $(host_CFLAGS) $(host_$(release_type)_CFLAGS))|' \ |
| 183 | -e 's|@CXXFLAGS@|$(strip $(host_CXXFLAGS) $(host_$(release_type)_CXXFLAGS))|' \ |
| 184 | -e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \ |
| 185 | -e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \ |
| 186 | -e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \ |
| 187 | -e 's|@debug@|$(DEBUG)|' \ |
| 188 | -e 's|@release_type@|$(cmake_release_type)|' \ |
| 189 | -e 's|@build_tests@|$(build_tests)|' \ |
| 190 | -e 's|@depends@|$(host_cmake)|' \ |
| 191 | -e 's|@prefix@|$($(host_arch)_$(host_os)_prefix)|'\ |
| 192 | -e 's|@arch@|$(host_arch)|'\ |
| 193 | $< > $@ |
| 194 | $(AT)touch $@ |
| 195 | |
| 196 | define check_or_remove_cached |
| 197 | mkdir -p $(BASE_CACHE)/$(host)/$(package) && cd $(BASE_CACHE)/$(host)/$(package); \ |
| 198 | $(build_SHA256SUM) -c $($(package)_cached_checksum) >/dev/null 2>/dev/null || \ |
| 199 | ( rm -f $($(package)_cached_checksum); \ |
| 200 | if test -f "$($(package)_cached)"; then echo "Checksum mismatch for $(package). Forcing rebuild.."; rm -f $($(package)_cached_checksum) $($(package)_cached); fi ) |
| 201 | endef |
| 202 | |
| 203 | define check_or_remove_sources |
| 204 | mkdir -p $($(package)_source_dir); cd $($(package)_source_dir); \ |
| 205 | test -f $($(package)_fetched) && ( $(build_SHA256SUM) -c $($(package)_fetched) >/dev/null 2>/dev/null || \ |
| 206 | ( echo "Checksum missing or mismatched for $(package) source. Forcing re-download."; \ |
| 207 | rm -f $($(package)_all_sources) $($(1)_fetched))) || true |
| 208 | endef |
| 209 | |
| 210 | check-packages: |
| 211 | @$(foreach package,$(all_packages),$(call check_or_remove_cached,$(package));) |
| 212 | check-sources: |
| 213 | @$(foreach package,$(all_packages),$(call check_or_remove_sources,$(package));) |
| 214 | |
| 215 | $(host_prefix)/share/config.site: check-packages |
| 216 | $(host_prefix)/share/toolchain.cmake: check-packages |
| 217 | |
| 218 | check-packages: check-sources |
| 219 | |
| 220 | install: check-packages $(host_prefix)/share/config.site |
| 221 | install: check-packages $(host_prefix)/share/toolchain.cmake |
| 222 | |
| 223 | download-one: check-sources $(all_sources) |
| 224 | |
| 225 | download-osx: |
| 226 | @$(MAKE) -s HOST=x86_64-apple-darwin11 download-one |
| 227 | download-linux: |
| 228 | @$(MAKE) -s HOST=x86_64-unknown-linux-gnu download-one |
| 229 | download-win: |
| 230 | @$(MAKE) -s HOST=x86_64-w64-mingw32 download-one |
| 231 | download: download-osx download-linux download-win |
| 232 | |
| 233 | $(foreach package,$(all_packages),$(eval $(call ext_add_stages,$(package)))) |
| 234 | |
| 235 | .PHONY: install cached download-one download-osx download-linux download-win download check-packages check-sources |