1#!/usr/bin/env bash
2
3echo "Downloading Expat"
4if ! curl -L -k -s -o expat-2.2.9.tar.gz https://github.com/libexpat/libexpat/releases/download/R_2_2_9/expat-2.2.9.tar.gz;
5then
6    echo "Failed to download Expat"
7    exit 1
8fi
9
10echo "Unpacking Expat"
11rm -rf ./expat-2.2.9
12if ! tar -xf expat-2.2.9.tar.gz;
13then
14    echo "Failed to unpack Expat"
15    exit 1
16fi
17
18cd expat-2.2.9 || exit 1
19
20echo "Configuring Expat"
21if ! ./configure --build="$AUTOTOOLS_BUILD" --host="$AUTOTOOLS_HOST" --prefix="$ANDROID_PREFIX"; then
22    echo "Error: Failed to configure Expat"
23    exit 1
24fi
25
26# Cleanup warnings, https://github.com/libexpat/libexpat/issues/383
27echo "Fixing Makefiles"
28(IFS="" find "$PWD" -name 'Makefile' -print | while read -r file
29do
30    cp -p "$file" "$file.fixed"
31    sed 's|-Wduplicated-cond ||g; s|-Wduplicated-branches ||g; s|-Wlogical-op ||g' "$file" > "$file.fixed"
32    mv "$file.fixed" "$file"
33
34    cp -p "$file" "$file.fixed"
35    sed 's|-Wrestrict ||g; s|-Wjump-misses-init ||g; s|-Wmisleading-indentation ||g' "$file" > "$file.fixed"
36    mv "$file.fixed" "$file"
37done)
38
39echo "Building Expat"
40if ! make; then
41    echo "Failed to build Expat"
42    exit 1
43fi
44
45echo "Installing Expat"
46if ! make install; then
47    echo "Failed to install Expat"
48    exit 1
49fi
50
51exit 0
52