You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

funcs.mk 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. define int_vars
  2. #Set defaults for vars which may be overridden per-package
  3. $(1)_cc=$($($(1)_type)_CC)
  4. $(1)_cxx=$($($(1)_type)_CXX)
  5. $(1)_objc=$($($(1)_type)_OBJC)
  6. $(1)_objcxx=$($($(1)_type)_OBJCXX)
  7. $(1)_ar=$($($(1)_type)_AR)
  8. $(1)_ranlib=$($($(1)_type)_RANLIB)
  9. $(1)_libtool=$($($(1)_type)_LIBTOOL)
  10. $(1)_nm=$($($(1)_type)_NM)
  11. $(1)_cflags=$($($(1)_type)_CFLAGS) $($($(1)_type)_$(release_type)_CFLAGS)
  12. $(1)_cxxflags=$($($(1)_type)_CXXFLAGS) $($($(1)_type)_$(release_type)_CXXFLAGS)
  13. $(1)_ldflags=$($($(1)_type)_LDFLAGS) $($($(1)_type)_$(release_type)_LDFLAGS) -L$($($(1)_type)_prefix)/lib
  14. $(1)_cppflags=$($($(1)_type)_CPPFLAGS) $($($(1)_type)_$(release_type)_CPPFLAGS) -I$($($(1)_type)_prefix)/include
  15. $(1)_recipe_hash:=
  16. endef
  17. define int_get_all_dependencies
  18. $(sort $(foreach dep,$(2),$(2) $(call int_get_all_dependencies,$(1),$($(dep)_dependencies))))
  19. endef
  20. define fetch_file_inner
  21. ( mkdir -p $$($(1)_download_dir) && echo Fetching $(3) from $(2) && \
  22. $(build_DOWNLOAD) "$$($(1)_download_dir)/$(4).temp" "$(2)/$(3)" && \
  23. echo "$(5) $$($(1)_download_dir)/$(4).temp" > $$($(1)_download_dir)/.$(4).hash && \
  24. $(build_SHA256SUM) -c $$($(1)_download_dir)/.$(4).hash && \
  25. mv $$($(1)_download_dir)/$(4).temp $$($(1)_source_dir)/$(4) && \
  26. rm -rf $$($(1)_download_dir) )
  27. endef
  28. define fetch_file
  29. ( test -f $$($(1)_source_dir)/$(4) || \
  30. ( $(call fetch_file_inner,$(1),$(2),$(3),$(4),$(5)) || \
  31. $(call fetch_file_inner,$(1),$(FALLBACK_DOWNLOAD_PATH),$(3),$(4),$(5))))
  32. endef
  33. define int_get_build_recipe_hash
  34. $(eval $(1)_all_file_checksums:=$(shell $(build_SHA256SUM) $(meta_depends) packages/$(1).mk $(addprefix $(PATCHES_PATH)/$(1)/,$($(1)_patches)) | cut -d" " -f1))
  35. $(eval $(1)_recipe_hash:=$(shell echo -n "$($(1)_all_file_checksums)" | $(build_SHA256SUM) | cut -d" " -f1))
  36. endef
  37. define int_get_build_id
  38. $(eval $(1)_dependencies += $($(1)_$(host_arch)_$(host_os)_dependencies) $($(1)_$(host_os)_dependencies))
  39. $(eval $(1)_all_dependencies:=$(call int_get_all_dependencies,$(1),$($($(1)_type)_native_toolchain) $($(1)_dependencies)))
  40. $(foreach dep,$($(1)_all_dependencies),$(eval $(1)_build_id_deps+=$(dep)-$($(dep)_version)-$($(dep)_recipe_hash)))
  41. $(eval $(1)_build_id_long:=$(1)-$($(1)_version)-$($(1)_recipe_hash)-$(release_type) $($(1)_build_id_deps) $($($(1)_type)_id_string))
  42. $(eval $(1)_build_id:=$(shell echo -n "$($(1)_build_id_long)" | $(build_SHA256SUM) | cut -c-$(HASH_LENGTH)))
  43. final_build_id_long+=$($(package)_build_id_long)
  44. #compute package-specific paths
  45. $(1)_build_subdir?=.
  46. $(1)_download_file?=$($(1)_file_name)
  47. $(1)_source_dir:=$(SOURCES_PATH)
  48. $(1)_source:=$$($(1)_source_dir)/$($(1)_file_name)
  49. $(1)_staging_dir=$(base_staging_dir)/$(host)/$(1)/$($(1)_version)-$($(1)_build_id)
  50. $(1)_staging_prefix_dir:=$$($(1)_staging_dir)$($($(1)_type)_prefix)
  51. $(1)_extract_dir:=$(base_build_dir)/$(host)/$(1)/$($(1)_version)-$($(1)_build_id)
  52. $(1)_download_dir:=$(base_download_dir)/$(1)-$($(1)_version)
  53. $(1)_build_dir:=$$($(1)_extract_dir)/$$($(1)_build_subdir)
  54. $(1)_cached_checksum:=$(BASE_CACHE)/$(host)/$(1)/$(1)-$($(1)_version)-$($(1)_build_id).tar.gz.hash
  55. $(1)_patch_dir:=$(base_build_dir)/$(host)/$(1)/$($(1)_version)-$($(1)_build_id)/.patches-$($(1)_build_id)
  56. $(1)_prefixbin:=$($($(1)_type)_prefix)/bin/
  57. $(1)_cached:=$(BASE_CACHE)/$(host)/$(1)/$(1)-$($(1)_version)-$($(1)_build_id).tar.gz
  58. $(1)_all_sources=$($(1)_file_name) $($(1)_extra_sources)
  59. #stamps
  60. $(1)_fetched=$(SOURCES_PATH)/download-stamps/.stamp_fetched-$(1)-$($(1)_file_name).hash
  61. $(1)_extracted=$$($(1)_extract_dir)/.stamp_extracted
  62. $(1)_preprocessed=$$($(1)_extract_dir)/.stamp_preprocessed
  63. $(1)_cleaned=$$($(1)_extract_dir)/.stamp_cleaned
  64. $(1)_built=$$($(1)_build_dir)/.stamp_built
  65. $(1)_configured=$$($(1)_build_dir)/.stamp_configured
  66. $(1)_staged=$$($(1)_staging_dir)/.stamp_staged
  67. $(1)_postprocessed=$$($(1)_staging_prefix_dir)/.stamp_postprocessed
  68. $(1)_download_path_fixed=$(subst :,\:,$$($(1)_download_path))
  69. #default commands
  70. $(1)_fetch_cmds ?= $(call fetch_file,$(1),$(subst \:,:,$$($(1)_download_path_fixed)),$$($(1)_download_file),$($(1)_file_name),$($(1)_sha256_hash))
  71. $(1)_extract_cmds ?= mkdir -p $$($(1)_extract_dir) && echo "$$($(1)_sha256_hash) $$($(1)_source)" > $$($(1)_extract_dir)/.$$($(1)_file_name).hash && $(build_SHA256SUM) -c $$($(1)_extract_dir)/.$$($(1)_file_name).hash && tar --strip-components=1 -xf $$($(1)_source)
  72. $(1)_preprocess_cmds ?=
  73. $(1)_build_cmds ?=
  74. $(1)_config_cmds ?=
  75. $(1)_stage_cmds ?=
  76. $(1)_set_vars ?=
  77. all_sources+=$$($(1)_fetched)
  78. endef
  79. #$(foreach dep_target,$($(1)_all_dependencies),$(eval $(1)_dependency_targets=$($(dep_target)_cached)))
  80. define int_config_attach_build_config
  81. $(eval $(call $(1)_set_vars,$(1)))
  82. $(1)_cflags+=$($(1)_cflags_$(release_type))
  83. $(1)_cflags+=$($(1)_cflags_$(host_arch)) $($(1)_cflags_$(host_arch)_$(release_type))
  84. $(1)_cflags+=$($(1)_cflags_$(host_os)) $($(1)_cflags_$(host_os)_$(release_type))
  85. $(1)_cflags+=$($(1)_cflags_$(host_arch)_$(host_os)) $($(1)_cflags_$(host_arch)_$(host_os)_$(release_type))
  86. $(1)_cxxflags+=$($(1)_cxxflags_$(release_type))
  87. $(1)_cxxflags+=$($(1)_cxxflags_$(host_arch)) $($(1)_cxxflags_$(host_arch)_$(release_type))
  88. $(1)_cxxflags+=$($(1)_cxxflags_$(host_os)) $($(1)_cxxflags_$(host_os)_$(release_type))
  89. $(1)_cxxflags+=$($(1)_cxxflags_$(host_arch)_$(host_os)) $($(1)_cxxflags_$(host_arch)_$(host_os)_$(release_type))
  90. $(1)_cppflags+=$($(1)_cppflags_$(release_type))
  91. $(1)_cppflags+=$($(1)_cppflags_$(host_arch)) $($(1)_cppflags_$(host_arch)_$(release_type))
  92. $(1)_cppflags+=$($(1)_cppflags_$(host_os)) $($(1)_cppflags_$(host_os)_$(release_type))
  93. $(1)_cppflags+=$($(1)_cppflags_$(host_arch)_$(host_os)) $($(1)_cppflags_$(host_arch)_$(host_os)_$(release_type))
  94. $(1)_ldflags+=$($(1)_ldflags_$(release_type))
  95. $(1)_ldflags+=$($(1)_ldflags_$(host_arch)) $($(1)_ldflags_$(host_arch)_$(release_type))
  96. $(1)_ldflags+=$($(1)_ldflags_$(host_os)) $($(1)_ldflags_$(host_os)_$(release_type))
  97. $(1)_ldflags+=$($(1)_ldflags_$(host_arch)_$(host_os)) $($(1)_ldflags_$(host_arch)_$(host_os)_$(release_type))
  98. $(1)_build_opts+=$$($(1)_build_opts_$(release_type))
  99. $(1)_build_opts+=$$($(1)_build_opts_$(host_arch)) $$($(1)_build_opts_$(host_arch)_$(release_type))
  100. $(1)_build_opts+=$$($(1)_build_opts_$(host_os)) $$($(1)_build_opts_$(host_os)_$(release_type))
  101. $(1)_build_opts+=$$($(1)_build_opts_$(host_arch)_$(host_os)) $$($(1)_build_opts_$(host_arch)_$(host_os)_$(release_type))
  102. $(1)_config_opts+=$$($(1)_config_opts_$(release_type))
  103. $(1)_config_opts+=$$($(1)_config_opts_$(host_arch)) $$($(1)_config_opts_$(host_arch)_$(release_type))
  104. $(1)_config_opts+=$$($(1)_config_opts_$(host_os)) $$($(1)_config_opts_$(host_os)_$(release_type))
  105. $(1)_config_opts+=$$($(1)_config_opts_$(host_arch)_$(host_os)) $$($(1)_config_opts_$(host_arch)_$(host_os)_$(release_type))
  106. $(1)_config_env+=$$($(1)_config_env_$(release_type))
  107. $(1)_config_env+=$($(1)_config_env_$(host_arch)) $($(1)_config_env_$(host_arch)_$(release_type))
  108. $(1)_config_env+=$($(1)_config_env_$(host_os)) $($(1)_config_env_$(host_os)_$(release_type))
  109. $(1)_config_env+=$($(1)_config_env_$(host_arch)_$(host_os)) $($(1)_config_env_$(host_arch)_$(host_os)_$(release_type))
  110. $(1)_config_env+=PKG_CONFIG_LIBDIR=$($($(1)_type)_prefix)/lib/pkgconfig
  111. $(1)_config_env+=PKG_CONFIG_PATH=$($($(1)_type)_prefix)/share/pkgconfig
  112. $(1)_config_env+=PATH=$(build_prefix)/bin:$(PATH)
  113. $(1)_build_env+=PATH=$(build_prefix)/bin:$(PATH)
  114. $(1)_stage_env+=PATH=$(build_prefix)/bin:$(PATH)
  115. $(1)_autoconf=./configure --host=$($($(1)_type)_host) --disable-dependency-tracking --prefix=$($($(1)_type)_prefix) $$($(1)_config_opts) CC="$$($(1)_cc)" CXX="$$($(1)_cxx)"
  116. ifneq ($($(1)_nm),)
  117. $(1)_autoconf += NM="$$($(1)_nm)"
  118. endif
  119. ifneq ($($(1)_ranlib),)
  120. $(1)_autoconf += RANLIB="$$($(1)_ranlib)"
  121. endif
  122. ifneq ($($(1)_ar),)
  123. $(1)_autoconf += AR="$$($(1)_ar)"
  124. endif
  125. ifneq ($($(1)_cflags),)
  126. $(1)_autoconf += CFLAGS="$$($(1)_cflags)"
  127. endif
  128. ifneq ($($(1)_cxxflags),)
  129. $(1)_autoconf += CXXFLAGS="$$($(1)_cxxflags)"
  130. endif
  131. ifneq ($($(1)_cppflags),)
  132. $(1)_autoconf += CPPFLAGS="$$($(1)_cppflags)"
  133. endif
  134. ifneq ($($(1)_ldflags),)
  135. $(1)_autoconf += LDFLAGS="$$($(1)_ldflags)"
  136. endif
  137. endef
  138. define int_add_cmds
  139. $($(1)_fetched):
  140. $(AT)mkdir -p $$(@D) $(SOURCES_PATH)
  141. $(AT)rm -f $$@
  142. $(AT)touch $$@
  143. $(AT)cd $$(@D); $(call $(1)_fetch_cmds,$(1))
  144. $(AT)cd $($(1)_source_dir); $(foreach source,$($(1)_all_sources),$(build_SHA256SUM) $(source) >> $$(@);)
  145. $(AT)touch $$@
  146. $($(1)_extracted): | $($(1)_fetched)
  147. $(AT)echo Extracting $(1)...
  148. $(AT)mkdir -p $$(@D)
  149. $(AT)cd $$(@D); $(call $(1)_extract_cmds,$(1))
  150. $(AT)touch $$@
  151. $($(1)_preprocessed): | $($(1)_dependencies) $($(1)_extracted)
  152. $(AT)echo Preprocessing $(1)...
  153. $(AT)mkdir -p $$(@D) $($(1)_patch_dir)
  154. $(AT)$(foreach patch,$($(1)_patches),cd $(PATCHES_PATH)/$(1); cp $(patch) $($(1)_patch_dir) ;)
  155. $(AT)cd $$(@D); $(call $(1)_preprocess_cmds, $(1))
  156. $(AT)touch $$@
  157. $($(1)_configured): | $($(1)_preprocessed)
  158. $(AT)echo Configuring $(1)...
  159. $(AT)rm -rf $(host_prefix); mkdir -p $(host_prefix)/lib; cd $(host_prefix); $(foreach package,$($(1)_all_dependencies), tar xf $($(package)_cached); )
  160. $(AT)mkdir -p $$(@D)
  161. $(AT)+cd $$(@D); $($(1)_config_env) $(call $(1)_config_cmds, $(1))
  162. $(AT)touch $$@
  163. $($(1)_built): | $($(1)_configured)
  164. $(AT)echo Building $(1)...
  165. $(AT)mkdir -p $$(@D)
  166. $(AT)+cd $$(@D); $($(1)_build_env) $(call $(1)_build_cmds, $(1))
  167. $(AT)touch $$@
  168. $($(1)_staged): | $($(1)_built)
  169. $(AT)echo Staging $(1)...
  170. $(AT)mkdir -p $($(1)_staging_dir)/$(host_prefix)
  171. $(AT)cd $($(1)_build_dir); $($(1)_stage_env) $(call $(1)_stage_cmds, $(1))
  172. $(AT)rm -rf $($(1)_extract_dir)
  173. $(AT)touch $$@
  174. $($(1)_postprocessed): | $($(1)_staged)
  175. $(AT)echo Postprocessing $(1)...
  176. $(AT)cd $($(1)_staging_prefix_dir); $(call $(1)_postprocess_cmds)
  177. $(AT)touch $$@
  178. $($(1)_cached): | $($(1)_dependencies) $($(1)_postprocessed)
  179. $(AT)echo Caching $(1)...
  180. $(AT)cd $$($(1)_staging_dir)/$(host_prefix); find . | sort | tar --no-recursion -czf $$($(1)_staging_dir)/$$(@F) -T -
  181. $(AT)mkdir -p $$(@D)
  182. $(AT)rm -rf $$(@D) && mkdir -p $$(@D)
  183. $(AT)mv $$($(1)_staging_dir)/$$(@F) $$(@)
  184. $(AT)rm -rf $($(1)_staging_dir)
  185. $($(1)_cached_checksum): $($(1)_cached)
  186. $(AT)cd $$(@D); $(build_SHA256SUM) $$(<F) > $$(@)
  187. .PHONY: $(1)
  188. $(1): | $($(1)_cached_checksum)
  189. .SECONDARY: $($(1)_cached) $($(1)_postprocessed) $($(1)_staged) $($(1)_built) $($(1)_configured) $($(1)_preprocessed) $($(1)_extracted) $($(1)_fetched)
  190. endef
  191. # These functions create the build targets for each package. They must be
  192. # broken down into small steps so that each part is done for all packages
  193. # before moving on to the next step. Otherwise, a package's info
  194. # (build-id for example) would only be available to another package if it
  195. # happened to be computed already.
  196. #set the type for host/build packages.
  197. $(foreach native_package,$(native_packages),$(eval $(native_package)_type=build))
  198. $(foreach package,$(packages),$(eval $(package)_type=$(host_arch)_$(host_os)))
  199. #set overridable defaults
  200. $(foreach package,$(all_packages),$(eval $(call int_vars,$(package))))
  201. #include package files
  202. $(foreach package,$(all_packages),$(eval include packages/$(package).mk))
  203. #compute a hash of all files that comprise this package's build recipe
  204. $(foreach package,$(all_packages),$(eval $(call int_get_build_recipe_hash,$(package))))
  205. #generate a unique id for this package, incorporating its dependencies as well
  206. $(foreach package,$(all_packages),$(eval $(call int_get_build_id,$(package))))
  207. #compute final vars after reading package vars
  208. $(foreach package,$(all_packages),$(eval $(call int_config_attach_build_config,$(package))))
  209. #create build targets
  210. $(foreach package,$(all_packages),$(eval $(call int_add_cmds,$(package))))
  211. #special exception: if a toolchain package exists, all non-native packages depend on it
  212. $(foreach package,$(packages),$(eval $($(package)_unpacked): |$($($(host_arch)_$(host_os)_native_toolchain)_cached) ))