summaryrefslogtreecommitdiff
path: root/mk/macros.packages.mk
blob: f8020e1b9689d22248c6b169c70b2a8936d0f194 (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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
################################################################################
# Embtoolkit
# Copyright(C) 2011-2012 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         macros.mk
# \brief	macros.mk of Embtoolkit
# \author       Abdoulaye Walsimou GAYE <awg@embtoolkit.org>
# \date         September 2011
################################################################################

#
# wget wrapper
# usage: $(call embtk_wget,$(OUTPUT_FILE),$(SITE),$(FOREIGN_FILE))
#
__wget_outfile		= $(patsubst %/,%,$(embtk_dldir))/$(strip $(1))
__wget_remotesite	= $(patsubst %/,%,$(strip $(2)))
__wget_foreignfiles	= $(strip $(3))
__wget_opts		:= --tries=5 --timeout=10 --waitretry=5
__wget_opts		+= --no-check-certificate

define embtk_wget
	wget $(__wget_opts) -O $(__wget_outfile)				\
	$(__wget_remotesite)/$(__wget_foreignfiles) ||				\
	wget $(__wget_opts) --no-passive-ftp -O $(__wget_outfile)		\
	$(__wget_remotesite)/$(__wget_foreignfiles)
endef

#
# embtk_pkgconfig-libs:
# A macro to get pkg-config libs entry for a target package
# Usage: $(call embtk_pkgconfig_getlibs,pkgname)
#
define embtk_pkgconfig-libs
	$(shell									\
		PKG_CONFIG_PATH=$(EMBTK_PKG_CONFIG_PATH)			\
		PKG_CONFIG_LIBDIR="$(EMBTK_PKG_CONFIG_LIBDIR)"			\
		$(PKGCONFIG_BIN) $(strip $(1)) --libs)
endef

#
# embtk_pkgconfig-cflags:
# A macro to get pkg-config cflags entry for a target package
# Usage: $(call embtk_pkgconfig_getcflags,pkgname)
#
define embtk_pkgconfig-cflags
	$(shell									\
		PKG_CONFIG_PATH=$(EMBTK_PKG_CONFIG_PATH)			\
		PKG_CONFIG_LIBDIR="$(EMBTK_PKG_CONFIG_LIBDIR)"			\
		$(PKGCONFIG_BIN) $(strip $(1)) --cflags)
endef

#
# 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 freebsd,$(HOST_ARCH)),freebsd)
__embtk_make_cmd	:= gmake
endif

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

#Macro to adapt libtool files (*.la) for cross compiling
__ltlibdirold		= libdir='\/usr\/$(LIBDIR)\(.*\)'
__ltlibdirnew		= libdir='$(embtk_sysroot)\/usr\/$(LIBDIR)\1'
__lt_usr/lib		= $(embtk_space)\/usr\/$(LIBDIR)\/
__lt_sysroot/usr/lib	= $(embtk_space)$(embtk_sysroot)\/usr\/$(LIBDIR)\/
__lt_path		= $(addprefix $(embtk_sysroot)/usr/,$(or $(1),$(LIBDIR)))
define __embtk_fix_libtool_files
	__lt_las=$$(find $(__lt_path) -name '*.la');				\
	for la in $$__lt_las; do						\
		sed -e "s;$(__ltlibdirold);$(__ltlibdirnew);"			\
			-e "s;$(__lt_usr/lib);$(__lt_sysroot/usr/lib);g"	\
			 < $$la > $$la.new;					\
		mv $$la.new $$la;						\
	done
endef
libtool_files_adapt:
	$(Q)$(call __embtk_fix_libtool_files)

# Macro to adapt pkg-config files for cross compiling
__pkgconfig_includedir	= includedir=$(embtk_sysroot)/usr/include
__pkgconfig_prefix	= prefix=$(embtk_sysroot)/usr
__pkgconfig_libdir	= libdir=$(embtk_sysroot)/usr/$(LIBDIR)
define __embtk_fix_pkgconfig_files
	__conf_files0=$$(find $(embtk_sysroot)/usr/$(LIBDIR)/pkgconfig -name *.pc);	\
	__conf_files1=$$(find $(embtk_sysroot)/usr/share/pkgconfig -name *.pc);	\
	for i in $$__conf_files0 $$__conf_files1; do				\
		sed -e 's;prefix=.*;$(__pkgconfig_prefix);'			\
		-e 's;includedir=$${prefix}/include;$(__pkgconfig_includedir);'	\
		-e 's;libdir=.*;$(__pkgconfig_libdir);' < $$i > $$i.new;	\
		mv $$i.new $$i;							\
	done
endef

#A macro to remove rpath in packages that use libtool -rpath
define __embtk_kill_lt_rpath
	cd $(strip $(1));								\
	LOCAL_LT_FILES=`find . -type f -name libtool`;					\
	for i in $$LOCAL_LT_FILES; do							\
		sed -e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g'	\
			-e 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g'	\
			< $$i > $$i.new;						\
		mv $$i.new $$i;								\
	done
endef

#
# Get passed package variables prefix and set some helpers macros.
#
PKGV				= $(strip $(shell echo $(1) | tr a-z A-Z))
pkgv				= $(strip $(shell echo $(1) | tr A-Z a-z))
__embtk_pkg_name		= $(strip $($(PKGV)_NAME))
__embtk_pkg_needpatch		= $(CONFIG_EMBTK_$(PKGV)_NEED_PATCH)
__embtk_pkg_site		= $(strip $($(PKGV)_SITE))
__embtk_patch_site		= ftp://ftp.embtoolkit.org/embtoolkit.org
__embtk_patch_url		= $(__embtk_patch_site)/$(__embtk_pkg_name)/$(__embtk_pkg_version)
__embtk_pkg_patch_site		= $(strip $(or $($(PKGV)_PATCH_SITE),$(__embtk_patch_url)))
__embtk_pkg_patch_f		= $(strip $(embtk_dldir))/$(__embtk_pkg_name)-$(__embtk_pkg_version).patch
__embtk_pkg_mirror		= $(__embtk_patch_site)/packages-mirror
__embtk_pkg_mirror1		= $(strip $($(PKGV)_MIRROR1))
__embtk_pkg_mirror2		= $(strip $($(PKGV)_MIRROR2))
__embtk_pkg_mirror3		= $(strip $($(PKGV)_MIRROR3))
__embtk_pkg_package		= $(strip $($(PKGV)_PACKAGE))

__embtk_pkg_refspec		= $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_REFSPEC))

