1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 inherit eutils fdo-mime bash-completion-r1 multilib toolchain-funcs
8 DESCRIPTION="Ebook management application"
9 HOMEPAGE="http://calibre-ebook.com/"
10 SRC_URI="http://download.calibre-ebook.com/${PV}/${P}.tar.xz"
26 || ( Artistic GPL-1+ )
32 KEYWORDS="~amd64 ~arm ~x86"
37 >=app-text/podofo-0.8.2:=
38 >=app-text/poppler-0.26.5[qt5]
39 >=dev-lang/python-2.7.9:2.7[sqlite,ssl]
40 >=dev-libs/chmlib-0.40:=
43 >=dev-python/apsw-3.7.17[python_targets_python2_7(-)]
44 >=dev-python/beautifulsoup-3.0.5:python-2[python_targets_python2_7(-)]
45 virtual/dnspython[python_targets_python2_7(-)]
46 >=dev-python/cssselect-0.7.1[python_targets_python2_7(-)]
47 >=dev-python/cssutils-0.9.9[python_targets_python2_7(-)]
48 >=dev-python/dbus-python-1.2.0[python_targets_python2_7(-)]
49 >=dev-python/lxml-3.2.1[python_targets_python2_7(-)]
50 >=dev-python/mechanize-0.1.11[python_targets_python2_7(-)]
51 dev-python/netifaces[python_targets_python2_7(-)]
52 dev-python/psutil[python_targets_python2_7(-)]
53 >=dev-python/pygments-2.0.1[python_targets_python2_7(-)]
54 >=dev-python/python-dateutil-1.4.1[python_targets_python2_7(-)]
55 >=dev-python/PyQt5-5.3.1[gui,svg,webkit,widgets,network,printsupport,python_targets_python2_7(-)]
59 media-fonts/liberation-fonts
60 >=media-gfx/imagemagick-6.5.9[jpeg,png]
62 >=media-libs/freetype-2:=
63 >=media-libs/libmtp-1.1.5:=
64 >=media-libs/libwmf-0.2.8
67 virtual/python-imaging[python_targets_python2_7(-)]
71 >=x11-misc/xdg-utils-1.0.2-r2
72 udisks? ( virtual/libudev )"
73 RDEPEND="${COMMON_DEPEND}
74 udisks? ( || ( sys-fs/udisks:2 sys-fs/udisks:0 ) )"
75 DEPEND="${COMMON_DEPEND}
76 >=dev-python/setuptools-0.6_rc5
77 >=virtual/podofo-build-0.8.2"
80 # Fix outdated version constant.
81 #sed -e "s#\\(^numeric_version =\\).*#\\1 (${PV//./, })#" \
82 # -i src/calibre/constants.py || \
83 # die "sed failed to patch constants.py"
85 # Avoid sandbox violation in /usr/share/gnome/apps when linux.py
86 # calls xdg-* (bug #258938).
87 sed -e "s|'xdg-desktop-menu', 'install'|\\0, '--mode', 'user'|" \
88 -e "s|check_call(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
89 -e "s|\\(CurrentDir(tdir)\\), \\\\\$|\\1:|" \
90 -e "s|PreserveMIMEDefaults():||" \
91 -e "s|xdg-icon-resource install|\\0 --mode user|" \
92 -e "s|cc(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
93 -e "s|'xdg-mime', 'install'|\\0, '--mode', 'user'|" \
94 -i src/calibre/linux.py || die "sed failed to patch linux.py"
96 # Disable unnecessary privilege dropping for bug #287067.
97 sed -e "s:if os.geteuid() == 0:if False and os.geteuid() == 0:" \
98 -i setup/install.py || die "sed failed to patch install.py"
100 sed -e "/^ self\\.check_call(qmc + \\[.*\\.pro'\\])$/a\
101 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ self.check_call(['sed', \
102 '-e', 's|^CFLAGS .*|\\\\\\\\0 ${CFLAGS}|', \
103 '-e', 's|^CXXFLAGS .*|\\\\\\\\0 ${CXXFLAGS}|', \
104 '-e', 's|^LFLAGS .*|\\\\\\\\0 ${LDFLAGS}|', \
105 '-i', 'Makefile'])" \
106 -i setup/extensions.py || die "sed failed to patch extensions.py"
108 # use system beautifulsoup, instead of bundled
109 rm -f "${S}"/src/calibre/ebooks/BeautifulSoup.py \
110 || die "could not remove bundled beautifulsoup"
111 find "${S}" -type f -name \*.py -exec \
112 sed -e 's/calibre.ebooks.BeautifulSoup/BeautifulSoup/' -i {} + \
113 || die "could not sed bundled beautifulsoup out of the source tree"
115 # avoid failure of xdg tools to recognize vendor prefix
116 sed -e "s|xdg-icon-resource install|xdg-icon-resource install --novendor|" \
117 -e "s|'xdg-mime', 'install'|'xdg-mime', 'install', '--novendor'|" \
118 -e "s|'xdg-desktop-menu', 'install'|'xdg-desktop-menu', 'install', '--novendor'|" \
119 -i "${S}"/src/calibre/linux.py || die 'sed failed'
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 # Bypass kbuildsycoca and update-mime-database in order to
130 # avoid sandbox violations if xdg-mime tries to call them.
131 cat - > "${T}/kbuildsycoca" <<-EOF
137 cp "${T}"/{kbuildsycoca,update-mime-database}
138 chmod +x "${T}"/{kbuildsycoca,update-mime-database}
140 export QMAKE="${EPREFIX}/usr/$(get_libdir)/qt5/bin/qmake"
142 # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
143 # violation with kbuildsycoca as in bug #287067, comment #13.
146 # Bug #352625 - Some LANGUAGE values can trigger the following ValueError:
147 # File "/usr/lib/python2.6/locale.py", line 486, in getdefaultlocale
148 # return _parse_localename(localename)
149 # File "/usr/lib/python2.6/locale.py", line 418, in _parse_localename
150 # raise ValueError, 'unknown locale: %s' % localename
151 #ValueError: unknown locale: 46
154 # Bug #295672 - Avoid sandbox violation in ~/.config by forcing
155 # variables to point to our fake temporary $HOME.
156 export HOME="${T}/fake_homedir"
157 export XDG_CONFIG_HOME="${HOME}/.config"
158 export XDG_DATA_HOME="${HOME}/.local/share"
159 export CALIBRE_CONFIG_DIRECTORY="${XDG_CONFIG_HOME}/calibre"
160 mkdir -p "${XDG_DATA_HOME}" "${CALIBRE_CONFIG_DIRECTORY}"
163 # Bug #334243 - respect LDFLAGS when building extensions
164 export OVERRIDE_CFLAGS="$CFLAGS" OVERRIDE_LDFLAGS="$LDFLAGS"
165 local libdir=$(get_libdir)
166 [[ -n $libdir ]] || die "get_libdir returned an empty string"
168 # Bug #472690 - Avoid sandbox violation for /dev/dri/card0.
170 for x in /dev/dri/card[0-9] ; do
171 [[ -e ${x} ]] && addpredict ${x}
174 dodir "/usr/$(get_libdir)/python2.7/site-packages" # for init_calibre.py
175 PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
176 "${EPREFIX}"/usr/bin/python2.7 setup.py install \
178 --prefix="${EPREFIX}/usr" \
179 --libdir="${EPREFIX}/usr/${libdir}" \
180 --staging-root="${ED}usr" \
181 --staging-libdir="${ED}usr/${libdir}" || die
183 grep -rlZ "${ED}" "${ED}" | xargs -0 sed -e "s:${D}:/:g" -i ||
184 die "failed to fix harcoded \$D in paths"
186 # The menu entries end up here due to '--mode user' being added to
187 # xdg-* options in src_prepare.
188 dodir /usr/share/mime/packages
189 chmod -fR a+rX,u+w,g-w,o-w "${HOME}"/.local
190 mv "${HOME}"/.local/share/mime/packages/* "${ED}"usr/share/mime/packages/ ||
191 die "failed to register mime types"
192 dodir /usr/share/icons
193 mv "${HOME}"/.local/share/icons/* "${ED}"usr/share/icons/ ||
194 die "failed to install icon files"
196 domenu "${HOME}"/.local/share/applications/*.desktop ||
197 die "failed to install .desktop menu files"
199 find "${ED}"usr/share -type d -empty -delete
201 cd "${ED}"/usr/share/calibre/fonts/liberation || die
204 [[ -f ${EROOT}usr/share/fonts/liberation-fonts/${x} ]] || continue
205 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
208 einfo "Converting python shebangs"
209 while read -r -d $'\0' ; do
210 local shebang=$(head -n1 "$REPLY")
211 if [[ ${shebang} == "#!"*python* ]] ; then
212 sed -i -e "1s:.*:#!${EPREFIX}/usr/bin/python2.7:" "$REPLY" || \
215 done < <(find "${ED}" -type f -print0)
217 einfo "Compiling python modules"
218 "${EPREFIX}"/usr/bin/python2.7 -m compileall -q -f \
219 -d "${EPREFIX}"/usr/lib/calibre "${ED}"usr/lib/calibre || die
221 newinitd "${FILESDIR}"/calibre-server.init calibre-server
222 newconfd "${FILESDIR}"/calibre-server.conf calibre-server
226 fdo-mime_desktop_database_update
227 fdo-mime_mime_database_update