1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python3_{6,7} )
7 PYTHON_REQ_USE="sqlite,ssl"
9 inherit bash-completion-r1 desktop toolchain-funcs python-single-r1 xdg-utils
11 DESCRIPTION="Ebook management application"
12 HOMEPAGE="https://calibre-ebook.com/"
13 SRC_URI="https://download.calibre-ebook.com/${PV}/${P}.tar.xz"
29 || ( Artistic GPL-1+ )
34 KEYWORDS="~amd64 ~arm ~x86"
38 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
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:=
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 dev-python/zeroconf[${PYTHON_MULTI_USEDEP}]
79 >=dev-qt/qtwebengine-5.12
81 dev-util/desktop-file-utils
82 dev-util/gtk-update-icon-cache
83 media-fonts/liberation-fonts
84 media-libs/fontconfig:=
85 >=media-libs/freetype-2:=
86 >=media-libs/libmtp-1.1.11:=
87 >=media-libs/libwmf-0.2.8
88 >=media-gfx/optipng-0.7.6
89 >=sys-libs/zlib-1.2.11:=
91 x11-libs/libxkbcommon:=
95 x11-misc/shared-mime-info
96 >=x11-misc/xdg-utils-1.0.2-r2
98 >=app-pda/usbmuxd-1.0.8
99 >=app-pda/libimobiledevice-1.2.0
101 udisks? ( virtual/libudev )"
102 RDEPEND="${COMMON_DEPEND}
103 udisks? ( sys-fs/udisks:2 )"
104 DEPEND="${COMMON_DEPEND}
105 $(python_gen_cond_dep '
106 >=dev-python/setuptools-23.1.0[${PYTHON_MULTI_USEDEP}]
107 dev-python/sip[${PYTHON_MULTI_USEDEP}]
109 >=virtual/podofo-build-0.9.6_pre20171027
113 if [[ ${MERGE_TYPE} != binary ]] && tc-is-gcc && [[ $(gcc-major-version) -lt 6 ]]; then
114 eerror "Calibre cannot be built with this version of gcc."
115 eerror "You need at least gcc-6.0"
116 die "Your C compiler is too old for this package."
121 # no_updates: do not annoy user with "new version is availible all the time
122 # disable_plugins: walking sec-hole, wait for upstream to use GHNS interface
124 "${FILESDIR}/${PN}-2.9.0-no_updates_dialog.patch" \
125 "${FILESDIR}/${PN}-disable_plugins.patch"
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"
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"
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"
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"
160 # calibre works with python 3, so remove the python 2 constraint
161 export CALIBRE_PY3_PORT=1
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
171 cp "${T}"/{kbuildsycoca,update-mime-database} || die
172 chmod +x "${T}"/{kbuildsycoca,update-mime-database} || die
174 export QMAKE="${EPREFIX}/usr/$(get_libdir)/qt5/bin/qmake"
176 # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
177 # violation with kbuildsycoca as in bug #287067, comment #13.
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
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
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"
203 addpredict /dev/dri #665310
205 PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
206 "${PYTHON}" setup.py install \
208 --prefix="${EPREFIX}/usr" \
209 --libdir="${EPREFIX}/usr/${libdir}" \
210 --staging-root="${ED}/usr" \
211 --staging-libdir="${ED}/usr/${libdir}" || die
213 rm "${ED}/usr/share/applications/defaults.list" || die
214 find "${ED}"/usr/share -type d -empty -delete
216 cd "${ED}"/usr/share/calibre/fonts/liberation || die
219 [[ -f ${EPREFIX}/usr/share/fonts/liberation-fonts/${x} ]] || continue
220 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
223 einfo "Converting python shebangs"
224 python_fix_shebang --force "${ED}"
226 einfo "Compiling python modules"
227 python_optimize "${ED}"/usr/lib/calibre
229 newinitd "${FILESDIR}"/calibre-server-3.init calibre-server
230 newconfd "${FILESDIR}"/calibre-server-3.conf calibre-server
232 bashcomp_alias calibre \
239 fetch-ebook-metadata \
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}"
257 [[ -n ${CALIBRE_LIB_DIR} ]] || die "CALIBRE_LIB_DIR is unset"
259 for x in "${EROOT}${CALIBRE_LIB_DIR}"/*; do
260 if [[ " ${CALIBRE_LIB_CONTENT} " != *" ${x##*/} "* ]]; then
261 elog "Purging '${x}'"
265 xdg_desktop_database_update
266 xdg_mimeinfo_database_update
267 xdg_icon_cache_update
271 xdg_desktop_database_update
272 xdg_mimeinfo_database_update
273 xdg_icon_cache_update