__embtk_pkg_usesvn		= $(if $(CONFIG_EMBTK_$(PKGV)_VERSION_SVN),svn)
__embtk_pkg_svnsite		= $(or $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_SVN_SITE)),$(strip $($(PKGV)_SVN_SITE)))
__embtk_pkg_svnbranch		= $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_SVN_BRANCH))
__embtk_pkg_svnrev		= $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_SVN_REVISION))
__embtk_pkg_localsvn		= $(strip $(if $(__embtk_pkg_usesvn),		\
	$(EMBTK_ROOT)/src/$(__embtk_pkg_refspec)/$(__embtk_pkg_name)-$(notdir $(__embtk_pkg_svnbranch)).svn))

__embtk_pkg_usegit		= $(if $(CONFIG_EMBTK_$(PKGV)_VERSION_GIT),git)
__embtk_pkg_gitsite		= $(or $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_GIT_SITE)),$(strip $($(PKGV)_GIT_SITE)))
__embtk_pkg_gitbranch		= $(or $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_GIT_BRANCH)),master)
__embtk_pkg_gitrev		= $(or $(call __embtk_mk_uquote,$(CONFIG_EMBTK_$(PKGV)_GIT_REVISION)),HEAD)
__embtk_pkg_localgit		= $(strip $(if $(__embtk_pkg_usegit),		\
	$(EMBTK_ROOT)/src/$(__embtk_pkg_refspec)/$(__embtk_pkg_name).git))

# FIXME: __embtk_pkg_versionsvn: hack for eglibc, should work just as git
__embtk_pkg_versionsvn		= $(if $(__embtk_pkg_usesvn),$(or $(CONFIG_EMBTK_$(PKGV)_VERSION_STRING),$(__embtk_pkg_usesvn)))
__embtk_pkg_version		= $(or $(__embtk_pkg_usegit),$(__embtk_pkg_versionsvn),$(strip $($(PKGV)_VERSION)))

__embtk_pkg_package_f		= $(strip $(embtk_dldir))/$(__embtk_pkg_package)
__embtk_pkg_srcdir		= $(or $(__embtk_pkg_localgit),$(__embtk_pkg_localsvn),$(patsubst %/,%,$(strip $($(PKGV)_SRC_DIR))))
__embtk_pkg_builddir		= $(patsubst %/,%,$(strip $($(PKGV)_BUILD_DIR)))

