# Exit on error:
set -e

wget ftp://xmlsoft.org/libxml2/libxml2-2.9.1.tar.gz
tar xf libxml2-2.9.1.tar.gz
cd libxml2-2.9.1

CC=/static/bin/musl-gcc \
    LDFLAGS='-s -L/static/lib -static -static-libgcc' \
    ./configure --prefix=/static \
    --without-python

# From: https://github.com/openwrt/packages/commit/ \
# dd538b6e0233794bf5c0171e37ef449ff6198c9f

sed -e '50s/ifdef __GNUC__/if defined(__GNUC__) \&\& defined(__GLIBC__)/' \
    -e '92s/__GNUC__/defined(__GNUC__) \&\& defined(__GLIBC__)/' \
    -i.orig threads.c

make
make install
cd ..
rm -rf libxml2-2.9.1
rm libxml2-2.9.1.tar.gz

exit 0
