1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: readme.gentoo.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 if [[ -z ${_README_GENTOO_ECLASS} ]]; then
19 _README_GENTOO_ECLASS=1
25 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
28 # EAPI>=4 is required for REPLACING_VERSIONS preventing us
29 # from needing to export another pkg_preinst phase to save has_version
30 # result. Also relies on EAPI >=4 default src_install phase.
33 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
37 EXPORT_FUNCTIONS src_install pkg_postinst
39 # @ECLASS-VARIABLE: DISABLE_AUTOFORMATTING
42 # If non-empty, DOC_CONTENTS information will be strictly respected,
43 # not getting it automatically formatted by fmt. If empty, it will
44 # rely on fmt for formatting and 'echo -e' options to tweak lines a bit.
46 # @ECLASS-VARIABLE: FORCE_PRINT_ELOG
49 # If non-empty this variable forces elog messages to be printed.
51 # @ECLASS-VARIABLE: README_GENTOO_SUFFIX
53 # If you want to specify a suffix for README.gentoo file please export it.
54 : ${README_GENTOO_SUFFIX:=""}
56 # @FUNCTION: readme.gentoo_create_doc
58 # Create doc file with ${DOC_CONTENTS} variable (preferred) and, if not set,
59 # look for "${FILESDIR}/README.gentoo" contents. You can use
60 # ${FILESDIR}/README.gentoo-${SLOT} also.
61 # Usually called at src_install phase.
62 readme.gentoo_create_doc() {
63 debug-print-function ${FUNCNAME} "${@}"
65 if [[ -n "${DOC_CONTENTS}" ]]; then
68 if [[ -n "${DISABLE_AUTOFORMATTING}" ]]; then
69 echo "${DOC_CONTENTS}" > "${T}"/README.gentoo
71 echo -e ${DOC_CONTENTS} | fold -s -w 70 \
72 | sed 's/[[:space:]]*$//' > "${T}"/README.gentoo
75 elif [[ -f "${FILESDIR}/README.gentoo-${SLOT%/*}" ]]; then
76 cp "${FILESDIR}/README.gentoo-${SLOT%/*}" "${T}"/README.gentoo || die
77 elif [[ -f "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" ]]; then
78 cp "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" "${T}"/README.gentoo || die
80 die "You are not specifying README.gentoo contents!"
83 dodoc "${T}"/README.gentoo
84 README_GENTOO_DOC_VALUE=$(< "${T}/README.gentoo")
87 # @FUNCTION: readme.gentoo_print_elog
89 # Print elog messages with "${T}"/README.gentoo contents. They will be
90 # shown only when package is installed at first time.
91 # Usually called at pkg_postinst phase.
93 # If you want to show them always, please set FORCE_PRINT_ELOG to a non empty
94 # value in your ebuild before this function is called.
95 # This can be useful when, for example, DOC_CONTENTS is modified, then, you can
96 # rely on specific REPLACING_VERSIONS handling in your ebuild to print messages
97 # when people update from versions still providing old message.
98 readme.gentoo_print_elog() {
99 debug-print-function ${FUNCNAME} "${@}"
101 if [[ -z "${README_GENTOO_DOC_VALUE}" ]]; then
102 die "readme.gentoo_print_elog invoked without matching readme.gentoo_create_doc call!"
103 elif ! [[ -n "${REPLACING_VERSIONS}" ]] || [[ -n "${FORCE_PRINT_ELOG}" ]]; then
104 echo -e "${README_GENTOO_DOC_VALUE}" | while read -r ELINE; do elog "${ELINE}"; done
106 elog "(Note: Above message is only printed the first time package is"
107 elog "installed. Please look at ${EPREFIX}/usr/share/doc/${PF}/README.gentoo*"
108 elog "for future reference)"
113 # @FUNCTION: readme.gentoo_src_install
115 # Install generated doc file automatically.
116 readme.gentoo_src_install() {
117 debug-print-function ${FUNCNAME} "${@}"
119 readme.gentoo_create_doc
122 # @FUNCTION: readme.gentoo_pkg_postinst
124 # Show elog messages from from just generated doc file.
125 readme.gentoo_pkg_postinst() {
126 debug-print-function ${FUNCNAME} "${@}"
127 readme.gentoo_print_elog