nvidia-driver.eclass: Use next gen version of readme.gentoo eclass
[gentoo.git] / eclass / readme.gentoo.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.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 # This eclass is DEPRECATED. Please use readme.gentoo-r1 instead.
19
20 if [[ -z ${_README_GENTOO_ECLASS} ]]; then
21 _README_GENTOO_ECLASS=1
22
23 inherit eutils
24
25 case "${EAPI:-0}" in
26         0|1|2|3)
27                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
28                 ;;
29         4|5)
30                 # EAPI>=4 is required for REPLACING_VERSIONS preventing us
31                 # from needing to export another pkg_preinst phase to save has_version
32                 # result. Also relies on EAPI >=4 default src_install phase.
33                 EXPORT_FUNCTIONS src_install pkg_postinst
34                 ;;
35         6)
36                 die "Unsupported EAPI=${EAPI} for ${ECLASS}"
37                 die "Please migrate to readme.gentoo-r1.eclass and note that"
38                 die "it stops to export any ebuild phases and, then, you will"
39                 die "need to ensure readme.gentoo_create_doc is called in"
40                 die "src_install and readme.gentoo_print_elog in pkg_postinst"
41                 ;;
42         *)
43                 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
44                 ;;
45 esac
46
47 # @ECLASS-VARIABLE: DISABLE_AUTOFORMATTING
48 # @DEFAULT_UNSET
49 # @DESCRIPTION:
50 # If non-empty, DOC_CONTENTS information will be strictly respected,
51 # not getting it automatically formatted by fmt. If empty, it will
52 # rely on fmt for formatting and 'echo -e' options to tweak lines a bit.
53
54 # @ECLASS-VARIABLE: FORCE_PRINT_ELOG
55 # @DEFAULT_UNSET
56 # @DESCRIPTION:
57 # If non-empty this variable forces elog messages to be printed.
58
59 # @ECLASS-VARIABLE: README_GENTOO_SUFFIX
60 # @DESCRIPTION:
61 # If you want to specify a suffix for README.gentoo file please export it.
62 : ${README_GENTOO_SUFFIX:=""}
63
64 # @FUNCTION: readme.gentoo_create_doc
65 # @DESCRIPTION:
66 # Create doc file with ${DOC_CONTENTS} variable (preferred) and, if not set,
67 # look for "${FILESDIR}/README.gentoo" contents. You can use
68 # ${FILESDIR}/README.gentoo-${SLOT} also.
69 # Usually called at src_install phase.
70 readme.gentoo_create_doc() {
71         debug-print-function ${FUNCNAME} "${@}"
72
73         if [[ -n "${DOC_CONTENTS}" ]]; then
74                 eshopts_push
75                 set -f
76                 if [[ -n "${DISABLE_AUTOFORMATTING}" ]]; then
77                         echo "${DOC_CONTENTS}" > "${T}"/README.gentoo
78                 else
79                         echo -e ${DOC_CONTENTS} | fold -s -w 70 \
80                                 | sed 's/[[:space:]]*$//' > "${T}"/README.gentoo
81                 fi
82                 eshopts_pop
83         elif [[ -f "${FILESDIR}/README.gentoo-${SLOT%/*}" ]]; then
84                 cp "${FILESDIR}/README.gentoo-${SLOT%/*}" "${T}"/README.gentoo || die
85         elif [[ -f "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" ]]; then
86                 cp "${FILESDIR}/README.gentoo${README_GENTOO_SUFFIX}" "${T}"/README.gentoo || die
87         else
88                 die "You are not specifying README.gentoo contents!"
89         fi
90
91         dodoc "${T}"/README.gentoo
92         README_GENTOO_DOC_VALUE=$(< "${T}/README.gentoo")
93 }
94
95 # @FUNCTION: readme.gentoo_print_elog
96 # @DESCRIPTION:
97 # Print elog messages with "${T}"/README.gentoo contents. They will be
98 # shown only when package is installed at first time.
99 # Usually called at pkg_postinst phase.
100 #
101 # If you want to show them always, please set FORCE_PRINT_ELOG to a non empty
102 # value in your ebuild before this function is called.
103 # This can be useful when, for example, DOC_CONTENTS is modified, then, you can
104 # rely on specific REPLACING_VERSIONS handling in your ebuild to print messages
105 # when people update from versions still providing old message.
106 readme.gentoo_print_elog() {
107         debug-print-function ${FUNCNAME} "${@}"
108
109         eqawarn "${CATEGORY}/${PN} is using the deprecated readme.gentoo.eclass."
110         eqawarn "Please use readme.gentoo-r1 instead."
111
112         if [[ -z "${README_GENTOO_DOC_VALUE}" ]]; then
113                 die "readme.gentoo_print_elog invoked without matching readme.gentoo_create_doc call!"
114         elif ! [[ -n "${REPLACING_VERSIONS}" ]] || [[ -n "${FORCE_PRINT_ELOG}" ]]; then
115                 echo -e "${README_GENTOO_DOC_VALUE}" | while read -r ELINE; do elog "${ELINE}"; done
116                 elog ""
117                 elog "(Note: Above message is only printed the first time package is"
118                 elog "installed. Please look at ${EPREFIX}/usr/share/doc/${PF}/README.gentoo*"
119                 elog "for future reference)"
120         fi
121 }
122
123
124 # @FUNCTION: readme.gentoo_src_install
125 # @DESCRIPTION:
126 # Install generated doc file automatically.
127 readme.gentoo_src_install() {
128         debug-print-function ${FUNCNAME} "${@}"
129         default
130         readme.gentoo_create_doc
131 }
132
133 # @FUNCTION: readme.gentoo_pkg_postinst
134 # @DESCRIPTION:
135 # Show elog messages from from just generated doc file.
136 readme.gentoo_pkg_postinst() {
137         debug-print-function ${FUNCNAME} "${@}"
138         readme.gentoo_print_elog
139 }
140
141 fi