summaryrefslogtreecommitdiff
path: root/core/mk/pkg-macros/install.mk
blob: c8f2fc730a1ca5b6cf4d0f2356ef33cac1e1e8c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
################################################################################
# Embtoolkit
# Copyright(C) 2014 Abdoulaye Walsimou GAYE.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
#
# \file         install.mk
# \brief	install.mk of Embtoolkit
# \author       Abdoulaye Walsimou GAYE <awg@embtoolkit.org>
# \date         January 2014
################################################################################

#
# Define here which make program to use in MAKE.
# FIXME: On some systems, gnu make is named gmake (ie FreeBSD)
#
__embtk_make_cmd	:= make
ifeq ($(findstring bsd,$(HOST_ARCH)),bsd)
__embtk_make_cmd	:= gmake
endif

__embtk_make_env	:= $(if $(V),MAKEFLAGS="",MAKEFLAGS="--no-print-directory --silent")
MAKE			= $(__embtk_make_env) $(__embtk_pkg_scanbuild) $(__embtk_make_cmd)


# Some embtoolkit internal files for packages
__embtk_pkg_dotdecompressed_f	= $(__embtk_pkg_srcdir)/.embtk.decompressed
__embtk_pkg_dotpatched_f	= $(__embtk_pkg_srcdir)/.embtk.patched
__embtk_pkg_dotconfigured_f	= $(__embtk_pkg_statedir)/.embtk.configured
__embtk_pkg_dotinstalled_f	= $(__embtk_pkg_statedir)/.embtk.installed
__embtk_pkg_dotkconfig_f	= $(__embtk_pkg_statedir)/.embtk.kconfig

__embtk_setdecompressed_pkg	= touch $(__embtk_pkg_dotdecompressed_f)
__embtk_unsetdecompressed_pkg	= rm -rf $(__embtk_pkg_dotdecompressed_f)
__embtk_setpatched_pkg		= touch $(__embtk_pkg_dotpatched_f)
__embtk_unsetpatched_pkg	= rm -rf $(__embtk_pkg_dotpatched_f)
__embtk_setconfigured_pkg	= mkdir -p $(__embtk_pkg_statedir) && touch $(__embtk_pkg_dotconfigured_f)
__embtk_unsetconfigured_pkg	= rm -rf $(__embtk_pkg_dotconfigured_f)
__embtk_setinstalled_pkg	= mkdir -p $(__embtk_pkg_statedir) && touch $(__embtk_pkg_dotinstalled_f)
__embtk_unsetinstalled_pkg	= rm -rf $(__embtk_pkg_dotinstalled_f)
__embtk_setkconfigured_pkg	= mkdir -p $(__embtk_pkg_statedir) && touch $(__embtk_pkg_dotkconfig_f)
__embtk_unsetkconfigured_pkg	= rm -rf $(__embtk_pkg_dotkconfig_f)

ifeq ($(CONFIG_EMBTK_WIPEOUTWORKSPACES),y)
define __embtk_wipeoutworkspace_pkg
	$(if $(__embtk_pkg_usegit)$(__embtk_pkg_usesvn)$(__embtk_pkg_nowipeworkspace),,
		$(if $(__embtk_pkg_builddir),rm -rf $(__embtk_pkg_builddir))
		$(if $(__embtk_pkg_srcdir),rm -rf $(__embtk_pkg_srcdir)))
endef
endif

# Some useful macros about packages
__embtk_rootfs_pkgs-y		= $(patsubst %_install,%,$(ROOTFS_COMPONENTS-y))
__embtk_rootfs_nrpkgs-y		= $(words $(__embtk_rootfs_pkgs-y))

__embtk_hosttools_pkgs-y	= $(patsubst %_install,%,$(HOSTTOOLS_COMPONENTS-y))
__embtk_hosttools_nrpkgs-y	= $(words $(__embtk_hosttools_pkgs-y))

__embtk_rootfs_pkgs-n		= $(patsubst %_install,%,$(ROOTFS_COMPONENTS-))
__embtk_rootfs_nrpkgs-n		= $(words $(__embtk_rootfs_pkgs-n))

