sys-process/glances: revbump 3.1.4.1, add missing doc dep
[gentoo.git] / app-text / calibre / calibre-4.9.1-r2.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python3_{6,7} )
7 PYTHON_REQ_USE="sqlite,ssl"
8
9 inherit bash-completion-r1 desktop toolchain-funcs python-single-r1 xdg-utils
10
11 DESCRIPTION="Ebook management application"
12 HOMEPAGE="https://calibre-ebook.com/"
13 SRC_URI="https://download.calibre-ebook.com/${PV}/${P}.tar.xz"
14
15 LICENSE="
16         GPL-3+
17         GPL-3
18         GPL-2+
19         GPL-2
20         GPL-1+
21         LGPL-3+
22         LGPL-2.1+
23         LGPL-2.1
24         BSD
25         MIT
26         Old-MIT
27         Apache-2.0
28         public-domain
29         || ( Artistic GPL-1+ )
30         CC-BY-3.0
31         OFL-1.1
32         PSF-2
33 "
34 KEYWORDS="amd64 ~arm x86"
35 SLOT="0"
36 IUSE="ios +udisks"
37
38 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
39
40 COMMON_DEPEND="${PYTHON_DEPS}
41         >=app-text/hunspell-1.7:=
42         >=app-text/podofo-0.9.6_pre20171027:=
43         >=app-text/poppler-0.26.5[qt5]
44         >=dev-libs/chmlib-0.40:=
45         dev-libs/glib:2=
46         dev-libs/hyphen:=
47         >=dev-libs/icu-57.1:=
48         dev-libs/libinput:=
49         >=dev-libs/dbus-glib-0.106
50         >=sys-apps/dbus-1.10.8
51         $(python_gen_cond_dep '
52                 >=dev-python/apsw-3.25.2_p1[${PYTHON_MULTI_USEDEP}]
53                 dev-python/beautifulsoup:4[${PYTHON_MULTI_USEDEP}]
54                 >=dev-python/chardet-3.0.3[${PYTHON_MULTI_USEDEP}]
55                 >=dev-python/cssselect-0.7.1[${PYTHON_MULTI_USEDEP}]
56                 >=dev-python/css-parser-1.0.4[${PYTHON_MULTI_USEDEP}]
57                 >=dev-python/dbus-python-1.2.4[${PYTHON_MULTI_USEDEP}]
58                 dev-python/dnspython[${PYTHON_MULTI_USEDEP}]
59                 >=dev-python/feedparser-5.2.1[${PYTHON_MULTI_USEDEP}]
60                 >=dev-python/html2text-2019.8.11[${PYTHON_MULTI_USEDEP}]
61                 >=dev-python/html5-parser-0.4.9[${PYTHON_MULTI_USEDEP}]
62                 >=dev-python/lxml-3.8.0[${PYTHON_MULTI_USEDEP}]
63                 >=dev-python/markdown-3.0.1[${PYTHON_MULTI_USEDEP}]
64                 >=dev-python/mechanize-0.3.5[${PYTHON_MULTI_USEDEP}]
65                 >=dev-python/msgpack-0.5.6[${PYTHON_MULTI_USEDEP}]
66                 >=dev-python/netifaces-0.10.5[${PYTHON_MULTI_USEDEP}]
67                 >=dev-python/pillow-3.2.0[${PYTHON_MULTI_USEDEP}]
68                 >=dev-python/psutil-4.3.0[${PYTHON_MULTI_USEDEP}]
69                 >=dev-python/pygments-2.3.1[${PYTHON_MULTI_USEDEP}]
70                 >=dev-python/python-dateutil-2.5.3[${PYTHON_MULTI_USEDEP}]
71                 >=dev-python/PyQt5-5.12[gui,svg,widgets,network,printsupport,${PYTHON_MULTI_USEDEP}]
72                 >=dev-python/PyQtWebEngine-5.12[${PYTHON_MULTI_USEDEP}]
73                 dev-python/regex[${PYTHON_MULTI_USEDEP}]
74         ')
75         dev-qt/qtcore:5=
76         dev-qt/qtdbus:5=
77         dev-qt/qtgui:5=
78         >=dev-qt/qtwebengine-5.12
79         dev-qt/qtwidgets:5=
80         dev-util/desktop-file-utils
81         dev-util/gtk-update-icon-cache
82         media-fonts/liberation-fonts
83         media-libs/fontconfig:=
84         >=media-libs/freetype-2:=
85         >=media-libs/libmtp-1.1.11:=
86         >=media-libs/libwmf-0.2.8
87         >=media-gfx/optipng-0.7.6
88         >=sys-libs/zlib-1.2.11:=
89         virtual/libusb:1=
90         x11-libs/libxkbcommon:=
91         x11-libs/libX11:=
92         x11-libs/libXext:=
93         x11-libs/libXrender:=
94         x11-misc/shared-mime-info
95         >=x11-misc/xdg-utils-1.0.2-r2
96         ios? (
97                 >=app-pda/usbmuxd-1.0.8
98                 >=app-pda/libimobiledevice-1.2.0
99         )
100         udisks? ( virtual/libudev )"
101 RDEPEND="${COMMON_DEPEND}
102         udisks? ( sys-fs/udisks:2 )"
103 DEPEND="${COMMON_DEPEND}
104         $(python_gen_cond_dep '
105                 >=dev-python/setuptools-23.1.0[${PYTHON_MULTI_USEDEP}]
106                 dev-python/sip[${PYTHON_MULTI_USEDEP}]
107         ')
108         >=virtual/podofo-build-0.9.6_pre20171027
109         virtual/pkgconfig"
110
111 pkg_pretend() {
112         if [[ ${MERGE_TYPE} != binary ]] && tc-is-gcc && [[ $(gcc-major-version) -lt 6 ]]; then
113                 eerror "Calibre cannot be built with this version of gcc."
114                 eerror "You need at least gcc-6.0"
115                 die "Your C compiler is too old for this package."
116         fi
117 }
118
119 src_prepare() {
120         # no_updates: do not annoy user with "new version is availible all the time
121         # disable_plugins: walking sec-hole, wait for upstream to use GHNS interface
122         eapply \
123                 "${FILESDIR}/${PN}-2.9.0-no_updates_dialog.patch" \
124                 "${FILESDIR}/${PN}-disable_plugins.patch" \
125                 "${FILESDIR}/${PN}-4.9.1-py3-Ignore-TypeError-sorting-collections-kobo.patch"
126
127         eapply_user
128
129         # Fix outdated version constant.
130         #sed -e "s#\\(^numeric_version =\\).*#\\1 (${PV//./, })#" \
131         #       -i src/calibre/constants.py || \
132         #       die "sed failed to patch constants.py"
133
134         # Avoid sandbox violation in /usr/share/gnome/apps when linux.py
135         # calls xdg-* (bug #258938).
136         sed -e "s|'xdg-desktop-menu', 'install'|\\0, '--mode', 'user'|" \
137                 -e "s|check_call(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
138                 -e "s|\\(CurrentDir(tdir)\\), \\\\\$|\\1:|" \
139                 -e "s|, PreserveMIMEDefaults():|:|" \
140                 -e "s|'xdg-icon-resource', 'install'|\\0, '--mode', 'user'|" \
141                 -e "s|cmd\[2\]|cmd[4]|" \
142                 -e "s|cc(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
143                 -e "s|'xdg-mime', 'install'|\\0, '--mode', 'user'|" \
144                 -i src/calibre/linux.py || die "sed failed to patch linux.py"
145
146         # Disable unnecessary privilege dropping for bug #287067.
147         sed -e "s:if os.geteuid() == 0:if False and os.geteuid() == 0:" \
148                 -i setup/install.py || die "sed failed to patch install.py"
149
150         sed -e "/^                self.check_call(\\[QMAKE\\] + qmc + \\[proname\\])$/a\
151 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ self.check_call(['sed', \
152 '-e', 's|^CFLAGS .*|\\\\\\\\0 ${CFLAGS}|', \
153 '-e', 's|^CXXFLAGS .*|\\\\\\\\0 ${CXXFLAGS}|', \
154 '-e', 's|^LFLAGS .*|\\\\\\\\0 ${LDFLAGS}|', \
155 '-i', 'Makefile'])" \
156                 -i setup/build.py || die "sed failed to patch build.py"
157 }
158
159 src_install() {
160         # calibre works with python 3, so remove the python 2 constraint
161         export CALIBRE_PY3_PORT=1
162
163         # Bypass kbuildsycoca and update-mime-database in order to
164         # avoid sandbox violations if xdg-mime tries to call them.
165         cat - > "${T}/kbuildsycoca" <<-EOF
166         #!${BASH}
167         echo $0 : $@
168         exit 0
169         EOF
170
171         cp "${T}"/{kbuildsycoca,update-mime-database} || die
172         chmod +x "${T}"/{kbuildsycoca,update-mime-database} || die
173
174         export QMAKE="${EPREFIX}/usr/$(get_libdir)/qt5/bin/qmake"
175
176         # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
177         # violation with kbuildsycoca as in bug #287067, comment #13.
178         export -n DISPLAY
179
180         # Bug #352625 - Some LANGUAGE values can trigger the following ValueError:
181         #   File "/usr/lib/python2.6/locale.py", line 486, in getdefaultlocale
182         #    return _parse_localename(localename)
183         #  File "/usr/lib/python2.6/locale.py", line 418, in _parse_localename
184         #    raise ValueError, 'unknown locale: %s' % localename
185         #ValueError: unknown locale: 46
186         export -n LANG LANGUAGE ${!LC_*}
187         export LC_ALL=C.utf8 #709682
188
189         # Bug #295672 - Avoid sandbox violation in ~/.config by forcing
190         # variables to point to our fake temporary $HOME.
191         export HOME="${T}/fake_homedir"
192         export XDG_CONFIG_HOME="${HOME}/.config"
193         export XDG_DATA_HOME="${HOME}/.local/share"
194         export CALIBRE_CONFIG_DIRECTORY="${XDG_CONFIG_HOME}/calibre"
195         mkdir -p "${XDG_DATA_HOME}" "${CALIBRE_CONFIG_DIRECTORY}" || die
196
197         tc-export CC CXX
198         # Bug #334243 - respect LDFLAGS when building extensions
199         export OVERRIDE_CFLAGS="$CFLAGS" OVERRIDE_LDFLAGS="$LDFLAGS"
200         local libdir=$(get_libdir)
201         [[ -n $libdir ]] || die "get_libdir returned an empty string"
202
203         addpredict /dev/dri #665310
204
205         PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
206         "${PYTHON}" setup.py install \
207                 --root="${D}" \
208                 --prefix="${EPREFIX}/usr" \
209                 --libdir="${EPREFIX}/usr/${libdir}" \
210                 --staging-root="${ED}/usr" \
211                 --staging-libdir="${ED}/usr/${libdir}" || die
212
213         rm "${ED}/usr/share/applications/defaults.list" || die
214         find "${ED}"/usr/share -type d -empty -delete
215
216         cd "${ED}"/usr/share/calibre/fonts/liberation || die
217         local x
218         for x in * ; do
219                 [[ -f ${EPREFIX}/usr/share/fonts/liberation-fonts/${x} ]] || continue
220                 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
221         done
222
223         einfo "Converting python shebangs"
224         python_fix_shebang --force "${ED}"
225
226         einfo "Compiling python modules"
227         python_optimize "${ED}"/usr/lib/calibre
228
229         newinitd "${FILESDIR}"/calibre-server-3.init calibre-server
230         newconfd "${FILESDIR}"/calibre-server-3.conf calibre-server
231
232         bashcomp_alias calibre \
233                 lrfviewer \
234                 calibre-debug \
235                 ebook-meta \
236                 calibre-server \
237                 ebook-viewer \
238                 ebook-polish \
239                 fetch-ebook-metadata \
240                 lrf2lrs \
241                 ebook-convert \
242                 ebook-edit \
243                 calibre-smtp \
244                 ebook-device
245
246 }
247
248 pkg_preinst() {
249         # Indentify stray directories from upstream's "Binary install"
250         # method (see bug 622728).
251         CALIBRE_LIB_DIR=/usr/$(get_libdir)/calibre
252         CALIBRE_LIB_CONTENT=$(for x in "${ED}${CALIBRE_LIB_DIR}"/*; do
253                 printf -- "${x##*/} "; done) || die "Failed to list ${ED}${CALIBRE_LIB_DIR}"
254 }
255
256 pkg_postinst() {
257         [[ -n ${CALIBRE_LIB_DIR} ]] || die "CALIBRE_LIB_DIR is unset"
258         local x
259         for x in "${EROOT}${CALIBRE_LIB_DIR}"/*; do
260                 if [[ " ${CALIBRE_LIB_CONTENT} " != *" ${x##*/} "* ]]; then
261                         elog "Purging '${x}'"
262                         rm -rf "${x}"
263                 fi
264         done
265         xdg_desktop_database_update
266         xdg_mimeinfo_database_update
267         xdg_icon_cache_update
268 }
269
270 pkg_postrm() {
271         xdg_desktop_database_update
272         xdg_mimeinfo_database_update
273         xdg_icon_cache_update
274 }