__embtk_pkg_etc			= $(strip $($(PKGV)_ETC))
__embtk_pkg_bins		= $(strip $($(PKGV)_BINS))
__embtk_pkg_sbins		= $(strip $($(PKGV)_SBINS))
__embtk_pkg_includes		= $(strip $($(PKGV)_INCLUDES))
__embtk_pkg_libs		= $(strip $($(PKGV)_LIBS))
__embtk_pkg_libexecs		= $(strip $($(PKGV)_LIBEXECS))
__embtk_pkg_pkgconfigs		= $(strip $($(PKGV)_PKGCONFIGS))
__embtk_pkg_shares		= $(strip $($(PKGV)_SHARES))

__embtk_pkg_configureenv 	= $(strip $($(PKGV)_CONFIGURE_ENV))
__embtk_pkg_setrpath		= $(strip $($(PKGV)_SET_RPATH))
__embtk_pkg_configureopts	= $(strip $($(PKGV)_CONFIGURE_OPTS))
__embtk_pkg_sysrootsuffix	= $(strip $($(PKGV)_SYSROOT_SUFFIX))
__embtk_pkg_prefix		= $(strip $($(PKGV)_PREFIX))
__embtk_pkg_destdir		= $(strip $($(PKGV)_DESTDIR))
__embtk_pkg_nodestdir		= $(strip $($(PKGV)_NODESTDIR))
__embtk_pkg_deps		= $(strip $($(PKGV)_DEPS))
__embtk_pkg_depspkgv		= $(sort $(patsubst %_install,%,$(__embtk_pkg_deps)))
___embtk_pkg_kconfigsname	= $(strip $(or $($(PKGV)_KCONFIGS_NAME),$(PKGV)))
__embtk_pkg_kconfigsname	= $(patsubst %_HOST,%,$(___embtk_pkg_kconfigsname))
__embtk_pkg_cflags		= $(strip $($(PKGV)_CFLAGS))
__embtk_pkg_cppflags		= $(strip $($(PKGV)_CPPFLAGS))
__embtk_pkg_cxxflags		= $(strip $($(PKGV)_CXXFLAGS))

__embtk_pkg_makedirs		= $(strip $($(PKGV)_MAKE_DIRS))
__embtk_pkg_makeenv		= $(strip $($(PKGV)_MAKE_ENV))
__embtk_pkg_makeopts		= $(strip $($(PKGV)_MAKE_OPTS))

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

# 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))

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


#
# 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 print kconfig entries of a package
#
__embtk_pkg_printkconfigs	=						\
	grep 'CONFIG_K*EMBTK_.*$(__embtk_pkg_kconfigsname)_.*'			\
	$(EMBTK_DOTCONFIG)

#
# A macro to generate a package __embtk_pkg_dotkconfig_f file.
#
define __embtk_pkg_gen_dotkconfig_f
	$(call __embtk_pkg_printkconfigs,$(1))					\
			> $(__embtk_pkg_dotkconfig_f) 2>/dev/null		\
	$(if $(__embtk_pkg_deps),						\
		$(foreach dep,$(call __embtk_pkg_depspkgv,$(1)),;		\
			$(call __embtk_pkg_printkconfigs,$(dep))		\
					>> $(__embtk_pkg_dotkconfig_f)))
endef

#
# A macro to test if a package is already installed.
# It returns y if installed and nothing if not.
#
__installed_f		= $(__embtk_pkg_dotinstalled_f)
__pkgkconfig_f		= $(__embtk_pkg_dotkconfig_f)
__pkgkconfig_f_old	= $(__embtk_pkg_dotkconfig_f).old
__embtk_pkg_installed-y = $(shell						\
	if [ -e $(__installed_f) ] && [ -e $(__pkgkconfig_f) ]; then		\
		cp $(__pkgkconfig_f) $(__pkgkconfig_f_old);			\
		$(call __embtk_pkg_gen_dotkconfig_f,$(1));			\
		cmp -s $(__pkgkconfig_f) $(__pkgkconfig_f_old);			\
		if [ "x$$?" = "x0" ]; then					\
			echo y;							\
		fi;								\
	fi;)