__embtk_hosttools_pkgs-n	= $(patsubst %_install,%,$(HOSTTOOLS_COMPONENTS-))
__embtk_hosttools_nrpkgs-n	= $(words $(__embtk_hosttools_pkgs-n))

__embtk_pkgs_all-y		= $(__embtk_rootfs_pkgs-y) $(__embtk_hosttools_pkgs-y)
__embtk_pkgs_nrall-y		= $(words $(__embtk_pkgs_all-y))

__embtk_pkg_depof = $(strip $(sort $(___embtk_pkg_depof)))
define ___embtk_pkg_depof
	$(foreach p,$(__embtk_pkgs_all-y) $(__embtk_toolchain_deps-y) $(__embtk_toolchain_predeps-y) $(__embtk_toolchain_addons-y),
		$(if $(findstring $(pkgv)_install,$($(call PKGV,$(p)_deps))),$(p)))
endef

#
# A macro to get packages version from .config file.
# usage: $(call embtk_get_pkgversion,PACKAGE)
#
embtk_pkg_version    = $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_VERSION_STRING))
embtk_get_pkgversion = $(embtk_pkg_version)


#
# A macro to test if a package is already decompressed.
#
__embtk_pkg_decompressed-y	= $(call __embtk_mk_pathexist,$(__embtk_pkg_dotdecompressed_f))
__embtk_pkg_notdecompressed-y	= $(call __embtk_mk_pathnotexist,$(__embtk_pkg_dotdecompressed_f))

#
# A macro to test if a package is already patched.
#
__embtk_pkg_patched-y		= $(call __embtk_mk_pathexist,$(__embtk_pkg_dotpatched_f))
__embtk_pkg_notpatched-y	= $(call __embtk_mk_pathnotexist,$(__embtk_pkg_dotpatched_f))

#
# A macro to test if a package is already configured using autotools configure
# script.
#
__embtk_pkg_configured-y	= $(call __embtk_mk_pathexist,$(__embtk_pkg_dotconfigured_f))
__embtk_pkg_notconfigured-y	= $(call __embtk_mk_pathnotexist,$(__embtk_pkg_dotconfigured_f))

#
# A macro to generate a package __embtk_pkg_dotkconfig_f file.
#
define __embtk_pkg_gen_dotkconfig_f
	printf '__embtk_$(pkgv)_okconfigs      := %s\n'				\
		'$(call embtk_shell_quote,$(__embtk_pkg_kconfigs_all_v))'	\
		> $(__embtk_pkg_dotkconfig_f)
	printf '__embtk_$(pkgv)_oconfigureopts := %s\n'				\
		'$(call embtk_shell_quote,$(__embtk_pkg_configureopts))'	\
		>> $(__embtk_pkg_dotkconfig_f)
endef

#
# A macro to test if a package build recipe needs to be run or not.
#
__embtk_pkg_runrecipe-y		= $(or $(__embtk_pkg_ninstalled-y),$(__embtk_pkg_confchanged-y),$(__embtk_pkg_configurechanged-y))
__embtk_pkg_installed-y		= $(or $(__embtk_$(pkgv)_installed),$(and $(wildcard $(__embtk_pkg_dotinstalled_f)),$(__embtk_$(pkgv)_installed)))
__embtk_pkg_ninstalled-y	= $(if $(__embtk_pkg_installed-y),,y)
__embtk_pkg_confchanged-y	= $(call __embtk_strneq,$(__embtk_pkg_kconfigs_all_v),$(__embtk_$(pkgv)_okconfigs))
__embtk_pkg_configurechanged-y	= $(call __embtk_strneq,$(__embtk_pkg_configureopts),$(__embtk_$(pkgv)_oconfigureopts))

#
# Various helpers macros for different steps while installing packages.
#
__embtk_multi_make = $(foreach builddir,$(__embtk_pkg_makedirs),		\
			$(__embtk_pkg_makeenv)					\
			$(MAKE) -C $(__embtk_pkg_builddir)/$(builddir)		\
			$(J) $(__embtk_pkg_makeopts);)

__embtk_single_make = $(__embtk_pkg_makeenv)					\
			$(MAKE) -C $(__embtk_pkg_builddir)			\
			$(J) $(__embtk_pkg_makeopts)


