image.mk: force rebuild of kernel dependent parts - fixes auto-rebuild on DTS changes
[openwrt/openwrt.git] / include / host-build.mk
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
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
12 ifneq ($(CONFIG_PKG_BUILD_USE_JOBSERVER),)
13 HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) -j)
14 else
15 HOST_MAKE_J:=-j$(CONFIG_PKG_BUILD_JOBS)
16 endif
17
18 ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
19 HOST_JOBS?=-j1
20 else
21 HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL)$(CONFIG_PKG_DEFAULT_PARALLEL),\
22 $(if $(CONFIG_PKG_BUILD_PARALLEL),$(HOST_MAKE_J),-j1),-j1)
23 endif
24
25 include $(INCLUDE_DIR)/host.mk
26 include $(INCLUDE_DIR)/unpack.mk
27 include $(INCLUDE_DIR)/depends.mk
28
29 BUILD_TYPES += host
30 HOST_STAMP_PREPARED=$(HOST_BUILD_DIR)/.prepared$(if $(HOST_QUILT)$(DUMP),,$(shell $(call find_md5,${CURDIR} $(PKG_FILE_DEPENDS),)))
31 HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
32 HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
33 HOST_STAMP_INSTALLED:=$(STAGING_DIR_HOST)/stamp/.$(PKG_NAME)_installed
34
35 override MAKEFLAGS=
36
37 include $(INCLUDE_DIR)/download.mk
38 include $(INCLUDE_DIR)/quilt.mk
39 include $(INCLUDE_DIR)/autotools.mk
40
41 Host/Patch:=$(Host/Patch/Default)
42 ifneq ($(strip $(HOST_UNPACK)),)
43 define Host/Prepare/Default
44 $(HOST_UNPACK)
45 $(Host/Patch)
46 endef
47 endif
48
49 define Host/Prepare
50 $(call Host/Prepare/Default)
51 endef
52
53 HOST_CONFIGURE_VARS = \
54 CC="$(HOSTCC)" \
55 CFLAGS="$(HOST_CFLAGS)" \
56 CPPFLAGS="$(HOST_CPPFLAGS)" \
57 LDFLAGS="$(HOST_LDFLAGS)" \
58 SHELL="$(SHELL)"
59
60 HOST_CONFIGURE_ARGS = \
61 --target=$(GNU_HOST_NAME) \
62 --host=$(GNU_HOST_NAME) \
63 --build=$(GNU_HOST_NAME) \
64 --program-prefix="" \
65 --program-suffix="" \
66 --prefix=$(STAGING_DIR_HOST) \
67 --exec-prefix=$(STAGING_DIR_HOST) \
68 --sysconfdir=$(STAGING_DIR_HOST)/etc \
69 --localstatedir=$(STAGING_DIR_HOST)/var \
70 --sbindir=$(STAGING_DIR_HOST)/bin
71
72 HOST_MAKE_FLAGS =
73
74 HOST_CONFIGURE_CMD = $(BASH) ./configure
75
76 define Host/Configure/Default
77 $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
78 if [ -x configure ]; then \
79 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
80 $(2) \
81 $(HOST_CONFIGURE_CMD) \
82 $(HOST_CONFIGURE_VARS) \
83 $(HOST_CONFIGURE_ARGS) \
84 $(1); \
85 fi \
86 )
87 endef
88
89 define Host/Configure
90 $(call Host/Configure/Default)
91 endef
92
93 define Host/Compile/Default
94 +$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
95 $(HOST_MAKE_FLAGS) \
96 $(1)
97 endef
98
99 define Host/Compile
100 $(call Host/Compile/Default)
101 endef
102
103 define Host/Install/Default
104 $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
105 endef
106
107 define Host/Install
108 $(call Host/Install/Default)
109 endef
110
111
112 ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
113 define HostHost/Autoclean
114 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
115 $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
116 endef
117 endif
118
119 define Download/default
120 FILE:=$(PKG_SOURCE)
121 URL:=$(PKG_SOURCE_URL)
122 PROTO:=$(PKG_SOURCE_PROTO)
123 SUBDIR:=$(PKG_SOURCE_SUBDIR)
124 VERSION:=$(PKG_SOURCE_VERSION)
125 MD5SUM:=$(PKG_MD5SUM)
126 MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM)
127 endef
128
129 define Host/Exports/Default
130 $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-*),-I $$(p))
131 $(1) : export STAGING_PREFIX=$$(STAGING_DIR_HOST)
132 $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
133 $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
134 $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
135 endef
136 Host/Exports=$(Host/Exports/Default)
137
138 .NOTPARALLEL:
139
140 ifndef DUMP
141 define HostBuild
142 $(if $(HOST_QUILT),$(Host/Quilt))
143 $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
144 $(if $(DUMP),,$(call HostHost/Autoclean))
145
146 $(HOST_STAMP_PREPARED):
147 @-rm -rf $(HOST_BUILD_DIR)
148 @mkdir -p $(HOST_BUILD_DIR)
149 $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
150 $(call Host/Prepare)
151 $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
152 touch $$@
153
154 $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
155 $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
156 $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
157 $(call Host/Configure)
158 $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
159 touch $$@
160
161 $(call Host/Exports,$(HOST_STAMP_BUILT))
162 $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
163 $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
164 $(call Host/Compile)
165 $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
166 touch $$@
167
168 $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
169 $(call Host/Install)
170 $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
171 mkdir -p $$(shell dirname $$@)
172 touch $(HOST_STAMP_BUILT)
173 touch $$@
174
175 ifndef STAMP_BUILT
176 prepare: host-prepare
177 compile: host-compile
178 install: host-install
179 clean: host-clean
180 update: host-update
181 refresh: host-refresh
182 endif
183
184 host-prepare: $(HOST_STAMP_PREPARED)
185 host-configure: $(HOST_STAMP_CONFIGURED)
186 host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
187 host-install: $(HOST_STAMP_INSTALLED)
188 host-clean: FORCE
189 $(call Host/Clean)
190 $(call Host/Uninstall)
191 rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
192
193 endef
194
195 download:
196 prepare:
197 compile:
198 install:
199 clean:
200
201 endif