dev-libs/libxml2: x86 stable wrt bug #701020
[gentoo.git] / dev-libs / libxml2 / libxml2-2.9.9-r3.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=6
5
6 PYTHON_COMPAT=( python2_7 python3_{5,6,7,8} )
7 PYTHON_REQ_USE="xml"
8
9 inherit libtool flag-o-matic python-r1 autotools prefix multilib-minimal
10
11 DESCRIPTION="XML C parser and toolkit"
12 HOMEPAGE="http://www.xmlsoft.org/"
13
14 LICENSE="MIT"
15 SLOT="2"
16 KEYWORDS="~alpha amd64 ~arm arm64 ~hppa ia64 ~m68k ~mips ppc ppc64 ~riscv s390 ~sh sparc x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
17 IUSE="debug examples icu ipv6 lzma python readline static-libs test"
18 REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
19 RESTRICT="!test? ( test )"
20
21 XSTS_HOME="http://www.w3.org/XML/2004/xml-schema-test-suite"
22 XSTS_NAME_1="xmlschema2002-01-16"
23 XSTS_NAME_2="xmlschema2004-01-14"
24 XSTS_TARBALL_1="xsts-2002-01-16.tar.gz"
25 XSTS_TARBALL_2="xsts-2004-01-14.tar.gz"
26 XMLCONF_TARBALL="xmlts20080827.tar.gz"
27
28 SRC_URI="ftp://xmlsoft.org/${PN}/${PN}-${PV/_rc/-rc}.tar.gz
29         https://dev.gentoo.org/~leio/distfiles/${P}-patchset.tar.xz
30         test? (
31                 ${XSTS_HOME}/${XSTS_NAME_1}/${XSTS_TARBALL_1}
32                 ${XSTS_HOME}/${XSTS_NAME_2}/${XSTS_TARBALL_2}
33                 http://www.w3.org/XML/Test/${XMLCONF_TARBALL} )"
34
35 RDEPEND="
36         >=sys-libs/zlib-1.2.8-r1:=[${MULTILIB_USEDEP}]
37         icu? ( >=dev-libs/icu-51.2-r1:=[${MULTILIB_USEDEP}] )
38         lzma? ( >=app-arch/xz-utils-5.0.5-r1:=[${MULTILIB_USEDEP}] )
39         python? ( ${PYTHON_DEPS} )
40         readline? ( sys-libs/readline:= )
41 "
42 DEPEND="${RDEPEND}
43         dev-util/gtk-doc-am
44         virtual/pkgconfig
45         hppa? ( >=sys-devel/binutils-2.15.92.0.2 )
46 "
47
48 S="${WORKDIR}/${PN}-${PV%_rc*}"
49
50 MULTILIB_CHOST_TOOLS=(
51         /usr/bin/xml2-config
52 )
53
54 src_unpack() {
55         # ${A} isn't used to avoid unpacking of test tarballs into $WORKDIR,
56         # as they are needed as tarballs in ${S}/xstc instead and not unpacked
57         unpack ${P/_rc/-rc}.tar.gz
58         unpack ${P}-patchset.tar.xz
59         cd "${S}" || die
60
61         if use test; then
62                 cp "${DISTDIR}/${XSTS_TARBALL_1}" \
63                         "${DISTDIR}/${XSTS_TARBALL_2}" \
64                         "${S}"/xstc/ \
65                         || die "Failed to install test tarballs"
66                 unpack ${XMLCONF_TARBALL}
67         fi
68 }
69
70 src_prepare() {
71         default
72
73         DOCS=( AUTHORS ChangeLog NEWS README* TODO* )
74
75         # Selective cherry-picks from master up to 2019-02-28 (commit 8161b463f5)
76         eapply "${WORKDIR}"/patches
77
78         # Patches needed for prefix support
79         eapply "${FILESDIR}"/${PN}-2.7.1-catalog_path.patch
80
81         eprefixify catalog.c xmlcatalog.c runtest.c xmllint.c
82
83         # Fix build for Windows platform
84         # https://bugzilla.gnome.org/show_bug.cgi?id=760456
85         # eapply "${FILESDIR}"/${PN}-2.8.0_rc1-winnt.patch
86
87         # Fix python detection, bug #567066
88         # https://bugzilla.gnome.org/show_bug.cgi?id=760458
89         eapply "${FILESDIR}"/${PN}-2.9.2-python-ABIFLAG.patch
90
91         # Fix python tests when building out of tree #565576
92         eapply "${FILESDIR}"/${PN}-2.9.8-out-of-tree-test.patch
93
94         # Workaround python3 itstool potential problems, bug 701020
95         eapply "${FILESDIR}"/${PV}-python3-unicode-errors.patch
96
97         if [[ ${CHOST} == *-darwin* ]] ; then
98                 # Avoid final linking arguments for python modules
99                 sed -i -e '/PYTHON_LIBS/s/ldflags/libs/' configure.ac || die
100                 # gcc-apple doesn't grok -Wno-array-bounds
101                 sed -i -e 's/-Wno-array-bounds//' configure.ac || die
102         fi
103
104         # Please do not remove, as else we get references to PORTAGE_TMPDIR
105         # in /usr/lib/python?.?/site-packages/libxml2mod.la among things.
106         # We now need to run eautoreconf at the end to prevent maintainer mode.
107 #       elibtoolize
108 #       epunt_cxx # if we don't eautoreconf
109
110         eautoreconf
111 }
112
113 multilib_src_configure() {
114         # filter seemingly problematic CFLAGS (#26320)
115         filter-flags -fprefetch-loop-arrays -funroll-loops
116
117         # USE zlib support breaks gnome2
118         # (libgnomeprint for instance fails to compile with
119         # fresh install, and existing) - <azarah@gentoo.org> (22 Dec 2002).
120
121         # The meaning of the 'debug' USE flag does not apply to the --with-debug
122         # switch (enabling the libxml2 debug module). See bug #100898.
123
124         # --with-mem-debug causes unusual segmentation faults (bug #105120).
125
126         libxml2_configure() {
127                 ECONF_SOURCE="${S}" econf \
128                         --with-html-subdir=${PF}/html \
129                         $(use_with debug run-debug) \
130                         $(use_with icu) \
131                         $(use_with lzma) \
132                         $(use_enable ipv6) \
133                         $(use_enable static-libs static) \
134                         $(multilib_native_use_with readline) \
135                         $(multilib_native_use_with readline history) \
136                         "$@"
137         }
138
139         libxml2_py_configure() {
140                 mkdir -p "${BUILD_DIR}" || die # ensure python build dirs exist
141                 run_in_build_dir libxml2_configure \
142                         "--with-python=${EPYTHON}" \
143                         "--with-python-install-dir=$(python_get_sitedir)"
144                         # odd build system, also see bug #582130
145         }
146
147         libxml2_configure --without-python # build python bindings separately
148
149         if multilib_is_native_abi && use python; then
150                 python_foreach_impl libxml2_py_configure
151         fi
152 }
153
154 multilib_src_compile() {
155         default
156         if multilib_is_native_abi && use python; then
157                 local native_builddir=${BUILD_DIR}
158                 python_foreach_impl libxml2_py_emake top_builddir="${native_builddir}" all
159         fi
160 }
161
162 multilib_src_test() {
163         ln -s "${S}"/xmlconf || die
164         emake check
165         multilib_is_native_abi && use python && python_foreach_impl libxml2_py_emake test
166 }
167
168 multilib_src_install() {
169         emake DESTDIR="${D}" \
170                 EXAMPLES_DIR="${EPREFIX}"/usr/share/doc/${PF}/examples install
171
172         if multilib_is_native_abi && use python; then
173                 python_foreach_impl libxml2_py_emake \
174                         DESTDIR="${D}" \
175                         docsdir="${EPREFIX}"/usr/share/doc/${PF}/python \
176                         exampledir="${EPREFIX}"/usr/share/doc/${PF}/python/examples \
177                         install
178                 python_foreach_impl python_optimize
179         fi
180 }
181
182 multilib_src_install_all() {
183         # on windows, xmllint is installed by interix libxml2 in parent prefix.
184         # this is the version to use. the native winnt version does not support
185         # symlinks, which makes repoman fail if the portage tree is linked in
186         # from another location (which is my default). -- mduft
187         if [[ ${CHOST} == *-winnt* ]]; then
188                 rm -rf "${ED}"/usr/bin/xmllint
189                 rm -rf "${ED}"/usr/bin/xmlcatalog
190         fi
191
192         rm -rf "${ED}"/usr/share/doc/${P}
193         einstalldocs
194
195         if ! use examples; then
196                 rm -rf "${ED}"/usr/share/doc/${PF}/examples
197                 rm -rf "${ED}"/usr/share/doc/${PF}/python/examples
198         fi
199
200         find "${D}" -name '*.la' -delete || die
201 }
202
203 pkg_postinst() {
204         # We don't want to do the xmlcatalog during stage1, as xmlcatalog will not
205         # be in / and stage1 builds to ROOT=/tmp/stage1root. This fixes bug #208887.
206         if [[ "${ROOT}" != "/" ]]; then
207                 elog "Skipping XML catalog creation for stage building (bug #208887)."
208         else
209                 # need an XML catalog, so no-one writes to a non-existent one
210                 CATALOG="${EROOT}etc/xml/catalog"
211
212                 # we dont want to clobber an existing catalog though,
213                 # only ensure that one is there
214                 # <obz@gentoo.org>
215                 if [[ ! -e ${CATALOG} ]]; then
216                         [[ -d "${EROOT}etc/xml" ]] || mkdir -p "${EROOT}etc/xml"
217                         "${EPREFIX}"/usr/bin/xmlcatalog --create > "${CATALOG}"
218                         einfo "Created XML catalog in ${CATALOG}"
219                 fi
220         fi
221 }
222
223 libxml2_py_emake() {
224         pushd "${BUILD_DIR}/python" > /dev/null || die
225         emake "$@"
226         popd > /dev/null
227 }