1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 inherit eutils fdo-mime bash-completion-r1 multilib toolchain-funcs
9 DESCRIPTION="Ebook management application"
10 HOMEPAGE="http://calibre-ebook.com/"
11 [[ ${PV} == ${PV%.*}.${PV#*.} ]] && MY_PV=${PV}.0 || MY_PV=${PV}
12 SRC_URI="http://sourceforge.net/projects/calibre/files/${MY_PV}/${PN}-${MY_PV}.tar.xz"
28 || ( Artistic GPL-1+ )
35 KEYWORDS="~amd64 ~arm ~x86"
40 >=app-text/podofo-0.8.2:=
41 >=app-text/poppler-0.20.2:=[qt4,xpdf-headers(+)]
42 >=dev-lang/python-2.7.1:2.7[sqlite,ssl]
43 >=dev-libs/chmlib-0.40:=
45 >=dev-python/apsw-3.7.17[python_targets_python2_7(-)]
46 >=dev-python/beautifulsoup-3.0.5:python-2[python_targets_python2_7(-)]
47 dev-python/netifaces[python_targets_python2_7(-)]
48 >=dev-python/dnspython-1.6.0:0[python_targets_python2_7(-)]
49 >=dev-python/cssselect-0.7.1[python_targets_python2_7(-)]
50 >=dev-python/cssutils-0.9.9[python_targets_python2_7(-)]
51 >=dev-python/dbus-python-0.82.2[python_targets_python2_7(-)]
52 >=dev-python/lxml-3.2.1[python_targets_python2_7(-)]
53 >=dev-python/mechanize-0.1.11[python_targets_python2_7(-)]
54 >=dev-python/python-dateutil-1.4.1[python_targets_python2_7(-)]
55 >=dev-python/PyQt4-4.9.6[X,svg,webkit,python_targets_python2_7(-)]
58 media-fonts/liberation-fonts
59 >=media-gfx/imagemagick-6.5.9[jpeg,png]
60 >=media-libs/freetype-2:=
61 >=media-libs/libwmf-0.2.8
62 >=media-libs/libmtp-1.1.5:=
64 virtual/python-imaging[python_targets_python2_7(-)]
65 >=x11-misc/xdg-utils-1.0.2-r2"
67 RDEPEND="${COMMON_DEPEND}
68 udisks? ( || ( sys-fs/udisks:2 sys-fs/udisks:0 ) )"
70 DEPEND="${COMMON_DEPEND}
71 >=dev-python/setuptools-0.6_rc5
72 >=virtual/podofo-build-0.8.2"
77 # Fix outdated version constant.
78 #sed -e "s#\\(^numeric_version =\\).*#\\1 (${PV//./, })#" \
79 # -i src/calibre/constants.py || \
80 # die "sed failed to patch constants.py"
82 # Avoid sandbox violation in /usr/share/gnome/apps when linux.py
83 # calls xdg-* (bug #258938).
84 sed -e "s|'xdg-desktop-menu', 'install'|\\0, '--mode', 'user'|" \
85 -e "s|check_call(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
86 -e "s|\\(CurrentDir(tdir)\\), \\\\\$|\\1:|" \
87 -e "s|PreserveMIMEDefaults():||" \
88 -e "s|xdg-icon-resource install|\\0 --mode user|" \
89 -e "s|cc(\\['xdg-desktop-menu', 'forceupdate'\\])|#\\0|" \
90 -e "s|'xdg-mime', 'install'|\\0, '--mode', 'user'|" \
91 -i src/calibre/linux.py || die "sed failed to patch linux.py"
93 # Disable unnecessary privilege dropping for bug #287067.
94 sed -e "s:if os.geteuid() == 0:if False and os.geteuid() == 0:" \
95 -i setup/install.py || die "sed failed to patch install.py"
97 sed -e "/^ self\\.check_call(qmc + \\[.*\\.pro'\\])$/a\
98 \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ self.check_call(['sed', \
99 '-e', 's|^CFLAGS .*|\\\\\\\\0 ${CFLAGS}|', \
100 '-e', 's|^CXXFLAGS .*|\\\\\\\\0 ${CXXFLAGS}|', \
101 '-e', 's|^LFLAGS .*|\\\\\\\\0 ${LDFLAGS}|', \
102 '-i', 'Makefile'])" \
103 -i setup/extensions.py || die "sed failed to patch extensions.py"
105 # use system beautifulsoup, instead of bundled
106 rm -f "${S}"/src/calibre/ebooks/BeautifulSoup.py || die "could not remove bundled beautifulsoup"
107 find "${S}" -type f -name \*.py -exec \
108 sed -e 's/calibre.ebooks.BeautifulSoup/BeautifulSoup/' -i {} + \
109 || die "could not sed bundled beautifulsoup out of the source tree"
111 # no_updates: do not annoy user with "new version is availible all the time
112 # disable_plugins: walking sec-hole, wait for upstream to use GHNS interface
113 # C locale: if LC_ALL=C do not raise an exception when locale cannot be canonicalized
115 "${FILESDIR}/${PN}-1.34-no_updates_dialog.patch" \
116 "${FILESDIR}/${PN}-disable_plugins.patch"
118 # override install path for bash-completions
119 local mybcd="${D}/$(get_bashcompdir)"
120 sed -e "s#^def \(get_bash_completion_path.*\)\$#def \1\n return os.path.join('${mybcd}','calibre')\n\ndef old_\1#" \
121 -i "${S}"/src/calibre/linux.py || die "Could not fix bash-completions install path"
125 # Bypass kbuildsycoca and update-mime-database in order to
126 # avoid sandbox violations if xdg-mime tries to call them.
127 cat - > "${T}/kbuildsycoca" <<-EOF
132 cp "${T}"/{kbuildsycoca,update-mime-database}
133 chmod +x "${T}"/{kbuildsycoca,update-mime-database}
135 # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
136 # violation with kbuildsycoca as in bug #287067, comment #13.
139 # Bug #352625 - Some LANGUAGE values can trigger the following ValueError:
140 # File "/usr/lib/python2.6/locale.py", line 486, in getdefaultlocale
141 # return _parse_localename(localename)
142 # File "/usr/lib/python2.6/locale.py", line 418, in _parse_localename
143 # raise ValueError, 'unknown locale: %s' % localename
144 #ValueError: unknown locale: 46
147 # Bug #295672 - Avoid sandbox violation in ~/.config by forcing
148 # variables to point to our fake temporary $HOME.
149 export HOME="${T}/fake_homedir"
150 export XDG_CONFIG_HOME="${HOME}/.config"
151 export XDG_DATA_HOME="${HOME}/.local/share"
152 export CALIBRE_CONFIG_DIRECTORY="${XDG_CONFIG_HOME}/calibre"
153 mkdir -p "${XDG_CONFIG_HOME}" "${CALIBRE_CONFIG_DIRECTORY}"
156 # Bug #334243 - respect LDFLAGS when building extensions
157 export OVERRIDE_CFLAGS="$CFLAGS" OVERRIDE_LDFLAGS="$LDFLAGS"
158 local libdir=$(get_libdir)
159 [[ -n $libdir ]] || die "get_libdir returned an empty string"
161 # Bug #472690 - Avoid sandbox violation for /dev/dri/card0.
163 for x in /dev/dri/card[0-9] ; do
164 [[ -e ${x} ]] && addpredict ${x}
167 dodir "/usr/$(get_libdir)/python2.7/site-packages" # for init_calibre.py
168 PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
169 "${EPREFIX}"/usr/bin/python2.7 setup.py install \
171 --prefix="${EPREFIX}/usr" \
172 --libdir="${EPREFIX}/usr/${libdir}" \
173 --staging-root="${ED}usr" \
174 --staging-libdir="${ED}usr/${libdir}" || die
176 grep -rlZ "${ED}" "${ED}" | xargs -0 sed -e "s:${D}:/:g" -i ||
177 die "failed to fix harcoded \$D in paths"
179 # The menu entries end up here due to '--mode user' being added to
180 # xdg-* options in src_prepare.
181 dodir /usr/share/mime/packages
182 chmod -fR a+rX,u+w,g-w,o-w "${HOME}"/.local
183 mv "${HOME}"/.local/share/mime/packages/* "${ED}"usr/share/mime/packages/ ||
184 die "failed to register mime types"
185 dodir /usr/share/icons
186 mv "${HOME}"/.local/share/icons/* "${ED}"usr/share/icons/ ||
187 die "failed to install icon files"
189 domenu "${HOME}"/.local/share/applications/*.desktop ||
190 die "failed to install .desktop menu files"
192 # dobashcomp "${ED}"usr/share/bash-completion/completions/calibre
193 # rm -r "${ED}"usr/share/bash-completion
194 find "${ED}"usr/share -type d -empty -delete
196 cd "${ED}"/usr/share/calibre/fonts/liberation || die
199 [[ -f ${EROOT}usr/share/fonts/liberation-fonts/${x} ]] || continue
200 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
203 einfo "Converting python shebangs"
204 while read -r -d $'\0' ; do
205 local shebang=$(head -n1 "$REPLY")
206 if [[ ${shebang} == "#!"*python* ]] ; then
207 sed -i -e "1s:.*:#!${EPREFIX}/usr/bin/python2.7:" "$REPLY" || \
210 done < <(find "${ED}" -type f -print0)
212 einfo "Compiling python modules"
213 "${EPREFIX}"/usr/bin/python2.7 -m compileall -q -f \
214 -d "${EPREFIX}"/usr/lib/calibre "${ED}"usr/lib/calibre || die
216 newinitd "${FILESDIR}"/calibre-server.init calibre-server
217 newconfd "${FILESDIR}"/calibre-server.conf calibre-server
221 fdo-mime_desktop_database_update
222 fdo-mime_mime_database_update