#
# embtk_fixgconfigsfor_pkg
#
__embtk_gconfigsub	:= $(EMBTK_ROOT)/scripts/config.sub
__embtk_gconfiguess	:= $(EMBTK_ROOT)/scripts/config.guess
define __embtk_fixgconfigsfor_pkg
	subs="$$(find $(__embtk_pkg_srcdir)/ -type f -name config.sub)";	\
	for sub in $$subs; do							\
		if [ -n $$sub -a -e $$sub ]; then				\
			ln -sf $(__embtk_gconfigsub) $$sub;			\
		fi;								\
	done;									\
	guesses="$$(find $(__embtk_pkg_srcdir)/ -type f -name config.guess)"; 	\
	for guess in $$guesses; do						\
		if [ -n $$guess -a -e $$guess ]; then				\
			ln -sf $(__embtk_gconfiguess) $$guess;			\
		fi;								\
	done;
endef

#
# A macro which runs configure script (conpatible with autotools configure)
# for a package and sets environment variables correctly.
# Usage:
# $(call embtk_configure_pkg,PACKAGE)
#
define __embtk_configure_autoreconfpkg
if [ "x$(CONFIG_EMBTK_$(PKGV)_NEED_AUTORECONF)" = "xy" ]; then			\
	test -e $(__embtk_pkg_srcdir)/configure.ac ||				\
	test -e $(__embtk_pkg_srcdir)/configure.in || exit 1;			\
	cd $(__embtk_pkg_srcdir);						\
	$(AUTORECONF) --install -f;						\
fi
endef

__embtk_parse_configure_opts = $(subst $(embtk_space),"\\n\\t",$(strip $(1)))
define __embtk_print_configure_opts
	$(if $(strip $(1)),
	$(call embtk_echo_blue,"Configure options:\\n\\t$(__embtk_parse_configure_opts)"))
	echo
endef

define embtk_configure_pkg
	$(if $(EMBTK_BUILDSYS_DEBUG),
		$(call embtk_pinfo,"Configure $(__embtk_pkg_package)..."))
	$(call __embtk_configure_autoreconfpkg,$(1))
	$(Q)test -e $(__embtk_pkg_srcdir)/configure || exit 1
	$(call __embtk_print_configure_opts,$(__embtk_pkg_configureopts))
	$(Q)cd $(__embtk_pkg_builddir);						\
	CC=$(TARGETCC_CACHED)							\
	CXX=$(TARGETCXX_CACHED)							\
	AR=$(TARGETAR)								\
	RANLIB=$(TARGETRANLIB)							\
	AS=$(CROSS_COMPILE)as							\
	NM=$(TARGETNM)								\
	STRIP=$(TARGETSTRIP)							\
	OBJDUMP=$(TARGETOBJDUMP)						\
	OBJCOPY=$(TARGETOBJCOPY)						\
	CFLAGS="$(TARGET_CFLAGS) $(__embtk_pkg_cflags)"				\
	CXXFLAGS="$(TARGET_CXXFLAGS) $(__embtk_pkg_cxxflags)"			\
	LDFLAGS="-L$(embtk_sysroot)/$(LIBDIR) -L$(embtk_sysroot)/usr/$(LIBDIR)"	\
	CPPFLAGS="-I$(embtk_sysroot)/usr/include $(__embtk_pkg_cppflags)"	\
	PKG_CONFIG="$(PKGCONFIG_BIN)"						\
	PKG_CONFIG_PATH="$(EMBTK_PKG_CONFIG_PATH)"				\
	PKG_CONFIG_LIBDIR="$(EMBTK_PKG_CONFIG_LIBDIR)"				\
	ac_cv_func_malloc_0_nonnull=yes						\
	ac_cv_func_realloc_0_nonnull=yes					\
	$(__embtk_pkg_configureenv)						\
	$(CONFIG_SHELL) $(__embtk_pkg_srcdir)/configure				\
	--build=$(HOST_BUILD) --host=$(STRICT_GNU_TARGET)			\
	--target=$(STRICT_GNU_TARGET) --libdir=/usr/$(LIBDIR)			\
	--prefix=/usr --sysconfdir=/etc --localstatedir=/var --disable-rpath	\
	$(__embtk_pkg_configureopts)
	$(Q)touch $(__embtk_pkg_dotconfigured_f)
	$(Q)$(call __embtk_kill_lt_rpath,$(__embtk_pkg_builddir))
endef

#
# A macro which runs configure script (conpatible with autotools configure)
# for a package for host development machine and sets environment variables
# correctly.
# Usage:
# $(call embtk_configure_hostpkg,PACKAGE)
#
__embtk_hostpkg_rpathldflags	= "-Wl,-rpath,$(embtk_htools)/usr/lib"
__embtk_hostpkg_rpath		= $(strip $(if $(__embtk_pkg_setrpath),		\
					$(__embtk_hostpkg_rpathldflags)))

