build: disable CONFIG_AUTOREMOVE for packages/tools where QUILT is used
[openwrt/staging/wigyori.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 include $(INCLUDE_DIR)/download.mk
9
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 ?=
13
14 HOST_MAKE_J:=$(if $(MAKE_JOBSERVER),$(MAKE_JOBSERVER) $(if $(filter 3.% 4.0 4.1,$(MAKE_VERSION)),-j))
15
16 ifeq ($(strip $(HOST_BUILD_PARALLEL)),0)
17 HOST_JOBS?=-j1
18 else
19 HOST_JOBS?=$(if $(HOST_BUILD_PARALLEL),$(HOST_MAKE_J),-j1)
20 endif
21
22 include $(INCLUDE_DIR)/host.mk
23 include $(INCLUDE_DIR)/unpack.mk
24 include $(INCLUDE_DIR)/depends.mk
25
26 BUILD_TYPES += host
27 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)))
28 HOST_STAMP_CONFIGURED:=$(HOST_BUILD_DIR)/.configured
29 HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
30 HOST_BUILD_PREFIX:=$(if $(IS_PACKAGE_BUILD),$(STAGING_DIR_HOSTPKG),$(STAGING_DIR_HOST))
31 HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.$(PKG_NAME)_installed
32
33 override MAKEFLAGS=
34
35 include $(INCLUDE_DIR)/quilt.mk
36 include $(INCLUDE_DIR)/autotools.mk
37
38 _host_target:=$(if $(HOST_QUILT),,.)
39
40 Host/Patch:=$(Host/Patch/Default)
41 ifneq ($(strip $(HOST_UNPACK)),)
42 define Host/Prepare/Default
43 $(HOST_UNPACK)
44 [ ! -d ./src/ ] || $(CP) ./src/* $(HOST_BUILD_DIR)
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 CONFIG_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=$(HOST_BUILD_PREFIX) \
67 --exec-prefix=$(HOST_BUILD_PREFIX) \
68 --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
69 --localstatedir=$(HOST_BUILD_PREFIX)/var \
70 --sbindir=$(HOST_BUILD_PREFIX)/bin
71
72 HOST_MAKE_VARS = \
73 CFLAGS="$(HOST_CFLAGS)" \
74 CPPFLAGS="$(HOST_CPPFLAGS)" \
75 CXXFLAGS="$(HOST_CXXFLAGS)" \
76 LDFLAGS="$(HOST_LDFLAGS)"
77
78 HOST_MAKE_FLAGS =
79
80 HOST_CONFIGURE_CMD = $(BASH) ./configure
81
82 define Host/Configure/Default
83 $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
84 if [ -x configure ]; then \
85 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
86 $(HOST_CONFIGURE_VARS) \
87 $(2) \
88 $(HOST_CONFIGURE_CMD) \
89 $(HOST_CONFIGURE_ARGS) \
90 $(1); \
91 fi \
92 )
93 endef
94
95 define Host/Configure
96 $(call Host/Configure/Default)
97 endef
98
99 define Host/Compile/Default
100 +$(HOST_MAKE_VARS) \
101 $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
102 $(HOST_MAKE_FLAGS) \
103 $(1)
104 endef
105
106 define Host/Compile
107 $(call Host/Compile/Default)
108 endef
109
110 define Host/Install/Default
111 $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
112 endef
113
114 define Host/Install
115 $(call Host/Install/Default,$(HOST_BUILD_PREFIX))
116 endef
117
118
119 ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
120 define HostHost/Autoclean
121 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
122 $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
123 endef
124 endif
125
126 define Host/Exports/Default
127 $(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))
128 $(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
129 $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
130 $(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
131 $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
132 $(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
133 endef
134 Host/Exports=$(Host/Exports/Default)
135
136 .NOTPARALLEL:
137
138 ifndef DUMP
139 define HostBuild/Core
140 $(if $(HOST_QUILT),$(Host/Quilt))
141 $(if $(DUMP),,$(call HostHost/Autoclean))
142
143 $(HOST_STAMP_PREPARED):
144 @-rm -rf $(HOST_BUILD_DIR)
145 @mkdir -p $(HOST_BUILD_DIR)
146 $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
147 $(call Host/Prepare)
148 $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
149 touch $$@
150
151 $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
152 $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
153 $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
154 $(call Host/Configure)
155 $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
156 touch $$@
157
158 $(call Host/Exports,$(HOST_STAMP_BUILT))
159 $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
160 $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
161 $(call Host/Compile)
162 $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
163 touch $$@
164
165 $(call Host/Exports,$(HOST_STAMP_INSTALLED))
166 $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
167 $(call Host/Install,$(HOST_BUILD_PREFIX))
168 $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
169 mkdir -p $$(shell dirname $$@)
170 touch $(HOST_STAMP_BUILT)
171 touch $$@
172
173 $(call DefaultTargets,$(patsubst %,host-%,$(DEFAULT_SUBDIR_TARGETS)))
174 ifndef STAMP_BUILT
175 $(foreach t,$(DEFAULT_SUBDIR_TARGETS),
176 $(t): host-$(t)
177 .$(t): .host-$(t)
178 )
179 endif
180
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-clean: FORCE
185 $(call Host/Clean)
186 $(call Host/Uninstall)
187 rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
188
189 ifneq ($(CONFIG_AUTOREMOVE),)
190 host-compile:
191 $(FIND) $(HOST_BUILD_DIR) -mindepth 1 -maxdepth 1 -not '(' -type f -and -name '.*' -and -size 0 ')' | \
192 $(XARGS) rm -rf
193 endif
194 endef
195 endif
196
197 define HostBuild
198 $(HostBuild/Core)
199 $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
200 endef