__embtk_multi_make_install = $(foreach builddir,$(__embtk_pkg_makedirs),	\
	$(__embtk_pkg_makeenv) $(filter-out $(__embtk_pkg_scanbuild),$(MAKE))	\
		 -C $(__embtk_pkg_builddir)/$(builddir)				\
	$(if $(__embtk_pkg_nodestdir),,						\
		DESTDIR=$(embtk_sysroot)$(if $(__embtk_pkg_sysrootsuffix),/$(__embtk_pkg_sysrootsuffix))) \
	$(__embtk_pkg_makeopts) install;)

__embtk_single_make_install = $(__embtk_pkg_makeenv)				\
	$(filter-out $(__embtk_pkg_scanbuild),$(MAKE))				\
		-C $(__embtk_pkg_builddir)					\
	$(if $(__embtk_pkg_nodestdir),,						\
		DESTDIR=$(embtk_sysroot)$(if $(__embtk_pkg_sysrootsuffix),/$(__embtk_pkg_sysrootsuffix))) \
	$(__embtk_pkg_makeopts) install

__embtk_multi_make_hostinstall = $(foreach builddir,$(__embtk_pkg_makedirs),	\
	$(__embtk_pkg_makeenv)							\
	$(MAKE) -C $(__embtk_pkg_builddir)/$(builddir)				\
	$(if $(__embtk_pkg_destdir),DESTDIR=$(__embtk_pkg_destdir))		\
	$(__embtk_pkg_makeopts) install;)

__embtk_single_make_hostinstall = $(__embtk_pkg_makeenv)			\
	$(MAKE) -C $(__embtk_pkg_builddir)					\
	$(if $(__embtk_pkg_destdir),DESTDIR=$(__embtk_pkg_destdir))		\
	$(__embtk_pkg_makeopts) install

define __embtk_install_pkgdeps
	$(if $(__embtk_pkg_deps),$(MAKE) $(__embtk_pkg_deps))
endef

define __embtk_preinstall_pkg
	$(call __embtk_install_pkgdeps,$(1))
	$(call embtk_pinfo,"Compile/Install $(__embtk_pkg_name)-$(__embtk_pkg_version) in target system...")
	mkdir -p $(__embtk_pkg_builddir)
	$(call embtk_download_pkg,$(1))
	$(call embtk_decompress_pkg,$(1))
	$(embtk_beforeinstall_$(pkgv))
endef
define __embtk_preinstall_hostpkg
	$(call __embtk_install_pkgdeps,$(1))
	$(call embtk_pinfo,"Compile/Install $(__embtk_pkg_name)-$(__embtk_pkg_version) for host...")
	mkdir -p $(__embtk_pkg_builddir)
	$(call embtk_download_pkg,$(1))
	$(call embtk_decompress_pkg,$(1))
	$(embtk_beforeinstall_$(pkgv))
endef
define __embtk_postinstall_pkg
	$(call __embtk_setinstalled_pkg,$(1))
	$(call __embtk_pkg_gen_dotkconfig_f,$(1))
	$(eval __embtk_$(pkgv)_installed = y)
	$(embtk_postinstallonce_$(pkgv))
	$(call __embtk_wipeoutworkspace_pkg,$(1))
endef

__embtk_autotoolspkg-y=$(2)
define __embtk_install_pkg_make
	$(if $(__embtk_autotoolspkg-y),$(call embtk_configure_pkg,$(1)))
	$(if $(__embtk_pkg_makedirs),						\
		$(__embtk_multi_make),						\
		$(__embtk_single_make))
	$(if $(__embtk_pkg_makedirs),						\
		$(__embtk_multi_make_install),					\
		$(__embtk_single_make_install))
	$(if $(__embtk_autotoolspkg-y)$(__embtk_pkg_pkgconfigs),
		$(call __embtk_fix_libtool_files)
		$(call __embtk_fix_pkgconfig_files))
endef
define __embtk_install_hostpkg_make
	$(if $(__embtk_autotoolspkg-y),$(call embtk_configure_hostpkg,$(1)))
	$(if $(__embtk_pkg_makedirs),						\
		$(__embtk_multi_make),						\
		$(__embtk_single_make))
	$(if $(__embtk_pkg_makedirs),						\
		$(__embtk_multi_make_hostinstall),				\
		$(__embtk_single_make_hostinstall))