__embtk_hostpkg_ldflags		= -L$(embtk_htools)/usr/lib $(__embtk_hostpkg_rpath)
__embtk_hostpkg_cppflags	= -I$(embtk_htools)/usr/include
define embtk_configure_hostpkg
	$(if $(EMBTK_BUILDSYS_DEBUG),
	$(call embtk_pinfo,"Configure $(__embtk_pkg_package) for host..."))
	$(call __embtk_configure_autoreconfpkg,$(1))
	$(Q)test -e $(__embtk_pkg_srcdir)/configure || exit 1
	$(call __embtk_print_configure_opts,$(__embtk_pkg_configureopts))
	$(Q)cd $(__embtk_pkg_builddir);						\
	CPPFLAGS="$(__embtk_hostpkg_cppflags)"					\
	LDFLAGS="$(__embtk_hostpkg_ldflags)"					\
	PKG_CONFIG="$(PKGCONFIG_BIN)"						\
	PKG_CONFIG_PATH="$(EMBTK_HOST_PKG_CONFIG_PATH)"				\
	$(if $(call __embtk_mk_strcmp,$(PKGV),CCACHE),,CC=$(HOSTCC_CACHED))	\
	$(if $(call __embtk_mk_strcmp,$(PKGV),CCACHE),,CXX=$(HOSTCXX_CACHED))	\
	$(__embtk_pkg_configureenv)						\
	$(CONFIG_SHELL) $(__embtk_pkg_srcdir)/configure				\
	--build=$(HOST_BUILD) --host=$(HOST_ARCH)				\
	--prefix=$(strip $(if $(__embtk_pkg_prefix),				\
				$(__embtk_pkg_prefix),$(embtk_htools)/usr))	\
	$(__embtk_pkg_configureopts)
	$(Q)touch $(__embtk_pkg_dotconfigured_f)
endef

#
# 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) $(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)				\
	$(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

__embtk_autotoolspkg-y=$(2)
define __embtk_install_pkg_make
	$(foreach dep,$(__embtk_pkg_depspkgv),$(call embtk_install_xpkg,$(dep)))
	$(call embtk_pinfo,"Compile/Install $(__embtk_pkg_name)-$(__embtk_pkg_version) in your root filesystem...")
	$(call embtk_download_pkg,$(1))
	$(call embtk_decompress_pkg,$(1))
	mkdir -p $(__embtk_pkg_builddir)
	$(if $(embtk_beforeinstall_$(pkgv)),$(embtk_beforeinstall_$(pkgv)))
	$(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))
	touch $(__embtk_pkg_dotinstalled_f)
	$(call __embtk_pkg_gen_dotkconfig_f,$(1))
