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 [[ ${PV} == ${PV%.*}.${PV#*.} ]] && MY_PV=${PV}.0 || MY_PV=${PV}
11 SRC_URI="http://sourceforge.net/projects/calibre/files/${MY_PV}/${PN}-${MY_PV}.tar.xz"
27 || ( Artistic GPL-1+ )
33 KEYWORDS="~amd64 ~arm ~x86"
38 >=app-text/podofo-0.8.2:=
39 >=app-text/poppler-0.26.5[qt5]
40 >=dev-lang/python-2.7.1:2.7[sqlite,ssl]
41 >=dev-libs/chmlib-0.40:=
44 >=dev-python/apsw-3.7.17[python_targets_python2_7(-)]
45 >=dev-python/beautifulsoup-3.0.5:python-2[python_targets_python2_7(-)]
46 >=dev-python/dnspython-1.6.0:0[python_targets_python2_7(-)]
47 >=dev-python/cssselect-0.7.1[python_targets_python2_7(-)]
48 >=dev-python/cssutils-0.9.9[python_targets_python2_7(-)]
49 >=dev-python/dbus-python-1.2.0[python_targets_python2_7(-)]
50 >=dev-python/lxml-3.2.1[python_targets_python2_7(-)]
51 >=dev-python/mechanize-0.1.11[python_targets_python2_7(-)]
52 dev-python/netifaces[python_targets_python2_7(-)]
53 dev-python/psutil[python_targets_python2_7(-)]
54 >=dev-python/pygments-2.0.1[python_targets_python2_7(-)]
55 >=dev-python/python-dateutil-1.4.1[python_targets_python2_7(-)]
56 >=dev-python/PyQt5-5.2.0[gui,svg,webkit,widgets,network,printsupport,python_targets_python2_7(-)]
60 media-fonts/liberation-fonts
61 >=media-gfx/imagemagick-6.5.9[jpeg,png]
63 >=media-libs/freetype-2:=
64 >=media-libs/libmtp-1.1.5:=
65 >=media-libs/libwmf-0.2.8
68 virtual/python-imaging[python_targets_python2_7(-)]
72 >=x11-misc/xdg-utils-1.0.2-r2
73 udisks? ( virtual/libudev )"
74 RDEPEND="${COMMON_DEPEND}
75 udisks? ( || ( sys-fs/udisks:2 sys-fs/udisks:0 ) )"
76 DEPEND="${COMMON_DEPEND}
77 >=dev-python/setuptools-0.6_rc5
78 >=virtual/podofo-build-0.8.2"
81 # Fix outdated version constant.
82 #sed -e "s#\\(^numeric_version =\\).*#\\1 (${PV//./, })#" \
83 # -i src/calibre/constants.py || \
84 # die "sed failed to patch constants.py"
86 # Avoid sandbox violation in /usr/share/gnome/apps when linux.py
87 # calls xdg-* (bug #258938).
88 sed -e "s|'xdg-desktop-menu', 'install'|\\0, '--mode', 'user'|" \
89 -e "s|check_call(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
90 -e "s|\\(CurrentDir(tdir)\\), \\\\\$|\\1:|" \
91 -e "s|PreserveMIMEDefaults():||" \
92 -e "s|xdg-icon-resource install|\\0 --mode user|" \
93 -e "s|cc(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
94 -e "s|'xdg-mime', 'install'|\\0, '--mode', 'user'|" \
95 -i src/calibre/linux.py || die "sed failed to patch linux.py"
97 # Disable unnecessary privilege dropping for bug #287067.
98 sed -e "s:if os.geteuid() == 0:if False and os.geteuid() == 0:" \
99 -i setup/install.py || die "sed failed to patch install.py"
101 sed -e "/^ self\\.check_call(qmc + \\[.*\\.pro'\\])$/a\
102 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ self.check_call(['sed', \
103 '-e', 's|^CFLAGS .*|\\\\\\\\0 ${CFLAGS}|', \
104 '-e', 's|^CXXFLAGS .*|\\\\\\\\0 ${CXXFLAGS}|', \
105 '-e', 's|^LFLAGS .*|\\\\\\\\0 ${LDFLAGS}|', \
106 '-i', 'Makefile'])" \
107 -i setup/extensions.py || die "sed failed to patch extensions.py"
109 # use system beautifulsoup, instead of bundled
110 rm -f "${S}"/src/calibre/ebooks/BeautifulSoup.py \
111 || die "could not remove bundled beautifulsoup"
112 find "${S}" -type f -name \*.py -exec \
113 sed -e 's/calibre.ebooks.BeautifulSoup/BeautifulSoup/' -i {} + \
114 || die "could not sed bundled beautifulsoup out of the source tree"
116 # avoid failure of xdg tools to recognize vendor prefix
117 sed -e "s|xdg-icon-resource install|xdg-icon-resource install --novendor|" \
118 -e "s|'xdg-mime', 'install'|'xdg-mime', 'install', '--novendor'|" \
119 -e "s|'xdg-desktop-menu', 'install'|'xdg-desktop-menu', 'install', '--novendor'|" \
120 -i "${S}"/src/calibre/linux.py || die 'sed failed'
122 # no_updates: do not annoy user with "new version is availible all the time
123 # disable_plugins: walking sec-hole, wait for upstream to use GHNS interface
125 "${FILESDIR}/${PN}-2.9.0-no_updates_dialog.patch" \
126 "${FILESDIR}/${PN}-disable_plugins.patch"
130 # Bypass kbuildsycoca and update-mime-database in order to
131 # avoid sandbox violations if xdg-mime tries to call them.
132 cat - > "${T}/kbuildsycoca" <<-EOF
138 cp "${T}"/{kbuildsycoca,update-mime-database}
139 chmod +x "${T}"/{kbuildsycoca,update-mime-database}
141 export QMAKE="${EPREFIX}/usr/$(get_libdir)/qt5/bin/qmake"
143 # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
144 # violation with kbuildsycoca as in bug #287067, comment #13.
147 # Bug #352625 - Some LANGUAGE values can trigger the following ValueError:
148 # File "/usr/lib/python2.6/locale.py", line 486, in getdefaultlocale
149 # return _parse_localename(localename)
150 # File "/usr/lib/python2.6/locale.py", line 418, in _parse_localename
151 # raise ValueError, 'unknown locale: %s' % localename
152 #ValueError: unknown locale: 46
155 # Bug #295672 - Avoid sandbox violation in ~/.config by forcing
156 # variables to point to our fake temporary $HOME.
157 export HOME="${T}/fake_homedir"
158 export XDG_CONFIG_HOME="${HOME}/.config"
159 export XDG_DATA_HOME="${HOME}/.local/share"
160 export CALIBRE_CONFIG_DIRECTORY="${XDG_CONFIG_HOME}/calibre"
161 mkdir -p "${XDG_DATA_HOME}" "${CALIBRE_CONFIG_DIRECTORY}"
164 # Bug #334243 - respect LDFLAGS when building extensions
165 export OVERRIDE_CFLAGS="$CFLAGS" OVERRIDE_LDFLAGS="$LDFLAGS"
166 local libdir=$(get_libdir)
167 [[ -n $libdir ]] || die "get_libdir returned an empty string"
169 # Bug #472690 - Avoid sandbox violation for /dev/dri/card0.
171 for x in /dev/dri/card[0-9] ; do
172 [[ -e ${x} ]] && addpredict ${x}
175 dodir "/usr/$(get_libdir)/python2.7/site-packages" # for init_calibre.py
176 PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
177 "${EPREFIX}"/usr/bin/python2.7 setup.py install \
179 --prefix="${EPREFIX}/usr" \
180 --libdir="${EPREFIX}/usr/${libdir}" \
181 --staging-root="${ED}usr" \
182 --staging-libdir="${ED}usr/${libdir}" || die
184 grep -rlZ "${ED}" "${ED}" | xargs -0 sed -e "s:${D}:/:g" -i ||
185 die "failed to fix harcoded \$D in paths"
187 # The menu entries end up here due to '--mode user' being added to
188 # xdg-* options in src_prepare.
189 dodir /usr/share/mime/packages
190 chmod -fR a+rX,u+w,g-w,o-w "${HOME}"/.local
191 mv "${HOME}"/.local/share/mime/packages/* "${ED}"usr/share/mime/packages/ ||
192 die "failed to register mime types"
193 dodir /usr/share/icons
194 mv "${HOME}"/.local/share/icons/* "${ED}"usr/share/icons/ ||
195 die "failed to install icon files"
197 domenu "${HOME}"/.local/share/applications/*.desktop ||
198 die "failed to install .desktop menu files"
200 find "${ED}"usr/share -type d -empty -delete
202 cd "${ED}"/usr/share/calibre/fonts/liberation || die
205 [[ -f ${EROOT}usr/share/fonts/liberation-fonts/${x} ]] || continue
206 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
209 einfo "Converting python shebangs"
210 while read -r -d $'\0' ; do
211 local shebang=$(head -n1 "$REPLY")
212 if [[ ${shebang} == "#!"*python* ]] ; then
213 sed -i -e "1s:.*:#!${EPREFIX}/usr/bin/python2.7:" "$REPLY" || \
216 done < <(find "${ED}" -type f -print0)
218 einfo "Compiling python modules"
219 "${EPREFIX}"/usr/bin/python2.7 -m compileall -q -f \
220 -d "${EPREFIX}"/usr/lib/calibre "${ED}"usr/lib/calibre || die
222 newinitd "${FILESDIR}"/calibre-server.init calibre-server
223 newconfd "${FILESDIR}"/calibre-server.conf calibre-server
227 fdo-mime_desktop_database_update
228 fdo-mime_mime_database_update