host-build.mk 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. ifeq ($(HOST_OS),Darwin)
  44. HOST_CFLAGS += -I/usr/local/opt/openssl/include
  45. HOST_LDFLAGS += -L/usr/local/opt/openssl/lib
  46. endif
  47. HOST_CONFIGURE_VARS = \
  48. CC="$(HOSTCC)" \
  49. CFLAGS="$(HOST_CFLAGS)" \
  50. CPPFLAGS="$(HOST_CPPFLAGS)" \
  51. LDFLAGS="$(HOST_LDFLAGS)" \
  52. SHELL="$(SHELL)"
  53. HOST_CONFIGURE_ARGS = \
  54. --target=$(GNU_HOST_NAME) \
  55. --host=$(GNU_HOST_NAME) \
  56. --build=$(GNU_HOST_NAME) \
  57. --program-prefix="" \
  58. --program-suffix="" \
  59. --prefix=$(STAGING_DIR_HOST) \
  60. --exec-prefix=$(STAGING_DIR_HOST) \
  61. --sysconfdir=$(STAGING_DIR_HOST)/etc \
  62. --localstatedir=$(STAGING_DIR_HOST)/var \
  63. --sbindir=$(STAGING_DIR_HOST)/bin
  64. HOST_MAKE_FLAGS =
  65. HOST_CONFIGURE_CMD = $(BASH) ./configure
  66. define Host/Configure/Default
  67. $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
  68. if [ -x configure ]; then \
  69. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
  70. $(2) \
  71. $(HOST_CONFIGURE_CMD) \
  72. $(HOST_CONFIGURE_VARS) \
  73. $(HOST_CONFIGURE_ARGS) \
  74. $(1); \
  75. fi \
  76. )
  77. endef
  78. define Host/Configure
  79. $(call Host/Configure/Default)
  80. endef
  81. define Host/Compile/Default
  82. +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
  83. $(HOST_MAKE_FLAGS) \
  84. $(1)
  85. endef
  86. define Host/Compile
  87. $(call Host/Compile/Default)
  88. endef
  89. define Host/Install/Default
  90. $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
  91. endef
  92. define Host/Install
  93. $(call Host/Install/Default)
  94. endef
  95. ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
  96. define HostHost/Autoclean
  97. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
  98. $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
  99. endef
  100. endif
  101. define Download/default
  102. FILE:=$(PKG_SOURCE)
  103. URL:=$(PKG_SOURCE_URL)
  104. PROTO:=$(PKG_SOURCE_PROTO)
  105. SUBDIR:=$(PKG_SOURCE_SUBDIR)
  106. VERSION:=$(PKG_SOURCE_VERSION)
  107. MD5SUM:=$(PKG_MD5SUM)
  108. MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM)
  109. endef
  110. define Host/Exports/Default
  111. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-*),-I $$(p))
  112. $(1) : export STAGING_PREFIX=$$(STAGING_DIR_HOST)
  113. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
  114. $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
  115. $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
  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 $(HOST_STAMP_BUILT)
  148. touch $$@
  149. ifndef STAMP_BUILT
  150. prepare: host-prepare
  151. compile: host-compile
  152. install: host-install
  153. clean: host-clean
  154. update: host-update
  155. refresh: host-refresh
  156. endif
  157. host-prepare: $(HOST_STAMP_PREPARED)
  158. host-configure: $(HOST_STAMP_CONFIGURED)
  159. host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
  160. host-install: $(HOST_STAMP_INSTALLED)
  161. host-clean: FORCE
  162. $(call Host/Clean)
  163. $(call Host/Uninstall)
  164. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
  165. endef
  166. download:
  167. prepare:
  168. compile:
  169. install:
  170. clean:
  171. endif