Initial commit: source archives + unpack-sources.sh
diff --git a/archive/SDL-1.2.15.tar.gz b/archive/SDL-1.2.15.tar.gz
new file mode 100644
index 0000000..b891501
--- /dev/null
+++ b/archive/SDL-1.2.15.tar.gz
Binary files differ
diff --git a/archive/expat-2.1.0.tar.gz b/archive/expat-2.1.0.tar.gz
new file mode 100644
index 0000000..a791223
--- /dev/null
+++ b/archive/expat-2.1.0.tar.gz
Binary files differ
diff --git a/archive/gettext-0.19.1.tar.xz b/archive/gettext-0.19.1.tar.xz
new file mode 100644
index 0000000..5e1798b
--- /dev/null
+++ b/archive/gettext-0.19.1.tar.xz
Binary files differ
diff --git a/archive/glib-2.41.0.tar.xz b/archive/glib-2.41.0.tar.xz
new file mode 100644
index 0000000..823a0c3
--- /dev/null
+++ b/archive/glib-2.41.0.tar.xz
Binary files differ
diff --git a/archive/libffi-3.1.tar.gz b/archive/libffi-3.1.tar.gz
new file mode 100644
index 0000000..fed33dc
--- /dev/null
+++ b/archive/libffi-3.1.tar.gz
Binary files differ
diff --git a/archive/libiconv-1.14.tar.gz b/archive/libiconv-1.14.tar.gz
new file mode 100644
index 0000000..3d59bb9
--- /dev/null
+++ b/archive/libiconv-1.14.tar.gz
Binary files differ
diff --git a/archive/libpng-1.6.12.tar.xz b/archive/libpng-1.6.12.tar.xz
new file mode 100644
index 0000000..07a6bd7
--- /dev/null
+++ b/archive/libpng-1.6.12.tar.xz
Binary files differ
diff --git a/archive/pixman-0.32.4.tar.gz b/archive/pixman-0.32.4.tar.gz
new file mode 100644
index 0000000..b114dc7
--- /dev/null
+++ b/archive/pixman-0.32.4.tar.gz
Binary files differ
diff --git a/archive/zlib-1.2.8.tar.gz b/archive/zlib-1.2.8.tar.gz
new file mode 100644
index 0000000..ed88885
--- /dev/null
+++ b/archive/zlib-1.2.8.tar.gz
Binary files differ
diff --git a/scripts/build-defaults.shi b/scripts/build-defaults.shi
new file mode 100644
index 0000000..8f02edb
--- /dev/null
+++ b/scripts/build-defaults.shi
@@ -0,0 +1,12 @@
+# Default values for all build scripts.
+
+SOURCES_PACKAGES="\
+zlib-1.2.8.tar.gz \
+libpng-1.6.12.tar.xz \
+libffi-3.1.tar.gz \
+gettext-0.19.1.tar.xz \
+glib-2.41.0.tar.xz \
+expat-2.1.0.tar.gz \
+pixman-0.32.4.tar.gz \
+SDL-1.2.15.tar.gz \
+"
diff --git a/scripts/build-zlib.sh b/scripts/build-zlib.sh
new file mode 100755
index 0000000..92981ef
--- /dev/null
+++ b/scripts/build-zlib.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+. $(dirname "$0")/common.shi
+
+shell_import build-defaults.shi
+
+usage () {
+    cat <<EOF
+Usage: $(program_name) [options] <src-directory>
+
+Valid options:
+    --help, -?          Print this message.
+    --verbose           Increment verbosity.
+    --quiet             Decrement verbosity.
+    --prefix=<path>     Installation path prefix [/usr/local].
+EOF
\ No newline at end of file
diff --git a/scripts/common.shi b/scripts/common.shi
new file mode 100644
index 0000000..21676ce
--- /dev/null
+++ b/scripts/common.shi
@@ -0,0 +1,123 @@
+# Common routines - do not execute directly.
+
+# Sanitize environment
+set -e
+export LANG=C
+export LC_ALL=C
+
+_SHU_PROGDIR=$(dirname "$0")
+_SHU_PROGNAME=$(basename "$0")
+
+# Print an error message to stderr then exit the current process.
+panic () {
+    echo "ERROR: $@" >&2
+    exit 1
+}
+
+# Internal verbosity level. Note that this value is inherited from
+# the VERBOSE environment variable.
+_SHU_VERBOSE=${VERBOSE:-1}
+
+# Increment internal verbosity level.
+increment_verbosity () {
+    _SHU_VERBOSE=$(( $_SHU_VERBOSE + 1 ))
+}
+
+# Decrement internal verbosity level.
+decrement_verbosity () {
+    _SHU_VERBOSE=$(( $_SHU_VERBOSE - 1 ))
+}
+
+# Return internal verbosity level, clamped to 0 as a minimum bound.
+get_verbosity () {
+    local RET=$_SHU_VERBOSE
+    if [ "$RET" -lt 0 ]; then
+        RET=0
+    fi
+    echo "$RET"
+}
+
+# Used internally to conditionally print a message.
+# $1: message's verbosity level. If greater or equal than $_SHU_VERBOSE then
+#     the message will be ignored.
+# $2+: message to print to stdout.
+dump_n () {
+    local LEVEL=$1
+    shift
+    if [ "$LEVEL" -lt "$_SHU_VERBOSE" ]; then
+        printf "%s\n" "$@"
+    fi
+}
+
+# Dump a message to standard output.
+dump () {
+    dump_n 0 "$@"
+}
+
+# Dump a message to standard output if --verbose was used.
+log () {
+    dump_n 1 "$@"
+}
+
+# Dump a message to standard output if --verbose --verbose is used.
+log2 () {
+    dump_n 2 "$@"
+}
+
+# Run a command, output depends on verbosity level
+run () {
+    local VERBOSE=$_SHU_VERBOSE
+    if [ "$VERBOSE" -lt 0 ]; then
+        VERBOSE=0
+    fi
+    if [ "$VERBOSE" -gt 1 ]; then
+        echo "COMMAND: $@"
+    fi
+    case $VERBOSE in
+        0)
+             "$@" >/dev/null >&2
+             ;;
+        1)
+            "$@" >/dev/null
+            ;;
+        *)
+            "$@"
+            ;;
+    esac
+}
+
+program_directory () {
+    printf "%s" "$_SHU_PROGDIR"
+}
+
+program_name () {
+    printf "%s" "$_SHU_PROGNAME"
+}
+
+
+# Unpack a given archive into a given destination directory.
+# $1: Archive path
+# $2: Destination directory
+unpack_archive () {
+    local PKG_PATH="$1"
+    local DEST_DIR="$2"
+    case $PKG in
+        *.tar.gz|*.tar.bz2|*.tar.xz)
+            run tar xf "$PKG_PATH" -C "$DEST_DIR"
+            ;;
+        *.zip)
+            run unzip -q -o -d "$DEST_DIR" "$PKG_PATH"
+            ;;
+        *)
+            panic "Unsupported package format: $PKG_PATH"
+            ;;
+    esac
+}
+
+shell_import () {
+    local SCRIPT="$_SHU_PROGDIR/$1"
+    if [ ! -f "$SCRIPT" ]; then
+        panic "Missing script: $SCRIPT"
+    fi
+    . "$SCRIPT"
+}
diff --git a/scripts/unpack-sources.sh b/scripts/unpack-sources.sh
new file mode 100755
index 0000000..28d0eb0
--- /dev/null
+++ b/scripts/unpack-sources.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+# Include common function definitions.
+. $(dirname "$0")/common.shi
+
+shell_import build-defaults.shi
+
+usage () {
+    cat >&2 <<EOF
+Usage: $(program_name) <destination-path>
+
+This script is used to unpack all required support library sources needed
+by the qemu-android build system. Sources will be extracted at the target
+destination path, which will be created on demand by this script.
+EOF
+    exit ${1:-0}
+}
+
+if [ -z "$1" ]; then
+    usage 1
+fi
+
+DEST_DIR=$1
+if [ ! -d "$DEST_DIR" ]; then
+    dump "Creating $DEST_DIR"
+    mkdir -p "$DEST_DIR" ||
+    panic "Could not create destination directory: $DEST_DIR"
+else
+    dump "Cleaning up $DEST_DIR"
+    rm -rf "$DEST_DIR"/*
+fi
+
+# Sanity check.
+ARCHIVE_DIR=$(program_directory)/../archive
+if [ ! -d "$ARCHIVE_DIR" ]; then
+    panic "Missing archive directory: $ARCHIVE_DIR"
+fi
+ARCHIVE_DIR=$(cd "$ARCHIVE_DIR" && pwd -P)
+
+MISSING_PKGS=
+for PKG in $SOURCES_PACKAGES; do
+    PKG_PATH=$ARCHIVE_DIR/$PKG
+    if [ ! -f "$PKG_PATH" ]; then
+        MISSING_PKGS="$MISSING_PKGS $PKG_PATH"
+    else
+        dump "Unpacking $PKG"
+        unpack_archive "$PKG_PATH" "$DEST_DIR"
+    fi
+done
+
+if [ "$MISSING_PKGS" ]; then
+    panic "Missing packages: $MISSING_PKGS"
+fi
+
+echo "Done!"