2 # Copyright (C) 2006-2010 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 include $(INCLUDE_DIR)/download.mk
10 HOST_BUILD_DIR ?= $(BUILD_DIR_HOST)/$(PKG_NAME)$(if $(PKG_VERSION),-$(PKG_VERSION))
11 HOST_INSTALL_DIR ?= $(HOST_BUILD_DIR)/host-install
12 HOST_BUILD_PARALLEL ?=
14 HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
16 ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
19 HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL),$(HOST_MAKE_J),-j1)
22 include $(INCLUDE_DIR)/unpack.mk
23 include $(INCLUDE_DIR)/depends.mk
26 HOST_STAMP_PREPARED:=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),))_$(call confvar,CONFIG_AUTOREMOVE $(HOST_PREPARED_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
34 include $(INCLUDE_DIR)/quilt.mk
35 include $(INCLUDE_DIR)/autotools.mk
37 _host_target:=$(if $(HOST_QUILT),,.)
39 Host/Patch:=$(Host/Patch/Default)
40 ifneq ($(strip $(HOST_UNPACK)),)
41 define Host/Prepare/Default
43 [ ! -d ./src/ ] || $(CP) ./src/* $(HOST_BUILD_DIR)
49 $(call Host/Prepare/Default)
52 HOST_CONFIGURE_VARS = \
54 CFLAGS="$(HOST_CFLAGS)" \
55 CPPFLAGS="$(HOST_CPPFLAGS)" \
56 LDFLAGS="$(HOST_LDFLAGS)" \
57 CONFIG_SHELL="$(SHELL)"
59 HOST_CONFIGURE_ARGS = \
60 --target=$(GNU_HOST_NAME) \
61 --host=$(GNU_HOST_NAME) \
62 --build=$(GNU_HOST_NAME) \
65 --prefix=$(HOST_BUILD_PREFIX) \
66 --exec-prefix=$(HOST_BUILD_PREFIX) \
67 --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
68 --localstatedir=$(HOST_BUILD_PREFIX)/var \
69 --sbindir=$(HOST_BUILD_PREFIX)/bin
72 CFLAGS="$(HOST_CFLAGS)" \
73 CPPFLAGS="$(HOST_CPPFLAGS)" \
74 CXXFLAGS="$(HOST_CXXFLAGS)" \
75 LDFLAGS="$(HOST_LDFLAGS)"
79 HOST_CONFIGURE_CMD = $(BASH) ./configure
81 define Host/Configure/Default
82 $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
83 if [ -x configure ]; then \
84 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
85 $(HOST_CONFIGURE_VARS) \
87 $(HOST_CONFIGURE_CMD) \
88 $(HOST_CONFIGURE_ARGS) \
95 $(call Host/Configure/Default)
98 define Host/Compile/Default
100 $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
106 $(call Host/Compile/Default)
109 define Host/Install/Default
110 $(call Host/Compile/Default,install)
114 $(call Host/Install/Default,$(HOST_BUILD_PREFIX))
118 ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
119 define HostHost/Autoclean
120 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
121 $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
125 define Host/Exports/Default
126 $(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_HOSTPKG)/share/aclocal $$(STAGING_DIR)/host/share/aclocal-*)),-I $$(p))
127 $(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
128 $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
129 $(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
130 $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
131 $(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
133 Host/Exports=$(Host/Exports/Default)
138 define HostBuild/Core
139 $(if $(HOST_QUILT),$(Host/Quilt))
140 $(if $(DUMP),,$(call HostHost/Autoclean))
142 $(HOST_STAMP_PREPARED):
143 @-rm -rf $(HOST_BUILD_DIR)
144 @mkdir -p $(HOST_BUILD_DIR)
145 $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
147 $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
150 $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
151 $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
152 $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
153 $(call Host/Configure)
154 $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
157 $(call Host/Exports,$(HOST_STAMP_BUILT))
158 $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
159 $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
161 $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
164 $(call Host/Exports,$(HOST_STAMP_INSTALLED))
165 $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
166 $(call Host/Install,$(HOST_BUILD_PREFIX))
167 $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
168 mkdir -p $$(shell dirname $$@)
169 touch $(HOST_STAMP_BUILT)
172 $(call DefaultTargets,$(patsubst %,host-%,$(DEFAULT_SUBDIR_TARGETS)))
174 $(foreach t,$(DEFAULT_SUBDIR_TARGETS),
178 clean-build: host-clean-build
181 $(_host_target)host-prepare: $(HOST_STAMP_PREPARED)
182 $(_host_target)host-configure: $(HOST_STAMP_CONFIGURED)
183 $(_host_target)host-compile: $(HOST_STAMP_BUILT) $(HOST_STAMP_INSTALLED)
184 host-install: host-compile
186 host-clean-build: FORCE
187 rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_BUILT)
189 host-clean: host-clean-build
191 $(call Host/Uninstall)
192 rm -rf $(HOST_STAMP_INSTALLED)
194 ifneq ($(CONFIG_AUTOREMOVE),)
196 $(FIND) $(HOST_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' | \
204 $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))