1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7#
8# This class will generate the proper postinst/postrm scriptlets for font
9# packages.
10#
11
12PACKAGE_WRITE_DEPS += "qemu-native"
13inherit qemu
14
15FONT_PACKAGES ??= "${PN}"
16FONT_EXTRA_RDEPENDS ?= "${MLPREFIX}fontconfig-utils"
17FONTCONFIG_CACHE_DIR ?= "${localstatedir}/cache/fontconfig"
18FONTCONFIG_CACHE_PARAMS ?= "-v"
19# You can change this to e.g. FC_DEBUG=16 to debug fc-cache issues,
20# something has to be set, because qemuwrapper is using this variable after -E
21# multiple variables aren't allowed because for qemu they are separated
22# by comma and in -n "$D" case they should be separated by space
23FONTCONFIG_CACHE_ENV ?= "FC_DEBUG=1"
24fontcache_common() {
25if [ -n "$D" ] ; then
26	$INTERCEPT_DIR/postinst_intercept update_font_cache ${PKG} mlprefix=${MLPREFIX} binprefix=${MLPREFIX} \
27		'bindir="${bindir}"' \
28		'libdir="${libdir}"' \
29		'libexecdir="${libexecdir}"' \
30		'base_libdir="${base_libdir}"' \
31		'fontconfigcachedir="${FONTCONFIG_CACHE_DIR}"' \
32		'fontconfigcacheparams="${FONTCONFIG_CACHE_PARAMS}"' \
33		'fontconfigcacheenv="${FONTCONFIG_CACHE_ENV}"'
34else
35	${FONTCONFIG_CACHE_ENV} fc-cache ${FONTCONFIG_CACHE_PARAMS}
36fi
37}
38
39python () {
40    font_pkgs = d.getVar('FONT_PACKAGES').split()
41    deps = d.getVar("FONT_EXTRA_RDEPENDS")
42
43    for pkg in font_pkgs:
44        if deps: d.appendVar('RDEPENDS:' + pkg, ' '+deps)
45}
46
47python add_fontcache_postinsts() {
48    for pkg in d.getVar('FONT_PACKAGES').split():
49        bb.note("adding fonts postinst and postrm scripts to %s" % pkg)
50        postinst = d.getVar('pkg_postinst:%s' % pkg) or d.getVar('pkg_postinst')
51        if not postinst:
52            postinst = '#!/bin/sh\n'
53        postinst += d.getVar('fontcache_common')
54        d.setVar('pkg_postinst:%s' % pkg, postinst)
55
56        postrm = d.getVar('pkg_postrm:%s' % pkg) or d.getVar('pkg_postrm')
57        if not postrm:
58            postrm = '#!/bin/sh\n'
59        postrm += d.getVar('fontcache_common')
60        d.setVar('pkg_postrm:%s' % pkg, postrm)
61}
62
63PACKAGEFUNCS =+ "add_fontcache_postinsts"
64