host-build.mk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #
  2. # Copyright (C) 2006-2010 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. HOST_BUILD_DIR ?= $(BUILD_DIR_HOST)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
  8. HOST_INSTALL_DIR ?= $(HOST_BUILD_DIR)/host-install
  9. HOST_BUILD_PARALLEL ?=
  10. ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
  11. HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) -j)
  12. else
  13. HOST_MAKE_J:=-j$(CONFIG_PKG_BUILD_JOBS)
  14. endif
  15. ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
  16. HOST_JOBS?=-j1
  17. else
  18. HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
  19. $(if $(CONFIG_PKG_BUILD_PARALLEL),$(HOST_MAKE_J),-j1),-j1)
  20. endif
  21. include $(INCLUDE_DIR)/host.mk
  22. include $(INCLUDE_DIR)/unpack.mk
  23. include $(INCLUDE_DIR)/depends.mk
  24. BUILD_TYPES += host
  25. HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
  26. HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
  27. HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
  28. HOST_STAMP_INSTALLED:=$(STAGING_DIR_HOST)/stamp/.$(PKG_NAME)_installed
  29. override MAKEFLAGS=
  30. include $(INCLUDE_DIR)/download.mk
  31. include $(INCLUDE_DIR)/quilt.mk
  32. include $(INCLUDE_DIR)/autotools.mk
  33. Host/Patch:=$(Host/Patch/Default)
  34. ifneq ($(strip $(HOST_UNPACK)),)
  35. define Host/Prepare/Default
  36. $(HOST_UNPACK)
  37. $(Host/Patch)
  38. endef
  39. endif
  40. define Host/Prepare
  41. $(call Host/Prepare/Default)
  42. endef
  43. HOST_CONFIGURE_VARS = \
  44. CC="$(HOSTCC)" \
  45. CFLAGS="$(HOST_CFLAGS)" \
  46. CPPFLAGS="$(HOST_CPPFLAGS)" \
  47. LDFLAGS="$(HOST_LDFLAGS)" \
  48. SHELL="$(SHELL)"
  49. HOST_CONFIGURE_ARGS = \
  50. --target=$(GNU_HOST_NAME) \
  51. --host=$(GNU_HOST_NAME) \
  52. --build=$(GNU_HOST_NAME) \
  53. --program-prefix="" \
  54. --program-suffix="" \
  55. --prefix=$(STAGING_DIR_HOST) \
  56. --exec-prefix=$(STAGING_DIR_HOST) \
  57. --sysconfdir=$(STAGING_DIR_HOST)/etc \
  58. --localstatedir=$(STAGING_DIR_HOST)/var \
  59. --sbindir=$(STAGING_DIR_HOST)/bin
  60. HOST_MAKE_FLAGS =
  61. HOST_CONFIGURE_CMD = $(BASH) ./configure
  62. define Host/Configure/Default
  63. $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
  64. if [ -x configure ]; then \
  65. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
  66. $(2) \
  67. $(HOST_CONFIGURE_CMD) \
  68. $(HOST_CONFIGURE_VARS) \
  69. $(HOST_CONFIGURE_ARGS) \
  70. $(1); \
  71. fi \
  72. )
  73. endef
  74. define Host/Configure
  75. $(call Host/Configure/Default)
  76. endef
  77. define Host/Compile/Default
  78. +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
  79. $(HOST_MAKE_FLAGS) \
  80. $(1)
  81. endef
  82. define Host/Compile
  83. $(call Host/Compile/Default)
  84. endef
  85. define Host/Install/Default
  86. $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
  87. endef
  88. define Host/Install
  89. $(call Host/Install/Default)
  90. endef
  91. ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
  92. define HostHost/Autoclean
  93. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
  94. $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
  95. endef
  96. endif
  97. define Download/default
  98. FILE:=$(PKG_SOURCE)
  99. URL:=$(PKG_SOURCE_URL)
  100. PROTO:=$(PKG_SOURCE_PROTO)
  101. SUBDIR:=$(PKG_SOURCE_SUBDIR)
  102. VERSION:=$(PKG_SOURCE_VERSION)
  103. MD5SUM:=$(PKG_MD5SUM)
  104. MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM)
  105. endef
  106. define Host/Exports/Default
  107. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-*),-I $$(p))
  108. $(1) : export STAGING_PREFIX=$$(STAGING_DIR_HOST)
  109. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
  110. $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
  111. $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
  112. endef
  113. Host/Exports=$(Host/Exports/Default)
  114. .NOTPARALLEL:
  115. ifndef DUMP
  116. define HostBuild
  117. $(if $(HOST_QUILT),$(Host/Quilt))
  118. $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  119. $(if $(DUMP),,$(call HostHost/Autoclean))
  120. $(HOST_STAMP_PREPARED):
  121. @-rm -rf $(HOST_BUILD_DIR)
  122. @mkdir -p $(HOST_BUILD_DIR)
  123. $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
  124. $(call Host/Prepare)
  125. $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
  126. touch $$@
  127. $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
  128. $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
  129. $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
  130. $(call Host/Configure)
  131. $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
  132. touch $$@
  133. $(call Host/Exports,$(HOST_STAMP_BUILT))
  134. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  135. $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
  136. $(call Host/Compile)
  137. $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
  138. touch $$@
  139. $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
  140. $(call Host/Install)
  141. $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
  142. mkdir -p $$(shell dirname $$@)
  143. touch $(HOST_STAMP_BUILT)
  144. touch $$@
  145. ifndef STAMP_BUILT
  146. prepare: host-prepare
  147. compile: host-compile
  148. install: host-install
  149. clean: host-clean
  150. update: host-update
  151. refresh: host-refresh
  152. endif
  153. host-prepare: $(HOST_STAMP_PREPARED)
  154. host-configure: $(HOST_STAMP_CONFIGURED)
  155. host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
  156. host-install: $(HOST_STAMP_INSTALLED)
  157. host-clean: FORCE
  158. $(call Host/Clean)
  159. $(call Host/Uninstall)
  160. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
  161. endef
  162. download:
  163. prepare:
  164. compile:
  165. install:
  166. clean:
  167. endif