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