build: add jobserver support for host builds
[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 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="$(BASH)"
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_CONFIGURE_CMD = ./configure
73
74 ifneq ($(HOST_OS),Darwin)
75 ifeq ($(CONFIG_BUILD_STATIC_TOOLS),y)
76 HOST_STATIC_LINKING = -static
77 endif
78 endif
79
80 define Host/Configure/Default
81 (cd $(HOST_BUILD_DIR)/$(3); \
82 if [ -x configure ]; then \
83 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
84 $(2) \
85 $(HOST_CONFIGURE_CMD) \
86 $(HOST_CONFIGURE_VARS) \
87 $(HOST_CONFIGURE_ARGS) \
88 $(1); \
89 fi \
90 )
91 endef
92
93 define Host/Configure
94 $(call Host/Configure/Default)
95 endef
96
97 define Host/Compile/Default
98 $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) $(1)
99 endef
100
101 define Host/Compile
102 $(call Host/Compile/Default)
103 endef
104
105 define Host/Install/Default
106 $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
107 endef
108
109 define Host/Install
110 $(call Host/Install/Default)
111 endef
112
113
114 ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
115 define HostHost/Autoclean
116 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
117 $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
118 endef
119 endif
120
121 define Download/default
122 FILE:=$(PKG_SOURCE)
123 URL:=$(PKG_SOURCE_URL)
124 PROTO:=$(PKG_SOURCE_PROTO)
125 SUBDIR:=$(PKG_SOURCE_SUBDIR)
126 VERSION:=$(PKG_SOURCE_VERSION)
127 MD5SUM:=$(PKG_MD5SUM)
128 MIRROR_MD5SUM:=$(PKG_MIRROR_MD5SUM)
129 endef
130
131 define Host/Exports/Default
132 $(1) : export ACLOCAL_INCLUDE=$$(foreach p,$$(wildcard $$(STAGING_DIR_HOST)/share/aclocal $$(STAGING_DIR_HOST)/share/aclocal-*),-I $$(p))
133 $(1) : export STAGING_PREFIX=$$(STAGING_DIR_HOST)
134 $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig
135 $(1) : export PKG_CONFIG_LIBDIR=$$(STAGING_DIR_HOST)/lib/pkgconfig
136 endef
137 Host/Exports=$(Host/Exports/Default)
138
139 ifndef DUMP
140 define HostBuild
141 $(if $(HOST_QUILT),$(Host/Quilt))
142 $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
143 $(if $(DUMP),,$(call HostHost/Autoclean))
144
145 $(HOST_STAMP_PREPARED):
146 @-rm -rf $(HOST_BUILD_DIR)
147 @mkdir -p $(HOST_BUILD_DIR)
148 $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
149 $(call Host/Prepare)
150 $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
151 touch $$@
152
153 $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
154 $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
155 $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
156 $(call Host/Configure)
157 $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
158 touch $$@
159
160 $(call Host/Exports,$(HOST_STAMP_BUILT))
161 ifdef Host/Install
162 host-install: $(if $(STAMP_BUILT),$(HOST_STAMP_BUILT),$(HOST_STAMP_INSTALLED))
163 endif
164
165 ifndef STAMP_BUILT
166 prepare: host-prepare
167 compile: host-compile
168 install: host-install
169 clean: host-clean
170 update: host-update
171 refresh: host-refresh
172
173 $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
174 $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
175 $(call Host/Compile)
176 $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
177 touch $$@
178
179 $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
180 $(call Host/Install)
181 $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
182 mkdir -p $$(shell dirname $$@)
183 touch $$@
184 else
185 $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED) $(if $(FORCE_HOST_INSTALL),FORCE)
186 $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
187 $(call Host/Compile)
188 $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
189 $(call Host/Install)
190 $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
191 touch $$@
192 endif
193 host-prepare: $(HOST_STAMP_PREPARED)
194 host-configure: $(HOST_STAMP_CONFIGURED)
195 host-compile: $(HOST_STAMP_BUILT)
196 host-install:
197 host-clean: FORCE
198 $(call Host/Clean)
199 $(call Host/Uninstall)
200 rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_INSTALLED) $(HOST_STAMP_BUILT)
201
202 endef
203
204 download:
205 prepare:
206 compile:
207 install:
208 clean:
209
210 endif