x11-themes/gentoo10-backgrounds: Cleanup per bug #85210
[gentoo.git] / eclass / readme.gentoo-r1.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: readme.gentoo-r1.eclass
6 # @MAINTAINER:
7 # Pacho Ramos <pacho@gentoo.org>
8 # @AUTHOR:
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.
12 # @DESCRIPTION:
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}
17 #
18 # You need to call readme.gentoo_create_doc in src_install phase and
19 # readme.gentoo_print_elog in pkg_postinst
20
21 if [[ -z ${_README_GENTOO_ECLASS} ]]; then
22 _README_GENTOO_ECLASS=1
23
24 case "${EAPI:-0}" in
25         0|1|2|3)
26                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
27                 ;;
28         4|5|6)
29                 ;;
30         *)
31                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
32                 ;;
33 esac
34
35 # @ECLASS-VARIABLE: DISABLE_AUTOFORMATTING
36 # @DEFAULT_UNSET
37 # @DESCRIPTION:
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.
41
42 # @ECLASS-VARIABLE: FORCE_PRINT_ELOG
43 # @DEFAULT_UNSET
44 # @DESCRIPTION:
45 # If non-empty this variable forces elog messages to be printed.
46
47 # @ECLASS-VARIABLE: README_GENTOO_SUFFIX
48 # @DESCRIPTION:
49 # If you want to specify a suffix for README.gentoo file please export it.
50 : ${README_GENTOO_SUFFIX:=""}
51
52 # @FUNCTION: readme.gentoo_create_doc
53 # @DESCRIPTION:
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} "${@}"
60
61         if [[ -n "${DOC_CONTENTS}" ]]; then
62                 if [[ -n "${DISABLE_AUTOFORMATTING}" ]]; then
63                         echo "${DOC_CONTENTS}" > "${T}"/README.gentoo || die
64                 else
65                         local saved_flags=$-
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
69                         assert
70                         set +f -${saved_flags}
71                 fi
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
76         else
77                 die "You are not specifying README.gentoo contents!"
78         fi
79
80         dodoc "${T}"/README.gentoo
81         README_GENTOO_DOC_VALUE=$(< "${T}/README.gentoo")
82 }
83
84 # @FUNCTION: readme.gentoo_print_elog
85 # @DESCRIPTION:
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.
89 #
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} "${@}"
97
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
102                 elog ""
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)"
106         fi
107 }
108
109 fi