host-build.mk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
  12. HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
  13. else
  14. HOST_MAKE_J:=-j$(CONFIG_PKG_BUILD_JOBS)
  15. endif
  16. ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
  17. HOST_JOBS?=-j1
  18. else
  19. HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
  20. $(if $(CONFIG_PKG_BUILD_PARALLEL),$(HOST_MAKE_J),-j1),-j1)
  21. endif
  22. include $(INCLUDE_DIR)/host.mk
  23. include $(INCLUDE_DIR)/unpack.mk
  24. include $(INCLUDE_DIR)/depends.mk
  25. BUILD_TYPES += host
  26. HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
  27. HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
  28. HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
  29. HOST_BUILD_PREFIX:=$(if $(IS_PACKAGE_BUILD),$(STAGING_DIR_HOSTPKG),$(STAGING_DIR_HOST))
  30. HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.$(PKG_NAME)_installed
  31. override MAKEFLAGS=
  32. include $(INCLUDE_DIR)/quilt.mk
  33. include $(INCLUDE_DIR)/autotools.mk
  34. Host/Patch:=$(Host/Patch/Default)
  35. ifneq ($(strip $(HOST_UNPACK)),)
  36. define Host/Prepare/Default
  37. $(HOST_UNPACK)
  38. $(Host/Patch)
  39. endef
  40. endif
  41. define Host/Prepare
  42. $(call Host/Prepare/Default)
  43. endef
  44. ifeq ($(HOST_OS),Darwin)
  45. HOST_CFLAGS += -I/usr/local/opt/openssl/include
  46. HOST_LDFLAGS += -L/usr/local/opt/openssl/lib
  47. endif
  48. HOST_CONFIGURE_VARS = \
  49. CC="$(HOSTCC)" \
  50. CFLAGS="$(HOST_CFLAGS)" \
  51. CPPFLAGS="$(HOST_CPPFLAGS)" \
  52. LDFLAGS="$(HOST_LDFLAGS)" \
  53. SHELL="$(SHELL)"
  54. HOST_CONFIGURE_ARGS = \
  55. --target=$(GNU_HOST_NAME) \
  56. --host=$(GNU_HOST_NAME) \
  57. --build=$(GNU_HOST_NAME) \
  58. --program-prefix="" \
  59. --program-suffix="" \
  60. --prefix=$(HOST_BUILD_PREFIX) \
  61. --exec-prefix=$(HOST_BUILD_PREFIX) \
  62. --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
  63. --localstatedir=$(HOST_BUILD_PREFIX)/var \
  64. --sbindir=$(HOST_BUILD_PREFIX)/bin
  65. HOST_MAKE_FLAGS =
  66. HOST_CONFIGURE_CMD = $(BASH) ./configure
  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,$(HOST_BUILD_PREFIX))
  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 Host/Exports/Default
  103. $(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))
  104. $(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
  105. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
  106. $(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
  107. $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
  108. $(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
  109. endef
  110. Host/Exports=$(Host/Exports/Default)
  111. .NOTPARALLEL:
  112. ifndef DUMP
  113. define HostBuild
  114. $(if $(HOST_QUILT),$(Host/Quilt))
  115. $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  116. $(if $(DUMP),,$(call HostHost/Autoclean))
  117. $(HOST_STAMP_PREPARED):
  118. @-rm -rf $(HOST_BUILD_DIR)
  119. @mkdir -p $(HOST_BUILD_DIR)
  120. $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
  121. $(call Host/Prepare)
  122. $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
  123. touch $$@
  124. $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
  125. $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
  126. $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
  127. $(call Host/Configure)
  128. $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
  129. touch $$@
  130. $(call Host/Exports,$(HOST_STAMP_BUILT))
  131. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  132. $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
  133. $(call Host/Compile)
  134. $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
  135. touch $$@
  136. $(call Host/Exports,$(HOST_STAMP_INSTALLED))
  137. $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
  138. $(call Host/Install,$(HOST_BUILD_PREFIX))
  139. $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
  140. mkdir -p $$(shell dirname $$@)
  141. touch $(HOST_STAMP_BUILT)
  142. touch $$@
  143. ifndef STAMP_BUILT
  144. prepare: host-prepare
  145. compile: host-compile
  146. install: host-install
  147. clean: host-clean
  148. update: host-update
  149. refresh: host-refresh
  150. endif
  151. host-prepare: $(HOST_STAMP_PREPARED)
  152. host-configure: $(HOST_STAMP_CONFIGURED)
  153. host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
  154. host-install: $(HOST_STAMP_INSTALLED)
  155. host-clean: FORCE
  156. $(call Host/Clean)
  157. $(call Host/Uninstall)
  158. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
  159. endef
  160. download:
  161. prepare:
  162. compile:
  163. install:
  164. clean:
  165. endif