1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7FILES:${PN} += "${datadir}/icons/hicolor"
8
9GTKIC_VERSION ??= '3'
10
11GTKPN = "${@ 'gtk4' if d.getVar('GTKIC_VERSION') == '4' else 'gtk+3' }"
12GTKIC_CMD = "${@ 'gtk4-update-icon-cache' if d.getVar('GTKIC_VERSION') == '4' else 'gtk-update-icon-cache-3.0' }"
13
14#gtk+3/gtk4 require GTK3DISTROFEATURES, DEPENDS on it make all the
15#recipes inherit this class require GTK3DISTROFEATURES
16inherit features_check
17ANY_OF_DISTRO_FEATURES = "${GTK3DISTROFEATURES}"
18
19DEPENDS +=" ${@ '' if d.getVar('BPN') == 'hicolor-icon-theme' else 'hicolor-icon-theme' } \
20            ${@ '' if d.getVar('BPN') == 'gdk-pixbuf' else 'gdk-pixbuf' } \
21            ${@ '' if d.getVar('BPN') == d.getVar('GTKPN') else d.getVar('GTKPN') } \
22            ${GTKPN}-native \
23"
24
25PACKAGE_WRITE_DEPS += "${GTKPN}-native gdk-pixbuf-native"
26
27gtk_icon_cache_postinst() {
28if [ "x$D" != "x" ]; then
29	$INTERCEPT_DIR/postinst_intercept update_gtk_icon_cache ${PKG} \
30		mlprefix=${MLPREFIX} \
31		libdir_native=${libdir_native}
32else
33
34	# Update the pixbuf loaders in case they haven't been registered yet
35	${libdir}/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders --update-cache
36
37	for icondir in /usr/share/icons/* ; do
38		if [ -d $icondir ] ; then
39			${GTKIC_CMD} -fqt  $icondir
40		fi
41	done
42fi
43}
44
45gtk_icon_cache_postrm() {
46if [ "x$D" != "x" ]; then
47	$INTERCEPT_DIR/postinst_intercept update_gtk_icon_cache ${PKG} \
48		mlprefix=${MLPREFIX} \
49		libdir=${libdir}
50else
51	for icondir in /usr/share/icons/* ; do
52		if [ -d $icondir ] ; then
53			${GTKIC_CMD} -qt  $icondir
54		fi
55	done
56fi
57}
58
59python populate_packages:append () {
60    packages = d.getVar('PACKAGES').split()
61    pkgdest =  d.getVar('PKGDEST')
62
63    for pkg in packages:
64        icon_dir = '%s/%s/%s/icons' % (pkgdest, pkg, d.getVar('datadir'))
65        if not os.path.exists(icon_dir):
66            continue
67
68        bb.note("adding hicolor-icon-theme dependency to %s" % pkg)
69        rdepends = ' ' + d.getVar('MLPREFIX', False) + "hicolor-icon-theme"
70        d.appendVar('RDEPENDS:%s' % pkg, rdepends)
71
72        #gtk_icon_cache_postinst depend on gdk-pixbuf and gtk+3/gtk4
73        bb.note("adding gdk-pixbuf dependency to %s" % pkg)
74        rdepends = ' ' + d.getVar('MLPREFIX', False) + "gdk-pixbuf"
75        d.appendVar('RDEPENDS:%s' % pkg, rdepends)
76
77        bb.note("adding %s dependency to %s" % (d.getVar('GTKPN'), pkg))
78        rdepends = ' ' + d.getVar('MLPREFIX', False) + d.getVar('GTKPN')
79        d.appendVar('RDEPENDS:%s' % pkg, rdepends)
80
81        bb.note("adding gtk-icon-cache postinst and postrm scripts to %s" % pkg)
82
83        postinst = d.getVar('pkg_postinst:%s' % pkg)
84        if not postinst:
85            postinst = '#!/bin/sh\n'
86        postinst += d.getVar('gtk_icon_cache_postinst')
87        d.setVar('pkg_postinst:%s' % pkg, postinst)
88
89        postrm = d.getVar('pkg_postrm:%s' % pkg)
90        if not postrm:
91            postrm = '#!/bin/sh\n'
92        postrm += d.getVar('gtk_icon_cache_postrm')
93        d.setVar('pkg_postrm:%s' % pkg, postrm)
94}
95
96