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