endef
define __embtk_install_hostpkg_make
	$(Q)$(if $(__embtk_pkg_deps),$(MAKE) $(__embtk_pkg_deps))
	$(call embtk_pinfo,"Compile/Install $(__embtk_pkg_name)-$(__embtk_pkg_version) for host...")
	$(call embtk_download_pkg,$(1))
	$(call embtk_decompress_pkg,$(1))
	mkdir -p $(__embtk_pkg_builddir)
	$(if $(embtk_beforeinstall_$(pkgv)),$(embtk_beforeinstall_$(pkgv)))
	$(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))
	touch $(__embtk_pkg_dotinstalled_f)
	$(call __embtk_pkg_gen_dotkconfig_f,$(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 install automatically a package, using autotools scripts, intended
# to run on the target
# Usage:
# $(call embtk_install_pkg,package)
#
define __embtk_install_pkg
	$(if $(__embtk_pkg_installed-y),true,
		$(Q)$(call __embtk_install_pkg_make,$(1),autotools))
	$(if $(embtk_postinstall_$(pkgv)),$(embtk_postinstall_$(pkgv)))
endef

define embtk_install_pkg
	$(if $(__embtk_xinstall_xpkg_allvarset-y),
		$(or $(embtk_install_$(pkgv)),$(call __embtk_install_pkg,$(1))),
		$(call __embtk_install_paramsfailure,$(1)))
endef

#
# A macro to install automatically a package, using simple Makefile and an
# install target, intented to run on the target.
# Usage:
# $(call embtk_makeinstall_pkg,package)
#
define embtk_makeinstall_pkg
	$(if $(__embtk_xinstall_xpkg_allvarset-y),
		$(if $(__embtk_pkg_installed-y),true,
			$(Q)$(call __embtk_install_pkg_make,$(1)))
		$(if $(embtk_postinstall_$(pkgv)),$(embtk_postinstall_$(pkgv))),
		$(call __embtk_install_paramsfailure,$(1)))
endef

#
# A macro to install automatically a package, using autotools scripts, intended
# to run on the host development machine.
# Usage:
# $(call embtk_install_hostpkg,package)
#

define __embtk_install_hostpkg
	$(if $(__embtk_pkg_installed-y),true,
		$(Q)$(call __embtk_install_hostpkg_make,$(1),autotools))
	$(if $(embtk_postinstall_$(pkgv)),$(embtk_postinstall_$(pkgv)))
endef
define embtk_install_hostpkg
	$(if $(__embtk_xinstall_xpkg_allvarset-y),
		$(or $(embtk_install_$(pkgv)),$(call __embtk_install_hostpkg,$(1))),
		$(call __embtk_install_paramsfailure,$(1)))
endef

#
# A macro to install automatically a package, using simple Makefile and an
# install target, intended to run on the host development machine.
# Usage:
# $(call embtk_makeinstall_hostpkg,package)
#
define embtk_makeinstall_hostpkg
	$(if $(__embtk_xinstall_xpkg_allvarset-y),
		$(if $(__embtk_pkg_installed-y),true,
			$(Q)$(call __embtk_install_hostpkg_make,$(1)))
		$(or $(embtk_postinstall_$(pkgv)),true),
		$(call __embtk_install_paramsfailure,$(1)))
endef

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

#
# A macro which downloads a package.
# Usage:
# $(call embtk_download_pkg,PACKAGE)
#

__embtk_pkg_depof = $(strip $(foreach p,$(__embtk_pkgs_all-y) toolchain toolchain_addons,\
		$(if $(findstring $(pkgv),$($(call PKGV,$(p)_deps))),$(p))))

__embtk_pkg_needpatch_yesno = $(if $(__embtk_pkg_needpatch),Yes,No)

define __embtk_download_pkg_patches
	$(if $(__embtk_pkg_needpatch),						\
	test -e	$(__embtk_pkg_patch_f) ||					\
	$(call embtk_wget,							\
		$(__embtk_pkg_name)-$(__embtk_pkg_version).patch,		\
		$(__embtk_pkg_patch_site),					\
		$(__embtk_pkg_name)-$(__embtk_pkg_version)-*.patch),true)
endef

define __embtk_download_pkg_exitfailure
	($(call embtk_perror,"On $(notdir $(1)) download!");			\
		$(if $(notdir $(1)),rm -rf $(1);)				\
		exit 1)
endef

define __embtk_svncheckout_pkg
	svn co $(__embtk_pkg_svnsite)/$(__embtk_pkg_svnbranch)			\
			-r$(__embtk_pkg_svnrev)	$(__embtk_pkg_localsvn)
endef
define __embtk_download_pkg_from_svn
	$(call embtk_echo_blue,"$(__embtk_pkg_name) using SVN")
	$(call embtk_echo_blue,"\tBranch        : $(notdir $(__embtk_pkg_svnbranch))")
	$(call embtk_echo_blue,"\tRevision      : $(__embtk_pkg_svnrev)")
	$(call embtk_echo_blue,"\tIn            : $(or $(__embtk_pkg_refspec),src)")
	$(call embtk_echo_blue,"\tCheckout URL  : $(__embtk_pkg_svnsite)")
	$(call embtk_echo_blue,"\tPatched       : $(__embtk_pkg_needpatch_yesno)")
	$(call embtk_echo_blue,"\tDependency of : $(or $(__embtk_pkg_depof),N/A)")
	test -e $(__embtk_pkg_localsvn) ||					\
	$(call __embtk_svncheckout_pkg,$(1)) ||					\
	$(call __embtk_download_pkg_exitfailure,$(__embtk_pkg_package_f))
	$(call __embtk_download_pkg_patches,$(1)) ||				\
	$(call __embtk_download_pkg_exitfailure,$(__embtk_pkg_patch_f))
	$(call __embtk_applypatch_pkg,$(1))

endef

define __embtk_gitclone_pkg
	(git clone $(__embtk_pkg_gitsite) $(__embtk_pkg_localgit) &&		\
	$(if $(findstring master,$(__embtk_pkg_gitbranch)),,			\
		cd $(__embtk_pkg_localgit);					\
		git checkout -b $(__embtk_pkg_gitbranch)			\
					origin/$(__embtk_pkg_gitbranch) &&)	\
	$(if $(findstring HEAD,$(__embtk_pkg_gitrev)),,				\
		cd $(__embtk_pkg_localgit);					\
		git reset --hard $(__embtk_pkg_gitrev) &&)			\
	true)
endef

define __embtk_download_pkg_from_git
	$(call embtk_echo_blue,"$(__embtk_pkg_name) using GIT")
	$(call embtk_echo_blue,"\tBranch        : $(__embtk_pkg_gitbranch)")
	$(call embtk_echo_blue,"\tRevision      : $(__embtk_pkg_gitrev)")
	$(call embtk_echo_blue,"\tIn            : $(or $(__embtk_pkg_refspec),src)")
	$(call embtk_echo_blue,"\tClone URL     : $(__embtk_pkg_gitsite)")
	$(call embtk_echo_blue,"\tPatched       : $(__embtk_pkg_needpatch_yesno)")
	$(call embtk_echo_blue,"\tDependency of : $(or $(__embtk_pkg_depof),N/A)")
	test -e $(__embtk_pkg_localgit) || $(call __embtk_gitclone_pkg,$(1))
endef

define __embtk_download_pkg_from_tarball
	$(call embtk_echo_blue,"$(__embtk_pkg_name) using tarball")
	$(call embtk_echo_blue,"\tVersion       : $(__embtk_pkg_version)")
	$(call embtk_echo_blue,"\tFrom          : $(__embtk_pkg_site)")
	$(call embtk_echo_blue,"\tIn            : $(__embtk_pkg_package_f)")
	$(call embtk_echo_blue,"\tPatched       : $(__embtk_pkg_needpatch_yesno)")
	$(call embtk_echo_blue,"\tDependency of : $(or $(__embtk_pkg_depof),N/A)")
	test -e $(__embtk_pkg_package_f) ||					\
	$(call embtk_wget,							\
		$(__embtk_pkg_package),						\
		$(__embtk_pkg_site),						\
		$(__embtk_pkg_package)) ||					\
	$(if $(__embtk_pkg_mirror1),						\
		$(call embtk_wget,						\
			$(__embtk_pkg_package),					\
			$(__embtk_pkg_mirror1),					\
			$(__embtk_pkg_package)),false) ||			\
	$(if $(__embtk_pkg_mirror2),						\
		$(call embtk_wget,						\
			$(__embtk_pkg_package),					\
			$(__embtk_pkg_mirror2),					\
			$(__embtk_pkg_package)),false) ||			\
	$(if $(__embtk_pkg_mirror3),						\
		$(call embtk_wget,						\
			$(__embtk_pkg_package),					\
			$(__embtk_pkg_mirror3),					\
			$(__embtk_pkg_package)),false) ||			\
	$(if $(__embtk_pkg_mirror),						\
		$(call embtk_wget,						\
			$(__embtk_pkg_package),					\
			$(__embtk_pkg_mirror),					\
			$(__embtk_pkg_package)),false) ||			\
	$(call __embtk_download_pkg_exitfailure,$(__embtk_pkg_package_f))
	$(call __embtk_download_pkg_patches,$(1)) ||				\
	 $(call __embtk_download_pkg_exitfailure,$(__embtk_pkg_patch_f))
endef

__embtk_pkgdl_src = $(or $(__embtk_pkg_usegit),$(__embtk_pkg_usesvn),tarball)
define embtk_download_pkg
	$(if $(EMBTK_BUILDSYS_DEBUG),
		$(call embtk_pinfo,"Download $(__embtk_pkg_name) if needed..."))
	$(call __embtk_download_pkg_from_$(call __embtk_pkgdl_src,$(1)),$(1))
endef

#
# A macro to decompress packages tarball intended to run on target.
# Usage:
# $(call embtk_decompress_pkg,pkgname)
#

__embtk_applypatch_pkg =							\
	$(if $(__embtk_pkg_needpatch),						\
		if [ ! -e $(__embtk_pkg_dotpatched_f) ]; then			\
			cd $(__embtk_pkg_srcdir);				\
			patch -p1 --silent < $(__embtk_pkg_patch_f);		\
			touch $(__embtk_pkg_dotpatched_f);			\
		fi,true;)

__embtk_decompress_pkg_exitfailure =						\
	$(call embtk_perror,"!Compression unknown for $(__embtk_pkg_name)!");	\
	exit 1

__embtk_decompress_pkg =							\
	case $(__embtk_pkg_package_f) in					\
		*.tar.bz2 | *.tbz2)						\
			tar -C $(dir $(__embtk_pkg_srcdir)) -xjf		\
						$(__embtk_pkg_package_f) &&	\
			mkdir -p $(__embtk_pkg_builddir) &&			\
			touch $(__embtk_pkg_dotdecompressed_f)			\
			;;							\
		*.tar.gz | *.tgz)						\
			tar -C $(dir $(__embtk_pkg_srcdir)) -xzf		\
						$(__embtk_pkg_package_f) &&	\
			mkdir -p $(__embtk_pkg_builddir) &&			\
			touch $(__embtk_pkg_dotdecompressed_f)			\
			;;							\
		*.tar.xz)							\
			tar -C $(dir $(__embtk_pkg_srcdir)) -xJf		\
						$(__embtk_pkg_package_f) &&	\
			mkdir -p $(__embtk_pkg_builddir) &&			\
			touch $(__embtk_pkg_dotdecompressed_f)			\
			;;							\
		*.tar)								\
			tar -C $(dir $(__embtk_pkg_srcdir)) -xf			\
						$(__embtk_pkg_package_f) &&	\
			mkdir -p $(__embtk_pkg_builddir) &&			\
			touch $(__embtk_pkg_dotdecompressed_f)			\
			;;							\
		*)								\
			$(call __embtk_decompress_pkg_exitfailure,$(1))		\
			;;							\
	esac

