net-irc/limnoria: use HTTPS for GitHub and HOMEPAGE
[gentoo.git] / eclass / office-ext-r1.eclass
1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: office-ext-r1.eclass
5 # @MAINTAINER:
6 # The office team <openoffice@gentoo.org>
7 # @AUTHOR:
8 # Tomáš Chvátal <scarabeus@gentoo.org>
9 # @BLURB: Eclass for installing libreoffice/openoffice extensions
10 # @DESCRIPTION:
11 # Eclass for easing maitenance of libreoffice/openoffice extensions.
12
13 case "${EAPI:-0}" in
14         5|6) OEXT_EXPORTED_FUNCTIONS="src_unpack src_install pkg_postinst pkg_prerm" ;;
15         *) die "EAPI=${EAPI} is not supported" ;;
16 esac
17
18 inherit eutils multilib
19
20 # @ECLASS-VARIABLE: OFFICE_REQ_USE
21 # @DESCRIPTION:
22 # Useflags required on office implementation for the extension.
23 #
24 # Example:
25 # @CODE
26 # OFFICE_REQ_USE="java,jemalloc(-)?"
27 # @CODE
28 if [[ ${OFFICE_REQ_USE} ]]; then
29         # Append the brackets for the depend bellow
30         OFFICE_REQ_USE="[${OFFICE_REQ_USE}]"
31 fi
32
33 # @ECLASS-VARIABLE: OFFICE_IMPLEMENTATIONS
34 # @DESCRIPTION:
35 # List of implementations supported by the extension.
36 # Some work only for libreoffice and vice versa.
37 # Default value is all implementations.
38 #
39 # Example:
40 # @CODE
41 # OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
42 # @CODE
43 [[ -z ${OFFICE_IMPLEMENTATIONS} ]] && OFFICE_IMPLEMENTATIONS=( "libreoffice" "openoffice" )
44
45 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS
46 # @REQUIRED
47 # @DESCRIPTION:
48 # Array containing list of extensions to install.
49 #
50 # Example:
51 # @CODE
52 # OFFICE_EXTENSIONS=( ${PN}_${PV}.oxt )
53 # @CODE
54 [[ -z ${OFFICE_EXTENSIONS} ]] && die "OFFICE_EXTENSIONS variable is unset."
55 if [[ "$(declare -p OFFICE_EXTENSIONS 2>/dev/null 2>&1)" != "declare -a"* ]]; then
56         die "OFFICE_EXTENSIONS variable is not an array."
57 fi
58
59 # @ECLASS-VARIABLE: OFFICE_EXTENSIONS_LOCATION
60 # @DESCRIPTION:
61 # Path to the extensions location. Defaults to ${DISTDIR}.
62 #
63 # Example:
64 # @CODE
65 # OFFICE_EXTENSIONS_LOCATION="${S}/unpacked/"
66 # @CODE
67 : ${OFFICE_EXTENSIONS_LOCATION:=${DISTDIR}}
68
69 IUSE=""
70 RDEPEND=""
71
72 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
73         IUSE+=" office_implementation_${i}"
74         if [[ ${i} == "openoffice" ]]; then
75                 # special only binary
76                 RDEPEND+="
77                         office_implementation_openoffice? (
78                                 app-office/openoffice-bin${OFFICE_REQ_USE}
79                         )
80                 "
81         else
82                 RDEPEND+="
83                         office_implementation_${i}? (
84                                 || (
85                                         app-office/${i}${OFFICE_REQ_USE}
86                                         app-office/${i}-bin${OFFICE_REQ_USE}
87                                 )
88                         )
89                 "
90         fi
91 done
92
93 REQUIRED_USE="|| ( "
94 for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
95         REQUIRED_USE+=" office_implementation_${i} "
96 done
97 REQUIRED_USE+=" )"
98
99 DEPEND="${RDEPEND}
100         app-arch/unzip
101 "
102
103 # Most projects actually do not provide any relevant sourcedir as they are oxt.
104 S="${WORKDIR}"
105
106 # @FUNCTION: office-ext-r1_src_unpack
107 # @DESCRIPTION:
108 # Flush the cache after removal of an extension.
109 office-ext-r1_src_unpack() {
110         debug-print-function ${FUNCNAME} "$@"
111         local i
112
113         default
114
115         for i in ${OFFICE_EXTENSIONS[@]}; do
116                 # Unpack the extensions where required and add case for oxt
117                 # which should be most common case for the extensions.
118                 if [[ -f "${OFFICE_EXTENSIONS_LOCATION}/${i}" ]] ; then
119                         case ${i} in
120                                 *.oxt)
121                                         mkdir -p "${WORKDIR}/${i}/"
122                                         pushd "${WORKDIR}/${i}/" > /dev/null
123                                         echo ">>> Unpacking "${OFFICE_EXTENSIONS_LOCATION}/${i}" to ${PWD}"
124                                         unzip -qo ${OFFICE_EXTENSIONS_LOCATION}/${i}
125                                         assert "failed unpacking ${OFFICE_EXTENSIONS_LOCATION}/${i}"
126                                         popd > /dev/null
127                                         ;;
128                                 *) unpack ${i} ;;
129                         esac
130                 fi
131         done
132 }
133
134 # @FUNCTION: office-ext-r1_src_install
135 # @DESCRIPTION:
136 # Install the extension source to the proper location.
137 office-ext-r1_src_install() {
138         debug-print-function ${FUNCNAME} "$@"
139         debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
140
141         local i j
142
143         for i in ${OFFICE_IMPLEMENTATIONS[@]}; do
144                 if use office_implementation_${i}; then
145                         if [[ ${i} == openoffice ]]; then
146                                 # OOO needs to use uno because direct deployment segfaults.
147                                 # This is bug by their side, but i don't want to waste time
148                                 # fixing it myself.
149                                 insinto /usr/$(get_libdir)/${i}/share/extension/install
150                                 for j in ${OFFICE_EXTENSIONS[@]}; do
151                                         doins ${OFFICE_EXTENSIONS_LOCATION}/${j}
152                                 done
153                         else
154                                 for j in ${OFFICE_EXTENSIONS[@]}; do
155                                         pushd "${WORKDIR}/${j}/" > /dev/null
156                                         insinto /usr/$(get_libdir)/${i}/share/extensions/${j/.oxt/}
157                                         doins -r *
158                                         popd > /dev/null
159                                 done
160                         fi
161                 fi
162         done
163 }
164
165 #### OPENOFFICE COMPAT CODE
166
167 UNOPKG_BINARY="/usr/lib64/openoffice/program/unopkg"
168
169 # @FUNCTION: office-ext-r1_add_extension
170 # @DESCRIPTION:
171 # Install the extension into the libreoffice/openoffice.
172 office-ext-r1_add_extension() {
173         debug-print-function ${FUNCNAME} "$@"
174         local ext=$1
175         local tmpdir=$(emktemp -d)
176
177         debug-print "${FUNCNAME}: ${UNOPKG_BINARY} add --shared \"${ext}\""
178         ebegin "Adding office extension: \"${ext}\""
179         ${UNOPKG_BINARY} add --suppress-license \
180                 --shared "${ext}" \
181                 "-env:UserInstallation=file:///${tmpdir}" \
182                 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
183         eend $?
184         ${UNOPKG_BINARY} list --shared > /dev/null
185         rm -rf "${tmpdir}"
186 }
187
188 # @FUNCTION: office-ext-r1_remove_extension
189 # @DESCRIPTION:
190 # Remove the extension from the libreoffice/openoffice.
191 office-ext-r1_remove_extension() {
192         debug-print-function ${FUNCNAME} "$@"
193         local ext=$1
194         local tmpdir=$(mktemp -d --tmpdir="${T}")
195
196         debug-print "${FUNCNAME}: ${UNOPKG_BINARY} remove --shared \"${ext}\""
197         ebegin "Removing office extension: \"${ext}\""
198         ${UNOPKG_BINARY} remove --suppress-license \
199                 --shared "${ext}" \
200                 "-env:UserInstallation=file:///${tmpdir}" \
201                 "-env:JFW_PLUGIN_DO_NOT_CHECK_ACCESSIBILITY=1"
202         eend $?
203         ${UNOPKG_BINARY} list --shared > /dev/null
204         rm -rf "${tmpdir}"
205 }
206
207 # @FUNCTION: office-ext-r1_pkg_postinst
208 # @DESCRIPTION:
209 # Add the extensions to the openoffice.
210 office-ext-r1_pkg_postinst() {
211         if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
212                 debug-print-function ${FUNCNAME} "$@"
213                 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
214                 local i
215
216                 for i in ${OFFICE_EXTENSIONS[@]}; do
217                         office-ext-r1_add_extension "/usr/lib64/openoffice/share/extension/install/${i}"
218                 done
219         fi
220 }
221
222 # @FUNCTION: office-ext-r1_pkg_prerm
223 # @DESCRIPTION:
224 # Remove the extensions from the openoffice.
225 office-ext-r1_pkg_prerm() {
226         if in_iuse office_implementation_openoffice && use office_implementation_openoffice; then
227                 debug-print-function ${FUNCNAME} "$@"
228                 debug-print "Extensions: ${OFFICE_EXTENSIONS[@]}"
229                 local i
230
231                 for i in ${OFFICE_EXTENSIONS[@]}; do
232                         office-ext-r1_remove_extension "${i}"
233                 done
234         fi
235 }
236
237 EXPORT_FUNCTIONS ${OEXT_EXPORTED_FUNCTIONS}
238 unset OEXT_EXPORTED_FUNCTIONS