1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: readme.gentoo-r1.eclass
7 # Pacho Ramos <pacho@gentoo.org>
9 # Author: Pacho Ramos <pacho@gentoo.org>
10 # @BLURB: An eclass for installing a README.gentoo doc file recording tips
11 # shown via elog messages.
13 # An eclass for installing a README.gentoo doc file recording tips
14 # shown via elog messages. With this eclass, those elog messages will only be
15 # shown at first package installation and a file for later reviewing will be
16 # installed under /usr/share/doc/${PF}
18 # You need to call readme.gentoo_create_doc in src_install phase and
19 # readme.gentoo_print_elog in pkg_postinst
21 if [[ -z ${_README_GENTOO_ECLASS} ]]; then
22 _README_GENTOO_ECLASS=1
26 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
31 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
35 # @ECLASS-VARIABLE: DISABLE_AUTOFORMATTING
38 # If non-empty, DOC_CONTENTS information will be strictly respected,
39 # not getting it automatically formatted by fmt. If empty, it will
40 # rely on fmt for formatting and 'echo -e' options to tweak lines a bit.
42 # @ECLASS-VARIABLE: FORCE_PRINT_ELOG
45 # If non-empty this variable forces elog messages to be printed.
47 # @ECLASS-VARIABLE: README_GENTOO_SUFFIX
49 # If you want to specify a suffix for README.gentoo file please export it.
50 : ${README_GENTOO_SUFFIX:=""}
52 # @FUNCTION: readme.gentoo_create_doc
54 # Create doc file with ${DOC_CONTENTS} variable (preferred) and, if not set,
55 # look for "${FILESDIR}/README.gentoo" contents. You can use
56 # ${FILESDIR}/README.gentoo-${SLOT} also.
57 # Usually called at src_install phase.
58 readme.gentoo_create_doc() {
59 debug-print-function ${FUNCNAME} "${@}"
61 if [[ -n "${DOC_CONTENTS}" ]]; then
62 if [[ -n "${DISABLE_AUTOFORMATTING}" ]]; then
63 echo "${DOC_CONTENTS}" > "${T}"/README.gentoo || die
66 set -f # disable filename expansion in echo arguments
67 echo -e ${DOC_CONTENTS} | fold -s -w 70 \
68 | sed 's/[[:space:]]*$//' > "${T}"/README.gentoo
70 set +f -${saved_flags}
72 elif [[ -f "${FILESDIR}/README.gentoo-${SLOT%/*}" ]]; then
73 cp "${FILESDIR}/README.gentoo-${SLOT%/*}" "${T}"/README.gentoo || die
74 elif [[ -f "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" ]]; then
75 cp "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" "${T}"/README.gentoo || die
77 die "You are not specifying README.gentoo contents!"
80 dodoc "${T}"/README.gentoo
81 README_GENTOO_DOC_VALUE=$(< "${T}/README.gentoo")
84 # @FUNCTION: readme.gentoo_print_elog
86 # Print elog messages with "${T}"/README.gentoo contents. They will be
87 # shown only when package is installed at first time.
88 # Usually called at pkg_postinst phase.
90 # If you want to show them always, please set FORCE_PRINT_ELOG to a non empty
91 # value in your ebuild before this function is called.
92 # This can be useful when, for example, DOC_CONTENTS is modified, then, you can
93 # rely on specific REPLACING_VERSIONS handling in your ebuild to print messages
94 # when people update from versions still providing old message.
95 readme.gentoo_print_elog() {
96 debug-print-function ${FUNCNAME} "${@}"
98 if [[ -z "${README_GENTOO_DOC_VALUE}" ]]; then
99 die "readme.gentoo_print_elog invoked without matching readme.gentoo_create_doc call!"
100 elif ! [[ -n "${REPLACING_VERSIONS}" ]] || [[ -n "${FORCE_PRINT_ELOG}" ]]; then
101 echo -e "${README_GENTOO_DOC_VALUE}" | while read -r ELINE; do elog "${ELINE}"; done
103 elog "(Note: Above message is only printed the first time package is"
104 elog "installed. Please look at ${EPREFIX}/usr/share/doc/${PF}/README.gentoo*"
105 elog "for future reference)"