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+ )
40 >=app-text/podofo-0.8.2:=
41 >=app-text/poppler-0.12.3-r3:=[qt4,xpdf-headers(+)]
42 >=dev-lang/python-2.7.1:2.7[sqlite,ssl]
43 >=dev-libs/chmlib-0.40:=
46 >=dev-python/beautifulsoup-3.0.5:python-2
48 >=dev-python/dnspython-1.6.0:0
49 >=dev-python/cssselect-0.7.1
50 >=dev-python/cssutils-0.9.9
51 >=dev-python/dbus-python-0.82.2
52 virtual/python-imaging
53 >=dev-python/lxml-2.2.1
54 >=dev-python/mechanize-0.1.11
55 >=dev-python/python-dateutil-1.4.1[python_targets_python2_7(-)]
56 >=dev-python/PyQt4-4.9.1[X,svg,webkit]
57 media-fonts/liberation-fonts
58 >=media-gfx/imagemagick-6.5.9[jpeg,png]
59 >=media-libs/freetype-2:=
60 >=media-libs/libwmf-0.2.8
61 >=media-libs/libmtp-1.1.4:=
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 # no_updates: do not annoy user with "new version is availible all the time
106 # disable_plugins: walking sec-hole, wait for upstream to use GHNS interface
108 "${FILESDIR}/${PN}-1.20-no_updates_dialog.patch" \
109 "${FILESDIR}/${PN}-disable_plugins.patch"
113 # Bypass kbuildsycoca and update-mime-database in order to
114 # avoid sandbox violations if xdg-mime tries to call them.
115 cat - > "${T}/kbuildsycoca" <<-EOF
120 cp "${T}"/{kbuildsycoca,update-mime-database}
121 chmod +x "${T}"/{kbuildsycoca,update-mime-database}
123 # Unset DISPLAY in order to prevent xdg-mime from triggering a sandbox
124 # violation with kbuildsycoca as in bug #287067, comment #13.
127 # Bug #352625 - Some LANGUAGE values can trigger the following ValueError:
128 # File "/usr/lib/python2.6/locale.py", line 486, in getdefaultlocale
129 # return _parse_localename(localename)
130 # File "/usr/lib/python2.6/locale.py", line 418, in _parse_localename
131 # raise ValueError, 'unknown locale: %s' % localename
132 #ValueError: unknown locale: 46
135 # Bug #295672 - Avoid sandbox violation in ~/.config by forcing
136 # variables to point to our fake temporary $HOME.
137 export HOME="${T}/fake_homedir"
138 export XDG_CONFIG_HOME="${HOME}/.config"
139 export XDG_DATA_HOME="${HOME}/.local/share"
140 export CALIBRE_CONFIG_DIRECTORY="${XDG_CONFIG_HOME}/calibre"
141 mkdir -p "${XDG_CONFIG_HOME}" "${CALIBRE_CONFIG_DIRECTORY}"
144 # Bug #334243 - respect LDFLAGS when building extensions
145 export OVERRIDE_CFLAGS="$CFLAGS" OVERRIDE_LDFLAGS="$LDFLAGS"
146 local libdir=$(get_libdir)
147 [[ -n $libdir ]] || die "get_libdir returned an empty string"
149 # Bug #472690 - Avoid sandbox violation for /dev/dri/card0.
151 for x in /dev/dri/card[0-9] ; do
152 [[ -e ${x} ]] && addpredict ${x}
155 dodir "/usr/$(get_libdir)/python2.7/site-packages" # for init_calibre.py
156 PATH=${T}:${PATH} PYTHONPATH=${S}/src${PYTHONPATH:+:}${PYTHONPATH} \
157 "${EPREFIX}"/usr/bin/python2.7 setup.py install \
159 --prefix="${EPREFIX}/usr" \
160 --libdir="${EPREFIX}/usr/${libdir}" \
161 --staging-root="${ED}usr" \
162 --staging-libdir="${ED}usr/${libdir}" || die
164 grep -rlZ "${ED}" "${ED}" | xargs -0 sed -e "s:${D}:/:g" -i ||
165 die "failed to fix harcoded \$D in paths"
167 # The menu entries end up here due to '--mode user' being added to
168 # xdg-* options in src_prepare.
169 dodir /usr/share/mime/packages
170 chmod -fR a+rX,u+w,g-w,o-w "${HOME}"/.local
171 mv "${HOME}"/.local/share/mime/packages/* "${ED}"usr/share/mime/packages/ ||
172 die "failed to register mime types"
173 dodir /usr/share/icons
174 mv "${HOME}"/.local/share/icons/* "${ED}"usr/share/icons/ ||
175 die "failed to install icon files"
177 domenu "${HOME}"/.local/share/applications/*.desktop ||
178 die "failed to install .desktop menu files"
180 dobashcomp "${ED}"usr/etc/bash_completion.d/calibre
181 rm -r "${ED}"usr/etc/bash_completion.d
182 find "${ED}"usr/etc -type d -empty -delete
184 cd "${ED}"/usr/share/calibre/fonts/liberation || die
187 [[ -f ${EROOT}usr/share/fonts/liberation-fonts/${x} ]] || continue
188 ln -sf "../../../fonts/liberation-fonts/${x}" "${x}" || die
191 einfo "Converting python shebangs"
192 while read -r -d $'\0' ; do
193 local shebang=$(head -n1 "$REPLY")
194 if [[ ${shebang} == "#!"*python* ]] ; then
195 sed -i -e "1s:.*:#!${EPREFIX}/usr/bin/python2.7:" "$REPLY" || \
198 done < <(find "${ED}" -type f -print0)
200 einfo "Compiling python modules"
201 "${EPREFIX}"/usr/bin/python2.7 -m compileall -q -f \
202 -d "${EPREFIX}"/usr/lib/calibre "${ED}"usr/lib/calibre || die
204 newinitd "${FILESDIR}"/calibre-server.init calibre-server
205 newconfd "${FILESDIR}"/calibre-server.conf calibre-server
209 fdo-mime_desktop_database_update
210 fdo-mime_mime_database_update