__embtk_decompress_pkg_msg = $(call embtk_pinfo,"Decrompressing $(__embtk_pkg_package) ...")
define embtk_decompress_pkg
	$(if $(__embtk_pkg_usegit)$(__embtk_pkg_usesvn),true,
		$(if $(EMBTK_BUILDSYS_DEBUG),$(__embtk_decompress_pkg_msg))
		if [ ! -e $(__embtk_pkg_dotdecompressed_f) ]; then		\
			$(call __embtk_decompress_pkg,$(1)) &&			\
			$(call __embtk_applypatch_pkg,$(1))			\
		fi)
	$(Q)mkdir -p $(__embtk_pkg_builddir)
endef

#
# A macro to clean installed packages from sysroot.
# Usage:
# $(call embtk_cleanup_pkg,pkgname)
#
define __embtk_cleanup_pkg
	$(if $(embtk_cleanup_$(pkgv)),$(embtk_cleanup_$(pkgv)))
	$(if $(__embtk_pkg_etc),
		rm -rf $(addprefix $(embtk_sysroot)/etc/,$(__embtk_pkg_etc)))
	$(if $(__embtk_pkg_bins),
		rm -rf $(addprefix $(embtk_sysroot)/usr/bin/,$(__embtk_pkg_bins)))
	$(if $(__embtk_pkg_sbins),
		rm -rf $(addprefix $(embtk_sysroot)/usr/sbin/,$(__embtk_pkg_sbins)))
	$(if $(__embtk_pkg_includes),
		rm -rf $(addprefix $(embtk_sysroot)/usr/include/,$(__embtk_pkg_includes)))
	$(if $(__embtk_pkg_libs),
		rm -rf $(addprefix $(embtk_sysroot)/usr/$(LIBDIR)/,$(__embtk_pkg_libs)))
	$(if $(__embtk_pkg_libexecs),
		rm -rf $(addprefix $(embtk_sysroot)/usr/libexec/,$(__embtk_pkg_libexecs)))
	$(if $(__embtk_pkg_pkgconfigs),
		rm -rf $(addprefix $(embtk_sysroot)/usr/$(LIBDIR)/pkgconfig/,$(__embtk_pkg_pkgconfigs))
		rm -rf $(addprefix $(embtk_sysroot)/usr/share/pkgconfig/,$(__embtk_pkg_pkgconfigs)))
	$(if $(__embtk_pkg_shares),
		rm -rf $(addprefix $(embtk_sysroot)/usr/share/,$(__embtk_pkg_shares)))
	$(if $(__embtk_pkg_usegit)$(__embtk_pkg_usesvn),
		rm -rf $(__embtk_pkg_dotconfigured_f)
		rm -rf $(__embtk_pkg_dotinstalled_f),
		$(if $(__embtk_pkg_builddir),rm -rf $(__embtk_pkg_builddir)*))
endef

define embtk_cleanup_pkg
	$(if $(EMBTK_BUILDSYS_DEBUG),
		$(call embtk_pinfo,"Cleanup $(__embtk_pkg_name)..."))
	$(Q)$(call __embtk_cleanup_pkg,$(1))
endef