6c2f91581b895bda1ee9f2ee94afc2e5c06de380
[openwrt/staging/lynxis/omap.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),)))
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/Patch:=$(Host/Patch/Default)
39 ifneq ($(strip $(HOST_UNPACK)),)
40 define Host/Prepare/Default
41 $(HOST_UNPACK)
42 [ ! -d ./src/ ] || $(CP) ./src/* $(HOST_BUILD_DIR)
43 $(Host/Patch)
44 endef
45 endif
46
47 define Host/Prepare
48 $(call Host/Prepare/Default)
49 endef
50
51 HOST_CONFIGURE_VARS = \
52 CC="$(HOSTCC)" \
53 CFLAGS="$(HOST_CFLAGS)" \
54 CPPFLAGS="$(HOST_CPPFLAGS)" \
55 LDFLAGS="$(HOST_LDFLAGS)" \
56 CONFIG_SHELL="$(SHELL)"
57
58 HOST_CONFIGURE_ARGS = \
59 --target=$(GNU_HOST_NAME) \
60 --host=$(GNU_HOST_NAME) \
61 --build=$(GNU_HOST_NAME) \
62 --program-prefix="" \
63 --program-suffix="" \
64 --prefix=$(HOST_BUILD_PREFIX) \
65 --exec-prefix=$(HOST_BUILD_PREFIX) \
66 --sysconfdir=$(HOST_BUILD_PREFIX)/etc \
67 --localstatedir=$(HOST_BUILD_PREFIX)/var \
68 --sbindir=$(HOST_BUILD_PREFIX)/bin
69
70 HOST_MAKE_VARS = \
71 CFLAGS="$(HOST_CFLAGS)" \
72 CPPFLAGS="$(HOST_CPPFLAGS)" \
73 CXXFLAGS="$(HOST_CXXFLAGS)" \
74 LDFLAGS="$(HOST_LDFLAGS)"
75
76 HOST_MAKE_FLAGS =
77
78 HOST_CONFIGURE_CMD = $(BASH) ./configure
79
80 define Host/Configure/Default
81 $(if $(HOST_CONFIGURE_PARALLEL),+)(cd $(HOST_BUILD_DIR)/$(3); \
82 if [ -x configure ]; then \
83 $(CP) $(SCRIPT_DIR)/config.{guess,sub} $(HOST_BUILD_DIR)/$(3)/ && \
84 $(HOST_CONFIGURE_VARS) \
85 $(2) \
86 $(HOST_CONFIGURE_CMD) \
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 +$(HOST_MAKE_VARS) \
99 $(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
100 $(HOST_MAKE_FLAGS) \
101 $(1)
102 endef
103
104 define Host/Compile
105 $(call Host/Compile/Default)
106 endef
107
108 define Host/Install/Default
109 $(_SINGLE)$(MAKE) -C $(HOST_BUILD_DIR) install
110 endef
111
112 define Host/Install
113 $(call Host/Install/Default,$(HOST_BUILD_PREFIX))
114 endef
115
116
117 ifneq ($(if $(HOST_QUILT),,$(CONFIG_AUTOREBUILD)),)
118 define HostHost/Autoclean
119 $(call rdep,${CURDIR} $(PKG_FILE_DEPENDS),$(HOST_STAMP_PREPARED))
120 $(if $(if $(Host/Compile),$(filter prepare,$(MAKECMDGOALS)),1),,$(call rdep,$(HOST_BUILD_DIR),$(HOST_STAMP_BUILT)))
121 endef
122 endif
123
124 define Host/Exports/Default
125 $(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))
126 $(1) : export STAGING_PREFIX=$$(HOST_BUILD_PREFIX)
127 $(1) : export PKG_CONFIG_PATH=$$(STAGING_DIR_HOST)/lib/pkgconfig:$$(HOST_BUILD_PREFIX)/lib/pkgconfig
128 $(1) : export PKG_CONFIG_LIBDIR=$$(HOST_BUILD_PREFIX)/lib/pkgconfig
129 $(1) : export CCACHE_DIR:=$(STAGING_DIR_HOST)/ccache
130 $(if $(IS_PACKAGE_BUILD),$(1) : export PATH=$$(TARGET_PATH_PKG))
131 endef
132 Host/Exports=$(Host/Exports/Default)
133
134 .NOTPARALLEL:
135
136 ifndef DUMP
137 define HostBuild/Core
138 $(if $(HOST_QUILT),$(Host/Quilt))
139 $(if $(DUMP),,$(call HostHost/Autoclean))
140
141 $(HOST_STAMP_PREPARED):
142 @-rm -rf $(HOST_BUILD_DIR)
143 @mkdir -p $(HOST_BUILD_DIR)
144 $(foreach hook,$(Hooks/HostPrepare/Pre),$(call $(hook))$(sep))
145 $(call Host/Prepare)
146 $(foreach hook,$(Hooks/HostPrepare/Post),$(call $(hook))$(sep))
147 touch $$@
148
149 $(call Host/Exports,$(HOST_STAMP_CONFIGURED))
150 $(HOST_STAMP_CONFIGURED): $(HOST_STAMP_PREPARED)
151 $(foreach hook,$(Hooks/HostConfigure/Pre),$(call $(hook))$(sep))
152 $(call Host/Configure)
153 $(foreach hook,$(Hooks/HostConfigure/Post),$(call $(hook))$(sep))
154 touch $$@
155
156 $(call Host/Exports,$(HOST_STAMP_BUILT))
157 $(HOST_STAMP_BUILT): $(HOST_STAMP_CONFIGURED)
158 $(foreach hook,$(Hooks/HostCompile/Pre),$(call $(hook))$(sep))
159 $(call Host/Compile)
160 $(foreach hook,$(Hooks/HostCompile/Post),$(call $(hook))$(sep))
161 touch $$@
162
163 $(call Host/Exports,$(HOST_STAMP_INSTALLED))
164 $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
165 $(call Host/Install,$(HOST_BUILD_PREFIX))
166 $(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
167 mkdir -p $$(shell dirname $$@)
168 touch $(HOST_STAMP_BUILT)
169 touch $$@
170
171 ifndef STAMP_BUILT
172 prepare: host-prepare
173 compile: host-compile
174 install: host-install
175 clean: host-clean
176 update: host-update
177 refresh: host-refresh
178 endif
179
180 host-prepare: $(HOST_STAMP_PREPARED)
181 host-configure: $(HOST_STAMP_CONFIGURED)
182 host-compile: $(HOST_STAMP_BUILT) $(if $(STAMP_BUILT),$(HOST_STAMP_INSTALLED))
183 host-install: $(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 endef
190
191 download:
192 prepare:
193 compile:
194 install:
195 clean:
196
197 endif
198
199 define HostBuild
200 $(HostBuild/Core)
201 $(if $(if $(PKG_HOST_ONLY),,$(STAMP_PREPARED)),,$(if $(strip $(PKG_SOURCE_URL)),$(call Download,default)))
202 endef