1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: readme.gentoo.eclass
6 # Pacho Ramos <pacho@gentoo.org>
8 # Author: Pacho Ramos <pacho@gentoo.org>
9 # @SUPPORTED_EAPIS: 4 5
10 # @BLURB: install a doc file shown via elog messages
12 # An eclass for installing a README.gentoo doc file recording tips
13 # shown via elog messages. With this eclass, those elog messages will only be
14 # shown at first package installation and a file for later reviewing will be
15 # installed under /usr/share/doc/${PF}
17 # This eclass is DEPRECATED. Please use readme.gentoo-r1 instead.
19 if [[ -z ${_README_GENTOO_ECLASS} ]]; then
20 _README_GENTOO_ECLASS=1
26 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
29 # EAPI>=4 is required for REPLACING_VERSIONS preventing us
30 # from needing to export another pkg_preinst phase to save has_version
31 # result. Also relies on EAPI >=4 default src_install phase.
32 EXPORT_FUNCTIONS src_install pkg_postinst
35 die "Unsupported EAPI=${EAPI} for ${ECLASS}"
36 die "Please migrate to readme.gentoo-r1.eclass and note that"
37 die "it stops to export any ebuild phases and, then, you will"
38 die "need to ensure readme.gentoo_create_doc is called in"
39 die "src_install and readme.gentoo_print_elog in pkg_postinst"
42 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
46 # @ECLASS-VARIABLE: DISABLE_AUTOFORMATTING
49 # If non-empty, DOC_CONTENTS information will be strictly respected,
50 # not getting it automatically formatted by fmt. If empty, it will
51 # rely on fmt for formatting and 'echo -e' options to tweak lines a bit.
53 # @ECLASS-VARIABLE: FORCE_PRINT_ELOG
56 # If non-empty this variable forces elog messages to be printed.
58 # @ECLASS-VARIABLE: README_GENTOO_SUFFIX
60 # If you want to specify a suffix for README.gentoo file please export it.
61 : ${README_GENTOO_SUFFIX:=""}
63 # @FUNCTION: readme.gentoo_create_doc
65 # Create doc file with ${DOC_CONTENTS} variable (preferred) and, if not set,
66 # look for "${FILESDIR}/README.gentoo" contents. You can use
67 # ${FILESDIR}/README.gentoo-${SLOT} also.
68 # Usually called at src_install phase.
69 readme.gentoo_create_doc() {
70 debug-print-function ${FUNCNAME} "${@}"
72 if [[ -n "${DOC_CONTENTS}" ]]; then
75 if [[ -n "${DISABLE_AUTOFORMATTING}" ]]; then
76 echo "${DOC_CONTENTS}" > "${T}"/README.gentoo
78 echo -e ${DOC_CONTENTS} | fold -s -w 70 \
79 | sed 's/[[:space:]]*$//' > "${T}"/README.gentoo
82 elif [[ -f "${FILESDIR}/README.gentoo-${SLOT%/*}" ]]; then
83 cp "${FILESDIR}/README.gentoo-${SLOT%/*}" "${T}"/README.gentoo || die
84 elif [[ -f "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" ]]; then
85 cp "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" "${T}"/README.gentoo || die
87 die "You are not specifying README.gentoo contents!"
90 dodoc "${T}"/README.gentoo
91 README_GENTOO_DOC_VALUE=$(< "${T}/README.gentoo")
94 # @FUNCTION: readme.gentoo_print_elog
96 # Print elog messages with "${T}"/README.gentoo contents. They will be
97 # shown only when package is installed at first time.
98 # Usually called at pkg_postinst phase.
100 # If you want to show them always, please set FORCE_PRINT_ELOG to a non empty
101 # value in your ebuild before this function is called.
102 # This can be useful when, for example, DOC_CONTENTS is modified, then, you can
103 # rely on specific REPLACING_VERSIONS handling in your ebuild to print messages
104 # when people update from versions still providing old message.
105 readme.gentoo_print_elog() {
106 debug-print-function ${FUNCNAME} "${@}"
108 eqawarn "${CATEGORY}/${PN} is using the deprecated readme.gentoo.eclass."
109 eqawarn "Please use readme.gentoo-r1 instead."
111 if [[ -z "${README_GENTOO_DOC_VALUE}" ]]; then
112 die "readme.gentoo_print_elog invoked without matching readme.gentoo_create_doc call!"
113 elif ! [[ -n "${REPLACING_VERSIONS}" ]] || [[ -n "${FORCE_PRINT_ELOG}" ]]; then
114 echo -e "${README_GENTOO_DOC_VALUE}" | while read -r ELINE; do elog "${ELINE}"; done
116 elog "(Note: Above message is only printed the first time package is"
117 elog "installed. Please look at ${EPREFIX}/usr/share/doc/${PF}/README.gentoo*"
118 elog "for future reference)"
123 # @FUNCTION: readme.gentoo_src_install
125 # Install generated doc file automatically.
126 readme.gentoo_src_install() {
127 debug-print-function ${FUNCNAME} "${@}"
129 readme.gentoo_create_doc
132 # @FUNCTION: readme.gentoo_pkg_postinst
134 # Show elog messages from from just generated doc file.
135 readme.gentoo_pkg_postinst() {
136 debug-print-function ${FUNCNAME} "${@}"
137 readme.gentoo_print_elog