1
0

host-build.mk 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2006-2020 OpenWrt.org
  4. include $(INCLUDE_DIR)/download.mk
  5. HOST_BUILD_DIR ?= $(BUILD_DIR_HOST)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
  6. HOST_INSTALL_DIR ?= $(HOST_BUILD_DIR)/host-install
  7. HOST_BUILD_PARALLEL ?=
  8. HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
  9. ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
  10. HOST_JOBS?=-j1
  11. else
  12. HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL),$(HOST_MAKE_J),-j1)
  13. endif
  14. include $(INCLUDE_DIR)/unpack.mk
  15. include $(INCLUDE_DIR)/depends.mk
  16. include $(INCLUDE_DIR)/quilt.mk
  17. BUILD_TYPES += host
  18. HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call $(if $(CONFIG_AUTOREMOVE),find_md5_reproducible,find_md5),${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(HOST_PREPARED_DEPENDS)))
  19. HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
  20. HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
  21. HOST_BUILD_PREFIX?=$(if $(IS_PACKAGE_BUILD),$(STAGING_DIR_HOSTPKG),$(STAGING_DIR_HOST))
  22. HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.$(PKG_NAME)_installed
  23. HOST_STAMP_PROGRAMS:=$(foreach program,$(PKG_PROGRAMS),$(subst $(PKG_NAME),$(program),$(HOST_STAMP_INSTALLED)) )
  24. override MAKEFLAGS=
  25. include $(INCLUDE_DIR)/autotools.mk
  26. _host_target:=$(if $(HOST_QUILT),,.)
  27. Host/Patch:=$(Host/Patch/Default)
  28. ifneq ($(strip $(HOST_UNPACK)),)
  29. define Host/Prepare/Default
  30. $(HOST_UNPACK)
  31. [ ! -d ./src/ ] || $(CP) ./src/* $(HOST_BUILD_DIR)
  32. $(Host/Patch)
  33. endef
  34. endif
  35. define Host/Prepare
  36. $(call Host/Prepare/Default)
  37. endef
  38. HOST_CONFIGURE_VARS = \
  39. CC="$(HOSTCC)" \
  40. CFLAGS="$(HOST_CFLAGS)" \
  41. CXX="$(HOSTCXX)" \
  42. CPPFLAGS="$(HOST_CPPFLAGS)" \
  43. CXXFLAGS="$(HOST_CXXFLAGS)" \
  44. LDFLAGS="$(HOST_LDFLAGS)" \
  45. CONFIG_SHELL="$(SHELL)"
  46. HOST_CONFIGURE_ARGS = \
  47. --target=$(GNU_HOST_NAME) \
  48. --host=$(GNU_HOST_NAME) \
  49. --build=$(GNU_HOST_NAME) \
  50. --disable-dependency-tracking \
  51. --program-prefix="" \
  52. --program-suffix="" \
  53. --prefix=$(HOST_BUILD_PREFIX) \
  54. --exec-prefix=$(HOST_BUILD_PREFIX) \
  55. --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
  56. --localstatedir=$(HOST_BUILD_PREFIX)/var \
  57. --sbindir=$(HOST_BUILD_PREFIX)/bin
  58. HOST_MAKE_VARS = \
  59. CFLAGS="$(HOST_CFLAGS)" \
  60. CPPFLAGS="$(HOST_CPPFLAGS)" \
  61. CXXFLAGS="$(HOST_CXXFLAGS)" \
  62. LDFLAGS="$(HOST_LDFLAGS)"
  63. HOST_MAKE_FLAGS =
  64. HOST_CONFIGURE_CMD = $(BASH) ./configure
  65. ifeq ($(HOST_OS),Darwin)
  66. HOST_CONFIG_SITE:=$(INCLUDE_DIR)/site/darwin
  67. endif
  68. define Host/Configure/Default
  69. $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
  70. if [ -x configure ]; then \
  71. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
  72. $(HOST_CONFIGURE_VARS) \
  73. $(2) \
  74. $(HOST_CONFIGURE_CMD) \
  75. $(HOST_CONFIGURE_ARGS) \
  76. $(1); \
  77. fi \
  78. )
  79. endef
  80. define Host/Configure
  81. $(call Host/Configure/Default)
  82. endef
  83. define Host/Compile/Default
  84. +$(HOST_MAKE_VARS) \
  85. $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
  86. $(HOST_MAKE_FLAGS) \
  87. $(1)
  88. endef
  89. define Host/Compile
  90. $(call Host/Compile/Default)
  91. endef
  92. define Host/Install/Default
  93. $(call Host/Compile/Default,install)
  94. endef
  95. define Host/Install
  96. $(call Host/Install/Default,$(HOST_BUILD_PREFIX))
  97. endef
  98. ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
  99. define HostHost/Autoclean
  100. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
  101. $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
  102. endef
  103. endif
  104. define Host/Exports/Default
  105. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-* $(if $(IS_PACKAGE_BUILD),$$(STAGING_DIR)/host/share/aclocal $$(STAGING_DIR_HOSTPKG)/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*)),-I $$(p))
  106. $(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
  107. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
  108. $(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
  109. $(1) : export GIT_CEILING_DIRECTORIES=$$(BUILD_DIR_HOST)
  110. $(if $(HOST_CONFIG_SITE),$(1) : export CONFIG_SITE:=$(HOST_CONFIG_SITE))
  111. $(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
  112. endef
  113. Host/Exports=$(Host/Exports/Default)
  114. .NOTPARALLEL:
  115. ifndef DUMP
  116. define HostBuild/Core
  117. $(if $(HOST_QUILT),$(Host/Quilt))
  118. $(if $(DUMP),,$(call HostHost/Autoclean))
  119. $(HOST_STAMP_PREPARED):
  120. @-rm -rf $(HOST_BUILD_DIR)
  121. @mkdir -p $(HOST_BUILD_DIR)
  122. $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
  123. $(call Host/Prepare)
  124. $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
  125. touch $$@
  126. $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
  127. $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
  128. $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
  129. $(call Host/Configure)
  130. $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
  131. touch $$@
  132. $(call Host/Exports,$(HOST_STAMP_BUILT))
  133. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  134. $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
  135. $(call Host/Compile)
  136. $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
  137. touch $$@
  138. $(call Host/Exports,$(HOST_STAMP_INSTALLED))
  139. $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
  140. $(call Host/Install,$(HOST_BUILD_PREFIX))
  141. $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
  142. mkdir -p $$(shell dirname $$@)
  143. touch $(HOST_STAMP_BUILT)
  144. touch $$@ $(HOST_STAMP_PROGRAMS)
  145. $(call DefaultTargets,$(patsubst %,host-%,$(DEFAULT_SUBDIR_TARGETS)))
  146. ifndef STAMP_BUILT
  147. $(foreach t,$(DEFAULT_SUBDIR_TARGETS),
  148. $(t): host-$(t)
  149. .$(t): .host-$(t)
  150. )
  151. clean-build: host-clean-build
  152. endif
  153. $(call check_download_integrity)
  154. $(_host_target)host-prepare: $(HOST_STAMP_PREPARED)
  155. $(_host_target)host-configure: $(HOST_STAMP_CONFIGURED)
  156. $(_host_target)host-compile: $(HOST_STAMP_BUILT) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_PROGRAMS)
  157. host-install: host-compile
  158. host-clean-build: FORCE
  159. $(call Host/Uninstall)
  160. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_BUILT)
  161. host-clean: host-clean-build
  162. $(call Host/Clean)
  163. rm -rf $(HOST_STAMP_INSTALLED) $(HOST_STAMP_PROGRAMS)
  164. ifneq ($(CONFIG_AUTOREMOVE),)
  165. host-compile:
  166. $(FIND) $(HOST_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' -print0 | \
  167. $(XARGS) -0 rm -rf
  168. endif
  169. endef
  170. endif
  171. define HostBuild
  172. $(HostBuild/Core)
  173. $(if $(if $(PKG_HOST_ONLY),,$(if $(and $(filter host-%,$(MAKECMDGOALS)),$(PKG_SKIP_DOWNLOAD)),,$(STAMP_PREPARED))),,
  174. $(if $(and $(CONFIG_AUTOREMOVE), $(wildcard $(HOST_STAMP_INSTALLED), $(wildcard $(HOST_STAMP_BUILT)))),,
  175. $(if $(strip $(PKG_SOURCE_URL)),$(call Download,default))
  176. )
  177. )
  178. endef