host-build.mk 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. include $(INCLUDE_DIR)/download.mk
  8. HOST_BUILD_DIR ?= $(BUILD_DIR_HOST)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
  9. HOST_INSTALL_DIR ?= $(HOST_BUILD_DIR)/host-install
  10. HOST_BUILD_PARALLEL ?=
  11. HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
  12. ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
  13. HOST_JOBS?=-j1
  14. else
  15. HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL),$(HOST_MAKE_J),-j1)
  16. endif
  17. include $(INCLUDE_DIR)/host.mk
  18. include $(INCLUDE_DIR)/unpack.mk
  19. include $(INCLUDE_DIR)/depends.mk
  20. include $(INCLUDE_DIR)/quilt.mk
  21. BUILD_TYPES += host
  22. HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
  23. HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
  24. HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
  25. HOST_BUILD_PREFIX:=$(if $(IS_PACKAGE_BUILD),$(STAGING_DIR_HOSTPKG),$(STAGING_DIR_HOST))
  26. HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.$(PKG_NAME)_installed
  27. override MAKEFLAGS=
  28. include $(INCLUDE_DIR)/autotools.mk
  29. Host/Patch:=$(Host/Patch/Default)
  30. ifneq ($(strip $(HOST_UNPACK)),)
  31. define Host/Prepare/Default
  32. $(HOST_UNPACK)
  33. [ ! -d ./src/ ] || $(CP) ./src/* $(HOST_BUILD_DIR)
  34. $(Host/Patch)
  35. endef
  36. endif
  37. define Host/Prepare
  38. $(call Host/Prepare/Default)
  39. endef
  40. HOST_CONFIGURE_VARS = \
  41. CC="$(HOSTCC)" \
  42. CFLAGS="$(HOST_CFLAGS)" \
  43. CPPFLAGS="$(HOST_CPPFLAGS)" \
  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. --program-prefix="" \
  51. --program-suffix="" \
  52. --prefix=$(HOST_BUILD_PREFIX) \
  53. --exec-prefix=$(HOST_BUILD_PREFIX) \
  54. --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
  55. --localstatedir=$(HOST_BUILD_PREFIX)/var \
  56. --sbindir=$(HOST_BUILD_PREFIX)/bin
  57. HOST_MAKE_VARS = \
  58. CFLAGS="$(HOST_CFLAGS)" \
  59. CPPFLAGS="$(HOST_CPPFLAGS)" \
  60. CXXFLAGS="$(HOST_CXXFLAGS)" \
  61. LDFLAGS="$(HOST_LDFLAGS)"
  62. HOST_MAKE_FLAGS =
  63. HOST_CONFIGURE_CMD = $(BASH) ./configure
  64. ifeq ($(HOST_OS),Darwin)
  65. HOST_CONFIG_SITE:=$(INCLUDE_DIR)/site/darwin
  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. $(HOST_CONFIGURE_VARS) \
  72. $(2) \
  73. $(HOST_CONFIGURE_CMD) \
  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. +$(HOST_MAKE_VARS) \
  84. $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
  85. $(HOST_MAKE_FLAGS) \
  86. $(1)
  87. endef
  88. define Host/Compile
  89. $(call Host/Compile/Default)
  90. endef
  91. define Host/Install/Default
  92. $(call Host/Compile/Default,install)
  93. endef
  94. define Host/Install
  95. $(call Host/Install/Default,$(HOST_BUILD_PREFIX))
  96. endef
  97. ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
  98. define HostHost/Autoclean
  99. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
  100. $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
  101. endef
  102. endif
  103. define Host/Exports/Default
  104. $(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)/host/share/aclocal-*)),-I $$(p))
  105. $(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
  106. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
  107. $(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
  108. $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
  109. $(if $(HOST_CONFIG_SITE),$(1) : export CONFIG_SITE:=$(HOST_CONFIG_SITE))
  110. $(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
  111. endef
  112. Host/Exports=$(Host/Exports/Default)
  113. .NOTPARALLEL:
  114. ifndef DUMP
  115. define HostBuild/Core
  116. $(if $(HOST_QUILT),$(Host/Quilt))
  117. $(if $(DUMP),,$(call HostHost/Autoclean))
  118. $(HOST_STAMP_PREPARED):
  119. @-rm -rf $(HOST_BUILD_DIR)
  120. @mkdir -p $(HOST_BUILD_DIR)
  121. $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
  122. $(call Host/Prepare)
  123. $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
  124. touch $$@
  125. $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
  126. $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
  127. $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
  128. $(call Host/Configure)
  129. $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
  130. touch $$@
  131. $(call Host/Exports,$(HOST_STAMP_BUILT))
  132. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  133. $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
  134. $(call Host/Compile)
  135. $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
  136. touch $$@
  137. $(call Host/Exports,$(HOST_STAMP_INSTALLED))
  138. $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
  139. $(call Host/Install,$(HOST_BUILD_PREFIX))
  140. $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
  141. mkdir -p $$(shell dirname $$@)
  142. touch $(HOST_STAMP_BUILT)
  143. touch $$@
  144. ifndef STAMP_BUILT
  145. prepare: host-prepare
  146. compile: host-compile
  147. install: host-install
  148. clean: host-clean
  149. update: host-update
  150. refresh: host-refresh
  151. endif
  152. host-prepare: $(HOST_STAMP_PREPARED)
  153. host-configure: $(HOST_STAMP_CONFIGURED)
  154. host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
  155. host-install: $(HOST_STAMP_INSTALLED)
  156. host-clean: FORCE
  157. $(call Host/Clean)
  158. $(call Host/Uninstall)
  159. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
  160. endef
  161. download:
  162. prepare:
  163. compile:
  164. install:
  165. clean:
  166. endif
  167. define HostBuild
  168. $(HostBuild/Core)
  169. $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  170. endef