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