Make the individual install_ and uninstall_ functions idempotent.
authorGuy Harris <guy@alum.mit.edu>
Thu, 22 Jan 2015 02:09:30 +0000 (18:09 -0800)
committerGuy Harris <guy@alum.mit.edu>
Thu, 22 Jan 2015 02:10:10 +0000 (02:10 +0000)
Move the "do I want this and, if so, is it already installed?" checks
into the install_ functions.

Move the "is this already installed?" checks into the uninstall_
functions, and have them clear the appropriate installed version
variable when finished.

Also, fetch the installed versions early in the main line.

Change-Id: I9e5d8ca48285c6d424a4a2a5f53f4aa449a891d3
Reviewed-on: https://code.wireshark.org/review/6730
Reviewed-by: Guy Harris <guy@alum.mit.edu>
macosx-setup.sh

index 8821f71ee588d5683c7d7cd82b66af8acb952803..dee8d56912f3c72ceea8d946404ce0b72b36ab96 100755 (executable)
@@ -140,828 +140,937 @@ if [[ $DARWIN_MAJOR_VERSION -gt 10 ]]; then
 fi
 
 install_xz() {
-    echo "Downloading, building, and installing xz:"
-    [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
-    bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
-    cd xz-$XZ_VERSION
-    CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch xz-$XZ_VERSION-done
+    if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
+        echo "Downloading, building, and installing xz:"
+        [ -f xz-$XZ_VERSION.tar.bz2 ] || curl -O http://tukaani.org/xz/xz-$XZ_VERSION.tar.bz2 || exit 1
+        bzcat xz-$XZ_VERSION.tar.bz2 | tar xf - || exit 1
+        cd xz-$XZ_VERSION
+        CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch xz-$XZ_VERSION-done
+    fi
 }
 
 uninstall_xz() {
-    echo "Uninstalling xz:"
-    cd xz-$installed_xz_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm xz-$installed_xz_version-done
+    if [ ! -z "$installed_xz_version" ] ; then
+        echo "Uninstalling xz:"
+        cd xz-$installed_xz_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm xz-$installed_xz_version-done
+        installed_xz_version=""
+    fi
 }
 
 install_autoconf() {
-    echo "Downloading, building and installing GNU autoconf..."
-    [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
-    xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
-    cd autoconf-$AUTOCONF_VERSION
-    ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch autoconf-$AUTOCONF_VERSION-done
+    if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
+        echo "Downloading, building and installing GNU autoconf..."
+        [ -f autoconf-$AUTOCONF_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/autoconf/autoconf-$AUTOCONF_VERSION.tar.xz || exit 1
+        xzcat autoconf-$AUTOCONF_VERSION.tar.xz | tar xf - || exit 1
+        cd autoconf-$AUTOCONF_VERSION
+        ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch autoconf-$AUTOCONF_VERSION-done
+    fi
 }
 
 uninstall_autoconf() {
-    echo "Uninstalling GNU autoconf:"
-    cd autoconf-$installed_autoconf_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm autoconf-$installed_autoconf_version-done
+    if [ ! -z "$installed_autoconf_version" ] ; then
+        echo "Uninstalling GNU autoconf:"
+        cd autoconf-$installed_autoconf_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm autoconf-$installed_autoconf_version-done
+        installed_autoconf_version=""
+    fi
 }
 
 install_automake() {
-    echo "Downloading, building and installing GNU automake..."
-    [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
-    xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
-    cd automake-$AUTOMAKE_VERSION
-    ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch automake-$AUTOMAKE_VERSION-done
+    if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
+        echo "Downloading, building and installing GNU automake..."
+        [ -f automake-$AUTOMAKE_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/automake/automake-$AUTOMAKE_VERSION.tar.xz || exit 1
+        xzcat automake-$AUTOMAKE_VERSION.tar.xz | tar xf - || exit 1
+        cd automake-$AUTOMAKE_VERSION
+        ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch automake-$AUTOMAKE_VERSION-done
+    fi
 }
 
 uninstall_automake() {
-    echo "Uninstalling GNU automake:"
-    cd automake-$installed_automake_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm automake-$installed_automake_version-done
+    if [ ! -z "$installed_automake_version" ] ; then
+        echo "Uninstalling GNU automake:"
+        cd automake-$installed_automake_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm automake-$installed_automake_version-done
+        installed_automake_version=""
+    fi
 }
 
 install_libtool() {
-    echo "Downloading, building and installing GNU libtool..."
-    [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
-    xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
-    cd libtool-$LIBTOOL_VERSION
-    ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    $DO_MV /usr/local/bin/libtool /usr/local/bin/glibtool
-    $DO_MV /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
-    cd ..
-    touch libtool-$LIBTOOL_VERSION-done
+    if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
+        echo "Downloading, building and installing GNU libtool..."
+        [ -f libtool-$LIBTOOL_VERSION.tar.xz ] || curl -O ftp://ftp.gnu.org/gnu/libtool/libtool-$LIBTOOL_VERSION.tar.xz || exit 1
+        xzcat libtool-$LIBTOOL_VERSION.tar.xz | tar xf - || exit 1
+        cd libtool-$LIBTOOL_VERSION
+        ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        $DO_MV /usr/local/bin/libtool /usr/local/bin/glibtool
+        $DO_MV /usr/local/bin/libtoolize /usr/local/bin/glibtoolize
+        cd ..
+       touch libtool-$LIBTOOL_VERSION-done
+    fi
 }
 
 uninstall_libtool() {
-    echo "Uninstalling GNU libtool:"
-    cd libtool-$installed_libtool_version
-    $DO_MV /usr/local/bin/glibtool /usr/local/bin/libtool
-    $DO_MV /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm libtool-$installed_libtool_version-done
+    if [ ! -z "$installed_libtool_version" ] ; then
+        echo "Uninstalling GNU libtool:"
+        cd libtool-$installed_libtool_version
+        $DO_MV /usr/local/bin/glibtool /usr/local/bin/libtool
+        $DO_MV /usr/local/bin/glibtoolize /usr/local/bin/libtoolize
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm libtool-$installed_libtool_version-done
+        installed_libtool_version=""
+    fi
 }
 
 install_cmake() {
-    echo "Downloading and installing CMake:"
-    cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
-    #
-    # NOTE: the "64" in "Darwin64" doesn't mean "64-bit-only"; the
-    # package in question supports both 32-bit and 64-bit x86.
-    #
-    [ -f cmake-$CMAKE_VERSION-Darwin64-universal.dmg ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
-    sudo hdiutil attach http://www.cmake.org/files/v2.8/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
-    sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
-    sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
-    touch cmake-$CMAKE_VERSION-done
+    if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
+        echo "Downloading and installing CMake:"
+        cmake_dir=`expr $CMAKE_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        #
+        # NOTE: the "64" in "Darwin64" doesn't mean "64-bit-only"; the
+        # package in question supports both 32-bit and 64-bit x86.
+        #
+        [ -f cmake-$CMAKE_VERSION-Darwin64-universal.dmg ] || curl -O http://www.cmake.org/files/v$cmake_dir/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
+        sudo hdiutil attach http://www.cmake.org/files/v2.8/cmake-$CMAKE_VERSION-Darwin64-universal.dmg || exit 1
+        sudo installer -target / -pkg /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal/cmake-$CMAKE_VERSION-Darwin64-universal.pkg || exit 1
+        sudo hdiutil detach /Volumes/cmake-$CMAKE_VERSION-Darwin64-universal
+        touch cmake-$CMAKE_VERSION-done
+    fi
 }
 
 uninstall_cmake() {
-    echo "Uninstalling CMake:"
-    sudo rm -rf "/Applications/CMake "`echo "$installed_cmake_version" | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1.\2-\3/'`.app
-    sudo rm /usr/bin/ccmake
-    sudo rm /usr/bin/cmake
-    sudo rm /usr/bin/cmake-gui
-    sudo rm /usr/bin/cmakexbuild
-    sudo rm /usr/bin/cpack
-    sudo rm /usr/bin/ctest
-    sudo pkgutil --forget com.Kitware.CMake
-    rm cmake-$installed_cmake_version-done
+    if [ ! -z "$installed_cmake_version" ]; then
+        echo "Uninstalling CMake:"
+        sudo rm -rf "/Applications/CMake "`echo "$installed_cmake_version" | sed 's/\([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/\1.\2-\3/'`.app
+        sudo rm /usr/bin/ccmake
+        sudo rm /usr/bin/cmake
+        sudo rm /usr/bin/cmake-gui
+        sudo rm /usr/bin/cmakexbuild
+        sudo rm /usr/bin/cpack
+        sudo rm /usr/bin/ctest
+        sudo pkgutil --forget com.Kitware.CMake
+        rm cmake-$installed_cmake_version-done
+        installed_cmake_version=""
+    fi
 }
 
 install_gettext() {
-    echo "Downloading, building, and installing GNU gettext:"
-    [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
-    gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
-    cd gettext-$GETTEXT_VERSION
-    CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch gettext-$GETTEXT_VERSION-done
+    if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
+        echo "Downloading, building, and installing GNU gettext:"
+        [ -f gettext-$GETTEXT_VERSION.tar.gz ] || curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-$GETTEXT_VERSION.tar.gz || exit 1
+        gzcat gettext-$GETTEXT_VERSION.tar.gz | tar xf - || exit 1
+        cd gettext-$GETTEXT_VERSION
+        CFLAGS="$CFLAGS -D_FORTIFY_SOURCE=0 $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+       touch gettext-$GETTEXT_VERSION-done
+    fi
 }
 
 uninstall_gettext() {
-    echo "Uninstalling GNU gettext:"
-    cd gettext-$installed_gettext_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm gettext-$installed_gettext_version-done
+    if [ ! -z "$installed_gettext_version" ] ; then
+        echo "Uninstalling GNU gettext:"
+        cd gettext-$installed_gettext_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm gettext-$installed_gettext_version-done
+        installed_gettext_version=""
+    fi
 }
 
 install_pkg_config() {
-    echo "Downloading, building, and installing pkg-config:"
-    [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
-    gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
-    cd pkg-config-$PKG_CONFIG_VERSION
-    ./configure --with-internal-glib || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch pkg-config-$PKG_CONFIG_VERSION-done
+    if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
+        echo "Downloading, building, and installing pkg-config:"
+        [ -f pkg-config-$PKG_CONFIG_VERSION.tar.gz ] || curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-$PKG_CONFIG_VERSION.tar.gz || exit 1
+        gzcat pkg-config-$PKG_CONFIG_VERSION.tar.gz | tar xf - || exit 1
+        cd pkg-config-$PKG_CONFIG_VERSION
+        ./configure --with-internal-glib || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch pkg-config-$PKG_CONFIG_VERSION-done
+    fi
 }
 
 uninstall_pkg_config() {
-    echo "Uninstalling pkg-config:"
-    cd pkg-config-$installed_pkg_config_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm pkg-config-$installed_pkg_config_version-done
+    if [ ! -z "$installed_pkg_config_version" ] ; then
+        echo "Uninstalling pkg-config:"
+        cd pkg-config-$installed_pkg_config_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm pkg-config-$installed_pkg_config_version-done
+        installed_pkg_config_version=""
+    fi
 }
 
 install_glib() {
-    echo "Downloading, building, and installing GLib:"
-    glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
-    GLIB_MAJOR_VERSION="`expr $GLIB_VERSION : '\([0-9][0-9]*\).*'`"
-    GLIB_MINOR_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    GLIB_DOTDOT_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    if [[ $GLIB_MAJOR_VERSION -gt 2 ||
-          $GLIB_MINOR_VERSION -gt 28 ||
-          ($GLIB_MINOR_VERSION -eq 28 && $GLIB_DOTDOT_VERSION -ge 8) ]]
-    then
+    if [ ! -f glib-$GLIB_VERSION-done ] ; then
+        echo "Downloading, building, and installing GLib:"
+        glib_dir=`expr $GLIB_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        GLIB_MAJOR_VERSION="`expr $GLIB_VERSION : '\([0-9][0-9]*\).*'`"
+        GLIB_MINOR_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        GLIB_DOTDOT_VERSION="`expr $GLIB_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        if [[ $GLIB_MAJOR_VERSION -gt 2 ||
+              $GLIB_MINOR_VERSION -gt 28 ||
+              ($GLIB_MINOR_VERSION -eq 28 && $GLIB_DOTDOT_VERSION -ge 8) ]]
+        then
+            #
+            # Starting with GLib 2.28.8, xz-compressed tarballs are available.
+            #
+            [ -f glib-$GLIB_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.xz || exit 1
+            xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
+        else
+            [ -f glib-$GLIB_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.bz2 || exit 1
+            bzcat glib-$GLIB_VERSION.tar.bz2 | tar xf - || exit 1
+        fi
+        cd glib-$GLIB_VERSION
         #
-        # Starting with GLib 2.28.8, xz-compressed tarballs are available.
+        # OS X ships with libffi, but doesn't provide its pkg-config file;
+        # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
+        # script doesn't try to use pkg-config to get the appropriate
+        # C flags and loader flags.
         #
-        [ -f glib-$GLIB_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.xz || exit 1
-        xzcat glib-$GLIB_VERSION.tar.xz | tar xf - || exit 1
-    else
-        [ -f glib-$GLIB_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/glib/$glib_dir/glib-$GLIB_VERSION.tar.bz2 || exit 1
-        bzcat glib-$GLIB_VERSION.tar.bz2 | tar xf - || exit 1
-    fi
-    cd glib-$GLIB_VERSION
-    #
-    # OS X ships with libffi, but doesn't provide its pkg-config file;
-    # explicitly specify LIBFFI_CFLAGS and LIBFFI_LIBS, so the configure
-    # script doesn't try to use pkg-config to get the appropriate
-    # C flags and loader flags.
-    #
-    # And, what's worse, at least with the version of Xcode that comes
-    # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
-    # which causes the build of GLib to fail.  If we don't find
-    # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explicitly
-    # define it.
-    #
-    # While we're at it, suppress -Wformat-nonliteral to avoid a case
-    # where clang's stricter rules on when not to complain about
-    # non-literal format arguments cause it to complain about code
-    # that's safe but it wasn't told that.  See my comment #25 in
-    # GNOME bug 691608:
-    #
-    #    https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
-    #
-    # First, determine where the system include files are.  (It's not
-    # necessarily /usr/include.)  There's a bit of a greasy hack here;
-    # pre-5.x versions of the developer tools don't support the
-    # --show-sdk-path option, and will produce no output, so includedir
-    # will be set to /usr/include (in those older versions of the
-    # developer tools, there is a /usr/include directory).
-    #
-    includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
-    if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
-    then
-        # It's defined, nothing to do
-        LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    else
-        LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    fi
+        # And, what's worse, at least with the version of Xcode that comes
+        # with Leopard, /usr/include/ffi/fficonfig.h doesn't define MACOSX,
+        # which causes the build of GLib to fail.  If we don't find
+        # "#define.*MACOSX" in /usr/include/ffi/fficonfig.h, explicitly
+        # define it.
+        #
+        # While we're at it, suppress -Wformat-nonliteral to avoid a case
+        # where clang's stricter rules on when not to complain about
+        # non-literal format arguments cause it to complain about code
+        # that's safe but it wasn't told that.  See my comment #25 in
+        # GNOME bug 691608:
+        #
+        #    https://bugzilla.gnome.org/show_bug.cgi?id=691608#c25
+        #
+        # First, determine where the system include files are.  (It's not
+        # necessarily /usr/include.)  There's a bit of a greasy hack here;
+        # pre-5.x versions of the developer tools don't support the
+        # --show-sdk-path option, and will produce no output, so includedir
+        # will be set to /usr/include (in those older versions of the
+        # developer tools, there is a /usr/include directory).
+        #
+        includedir=`xcrun --show-sdk-path 2>/dev/null`/usr/include
+        if grep -qs '#define.*MACOSX' $includedir/ffi/fficonfig.h
+        then
+            # It's defined, nothing to do
+            LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        else
+            LIBFFI_CFLAGS="-I $includedir/ffi" LIBFFI_LIBS="-lffi" CFLAGS="$CFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS -DMACOSX -Wno-format-nonliteral $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        fi
 
-    #
-    # Apply the fix to GNOME bug 529806:
-    #
-    #    https://bugzilla.gnome.org/show_bug.cgi?id=529806
-    #
-    # if we have a version of GLib prior to 2.30.
-    #
-    if [[ $GLIB_MAJOR_VERSION -eq 2 && $GLIB_MINOR_VERSION -le 30 ]]
-    then
-        patch -p0 <../../macosx-support-lib-patches/glib-gconvert.c.patch || exit 1
+        #
+        # Apply the fix to GNOME bug 529806:
+        #
+        #    https://bugzilla.gnome.org/show_bug.cgi?id=529806
+        #
+        # if we have a version of GLib prior to 2.30.
+        #
+        if [[ $GLIB_MAJOR_VERSION -eq 2 && $GLIB_MINOR_VERSION -le 30 ]]
+        then
+            patch -p0 <../../macosx-support-lib-patches/glib-gconvert.c.patch || exit 1
+        fi
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch glib-$GLIB_VERSION-done
     fi
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch glib-$GLIB_VERSION-done
 }
 
 uninstall_glib() {
-    echo "Uninstalling GLib:"
-    cd glib-$installed_glib_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm glib-$installed_glib_version-done
+    if [ ! -z "$installed_glib_version" ] ; then
+        echo "Uninstalling GLib:"
+        cd glib-$installed_glib_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm glib-$installed_glib_version-done
+        installed_glib_version=""
+    fi
 }
 
 install_qt() {
-    echo "Downloading, building, and installing Qt:"
-    QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
-    QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
-    #
-    # What you get for this URL might just be a 302 Found reply, so use
-    # -L so we get redirected.
-    #
-    curl -L -O http://download.qt-project.org/official_releases/qt/$QT_MAJOR_MINOR_VERSION/$QT_VERSION/single/qt-everywhere-opensource-src-$QT_VERSION.tar.gz
-    #
-    # Qt 5.1.x sets QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
-    # in qtbase/mkspecs/$TARGET_PLATFORM/qmake.conf
-    # We may need to adjust this manually in the future.
-    #
-    # The -no-c++11 flag is needed to work around
-    # https://bugreports.qt-project.org/browse/QTBUG-30487
-    #
-    tar xf qt-everywhere-opensource-src-$QT_VERSION.tar.gz
-    cd qt-everywhere-opensource-src-$QT_VERSION
-    #
-    # We don't build Qt in its Full Shining Glory, as we don't need all
-    # of its components, and it takes *forever* to build in that form.
-    #
-    # Qt 5.2.0 beta1 fails to build on OS X without -no-xcb due to bug
-    # QTBUG-34382.
-    #
-    # Qt 5.x fails to build on OS X with -no-opengl due to bug
-    # QTBUG-31151.
-    #
-    ./configure -v $qt_sdk_arg -platform $TARGET_PLATFORM \
-        -opensource -confirm-license -no-c++11 -no-dbus \
-        -no-sql-sqlite -no-xcb -nomake examples \
-        -skip qtdoc -skip qtquickcontrols -skip qtwebkit \
-        -skip qtwebkit-examples -skip qtxmlpatterns
-    make || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch qt-$QT_VERSION-done
+    if [ "$QT_VERSION" -a ! -f qt-$QT_VERSION-done ]; then
+        echo "Downloading, building, and installing Qt:"
+        QT_MAJOR_VERSION="`expr $QT_VERSION : '\([0-9][0-9]*\).*'`"
+        QT_MINOR_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        QT_DOTDOT_VERSION="`expr $QT_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        QT_MAJOR_MINOR_VERSION=$QT_MAJOR_VERSION.$QT_MINOR_VERSION
+        #
+        # What you get for this URL might just be a 302 Found reply, so use
+        # -L so we get redirected.
+        #
+        curl -L -O http://download.qt-project.org/official_releases/qt/$QT_MAJOR_MINOR_VERSION/$QT_VERSION/single/qt-everywhere-opensource-src-$QT_VERSION.tar.gz
+        #
+        # Qt 5.1.x sets QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.6
+        # in qtbase/mkspecs/$TARGET_PLATFORM/qmake.conf
+        # We may need to adjust this manually in the future.
+        #
+        # The -no-c++11 flag is needed to work around
+        # https://bugreports.qt-project.org/browse/QTBUG-30487
+        #
+        tar xf qt-everywhere-opensource-src-$QT_VERSION.tar.gz
+        cd qt-everywhere-opensource-src-$QT_VERSION
+        #
+        # We don't build Qt in its Full Shining Glory, as we don't need all
+        # of its components, and it takes *forever* to build in that form.
+        #
+        # Qt 5.2.0 beta1 fails to build on OS X without -no-xcb due to bug
+        # QTBUG-34382.
+        #
+        # Qt 5.x fails to build on OS X with -no-opengl due to bug
+        # QTBUG-31151.
+        #
+        ./configure -v $qt_sdk_arg -platform $TARGET_PLATFORM \
+            -opensource -confirm-license -no-c++11 -no-dbus \
+            -no-sql-sqlite -no-xcb -nomake examples \
+            -skip qtdoc -skip qtquickcontrols -skip qtwebkit \
+            -skip qtwebkit-examples -skip qtxmlpatterns
+        make || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch qt-$QT_VERSION-done
+    fi
 }
 
 uninstall_qt() {
-    echo "Uninstalling Qt:"
-    cd qt-everywhere-opensource-src-$installed_qt_version
-    $DO_MAKE_UNINSTALL || exit 1
-    #
-    # XXX - "make distclean" doesn't work.  qmake sure does a
-    # good job of constructing Makefiles that work correctly....
-    #
-    #make distclean || exit 1
-    cd ..
-    rm qt-$installed_qt_version-done
+    if [ ! -z "$installed_qt_version" ] ; then
+        echo "Uninstalling Qt:"
+        cd qt-everywhere-opensource-src-$installed_qt_version
+        $DO_MAKE_UNINSTALL || exit 1
+        #
+        # XXX - "make distclean" doesn't work.  qmake sure does a
+        # good job of constructing Makefiles that work correctly....
+        #
+        #make distclean || exit 1
+        cd ..
+        rm qt-$installed_qt_version-done
+        installed_qt_version=""
+    fi
 }
 
 install_libpng() {
-    echo "Downloading, building, and installing libpng:"
-    #
-    # The FTP site puts libpng x.y.* into a libpngxy directory.
-    #
-    subdir=`echo $PNG_VERSION | sed 's/\([1-9][0-9]*\)\.\([1-9][0-9]*\).*/libpng\1\2'/`
-    [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/$subdir/libpng-$PNG_VERSION.tar.xz
-    xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
-    cd libpng-$PNG_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch libpng-$PNG_VERSION-done
+    if [ ! -f libpng-$PNG_VERSION-done ] ; then
+        echo "Downloading, building, and installing libpng:"
+        #
+        # The FTP site puts libpng x.y.* into a libpngxy directory.
+        #
+        subdir=`echo $PNG_VERSION | sed 's/\([1-9][0-9]*\)\.\([1-9][0-9]*\).*/libpng\1\2'/`
+        [ -f libpng-$PNG_VERSION.tar.xz ] || curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/$subdir/libpng-$PNG_VERSION.tar.xz
+        xzcat libpng-$PNG_VERSION.tar.xz | tar xf - || exit 1
+        cd libpng-$PNG_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch libpng-$PNG_VERSION-done
+    fi
 }
 
 uninstall_libpng() {
-    echo "Uninstalling libpng:"
-    cd libpng-$installed_libpng_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm libpng-$installed_libpng_version-done
+    if [ ! -z "$installed_libpng_version" ] ; then
+        echo "Uninstalling libpng:"
+        cd libpng-$installed_libpng_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm libpng-$installed_libpng_version-done
+        installed_libpng_version=""
+    fi
 }
 
 install_libpixman() {
-    echo "Downloading, building, and installing pixman:"
-    [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
-    gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
-    cd pixman-$PIXMAN_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch pixman-$PIXMAN_VERSION-done
+    if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
+        echo "Downloading, building, and installing pixman:"
+        [ -f pixman-$PIXMAN_VERSION.tar.gz ] || curl -O http://www.cairographics.org/releases/pixman-$PIXMAN_VERSION.tar.gz
+        gzcat pixman-$PIXMAN_VERSION.tar.gz | tar xf - || exit 1
+        cd pixman-$PIXMAN_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch pixman-$PIXMAN_VERSION-done
+    fi
 }
 
 uninstall_pixman() {
-    echo "Uninstalling pixman:"
-    cd pixman-$installed_pixman_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm pixman-$installed_pixman_version-done
+    if [ ! -z "$installed_pixman_version" ] ; then
+        echo "Uninstalling pixman:"
+        cd pixman-$installed_pixman_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm pixman-$installed_pixman_version-done
+        installed_pixman_version=""
+    fi
 }
 
 install_cairo() {
-    echo "Downloading, building, and installing Cairo:"
-    CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
-    CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
-          $CAIRO_MINOR_VERSION -gt 12 ||
-          ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
-    then
+    if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
+        echo "Downloading, building, and installing Cairo:"
+        CAIRO_MAJOR_VERSION="`expr $CAIRO_VERSION : '\([0-9][0-9]*\).*'`"
+        CAIRO_MINOR_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        CAIRO_DOTDOT_VERSION="`expr $CAIRO_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        if [[ $CAIRO_MAJOR_VERSION -gt 1 ||
+              $CAIRO_MINOR_VERSION -gt 12 ||
+              ($CAIRO_MINOR_VERSION -eq 12 && $CAIRO_DOTDOT_VERSION -ge 2) ]]
+        then
+            #
+            # Starting with Cairo 1.12.2, the tarballs are compressed with
+            # xz rather than gzip.
+            #
+            [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
+            xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
+        else
+            [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
+            gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
+        fi
+        cd cairo-$CAIRO_VERSION
+        # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
+        # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
         #
-        # Starting with Cairo 1.12.2, the tarballs are compressed with
-        # xz rather than gzip.
+        # We must avoid the version of libpng that comes with X11; the
+        # only way I've found to force that is to forcibly set INCLUDES
+        # when we do the build, so that this comes before CAIRO_CFLAGS,
+        # which has -I/usr/X11/include added to it before anything
+        # connected to libpng is.
         #
-        [ -f cairo-$CAIRO_VERSION.tar.xz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.xz || exit 1
-        xzcat cairo-$CAIRO_VERSION.tar.xz | tar xf - || exit 1
-    else
-        [ -f cairo-$CAIRO_VERSION.tar.gz ] || curl -O http://cairographics.org/releases/cairo-$CAIRO_VERSION.tar.gz || exit 1
-        gzcat cairo-$CAIRO_VERSION.tar.gz | tar xf - || exit 1
+        INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch cairo-$CAIRO_VERSION-done
     fi
-    cd cairo-$CAIRO_VERSION
-    # CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=no || exit 1
-    # Maybe follow http://cairographics.org/end_to_end_build_for_mac_os_x/
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --enable-quartz=yes || exit 1
-    #
-    # We must avoid the version of libpng that comes with X11; the
-    # only way I've found to force that is to forcibly set INCLUDES
-    # when we do the build, so that this comes before CAIRO_CFLAGS,
-    # which has -I/usr/X11/include added to it before anything
-    # connected to libpng is.
-    #
-    INCLUDES="-I/usr/local/include/libpng15" make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch cairo-$CAIRO_VERSION-done
 }
 
 uninstall_cairo() {
-    echo "Uninstalling Cairo:"
-    cd cairo-$installed_cairo_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm cairo-$installed_cairo_version-done
+    if [ ! -z "$installed_cairo_version" ] ; then
+        echo "Uninstalling Cairo:"
+        cd cairo-$installed_cairo_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm cairo-$installed_cairo_version-done
+        installed_cairo_version=""
+    fi
 }
 
 install_atk() {
-    echo "Downloading, building, and installing ATK:"
-    atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
-    ATK_MAJOR_VERSION="`expr $ATK_VERSION : '\([0-9][0-9]*\).*'`"
-    ATK_MINOR_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    ATK_DOTDOT_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    if [[ $ATK_MAJOR_VERSION -gt 2 ||
-          ($ATK_MAJOR_VERSION -eq 2 && $ATK_MINOR_VERSION -gt 0) ||
-          ($ATK_MANOR_VERSION -eq 2 && $ATK_MINOR_VERSION -eq 0 && $ATK_DOTDOT_VERSION -ge 1) ]]
-    then
-        #
-        # Starting with ATK 2.0.1, xz-compressed tarballs are available.
-        #
-        [ -f atk-$ATK_VERSION.tar.xz ] || curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.xz || exit 1
-        xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
-    else
-        [ -f atk-$ATK_VERSION.tar.bz2 ] || curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.bz2 || exit 1
-        bzcat atk-$ATK_VERSION.tar.bz2 | tar xf - || exit 1
+    if [ ! -f atk-$ATK_VERSION-done ] ; then
+        echo "Downloading, building, and installing ATK:"
+        atk_dir=`expr $ATK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        ATK_MAJOR_VERSION="`expr $ATK_VERSION : '\([0-9][0-9]*\).*'`"
+        ATK_MINOR_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        ATK_DOTDOT_VERSION="`expr $ATK_VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        if [[ $ATK_MAJOR_VERSION -gt 2 ||
+              ($ATK_MAJOR_VERSION -eq 2 && $ATK_MINOR_VERSION -gt 0) ||
+              ($ATK_MANOR_VERSION -eq 2 && $ATK_MINOR_VERSION -eq 0 && $ATK_DOTDOT_VERSION -ge 1) ]]
+        then
+            #
+            # Starting with ATK 2.0.1, xz-compressed tarballs are available.
+            #
+            [ -f atk-$ATK_VERSION.tar.xz ] || curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.xz || exit 1
+            xzcat atk-$ATK_VERSION.tar.xz | tar xf - || exit 1
+        else
+            [ -f atk-$ATK_VERSION.tar.bz2 ] || curl -O http://ftp.gnome.org/pub/gnome/sources/atk/$atk_dir/atk-$ATK_VERSION.tar.bz2 || exit 1
+            bzcat atk-$ATK_VERSION.tar.bz2 | tar xf - || exit 1
+        fi
+        cd atk-$ATK_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch atk-$ATK_VERSION-done
     fi
-    cd atk-$ATK_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch atk-$ATK_VERSION-done
 }
 
 uninstall_atk() {
-    echo "Uninstalling ATK:"
-    cd atk-$installed_atk_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm atk-$installed_atk_version-done
+    if [ ! -z "$installed_atk_version" ] ; then
+        echo "Uninstalling ATK:"
+        cd atk-$installed_atk_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm atk-$installed_atk_version-done
+        installed_atk_version=""
+    fi
 }
 
 install_pango() {
-    echo "Downloading, building, and installing Pango:"
-    pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
-    PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
-    PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
-    if [[ $PANGO_MAJOR_VERSION -gt 1 ||
-          $PANGO_MINOR_VERSION -ge 29 ]]
-    then
-        #
-        # Starting with Pango 1.29, the tarballs are compressed with
-        # xz rather than bzip2.
-        #
-        [ -f pango-$PANGO_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.xz || exit 1
-        xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
-    else
-        [ -f pango-$PANGO_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.bz2 || exit 1
-        bzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
+    if [ ! -f pango-$PANGO_VERSION-done ] ; then
+        echo "Downloading, building, and installing Pango:"
+        pango_dir=`expr $PANGO_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        PANGO_MAJOR_VERSION="`expr $PANGO_VERSION : '\([0-9][0-9]*\).*'`"
+        PANGO_MINOR_VERSION="`expr $PANGO_VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\).*'`"
+        if [[ $PANGO_MAJOR_VERSION -gt 1 ||
+              $PANGO_MINOR_VERSION -ge 29 ]]
+        then
+            #
+            # Starting with Pango 1.29, the tarballs are compressed with
+            # xz rather than bzip2.
+            #
+            [ -f pango-$PANGO_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.xz || exit 1
+            xzcat pango-$PANGO_VERSION.tar.xz | tar xf - || exit 1
+        else
+            [ -f pango-$PANGO_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/pango/$pango_dir/pango-$PANGO_VERSION.tar.bz2 || exit 1
+            bzcat pango-$PANGO_VERSION.tar.bz2 | tar xf - || exit 1
+        fi
+        cd pango-$PANGO_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch pango-$PANGO_VERSION-done
     fi
-    cd pango-$PANGO_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch pango-$PANGO_VERSION-done
 }
 
 uninstall_pango() {
-    echo "Uninstalling Pango:"
-    cd pango-$installed_pango_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm pango-$installed_pango_version-done
+    if [ ! -z "$installed_pango_version" ] ; then
+        echo "Uninstalling Pango:"
+        cd pango-$installed_pango_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm pango-$installed_pango_version-done
+        installed_pango_version=""
+    fi
 }
 
 install_gdk_pixbuf() {
-    echo "Downloading, building, and installing gdk-pixbuf:"
-    gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
-    [ -f gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/$gdk_pixbuf_dir/gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz || exit 1
-    xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
-    cd gdk-pixbuf-$GDK_PIXBUF_VERSION
-    #
-    # If we're building using the 10.6 SDK, force the use of libpng12.
-    #
-    # The OS's X11, and corresponding SDK, didn't introduce libpng15,
-    # or pkg-config files, until 10.7, so, for 10.6 have to explicitly
-    # set LIBPNG to override the configure script, and also force the
-    # CFLAGS to look for the header files for libpng12 (note that
-    # -isysroot doesn't affect the arguments to -I, so we need to
-    # include the SDK path explicitly).
-    #
-    if [[ "$sdk_target" = 10.6 ]]
-    then
-        LIBPNG="-L/usr/X11/lib -lpng12" CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
-    else
-        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
+    if [ "$GDK_PIXBUF_VERSION" -a ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
+        echo "Downloading, building, and installing gdk-pixbuf:"
+        gdk_pixbuf_dir=`expr $GDK_PIXBUF_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        [ -f gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gdk-pixbuf/$gdk_pixbuf_dir/gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz || exit 1
+        xzcat gdk-pixbuf-$GDK_PIXBUF_VERSION.tar.xz | tar xf - || exit 1
+        cd gdk-pixbuf-$GDK_PIXBUF_VERSION
+        #
+        # If we're building using the 10.6 SDK, force the use of libpng12.
+        #
+        # The OS's X11, and corresponding SDK, didn't introduce libpng15,
+        # or pkg-config files, until 10.7, so, for 10.6 have to explicitly
+        # set LIBPNG to override the configure script, and also force the
+        # CFLAGS to look for the header files for libpng12 (note that
+        # -isysroot doesn't affect the arguments to -I, so we need to
+        # include the SDK path explicitly).
+        #
+        if [[ "$sdk_target" = 10.6 ]]
+        then
+            LIBPNG="-L/usr/X11/lib -lpng12" CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS -I$SDKPATH/usr/X11/include/libpng12" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
+        else
+            CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
+        fi
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
     fi
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch gdk-pixbuf-$GDK_PIXBUF_VERSION-done
 }
 
 uninstall_gdk_pixbuf() {
-    echo "Uninstalling gdk-pixbuf:"
-    cd gdk-pixbuf-$installed_gdk_pixbuf_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm gdk-pixbuf-$installed_gdk_pixbuf_version-done
+    if [ ! -z "$installed_gdk_pixbuf_version" ] ; then
+        echo "Uninstalling gdk-pixbuf:"
+        cd gdk-pixbuf-$installed_gdk_pixbuf_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm gdk-pixbuf-$installed_gdk_pixbuf_version-done
+        installed_gdk_pixbuf_version=""
+    fi
 }
 
 install_gtk() {
-    echo "Downloading, building, and installing GTK+:"
-    gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
-    if [[ $GTK_MAJOR_VERSION -gt 2 ||
-          $GTK_MINOR_VERSION -gt 24 ||
-         ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
-    then
-        #
-        # Starting with GTK+ 2.24.5, the tarballs are compressed with
-        # xz rather than gzip, in addition to bzip2; use xz, as we've
-        # built and installed it, and as xz compresses better than
-        # bzip2 so the tarballs take less time to download.
-        #
-        [ -f gtk+-$GTK_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.xz || exit 1
-        xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
-    else
-        [ -f gtk+-$GTK_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.bz2 || exit 1
-        bzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
-    fi
-    cd gtk+-$GTK_VERSION
-    if [ $DARWIN_MAJOR_VERSION -ge "12" ]
-    then
-        #
-        # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
-        # CUPS printing backend - either the CUPS API changed incompatibly
-        # or the backend was depending on non-API implementation details.
-        #
-        # Configure it out, on Mountain Lion and later, for now.
-        # (12 is the Darwin major version number in Mountain Lion.)
-        #
-        # Also, configure out libtiff and libjpeg; configure scripts
-        # just ignore unknown --enable/--disable and --with/--without
-        # options (at least they've always do so up to now).
-        #
-        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-cups --without-libtiff --without-libjpeg || exit 1
-    else
-        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
+    if [ ! -f gtk+-$GTK_VERSION-done ] ; then
+        echo "Downloading, building, and installing GTK+:"
+        gtk_dir=`expr $GTK_VERSION : '\([0-9][0-9]*\.[0-9][0-9]*\).*'`
+        if [[ $GTK_MAJOR_VERSION -gt 2 ||
+              $GTK_MINOR_VERSION -gt 24 ||
+             ($GTK_MINOR_VERSION -eq 24 && $GTK_DOTDOT_VERSION -ge 5) ]]
+        then
+            #
+            # Starting with GTK+ 2.24.5, the tarballs are compressed with
+            # xz rather than gzip, in addition to bzip2; use xz, as we've
+            # built and installed it, and as xz compresses better than
+            # bzip2 so the tarballs take less time to download.
+            #
+            [ -f gtk+-$GTK_VERSION.tar.xz ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.xz || exit 1
+            xzcat gtk+-$GTK_VERSION.tar.xz | tar xf - || exit 1
+        else
+            [ -f gtk+-$GTK_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnome.org/pub/gnome/sources/gtk+/$gtk_dir/gtk+-$GTK_VERSION.tar.bz2 || exit 1
+            bzcat gtk+-$GTK_VERSION.tar.bz2 | tar xf - || exit 1
+        fi
+        cd gtk+-$GTK_VERSION
+        if [ $DARWIN_MAJOR_VERSION -ge "12" ]
+        then
+            #
+            # GTK+ 2.24.10, at least, doesn't build on Mountain Lion with the
+            # CUPS printing backend - either the CUPS API changed incompatibly
+            # or the backend was depending on non-API implementation details.
+            #
+            # Configure it out, on Mountain Lion and later, for now.
+            # (12 is the Darwin major version number in Mountain Lion.)
+            #
+            # Also, configure out libtiff and libjpeg; configure scripts
+            # just ignore unknown --enable/--disable and --with/--without
+            # options (at least they've always do so up to now).
+            #
+            CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-cups --without-libtiff --without-libjpeg || exit 1
+        else
+            CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --without-libtiff --without-libjpeg || exit 1
+        fi
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch gtk+-$GTK_VERSION-done
     fi
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch gtk+-$GTK_VERSION-done
 }
 
 uninstall_gtk() {
-    echo "Uninstalling GTK+:"
-    cd gtk+-$installed_gtk_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm gtk+-$installed_gtk_version-done
+    if [ ! -z "$installed_gtk_version" ] ; then
+        echo "Uninstalling GTK+:"
+        cd gtk+-$installed_gtk_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm gtk+-$installed_gtk_version-done
+        installed_gtk_version=""
+    fi
 }
 
 install_libsmi() {
-    echo "Downloading, building, and installing libsmi:"
-    [ -f libsmi-$LIBSMI_VERSION.tar.gz ] || curl -L -O https://www.ibr.cs.tu-bs.de/projects/libsmi/download/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
-    gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
-    cd libsmi-$LIBSMI_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch libsmi-$LIBSMI_VERSION-done
+    if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
+        echo "Downloading, building, and installing libsmi:"
+        [ -f libsmi-$LIBSMI_VERSION.tar.gz ] || curl -L -O https://www.ibr.cs.tu-bs.de/projects/libsmi/download/libsmi-$LIBSMI_VERSION.tar.gz || exit 1
+        gzcat libsmi-$LIBSMI_VERSION.tar.gz | tar xf - || exit 1
+        cd libsmi-$LIBSMI_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch libsmi-$LIBSMI_VERSION-done
+    fi
 }
 
 uninstall_libsmi() {
-    echo "Uninstalling libsmi:"
-    cd libsmi-$installed_libsmi_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm libsmi-$installed_libsmi_version-done
+    if [ ! -z "$installed_libsmi_version" ] ; then
+        echo "Uninstalling libsmi:"
+        cd libsmi-$installed_libsmi_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm libsmi-$installed_libsmi_version-done
+        installed_libsmi_version=""
+    fi
 }
 
 install_libgpg_error() {
-    echo "Downloading, building, and installing libgpg-error:"
-    [ -f libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 || exit 1
-    bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
-    cd libgpg-error-$LIBGPG_ERROR_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch libgpg-error-$LIBGPG_ERROR_VERSION-done
+    if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
+        echo "Downloading, building, and installing libgpg-error:"
+        [ -f libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 || exit 1
+        bzcat libgpg-error-$LIBGPG_ERROR_VERSION.tar.bz2 | tar xf - || exit 1
+        cd libgpg-error-$LIBGPG_ERROR_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch libgpg-error-$LIBGPG_ERROR_VERSION-done
+    fi
 }
 
 uninstall_libgpg_error() {
-    echo "Uninstalling libgpg-error:"
-    cd libgpg-error-$installed_libgpg_error_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm libgpg-error-$installed_libgpg_error_version-done
+    if [ ! -z "$installed_libgpg_error_version" ] ; then
+        echo "Uninstalling libgpg-error:"
+        cd libgpg-error-$installed_libgpg_error_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm libgpg-error-$installed_libgpg_error_version-done
+        installed_libgpg_error_version=""
+    fi
 }
 
 install_libgcrypt() {
-    #
-    # libgpg-error is required for libgcrypt.
-    #
-    if [ -z $LIBGPG_ERROR_VERSION ]
-    then
-        echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
-        exit 1
-    fi
+    if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
+        #
+        # libgpg-error is required for libgcrypt.
+        #
+        if [ -z $LIBGPG_ERROR_VERSION ]
+        then
+            echo "libgcrypt requires libgpg-error, but you didn't install libgpg-error." 1>&2
+            exit 1
+        fi
 
-    echo "Downloading, building, and installing libgcrypt:"
-    [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
-    gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
-    cd libgcrypt-$LIBGCRYPT_VERSION
-    #
-    # The assembler language code is not compatible with the OS X
-    # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
-    #
-    # libgcrypt expects gnu89, not c99/gnu99, semantics for
-    # "inline".  See, for example:
-    #
-    #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
-    #
-    CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-asm || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch libgcrypt-$LIBGCRYPT_VERSION-done
+        echo "Downloading, building, and installing libgcrypt:"
+        [ -f libgcrypt-$LIBGCRYPT_VERSION.tar.gz ] || curl -L -O ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-$LIBGCRYPT_VERSION.tar.gz || exit 1
+        gzcat libgcrypt-$LIBGCRYPT_VERSION.tar.gz | tar xf - || exit 1
+        cd libgcrypt-$LIBGCRYPT_VERSION
+        #
+        # The assembler language code is not compatible with the OS X
+        # x86 assembler (or is it an x86-64 vs. x86-32 issue?).
+        #
+        # libgcrypt expects gnu89, not c99/gnu99, semantics for
+        # "inline".  See, for example:
+        #
+        #    http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2010-October/198809.html
+        #
+        CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" CFLAGS="$CFLAGS -std=gnu89 $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-asm || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch libgcrypt-$LIBGCRYPT_VERSION-done
+    fi
 }
 
 uninstall_libgcrypt() {
-    echo "Uninstalling libgcrypt:"
-    cd libgcrypt-$installed_libgcrypt_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm libgcrypt-$installed_libgcrypt_version-done
+    if [ ! -z "$installed_libgcrypt_version" ] ; then
+        echo "Uninstalling libgcrypt:"
+        cd libgcrypt-$installed_libgcrypt_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm libgcrypt-$installed_libgcrypt_version-done
+        installed_libgcrypt_version=""
+    fi
 }
 
 install_gnutls() {
-    #
-    # GnuTLS requires libgcrypt (or nettle, in newer versions).
-    #
-    if [ -z $LIBGCRYPT_VERSION ]
-    then
-        echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
-        exit 1
-    fi
+    if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
+        #
+        # GnuTLS requires libgcrypt (or nettle, in newer versions).
+        #
+        if [ -z $LIBGCRYPT_VERSION ]
+        then
+            echo "GnuTLS requires libgcrypt, but you didn't install libgcrypt" 1>&2
+            exit 1
+        fi
 
-    echo "Downloading, building, and installing GnuTLS:"
-    [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
-    bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
-    cd gnutls-$GNUTLS_VERSION
-    #
-    # Use libgcrypt, not nettle.
-    # XXX - is there some reason to prefer nettle?  Or does
-    # Wireshark directly use libgcrypt routines?
-    #
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --with-libgcrypt --without-p11-kit || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    #
-    # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
-    # while it supplies zlib, doesn't supply a pkgconfig file for
-    # it.
-    #
-    # Patch the GnuTLS pkgconfig file not to require zlib.
-    # (If the capabilities of GnuTLS that Wireshark uses don't
-    # depend on building GnuTLS with zlib, an alternative would be
-    # to configure it not to use zlib.)
-    #
-    patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch gnutls-$GNUTLS_VERSION-done
+        echo "Downloading, building, and installing GnuTLS:"
+        [ -f gnutls-$GNUTLS_VERSION.tar.bz2 ] || curl -L -O http://ftp.gnu.org/gnu/gnutls/gnutls-$GNUTLS_VERSION.tar.bz2 || exit 1
+        bzcat gnutls-$GNUTLS_VERSION.tar.bz2 | tar xf - || exit 1
+        cd gnutls-$GNUTLS_VERSION
+        #
+        # Use libgcrypt, not nettle.
+        # XXX - is there some reason to prefer nettle?  Or does
+        # Wireshark directly use libgcrypt routines?
+        #
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --with-libgcrypt --without-p11-kit || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        #
+        # The pkgconfig file for GnuTLS says "requires zlib", but OS X,
+        # while it supplies zlib, doesn't supply a pkgconfig file for
+        # it.
+        #
+        # Patch the GnuTLS pkgconfig file not to require zlib.
+        # (If the capabilities of GnuTLS that Wireshark uses don't
+        # depend on building GnuTLS with zlib, an alternative would be
+        # to configure it not to use zlib.)
+        #
+        patch -p0 lib/gnutls.pc.in <../../macosx-support-lib-patches/gnutls-pkgconfig.patch || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch gnutls-$GNUTLS_VERSION-done
+    fi
 }
 
 uninstall_gnutls() {
-    echo "Uninstalling GnuTLS:"
-    cd gnutls-$installed_gnutls_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm gnutls-$installed_gnutls_version-done
+    if [ ! -z "$installed_gnutls_version" ] ; then
+        echo "Uninstalling GnuTLS:"
+        cd gnutls-$installed_gnutls_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm gnutls-$installed_gnutls_version-done
+        installed_gnutls_version=""
+    fi
 }
 
 install_lua() {
-    echo "Downloading, building, and installing Lua:"
-    [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
-    gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
-    cd lua-$LUA_VERSION
-    make $MAKE_BUILD_OPTS macosx || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch lua-$LUA_VERSION-done
+    if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
+        echo "Downloading, building, and installing Lua:"
+        [ -f lua-$LUA_VERSION.tar.gz ] || curl -L -O http://www.lua.org/ftp/lua-$LUA_VERSION.tar.gz || exit 1
+        gzcat lua-$LUA_VERSION.tar.gz | tar xf - || exit 1
+        cd lua-$LUA_VERSION
+        make $MAKE_BUILD_OPTS macosx || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch lua-$LUA_VERSION-done
+    fi
 }
 
 uninstall_lua() {
-    echo "Uninstalling Lua:"
-    #
-    # Lua has no "make uninstall", so just remove stuff manually.
-    # There's no configure script, so there's no need for
-    # "make distclean", either; just do "make clean".
-    #
-    (cd /usr/local/bin; $DO_RM -f lua luac)
-    (cd /usr/local/include; $DO_RM -f lua.h luaconf.h lualib.h lauxlib.h lua.hpp)
-    (cd /usr/local/lib; $DO_RM -f liblua.a)
-    (cd /usr/local/man/man1; $DO_RM -f lua.1 luac.1)
-    cd lua-$installed_lua_version
-    make clean || exit 1
-    cd ..
-    rm lua-$installed_lua_version-done
+    if [ ! -z "$installed_lua_version" ] ; then
+        echo "Uninstalling Lua:"
+        #
+        # Lua has no "make uninstall", so just remove stuff manually.
+        # There's no configure script, so there's no need for
+        # "make distclean", either; just do "make clean".
+        #
+        (cd /usr/local/bin; $DO_RM -f lua luac)
+        (cd /usr/local/include; $DO_RM -f lua.h luaconf.h lualib.h lauxlib.h lua.hpp)
+        (cd /usr/local/lib; $DO_RM -f liblua.a)
+        (cd /usr/local/man/man1; $DO_RM -f lua.1 luac.1)
+        cd lua-$installed_lua_version
+        make clean || exit 1
+        cd ..
+        rm lua-$installed_lua_version-done
+        installed_lua_version=""
+    fi
 }
 
 install_portaudio() {
-    echo "Downloading, building, and installing PortAudio:"
-    [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
-    gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
-    cd portaudio
-    #
-    # Un-comment an include that's required on Lion.
-    #
-    patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
-    #
-    # Fix a bug that showed up with clang (but is a bug with any
-    # compiler).
-    #
-    patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
-    #
-    # Disable fat builds - the configure script doesn't work right
-    # with Xcode 4 if you leave them enabled, and we don't build
-    # any other libraries fat (GLib, for example, would be very
-    # hard to build fat), so there's no advantage to having PortAudio
-    # built fat.
-    #
-    # Set the minimum OS X version to 10.4, to suppress some
-    # deprecation warnings.  (Good luck trying to make any of
-    # this build on an OS+Xcode with a pre-10.4 SDK; we don't
-    # worry about the user requesting that.)
-    #
-    CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch portaudio-done
+    if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
+        echo "Downloading, building, and installing PortAudio:"
+        [ -f $PORTAUDIO_VERSION.tgz ] || curl -L -O http://www.portaudio.com/archives/$PORTAUDIO_VERSION.tgz || exit 1
+        gzcat $PORTAUDIO_VERSION.tgz | tar xf - || exit 1
+        cd portaudio
+        #
+        # Un-comment an include that's required on Lion.
+        #
+        patch -p0 include/pa_mac_core.h <../../macosx-support-lib-patches/portaudio-pa_mac_core.h.patch
+        #
+        # Fix a bug that showed up with clang (but is a bug with any
+        # compiler).
+        #
+        patch -p0 src/hostapi/coreaudio/pa_mac_core.c <../../macosx-support-lib-patches/portaudio-pa_mac_core.c.patch
+        #
+        # Disable fat builds - the configure script doesn't work right
+        # with Xcode 4 if you leave them enabled, and we don't build
+        # any other libraries fat (GLib, for example, would be very
+        # hard to build fat), so there's no advantage to having PortAudio
+        # built fat.
+        #
+        # Set the minimum OS X version to 10.4, to suppress some
+        # deprecation warnings.  (Good luck trying to make any of
+        # this build on an OS+Xcode with a pre-10.4 SDK; we don't
+        # worry about the user requesting that.)
+        #
+        CFLAGS="$CFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" CXXFLAGS="$CXXFLAGS -mmacosx-version-min=10.4 $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure --disable-mac-universal || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch portaudio-done
+    fi
 }
 
 uninstall_portaudio() {
-    echo "Uninstalling PortAudio:"
-    cd portaudio
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm portaudio-done
+    if [ "$PORTAUDIO_VERSION" -a -f portaudio-done ] ; then
+        echo "Uninstalling PortAudio:"
+        cd portaudio
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm portaudio-done
+    fi
 }
 
 install_geoip() {
-    echo "Downloading, building, and installing GeoIP API:"
-    [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
-    gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
-    cd GeoIP-$GEOIP_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    #
-    # Grr.  Their man pages "helpfully" have an ISO 8859-1
-    # copyright symbol in the copyright notice, but OS X's
-    # default character encoding is UTF-8.  sed on Mountain
-    # Lion barfs at the "illegal character sequence" represented
-    # by an ISO 8859-1 copyright symbol, as it's not a valid
-    # UTF-8 sequence.
-    #
-    # iconv the relevant man pages into UTF-8.
-    #
-    for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
-    do
-        iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
-            mv man/"$i".tmp man/"$i"
-    done
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch geoip-$GEOIP_VERSION-done
+    if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ] ; then
+        echo "Downloading, building, and installing GeoIP API:"
+        [ -f GeoIP-$GEOIP_VERSION.tar.gz ] || curl -L -O http://geolite.maxmind.com/download/geoip/api/c/GeoIP-$GEOIP_VERSION.tar.gz || exit 1
+        gzcat GeoIP-$GEOIP_VERSION.tar.gz | tar xf - || exit 1
+        cd GeoIP-$GEOIP_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        #
+        # Grr.  Their man pages "helpfully" have an ISO 8859-1
+        # copyright symbol in the copyright notice, but OS X's
+        # default character encoding is UTF-8.  sed on Mountain
+        # Lion barfs at the "illegal character sequence" represented
+        # by an ISO 8859-1 copyright symbol, as it's not a valid
+        # UTF-8 sequence.
+        #
+        # iconv the relevant man pages into UTF-8.
+        #
+        for i in geoipupdate.1.in geoiplookup6.1.in geoiplookup.1.in
+        do
+            iconv -f iso8859-1 -t utf-8 man/"$i" >man/"$i".tmp &&
+                mv man/"$i".tmp man/"$i"
+        done
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch geoip-$GEOIP_VERSION-done
+    fi
 }
 
 uninstall_geoip() {
-    echo "Uninstalling GeoIP API:"
-    cd GeoIP-$installed_geoip_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm geoip-$installed_geoip_version-done
+    if [ ! -z "$installed_geoip_version" ] ; then
+        echo "Uninstalling GeoIP API:"
+        cd GeoIP-$installed_geoip_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm geoip-$installed_geoip_version-done
+        installed_geoip_version=""
+    fi
 }
 
 install_c_ares() {
-    echo "Downloading, building, and installing C-Ares API:"
-    [ -f c-ares-$CARES_VERSION.tar.gz ] || curl -L -O http://c-ares.haxx.se/download/c-ares-$CARES_VERSION.tar.gz || exit 1
-    gzcat c-ares-$CARES_VERSION.tar.gz | tar xf - || exit 1
-    cd c-ares-$CARES_VERSION
-    CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS"  LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
-    make $MAKE_BUILD_OPTS || exit 1
-    $DO_MAKE_INSTALL || exit 1
-    cd ..
-    touch c-ares-$CARES_VERSION-done
+    if [ "$CARES_VERSION" -a ! -f c-ares-$CARES_VERSION-done ] ; then
+        echo "Downloading, building, and installing C-Ares API:"
+        [ -f c-ares-$CARES_VERSION.tar.gz ] || curl -L -O http://c-ares.haxx.se/download/c-ares-$CARES_VERSION.tar.gz || exit 1
+        gzcat c-ares-$CARES_VERSION.tar.gz | tar xf - || exit 1
+        cd c-ares-$CARES_VERSION
+        CFLAGS="$CFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" CXXFLAGS="$CXXFLAGS $VERSION_MIN_FLAGS $SDKFLAGS"  LDFLAGS="$LDFLAGS $VERSION_MIN_FLAGS $SDKFLAGS" ./configure || exit 1
+        make $MAKE_BUILD_OPTS || exit 1
+        $DO_MAKE_INSTALL || exit 1
+        cd ..
+        touch c-ares-$CARES_VERSION-done
+    fi
 }
 
 uninstall_c_ares() {
-    echo "Uninstalling C-Ares API:"
-    cd c-ares-$installed_cares_version
-    $DO_MAKE_UNINSTALL || exit 1
-    make distclean || exit 1
-    cd ..
-    rm c-ares-$installed_cares_version-done
+    if [ ! -z "$installed_cares_version" ] ; then
+        echo "Uninstalling C-Ares API:"
+        cd c-ares-$installed_cares_version
+        $DO_MAKE_UNINSTALL || exit 1
+        make distclean || exit 1
+        cd ..
+        rm c-ares-$installed_cares_version-done
+        installed_cares_version=""
+    fi
 }
 
 install_all() {
     #
     # Start with xz: It is the sole download format of glib later than 2.31.2
     #
-    if [ "$XZ_VERSION" -a ! -f xz-$XZ_VERSION-done ] ; then
-        install_xz
-    fi
+    install_xz
 
-    if [ "$AUTOCONF_VERSION" -a ! -f autoconf-$AUTOCONF_VERSION-done ] ; then
-        install_autoconf
-    fi
+    install_autoconf
 
-    if [ "$AUTOMAKE_VERSION" -a ! -f automake-$AUTOMAKE_VERSION-done ] ; then
-        install_automake
-    fi
+    install_automake
 
-    if [ "$LIBTOOL_VERSION" -a ! -f libtool-$LIBTOOL_VERSION-done ] ; then
-        install_libtool
-    fi
+    install_libtool
 
-    if [ -n "$CMAKE" -a ! -f cmake-$CMAKE_VERSION-done ]; then
-        install_cmake
-    fi
+    install_cmake
 
     #
     # Start with GNU gettext; GLib requires it, and OS X doesn't have it
@@ -974,30 +1083,22 @@ install_all() {
     # with the result being a huge train wreck.  Define _FORTIFY_SOURCE
     # as 0 in an attempt to keep the trains on separate tracks.
     #
-    if [ ! -f gettext-$GETTEXT_VERSION-done ] ; then
-        install_gettext
-    fi
+    install_gettext
 
     #
     # GLib depends on pkg-config.
     # By default, pkg-config depends on GLib; we break the dependency cycle
     # by configuring pkg-config to use its own internal version of GLib.
     #
-    if [ ! -f pkg-config-$PKG_CONFIG_VERSION-done ] ; then
-        install_pkg_config
-    fi
+    install_pkg_config
 
-    if [ ! -f glib-$GLIB_VERSION-done ] ; then
-        install_glib
-    fi
+    install_glib
 
     #
     # Now we have reached a point where we can build everything but
     # the GUI (Wireshark).
     #
-    if [ "$QT_VERSION" -a ! -f qt-$QT_VERSION-done ]; then
-        install_qt
-    fi
+    install_qt
 
     if [ "$GTK_VERSION" ]; then
         #
@@ -1022,9 +1123,7 @@ install_all() {
             # The libpng in later versions is not what the version of
             # libpixman we build below wants - it wants libpng15.
             #
-            if [ ! -f libpng-$PNG_VERSION-done ] ; then
-                install_libpng
-            fi
+            install_libpng
 
             #
             # The libpixman versions that come with the X11s for Leopard,
@@ -1034,35 +1133,23 @@ install_all() {
             # XXX - what about the one that comes with the latest version
             # of Xquartz?
             #
-            if [ ! -f pixman-$PIXMAN_VERSION-done ] ; then
-                install_libpixman
-            fi
+            install_libpixman
 
             #
             # And now Cairo itself.
             # XXX - with the libxcb that comes with 10.6,
             # xcb_discard_reply() is missing, and the build fails.
             #
-            if [ ! -f cairo-$CAIRO_VERSION-done ] ; then
-                install_cairo
-            fi
+            install_cairo
         fi
 
-        if [ ! -f atk-$ATK_VERSION-done ] ; then
-            install_atk
-        fi
+        install_atk
 
-        if [ ! -f pango-$PANGO_VERSION-done ] ; then
-            install_pango
-        fi
+        install_pango
 
-        if [ "$GDK_PIXBUF_VERSION" -a ! -f gdk-pixbuf-$GDK_PIXBUF_VERSION-done ] ; then
-            install_gdk_pixbuf
-        fi
+        install_gdk_pixbuf
 
-        if [ ! -f gtk+-$GTK_VERSION-done ] ; then
-            install_gtk
-        fi
+        install_gtk
     fi
 
     #
@@ -1075,37 +1162,21 @@ install_all() {
     # the default is to download them all.
     #
 
-    if [ "$LIBSMI_VERSION" -a ! -f libsmi-$LIBSMI_VERSION-done ] ; then
-        install_libsmi
-    fi
+    install_libsmi
 
-    if [ "$LIBGPG_ERROR_VERSION" -a ! -f libgpg-error-$LIBGPG_ERROR_VERSION-done ] ; then
-        install_libgpg_error
-    fi
+    install_libgpg_error
 
-    if [ "$LIBGCRYPT_VERSION" -a ! -f libgcrypt-$LIBGCRYPT_VERSION-done ] ; then
-        install_libgcrypt
-    fi
+    install_libgcrypt
 
-    if [ "$GNUTLS_VERSION" -a ! -f gnutls-$GNUTLS_VERSION-done ] ; then
-        install_gnutls
-    fi
+    install_gnutls
 
-    if [ "$LUA_VERSION" -a ! -f lua-$LUA_VERSION-done ] ; then
-        install_lua
-    fi
+    install_lua
 
-    if [ "$PORTAUDIO_VERSION" -a ! -f portaudio-done ] ; then
-        install_portaudio
-    fi
+    install_portaudio
 
-    if [ "$GEOIP_VERSION" -a ! -f geoip-$GEOIP_VERSION-done ] ; then
-        install_geoip
-    fi
+    install_geoip
 
-    if [ "$CARES_VERSION" -a ! -f c-ares-$CARES_VERSION-done ] ; then
-        install_c_ares
-    fi
+    install_c_ares
 }
 
 uninstall_all() {
@@ -1122,130 +1193,58 @@ uninstall_all() {
         # We also do a "make distclean", so that we don't have leftovers from
         # old configurations.
         #
+        uninstall_c_ares
 
-        installed_cares_version=`ls c-ares-*-done 2>/dev/null | sed 's/c-ares-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_cares_version" ] ; then
-            uninstall_c_ares
-        fi
+        uninstall_geoip
 
-        installed_geoip_version=`ls geoip-*-done 2>/dev/null | sed 's/geoip-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_geoip_version" ] ; then
-            uninstall_geoip
-        fi
+        uninstall_portaudio
 
-        if [ "$PORTAUDIO_VERSION" -a -f portaudio-done ] ; then
-            uninstall_portaudio
-        fi
+        uninstall_lua
 
-        installed_lua_version=`ls lua-*-done 2>/dev/null | sed 's/lua-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_lua_version" ] ; then
-            uninstall_lua
-        fi
+        uninstall_gnutls
 
-        installed_gnutls_version=`ls gnutls-*-done 2>/dev/null | sed 's/gnutls-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_gnutls_version" ] ; then
-            uninstall_gnutls
-        fi
+        uninstall_libgcrypt
 
-        installed_libgcrypt_version=`ls libgcrypt-*-done 2>/dev/null | sed 's/libgcrypt-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_libgcrypt_version" ] ; then
-            uninstall_libgcrypt
-        fi
+        uninstall_libgpg_error
 
-        installed_libgpg_error_version=`ls libgpg-error-*-done 2>/dev/null | sed 's/libgpg-error-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_libgpg_error_version" ] ; then
-            uninstall_libgpg_error
-        fi
+        uninstall_libsmi
 
-        installed_libsmi_version=`ls libsmi-*-done 2>/dev/null | sed 's/libsmi-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_libsmi_version" ] ; then
-            uninstall_libsmi
-        fi
-
-        installed_gtk_version=`ls gtk+-*-done 2>/dev/null | sed 's/gtk+-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_gtk_version" ] ; then
-            uninstall_gtk
-        fi
+        uninstall_gtk
 
-        installed_gdk_pixbuf_version=`ls gdk-pixbuf-*-done 2>/dev/null | sed 's/gdk-pixbuf-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_gdk_pixbuf_version" ] ; then
-            uninstall_gdk_pixbuf
-        fi
+        uninstall_gdk_pixbuf
 
-        installed_pango_version=`ls pango-*-done 2>/dev/null | sed 's/pango-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_pango_version" ] ; then
-            uninstall_pango
-        fi
+        uninstall_pango
 
-        installed_atk_version=`ls atk-*-done 2>/dev/null | sed 's/atk-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_atk_version" ] ; then
-            uninstall_atk
-        fi
+        uninstall_atk
 
-        installed_cairo_version=`ls cairo-*-done 2>/dev/null | sed 's/cairo-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_cairo_version" ] ; then
-            uninstall_cairo
-        fi
+        uninstall_cairo
 
-        installed_pixman_version=`ls pixman-*-done 2>/dev/null | sed 's/pixman-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_pixman_version" ] ; then
-            uninstall_pixman
-        fi
+        uninstall_pixman
 
-        installed_libpng_version=`ls libpng-*-done 2>/dev/null | sed 's/libpng-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_libpng_version" ] ; then
-            uninstall_libpng
-        fi
+        uninstall_libpng
 
-        installed_qt_version=`ls qt-*-done 2>/dev/null | sed 's/qt-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_qt_version" ] ; then
-            uninstall_qt
-        fi
+        uninstall_qt
 
-        installed_glib_version=`ls glib-*-done 2>/dev/null | sed 's/glib-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_glib_version" ] ; then
-            uninstall_glib
-        fi
+        uninstall_glib
 
-        installed_pkg_config_version=`ls pkg-config-*-done 2>/dev/null | sed 's/pkg-config-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_pkg_config_version" ] ; then
-            uninstall_pkg_config
-        fi
+        uninstall_pkg_config
 
-        installed_gettext_version=`ls gettext-*-done 2>/dev/null | sed 's/gettext-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_gettext_version" ] ; then
-            uninstall_gettext
-        fi
+        uninstall_gettext
 
         #
         # XXX - really remove this?
         # Or should we remember it as installed only if this script
         # installed it?
         #
-        installed_cmake_version=`ls cmake-*-done 2>/dev/null | sed 's/cmake-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_cmake_version" ]; then
-            uninstall_cmake
-        fi
+        uninstall_cmake
 
-        installed_libtool_version=`ls libtool-*-done 2>/dev/null | sed 's/libtool-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_libtool_version" ] ; then
-            uninstall_libtool
-        fi
+        uninstall_libtool
 
-        installed_automake_version=`ls automake-*-done 2>/dev/null | sed 's/automake-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_automake_version" ] ; then
-            uninstall_automake
-        fi
+        uninstall_automake
 
-        installed_autoconf_version=`ls autoconf-*-done 2>/dev/null | sed 's/autoconf-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_autoconf_version" ] ; then
-            uninstall_autoconf
-        fi
+        uninstall_autoconf
 
-        installed_xz_version=`ls xz-*-done 2>/dev/null | sed 's/xz-\(.*\)-done/\1/'`
-        if [ ! -z "$installed_xz_version" ] ; then
-            uninstall_xz
-        fi
+        uninstall_xz
     fi
 }
 
@@ -1317,6 +1316,40 @@ do
     esac
 done
 
+#
+# Get the version numbers of installed packages, if any.
+#
+if [ -d macosx-support-libs ]
+then
+    cd macosx-support-libs
+
+    installed_xz_version=`ls xz-*-done 2>/dev/null | sed 's/xz-\(.*\)-done/\1/'`
+    installed_autoconf_version=`ls autoconf-*-done 2>/dev/null | sed 's/autoconf-\(.*\)-done/\1/'`
+    installed_automake_version=`ls automake-*-done 2>/dev/null | sed 's/automake-\(.*\)-done/\1/'`
+    installed_libtool_version=`ls libtool-*-done 2>/dev/null | sed 's/libtool-\(.*\)-done/\1/'`
+    installed_cmake_version=`ls cmake-*-done 2>/dev/null | sed 's/cmake-\(.*\)-done/\1/'`
+    installed_gettext_version=`ls gettext-*-done 2>/dev/null | sed 's/gettext-\(.*\)-done/\1/'`
+    installed_pkg_config_version=`ls pkg-config-*-done 2>/dev/null | sed 's/pkg-config-\(.*\)-done/\1/'`
+    installed_glib_version=`ls glib-*-done 2>/dev/null | sed 's/glib-\(.*\)-done/\1/'`
+    installed_qt_version=`ls qt-*-done 2>/dev/null | sed 's/qt-\(.*\)-done/\1/'`
+    installed_libpng_version=`ls libpng-*-done 2>/dev/null | sed 's/libpng-\(.*\)-done/\1/'`
+    installed_pixman_version=`ls pixman-*-done 2>/dev/null | sed 's/pixman-\(.*\)-done/\1/'`
+    installed_cairo_version=`ls cairo-*-done 2>/dev/null | sed 's/cairo-\(.*\)-done/\1/'`
+    installed_atk_version=`ls atk-*-done 2>/dev/null | sed 's/atk-\(.*\)-done/\1/'`
+    installed_pango_version=`ls pango-*-done 2>/dev/null | sed 's/pango-\(.*\)-done/\1/'`
+    installed_gdk_pixbuf_version=`ls gdk-pixbuf-*-done 2>/dev/null | sed 's/gdk-pixbuf-\(.*\)-done/\1/'`
+    installed_gtk_version=`ls gtk+-*-done 2>/dev/null | sed 's/gtk+-\(.*\)-done/\1/'`
+    installed_libsmi_version=`ls libsmi-*-done 2>/dev/null | sed 's/libsmi-\(.*\)-done/\1/'`
+    installed_libgpg_error_version=`ls libgpg-error-*-done 2>/dev/null | sed 's/libgpg-error-\(.*\)-done/\1/'`
+    installed_libgcrypt_version=`ls libgcrypt-*-done 2>/dev/null | sed 's/libgcrypt-\(.*\)-done/\1/'`
+    installed_gnutls_version=`ls gnutls-*-done 2>/dev/null | sed 's/gnutls-\(.*\)-done/\1/'`
+    installed_lua_version=`ls lua-*-done 2>/dev/null | sed 's/lua-\(.*\)-done/\1/'`
+    installed_geoip_version=`ls geoip-*-done 2>/dev/null | sed 's/geoip-\(.*\)-done/\1/'`
+    installed_cares_version=`ls c-ares-*-done 2>/dev/null | sed 's/c-ares-\(.*\)-done/\1/'`
+
+    cd ..
+fi
+
 if [ "$do_uninstall" = "yes" ]
 then
     uninstall_all