media-fonts/noto-emoji: add ~ppc64 keyword
[gentoo.git] / eclass / sgml-catalog-r1.eclass
1 # Copyright 2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: sgml-catalog-r1.eclass
5 # @MAINTAINER:
6 # Michał Górny <mgorny@gentoo.org>
7 # @AUTHOR:
8 # Michał Górny <mgorny@gentoo.org>
9 # @SUPPORTED_EAPIS: 7
10 # @BLURB: Functions for installing SGML catalogs
11 # @DESCRIPTION:
12 # This eclass regenerates /etc/sgml/catalog, /etc/sgml.{,c}env
13 # and /etc/env.d/93sgmltools-lite as necessary for the DocBook tooling.
14 # This is done via exported pkg_postinst and pkg_postrm phases.
15
16 case ${EAPI:-0} in
17         7) ;;
18         *) die "Unsupported EAPI=${EAPI} for ${ECLASS}";;
19 esac
20
21 EXPORT_FUNCTIONS pkg_postinst pkg_postrm
22
23 if [[ ! ${_SGML_CATALOG_R1} ]]; then
24
25 if [[ ${CATEGORY}/${PN} != app-text/sgml-common ]]; then
26         RDEPEND=">=app-text/sgml-common-0.6.3-r7"
27 fi
28
29 # @FUNCTION: sgml-catalog-r1_update_catalog
30 # @DESCRIPTION:
31 # Regenerate /etc/sgml/catalog to include all installed catalogs.
32 sgml-catalog-r1_update_catalog() {
33         local shopt_save=$(shopt -p nullglob)
34         shopt -s nullglob
35         local cats=( "${EROOT}"/etc/sgml/*.cat )
36         ${shopt_save}
37
38         if [[ ${#cats[@]} -gt 0 ]]; then
39                 ebegin "Updating ${EROOT}/etc/sgml/catalog"
40                 printf 'CATALOG "%s"\n' "${cats[@]}" > "${T}"/catalog &&
41                 mv "${T}"/catalog "${EROOT}"/etc/sgml/catalog
42                 eend "${?}"
43         else
44                 ebegin "Removing ${EROOT}/etc/sgml/catalog"
45                 rm "${EROOT}"/etc/sgml/catalog &&
46                 { rmdir "${EROOT}"/etc/sgml &>/dev/null || :; }
47                 eend "${?}"
48         fi
49 }
50
51 # @FUNCTION: sgml-catalog-r1_update_env
52 # @DESCRIPTION:
53 # Regenerate environment variables and copy them to env.d.
54 sgml-catalog-r1_update_env() {
55         # gensgmlenv doesn't support overriding root
56         if [[ -z ${ROOT} && -x "${EPREFIX}/usr/bin/gensgmlenv" ]]; then
57                 ebegin "Regenerating SGML environment variables"
58                 gensgmlenv &&
59                 grep -v export "${EPREFIX}/etc/sgml/sgml.env" > "${T}"/93sgmltools-lite &&
60                 mv "${T}"/93sgmltools-lite "${EPREFIX}/etc/env.d/93sgmltools-lite"
61                 eend "${?}"
62         fi
63 }
64
65 sgml-catalog-r1_pkg_postinst() {
66         sgml-catalog-r1_update_catalog
67         sgml-catalog-r1_update_env
68 }
69
70 sgml-catalog-r1_pkg_postrm() {
71         sgml-catalog-r1_update_catalog
72         sgml-catalog-r1_update_env
73 }
74
75 _SGML_CATALOG_R1=1
76 fi