endef

__embtk_waf_build	= cd $(__embtk_pkg_srcdir); ./waf build $(J) --progress

__embtk_waf_install	= cd $(__embtk_pkg_srcdir); ./waf install --progress	\
	$(if $(__embtk_pkg_nodestdir),,						\
		--destdir=$(embtk_sysroot)$(if $(__embtk_pkg_sysrootsuffix),/$(__embtk_pkg_sysrootsuffix)))

__embtk_waf_hostinstall	= cd $(__embtk_pkg_srcdir); ./waf install --progress	\
	$(if $(__embtk_pkg_destdir),--destdir=$(__embtk_pkg_destdir))

define __embtk_install_pkg_waf
	$(call embtk_wafconfigure_pkg,$(1))
	$(call __embtk_waf_build,$(1))
	$(call __embtk_waf_install,$(1))
	$(if $(__embtk_pkg_pkgconfigs),
		$(call __embtk_fix_libtool_files)
		$(call __embtk_fix_pkgconfig_files))
endef

define __embtk_install_hostpkg_waf
	$(call embtk_wafconfigure_hostpkg,$(1))
	$(call __embtk_waf_build,$(1))
	$(call __embtk_waf_hostinstall,$(1))
endef

#
# A macro to exit with error when needed package variables not define.
# Usage:
# $(call __embtk_install_paramsfailure,pkgname)
#
define __embtk_install_paramsfailure
	$(call embtk_perror,"!Not all needed variables defined for $(1)!")
	$(call embtk_echo_red,"Summary of variables and their current values")
	$(call embtk_echo_red,"$(PKGV)_NAME                             (needed) = $(or $(__embtk_pkg_name),not set)")
	$(call embtk_echo_red,"$(PKGV)_SITE                  (needed if tarball) = $(or $(__embtk_pkg_site),not set)")
	$(call embtk_echo_red,"$(PKGV)_VERSION               (needed if tarball) = $(or $(__embtk_pkg_version),not set)")
	$(call embtk_echo_red,"$(PKGV)_PACKAGE               (needed if tarball) = $(or $(__embtk_pkg_package),not set)")
	$(call embtk_echo_red,"$(PKGV)_GIT_SITE                  (needed if git) = $(or $(__embtk_pkg_gitsite),not set)")
	$(call embtk_echo_red,"CONFIG_EMBTK_$(PKGV)_VERSION_GIT  (needed if git) = $(or $(__embtk_pkg_usegit),not set)")
	$(call embtk_echo_red,"CONFIG_EMBTK_$(PKGV)_GIT_REVISION (needed if git) = $(or $(__embtk_pkg_gitrev),not set)")
	$(call embtk_echo_red,"CONFIG_EMBTK_$(PKGV)_GIT_BRANCH   (needed if git) = $(or $(__embtk_pkg_gitbranch),not set)")
	$(call embtk_echo_red,"$(PKGV)_SVN_SITE                  (needed if svn) = $(or $(__embtk_pkg_svnsite),not set)")
	$(call embtk_echo_red,"CONFIG_EMBTK_$(PKGV)_VERSION_SVN (needed if svn)  = $(or $(__embtk_pkg_usesvn),not set)")
	$(call embtk_echo_red,"CONFIG_EMBTK_$(PKGV)_SVN_REVISION (needed if svn) = $(or $(__embtk_pkg_svnrev),not set)")
	$(call embtk_echo_red,"CONFIG_EMBTK_$(PKGV)_SVN_BRANCH   (needed if svn) = $(or $(__embtk_pkg_svnbranch),not set)")
	$(call embtk_echo_red,"$(PKGV)_SRC_DIR               (needed if tarball) = $(or $(__embtk_pkg_srcdir),not set)")
	$(call embtk_echo_red,"$(PKGV)_BUILD_DIR                      (optional) = $(or $(__embtk_pkg_builddir),not set)")

	exit 1
endef

