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