mail-client/thunderbird: x86 stable (bug #651862)
[gentoo.git] / mail-client / thunderbird / thunderbird-45.8.0.ebuild
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5 WANT_AUTOCONF="2.1"
6 MOZ_ESR=""
7 MOZ_LIGHTNING_VER="4.7.8"
8 MOZ_LIGHTNING_GDATA_VER="2.6"
9
10 # This list can be updated using scripts/get_langs.sh from the mozilla overlay
11 MOZ_LANGS=(ar ast be bg bn-BD br ca cs cy da de el en en-GB en-US es-AR
12 es-ES et eu fi fr fy-NL ga-IE gd gl he hr hsb hu hy-AM id is it ja ko lt
13 nb-NO nl nn-NO pa-IN pl pt-BR pt-PT rm ro ru si sk sl sq sr sv-SE ta-LK tr
14 uk vi zh-CN zh-TW )
15
16 # Convert the ebuild version to the upstream mozilla version, used by mozlinguas
17 MOZ_PV="${PV/_beta/b}"
18
19 # Patches
20 PATCH="thunderbird-38.0-patches-0.1"
21 PATCHFF="firefox-45.0-patches-12"
22
23 MOZ_HTTP_URI="https://archive.mozilla.org/pub/${PN}/releases"
24
25 # ESR releases have slightly version numbers
26 if [[ ${MOZ_ESR} == 1 ]]; then
27         MOZ_PV="${MOZ_PV}esr"
28 fi
29 MOZ_P="${PN}-${MOZ_PV}"
30
31 MOZCONFIG_OPTIONAL_JIT="enabled"
32 inherit flag-o-matic toolchain-funcs mozconfig-v6.45 autotools pax-utils check-reqs nsplugins mozlinguas-v2 xdg-utils gnome2-utils
33
34 DESCRIPTION="Thunderbird Mail Client"
35 HOMEPAGE="http://www.mozilla.com/en-US/thunderbird/"
36
37 KEYWORDS="~alpha amd64 ~arm ppc ppc64 x86 ~x86-fbsd ~amd64-linux ~x86-linux"
38 SLOT="0"
39 LICENSE="MPL-2.0 GPL-2 LGPL-2.1"
40 IUSE="bindist crypt hardened ldap lightning +minimal mozdom selinux"
41 RESTRICT="!bindist? ( bindist )"
42
43 PATCH_URIS=( https://dev.gentoo.org/~{anarchy,axs,polynomial-c}/mozilla/patchsets/{${PATCH},${PATCHFF}}.tar.xz )
44 SRC_URI="${SRC_URI}
45         ${MOZ_HTTP_URI}/${MOZ_PV}/source/${MOZ_P}.source.tar.xz
46         https://dev.gentoo.org/~axs/distfiles/lightning-${MOZ_LIGHTNING_VER}.tar.xz
47         lightning? ( https://dev.gentoo.org/~axs/distfiles/gdata-provider-${MOZ_LIGHTNING_GDATA_VER}-r1.tar.xz )
48         ${PATCH_URIS[@]}"
49
50 ASM_DEPEND=">=dev-lang/yasm-1.1"
51
52 CDEPEND="
53         >=dev-libs/nss-3.21.1
54         >=dev-libs/nspr-4.12
55         crypt? ( >=x11-plugins/enigmail-1.9.6.1-r1 )
56         "
57
58 DEPEND="${CDEPEND}
59         amd64? ( ${ASM_DEPEND}
60                 virtual/opengl )
61         x86? ( ${ASM_DEPEND}
62                 virtual/opengl )"
63
64 RDEPEND="${CDEPEND}
65         selinux? ( sec-policy/selinux-thunderbird )
66 "
67
68 S="${WORKDIR}/${MOZ_P}"
69
70 BUILD_OBJ_DIR="${S}/tbird"
71
72 pkg_setup() {
73         moz_pkgsetup
74
75         export MOZILLA_DIR="${S}/mozilla"
76
77         if ! use bindist ; then
78                 elog "You are enabling official branding. You may not redistribute this build"
79                 elog "to any users on your network or the internet. Doing so puts yourself into"
80                 elog "a legal problem with Mozilla Foundation"
81                 elog "You can disable it by emerging ${PN} _with_ the bindist USE-flag"
82                 elog
83         fi
84 }
85
86 pkg_pretend() {
87         # Ensure we have enough disk space to compile
88         CHECKREQS_DISK_BUILD="4G"
89         check-reqs_pkg_setup
90
91         if use jit && [[ -n ${PROFILE_IS_HARDENED} ]]; then
92                 ewarn "You are emerging this package on a hardened profile with USE=jit enabled."
93                 ewarn "This is horribly insecure as it disables all PAGEEXEC restrictions."
94                 ewarn "Please ensure you know what you are doing.  If you don't, please consider"
95                 ewarn "emerging the package with USE=-jit"
96         fi
97 }
98
99 src_unpack() {
100         unpack ${A}
101
102         # Unpack language packs
103         mozlinguas_src_unpack
104
105         # this version of lightning is a .tar.xz, no xpi needed
106         #xpi_unpack lightning-${MOZ_LIGHTNING_VER}.xpi
107
108         # this version of gdata-provider is a .tar.xz , no xpi needed
109         #use lightning && xpi_unpack gdata-provider-${MOZ_LIGHTNING_GDATA_VER}.xpi
110 }
111
112 src_prepare() {
113         # Apply our Thunderbird patchset
114         rm -f "${WORKDIR}"/thunderbird/2001_ldap_respect_cflags.patch
115         eapply "${WORKDIR}/thunderbird"
116
117         # Apply our patchset from firefox to thunderbird as well
118         pushd "${S}"/mozilla &>/dev/null || die
119         eapply "${WORKDIR}/firefox"
120         popd &>/dev/null || die
121
122         # Ensure that are plugins dir is enabled as default
123         sed -i -e "s:/usr/lib/mozilla/plugins:/usr/lib/nsbrowser/plugins:" \
124                 "${S}"/mozilla/xpcom/io/nsAppFileLocationProvider.cpp || die "sed failed to replace plugin path for 32bit!"
125         sed -i -e "s:/usr/lib64/mozilla/plugins:/usr/lib64/nsbrowser/plugins:" \
126                 "${S}"/mozilla/xpcom/io/nsAppFileLocationProvider.cpp || die "sed failed to replace plugin path for 64bit!"
127
128         # Don't exit with error when some libs are missing which we have in
129         # system.
130         sed '/^MOZ_PKG_FATAL_WARNINGS/s@= 1@= 0@' \
131                 -i "${S}"/mail/installer/Makefile.in || die
132
133         # Don't error out when there's no files to be removed:
134         sed 's@\(xargs rm\)$@\1 -f@' \
135                 -i "${S}"/mozilla/toolkit/mozapps/installer/packager.mk || die
136
137         # Shell scripts sometimes contain DOS line endings; bug 391889
138         grep -rlZ --include="*.sh" $'\r$' . |
139         while read -r -d $'\0' file ; do
140                 einfo edos2unix "${file}"
141                 edos2unix "${file}"
142         done
143
144         # Allow user to apply any additional patches without modifing ebuild
145         eapply_user
146
147         # Confirm the version of lightning being grabbed for langpacks is the same
148         # as that used in thunderbird
149         local THIS_MOZ_LIGHTNING_VER=$(python "${S}"/calendar/lightning/build/makeversion.py ${PV})
150         if [[ ${MOZ_LIGHTNING_VER} != ${THIS_MOZ_LIGHTNING_VER} ]]; then
151                 eqawarn "The version of lightning used for localization differs from the version"
152                 eqawarn "in thunderbird.  Please update MOZ_LIGHTNING_VER in the ebuild from ${MOZ_LIGHTNING_VER}"
153                 eqawarn "to ${THIS_MOZ_LIGHTNING_VER}"
154         fi
155
156         eautoreconf
157         # Ensure we run eautoreconf in mozilla to regenerate configure
158         cd "${S}"/mozilla || die
159         eautoconf
160         cd "${S}"/mozilla/js/src || die
161         eautoconf
162 }
163
164 src_configure() {
165         MEXTENSIONS="default"
166
167         ####################################
168         #
169         # mozconfig, CFLAGS and CXXFLAGS setup
170         #
171         ####################################
172
173         mozconfig_init
174         mozconfig_config
175
176         # It doesn't compile on alpha without this LDFLAGS
177         use alpha && append-ldflags "-Wl,--no-relax"
178
179         # Add full relro support for hardened
180         use hardened && append-ldflags "-Wl,-z,relro,-z,now"
181
182         mozconfig_annotate '' --enable-extensions="${MEXTENSIONS}"
183         mozconfig_annotate '' --disable-mailnews
184         mozconfig_annotate '' --enable-calendar
185
186         # Other tb-specific settings
187         mozconfig_annotate '' --with-user-appdir=.thunderbird
188
189         mozconfig_use_enable ldap
190
191         mozlinguas_mozconfig
192
193         # Bug #72667
194         if use mozdom; then
195                 MEXTENSIONS="${MEXTENSIONS},inspector"
196         fi
197
198         # Use an objdir to keep things organized.
199         echo "mk_add_options MOZ_OBJDIR=${BUILD_OBJ_DIR}" >> "${S}"/.mozconfig
200
201         # Finalize and report settings
202         mozconfig_final
203
204         ####################################
205         #
206         #  Configure and build
207         #
208         ####################################
209
210         # Disable no-print-directory
211         MAKEOPTS=${MAKEOPTS/--no-print-directory/}
212
213         if [[ $(gcc-major-version) -lt 4 ]]; then
214                 append-cxxflags -fno-stack-protector
215         fi
216 }
217
218 src_compile() {
219         mkdir -p "${BUILD_OBJ_DIR}" && cd "${BUILD_OBJ_DIR}" || die
220
221         CC="$(tc-getCC)" CXX="$(tc-getCXX)" LD="$(tc-getLD)" \
222         MOZ_MAKE_FLAGS="${MAKEOPTS}" SHELL="${SHELL:-${EPREFIX%/}/bin/bash}" \
223         emake -f "${S}"/client.mk
224 }
225
226 src_install() {
227         declare emid
228         cd "${BUILD_OBJ_DIR}" || die
229
230         # Copy our preference before omnijar is created.
231         cp "${FILESDIR}"/thunderbird-gentoo-default-prefs-1.js-1 \
232                 "${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" \
233                 || die
234
235         mozconfig_install_prefs \
236                 "${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js"
237
238         # dev-db/sqlite does not have FTS3_TOKENIZER support.
239         # gloda needs it to function, and bad crashes happen when its enabled and doesn't work
240         if in_iuse system-sqlite && use system-sqlite ; then
241                 echo "lockPref(\"mailnews.database.global.indexer.enabled\", false);" \
242                         >>"${BUILD_OBJ_DIR}/dist/bin/defaults/pref/all-gentoo.js" || die
243         fi
244
245         # Pax mark xpcshell for hardened support, only used for startupcache creation.
246         pax-mark m "${BUILD_OBJ_DIR}"/dist/bin/xpcshell
247
248         MOZ_MAKE_FLAGS="${MAKEOPTS}" \
249         emake DESTDIR="${D}" install
250
251         # Install language packs
252         mozlinguas_src_install
253
254         local size sizes icon_path icon
255         if ! use bindist; then
256                 icon_path="${S}/other-licenses/branding/thunderbird"
257                 icon="${PN}-icon"
258
259                 domenu "${FILESDIR}"/icon/${PN}.desktop
260         else
261                 icon_path="${S}/mail/branding/aurora"
262                 icon="${PN}-icon-unbranded"
263
264                 newmenu "${FILESDIR}"/icon/${PN}-unbranded.desktop \
265                         ${PN}.desktop
266
267                 sed -i -e "s:Mozilla\ Thunderbird:EarlyBird:g" \
268                         "${ED}"/usr/share/applications/${PN}.desktop
269         fi
270
271         # Install a 48x48 icon into /usr/share/pixmaps for legacy DEs
272         newicon "${icon_path}"/mailicon48.png "${icon}".png
273         # Install icons for menu entry
274         sizes="16 22 24 32 48 256"
275         for size in ${sizes}; do
276                 newicon -s ${size} "${icon_path}/mailicon${size}.png" "${icon}.png"
277         done
278
279         local emid
280         # stage extra locales for lightning and install over existing
281         mozlinguas_xpistage_langpacks "${BUILD_OBJ_DIR}"/dist/xpi-stage/lightning \
282                 "${WORKDIR}"/lightning-${MOZ_LIGHTNING_VER} lightning calendar
283
284         emid='{e2fda1a4-762b-4020-b5ad-a41df1933103}'
285         mkdir -p "${T}/${emid}" || die
286         cp -RLp -t "${T}/${emid}" "${BUILD_OBJ_DIR}"/dist/xpi-stage/lightning/* || die
287         insinto ${MOZILLA_FIVE_HOME}/distribution/extensions
288         doins -r "${T}/${emid}"
289
290         if use lightning; then
291                 # move lightning out of distribution/extensions and into extensions for app-global install
292                 mv "${ED}"/${MOZILLA_FIVE_HOME}/{distribution,}/extensions/${emid} || die
293
294                 # stage extra locales for gdata-provider and install app-global
295                 mozlinguas_xpistage_langpacks "${BUILD_OBJ_DIR}"/dist/xpi-stage/gdata-provider \
296                         "${WORKDIR}"/gdata-provider-${MOZ_LIGHTNING_GDATA_VER}
297                 emid='{a62ef8ec-5fdc-40c2-873c-223b8a6925cc}'
298                 mkdir -p "${T}/${emid}" || die
299                 cp -RLp -t "${T}/${emid}" "${BUILD_OBJ_DIR}"/dist/xpi-stage/gdata-provider/* || die
300                 insinto ${MOZILLA_FIVE_HOME}/extensions
301                 doins -r "${T}/${emid}"
302         fi
303
304         if use crypt ; then
305                 emid=$(sed -n '/<em:id>/!d; s/.*\({.*}\).*/\1/; p; q' "${EPREFIX}"/usr/share/enigmail/install.rdf)
306                 if [[ -n ${emid} ]]; then
307                         dosym "${EPREFIX}"/usr/share/enigmail ${MOZILLA_FIVE_HOME}/extensions/${emid}
308                 else
309                         eerror "${EPREFIX}/usr/share/enigmail/install.rdf: No such file or directory"
310                         die "<EM:ID> tag for installed enigmail could not be found!"
311                 fi
312         fi
313
314         # Required in order for jit to work on hardened, for mozilla-31 and above
315         use jit && pax-mark pm "${ED}"${MOZILLA_FIVE_HOME}/{thunderbird,thunderbird-bin}
316
317         # Plugin-container needs to be pax-marked for hardened to ensure plugins such as flash
318         # continue to work as expected.
319         pax-mark m "${ED}"${MOZILLA_FIVE_HOME}/plugin-container
320
321         if use minimal; then
322                 rm -r "${ED}"/usr/include "${ED}"${MOZILLA_FIVE_HOME}/{idl,include,lib,sdk} || \
323                         die "Failed to remove sdk and headers"
324         fi
325 }
326
327 pkg_preinst() {
328         gnome2_icon_savelist
329
330         # Because PM's dont seem to properly merge a symlink replacing a directory
331         if use crypt ; then
332                 local emid=$(sed -n '/<em:id>/!d; s/.*\({.*}\).*/\1/; p; q' "${EPREFIX}"/usr/share/enigmail/install.rdf)
333                 if [[ -z ${emid} ]]; then
334                         eerror "${EPREFIX}/usr/share/enigmail/install.rdf: No such file or directory"
335                         die "Could not find enigmail on disk during pkg_preinst()"
336                 fi
337                 if [[ ! -h "${EPREFIX}${MOZILLA_FIVE_HOME}/extensions/${emid}" ]] && \
338                    [[ -d "${EPREFIX}${MOZILLA_FIVE_HOME}/extensions/${emid}" ]]; then
339                         rm -Rf "${EPREFIX}${MOZILLA_FIVE_HOME}/extensions/${emid}" || (
340                         eerror "Could not remove enigmail directory from previous installation,"
341                         eerror "You must remove this by hand and rename the symbolic link yourself:"
342                         eerror
343                         eerror "\t cd ${EPREFIX}${MOZILLA_FIVE_HOME}/extensions"
344                         eerror "\t rm -Rf ${emid}"
345                         eerror "\t mv ${emid}.backup* ${emid}" )
346                 fi
347         fi
348 }
349
350 pkg_postinst() {
351         xdg_desktop_database_update
352         gnome2_icon_cache_update
353
354         elog "If you experience problems with plugins please issue the"
355         elog "following command : rm \${HOME}/.thunderbird/*/extensions.sqlite ,"
356         elog "then restart thunderbird"
357         if ! use lightning; then
358                 elog
359                 elog "If calendar fails to show up in extensions please open config editor"
360                 elog "and set extensions.lastAppVersion to 38.0.0 to force a reload. If this"
361                 elog "fails to show the calendar extension after restarting with above change"
362                 elog "please file a bug report."
363         fi
364 }
365
366 pkg_postrm() {
367         xdg_desktop_database_update
368         gnome2_icon_cache_update
369 }