host-build.mk 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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="$(BASH)"
  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. ifneq ($(HOST_OS),Darwin)
  63. ifeq ($(CONFIG_BUILD_STATIC_TOOLS),y)
  64. HOST_STATIC_LINKING = -static
  65. endif
  66. endif
  67. define Host/Configure/Default
  68. $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
  69. if [ -x configure ]; then \
  70. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
  71. $(2) \
  72. $(HOST_CONFIGURE_CMD) \
  73. $(HOST_CONFIGURE_VARS) \
  74. $(HOST_CONFIGURE_ARGS) \
  75. $(1); \
  76. fi \
  77. )
  78. endef
  79. define Host/Configure
  80. $(call Host/Configure/Default)
  81. endef
  82. define Host/Compile/Default
  83. +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
  84. $(HOST_MAKE_FLAGS) \
  85. $(1)
  86. endef
  87. define Host/Compile
  88. $(call Host/Compile/Default)
  89. endef
  90. define Host/Install/Default
  91. $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
  92. endef
  93. define Host/Install
  94. $(call Host/Install/Default)
  95. endef
  96. ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
  97. define HostHost/Autoclean
  98. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
  99. $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
  100. endef
  101. endif
  102. define Download/default
  103. FILE:=$(PKG_SOURCE)
  104. URL:=$(PKG_SOURCE_URL)
  105. PROTO:=$(PKG_SOURCE_PROTO)
  106. SUBDIR:=$(PKG_SOURCE_SUBDIR)
  107. VERSION:=$(PKG_SOURCE_VERSION)
  108. MD5SUM:=$(PKG_MD5SUM)
  109. MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM)
  110. endef
  111. define Host/Exports/Default
  112. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-*),-I $$(p))
  113. $(1) : export STAGING_PREFIX=$$(STAGING_DIR_HOST)
  114. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
  115. $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
  116. endef
  117. Host/Exports=$(Host/Exports/Default)
  118. .NOTPARALLEL:
  119. ifndef DUMP
  120. define HostBuild
  121. $(if $(HOST_QUILT),$(Host/Quilt))
  122. $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  123. $(if $(DUMP),,$(call HostHost/Autoclean))
  124. $(HOST_STAMP_PREPARED):
  125. @-rm -rf $(HOST_BUILD_DIR)
  126. @mkdir -p $(HOST_BUILD_DIR)
  127. $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
  128. $(call Host/Prepare)
  129. $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
  130. touch $$@
  131. $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
  132. $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
  133. $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
  134. $(call Host/Configure)
  135. $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
  136. touch $$@
  137. $(call Host/Exports,$(HOST_STAMP_BUILT))
  138. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  139. $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
  140. $(call Host/Compile)
  141. $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
  142. touch $$@
  143. $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
  144. $(call Host/Install)
  145. $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
  146. mkdir -p $$(shell dirname $$@)
  147. touch $$@
  148. ifndef STAMP_BUILT
  149. prepare: host-prepare
  150. compile: host-compile
  151. install: host-install
  152. clean: host-clean
  153. update: host-update
  154. refresh: host-refresh
  155. endif
  156. host-prepare: $(HOST_STAMP_PREPARED)
  157. host-configure: $(HOST_STAMP_CONFIGURED)
  158. host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
  159. host-install: $(HOST_STAMP_INSTALLED)
  160. host-clean: FORCE
  161. $(call Host/Clean)
  162. $(call Host/Uninstall)
  163. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
  164. endef
  165. download:
  166. prepare:
  167. compile:
  168. install:
  169. clean:
  170. endif