host-build.mk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
  11. HOST_JOBS?=-j1
  12. else
  13. HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
  14. $(if $(CONFIG_PKG_BUILD_PARALLEL),-j$(CONFIG_PKG_BUILD_JOBS),-j1),-j1)
  15. endif
  16. include $(INCLUDE_DIR)/host.mk
  17. include $(INCLUDE_DIR)/unpack.mk
  18. include $(INCLUDE_DIR)/depends.mk
  19. BUILD_TYPES += host
  20. HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
  21. HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
  22. HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
  23. HOST_STAMP_INSTALLED:=$(STAGING_DIR_HOST)/stamp/.$(PKG_NAME)_installed
  24. override MAKEFLAGS=
  25. include $(INCLUDE_DIR)/download.mk
  26. include $(INCLUDE_DIR)/quilt.mk
  27. Host/Patch:=$(Host/Patch/Default)
  28. ifneq ($(strip $(HOST_UNPACK)),)
  29. define Host/Prepare/Default
  30. $(HOST_UNPACK)
  31. $(Host/Patch)
  32. endef
  33. endif
  34. define Host/Prepare
  35. $(call Host/Prepare/Default)
  36. endef
  37. HOST_CONFIGURE_VARS = \
  38. CFLAGS="$(HOST_CFLAGS)" \
  39. CPPFLAGS="$(HOST_CFLAGS)" \
  40. LDFLAGS="$(HOST_LDFLAGS)" \
  41. SHELL="$(BASH)"
  42. HOST_CONFIGURE_ARGS = \
  43. --target=$(GNU_HOST_NAME) \
  44. --host=$(GNU_HOST_NAME) \
  45. --build=$(GNU_HOST_NAME) \
  46. --program-prefix="" \
  47. --program-suffix="" \
  48. --prefix=$(STAGING_DIR_HOST) \
  49. --exec-prefix=$(STAGING_DIR_HOST) \
  50. --sysconfdir=$(STAGING_DIR_HOST)/etc \
  51. --localstatedir=$(STAGING_DIR_HOST)/var
  52. HOST_CONFIGURE_CMD = ./configure
  53. define Host/Configure/Default
  54. (cd $(HOST_BUILD_DIR)/$(3); \
  55. if [ -x configure ]; then \
  56. $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
  57. $(2) \
  58. $(HOST_CONFIGURE_CMD) \
  59. $(HOST_CONFIGURE_VARS) \
  60. $(HOST_CONFIGURE_ARGS) \
  61. $(1); \
  62. fi \
  63. )
  64. endef
  65. define Host/Configure
  66. $(call Host/Configure/Default)
  67. endef
  68. define Host/Compile/Default
  69. $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) $(1)
  70. endef
  71. define Host/Compile
  72. $(call Host/Compile/Default)
  73. endef
  74. define Host/Install/Default
  75. $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
  76. endef
  77. define Host/Install
  78. $(call Host/Install/Default)
  79. endef
  80. ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
  81. define HostHost/Autoclean
  82. $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
  83. $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
  84. endef
  85. endif
  86. define Download/default
  87. FILE:=$(PKG_SOURCE)
  88. URL:=$(PKG_SOURCE_URL)
  89. PROTO:=$(PKG_SOURCE_PROTO)
  90. SUBDIR:=$(PKG_SOURCE_SUBDIR)
  91. VERSION:=$(PKG_SOURCE_VERSION)
  92. MD5SUM:=$(PKG_MD5SUM)
  93. endef
  94. define Host/Exports/Default
  95. $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-*),-I $$(p))
  96. $(1) : export STAGING_PREFIX=$$(STAGING_DIR_HOST)
  97. $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
  98. $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
  99. endef
  100. Host/Exports=$(Host/Exports/Default)
  101. ifndef DUMP
  102. define HostBuild
  103. $(if $(HOST_QUILT),$(Host/Quilt))
  104. $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
  105. $(if $(DUMP),,$(call HostHost/Autoclean))
  106. $(HOST_STAMP_PREPARED):
  107. @-rm -rf $(HOST_BUILD_DIR)
  108. @mkdir -p $(HOST_BUILD_DIR)
  109. $(call Host/Prepare)
  110. touch $$@
  111. $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
  112. $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
  113. $(call Host/Configure)
  114. touch $$@
  115. $(call Host/Exports,$(HOST_STAMP_BUILT))
  116. ifdef Host/Install
  117. host-install: $(if $(STAMP_BUILT),$(HOST_STAMP_BUILT),$(HOST_STAMP_INSTALLED))
  118. endif
  119. ifndef STAMP_BUILT
  120. prepare: host-prepare
  121. compile: host-compile
  122. install: host-install
  123. clean: host-clean
  124. update: host-update
  125. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  126. $(call Host/Compile)
  127. touch $$@
  128. $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT)
  129. $(call Host/Install)
  130. mkdir -p $$(shell dirname $$@)
  131. touch $$@
  132. else
  133. $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
  134. $(call Host/Compile)
  135. $(call Host/Install)
  136. touch $$@
  137. endif
  138. host-prepare: $(HOST_STAMP_PREPARED)
  139. host-configure: $(HOST_STAMP_CONFIGURED)
  140. host-compile: $(HOST_STAMP_BUILT)
  141. host-install:
  142. host-clean: FORCE
  143. $(call Host/Clean)
  144. $(call Host/Uninstall)
  145. rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
  146. endef
  147. download:
  148. prepare:
  149. compile:
  150. install:
  151. clean:
  152. endif