__embtk_xinstall_xgitpkg_allvarset-y	= 					\
		$(strip $(if $(__embtk_pkg_usegit),$(__embtk_pkg_gitsite)))

__embtk_xinstall_xsvnpkg_allvarset-y	= $(strip 				\
	$(if $(__embtk_pkg_usesvn),						\
		$(and $(__embtk_pkg_svnsite),$(__embtk_pkg_svnbranch),		\
			$(__embtk_pkg_svnrev))))

__embtk_xinstall_xtarbpkg_allvarset-y	= $(strip				\
	$(if $(__embtk_pkg_usegit)$(__embtk_pkg_usesvn),,			\
		$(and $(__embtk_pkg_site),$(__embtk_pkg_version),		\
			$(__embtk_pkg_package))))

__embtk_xinstall_xpkg_allvarset-y = $(and $(__embtk_pkg_name),			\
	$(__embtk_pkg_srcdir),$(__embtk_pkg_builddir),				\
	$(or $(__embtk_xinstall_xgitpkg_allvarset-y),				\
		$(__embtk_xinstall_xtarbpkg_allvarset-y),			\
		$(__embtk_xinstall_xsvnpkg_allvarset-y)))

#
# A macro to automatically install a package intended to run on the target,
# using autotools script.
# Usage:
# $(call embtk_install_pkg,package)
#
define embtk_install_pkg
	$(if $(__embtk_xinstall_xpkg_allvarset-y),
		$(Q)$(call __embtk_install_pkg,$(1)),
		$(call __embtk_install_paramsfailure,$(1)))
endef
define __embtk_install_pkg
	$(if $(__embtk_pkg_runrecipe-y),
		$(call __embtk_preinstall_pkg,$(1))
		$(or $(embtk_install_$(pkgv)),$(call ___embtk_install_pkg,$(1)))
		$(call __embtk_postinstall_pkg,$(1)))
	$(embtk_postinstall_$(pkgv))
endef
define ___embtk_install_pkg
	$(if $(__embtk_pkg_usewaf-y),
		$(call __embtk_install_pkg_waf,$(1)),
		$(call __embtk_install_pkg_make,$(1),autotools))
endef
#
# A macro to automatically install a package intended to run on the target,
# using simple Makefile and an nstall target.
# Usage:
# # autotooled: add this optional string to install an autotooled package
# $(call embtk_makeinstall_pkg,package[,autotooled])
#
define embtk_makeinstall_pkg
	$(Q)$(call __embtk_install_pkg_make,$(1),$(2))
endef

#
# A macro to automatically install a package intended to run on the host
# development machine, using autotools scripts.
# Usage:
# $(call embtk_install_hostpkg,package)
#
define embtk_install_hostpkg
	$(if $(__embtk_xinstall_xpkg_allvarset-y),
		$(Q)$(call __embtk_install_hostpkg,$(1)),
		$(call __embtk_install_paramsfailure,$(1)))
endef
define __embtk_install_hostpkg
	$(if $(__embtk_pkg_runrecipe-y),
		$(call __embtk_preinstall_hostpkg,$(1))
		$(or $(embtk_install_$(pkgv)),$(call ___embtk_install_hostpkg,$(1)))
		$(call __embtk_postinstall_pkg,$(1)))
	$(embtk_postinstall_$(pkgv))
endef
define ___embtk_install_hostpkg
	$(if $(__embtk_pkg_usewaf-y),
		$(call __embtk_install_hostpkg_waf,$(1)),
		$(call __embtk_install_hostpkg_make,$(1),autotools))
endef

#
# A macro to automatically install a package intended to run on the host
# development machine, using simple Makefile and an install target.
# Usage:
# autotooled: add this optional string to install an autotooled package
# $(call embtk_makeinstall_hostpkg,package[,autotooled])
#
define embtk_makeinstall_hostpkg
	$(Q)$(call __embtk_install_hostpkg_make,$(1),$(2))
endef

#
# A wrapper macro for embtk_install_hostpkg and embtk_install_pkg, based on
# package name (xxxx or xxxx_host).
# Usage:
# $(call embtk_install_xpkg,xxxx)
#
define embtk_install_xpkg
	$(call embtk_install_$(findstring host,$(1))pkg,$(1))
endef