[105085] branches/gsoc11-statistics/base

snc at macports.org snc at macports.org
Tue Apr 9 11:46:31 PDT 2013


Revision: 105085
          https://trac.macports.org/changeset/105085
Author:   snc at macports.org
Date:     2013-04-09 11:46:31 -0700 (Tue, 09 Apr 2013)
Log Message:
-----------
merge from trunk

Modified Paths:
--------------
    branches/gsoc11-statistics/base/ChangeLog
    branches/gsoc11-statistics/base/LICENSE
    branches/gsoc11-statistics/base/Makefile.in
    branches/gsoc11-statistics/base/NEWS
    branches/gsoc11-statistics/base/aclocal.m4
    branches/gsoc11-statistics/base/config/RELEASE_URL
    branches/gsoc11-statistics/base/config/macports_version
    branches/gsoc11-statistics/base/configure
    branches/gsoc11-statistics/base/configure.ac
    branches/gsoc11-statistics/base/doc/Makefile
    branches/gsoc11-statistics/base/doc/base.mtree.in
    branches/gsoc11-statistics/base/doc/macports.conf.5
    branches/gsoc11-statistics/base/doc/macports.conf.in
    branches/gsoc11-statistics/base/doc/port.1
    branches/gsoc11-statistics/base/doc/portfile.7
    branches/gsoc11-statistics/base/m4/tcl.m4
    branches/gsoc11-statistics/base/portmgr/ReleaseProcess
    branches/gsoc11-statistics/base/portmgr/dmg/License.html
    branches/gsoc11-statistics/base/portmgr/dmg/postflight
    branches/gsoc11-statistics/base/portmgr/jobs/mprsyncup
    branches/gsoc11-statistics/base/portmgr/jobs/port_binary_distributable.tcl
    branches/gsoc11-statistics/base/regen.sh
    branches/gsoc11-statistics/base/setupenv.bash.in
    branches/gsoc11-statistics/base/src/config.h.in
    branches/gsoc11-statistics/base/src/cregistry/entry.c
    branches/gsoc11-statistics/base/src/cregistry/entry.h
    branches/gsoc11-statistics/base/src/cregistry/file.c
    branches/gsoc11-statistics/base/src/cregistry/registry.c
    branches/gsoc11-statistics/base/src/cregistry/registry.h
    branches/gsoc11-statistics/base/src/cregistry/sql.c
    branches/gsoc11-statistics/base/src/cregistry/sql.h
    branches/gsoc11-statistics/base/src/cregistry/util.c
    branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c
    branches/gsoc11-statistics/base/src/images_to_archives.tcl
    branches/gsoc11-statistics/base/src/machista1.0/Makefile.in
    branches/gsoc11-statistics/base/src/machista1.0/libmachista.c
    branches/gsoc11-statistics/base/src/machista1.0/libmachista.h
    branches/gsoc11-statistics/base/src/machista1.0/machista.i
    branches/gsoc11-statistics/base/src/machista1.0/machista_wrap.c
    branches/gsoc11-statistics/base/src/machista1.0/tests/libmachista-test.c
    branches/gsoc11-statistics/base/src/macports1.0/macports.tcl
    branches/gsoc11-statistics/base/src/macports1.0/macports_autoconf.tcl.in
    branches/gsoc11-statistics/base/src/macports1.0/macports_dlist.tcl
    branches/gsoc11-statistics/base/src/macports1.0/macports_index.tcl
    branches/gsoc11-statistics/base/src/package1.0/Makefile
    branches/gsoc11-statistics/base/src/package1.0/package.tcl
    branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl
    branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl
    branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl
    branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl
    branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl
    branches/gsoc11-statistics/base/src/pextlib1.0/Pextlib.c
    branches/gsoc11-statistics/base/src/pextlib1.0/base32cmd.c
    branches/gsoc11-statistics/base/src/pextlib1.0/md_wrappers.h
    branches/gsoc11-statistics/base/src/pextlib1.0/rmd160cmd.c
    branches/gsoc11-statistics/base/src/pextlib1.0/system.c
    branches/gsoc11-statistics/base/src/pextlib1.0/tests/base32.tcl
    branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c
    branches/gsoc11-statistics/base/src/pextlib1.0/uid.c
    branches/gsoc11-statistics/base/src/port/port-help.tcl
    branches/gsoc11-statistics/base/src/port/port.tcl
    branches/gsoc11-statistics/base/src/port/portindex.tcl
    branches/gsoc11-statistics/base/src/port1.0/Makefile
    branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl
    branches/gsoc11-statistics/base/src/port1.0/port.tcl
    branches/gsoc11-statistics/base/src/port1.0/port_autoconf.tcl.in
    branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl
    branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl
    branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl
    branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl
    branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl
    branches/gsoc11-statistics/base/src/port1.0/portextract.tcl
    branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl
    branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl
    branches/gsoc11-statistics/base/src/port1.0/portlint.tcl
    branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl
    branches/gsoc11-statistics/base/src/port1.0/portload.tcl
    branches/gsoc11-statistics/base/src/port1.0/portmain.tcl
    branches/gsoc11-statistics/base/src/port1.0/portpatch.tcl
    branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl
    branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl
    branches/gsoc11-statistics/base/src/port1.0/portunload.tcl
    branches/gsoc11-statistics/base/src/port1.0/portutil.tcl
    branches/gsoc11-statistics/base/src/programs/daemondo/main.c
    branches/gsoc11-statistics/base/src/registry2.0/entry.c
    branches/gsoc11-statistics/base/src/registry2.0/graph.c
    branches/gsoc11-statistics/base/src/registry2.0/item.c
    branches/gsoc11-statistics/base/src/registry2.0/itemobj.c
    branches/gsoc11-statistics/base/src/registry2.0/portimage.tcl
    branches/gsoc11-statistics/base/src/registry2.0/portuninstall.tcl
    branches/gsoc11-statistics/base/src/registry2.0/receipt_flat.tcl
    branches/gsoc11-statistics/base/src/registry2.0/registry.c
    branches/gsoc11-statistics/base/src/registry2.0/registry.tcl
    branches/gsoc11-statistics/base/src/registry2.0/util.c
    branches/gsoc11-statistics/base/src/registry2.0/util.h
    branches/gsoc11-statistics/base/tests/Makefile
    branches/gsoc11-statistics/base/tests/test/checksums-1/master
    branches/gsoc11-statistics/base/tests/test/dependencies-c/master
    branches/gsoc11-statistics/base/tests/test/dependencies-d/master
    branches/gsoc11-statistics/base/tests/test/dependencies-e/master
    branches/gsoc11-statistics/base/tests/test/envvariables/master
    branches/gsoc11-statistics/base/tests/test/site-tags/master
    branches/gsoc11-statistics/base/tests/test/svn-and-patchsites/master
    branches/gsoc11-statistics/base/tests/test/trace/master
    branches/gsoc11-statistics/base/tests/test/variants/master
    branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile
    branches/gsoc11-statistics/base/tests/test/xcodeversion/master

Added Paths:
-----------
    branches/gsoc11-statistics/base/doc/archive_sites.conf
    branches/gsoc11-statistics/base/portmgr/dmg/Distribution
    branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl
    branches/gsoc11-statistics/base/src/port1.0/tests/common.tcl
    branches/gsoc11-statistics/base/src/port1.0/tests/portdestroot.tcl
    branches/gsoc11-statistics/base/src/port1.0/tests/portfetch.tcl
    branches/gsoc11-statistics/base/tests/test/statefile-unknown-version/
    branches/gsoc11-statistics/base/tests/test/statefile-version1/
    branches/gsoc11-statistics/base/tests/test/statefile-version1-outdated/
    branches/gsoc11-statistics/base/tests/test/statefile-version2/
    branches/gsoc11-statistics/base/tests/test/statefile-version2-invalid/
    branches/gsoc11-statistics/base/tests/test/statefile-version2-outdated/

Removed Paths:
-------------
    branches/gsoc11-statistics/base/src/package1.0/portportpkg.tcl
    branches/gsoc11-statistics/base/src/port1.0/portsubmit.tcl
    branches/gsoc11-statistics/base/src/portindex/

Property Changed:
----------------
    branches/gsoc11-statistics/base/


Property changes on: branches/gsoc11-statistics/base
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:78736-88411
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692
   + /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/gsoc11-rev-upgrade/base:78828-88375
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base:78736-105084
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692

Modified: branches/gsoc11-statistics/base/ChangeLog
===================================================================
--- branches/gsoc11-statistics/base/ChangeLog	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/ChangeLog	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,18 +3,251 @@
 # $Id$
 ###
 
-Unreleased changes:
+Release 2.2.0 (unreleased)
+    - Remove unsupported xpkg package type, xar-based format with XML.
+      (afb in r105002)
 
+    - Remove unimplemented 'port submit', remove XAR source packages.
+      (cal in r103400)
+
+    - Remove dependency_libs information from libtool libraries (.la).
+      (#38010, jmr in r102945)
+
+    - Add 'port space --total' which displays the grand total only.
+      (raimue in r102248)
+
+    - Added 'subport:' pseudo-portname that expands to ports that provide
+      a matching subport; added 'subportof:' pseudo-portname that expands to
+      the list of subports of the given port name
+      (raimue in r100059)
+
+    - Fixes bringing trace mode back to a working state. Improvements to reduce
+      the number of builds trace mode breaks.
+      (cal in r100071-100073, r100077, r100126, r100221)
+
+    - Began using sandbox-exec(1) on 10.5+ to prevent commands executed using
+      the 'system' procedure from writing files outside of the build directory
+      and selected other locations like /tmp. (jmr in r98156, r98193, etc.)
+
+Release 2.1.3 (2013-01-31 by jmr)
+    - Fixed a bug where a certain order of starting and aborting a build,
+      running selfupdate and continuing a build would resume building although
+      it should start from the beginning.
+      (#29223, cal in r96136, r96399, r96400, r96538)
+
+    - Fix permission problem in the creation of the ccache directory with
+      ccache >= 3.1.7 by running the initialization step as the macportsuser.
+      (raimue in r97868)
+
+    - Fix an endless loop that could be triggered in rev-upgrade when a broken
+      port is not in the index, e.g. when it has been deleted from the tree,
+      or it was installed directly from a Portfile not in the tree.
+      (cal in r100129, jmr in r101313)
+
+    - Set a busy timeout on SQLite connections to prevent MacPorts from
+      uselessly burning CPU cycles when waiting for a database lock.
+      (cal in r100217)
+
+    - Switch from exclusive locking to immediate locking in the registry
+      database to avoid locking reads where not needed.
+      (cal in r100218)
+
+    - Fix a problem where interrupting the uninstallation process could leave
+      the registry database in a corrupted state.
+      (#34482, cal in r100219)
+
+    - Fixed a failure in the fallback code used by 'port pkg' when
+      PackageMaker is not installed. (#36597, jmr in r96262)
+
+    - Fixed an incorrect lint error about the port directory name when a full
+      @macports.org maintainer address is used. (#35925, ryandesign in r97264)
+
+    - Fixed creation of disk images with flat packages. (jmr in r99167)
+
+    - Fixed a bug where not all requested variants would be passed on to
+      dependencies when building an mpkg. (#36363, jmr in r100679)
+
+    - Added configure.compiler options macports-clang-3.2 and
+      macports-clang-3.3 (jeremyhu, ryandesign, jmr in r92588, r101163,
+      r101166, r101270)
+
+    - Added configure.compiler options macports-dragonegg-3.0 through
+      macports-dragonegg-3.3. (jeremyhu in r101933)
+
+Release 2.1.2 (2012-07-26 by jmr):
+    - Fixed autodetection of developer_dir with Xcode 4.4
+      (#35150, mfeiri in r95552)
+
+    - Made conversion of images to archives more robust against missing images
+      (jmr in r95480)
+
+    - Support spaces in hg.tag when fetching from mercurial (#22684 comment
+      11,12, cal in r95438)
+
+    - Made mpkg fail when building a component pkg fails, instead of trying to
+      continue (jmr in r95382)
+
+    - Added a log message when everything to be installed has an unsatisfied
+      dependency, such as in the case of circular dependencies (jmr in r93962)
+
+    - Fixed incorrect error message when installing a port that has a
+      dependency that is not in the index (#31130, jmr in r93511)
+
+Release 2.1.1 (2012-05-19 by jmr):
+    - Fixed incorrect parsing of mirror group URLs that contain a colon to
+      indicate a port number (#32018, jmr in r93258)
+
+    - Do not print detailed progress information in rev-upgrade when stdout is
+      not a terminal (#34480, cal in r93221,r93222)
+
+    - Made rev-upgrade avoid trying to upgrade ports that are not in the index
+      (jmr in r93197)
+
+    - Fixed rev-upgrade disabling source-only mode in its first upgrade pass
+      (jmr in r93153)
+
+    - Fixed incorrect rebuild order in rev-upgrade (cal in r93129)
+
+    - Fixed port lookups failing for all sources when the index is missing in
+      one source (#30593, jmr in r92976)
+
+    - Fix database upgrade on Tiger, where SQLite doesn't support ALTER TABLE
+      ADD COLUMN (#34463, cal in r93256)
+
+Release 2.1.0 (2012-05-15 by jmr):
+    - New configure.compiler options: macports-clang-2.9, macports-clang-3.0,
+      macports-clang-3.1, macports-gcc-4.7, macports-gcc-4.8
+      (jeremyhu in r86719, ryandesign in r91521)
+
+    - Avoid using pkg-config to find sqlite3 in our configure script unless it
+      can't be found by other means, because some third-party packages
+      incorrectly install a /usr/bin/pkg-config that points to an incompatible
+      copy of sqlite3. (#30932, dluke/jmr in r91512)
+
+    - 'port pkg' and 'port mpkg' will now create flat packages (i.e. a xar
+      archive rather than a directory) on 10.6+.
+      (jmr in r91317, r91329, r91331, r91437)
+
+    - Fixed dependencies sometimes being installed multiple times when
+      required with different archs. (#31794, jmr in r91357)
+
+    - Build-time dependencies will no longer be installed if a prebuilt
+      archive is available for download (and port is configured to use it).
+      (jmr in r91196, r91217)
+
+    - Added new config file archive_sites.conf, which can be used to configure
+      additional archive download sources. Each source has an associated
+      archive type; portarchivetype is now only used when creating archives
+      locally. Sources also have an associated prefix, applications_dir and
+      frameworks_dir, and if any of these do not match the current values, the
+      source is not used. (jmr in r91009)
+
+    - Xcode 4.3 support: Search harder for developer directory; advise user to
+      run xcode-select when necessary, searching for Xcode and suggesting
+      xcode-select commands.
+      (jberry, jmr in r89970,r89971,r89972,r89996,r89999,r90003,r90005-r90009,
+      r90018-r90019,r90024,r90031)
+
+    - warn about non-existing developer_dir when it's set in macports.conf
+      (cal in 90802)
+
+    - port automatically installs bsdmake when there's no bsdmake in $PATH and a
+      port sets build.type bsd (#33355, cal in r90650)
+
+    - Added -W option for reinplace that sets a base directory that all file
+      arguments are interpreted as being relative to. (raimue in r90610)
+
+    - Added macports.conf options 'host_blacklist' and 'preferred_hosts', used
+      for indicating lists of download hosts that should not be used or should
+      be used preferentially, respectively. These override the usual ping time
+      check. Ping times are also now cached for 24 hours. (jmr in r89459)
+
+    - Added 'rev-upgrade' action checking for broken linkage and rebuilding
+      ports containing broken files. Made rev-upgrade run automatically after
+      each upgrade or install.
+      (cal in branch gsoc11-rev-upgrade, merge in r88376, also cal, raimue, jmr
+      in r88377,r88411,r88441,r88511,r88666,r88732,r89180,r89659,r89661,r90102,
+      r90381)
+
+    - Added options controlling rev-upgrade behavior to macports.conf
+      (jmr, cal in r88725,r88794,r89189)
+
     - port livecheck regex finds multiple matches on the same line
       (raimue in r88031)
 
-    - port lint now recognizes licenses (snc in r85929, r86016)
+    - Several improvements to port lint:
+      licenses, subversion properties, maintainer addresses
+      (#30194, snc, raimue in r85929, r86016, r89428, r89610)
 
+    - Added license_noconflict option to specify dependencies for which the
+      maintainer has manually checked license compatibility and wishes to
+      overrule the conservative automated checks. (jmr in r89004)
+
+    - Xcode 4.3 support: Use xcrun -find to find xcode compiler if it's not
+      found in /usr/bin.
+      (jberry, jmr in r88540,r88541,r88546,r88777,r88779,r88787,r89359,r89984,r90028)
+
+    - Added options compiler.blacklist, compiler.whitelist, and
+      compiler.fallback; to allow blacklisting, whitelisting, and setting the
+      fallback order for configure.compiler values, respectively.
+      (#30041, jmr in r88676)
+
+    - Fix sync with subdirectory of Subversion 1.7-format working copy
+      (#33573, jmr in 86872)
+
+    - Fixed conflicts not being checked for when installing ports that have no
+      dependencies. (#31571, dports in r85382)
+
+    - dmg postflight: quote all paths to handle the increasingly frequent
+      occurrence that $HOME contains spaces (#33583, ryandesign in r84345)
+
+    - dmg postflight: adjust wording of some messages (ryandesign in r84344)
+
+    - The deprecated Portfile options svn.tag, distcheck.check and
+      livecheck.check have been removed. (raimue in r82763)
+
     - Implement new option-replace using lsearch/lreplace. The old behavior is
       deprecated for option-replace with only one argument, but can still be
       found in option-strsed.
       (raimue in r82760, r82761)
 
+    - Added 'buildfromsource' macports.conf setting, which allows permanently
+      selecting the behaviour of the -s or -b option. (jmr in r81540)
+
+Release 2.0.4 (2012-02-25 by jmr)
+    - Added -locale option for reinplace (jeremyhu in r89839)
+
+    - Xcode 4.3 support: Change home directory for MacPorts user to
+      ${prefix}/var/macports/home.
+      (jberry, jmr in r89988, r89993, r90002, r90010, r90011)
+
+    - set env(HOME) to ${workpath}/.home when building ports
+      (#31827, jmr in r89994, r90004)
+
+    - Fix use_xmkmf to honor xmkmf.env for its make Makefiles phase
+      (#31504, jeremyhu in r89537, r89538, r89539)
+
+    - Added configure.cxx setting when configure.compiler is apple-gcc-4.2
+      (jeremyhu in r80248)
+
+    - Xcode 4.3 support: added packagemaker_path macports.conf setting
+      (jmr in r90058)
+
+    - Resolve ambiguity in selection in portlists
+      (jberry in r88179, r88185)
+
+    - Xcode 4.3 support: updated default developer_dir location for 4.3
+      (jmr in r90016)
+
+    - Xcode 4.3 support: use compilers in /usr/bin instead of developer_dir
+      when possible, as the latter has proven to be volatile.
+      (jmr in r90015)
+
+    - Xcode 4.3 support: updated SDK paths for 4.3 (jmr in r90000)
+
+    - Work around broken FTP proxy support in some versions of libcurl
+      (jmr in r84351, r88045)
+
 Release 2.0.3 (2011-09-05 by raimue)
     - Fix a regression introduced in 2.0.2 when fetching with a VCS
       (#31073, jmr in r83471)
@@ -179,8 +412,8 @@
     - Computing large dependency trees that contain the same port(s) multiple
       times should be considerably faster. (jmr in r73133)
 
-    - configure.compiler can now be set to macports-llvm-gcc-4.2 or
-      macports-clang (mfeiri in r72936, r72937)
+    - New configure.compiler options: macports-gcc-4.6, macports-llvm-gcc-4.2,
+      macports-clang (jmr in r71487; mfeiri in r72936, r72937)
 
     - Add '-n' option to reinplace (#26406, ryandesign in r73227)
 

Modified: branches/gsoc11-statistics/base/LICENSE
===================================================================
--- branches/gsoc11-statistics/base/LICENSE	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/LICENSE	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
 Copyright (c) 2002 - 2003, Apple Inc.
-Copyright (c) 2004 - 2011, The MacPorts Project.
+Copyright (c) 2004 - 2013, The MacPorts Project.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/Makefile.in
===================================================================
--- branches/gsoc11-statistics/base/Makefile.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/Makefile.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -32,9 +32,10 @@
 include Mk/macports.subdir.mk
 
 install::
-	[ ! -f $(DESTDIR)${sysconfdir}/macports/mp_version ] || rm -vf $(DESTDIR)${sysconfdir}/macports/mp_version
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 setupenv.bash  $(DESTDIR)${datadir}/macports/
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 macports-pubkey.pem  $(DESTDIR)${datadir}/macports/
+	[ ! -f "$(DESTDIR)${sysconfdir}/macports/mp_version" ] || rm -vf "$(DESTDIR)${sysconfdir}/macports/mp_version"
+	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} "$(DESTDIR)${datadir}/macports/"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 setupenv.bash  "$(DESTDIR)${datadir}/macports/"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 macports-pubkey.pem  "$(DESTDIR)${datadir}/macports/"
 	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 544 submitstats.sh $(DESTDIR)${datadir}/macports/
 # Install launchd script that runs submistats.sh
 	./setupstats.sh $(DESTDIR)${datadir}/macports/submitstats.sh $(DESTDIR)${sysconfdir}/macports/macports.conf
@@ -68,12 +69,20 @@
                 ${DSCL} -q . -create /Users/${RUNUSR} RealName MacPorts ; \
                 ${DSCL} -q . -create /Users/${RUNUSR} Password \* ; \
                 ${DSCL} -q . -create /Users/${RUNUSR} PrimaryGroupID $$(${DSCL} -q . -read /Groups/${RUNUSR} PrimaryGroupID | /usr/bin/awk '{print $$2}') ; \
-                ${DSCL} -q . -create /Users/${RUNUSR} NFSHomeDirectory /var/empty ; \
+                ${DSCL} -q . -create /Users/${RUNUSR} NFSHomeDirectory "${localstatedir}/macports/home" ; \
                 ${DSCL} -q . -create /Users/${RUNUSR} UserShell /usr/bin/false ; \
             else \
                 echo "Not creating user \"${RUNUSR}\" (not root)" ; \
             fi ; \
         fi ; \
+        if test "$$(${DSCL} -q . -read /Users/${RUNUSR} NFSHomeDirectory)" = "NFSHomeDirectory: /var/empty" ; then \
+            if test `id -u` -eq 0; then \
+                echo "Updating home directory location for user \"${RUNUSR}\"" ; \
+                ${DSCL} -q . -create /Users/${RUNUSR} NFSHomeDirectory "${localstatedir}/macports/home" ; \
+            else \
+                echo "Not updating home directory location for user \"${RUNUSR}\" (not root)" ; \
+            fi ; \
+        fi ; \
         if test `sw_vers -productVersion | /usr/bin/awk -F . '{print $$2}'` -eq 4 -a `id -u` -eq 0; then \
             GID=`${DSCL} -q . -read /Groups/${RUNUSR} PrimaryGroupID | /usr/bin/awk '{print $$2}'` ; \
             if test "`${DSCL} -q . -read /Users/${RUNUSR} PrimaryGroupID 2>/dev/null | /usr/bin/awk '{print $$2}'`" != "$$GID"; then \

Modified: branches/gsoc11-statistics/base/NEWS
===================================================================
--- branches/gsoc11-statistics/base/NEWS	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/NEWS	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,3 +1,41 @@
+== Overview of changes from MacPorts 2.0.4 to 2.1.0 ==
+
+# For regular users:
+
+*) New 'rev-upgrade' action that checks for and rebuilds ports that may have
+   become incorrectly linked when a dependency was upgraded to a new,
+   binary-incompatible version. This runs automatically after upgrades and
+   installs by default, and can be turned off or configured to only report
+   problems in macports.conf.
+
+*) The pkg and mpkg targets will create flat packages on 10.6+.
+
+*) Build-time dependencies will no longer be installed if a prebuilt
+   archive is available for download (and port is configured to use it).
+
+*) Config file archive_sites.conf can be used to download archives from
+   custom locations.
+
+*) 'buildfromsource' macports.conf option allows permanently choosing
+   source-only or binary-only mode.
+
+*) New macports.conf options 'host_blacklist' and 'preferred_hosts', for
+   controlling which download hosts will be used.
+
+# For Portfile writers:
+
+*) New -W option for reinplace that sets a base directory for all file
+   arguments.
+
+*) Livecheck can now find multiple regex matches on each line.
+
+*) license_noconflict option can be used to override automatic license
+   compatibility checks.
+
+*) compiler.whitelist, compiler.blacklist, and compiler.fallback options allow
+   simpler, detailed control over which compilers are used to build ports.
+
+
 == Overview of changes from MacPorts 1.9.2 to 2.0.0 ==
 
 # For regular users:
@@ -166,7 +204,7 @@
     builds (defaulting to no);
 *) Improved building of configure-based universal ports on Leopard;
 *) Fixed a bug by which the 'universal' variant would disappear if a 'macosx' variant was selected;
-*) Added a 'macosx_deployment_target' option to the main 'macports.conf' file for ports that benefit form this Mac OS X specific flag;
+*) Added a 'macosx_deployment_target' option to the main 'macports.conf' file for ports that benefit from this Mac OS X specific flag;
 *) Added a 'configurepipe' option to the main 'macports.conf' file for using pipes rather than intermediate files when compiling C/C++
     based ports;
 *) Removed LD_PREBIND & LD_PREBIND_ALLOW_OVERLAP variables from MacPorts' environment to prevent prebinding of binaries, which can be harmful

Modified: branches/gsoc11-statistics/base/aclocal.m4
===================================================================
--- branches/gsoc11-statistics/base/aclocal.m4	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/aclocal.m4	2013-04-09 18:46:31 UTC (rev 105085)
@@ -295,7 +295,7 @@
 	AC_MSG_CHECKING([that any existing MacPorts install can be upgraded])
 
 	eval dpversionfile="${sysconfdir}/ports/dp_version"
-	if test -f $dpversionfile; then
+	if test -f "$dpversionfile"; then
 		AC_MSG_ERROR([Existing MacPorts or DarwinPorts install is too old to be upgraded. Install MacPorts 1.7.1 first.])
 	else
 		AC_MSG_RESULT([yes])
@@ -810,21 +810,23 @@
 		   [  sqlite3prefix=$withval ])
 
 	if test "x$sqlite3prefix" = "x"; then
-		AC_PATH_PROG([PKG_CONFIG], [pkg-config])
-		if test "x$PKG_CONFIG" = "x" || ! $PKG_CONFIG --exists sqlite3; then
-		    # assume it's somewhere like /usr that needs no extra flags
-		    AC_CHECK_HEADER(sqlite3.h, [], [AC_MSG_ERROR([cannot find sqlite3 header])])
-            CFLAGS_SQLITE3=""
-		    LDFLAGS_SQLITE3="-lsqlite3"
-        else
-            CFLAGS_SQLITE3=$($PKG_CONFIG --cflags sqlite3)
-            LDFLAGS_SQLITE3=$($PKG_CONFIG --libs sqlite3)
-            # for tclsqlite below
-            mp_sqlite3_dir=$($PKG_CONFIG --variable=prefix sqlite3)
-            if test "x$mp_sqlite3_dir" != "x"; then
-                mp_sqlite3_dir=${mp_sqlite3_dir}/lib/sqlite3
-            fi
-        fi
+		# see if it's somewhere like /usr that needs no extra flags
+		LDFLAGS_SQLITE3="-lsqlite3"
+		AC_CHECK_HEADER(sqlite3.h, [],[
+		    # nope - try pkg-config
+			AC_PATH_PROG([PKG_CONFIG], [pkg-config])
+			if test "x$PKG_CONFIG" = "x" || ! $PKG_CONFIG --exists sqlite3; then
+				AC_MSG_ERROR([cannot find sqlite3 header])
+			else
+				CFLAGS_SQLITE3=$($PKG_CONFIG --cflags sqlite3)
+				LDFLAGS_SQLITE3=$($PKG_CONFIG --libs sqlite3)
+				# for tclsqlite below
+				mp_sqlite3_dir=$($PKG_CONFIG --variable=prefix sqlite3)
+            			if test "x$mp_sqlite3_dir" != "x"; then
+                			mp_sqlite3_dir=${mp_sqlite3_dir}/lib/sqlite3
+            			fi
+			fi
+		])
 	else
 	    CFLAGS_SQLITE3="-I${sqlite3prefix}/include"
 		LDFLAGS_SQLITE3="-L${sqlite3prefix}/lib -lsqlite3"
@@ -1064,3 +1066,75 @@
 	fi
 	AC_SUBST([CFLAGS_WERROR])
 ])
+
+#------------------------------------------------------------------------
+# MP_CHECK_SQLITE_VERSION --
+#
+#	Check for a specific SQLite version and execute commands depending on availability
+#
+# Arguments:
+#       Required SQLite version for the test to succeed in the form of SQLITE_VERSION_NUMBER
+#
+# Requires:
+#       MP_SQLITE3_FLAGS
+#
+# Depends:
+#		AC_LANG_SOURCE
+#
+# Results:
+#		Result is cached.
+#
+#       sets mp_sqlite_version_ge_$1 to yes or no
+#
+#------------------------------------------------------------------------
+AC_DEFUN(MP_CHECK_SQLITE_VERSION, [
+	AC_REQUIRE([MP_SQLITE3_FLAGS])
+
+	AC_MSG_CHECKING([for SQLite >= $1])
+
+	mp_check_sqlite_version_cppflags_save=$CPPFLAGS
+	CPPFLAGS="$CPPFLAGS $CFLAGS_SQLITE3"
+
+	AC_CACHE_VAL(mp_cv_sqlite_version_defined, [
+		AC_PREPROC_IFELSE(
+			[AC_LANG_SOURCE(
+				[[
+					#include <sqlite3.h>
+					#ifndef SQLITE_VERSION_NUMBER
+					#  error "SQLITE_VERSION_NUMBER undefined"
+					#endif
+				]]
+			)],
+			[mp_cv_sqlite_version_defined="yes"],
+			[AC_MSG_ERROR("SQLITE_VERSION_NUMBER undefined or sqlite3.h not found")]
+		)
+	])
+
+	if test x"${mp_cv_sqlite_version_defined}" = "xno"; then
+		AC_MSG_RESULT([SQLite version not found])
+		mp_sqlite_version_ge_$1="no"
+	else
+		AC_CACHE_VAL(mp_cv_sqlite_version_ge_$1, [
+			AC_PREPROC_IFELSE(
+				[AC_LANG_SOURCE(
+					[[
+						#include <sqlite3.h>
+						#if (SQLITE_VERSION_NUMBER >= $1)
+						/* Everything is fine */
+						#else
+						#  error "SQLite version too old"
+						#endif
+					]]
+				)],
+				[mp_cv_sqlite_version_ge_$1="yes"],
+				[mp_cv_sqlite_version_ge_$1="no"]
+			)
+		])
+
+		AC_MSG_RESULT(${mp_cv_sqlite_version_ge_$1})
+		mp_sqlite_version_ge_$1=${mp_cv_sqlite_version_ge_$1}
+	fi
+
+	CPPFLAGS=$mp_check_sqlite_version_cppflags_save
+])
+

Modified: branches/gsoc11-statistics/base/config/RELEASE_URL
===================================================================
--- branches/gsoc11-statistics/base/config/RELEASE_URL	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/config/RELEASE_URL	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1 +1 @@
-https://svn.macports.org/repository/macports/tags/release_2_0_3/base
+https://svn.macports.org/repository/macports/tags/release_2_1_3/base

Modified: branches/gsoc11-statistics/base/config/macports_version
===================================================================
--- branches/gsoc11-statistics/base/config/macports_version	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/config/macports_version	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1 +1 @@
-2.0.99
+2.1.99

Modified: branches/gsoc11-statistics/base/configure
===================================================================
--- branches/gsoc11-statistics/base/configure	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/configure	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,13 +1,11 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for MacPorts 2.0.99.
+# Generated by GNU Autoconf 2.69 for MacPorts 2.1.99.
 #
 # Report bugs to <macports-dev at lists.macosforge.org>.
 #
 #
-# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001,
-# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software
-# Foundation, Inc.
+# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
 #
 #
 # This configure script is free software; the Free Software Foundation
@@ -136,6 +134,31 @@
 # CDPATH.
 (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
 
+# Use a proper internal environment variable to ensure we don't fall
+  # into an infinite loop, continuously re-executing ourselves.
+  if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then
+    _as_can_reexec=no; export _as_can_reexec;
+    # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+as_fn_exit 255
+  fi
+  # We don't want this to propagate to other subprocesses.
+          { _as_can_reexec=; unset _as_can_reexec;}
 if test "x$CONFIG_SHELL" = x; then
   as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :
   emulate sh
@@ -169,7 +192,8 @@
 else
   exitcode=1; echo positional parameters were not saved.
 fi
-test x\$exitcode = x0 || exit 1"
+test x\$exitcode = x0 || exit 1
+test -x / || exit 1"
   as_suggested="  as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO
   as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO
   eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" &&
@@ -214,21 +238,25 @@
 
 
       if test "x$CONFIG_SHELL" != x; then :
-  # We cannot yet assume a decent shell, so we have to provide a
-	# neutralization value for shells without unset; and this also
-	# works around shells that cannot unset nonexistent variables.
-	# Preserve -v and -x to the replacement shell.
-	BASH_ENV=/dev/null
-	ENV=/dev/null
-	(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
-	export CONFIG_SHELL
-	case $- in # ((((
-	  *v*x* | *x*v* ) as_opts=-vx ;;
-	  *v* ) as_opts=-v ;;
-	  *x* ) as_opts=-x ;;
-	  * ) as_opts= ;;
-	esac
-	exec "$CONFIG_SHELL" $as_opts "$as_myself" ${1+"$@"}
+  export CONFIG_SHELL
+             # We cannot yet assume a decent shell, so we have to provide a
+# neutralization value for shells without unset; and this also
+# works around shells that cannot unset nonexistent variables.
+# Preserve -v and -x to the replacement shell.
+BASH_ENV=/dev/null
+ENV=/dev/null
+(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV
+case $- in # ((((
+  *v*x* | *x*v* ) as_opts=-vx ;;
+  *v* ) as_opts=-v ;;
+  *x* ) as_opts=-x ;;
+  * ) as_opts= ;;
+esac
+exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"}
+# Admittedly, this is quite paranoid, since all the known shells bail
+# out after a failed `exec'.
+$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2
+exit 255
 fi
 
     if test x$as_have_required = xno; then :
@@ -331,6 +359,14 @@
 
 
 } # as_fn_mkdir_p
+
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
 # as_fn_append VAR VALUE
 # ----------------------
 # Append the text in VALUE to the end of the definition contained in VAR. Take
@@ -452,6 +488,10 @@
   chmod +x "$as_me.lineno" ||
     { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; }
 
+  # If we had to re-execute with $CONFIG_SHELL, we're ensured to have
+  # already done that, so ensure we don't try to do so again and fall
+  # in an infinite loop.  This has already happened in practice.
+  _as_can_reexec=no; export _as_can_reexec
   # Don't try to exec as it changes $[0], causing all sort of problems
   # (the dirname of $[0] is not the place where we might find the
   # original and so on.  Autoconf is especially sensitive to this).
@@ -486,16 +526,16 @@
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -p'.
+    # In both cases, we have to default to `cp -pR'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -p'
+      as_ln_s='cp -pR'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -p'
+    as_ln_s='cp -pR'
   fi
 else
-  as_ln_s='cp -p'
+  as_ln_s='cp -pR'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -507,28 +547,8 @@
   as_mkdir_p=false
 fi
 
-if test -x / >/dev/null 2>&1; then
-  as_test_x='test -x'
-else
-  if ls -dL / >/dev/null 2>&1; then
-    as_ls_L_option=L
-  else
-    as_ls_L_option=
-  fi
-  as_test_x='
-    eval sh -c '\''
-      if test -d "$1"; then
-	test -d "$1/.";
-      else
-	case $1 in #(
-	-*)set "./$1";;
-	esac;
-	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
-	???[sx]*):;;*)false;;esac;fi
-    '\'' sh
-  '
-fi
-as_executable_p=$as_test_x
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
 
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
@@ -560,8 +580,8 @@
 # Identity of this package.
 PACKAGE_NAME='MacPorts'
 PACKAGE_TARNAME='macports'
-PACKAGE_VERSION='2.0.99'
-PACKAGE_STRING='MacPorts 2.0.99'
+PACKAGE_VERSION='2.1.99'
+PACKAGE_STRING='MacPorts 2.1.99'
 PACKAGE_BUGREPORT='macports-dev at lists.macosforge.org'
 PACKAGE_URL=''
 
@@ -679,55 +699,60 @@
 TAR_CMD
 TAR_Q
 SED_EXT
-SWIG
-OPEN
-XAR
-PAX
-MKBOM
-LSBOM
+HAVE_LAUNCHD
+ZIP
 XZ
-LZMA
-BZIP2
-GNUPATCH
-GNUMAKE
-GNUTAR
+XCRUN
 XCODEBUILD
-LAUNCHCTL
-HAVE_LAUNCHD
-HDIUTIL
-MAKE
-BSDMAKE
-ZIP
+XAR
 UNZIP
 TAR
+SWIG
+SVN
 SED
-OPENSSL
+SANDBOX_EXEC
 RSYNC
 RMDIR
+PAX
 PATCH
+OPENSSL
+OPEN
+MTREE
+MKBOM
+MDLS
+MDFIND
+MAKE
+LZMA
+LSBOM
 LIPO
+LAUNCHCTL
+HG
+HDIUTIL
 GZIP
-HG
+GNUTAR
+GNUPATCH
+GNUMAKE
 GIT
-SVN
-CVS
-BZR
+FIND
 FILE
 DSEDITGROUP
 DSCL
 DIFF
+CVS
 CPIO
 CP
 CHOWN
-MTREE
+BZR
+BZIP2
+BSDMAKE
+ac_ct_OBJC
+OBJCFLAGS
+OBJC
+SET_MAKE
 LN_S
-SET_MAKE
 INSTALL_DATA
 INSTALL_SCRIPT
 INSTALL_PROGRAM
-ac_ct_OBJC
-OBJCFLAGS
-OBJC
 OBJEXT
 EXEEXT
 ac_ct_CC
@@ -830,23 +855,23 @@
 CPPFLAGS
 OBJC
 OBJCFLAGS
+BSDMAKE
+BZIP2
+CVS
+GNUMAKE
+GNUTAR
+LZMA
+MAKE
 MTREE
-CVS
-SVN
+OPEN
 OPENSSL
 RSYNC
 SED
+SVN
+SWIG
 TAR
-MAKE
-GNUTAR
-BSDMAKE
-GNUMAKE
-BZIP2
-LZMA
+XAR
 XZ
-XAR
-OPEN
-SWIG
 OBJCPP
 CPP'
 ac_subdirs_all='src/thread2.6'
@@ -1304,8 +1329,6 @@
 if test "x$host_alias" != x; then
   if test "x$build_alias" = x; then
     cross_compiling=maybe
-    $as_echo "$as_me: WARNING: if you wanted to set the --build type, don't use --host.
-    If a cross compiler is detected then cross compile mode will be used" >&2
   elif test "x$build_alias" != "x$host_alias"; then
     cross_compiling=yes
   fi
@@ -1391,7 +1414,7 @@
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures MacPorts 2.0.99 to adapt to many kinds of systems.
+\`configure' configures MacPorts 2.1.99 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1457,7 +1480,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of MacPorts 2.0.99:";;
+     short | recursive ) echo "Configuration of MacPorts 2.1.99:";;
    esac
   cat <<\_ACEOF
 
@@ -1517,23 +1540,23 @@
               you have headers in a nonstandard directory <include dir>
   OBJC        Objective C compiler command
   OBJCFLAGS   Objective C compiler flags
+  BSDMAKE     path to bsdmake/pmake command
+  BZIP2       path to bzip2 command
+  CVS         path to cvs command
+  GNUMAKE     path to gnumake command
+  GNUTAR      path to gnutar command
+  LZMA        path to lzma command
+  MAKE        path to make command
   MTREE       path to mtree command
-  CVS         path to cvs command
-  SVN         path to svn command
+  OPEN        path to open command
   OPENSSL     path to openssl command
   RSYNC       path to rsync command
   SED         path to sed command
+  SVN         path to svn command
+  SWIG        path to swig command
   TAR         path to tar command
-  MAKE        path to make command
-  GNUTAR      path to gnutar command
-  BSDMAKE     path to bsdmake/pmake command
-  GNUMAKE     path to gnumake command
-  BZIP2       path to bzip2 command
-  LZMA        path to lzma command
+  XAR         path to xar command
   XZ          path to xz command
-  XAR         path to xar command
-  OPEN        path to open command
-  SWIG        path to swig command
   OBJCPP      Objective C preprocessor
   CPP         C preprocessor
 
@@ -1603,10 +1626,10 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-MacPorts configure 2.0.99
-generated by GNU Autoconf 2.68
+MacPorts configure 2.1.99
+generated by GNU Autoconf 2.69
 
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 _ACEOF
@@ -1720,7 +1743,7 @@
 	 test ! -s conftest.err
        } && test -s conftest$ac_exeext && {
 	 test "$cross_compiling" = yes ||
-	 $as_test_x conftest$ac_exeext
+	 test -x conftest$ac_exeext
        }; then :
   ac_retval=0
 else
@@ -1967,7 +1990,7 @@
 	 test ! -s conftest.err
        } && test -s conftest$ac_exeext && {
 	 test "$cross_compiling" = yes ||
-	 $as_test_x conftest$ac_exeext
+	 test -x conftest$ac_exeext
        }; then :
   ac_retval=0
 else
@@ -2272,8 +2295,8 @@
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by MacPorts $as_me 2.0.99, which was
-generated by GNU Autoconf 2.68.  Invocation command line was
+It was created by MacPorts $as_me 2.1.99, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
 
   $ $0 $@
 
@@ -2767,7 +2790,7 @@
 # Read in the MacPorts version from the base/config/macports_version file
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking MacPorts version" >&5
 $as_echo_n "checking MacPorts version... " >&6; }
-MACPORTS_VERSION=2.0.99
+MACPORTS_VERSION=2.1.99
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MACPORTS_VERSION" >&5
 $as_echo "$MACPORTS_VERSION" >&6; }
 
@@ -2817,7 +2840,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_SW_VERS="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2857,7 +2880,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_DEFAULTS="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2897,7 +2920,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_XCODE_SELECT="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -2933,36 +2956,49 @@
     as_fn_error $? "This version of Mac OS X is not supported
                   Please upgrade at http://store.apple.com/" "$LINENO" 5
     ;;
-  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7])
+  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-4]|10.8.[0-1])
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: This version of Mac OS X is out of date" >&5
 $as_echo "$as_me: WARNING: This version of Mac OS X is out of date" >&2;}
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please run Software Update to update it" >&5
 $as_echo "$as_me: WARNING: Please run Software Update to update it" >&2;}
     ;;
-  10.4*|10.5*|10.6*|10.7*)
+  10.4*|10.5*|10.6*|10.7*|10.8*)
         ;;
   *)
     ;;
 esac
 
 # locate currently selected Xcode path
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking Xcode location" >&5
+$as_echo_n "checking Xcode location... " >&6; }
 if test "x$XCODE_SELECT" != "x"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking Xcode location" >&5
-$as_echo_n "checking Xcode location... " >&6; }
   DEVELOPER_DIR=`$XCODE_SELECT -print-path`
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DEVELOPER_DIR" >&5
+fi
+if test -z "$DEVELOPER_DIR" -o ! -d "$DEVELOPER_DIR" ; then
+    if test -d /Applications/Xcode.app/Contents/Developer ; then
+        DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
+    else
+        DEVELOPER_DIR=/Developer
+    fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $DEVELOPER_DIR" >&5
 $as_echo "$DEVELOPER_DIR" >&6; }
-else
-  DEVELOPER_DIR=/Developer
-fi
 
 
-XCODEPLIST=$DEVELOPER_DIR/Applications/Xcode.app/Contents/version.plist
+case "$DEVELOPER_DIR" in
+  *Xcode.app/Contents/Developer)
+    XCODEPLIST_BASE=`dirname $DEVELOPER_DIR`/version
+    ;;
+  *)
+    XCODEPLIST_BASE=$DEVELOPER_DIR/Applications/Xcode.app/Contents/version
+    ;;
+esac
+XCODEPLIST=${XCODEPLIST_BASE}.plist
 if test -r "$XCODEPLIST"; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking Xcode version" >&5
 $as_echo_n "checking Xcode version... " >&6; }
   if test "x$DEFAULTS" != "x"; then
-    XCODE_VERSION=`$DEFAULTS read $DEVELOPER_DIR/Applications/Xcode.app/Contents/version CFBundleShortVersionString`
+    XCODE_VERSION=`$DEFAULTS read $XCODEPLIST_BASE CFBundleShortVersionString`
   else
     XCODE_VERSION=`tr -d '\r\n' < $XCODEPLIST | sed -e 's/.*<key>CFBundleShortVersionString<\/key>.<string>\([0-9.]*\)<\/string>.*/\1/'`
   fi
@@ -3016,7 +3052,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_CC="${ac_tool_prefix}gcc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3056,7 +3092,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_ac_ct_CC="gcc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3109,7 +3145,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_CC="${ac_tool_prefix}cc"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3150,7 +3186,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
        ac_prog_rejected=yes
        continue
@@ -3208,7 +3244,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3252,7 +3288,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_ac_ct_CC="$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3698,8 +3734,7 @@
 /* end confdefs.h.  */
 #include <stdarg.h>
 #include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+struct stat;
 /* Most of the following tests are stolen from RCS 5.7's src/conf.sh.  */
 struct buf { int x; };
 FILE * (*rcsopen) (struct buf *, struct stat *, int);
@@ -3784,6 +3819,141 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+# Find a good install program.  We prefer a C program (faster),
+# so one script is as good as another.  But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+# Reject install programs that cannot install multiple files.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
+$as_echo_n "checking for a BSD-compatible install... " >&6; }
+if test -z "$INSTALL"; then
+if ${ac_cv_path_install+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in #((
+  ./ | .// | /[cC]/* | \
+  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
+  /usr/ucb/* ) ;;
+  *)
+    # OSF1 and SCO ODT 3.0 have their own names for install.
+    # Don't use installbsd from OSF since it installs stuff as root
+    # by default.
+    for ac_prog in ginstall scoinst install; do
+      for ac_exec_ext in '' $ac_executable_extensions; do
+	if as_fn_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+	  if test $ac_prog = install &&
+	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # AIX install.  It has an incompatible calling convention.
+	    :
+	  elif test $ac_prog = install &&
+	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+	    # program-specific install script used by HP pwplus--don't use.
+	    :
+	  else
+	    rm -rf conftest.one conftest.two conftest.dir
+	    echo one > conftest.one
+	    echo two > conftest.two
+	    mkdir conftest.dir
+	    if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
+	      test -s conftest.one && test -s conftest.two &&
+	      test -s conftest.dir/conftest.one &&
+	      test -s conftest.dir/conftest.two
+	    then
+	      ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+	      break 3
+	    fi
+	  fi
+	fi
+      done
+    done
+    ;;
+esac
+
+  done
+IFS=$as_save_IFS
+
+rm -rf conftest.one conftest.two conftest.dir
+
+fi
+  if test "${ac_cv_path_install+set}" = set; then
+    INSTALL=$ac_cv_path_install
+  else
+    # As a last resort, use the slow shell script.  Don't cache a
+    # value for INSTALL within a source directory, because that will
+    # break other packages using the cache if that directory is
+    # removed, or if the value is a relative name.
+    INSTALL=$ac_install_sh
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
+$as_echo "$INSTALL" >&6; }
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
+$as_echo_n "checking whether ln -s works... " >&6; }
+LN_S=$as_ln_s
+if test "$LN_S" = "ln -s"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
+$as_echo "no, using $LN_S" >&6; }
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
+$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
+set x ${MAKE-make}
+ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
+if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat >conftest.make <<\_ACEOF
+SHELL = /bin/sh
+all:
+	@echo '@@@%%%=$(MAKE)=@@@%%%'
+_ACEOF
+# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
+case `${MAKE-make} -f conftest.make 2>/dev/null` in
+  *@@@%%%=?*=@@@%%%*)
+    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  *)
+    eval ac_cv_prog_make_${ac_make}_set=no;;
+esac
+rm -f conftest.make
+fi
+if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+  SET_MAKE=
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+  SET_MAKE="MAKE=${MAKE-make}"
+fi
+
 ac_ext=m
 ac_cpp='$OBJCPP $CPPFLAGS'
 ac_compile='$OBJC -c $OBJCFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -3808,7 +3978,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_OBJC="$ac_tool_prefix$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -3852,7 +4022,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_ac_ct_OBJC="$ac_prog"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4035,162 +4205,112 @@
 ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
-# Find a good install program.  We prefer a C program (faster),
-# so one script is as good as another.  But avoid the broken or
-# incompatible versions:
-# SysV /etc/install, /usr/sbin/install
-# SunOS /usr/etc/install
-# IRIX /sbin/install
-# AIX /bin/install
-# AmigaOS /C/install, which installs bootblocks on floppy discs
-# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
-# AFS /usr/afsws/bin/install, which mishandles nonexistent args
-# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
-# OS/2's system install, which has a completely different semantic
-# ./install, which can be erroneously created by make from ./install.sh.
-# Reject install programs that cannot install multiple files.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for a BSD-compatible install" >&5
-$as_echo_n "checking for a BSD-compatible install... " >&6; }
-if test -z "$INSTALL"; then
-if ${ac_cv_path_install+:} false; then :
+
+for ac_prog in bsdmake pmake
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_BSDMAKE+:} false; then :
   $as_echo_n "(cached) " >&6
 else
+  case $BSDMAKE in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_BSDMAKE="$BSDMAKE" # Let the user override the test with a path.
+  ;;
+  *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
-    # Account for people who put trailing slashes in PATH elements.
-case $as_dir/ in #((
-  ./ | .// | /[cC]/* | \
-  /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
-  ?:[\\/]os2[\\/]install[\\/]* | ?:[\\/]OS2[\\/]INSTALL[\\/]* | \
-  /usr/ucb/* ) ;;
-  *)
-    # OSF1 and SCO ODT 3.0 have their own names for install.
-    # Don't use installbsd from OSF since it installs stuff as root
-    # by default.
-    for ac_prog in ginstall scoinst install; do
-      for ac_exec_ext in '' $ac_executable_extensions; do
-	if { test -f "$as_dir/$ac_prog$ac_exec_ext" && $as_test_x "$as_dir/$ac_prog$ac_exec_ext"; }; then
-	  if test $ac_prog = install &&
-	    grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
-	    # AIX install.  It has an incompatible calling convention.
-	    :
-	  elif test $ac_prog = install &&
-	    grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
-	    # program-specific install script used by HP pwplus--don't use.
-	    :
-	  else
-	    rm -rf conftest.one conftest.two conftest.dir
-	    echo one > conftest.one
-	    echo two > conftest.two
-	    mkdir conftest.dir
-	    if "$as_dir/$ac_prog$ac_exec_ext" -c conftest.one conftest.two "`pwd`/conftest.dir" &&
-	      test -s conftest.one && test -s conftest.two &&
-	      test -s conftest.dir/conftest.one &&
-	      test -s conftest.dir/conftest.two
-	    then
-	      ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
-	      break 3
-	    fi
-	  fi
-	fi
-      done
-    done
-    ;;
-esac
-
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_BSDMAKE="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
   done
 IFS=$as_save_IFS
 
-rm -rf conftest.one conftest.two conftest.dir
-
+  ;;
+esac
 fi
-  if test "${ac_cv_path_install+set}" = set; then
-    INSTALL=$ac_cv_path_install
-  else
-    # As a last resort, use the slow shell script.  Don't cache a
-    # value for INSTALL within a source directory, because that will
-    # break other packages using the cache if that directory is
-    # removed, or if the value is a relative name.
-    INSTALL=$ac_install_sh
-  fi
+BSDMAKE=$ac_cv_path_BSDMAKE
+if test -n "$BSDMAKE"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BSDMAKE" >&5
+$as_echo "$BSDMAKE" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
 fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $INSTALL" >&5
-$as_echo "$INSTALL" >&6; }
 
-# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
-# It thinks the first close brace ends the variable substitution.
-test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
 
-test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+  test -n "$BSDMAKE" && break
+done
 
-test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
-
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${MAKE-make} sets \$(MAKE)" >&5
-$as_echo_n "checking whether ${MAKE-make} sets \$(MAKE)... " >&6; }
-set x ${MAKE-make}
-ac_make=`$as_echo "$2" | sed 's/+/p/g; s/[^a-zA-Z0-9_]/_/g'`
-if eval \${ac_cv_prog_make_${ac_make}_set+:} false; then :
+# Extract the first word of "bzip2", so it can be a program name with args.
+set dummy bzip2; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_BZIP2+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  cat >conftest.make <<\_ACEOF
-SHELL = /bin/sh
-all:
-	@echo '@@@%%%=$(MAKE)=@@@%%%'
-_ACEOF
-# GNU make sometimes prints "make[1]: Entering ...", which would confuse us.
-case `${MAKE-make} -f conftest.make 2>/dev/null` in
-  *@@@%%%=?*=@@@%%%*)
-    eval ac_cv_prog_make_${ac_make}_set=yes;;
+  case $BZIP2 in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_BZIP2="$BZIP2" # Let the user override the test with a path.
+  ;;
   *)
-    eval ac_cv_prog_make_${ac_make}_set=no;;
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_BZIP2="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
 esac
-rm -f conftest.make
 fi
-if eval test \$ac_cv_prog_make_${ac_make}_set = yes; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-  SET_MAKE=
+BZIP2=$ac_cv_path_BZIP2
+if test -n "$BZIP2"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BZIP2" >&5
+$as_echo "$BZIP2" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-  SET_MAKE="MAKE=${MAKE-make}"
 fi
 
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ln -s works" >&5
-$as_echo_n "checking whether ln -s works... " >&6; }
-LN_S=$as_ln_s
-if test "$LN_S" = "ln -s"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-else
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no, using $LN_S" >&5
-$as_echo "no, using $LN_S" >&6; }
-fi
 
-# Extract the first word of "mtree", so it can be a program name with args.
-set dummy mtree; ac_word=$2
+# Extract the first word of "bzr", so it can be a program name with args.
+set dummy bzr; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_MTREE+:} false; then :
+if ${ac_cv_path_BZR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MTREE in
+  case $BZR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_MTREE="$MTREE" # Let the user override the test with a path.
+  ac_cv_path_BZR="$BZR" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="$PATH:/usr/sbin"
-for as_dir in $as_dummy
+for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_MTREE="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_BZR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4201,10 +4321,10 @@
   ;;
 esac
 fi
-MTREE=$ac_cv_path_MTREE
-if test -n "$MTREE"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MTREE" >&5
-$as_echo "$MTREE" >&6; }
+BZR=$ac_cv_path_BZR
+if test -n "$BZR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BZR" >&5
+$as_echo "$BZR" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
@@ -4230,7 +4350,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_CHOWN="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4270,7 +4390,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_CP="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4310,7 +4430,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_CPIO="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4332,6 +4452,46 @@
 fi
 
 
+# Extract the first word of "cvs", so it can be a program name with args.
+set dummy cvs; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_CVS+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $CVS in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_CVS="$CVS" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_CVS="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+CVS=$ac_cv_path_CVS
+if test -n "$CVS"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CVS" >&5
+$as_echo "$CVS" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
 # Extract the first word of "diff", so it can be a program name with args.
 set dummy diff; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -4350,7 +4510,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_DIFF="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4390,7 +4550,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_DSCL="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4430,7 +4590,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_DSEDITGROUP="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4470,7 +4630,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_FILE="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4492,16 +4652,16 @@
 fi
 
 
-# Extract the first word of "bzr", so it can be a program name with args.
-set dummy bzr; ac_word=$2
+# Extract the first word of "find", so it can be a program name with args.
+set dummy find; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_BZR+:} false; then :
+if ${ac_cv_path_FIND+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $BZR in
+  case $FIND in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_BZR="$BZR" # Let the user override the test with a path.
+  ac_cv_path_FIND="$FIND" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4510,8 +4670,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_BZR="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_FIND="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4522,26 +4682,26 @@
   ;;
 esac
 fi
-BZR=$ac_cv_path_BZR
-if test -n "$BZR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BZR" >&5
-$as_echo "$BZR" >&6; }
+FIND=$ac_cv_path_FIND
+if test -n "$FIND"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $FIND" >&5
+$as_echo "$FIND" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "cvs", so it can be a program name with args.
-set dummy cvs; ac_word=$2
+# Extract the first word of "git", so it can be a program name with args.
+set dummy git; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_CVS+:} false; then :
+if ${ac_cv_path_GIT+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $CVS in
+  case $GIT in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_CVS="$CVS" # Let the user override the test with a path.
+  ac_cv_path_GIT="$GIT" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4550,8 +4710,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_CVS="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_GIT="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4562,36 +4722,39 @@
   ;;
 esac
 fi
-CVS=$ac_cv_path_CVS
-if test -n "$CVS"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CVS" >&5
-$as_echo "$CVS" >&6; }
+GIT=$ac_cv_path_GIT
+if test -n "$GIT"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GIT" >&5
+$as_echo "$GIT" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "svn", so it can be a program name with args.
-set dummy svn; ac_word=$2
+for ac_prog in gnumake gmake
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_SVN+:} false; then :
+if ${ac_cv_path_GNUMAKE+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $SVN in
+  case $GNUMAKE in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_SVN="$SVN" # Let the user override the test with a path.
+  ac_cv_path_GNUMAKE="$GNUMAKE" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
+as_dummy="$PATH:/usr/local/bin"
+for as_dir in $as_dummy
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_SVN="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_GNUMAKE="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4602,36 +4765,42 @@
   ;;
 esac
 fi
-SVN=$ac_cv_path_SVN
-if test -n "$SVN"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SVN" >&5
-$as_echo "$SVN" >&6; }
+GNUMAKE=$ac_cv_path_GNUMAKE
+if test -n "$GNUMAKE"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GNUMAKE" >&5
+$as_echo "$GNUMAKE" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "git", so it can be a program name with args.
-set dummy git; ac_word=$2
+  test -n "$GNUMAKE" && break
+done
+
+for ac_prog in gnupatch gpatch
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_GIT+:} false; then :
+if ${ac_cv_path_GNUPATCH+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GIT in
+  case $GNUPATCH in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GIT="$GIT" # Let the user override the test with a path.
+  ac_cv_path_GNUPATCH="$GNUPATCH" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
+as_dummy="$PATH:/usr/local/bin"
+for as_dir in $as_dummy
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_GIT="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_GNUPATCH="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4642,36 +4811,42 @@
   ;;
 esac
 fi
-GIT=$ac_cv_path_GIT
-if test -n "$GIT"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GIT" >&5
-$as_echo "$GIT" >&6; }
+GNUPATCH=$ac_cv_path_GNUPATCH
+if test -n "$GNUPATCH"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GNUPATCH" >&5
+$as_echo "$GNUPATCH" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "hg", so it can be a program name with args.
-set dummy hg; ac_word=$2
+  test -n "$GNUPATCH" && break
+done
+
+for ac_prog in gnutar gtar
+do
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_HG+:} false; then :
+if ${ac_cv_path_GNUTAR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $HG in
+  case $GNUTAR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_HG="$HG" # Let the user override the test with a path.
+  ac_cv_path_GNUTAR="$GNUTAR" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
+as_dummy="$PATH:/usr/local/bin"
+for as_dir in $as_dummy
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_HG="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_GNUTAR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4682,16 +4857,19 @@
   ;;
 esac
 fi
-HG=$ac_cv_path_HG
-if test -n "$HG"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HG" >&5
-$as_echo "$HG" >&6; }
+GNUTAR=$ac_cv_path_GNUTAR
+if test -n "$GNUTAR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GNUTAR" >&5
+$as_echo "$GNUTAR" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
+  test -n "$GNUTAR" && break
+done
+
 # Extract the first word of "gzip", so it can be a program name with args.
 set dummy gzip; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -4710,7 +4888,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_GZIP="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -4732,16 +4910,16 @@
 fi
 
 
-# Extract the first word of "lipo", so it can be a program name with args.
-set dummy lipo; ac_word=$2
+# Extract the first word of "hdiutil", so it can be a program name with args.
+set dummy hdiutil; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_LIPO+:} false; then :
+if ${ac_cv_path_HDIUTIL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $LIPO in
+  case $HDIUTIL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_LIPO="$LIPO" # Let the user override the test with a path.
+  ac_cv_path_HDIUTIL="$HDIUTIL" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4750,8 +4928,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_LIPO="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_HDIUTIL="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4762,26 +4940,26 @@
   ;;
 esac
 fi
-LIPO=$ac_cv_path_LIPO
-if test -n "$LIPO"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5
-$as_echo "$LIPO" >&6; }
+HDIUTIL=$ac_cv_path_HDIUTIL
+if test -n "$HDIUTIL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HDIUTIL" >&5
+$as_echo "$HDIUTIL" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "patch", so it can be a program name with args.
-set dummy patch; ac_word=$2
+# Extract the first word of "hg", so it can be a program name with args.
+set dummy hg; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_PATCH+:} false; then :
+if ${ac_cv_path_HG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $PATCH in
+  case $HG in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_PATCH="$PATCH" # Let the user override the test with a path.
+  ac_cv_path_HG="$HG" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4790,8 +4968,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_PATCH="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_HG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4802,26 +4980,26 @@
   ;;
 esac
 fi
-PATCH=$ac_cv_path_PATCH
-if test -n "$PATCH"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PATCH" >&5
-$as_echo "$PATCH" >&6; }
+HG=$ac_cv_path_HG
+if test -n "$HG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HG" >&5
+$as_echo "$HG" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "rmdir", so it can be a program name with args.
-set dummy rmdir; ac_word=$2
+# Extract the first word of "launchctl", so it can be a program name with args.
+set dummy launchctl; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_RMDIR+:} false; then :
+if ${ac_cv_path_LAUNCHCTL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $RMDIR in
+  case $LAUNCHCTL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_RMDIR="$RMDIR" # Let the user override the test with a path.
+  ac_cv_path_LAUNCHCTL="$LAUNCHCTL" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4830,8 +5008,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_RMDIR="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_LAUNCHCTL="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4842,26 +5020,26 @@
   ;;
 esac
 fi
-RMDIR=$ac_cv_path_RMDIR
-if test -n "$RMDIR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RMDIR" >&5
-$as_echo "$RMDIR" >&6; }
+LAUNCHCTL=$ac_cv_path_LAUNCHCTL
+if test -n "$LAUNCHCTL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LAUNCHCTL" >&5
+$as_echo "$LAUNCHCTL" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "rsync", so it can be a program name with args.
-set dummy rsync; ac_word=$2
+# Extract the first word of "lipo", so it can be a program name with args.
+set dummy lipo; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_RSYNC+:} false; then :
+if ${ac_cv_path_LIPO+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $RSYNC in
+  case $LIPO in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_RSYNC="$RSYNC" # Let the user override the test with a path.
+  ac_cv_path_LIPO="$LIPO" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4870,8 +5048,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_RSYNC="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_LIPO="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4882,26 +5060,26 @@
   ;;
 esac
 fi
-RSYNC=$ac_cv_path_RSYNC
-if test -n "$RSYNC"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RSYNC" >&5
-$as_echo "$RSYNC" >&6; }
+LIPO=$ac_cv_path_LIPO
+if test -n "$LIPO"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIPO" >&5
+$as_echo "$LIPO" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "openssl", so it can be a program name with args.
-set dummy openssl; ac_word=$2
+# Extract the first word of "lsbom", so it can be a program name with args.
+set dummy lsbom; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_OPENSSL+:} false; then :
+if ${ac_cv_path_LSBOM+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $OPENSSL in
+  case $LSBOM in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_OPENSSL="$OPENSSL" # Let the user override the test with a path.
+  ac_cv_path_LSBOM="$LSBOM" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4910,8 +5088,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_OPENSSL="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_LSBOM="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4922,26 +5100,26 @@
   ;;
 esac
 fi
-OPENSSL=$ac_cv_path_OPENSSL
-if test -n "$OPENSSL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPENSSL" >&5
-$as_echo "$OPENSSL" >&6; }
+LSBOM=$ac_cv_path_LSBOM
+if test -n "$LSBOM"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LSBOM" >&5
+$as_echo "$LSBOM" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "sed", so it can be a program name with args.
-set dummy sed; ac_word=$2
+# Extract the first word of "lzma", so it can be a program name with args.
+set dummy lzma; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_SED+:} false; then :
+if ${ac_cv_path_LZMA+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $SED in
+  case $LZMA in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_SED="$SED" # Let the user override the test with a path.
+  ac_cv_path_LZMA="$LZMA" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4950,8 +5128,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_SED="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_LZMA="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -4962,26 +5140,26 @@
   ;;
 esac
 fi
-SED=$ac_cv_path_SED
-if test -n "$SED"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SED" >&5
-$as_echo "$SED" >&6; }
+LZMA=$ac_cv_path_LZMA
+if test -n "$LZMA"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LZMA" >&5
+$as_echo "$LZMA" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "tar", so it can be a program name with args.
-set dummy tar; ac_word=$2
+# Extract the first word of "make", so it can be a program name with args.
+set dummy make; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_TAR+:} false; then :
+if ${ac_cv_path_MAKE+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $TAR in
+  case $MAKE in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_TAR="$TAR" # Let the user override the test with a path.
+  ac_cv_path_MAKE="$MAKE" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -4990,8 +5168,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_TAR="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_MAKE="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5002,26 +5180,26 @@
   ;;
 esac
 fi
-TAR=$ac_cv_path_TAR
-if test -n "$TAR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $TAR" >&5
-$as_echo "$TAR" >&6; }
+MAKE=$ac_cv_path_MAKE
+if test -n "$MAKE"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAKE" >&5
+$as_echo "$MAKE" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "unzip", so it can be a program name with args.
-set dummy unzip; ac_word=$2
+# Extract the first word of "mdfind", so it can be a program name with args.
+set dummy mdfind; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_UNZIP+:} false; then :
+if ${ac_cv_path_MDFIND+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $UNZIP in
+  case $MDFIND in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_UNZIP="$UNZIP" # Let the user override the test with a path.
+  ac_cv_path_MDFIND="$MDFIND" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5030,8 +5208,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_UNZIP="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_MDFIND="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5042,26 +5220,26 @@
   ;;
 esac
 fi
-UNZIP=$ac_cv_path_UNZIP
-if test -n "$UNZIP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $UNZIP" >&5
-$as_echo "$UNZIP" >&6; }
+MDFIND=$ac_cv_path_MDFIND
+if test -n "$MDFIND"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MDFIND" >&5
+$as_echo "$MDFIND" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "zip", so it can be a program name with args.
-set dummy zip; ac_word=$2
+# Extract the first word of "mdls", so it can be a program name with args.
+set dummy mdls; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_ZIP+:} false; then :
+if ${ac_cv_path_MDLS+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $ZIP in
+  case $MDLS in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_ZIP="$ZIP" # Let the user override the test with a path.
+  ac_cv_path_MDLS="$MDLS" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5070,8 +5248,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_ZIP="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_MDLS="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5082,28 +5260,26 @@
   ;;
 esac
 fi
-ZIP=$ac_cv_path_ZIP
-if test -n "$ZIP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ZIP" >&5
-$as_echo "$ZIP" >&6; }
+MDLS=$ac_cv_path_MDLS
+if test -n "$MDLS"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MDLS" >&5
+$as_echo "$MDLS" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-for ac_prog in bsdmake pmake
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
+# Extract the first word of "mkbom", so it can be a program name with args.
+set dummy mkbom; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_BSDMAKE+:} false; then :
+if ${ac_cv_path_MKBOM+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $BSDMAKE in
+  case $MKBOM in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_BSDMAKE="$BSDMAKE" # Let the user override the test with a path.
+  ac_cv_path_MKBOM="$MKBOM" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5112,8 +5288,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_BSDMAKE="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_MKBOM="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5124,29 +5300,67 @@
   ;;
 esac
 fi
-BSDMAKE=$ac_cv_path_BSDMAKE
-if test -n "$BSDMAKE"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BSDMAKE" >&5
-$as_echo "$BSDMAKE" >&6; }
+MKBOM=$ac_cv_path_MKBOM
+if test -n "$MKBOM"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKBOM" >&5
+$as_echo "$MKBOM" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-  test -n "$BSDMAKE" && break
+# Extract the first word of "mtree", so it can be a program name with args.
+set dummy mtree; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_MTREE+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $MTREE in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_MTREE="$MTREE" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+as_dummy="$PATH:/usr/sbin"
+for as_dir in $as_dummy
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_MTREE="$as_dir/$ac_word$ac_exec_ext"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
 done
+  done
+IFS=$as_save_IFS
 
-# Extract the first word of "make", so it can be a program name with args.
-set dummy make; ac_word=$2
+  ;;
+esac
+fi
+MTREE=$ac_cv_path_MTREE
+if test -n "$MTREE"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MTREE" >&5
+$as_echo "$MTREE" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+# Extract the first word of "open", so it can be a program name with args.
+set dummy open; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_MAKE+:} false; then :
+if ${ac_cv_path_OPEN+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MAKE in
+  case $OPEN in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_MAKE="$MAKE" # Let the user override the test with a path.
+  ac_cv_path_OPEN="$OPEN" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5155,8 +5369,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_MAKE="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_OPEN="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5167,26 +5381,26 @@
   ;;
 esac
 fi
-MAKE=$ac_cv_path_MAKE
-if test -n "$MAKE"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MAKE" >&5
-$as_echo "$MAKE" >&6; }
+OPEN=$ac_cv_path_OPEN
+if test -n "$OPEN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPEN" >&5
+$as_echo "$OPEN" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "hdiutil", so it can be a program name with args.
-set dummy hdiutil; ac_word=$2
+# Extract the first word of "openssl", so it can be a program name with args.
+set dummy openssl; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_HDIUTIL+:} false; then :
+if ${ac_cv_path_OPENSSL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $HDIUTIL in
+  case $OPENSSL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_HDIUTIL="$HDIUTIL" # Let the user override the test with a path.
+  ac_cv_path_OPENSSL="$OPENSSL" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5195,8 +5409,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_HDIUTIL="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_OPENSSL="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5207,34 +5421,36 @@
   ;;
 esac
 fi
-HDIUTIL=$ac_cv_path_HDIUTIL
-if test -n "$HDIUTIL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HDIUTIL" >&5
-$as_echo "$HDIUTIL" >&6; }
+OPENSSL=$ac_cv_path_OPENSSL
+if test -n "$OPENSSL"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPENSSL" >&5
+$as_echo "$OPENSSL" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "launchd", so it can be a program name with args.
-set dummy launchd; ac_word=$2
+# Extract the first word of "patch", so it can be a program name with args.
+set dummy patch; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_prog_HAVE_LAUNCHD+:} false; then :
+if ${ac_cv_path_PATCH+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  if test -n "$HAVE_LAUNCHD"; then
-  ac_cv_prog_HAVE_LAUNCHD="$HAVE_LAUNCHD" # Let the user override the test.
-else
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+  case $PATCH in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_PATCH="$PATCH" # Let the user override the test with a path.
+  ;;
+  *)
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
 for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_prog_HAVE_LAUNCHD="yes"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PATCH="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5242,28 +5458,29 @@
   done
 IFS=$as_save_IFS
 
+  ;;
+esac
 fi
-fi
-HAVE_LAUNCHD=$ac_cv_prog_HAVE_LAUNCHD
-if test -n "$HAVE_LAUNCHD"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_LAUNCHD" >&5
-$as_echo "$HAVE_LAUNCHD" >&6; }
+PATCH=$ac_cv_path_PATCH
+if test -n "$PATCH"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PATCH" >&5
+$as_echo "$PATCH" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "launchctl", so it can be a program name with args.
-set dummy launchctl; ac_word=$2
+# Extract the first word of "pax", so it can be a program name with args.
+set dummy pax; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_LAUNCHCTL+:} false; then :
+if ${ac_cv_path_PAX+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $LAUNCHCTL in
+  case $PAX in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_LAUNCHCTL="$LAUNCHCTL" # Let the user override the test with a path.
+  ac_cv_path_PAX="$PAX" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5272,8 +5489,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_LAUNCHCTL="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_PAX="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5284,26 +5501,26 @@
   ;;
 esac
 fi
-LAUNCHCTL=$ac_cv_path_LAUNCHCTL
-if test -n "$LAUNCHCTL"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LAUNCHCTL" >&5
-$as_echo "$LAUNCHCTL" >&6; }
+PAX=$ac_cv_path_PAX
+if test -n "$PAX"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PAX" >&5
+$as_echo "$PAX" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "xcodebuild", so it can be a program name with args.
-set dummy xcodebuild; ac_word=$2
+# Extract the first word of "rmdir", so it can be a program name with args.
+set dummy rmdir; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_XCODEBUILD+:} false; then :
+if ${ac_cv_path_RMDIR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $XCODEBUILD in
+  case $RMDIR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_XCODEBUILD="$XCODEBUILD" # Let the user override the test with a path.
+  ac_cv_path_RMDIR="$RMDIR" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5312,8 +5529,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_XCODEBUILD="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_RMDIR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5324,39 +5541,36 @@
   ;;
 esac
 fi
-XCODEBUILD=$ac_cv_path_XCODEBUILD
-if test -n "$XCODEBUILD"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XCODEBUILD" >&5
-$as_echo "$XCODEBUILD" >&6; }
+RMDIR=$ac_cv_path_RMDIR
+if test -n "$RMDIR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RMDIR" >&5
+$as_echo "$RMDIR" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-for ac_prog in gnutar gtar
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
+# Extract the first word of "rsync", so it can be a program name with args.
+set dummy rsync; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_GNUTAR+:} false; then :
+if ${ac_cv_path_RSYNC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GNUTAR in
+  case $RSYNC in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GNUTAR="$GNUTAR" # Let the user override the test with a path.
+  ac_cv_path_RSYNC="$RSYNC" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="$PATH:/usr/local/bin"
-for as_dir in $as_dummy
+for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_GNUTAR="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_RSYNC="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5367,42 +5581,36 @@
   ;;
 esac
 fi
-GNUTAR=$ac_cv_path_GNUTAR
-if test -n "$GNUTAR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GNUTAR" >&5
-$as_echo "$GNUTAR" >&6; }
+RSYNC=$ac_cv_path_RSYNC
+if test -n "$RSYNC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $RSYNC" >&5
+$as_echo "$RSYNC" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-  test -n "$GNUTAR" && break
-done
-
-for ac_prog in gnumake gmake
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
+# Extract the first word of "sandbox-exec", so it can be a program name with args.
+set dummy sandbox-exec; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_GNUMAKE+:} false; then :
+if ${ac_cv_path_SANDBOX_EXEC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GNUMAKE in
+  case $SANDBOX_EXEC in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GNUMAKE="$GNUMAKE" # Let the user override the test with a path.
+  ac_cv_path_SANDBOX_EXEC="$SANDBOX_EXEC" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="$PATH:/usr/local/bin"
-for as_dir in $as_dummy
+for as_dir in /usr/bin
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_GNUMAKE="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_SANDBOX_EXEC="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5413,42 +5621,36 @@
   ;;
 esac
 fi
-GNUMAKE=$ac_cv_path_GNUMAKE
-if test -n "$GNUMAKE"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GNUMAKE" >&5
-$as_echo "$GNUMAKE" >&6; }
+SANDBOX_EXEC=$ac_cv_path_SANDBOX_EXEC
+if test -n "$SANDBOX_EXEC"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SANDBOX_EXEC" >&5
+$as_echo "$SANDBOX_EXEC" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-  test -n "$GNUMAKE" && break
-done
-
-for ac_prog in gnupatch gpatch
-do
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
-set dummy $ac_prog; ac_word=$2
+# Extract the first word of "sed", so it can be a program name with args.
+set dummy sed; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_GNUPATCH+:} false; then :
+if ${ac_cv_path_SED+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GNUPATCH in
+  case $SED in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GNUPATCH="$GNUPATCH" # Let the user override the test with a path.
+  ac_cv_path_SED="$SED" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="$PATH:/usr/local/bin"
-for as_dir in $as_dummy
+for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_GNUPATCH="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_SED="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5459,29 +5661,26 @@
   ;;
 esac
 fi
-GNUPATCH=$ac_cv_path_GNUPATCH
-if test -n "$GNUPATCH"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GNUPATCH" >&5
-$as_echo "$GNUPATCH" >&6; }
+SED=$ac_cv_path_SED
+if test -n "$SED"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SED" >&5
+$as_echo "$SED" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-  test -n "$GNUPATCH" && break
-done
-
-# Extract the first word of "bzip2", so it can be a program name with args.
-set dummy bzip2; ac_word=$2
+# Extract the first word of "svn", so it can be a program name with args.
+set dummy svn; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_BZIP2+:} false; then :
+if ${ac_cv_path_SVN+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $BZIP2 in
+  case $SVN in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_BZIP2="$BZIP2" # Let the user override the test with a path.
+  ac_cv_path_SVN="$SVN" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5490,8 +5689,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_BZIP2="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_SVN="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5502,36 +5701,37 @@
   ;;
 esac
 fi
-BZIP2=$ac_cv_path_BZIP2
-if test -n "$BZIP2"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $BZIP2" >&5
-$as_echo "$BZIP2" >&6; }
+SVN=$ac_cv_path_SVN
+if test -n "$SVN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SVN" >&5
+$as_echo "$SVN" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "lzma", so it can be a program name with args.
-set dummy lzma; ac_word=$2
+# Extract the first word of "swig", so it can be a program name with args.
+set dummy swig; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_LZMA+:} false; then :
+if ${ac_cv_path_SWIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $LZMA in
+  case $SWIG in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_LZMA="$LZMA" # Let the user override the test with a path.
+  ac_cv_path_SWIG="$SWIG" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-for as_dir in $PATH
+as_dummy="$PATH:/usr/local/bin"
+for as_dir in $as_dummy
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_LZMA="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_SWIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5542,26 +5742,26 @@
   ;;
 esac
 fi
-LZMA=$ac_cv_path_LZMA
-if test -n "$LZMA"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LZMA" >&5
-$as_echo "$LZMA" >&6; }
+SWIG=$ac_cv_path_SWIG
+if test -n "$SWIG"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SWIG" >&5
+$as_echo "$SWIG" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "xz", so it can be a program name with args.
-set dummy xz; ac_word=$2
+# Extract the first word of "tar", so it can be a program name with args.
+set dummy tar; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_XZ+:} false; then :
+if ${ac_cv_path_TAR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $XZ in
+  case $TAR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_XZ="$XZ" # Let the user override the test with a path.
+  ac_cv_path_TAR="$TAR" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5570,8 +5770,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_XZ="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_TAR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5582,26 +5782,26 @@
   ;;
 esac
 fi
-XZ=$ac_cv_path_XZ
-if test -n "$XZ"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XZ" >&5
-$as_echo "$XZ" >&6; }
+TAR=$ac_cv_path_TAR
+if test -n "$TAR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $TAR" >&5
+$as_echo "$TAR" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "lsbom", so it can be a program name with args.
-set dummy lsbom; ac_word=$2
+# Extract the first word of "unzip", so it can be a program name with args.
+set dummy unzip; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_LSBOM+:} false; then :
+if ${ac_cv_path_UNZIP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $LSBOM in
+  case $UNZIP in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_LSBOM="$LSBOM" # Let the user override the test with a path.
+  ac_cv_path_UNZIP="$UNZIP" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5610,8 +5810,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_LSBOM="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_UNZIP="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5622,26 +5822,26 @@
   ;;
 esac
 fi
-LSBOM=$ac_cv_path_LSBOM
-if test -n "$LSBOM"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LSBOM" >&5
-$as_echo "$LSBOM" >&6; }
+UNZIP=$ac_cv_path_UNZIP
+if test -n "$UNZIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $UNZIP" >&5
+$as_echo "$UNZIP" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "mkbom", so it can be a program name with args.
-set dummy mkbom; ac_word=$2
+# Extract the first word of "xar", so it can be a program name with args.
+set dummy xar; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_MKBOM+:} false; then :
+if ${ac_cv_path_XAR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MKBOM in
+  case $XAR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_MKBOM="$MKBOM" # Let the user override the test with a path.
+  ac_cv_path_XAR="$XAR" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5650,8 +5850,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_MKBOM="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_XAR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5662,26 +5862,26 @@
   ;;
 esac
 fi
-MKBOM=$ac_cv_path_MKBOM
-if test -n "$MKBOM"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MKBOM" >&5
-$as_echo "$MKBOM" >&6; }
+XAR=$ac_cv_path_XAR
+if test -n "$XAR"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAR" >&5
+$as_echo "$XAR" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "pax", so it can be a program name with args.
-set dummy pax; ac_word=$2
+# Extract the first word of "xcodebuild", so it can be a program name with args.
+set dummy xcodebuild; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_PAX+:} false; then :
+if ${ac_cv_path_XCODEBUILD+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $PAX in
+  case $XCODEBUILD in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_PAX="$PAX" # Let the user override the test with a path.
+  ac_cv_path_XCODEBUILD="$XCODEBUILD" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5690,8 +5890,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_PAX="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_XCODEBUILD="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5702,26 +5902,26 @@
   ;;
 esac
 fi
-PAX=$ac_cv_path_PAX
-if test -n "$PAX"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PAX" >&5
-$as_echo "$PAX" >&6; }
+XCODEBUILD=$ac_cv_path_XCODEBUILD
+if test -n "$XCODEBUILD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XCODEBUILD" >&5
+$as_echo "$XCODEBUILD" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "xar", so it can be a program name with args.
-set dummy xar; ac_word=$2
+# Extract the first word of "xcrun", so it can be a program name with args.
+set dummy xcrun; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_XAR+:} false; then :
+if ${ac_cv_path_XCRUN+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $XAR in
+  case $XCRUN in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_XAR="$XAR" # Let the user override the test with a path.
+  ac_cv_path_XCRUN="$XCRUN" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5730,8 +5930,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_XAR="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_XCRUN="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5742,26 +5942,26 @@
   ;;
 esac
 fi
-XAR=$ac_cv_path_XAR
-if test -n "$XAR"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XAR" >&5
-$as_echo "$XAR" >&6; }
+XCRUN=$ac_cv_path_XCRUN
+if test -n "$XCRUN"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XCRUN" >&5
+$as_echo "$XCRUN" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "open", so it can be a program name with args.
-set dummy open; ac_word=$2
+# Extract the first word of "xz", so it can be a program name with args.
+set dummy xz; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_OPEN+:} false; then :
+if ${ac_cv_path_XZ+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $OPEN in
+  case $XZ in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_OPEN="$OPEN" # Let the user override the test with a path.
+  ac_cv_path_XZ="$XZ" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
@@ -5770,8 +5970,8 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_OPEN="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_XZ="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5782,37 +5982,36 @@
   ;;
 esac
 fi
-OPEN=$ac_cv_path_OPEN
-if test -n "$OPEN"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $OPEN" >&5
-$as_echo "$OPEN" >&6; }
+XZ=$ac_cv_path_XZ
+if test -n "$XZ"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $XZ" >&5
+$as_echo "$XZ" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 fi
 
 
-# Extract the first word of "swig", so it can be a program name with args.
-set dummy swig; ac_word=$2
+# Extract the first word of "zip", so it can be a program name with args.
+set dummy zip; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
-if ${ac_cv_path_SWIG+:} false; then :
+if ${ac_cv_path_ZIP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $SWIG in
+  case $ZIP in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_SWIG="$SWIG" # Let the user override the test with a path.
+  ac_cv_path_ZIP="$ZIP" # Let the user override the test with a path.
   ;;
   *)
   as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-as_dummy="$PATH:/usr/local/bin"
-for as_dir in $as_dummy
+for as_dir in $PATH
 do
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-    ac_cv_path_SWIG="$as_dir/$ac_word$ac_exec_ext"
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_path_ZIP="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
   fi
@@ -5823,10 +6022,10 @@
   ;;
 esac
 fi
-SWIG=$ac_cv_path_SWIG
-if test -n "$SWIG"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SWIG" >&5
-$as_echo "$SWIG" >&6; }
+ZIP=$ac_cv_path_ZIP
+if test -n "$ZIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ZIP" >&5
+$as_echo "$ZIP" >&6; }
 else
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
@@ -5834,6 +6033,44 @@
 
 
 
+# Extract the first word of "launchd", so it can be a program name with args.
+set dummy launchd; ac_word=$2
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_prog_HAVE_LAUNCHD+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  if test -n "$HAVE_LAUNCHD"; then
+  ac_cv_prog_HAVE_LAUNCHD="$HAVE_LAUNCHD" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+  IFS=$as_save_IFS
+  test -z "$as_dir" && as_dir=.
+    for ac_exec_ext in '' $ac_executable_extensions; do
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+    ac_cv_prog_HAVE_LAUNCHD="yes"
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
+    break 2
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+fi
+fi
+HAVE_LAUNCHD=$ac_cv_prog_HAVE_LAUNCHD
+if test -n "$HAVE_LAUNCHD"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $HAVE_LAUNCHD" >&5
+$as_echo "$HAVE_LAUNCHD" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+
 # Define some precious variables allowing user to override PATH for some programs
 
 
@@ -5853,7 +6090,11 @@
 
 
 
+if test "x$MTREE" = "x"; then
+    as_fn_error $? "mtree not found" "$LINENO" 5
+fi
 
+
 	# Extract the first word of "sed", so it can be a program name with args.
 set dummy sed; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -5872,7 +6113,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_SED="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -5942,7 +6183,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_TAR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -5997,7 +6238,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_TAR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -6037,7 +6278,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_GNUTAR="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -6102,7 +6343,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_PATCH="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -6142,7 +6383,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_GNUPATCH="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -6420,7 +6661,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_prog_acx_pthread_config="yes"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -6729,7 +6970,7 @@
     for ac_prog in grep ggrep; do
     for ac_exec_ext in '' $ac_executable_extensions; do
       ac_path_GREP="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_GREP" && $as_test_x "$ac_path_GREP"; } || continue
+      as_fn_executable_p "$ac_path_GREP" || continue
 # Check for GNU ac_path_GREP and select it if it is found.
   # Check for GNU $ac_path_GREP
 case `"$ac_path_GREP" --version 2>&1` in
@@ -6795,7 +7036,7 @@
     for ac_prog in egrep; do
     for ac_exec_ext in '' $ac_executable_extensions; do
       ac_path_EGREP="$as_dir/$ac_prog$ac_exec_ext"
-      { test -f "$ac_path_EGREP" && $as_test_x "$ac_path_EGREP"; } || continue
+      as_fn_executable_p "$ac_path_EGREP" || continue
 # Check for GNU ac_path_EGREP and select it if it is found.
   # Check for GNU $ac_path_EGREP
 case `"$ac_path_EGREP" --version 2>&1` in
@@ -9045,8 +9286,10 @@
 			`ls -d /usr/local/lib 2>/dev/null` \
 			`ls -d /usr/contrib/lib 2>/dev/null` \
 			`ls -d /usr/pkg/lib 2>/dev/null` \
+			`ls -d /usr/local/lib/tcl8.6 2>/dev/null` \
 			`ls -d /usr/local/lib/tcl8.5 2>/dev/null` \
 			`ls -d /usr/local/lib/tcl8.4 2>/dev/null` \
+			`ls -d /usr/lib/tcl8.6 2>/dev/null` \
 			`ls -d /usr/lib/tcl8.5 2>/dev/null` \
 			`ls -d /usr/lib/tcl8.4 2>/dev/null` \
 			; do
@@ -9228,7 +9471,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_TCLSH="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -9271,7 +9514,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_TCLSH="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -9425,7 +9668,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_CURL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -9466,7 +9709,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_CURL_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -9520,7 +9763,15 @@
 
 
 	if test "x$sqlite3prefix" = "x"; then
-		# Extract the first word of "pkg-config", so it can be a program name with args.
+		# see if it's somewhere like /usr that needs no extra flags
+		LDFLAGS_SQLITE3="-lsqlite3"
+		ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default"
+if test "x$ac_cv_header_sqlite3_h" = xyes; then :
+
+else
+
+		    # nope - try pkg-config
+			# Extract the first word of "pkg-config", so it can be a program name with args.
 set dummy pkg-config; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
 $as_echo_n "checking for $ac_word... " >&6; }
@@ -9538,7 +9789,7 @@
   IFS=$as_save_IFS
   test -z "$as_dir" && as_dir=.
     for ac_exec_ext in '' $ac_executable_extensions; do
-  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
     ac_cv_path_PKG_CONFIG="$as_dir/$ac_word$ac_exec_ext"
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
     break 2
@@ -9560,27 +9811,21 @@
 fi
 
 
-		if test "x$PKG_CONFIG" = "x" || ! $PKG_CONFIG --exists sqlite3; then
-		    # assume it's somewhere like /usr that needs no extra flags
-		    ac_fn_c_check_header_mongrel "$LINENO" "sqlite3.h" "ac_cv_header_sqlite3_h" "$ac_includes_default"
-if test "x$ac_cv_header_sqlite3_h" = xyes; then :
+			if test "x$PKG_CONFIG" = "x" || ! $PKG_CONFIG --exists sqlite3; then
+				as_fn_error $? "cannot find sqlite3 header" "$LINENO" 5
+			else
+				CFLAGS_SQLITE3=$($PKG_CONFIG --cflags sqlite3)
+				LDFLAGS_SQLITE3=$($PKG_CONFIG --libs sqlite3)
+				# for tclsqlite below
+				mp_sqlite3_dir=$($PKG_CONFIG --variable=prefix sqlite3)
+            			if test "x$mp_sqlite3_dir" != "x"; then
+                			mp_sqlite3_dir=${mp_sqlite3_dir}/lib/sqlite3
+            			fi
+			fi
 
-else
-  as_fn_error $? "cannot find sqlite3 header" "$LINENO" 5
 fi
 
 
-            CFLAGS_SQLITE3=""
-		    LDFLAGS_SQLITE3="-lsqlite3"
-        else
-            CFLAGS_SQLITE3=$($PKG_CONFIG --cflags sqlite3)
-            LDFLAGS_SQLITE3=$($PKG_CONFIG --libs sqlite3)
-            # for tclsqlite below
-            mp_sqlite3_dir=$($PKG_CONFIG --variable=prefix sqlite3)
-            if test "x$mp_sqlite3_dir" != "x"; then
-                mp_sqlite3_dir=${mp_sqlite3_dir}/lib/sqlite3
-            fi
-        fi
 	else
 	    CFLAGS_SQLITE3="-I${sqlite3prefix}/include"
 		LDFLAGS_SQLITE3="-L${sqlite3prefix}/lib -lsqlite3"
@@ -9644,6 +9889,85 @@
 
 
 
+
+
+
+	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SQLite >= 3003011" >&5
+$as_echo_n "checking for SQLite >= 3003011... " >&6; }
+
+	mp_check_sqlite_version_cppflags_save=$CPPFLAGS
+	CPPFLAGS="$CPPFLAGS $CFLAGS_SQLITE3"
+
+	if ${mp_cv_sqlite_version_defined+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+		cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+					#include <sqlite3.h>
+					#ifndef SQLITE_VERSION_NUMBER
+					#  error "SQLITE_VERSION_NUMBER undefined"
+					#endif
+
+
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  mp_cv_sqlite_version_defined="yes"
+else
+  as_fn_error $? "\"SQLITE_VERSION_NUMBER undefined or sqlite3.h not found\"" "$LINENO" 5
+
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+fi
+
+
+	if test x"${mp_cv_sqlite_version_defined}" = "xno"; then
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: SQLite version not found" >&5
+$as_echo "SQLite version not found" >&6; }
+		mp_sqlite_version_ge_3003011="no"
+	else
+		if ${mp_cv_sqlite_version_ge_3003011+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+
+			cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+						#include <sqlite3.h>
+						#if (SQLITE_VERSION_NUMBER >= 3003011)
+						/* Everything is fine */
+						#else
+						#  error "SQLite version too old"
+						#endif
+
+
+_ACEOF
+if ac_fn_c_try_cpp "$LINENO"; then :
+  mp_cv_sqlite_version_ge_3003011="yes"
+else
+  mp_cv_sqlite_version_ge_3003011="no"
+
+fi
+rm -f conftest.err conftest.i conftest.$ac_ext
+
+fi
+
+
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ${mp_cv_sqlite_version_ge_3003011}" >&5
+$as_echo "${mp_cv_sqlite_version_ge_3003011}" >&6; }
+		mp_sqlite_version_ge_3003011=${mp_cv_sqlite_version_ge_3003011}
+	fi
+
+	CPPFLAGS=$mp_check_sqlite_version_cppflags_save
+
+if test "x${mp_sqlite_version_ge_3003011}" = "xno"; then
+
+$as_echo "#define sqlite3_prepare_v2 sqlite3_prepare" >>confdefs.h
+
+fi
+
 # Determine if we need to install some bundled packages
 OUR_INCLUDED_PACKAGES=
 
@@ -9764,7 +10088,7 @@
 $as_echo_n "checking that any existing MacPorts install can be upgraded... " >&6; }
 
 	eval dpversionfile="${sysconfdir}/ports/dp_version"
-	if test -f $dpversionfile; then
+	if test -f "$dpversionfile"; then
 		as_fn_error $? "Existing MacPorts or DarwinPorts install is too old to be upgraded. Install MacPorts 1.7.1 first." "$LINENO" 5
 	else
 		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
@@ -10203,16 +10527,16 @@
     # ... but there are two gotchas:
     # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail.
     # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable.
-    # In both cases, we have to default to `cp -p'.
+    # In both cases, we have to default to `cp -pR'.
     ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe ||
-      as_ln_s='cp -p'
+      as_ln_s='cp -pR'
   elif ln conf$$.file conf$$ 2>/dev/null; then
     as_ln_s=ln
   else
-    as_ln_s='cp -p'
+    as_ln_s='cp -pR'
   fi
 else
-  as_ln_s='cp -p'
+  as_ln_s='cp -pR'
 fi
 rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file
 rmdir conf$$.dir 2>/dev/null
@@ -10272,29 +10596,17 @@
   as_mkdir_p=false
 fi
 
-if test -x / >/dev/null 2>&1; then
-  as_test_x='test -x'
-else
-  if ls -dL / >/dev/null 2>&1; then
-    as_ls_L_option=L
-  else
-    as_ls_L_option=
-  fi
-  as_test_x='
-    eval sh -c '\''
-      if test -d "$1"; then
-	test -d "$1/.";
-      else
-	case $1 in #(
-	-*)set "./$1";;
-	esac;
-	case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #((
-	???[sx]*):;;*)false;;esac;fi
-    '\'' sh
-  '
-fi
-as_executable_p=$as_test_x
 
+# as_fn_executable_p FILE
+# -----------------------
+# Test if FILE is an executable regular file.
+as_fn_executable_p ()
+{
+  test -f "$1" && test -x "$1"
+} # as_fn_executable_p
+as_test_x='test -x'
+as_executable_p=as_fn_executable_p
+
 # Sed expression to map a string onto a valid CPP name.
 as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
 
@@ -10314,8 +10626,8 @@
 # report actual input values of CONFIG_FILES etc. instead of their
 # values after options handling.
 ac_log="
-This file was extended by MacPorts $as_me 2.0.99, which was
-generated by GNU Autoconf 2.68.  Invocation command line was
+This file was extended by MacPorts $as_me 2.1.99, which was
+generated by GNU Autoconf 2.69.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
   CONFIG_HEADERS  = $CONFIG_HEADERS
@@ -10376,11 +10688,11 @@
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
 ac_cs_version="\\
-MacPorts config.status 2.0.99
-configured by $0, generated by GNU Autoconf 2.68,
+MacPorts config.status 2.1.99
+configured by $0, generated by GNU Autoconf 2.69,
   with options \\"\$ac_cs_config\\"
 
-Copyright (C) 2010 Free Software Foundation, Inc.
+Copyright (C) 2012 Free Software Foundation, Inc.
 This config.status script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it."
 
@@ -10469,7 +10781,7 @@
 _ACEOF
 cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 if \$ac_cs_recheck; then
-  set X '$SHELL' '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+  set X $SHELL '$0' $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
   shift
   \$as_echo "running CONFIG_SHELL=$SHELL \$*" >&6
   CONFIG_SHELL='$SHELL'

Modified: branches/gsoc11-statistics/base/configure.ac
===================================================================
--- branches/gsoc11-statistics/base/configure.ac	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/configure.ac	2013-04-09 18:46:31 UTC (rev 105085)
@@ -32,11 +32,11 @@
     AC_MSG_ERROR([This version of Mac OS X is not supported
                   Please upgrade at http://store.apple.com/])
     ;;
-  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]])
+  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-4]]|10.8.[[0-1]])
     AC_MSG_WARN([This version of Mac OS X is out of date])
     AC_MSG_WARN([Please run Software Update to update it])
     ;;
-  10.4*|10.5*|10.6*|10.7*)
+  10.4*|10.5*|10.6*|10.7*|10.8*)
     dnl Supported version
     ;;
   *)
@@ -44,20 +44,33 @@
 esac
 
 # locate currently selected Xcode path
+AC_MSG_CHECKING(Xcode location)
 if test "x$XCODE_SELECT" != "x"; then
-  AC_MSG_CHECKING(Xcode location)
   DEVELOPER_DIR=`$XCODE_SELECT -print-path`
-  AC_MSG_RESULT([$DEVELOPER_DIR])
-else
-  DEVELOPER_DIR=/Developer
 fi
+if test -z "$DEVELOPER_DIR" -o ! -d "$DEVELOPER_DIR" ; then
+    if test -d /Applications/Xcode.app/Contents/Developer ; then
+        DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
+    else
+        DEVELOPER_DIR=/Developer
+    fi
+fi
+AC_MSG_RESULT([$DEVELOPER_DIR])
 AC_SUBST(DEVELOPER_DIR)
 
-XCODEPLIST=$DEVELOPER_DIR/Applications/Xcode.app/Contents/version.plist
+case "$DEVELOPER_DIR" in
+  *Xcode.app/Contents/Developer)
+    XCODEPLIST_BASE=`dirname $DEVELOPER_DIR`/version
+    ;;
+  *)
+    XCODEPLIST_BASE=$DEVELOPER_DIR/Applications/Xcode.app/Contents/version
+    ;;
+esac
+XCODEPLIST=${XCODEPLIST_BASE}.plist
 if test -r "$XCODEPLIST"; then
   AC_MSG_CHECKING(Xcode version)
   if test "x$DEFAULTS" != "x"; then
-    XCODE_VERSION=`$DEFAULTS read $DEVELOPER_DIR/Applications/Xcode.app/Contents/version CFBundleShortVersionString`
+    XCODE_VERSION=`$DEFAULTS read $XCODEPLIST_BASE CFBundleShortVersionString`
   else
     XCODE_VERSION=`tr -d '\r\n' < $XCODEPLIST | sed -e 's/.*<key>CFBundleShortVersionString<\/key>.<string>\([[0-9.]]*\)<\/string>.*/\1/'`
   fi
@@ -86,71 +99,82 @@
 
 # Checks for programs.
 AC_PROG_CC
-AC_PROG_OBJC
 AC_PROG_INSTALL
+AC_PROG_LN_S
 AC_PROG_MAKE_SET
-AC_PROG_LN_S
-AC_PATH_PROG(MTREE, [mtree], [], [$PATH:/usr/sbin])
+AC_PROG_OBJC
+
+AC_PATH_PROGS(BSDMAKE, [bsdmake pmake], [])
+AC_PATH_PROG(BZIP2, [bzip2], [])
+AC_PATH_PROG(BZR, [bzr], [])
 AC_PATH_PROG(CHOWN, [chown], [], [$PATH:/usr/sbin])
 AC_PATH_PROG(CP, [cp], [])
 AC_PATH_PROG(CPIO, [cpio], [])
+AC_PATH_PROG(CVS, [cvs], [])
 AC_PATH_PROG(DIFF, [diff], [])
 AC_PATH_PROG(DSCL, [dscl], [])
 AC_PATH_PROG(DSEDITGROUP, [dseditgroup], [])
 AC_PATH_PROG(FILE, [file], [])
-AC_PATH_PROG(BZR, [bzr], [])
-AC_PATH_PROG(CVS, [cvs], [])
-AC_PATH_PROG(SVN, [svn], [])
+AC_PATH_PROG(FIND, [find], [])
 AC_PATH_PROG(GIT, [git], [])
+AC_PATH_PROGS(GNUMAKE, [gnumake gmake], [], [$PATH:/usr/local/bin])
+AC_PATH_PROGS(GNUPATCH, [gnupatch gpatch], [], [$PATH:/usr/local/bin])
+AC_PATH_PROGS(GNUTAR, [gnutar gtar], [], [$PATH:/usr/local/bin])
+AC_PATH_PROG(GZIP, [gzip], [])
+AC_PATH_PROG(HDIUTIL, [hdiutil], [])
 AC_PATH_PROG(HG, [hg], [])
-AC_PATH_PROG(GZIP, [gzip], [])
+AC_PATH_PROG(LAUNCHCTL, [launchctl], [])
 AC_PATH_PROG(LIPO, [lipo], [])
+AC_PATH_PROG(LSBOM, [lsbom], [])
+AC_PATH_PROG(LZMA, [lzma], [])
+AC_PATH_PROG(MAKE, [make])
+AC_PATH_PROG(MDFIND, [mdfind], [])
+AC_PATH_PROG(MDLS, [mdls], [])
+AC_PATH_PROG(MKBOM, [mkbom], [])
+AC_PATH_PROG(MTREE, [mtree], [], [$PATH:/usr/sbin])
+AC_PATH_PROG(OPEN, [open], [])
+AC_PATH_PROG(OPENSSL, [openssl], [])
 AC_PATH_PROG(PATCH, [patch], [])
+AC_PATH_PROG(PAX, [pax], [])
 AC_PATH_PROG(RMDIR, [rmdir], [])
 AC_PATH_PROG(RSYNC, [rsync], [])
-AC_PATH_PROG(OPENSSL, [openssl], [])
+AC_PATH_PROG(SANDBOX_EXEC, [sandbox-exec], [], [/usr/bin])
 AC_PATH_PROG(SED, [sed])
+AC_PATH_PROG(SVN, [svn], [])
+AC_PATH_PROG(SWIG, [swig], [], [$PATH:/usr/local/bin])
 AC_PATH_PROG(TAR, [tar])
 AC_PATH_PROG(UNZIP, [unzip])
-AC_PATH_PROG(ZIP, [zip])
-AC_PATH_PROGS(BSDMAKE, [bsdmake pmake], [])
-AC_PATH_PROG(MAKE, [make])
-AC_PATH_PROG(HDIUTIL, [hdiutil], [])
-AC_CHECK_PROG(HAVE_LAUNCHD, [launchd], [yes], [])
-AC_PATH_PROG(LAUNCHCTL, [launchctl], [])
+AC_PATH_PROG(XAR, [xar], [])
 AC_PATH_PROG(XCODEBUILD, [xcodebuild], [])
-AC_PATH_PROGS(GNUTAR, [gnutar gtar], [], [$PATH:/usr/local/bin])
-AC_PATH_PROGS(GNUMAKE, [gnumake gmake], [], [$PATH:/usr/local/bin])
-AC_PATH_PROGS(GNUPATCH, [gnupatch gpatch], [], [$PATH:/usr/local/bin])
-AC_PATH_PROG(BZIP2, [bzip2], [])
-AC_PATH_PROG(LZMA, [lzma], [])
+AC_PATH_PROG(XCRUN, [xcrun], [])
 AC_PATH_PROG(XZ, [xz], [])
-AC_PATH_PROG(LSBOM, [lsbom], [])
-AC_PATH_PROG(MKBOM, [mkbom], [])
-AC_PATH_PROG(PAX, [pax], [])
-AC_PATH_PROG(XAR, [xar], [])
-AC_PATH_PROG(OPEN, [open], [])
-AC_PATH_PROG(SWIG, [swig], [], [$PATH:/usr/local/bin])
+AC_PATH_PROG(ZIP, [zip])
 
+AC_CHECK_PROG(HAVE_LAUNCHD, [launchd], [yes], [])
+
 # Define some precious variables allowing user to override PATH for some programs
+AC_ARG_VAR(BSDMAKE, [path to bsdmake/pmake command])
+AC_ARG_VAR(BZIP2, [path to bzip2 command])
+AC_ARG_VAR(CVS, [path to cvs command])
+AC_ARG_VAR(GNUMAKE, [path to gnumake command])
+AC_ARG_VAR(GNUTAR, [path to gnutar command])
+AC_ARG_VAR(LZMA, [path to lzma command])
+AC_ARG_VAR(MAKE, [path to make command])
 AC_ARG_VAR(MTREE, [path to mtree command])
-AC_ARG_VAR(CVS, [path to cvs command])
-AC_ARG_VAR(SVN, [path to svn command])
+AC_ARG_VAR(OPEN, [path to open command])
 AC_ARG_VAR(OPENSSL, [path to openssl command])
 AC_ARG_VAR(RSYNC, [path to rsync command])
 AC_ARG_VAR(SED, [path to sed command])
+AC_ARG_VAR(SVN, [path to svn command])
+AC_ARG_VAR(SWIG, [path to swig command])
 AC_ARG_VAR(TAR, [path to tar command])
-AC_ARG_VAR(MAKE, [path to make command])
-AC_ARG_VAR(GNUTAR, [path to gnutar command])
-AC_ARG_VAR(BSDMAKE, [path to bsdmake/pmake command])
-AC_ARG_VAR(GNUMAKE, [path to gnumake command])
-AC_ARG_VAR(BZIP2, [path to bzip2 command])
-AC_ARG_VAR(LZMA, [path to lzma command])
+AC_ARG_VAR(XAR, [path to xar command])
 AC_ARG_VAR(XZ, [path to xz command])
-AC_ARG_VAR(XAR, [path to xar command])
-AC_ARG_VAR(OPEN, [path to open command])
-AC_ARG_VAR(SWIG, [path to swig command])
 
+if test "x$MTREE" = "x"; then
+    AC_MSG_ERROR([mtree not found])
+fi
+
 MP_SED_EXTENDED_REGEXP
 MP_TAR_FAST_READ
 MP_TAR_NO_SAME_OWNER
@@ -234,7 +258,7 @@
 [
 	AC_CHECK_LIB([readline], [readline], [
 				  READLINE_LIBS=-lreadline
-				  AC_DEFINE([HAVE_LIBREADLINE], [1], [Define to 1 if you have the `readline' library (-lreadline).])
+				  AC_DEFINE([HAVE_LIBREADLINE], [1], [Define to 1 if you have the 'readline' library (-lreadline).])
 				  ])
 	AC_CHECK_DECLS([rl_username_completion_function,rl_filename_completion_function,rl_completion_matches,username_completion_function,filename_completion_function,completion_matches], [], [],
 	[
@@ -274,6 +298,11 @@
 ## sqlite3
 MP_SQLITE3_FLAGS
 
+MP_CHECK_SQLITE_VERSION(3003011)
+if test "x${mp_sqlite_version_ge_3003011}" = "xno"; then
+	AC_DEFINE([sqlite3_prepare_v2], [sqlite3_prepare], [define sqlite3_prepare to sqlite_prepare_v2 if the latter is not available])
+fi
+
 # Determine if we need to install some bundled packages
 OUR_INCLUDED_PACKAGES=
 
@@ -322,7 +351,6 @@
 SHLIB_SUFFIX=${TCL_SHLIB_SUFFIX}
 
 AC_SUBST(INCLUDES)
-AC_SUBST(PATHCONF)
 AC_SUBST(STLIB_LD)
 AC_SUBST(SHLIB_LD)
 AC_SUBST(SHLIB_CFLAGS)

Modified: branches/gsoc11-statistics/base/doc/Makefile
===================================================================
--- branches/gsoc11-statistics/base/doc/Makefile	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/doc/Makefile	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,7 +1,7 @@
 MAN1=		port.1
 MAN5=		macports.conf.5
 MAN7=		portfile.7 portstyle.7 porthier.7 portgroup.7
-CONF=       macports.conf pubkeys.conf sources.conf variants.conf
+CONF=       archive_sites.conf macports.conf pubkeys.conf sources.conf variants.conf
 INSTALLDIR=	${DESTDIR}${prefix}
 TOPSRCDIR=	..
 
@@ -29,39 +29,32 @@
 	gzip -c $^ > $@
 
 install: all
-	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${INSTALLDIR}
-	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${DESTDIR}${mpconfigdir}
+	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} "${INSTALLDIR}"
+	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} "${DESTDIR}${mpconfigdir}"
 
-	< prefix.mtree $(MTREE) -U -e -p ${INSTALLDIR} > /dev/null
-	< base.mtree $(MTREE) -U -e -p ${INSTALLDIR} > /dev/null
-	if test -L "${INSTALLDIR}/man" ; then \
-		rm -f "${INSTALLDIR}/man"; \
-	fi
+	< prefix.mtree $(MTREE) -U -e -p "${INSTALLDIR}" > /dev/null
+	< base.mtree $(MTREE) -U -e -p "${INSTALLDIR}" > /dev/null
 
-	if test ! -e "${INSTALLDIR}/man" ; then \
-		$(LN_S) share/man ${INSTALLDIR}/man; \
-	fi
-
 	for f in ${CONF}; do \
-		$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 $$f ${DESTDIR}${mpconfigdir}/$${f}.default; \
-		if test ! -e ${DESTDIR}${mpconfigdir}/$$f ; then \
+		$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 $$f "${DESTDIR}${mpconfigdir}/$${f}.default"; \
+		if test ! -e "${DESTDIR}${mpconfigdir}/$$f" ; then \
 			set -x; \
-			$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 $$f ${DESTDIR}${mpconfigdir}; \
+			$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 $$f "${DESTDIR}${mpconfigdir}"; \
 		fi; \
 	done
 
 	# delete old uncompressed man pages if they exist
-	for m in ${MAN1}; do rm -f ${INSTALLDIR}/share/man/man1/$$m ; done
-	for m in ${MAN5}; do rm -f ${INSTALLDIR}/share/man/man5/$$m ; done
-	for m in ${MAN7}; do rm -f ${INSTALLDIR}/share/man/man7/$$m ; done
+	for m in ${MAN1}; do rm -f "${INSTALLDIR}/share/man/man1/$$m" ; done
+	for m in ${MAN5}; do rm -f "${INSTALLDIR}/share/man/man5/$$m" ; done
+	for m in ${MAN7}; do rm -f "${INSTALLDIR}/share/man/man7/$$m" ; done
 
-	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} ${INSTALLDIR}/share/macports/install
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 base.mtree ${INSTALLDIR}/share/macports/install/
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 prefix.mtree ${INSTALLDIR}/share/macports/install/
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 macosx.mtree ${INSTALLDIR}/share/macports/install/
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 port.1.gz ${INSTALLDIR}/share/man/man1
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 macports.conf.5.gz ${INSTALLDIR}/share/man/man5
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 portfile.7.gz ${INSTALLDIR}/share/man/man7
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 portstyle.7.gz ${INSTALLDIR}/share/man/man7
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 porthier.7.gz ${INSTALLDIR}/share/man/man7
-	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 portgroup.7.gz ${INSTALLDIR}/share/man/man7
+	$(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} "${INSTALLDIR}/share/macports/install"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 base.mtree "${INSTALLDIR}/share/macports/install/"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 prefix.mtree "${INSTALLDIR}/share/macports/install/"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 644 macosx.mtree "${INSTALLDIR}/share/macports/install/"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 port.1.gz "${INSTALLDIR}/share/man/man1"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 macports.conf.5.gz "${INSTALLDIR}/share/man/man5"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 portfile.7.gz "${INSTALLDIR}/share/man/man7"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 portstyle.7.gz "${INSTALLDIR}/share/man/man7"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 porthier.7.gz "${INSTALLDIR}/share/man/man7"
+	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 portgroup.7.gz "${INSTALLDIR}/share/man/man7"

Copied: branches/gsoc11-statistics/base/doc/archive_sites.conf (from rev 105084, trunk/base/doc/archive_sites.conf)
===================================================================
--- branches/gsoc11-statistics/base/doc/archive_sites.conf	                        (rev 0)
+++ branches/gsoc11-statistics/base/doc/archive_sites.conf	2013-04-09 18:46:31 UTC (rev 105085)
@@ -0,0 +1,27 @@
+# Configuration for (binary) archive sources.
+# $Id$
+
+# Each entry is started by a name line. The only required values are name and
+# urls. Other fields are type, prefix, applications_dir and frameworks_dir,
+# which have the usual default values:
+#    type tbz2
+#    prefix /opt/local
+#    applications_dir /Applications/MacPorts
+#    frameworks_dir ${prefix}/Library/Frameworks
+#
+# type can be any of: tgz, tar, tbz, tbz2, tlz, txz, xar, zip, cpgz, cpio
+# Note that some types require a corresponding tool to be installed, and
+# entries with an unsupported type will not be used.
+
+# Example:
+#name                mysource
+#urls                http://example.com/ ftp://ftp.example.org/
+#type                tbz2
+#prefix              /opt/mysource
+#applications_dir    /opt/mysource/Applications
+#frameworks_dir      /opt/mysource/Library/Frameworks
+
+# If you want to disable use of the archive sites listed in the ports tree,
+# you could do this:
+#name                macports_archives
+#urls

Modified: branches/gsoc11-statistics/base/doc/base.mtree.in
===================================================================
--- branches/gsoc11-statistics/base/doc/base.mtree.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/doc/base.mtree.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -5,12 +5,20 @@
 
 /set type=dir uname=@DSTUSR@ gname=@DSTGRP@ mode=@DSTMODE@
 .
+    man type=link link=share/man
+    ..
     var
         macports
             build
             ..
             distfiles
             ..
+            home
+                Library
+                    Preferences
+                    ..
+                ..
+            ..
             logs
             ..
             registry

Modified: branches/gsoc11-statistics/base/doc/macports.conf.5
===================================================================
--- branches/gsoc11-statistics/base/doc/macports.conf.5	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/doc/macports.conf.5	2013-04-09 18:46:31 UTC (rev 105085)
@@ -92,6 +92,14 @@
 .br
 .Ic Default:
 ${prefix}/etc/macports/variants.conf
+.It Va buildfromsource
+Controls whether ports are built from source or downloaded as pre-built
+archives. Setting to 'always' will never use archives, 'never' will always
+try to use an archive and fail if one is not available. 'ifneeded' will try to
+fetch an archive and fall back to building from source if that isn't possible.
+.br
+.Ic Default:
+ifneeded
 .It Va portarchivetype
 Format of archives in which to store port images. This controls both the type
 of archive created locally after building from source, and the type to request
@@ -179,6 +187,14 @@
 .br
 .Ic Default:
 default
+.It Va startupitem_install
+Option to install symlinks into /Library/LaunchAgents or
+/Library/LaunchDaemons; startupitem_install may be empty, "yes" or "no";
+if the option is NOT "no" then a symlink for the startupitem will be
+created in the appropriate system directory.
+.br
+.Ic Default:
+yes
 .It Va destroot_umask
 Umask value to use during the destrooting of a port.
 .br
@@ -204,8 +220,8 @@
 -rtzv --delete-after
 .It Va binpath
 Sets the directory search path for locating system executables used by MacPorts. This variable should contain
-the paths for locating utilities such as rsync, tar, cvs and others. Don't change this unless you understand
-and accept the consequences.
+the paths for locating utilities such as rsync, tar, cvs and others. Changing this is unsupported; don't do so
+unless you understand and accept the consequences.
 .br
 .Ic Default:
 ${prefix}/bin:${prefix}/sbin:/bin:/sbin:/usr/bin:/usr/sbin
@@ -221,6 +237,77 @@
 .It Va stats_id
 This is a string that uniquely identifies this installation of MacPorts. It is automatically generated 
 and should not be modified.
+Changing this is unsupported.
+.It Va proxy_override_env
+Proxy support. Precedence is: env, macports.conf, System Preferences.
+That is, if it's set in the environment, that will be used instead of
+anything here or in System Preferences. Setting proxy_override_env to
+yes will cause any proxies set here (or in System Preferences if set
+there but not here) to override what's in the environment. Note that
+System Preferences doesn't have an rsync proxy definition. Also note, on
+10.5, sudo will clear many environment variables including those for
+proxy support. Equivalent environment variables: http_proxy,
+HTTPS_PROXY, FTP_PROXY, RSYNC_PROXY, NO_PROXY
+.br
+.Ic Default:
+yes
+.It Va proxy_http
+HTTP proxy
+.br
+.Ic Default:
+none
+.It Va proxy_https
+HTTPS proxy
+.br
+.Ic Default:
+none
+.It Va proxy_ftp
+FTP proxy
+.br
+.Ic Default:
+none
+.It Va proxy_rsync
+rsync proxy
+.br
+.Ic Default:
+none
+.It Va proxy_skip
+Hosts not to go through the proxy (comma-separated, applies to HTTP,
+HTTPS and FTP, but not rsync):
+.br
+.Ic Default:
+none
+.It Va host_blacklist
+Space separated list of download hosts that should not be used.
+.br
+.Ic Default:
+none
+.It Va preferred_hosts
+Space separated list of download hosts that should be used preferentially.
+.br
+.Ic Default:
+none
+.It Va revupgrade_autorun
+Controls whether the rev-upgrade action will be run automatically after
+upgrading ports.
+.br
+.Ic Default:
+yes
+.It Va revupgrade_mode
+Controls the rev-upgrade functionality which checks for broken linking and can
+rebuild ports to fix it. 'rebuild' means ports will automatically be rebuilt
+when broken linking is detected in their files, while 'report' means broken
+files will be scanned for and reported but the ports will not be rebuilt.
+.br
+.Ic Default:
+rebuild
+.It Va default_compiler
+Default value for configure.compiler. This can be a space-separated list. Later
+entries will be used if earlier entries are unavailable or blacklisted by a
+port. Setting this is unsupported.
+.br
+.Ic Default:
+none (internal list based on Xcode version is normally used)
 .El
 .Sh FILES
 .Bl -tag -width

Modified: branches/gsoc11-statistics/base/doc/macports.conf.in
===================================================================
--- branches/gsoc11-statistics/base/doc/macports.conf.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/doc/macports.conf.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -10,13 +10,23 @@
 # Where to store MacPorts working data
 portdbpath		@localstatedir_expanded@/macports
 
-# PATH settings that are used for external tools (configure, make, etc.) while installing ports. The default
-# paths are given in the example; it need not be uncommented.  Customizing binpath is intended for advanced users only.
+# PATH settings that are used for external tools (configure, make, etc.) while
+# installing ports. The default paths are given in the example; it need not be
+# uncommented.  Customizing binpath is unsupported and is intended for
+# advanced users only.
 #binpath		@prefix_expanded@/bin:@prefix_expanded@/sbin:/bin:/sbin:/usr/bin:/usr/sbin
 
 # Directory containing Xcode Tools (default is to ask xcode-select)
-#developer_dir       @DEVELOPER_DIR@
+#developer_dir		@DEVELOPER_DIR@
 
+# Path to PackageMaker.app
+# It may be necessary to set this with Xcode >= 4.3, as that version
+# requires PackageMaker to be installed manually from the Auxiliary Tools for
+# Xcode disk image. The default is /Applications/PackageMaker.app with Xcode
+# 4.3 and ${developer_dir}/Applications/Utilities/PackageMaker.app with older
+# versions.
+#packagemaker_path /Applications/PackageMaker.app
+
 # Directory containing Applications from ports.
 applications_dir	@MPAPPLICATIONSDIR@
 
@@ -29,31 +39,36 @@
 # Where to find global variants definition file (optional)
 variants_conf		@MPCONFIGDIR_EXPANDED@/variants.conf
 
+# When to build ports from source. Default is 'ifneeded', which downloads an
+# archive if available or builds from source otherwise. 'always' has the same
+# effect as -s on the command line, and 'never' is likewise the same as -b.
+#buildfromsource	ifneeded
+
 # Type of archives to use for port images
 #
 # Supported types: tgz, tar, tbz, tbz2 (default), tlz, txz, xar, zip, cpgz, cpio
-#portarchivetype		tbz2
+#portarchivetype	tbz2
 
 # CPU architecture to compile for. Defaults to i386 or ppc on Mac OS X 10.5
 # and earlier, depending on the CPU type detected at runtime. On Mac OS X 10.6
 # the default is x86_64 if the CPU supports it, i386 otherwise.
-#build_arch			i386
+#build_arch		i386
 
 # CPU architectures to use for Universal Binaries (+universal variant)
 universal_archs		@UNIVERSAL_ARCHS@
 
 # Use ccache (C/C++ compiler cache) - see http://ccache.samba.org/
-#configureccache		no
+#configureccache	no
 
 # Location where ccache stores its files
-#ccache_dir			@localstatedir_expanded@/macports/build/.ccache
+#ccache_dir		@localstatedir_expanded@/macports/build/.ccache
 
 # Maximum size ccache may use.
 # Use 'G', 'M', or 'K' suffix for giga-, mega- or kilobytes.
-#ccache_size			2G
+#ccache_size		2G
 
 # Use distcc (distributed compiler) - see http://distcc.samba.org/
-#configuredistcc		no
+#configuredistcc	no
 
 # Use pipes rather than intermediate files when compiling C/C++/etc
 #configurepipe		yes
@@ -68,13 +83,13 @@
 #buildmakejobs		0
 
 # umask value to use when a port installs its files
-#destroot_umask 022
+#destroot_umask		022
 
 # Set whether to automatically execute "clean" after "install" of ports
 #portautoclean		yes
 
 # Set to yes if you don't want logs to be deleted after successful builds
-#keeplogs no
+#keeplogs		no
 
 # Rsync server to fetch MacPorts sources from. Note that this is only used
 # for selfupdate. The source(s) for the ports tree are set in sources.conf.
@@ -87,7 +102,7 @@
 # Rsync directory from which to pull the base/ component (infrastructure) of MacPorts
 # If this points to a .tar file, a signed .rmd160 must exist next to it
 # on the server and will be used to verify its integrity.
-#rsync_dir			release/tarballs/base.tar
+#rsync_dir		release/tarballs/base.tar
 
 # Rsync options
 #rsync_options		-rtzv --delete-after
@@ -101,6 +116,12 @@
 # are installed.
 #startupitem_type	default
 
+# Option to install symlinks into /Library/LaunchAgents or /Library/LaunchDaemons
+# startupitem_install may be empty, "yes" or "no";
+# if the option is NOT "no" then a symlink for the startupitem will be created in
+# the appropriate system directory.
+#startupitem_install	yes
+
 # Extra environment variables to keep. Any variables listed here are added
 # to the list of variables that are not removed from the environment used
 # while processing ports. As with binpath, setting extra_env is intended for
@@ -119,15 +140,15 @@
 # Equivalent environment variables: http_proxy, HTTPS_PROXY, FTP_PROXY,
 # RSYNC_PROXY, NO_PROXY
 #
-#proxy_override_env    yes
+#proxy_override_env	yes
 # HTTP proxy:
-#proxy_http            hostname:12345
+#proxy_http		hostname:12345
 # HTTPS proxy:
-#proxy_https       hostname:12345
+#proxy_https		hostname:12345
 # FTP proxy:
-#proxy_ftp         hostname:12345
+#proxy_ftp		hostname:12345
 # rsync proxy:
-#proxy_rsync       hostname:12345
+#proxy_rsync		hostname:12345
 # hosts not to go through the proxy (comma-separated, applies to HTTP, HTTPS,
 # and FTP, but not rsync):
 #proxy_skip            internal1, internal2, internal3
@@ -142,3 +163,17 @@
 
 # Unique identifier for usage statistics
 stats_id	@STATS_UUID@
+
+# Options 'host_blacklist' and 'preferred_hosts', used for indicating
+# space separated lists of download hosts that should not be used or
+# should be used preferentially, respectively. These override the usual
+# ping time check.
+#host_blacklist     badhost1.org badhost2.org
+#preferred_hosts    preferredhost1.org preferredhost2.org
+
+# Set whether to automatically run rev-upgrade after upgrading ports
+#revupgrade_autorun yes
+# Option controlling action taken by rev-upgrade, which checks for broken
+# linking and can rebuild affected ports. Possible values are
+#'rebuild' (default) or 'report'.
+#revupgrade_mode	rebuild

Modified: branches/gsoc11-statistics/base/doc/port.1
===================================================================
--- branches/gsoc11-statistics/base/doc/port.1	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/doc/port.1	2013-04-09 18:46:31 UTC (rev 105085)
@@ -252,7 +252,7 @@
 .It Fl f
 force mode (ignore state file)
 .It Fl o
-honor state files older than Portfile
+honor state files even if the Portfile has been modified since (called -o because it used to mean "older")
 .It Fl s
 source-only mode (build and install from source, do not attempt to fetch binary archives)
 .It Fl b
@@ -367,13 +367,13 @@
 .Ar portname .
 To uninstall all installed but inactive ports, use
 .Fl u .
-To recursively uninstall all dependents of
+To recursively uninstall all ports that depend on
 .Ar portname
 before uninstalling the port itself, use
 .Fl -follow-dependents .
 To uninstall
 .Ar portname
-and then recursively uninstall all its dependencies, use
+and then recursively uninstall all ports it depended on, use
 .Fl -follow-dependencies .
 This will not uninstall dependencies that are marked as requested or that have other dependents.
 .Pp
@@ -510,6 +510,9 @@
 helpful for maintainers to check whether their ports have been built correctly.
 It is disabled by default and can be enabled by passing \fB--id-loadcmd-check\fP
 to \fBrev-upgrade\fP.
+.Pp
+See also:
+.Xr macports.conf 5
 .Ss clean
 Clean the files used for building
 .Ar portname .
@@ -541,6 +544,10 @@
 .Dl "port log --phase configure vim"
 .Dl "port log --phase fetch --verbosity debug vim"
 .Pp
+.Ss logfile
+Displays the path to the log file for
+.Ar portname .
+.Pp
 .Ss echo
 Writes to stdout the arguments passed to
 .Nm .
@@ -629,18 +636,13 @@
 .Ss edit
 Opens
 .Ar Portfile 
-with your default editor specified in your shell's environment variable. Alias
-.Ar ed
-also invokes this command.
+with your default editor specified in your shell's environment variable.
 .Pp
 You can also use the
 .Fl -editor
 flag on the command line to specify an alternative editor. For example:
 .Dl port edit --editor nano apache2
 .Pp
-.Ss ed
-An alias for
-.Ic edit .
 .Ss fetch
 Fetches the distribution files required to build
 .Ar portname .

Modified: branches/gsoc11-statistics/base/doc/portfile.7
===================================================================
--- branches/gsoc11-statistics/base/doc/portfile.7	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/doc/portfile.7	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,6 +1,6 @@
 .\" portfile.7
 .\"
-.\" Copyright (c) 2004-2011 The MacPorts Project
+.\" Copyright (c) 2004-2013 The MacPorts Project
 .\" Copyright (c) 2002-2003 Apple Inc.
 .\" All rights reserved.
 .\"
@@ -449,6 +449,23 @@
 .br
 .Sy Example:
 .Dl installs_libs no
+.It Ic license_noconflict
+By default, it is assumed that ports may use libraries or headers from their
+dependencies and thus form a derivative work. A dependency with an
+incompatible license thus prevents the port from being distributed in binary
+form. If a dependency with an incompatible license is not used in such a way
+that a derivative work is formed, or should not prevent binary distribution
+for any other reason, add its name to this list.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em none
+.br
+.Sy Example:
+.Dl license_noconflict openssl
+.Dl license_noconflict readline gdbm
 .El
 .Sh TARGET HOOKS
 A number of hooks are available for customizing many of the standard
@@ -1093,7 +1110,7 @@
 .Em optional
 .br
 .Sy Default:
-.Em -O2
+.Em -Os
 .br
 .Sy Example:
 .Dl configure.optflags -O3
@@ -1231,6 +1248,8 @@
 .Em macports-gcc-4.4
 .Em macports-gcc-4.5
 .Em macports-gcc-4.6
+.Em macports-gcc-4.7
+.Em macports-gcc-4.8
 .Em macports-llvm-gcc-4.2
 use the vanilla compiler suites installed via MacPorts.
 .br
@@ -1238,7 +1257,7 @@
 .Em optional
 .br
 .Sy Values:
-.Em gcc-3.3 gcc-4.0 gcc-4.2 llvm-gcc-4.2 clang apple-gcc-4.0 apple-gcc-4.2 macports-gcc-4.2 macports-gcc-4.3 macports-gcc-4.4 macports-gcc-4.5 macports-gcc-4.6 macports-llvm-gcc-4.2
+.Em gcc-3.3 gcc-4.0 gcc-4.2 llvm-gcc-4.2 clang apple-gcc-4.0 apple-gcc-4.2 macports-gcc-4.2 macports-gcc-4.3 macports-gcc-4.4 macports-gcc-4.5 macports-gcc-4.6 macports-gcc-4.7 macports-gcc-4.8 macports-llvm-gcc-4.2
 .br
 .Sy Example:
 .Dl configure.compiler llvm-gcc-4.2
@@ -1655,8 +1674,8 @@
 .It Ic livecheck.type
 What kind of check to perform to figure out if the software has been updated.
 Can be
-.Em freshmeat
-(uses the date_updated tag of the freshmeat XML file),
+.Em freecode
+(uses the date_updated tag of the freecode XML file),
 .Em sourceforge
 (uses the version of the latest file release of the project),
 .Em googlecode
@@ -1680,19 +1699,19 @@
 or
 .Em googlecode
 if the master_sites is one of these, else
-.Em freshmeat
+.Em freecode
 .br
 .Sy Values:
-.Em freshmeat sourceforge googlecode moddate regex regexm md5 none
+.Em freecode sourceforge googlecode moddate regex regexm md5 none
 .It Ic livecheck.name
-Name of the project for live checks (used for freshmeat, sourceforge, and googlecode checks).
+Name of the project for live checks (used for freecode, sourceforge, and googlecode checks).
 .br
 .Sy Type:
 .Em optional
 .br
 .Sy Default:
 .Em ${name}
-or the sourceforge/freshmeat/googlecode project name if it can be guessed by looking at the master_sites.
+or the sourceforge/freecode/googlecode project name if it can be guessed by looking at the master_sites.
 .It Ic livecheck.distname
 Name of the file release (used for sourceforge and googlecode checks).
 For sourceforge releases use the name of the package release.
@@ -1724,7 +1743,7 @@
 .Sy Default:
 .Em ${homepage}
 or
-.Em http://freshmeat.net/projects-xml/${livecheck.name}/${livecheck.name}.xml
+.Em http://freecode.com/projects/${livecheck.name}/releases.atom
 or
 .Em http://sourceforge.net/export/rss2_projfiles.php?project=${livecheck.name}
 or

Modified: branches/gsoc11-statistics/base/m4/tcl.m4
===================================================================
--- branches/gsoc11-statistics/base/m4/tcl.m4	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/m4/tcl.m4	2013-04-09 18:46:31 UTC (rev 105085)
@@ -110,8 +110,10 @@
 			`ls -d /usr/local/lib 2>/dev/null` \
 			`ls -d /usr/contrib/lib 2>/dev/null` \
 			`ls -d /usr/pkg/lib 2>/dev/null` \
+			`ls -d /usr/local/lib/tcl8.6 2>/dev/null` \
 			`ls -d /usr/local/lib/tcl8.5 2>/dev/null` \
 			`ls -d /usr/local/lib/tcl8.4 2>/dev/null` \
+			`ls -d /usr/lib/tcl8.6 2>/dev/null` \
 			`ls -d /usr/lib/tcl8.5 2>/dev/null` \
 			`ls -d /usr/lib/tcl8.4 2>/dev/null` \
 			; do

Modified: branches/gsoc11-statistics/base/portmgr/ReleaseProcess
===================================================================
--- branches/gsoc11-statistics/base/portmgr/ReleaseProcess	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/portmgr/ReleaseProcess	2013-04-09 18:46:31 UTC (rev 105085)
@@ -137,30 +137,38 @@
  Security experts in the project, would you be interested in leading this effort? Eric? Mark? Anyone else?)
 
 
-=== Create Release Disk Image(s) ===
+=== Create Release Packages and Disk Image(s) ===
 
 The dmg is a Mac OS X disk image that contains a standalone installer, configured in the usual way, for major
 MacPorts releases (x.y.0), named in a consistent fashion and incorporating the OS version for which it
 was built.
 
+For 10.6 and newer, we now build flat packages, so an enclosing dmg is not necessary.
+
  MacPorts-2.0.0-10.5-Leopard.dmg
- MacPorts-2.0.0-10.6-SnowLeopard.dmg
- MacPorts-2.0.0-10.7-Lion.dmg
+ MacPorts-2.0.0-10.6-SnowLeopard.pkg
+ MacPorts-2.0.0-10.7-Lion.pkg
 
-To create a disk image, use the MacPorts port. The Portfile will need to be updated to incorporate the
+To create a pkg or dmg, use the MacPorts port. The Portfile will need to be updated to incorporate the
 proper release version and checksums, and the release tarballs will need to be already uploaded to the
-downloads section of the site (wherefrom the sources are fetched by the MacPorts port to build the dmg
-for the release). Make sure the ports tree you're using to build the dmg's is fully up to date.
+downloads section of the site (wherefrom the sources are fetched by the MacPorts port to build the pkg
+for the release). Make sure the ports tree you're using to build the pkgs is fully up to date.
 
+ sudo port -d pkg MacPorts
  sudo port -d dmg MacPorts
 
-Name the dmg appropriately, and generate checksums, which will need to be added to the existing checksums
-file in the downloads directory:
+Name each pkg/dmg appropriately, and then sign the pkgs with a Developer ID (make sure to use the
+Installer certificate, not the Application one):
 
  cd work
- mv MacPorts-2.0.0.dmg MacPorts-2.0.0-10.6-SnowLeopard.dmg
- for dmg in MacPorts-2.0.0-*.dmg; do for type in -md5 -sha1 -ripemd160 -sha256; do openssl dgst $type $dmg; done >> MacPorts-2.0.0.chk.txt; done
+ mv MacPorts-2.0.0.pkg unsigned/MacPorts-2.0.0-10.7-Lion.pkg
+ productsign --sign "Developer ID Installer: John Doe" unsigned/MacPorts-2.0.0-10.7-Lion.pkg MacPorts-2.0.0-10.7-Lion.pkg
 
+After signing, generate checksums, which will need to be added to the existing checksums
+file in the downloads directory:
+
+ for pkg in MacPorts-2.0.0-*.{pkg,dmg}; do for type in -md5 -sha1 -ripemd160 -sha256; do openssl dgst $type $pkg; done >> MacPorts-2.0.0.chk.txt; done
+
 These new products, along with the new checksums, also have to be posted to the appropriate
 directory of the MacPorts distfiles server. Developers are required to validate the generated installer as
 thoroughly as possible through extensive testing, which is mainly why this step of the release process
@@ -219,9 +227,10 @@
 Once the release has been posted, notification of the release should be sent/posted to the following places:
 
  * The macports-announce@, macports-users@ and macports-dev@ mailing lists.
- * The MacPorts website, by adapting the $macports_version_major and $macports_version_latest variables as appropriate in the trunk/www/includes/common.inc file.
+ * The MacPorts website, by adapting the $macports_version_major and $macports_version_latest variables as
+   appropriate in the trunk/www/includes/common.inc file.
  * [https://trac.macports.org/news/] The MacOSforge news section (submitter: portmgr@)
- * [http://freshmeat.net/projects/macports/ Freshmeat] (submitter: mww@)
+ * [http://freecode.com/projects/macports/ Freecode] (submitter: mww@)
  * [http://www.versiontracker.com/dyn/moreinfo/macosx/26679 VersionTracker] (submitter: mij@)
  * [http://sourceforge.net/projects/macports/ sourceforge] (submitted: rhwood@)
  * [http://www.macupdate.com/info.php/id/21309/macports MacUpdate] (submitter: ???)

Copied: branches/gsoc11-statistics/base/portmgr/dmg/Distribution (from rev 105084, trunk/base/portmgr/dmg/Distribution)
===================================================================
--- branches/gsoc11-statistics/base/portmgr/dmg/Distribution	                        (rev 0)
+++ branches/gsoc11-statistics/base/portmgr/dmg/Distribution	2013-04-09 18:46:31 UTC (rev 105085)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<installer-gui-script minSpecVersion="1">
+    <title>MacPorts</title>
+    <options customize="never"/>
+    <allowed-os-versions><os-version min="__XVERS__" before="__NEXT_XVERS__"/></allowed-os-versions>
+    <installation-check script="InstallationCheck();"/>
+    <script><![CDATA[
+function InstallationCheck () {
+    if (system.compareVersions(system.version.ProductVersion, "__XVERS__") < 0
+        || system.compareVersions(system.version.ProductVersion, "__NEXT_XVERS__") >= 0) {
+        my.result.message = "This package is meant to be installed on Mac OS X __XVERS__.";
+        my.result.type = 'Fatal';
+        return false;
+    }
+    if (system.files.fileExistsAtPath('__PREFIX__/etc/ports/dp_version')) {
+        my.result.message = "Your existing MacPorts or DarwinPorts installation is too old to be upgraded by this installer. Please install MacPorts 1.7.1 first.";
+        my.result.type = 'Fatal';
+        return false;
+    }
+    if (!system.files.fileExistsAtPath('/usr/bin/xcodebuild')) {
+        my.result.message = "Xcode is not installed, or was installed without __XCODECLITOOLS__.";
+        my.result.type = 'Warn';
+        return false;
+    }
+    return true;
+}
+    ]]>
+    </script>
+    <background file="background.tiff" mime-type="image/tiff" alignment="bottomleft" scaling="none"/>
+    <license mime-type="text/html" file="License.html"/>
+    <readme mime-type="text/rtf" file="ReadMe.rtf"/>
+    <welcome mime-type="text/html" file="Welcome.html"/>
+    <choices-outline>
+        <line choice="default">
+            <line choice="org.macports.MacPorts"/>
+        </line>
+    </choices-outline>
+    <choice id="default"/>
+    <choice id="org.macports.MacPorts" visible="false">
+        <pkg-ref id="org.macports.MacPorts"/>
+    </choice>
+    <pkg-ref id="org.macports.MacPorts">MacPorts-__VERSION__-component.pkg</pkg-ref>
+</installer-gui-script>

Modified: branches/gsoc11-statistics/base/portmgr/dmg/License.html
===================================================================
--- branches/gsoc11-statistics/base/portmgr/dmg/License.html	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/portmgr/dmg/License.html	2013-04-09 18:46:31 UTC (rev 105085)
@@ -15,7 +15,7 @@
 
     <body>
     
-        <p>Copyright (c) 2002 - 2003, Apple Inc.<br>Copyright (c) 2004 - 2011, The MacPorts Project.</p>
+        <p>Copyright (c) 2002 - 2003, Apple Inc.<br>Copyright (c) 2004 - 2013, The MacPorts Project.</p>
         <p>All rights reserved.</p>
         <p><br></p>
         

Modified: branches/gsoc11-statistics/base/portmgr/dmg/postflight
===================================================================
--- branches/gsoc11-statistics/base/portmgr/dmg/postflight	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/portmgr/dmg/postflight	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,7 +1,7 @@
 #!/bin/bash
 # -*- coding: utf-8; mode: shell-script-mode; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=sh:et:sw=4:ts=4:sts=4
 #
-# Copyright (c) 2008-2011 The MacPorts Project
+# Copyright (c) 2008-2012 The MacPorts Project
 # Copyright (c) 2002-2007 Juan Manuel Palacios <jmpp at macports.org>, The MacPorts Project.
 # All rights reserved.
 #
@@ -36,7 +36,7 @@
 #set -x
 
 # Script identification ('cause more often than not the svn Id is not expanded):
-VERSION=2.0.0
+VERSION=2.1.0
 
 # Abstraction variables:
 PREFIX=__PREFIX__
@@ -56,7 +56,7 @@
 
 # Create config files from defaults if not present
 function setup_configs {
-    for f in macports.conf pubkeys.conf sources.conf variants.conf ; do
+    for f in archive_sites.conf macports.conf pubkeys.conf sources.conf variants.conf ; do
         if [[ ! -f ${CONFIGPATH}/${f} ]]; then
             echo "Copying ${f}.default to ${f}"
             /bin/cp ${CONFIGPATH}/${f}.default ${CONFIGPATH}/${f}
@@ -67,12 +67,13 @@
 
 # Command to update the MacPorts installation through "selfupdate":
 function update_macports {
+    SCRIPT_DIR=$(dirname $0)
     # Add [default] tag to the central MacPorts repository, if it isn't already
     echo "Adding [default] tag to sources.conf if needed..."
-    ${TCLSH} ${PACKAGE_PATH}/Contents/Resources/upgrade_sources_conf_default.tcl ${PREFIX}
+    ${TCLSH} ${SCRIPT_DIR}/upgrade_sources_conf_default.tcl ${PREFIX}
     # Convert image directories (and direct mode installs) to image archives
     echo "Updating port image format..."
-    ${TCLSH} ${PACKAGE_PATH}/Contents/Resources/images_to_archives.tcl ${MACPORTS_TCL_DIR}
+    ${TCLSH} ${SCRIPT_DIR}/images_to_archives.tcl ${MACPORTS_TCL_DIR}
 
     echo "Synchronizing the MacPorts installation with the project's rsync server..."
     if ! ${BINPATH}/port -v selfupdate; then 
@@ -165,7 +166,7 @@
         ${DSCL} -q . -create /Users/${RUNUSR} RealName MacPorts
         ${DSCL} -q . -create /Users/${RUNUSR} Password \*
         ${DSCL} -q . -create /Users/${RUNUSR} PrimaryGroupID $(${DSCL} -q . -read /Groups/${RUNUSR} PrimaryGroupID | /usr/bin/awk '{print $2}')
-        ${DSCL} -q . -create /Users/${RUNUSR} NFSHomeDirectory /var/empty
+        ${DSCL} -q . -create /Users/${RUNUSR} NFSHomeDirectory ${PREFIX}/var/macports/home
         ${DSCL} -q . -create /Users/${RUNUSR} UserShell /usr/bin/false
     fi
     if [[ $(sw_vers -productVersion | /usr/bin/awk -F . '{print $2}') -eq 4 ]]; then
@@ -176,6 +177,10 @@
             ${DSCL} -q . -create /Users/${RUNUSR} RealName MacPorts
         fi
     fi
+    if [[ "$(${DSCL} -q . -read /Users/${RUNUSR} NFSHomeDirectory)" = "NFSHomeDirectory: /var/empty" ]]; then
+        echo "Updating home directory location for user \"${RUNUSR}\""
+        ${DSCL} -q . -create /Users/${RUNUSR} NFSHomeDirectory ${PREFIX}/var/macports/home
+    fi
 }
 
 echo "The MacPorts Project, postflight script version ${VERSION}: checking the shell environment for user \"${USER}\"."

Modified: branches/gsoc11-statistics/base/portmgr/jobs/mprsyncup
===================================================================
--- branches/gsoc11-statistics/base/portmgr/jobs/mprsyncup	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/portmgr/jobs/mprsyncup	2013-04-09 18:46:31 UTC (rev 105085)
@@ -55,9 +55,7 @@
 PATH=${PREFIX}/bin:/bin:/usr/bin:/usr/sbin:/opt/local/bin
 
 # platforms we generate indexes for
-PLATFORMS="8_powerpc 8_i386 9_powerpc 9_i386 10_i386 11_i386"
-# copy new index of this platform to old index location for MP v1.8 compatability
-OLD_INDEX_PLATFORM="9_i386"
+PLATFORMS="8_powerpc 8_i386 9_powerpc 9_i386 10_i386 11_i386 12_i386"
 
 # Sources information:
 SVNURL=https://svn.macports.org/repository/macports
@@ -87,7 +85,7 @@
 # Read what tag we're releasing from, switch to/checkout a copy, export and rsync it to ${RSYNCROOT}/release/base:
 read RELEASE_URL < ${TBASE}/${RELEASE_URL_FILE}
 if [ ! -n ${RELEASE_URL} ]; then
-    echo "no RELEASE_URL specified in svn trunk, baling out!"
+    echo "no RELEASE_URL specified in svn trunk, bailing out!"
     exit 1
 fi
 if [ -d ${RBASE}/.svn ]; then
@@ -127,11 +125,9 @@
 popd
 
 for PLATFORM in $PLATFORMS; do
-	$PORTINDEX -p darwin_${PLATFORM} -o PortIndex_darwin_${PLATFORM};
+	$PORTINDEX -p macosx_${PLATFORM} -o PortIndex_darwin_${PLATFORM};
 done
 
-# support MP 1.8
-cp PortIndex_darwin_${OLD_INDEX_PLATFORM}/* ./
 popd
 
 if [ ! -d ${RSYNCROOT}/release/ports ]; then

Modified: branches/gsoc11-statistics/base/portmgr/jobs/port_binary_distributable.tcl
===================================================================
--- branches/gsoc11-statistics/base/portmgr/jobs/port_binary_distributable.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/portmgr/jobs/port_binary_distributable.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -35,12 +35,12 @@
 # to do so below.
 # 'Noncommercial' means a license that prohibits commercial use.
 set good_licenses {afl agpl apache apsl artistic autoconf beopen bitstreamvera \
-                   boost bsd bsd-old cecill cecill-b cecill-c cnri copyleft \
+                   boost bsd bsd-old cddl cecill cecill-b cecill-c cnri copyleft \
                    cpl curl epl fpll fontconfig freetype gd gfdl gpl \
-                   gplconflict ibmpl ijg isc  jasper lgpl libtool lppl mit \
+                   gplconflict ibmpl ijg isc jasper lgpl libtool lppl mit \
                    mpl ncsa noncommercial openldap openssl permissive php \
                    psf public-domain qpl restrictive/distributable ruby \
-                   sleepycat ssleay tcl/tk w3c wtfpl x11 zlib wxwidgets zpl}
+                   sleepycat ssleay tcl/tk vim w3c wtfpl wxwidgets x11 zlib zpl}
 foreach lic $good_licenses {
     set license_good($lic) 1
 }
@@ -56,38 +56,42 @@
 
 # keep these values sorted
 array set license_conflicts \
-    "afl {cecill gpl}
-    agpl {apache-1 apache-1.1 cecill gpl-1 gpl-2 gplconflict noncommercial restrictive/distributable}
-    apache {cecill gpl-1 gpl-2}
+    "afl {agpl cecill gpl}
+    agpl {afl apache-1 apache-1.1 apsl beopen bsd-old cddl cecill cnri cpl epl gd gpl-1 gpl-2 gplconflict ibmpl lppl mpl noncommercial openssl php qpl restrictive/distributable ruby ssleay zpl-1}
+    agpl-1 {apache freetype gpl-3 gpl-3+ lgpl-3 lgpl-3+}
+    apache {agpl-1 cecill gpl-1 gpl-2}
     apache-1 {agpl gpl}
     apache-1.1 {agpl gpl}
-    apsl {cecill gpl}
-    beopen {cecill gpl}
-    bsd-old {cecill gpl}
-    cnri {cecill gpl}
-    cpl {cecill gpl}
-    cecill {afl agpl apache apsl beopen bsd-old cnri cpl epl gd gplconflict ibmpl lppl mpl noncommercial openssl php qpl restrictive/distributable ruby ssleay zpl-1}
-    epl {cecill gpl}
-    freetype {gpl-2}
-    gd {cecill gpl}
-    gpl {afl agpl apache-1 apache-1.1 apsl beopen cnri bsd-old cpl epl gd gplconflict ibmpl lppl mpl noncommercial openssl php qpl restrictive/distributable ruby ssleay zpl-1}
-    gpl-1 {apache gpl-3 gpl-3+ lgpl-3 lgpl-3+}
-    gpl-2 {apache freetype gpl-3 gpl-3+ lgpl-3 lgpl-3+}
-    gpl-3 {gpl-1 gpl-2}
-    gpl-3+ {gpl-1 gpl-2}
-    ibmpl {cecill gpl}
-    lgpl-3 {gpl-1 gpl-2}
-    lgpl-3+ {gpl-1 gpl-2}
-    lppl {cecill gpl}
-    mpl {cecill gpl}
-    openssl {cecill gpl}
+    apsl {agpl cecill gpl}
+    beopen {agpl cecill gpl}
+    bsd-old {agpl cecill gpl}
+    cddl {agpl cecill gpl}
+    cecill {afl agpl apache apsl beopen bsd-old cddl cnri cpl epl gd gplconflict ibmpl lppl mpl noncommercial openssl php qpl restrictive/distributable ruby ssleay zpl-1}
+    cnri {agpl cecill gpl}
+    cpl {agpl cecill gpl}
+    epl {agpl cecill gpl}
+    freetype {agpl-1 gpl-2}
+    gd {agpl cecill gpl}
+    gpl {afl apache-1 apache-1.1 apsl beopen cddl cnri bsd-old cpl epl gd gplconflict ibmpl lppl mpl noncommercial openssl php qpl restrictive/distributable ruby ssleay zpl-1}
+    gpl-1 {agpl apache gpl-3 gpl-3+ lgpl-3 lgpl-3+}
+    gpl-2 {agpl apache freetype gpl-3 gpl-3+ lgpl-3 lgpl-3+}
+    gpl-3 {agpl-1 gpl-1 gpl-2}
+    gpl-3+ {agpl-1 gpl-1 gpl-2}
+    gplconflict {agpl cecill gpl}
+    ibmpl {agpl cecill gpl}
+    lgpl-3 {agpl-1 gpl-1 gpl-2}
+    lgpl-3+ {agpl-1 gpl-1 gpl-2}
+    lppl {agpl cecill gpl}
+    mpl {agpl cecill gpl}
+    noncommercial {agpl cecill gpl}
+    openssl {agpl cecill gpl}
     opensslexception [all_licenses_except openssl ssleay]
-    php {cecill gpl}
-    qpl {cecill gpl}
+    php {agpl cecill gpl}
+    qpl {agpl cecill gpl}
     restrictive/distributable {agpl cecill gpl}
-    ruby {cecill gpl}
-    ssleay {cecill gpl}
-    zpl-1 {cecill gpl}"
+    ruby {agpl cecill gpl}
+    ssleay {agpl cecill gpl}
+    zpl-1 {agpl cecill gpl}"
 
 proc printUsage {} {
     puts "Usage: $::argv0 \[-hvV\] \[-t macports-tcl-path\] port-name \[variants...\]"
@@ -133,6 +137,9 @@
         # when in doubt, assume code from the dep is incorporated
         lappend ret yes
     }
+    if {[info exists portInfo(license_noconflict)]} {
+        lappend ret $portInfo(license_noconflict)
+    }
     return $ret
 }
 
@@ -150,7 +157,13 @@
     global license_good license_conflicts
     array set portSeen {}
     set top_info [infoForPort $portName $variantInfo]
+    if {$top_info == {}} {
+        return 1
+    }
     set top_license [lindex $top_info 1]
+    foreach noconflict_port [lindex $top_info 3] {
+        set noconflict_ports($noconflict_port) 1
+    }
     set top_license_names {}
     # check that top-level port's license(s) are good
     foreach sublist $top_license {
@@ -182,6 +195,9 @@
         # mark as seen and remove from the list
         set portSeen($aPort) 1
         set portList [lreplace $portList 0 0]
+        if {[info exists noconflict_ports($aPort)]} {
+            continue
+        }
 
         set aPortInfo [infoForPort $aPort $variantInfo]
         set aPortLicense [lindex $aPortInfo 1]
@@ -239,9 +255,14 @@
             }
         }
 
+        # skip deps that are explicitly stated to not conflict
+        array unset aPort_noconflict_ports
+        foreach noconflict_port [lindex $aPortInfo 3] {
+            set aPort_noconflict_ports($noconflict_port) 1
+        }
         # add its deps to the list
         foreach possiblyNewPort [lindex $aPortInfo 0] {
-            if {![info exists portSeen($possiblyNewPort)]} {
+            if {![info exists portSeen($possiblyNewPort)] && ![info exists aPort_noconflict_ports($possiblyNewPort)]} {
                 lappend portList $possiblyNewPort
             }
         }

Modified: branches/gsoc11-statistics/base/regen.sh
===================================================================
--- branches/gsoc11-statistics/base/regen.sh	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/regen.sh	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,4 +1,4 @@
 #!/bin/sh
 
-autoconf --warnings=all
-autoheader --warnings=all
+autoconf --warnings=all --force
+autoheader --warnings=all --force

Modified: branches/gsoc11-statistics/base/setupenv.bash.in
===================================================================
--- branches/gsoc11-statistics/base/setupenv.bash.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/setupenv.bash.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -34,6 +34,8 @@
     local sbinpath="@prefix_expanded@/sbin"
 
     local IFS=":"
+    local p
+
     for p in $PATH; do
         if [ "$p" == "$binpath" ]; then
             binpath=""
@@ -54,13 +56,14 @@
 }
 
 function export_manpath() {
-    mpath="@prefix_expanded@/share/man"
+    local mpath="@prefix_expanded@/share/man"
+    local IFS=":"
+    local p
 
     if [ -z "$MANPATH" ]; then
         return
     fi
 
-    local IFS=":"
     for p in $MANPATH; do
         if [ "$p" == "$mpath" ]; then
             mpath=""
@@ -75,7 +78,7 @@
 }
 
 function export_display() {
-    if [ -z $DISPLAY ]; then
+    if [ -z "$DISPLAY" ]; then
         export DISPLAY=":0.0"
     fi
 }

Modified: branches/gsoc11-statistics/base/src/config.h.in
===================================================================
--- branches/gsoc11-statistics/base/src/config.h.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/config.h.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -89,7 +89,7 @@
 /* Define if you have the `md' library (-lmd). */
 #undef HAVE_LIBMD
 
-/* Define to 1 if you have the `readline' library (-lreadline). */
+/* Define to 1 if you have the 'readline' library (-lreadline). */
 #undef HAVE_LIBREADLINE
 
 /* Define to 1 if you have the <limits.h> header file. */
@@ -269,3 +269,7 @@
 
 /* Attribute to mark unused variables */
 #undef UNUSED
+
+/* define sqlite3_prepare to sqlite_prepare_v2 if the latter is not available
+   */
+#undef sqlite3_prepare_v2

Modified: branches/gsoc11-statistics/base/src/cregistry/entry.c
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/entry.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/entry.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -121,7 +121,7 @@
     reg_entry* entry = NULL;
     char* query = "INSERT INTO registry.ports "
         "(name, version, revision, variants, epoch) VALUES (?, ?, ?, ?, ?)";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, name, -1, SQLITE_STATIC)
                 == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 2, version, -1, SQLITE_STATIC)
@@ -190,7 +190,7 @@
         query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
         "AND revision=? AND variants=? AND epoch!=?";
     }
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, name, -1, SQLITE_STATIC)
                 == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 2, version, -1, SQLITE_STATIC)
@@ -249,12 +249,12 @@
     char* ports_query = "DELETE FROM registry.ports WHERE id=?";
     char* files_query = "DELETE FROM registry.files WHERE id=?";
     char* dependencies_query = "DELETE FROM registry.dependencies WHERE id=?";
-    if ((sqlite3_prepare(reg->db, ports_query, -1, &ports, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, ports_query, -1, &ports, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(ports, 1, entry->id) == SQLITE_OK)
-            && (sqlite3_prepare(reg->db, files_query, -1, &files, NULL)
+            && (sqlite3_prepare_v2(reg->db, files_query, -1, &files, NULL)
                 == SQLITE_OK)
             && (sqlite3_bind_int64(files, 1, entry->id) == SQLITE_OK)
-            && (sqlite3_prepare(reg->db, dependencies_query, -1, &dependencies,
+            && (sqlite3_prepare_v2(reg->db, dependencies_query, -1, &dependencies,
                     NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(dependencies, 1, entry->id) == SQLITE_OK)) {
         int r;
@@ -496,7 +496,7 @@
     sqlite3_stmt* stmt = NULL;
     char* query = "SELECT id FROM registry.files WHERE actual_path=? AND active";
     int lower_bound = 0;
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, path, -1, SQLITE_STATIC)
                 == SQLITE_OK)) {
         int r;
@@ -543,7 +543,7 @@
     sqlite3_stmt* stmt = NULL;
     sqlite_int64 result = 0;
     char* query = "SELECT id FROM registry.files WHERE actual_path=? AND active";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, path, -1, SQLITE_STATIC)
                 == SQLITE_OK)) {
         int r;
@@ -580,7 +580,7 @@
     const char *text;
     query = sqlite3_mprintf("SELECT %q FROM registry.ports WHERE id=%lld", key,
             entry->id);
-    if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         do {
             r = sqlite3_step(stmt);
@@ -638,7 +638,7 @@
     char* query;
     query = sqlite3_mprintf("UPDATE registry.ports SET %q = '%q' WHERE id=%lld",
             key, value, entry->id);
-    if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         do {
             r = sqlite3_step(stmt);
@@ -686,7 +686,7 @@
     sqlite3_stmt* stmt = NULL;
     char* insert = "INSERT INTO registry.files (id, path, mtime, active) "
         "VALUES (?, ?, 0, 0)";
-    if ((sqlite3_prepare(reg->db, insert, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, insert, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
         int i;
         for (i=0; i<file_count && result; i++) {
@@ -738,7 +738,7 @@
     int result = 1;
     sqlite3_stmt* stmt = NULL;
     char* query = "DELETE FROM registry.files WHERE path=? AND id=?";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 2, entry->id) == SQLITE_OK)) {
         int i;
         for (i=0; i<file_count && result; i++) {
@@ -795,7 +795,7 @@
     reg_registry* reg = entry->reg;
     sqlite3_stmt* stmt = NULL;
     char* query = "SELECT path FROM registry.files WHERE id=? ORDER BY path";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
         char** result = malloc(10*sizeof(char*));
         int result_count = 0;
@@ -863,7 +863,7 @@
     sqlite3_stmt* stmt = NULL;
     char* query = "SELECT actual_path FROM registry.files WHERE id=? "
         "AND active ORDER BY actual_path";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)) {
         char** result = malloc(10*sizeof(char*));
         int result_count = 0;
@@ -946,8 +946,8 @@
         as_files = files;
     }
 
-    if (sqlite3_prepare(reg->db, select_query, -1, &select, NULL) == SQLITE_OK){
-        if ((sqlite3_prepare(reg->db, update_query, -1, &update, NULL)
+    if (sqlite3_prepare_v2(reg->db, select_query, -1, &select, NULL) == SQLITE_OK){
+        if ((sqlite3_prepare_v2(reg->db, update_query, -1, &update, NULL)
                 == SQLITE_OK)
                 && (sqlite3_bind_int64(update, 3, entry->id) == SQLITE_OK)) {
             for (i=0; i<file_count && result; i++) {
@@ -1038,7 +1038,7 @@
     int i;
     sqlite3_stmt* stmt = NULL;
     char* query = "UPDATE registry.files SET active=0 WHERE actual_path=? AND id=?";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 2, entry->id) == SQLITE_OK)) {
         for (i=0; i<file_count && result; i++) {
             if (sqlite3_bind_text(stmt, 1, files[i], -1, SQLITE_STATIC)
@@ -1139,7 +1139,7 @@
     int result = 0;
     sqlite3_stmt* stmt = NULL;
     char* query = "INSERT INTO registry.dependencies (id, name) VALUES (?,?)";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_int64(stmt, 1, entry->id) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 2, name, -1, SQLITE_STATIC)
                 == SQLITE_OK)) {

Modified: branches/gsoc11-statistics/base/src/cregistry/entry.h
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/entry.h	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/entry.h	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/cregistry/file.c
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/file.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/file.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -108,7 +108,7 @@
     char* query = "SELECT id, path FROM registry.files WHERE id=? AND path=?";
     int lower_bound = 0;
 
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 1, id, -1, SQLITE_STATIC)
                 == SQLITE_OK)
             && (sqlite3_bind_text(stmt, 2, name, -1, SQLITE_STATIC)
@@ -237,7 +237,7 @@
     const char *text;
     query = sqlite3_mprintf("SELECT %q FROM registry.files WHERE id=%lld "
             "AND path='%q'", key, file->key.id, file->key.path);
-    if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         do {
             r = sqlite3_step(stmt);
@@ -292,7 +292,7 @@
     char* query;
     query = sqlite3_mprintf("UPDATE registry.files SET %q = '%q' WHERE id=%lld "
             "AND path='%q'", key, value, file->key.id, file->key.path);
-    if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         do {
             r = sqlite3_step(stmt);

Modified: branches/gsoc11-statistics/base/src/cregistry/registry.c
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/registry.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/registry.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,6 +4,7 @@
  * vim:expandtab:tw=80
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -117,6 +118,8 @@
         sqlite3_extended_result_codes(reg->db, 1);
 #endif
 
+        sqlite3_busy_timeout(reg->db, 25);
+
         if (init_db(reg->db, errPtr)) {
             reg->status = reg_none;
             *regPtr = reg;
@@ -204,7 +207,7 @@
         char* query = sqlite3_mprintf("ATTACH DATABASE '%q' AS registry", path);
         int r;
         do {
-            r = sqlite3_prepare(reg->db, query, -1, &stmt, NULL);
+            r = sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL);
         } while (r == SQLITE_BUSY);
         if (r == SQLITE_OK) {
             /* XXX: Busy waiting, consider using sqlite3_busy_handler/timeout */
@@ -229,6 +232,9 @@
                 }
             } while (r == SQLITE_BUSY);
 
+            sqlite3_finalize(stmt);
+            stmt = NULL;
+
             if (result) {
                 result &= update_db(reg->db, errPtr);
             }
@@ -263,7 +269,7 @@
         reg_throw(errPtr,REG_MISUSE,"no database is attached to this registry");
         return 0;
     }
-    if (sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         reg_entry* entry;
         Tcl_HashEntry* curr;
@@ -360,7 +366,7 @@
  * @return             true if success; false if failure
  */
 int reg_start_write(reg_registry* reg, reg_error* errPtr) {
-    if (reg_start(reg, "BEGIN EXCLUSIVE", errPtr)) {
+    if (reg_start(reg, "BEGIN IMMEDIATE", errPtr)) {
         reg->status |= reg_transacting | reg_can_write;
         return 1;
     } else {
@@ -371,7 +377,7 @@
 /**
  * Helper function for `reg_commit` and `reg_rollback`.
  */
-static int reg_end(reg_registry* reg, const char* query, reg_error* errPtr) {
+static int reg_end(reg_registry* reg, const char* query, reg_error* errPtr, int is_rollback) {
     if (!(reg->status & reg_transacting)) {
         reg_throw(errPtr, REG_MISUSE, "couldn't end transaction because no "
                 "transaction is open");
@@ -383,7 +389,7 @@
             if (r == SQLITE_OK) {
                 return 1;
             }
-        } while (r == SQLITE_BUSY);
+        } while (r == SQLITE_BUSY && !is_rollback);
         reg_sqlite_error(reg->db, errPtr, NULL);
         return 0;
     }
@@ -398,7 +404,7 @@
  * @return             true if success; false if failure
  */
 int reg_commit(reg_registry* reg, reg_error* errPtr) {
-    if (reg_end(reg, "COMMIT", errPtr)) {
+    if (reg_end(reg, "COMMIT", errPtr, 0)) {
         reg->status &= ~(reg_transacting | reg_can_write);
         return 1;
     } else {
@@ -415,7 +421,7 @@
  * @return             true if success; false if failure
  */
 int reg_rollback(reg_registry* reg, reg_error* errPtr) {
-    if (reg_end(reg, "ROLLBACK", errPtr)) {
+    if (reg_end(reg, "ROLLBACK", errPtr, 1)) {
         reg->status &= ~(reg_transacting | reg_can_write);
         return 1;
     } else {
@@ -446,7 +452,7 @@
         return 0;
     }
 
-    if (sqlite3_prepare(db, "VACUUM", -1, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(db, "VACUUM", -1, &stmt, NULL) == SQLITE_OK) {
         int r;
         /* XXX: Busy waiting, consider using sqlite3_busy_handler/timeout */
         do {

Modified: branches/gsoc11-statistics/base/src/cregistry/registry.h
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/registry.h	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/registry.h	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,6 +4,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/cregistry/sql.c
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/sql.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/sql.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -51,19 +52,38 @@
  */
 int do_queries(sqlite3* db, char** queries, reg_error* errPtr) {
     char** query;
+    sqlite3_stmt* stmt = NULL;
+    int r = SQLITE_OK;
+
     for (query = queries; *query != NULL; query++) {
-        sqlite3_stmt* stmt = NULL;
-        if ((sqlite3_prepare(db, *query, -1, &stmt, NULL) != SQLITE_OK)
-                || (sqlite3_step(stmt) != SQLITE_DONE)) {
-            reg_sqlite_error(db, errPtr, *query);
-            if (stmt) {
-                sqlite3_finalize(stmt);
-            }
-            return 0;
+        if ((r = sqlite3_prepare_v2(db, *query, -1, &stmt, NULL)) != SQLITE_OK) {
+            sqlite3_finalize(stmt);
+            break;
         }
+
+        do {
+            r = sqlite3_step(stmt);
+        } while (r == SQLITE_BUSY);
+
         sqlite3_finalize(stmt);
+
+        /* Either execution succeeded and r == SQLITE_DONE | SQLITE_ROW, or there was an error */
+        if (r != SQLITE_DONE && r != SQLITE_ROW) {
+            /* stop executing statements in case of errors */
+            break;
+        }
     }
-    return 1;
+
+    switch (r) {
+        case SQLITE_OK:
+        case SQLITE_DONE:
+        case SQLITE_ROW:
+            return 1;
+        default:
+            /* handle errors */
+            reg_sqlite_error(db, errPtr, *query);
+            return 0;
+    }
 }
 
 /**
@@ -150,6 +170,35 @@
 }
 
 /**
+ * Tries to ROLLBACK a currently running transaction on the SQLite database.
+ * Errors are silently ignored to preserve errors that have been set before and
+ * are probably the root cause of why we did the rollback in the first place.
+ *
+ * @param [in] db    database to rollback
+ * @return           true if success, false on failure
+ */
+static int rollback_db(sqlite3* db) {
+    char* rollback = "ROLLBACK";
+    sqlite3_stmt* stmt = NULL;
+
+    /*puts("Attempting to ROLLBACK...");*/
+
+    if (sqlite3_prepare_v2(db, rollback, -1, &stmt, NULL) != SQLITE_OK) {
+        /*printf("failed prepare: %d: %s\n", sqlite3_errcode(db), sqlite3_errmsg(db));*/
+        return 0;
+    }
+
+    if (sqlite3_step(stmt) != SQLITE_DONE) {
+        /*printf("failed step: %d: %s\n", sqlite3_errcode(db), sqlite3_errmsg(db));*/
+        return 0;
+    }
+
+    /*puts("success.");*/
+
+    return 1;
+}
+
+/**
  * Updates the database if necessary. This function queries the current database version
  * from the metadata table and executes SQL to update the schema to newer versions if needed.
  * After that, this function updates the database version number
@@ -160,45 +209,144 @@
  */
 int update_db(sqlite3* db, reg_error* errPtr) {
     const char* version;
-    char* query = "SELECT value FROM registry.metadata WHERE key = 'version'";
-    sqlite3_stmt *stmt = NULL;
+    int r;
+    int did_update = 0; /* true, if an update was done and the loop should be run again */
+    char* q_begin = "BEGIN";
+    char* q_version = "SELECT value FROM registry.metadata WHERE key = 'version'";
+    char* query = q_begin;
+    sqlite3_stmt* stmt = NULL;
 
-    if ((sqlite3_prepare(db, query, -1, &stmt, NULL) != SQLITE_OK)
-            || (sqlite3_step(stmt) != SQLITE_ROW)) {
-        goto reg_err_out;
-    }
-    if (NULL == (version = (const char *)sqlite3_column_text(stmt, 0))) {
-        goto reg_err_out;
-    }
-    /* can't call rpm_vercomp directly, because it is static, but can call sql_version */
-    if (sql_version(NULL, strlen(version), version, strlen("1.1"), "1.1") < 0) {
-        /* conversion necessary, add binary field and index to files table */
-        static char* version_1_1_queries[] = {
-            "BEGIN",
+    do {
+        did_update = 0;
 
-            "ALTER TABLE registry.files ADD COLUMN binary BOOL",
-            "CREATE INDEX registry.file_binary ON files(binary)",
+        /* open a transaction to prevent a check-and-change race condition between
+         * multiple port(1) instances */
+        if ((r = sqlite3_prepare_v2(db, query, -1, &stmt, NULL)) != SQLITE_OK) {
+            break;
+        }
 
-            "UPDATE registry.metadata SET value = '1.100' WHERE key = 'version'",
+        if ((r = sqlite3_step(stmt)) != SQLITE_DONE) {
+            break;
+        }
 
-            "COMMIT",
-            NULL
-        };
+        sqlite3_finalize(stmt);
+        stmt = NULL;
 
-        if (!do_queries(db, version_1_1_queries, errPtr)) {
-            goto err_out;
+        /* query current version number */
+        query = q_version;
+        if ((r = sqlite3_prepare_v2(db, query, -1, &stmt, NULL)) != SQLITE_OK) {
+            break;
         }
 
-        /* TODO: Walk the file tree and set the binary field */
-    }
-    sqlite3_finalize(stmt);
-    return 1;
+        r = sqlite3_step(stmt);
+        if (r == SQLITE_DONE) {
+            /* the version number was not found */
+            reg_throw(errPtr, REG_INVALID, "Version number in metadata table not found.");
+            sqlite3_finalize(stmt);
+            rollback_db(db);
+            return 0;
+        }
+        if (r != SQLITE_ROW) {
+            /* an error occured querying */
+            break;
+        }
+        if (NULL == (version = (const char *)sqlite3_column_text(stmt, 0))) {
+            reg_throw(errPtr, REG_INVALID, "Version number in metadata table is NULL.");
+            sqlite3_finalize(stmt);
+            rollback_db(db);
+            return 0;
+        }
 
-reg_err_out:
-    reg_sqlite_error(db, errPtr, query);
-err_out:
+        /* we can't call vercmp directly because it's static, but we have
+         * sql_version, which is basically an alias */
+        if (sql_version(NULL, -1, version, -1, "1.1") < 0) {
+            /* we need to update to 1.1, add binary field and index to files
+             * table */
+            static char* version_1_1_queries[] = {
+#if SQLITE_VERSION_NUMBER >= 3002000
+                "ALTER TABLE registry.files ADD COLUMN binary BOOL",
+#else
+                /*
+                 * SQLite < 3.2.0 doesn't support ALTER TABLE ADD COLUMN
+                 * Unfortunately, Tiger ships with SQLite < 3.2.0 (#34463)
+                 * This is taken from http://www.sqlite.org/faq.html#q11
+                 */
+
+                /* Create a temporary table */
+                "CREATE TEMPORARY TABLE mp_files_backup (id INTEGER, path TEXT, "
+                    "actual_path TEXT, active INT, mtime DATETIME, md5sum TEXT, editable INT, "
+                    "FOREIGN KEY(id) REFERENCES ports(id))",
+
+                /* Copy all data into the temporary table */
+                "INSERT INTO mp_files_backup SELECT id, path, actual_path, active, mtime, "
+                    "md5sum, editable FROM registry.files",
+
+                /* Drop the original table and re-create it with the new structure */
+                "DROP TABLE registry.files",
+                "CREATE TABLE registry.files (id INTEGER, path TEXT, actual_path TEXT, "
+                    "active INT, mtime DATETIME, md5sum TEXT, editable INT, binary BOOL, "
+                    "FOREIGN KEY(id) REFERENCES ports(id))",
+                "CREATE INDEX registry.file_port ON files(id)",
+                "CREATE INDEX registry.file_path ON files(path)",
+                "CREATE INDEX registry.file_actual ON files(actual_path)",
+
+                /* Copy all data back from temporary table */
+                "INSERT INTO registry.files (id, path, actual_path, active, mtime, md5sum, "
+                    "editable) SELECT id, path, actual_path, active, mtime, md5sum, "
+                    "editable FROM mp_files_backup",
+
+                /* Remove temporary table */
+                "DROP TABLE mp_files_backup",
+#endif
+                "CREATE INDEX registry.file_binary ON files(binary)",
+
+                "UPDATE registry.metadata SET value = '1.100' WHERE key = 'version'",
+
+                "COMMIT",
+                NULL
+            };
+
+            /* don't forget to finalize the version query here, or it might
+             * cause "cannot commit transaction - SQL statements in progress",
+             * see #32686 */
+            sqlite3_finalize(stmt);
+            stmt = NULL;
+
+            if (!do_queries(db, version_1_1_queries, errPtr)) {
+                rollback_db(db);
+                return 0;
+            }
+
+            did_update = 1;
+            continue;
+        }
+
+        /* add new versions here, but remember to:
+         *  - finalize the version query statement and set stmt to NULL
+         *  - do _not_ use "BEGIN" in your query list, since a transaction has
+         *    already been started for you
+         *  - end your query list with "COMMIT", NULL
+         *  - set did_update = 1 and continue;
+         */
+
+        /* if we arrive here, no update was done and we should end the
+         * transaction. Using ROLLBACK here causes problems when rolling back
+         * other transactions later in the program. */
+        sqlite3_finalize(stmt);
+        stmt = NULL;
+        r = sqlite3_exec(db, "COMMIT", NULL, NULL, NULL);
+    } while (did_update);
+
     sqlite3_finalize(stmt);
-    return 0;
+    switch (r) {
+        case SQLITE_OK:
+        case SQLITE_DONE:
+        case SQLITE_ROW:
+            return 1;
+        default:
+            reg_sqlite_error(db, errPtr, query);
+            return 0;
+    }
 }
 
 /**

Modified: branches/gsoc11-statistics/base/src/cregistry/sql.h
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/sql.h	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/sql.h	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/cregistry/util.c
===================================================================
--- branches/gsoc11-statistics/base/src/cregistry/util.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/cregistry/util.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,6 +4,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -122,6 +123,7 @@
  * @param [in] query_len length of the query (or -1 for automatic)
  * @param [out] objects  the objects selected
  * @param [in] fn        a function to convert sqlite3_stmts to the desired type
+ * @param [inout] data   data passed along to the cast function
  * @param [in] del       a function to delete the desired type of object
  * @param [out] errPtr   on error, a description of the error that occurred
  * @return               the number of objects if success; negative if failure
@@ -136,7 +138,7 @@
     if (!results || !fn) {
         return -1;
     }
-    if (sqlite3_prepare(reg->db, query, query_len, &stmt, NULL) == SQLITE_OK) {
+    if (sqlite3_prepare_v2(reg->db, query, query_len, &stmt, NULL) == SQLITE_OK) {
         int r;
         void* row;
         do {

Modified: branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/darwintracelib1.0/darwintrace.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -59,19 +59,21 @@
 #include <sys/paths.h>
 #endif
 
+#include <dirent.h>
+#include <dlfcn.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
-#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/socket.h>
 #include <sys/stat.h>
-#include <sys/param.h>
 #include <sys/syscall.h>
-#include <errno.h>
-#include <sys/socket.h>
+#include <sys/types.h>
 #include <sys/un.h>
+#include <unistd.h>
 
 #ifndef HAVE_STRLCPY
 /* Define strlcpy if it's not available. */
@@ -138,12 +140,13 @@
 void __darwintrace_copy_env() __attribute__((constructor));
 inline char* __darwintrace_alloc_env(const char* varName, const char* varValue);
 inline char* const* __darwintrace_restore_env(char* const envp[]);
-inline void __darwintrace_setup();
+static inline void __darwintrace_setup();
 inline void __darwintrace_cleanup_path(char *path);
-static char * exchange_with_port(const char * buf, size_t len, int answer, char failures);
+static char * exchange_with_port(const char * buf, size_t len, int answer);
 
-#define START_FD 81
-static int __darwintrace_fd = -1;
+static int __darwintrace_fd = -2;
+static FILE *__darwintrace_debug = NULL;
+static pid_t __darwintrace_pid = (pid_t) -1;
 #define BUFFER_SIZE	1024
 
 /**
@@ -160,15 +163,15 @@
 static char* __env_dyld_insert_libraries;
 static char* __env_dyld_force_flat_namespace;
 static char* __env_darwintrace_log;
+static char* __env_darwintrace_debug_log;
 
+#if DARWINTRACE_DEBUG_OUTPUT
 #if __STDC_VERSION__>=199901L
-#if DARWINTRACE_DEBUG_OUTPUT
-#define debug_printf(...) fprintf(stderr, __VA_ARGS__)
+#define debug_printf(format, ...) fprintf(stderr, "darwintrace[%d]: " format, getpid(), __VA_ARGS__); \
+	if (__darwintrace_debug) { \
+		fprintf(__darwintrace_debug, "darwintrace: " format, __VA_ARGS__); \
+	}
 #else
-#define debug_printf(...)
-#endif
-#else
-#if DARWINTRACE_DEBUG_OUTPUT
 __attribute__ ((format (printf, 1, 2)))
 static inline
 int debug_printf(const char *format, ...) {
@@ -179,40 +182,12 @@
     va_end(args);
     return ret;
 }
+#endif
 #else
-#define debug_printf(format, param)
+#define debug_printf(...)
 #endif
-#endif
 
 /*
- * char wait_for_socket(int sock, char w)
- * Function used for read/write operation to socket...
- * Args:
- *  sock - socket 
- *  w - what should socket do in next operation. 1 for write, 0 for read
- * Return value: 
- *  1 - everything is ok, we can read/write to/from it
- *  0 - something's went wrong
- */
-static int wait_for_socket(int sock, char w)
-{
-	struct timeval tv;
-	fd_set fds;
-	
-	if(sock==-1)
-		return 0;
-	
-	tv.tv_sec=10;
-	tv.tv_usec=0;
-	FD_ZERO(&fds);
-	FD_SET(sock, &fds);
-	if(select(sock+1, (w==0 ? &fds : 0), (w==1 ? &fds : 0), 0, &tv)<1)
-		return 0;
-	return FD_ISSET(sock, &fds)!=0;
-}
-
-
-/*
  * return 0 if str doesn't begin with prefix, 1 otherwise.
  */
 inline int __darwintrace_strbeginswith(const char* str, const char* prefix) {
@@ -248,6 +223,12 @@
 	} else {
 		__env_darwintrace_log = NULL;
 	}
+	theValue = getenv("DARWINTRACE_DEBUG_LOG");
+	if (theValue != NULL) {
+		__env_darwintrace_debug_log = strdup(theValue);
+	} else {
+		__env_darwintrace_debug_log = NULL;
+	}
 }
 
 /*
@@ -291,6 +272,10 @@
 		__darwintrace_alloc_env(
 			"DARWINTRACE_LOG",
 			__env_darwintrace_log);
+	char* darwintrace_debug_log_ptr =	
+		__darwintrace_alloc_env(
+			"DARWINTRACE_DEBUG_LOG",
+			__env_darwintrace_debug_log);
 
 	char* const * theEnvIter = envp;
 	int theEnvLength = 0;
@@ -318,6 +303,9 @@
 		} else if (__darwintrace_strbeginswith(theValue, "DARWINTRACE_LOG=")) {
 			theValue = darwintrace_log_ptr;
 			darwintrace_log_ptr = NULL;
+		} else if (__darwintrace_strbeginswith(theValue, "DARWINTRACE_DEBUG_LOG=")) {
+			theValue = darwintrace_debug_log_ptr;
+			darwintrace_debug_log_ptr = NULL;
 		}
 		
 		if (theValue) {
@@ -336,6 +324,9 @@
 	if (darwintrace_log_ptr) {
 		*theCopyIter++ = darwintrace_log_ptr;
 	}
+	if (darwintrace_debug_log_ptr) {
+		*theCopyIter++ = darwintrace_debug_log_ptr;
+	}
 
 	*theCopyIter = 0;
 	
@@ -344,26 +335,38 @@
 
 static void ask_for_filemap()
 {
-	filemap=exchange_with_port("filemap\t", sizeof("filemap\t"), 1, 0);
+	filemap=exchange_with_port("filemap\t", sizeof("filemap\t"), 1);
 	if(filemap==(char*)-1)
 		filemap=0;
 }
 
 __attribute__((always_inline))
-inline void __darwintrace_setup() {
+static inline void __darwintrace_setup() {
 #define open(x,y,z) syscall(SYS_open, (x), (y), (z))
 #define close(x) syscall(SYS_close, (x))
-	if (__darwintrace_fd == -1) {
+	pid_t oldpid = __darwintrace_pid;
+	if (__darwintrace_pid != (pid_t) -1 && __darwintrace_pid != getpid()) {
+		if (__darwintrace_fd != -2) {
+			close(__darwintrace_fd);
+			__darwintrace_fd = -2;
+		}
+		if (__darwintrace_debug) {
+			fclose(__darwintrace_debug);
+			__darwintrace_debug = NULL;
+		}
+		__darwintrace_pid = (pid_t) -1;
+	}
+	if (__darwintrace_pid == (pid_t) -1) {
+		__darwintrace_pid = getpid();
 		if (__env_darwintrace_log != NULL) {
 			int olderrno = errno;
-			int sock=socket(AF_UNIX, SOCK_STREAM, 0);
+			int sock = socket(AF_UNIX, SOCK_STREAM, 0);
 			struct sockaddr_un sun;
-			sun.sun_family=AF_UNIX;
+			sun.sun_family = AF_UNIX;
 			strncpy(sun.sun_path, __env_darwintrace_log, sizeof(sun.sun_path));
-			if(connect(sock, (struct sockaddr*)&sun, strlen(__env_darwintrace_log)+1+sizeof(sun.sun_family))!=-1)
-			{
-				debug_printf("darwintrace: connect successful. socket %d\n", sock);
-				__darwintrace_fd=sock;
+			if (connect(sock, (struct sockaddr*)&sun, strlen(__env_darwintrace_log) + 1 + sizeof(sun.sun_family)) != -1) {
+				debug_printf("connect successful, socket %d in pid %d\n", sock, __darwintrace_pid);
+				__darwintrace_fd = sock;
 				ask_for_filemap();
 			} else {
 				debug_printf("connect failed: %s\n", strerror(errno));
@@ -371,6 +374,21 @@
 			}
 			errno = olderrno;
 		}
+		if (__darwintrace_debug == NULL) {
+			if (__env_darwintrace_debug_log != NULL) {
+				char logpath[MAXPATHLEN];
+				snprintf(logpath, MAXPATHLEN, __env_darwintrace_debug_log, getpid());
+				if (NULL == (__darwintrace_debug = fopen(logpath, "w"))) {
+					fprintf(stderr, "failed to open logfile: %s\n", strerror(errno));
+					abort();
+				}
+				fprintf(__darwintrace_debug, "pid %d is process %s\n", getpid(), getenv("_"));
+				debug_printf("logging socket communication to: %s\n", logpath);
+			}
+		}
+		if (oldpid != (pid_t) -1) {
+			debug_printf("seems to have forked from %d, re-opened files\n", oldpid);
+		}
 	}
 #undef close
 #undef open
@@ -386,7 +404,7 @@
 	int size;
 	char somepath[MAXPATHLEN];
 	char logbuffer[BUFFER_SIZE];
-	
+
 	do {
 #ifdef __APPLE__ /* Only Darwin has volfs and F_GETPATH */
 		if ((fd > 0) && (DARWINTRACE_LOG_FULL_PATH
@@ -416,9 +434,9 @@
 
 	size = snprintf(logbuffer, sizeof(logbuffer),
 		"%s\t%s",
-		op, somepath );
+		op, somepath);
 
-	exchange_with_port(logbuffer, size+1, 0, 0);
+	exchange_with_port(logbuffer, size+1, 0);
 	
 	return;
 }
@@ -427,82 +445,66 @@
  * do a partial realpath(3) to fix "foo//bar" to "foo/bar"
  */
 inline void __darwintrace_cleanup_path(char *path) {
-  size_t pathlen;
+	size_t pathlen;
 #ifdef __APPLE__
-  size_t rsrclen;
+	size_t rsrclen;
 #endif
-  size_t i, shiftamount;
-  enum { SAWSLASH, NOTHING } state = NOTHING;
+	size_t i, shiftamount;
+	enum { SAWSLASH, NOTHING } state = NOTHING;
 
-  /* if this is a foo/..namedfork/rsrc, strip it off */
-  pathlen = strlen(path);
-  /* ..namedfork/rsrc is only on OS X */
-#ifdef __APPLE__ 
-  rsrclen = strlen(_PATH_RSRCFORKSPEC);
-  if(pathlen > rsrclen
-     && 0 == strcmp(path + pathlen - rsrclen,
-		    _PATH_RSRCFORKSPEC)) {
-    path[pathlen - rsrclen] = '\0';
-    pathlen -= rsrclen;
-  }
+	/* if this is a foo/..namedfork/rsrc, strip it off */
+	pathlen = strlen(path);
+	/* ..namedfork/rsrc is only on OS X */
+#ifdef __APPLE__
+	rsrclen = strlen(_PATH_RSRCFORKSPEC);
+	if (pathlen > rsrclen && 0 == strcmp(path + pathlen - rsrclen, _PATH_RSRCFORKSPEC)) {
+		path[pathlen - rsrclen] = '\0';
+		pathlen -= rsrclen;
+	}
 #endif
 
-  /* for each position in string (including
-     terminal \0), check if we're in a run of
-     multiple slashes, and only emit the
-     first one
-  */
-  for(i=0, shiftamount=0; i <= pathlen; i++) {
-    if(state == SAWSLASH) {
-      if(path[i] == '/') {
-	/* consume it */
-	shiftamount++;
-      } else {
-	state = NOTHING;
-	path[i - shiftamount] = path[i];
-      }
-    } else {
-      if(path[i] == '/') {
-	state = SAWSLASH;
-      }
-      path[i - shiftamount] = path[i];
-    }
-  }
-
-  debug_printf("darwintrace: cleanup resulted in %s\n", path);
+	/* for each position in string (including terminal \0), check if we're in
+	 * a run of multiple slashes, and only emit the first one */
+	for(i = 0, shiftamount = 0; i <= pathlen; i++) {
+		if (state == SAWSLASH) {
+			if (path[i] == '/') {
+				/* consume it */
+				shiftamount++;
+				continue;
+			} else {
+				state = NOTHING;
+			}
+		} else {
+			if (path[i] == '/') {
+				state = SAWSLASH;
+			}
+		}
+		path[i - shiftamount] = path[i];
+	}
 }
 
 /*
- * return 1 if path is directory or not exists
- * return 0 otherwise
+ * return 1 if path allowed, 0 otherwise
  */
-static int is_directory(const char * path)
-{
-#define stat(path, sb) syscall(SYS_stat, path, sb)
-	struct stat s;
-	if(stat(path, &s)==-1)
-		/* Actually is not directory, but anyway, we shouldn't test a dependency unless file exists */
-		return 1;
-	
-	return S_ISDIR(s.st_mode);
-#undef stat
-}
+static int ask_for_dependency(char * path) {
+#define stat(y, z) syscall(SYS_stat, (y), (z))
+	char buffer[BUFFER_SIZE], *p;
+	int result = 0;
+	struct stat st;
 
+	debug_printf("ask_for_dependency: %s\n", path);
 
-/*
- * return 1 if path allowed, 0 otherwise
- */
-static int ask_for_dependency(char * path)
-{
-	char buffer[BUFFER_SIZE], *p;
-	int result=0;
-	
-	if(is_directory(path))
+	if (-1 == stat(path, &st)) {
 		return 1;
+	}
+	if (S_ISDIR(st.st_mode)) {
+		debug_printf("%s is directory\n", path);
+		return 1;
+	}
 	
 	strncpy(buffer, "dep_check\t", sizeof(buffer));
 	strncpy(buffer+10, path, sizeof(buffer)-10);
-	p=exchange_with_port(buffer, strlen(buffer)+1, 1, 0);
+	p=exchange_with_port(buffer, strlen(buffer)+1, 1);
 	if(p==(char*)-1||!p)
 		return 0;
 	
@@ -511,6 +513,7 @@
 	
 	free(p);
 	return result;
+#undef stat
 }
 
 /*
@@ -525,155 +528,182 @@
  *    0      -- data successfully sent
  *    string -- answer (caller shoud free it)
  */
-static char * exchange_with_port(const char * buf, size_t len, int answer, char failures)
-{
-	wait_for_socket(__darwintrace_fd, 1);
-	if(send(__darwintrace_fd, buf, len, 0)==-1)
-	{
-		if(errno==ENOTSOCK && failures<3)
-		{
-			__darwintrace_fd=-1;
-			__darwintrace_setup();
-			return exchange_with_port(buf, len, answer, failures+1);
+static char * exchange_with_port(const char * buf, size_t len, int answer) {
+	size_t sent = 0;
+
+	if (__darwintrace_debug) {
+		fprintf(__darwintrace_debug, "> %s\n", buf);
+	}
+	while (sent < len) {
+		ssize_t local_sent = send(__darwintrace_fd, buf + sent, len - sent, 0);
+		if (local_sent == -1) {
+			debug_printf("error communicating with socket %d: %s\n", __darwintrace_fd, strerror(errno));
+			if (__darwintrace_debug)
+				fprintf(__darwintrace_debug, "darwintrace: error communicating with socket %d: %s\n", __darwintrace_fd, strerror(errno));
+			abort();
 		}
-		return (char*)-1;
+		sent += local_sent;
 	}
-	if(!answer)
+	if (!answer) {
 		return 0;
-	{
-		size_t l=0;
-		char * b;
+	} else {
+		size_t recv_len = 0, received;
+		char *recv_buf;
 		
-		wait_for_socket(__darwintrace_fd, 0);
-		recv(__darwintrace_fd, &l, sizeof(l),0);
-		if(!l)
+		received = 0;
+		while (received < sizeof(recv_len)) {
+			ssize_t local_received = recv(__darwintrace_fd, ((char *) &recv_len) + received, sizeof(recv_len) - received, 0);
+			if (local_received == -1) {
+				debug_printf("error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
+				if (__darwintrace_debug)
+					fprintf(__darwintrace_debug, "darwintrace: error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
+				abort();
+			}
+			received += local_received;
+		}
+		if (recv_len == 0) {
 			return 0;
-		b=(char*)malloc(l+1);
-		b[l]=0;
-		recv(__darwintrace_fd, b, l, 0);
-		return b;
+		}
+
+		recv_buf = malloc(recv_len + 1);
+		recv_buf[recv_len] = '\0';
+
+		received = 0;
+		while (received < recv_len) {
+			ssize_t local_received = recv(__darwintrace_fd, recv_buf + received, recv_len - received, 0);
+			if (local_received == -1) {
+				debug_printf("error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
+				if (__darwintrace_debug)
+					fprintf(__darwintrace_debug, "darwintrace: error reading data from socket %d: %s\n", __darwintrace_fd, strerror(errno));
+				abort();
+			}
+			received += local_received;
+		}
+		if (__darwintrace_debug) {
+			fprintf(__darwintrace_debug, "< %s\n", recv_buf);
+		}
+		return recv_buf;
 	}
 }
 
+#define DARWINTRACE_STATUS_PATH    ((char) 0)
+#define DARWINTRACE_STATUS_COMMAND ((char) 1)
+#define DARWINTRACE_STATUS_DONE    ((char) 2)
+
 /*
  * return 1 if path (once normalized) is in sandbox or redirected, 0 otherwise.
  */
 __attribute__((always_inline))
 inline int __darwintrace_is_in_sandbox(const char* path, char * newpath) {
-	char * t, * p, * _;
-	int result=-1;
+	char *t, *p, *_;
+	char lpath[MAXPATHLEN];
 	
 	__darwintrace_setup();
 	
-	if(!filemap)
+	if (!filemap)
 		return 1;
 	
-	if(*path=='/')
-		p=strdup(path);
-	else
-	{
-		p=(char*)malloc(MAXPATHLEN);
-		if (getcwd(p, MAXPATHLEN-1) == NULL) {
+	if (*path=='/') {
+		p = strcpy(lpath, path);
+	} else {
+		if (getcwd(lpath, MAXPATHLEN - 1) == NULL) {
 			fprintf(stderr, "darwintrace: getcwd: %s, path was: %s\n", strerror(errno), path);
 			abort();
 		}
-		if (p[strlen(p)-1] != '/')
-			strcat(p, "/");
-		strcat(p, path);
+		strcat(lpath, "/");
+		strcat(lpath, path);
 	}
-	__darwintrace_cleanup_path(p);
-			
-	do
-	{
-		for(t=filemap; *t;)
-		{
-			if(__darwintrace_strbeginswith(p, t))
-			{
-				t+=strlen(t)+1;
-				switch(*t)
-				{
+
+	p = lpath;
+
+	for (t = filemap; *t;) {
+		char state;
+		
+		if (__darwintrace_strbeginswith(p, t)) {
+			/* move t to the integer describing how to handle this match */
+			t += strlen(t) + 1;
+			switch (*t) {
 				case 0:
-					result=1;
-					break;
+					return 1;
 				case 1:
-					if(!newpath)
-					{
-						result=0;
-						break;
+					if (!newpath) {
+						return 0;
 					}
-					strcpy(newpath, t+1);
-					_=newpath+strlen(newpath);
-					if(_[-1]!='/')
-						*_++='/';
+					/* the redirected path starts right after the byte telling
+					 * us we should redirect */
+					strcpy(newpath, t + 1);
+					_ = newpath + strlen(newpath);
+					/* append '/' if it's missing */
+					if (_[-1] != '/') {
+						*_ = '/';
+					}
 					strcpy(_, p);
-					result=1;
-					break;
+					return 1;
 				case 2:
-					result=ask_for_dependency(p);
+					/* ask the socket whether this file is OK */
+					return ask_for_dependency(p);
+				default:
+					fprintf(stderr, "darwintrace: error: unexpected byte in file map: `%x'\n", *t);
+					abort();
+			}
+		}
+
+		/* advance the cursor: if the number after the string is not 1, there's
+		 * no path behind it and we can advance by strlen(t) + 3. If it is 1,
+		 * make sure to skip the path, too.
+		 */
+		state = DARWINTRACE_STATUS_PATH;
+		while (state != DARWINTRACE_STATUS_DONE) {
+			switch (state) {
+				case DARWINTRACE_STATUS_PATH:
+					if (!*t) {
+						state = DARWINTRACE_STATUS_COMMAND;
+					}
 					break;
-				}
+				case DARWINTRACE_STATUS_COMMAND:
+					if (*t == 1) {
+						state = DARWINTRACE_STATUS_PATH;
+						t++;
+					} else {
+						state = DARWINTRACE_STATUS_DONE;
+					}
+					break;
 			}
-			if(result!=-1)
-				break;
-			t+=strlen(t)+1;
-			if(*t==1)
-				t+=strlen(t)+1;
-			else
-				t+=2;
+			t++;
 		}
-		if(result!=-1)
-			break;
-		__darwintrace_log_op("sandbox_violation", path, 0);
-		result=0;
+		t++;
 	}
-	while(0);
-	free(p);
-	return result;
+
+	__darwintrace_log_op("sandbox_violation", path, 0);
+	return 0;
 }
 
-/* Log calls to open(2) into the file specified by DARWINTRACE_LOG.
-   Only logs if the DARWINTRACE_LOG environment variable is set.
-   Only logs files (or rather, do not logs directories)
-   Only logs files where the open succeeds.
-   Only logs files opened for read access, without the O_CREAT flag set
-   	(unless DARWINTRACE_LOG_CREATE is set).
-   The assumption is that any file that can be created isn't necessary
-   to build the project.
-*/
-
+/* wrapper for open(2) preventing opening files outside the sandbox */
 int open(const char* path, int flags, ...) {
 #define open(x,y,z) syscall(SYS_open, (x), (y), (z))
 	mode_t mode;
-	int result;
 	va_list args;
-	struct stat sb;
 	char newpath[MAXPATHLEN];
-	int isInSandbox;	
 
+	debug_printf("open(%s)\n", path);
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		debug_printf("open %s was forbidden\n", path);
+		errno = ((flags & O_CREAT) > 0) ? EACCES : ENOENT;
+		return -1;
+	}
+
+	if (*newpath) {
+		path = newpath;
+	}
+
 	/* Why mode here ? */
 	va_start(args, flags);
 	mode = va_arg(args, int);
 	va_end(args);
-	
-	result = 0;
-	
-	if((stat(path, &sb)!=-1 && !(sb.st_mode&S_IFDIR)) || flags & O_CREAT )
-	{
-		*newpath=0;
-		__darwintrace_setup();
-		isInSandbox = __darwintrace_is_in_sandbox(path, newpath);
-		if (isInSandbox == 0) {
-			debug_printf("darwintrace: creation/writing was forbidden at %s\n", path);
-			errno = EACCES;
-			result = -1;
-		}
-		if(*newpath)
-			path=newpath;
-	}
-	if (result == 0) {
-		result = open(path, flags, mode);
-	}
-	return result;
+
+	return open(path, flags, mode);
 #undef open
 }
 
@@ -682,25 +712,26 @@
    Only logs files where the readlink succeeds.
 */
 #ifdef READLINK_IS_NOT_P1003_1A
-int  readlink(const char * path, char * buf, int bufsiz) {
+int readlink(const char * path, char * buf, int bufsiz) {
 #else
-ssize_t  readlink(const char * path, char * buf, size_t bufsiz) {
+ssize_t readlink(const char * path, char * buf, size_t bufsiz) {
 #endif
 #define readlink(x,y,z) syscall(SYS_readlink, (x), (y), (z))
-	ssize_t result;
-	int isInSandbox;
+	char newpath[MAXPATHLEN];
 
-	result = readlink(path, buf, bufsiz);
-	if (result >= 0) {
-		__darwintrace_setup();
-		isInSandbox = __darwintrace_is_in_sandbox(path, 0);
-		if (!isInSandbox)
-		{
-			errno=EACCES;
-			result=-1;
-		}
+	debug_printf("readlink(%s)\n", path);
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		errno = ENOENT;
+		return -1;
 	}
-	return result;
+
+	if (*newpath) {
+		path = newpath;
+	}
+
+	return readlink(path, buf, bufsiz);
 #undef readlink
 }
 
@@ -709,314 +740,442 @@
 #define open(x,y,z) syscall(SYS_open, (x), (y), (z))
 #define close(x) syscall(SYS_close, (x))
 #define lstat(x, y) syscall(SYS_lstat, (x), (y))
-	int result;
+	debug_printf("execve(%s)\n", path);
 	__darwintrace_setup();
 	if (__darwintrace_fd >= 0) {
-	  struct stat sb;
-	  /* for symlinks, we want to capture
-	   * both the original path and the modified one,
-	   * since for /usr/bin/gcc -> gcc-4.0,
-	   * both "gcc_select" and "gcc" are contributors
-	   */
-	  if (lstat(path, &sb) == 0) {
-	  	int fd;
+		struct stat sb;
+		/* for symlinks, we want to capture both the original path and the
+		 * modified one, since for /usr/bin/gcc -> gcc-4.0, both "gcc_select"
+		 * and "gcc" are contributors
+		 */
+		if (lstat(path, &sb) == 0) {
+			int fd;
+			if (S_ISLNK(sb.st_mode)) {
+				/* for symlinks, print both */
+				__darwintrace_log_op("execve", path, 0);
+			}
 
-	    if(S_ISLNK(sb.st_mode)) {
-	      /* for symlinks, print both */
-		  __darwintrace_log_op("execve", path, 0);
-	    }
-		
-		fd = open(path, O_RDONLY, 0);
-		if (fd > 0) {
-		  char buffer[MAXPATHLEN+1], newpath[MAXPATHLEN+1];
-		  ssize_t bytes_read;
-		
-		  *newpath=0;
-		  if(__darwintrace_is_in_sandbox(path, newpath)==0)
-		  {
-			close(fd);
-			errno=ENOENT;
-		    return -1;
-		  }
-		  if(*newpath)
-		    path=newpath;
+			fd = open(path, O_RDONLY, 0);
+			if (fd > 0) {
+				char buffer[MAXPATHLEN+1];
+				ssize_t bytes_read;
+
+				if(!__darwintrace_is_in_sandbox(path, NULL)) {
+					close(fd);
+					errno = ENOENT;
+					return -1;
+				}
 	
-		  /* once we have an open fd, if a full path was requested, do it */
-		  __darwintrace_log_op("execve", path, fd);
-
-		  /* read the file for the interpreter */
-		  bytes_read = read(fd, buffer, MAXPATHLEN);
-		  buffer[bytes_read] = 0;
-		  if (bytes_read > 2 &&
-			buffer[0] == '#' && buffer[1] == '!') {
-			const char* interp = &buffer[2];
-			int i;
-			/* skip past leading whitespace */
-			for (i = 2; i < bytes_read; ++i) {
-			  if (buffer[i] != ' ' && buffer[i] != '\t') {
-				interp = &buffer[i];
-				break;
-			  }
+				/* once we have an open fd, if a full path was requested, do it */
+				__darwintrace_log_op("execve", path, fd);
+	
+				/* read the file for the interpreter */
+				bytes_read = read(fd, buffer, MAXPATHLEN);
+				buffer[bytes_read] = 0;
+				if (bytes_read > 2 && buffer[0] == '#' && buffer[1] == '!') {
+					const char* interp = &buffer[2];
+					int i;
+					/* skip past leading whitespace */
+					for (i = 2; i < bytes_read; ++i) {
+						if (buffer[i] != ' ' && buffer[i] != '\t') {
+							interp = &buffer[i];
+							break;
+						}
+					}
+					/* found interpreter (or ran out of data); skip until next
+					 * whitespace, then terminate the string */
+					for (; i < bytes_read; ++i) {
+						if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n') {
+							buffer[i] = 0;
+							break;
+						}
+					}
+					/* we have liftoff */
+					if (interp && interp[0] != '\0') {
+						__darwintrace_log_op("execve", interp, 0);
+					}
+				}
+				close(fd);
 			}
-			/* found interpreter (or ran out of data)
-			   skip until next whitespace, then terminate the string */
-			for (; i < bytes_read; ++i) {
-			  if (buffer[i] == ' ' || buffer[i] == '\t' || buffer[i] == '\n') {
-				buffer[i] = 0;
-				break;
-			  }
-			}
-			/* we have liftoff */
-			if (interp && interp[0] != '\0') {
-			  __darwintrace_log_op("execve", interp, 0);
-			}
-		  }
-		  close(fd);
 		}
-	  }
-	close(__darwintrace_fd);
-	__darwintrace_fd=-1;
 	}
-	
+	/* our variables won't survive exec, clean up */
+	if (__darwintrace_fd != -2) {
+		close(__darwintrace_fd);
+		__darwintrace_fd = -2;
+	}
+	if (__darwintrace_debug) {
+		fclose(__darwintrace_debug);
+		__darwintrace_debug = NULL;
+	}
+	__darwintrace_pid = (pid_t) -1;
+
 	/* call the original execve function, but fix the environment if required. */
-	result = __execve(path, argv, __darwintrace_restore_env(envp));
-	return result;
+	return __execve(path, argv, __darwintrace_restore_env(envp));
 #undef lstat
 #undef close
 #undef open
 #undef execve
 }
 
-/* if darwintrace has been initialized, trap
-   attempts to close our file descriptor
-*/
+/* if darwintrace has been initialized, trap attempts to close our file
+ * descriptor */
 int close(int fd) {
 #define close(x) syscall(SYS_close, (x))
+	if (__darwintrace_fd != -2 && fd == __darwintrace_fd) {
+		errno = EBADF;
+		return -1;
+	}
 
-  if(__darwintrace_fd != -2 && fd == __darwintrace_fd) {
-    errno = EBADF;
-    return -1;
-  }
-
-  return close(fd);
+	return close(fd);
 #undef close
 }
 
-/* Trap attempts to unlink a file outside the sandbox.
- */
+/* if darwintrace has been initialized, trap attempts to dup2 over our file descriptor */
+int dup2(int filedes, int filedes2) {
+#define dup2(x, y) syscall(SYS_dup2, (x), (y))
+
+	debug_printf("dup2(%d, %d)\n", filedes, filedes2);
+	if (__darwintrace_fd != -2 && filedes2 == __darwintrace_fd) {
+		/* if somebody tries to close our file descriptor, just move it out of
+		 * the way. Make sure it doesn't end up as stdin/stdout/stderr, though!
+		 * */
+		int new_darwintrace_fd;
+
+		if (-1 == (new_darwintrace_fd = fcntl(__darwintrace_fd, F_DUPFD, STDOUT_FILENO + 1))) {
+			/* if duplicating fails, do not allow overwriting either! */
+			return -1;
+		}
+
+		debug_printf("moving __darwintrace_fd from %d to %d\n", __darwintrace_fd, new_darwintrace_fd);
+		__darwintrace_fd = new_darwintrace_fd;
+	}
+
+	return dup2(filedes, filedes2);
+#undef dup2
+}
+
+
+/* Trap attempts to unlink a file outside the sandbox. */
 int unlink(const char* path) {
 #define __unlink(x) syscall(SYS_unlink, (x))
-	int result = 0;
-	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
-	if (isInSandbox == 1) {
-		debug_printf("darwintrace: unlink was allowed at %s\n", path);
-	} else if (isInSandbox == 0) {
-		/* outside sandbox, but sandbox is defined: forbid */
-		debug_printf("darwintrace: unlink was forbidden at %s\n", path);
-		errno = EACCES;
-		result = -1;
+	char newpath[MAXPATHLEN];
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		debug_printf("unlink %s was forbidden\n", path);
+		errno = ENOENT;
+		return -1;
 	}
-	
-	if (result == 0) {
-		result = __unlink(path);
+
+	if (*newpath) {
+		path = newpath;
 	}
-	
-	return result;
+
+	debug_printf("unlink %s was allowed\n", path);
+
+	return __unlink(path);
 }
 
 /* Trap attempts to create directories outside the sandbox.
  */
 int mkdir(const char* path, mode_t mode) {
 #define __mkdir(x,y) syscall(SYS_mkdir, (x), (y))
-	int result = 0;
-	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
-	if (isInSandbox == 1) {
-		debug_printf("darwintrace: mkdir was allowed at %s\n", path);
-	} else if (isInSandbox == 0) {
-		/* outside sandbox, but sandbox is defined: forbid */
-		/* only consider directories that do not exist. */
-		struct stat theInfo;
-		int err;
-		err = lstat(path, &theInfo);
-		if ((err == -1) && (errno == ENOENT))
-		{
-			debug_printf("darwintrace: mkdir was forbidden at %s\n", path);
-			errno = EACCES;
-			result = -1;
-		} /* otherwise, mkdir will do nothing (directory exists) or fail
-		     (another error) */
+	char newpath[MAXPATHLEN];
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		struct stat st;
+		if (-1 == lstat(path, &st)) {
+			if (errno == ENOENT) {
+				/* directory doesn't exist yet */
+				debug_printf("mkdir was forbidden at %s\n", path);
+				errno = EACCES;
+				return -1;
+			}
+		}
+		/* otherwise, mkdir will do nothing or fail with a hopefully meaningful
+		 * error */
+	} else {
+		if (*newpath) {
+			path = newpath;
+		}
+
+		debug_printf("mkdir was allowed at %s\n", path);
 	}
-	
-	if (result == 0) {
-		result = __mkdir(path, mode);
-	}
-	
-	return result;
+
+	return __mkdir(path, mode);
 }
 
 /* Trap attempts to remove directories outside the sandbox.
  */
 int rmdir(const char* path) {
 #define __rmdir(x) syscall(SYS_rmdir, (x))
-	int result = 0;
-	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
-	if (isInSandbox == 1) {
-		debug_printf("darwintrace: rmdir was allowed at %s\n", path);
-	} else if (isInSandbox == 0) {
-		/* outside sandbox, but sandbox is defined: forbid */
-		debug_printf("darwintrace: removing directory %s was forbidden\n", path);
-		errno = EACCES;
-		result = -1;
+	if (!__darwintrace_is_in_sandbox(path, NULL)) {
+		debug_printf("removing directory %s was forbidden\n", path);
+		errno = ENOENT;
+		return -1;
 	}
-	
-	if (result == 0) {
-		result = __rmdir(path);
-	}
-	
-	return result;
+
+	debug_printf("rmdir %s was allowed\n", path);
+
+	return __rmdir(path);
 }
 
 /* Trap attempts to rename files/directories outside the sandbox.
  */
 int rename(const char* from, const char* to) {
 #define __rename(x,y) syscall(SYS_rename, (x), (y))
-	int result = 0;
-	int isInSandbox = __darwintrace_is_in_sandbox(from, 0);
-	if (isInSandbox == 1) {
-		debug_printf("darwintrace: rename was allowed at %s\n", from);
-	} else if (isInSandbox == 0) {
-		/* outside sandbox, but sandbox is defined: forbid */
-		debug_printf("darwintrace: renaming from %s was forbidden\n", from);
+	if (!__darwintrace_is_in_sandbox(from, NULL)) {
+		/* outside sandbox, forbid */
+		debug_printf("renaming from %s was forbidden\n", from);
+		errno = ENOENT;
+		return -1;
+	}
+	if (!__darwintrace_is_in_sandbox(to, NULL)) {
+		debug_printf("renaming to %s was forbidden\n", to);
 		errno = EACCES;
-		result = -1;
+		return -1;
 	}
 
-	if (result == 0) {
-		isInSandbox = __darwintrace_is_in_sandbox(to, 0);
-		if (isInSandbox == 1) {
-			debug_printf("darwintrace: rename was allowed at %s\n", to);
-		} else if (isInSandbox == 0) {
-			/* outside sandbox, but sandbox is defined: forbid */
-			debug_printf("darwintrace: renaming to %s was forbidden\n", to);
-			errno = EACCES;
-			result = -1;
-		}
-	}
-	
-	if (result == 0) {
-		result = __rename(from, to);
-	}
-	
-	return result;
+	debug_printf("renaming from %s to %s was allowed\n", from, to);
+
+	return __rename(from, to);
 }
 
-int stat(const char * path, struct stat * sb)
-{
+int stat(const char * path, struct stat * sb) {
 #define stat(path, sb) syscall(SYS_stat, path, sb)
-	int result=0;
-	char newpath[260];
-		
-	*newpath=0;
-	if(!is_directory(path)&&__darwintrace_is_in_sandbox(path, newpath)==0)
-	{
-		errno=ENOENT;
-		result=-1;
-	}else
-	{
-		if(*newpath)
-			path=newpath;
-			
-		result=stat(path, sb);
+	int result = 0;
+	char newpath[MAXPATHLEN];
+
+	debug_printf("stat(%s)\n", path);
+	if (-1 == (result = stat(path, sb))) {
+		return -1;
 	}
-	
+
+	if (S_ISDIR(sb->st_mode)) {
+		return result;
+	}
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		errno = ENOENT;
+		return -1;
+	}
+
+	if (*newpath) {
+		result = stat(newpath, sb);
+	}
+
 	return result;
 #undef stat
 }
 
 #if defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
 
-int stat64(const char * path, struct stat64 * sb)
-{
+int stat64(const char * path, struct stat64 * sb) {
 #define stat64(path, sb) syscall(SYS_stat64, path, sb)
-	int result=0;
-	char newpath[260];
-		
-	*newpath=0;
-	if(!is_directory(path)&&__darwintrace_is_in_sandbox(path, newpath)==0)
-	{
-		errno=ENOENT;
-		result=-1;
-	}else
-	{
-		if(*newpath)
-			path=newpath;
-			
-		result=stat64(path, sb);
+	int result = 0;
+	char newpath[MAXPATHLEN];
+
+	debug_printf("stat64(%s)\n", path);
+	if (-1 == (result = stat64(path, sb))) {
+		return -1;
 	}
-	
+
+	if (S_ISDIR(sb->st_mode)) {
+		return result;
+	}
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		errno = ENOENT;
+		return -1;
+	}
+
+	if (*newpath) {
+		result = stat64(newpath, sb);
+	}
+
 	return result;
 #undef stat64
 }
 
-int stat$INODE64(const char * path, struct stat64 * sb)
-{
+int stat$INODE64(const char * path, struct stat64 * sb) {
     return stat64(path, sb);
 }
 
 #endif /* defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE) */
 
 
-int lstat(const char * path, struct stat * sb)
-{
+int lstat(const char * path, struct stat * sb) {
 #define lstat(path, sb) syscall(SYS_lstat, path, sb)
-	int result=0;
-	char newpath[260];
-	
-	*newpath=0;
-	if(!is_directory(path)&&__darwintrace_is_in_sandbox(path, newpath)==0)
-	{
-		errno=ENOENT;
-		result=-1;
-	}else
-	{
-		if(*newpath)
-			path=newpath;
-			
-		result=lstat(path, sb);
+	int result = 0;
+	char newpath[MAXPATHLEN];
+
+	debug_printf("lstat(%s)\n", path);
+	if (-1 == (result = lstat(path, sb))) {
+		return -1;
 	}
-	
+
+	if (S_ISDIR(sb->st_mode)) {
+		return result;
+	}
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		errno = ENOENT;
+		return -1;
+	}
+
+	if (*newpath) {
+		result = lstat(newpath, sb);
+	}
+
 	return result;
 #undef lstat
 }
 
 #if defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE)
 
-int lstat64(const char * path, struct stat64 * sb)
-{
+int lstat64(const char * path, struct stat64 * sb) {
 #define lstat64(path, sb) syscall(SYS_lstat64, path, sb)
-	int result=0;
-	char newpath[260];
-	
-	*newpath=0;
-	if(!is_directory(path)&&__darwintrace_is_in_sandbox(path, newpath)==0)
-	{
-		errno=ENOENT;
-		result=-1;
-	}else
-	{
-		if(*newpath)
-			path=newpath;
-			
-		result=lstat64(path, sb);
+	int result = 0;
+	char newpath[MAXPATHLEN];
+
+	debug_printf("lstat64(%s)\n", path);
+	if (-1 == (result = lstat64(path, sb))) {
+		return -1;
 	}
-	
+
+	if (S_ISDIR(sb->st_mode)) {
+		return result;
+	}
+
+	*newpath = '\0';
+	if (!__darwintrace_is_in_sandbox(path, newpath)) {
+		errno = ENOENT;
+		return -1;
+	}
+
+	if (*newpath) {
+		result = lstat64(newpath, sb);
+	}
+
 	return result;
 #undef lstat64
 }
 
-int lstat$INODE64(const char * path, struct stat64 * sb)
-{
+int lstat$INODE64(const char * path, struct stat64 * sb) {
     return lstat64(path, sb);
 }
 
 #endif /* defined(__DARWIN_64_BIT_INO_T) && !defined(_DARWIN_FEATURE_ONLY_64_BIT_INODE) */
+
+/**
+ * re-implementation of getdirent(2) and __getdirent64(2) preventing paths
+ * outside the sandbox to show up when reading the contents of a directory.
+ * Unfortunately, since we need to access the contents of the buffer, but the
+ * contents differ by architecture, we can not rely on the dirent structure
+ * defined by the header included by this program, because we don't know
+ * whether darwintrace.dylib has been compiled for 64bit or 32bit inodes. We
+ * thus copy both structs and decide at runtime.
+ */
+
+#ifdef __APPLE__
+/* only do this on mac, because fcntl(fd, F_GETPATH) might not be available on
+ * other systems, and because other system's syscall names are probably
+ * different anyway */
+
+#pragma pack(4)
+struct dirent32 {
+	ino_t d_ino;			/* file number of entry */
+	__uint16_t d_reclen;		/* length of this record */
+	__uint8_t  d_type; 		/* file type, see below */
+	__uint8_t  d_namlen;		/* length of string in d_name */
+	char d_name[__DARWIN_MAXNAMLEN + 1];	/* name must be no longer than this */
+};
+#pragma pack()
+
+struct dirent64  {
+	__uint64_t  d_ino;      /* file number of entry */
+	__uint64_t  d_seekoff;  /* seek offset (optional, used by servers) */
+	__uint16_t  d_reclen;   /* length of this record */
+	__uint16_t  d_namlen;   /* length of string in d_name */
+	__uint8_t   d_type;     /* file type, see below */
+	char      d_name[__DARWIN_MAXPATHLEN]; /* entry name (up to MAXPATHLEN bytes) */
+};
+
+size_t __getdirentries64(int fd, void *buf, size_t bufsize, __darwin_off_t *basep) {
+#define __getdirentries64(w,x,y,z) syscall(SYS_getdirentries64, (w), (x), (y), (z))
+	size_t sz = __getdirentries64(fd, buf, bufsize, basep);
+	char dirname[MAXPATHLEN];
+	size_t dnamelen;
+
+	if (-1 == fcntl(fd, F_GETPATH, dirname)) {
+		errno = EBADF;
+		return 0;
+	}
+
+	dnamelen = strlen(dirname);
+	if (dirname[dnamelen - 1] != '/') {
+		dirname[dnamelen] = '/';
+		dirname[dnamelen + 1] = '\0';
+		dnamelen++;
+	}
+
+	dnamelen = strlen(dirname);
+	size_t offset;
+	for (offset = 0; offset < sz;) {
+		struct dirent64 *dent = (struct dirent64 *)(((char *) buf) + offset);
+		dirname[dnamelen] = '\0';
+		strcat(dirname, dent->d_name);
+		if (!__darwintrace_is_in_sandbox(dirname, NULL)) {
+			debug_printf("__getdirentries64: filtered %s\n", dirname);
+			dent->d_ino = 0;
+		} else {
+			debug_printf("__getdirentries64:  allowed %s\n", dirname);
+		}
+		offset += dent->d_reclen;
+	}
+
+	return sz;
+#undef __getdirentries64
+}
+
+int getdirentries(int fd, char *buf, int nbytes, long *basep) {
+#define getdirentries(w,x,y,z) syscall(SYS_getdirentries, (w), (x), (y), (z))
+	size_t sz = getdirentries(fd, buf, nbytes, basep);
+	char dirname[MAXPATHLEN];
+	size_t dnamelen;
+
+	if (-1 == fcntl(fd, F_GETPATH, dirname)) {
+		errno = EBADF;
+		return 0;
+	}
+
+	dnamelen = strlen(dirname);
+	if (dirname[dnamelen - 1] != '/') {
+		dirname[dnamelen] = '/';
+		dirname[dnamelen + 1] = '\0';
+		dnamelen++;
+	}
+
+	size_t offset;
+	for (offset = 0; offset < sz;) {
+		struct dirent32 *dent = (struct dirent32 *)(buf + offset);
+		dirname[dnamelen] = '\0';
+		strcat(dirname, dent->d_name);
+		if (!__darwintrace_is_in_sandbox(dirname, NULL)) {
+			debug_printf("getdirentries: filtered %s\n", dirname);
+			dent->d_ino = 0;
+		} else {
+			debug_printf("getdirentries:  allowed %s\n", dirname);
+		}
+		offset += dent->d_reclen;
+	}
+
+	return sz;
+#undef getdirentries
+}
+#endif /* __APPLE__ */

Modified: branches/gsoc11-statistics/base/src/images_to_archives.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/images_to_archives.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/images_to_archives.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -74,7 +74,7 @@
         }
         set found 0
         foreach adir [list $oldarchivedir $olderarchivedir] {
-            foreach type {tbz2 tbz tgz tar txz tlz xar xpkg zip cpgz cpio} {
+            foreach type {tbz2 tbz tgz tar txz tlz xar zip cpgz cpio} {
                 set oldarchivefullpath "[file join $adir $oldarchiverootname].${type}"
                 if {[file isfile $oldarchivefullpath]} {
                     set found 1
@@ -92,19 +92,21 @@
             set targetdir [file dirname $location]
         } else {
             set targetdir [file join ${macports::registry.path} software ${iname}]
-            file mkdir $targetdir
+        }
+        if {$location == "" || ![file isdirectory $location]} {
             set contents [$iref imagefiles]
         }
+        file mkdir $targetdir
         set newlocation [file join $targetdir $archivename]
 
         if {$found} {
             file rename $oldarchivefullpath $newlocation
-        } elseif {$installtype == "image"} {
+        } elseif {$installtype == "image" && [file isdirectory $location]} {
             # create archive from image dir
-            system "cd $location && $tarcmd -cjf $newlocation * > ${targetdir}/error.log 2>&1"
+            system -W $location "$tarcmd -cjf $newlocation * > ${targetdir}/error.log 2>&1"
             file delete -force ${targetdir}/error.log
         } else {
-            # direct mode, create archive from installed files
+            # direct mode (or missing image dir), create archive from installed files
             # we tell tar to read filenames from a file so as not to run afoul of command line length limits
             set fd [open ${targetdir}/tarlist w]
             foreach entry $contents {

Modified: branches/gsoc11-statistics/base/src/machista1.0/Makefile.in
===================================================================
--- branches/gsoc11-statistics/base/src/machista1.0/Makefile.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/machista1.0/Makefile.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -37,14 +37,12 @@
 
 clean::
 	rm -f ${SWIG_OBJS} ${PKG_INDEX}
-ifdef SWIG
-	rm -f ${SWIG_SRCS}
-else
-	@echo "Not cleaning SWIG-generated sources, because you have configured MacPorts without SWIG." >&2
-endif
 	rm -f ${TESTS}
 	rm -rf ${TESTS:%=%.dSYM}
 
+distclean::
+	rm -f Makefile
+
 test:: ${TESTS}
 	${TESTS}
 

Modified: branches/gsoc11-statistics/base/src/machista1.0/libmachista.c
===================================================================
--- branches/gsoc11-statistics/base/src/machista1.0/libmachista.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/machista1.0/libmachista.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -42,14 +42,35 @@
 #include <err.h>
 #include <string.h>
 
+#ifdef __MACH__
 #include <mach-o/fat.h>
 #include <mach-o/loader.h>
 
 #include <libkern/OSAtomic.h>
+#endif
 
 #include "libmachista.h"
 #include "hashmap.h"
 
+#ifdef __MACH__
+/* Tiger compatibility */
+#ifndef LC_RPATH
+#define LC_RPATH       (0x1c | LC_REQ_DYLD)    /* runpath additions */
+/*
+ * The rpath_command contains a path which at runtime should be added to
+ * the current run path used to find @rpath prefixed dylibs.
+ */
+struct rpath_command {
+    uint32_t     cmd;       /* LC_RPATH */
+    uint32_t     cmdsize;   /* includes string */
+    union lc_str path;      /* path to add to run path */
+};
+#endif
+#ifndef LC_REEXPORT_DYLIB
+#define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */
+#endif
+#endif /* __MACH__ */
+
 typedef struct macho_input {
     const void *data;
     size_t length;
@@ -60,6 +81,7 @@
     HashMap *result_map;
 };
 
+#ifdef __MACH__
 /* Verify that the given range is within bounds. */
 static const void *macho_read (macho_input_t *input, const void *address, size_t length) {
     if ((((uint8_t *) address) - ((uint8_t *) input->data)) + length > input->length) {
@@ -75,6 +97,7 @@
     void *result = ((uint8_t *) address) + offset;
     return macho_read(input, result, length);
 }
+#endif
 
 /* return a human readable formatted version number. the result must be free()'d. */
 char *macho_format_dylib_version (uint32_t version) {
@@ -84,13 +107,18 @@
 }
 
 const char *macho_get_arch_name (cpu_type_t cputype) {
+#ifdef __MACH__
     const NXArchInfo *archInfo = NXGetArchInfoFromCpuType(cputype, CPU_SUBTYPE_MULTIPLE);	
     if (!archInfo) {
         return NULL;
     }
     return archInfo->name;
+#else
+    return NULL;
+#endif
 }
 
+#ifdef __MACH__
 /* Some byteswap wrappers */
 static uint32_t macho_swap32 (uint32_t input) {
     return OSSwapInt32(input);
@@ -132,6 +160,7 @@
     memset(mlt, 0, sizeof(macho_loadcmd_t));
     return mlt;
 }
+#endif
 
 /* Frees a previously allocated macho_loadcmd_t and all it's associated resources */
 static void free_macho_loadcmd_t (macho_loadcmd_t *mlt) {
@@ -174,6 +203,7 @@
     free(mt);
 }
 
+#ifdef __MACH__
 /* Creates a new element in the architecture list of a macho_t (mt_archs), increases the counter of
  * architectures (mt_arch_count) and returns a pointer to the newly allocated element or NULL on
  * error */
@@ -203,9 +233,11 @@
 
     return mat->mat_loadcmds;
 }
+#endif
 
 /* Parse a Mach-O header */
 static int parse_macho (macho_t *mt, macho_input_t *input) {
+#ifdef __MACH__
     /* Read the file type. */
     const uint32_t *magic = macho_read(input, input->data, sizeof(uint32_t));
     if (magic == NULL)
@@ -401,10 +433,14 @@
     }
 
     return MACHO_SUCCESS;
+#else
+    return 0;
+#endif
 }
 
 /* Parse a (possible Mach-O) file. For a more detailed description, see the header */
 int macho_parse_file(macho_handle_t *handle, const char *filepath, const macho_t **res) {
+#ifdef __MACH__
     int fd;
     struct stat st;
     void *data;
@@ -464,6 +500,9 @@
     close(fd);
 
     return ret;
+#else
+    return 0;
+#endif
 }
 
 /* Create a new macho_handle_t. More information on this function is available in the header */

Modified: branches/gsoc11-statistics/base/src/machista1.0/libmachista.h
===================================================================
--- branches/gsoc11-statistics/base/src/machista1.0/libmachista.h	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/machista1.0/libmachista.h	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,7 +4,7 @@
  * $Id$
  *
  * Copyright (c) 2011 The MacPorts Project
- * Copyright (c) 2011 Clemens Lang
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -38,7 +38,11 @@
  * The name a pun: machista is the spanish translation of "macho".
  */
 
+#ifdef __MACH__
 #include <mach-o/arch.h>
+#else
+typedef int cpu_type_t;
+#endif
 #include <inttypes.h>
 
 #define MACHO_SUCCESS   (0x00)

Modified: branches/gsoc11-statistics/base/src/machista1.0/machista.i
===================================================================
--- branches/gsoc11-statistics/base/src/machista1.0/machista.i	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/machista1.0/machista.i	2013-04-09 18:46:31 UTC (rev 105085)
@@ -6,7 +6,9 @@
 %}
 
 %inline %{
+#ifdef __MACH__
     #include <mach-o/arch.h>
+#endif
     #include <inttypes.h>
     #include <stdint.h>
 %}

Modified: branches/gsoc11-statistics/base/src/machista1.0/machista_wrap.c
===================================================================
--- branches/gsoc11-statistics/base/src/machista1.0/machista_wrap.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/machista1.0/machista_wrap.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1674,7 +1674,9 @@
     #include "libmachista.h"
 
 
+#ifdef __MACH__
     #include <mach-o/arch.h>
+#endif
     #include <inttypes.h>
     #include <stdint.h>
 
@@ -2456,8 +2458,6 @@
   swig_module_info *module_head, *iter;
   int found, init;
   
-  clientdata = clientdata;
-  
   /* check to see if the circular list has been setup, if not, set it up */
   if (swig_module.next==0) {
     /* Initialize the swig_module */

Modified: branches/gsoc11-statistics/base/src/machista1.0/tests/libmachista-test.c
===================================================================
--- branches/gsoc11-statistics/base/src/machista1.0/tests/libmachista-test.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/machista1.0/tests/libmachista-test.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,3 +1,5 @@
+#ifdef __MACH__
+
 #include <libmachista.h>
 #include <limits.h>
 #include <mach-o/arch.h>
@@ -340,13 +342,18 @@
 	free(version_string);
 	return false;
 }
+#endif
 
 int main() {
+#ifdef __MACH__
 	bool result = true;
 	result &= test_destroy_null();
 	result &= test_handle();
 	result &= test_format_dylib_version();
 	result &= test_libsystem();
-	exit(!result);
+	return !result;
+#else
+	return 0;
+#endif
 }
 

Modified: branches/gsoc11-statistics/base/src/macports1.0/macports.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/macports1.0/macports.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/macports1.0/macports.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -6,7 +6,7 @@
 # Copyright (c) 2004 - 2005 Paul Guyot, <pguyot at kallisys.net>.
 # Copyright (c) 2004 - 2006 Ole Guldberg Jensen <olegb at opendarwin.org>.
 # Copyright (c) 2004 - 2005 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2004 - 2011 The MacPorts Project
+# Copyright (c) 2004 - 2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -37,7 +37,6 @@
 package require macports_dlist 1.0
 package require macports_index 1.0
 package require macports_util 1.0
-package require machista 1.0
 
 namespace eval macports {
     namespace export bootstrap_options user_options portinterp_options open_mports ui_priorities port_phases 
@@ -45,25 +44,29 @@
         portdbpath libpath binpath auto_path extra_env sources_conf prefix portdbformat \
         portarchivetype portautoclean \
         porttrace portverbose keeplogs destroot_umask variants_conf rsync_server rsync_options \
-        rsync_dir startupitem_type place_worksymlink xcodeversion xcodebuildcmd gccversion \
-        mp_remote_url mp_remote_submit_url configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
+        rsync_dir startupitem_type startupitem_install place_worksymlink xcodeversion xcodebuildcmd gccversion \
+        configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
         applications_dir frameworks_dir developer_dir universal_archs build_arch macosx_deployment_target \
         macportsuser proxy_override_env proxy_http proxy_https proxy_ftp proxy_rsync proxy_skip \
-        master_site_local patch_site_local archive_site_local buildfromsource stats_participate stats_url stats_id"
-    variable user_options "submitter_name submitter_email submitter_key"
+        master_site_local patch_site_local archive_site_local buildfromsource stats_participate stats_url stats_id \
+        revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
+        host_blacklist preferred_hosts\
+        packagemaker_path default_compilers"
+    variable user_options ""
     variable portinterp_options "\
         portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
-        registry.path registry.format \
+        registry.path registry.format user_home \
         portarchivetype archivefetch_pubkeys portautoclean porttrace keeplogs portverbose destroot_umask \
-        rsync_server rsync_options rsync_dir startupitem_type place_worksymlink macportsuser \
-        mp_remote_url mp_remote_submit_url configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
+        rsync_server rsync_options rsync_dir startupitem_type startupitem_install place_worksymlink macportsuser \
+        configureccache ccache_dir ccache_size configuredistcc configurepipe buildnicevalue buildmakejobs \
         applications_dir current_phase frameworks_dir developer_dir universal_archs build_arch \
-        os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target $user_options"
+        os_arch os_endian os_version os_major os_platform macosx_version macosx_deployment_target \
+        packagemaker_path default_compilers $user_options"
 
     # deferred options are only computed when needed.
     # they are not exported to the trace thread.
     # they are not exported to the interpreter in system_options array.
-    variable portinterp_deferred_options "xcodeversion xcodebuildcmd gccversion"
+    variable portinterp_deferred_options "xcodeversion xcodebuildcmd developer_dir gccversion"
 
     variable open_mports {}
 
@@ -365,7 +368,7 @@
     trace remove variable macports::xcodeversion read macports::setxcodeinfo
     trace remove variable macports::xcodebuildcmd read macports::setxcodeinfo
 
-    if {[catch {set xcodebuild [binaryInPath "xcodebuild"]}] == 0} {
+    if {![catch {findBinary xcodebuild $macports::autoconf::xcodebuild_path} xcodebuild]} {
         if {![info exists xcodeversion]} {
             # Determine xcode version
             set macports::xcodeversion "2.0orlower"
@@ -449,6 +452,103 @@
     }
 }
 
+# deferred calculation of developer_dir
+proc macports::set_developer_dir {name1 name2 op} {
+    global macports::developer_dir macports::os_major macports::xcodeversion
+
+    trace remove variable macports::developer_dir read macports::set_developer_dir
+    
+    # Look for xcodeselect, and make sure it has a valid value
+    if {![catch {findBinary xcode-select $macports::autoconf::xcode_select_path} xcodeselect]} {
+
+        # We have xcode-select: ask it where xcode is and check if it's valid.
+        # If no xcode is selected, xcode-select will fail, so catch that
+        if {![catch {exec $xcodeselect -print-path 2> /dev/null} devdir] &&
+            [_is_valid_developer_dir $devdir]} {
+            set macports::developer_dir $devdir
+            return
+        }
+
+        # The directory from xcode-select isn't correct.
+        
+        # Ask mdfind where Xcode is and make some suggestions for the user,
+        # searching by bundle identifier for various Xcode versions (3.x and 4.x)
+        set installed_xcodes {}
+        if {![catch {findBinary mdfind $macports::autoconf::mdfind_path} mdfind]} {
+            set installed_xcodes [exec $mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode' || kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"]
+        }
+        
+        # In case mdfind metadata wasn't complete, also look in two well-known locations for Xcode.app
+        foreach app {/Applications/Xcode.app /Developer/Applications/Xcode.app} {
+            if {[file isdirectory $app]} {
+                lappend installed_xcodes $app
+            }
+        }
+        
+        # Form a list of unique xcode installations
+        set installed_xcodes [lsort -unique $installed_xcodes]
+
+        # Present instructions to the user
+        ui_error
+        if {[llength $installed_xcodes] > 0 && ![catch {findBinary mdls $macports::autoconf::mdls_path} mdls]} {
+            # One, or more than one, Xcode installations found
+            ui_error "No valid Xcode installation is properly selected."
+            ui_error "Please use xcode-select to select an Xcode installation:"
+            foreach xcode $installed_xcodes {
+                set vers [exec $mdls -raw -name kMDItemVersion $xcode]
+                if {$vers == "(null)"} { set vers "unknown" }
+                if {[_is_valid_developer_dir "${xcode}/Contents/Developer"]} {
+                    # Though xcode-select shipped with xcode 4.3 supports and encourages
+                    # direct use of the app path, older xcode-select does not.
+                    # Specify the Contents/Developer directory if it exists
+                    ui_error "    sudo xcode-select -switch ${xcode}/Contents/Developer # version ${vers}"
+                } elseif {[vercmp $vers 4.3] >= 0} {
+                    # Future proofing: fall back to the app-path only for xcode >= 4.3, since Contents/Developer doesn't exist
+                    ui_error "    sudo xcode-select -switch ${xcode} # version ${vers}"
+                } elseif {[_is_valid_developer_dir "${xcode}/../.."]} {
+                    # Older xcode (< 4.3) is below the developer directory
+                    ui_error "    sudo xcode-select -switch [file normalize ${xcode}/../..] # version ${vers}"
+                } else {
+                    ui_error "    # malformed Xcode at ${xcode}, version ${vers}"
+                }
+            }
+        } else {
+            ui_error "No Xcode installation was found."
+            ui_error "Please install Xcode and/or run xcode-select to specify its location."
+        }
+        ui_error
+    }
+
+    # Try the default
+    if {$os_major >= 11 && [vercmp $xcodeversion 4.3] >= 0} {
+        set devdir "/Applications/Xcode.app/Contents/Developer"
+    } else {
+        set devdir "/Developer"
+    }
+
+    set macports::developer_dir $devdir
+}
+
+proc macports::_is_valid_developer_dir {dir} {
+    # Check whether specified directory looks valid for an Xcode installation
+
+    # Verify that the directory exists
+    if {![file isdirectory $dir]} {
+        return 0
+    }
+
+    # Verify that the directory has some key subdirectories
+    foreach subdir {Library usr} {
+        if {![file isdirectory "${dir}/${subdir}"]} {
+            return 0
+        }
+    }
+
+    # The specified directory seems valid for Xcode
+    return 1
+}
+
+
 proc mportinit {{up_ui_options {}} {up_options {}} {up_variations {}}} {
     if {$up_ui_options eq ""} {
         array set macports::ui_options {}
@@ -519,20 +619,13 @@
     global macports::macosx_version
     global macports::macosx_deployment_target
     global macports::archivefetch_pubkeys
+    global macports::ping_cache
+    global macports::host_blacklisted
+    global macports::host_preferred
 
     # Set the system encoding to utf-8
     encoding system utf-8
 
-    # Ensure that the macports user directory exists if HOME is defined
-    if {[info exists env(HOME)]} {
-        set macports::macports_user_dir [file normalize $macports::autoconf::macports_user_dir]
-    } else {
-        # Otherwise define the user directory as a direcotory that will never exist
-        set macports::macports_user_dir "/dev/null/NO_HOME_DIR"
-        # Tcl library code wants to do tilde expansion in various places
-        set env(HOME) ${macports::macports_user_dir}
-    }
-
     # set up platform info variables
     set os_arch $tcl_platform(machine)
     if {$os_arch == "Power Macintosh"} { set os_arch "powerpc" }
@@ -548,6 +641,23 @@
         set macosx_version [expr 10.0 + ($os_major - 4) / 10.0]
     }
 
+    # Ensure that the macports user directory (i.e. ~/.macports) exists if HOME is defined.
+    # Also save $HOME for later use before replacing it with our own.
+    if {[info exists env(HOME)]} {
+        set macports::user_home $env(HOME)
+        set macports::macports_user_dir [file normalize $macports::autoconf::macports_user_dir]
+    } elseif {[info exists env(SUDO_USER)] && $os_platform == "darwin"} {
+        set macports::user_home [exec dscl -q . -read /Users/$env(SUDO_USER) NFSHomeDirectory | cut -d ' ' -f 2]
+        set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
+    } elseif {[exec id -u] != 0 && $os_platform == "darwin"} {
+        set macports::user_home [exec dscl -q . -read /Users/[exec id -un] NFSHomeDirectory | cut -d ' ' -f 2]
+        set macports::macports_user_dir [file join ${macports::user_home} [string range $macports::autoconf::macports_user_dir 2 end]]
+    } else {
+        # Otherwise define the user directory as a directory that will never exist
+        set macports::macports_user_dir "/dev/null/NO_HOME_DIR"
+        set macports::user_home "/dev/null/NO_HOME_DIR"
+    }
+
     # Configure the search path for configuration files
     set conf_files ""
     lappend conf_files "${macports_conf_path}/macports.conf"
@@ -566,7 +676,7 @@
             set fd [open $file r]
             while {[gets $fd line] >= 0} {
                 if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
-                    if {[lsearch $bootstrap_options $option] >= 0} {
+                    if {[lsearch -exact $bootstrap_options $option] >= 0} {
                         set macports::$option [string trim $val]
                         global macports::$option
                     }
@@ -582,7 +692,7 @@
         set fd [open $per_user r]
         while {[gets $fd line] >= 0} {
             if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
-                if {[lsearch $user_options $option] >= 0} {
+                if {[lsearch -exact $user_options $option] >= 0} {
                     set macports::$option $val
                     global macports::$option
                 }
@@ -687,6 +797,7 @@
         }
     }
 
+    set env(HOME) [file join $portdbpath home]
     set registry.path $portdbpath
 
     # Format for receipts; currently only "sqlite" is allowed
@@ -702,8 +813,8 @@
         set macports::portautoclean "yes"
         global macports::portautoclean
     }
-	# whether to keep logs after successful builds
-   	if {![info exists keeplogs]} {
+    # whether to keep logs after successful builds
+    if {![info exists keeplogs]} {
         set macports::keeplogs "no"
         global macports::keeplogs
     }
@@ -731,8 +842,10 @@
         && [info exists macports::buildfromsource]} {
         if {${macports::buildfromsource} == "never"} {
             set macports::global_options(ports_binary_only) yes
+            set temp_options(ports_binary_only) yes
         } elseif {${macports::buildfromsource} == "always"} {
             set macports::global_options(ports_source_only) yes
+            set temp_options(ports_source_only) yes
         } elseif {${macports::buildfromsource} != "ifneeded"} {
             ui_warn "'buildfromsource' set to unknown value '${macports::buildfromsource}', using 'ifneeded' instead"
         }
@@ -742,6 +855,10 @@
     # can always get to the original prefix, even if a portfile overrides prefix
     set macports::prefix_frozen $prefix
 
+    if {![info exists macports::applications_dir]} {
+        set macports::applications_dir /Applications/MacPorts
+    }
+
     # Export verbosity.
     if {![info exists portverbose]} {
         set macports::portverbose "no"
@@ -796,19 +913,16 @@
         set macports::startupitem_type "default"
     }
 
+    # Set whether startupitems are symlinked into system directories
+    if {![info exists macports::startupitem_install]} {
+        set macports::startupitem_install yes
+    }
+
     # Default place_worksymlink
     if {![info exists macports::place_worksymlink]} {
         set macports::place_worksymlink yes
     }
 
-    # Default mp remote options
-    if {![info exists macports::mp_remote_url]} {
-        set macports::mp_remote_url "http://db.macports.org"
-    }
-    if {![info exists macports::mp_remote_submit_url]} {
-        set macports::mp_remote_submit_url "${macports::mp_remote_url}/submit"
-    }
-
     # Default mp configure options
     if {![info exists macports::configureccache]} {
         set macports::configureccache no
@@ -877,6 +991,18 @@
         set macports::macosx_deployment_target $macosx_version
     }
 
+    if {![info exists macports::revupgrade_autorun]} {
+        set macports::revupgrade_autorun yes
+    }
+    if {![info exists macports::revupgrade_mode]} {
+        set macports::revupgrade_mode "rebuild"
+    }
+    if {![info exists macports::global_options(ports_rev-upgrade_id-loadcmd-check)]
+         && [info exists macports::revupgrade_check_id_loadcmds]} {
+        set macports::global_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
+        set temp_options(ports_rev-upgrade_id-loadcmd-check) ${macports::revupgrade_check_id_loadcmds}
+    }
+
     # make tools we run operate in UTF-8 mode
     set env(LANG) en_US.UTF-8
 
@@ -905,6 +1031,7 @@
         package require Pextlib 1.0
         package require registry 1.0
         package require registry2 2.0
+        package require machista 1.0
     } else {
         return -code error "Library directory '$libpath' must exist"
     }
@@ -946,6 +1073,25 @@
         trace add variable macports::gccversion read macports::setgccinfo
     }
 
+    if {![info exists developer_dir]} {
+        if {$os_platform == "darwin"} {
+            trace add variable macports::developer_dir read macports::set_developer_dir
+        } else {
+            set macports::developer_dir ""
+        }
+    } else {
+        if {$os_platform == "darwin" && ![file isdirectory $developer_dir]} {
+            ui_warn "Your developer_dir setting in macports.conf points to a non-existing directory.\
+                Since this is known to cause problems, please correct the setting or comment it and let\
+                macports auto-discover the correct path."
+        }
+    }
+
+    if {[getuid] == 0 && $os_major >= 11 && $os_platform == "darwin" && 
+            [file isfile "${macports::user_home}/Library/Preferences/com.apple.dt.Xcode.plist"]} {
+        macports::copy_xcode_plist $env(HOME)
+    }
+
     # Set the default umask
     if {![info exists destroot_umask]} {
         set destroot_umask 022
@@ -1005,6 +1151,24 @@
     # add ccache to environment
     set env(CCACHE_DIR) ${macports::ccache_dir}
 
+    # load cached ping times
+    if {[catch {
+        set pingfile [open ${macports::portdbpath}/pingtimes r]
+        array set macports::ping_cache [gets $pingfile]
+        close $pingfile
+    }]} { array set macports::ping_cache {} }
+    # set up arrays of blacklisted and preferred hosts
+    if {[info exists macports::host_blacklist]} {
+        foreach host ${macports::host_blacklist} {
+            set macports::host_blacklisted($host) 1
+        }
+    }
+    if {[info exists macports::preferred_hosts]} {
+        foreach host ${macports::preferred_hosts} {
+            set macports::host_preferred($host) 1
+        }
+    }
+
     # load the quick index
     _mports_load_quickindex
 
@@ -1013,7 +1177,7 @@
         if {[macports::getprotocol $default_source_url] == "file" || [macports::getprotocol $default_source_url] == "rsync"} {
             set default_portindex [macports::getindex $default_source_url]
             if {[file exists $default_portindex] && [expr [clock seconds] - [file mtime $default_portindex]] > 1209600} {
-                ui_warn "port definitions are more than two weeks old, consider using selfupdate"
+                ui_warn "port definitions are more than two weeks old, consider updating them by running 'port selfupdate'."
             }
         }
     }
@@ -1040,10 +1204,48 @@
 
 # call this just before you exit
 proc mportshutdown {} {
+    # save ping times
+    global macports::ping_cache macports::portdbpath
+    if {[file writable ${macports::portdbpath}]} {
+        catch {
+            foreach host [array names ping_cache] {
+                # don't save expired entries
+                if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] < 86400} {
+                    lappend pinglist_fresh $host $ping_cache($host)
+                }
+            }
+            set pingfile [open ${macports::portdbpath}/pingtimes w]
+            puts $pingfile $pinglist_fresh
+            close $pingfile
+        }
+    }
     # close it down so the cleanup stuff is called, e.g. vacuuming the db
     registry::close
 }
 
+# link plist for xcode 4.3's benefit
+proc macports::copy_xcode_plist {target_homedir} {
+    global macports::user_home macports::macportsuser
+    set user_plist "${user_home}/Library/Preferences/com.apple.dt.Xcode.plist"
+    set target_dir "${target_homedir}/Library/Preferences"
+    file delete -force "${target_dir}/com.apple.dt.Xcode.plist"
+    if {[file isfile $user_plist]} {
+        if {![file isdirectory "${target_dir}"]} {
+            if {[catch {file mkdir "${target_dir}"} result]} {
+                ui_warn "Failed to create Library/Preferences in ${target_homedir}: $result"
+                return
+            }
+        }
+        if {[file writable ${target_dir}] && [catch {
+            ui_debug "Copying $user_plist to ${target_dir}"
+            file copy -force $user_plist $target_dir
+            file attributes "${target_dir}/com.apple.dt.Xcode.plist" -owner $macportsuser -permissions 0644
+        } result]} {
+            ui_warn "Failed to copy com.apple.dt.Xcode.plist to ${target_dir}: $result"
+        }
+    }
+}
+
 proc macports::worker_init {workername portpath porturl portbuildpath options variations} {
     global macports::portinterp_options macports::portinterp_deferred_options
 
@@ -1123,10 +1325,18 @@
     $workername alias registry_active registry::active
     $workername alias registry_file_registered registry::file_registered
     $workername alias registry_port_registered registry::port_registered
+    $workername alias registry_list_depends registry::list_depends
 
     # deferred options processing.
     $workername alias getoption macports::getoption
 
+    # ping cache
+    $workername alias get_pingtime macports::get_pingtime
+    $workername alias set_pingtime macports::set_pingtime
+
+    # archive_sites.conf handling
+    $workername alias get_archive_sites_conf_values macports::get_archive_sites_conf_values
+
     foreach opt $portinterp_options {
         if {![info exists $opt]} {
             global macports::$opt
@@ -1441,6 +1651,8 @@
         error "Error evaluating variants"
     }
 
+    $workername eval port::run_callbacks
+
     ditem_key $mport provides [$workername eval return \$subport]
 
     return $mport
@@ -1555,6 +1767,10 @@
                 break
             }
         }
+
+        if {$found} {
+            break
+        }
     }
     if {$return_match} {
         if {$found} {
@@ -1702,7 +1918,7 @@
         ui_error "Failed to install $portname"
         ui_debug "$::errorInfo"
         if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
-            ui_notice "Log for $portname is at: $::debuglogname"
+            ui_notice "Please see the log file for port $portname for details:\n    $::debuglogname"
         }
         macports::pop_log
         return 1
@@ -1725,6 +1941,20 @@
         macports::push_log $mport
     }
 
+    # Use _target_needs_deps as a proxy for whether we're going to
+    # build and will therefore need to check Xcode version and
+    # supported_archs.
+    if {[macports::_target_needs_deps $target]} {
+        # possibly warn or error out depending on how old xcode is
+        if {[$workername eval _check_xcode_version] != 0} {
+            return 1
+        }
+        # error out if selected arch(s) not supported by this port
+        if {[$workername eval check_supported_archs] != 0} {
+            return 1
+        }
+    }
+
     # Before we build the port, we must build its dependencies.
     set dlist {}
     if {[macports::_target_needs_deps $target] && [macports::_mport_has_deptypes $mport [macports::_deptypes_for_target $target $workername]]} {
@@ -1732,14 +1962,6 @@
         # see if we actually need to build this port
         if {($target != "activate" && $target != "install") ||
             ![$workername eval registry_exists \$subport \$version \$revision \$portvariants]} {
-            # possibly warn or error out depending on how old xcode is
-            if {[$workername eval _check_xcode_version] != 0} {
-                return 1
-            }
-            # error out if selected arch(s) not supported by this port
-            if {[$workername eval check_supported_archs] != 0} {
-                return 1
-            }
     
             # upgrade dependencies that are already installed
             if {![macports::global_option_isset ports_nodeps]} {
@@ -1822,7 +2044,7 @@
     global ::logenabled ::debuglogname
     if {[info exists ::logenabled] && $::logenabled && [info exists ::debuglogname]} {
         if {$result != 0} {
-            ui_notice "Log for $portname is at: $::debuglogname"
+            ui_notice "Please see the log file for port $portname for details:\n    $::debuglogname"
         }
         macports::pop_log
     }
@@ -1845,7 +2067,7 @@
 
     foreach deptype $deptypes {
         if {![info exists portinfo($deptype)]} {
-            set portinfo($deptype) ""
+            continue
         }
         foreach depspec $portinfo($deptype) {
             set dep_portname [$workername eval _get_dep_port $depspec]
@@ -1872,7 +2094,7 @@
                         }
                     }
                     if {[llength $missing] > 0} {
-                        if {[info exists dep_portinfo(variants)] && [lsearch $dep_portinfo(variants) universal] != -1} {
+                        if {[info exists dep_portinfo(variants)] && [lsearch -exact $dep_portinfo(variants) universal] != -1} {
                             # dep offers a universal variant
                             if {[llength $active_archs] == 1} {
                                 # not installed universal
@@ -2005,7 +2227,7 @@
 
     set numfailed 0
 
-    ui_debug "Synchronizing ports tree(s)"
+    ui_msg "$macports::ui_prefix Updating the ports tree"
     foreach source $sources {
         set flags [lrange $source 1 end]
         set source [lindex $source 0]
@@ -2020,6 +2242,8 @@
                 set portdir [macports::getportdir $source]
                 set svn_cmd ""
                 catch {set svn_cmd [macports::findBinary svn]}
+                set git_cmd ""
+                catch {set git_cmd [macports::findBinary git]}
                 if {$svn_cmd != "" && ([file exists $portdir/.svn] || ![catch {exec $svn_cmd info $portdir > /dev/null 2>@1}])} {
                     set svn_commandline "$svn_cmd update --non-interactive ${portdir}"
                     ui_debug $svn_commandline
@@ -2044,6 +2268,30 @@
                         incr numfailed
                         continue
                     }
+                } elseif {$git_cmd != "" && [file exists $portdir/.git]} {
+                    set git_commandline "pushd $portdir ; $git_cmd pull --rebase ; popd"
+                    ui_debug $git_commandline
+                    if {
+                        [catch {
+                            if {[getuid] == 0} {
+                                set euid [geteuid]
+                                set egid [getegid]
+                                ui_debug "changing euid/egid - current euid: $euid - current egid: $egid"
+                                setegid [name_to_gid [file attributes $portdir -group]]
+                                seteuid [name_to_uid [file attributes $portdir -owner]]
+                            }
+                            system $git_commandline
+                            if {[getuid] == 0} {
+                                seteuid $euid
+                                setegid $egid
+                            }
+                        }]
+                    } {
+                        ui_debug "$::errorInfo"
+                        ui_error "Synchronization of the local ports tree failed doing a git pull --rebase"
+                        incr numfailed
+                        continue
+                    }
                 }
                 set needs_portindex 1
             }
@@ -2371,7 +2619,7 @@
         }
     }
     if {!$found} {
-        return -code error "No index(es) found! Have you synced your source indexes?"
+        return -code error "No index(es) found! Have you synced your port definitions? Try running 'port selfupdate'."
     }
 
     return $matches
@@ -2528,7 +2776,7 @@
         }
     }
     if {!$found} {
-        return -code error "No index(es) found! Have you synced your source indexes?"
+        return -code error "No index(es) found! Have you synced your port definitions? Try running 'port selfupdate'."
     }
 
     return $matches
@@ -2549,11 +2797,13 @@
         set source [lindex $source 0]
         set index [macports::getindex $source]
         if {![file exists ${index}]} {
+            incr sourceno
             continue
         }
         if {![file exists ${index}.quick]} {
             ui_warn "No quick index file found, attempting to generate one for source: $source"
             if {[catch {set quicklist [mports_generate_quickindex ${index}]}]} {
+                incr sourceno
                 continue
             }
         }
@@ -2561,6 +2811,7 @@
         if {![info exists quicklist]} {
             if {[catch {set fd [open ${index}.quick r]} result]} {
                 ui_warn "Can't open quick index file for source: $source"
+                incr sourceno
                 continue
             } else {
                 set quicklist [read $fd]
@@ -2573,7 +2824,7 @@
         incr sourceno 1
     }
     if {!$sourceno} {
-        ui_warn "No index(es) found! Have you synced your source indexes?"
+        ui_warn "No index(es) found! Have you synced your port definitions? Try running 'port selfupdate'."
     }
 }
 
@@ -2664,11 +2915,10 @@
 proc mportdepends {mport {target ""} {recurseDeps 1} {skipSatisfied 1} {accDeps 0}} {
 
     array set portinfo [mportinfo $mport]
-    set deptypes {}
     if {$accDeps} {
-        upvar depspec_seen depspec_seen
+        upvar port_seen port_seen
     } else {
-        array set depspec_seen {}
+        array set port_seen {}
     }
 
     # progress indicator
@@ -2703,17 +2953,19 @@
             continue
         }
         foreach depspec $portinfo($deptype) {
-            # skip depspec/archs combos we've already seen, and ones with less archs than ones we've seen
-            set seenkey "${depspec},[join $required_archs ,]"
+            # get the portname that satisfies the depspec
+            set dep_portname [$workername eval _get_dep_port $depspec]
+            # skip port/archs combos we've already seen, and ones with the same port but less archs than ones we've seen (or noarch)
+            set seenkey "${dep_portname},[join $required_archs ,]"
             set seen 0
-            if {[info exists depspec_seen($seenkey)]} {
+            if {[info exists port_seen($seenkey)]} {
                 set seen 1
             } else {
-                set prev_seenkeys [array names depspec_seen ${depspec},*]
+                set prev_seenkeys [array names port_seen ${dep_portname},*]
                 set nrequired [llength $required_archs]
                 foreach key $prev_seenkeys {
                     set key_archs [lrange [split $key ,] 1 end]
-                    if {[llength $key_archs] > $nrequired} {
+                    if {$key_archs == "noarch" || $required_archs == "noarch" || [llength $key_archs] > $nrequired} {
                         set seen 1
                         set seenkey $key
                         break
@@ -2721,9 +2973,9 @@
                 }
             }
             if {$seen} {
-                if {$depspec_seen($seenkey) != 0} {
+                if {$port_seen($seenkey) != 0} {
                     # nonzero means the dep is not satisfied, so we have to record it
-                    ditem_append_unique $mport requires $depspec_seen($seenkey)
+                    ditem_append_unique $mport requires $port_seen($seenkey)
                 }
                 continue
             }
@@ -2732,8 +2984,6 @@
             # If we don't skip or if it is not, add it to the list.
             set present [_mportispresent $mport $depspec]
 
-            # get the portname that satisfies the depspec
-            set dep_portname [$workername eval _get_dep_port $depspec]
             if {!$skipSatisfied && $dep_portname == ""} {
                 set dep_portname [lindex [split $depspec :] end]
             }
@@ -2769,15 +3019,16 @@
                 } elseif {[info exists dep_portinfo(installs_libs)] && !$dep_portinfo(installs_libs)} {
                     set check_archs 0
                 }
-                lappend options subport $dep_portinfo(name)
+                set dep_options $options
+                lappend dep_options subport $dep_portinfo(name)
                 # Figure out the depport. Check the open_mports list first, since
                 # we potentially leak mport references if we mportopen each time,
                 # because mportexec only closes each open mport once.
-                set depport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $options variations $variations]]
-                
+                set depport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $dep_options]]
+
                 if {$depport == {}} {
                     # We haven't opened this one yet.
-                    set depport [mportopen $dep_portinfo(porturl) $options $variations]
+                    set depport [mportopen $dep_portinfo(porturl) $dep_options $variations]
                 }
             }
 
@@ -2786,18 +3037,18 @@
                 && ![macports::_mport_supports_archs $depport $required_archs]} {
 
                 set supported_archs [_mportkey $depport supported_archs]
+                array unset variation_array
+                array set variation_array [[ditem_key $depport workername] eval "array get variations"]
                 mportclose $depport
                 set arch_mismatch 1
                 set has_universal 0
                 if {[info exists dep_portinfo(variants)] && [lsearch -exact $dep_portinfo(variants) universal] != -1} {
                     # a universal variant is offered
                     set has_universal 1
-                    array unset variation_array
-                    array set variation_array $variations
                     if {![info exists variation_array(universal)] || $variation_array(universal) != "+"} {
                         set variation_array(universal) +
                         # try again with +universal
-                        set depport [mportopen $dep_portinfo(porturl) $options [array get variation_array]]
+                        set depport [mportopen $dep_portinfo(porturl) $dep_options [array get variation_array]]
                         if {[macports::_mport_supports_archs $depport $required_archs]} {
                             set arch_mismatch 0
                         }
@@ -2818,9 +3069,11 @@
                 # Append the sub-port's provides to the port's requirements list.
                 set depport_provides "[ditem_key $depport provides]"
                 ditem_append_unique $mport requires $depport_provides
-                set depspec_seen($seenkey) $depport_provides
-            } else {
-                set depspec_seen($seenkey) 0
+                # record actual archs we ended up getting
+                set port_seen(${dep_portname},[join [macports::_mport_archs $depport] ,]) $depport_provides
+            } elseif {$present && $dep_portname != ""} {
+                # record actual installed archs
+                set port_seen(${dep_portname},[join [macports::_active_archs $dep_portname] ,]) 0
             }
         }
     }
@@ -2844,8 +3097,7 @@
     if {$required_archs == "noarch"} {
         return 1
     }
-    set workername [ditem_key $mport workername]
-    set provided_archs [$workername eval get_canonical_archs]
+    set provided_archs [_mport_archs $mport]
     if {$provided_archs == "noarch"} {
         return 1
     }
@@ -2857,17 +3109,21 @@
     return 1
 }
 
+# return the archs of the given mport
+proc macports::_mport_archs {mport} {
+    set workername [ditem_key $mport workername]
+    return [$workername eval get_canonical_archs]
+}
+
 # check if the active version of a port supports the given archs
 proc macports::_active_supports_archs {portname required_archs} {
     if {$required_archs == "noarch"} {
         return 1
     }
-    if {[catch {set ilist [registry::active $portname]}]} {
+    if {[catch {registry::active $portname}]} {
         return 0
     }
-    set i [lindex $ilist 0]
-    set regref [registry::open_entry $portname [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
-    set provided_archs [registry::property_retrieve $regref archs]
+    set provided_archs [_active_archs $portname]
     if {$provided_archs == "noarch" || $provided_archs == "" || $provided_archs == 0} {
         return 1
     }
@@ -2879,6 +3135,16 @@
     return 1
 }
 
+# get the archs for a given active port
+proc macports::_active_archs {portname} {
+    if {[catch {set ilist [registry::active $portname]}]} {
+        return ""
+    }
+    set i [lindex $ilist 0]
+    set regref [registry::open_entry $portname [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
+    return [registry::property_retrieve $regref archs]
+}
+
 # print an error message explaining why a port's archs are not provided by a dependency
 proc macports::_explain_arch_mismatch {port dep required_archs supported_archs has_universal} {
     global macports::universal_archs
@@ -2963,7 +3229,8 @@
         mpkg        -
         rpm         -
         dpkg        {
-            if {[$workername eval _archive_available]} {
+            if {[global_option_isset ports_binary_only] ||
+                (![global_option_isset ports_source_only] && [$workername eval _archive_available])} {
                 return "depends_lib depends_run"
             } else {
                 return "depends_fetch depends_extract depends_build depends_lib depends_run"
@@ -2972,8 +3239,9 @@
         install     -
         activate    -
         ""          {
-            if {[$workername eval registry_exists \$subport \$version \$revision \$portvariants]
-                || [$workername eval _archive_available]} {
+            if {[global_option_isset ports_binary_only] ||
+                [$workername eval registry_exists \$subport \$version \$revision \$portvariants]
+                || (![global_option_isset ports_source_only] && [$workername eval _archive_available])} {
                 return "depends_lib depends_run"
             } else {
                 return "depends_fetch depends_extract depends_build depends_lib depends_run"
@@ -3087,7 +3355,6 @@
 
     # syncing ports tree.
     if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
-        ui_msg "$macports::ui_prefix Updating the ports tree"
         if {$comp > 0} {
             # updated portfiles potentially need new base to parse - tell sync to try to 
             # use prefabricated PortIndex files and signal if it couldn't
@@ -3139,12 +3406,12 @@
             # Choose a sane compiler
             set cc_arg ""
             if {$::macports::os_platform == "darwin"} {
-                set cc_arg "CC=/usr/bin/cc "
+                set cc_arg "CC=/usr/bin/cc OBJC=/usr/bin/cc "
             }
 
             # do the actual configure, build and installation of new base
             ui_msg "Installing new MacPorts release in $prefix as $owner:$group; permissions $perms; Tcl-Package in $tclpackage\n"
-            if { [catch { system "cd $mp_source_path && ${cc_arg}./configure $configure_args && make && make install SELFUPDATING=1" } result] } {
+            if { [catch { system "cd $mp_source_path && ${cc_arg}./configure $configure_args && make SELFUPDATING=1 && make install SELFUPDATING=1" } result] } {
                 return -code error "Error installing new MacPorts base: $result"
             }
             if {[info exists updatestatus]} {
@@ -3178,12 +3445,16 @@
 }
 
 # upgrade API wrapper procedure
-# return codes: 0 = success, 1 = general failure, 2 = port name not found in index
+# return codes:
+#   0 = success
+#   1 = general failure
+#   2 = port name not found in index
+#   3 = port not installed
 proc macports::upgrade {portname dspec variationslist optionslist {depscachename ""}} {
     # only installed ports can be upgraded
     if {![registry::entry_exists_for_name $portname]} {
         ui_error "$portname is not installed"
-        return 1
+        return 3
     }
     if {![string match "" $depscachename]} {
         upvar $depscachename depscache
@@ -3224,11 +3495,11 @@
 
     # Is this a rev-upgrade-called run?
     set is_revupgrade no
-    if {[macports::global_option_isset ports_revupgrade]} {
+    if {[info exists options(ports_revupgrade)] && $options(ports_revupgrade)} {
         set is_revupgrade yes
     }
     set is_revupgrade_second_run no
-    if {[macports::global_option_isset ports_revupgrade_second_run]} {
+    if {[info exists options(ports_revupgrade_second_run)] && $options(ports_revupgrade_second_run)} {
         set is_revupgrade_second_run yes
     }
 
@@ -3279,7 +3550,7 @@
                 array set portinfo [mportinfo $workername]
                 
                 # upgrade its dependencies first
-                set status [_upgrade_dependencies portinfo depscache variationslist options yes]
+                set status [_upgrade_dependencies portinfo depscache variationslist options]
                 if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
                     catch {mportclose $workername}
                     return $status
@@ -3488,8 +3759,10 @@
             ui_debug "platform mismatch ... upgrading!"
             set build_override 1
         } elseif {$is_revupgrade_second_run} {
+            ui_debug "rev-upgrade override ... upgrading (from source)!"
             set build_override 1
         } elseif {$is_revupgrade} {
+            ui_debug "rev-upgrade override ... upgrading!"
             # in the first run of rev-upgrade, only activate possibly already existing files and check for missing dependencies
             set will_install yes
         } else {
@@ -3507,17 +3780,19 @@
     }
 
     set will_build no
+    set already_installed [registry::entry_exists $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants)]
     # avoid building again unnecessarily
     if {$will_install &&
         ([info exists options(ports_upgrade_force)]
             || $build_override == 1
-            || ![registry::entry_exists $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants)])} {
+            || !$already_installed)} {
         set will_build yes
     }
 
     # first upgrade dependencies
     if {![info exists options(ports_nodeps)] && !$is_revupgrade} {
-        set status [_upgrade_dependencies portinfo depscache variationslist options $will_build]
+        # the last arg is because we might have to build from source if a rebuild is being forced
+        set status [_upgrade_dependencies portinfo depscache variationslist options [expr $will_build && $already_installed]]
         if {$status != 0 && $status != 2 && ![ui_isset ports_processall]} {
             catch {mportclose $workername}
             return $status
@@ -3569,7 +3844,7 @@
     }
 
     # are we installing an existing version due to force or epoch override?
-    if {[registry::entry_exists $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants)]
+    if {$already_installed
         && ([info exists options(ports_upgrade_force)] || $build_override == 1)} {
          ui_debug "Uninstalling $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants)"
         # we have to force the uninstall in case of dependents
@@ -3701,7 +3976,7 @@
 # upgrade_dependencies: helper proc for upgrade
 # Calls upgrade on each dependency listed in the PortInfo.
 # Uses upvar to access the variables.
-proc macports::_upgrade_dependencies {portinfoname depscachename variationslistname optionsname {build_needed yes}} {
+proc macports::_upgrade_dependencies {portinfoname depscachename variationslistname optionsname {build_needed no}} {
     upvar $portinfoname portinfo $depscachename depscache \
           $variationslistname variationslist \
           $optionsname options
@@ -3719,17 +3994,18 @@
     set saved_do_dependents [info exists options(ports_do_dependents)]
     unset -nocomplain options(ports_do_dependents)
 
-    set status 0
+    set parent_interp [ditem_key $parentworker workername]
     # each required dep type is upgraded
-    if {$build_needed} {
-        set dtypes {depends_fetch depends_extract depends_build depends_lib depends_run}
+    if {$build_needed && ![global_option_isset ports_binary_only]} {
+        set dtypes [_deptypes_for_target destroot $parent_interp]
     } else {
-        set dtypes {depends_lib depends_run}
+        set dtypes [_deptypes_for_target install $parent_interp]
     }
+
+    set status 0
     foreach dtype $dtypes {
         if {[info exists portinfo($dtype)]} {
             foreach i $portinfo($dtype) {
-                set parent_interp [ditem_key $parentworker workername]
                 set d [$parent_interp eval _get_dep_port $i]
                 if {![llength [array get depscache port:${d}]] && ![llength [array get depscache $i]]} {
                     if {$d != ""} {
@@ -3874,35 +4150,62 @@
     }
 }
 
+# check if the system we're on can run code of the given architecture
+proc macports::arch_runnable {arch} {
+    global macports::os_major macports::os_arch macports::os_platform
+    if {${macports::os_platform} == "darwin"} {
+        if {${macports::os_major} >= 11 && [string first "ppc" $arch] == 0} {
+            return no
+        } elseif {${macports::os_arch} == "i386" && $arch == "ppc64"} {
+            return no
+        } elseif {${macports::os_major} <= 8 && $arch == "x86_64"} {
+            return no
+        }
+    }
+    return yes
+}
+
 proc macports::revupgrade {opts} {
     set run_loop 1
     array set broken_port_counts {}
     while {$run_loop == 1} {
         set run_loop [revupgrade_scanandrebuild broken_port_counts $opts]
     }
-    return 0;
+    return 0
 }
 
 # returns 1 if ports were rebuilt and revupgrade_scanandrebuild should be called again
-proc revupgrade_scanandrebuild {broken_port_counts_name opts} {
+proc macports::revupgrade_scanandrebuild {broken_port_counts_name opts} {
     upvar $broken_port_counts_name broken_port_counts
     array set options $opts
 
     set files [registry::file search active 1 binary -null]
-    if {[llength $files] > 0} {
-        set files_count [llength $files]
+    set files_count [llength $files]
+    set fancy_output [expr ![macports::ui_isset ports_debug] && [isatty stdout]]
+    if {$files_count > 0} {
         registry::write {
             try {
                 ui_msg -nonewline "$macports::ui_prefix Updating database of binaries"
                 set i 1
                 foreach f $files {
-                    if {![macports::ui_isset ports_debug]} {
-                        ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr $i * 100 / $files_count]%"
-                        flush stdout
+                    if {$fancy_output} {
+                        if {$files_count < 10000 || $i % 10 == 1 || $i == $files_count} {
+                            ui_msg -nonewline "\r$macports::ui_prefix Updating database of binaries: [expr ($i * 1000 / $files_count) / 10.0]%"
+                            flush stdout
+                        }
                     }
-                    ui_debug "Updating binary flag for file $i of [llength $files]: [$f path]"
+                    set fpath [$f actual_path]
+                    ui_debug "Updating binary flag for file $i of $files_count: $fpath"
                     incr i
-                    $f binary [fileIsBinary [$f path]]
+
+                    if {0 != [catch {$f binary [fileIsBinary $fpath]} fileIsBinaryError]} {
+                        # handle errors (e.g. file not found, permission denied) gracefully
+                        if {$fancy_output} {
+                            ui_msg ""
+                        }
+                        ui_warn "Error determining file type of `$fpath': $fileIsBinaryError"
+                        ui_warn "A file belonging to the `[[registry::entry owner $fpath] name]' port is missing or unreadable. Consider reinstalling it."
+                    }
                 }
             } catch {*} {
                 ui_error "Updating database of binaries failed"
@@ -3914,8 +4217,9 @@
 
     set broken_files {};
     set binaries [registry::file search active 1 binary 1]
-    ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
-    if {[llength $binaries] > 0} {
+    set binary_count [llength $binaries]
+    if {$binary_count > 0} {
+        ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
         set handle [machista::create_handle]
         if {$handle == "NULL"} {
             error "Error creating libmachista handle"
@@ -3924,16 +4228,18 @@
         array set files_warned_about [list]
 
         set i 1
-        set binary_count [llength $binaries]
         foreach b $binaries {
-            if {![macports::ui_isset ports_debug]} {
-                ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr $i * 100 / $binary_count]%"
-                flush stdout
+            if {$fancy_output} {
+                if {$binary_count < 10000 || $i % 10 == 1 || $i == $binary_count} {
+                    ui_msg -nonewline "\r$macports::ui_prefix Scanning binaries for linking errors: [expr ($i * 1000 / $binary_count) / 10.0]%"
+                    flush stdout
+                }
             }
-            #ui_debug "$i/[llength $binaries]: [$b path]"
+            set bpath [$b actual_path]
+            #ui_debug "$i/$binary_count: $bpath"
             incr i
 
-            set resultlist [machista::parse_file $handle [$b path]]
+            set resultlist [machista::parse_file $handle $bpath]
             set returncode [lindex $resultlist 0]
             set result     [lindex $resultlist 1]
 
@@ -3941,12 +4247,12 @@
                 if {$returncode == $machista::EMAGIC} {
                     # not a Mach-O file
                     # ignore silently, these are only static libs anyway
-                    #ui_debug "Error parsing file [$b path]: [machista::strerror $returncode]"
+                    #ui_debug "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 } else {
-                    if {![macports::ui_isset ports_debug]} {
+                    if {$fancy_output} {
                         ui_msg ""
                     }
-                    ui_warn "Error parsing file [$b path]: [machista::strerror $returncode]"
+                    ui_warn "Error parsing file ${bpath}: [machista::strerror $returncode]"
                 }
                 continue;
             }
@@ -3957,56 +4263,64 @@
                     if {[$architecture cget -mat_install_name] != "NULL" && [$architecture cget -mat_install_name] != ""} {
                         # check if this lib's install name actually refers to this file itself
                         # if this is not the case software linking against this library might have erroneous load commands
-                        if {0 == [catch {set idloadcmdpath [revupgrade_handle_special_paths [$b path] [$architecture cget -mat_install_name]]}]} {
+                        if {0 == [catch {set idloadcmdpath [revupgrade_handle_special_paths $bpath [$architecture cget -mat_install_name]]}]} {
                             if {[string index $idloadcmdpath 0] != "/"} {
-                                set port [registry::entry owner [$b path]]
+                                set port [registry::entry owner $bpath]
                                 if {$port != ""} {
                                     set portname [$port name]
                                 } else {
                                     set portname "<unknown-port>"
                                 }
-                                if {![macports::ui_isset ports_debug]} {
+                                if {$fancy_output} {
                                     ui_msg ""
                                 }
-                                ui_warn "ID load command in [$b path], arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
+                                ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] (belonging to port $portname) contains relative path"
                             } elseif {![file exists $idloadcmdpath]} {
-                                set port [registry::entry owner [$b path]]
+                                set port [registry::entry owner $bpath]
                                 if {$port != ""} {
                                     set portname [$port name]
                                 } else {
                                     set portname "<unknown-port>"
                                 }
-                                if {![macports::ui_isset ports_debug]} {
+                                if {$fancy_output} {
                                     ui_msg ""
                                 }
-                                ui_warn "ID load command in [$b path], arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
+                                ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to non-existant file $idloadcmdpath"
                                 ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
                             } else {
     
-                                set hash_this [sha256 file [$b path]]
+                                set hash_this [sha256 file $bpath]
                                 set hash_idloadcmd [sha256 file $idloadcmdpath]
     
                                 if {$hash_this != $hash_idloadcmd} {
-                                    set port [registry::entry owner [$b path]]
+                                    set port [registry::entry owner $bpath]
                                     if {$port != ""} {
                                         set portname [$port name]
                                     } else {
                                         set portname "<unknown-port>"
                                     }
-                                    if {![macports::ui_isset ports_debug]} {
+                                    if {$fancy_output} {
                                         ui_msg ""
                                     }
-                                    ui_warn "ID load command in [$b path], arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file $idloadcmdpath, which is a different file"
+                                    ui_warn "ID load command in ${bpath}, arch [machista::get_arch_name [$architecture cget -mat_arch]] refers to file $idloadcmdpath, which is a different file"
                                     ui_warn "This is probably a bug in the $portname port and might cause problems in libraries linking against this file"
                                 }
                             }
                         }
                     }
                 }
+
+                set archname [machista::get_arch_name [$architecture cget -mat_arch]]
+                if {![arch_runnable $archname]} {
+                    ui_debug "skipping $archname in $bpath since this system can't run it anyway"
+                    set architecture [$architecture cget -next]
+                    continue
+                }
+
                 set loadcommand [$architecture cget -mat_loadcmds]
 
                 while {$loadcommand != "NULL"} {
-                    if {0 != [catch {set filepath [revupgrade_handle_special_paths [$b path] [$loadcommand cget -mlt_install_name]]}]} {
+                    if {0 != [catch {set filepath [revupgrade_handle_special_paths $bpath [$loadcommand cget -mlt_install_name]]}]} {
                         set loadcommand [$loadcommand cget -next]
                         continue;
                     }
@@ -4017,15 +4331,15 @@
 
                     if {$libreturncode != $machista::SUCCESS} {
                         if {![info exists files_warned_about($filepath)]} {
-                            if {![macports::ui_isset ports_debug]} {
+                            if {[macports::ui_isset ports_verbose]} {
                                 ui_msg ""
                             }
-                            ui_warn "Could not open $filepath: [machista::strerror $libreturncode]"
+                            ui_info "Could not open $filepath: [machista::strerror $libreturncode] (referenced from $bpath)"
                             set files_warned_about($filepath) yes
                         }
                         if {$libreturncode == $machista::EFILE} {
-                            ui_debug "Marking [$b path] as broken"
-                            lappend broken_files [$b path]
+                            ui_debug "Marking $bpath as broken"
+                            lappend broken_files $bpath
                         }
                         set loadcommand [$loadcommand cget -next]
                         continue;
@@ -4040,12 +4354,12 @@
                         }
 
                         if {[$loadcommand cget -mlt_version] != [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
-                            if {![macports::ui_isset ports_debug]} {
+                            if {[macports::ui_isset ports_verbose]} {
                                 ui_msg ""
                             }
-                            ui_warn "Incompatible library version of file [$loadcommand cget -mlt_install_name]: Expected [$loadcommand cget -mlt_comp_version], but got [$libarchitecture cget -mat_comp_version]"
-                            ui_debug "Marking [$b path] as broken"
-                            lappend broken_files [$b path]
+                            ui_info "Incompatible library version: $bpath requires version [machista::format_dylib_version [$loadcommand cget -mlt_comp_version]] or later, but $filepath provides version [machista::format_dylib_version [$libarchitecture cget -mat_comp_version]]"
+                            ui_debug "Marking $bpath as broken"
+                            lappend broken_files $bpath
                         }
 
                         set libarch_found true;
@@ -4055,10 +4369,10 @@
                     if {$libarch_found == false} {
                         ui_debug "Missing architecture [machista::get_arch_name [$architecture cget -mat_arch]] in file $filepath"
                         if {[path_is_in_prefix $filepath]} {
-                            ui_debug "Marking [$b path] as broken"
-                            lappend broken_files [$b path]
+                            ui_debug "Marking $bpath as broken"
+                            lappend broken_files $bpath
                         } else {
-                            ui_debug "Missing architecture [machista::get_arch_name [$architecture cget -mat_arch]] in file outside prefix referenced from [$b path]"
+                            ui_debug "Missing architecture [machista::get_arch_name [$architecture cget -mat_arch]] in file outside prefix referenced from $bpath"
                             # ui_debug "   How did you get that compiled anyway?"
                         }
                     }
@@ -4073,32 +4387,80 @@
         machista::destroy_handle $handle
 
         if {[llength $broken_files] == 0} {
-            ui_msg "$macports::ui_prefix No broken files found. :)"
-            return 0;
+            ui_msg "$macports::ui_prefix No broken files found."
+            return 0
         }
         ui_msg "$macports::ui_prefix Found [llength $broken_files] broken file(s), matching files to ports"
         set broken_ports {}
         set broken_files [lsort -unique $broken_files]
         foreach file $broken_files {
             set port [registry::entry owner $file]
-            if {$port == ""} {
+            if {$port != ""} {
+                lappend broken_ports $port
+                lappend broken_files_by_port($port) $file
+            } else {
                 ui_error "Broken file $file doesn't belong to any port."
             }
-            lappend broken_ports $port
         }
         set broken_ports [lsort -unique $broken_ports]
 
-        foreach port $broken_ports {
-            if {![info exists broken_port_counts([$port name])]} {
-                set broken_port_counts([$port name]) 0
+        if {${macports::revupgrade_mode} == "rebuild"} {
+            # don't try to rebuild ports that don't exist in the tree
+            set temp_broken_ports {}
+            foreach port $broken_ports {
+                set portname [$port name]
+                if {[catch {mportlookup $portname} result]} {
+                    ui_debug "$::errorInfo"
+                    error "lookup of portname $portname failed: $result"
+                }
+                if {[llength $result] >= 2} {
+                    lappend temp_broken_ports $port
+                } else {
+                    ui_warn "No port $portname found in the index; can't rebuild"
+                }
             }
-            incr broken_port_counts([$port name])
-            if {$broken_port_counts([$port name]) > 3} {
-                ui_error "Port [$port name] is still broken after rebuiling it more than 3 times. You might want to file a bug for this."
-                error "Port [$port name] still broken after rebuilding [expr $broken_port_counts([$port name]) - 1] time(s)"
+
+            if {[llength $temp_broken_ports] == 0} {
+                ui_msg "$macports::ui_prefix Broken files found, but all associated ports are not in the index and so cannot be rebuilt."
+                return 0
             }
+        } else {
+            set temp_broken_ports $broken_ports
         }
 
+        set broken_ports {}
+
+        foreach port $temp_broken_ports {
+            set portname [$port name]
+
+            if {![info exists broken_port_counts($portname)]} {
+                set broken_port_counts($portname) 0
+            }
+            incr broken_port_counts($portname)
+            if {$broken_port_counts($portname) > 3} {
+                ui_error "Port $portname is still broken after rebuilding it more than 3 times."
+                if {$fancy_output} {
+                    ui_error "Please run port -d -y rev-upgrade and use the output to report a bug."
+                }
+                error "Port $portname still broken after rebuilding [expr $broken_port_counts($portname) - 1] time(s)"
+            } elseif {$broken_port_counts($portname) > 1 && [global_option_isset ports_binary_only]} {
+                error "Port $portname still broken after reinstalling -- can't rebuild due to binary-only mode"
+            }
+            lappend broken_ports $port
+        }
+        unset temp_broken_ports
+
+        if {${macports::revupgrade_mode} != "rebuild"} {
+            ui_msg "$macports::ui_prefix Found [llength $broken_ports] broken port(s):"
+            foreach port $broken_ports {
+                ui_msg "     [$port name] @[$port version] [$port variants][$port negated_variants]"
+                foreach f $broken_files_by_port($port) {
+                    ui_msg "         $f"
+                }
+            }
+            return 0
+        }
+
         ui_msg "$macports::ui_prefix Found [llength $broken_ports] broken port(s), determining rebuild order"
         # broken_ports are the nodes in our graph
         # now we need adjacents
@@ -4106,6 +4468,7 @@
             # initialize with empty list
             set adjlist($port) {}
             set revadjlist($port) {}
+            ui_debug "Broken: [$port name]"
         }
 
         array set visited {}
@@ -4123,8 +4486,16 @@
         set unsorted_ports $broken_ports
         set topsort_ports {}
         while {[llength $unsorted_ports] > 0} {
+            set lowest_adj_number [llength $adjlist([lindex $unsorted_ports 0])]
+            set lowest_adj_port [lindex $unsorted_ports 0]
+
             foreach port $unsorted_ports {
-                if {[llength $adjlist($port)] == 0} {
+                set len [llength $adjlist($port)]
+                if {$len < $lowest_adj_number} {
+                    set lowest_adj_port $port
+                    set lowest_adj_number $len
+                }
+                if {$len == 0} {
                     # this node has no further dependencies
                     # add it to topsorted list
                     lappend topsort_ports $port
@@ -4137,8 +4508,25 @@
                         set index [lsearch -exact $adjlist($target) $port]
                         set adjlist($target) [lreplace $adjlist($target) $index $index]
                     }
+
+                    break;
                 }
             }
+
+            # if we arrive here and lowest_adj_number is larger than 0, then we
+            # have a loop in the graph and need to break it somehow
+            if {$lowest_adj_number > 0} {
+                ui_debug "Breaking loop in dependency graph by starting with [$lowest_adj_port name], which has $lowest_adj_number dependencies"
+                lappend topsort_ports $lowest_adj_port
+
+                set index [lsearch -exact $unsorted_ports $lowest_adj_port]
+                set unsorted_ports [lreplace $unsorted_ports $index $index]
+
+                foreach target $revadjlist($port) {
+                    set index [lsearch -exact $adjlist($target) $lowest_adj_port]
+                    set adjlist($target) [lreplace $adjlist($target) $index $index]
+                }
+            }
         }
 
         ui_msg "$macports::ui_prefix Rebuilding in order"
@@ -4149,39 +4537,27 @@
         # shared depscache for all ports that are going to be rebuilt
         array set depscache {}
         set status 0
+        array set my_options [array get macports::global_options]
         foreach port $topsort_ports {
-            if {![info exists depscache(port:[$port name])]} {
-
-                # convert variations into the format macports::upgrade needs
-                set minusvariant [lrange [split [$port negated_variants] "-"] 1 end]
-                set plusvariant  [lrange [split [$port variants]         "+"] 1 end]
-                set variants     [list]
-                foreach v $minusvariant {
-                    lappend variants $v "-"
-                }
-                foreach v $plusvariant {
-                    lappend variants $v "+"
-                }
-                array unset variations
-                array set variations $variants
-
+            set portname [$port name]
+            if {![info exists depscache(port:$portname)]} {
                 # set rev-upgrade options and nodeps if this is not the first run
-                set macports::global_options(ports_revupgrade) "yes"
-                unset -nocomplain macports::global_options(ports_nodeps)
-                unset -nocomplain macports::global_options(ports_revupgrade_second_run)
-                unset -nocomplain macports::global_options(ports_source_only)
-                if {$broken_port_counts([$port name]) > 1} {
-                    set macports::global_options(ports_revupgrade_second_run) yes
-                    set macports::global_options(ports_nodeps) yes
+                set my_options(ports_revupgrade) "yes"
+                unset -nocomplain my_options(ports_nodeps)
+                unset -nocomplain my_options(ports_revupgrade_second_run)
+                if {$broken_port_counts($portname) > 1} {
+                    set my_options(ports_revupgrade_second_run) yes
+                    set my_options(ports_nodeps) yes
                     # build from source only until the buildbot has some method of rev-upgrade, too
-                    set macports::global_options(ports_source_only) yes
+                    set my_options(ports_source_only) yes
                 }
 
                 # call macports::upgrade with ports_revupgrade option to rebuild the port
-                set status [macports::upgrade [$port name] "port:[$port name]" \
-                    [array get variations] [array get macports::global_options] depscache]
+                set status [macports::upgrade $portname "port:$portname" \
+                    {} [array get my_options] depscache]
+                ui_debug "Rebuilding port $portname finished with status $status"
                 if {$status != 0} {
-                    error "Error rebuilding [$port name]"
+                    error "Error rebuilding $portname"
                 }
             }
         }
@@ -4199,7 +4575,8 @@
 # Return whether a path is in the macports prefix
 # Usage: path_is_in_prefix path_to_test
 # Returns true if the path is in the prefix, false otherwise
-proc path_is_in_prefix {path} {
+proc macports::path_is_in_prefix {path} {
+    global macports::prefix macports::applications_dir
     if {[string first $macports::prefix $path] == 0} {
         return yes
     }
@@ -4215,7 +4592,7 @@
 # Note that we can't reliably replace @executable_path, because it's only clear when executing a file where it was executed from.
 # Replacing @rpath does not work yet, but it might be possible to get it working using the rpath attribute in the file containing the
 # loadcommand
-proc revupgrade_handle_special_paths {fname path} {
+proc macports::revupgrade_handle_special_paths {fname path} {
     set corrected_path $path
 
     set loaderpath_idx [string first "@loader_path" $corrected_path]
@@ -4225,8 +4602,8 @@
 
     set executablepath_idx [string first "@executable_path" $corrected_path]
     if {$executablepath_idx != -1} {
-        ui_debug "Ignoring loadcommand containing @exectuable_path in $fname"
-        error "@exectuable_path in loadcommand"
+        ui_debug "Ignoring loadcommand containing @executable_path in $fname"
+        error "@executable_path in loadcommand"
     }
 
     set rpath_idx [string first "@rpath" $corrected_path]
@@ -4240,24 +4617,22 @@
 
 # Recursively build the dependency graph between broken ports
 # Usage: revupgrade_buildgraph start_port name_of_stack name_of_adjacency_list name_of_reverse_adjacency_list name_of_visited_map
-proc revupgrade_buildgraph {port stackname adjlistname revadjlistname visitedname} {
+proc macports::revupgrade_buildgraph {port stackname adjlistname revadjlistname visitedname} {
     upvar $stackname stack
     upvar $adjlistname adjlist
     upvar $revadjlistname revadjlist
     upvar $visitedname visited
 
+    set visited($port) true
+
     ui_debug "Processing port [$port name] @[$port epoch]:[$port version]_[$port revision] [$port variants] [$port negated_variants]"
     set dependent_ports [$port dependents]
     foreach dep $dependent_ports {
-        if {[info exists visited($dep)]} {
-            continue
-        }
-        set visited($dep) true
         set is_broken_port false
 
         if {[info exists adjlist($dep)]} {
-            #ui_debug "Dependency [$dep name] is broken, adding edge from [[lindex $stack 0] name] to [$dep name]"
-            #ui_debug "Making [$dep name] new head of stack"
+            ui_debug "Dependent [$dep name] is broken, adding edge from [$dep name] to [[lindex $stack 0] name]"
+            ui_debug "Making [$dep name] new head of stack"
             # $dep is one of the broken ports
             # add an edge to the last broken port in the DFS
             lappend revadjlist([lindex $stack 0]) $dep
@@ -4267,12 +4642,98 @@
             
             set is_broken_port true
         }
-        revupgrade_buildgraph $dep stack adjlist revadjlist visited
+        if {![info exists visited($dep)]} {
+            revupgrade_buildgraph $dep stack adjlist revadjlist visited
+        }
         if {$is_broken_port} {
-            #ui_debug "Removing [$dep name] from stack"
+            ui_debug "Removing [$dep name] from stack"
             # remove $dep from the stack
             set stack [lrange $stack 1 end]
         }
     }
 }
 
+# get cached ping time for host, modified by blacklist and preferred list
+proc macports::get_pingtime {host} {
+    global macports::ping_cache macports::host_blacklisted macports::host_preferred
+    if {[info exists host_blacklisted($host)]} {
+        return -1
+    } elseif {[info exists host_preferred($host)]} {
+        return 1
+    } elseif {[info exists ping_cache($host)]} {
+        # expire entries after 1 day
+        if {[expr [clock seconds] - [lindex $ping_cache($host) 1]] <= 86400} {
+            return [lindex $ping_cache($host) 0]
+        }
+    }
+    return {}
+}
+
+# cache a ping time of ms for host
+proc macports::set_pingtime {host ms} {
+    global macports::ping_cache
+    set ping_cache($host) [list $ms [clock seconds]]
+}
+
+# read and cache archive_sites.conf (called from port1.0 code)
+proc macports::get_archive_sites_conf_values {} {
+    global macports::archive_sites_conf_values macports::autoconf::macports_conf_path
+    if {![info exists archive_sites_conf_values]} {
+        set archive_sites_conf_values {}
+        set all_names {}
+        array set defaults {applications_dir /Applications/MacPorts prefix /opt/local type tbz2}
+        set conf_file "${macports_conf_path}/archive_sites.conf"
+        set conf_options {applications_dir frameworks_dir name prefix type urls}
+        if {[file isfile $conf_file]} {
+            set fd [open $conf_file r]
+            while {[gets $fd line] >= 0} {
+                if {[regexp {^(\w+)([ \t]+(.*))?$} $line match option ignore val] == 1} {
+                    if {[lsearch -exact $conf_options $option] >= 0} {
+                        if {$option == "name"} {
+                            set cur_name $val
+                            lappend all_names $val
+                        } elseif {[info exists cur_name]} {
+                            set trimmedval [string trim $val]
+                            if {$option == "urls"} {
+                                set processed_urls {}
+                                foreach url $trimmedval {
+                                    lappend processed_urls ${url}:nosubdir
+                                }
+                                lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) $processed_urls
+                                set sites($cur_name) $processed_urls
+                            } else {
+                                lappend archive_sites_conf_values portfetch::mirror_sites::archive_${option}($cur_name) $trimmedval
+                                set archive_${option}($cur_name) $trimmedval
+                            }
+                        } else {
+                            ui_warn "archive_sites.conf: ignoring '$option' occurring before name"
+                        }
+                    } else {
+                        ui_warn "archive_sites.conf: ignoring unknown key '$option'"
+                    }
+                }
+            }
+            close $fd
+
+            # check for unspecified values and set to defaults
+            foreach cur_name $all_names {
+                foreach key [array names defaults] {
+                    if {![info exists archive_${key}($cur_name)]} {
+                        set archive_${key}($cur_name) $defaults($key)
+                        lappend archive_sites_conf_values portfetch::mirror_sites::archive_${key}($cur_name) $defaults($key)
+                    }
+                }
+                if {![info exists archive_frameworks_dir($cur_name)]} {
+                    set archive_frameworks_dir($cur_name) $archive_prefix($cur_name)/Library/Frameworks
+                    lappend archive_sites_conf_values portfetch::mirror_sites::archive_frameworks_dir($cur_name) $archive_frameworks_dir($cur_name)
+                }
+                if {![info exists sites($cur_name)]} {
+                    ui_warn "archive_sites.conf: no urls set for $cur_name"
+                    set sites($cur_name) ""
+                    lappend archive_sites_conf_values portfetch::mirror_sites::sites($cur_name) ""
+                }
+            }
+        }
+    }
+    return $archive_sites_conf_values
+}

Modified: branches/gsoc11-statistics/base/src/macports1.0/macports_autoconf.tcl.in
===================================================================
--- branches/gsoc11-statistics/base/src/macports1.0/macports_autoconf.tcl.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/macports1.0/macports_autoconf.tcl.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -40,6 +40,8 @@
     variable macports_version "@MACPORTS_VERSION@"
     variable macports_user_dir "~/.macports"
     variable macportsuser "@RUNUSR@"
+    variable mdfind_path "@MDFIND@"
+    variable mdls_path "@MDLS@"
     variable open_path "@OPEN@"
     variable openssl_path "@OPENSSL@"
     variable pax_path "@PAX@"
@@ -49,4 +51,6 @@
     variable tar_q "@TAR_Q@"
     variable unzip_path "@UNZIP@"
     variable xar_path "@XAR@"
+    variable xcode_select_path "@XCODE_SELECT@"
+    variable xcodebuild_path "@XCODEBUILD@"
 }

Modified: branches/gsoc11-statistics/base/src/macports1.0/macports_dlist.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/macports1.0/macports_dlist.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/macports1.0/macports_dlist.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -306,8 +306,11 @@
 	# Loop for as long as there are ditems in the dlist.
 	while {1} {
 		set ditem [$selector $dlist statusdict]
-		
+
 		if {$ditem == {}} {
+		    if {[llength $dlist] > 0} {
+		        ui_debug "dlist_eval: all entries in dependency list have unsatisfied dependencies; can't process"
+		    }
 			break
 		} else {
 			# $handler should return a unix status code, 0 for success.

Modified: branches/gsoc11-statistics/base/src/macports1.0/macports_index.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/macports1.0/macports_index.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/macports1.0/macports_index.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -278,8 +278,7 @@
 # Checks for a locally cached copy of the port, or downloads the port
 # from the specified URL.  The port is extracted into the current working
 # directory along with a .mports_source file containing the url of the
-# source the port came from.  (This can be later used as a default for
-# "port submit")
+# source the port came from.
 #
 # The cached portfiles are in the same directory as the cached remote index.
 #

Modified: branches/gsoc11-statistics/base/src/package1.0/Makefile
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/Makefile	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/Makefile	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,6 +1,6 @@
 INSTALLDIR=	${DESTDIR}${datadir}/macports/Tcl/package1.0
 
-SRCS=	package.tcl portdmg.tcl portmdmg.tcl portmpkg.tcl portpkg.tcl portportpkg.tcl \
+SRCS=	package.tcl portdmg.tcl portmdmg.tcl portmpkg.tcl portpkg.tcl \
 	portrpm.tcl portsrpm.tcl portdpkg.tcl portunarchive.tcl \
 	portarchivefetch.tcl
 

Modified: branches/gsoc11-statistics/base/src/package1.0/package.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/package.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/package.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -40,6 +40,5 @@
 package require portdmg 1.0
 package require portmdmg 1.0
 package require portdpkg 1.0
-package require portportpkg 1.0
 package require portarchivefetch 1.0
 package require portunarchive 1.0

Modified: branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portarchivefetch.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # $Id$
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
-# Copyright (c) 2004 - 2011 The MacPorts Project
+# Copyright (c) 2004 - 2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -36,7 +36,7 @@
 package require Pextlib 1.0
 
 set org.macports.archivefetch [target_new org.macports.archivefetch portarchivefetch::archivefetch_main]
-target_init ${org.macports.archivefetch} portarchivefetch::archivefetch_init
+#target_init ${org.macports.archivefetch} portarchivefetch::archivefetch_init
 target_provides ${org.macports.archivefetch} archivefetch
 target_requires ${org.macports.archivefetch} main
 target_prerun ${org.macports.archivefetch} portarchivefetch::archivefetch_start
@@ -65,19 +65,46 @@
 default archive.subdir {${subport}}
 
 proc portarchivefetch::filter_sites {} {
-    global prefix porturl
+    global prefix frameworks_dir applications_dir porturl \
+        portfetch::mirror_sites::sites portfetch::mirror_sites::archive_type \
+        portfetch::mirror_sites::archive_prefix \
+        portfetch::mirror_sites::archive_frameworks_dir \
+        portfetch::mirror_sites::archive_applications_dir
+
+    # get defaults from ports tree resources
     set mirrorfile [get_full_archive_sites_path]
     if {[file exists $mirrorfile]} {
         source $mirrorfile
     }
+    # get archive_sites.conf values
+    foreach {key val} [get_archive_sites_conf_values] {
+        set $key $val
+    }
+
     set ret {}
     foreach site [array names portfetch::mirror_sites::archive_prefix] {
-        if {$portfetch::mirror_sites::archive_prefix($site) == $prefix} {
-            lappend ret $site
+        set missing 0
+        foreach var {archive_frameworks_dir archive_applications_dir archive_type} {
+            if {![info exists portfetch::mirror_sites::${var}($site)]} {
+                ui_warn "no $var configured for site '$site'"
+                set missing 1
+            }
         }
+        if {$missing} {
+            continue
+        }
+        if {$portfetch::mirror_sites::archive_prefix($site) == $prefix &&
+            $portfetch::mirror_sites::archive_frameworks_dir($site) == $frameworks_dir &&
+            $portfetch::mirror_sites::archive_applications_dir($site) == $applications_dir &&
+            ![catch {archiveTypeIsSupported $portfetch::mirror_sites::archive_type($site)}]} {
+            # using the archive type as a tag
+            lappend ret ${site}::$portfetch::mirror_sites::archive_type($site)
+        }
     }
-    if {[file rootname [file tail $porturl]] == [file rootname [file tail [get_portimage_path]]]} {
-        lappend ret [string range $porturl 0 end-[string length [file tail $porturl]]]
+
+    # check if porturl itself points to an archive
+    if {[file rootname [file tail $porturl]] == [file rootname [get_portimage_name]] && [file extension $porturl] != ""} {
+        lappend ret [string range $porturl 0 end-[string length [file tail $porturl]]]:[string range [file extension $porturl] 1 end]
         archive.subdir
     }
     return $ret
@@ -87,21 +114,22 @@
 
 # Checks possible archive files to assemble url lists for later fetching
 proc portarchivefetch::checkarchivefiles {urls} {
-    global all_archive_files archivefetch.fulldestpath portarchivetype \
-           version revision portvariants archive_sites
+    global all_archive_files archivefetch.fulldestpath archive_sites
     upvar $urls fetch_urls
 
     # Define archive directory path
-    set archive.path [get_portimage_path]
-    set archivefetch.fulldestpath [file dirname ${archive.path}]
+    set archivefetch.fulldestpath [file join [option portdbpath] incoming/verified]
+    set archive.rootname [file rootname [get_portimage_name]]
 
-    # throws an error if unsupported
-    archiveTypeIsSupported $portarchivetype
-
-    set archive.file [file tail ${archive.path}]
-    lappend all_archive_files ${archive.file}
-    if {[info exists archive_sites]} {
-        lappend fetch_urls archive_sites ${archive.file}
+    foreach entry [option archive_sites] {
+        # the archive type is used as a tag
+        set type [lindex [split $entry :] end]
+        if {![info exists seen($type)]} {
+            set archive.file "${archive.rootname}.${type}"
+            lappend all_archive_files ${archive.file}
+            lappend fetch_urls $type ${archive.file}
+            set seen($type) 1
+        }
     }
 }
 
@@ -141,16 +169,6 @@
         }
     }
     set incoming_path [file join [option portdbpath] incoming]
-    if {![file isdirectory $incoming_path]} {
-        if {[catch {file mkdir $incoming_path} result]} {
-            elevateToRoot "archivefetch"
-            set elevated yes
-            if {[catch {file mkdir $incoming_path} result]} {
-                return -code error [format [msgcat::mc "Unable to create archive fetch path: %s"] $result]
-            }
-        }
-    }
-    chownAsRoot ${archivefetch.fulldestpath}
     chownAsRoot $incoming_path
     if {[info exists elevated] && $elevated == yes} {
         dropPrivileges
@@ -172,8 +190,10 @@
     }
     set sorted no
 
+    set existing_archive [find_portarchive_path]
+
     foreach {url_var archive} $archivefetch_urls {
-        if {![file isfile ${archivefetch.fulldestpath}/${archive}]} {
+        if {![file isfile ${archivefetch.fulldestpath}/${archive}] && $existing_archive == ""} {
             ui_info "$UI_PREFIX [format [msgcat::mc "%s doesn't seem to exist in %s"] $archive ${archivefetch.fulldestpath}]"
             if {![file writable ${archivefetch.fulldestpath}]} {
                 return -code error [format [msgcat::mc "%s must be writable"] ${archivefetch.fulldestpath}]
@@ -189,6 +209,7 @@
                 ui_error [format [msgcat::mc "No defined site for tag: %s, using archive_sites"] $url_var]
                 set urlmap($url_var) $urlmap(archive_sites)
             }
+            set failed_sites 0
             unset -nocomplain fetched
             foreach site $urlmap($url_var) {
                 if {[string index $site end] != "/"} {
@@ -206,6 +227,10 @@
                 } else {
                     ui_debug "[msgcat::mc "Fetching archive failed:"]: $result"
                     file delete -force "${incoming_path}/${archive}.TMP"
+                    incr failed_sites
+                    if {$failed_sites > 2 && ![tbool ports_binary_only] && ![_archive_available]} {
+                        break
+                    }
                 }
             }
             if {[info exists fetched]} {
@@ -228,18 +253,22 @@
                         ui_debug "openssl output: $result"
                     }
                 }
+                file delete -force $signature
                 if {!$verified} {
-                    return -code error "Failed to verify signature for archive!"
-                }
-                if {[catch {file rename -force "${incoming_path}/${archive}.TMP" "${archivefetch.fulldestpath}/${archive}"} result]} {
+                    # fall back to building from source (or error out later if binary only mode)
+                    ui_warn "Failed to verify signature for archive!"
+                    file delete -force "${incoming_path}/${archive}.TMP"
+                    break
+                } elseif {[catch {file rename -force "${incoming_path}/${archive}.TMP" "${archivefetch.fulldestpath}/${archive}"} result]} {
                     ui_debug "$::errorInfo"
                     return -code error "Failed to move downloaded archive into place: $result"
                 }
-                file delete -force $signature
                 set archive_exists 1
+                break
             }
         } else {
             set archive_exists 1
+            break
         }
     }
     if {[info exists archive_exists]} {
@@ -258,24 +287,22 @@
 }
 
 # Initialize archivefetch target and call checkfiles.
-proc portarchivefetch::archivefetch_init {args} {
-    global porturl portarchivetype
-    # installing straight from a binary archive
-    if {[file rootname [file tail $porturl]] == [file rootname [file tail [get_portimage_path]]] && [file extension $porturl] != ""} {
-        set portarchivetype [string range [file extension $porturl] 1 end]
-    }
-    return 0
-}
+#proc portarchivefetch::archivefetch_init {args} {
+#    return 0
+#}
 
 proc portarchivefetch::archivefetch_start {args} {
     variable archivefetch_urls
-    global UI_PREFIX subport all_archive_files ports_source_only
-    if {![tbool ports_source_only]} {
+    global UI_PREFIX subport all_archive_files destroot target_state_fd \
+           ports_source_only ports_binary_only
+    if {![tbool ports_source_only] && ([tbool ports_binary_only] ||
+            !([check_statefile target org.macports.destroot $target_state_fd] && [file isdirectory $destroot]))} {
         portarchivefetch::checkfiles archivefetch_urls
     }
     if {[info exists all_archive_files] && [llength $all_archive_files] > 0} {
         ui_msg "$UI_PREFIX [format [msgcat::mc "Fetching archive for %s"] $subport]"
     }
+    portfetch::check_dns
 }
 
 # Main archive fetch routine

Modified: branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portdmg.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,7 @@
 
 set org.macports.dmg [target_new org.macports.dmg portdmg::dmg_main]
 target_runtype ${org.macports.dmg} always
-target_provides ${org.macports.dmg} dmg 
+target_provides ${org.macports.dmg} dmg
 target_requires ${org.macports.dmg} pkg
 
 namespace eval portdmg {
@@ -50,7 +50,7 @@
     ui_msg "$UI_PREFIX [format [msgcat::mc "Creating disk image for %s-%s"] ${subport} ${version}]"
 
     if {[getuid] == 0 && [geteuid] != 0} {
-		setegid 0; seteuid 0
+		seteuid 0; setegid 0
 	}
 
     return [package_dmg $subport $version $revision]
@@ -59,17 +59,17 @@
 proc portdmg::package_dmg {portname portversion portrevision} {
     global UI_PREFIX package.destpath portpath
     global os.platform os.arch os.version os.major
-    
+
     if {[expr (${portrevision} > 0)]} {
         set imagename "${portname}-${portversion}-${portrevision}"
     } else {
         set imagename "${portname}-${portversion}"
     }
-    
+
     set tmp_image ${package.destpath}/${imagename}.tmp.dmg
     set final_image ${package.destpath}/${imagename}.dmg
     set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
-    
+
     if {[file readable $final_image] && ([file mtime ${final_image}] >= [file mtime ${portpath}/Portfile])} {
         ui_msg "$UI_PREFIX [format [msgcat::mc "Disk Image for %s-%s is up-to-date"] ${portname} ${portversion}]"
         return 0
@@ -83,7 +83,13 @@
         # Apple_partition_scheme (Apple_partition_map is at s1)
         set subdev 2
     }
-    
+
+    if {![file isdirectory $pkgpath]} {
+        file mkdir ${package.destpath}/${imagename}
+        file copy $pkgpath ${package.destpath}/${imagename}
+        set pkgpath ${package.destpath}/${imagename}
+    }
+
     set hdiutil [findBinary hdiutil $portutil::autoconf::hdiutil_path]
     if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${pkgpath} ${tmp_image}"] != ""} {
         return -code error [format [msgcat::mc "Failed to create temporary image: %s"] ${imagename}]
@@ -95,6 +101,6 @@
         return -code error [format [msgcat::mc "Failed to internet-enable: %s"] ${final_image}]
     }
     file delete -force "${tmp_image}"
-    
+
     return 0
 }

Modified: branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portdpkg.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -18,7 +18,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -54,7 +54,7 @@
 
 proc portdpkg::main {args} {
 	global UI_PREFIX destpath os.arch os.platform supported_archs configure.build_arch
-    
+
 	ui_msg "$UI_PREFIX [format [msgcat::mc "Creating dpkg for %s-%s"] [option subport] [option version]]"
 
 	# get deplist
@@ -95,7 +95,7 @@
 			set pkg_depends [join ${dependencies} ", "]
 		}
 	}
-	
+
 	# Create dpkg version number
 	if {[expr [option epoch] != 0]} {
 		set pkg_version "[option epoch]:[option version]"
@@ -125,11 +125,11 @@
 
 	# Discern correct architecture
 	# From http://www.debian.org/doc/debian-policy/ch-customized-programs.html#fr55:
-	# The following architectures and operating systems are currently recognised   
-	# by dpkg-archictecture. The architecture, arch, is one of the following:      
-	# alpha, arm, hppa, i386, ia64, m68k, mips, mipsel, powerpc, s390, sh, sheb,   
-	# sparc and sparc64. The operating system, os, is one of: linux, gnu,          
-	# freebsd and openbsd. Use of gnu in this string is reserved for the           
+	# The following architectures and operating systems are currently recognised
+	# by dpkg-archictecture. The architecture, arch, is one of the following:
+	# alpha, arm, hppa, i386, ia64, m68k, mips, mipsel, powerpc, s390, sh, sheb,
+	# sparc and sparc64. The operating system, os, is one of: linux, gnu,
+	# freebsd and openbsd. Use of gnu in this string is reserved for the
 	# GNU/Hurd operating system.
 	switch -regex ${configure.build_arch} {
 		i[3-9]86 { set pkg_arch "i386" }
@@ -144,7 +144,7 @@
 	} elseif {${pkg_arch} == "x86_64"} {
 		set pkg_arch "amd64"
 	}
-	
+
 	# An architecture-independent package
 	if {$supported_archs == "noarch"} {
 		set pkg_arch "all"
@@ -182,7 +182,7 @@
 	}
 	foreach {name array} $res {
 		array set portinfo $array
-	
+
 		if {[info exists portinfo(depends_run)] || [info exists portinfo(depends_lib)]} {
 			# get the union of depends_run and depends_lib
 			# xxx: only examines the portfile component of the depspec

Modified: branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portmdmg.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -36,7 +36,7 @@
 
 set org.macports.mdmg [target_new org.macports.mdmg portmdmg::mdmg_main]
 target_runtype ${org.macports.mdmg} always
-target_provides ${org.macports.mdmg} mdmg 
+target_provides ${org.macports.mdmg} mdmg
 target_requires ${org.macports.mdmg} mpkg
 
 namespace eval portmdmg {
@@ -45,31 +45,31 @@
 set_ui_prefix
 
 proc portmdmg::mdmg_main {args} {
-    global subport version revision package.destpath UI_PREFIX
+    global subport epoch version revision package.destpath UI_PREFIX
 
     ui_msg "$UI_PREFIX [format [msgcat::mc "Creating disk image for %s-%s"] ${subport} ${version}]"
 
     if {[getuid] == 0 && [geteuid] != 0} {
-		setegid 0; seteuid 0
+		seteuid 0; setegid 0
 	}
 
-    return [package_mdmg $subport $version $revision]
+    return [package_mdmg $subport $epoch $version $revision]
 }
 
-proc portmdmg::package_mdmg {portname portversion portrevision} {
+proc portmdmg::package_mdmg {portname portepoch portversion portrevision} {
     global UI_PREFIX package.destpath portpath
     global os.platform os.arch os.version os.major
-    
+
     if {[expr (${portrevision} > 0)]} {
         set imagename "${portname}-${portversion}-${portrevision}"
     } else {
         set imagename "${portname}-${portversion}"
     }
-    
+
     set tmp_image ${package.destpath}/${imagename}.tmp.dmg
     set final_image ${package.destpath}/${imagename}.dmg
-    set mpkgpath ${package.destpath}/${portname}-${portversion}.mpkg
-    
+    set mpkgpath [portmpkg::mpkg_path $portname $portepoch $portversion $portrevision]
+
     if {[file readable $final_image] && ([file mtime ${final_image}] >= [file mtime ${portpath}/Portfile])} {
         ui_msg "$UI_PREFIX [format [msgcat::mc "Disk Image for %s-%s is up-to-date"] ${portname} ${portversion}]"
         return 0
@@ -84,6 +84,12 @@
         set subdev 2
     }
 
+    if {![file isdirectory $mpkgpath]} {
+        file mkdir ${package.destpath}/${imagename}
+        file copy $mpkgpath ${package.destpath}/${imagename}
+        set mpkgpath ${package.destpath}/${imagename}
+    }
+
     set hdiutil [findBinary hdiutil $portutil::autoconf::hdiutil_path]
     if {[system "$hdiutil create -quiet -fs HFS+ -volname ${imagename} -srcfolder ${mpkgpath} ${tmp_image}"] != ""} {
         return -code error [format [msgcat::mc "Failed to create temporary image: %s"] ${imagename}]
@@ -95,6 +101,6 @@
         return -code error [format [msgcat::mc "Failed to internet-enable: %s"] ${final_image}]
     }
     file delete -force "${tmp_image}"
-    
+
     return 0
 }

Modified: branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portmpkg.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portmpkg.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007 - 2011 The MacPorts Project
+# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
 # Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -48,36 +48,38 @@
 set_ui_prefix
 
 proc portmpkg::mpkg_main {args} {
-    global subport version revision package.destpath package.flat UI_PREFIX
+    global subport epoch version revision os.major package.destpath package.flat UI_PREFIX
 
-    # Make sure the destination path exists.
-    file mkdir ${package.destpath}
+    if {!${package.flat} || ${os.major} < 10} {
+        # Make sure the destination path exists.
+        file mkdir ${package.destpath}
+    }
 
-    return [package_mpkg $subport $version $revision]
+    return [package_mpkg $subport $epoch $version $revision]
 }
 
 proc portmpkg::make_dependency_list {portname destination} {
-    global variations prefix package.destpath package.flat
-	set result {}
-	if {[catch {set res [mport_lookup $portname]} error]} {
-		global errorInfo
-		ui_debug "$errorInfo"
-		return -code error "port lookup failed: $error"
-	}
-	array set portinfo [lindex $res 1]
+    global requested_variations prefix package.destpath package.flat
+    set result {}
+    if {[catch {set res [mport_lookup $portname]} error]} {
+        global errorInfo
+        ui_debug "$errorInfo"
+        return -code error "port lookup failed: $error"
+    }
+    array set portinfo [lindex $res 1]
 
-	if {[getuid] == 0 && [geteuid] != 0} {
-		setegid 0; seteuid 0
-		set deprivileged 1
-	}
+    if {[getuid] == 0 && [geteuid] != 0} {
+        seteuid 0; setegid 0
+        set deprivileged 1
+    }
 
-	set mport [mport_open $portinfo(porturl) [list prefix $prefix package.destpath ${destination} package.flat ${package.flat} subport $portinfo(name)] [array get variations]]
+    set mport [mport_open $portinfo(porturl) [list prefix $prefix package.destpath ${destination} package.flat ${package.flat} subport $portinfo(name)] [array get requested_variations]]
 
     if {[info exists deprivileged]} {
-	    global macportsuser
-		setegid [uname_to_gid "$macportsuser"]
-		seteuid [name_to_uid "$macportsuser"]
-	}
+        global macportsuser
+        setegid [uname_to_gid "$macportsuser"]
+        seteuid [name_to_uid "$macportsuser"]
+    }
 
     unset portinfo
     array set portinfo [mport_info $mport]
@@ -94,58 +96,116 @@
         }
     }
 
-    lappend result [list $portinfo(name) $portinfo(version) $mport]
-	ui_debug "dependencies for ${portname}: $result"
-	return $result
+    lappend result [list $portinfo(name) $portinfo(epoch) $portinfo(version) $portinfo(revision) $mport]
+    return $result
 }
 
-proc portmpkg::make_one_package {portname portversion mport} {
-	if {[getuid] == 0 && [geteuid] != 0} {
-		setegid 0; seteuid 0
-		set deprivileged 1
-	}
+proc portmpkg::make_one_package {portname mport} {
+    if {[getuid] == 0 && [geteuid] != 0} {
+        seteuid 0; setegid 0
+        set deprivileged 1
+    }
 
     ui_debug "building dependency package: $portname"
-    mport_exec $mport pkg
+    set result [mport_exec $mport pkg]
     mport_close $mport
+    if {$result} {
+        error "Processing of port $portname failed"
+    }
 
-	if {[info exists deprivileged]} {
-	    global macportsuser
-		setegid [uname_to_gid "$macportsuser"]
-		seteuid [name_to_uid "$macportsuser"]
-	}
+    if {[info exists deprivileged]} {
+        global macportsuser
+        setegid [uname_to_gid "$macportsuser"]
+        seteuid [name_to_uid "$macportsuser"]
+    }
 }
 
-proc portmpkg::package_mpkg {portname portversion portrevision} {
-    global portdbpath destpath workpath prefix porturl description package.destpath package.flat long_description homepage depends_run depends_lib
+proc portmpkg::epoch_namestr {portepoch} {
+    set portepoch_namestr ""
+    if {${portepoch} != "0"} {
+        set portepoch_namestr "${portepoch}_"
+    }
+    return ${portepoch_namestr}
+}
 
-	set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
-	set mpkgpath ${package.destpath}/${portname}-${portversion}.mpkg
-	system "mkdir -p -m 0755 ${mpkgpath}/Contents/Resources"
-	system "mkdir -p -m 0755 ${mpkgpath}/Contents/Packages"
+proc portmpkg::revision_namestr {portrevision} {
+    set portrevision_namestr ""
+    if {${portrevision} != "0"} {
+        set portrevision_namestr "_${portrevision}"
+    }
+    return ${portrevision_namestr}
+}
 
-	set dependencies {}
-	# get deplist
-	set deps [make_dependency_list $portname ${mpkgpath}/Contents/Packages]
-	set deps [lsort -unique $deps]
-	foreach dep $deps {
-		set name [lindex $dep 0]
-		set vers [lindex $dep 1]
-		set mport [lindex $dep 2]
-		# don't re-package ourself
-		if {$name != $portname} {
-			make_one_package $name $vers $mport
-			lappend dependencies ${name}-${vers}.pkg
-		}
-	}
+proc portmpkg::mpkg_path {portname portepoch portversion portrevision} {
+    global package.destpath
+    set portepoch_namestr [portmpkg::epoch_namestr ${portepoch}]
+    set portrevision_namestr [portmpkg::revision_namestr ${portrevision}]
+    set mpkgpath ${package.destpath}/${portname}-${portepoch_namestr}${portversion}${portrevision_namestr}.mpkg
+    return $mpkgpath
+}
 
-	# copy our own pkg into the mpkg
-	system "cp -PR ${pkgpath} ${mpkgpath}/Contents/Packages/"
-	lappend dependencies ${portname}-${portversion}.pkg
-	
-    portpkg::write_PkgInfo ${mpkgpath}/Contents/PkgInfo
-    mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $portrevision $prefix $dependencies
-    portpkg::write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
+proc portmpkg::package_mpkg {portname portepoch portversion portrevision} {
+    global portdbpath os.major destpath workpath prefix porturl description package.destpath package.flat long_description homepage depends_run depends_lib
+
+    set mpkgpath [portmpkg::mpkg_path $portname $portepoch $portversion $portrevision]
+
+    set portepoch_namestr [portmpkg::epoch_namestr ${portepoch}]
+    set portrevision_namestr [portmpkg::revision_namestr ${portrevision}]
+    if {${package.flat} && ${os.major} >= 10} {
+        set pkgpath ${package.destpath}/${portname}-${portepoch_namestr}${portversion}${portrevision_namestr}-component.pkg
+        set packages_path ${workpath}/mpkg_packages
+        set resources_path ${workpath}/mpkg_resources
+    } else {
+        set pkgpath ${package.destpath}/${portname}-${portepoch_namestr}${portversion}${portrevision_namestr}.pkg
+        set packages_path ${mpkgpath}/Contents/Packages
+        set resources_path ${mpkgpath}/Contents/Resources
+    }
+    system "mkdir -p -m 0755 ${packages_path}"
+    system "mkdir -p -m 0755 ${resources_path}"
+
+    set dependencies {}
+    # get deplist
+    set deps [make_dependency_list $portname $packages_path]
+    set deps [lsort -unique $deps]
+    foreach dep $deps {
+        set name [lindex $dep 0]
+        set epoch [lindex $dep 1]
+        set epoch_namestr ""
+        if {$epoch != "0"} {
+            set epoch_namestr "${epoch}_"
+        }
+        set vers [lindex $dep 2]
+        set rev [lindex $dep 3]
+        set rev_namestr ""
+        if {$rev != "0"} {
+            set rev_namestr "_${rev}"
+        }
+        set mport [lindex $dep 4]
+        # don't re-package ourself
+        if {$name != $portname} {
+            make_one_package $name $mport
+            if {${package.flat} && ${os.major} >= 10} {
+                lappend dependencies org.macports.${name} ${name}-${epoch_namestr}${vers}${rev_namestr}-component.pkg
+            } else {
+                lappend dependencies ${name}-${epoch_namestr}${vers}${rev_namestr}.pkg
+            }
+        }
+    }
+    if {${package.flat} && ${os.major} >= 10} {
+        lappend dependencies org.macports.${portname} ${portname}-${portepoch_namestr}${portversion}${portrevision_namestr}-component.pkg
+    } else {
+        lappend dependencies ${portname}-${portepoch_namestr}${portversion}${portrevision_namestr}.pkg
+    }
+
+    # copy our own pkg into the mpkg
+    system "cp -PR ${pkgpath} ${packages_path}"
+
+    if {!${package.flat} || ${os.major} < 10} {
+        portpkg::write_PkgInfo ${mpkgpath}/Contents/PkgInfo
+        mpkg_write_info_plist ${mpkgpath}/Contents/Info.plist $portname $portversion $portrevision $prefix $dependencies
+        portpkg::write_description_plist ${mpkgpath}/Contents/Resources/Description.plist $portname $portversion $description
+        set resources_path ${mpkgpath}/Contents/Resources
+    }
     # long_description, description, or homepage may not exist
     foreach variable {long_description description homepage} {
         if {![info exists $variable]} {
@@ -154,68 +214,110 @@
             set pkg_$variable [set $variable]
         }
     }
-    portpkg::write_welcome_html ${mpkgpath}/Contents/Resources/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
-    file copy -force -- [getportresourcepath $porturl "port1.0/package/background.tiff"] ${mpkgpath}/Contents/Resources/background.tiff
+    portpkg::write_welcome_html ${resources_path}/Welcome.html $portname $portepoch $portversion $portrevision $pkg_long_description $pkg_description $pkg_homepage
+    file copy -force -- [getportresourcepath $porturl "port1.0/package/background.tiff"] ${resources_path}/background.tiff
 
-	return 0
+    if {${package.flat} && ${os.major} >= 10} {
+        write_distribution ${workpath}/Distribution $portname $dependencies
+        set productbuild [findBinary productbuild]
+        set v [portpkg::mp_version_to_apple_version $portepoch $portversion $portrevision]
+        set cmdline "$productbuild --resources ${resources_path} --identifier org.macports.mpkg.${portname} --distribution ${workpath}/Distribution --package-path ${packages_path} --version ${v} ${mpkgpath}"
+        ui_debug "Running command line: $cmdline"
+        system $cmdline
+    }
+
+    return 0
 }
 
+proc portmpkg::write_distribution {dfile portname dependencies} {
+    global macosx_deployment_target
+    set portname [xml_escape $portname]
+    set dfd [open $dfile w+]
+    puts $dfd "<?xml version=\"1.0\" encoding=\"utf-8\"?>
+<installer-gui-script minSpecVersion=\"1\">
+    <title>${portname}</title>
+    <options customize=\"never\"/>
+    <allowed-os-versions><os-version min=\"${macosx_deployment_target}\"/></allowed-os-versions>
+    <background file=\"background.tiff\" mime-type=\"image/tiff\" alignment=\"bottomleft\" scaling=\"none\"/>
+    <welcome mime-type=\"text/html\" file=\"Welcome.html\"/>
+    <choices-outline>
+    <line choice=\"default\">
+        <line choice=\"org.macports.mpkg.${portname}\"/>
+    </line>
+    </choices-outline>
+    <choice id=\"default\"/>
+    <choice id=\"org.macports.mpkg.${portname}\" visible=\"false\">
+"
+    foreach {identifier package} $dependencies {
+        set id [xml_escape $identifier]
+        set pkg [xml_escape $package]
+        puts $dfd "        <pkg-ref id=\"${id}\"/>"
+        lappend pkgrefs "<pkg-ref id=\"${id}\">${pkg}</pkg-ref>"
+    }
+    puts $dfd "    </choice>"
+    foreach pkgref $pkgrefs {
+        puts $dfd "    $pkgref"
+    }
+    puts $dfd "</installer-gui-script>"
+    close $dfd
+}
+
 proc portmpkg::xml_escape {s} {
-	regsub -all {&} $s {\&amp;} s
-	regsub -all {<} $s {\&lt;} s
-	regsub -all {>} $s {\&gt;} s
-	return $s
+    regsub -all {&} $s {\&amp;} s
+    regsub -all {<} $s {\&lt;} s
+    regsub -all {>} $s {\&gt;} s
+    return $s
 }
 
 proc portmpkg::mpkg_write_info_plist {infofile portname portversion portrevision destination dependencies} {
-	set vers [split $portversion "."]
-	
-	if {[string index $destination end] != "/"} {
-		append destination /
-	}
-	
-	set depxml ""
-	foreach dep $dependencies {
-		set dep [xml_escape $dep]
-		append depxml "<dict>
-			<key>IFPkgFlagPackageLocation</key>
-			<string>${dep}</string>
-			<key>IFPkgFlagPackageSelection</key>
-			<string>selected</string>
-		</dict>
-		"
-	}
+    set vers [split $portversion "."]
 
-	set portname [xml_escape $portname]
-	set portversion [xml_escape $portversion]
-	set portrevision [xml_escape $portrevision]
+    if {[string index $destination end] != "/"} {
+        append destination /
+    }
 
-	set infofd [open ${infofile} w+]
-	puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
+    set depxml ""
+    foreach dep $dependencies {
+        set dep [xml_escape $dep]
+        append depxml "<dict>
+            <key>IFPkgFlagPackageLocation</key>
+            <string>${dep}</string>
+            <key>IFPkgFlagPackageSelection</key>
+            <string>selected</string>
+        </dict>
+        "
+    }
+
+    set portname [xml_escape $portname]
+    set portversion [xml_escape $portversion]
+    set portrevision [xml_escape $portrevision]
+
+    set infofd [open ${infofile} w+]
+    puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 }
-	puts $infofd "<dict>
-	<key>CFBundleGetInfoString</key>
-	<string>${portname} ${portversion}</string>
-	<key>CFBundleIdentifier</key>
-	<string>org.macports.mpkg.${portname}</string>
-	<key>CFBundleName</key>
-	<string>${portname}</string>
-	<key>CFBundleShortVersionString</key>
-	<string>${portversion}</string>
-	<key>IFMajorVersion</key>
-	<integer>${portrevision}</integer>
-	<key>IFMinorVersion</key>
-	<integer>0</integer>
-	<key>IFPkgFlagComponentDirectory</key>
-	<string>./Contents/Packages</string>
-	<key>IFPkgFlagPackageList</key>
-	<array>
-		${depxml}</array>
-	<key>IFPkgFormatVersion</key>
-	<real>0.10000000149011612</real>
+    puts $infofd "<dict>
+    <key>CFBundleGetInfoString</key>
+    <string>${portname} ${portversion}</string>
+    <key>CFBundleIdentifier</key>
+    <string>org.macports.mpkg.${portname}</string>
+    <key>CFBundleName</key>
+    <string>${portname}</string>
+    <key>CFBundleShortVersionString</key>
+    <string>${portversion}</string>
+    <key>IFMajorVersion</key>
+    <integer>${portrevision}</integer>
+    <key>IFMinorVersion</key>
+    <integer>0</integer>
+    <key>IFPkgFlagComponentDirectory</key>
+    <string>./Contents/Packages</string>
+    <key>IFPkgFlagPackageList</key>
+    <array>
+        ${depxml}</array>
+    <key>IFPkgFormatVersion</key>
+    <real>0.10000000149011612</real>
 </dict>
 </plist>"
-	close $infofd
+    close $infofd
 }

Modified: branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portpkg.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portpkg.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007 - 2011 The MacPorts Project
+# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -38,64 +38,96 @@
 target_runtype ${org.macports.pkg} always
 target_provides ${org.macports.pkg} pkg
 target_requires ${org.macports.pkg} archivefetch unarchive destroot
+target_prerun ${org.macports.pkg} portpkg::pkg_start
 
 namespace eval portpkg {
 }
 
 # define options
-options package.type package.destpath package.flat
+options package.type package.destpath package.flat package.resources package.scripts
 
 # Set defaults
 default package.destpath {${workpath}}
-default package.flat     false
+default package.resources {${workpath}/pkg_resources}
+default package.scripts  {${workpath}/pkg_scripts}
+# Need productbuild to make flat packages really work
+default package.flat     {[expr [vercmp $macosx_deployment_target 10.6] >= 0]}
 
 set_ui_prefix
 
+proc portpkg::pkg_start {args} {
+    global packagemaker_path portpkg::packagemaker \
+           portpkg::language xcodeversion portpath porturl \
+           package.resources package.scripts package.flat \
+           subport epoch version revision description long_description \
+           homepage workpath os.major
+
+    if {![info exists packagemaker_path]} {
+        if {[vercmp $xcodeversion 4.3] >= 0} {
+            set packagemaker_path /Applications/PackageMaker.app
+            if {![file exists $packagemaker_path]} {
+                ui_warn "PackageMaker.app not found; you may need to install it or set packagemaker_path in macports.conf"
+            }
+        } else {
+            set packagemaker_path "[option developer_dir]/Applications/Utilities/PackageMaker.app"
+        }
+    }
+    set packagemaker "${packagemaker_path}/Contents/MacOS/PackageMaker"
+
+    set language "English"
+    file mkdir "${package.resources}/${language}.lproj"
+    file attributes "${package.resources}/${language}.lproj" -permissions 0755
+    file mkdir ${package.scripts}
+    file attributes ${package.scripts} -permissions 0755
+
+    # long_description, description, or homepage may not exist
+    foreach variable {long_description description homepage} {
+        if {![info exists $variable]} {
+            set pkg_$variable ""
+        } else {
+            set pkg_$variable [set $variable]
+        }
+    }
+    write_welcome_html ${package.resources}/${language}.lproj/Welcome.html $subport $epoch $version $revision $pkg_long_description $pkg_description $pkg_homepage
+    file copy -force -- [getportresourcepath $porturl "port1.0/package/background.tiff"] ${package.resources}/${language}.lproj/background.tiff
+
+    if {${package.flat} && ${os.major} >= 9} {
+        write_distribution "${workpath}/Distribution" $subport $epoch $version $revision
+    }
+}
+
 proc portpkg::pkg_main {args} {
-    global subport version revision package.type package.destpath package.flat UI_PREFIX
+    global subport epoch version revision UI_PREFIX
 
-    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating pkg for %s-%s"] ${subport} ${version}]"
+    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating pkg for %s-%s_%s_%s"] ${subport} ${epoch} ${version} ${revision}]"
 
     if {[getuid] == 0 && [geteuid] != 0} {
         elevateToRoot "pkg"
     }
 
-    return [package_pkg $subport $version $revision]
+    return [package_pkg $subport $epoch $version $revision]
 }
 
-proc portpkg::package_pkg {portname portversion portrevision} {
-    global UI_PREFIX portdbpath destpath workpath prefix description package.destpath package.flat long_description homepage portpath porturl
-    global os.version os.major
+proc portpkg::package_pkg {portname portepoch portversion portrevision} {
+    global UI_PREFIX portdbpath destpath workpath prefix description \
+    package.flat package.destpath portpath os.version os.major \
+    package.resources package.scripts portpkg::packagemaker portpkg::language
 
-    set pkgpath ${package.destpath}/${portname}-${portversion}.pkg
+    set portepoch_namestr ""
+    if {${portepoch} != "0"} {
+        set portepoch_namestr "${portepoch}_"
+    }
+    set portrevision_namestr ""
+    if {${portrevision} != "0"} {
+        set portrevision_namestr "_${portrevision}"
+    }
 
+    set pkgpath "${package.destpath}/${portname}-${portepoch_namestr}${portversion}${portrevision_namestr}.pkg"
     if {[file readable $pkgpath] && ([file mtime ${pkgpath}] >= [file mtime ${portpath}/Portfile])} {
-        ui_msg "$UI_PREFIX [format [msgcat::mc "Package for %s-%s is up-to-date"] ${portname} ${portversion}]"
+        ui_msg "$UI_PREFIX [format [msgcat::mc "Package for %s-%s_%s_%s is up-to-date"] ${portname} ${portepoch} ${portversion} ${portrevision}]"
         return 0
     }
 
-    set packagemaker "[option developer_dir]/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker"
-    if ([file exists "$packagemaker"]) {
-        set resourcepath ${workpath}/pkg_resources
-    } else {
-        set resourcepath "${pkgpath}/Contents/Resources"
-    }
-
-    set language "English"
-    file mkdir "${resourcepath}/${language}.lproj"
-    file attributes "${resourcepath}/${language}.lproj" -permissions 0755
-	
-    # long_description, description, or homepage may not exist
-    foreach variable {long_description description homepage} {
-        if {![info exists $variable]} {
-            set pkg_$variable ""
-        } else {
-            set pkg_$variable [set $variable]
-        }
-    }
-    write_welcome_html ${resourcepath}/${language}.lproj/Welcome.html $portname $portversion $pkg_long_description $pkg_description $pkg_homepage
-    file copy -force -- [getportresourcepath $porturl "port1.0/package/background.tiff"] ${resourcepath}/${language}.lproj/background.tiff
-
     foreach dir {etc var tmp} {
         if ([file exists "${destpath}/$dir"]) {
             # certain toplevel directories really are symlinks. leaving them as directories make pax lose the symlinks. that's bad.
@@ -111,42 +143,65 @@
         if {${os.major} >= 9} {
             if {${package.flat}} {
                 set pkgtarget "10.5"
-                set pkgresources ""
+                set pkgresources " --scripts ${package.scripts}"
                 set infofile "${workpath}/PackageInfo"
-                write_package_info ${workpath}/PackageInfo $portname $portversion $portrevision
+                write_package_info $infofile
             } else {
                 set pkgtarget "10.3"
-                set pkgresources " --resources ${resourcepath} --title \"$portname-$portversion\""
+                set pkgresources " --resources ${package.resources} --title \"$portname-$portversion\""
                 set infofile "${workpath}/Info.plist"
-                write_info_plist ${workpath}/Info.plist $portname $portversion $portrevision
+                write_info_plist $infofile $portname $portversion $portrevision
             }
-            set cmdline "PMResourceLocale=${language} $packagemaker -AppleLanguages \"(${language})\" --root ${destpath} --out ${pkgpath} ${pkgresources} --info $infofile --target $pkgtarget --domain system --id org.macports.$portname"
+            set cmdline "PMResourceLocale=${language} $packagemaker --root ${destpath} --out ${pkgpath} ${pkgresources} --info $infofile --target $pkgtarget --domain system --id org.macports.$portname"
             if {${os.major} >= 10} {
+                set v [mp_version_to_apple_version $portepoch $portversion $portrevision]
+                append cmdline " --version $v"
                 append cmdline " --no-relocate"
+            } else {
+                # 10.5 Leopard does not use current language, manually specify
+                append cmdline " -AppleLanguages \"(${language})\""
             }
             ui_debug "Running command line: $cmdline"
             system $cmdline
+
+            if {${package.flat} && ${os.major} >= 10} {
+                # the package we just built is just a component
+                set componentpath "[file rootname ${pkgpath}]-component.pkg"
+                file rename -force ${pkgpath} ${componentpath}
+                # Generate a distribution
+                set productbuild [findBinary productbuild]
+                set cmdline "$productbuild --resources ${package.resources} --identifier org.macports.${portname} --distribution ${workpath}/Distribution --package-path ${package.destpath} ${pkgpath}"
+                ui_debug "Running command line: $cmdline"
+                system $cmdline
+            }
         } else {
             write_info_plist ${workpath}/Info.plist $portname $portversion $portrevision
             write_description_plist ${workpath}/Description.plist $portname $portversion $description
-            system "$packagemaker -build -f ${destpath} -p ${pkgpath} -r ${resourcepath} -i ${workpath}/Info.plist -d ${workpath}/Description.plist"
+            system "$packagemaker -build -f ${destpath} -p ${pkgpath} -r ${package.resources} -i ${workpath}/Info.plist -d ${workpath}/Description.plist"
         }
 
-        file delete ${workpath}/Info.plist
-        file delete ${workpath}/PackageInfo
-        file delete ${workpath}/Description.plist
-        file delete -force ${workpath}/pkg_resources
+        file delete ${workpath}/Info.plist \
+                    ${workpath}/PackageInfo \
+                    ${workpath}/Distribution \
+                    ${workpath}/Description.plist
+        file delete -force ${package.resources} \
+                           ${package.scripts}
 
     } else {
 
+        file mkdir ${pkgpath}/Contents/Resources
+        foreach f [glob -directory ${package.resources} *] {
+            file copy -force -- $f ${pkgpath}/Contents/Resources
+        }
+
         write_PkgInfo ${pkgpath}/Contents/PkgInfo
         write_info_plist ${pkgpath}/Contents/Info.plist $portname $portversion $portrevision
 
         system "[findBinary mkbom $portutil::autoconf::mkbom_path] ${destpath} ${pkgpath}/Contents/Archive.bom"
-        system "cd ${destpath} && [findBinary pax $portutil::autoconf::pax_path] -x [findBinary cpio $portutil::autoconf::cpio_path] -w -z . > ${pkgpath}/Contents/Archive.pax.gz"
+        system "cd ${destpath} && [findBinary pax $portutil::autoconf::pax_path] -x cpio -w -z . > ${pkgpath}/Contents/Archive.pax.gz"
 
-        write_description_plist ${resourcepath}/Description.plist $portname $portversion $description
-        write_sizes_file ${resourcepath}/Archive.sizes ${portname} ${portversion} ${pkgpath} ${destpath}
+        write_description_plist ${pkgpath}/Contents/Resources/Description.plist $portname $portversion $description
+        write_sizes_file ${pkgpath}/Contents/Resources/Archive.sizes ${pkgpath} ${destpath}
 
     }
 
@@ -246,23 +301,37 @@
     close $infofd
 }
 
-proc portpkg::write_welcome_html {filename portname portversion long_description description homepage} {
+proc portpkg::write_welcome_html {filename portname portepoch portversion portrevision long_description description homepage} {
     set fd [open ${filename} w+]
     if {$long_description == ""} {
         set long_description $description
     }
 
     set portname [xml_escape $portname]
+    if {$portepoch != "0"} {
+        set portepoch [xml_escape $portepoch]
+        set portepoch_str "${portepoch}_"
+    } else {
+        set portepoch ""
+        set portepoch_str ""
+    }
     set portversion [xml_escape $portversion]
+    if {$portrevision != "0"} {
+        set portrevision [xml_escape $portrevision]
+        set portrevision_str "_${portrevision}"
+    } else {
+        set portrevision ""
+        set portrevision_str ""
+    }
     set long_description [xml_escape $long_description]
     set description [xml_escape $description]
     set homepage [xml_escape $homepage]
-	
+
     puts $fd "
 <html lang=\"en\">
 <head>
-	<meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
-	<title>Install ${portname}</title>
+    <meta http-equiv=\"content-type\" content=\"text/html; charset=iso-8859-1\">
+    <title>Install ${portname}</title>
 </head>
 <body>
 <font face=\"Helvetica\"><b>Welcome to the ${portname} for Mac OS X Installer</b></font>
@@ -274,15 +343,15 @@
         puts $fd "<font face=\"Helvetica\"><a href=\"${homepage}\">${homepage}</a></font><p>"
     }
 
-    puts $fd "<font face=\"Helvetica\">This installer guides you through the steps necessary to install ${portname} ${portversion} for Mac OS X. To get started, click Continue.</font>
+    puts $fd "<font face=\"Helvetica\">This installer guides you through the steps necessary to install ${portname} ${portepoch_str}${portversion}${portrevision_str} for Mac OS X. To get started, click Continue.</font>
 </body>
 </html>"
 
     close $fd
 }
 
-proc portpkg::write_sizes_file {sizesfile portname portversion pkgpath destpath} {
-    
+proc portpkg::write_sizes_file {sizesfile pkgpath destpath} {
+
     if {[catch {set numFiles [llength [split [exec [findBinary lsbom $portutil::autoconf::lsbom_path] -s ${pkgpath}/Contents/Archive.bom] "\n"]]} result]} {
         return -code error [format [msgcat::mc "Reading package bom failed: %s"] $result]
     }
@@ -300,7 +369,7 @@
     }
     incr installedSize $infoSize
     incr installedSize $bomSize
-	
+
     set fd [open ${sizesfile} w+]
     puts $fd "NumFiles $numFiles
 InstalledSize $installedSize
@@ -308,14 +377,141 @@
     close $fd
 }
 
-proc portpkg::write_package_info {infofile portname portversion portrevision} {
-    set portname [xml_escape $portname]
-    set portversion [xml_escape $portversion]
-    set portrevision [xml_escape $portrevision]
-
+proc portpkg::write_package_info {infofile} {
     set infofd [open ${infofile} w+]
     puts $infofd "
 <pkg-info install-location=\"/\" relocatable=\"false\" auth=\"root\">
 </pkg-info>"
     close $infofd
 }
+
+proc portpkg::write_distribution {dfile portname portepoch portversion portrevision} {
+    global macosx_deployment_target
+    set portname [xml_escape $portname]
+    if {$portepoch != "0"} {
+        set portepoch [xml_escape $portepoch]
+        set portepoch_str "${portepoch}_"
+    } else {
+        set portepoch ""
+        set portepoch_str ""
+    }
+    set portversion [xml_escape $portversion]
+    if {$portrevision != "0"} {
+        set portrevision [xml_escape $portrevision]
+        set portrevision_str "_${portrevision}"
+    } else {
+        set portrevision ""
+        set portrevision_str ""
+    }
+    set dfd [open $dfile w+]
+    puts $dfd "<?xml version=\"1.0\" encoding=\"utf-8\"?>
+<installer-gui-script minSpecVersion=\"1\">
+    <title>${portname}</title>
+    <options customize=\"never\"/>
+    <allowed-os-versions><os-version min=\"${macosx_deployment_target}\"/></allowed-os-versions>
+    <background file=\"background.tiff\" mime-type=\"image/tiff\" alignment=\"bottomleft\" scaling=\"none\"/>
+    <welcome mime-type=\"text/html\" file=\"Welcome.html\"/>
+    <choices-outline>
+        <line choice=\"default\">
+            <line choice=\"org.macports.${portname}\"/>
+        </line>
+    </choices-outline>
+    <choice id=\"default\"/>
+    <choice id=\"org.macports.${portname}\" visible=\"false\">
+        <pkg-ref id=\"org.macports.${portname}\"/>
+    </choice>
+    <pkg-ref id=\"org.macports.${portname}\">${portname}-${portepoch_str}${portversion}${portrevision_str}-component.pkg</pkg-ref>
+</installer-gui-script>
+"
+    close $dfd
+}
+
+# To create Apple packages, Apple version numbers consist of three
+# period separated integers [1][2].  Munki supports any number of
+# integers [3], so incorporate the port epoch, version and revision
+# numbers in the Apple package version number so that Munki can do
+# upgrades.  The Apple package number consists of the port epoch
+# number followed by the port version number followed by the port
+# revision number.
+#
+# Munki also requires that version numbers only consist of integers
+# and periods.  So replace all non-periods and non-digits in the
+# version number with periods so that any digits following the
+# non-digits can properly version the package.
+#
+# There is an edge case when upstream releases a new version which
+# adds an additional integer to its version number and the Portfile's
+# revision number is reset to 0.  For example, aspell epoch 0,
+# upstream 0.60.6, revision 4 was updated to epoch 0, upstream
+# 0.60.6.1, revision 0, which maps to 0.60.6.4 and 0.60.6.1.0
+# respectively, but the new Apple package version number is less than
+# the old one.  To handle this, all upstream version numbers are
+# mapped to seven period separated integers, appending 0 as necessary.
+# Six was the largest number of integers in all upstream version
+# numbers as of January 2013 [4], so add one to make space for
+# trailing [a-zA-Z] in the upstream version number.  This generates a
+# fixed format version number that will correctly upgrade the package,
+# e.g. 0.60.6.4.0.0.0.0.4 and 0.60.6.1.0.0.0.1 for aspell.
+#
+# [1] https://developer.apple.com/library/mac/#documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW1
+# [2] https://developer.apple.com/library/mac/#documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html#//apple_ref/doc/uid/TP40009249-SW1
+# [3] https://groups.google.com/d/msg/munki-dev/-DCERUz6rrM/zMbY6iimIGwJ
+# [4] http://lists.macosforge.org/pipermail/macports-dev/2013-January/021477.html
+proc portpkg::mp_version_to_apple_version {portepoch portversion portrevision} {
+    # Assume that portepoch and portrevision are non-negative integers
+    # so they do not need to be specially handled like the upstream
+    # version number.
+    set v $portversion
+
+    # Replace all non-period and non-digit characters with a period.
+    regsub -all -- {[^.0-9]+} $v . v
+
+    # Replace two or more consecutive periods with a single period.
+    regsub -all -- {[.]+} $v . v
+
+    # Trim trailing periods.
+    regsub -- {[.]+$} $v {} v
+
+    # Split the string into a list of integers.
+    set vs [split $v {.}]
+
+    # If the upstream version number ends in [a-zA-Z]+, e.g. openssl's
+    # 1.0.1c, then treat the trailing characters as a base 26 number,
+    # mapping 'A' and 'a' to 1, 'B' and 'b' to 2, etc.
+    if {[regexp -- {\d([a-zA-Z]+)} $portversion ignored chars]} {
+        # Get the integer ordinals of 'A' and 'a'.
+        scan "A" %c ord_A
+        scan "a" %c ord_a
+
+        set i 0
+        foreach char [split $chars ""] {
+            scan $char %c ord
+
+            # Treat uppercase and lowercase characters as the same
+            # value.  Ordinal values less then 'a' should have 'A'
+            # subtracted, otherwise subtract 'a'.  Add 1 to the value
+            # so that 'a' and 'A' are mapped to 1, not 0.
+            if {$ord < $ord_a} {
+                set j [expr $ord - $ord_A + 1]
+            } else {
+                set j [expr $ord - $ord_a + 1]
+            }
+            set i [expr 26*$i + $j]
+        }
+        lappend vs $i
+    }
+
+    # Add integers so that the total number of integers in the version
+    # number is seven.
+    while {[llength $vs] < 7} {
+        lappend vs 0
+    }
+
+    # Prepend the epoch and append the revision number.
+    set vs [linsert $vs 0 $portepoch]
+    lappend vs $portrevision
+
+    set v [join $vs {.}]
+
+    return $v
+}

Deleted: branches/gsoc11-statistics/base/src/package1.0/portportpkg.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portportpkg.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portportpkg.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,209 +0,0 @@
-# et:ts=4
-# portportpkg.tcl
-# $Id$
-#
-# Copyright (c) 2002 - 2004 Apple Inc.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. Neither the name of Apple Inc. nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-# 
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-
-package provide portportpkg 1.0
-package require portutil 1.0
-
-set org.macports.portpkg [target_new org.macports.portpkg portportpkg::portpkg_main]
-target_runtype ${org.macports.portpkg} always
-target_provides ${org.macports.portpkg} portpkg 
-target_requires ${org.macports.portpkg} main
-
-namespace eval portportpkg {
-}
-
-set_ui_prefix
-
-
-proc portportpkg::xar_path {args} {
-	global prefix_frozen
-    set xar ""
-    foreach path "${portutil::autoconf::xar_path} ${prefix_frozen}/bin/xar xar" {
- 	if { [file executable ${path}] } {
- 	   	  set xar $path
- 	      break;
- 	}
-    }
-    if { "${xar}" == "" } {
-    	ui_error "The xar tool is required to make portpkgs"
-    	ui_error "Please install the xar port before proceeding."
-		return -code error [msgcat::mc "Portpkg failed"]
-    }
-    
-    return $xar
-}
-
-
-# escape quotes, and things that make the shell cry
-proc portportpkg::shell_escape {str} {
-	regsub -all -- {\\} $str {\\\\} str
-	regsub -all -- {"} $str {\"} str
-	regsub -all -- {'} $str {\'} str
-	return $str
-}
-
-
-proc portportpkg::putel { fd el data } {
-	# Quote xml data
-	set quoted [string map  { & &amp; < &lt; > &gt; } $data]
-	# Write the element
-	puts $fd "<${el}>${quoted}</${el}>"
-}
-
-
-proc portportpkg::putlist { fd listel itemel list } {
-	puts $fd "<$listel>"
-	foreach item $list {
-		putel $fd $itemel $item
-	}
-	puts $fd "</$listel>"
-}
-
-
-proc portportpkg::create_portpkg {} {
-    global name prefix UI_PREFIX workpath portpath
-
-	set xar [xar_path]
-	
-    set dirname "portpkg"
-    set dirpath "${workpath}/${dirname}"
-    set pkgpath "${workpath}/${name}.portpkg"
-    set metaname "portpkg_meta.xml"
-    set metapath "${workpath}/${metaname}"
-    
-    # Expose and default some global variables
-    set vars " maintainers categories description \
-    	long_description master_sites homepage epoch version revision \
-    	PortInfo \
-    	submitter_name submitter_email submitter_key \
-    	"
-	eval "global $vars"
-	foreach var $vars {
-		if {![info exists $var]} { set $var {} }
-	}
-	
-	# Unobscure the maintainer addresses
-	set maintainers [unobscure_maintainers $maintainers]
-
-    # Make sure our workpath is clean
-    file delete -force $dirpath $metapath $pkgpath
-    
-    # Create the portpkg directory
-    file mkdir $dirpath
-
-    # Move in the Portfile
-    file copy Portfile ${dirpath}
-    
-    # Move in files    
-    if {[file isdirectory "files"]} {
-        file copy files ${dirpath}
-    }
-    
-    # Create the metadata subdoc
-    set sd [open ${metapath} w]
-    puts $sd "<portpkg version='1'>"
-    
-		puts $sd "<submitter>"
-			putel $sd name $submitter_name
-			putel $sd email $submitter_email
-			
-			# TODO provide means to set notes?
-			putel $sd notes ""
-		puts $sd "</submitter>"
-		
-		puts $sd "<package>"
-			putel $sd name $name
-			putel $sd homepage $homepage
-			putlist $sd categories category $categories
-			putlist $sd maintainers maintainer $maintainers
-			
-			putel $sd epoch $epoch
-			putel $sd version $version
-			putel $sd revision $revision
-			
-			putel $sd description [join $description]
-			putel $sd long_description [join $long_description]
-		
-			# TODO: variants has platforms in it
-			if {[info exists PortInfo(variants)]} {
-				if {[info exists PortInfo(variant_desc)]} {
-					array set descs $PortInfo(variant_desc)
-				} else {
-					array set descs ""
-				}
-	
-				puts $sd "<variants>"
-				foreach v $PortInfo(variants) {
-					puts $sd "<variant>"
-						putel $sd name $v
-						if {[info exists descs($v)]} {
-							putel $sd description $descs($v)
-						}
-					puts $sd "</variant>"
-				}
-				puts $sd "</variants>"
-			} else {
-				putel $sd variants ""
-			}
-			
-			# TODO: Dependencies and platforms
-			#putel $sd dependencies ""
-			#putel $sd platforms ""
-			
-		puts $sd "</package>"
-		
-    puts $sd "</portpkg>"
-    close $sd
-    
-    # Create portpkg.xar, including the metadata and the portpkg directory contents
-    set cmd "cd ${workpath}; ${xar} -cf ${pkgpath} --exclude \\.DSStore --exclude \\.svn ${dirname} -s ${metapath} -n ${metaname}"
-    if {[system $cmd] != ""} {
-		return -code error [format [msgcat::mc "Failed to create portpkg for port : %s"] $name]
-    }
-    
-    return ${pkgpath}
-}
-
-
-proc portportpkg::portpkg_main {args} {
-    global name version portverbose prefix UI_PREFIX workpath portpath
-    
-    ui_msg "$UI_PREFIX [format [msgcat::mc "Creating portpkg for %s-%s"] ${name} ${version}]"
-
-    # Make sure we have a work directory
-    file mkdir ${workpath}
-  
-    # Create portpkg.xar in the work directory
-    set pkgpath [create_portpkg]
- 
-    return 0
-}

Modified: branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portrpm.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -49,20 +49,23 @@
 # Set up defaults
 default rpm.asroot yes
 
+default rpm.srcdir {${prefix}/src/macports}
+default rpm.tmpdir {${prefix}/var/tmp}
+
 set_ui_prefix
 
 proc portrpm::rpm_main {args} {
     global subport version revision UI_PREFIX
-    
+
     ui_msg "$UI_PREFIX [format [msgcat::mc "Creating RPM package for %s-%s"] ${subport} ${version}]"
-    
+
     return [rpm_pkg $subport $version $revision]
 }
 
 proc portrpm::rpm_pkg {portname portversion portrevision} {
     global UI_PREFIX rpm.asroot package.destpath portdbpath destpath workpath prefix categories maintainers description long_description homepage epoch portpath
 	global os.platform os.arch os.version os.major supported_archs configure.build_arch license
-    
+
     set rpmdestpath ""
     if {![string equal ${package.destpath} ${workpath}] && ![string equal ${package.destpath} ""]} {
         set rpm.asroot no
@@ -83,7 +86,7 @@
     } elseif {${configure.build_arch} != ""} {
         set rpmbuildarch "--target ${configure.build_arch}"
     }
-    
+
     foreach dir [list "${prefix}/src/macports/RPMS" "${prefix}/src/apple/RPMS" "/usr/src/apple/RPMS" "/macports/rpms/RPMS"] {
         foreach arch [list ${configure.build_arch} ${os.arch} "fat" "noarch"] {
             set rpmpath "$dir/${arch}/${portname}-${portversion}-${portrevision}.${arch}.rpm"
@@ -94,7 +97,7 @@
             }
         }
     }
-    
+
     set specpath ${workpath}/${portname}.spec
     # long_description, description, or homepage may not exist
     foreach variable {long_description description homepage categories maintainers} {
@@ -106,7 +109,7 @@
     }
     set category   [lindex [split $categories " "] 0]
     set maintainer $maintainers
-    
+
     set dependencies {}
     # get deplist
     set deps [make_dependency_list $portname]
@@ -122,7 +125,7 @@
 
 	# depend on system (virtual packages for apple stuff)
 	lappend dependencies "org.macports.${os.platform}${os.major}"
-    
+
     set listpath ${workpath}/${portname}.filelist
     system "rm -f '${workpath}/${portname}.filelist' && touch '${workpath}/${portname}.filelist'"
     #system "cd '${destpath}' && find . -type d | grep -v -E '^.$' | sed -e 's/\"/\\\"/g' -e 's/^./%dir \"/' -e 's/$/\"/' > '${workpath}/${portname}.filelist'"
@@ -130,7 +133,7 @@
     system "cd '${destpath}' && find . ! -type d | grep /etc/ | sed -e 's/\"/\\\"/g' -e 's/^./%config \"/' -e 's/$/\"/' >> '${workpath}/${portname}.filelist'"
     write_spec ${specpath} ${destpath} ${listpath} $portname $portversion $portrevision $pkg_description $pkg_long_description $pkg_homepage $category $license $maintainer $dependencies $epoch
     system "MP_USERECEIPTS='${portdbpath}/receipts' rpmbuild -bb -v ${rpmbuildarch} ${rpmdestpath} ${specpath}"
-    
+
     return 0
 }
 
@@ -144,17 +147,17 @@
     }
     foreach {name array} $res {
         array set portinfo $array
-	
+
         if {[info exists portinfo(depends_run)] || [info exists portinfo(depends_lib)]} {
             # get the union of depends_run and depends_lib
             # xxx: only examines the portfile component of the depspec
             set depends {}
             if {[info exists portinfo(depends_run)]} { eval "lappend depends $portinfo(depends_run)" }
             if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
-	    
+
             foreach depspec $depends {
                 set dep [lindex [split $depspec :] end]
-		
+
                 # xxx: nasty hack
                 if {$dep != "XFree86"} {
                     eval "lappend result [make_dependency_list $dep]"

Modified: branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portsrpm.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -17,7 +17,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -45,20 +45,26 @@
 
 options package.destpath
 
+# Set up defaults
+default srpm.asroot yes
+
 set_ui_prefix
 
 proc portsrpm::srpm_main {args} {
     global subport version revision UI_PREFIX
-    
+
     ui_msg "$UI_PREFIX [format [msgcat::mc "Creating SRPM package for %s-%s"] ${subport} ${version}]"
-    
+
     return [srpm_pkg $subport $version $revision]
 }
 
 proc portsrpm::srpm_pkg {portname portversion portrevision} {
-    global UI_PREFIX package.destpath portdbpath destpath workpath distpath prefix categories maintainers description long_description homepage epoch portpath distfiles fetch_urls
+    global UI_PREFIX package.destpath portdbpath destpath workpath distpath prefix categories maintainers description long_description homepage epoch portpath distfiles
 	global os.platform os.arch os.version os.major
-    
+
+    set fetch_urls {}
+    portfetch::checkfiles fetch_urls
+
     set rpmdestpath ""
     if {![string equal ${package.destpath} ${workpath}] && ![string equal ${package.destpath} ""]} {
         set pkgpath ${package.destpath}
@@ -69,7 +75,7 @@
                    ${pkgpath}/SRPMS
         set rpmdestpath "--define '_topdir ${pkgpath}'"
     }
-    
+
     foreach dir [list "${prefix}/src/macports/SRPMS" "${prefix}/src/apple/SRPMS" "/usr/src/apple/SRPMS" "/macports/rpms/SRPMS"] {
         foreach arch {"src" "nosrc"} {
             set rpmpath "$dir/${portname}-${portversion}-${portrevision}.${arch}.rpm"
@@ -80,7 +86,7 @@
             }
         }
     }
-    
+
     set specpath ${workpath}/${portname}-port.spec
     # long_description, description, or homepage may not exist
     foreach variable {long_description description homepage categories maintainers} {
@@ -93,7 +99,7 @@
     set category   [lindex [split $categories " "] 0]
     set license    "Unknown"
     set maintainer $maintainers
-    
+
     set dependencies {}
     # get deplist
     set deps [make_dependency_list $portname]
@@ -114,14 +120,19 @@
     set sourcespath "`rpm --eval %{_sourcedir}`"
 
     system "cp -p ${portpath}/Portfile ${sourcespath}/$portname-Portfile"
-    system "cd ${portpath} && zip -r -q ${sourcespath}/$portname-files.zip files -x \\*.DS_Store -x files/.svn\\*"
+    if {[info exists ${portpath}/files]} {
+        system "cd ${portpath} && zip -r -q ${sourcespath}/$portname-files.zip files -x \\*.DS_Store -x files/.svn\\*"
+        set zip $portname-files.zip
+    } else {
+        set zip ""
+    }
     foreach dist $distfiles {
         system "cp -p ${distpath}/${dist} ${sourcespath}/${dist}"
     }
-    
-    write_port_spec ${specpath} $portname $portversion $portrevision $pkg_description $pkg_long_description $pkg_homepage $category $license $maintainer $distfiles $fetch_urls $dependencies $epoch $src
+
+    write_port_spec ${specpath} $portname $portversion $portrevision $pkg_description $pkg_long_description $pkg_homepage $category $license $maintainer $distfiles $fetch_urls $dependencies $epoch $src $zip
     system "rpmbuild -bs -v --nodeps ${rpmdestpath} ${specpath}"
-    
+
     return 0
 }
 
@@ -135,7 +146,7 @@
     }
     foreach {name array} $res {
         array set portinfo $array
-	
+
         if {[info exists portinfo(depends_fetch)] || [info exists portinfo(depends_extract)]
             || [info exists portinfo(depends_build)] || [info exists portinfo(depends_lib)]} {
             # get the union of depends_fetch, depends_extract, depends_build and depends_lib
@@ -145,10 +156,10 @@
             if {[info exists portinfo(depends_extract)]} { eval "lappend depends $portinfo(depends_extract)" }
             if {[info exists portinfo(depends_build)]} { eval "lappend depends $portinfo(depends_build)" }
             if {[info exists portinfo(depends_lib)]} { eval "lappend depends $portinfo(depends_lib)" }
-	    
+
             foreach depspec $depends {
                 set dep [lindex [split $depspec :] end]
-		
+
                 # xxx: nasty hack
                 if {$dep != "XFree86"} {
                     eval "lappend result [make_dependency_list $dep]"
@@ -192,7 +203,7 @@
     return $text
 }
 
-proc portsrpm::write_port_spec {specfile portname portversion portrevision description long_description homepage category license maintainer distfiles fetch_urls dependencies epoch src} {
+proc portsrpm::write_port_spec {specfile portname portversion portrevision description long_description homepage category license maintainer distfiles fetch_urls dependencies epoch src zip} {
     set specfd [open ${specfile} w+]
     set origportname ${portname}
     regsub -all -- "\-" $portversion "_" portversion
@@ -210,8 +221,10 @@
 License: ${license}
 URL: ${homepage}
 BuildRoot: %{_tmppath}/%{name}-%{version}-root
-Source0: ${portname}-Portfile
-Source1: ${portname}-files.zip"
+Source0: ${portname}-Portfile"
+    if {$zip != ""} {
+        puts $specfd "Source1: $zip"
+    }
     if {[expr ${epoch} != 0]} {
 	    puts $specfd "Epoch: ${epoch}"
     }
@@ -219,12 +232,12 @@
     set count $first
     puts $specfd "#distfiles"
     foreach file ${distfiles} {
-    
+
         puts -nonewline $specfd "Source${count}: "
         if {![info exists $fetch_urls]} {
         foreach {url_var distfile}  ${fetch_urls} {
             if {[string equal $distfile $file]} {
-                 global portfetch::$url_var
+                 global portfetch::$url_var master_sites
                  set site [lindex [set $url_var] 0]
                  set file [portfetch::assemble_url $site $distfile]
                  break
@@ -244,12 +257,17 @@
 	}
     }
     set wrap_description [word_wrap ${long_description} 72]
+    if {$zip != ""} {
+        set and "-a 1"
+    } else {
+        set and ""
+    }
     puts $specfd "
 %description
 $wrap_description
 
 %prep
-%setup -c -a 1 -T
+%setup -c $and -T
 cp -p %{SOURCE0} Portfile
 #prepare work area
 port fetch

Modified: branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/package1.0/portunarchive.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portunarchive.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007-2011 The MacPorts Project
+# Copyright (c) 2005, 2007-2012 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
@@ -18,7 +18,7 @@
 # 3. Neither the name of Apple Inc. nor the names of its contributors
 #    may be used to endorse or promote products derived from this software
 #    without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -82,19 +82,10 @@
         ui_debug "Skipping unarchive ($subport) since force is set"
         set skipped 1
     } else {
-        set found 0
-        set rootname [file rootname [get_portimage_path]]
-        foreach unarchive.type [supportedArchiveTypes] {
-            set unarchive.path "${rootname}.${unarchive.type}"
-            set unarchive.file [file tail ${unarchive.path}]
-            if {[file isfile ${unarchive.path}]} {
-                set found 1
-                break
-            } else {
-                ui_debug "No [string toupper ${unarchive.type}] archive: ${unarchive.path}"
-            }
-        }
-        if {$found == 1} {
+        set unarchive.path [find_portarchive_path]
+        set unarchive.file [file tail ${unarchive.path}]
+        set unarchive.type [string range [file extension ${unarchive.file}] 1 end]
+        if {${unarchive.path} != ""} {
             ui_debug "Found [string toupper ${unarchive.type}] archive: ${unarchive.path}"
         } else {
             if {[info exists ports_binary_only] && $ports_binary_only == "yes"} {
@@ -210,7 +201,7 @@
                 return -code error "No '$tar' was found on this system!"
             }
         }
-        xar|xpkg {
+        xar {
             set xar "xar"
             if {[catch {set xar [findBinary $xar ${portutil::autoconf::xar_path}]} errmsg] == 0} {
                 ui_debug "Using $xar"

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/Pextlib.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/Pextlib.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/Pextlib.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -5,6 +5,7 @@
  * Copyright (c) 2002 - 2003 Apple Inc.
  * Copyright (c) 2004 - 2005 Paul Guyot <pguyot at kallisys.net>
  * Copyright (c) 2004 Landon Fuller <landonf at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,6 +46,7 @@
 #include <fcntl.h>
 #include <grp.h>
 #include <limits.h>
+#include <netdb.h>
 #include <pwd.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -567,6 +569,34 @@
 }
 #endif
 
+/* Check if the configured DNS server(s) incorrectly return a result for
+   a nonexistent hostname. Returns true if broken, false if OK. */
+int CheckBrokenDNSCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
+{
+    static int already_checked = 0;
+    Tcl_Obj *tcl_result;
+    int broken = 0;
+    struct addrinfo *res = NULL;
+    int error;
+
+    /* Only do the actual test once per run. */
+    if (!already_checked) {
+        error = getaddrinfo("invalid-host.macports.org", NULL, NULL, &res);
+        if (!error) {
+            broken = 1;
+        }
+        if (res) {
+            freeaddrinfo(res);
+        }
+    
+        already_checked = 1;
+    }
+
+    tcl_result = Tcl_NewBooleanObj(broken);
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
+}
+
 int Pextlib_Init(Tcl_Interp *interp)
 {
     if (Tcl_InitStubs(interp, "8.4", 0) == NULL)
@@ -629,6 +659,8 @@
     Tcl_CreateObjCommand(interp, "isatty", IsattyCmd, NULL, NULL);
     Tcl_CreateObjCommand(interp, "term_get_size", TermGetSizeCmd, NULL, NULL);
 
+    Tcl_CreateObjCommand(interp, "check_broken_dns", CheckBrokenDNSCmd, NULL, NULL);
+
     if (Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
         return TCL_ERROR;
 

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/base32cmd.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/base32cmd.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/base32cmd.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -42,11 +42,11 @@
 #include "base32cmd.h"
 
 /* This package provides commands for encoding and decoding of hexstrings
-   into and out of the extended hex base32 encoding as specified in RFC 3548.
+   into and out of the standard base32 encoding as specified in RFC 4648.
 
    Based on public domain base32 code from tcllib, by Andreas Kupries */
 
-#define BASE32HEX 1
+#undef BASE32HEX
 
 static __inline__ int hex2dec(int data)
 {

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/md_wrappers.h
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/md_wrappers.h	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/md_wrappers.h	2013-04-09 18:46:31 UTC (rev 105085)
@@ -79,5 +79,15 @@
     return algo##End(&ctx, buf);						\
 }
 
+#define CHECKSUMData(algo, ctxtype)						\
+static char *algo##Data(const u_char *str, u_int32_t len, char *buf)		\
+{														\
+    ctxtype ctx;										\
+														\
+    algo##Init(&ctx);									\
+    algo##Update(&ctx,str,len);					        \
+    return algo##End(&ctx, buf);						\
+}
+
 #endif
 /* _MD_WRAPPERS_H */

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/rmd160cmd.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/rmd160cmd.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/rmd160cmd.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -55,6 +55,7 @@
 #include "md_wrappers.h"
 CHECKSUMEnd(RIPEMD160_, RIPEMD160_CTX, RIPEMD160_DIGEST_LENGTH)
 CHECKSUMFile(RIPEMD160_, RIPEMD160_CTX)
+CHECKSUMData(RIPEMD160_, RIPEMD160_CTX)
 #else
 /*
  * let's use our own version of rmd160* libraries.
@@ -64,18 +65,22 @@
 #include "rmd160.c"
 #define RIPEMD160_DIGEST_LENGTH 20
 #define RIPEMD160_File(x,y) RMD160File(x,y)
+#define RIPEMD160_Data(x,y,z) RMD160Data(x,y,z)
 
 #include "md_wrappers.h"
 CHECKSUMEnd(RMD160, RMD160_CTX, RIPEMD160_DIGEST_LENGTH)
 CHECKSUMFile(RMD160, RMD160_CTX)
+CHECKSUMData(RMD160, RMD160_CTX)
 #endif
 
 int RMD160Cmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	char *file, *action;
+	char *file, *instr, *action;
+	int inlen;
 	char buf[2*RIPEMD160_DIGEST_LENGTH + 1];
 	const char usage_message[] = "Usage: rmd160 file";
-	const char error_message[] = "Could not open file: ";
+	const char file_error_message[] = "Could not open file: ";
+	const char string_error_message[] = "Could not process string: ";
 	Tcl_Obj *tcl_result;
 
 	if (objc != 3) {
@@ -84,22 +89,33 @@
 	}
 
 	/*
-	 * Only the 'file' action is currently supported
+	 * 'file' and 'string' actions are currently supported
 	 */
 	action = Tcl_GetString(objv[1]);
-	if (strcmp(action, "file") != 0) {
+	if (strcmp(action, "file") == 0) {
+	    file = Tcl_GetString(objv[2]);
+
+        if (!RIPEMD160_File(file, buf)) {
+            tcl_result = Tcl_NewStringObj(file_error_message, sizeof(file_error_message) - 1);
+            Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(file, -1));
+            Tcl_SetObjResult(interp, tcl_result);
+            return TCL_ERROR;
+        }
+	} else if (strcmp(action, "string") == 0) {
+	    instr = Tcl_GetStringFromObj(objv[2], &inlen);
+
+	    if (!RIPEMD160_Data((u_char *)instr, (u_int32_t)inlen, buf)) {
+            tcl_result = Tcl_NewStringObj(string_error_message, sizeof(string_error_message) - 1);
+            Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(instr, -1));
+            Tcl_SetObjResult(interp, tcl_result);
+            return TCL_ERROR;
+        }
+	} else {
 		tcl_result = Tcl_NewStringObj(usage_message, sizeof(usage_message) - 1);
 		Tcl_SetObjResult(interp, tcl_result);
 		return TCL_ERROR;
 	}
-	file = Tcl_GetString(objv[2]);
-
-	if (!RIPEMD160_File(file, buf)) {
-		tcl_result = Tcl_NewStringObj(error_message, sizeof(error_message) - 1);
-		Tcl_AppendObjToObj(tcl_result, Tcl_NewStringObj(file, -1));
-		Tcl_SetObjResult(interp, tcl_result);
-		return TCL_ERROR;
-	}
+	
 	tcl_result = Tcl_NewStringObj(buf, sizeof(buf) - 1);
 	Tcl_SetObjResult(interp, tcl_result);
 	return TCL_OK;

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/system.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/system.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/system.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,7 +3,8 @@
  * system.c
  * $Id$
  *
- * Copyright (c) 2009 The MacPorts Project
+ * Copyright (c) 2002 - 2003 Apple, Inc.
+ * Copyright (c) 2008 - 2010, 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -76,14 +77,42 @@
     char *line;
 };
 
+static int check_sandboxing(Tcl_Interp *interp, char **sandbox_exec_path, char **profilestr)
+{
+    Tcl_Obj *tcl_result;
+    int supported;
+    int len;
+
+    tcl_result = Tcl_GetVar2Ex(interp, "portsandbox_supported", NULL, TCL_GLOBAL_ONLY);
+    if (!tcl_result || Tcl_GetBooleanFromObj(interp, tcl_result, &supported) != TCL_OK || !supported) {
+        return 0;
+    }
+
+    tcl_result = Tcl_GetVar2Ex(interp, "portutil::autoconf::sandbox_exec_path", NULL, TCL_GLOBAL_ONLY);
+    if (!tcl_result || !(*sandbox_exec_path = Tcl_GetString(tcl_result))) {
+        return 0;
+    }
+
+    tcl_result = Tcl_GetVar2Ex(interp, "portsandbox_profile", NULL, TCL_GLOBAL_ONLY);
+    if (!tcl_result || !(*profilestr = Tcl_GetStringFromObj(tcl_result, &len)) 
+        || len == 0) {
+        return 0;
+    }
+
+    return 1;
+}
+
 /* usage: system ?-notty? ?-nice value? ?-W path? command */
 int SystemCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
     char *buf;
     struct linebuf circbuf[CBUFSIZ];
     size_t linelen;
-    char *args[4];
+    char *args[7];
     char *cmdstring;
+    int sandbox = 0;
+    char *sandbox_exec_path;
+    char *profilestr;
     FILE *pdes;
     int fdset[2], nullfd;
     int fline, pos, ret;
@@ -127,17 +156,22 @@
         }
     }
 
+    /* check if and how we should use sandbox-exec */
+    sandbox = check_sandboxing(interp, &sandbox_exec_path, &profilestr);
+
     /*
      * Fork a child to run the command, in a popen() like fashion -
      * popen() itself is not used because stderr is also desired.
      */
     if (pipe(fdset) != 0) {
+        Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
         return TCL_ERROR;
     }
 
     pid = fork();
     switch (pid) {
     case -1: /* error */
+        Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
         return TCL_ERROR;
         break;
     case 0: /* child */
@@ -175,11 +209,22 @@
         }
 
         /* XXX ugly string constants */
-        args[0] = "sh";
-        args[1] = "-c";
-        args[2] = cmdstring;
-        args[3] = NULL;
-        execve("/bin/sh", args, environ);
+        if (sandbox) {
+            args[0] = "sandbox-exec";
+            args[1] = "-p";
+            args[2] = profilestr;
+            args[3] = "sh";
+            args[4] = "-c";
+            args[5] = cmdstring;
+            args[6] = NULL;
+            execve(sandbox_exec_path, args, environ);
+        } else {
+            args[0] = "sh";
+            args[1] = "-c";
+            args[2] = cmdstring;
+            args[3] = NULL;
+            execve("/bin/sh", args, environ);
+        }
         _exit(1);
         break;
     default: /* parent */
@@ -193,47 +238,52 @@
     pos = 0;
     memset(circbuf, 0, sizeof(circbuf));
     pdes = fdopen(fdset[0], "r");
-    while ((buf = fgetln(pdes, &linelen)) != NULL) {
-        char *sbuf;
-        int slen;
-
-        /*
-         * Allocate enough space to insert a terminating
-         * '\0' if the line is not terminated with a '\n'
-         */
-        if (buf[linelen - 1] == '\n')
-            slen = linelen;
-        else
-            slen = linelen + 1;
-
-        if (circbuf[pos].len == 0)
-            sbuf = malloc(slen);
-        else {
-            sbuf = realloc(circbuf[pos].line, slen);
+    if (pdes) {
+        while ((buf = fgetln(pdes, &linelen)) != NULL) {
+            char *sbuf;
+            int slen;
+    
+            /*
+             * Allocate enough space to insert a terminating
+             * '\0' if the line is not terminated with a '\n'
+             */
+            if (buf[linelen - 1] == '\n')
+                slen = linelen;
+            else
+                slen = linelen + 1;
+    
+            if (circbuf[pos].len == 0)
+                sbuf = malloc(slen);
+            else {
+                sbuf = realloc(circbuf[pos].line, slen);
+            }
+    
+            if (sbuf == NULL) {
+                read_failed = 1;
+                break;
+            }
+    
+            memcpy(sbuf, buf, linelen);
+            /* terminate line with '\0',replacing '\n' if it exists */
+            sbuf[slen - 1] = '\0';
+    
+            circbuf[pos].line = sbuf;
+            circbuf[pos].len = slen;
+    
+            if (pos++ == CBUFSIZ - 1) {
+                pos = 0;
+            }
+    
+            if (ui_info(interp, sbuf) != TCL_OK) {
+                read_failed = 1;
+                break;
+            }
         }
-
-        if (sbuf == NULL) {
-            read_failed = 1;
-            break;
-        }
-
-        memcpy(sbuf, buf, linelen);
-        /* terminate line with '\0',replacing '\n' if it exists */
-        sbuf[slen - 1] = '\0';
-
-        circbuf[pos].line = sbuf;
-        circbuf[pos].len = slen;
-
-        if (pos++ == CBUFSIZ - 1) {
-            pos = 0;
-        }
-
-        if (ui_info(interp, sbuf) != TCL_OK) {
-            read_failed = 1;
-            break;
-        }
+        fclose(pdes);
+    } else {
+        read_failed = 1;
+        Tcl_SetResult(interp, strerror(errno), TCL_STATIC);
     }
-    fclose(pdes);
 
     status = TCL_ERROR;
 
@@ -244,23 +294,28 @@
         } else {
             char *errorstr;
             size_t errorstrlen;
-            /* set errorCode [list CHILDSTATUS <pid> <code>] */
-            Tcl_Obj* errorCode = Tcl_NewListObj(0, NULL);
-            Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewStringObj("CHILDSTATUS", -1));
-            Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewIntObj(pid));
-            Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewIntObj(WEXITSTATUS(ret)));
-            Tcl_SetObjErrorCode(interp, errorCode);
+            Tcl_Obj* errorCode;
 
             /* print error */
-            errorstrlen = strlen("shell command \"")+strlen(cmdstring)+strlen("\" returned error ")+12;
+            /* get buffer large enough for additional message or the error code */
+            errorstrlen = strlen(cmdstring) + strlen("Command failed: ") + 12;
             errorstr = malloc(errorstrlen);
             if (errorstr) {
-                *errorstr = '\0';
-                snprintf(errorstr, errorstrlen, "%s%s%s%d", "shell command \"", cmdstring, "\" returned error ", WEXITSTATUS(ret));
+                snprintf(errorstr, errorstrlen, "Command failed: %s", cmdstring);
                 ui_info(interp, errorstr);
+                snprintf(errorstr, errorstrlen, "Exit code: %d", WEXITSTATUS(ret));
+                ui_info(interp, errorstr);
                 free(errorstr);
             }
-            Tcl_SetObjResult(interp, Tcl_NewStringObj("shell command failed (see log for details)", -1));
+
+            /* set errorCode [list CHILDSTATUS <pid> <code>] */
+            errorCode = Tcl_NewListObj(0, NULL);
+            Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewStringObj("CHILDSTATUS", -1));
+            Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewIntObj(pid));
+            Tcl_ListObjAppendElement(interp, errorCode, Tcl_NewIntObj(WEXITSTATUS(ret)));
+            Tcl_SetObjErrorCode(interp, errorCode);
+
+            Tcl_SetObjResult(interp, Tcl_NewStringObj("command execution failed", -1));
         }
     }
 

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/tests/base32.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/tests/base32.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/tests/base32.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -5,13 +5,13 @@
 proc main {pextlibname} {
 	load $pextlibname
 	
-	if {[base32encode "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"] != "SEOC8GKOVGE196NRUJ49IRTP4GJQSGF4CIDP6J54IMCHMU2IN1AG===="} {
-		puts {[base32encode "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"] != "SEOC8GKOVGE196NRUJ49IRTP4GJQSGF4CIDP6J54IMCHMU2IN1AG===="}
+	if {[base32encode "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"] != "4OYMIQUY7QOBJGX36TEJS35ZEQT24QPEMSNZGTFESWMRW6CSXBKQ===="} {
+		puts {[base32encode "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"] != "4OYMIQUY7QOBJGX36TEJS35ZEQT24QPEMSNZGTFESWMRW6CSXBKQ===="}
 		exit 1
 	}
 
-	if {[base32decode "SEOC8GKOVGE196NRUJ49IRTP4GJQSGF4CIDP6J54IMCHMU2IN1AG===="] != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"} {
-		puts {[base32decode "SEOC8GKOVGE196NRUJ49IRTP4GJQSGF4CIDP6J54IMCHMU2IN1AG===="] != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}
+	if {[base32decode "4OYMIQUY7QOBJGX36TEJS35ZEQT24QPEMSNZGTFESWMRW6CSXBKQ===="] != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"} {
+		puts {[base32decode "4OYMIQUY7QOBJGX36TEJS35ZEQT24QPEMSNZGTFESWMRW6CSXBKQ===="] != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}
 		exit 1
 	}
 }

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/tracelib.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -93,6 +93,7 @@
 static void sandbox_violation(int sock, const char * path);
 static void ui_warn(const char * format, ...);
 static void ui_info(const char * format, ...);
+static void ui_error(const char *format, ...);
 
 #define MAX_SOCKETS ((FD_SETSIZE)-1)
 
@@ -321,43 +322,47 @@
 	char * port=0;
 	size_t len=1;
 	char resolution='!';
+	int tcl_retval;
 		
 	Tcl_SetVar(interp, "path", path, 0);
-	Tcl_Eval(interp, "registry::file_registered $path");
-	port=strdup(Tcl_GetStringResult(interp));
+	/* FIXME: Use C registry API */
+	tcl_retval = Tcl_Eval(interp, "registry::file_registered $path");
+	port = strdup(Tcl_GetStringResult(interp));
 	if (!port) {
 		ui_warn("dep_check: memory allocation failed");
 	    return;
 	}
+	if (tcl_retval != TCL_OK) {
+		ui_error("failed to run registry::file_registered \"%s\": %s", path, port);
+	}
 	Tcl_UnsetVar(interp, "path", 0);
 	
-	if(*port!='0'||port[1])
-	{
-		char * t;
+	if (tcl_retval == TCL_OK && (*port != '0' || port[1])) {
+		char *t;
 	
-		t=depends;
-		for(;*t;t+=strlen(t)+1)
-		{
-			if(!strcmp(t, port))
-			{
-				resolution='+';
+		t = depends;
+		for (; *t; t += strlen(t) + 1) {
+			/* fprintf(stderr, "trace: %s =?= %s\n", t, port); */
+			if (!strcmp(t, port)) {
+				resolution = '+';
 				break;
 			}
 		}
 	}
-	
-	if(resolution!='+') {
-	    if(*port=='0'&&!port[1])
+
+	if (resolution != '+') {
+	    if (*port == '0' && !port[1]) {
 		    ui_info("trace: access denied to %s (*unknown*)", path);
-		else
+		} else {
 		    ui_info("trace: access denied to %s (%s)", path, port);
+		}
     }
 
 	free(port);
 	
-	if(send(sock, &len, sizeof(len), 0)==-1)
+	if (send(sock, &len, sizeof(len), 0) == -1)
 		ui_warn("tracelib send failed");
-	if(send(sock, &resolution, 1, 0)==-1)
+	if (send(sock, &resolution, 1, 0) == -1)
 		ui_warn("tracelib send failed");
 }
 
@@ -370,8 +375,9 @@
 	snprintf(tclcmd, sizeof(tclcmd), "ui_%s $warn", severity);
 	
 	Tcl_SetVar(interp, "warn", buf, 0);
-	
-	Tcl_Eval(interp, tclcmd);
+	if (TCL_OK != Tcl_Eval(interp, tclcmd)) {
+		fprintf(stderr, "Error evaluating tcl statement `%s': %s\n", tclcmd, Tcl_GetStringResult(interp));
+	}
 	Tcl_UnsetVar(interp, "warn", 0);
 	
 }
@@ -381,7 +387,7 @@
 	va_list va;
 	
 	va_start(va, format);
-		ui_msg("warn", format, va);
+	ui_msg("warn", format, va);
 	va_end(va);
 }
 
@@ -390,10 +396,17 @@
 	va_list va;
 	
 	va_start(va, format);
-		ui_msg("msg", format, va);
+	ui_msg("info", format, va);
 	va_end(va);
 }
 
+static void ui_error(const char *format, ...) {
+	va_list va;
+	va_start(va, format);
+	ui_msg("error", format, va);
+	va_end(va);
+}
+
 static int TracelibOpenSocketCmd(Tcl_Interp * in)
 {
 	struct sockaddr_un sun;

Modified: branches/gsoc11-statistics/base/src/pextlib1.0/uid.c
===================================================================
--- branches/gsoc11-statistics/base/src/pextlib1.0/uid.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/pextlib1.0/uid.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <tcl.h>
 
@@ -107,9 +108,9 @@
 		
 	/* set the uid */
 	if (0 != setuid(uid)) {
-        Tcl_Obj *result = Tcl_NewStringObj("could not set uid to ", -1);
-        Tcl_AppendObjToObj(result, objv[1]);
-        Tcl_SetObjResult(interp, result);
+        char buffer[128];
+        snprintf(buffer, sizeof(buffer), "could not set uid to %ld: %d %s", uid, errno, strerror(errno));
+        Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, -1));
         return TCL_ERROR;
     }
 		
@@ -137,9 +138,9 @@
 		
 	/* set the euid */
 	if (0 != seteuid(uid)) {
-        Tcl_Obj *result = Tcl_NewStringObj("could not set effective uid to ", -1);
-        Tcl_AppendObjToObj(result, objv[1]);
-        Tcl_SetObjResult(interp, result);
+        char buffer[128];
+        snprintf(buffer, sizeof(buffer), "could not set effective uid to %ld: %d %s", uid, errno, strerror(errno));
+        Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, -1));
         return TCL_ERROR;
     }
 		
@@ -163,9 +164,9 @@
     }
     
     if (0 != setgid(gid)) {
-        Tcl_Obj *result = Tcl_NewStringObj("could not set gid to ", -1);
-        Tcl_AppendObjToObj(result, objv[1]);
-        Tcl_SetObjResult(interp, result);
+        char buffer[128];
+        snprintf(buffer, sizeof(buffer), "could not set gid to %ld: %d %s", gid, errno, strerror(errno));
+        Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, -1));
         return TCL_ERROR;
     }
     
@@ -189,9 +190,9 @@
     }
     
     if (0 != setegid(gid)) {
-        Tcl_Obj *result = Tcl_NewStringObj("could not set effective gid to ", -1);
-        Tcl_AppendObjToObj(result, objv[1]);
-        Tcl_SetObjResult(interp, result);
+        char buffer[128];
+        snprintf(buffer, sizeof(buffer), "could not set effective gid to %ld: %d %s", gid, errno, strerror(errno));
+        Tcl_SetObjResult(interp, Tcl_NewStringObj(buffer, -1));
         return TCL_ERROR;
     }
     

Modified: branches/gsoc11-statistics/base/src/port/port-help.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port/port-help.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port/port-help.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -135,8 +135,6 @@
 Edit given ports
 }
 
-set porthelp(ed) $porthelp(edit)
-
 set porthelp(exit) {
 Exit port
 
@@ -181,7 +179,9 @@
 }
 
 set porthelp(install) {
-Installs the given ports
+Installs the given ports.
+    --no-rev-upgrade    Do not run rev-upgrade after the installation.
+    --unrequested       Do not mark the port as requested.
 }
 
 set porthelp(installed) {
@@ -253,6 +253,22 @@
 
 set porthelp(quit) $porthelp(exit)
 
+set porthelp(rev-upgrade) {
+Scan for broken binaries in the installed ports and rebuild them as needed. Can
+be run with -y to only report broken ports, but not automatically rebuild them.
+
+You normally wouldn't have to run rev-upgrade manually; it is run automatically
+after each install and upgrade by default. Rev-upgrade doesn't honor package
+names, e.g.
+	upgrade outdated
+will not run rev-upgrade only on outdated, because ports not in outdated might
+have been broken by upgrade outdated. Rev-upgrade will always run on all your
+active ports.
+
+See man 1 port, section rev-upgrade, and man 5 macports.conf, directives
+starting with revupgrade_ for configuration and more information.
+}
+
 set porthelp(rpm) {
 Creates a rpm for each of the given ports
 }
@@ -298,6 +314,7 @@
 
 --units <units> Specify units to use. Accepted units are: B, kB, KiB, MB, MiB,
                 GB, GiB. The 'B' may be omitted.
+--total         Display the grand total only
 }
 
 set porthelp(srpm) {
@@ -331,10 +348,6 @@
 port stats submit 
 }
 
-set porthelp(submit) {
-Submit a port to the MacPorts Web Application (unimplemented)
-}
-
 set porthelp(sync) {
 Synchronize the set of Portfiles
 }
@@ -350,7 +363,14 @@
 set porthelp(uninstall) {
 Uninstall the given ports
 
---no-exec   Do not execute any stored pre- or post-uninstall procedures
+--follow-dependents     Recursively uninstall all ports that depend on the
+                        specified port before uninstalling the port itself.
+--follow-dependencies   Also recursively uninstall all ports that the
+                        specified port depended on. This will not uninstall
+                        dependencies that are marked as requested or that
+                        have other dependents.
+--no-exec               Do not execute any stored pre- or post-uninstall
+                        procedures.
 }
 
 set porthelp(unload) $porthelp(load)

Modified: branches/gsoc11-statistics/base/src/port/port.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port/port.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port/port.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -5,7 +5,7 @@
 # port.tcl
 # $Id$
 #
-# Copyright (c) 2004-2011 The MacPorts Project
+# Copyright (c) 2004-2012 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
 # Copyright (c) 2002-2003 Apple Inc.
 # All rights reserved.
@@ -237,7 +237,7 @@
 # show the URL for the ticket reporting instructions
 proc print_tickets_url {args} {
     if {${macports::prefix} != "/usr/local" && ${macports::prefix} != "/usr"} {
-        ui_notice "To report a bug, see <http://guide.macports.org/#project.tickets>"
+        ui_notice "To report a bug, follow the instructions in the guide:\n    http://guide.macports.org/#project.tickets"
     }
 }
 
@@ -297,7 +297,8 @@
     switch -- $field {
         variant -
         platform -
-        maintainer {
+        maintainer -
+        subport {
             set field "${field}s"
         }
         category {
@@ -698,11 +699,15 @@
         array unset portinfo
         array set portinfo $info
         
+        set portentry [entry_for_portlist [list url $portinfo(porturl) name $name]]
+        
         array unset entry
-        array set entry [entry_for_portlist [list url $portinfo(porturl) name $name]]
+        array set entry $portentry
+        
         if {[info exists unique($entry(fullname))]} continue
         set unique($entry(fullname)) 1
-        lappend result [array get entry]
+        
+        lappend result $portentry
     }
     return $result
 }
@@ -1136,7 +1141,43 @@
     return [portlist_sort $results]
 }
 
+proc get_subports {portname} {
+    global global_variations
 
+    # look up portname
+    if {[catch {mportlookup $portname} result]} {
+        ui_debug "$::errorInfo"
+        return -code error "lookup of portname $portname failed: $result"
+    }
+    if {[llength $result] < 2} {
+        return -code error "Port $portname not found"
+    }
+    array unset portinfo
+    array set portinfo [lindex $result 1]
+    set porturl $portinfo(porturl)
+
+    # open portfile
+    if {[catch {set mport [mportopen $porturl [list subport $portinfo(name)] [array get global_variations]]} result]} {
+        ui_debug "$::errorInfo"
+        return -code error "Unable to open port: $result"
+    }
+    array unset portinfo
+    array set portinfo [mportinfo $mport]
+    mportclose $mport
+
+    # gather its subports
+    set results {}
+
+    if {[info exists portinfo(subports)]} {
+        foreach subport $portinfo(subports) {
+            add_to_portlist results [list name $subport]
+        }
+    }
+
+    return [portlist_sort $results]
+}
+
+
 ##########################################
 # Port expressions
 ##########################################
@@ -1321,6 +1362,8 @@
         ^depends_fetch:     -
         ^replaced_by:       -
         ^revision:          -
+        ^subport:           -
+        ^subports:          -
         ^license:           { # Handle special port selectors
             advance
 
@@ -1375,6 +1418,17 @@
             set el 1
         }
 
+        ^subportof:         {
+            advance
+
+            # Break up the token, because older Tcl switch doesn't support -matchvar
+            regexp {^(\w+):(.*)} $token matchvar selector portname
+
+            add_multiple_ports reslist [get_subports $portname]
+
+            set el 1
+        }
+
         [][?*]              { # Handle portname glob patterns
             advance; add_multiple_ports reslist [get_matching_ports $token no glob]
             set el 1
@@ -1818,6 +1872,7 @@
             array set portinfo [lindex $result 1]
             set porturl $portinfo(porturl)
             set portdir $portinfo(portdir)
+            set portname $portinfo(name)
         } elseif {$porturl ne "file://."} {
             # Extract the portdir from porturl and use it to search PortIndex.
             # Only the last two elements of the path (porturl) make up the
@@ -1835,7 +1890,14 @@
                 break_softcontinue "Portdir $portdir not found" 1 status
             }
             array unset portinfo
-            array set portinfo [lindex $result 1]
+            set matchindex [lsearch -exact -nocase $result $portname]
+            if {$matchindex != -1} {
+                array set portinfo [lindex $result [incr matchindex]]
+            } else {
+                ui_warn "Portdir $portdir doesn't seem to belong to portname $portname"
+                array set portinfo [lindex $result 1]
+            }
+            set portname $portinfo(name)
         }
         set portpath [macports::getportdir $porturl]
         set logfile [file join [macports::getportlogpath $portpath $portname] "main.log"]
@@ -2019,7 +2081,7 @@
         set pretty_print 0
         
         # For human-readable summary, which is the default with no options
-        if {![array size options]} {
+        if {[llength [array get options ports_info_*]] == 0} {
             set pretty_print 1
         } elseif {[info exists options(ports_info_pretty)]} {
             set pretty_print 1
@@ -2077,7 +2139,7 @@
                 set inf "$portinfo(name) @$portinfo(version)"
                 set ropt "heading"
                 if {[info exists portinfo(revision)] && $portinfo(revision) > 0} {
-                    append inf ", Revision $portinfo(revision)"
+                    append inf "_$portinfo(revision)"
                 }
                 if {[info exists portinfo(categories)]} {
                     append inf " ([join $portinfo(categories) ", "])"
@@ -2429,7 +2491,9 @@
     }
     set group [lindex $portlist 0]
 
-    set commands [array names [array set {} $opts]]
+    array set opts_array $opts
+    set commands [array names opts_array ports_select_*]
+    array unset opts_array
     # If no command (--set, --show, --list) is specified *but* more than one
     # argument is specified, default to the set command.
     if {[llength $commands] < 1 && [llength $portlist] > 1} {
@@ -2579,18 +2643,19 @@
     foreachport $portlist {
         if {![info exists depscache(port:$portname)]} {
             set status [macports::upgrade $portname "port:$portname" [array get requested_variations] [array get options] depscache]
-            # status 2 means the port was not found in the index
-            if {$status != 0 && $status != 2 && ![macports::ui_isset ports_processall]} {
+            # status 2 means the port was not found in the index,
+            # status 3 means the port is not installed
+            if {$status != 0 && $status != 2 && $status != 3 && ![macports::ui_isset ports_processall]} {
                 break
             }
         }
     }
     
-    if {$status != 0} {
+    if {$status != 0 && $status != 2 && $status != 3} {
         print_tickets_url
-    } else {
+    } elseif {$status == 0} {
         array set options $opts
-        if {![info exists options(ports_upgrade_no-rev-upgrade)]} {
+        if {![info exists options(ports_upgrade_no-rev-upgrade)] && ${macports::revupgrade_autorun} && ![macports::global_option_isset ports_dryrun]} {
             set status [action_revupgrade $action $portlist $opts]
         }
     }
@@ -2608,13 +2673,19 @@
 
 
 proc action_version { action portlist opts } {
-    puts "Version: [macports::version]"
+    if ![macports::ui_isset ports_quiet] {
+        puts -nonewline "Version: "
+    }
+    puts [macports::version]
     return 0
 }
 
 
 proc action_platform { action portlist opts } {
-    puts "Platform: ${macports::os_platform} ${macports::os_major} ${macports::os_arch}"
+    if ![macports::ui_isset ports_quiet] {
+        puts -nonewline "Platform: "
+    }
+    puts "${macports::os_platform} ${macports::os_major} ${macports::os_arch}"
     return 0
 }
 
@@ -2968,7 +3039,13 @@
             if {[llength $result] < 2} {
                 break_softcontinue "Portdir $portdir not found" 1 status
             }
-            array set portinfo [lindex $result 1]
+            set matchindex [lsearch -exact -nocase $result $portname]
+            if {$matchindex != -1} {
+                array set portinfo [lindex $result [incr matchindex]]
+            } else {
+                ui_warn "Portdir $portdir doesn't seem to belong to portname $portname"
+                array set portinfo [lindex $result 1]
+            }
         }
 
         if {!([info exists options(ports_${action}_index)] && $options(ports_${action}_index) eq "yes")} {
@@ -3482,20 +3559,22 @@
                         set space [expr $space + [file size $file] ]
                     }
                 }
-                set msg "[bytesize $space $units] $portname"
-                if { $portversion != {} } {
-                    append msg " @$portversion"
+                if {![info exists options(ports_space_total)] || $options(ports_space_total) != "yes"} {
+                    set msg "[bytesize $space $units] $portname"
+                    if { $portversion != {} } {
+                        append msg " @$portversion"
+                    }
+                    puts $msg
                 }
-                puts $msg
                 set spaceall [expr $space + $spaceall]
             } else {
-                puts "Port $portname does not contain any file or is not active."
+                puts stderr "Port $portname does not contain any file or is not active."
             }
         } else {
-            puts "Port $portname is not installed."
+            puts stderr "Port $portname is not installed."
         }
     }
-    if {[llength $portlist] > 1} {
+    if {[llength $portlist] > 1 || ([info exists options(ports_space_total)] && $options(ports_space_total) == "yes")} {
         puts "[bytesize $spaceall $units] total"
     }
     return 0
@@ -3734,11 +3813,20 @@
             } else {
                 if {[info exists options(ports_search_line)]
                         && $options(ports_search_line) == "yes"} {
-                    puts "$portinfo(name)\t$portinfo(version)\t$portinfo(categories)\t$portinfo(description)"
+                    # check for ports without category, e.g. replaced_by stubs
+                    if {[info exists portinfo(categories)]} {
+                        puts "$portinfo(name)\t$portinfo(version)\t$portinfo(categories)\t$portinfo(description)"
+                    } else {
+                        # keep two consecutive tabs in order to provide consistent columns' content
+                        puts "$portinfo(name)\t$portinfo(version)\t\t$portinfo(description)"
+                    }
                 } else {
                     puts -nonewline $joiner
 
                     puts -nonewline "$portinfo(name) @$portinfo(version)"
+                    if {[info exists portinfo(revision)] && $portinfo(revision) > 0} {
+                        puts -nonewline "_$portinfo(revision)"
+                    }
                     if {[info exists portinfo(categories)]} {
                         puts -nonewline " ([join $portinfo(categories) ", "])"
                     }
@@ -3810,12 +3898,16 @@
 
 
 proc action_echo { action portlist opts } {
+    global global_options
+
     # Simply echo back the port specs given to this command
     foreachport $portlist {
         if {![macports::ui_isset ports_quiet]} {
             set opts {}
             foreach { key value } [array get options] {
-                lappend opts "$key=$value"
+                if ![info exists global_options($key)] {
+                    lappend opts "$key=$value"
+                }
             }
 
             set composite_version [composite_version $portversion [array get variations] 1]
@@ -3861,6 +3953,7 @@
             }
             array set portinfo [lindex $res 1]
             set porturl $portinfo(porturl)
+            set portname $portinfo(name)
         }
         
         
@@ -3881,7 +3974,7 @@
                     close $f
                 }
                 
-                ed - edit {
+                edit {
                     # Edit the port's portfile with the user's editor
                     
                     # Restore our entire environment from start time.
@@ -4071,7 +4164,9 @@
         }
         # if installing, mark the port as explicitly requested
         if {$action == "install"} {
-            set options(ports_requested) 1
+            if {![info exists options(ports_install_unrequested)]} {
+                set options(ports_requested) 1
+            }
             # we actually activate as well
             set target activate
         } elseif {$action == "archive"} {
@@ -4102,12 +4197,16 @@
         
         # Process any error that wasn't thrown and handled already
         if {$result} {
-            break_softcontinue "Status $result encountered during processing." 1 status
+            print_tickets_url
+            break_softcontinue "Processing of port $portname failed" 1 status
         }
     }
     
-    if {$status != 0} {
-        print_tickets_url
+    if {$status == 0 && $action == "install" && ![macports::global_option_isset ports_dryrun]} {
+        array set options $opts
+        if {![info exists options(ports_nodeps)] && ![info exists options(ports_install_no-rev-upgrade)] && ${macports::revupgrade_autorun}} {
+            set status [action_revupgrade $action $portlist $opts]
+        }
     }
     
     return $status
@@ -4212,7 +4311,6 @@
     search      [list action_search         [ACTION_ARGS_STRINGS]] \
     list        [list action_list           [ACTION_ARGS_PORTS]] \
     \
-    ed          [list action_portcmds       [ACTION_ARGS_PORTS]] \
     edit        [list action_portcmds       [ACTION_ARGS_PORTS]] \
     cat         [list action_portcmds       [ACTION_ARGS_PORTS]] \
     dir         [list action_portcmds       [ACTION_ARGS_PORTS]] \
@@ -4234,7 +4332,6 @@
     clean       [list action_target         [ACTION_ARGS_PORTS]] \
     test        [list action_target         [ACTION_ARGS_PORTS]] \
     lint        [list action_target         [ACTION_ARGS_PORTS]] \
-    submit      [list action_target         [ACTION_ARGS_PORTS]] \
     livecheck   [list action_target         [ACTION_ARGS_PORTS]] \
     distcheck   [list action_target         [ACTION_ARGS_PORTS]] \
     mirror      [list action_target         [ACTION_ARGS_PORTS]] \
@@ -4328,7 +4425,6 @@
 global cmd_opts_array
 array set cmd_opts_array {
     edit        {{editor 1}}
-    ed          {{editor 1}}
     info        {category categories depends_fetch depends_extract
                  depends_build depends_lib depends_run
                  depends description epoch fullname heading homepage index license
@@ -4345,9 +4441,10 @@
                  long_description maintainer maintainers name platform
                  platforms portdir regex revision variant variants version}
     selfupdate  {nosync}
-    space       {{units 1}}
+    space       {{units 1} total}
     activate    {no-exec}
     deactivate  {no-exec}
+    install     {no-rev-upgrade unrequested}
     uninstall   {follow-dependents follow-dependencies no-exec}
     variants    {index}
     clean       {all dist work logs}
@@ -4475,7 +4572,7 @@
                         set global_options(ports_force) yes
                     }
                     o {
-                        set global_options(ports_ignore_older) yes
+                        set global_options(ports_ignore_different) yes
                     }
                     n {
                         set global_options(ports_nodeps) yes

Modified: branches/gsoc11-statistics/base/src/port/portindex.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port/portindex.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port/portindex.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -165,7 +165,7 @@
     }
 }
 
-if {[expr $argc > 4]} {
+if {[expr $argc > 8]} {
     print_usage
     exit 1
 }
@@ -187,6 +187,10 @@
                 set os_platform [lindex $platlist 0]
                 set os_major [lindex $platlist 1]
                 set os_arch [lindex $platlist 2]
+                if {$os_platform == "macosx"} {
+                    lappend port_options os.subplatform $os_platform os.universal_supported yes
+                    set os_platform darwin
+                }
                 lappend port_options os.platform $os_platform os.major $os_major os.arch $os_arch
             } elseif {$arg == "-f"} { # Completely rebuild index
                 set full_reindex 1

Modified: branches/gsoc11-statistics/base/src/port1.0/Makefile
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/Makefile	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/Makefile	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,9 +4,10 @@
 	portfetch.tcl portmain.tcl portbuild.tcl portpatch.tcl portutil.tcl \
 	portinstall.tcl portuninstall.tcl portdepends.tcl portdestroot.tcl \
 	portlint.tcl portclean.tcl porttest.tcl portactivate.tcl \
-	portdeactivate.tcl portsubmit.tcl port_autoconf.tcl portstartupitem.tcl \
+	portdeactivate.tcl port_autoconf.tcl portstartupitem.tcl \
 	porttrace.tcl portlivecheck.tcl portdistcheck.tcl portmirror.tcl \
-	portload.tcl portunload.tcl portdistfiles.tcl fetch_common.tcl
+	portload.tcl portunload.tcl portdistfiles.tcl fetch_common.tcl \
+	portsandbox.tcl
 
 include ../../Mk/macports.subdir.mk
 include ../../Mk/macports.autoconf.mk
@@ -33,3 +34,5 @@
 
 test::
 	${TCLSH} tests/portutil.tcl ${macports_tcl_dir}
+	${TCLSH} tests/portdestroot.tcl ${macports_tcl_dir}
+	${TCLSH} tests/portfetch.tcl ${macports_tcl_dir}

Modified: branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/fetch_common.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # $Id$
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
-# Copyright (c) 2004 - 2011 The MacPorts Project
+# Copyright (c) 2004 - 2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -103,10 +103,17 @@
 
         # here we have the chance to take a look at tags, that possibly
         # have been assigned in mirror_sites.tcl
-        set splitlist [split $element :]
-        # every element is a URL, so we'll always have multiple elements. no need to check
-        set element "[lindex $splitlist 0]:[lindex $splitlist 1]"
-        set mirror_tag "[lindex $splitlist 2]"
+        # tag will be after the last colon after the
+        # first slash after the ://
+        set lastcolon [string last : $element]
+        set aftersep [expr [string first : $element] + 3]
+        set firstslash [string first / $element $aftersep]
+        if {$firstslash != -1 && $firstslash < $lastcolon} {
+            set mirror_tag [string range $element [expr $lastcolon + 1] end]
+            set element [string range $element 0 [expr $lastcolon - 1]]
+        } else {
+            set mirror_tag ""
+        }
 
         set name_re {\$(?:name\y|\{name\})}
         # if the URL has $name embedded, kill any mirror_tag that may have been added
@@ -236,8 +243,7 @@
         if {[getuid] == 0 && [geteuid] != 0} {
             set oldeuid [geteuid]
             set oldegid [getegid]
-            seteuid 0
-            setegid 0
+            seteuid 0; setegid 0
         }
 
         foreach site $urllist {
@@ -252,7 +258,7 @@
                 continue
             }
             foreach fallback $fallback_mirror_list {
-                if {[string match [append fallback *] $site]} {
+                if {[string match ${fallback}* $site]} {
                     # don't bother pinging fallback mirrors
                     set seen($host) yes
                     # and make them sort to the very end of the list
@@ -261,25 +267,29 @@
                 }
             }
             if { ![info exists seen($host)] } {
-                if {[catch {set fds($host) [open "|ping -noq -c3 -t3 $host | grep round-trip | cut -d / -f 5"]}]} {
-                    ui_debug "Spawning ping for $host failed"
-                    # will end up after all hosts that were pinged OK but before those that didn't respond
-                    set pingtimes($host) 5000
-                } else {
-                    ui_debug "Pinging $host..."
-                    set seen($host) yes
-                    lappend hosts $host
+                # first check the persistent cache
+                set pingtimes($host) [get_pingtime $host]
+                if {$pingtimes($host) == {}} {
+                    if {[catch {set fds($host) [open "|ping -noq -c3 -t3 $host | grep round-trip | cut -d / -f 5"]}]} {
+                        ui_debug "Spawning ping for $host failed"
+                        # will end up after all hosts that were pinged OK but before those that didn't respond
+                        set pingtimes($host) 5000
+                    } else {
+                        set seen($host) yes
+                        lappend hosts $host
+                    }
                 }
             }
         }
 
         foreach host $hosts {
-            set len [gets $fds($host) pingtimes($host)]
+            gets $fds($host) pingtimes($host)
             if { [catch { close $fds($host) }] || ![string is double -strict $pingtimes($host)] } {
                 # ping failed, so put it last in the list (but before the fallback mirrors)
                 set pingtimes($host) 10000
             }
-            ui_debug "$host ping time is $pingtimes($host)"
+            # cache it
+            set_pingtime $host $pingtimes($host)
         }
 
         if {[info exists oldeuid]} {
@@ -294,7 +304,10 @@
             } else {
                 regexp $hostregex $site -> host
             }
-            lappend pinglist [ list $site $pingtimes($host) ]
+            # -1 means blacklisted
+            if {$pingtimes($host) != "-1"} {
+                lappend pinglist [ list $site $pingtimes($host) ]
+            }
         }
 
         set pinglist [ lsort -real -index 1 $pinglist ]
@@ -325,3 +338,11 @@
 
     return $urls
 }
+
+# warn if DNS is broken
+proc portfetch::check_dns {} {
+    # check_broken_dns returns true at most once, so we don't have to worry about spamming this message
+    if {[check_broken_dns]} {
+        ui_warn "Your DNS server(s) incorrectly claim to know the address of nonexistent hosts. This may cause checksum mismatches for some ports."
+    }
+}

Modified: branches/gsoc11-statistics/base/src/port1.0/port.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/port.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/port.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -32,6 +32,33 @@
 # standard package load
 package provide port 1.0
 
+# Provide a callback registration mechanism for port subpackages. This needs to
+# be done _before_ loading the subpackages.
+namespace eval port {
+	variable _callback_list [list]
+
+	# Append a new procedure to a list of callbacks to be called when
+	# port::run_callbacks is called from macports1.0 after evaluating
+	# a Portfile
+	proc register_callback {callback} {
+		variable _callback_list
+		lappend _callback_list ${callback}
+	}
+	
+	# Run the callbacks registered in the callback list. Called from
+	# macports1.0 in the child interpreter after evaluating the Portfile and
+	# the variants. Clears the list of callbacks.
+	proc run_callbacks {} {
+		variable _callback_list
+		foreach callback ${_callback_list} {
+			ui_debug "Running callback ${callback}"
+			${callback}
+			ui_debug "Finished running callback ${callback}"
+		}
+		set _callback_list [list]
+	}
+}
+
 package require mp_package 1.0
 package require portmain 1.0
 package require portdepends 1.0
@@ -49,7 +76,6 @@
 package require portclean 1.0
 package require porttest 1.0
 package require portlint 1.0
-package require portsubmit 1.0
 package require porttrace 1.0
 package require portdistcheck 1.0
 package require portlivecheck 1.0
@@ -58,3 +84,4 @@
 package require portunload 1.0
 
 package require portdistfiles 1.0
+package require portsandbox 1.0

Modified: branches/gsoc11-statistics/base/src/port1.0/port_autoconf.tcl.in
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/port_autoconf.tcl.in	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/port_autoconf.tcl.in	2013-04-09 18:46:31 UTC (rev 105085)
@@ -40,6 +40,7 @@
 	variable diff_path "@DIFF@"
 	variable dscl_path "@DSCL@"
 	variable file_path "@FILE@"
+	variable find_path "@FIND@"
 	variable bzr_path "@BZR@"
 	variable cvs_path "@CVS@"
 	variable svn_path "@SVN@"
@@ -62,13 +63,17 @@
 	variable mtree_path "@MTREE@"
 	variable pax_path "@PAX@"
 	variable xar_path "@XAR@"
+	variable xcode_select_path "@XCODE_SELECT@"
+	variable xcodebuild_path "@XCODEBUILD@"
+	variable xcrun_path "@XCRUN@"
+	variable sandbox_exec_path "@SANDBOX_EXEC@"
 	variable sed_command "@SED@"
 	variable sed_ext_flag "@SED_EXT@"
 	variable tar_command "@TAR_CMD@"
 	variable tar_path "@TAR@"
 	variable tar_q "@TAR_Q@"
 	variable hdiutil_path "@HDIUTIL@"
-	variable swig_path "@SIWG@"
+	variable swig_path "@SWIG@"
 	variable have_launchd "@HAVE_LAUNCHD@"
 	variable launchctl_path "@LAUNCHCTL@"
 	variable install_command "@INSTALL@"

Modified: branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portbuild.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portbuild.tcl
 # $Id$
 #
-# Copyright (c) 2007 - 2011 The MacPorts Project
+# Copyright (c) 2007 - 2012 The MacPorts Project
 # Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
@@ -43,9 +43,10 @@
 }
 
 # define options
+options build.asroot
+options build.jobs
 options build.target
-options build.jobs
-options build.asroot
+options build.type
 options use_parallel_build
 commands build
 # defaults
@@ -56,12 +57,31 @@
 default build.jobs {[portbuild::build_getjobs]}
 default build.pre_args {[portbuild::build_getargs]}
 default build.target "all"
+default build.type "default"
 default use_parallel_build yes
 
 set_ui_prefix
 
+# Automatically called from macports1.0 after evaluating the Portfile. If
+# ${build.type} == bsd, ensures bsdmake is present by adding a bin:-style
+# dependency.
+proc portbuild::add_automatic_buildsystem_dependencies {} {
+    if {[option build.type] == "bsd" && [option os.platform] == "darwin"} {
+        ui_debug "build.type is BSD, adding bin:bsdmake:bsdmake build dependency"
+        depends_build-delete bin:bsdmake:bsdmake
+        depends_build-append bin:bsdmake:bsdmake
+    }
+    if {[option build.type] == "gnu" && [option os.platform] == "freebsd"} {
+        ui_debug "build.type is GNU, adding bin:gmake:gmake build dependency"
+        depends_build-delete bin:gmake:gmake
+        depends_build-append bin:gmake:gmake
+    }
+}
+# Register the above procedure as a callback after Portfile evaluation
+port::register_callback portbuild::add_automatic_buildsystem_dependencies
+
 proc portbuild::build_getmaketype {args} {
-    if {![exists build.type]} {
+    if {[option build.type] == "default"} {
         return [findBinary make $portutil::autoconf::make_path]
     }
     switch -exact -- [option build.type] {
@@ -124,7 +144,8 @@
 }
 
 proc portbuild::build_getargs {args} {
-    if {((![exists build.type] && [option os.platform] != "freebsd") || ([exists build.type] && [option build.type] == "gnu")) \
+    if {(([option build.type] == "default" && [option os.platform] != "freebsd") || \
+         ([option build.type] == "gnu")) \
         && [regexp "^(/\\S+/|)(g|gnu|)make(\\s+.*|)$" [option build.cmd]]} {
         # Print "Entering directory" lines for better log debugging
         return "-w [option build.target]"

Modified: branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portchecksum.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -192,7 +192,7 @@
 proc portchecksum::checksum_start {args} {
     global UI_PREFIX
 
-    ui_notice "$UI_PREFIX [format [msgcat::mc "Verifying checksum(s) for %s"] [option subport]]"
+    ui_notice "$UI_PREFIX [format [msgcat::mc "Verifying checksums for %s"] [option subport]]"
 }
 
 # checksum_main
@@ -280,6 +280,8 @@
                     && "text/html" == $mimetype} {
                     # file --mime-type would be preferable to file --mime and strsed, but is only available as of Snow Leopard
                     set wrong_mimetype yes
+                    set htmlfile_path ${fullpath}.html
+                    file rename -force $fullpath $htmlfile_path
                 }
             }
 
@@ -291,10 +293,6 @@
 
     if {[tbool fail]} {
 
-        # Show the desired checksum line for easy cut-paste
-        ui_info "The correct checksum line may be:"
-        ui_info [format "%-20s%s" "checksums" [join $sums [format " \\\n%-20s" ""]]]
-
         if {[tbool wrong_mimetype]} {
             # We got an HTML file, though the distfile name does not suggest that one was
             # expected. Probably a helpful DNS server sent us to its search results page
@@ -305,6 +303,11 @@
             ui_notice "for the checksum mismatch:"
             ui_notice "<https://trac.macports.org/wiki/MisbehavingServers>"
             ui_notice "***"
+            ui_notice "The file has been moved to: $htmlfile_path"
+        } else {
+            # Show the desired checksum line for easy cut-paste
+            ui_info "The correct checksum line may be:"
+            ui_info [format "%-20s%s" "checksums" [join $sums [format " \\\n%-20s" ""]]]
         }
 
         return -code error "[msgcat::mc "Unable to verify file checksums"]"

Modified: branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portconfigure.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,8 +1,7 @@
 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
-# portconfigure.tcl
 # $Id$
 #
-# Copyright (c) 2007 - 2011 The MacPorts Project
+# Copyright (c) 2007 - 2013 The MacPorts Project
 # Copyright (c) 2007 Markus W. Weissmann <mww at macports.org>
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
@@ -128,14 +127,18 @@
 default configure.march     {}
 default configure.mtune     {}
 # We could have debug/optimizations be global configurable at some point.
-options configure.optflags configure.cflags configure.cppflags configure.cxxflags configure.objcflags configure.ldflags configure.libs configure.fflags configure.f90flags configure.fcflags configure.classpath
-default configure.optflags  {-O2}
+options configure.optflags
+options configure.cflags configure.cxxflags configure.objcflags
+options configure.cppflags configure.ldflags configure.libs
+options configure.fflags configure.f90flags configure.fcflags
+options configure.classpath
 # compiler flags section
+default configure.optflags  {-Os}
 default configure.cflags    {${configure.optflags}}
-default configure.cppflags  {-I${prefix}/include}
 default configure.cxxflags  {${configure.optflags}}
 default configure.objcflags {${configure.optflags}}
-default configure.ldflags   {-L${prefix}/lib}
+default configure.cppflags  {-I${prefix}/include}
+default configure.ldflags   {"-L${prefix}/lib -Wl,-headerpad_max_install_names"}
 default configure.libs      {}
 default configure.fflags    {${configure.optflags}}
 default configure.f90flags  {${configure.optflags}}
@@ -143,7 +146,9 @@
 default configure.classpath {}
 
 # tools section
-options configure.perl configure.python configure.ruby configure.install configure.awk configure.bison configure.pkg_config configure.pkg_config_path
+options configure.perl configure.python configure.ruby
+options configure.install configure.awk configure.bison
+options configure.pkg_config configure.pkg_config_path
 default configure.perl              {}
 default configure.python            {}
 default configure.ruby              {}
@@ -154,24 +159,29 @@
 default configure.pkg_config_path   {}
 
 options configure.build_arch configure.ld_archflags configure.sdkroot
-default configure.build_arch {[portconfigure::choose_supported_archs ${build_arch}]}
-default configure.ld_archflags {[portconfigure::configure_get_ld_archflags]}
-default configure.sdkroot {[portconfigure::configure_get_sdkroot]}
+default configure.build_arch    {[portconfigure::choose_supported_archs ${build_arch}]}
+default configure.ld_archflags  {[portconfigure::configure_get_ld_archflags]}
+default configure.sdkroot       {[portconfigure::configure_get_sdkroot]}
 foreach tool {cc cxx objc f77 f90 fc} {
     options configure.${tool}_archflags
     default configure.${tool}_archflags  "\[portconfigure::configure_get_archflags $tool\]"
 }
 
-options configure.universal_archs configure.universal_args configure.universal_cflags configure.universal_cppflags configure.universal_cxxflags configure.universal_ldflags
+options configure.universal_archs configure.universal_args
+options configure.universal_cflags configure.universal_cxxflags
+options configure.universal_cppflags configure.universal_ldflags
 default configure.universal_archs       {[portconfigure::choose_supported_archs ${universal_archs}]}
 default configure.universal_args        {--disable-dependency-tracking}
 default configure.universal_cflags      {[portconfigure::configure_get_universal_cflags]}
+default configure.universal_cxxflags    {[portconfigure::configure_get_universal_cflags]}
 default configure.universal_cppflags    {}
-default configure.universal_cxxflags    {[portconfigure::configure_get_universal_cflags]}
 default configure.universal_ldflags     {[portconfigure::configure_get_universal_ldflags]}
 
 # Select a distinct compiler (C, C preprocessor, C++)
-options configure.ccache configure.distcc configure.pipe configure.cc configure.cxx configure.cpp configure.objc configure.f77 configure.f90 configure.fc configure.javac configure.compiler
+options configure.ccache configure.distcc configure.pipe configure.cc \
+        configure.cxx configure.cpp configure.objc configure.f77 \
+        configure.f90 configure.fc configure.javac configure.compiler \
+        compiler.blacklist compiler.whitelist compiler.fallback
 default configure.ccache        {${configureccache}}
 default configure.distcc        {${configuredistcc}}
 default configure.pipe          {${configurepipe}}
@@ -184,6 +194,9 @@
 default configure.fc            {[portconfigure::configure_get_compiler fc]}
 default configure.javac         {[portconfigure::configure_get_compiler javac]}
 default configure.compiler      {[portconfigure::configure_get_default_compiler]}
+default compiler.fallback       {[portconfigure::get_compiler_fallback]}
+default compiler.blacklist      {}
+default compiler.whitelist      {}
 
 set_ui_prefix
 
@@ -195,44 +208,54 @@
     set name ""
     switch -exact ${configure.compiler} {
         cc { set name "System cc" }
-        gcc { set name "System gcc" }
-        gcc-3.3 { set name "Mac OS X gcc 3.3" }
-        gcc-4.0 { set name "Mac OS X gcc 4.0" }
-        gcc-4.2 { set name "Mac OS X gcc 4.2" }
-        llvm-gcc-4.2 { set name "Mac OS X llvm-gcc 4.2" }
-        clang { set name "Mac OS X clang" }
-        apple-gcc-4.0 { set name "MacPorts Apple gcc 4.0" }
-        apple-gcc-4.2 { set name "MacPorts Apple gcc 4.2" }
-        macports-gcc     { set name "MacPorts gcc (port select)" }
-        macports-gcc-4.0 { set name "MacPorts gcc 4.0" }
-        macports-gcc-4.1 { set name "MacPorts gcc 4.1" }
-        macports-gcc-4.2 { set name "MacPorts gcc 4.2" }
-        macports-gcc-4.3 { set name "MacPorts gcc 4.3" }
-        macports-gcc-4.4 { set name "MacPorts gcc 4.4" }
-        macports-gcc-4.5 { set name "MacPorts gcc 4.5" }
-        macports-gcc-4.6 { set name "MacPorts gcc 4.6" }
-        macports-llvm-gcc-4.2 { set name "MacPorts llvm-gcc 4.2" }
-        macports-clang { set name "MacPorts clang (port select)" }
-        macports-clang-2.9 { set name "MacPorts clang 2.9" }
-        macports-clang-3.0 { set name "MacPorts clang 3.0" }
-        macports-clang-3.1 { set name "MacPorts clang 3.1" }
-        default { return -code error "Invalid value for configure.compiler" }
+        gcc { set name "System GCC" }
+        gcc-3.3 { set name "Mac OS X GCC 3.3" }
+        gcc-4.0 { set name "Mac OS X GCC 4.0" }
+        gcc-4.2 { set name "Mac OS X GCC 4.2" }
+        llvm-gcc-4.2 { set name "Mac OS X LLVM-GCC 4.2" }
+        clang { set name "Mac OS X Clang" }
+        apple-gcc-4.0 { set name "MacPorts Apple GCC 4.0" }
+        apple-gcc-4.2 { set name "MacPorts Apple GCC 4.2" }
+        macports-gcc     { set name "MacPorts GCC (port select)" }
+        macports-llvm-gcc-4.2 { set name "MacPorts LLVM-GCC 4.2" }
+        macports-clang { set name "MacPorts Clang (port select)" }
+        default {
+            if {[regexp {macports-clang-(.*)\.(.*)} ${configure.compiler} -> major minor]} {
+                set name "MacPorts Clang ${major}.${minor}"
+            } elseif {[regexp {macports-dragonegg-(.*)\.(.*)} ${configure.compiler} -> major minor]} {
+                set name "MacPorts DragonEgg ${major}.${minor}"
+            } elseif {[regexp {macports-gcc-(.*)\.(.*)} ${configure.compiler} -> major minor]} {
+                set name "MacPorts GCC ${major}.${minor}"
+            } else {
+                return -code error "Invalid value for configure.compiler: ${configure.compiler}"
+            }
+        }
     }
     ui_debug "Using compiler '$name'"
 
     # Additional ccache directory setup
-    global configureccache ccache_dir ccache_size macportsuser
-    if {${configureccache}} {
+    global configure.ccache ccache_dir ccache_size macportsuser
+    if {${configure.ccache}} {
+        # Create ccache directory with correct permissions with root privileges
         elevateToRoot "configure ccache"
         if [catch {
                 file mkdir ${ccache_dir}
                 file attributes ${ccache_dir} -owner ${macportsuser} -permissions 0755
+            } result] {
+            ui_warn "ccache_dir ${ccache_dir} could not be created; disabling ccache: $result"
+            set configure.ccache no
+        }
+        dropPrivileges
+
+        # Initialize ccache directory with the given maximum size
+        if {${configure.ccache}} {
+            if [catch {
                 exec ccache -M ${ccache_size} >/dev/null
             } result] {
-            ui_warn "ccache_dir ${ccache_dir} could not be initialized; disabling ccache: $result"
-            set configureccache no
+                ui_warn "ccache_dir ${ccache_dir} could not be initialized; disabling ccache: $result"
+                set configure.ccache no
+            }
         }
-        dropPrivileges
     }
 }
 
@@ -271,7 +294,9 @@
     } elseif {[tbool configure.m32]} {
         set flags "-m32"
     } elseif {${configure.build_arch} != ""} {
-        if {[arch_flag_supported] && ($tool == "cc" || $tool == "cxx" || $tool == "objc")} {
+        if {[arch_flag_supported ${configure.compiler}] &&
+            ($tool == "cc" || $tool == "cxx" || $tool == "objc")
+        } then {
             set flags "-arch ${configure.build_arch}"
         } elseif {${configure.build_arch} == "x86_64" || ${configure.build_arch} == "ppc64"} {
             set flags "-m64"
@@ -287,8 +312,8 @@
 # doesn't support -arch, because it could be used to link rather than using
 # ld directly. So we punt and let portfiles deal with that case.
 proc portconfigure::configure_get_ld_archflags {args} {
-    global configure.build_arch
-    if {${configure.build_arch} != "" && [arch_flag_supported]} {
+    global configure.build_arch configure.compiler
+    if {${configure.build_arch} != "" && [arch_flag_supported ${configure.compiler}]} {
         return "-arch ${configure.build_arch}"
     } else {
         return ""
@@ -296,13 +321,18 @@
 }
 
 proc portconfigure::configure_get_sdkroot {} {
-    global developer_dir macosx_deployment_target macosx_version os.arch os.platform
+    global developer_dir macosx_deployment_target macosx_version xcodeversion os.arch os.platform
     if {${os.platform} == "darwin" && ($macosx_deployment_target != $macosx_version
         || (${os.arch} == "powerpc" && $macosx_version == "10.4" && [variant_exists universal] && [variant_isset universal]))} {
+        if {[vercmp $xcodeversion 4.3] < 0} {
+            set sdks_dir "${developer_dir}/SDKs"
+        } else {
+            set sdks_dir "${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs"
+        }
         if {$macosx_deployment_target == "10.4"} {
-            set sdk "${developer_dir}/SDKs/MacOSX10.4u.sdk"
+            set sdk "${sdks_dir}/MacOSX10.4u.sdk"
         } else {
-            set sdk "${developer_dir}/SDKs/MacOSX${macosx_deployment_target}.sdk"
+            set sdk "${sdks_dir}/MacOSX${macosx_deployment_target}.sdk"
         }
         if {[file exists $sdk]} {
             return $sdk
@@ -336,258 +366,267 @@
 }
 
 # internal proc to determine if the compiler supports -arch
-proc portconfigure::arch_flag_supported {args} {
-    global configure.compiler
-    switch -exact ${configure.compiler} {
-        gcc-4.0 -
-        gcc-4.2 -
-        llvm-gcc-4.2 -
-        clang -
-        apple-gcc-4.0 -
-        apple-gcc-4.2 -
-        macports-clang {
-            return yes
+proc portconfigure::arch_flag_supported {compiler} {
+    return [regexp {^gcc-4|llvm|apple|clang} $compiler]
+}
+
+# maps compiler names to the port that provides them
+# TODO: Remove this after 2.2 is released and ports aren't referring to it.
+array set portconfigure::compiler_name_map {
+        apple-gcc-4.0           apple-gcc40
+        apple-gcc-4.2           apple-gcc42
+        macports-gcc-4.2        gcc42
+        macports-gcc-4.3        gcc43
+        macports-gcc-4.4        gcc44
+        macports-gcc-4.5        gcc45
+        macports-gcc-4.6        gcc46
+        macports-gcc-4.7        gcc47
+        macports-gcc-4.8        gcc48
+        macports-llvm-gcc-4.2   llvm-gcc42
+        macports-clang-2.9      clang-2.9
+        macports-clang-3.0      clang-3.0
+        macports-clang-3.1      clang-3.1
+        macports-clang-3.2      clang-3.2
+        macports-clang-3.3      clang-3.3
+        macports-dragonegg-3.0  dragonegg-3.0
+        macports-dragonegg-3.1  dragonegg-3.1
+        macports-dragonegg-3.2  dragonegg-3.2
+        macports-dragonegg-3.3  dragonegg-3.3
+}
+
+proc portconfigure::compiler_port_name {compiler} {
+    if {[regexp {apple-gcc-(.*)\.(.*)} ${compiler} -> major minor]} {
+        return "apple-gcc${major}${minor}"
+    } elseif {[regexp {macports-clang-(.*)\.(.*)} ${compiler} -> major minor]} {
+        return "clang-${major}.${minor}"
+    } elseif {[regexp {macports-dragonegg-(.*)\.(.*)} ${compiler} -> major minor]} {
+        return "dragonegg-${major}.${minor}"
+    } elseif {[regexp {macports-gcc-(.*)\.(.*)} ${compiler} -> major minor]} {
+        return "gcc${major}${minor}"
+    } elseif {[regexp {macports-llvm-gcc-(.*)\.(.*)} ${compiler} -> major minor]} {
+        return "llvm-gcc${major}${minor}"
+    }
+
+    return ""
+}
+
+proc portconfigure::compiler_is_port {compiler} {
+    return [expr {[portconfigure::compiler_port_name ${compiler}] != ""}]
+}
+
+# internal function to determine the default compiler
+proc portconfigure::configure_get_default_compiler {args} {
+    if {[option compiler.whitelist] != {}} {
+        set search_list [option compiler.whitelist]
+    } else {
+        set search_list [option compiler.fallback]
+    }
+    foreach compiler $search_list {
+        set allowed yes
+        foreach pattern [option compiler.blacklist] {
+            if {[string match $pattern $compiler]} {
+                set allowed no
+                break
+            }
         }
-        default {
-            return no
+        if {$allowed &&
+            ([file executable [configure_get_compiler cc $compiler]] ||
+             [compiler_is_port $compiler])
+        } then {
+            return $compiler
         }
     }
+    ui_warn "All compilers are either blacklisted or unavailable; defaulting to first fallback option"
+    return [lindex [option compiler.fallback] 0]
 }
 
-# internal function to determine the default compiler
-proc portconfigure::configure_get_default_compiler {args} {
-    global xcodeversion macosx_deployment_target
-    if {$xcodeversion == "none" || $xcodeversion == ""} {
-        return cc
+# internal function to choose compiler fallback list based on platform
+proc portconfigure::get_compiler_fallback {} {
+    global xcodeversion macosx_deployment_target default_compilers
+    if {[info exists default_compilers]} {
+        return $default_compilers
+    } elseif {$xcodeversion == "none" || $xcodeversion == ""} {
+        return {cc}
+    } elseif {[vercmp $xcodeversion 4.6] >= 0} {
+        return {clang macports-llvm-gcc-4.2 apple-gcc-4.2 macports-clang-3.2}
     } elseif {[vercmp $xcodeversion 4.2] >= 0} {
-        return clang
+        return {clang llvm-gcc-4.2 apple-gcc-4.2 macports-clang-3.2}
     } elseif {[vercmp $xcodeversion 4.0] >= 0} {
-        return llvm-gcc-4.2
-    } elseif {[vercmp $xcodeversion 3.2] >= 0 && $macosx_deployment_target != "10.4"} {
-        return gcc-4.2
+        return {llvm-gcc-4.2 clang gcc-4.2 macports-clang-3.2 apple-gcc-4.2}
+    } elseif {[vercmp $xcodeversion 3.2] >= 0} {
+        if {$macosx_deployment_target == "10.4"} {
+            # It's not the deployment target that is the issue, it's the
+            # 10.4u SDK which base chooses if the deployment_target is set
+            return {gcc-4.0}
+        } else {
+            return {gcc-4.2 clang llvm-gcc-4.2 macports-clang-3.2 macports-llvm-gcc-4.2 apple-gcc-4.2 gcc-4.0}
+        }
+    } elseif {[vercmp $xcodeversion 3.0] >= 0} {
+        return {gcc-4.2 apple-gcc-4.2 gcc-4.0 macports-clang-3.2}
     } else {
-        return gcc-4.0
+        return {gcc-4.0 apple-gcc-4.2 gcc-3.3 macports-clang-3.2}
     }
 }
 
+# Find a developer tool
+proc portconfigure::find_developer_tool {name} {
+	global developer_dir
+
+    # first try /usr/bin since this doesn't move around
+    set toolpath "/usr/bin/${name}"
+    if {[file executable $toolpath]} {
+        return $toolpath
+    }
+
+	# Use xcode's xcrun to find the named tool.
+	if {![catch {exec [findBinary xcrun $portutil::autoconf::xcrun_path] -find ${name}} toolpath]} {
+		return ${toolpath}
+	}
+
+	# If xcrun failed to find the tool, return a path from
+	# the developer_dir.
+	# The tool may not be there, but we'll leave it up to
+	# the invoking code to figure out that it doesn't have
+	# a valid compiler
+	return "${developer_dir}/usr/bin/${name}"
+}
+
+
 # internal function to find correct compilers
-proc portconfigure::configure_get_compiler {type} {
-    global configure.compiler prefix developer_dir
-    set ret ""
-    switch -exact ${configure.compiler} {
-        cc {
-            switch -exact ${type} {
-                cc   { set ret /usr/bin/cc }
-                objc { set ret /usr/bin/cc }
-                cxx  { set ret /usr/bin/c++ }
-                cpp  { set ret /usr/bin/cpp }
-            }
+proc portconfigure::configure_get_compiler {type {compiler {}}} {
+    global configure.compiler prefix
+    if {$compiler == {}} {
+        set compiler ${configure.compiler}
+    }
+    # Tcl 8.4's switch doesn't support -matchvar.
+    if {[regexp {^gcc(-3\.3|-4\.0|-4\.2)?$} $compiler -> suffix]} {
+        switch $type {
+            cc   -
+            objc { return [find_developer_tool "gcc${suffix}"] }
+            cxx  { return [find_developer_tool "g++${suffix}"] }
+            cpp  { return [find_developer_tool "cpp${suffix}"] }
         }
-        gcc {
-            switch -exact ${type} {
-                cc   { set ret /usr/bin/gcc }
-                objc { set ret /usr/bin/gcc }
-                cxx  { set ret /usr/bin/g++ }
-                cpp  { set ret /usr/bin/cpp }
-            }
+    } elseif {[regexp {^llvm-gcc-4\.2$} $compiler]} {
+        switch $type {
+            cc   -
+            objc { return [find_developer_tool llvm-gcc-4.2] }
+            cxx  { return [find_developer_tool llvm-g++-4.2] }
+            cpp  { return [find_developer_tool llvm-cpp-4.2] }
         }
-        gcc-3.3 {
-            switch -exact ${type} {
-                cc   { set ret /usr/bin/gcc-3.3 }
-                objc { set ret /usr/bin/gcc-3.3 }
-                cxx  { set ret /usr/bin/g++-3.3 }
-                cpp  { set ret /usr/bin/cpp-3.3 }
+    } elseif {[regexp {^clang$} $compiler]} {
+        switch $type {
+            cc   -
+            objc { return [find_developer_tool clang] }
+            cxx  {
+                set clangpp [find_developer_tool clang++]
+                if {[file executable $clangpp]} {
+                    return $clangpp
+                }
+                return [find_developer_tool llvm-g++-4.2]
             }
         }
-        gcc-4.0 {
-            switch -exact ${type} {
-                cc   { set ret /usr/bin/gcc-4.0 }
-                objc { set ret /usr/bin/gcc-4.0 }
-                cxx  { set ret /usr/bin/g++-4.0 }
-                cpp  { set ret /usr/bin/cpp-4.0 }
-            }
-        }
-        gcc-4.2 {
-            switch -exact ${type} {
-                cc   { set ret /usr/bin/gcc-4.2 }
-                objc { set ret /usr/bin/gcc-4.2 }
-                cxx  { set ret /usr/bin/g++-4.2 }
-                cpp  { set ret /usr/bin/cpp-4.2 }
-            }
-        }
-        llvm-gcc-4.2 {
-            switch -exact ${type} {
-                cc   { set ret ${developer_dir}/usr/bin/llvm-gcc-4.2 }
-                objc { set ret ${developer_dir}/usr/bin/llvm-gcc-4.2 }
-                cxx  { set ret ${developer_dir}/usr/bin/llvm-g++-4.2 }
-                cpp  { set ret ${developer_dir}/usr/bin/llvm-cpp-4.2 }
-            }
-        }
-        clang {
-            switch -exact ${type} {
-                cc   { set ret ${developer_dir}/usr/bin/clang }
-                objc { set ret ${developer_dir}/usr/bin/clang }
-                cxx  {
-                    if {[file executable ${developer_dir}/usr/bin/clang++]} {
-                        set ret ${developer_dir}/usr/bin/clang++
-                    } else {
-                        set ret ${developer_dir}/usr/bin/llvm-g++-4.2
-                    }
+    } elseif {[regexp {^apple-gcc(-4\.0|-4\.2)$} $compiler -> suffix]} {
+        switch $type {
+            cc   -
+            objc { return ${prefix}/bin/gcc-apple${suffix} }
+            cxx  {
+                if {$suffix == "-4.2"} {
+                    return ${prefix}/bin/g++-apple${suffix}
                 }
             }
+            cpp  { return ${prefix}/bin/cpp-apple${suffix} }
         }
-        apple-gcc-4.0 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-apple-4.0 }
-                objc { set ret ${prefix}/bin/gcc-apple-4.0 }
-                cpp  { set ret ${prefix}/bin/cpp-apple-4.0 }
-            }
+    } elseif {[regexp {^macports-gcc(-\d+\.\d+)?$} $compiler -> suffix]} {
+        if {[string length $suffix]} {
+            set suffix "-mp${suffix}"
         }
-        apple-gcc-4.2 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-apple-4.2 }
-                objc { set ret ${prefix}/bin/gcc-apple-4.2 }
-                cpp  { set ret ${prefix}/bin/cpp-apple-4.2 }
-                cxx  { set ret ${prefix}/bin/g++-apple-4.2 }
-            }
+        switch $type {
+            cc   -
+            objc { return ${prefix}/bin/gcc${suffix} }
+            cxx  { return ${prefix}/bin/g++${suffix} }
+            cpp  { return ${prefix}/bin/cpp${suffix} }
+            fc   -
+            f77  -
+            f90  { return ${prefix}/bin/gfortran${suffix} }
         }
-        macports-gcc {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc }
-                objc { set ret ${prefix}/bin/gcc }
-                cxx  { set ret ${prefix}/bin/g++ }
-                cpp  { set ret ${prefix}/bin/cpp }
-                fc   { set ret ${prefix}/bin/gfortran }
-                f77  { set ret ${prefix}/bin/gfortran }
-                f90  { set ret ${prefix}/bin/gfortran }
-            }
+    } elseif {[regexp {^macports-llvm-gcc-4\.2$} $compiler]} {
+        switch $type {
+            cc   -
+            objc { return ${prefix}/bin/llvm-gcc-4.2 }
+            cxx  { return ${prefix}/bin/llvm-g++-4.2 }
+            cpp  { return ${prefix}/bin/llvm-cpp-4.2 }
         }
-        macports-gcc-4.0 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.0 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.0 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.0 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.0 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.0 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.0 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.0 }
-            }
+    } elseif {[regexp {^macports-clang(-\d+\.\d+)?$} $compiler -> suffix]} {
+        if {[string length $suffix]} {
+            set suffix "-mp${suffix}"
         }
-        macports-gcc-4.1 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.1 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.1 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.1 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.1 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.1 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.1 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.1 }
-            }
+        switch $type {
+            cc   -
+            objc { return ${prefix}/bin/clang${suffix} }
+            cxx  { return ${prefix}/bin/clang++${suffix} }
         }
-        macports-gcc-4.2 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.2 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.2 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.2 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.2 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.2 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.2 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.2 }
-            }
+    } elseif {[regexp {^macports-dragonegg(-\d+\.\d+)$} $compiler -> infix]} {
+        switch $type {
+            cc   -
+            objc { return ${prefix}/bin/dragonegg${infix}-gcc }
+            cxx  { return ${prefix}/bin/dragonegg${infix}-g++ }
+            cpp  { return ${prefix}/bin/dragonegg${infix}-cpp }
+            fc   -
+            f77  -
+            f90  { return ${prefix}/bin/dragonegg${infix}-gfortran }
         }
-        macports-gcc-4.3 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.3 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.3 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.3 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.3 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.3 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.3 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.3 }
-            }
-        }
-        macports-gcc-4.4 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.4 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.4 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.4 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.4 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.4 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.4 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.4 }
-            }
-        }
-        macports-gcc-4.5 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.5 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.5 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.5 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.5 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.5 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.5 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.5 }
-            }
-        }
-        macports-gcc-4.6 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/gcc-mp-4.6 }
-                objc { set ret ${prefix}/bin/gcc-mp-4.6 }
-                cxx  { set ret ${prefix}/bin/g++-mp-4.6 }
-                cpp  { set ret ${prefix}/bin/cpp-mp-4.6 }
-                fc   { set ret ${prefix}/bin/gfortran-mp-4.6 }
-                f77  { set ret ${prefix}/bin/gfortran-mp-4.6 }
-                f90  { set ret ${prefix}/bin/gfortran-mp-4.6 }
-            }
-        }
-        macports-llvm-gcc-4.2 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/llvm-gcc-4.2 }
-                objc { set ret ${prefix}/bin/llvm-gcc-4.2 }
-                cxx  { set ret ${prefix}/bin/llvm-g++-4.2 }
-                cpp  { set ret ${prefix}/bin/llvm-cpp-4.2 }
-                fc   { set ret ${prefix}/bin/llvm-gfortran-4.2 }
-                f77  { set ret ${prefix}/bin/llvm-gfortran-4.2 }
-                f90  { set ret ${prefix}/bin/llvm-gfortran-4.2 }
-            }
-        }
-        macports-clang {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/clang }
-                objc { set ret ${prefix}/bin/clang }
-                cxx  { set ret ${prefix}/bin/clang++ }
-            }
-        }
-        macports-clang-2.9 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/clang-mp-2.9 }
-                objc { set ret ${prefix}/bin/clang-mp-2.9 }
-                cxx  { set ret ${prefix}/bin/clang++-mp-2.9 }
-            }
-        }
-        macports-clang-3.0 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/clang-mp-3.0 }
-                objc { set ret ${prefix}/bin/clang-mp-3.0 }
-                cxx  { set ret ${prefix}/bin/clang++-mp-3.0 }
-            }
-        }
-        macports-clang-3.1 {
-            switch -exact ${type} {
-                cc   { set ret ${prefix}/bin/clang-mp-3.1 }
-                objc { set ret ${prefix}/bin/clang-mp-3.1 }
-                cxx  { set ret ${prefix}/bin/clang++-mp-3.1 }
-            }
-        }
     }
-    return $ret
+    # Fallbacks
+    switch $type {
+        cc   -
+        objc { return [find_developer_tool cc] }
+        cxx  { return [find_developer_tool c++] }
+        cpp  { return [find_developer_tool cpp] }
+    }
+    return ""
 }
 
+# Automatically called from macports1.0 after evaluating the Portfile
+# Some of the compilers we use are provided by MacPorts itself; ensure we
+# automatically add a dependency when needed
+proc portconfigure::add_automatic_compiler_dependencies {} {
+    global configure.compiler
+
+    # The default value requires substitution before use.
+    set compiler [subst ${configure.compiler}]
+    if {![compiler_is_port $compiler]} {
+        return
+    }
+
+    ui_debug "Chosen compiler ${compiler} is provided by a port, adding dependency"
+
+    set compiler_port [portconfigure::compiler_port_name ${compiler}]
+    set deptype "build"
+    if {[string first "macports-gcc-" $compiler] == 0} {
+        set deptype "lib"
+    }
+    ui_debug "Adding depends_${deptype} port:$compiler_port"
+    depends_${deptype}-delete port:$compiler_port
+    depends_${deptype}-append port:$compiler_port
+
+    if {[arch_flag_supported $compiler]} {
+        ui_debug "Adding depends_skip_archcheck $compiler_port"
+        depends_skip_archcheck-delete $compiler_port
+        depends_skip_archcheck-append $compiler_port
+    }
+}
+# Register the above procedure as a callback after Portfile evaluation
+port::register_callback portconfigure::add_automatic_compiler_dependencies
+
 proc portconfigure::configure_main {args} {
     global [info globals]
     global worksrcpath use_configure use_autoreconf use_autoconf use_automake use_xmkmf
     global configure.env configure.pipe configure.libs configure.classpath configure.universal_args
-    global configure.perl configure.python configure.ruby configure.install configure.awk configure.bison configure.pkg_config configure.pkg_config_path
-    global configure.ccache configure.distcc configure.cpp configure.javac configure.march configure.mtune configure.sdkroot
+    global configure.perl configure.python configure.ruby configure.install configure.awk configure.bison
+    global configure.pkg_config configure.pkg_config_path
+    global configure.ccache configure.distcc configure.cpp configure.javac configure.sdkroot
+    global configure.march configure.mtune
+    global os.platform os.major
     foreach tool {cc cxx objc f77 f90 fc ld} {
         global configure.${tool} configure.${tool}_archflags
     }
@@ -614,13 +653,17 @@
     }
 
     if {[tbool use_xmkmf]} {
+        parse_environment xmkmf
+        append_list_to_environment_value xmkmf "IMAKECPP" ${configure.cpp}
         if {[catch {command_exec xmkmf} result]} {
             return -code error "[format [msgcat::mc "%s failure: %s"] xmkmf $result]"
-        } else {
-            # XXX should probably use make command abstraction but we know that
-            # X11 will already set things up so that "make Makefiles" always works.
-            system "cd ${worksrcpath} && make Makefiles"
         }
+
+        parse_environment xmkmf
+        append_list_to_environment_value xmkmf "IMAKECPP" ${configure.cpp}
+        if {[catch {command_exec "cd ${worksrcpath} && make Makefiles" -varprefix xmkmf} result]} {
+            return -code error "[format [msgcat::mc "%s failure: %s"] "make Makefiles" $result]"
+        }
     } elseif {[tbool use_configure]} {
         # Merge (ld|c|cpp|cxx)flags into the environment variable.
         parse_environment configure
@@ -671,6 +714,11 @@
         append_list_to_environment_value configure "PKG_CONFIG" ${configure.pkg_config}
         append_list_to_environment_value configure "PKG_CONFIG_PATH" ${configure.pkg_config_path}
 
+        # https://trac.macports.org/ticket/34221
+        if {${os.platform} == "darwin" && ${os.major} == 12} {
+            append_list_to_environment_value configure "__CFPREFERENCES_AVOID_DAEMON" 1
+        }
+
         # add SDK flags if cross-compiling (or universal on ppc tiger)
         if {${configure.sdkroot} != ""} {
             foreach flags {CPPFLAGS CFLAGS CXXFLAGS OBJCFLAGS} {

Modified: branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portdestroot.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
 # Copyright (c) 2004 - 2005 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2004-2005, 2007-2011 The MacPorts Project
+# Copyright (c) 2004-2005, 2007-2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -48,12 +48,12 @@
 
 # define options
 options destroot.target destroot.destdir destroot.clean destroot.keepdirs destroot.umask
-options destroot.violate_mtree destroot.asroot
+options destroot.violate_mtree destroot.asroot destroot.delete_la_files
 options startupitem.create startupitem.requires startupitem.init
 options startupitem.name startupitem.start startupitem.stop startupitem.restart
 options startupitem.type startupitem.executable
 options startupitem.pidfile startupitem.logfile startupitem.logevents startupitem.netchange
-options startupitem.uniquename startupitem.plist startupitem.location
+options startupitem.uniquename startupitem.plist startupitem.location startupitem.install
 commands destroot
 
 # Set defaults
@@ -69,6 +69,7 @@
 default destroot.clean no
 default destroot.keepdirs ""
 default destroot.violate_mtree no
+default destroot.delete_la_files no
 
 default startupitem.name        {${subport}}
 default startupitem.uniquename  {org.macports.${startupitem.name}}
@@ -85,11 +86,13 @@
 default startupitem.logfile     ""
 default startupitem.logevents   no
 default startupitem.netchange   no
+default startupitem.install     {$system_options(startupitem_install)}
 
 set_ui_prefix
 
 proc portdestroot::destroot_getargs {args} {
-    if {((![exists build.type] && [option os.platform] != "freebsd") || ([exists build.type] && [option build.type] == "gnu")) \
+    if {(([option build.type] == "default" && [option os.platform] != "freebsd") || \
+         ([option build.type] == "gnu")) \
         && [regexp "^(/\\S+/|)(g|gnu|)make(\\s+.*|)$" [option destroot.cmd]]} {
         # Print "Entering directory" lines for better log debugging
         return "-w [option destroot.target]"
@@ -112,8 +115,8 @@
         ui_debug "Can't run destroot under sudo without elevated privileges (due to mtree)."
         ui_debug "Run destroot without sudo to avoid root privileges."
         ui_debug "Going to escalate privileges back to root."
+        seteuid $euid
         setegid $egid
-        seteuid $euid
         ui_debug "euid changed to: [geteuid]. egid changed to: [getegid]."
     }
 
@@ -147,7 +150,7 @@
 
 proc portdestroot::destroot_finish {args} {
     global UI_PREFIX destroot prefix subport startupitem.create destroot.violate_mtree
-    global applications_dir frameworks_dir destroot.keepdirs
+    global applications_dir frameworks_dir destroot.keepdirs destroot.delete_la_files
     global os.platform os.version
     variable oldmask
 
@@ -164,6 +167,28 @@
         }
     }
 
+    # Prevent overlinking due to glibtool .la files: https://trac.macports.org/ticket/38010
+    ui_debug "Fixing glibtool .la files in destroot for ${subport}"
+    fs-traverse -depth fullpath ${destroot} {
+        if {[file extension $fullpath] == ".la" && [file type $fullpath] == "file"} {
+            # Make sure it is from glibtool ... "a libtool library file" will appear in the first line
+            if {![catch {set fp [open $fullpath]}]} {
+                if {[gets $fp line] > 0 && [string first "a libtool library file" $line] != -1} {
+                    if {${destroot.delete_la_files}} {
+                        ui_debug "Removing [file tail $fullpath]"
+                        file delete -force ${fullpath}
+                    } else {
+                        ui_debug "Clearing dependency_libs in [file tail $fullpath]"
+                        reinplace "/dependency_libs/ s/'.*'/''/" ${fullpath}
+                    }
+                }
+            } else {
+                ui_debug "Failed to open $fullpath"
+            }
+            catch {close $fp}
+        }
+    }
+
     # Prune empty directories in ${destroot}
     foreach path ${destroot.keepdirs} {
         if {![file isdirectory ${path}]} {

Modified: branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portdistcheck.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -91,7 +91,7 @@
                         ui_warn "couldn't fetch $file_url for $subport ($error)"
                     } else {
                         if {$urlnewer} {
-                            ui_warn "port $subport: $file_url is newer than portfile"
+                            ui_warn "port $subport: $file_url is newer than Portfile"
                         }
                         incr count
                     }

Modified: branches/gsoc11-statistics/base/src/port1.0/portextract.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portextract.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portextract.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portextract.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007-2011 The MacPorts Project
+# Copyright (c) 2005, 2007-2011, 2013 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # Copyright (c) 2007 Markus W. Weissmann <mww at macports.org>
 # All rights reserved.
@@ -108,12 +108,12 @@
         set dmg_mount [mkdtemp "/tmp/mports.XXXXXXXX"]
         option extract.cmd [findBinary hdiutil ${portutil::autoconf::hdiutil_path}]
         option extract.pre_args attach
-        option extract.post_args "-private -readonly -nobrowse -mountpoint \\\"${dmg_mount}\\\" && [findBinary cp ${portutil::autoconf::cp_path}] -Rp \\\"${dmg_mount}\\\" \\\"${extract.dir}/${distname}\\\" && ${extract.cmd} detach \\\"${dmg_mount}\\\" && [findBinary rmdir ${portutil::autoconf::rmdir_path}] \\\"${dmg_mount}\\\""
+        option extract.post_args "-private -readonly -nobrowse -mountpoint \\\"${dmg_mount}\\\" && cd \\\"${dmg_mount}\\\" && [findBinary find ${portutil::autoconf::find_path}] . -depth -perm -+r -print0 | [findBinary cpio ${portutil::autoconf::cpio_path}] -0 -p -d -m -u \\\"${extract.dir}/${distname}\\\"; status=\$?; cd / && ${extract.cmd} detach \\\"${dmg_mount}\\\" && [findBinary rmdir ${portutil::autoconf::rmdir_path}] \\\"${dmg_mount}\\\"; exit \$status"
     }
 }
 
 proc portextract::extract_main {args} {
-    global UI_PREFIX filespath worksrcpath extract.dir usealtworkpath altprefix
+    global UI_PREFIX filespath worksrcpath extract.dir usealtworkpath altprefix use_dmg
 
     if {![exists distfiles] && ![exists extract.only]} {
         # nothing to do
@@ -129,14 +129,25 @@
         } else {
             option extract.args "'[option distpath]/$distfile'"
         }
-        if {[catch {command_exec extract} result]} {
+
+        # If the MacPorts user does not have the privileges to mount a
+        # DMG then hdiutil will fail with this error:
+        #   hdiutil: attach failed - Device not configured
+        # So elevate back to root.
+        if {[tbool use_dmg]} {
+            elevateToRoot {extract dmg}
+        }
+        set code [catch {command_exec extract} result]
+        if {[tbool use_dmg]} {
+            dropPrivileges
+        }
+        if {$code} {
             return -code error "$result"
         }
 
-    # start gsoc08-privileges
-    chownAsRoot ${extract.dir}
-    # end gsoc08-privileges
-
+        # start gsoc08-privileges
+        chownAsRoot ${extract.dir}
+        # end gsoc08-privileges
     }
     return 0
 }

Modified: branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portfetch.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portfetch.tcl
 # $Id$
 #
-# Copyright (c) 2004 - 2011 The MacPorts Project
+# Copyright (c) 2004 - 2012 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
@@ -279,11 +279,40 @@
 
 # Perform a bzr fetch
 proc portfetch::bzrfetch {args} {
-    global patchfiles
-    if {[catch {command_exec bzr "" "2>&1"} result]} {
-        return -code error [msgcat::mc "Bazaar checkout failed"]
+    global env patchfiles
+
+    # Behind a proxy bzr will fail with the following error if proxies
+    # listed in macports.conf appear in the environment in their
+    # unmodified form:
+    #   bzr: ERROR: Invalid url supplied to transport:
+    #   "proxy.example.com:8080": No host component
+    # Set the "http_proxy" and "HTTPS_PROXY" environmental variables
+    # to valid URLs by prepending "http://" and appending "/".
+    if {   [info exists env(http_proxy)]
+        && [string compare -length 7 {http://} $env(http_proxy)] != 0} {
+        set orig_http_proxy $env(http_proxy)
+        set env(http_proxy) http://${orig_http_proxy}/
     }
 
+    if {   [info exists env(HTTPS_PROXY)]
+        && [string compare -length 7 {http://} $env(HTTPS_PROXY)] != 0} {
+        set orig_https_proxy $env(HTTPS_PROXY)
+        set env(HTTPS_PROXY) http://${orig_https_proxy}/
+    }
+
+    try {
+        if {[catch {command_exec bzr "" "2>&1"} result]} {
+            return -code error [msgcat::mc "Bazaar checkout failed"]
+        }
+    } finally {
+        if ([info exists orig_http_proxy]) {
+            set env(http_proxy) ${orig_http_proxy}
+        }
+        if ([info exists orig_https_proxy]) {
+            set env(HTTPS_PROXY) ${orig_https_proxy}
+        }
+    }
+
     if {[info exists patchfiles]} {
         return [portfetch::fetchfiles]
     }
@@ -337,6 +366,31 @@
     return 0
 }
 
+# Given a URL to a Subversion repository, if the URL is http:// or
+# https:// and MacPorts has been configured with a proxy for that URL
+# type, then return command line options that should be passed to the
+# svn command line client to enable use of that proxy.  There are no
+# proxies for Subversion's native protocol, identified by svn:// URLs.
+proc portfetch::svn_proxy_args {url} {
+    global env
+
+    if {   [string compare -length 7 {http://} ${url}] == 0
+        && [info exists env(http_proxy)]} {
+        set proxy_str $env(http_proxy)
+    } elseif {   [string compare -length 8 {https://} ${url}] == 0
+              && [info exists env(HTTPS_PROXY)]} {
+        set proxy_str $env(HTTPS_PROXY)
+    } else {
+        return ""
+    }
+    regexp {(.*://)?([[:alnum:].-]+)(:(\d+))?} $proxy_str - - proxy_host - proxy_port
+    set ret "--config-option servers:global:http-proxy-host=${proxy_host}"
+    if {$proxy_port != ""} {
+        append ret " --config-option servers:global:http-proxy-port=${proxy_port}"
+    }
+    return $ret
+}
+
 # Perform an svn fetch
 proc portfetch::svnfetch {args} {
     global svn.args svn.method svn.revision svn.url patchfiles
@@ -348,8 +402,11 @@
     if {[string length ${svn.revision}]} {
         append svn.url "@${svn.revision}"
     }
-    set svn.args "${svn.method} ${svn.args} ${svn.url}"
 
+    set proxy_args [svn_proxy_args ${svn.url}]
+
+    set svn.args "${svn.method} ${svn.args} ${proxy_args} ${svn.url}"
+
     if {[catch {command_exec svn "" "2>&1"} result]} {
         return -code error [msgcat::mc "Subversion check out failed"]
     }
@@ -395,10 +452,15 @@
 
 # Perform a mercurial fetch.
 proc portfetch::hgfetch {args} {
-    global worksrcpath prefix_frozen patchfiles
-    global hg.url hg.tag hg.cmd
+    global worksrcpath prefix_frozen patchfiles hg.url hg.tag hg.cmd \
+           fetch.ignore_sslcert
 
-    set cmdstring "${hg.cmd} clone --rev ${hg.tag} ${hg.url} ${worksrcpath} 2>&1"
+    set insecureflag ""
+    if {${fetch.ignore_sslcert}} {
+        set insecureflag " --insecure"
+    }
+
+    set cmdstring "${hg.cmd} clone${insecureflag} --rev \"${hg.tag}\" ${hg.url} ${worksrcpath} 2>&1"
     ui_debug "Executing: $cmdstring"
     if {[catch {system $cmdstring} result]} {
         return -code error [msgcat::mc "Mercurial clone failed"]
@@ -470,7 +532,7 @@
                     set fetched 1
                     break
                 } else {
-                    ui_debug "[msgcat::mc "Fetching failed:"]: $result"
+                    ui_debug "[msgcat::mc "Fetching distfile failed"]: $result"
                     file delete -force "${distpath}/${distfile}.TMP"
                 }
             }
@@ -514,22 +576,30 @@
 proc portfetch::fetch_start {args} {
     global UI_PREFIX subport distpath
 
-    ui_notice "$UI_PREFIX [format [msgcat::mc "Fetching %s"] $subport]"
+    ui_notice "$UI_PREFIX [format [msgcat::mc "Fetching distfiles for %s"] $subport]"
 
     # create and chown $distpath
     if {![file isdirectory $distpath]} {
         if {[catch {file mkdir $distpath} result]} {
             elevateToRoot "fetch"
-            set elevated yes
             if {[catch {file mkdir $distpath} result]} {
                 return -code error [format [msgcat::mc "Unable to create distribution files path: %s"] $result]
             }
+            chownAsRoot $distpath
+            dropPrivileges
         }
     }
-    chownAsRoot $distpath
-    if {[info exists elevated] && $elevated == yes} {
-        dropPrivileges
+    if {![file owned $distpath]} {
+        if {[catch {chownAsRoot $distpath} result]} {
+            if {[file writable $distpath]} {
+                ui_warn "$UI_PREFIX [format [msgcat::mc "Couldn't change ownership of distribution files path to macports user: %s"] $result]"
+            } else {
+                return -code error [format [msgcat::mc "Distribution files path %s not writable and could not be chowned: %s"] $distpath $result]
+            }
+        }
     }
+
+    portfetch::check_dns
 }
 
 # Main fetch routine

Modified: branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portinstall.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 2002 - 2004 Apple Inc.
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2005, 2007 - 2011 The MacPorts Project
+# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -94,21 +94,6 @@
 	return $rval
 }
 
-proc portinstall::putel { fd el data } {
-    # Quote xml data
-    set quoted [string map  { & &amp; < &lt; > &gt; } $data]
-    # Write the element
-    puts $fd "<${el}>${quoted}</${el}>"
-}
-
-proc portinstall::putlist { fd listel itemel list } {
-    puts $fd "<$listel>"
-    foreach item $list {
-        putel $fd $itemel $item
-    }
-    puts $fd "</$listel>"
-}
-
 proc portinstall::create_archive {location archive.type} {
     global workpath destpath portpath subport version revision portvariants \
            epoch os.platform PortInfo installPlist \
@@ -200,22 +185,6 @@
                 return -code error "No '$xar' was found on this system!"
             }
         }
-        xpkg {
-            set xar "xar"
-            set compression "bzip2"
-            set archive.meta yes
-            set archive.metaname "xpkg"
-            set archive.metapath [file join $workpath "${archive.metaname}.xml"]
-            if {[catch {set xar [findBinary $xar ${portutil::autoconf::xar_path}]} errmsg] == 0} {
-                ui_debug "Using $xar"
-                set archive.cmd "$xar"
-                set archive.pre_args "-cv --exclude='\./\+.*' --compression=${compression} -n ${archive.metaname} -s ${archive.metapath} -f"
-                set archive.args "${location} ."
-            } else {
-                ui_debug $errmsg
-                return -code error "No '$xar' was found on this system!"
-            }
-        }
         zip {
             set zip "zip"
             if {[catch {set zip [findBinary $zip ${portutil::autoconf::zip_path}]} errmsg] == 0} {
@@ -298,12 +267,12 @@
                  set depname [lindex [split $depspec :] end]
                  set dep [mport_lookup $depname]
                  if {[llength $dep] < 2} {
-                     ui_error "Dependency $dep not found"
+                     ui_debug "Dependency $depname not found"
                  } else {
                      array set portinfo [lindex $dep 1]
                      set depver $portinfo(version)
                      set deprev $portinfo(revision)
-                     puts $fd "@pkgdep ${depname}-${depver}_${deprev}"
+                     puts $fd "@pkgdep $portinfo(name)-${depver}_${deprev}"
                  }
              }
          }
@@ -334,77 +303,6 @@
     }
     close $fd
 
-    # the XML package metadata, for XAR package
-    # (doesn't contain any file list/checksums)
-    if {[tbool archive.meta]} {
-        set sd [open ${archive.metapath} w]
-        puts $sd "<xpkg version='0.2'>"
-        # TODO: split contents into <buildinfo> (new) and <package> (current)
-        #       see existing <portpkg> for the matching source package layout
-
-        putel $sd name ${subport}
-        putel $sd epoch ${epoch}
-        putel $sd version ${version}
-        putel $sd revision ${revision}
-        putel $sd major 0
-        putel $sd minor 0
-
-        putel $sd platform ${os.platform}
-        if {[llength [get_canonical_archs]] > 1} {
-            putlist $sd archs arch [get_canonical_archs]
-        } else {
-            putel $sd arch [get_canonical_archs]
-        }
-        putlist $sd variants variant $vlist
-
-        if {[exists categories]} {
-            set primary [lindex [split [option categories] " "] 0]
-            putel $sd category $primary
-        }
-        if {[exists description]} {
-            putel $sd comment "[option description]"
-        }
-        if {[exists long_description]} {
-            putel $sd desc "[option long_description]"
-        }
-        if {[exists homepage]} {
-            putel $sd homepage "[option homepage]"
-        }
-
-            # Emit dependencies provided by this package
-            puts $sd "<provides>"
-                puts $sd "<item>"
-                putel $sd name $subport
-                putel $sd major 0
-                putel $sd minor 0
-                puts $sd "</item>"
-            puts $sd "</provides>"
-
-
-            # Emit build, library, and runtime dependencies
-            puts $sd "<requires>"
-            foreach {key type} {
-                depends_fetch "fetch"
-                depends_extract "extract"
-                depends_build "build"
-                depends_lib "library"
-                depends_run "runtime"
-            } {
-                if {[info exists $key]} {
-                    set depname [lindex [split [set $key] :] end]
-                    puts $sd "<item type=\"$type\">"
-                    putel $sd name $depname
-                    putel $sd major 0
-                    putel $sd minor 0
-                    puts $sd "</item>"
-                }
-            }
-            puts $sd "</requires>"
-
-        puts $sd "</xpkg>"
-        close $sd
-    }
-
     # Now create the archive
     ui_debug "Creating [file tail $location]"
     command_exec archive
@@ -423,28 +321,24 @@
     switch -- $type {
         tbz -
         tbz2 {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOj${qflag}f $location +CONTENTS]
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOj${qflag}f $location ./+CONTENTS]
         }
         tgz {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOz${qflag}f $location +CONTENTS]
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xOz${qflag}f $location ./+CONTENTS]
         }
         tar {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location +CONTENTS]
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location ./+CONTENTS]
         }
         txz {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location --use-compress-program [findBinary xz ""] +CONTENTS]
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location --use-compress-program [findBinary xz ""] ./+CONTENTS]
         }
         tlz {
-            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location --use-compress-program [findBinary lzma ""] +CONTENTS]
+            set raw_contents [exec [findBinary tar ${portutil::autoconf::tar_path}] -xO${qflag}f $location --use-compress-program [findBinary lzma ""] ./+CONTENTS]
         }
         xar {
             system "cd ${workpath} && [findBinary xar ${portutil::autoconf::xar_path}] -xf $location +CONTENTS"
             set twostep 1
         }
-        xpkg {
-            system "cd ${workpath} && [findBinary xar ${portutil::autoconf::xar_path}] -xf $location --compression=bzip2 +CONTENTS"
-            set twostep 1
-        }
         zip {
             set raw_contents [exec [findBinary unzip ${portutil::autoconf::unzip_path}] -p $location +CONTENTS]
         }
@@ -491,19 +385,22 @@
         set oldpwd $portpath
     }
 
-    # throws an error if an unsupported value has been configured
-    archiveTypeIsSupported $portarchivetype
-
     set location [get_portimage_path]
-    if {![file isfile $location]} {
+    set archive_path [find_portarchive_path]
+    if {$archive_path != ""} {
+        set install_dir [file dirname $location]
+        file mkdir $install_dir
+        file rename -force $archive_path $install_dir
+        set location [file join $install_dir [file tail $archive_path]]
+        set current_archive_type [string range [file extension $location] 1 end]
+        set installPlist [extract_contents $location $current_archive_type]
+    } else {
+        # throws an error if an unsupported value has been configured
+        archiveTypeIsSupported $portarchivetype
         # create archive from the destroot
         create_archive $location $portarchivetype
     }
 
-    if {![info exists installPlist]} {
-        set installPlist [extract_contents $location $portarchivetype]
-    }
-
     # can't do this inside the write transaction due to deadlock issues with _get_dep_port
     set dep_portnames [list]
     foreach deplist {depends_lib depends_run} {

Modified: branches/gsoc11-statistics/base/src/port1.0/portlint.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portlint.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portlint.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -191,7 +191,7 @@
 
         if {[string match "PortSystem*" $line]} {
             if {$seen_portsystem} {
-                ui_error "Line $lineno repeats PortSystem information"
+                ui_error "Line $lineno repeats PortSystem declaration"
                 incr errors
             }
             regexp {PortSystem\s+([0-9.]+)} $line -> portsystem
@@ -204,16 +204,17 @@
             set require_after "PortSystem"
         }
         if {[string match "PortGroup*" $line]} {
-            regexp {PortGroup\s+([a-z0-9]+)\s+([0-9.]+)} $line -> portgroup portgroupversion
+            regexp {PortGroup\s+([a-z0-9_]+)\s+([0-9.]+)} $line -> portgroup portgroupversion
             if {![info exists portgroup]} {
                 ui_error "Line $lineno has unrecognized PortGroup"
                 incr errors
-            }
-            if {[info exists portgroups($portgroup)]} {
-                ui_error "Line $lineno repeats PortGroup information"
-                incr errors
             } else {
-                set portgroups($portgroup) $portgroupversion
+                if {[info exists portgroups($portgroup)]} {
+                    ui_error "Line $lineno repeats inclusion of PortGroup $portgroup"
+                    incr errors
+                } else {
+                    set portgroups($portgroup) $portgroupversion
+                }
             }
             set seen_portgroup true
             set require_blank true
@@ -250,6 +251,11 @@
             }
         }
 
+        if {[string match "*adduser*" $line]} {
+            ui_warn "Line $lineno calling adduser directly; consider setting add_users instead"
+            incr warnings
+        }
+
         if {[regexp {(^|\s)configure\s+\{\s*\}} $line]} {
             ui_warn "Line $lineno should say \"use_configure no\" instead of declaring an empty configure phase"
             incr warnings
@@ -286,16 +292,13 @@
 
     ###################################################################
 
-    global os.platform os.arch os.version
-    global version revision epoch
+    global os.platform os.arch os.version version revision epoch \
+           description long_description platforms categories all_variants \
+           maintainers license homepage master_sites checksums patchfiles \
+           depends_fetch depends_extract depends_lib depends_build \
+           depends_run distfiles fetch.type lint_portsystem lint_platforms \
+           lint_required lint_optional
     set portarch [get_canonical_archs]
-    global description long_description platforms categories all_variants
-    global maintainers license homepage master_sites checksums patchfiles
-    global depends_fetch depends_extract depends_lib depends_build depends_run distfiles fetch.type
-    global livecheck.type subport name
-    
-    global lint_portsystem lint_platforms
-    global lint_required lint_optional
 
     if (!$seen_portsystem) {
         ui_error "Didn't find PortSystem specification"
@@ -491,17 +494,23 @@
         incr errors
     }
 
-    if {[string match "*darwinports at opendarwin.org*" $maintainers]} {
-        ui_warn "Using legacy email address for no/open maintainer"
-        incr warnings
+    foreach addr $maintainers {
+        if {$addr == "nomaintainer at macports.org" ||
+                $addr == "openmaintainer at macports.org"} {
+            ui_warn "Using full email address for no/open maintainer"
+            incr warnings
+        } elseif [regexp "^(.+)@macports.org$" $addr -> localpart] {
+            ui_warn "Maintainer email address for $localpart includes @macports.org"
+            incr warnings
+        } elseif {$addr == "darwinports at opendarwin.org"} {
+            ui_warn "Using legacy email address for no/open maintainer"
+            incr warnings
+        } elseif [regexp "^(.+)@(.+)$" $addr -> localpart domain] {
+            ui_warn "Maintainer email address should be obfuscated as $domain:$localpart"
+            incr warnings
+        }
     }
 
-    if {[string match "*nomaintainer at macports.org*" $maintainers] ||
-        [string match "*openmaintainer at macports.org*" $maintainers]} {
-        ui_warn "Using full email address for no/open maintainer"
-        incr warnings
-    }
-
     if {$license == "unknown"} {
         ui_warn "no license set"
         incr warnings
@@ -535,30 +544,22 @@
                 }
             }
 
-            # BSD-2 => BSD
             if {[string equal -nocase "BSD-2" $test]} {
+                # BSD-2 => BSD
                 ui_error "Invalid license '${test}': use BSD instead"
-            }
-    
-            # BSD-3 => BSD
-            if {[string equal -nocase "BSD-3" $test]} {
+            } elseif {[string equal -nocase "BSD-3" $test]} {
+                # BSD-3 => BSD
                 ui_error "Invalid license '${test}': use BSD instead"
-            }
-    
-            # BSD-4 => BSD-old
-            if {[string equal -nocase "BSD-4" $test]} {
+            } elseif {[string equal -nocase "BSD-4" $test]} {
+                # BSD-4 => BSD-old
                 ui_error "Invalid license '${test}': use BSD-old instead"
             }
-    
+
             set prev $test
         }
 
     }
 
-    if {$subport != $name && ${livecheck.type} != "none"} {
-        ui_warn "livecheck set for subport $subport"
-    }
-
     # these checks are only valid for ports stored in the regular tree directories
     if {[info exists category] && $portcatdir != $category} {
         ui_error "Portfile parent directory $portcatdir does not match primary category $category"
@@ -606,8 +607,35 @@
     ui_debug "Version: $version"
     ui_debug "Revision: $revision"
     ui_debug "Archs: $portarch"
+
     ###################################################################
 
+    set svn_cmd ""
+    catch {set svn_cmd [findBinary svn]}
+    if {$svn_cmd != "" && ([file exists $portpath/.svn] || ![catch {exec $svn_cmd info $portpath > /dev/null 2>@1}])} {
+        ui_debug "Checking svn properties"
+        if [catch {exec $svn_cmd propget svn:keywords $portfile 2>@1} output] {
+            ui_warn "Unable to check for svn:keywords property: $output"
+        } else {
+            ui_debug "Property svn:keywords is \"$output\", should be \"Id\""
+            if {$output != "Id"} {
+                ui_error "Missing subversion property on Portfile, please execute: svn ps svn:keywords Id Portfile"
+                incr errors
+            }
+        }
+        if [catch {exec $svn_cmd propget svn:eol-style $portfile 2>@1} output] {
+            ui_warn "Unable to check for svn:eol-style property: $output"
+        } else {
+            ui_debug "Property svn:eol-style is \"$output\", should be \"native\""
+            if {$output != "native"} {
+                ui_error "Missing subversion property on Portfile, please execute: svn ps svn:eol-style native Portfile"
+                incr errors
+            }
+        }
+    }
+
+    ###################################################################
+
     ui_notice "$UI_PREFIX [format [msgcat::mc "%d errors and %d warnings found."] $errors $warnings]"
 
     return {$errors > 0}

Modified: branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portlivecheck.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -87,9 +87,9 @@
         return -code 1 "No available types were found. Check '$types_dir'."
     }
 
-    # Convert available_types from a list of files (e.g., { freshmeat.tcl
+    # Convert available_types from a list of files (e.g., { freecode.tcl
     # gnu.tcl ... }) into a string in the format "type|type|..." (e.g.,
-    # "freshmeat|gnu|...").
+    # "freecode|gnu|...").
     set available_types [regsub -all {\.tcl} [join $available_types |] {}]
 
     if {${livecheck.type} eq "default"} {
@@ -177,7 +177,7 @@
                                 set updated_version $upver
                             }
                             ui_debug "The regex matched \"$matched\", extracted \"$upver\""
-                            lassign $offsets firstoff lastoff
+                            set lastoff [lindex $offsets end]
                         }
                     }
                     if {$foundmatch == 1} {

Modified: branches/gsoc11-statistics/base/src/port1.0/portload.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portload.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portload.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
 # et:ts=4
-# portsubmit.tcl
+# portload.tcl
 # $Id$
 #
 # Copyright (c) 2007, 2009, 2011 The MacPorts Project

Modified: branches/gsoc11-statistics/base/src/port1.0/portmain.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portmain.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portmain.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -2,7 +2,7 @@
 # portmain.tcl
 # $Id$
 #
-# Copyright (c) 2004 - 2005, 2007 - 2011 The MacPorts Project
+# Copyright (c) 2004 - 2005, 2007 - 2012 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
@@ -44,6 +44,8 @@
 namespace eval portmain {
 }
 
+set_ui_prefix
+
 # define options
 options prefix name version revision epoch categories maintainers \
         long_description description homepage notes license \
@@ -53,9 +55,9 @@
         platforms default_variants install.user install.group \
         macosx_deployment_target universal_variant os.universal_supported \
         supported_archs depends_skip_archcheck installs_libs \
-        copy_log_files \
+        license_noconflict copy_log_files \
         compiler.cpath compiler.library_path \
-        add_users
+        add_users altprefix
 
 # Order of option_proc and option_export matters. Filter before exporting.
 
@@ -65,7 +67,7 @@
 option_proc notes handle_option_string
 
 # Export options via PortInfo
-options_export name version revision epoch categories maintainers platforms description long_description notes homepage license provides conflicts replaced_by installs_libs
+options_export name version revision epoch categories maintainers platforms description long_description notes homepage license provides conflicts replaced_by installs_libs license_noconflict
 
 default subport {[portmain::get_default_subport]}
 proc portmain::get_default_subport {} {
@@ -89,7 +91,6 @@
 default prefix /opt/local
 default applications_dir /Applications/MacPorts
 default frameworks_dir {${prefix}/Library/Frameworks}
-default developer_dir {[portmain::get_developer_dir]}
 default destdir destroot
 default destpath {${workpath}/${destdir}}
 # destroot is provided as a clearer name for the "destpath" variable
@@ -144,43 +145,15 @@
 default compiler.cpath {${prefix}/include}
 default compiler.library_path {${prefix}/lib}
 
-proc portmain::get_developer_dir {} {
-    if {![catch {binaryInPath xcode-select}]} {
-        return [exec xcode-select -print-path 2> /dev/null]
-    }
-    return "/Developer"
-}
-
 # start gsoc08-privileges
 
 # Record initial euid/egid
 set euid [geteuid]
 set egid [getegid]
 
-# resolve the alternate work path in ~/.macports
-proc portmain::set_altprefix {} {
-    global altprefix env euid
-
-    # do tilde expansion manually - Tcl won't expand tildes automatically for curl, etc.
-    if {[info exists env(HOME)]} {
-        # HOME environment var is set, use it.
-        set userhome "$env(HOME)"
-    } elseif {$euid == 0 && [info exists env(SUDO_USER)] && $env(SUDO_USER) != ""} {
-        set userhome [file normalize "~$env(SUDO_USER)"]
-    } else {
-        # the environment var isn't set, expand ~user instead
-        set username [uid_to_name [getuid]]
-        if {[catch {set userhome [file normalize "~$username"]}]} {
-            set userhome ""
-        }
-    }
-
-    set altprefix [file join $userhome .macports]
-}
-
 # if unable to write to workpath, implies running without either root privileges
 # or a shared directory owned by the group so use ~/.macports
-portmain::set_altprefix
+default altprefix {[file join $user_home .macports]}
 if { $euid != 0 && (([info exists workpath] && [file exists $workpath] && ![file writable $workpath]) || ([info exists portdbpath] && ![file writable [file join $portdbpath build]])) } {
 
     # set global variable indicating to other functions to use ~/.macports as well

Modified: branches/gsoc11-statistics/base/src/port1.0/portpatch.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portpatch.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portpatch.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -97,7 +97,7 @@
     set gzcat "[findBinary gzip $portutil::autoconf::gzip_path] -dc"
     set bzcat "[findBinary bzip2 $portutil::autoconf::bzip2_path] -dc"
     foreach patch $patchlist {
-        ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] $patch]"
+        ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] [file tail $patch]]"
         switch -- [file extension $patch] {
             .Z -
             .gz {command_exec patch "$gzcat \"$patch\" | (" ")"}

Copied: branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl (from rev 105084, trunk/base/src/port1.0/portsandbox.tcl)
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl	                        (rev 0)
+++ branches/gsoc11-statistics/base/src/port1.0/portsandbox.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -0,0 +1,96 @@
+# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
+# $Id$
+#
+# Copyright (c) 2012 The MacPorts Project
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. Neither the name of The MacPorts Project nor the names of its
+#    contributors may be used to endorse or promote products derived from
+#    this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+package provide portsandbox 1.0
+
+namespace eval portsandbox {
+}
+
+options portsandbox_supported portsandbox_profile
+default portsandbox_supported {[file executable $portutil::autoconf::sandbox_exec_path]}
+default portsandbox_profile {}
+
+# set up a suitable profile to pass to sandbox-exec, based on the target
+# command line usage would be:
+# sandbox-exec -p '(version 1) (allow default) (deny file-write*) (allow file-write* <filter>)' some-command
+proc portsandbox::set_profile {target} {
+    global os.major portsandbox_profile workpath distpath altprefix \
+        package.destpath configure.ccache ccache_dir rpm.srcdir rpm.tmpdir
+
+    switch $target {
+        activate -
+        deactivate -
+        dmg -
+        mdmg -
+        load -
+        unload {
+            set portsandbox_profile ""
+            return
+        }
+        install -
+        uninstall {
+            set allow_dirs [list [file dirname [get_portimage_path]]]
+        }
+        fetch -
+        mirror -
+        clean {
+            set allow_dirs [list $distpath]
+        }
+        pkg {
+            set allow_dirs [list ${package.destpath}]
+        }
+        rpm -
+        srpm {
+            set allow_dirs [list ${rpm.srcdir} ${rpm.tmpdir}]
+        }
+    }
+
+    # TODO: remove altprefix support
+    lappend allow_dirs $workpath $altprefix
+    if {${configure.ccache}} {
+        lappend allow_dirs $ccache_dir
+    }
+
+    set portsandbox_profile "(version 1) (allow default) (deny file-write*) \
+(allow file-write-data (literal \"/dev/null\") (literal \"/dev/zero\") \
+(literal \"/dev/dtracehelper\") (literal \"/dev/tty\") \
+(literal \"/dev/stdin\") (literal \"/dev/stdout\") (literal \"/dev/stderr\") \
+(regex #\"^/dev/fd/\")) (allow file-write* \
+(regex #\"^(/private)?(/var)?/tmp/\" #\"^(/private)?/var/folders/\"))"
+
+    foreach dir $allow_dirs {
+        append portsandbox_profile " (allow file-write* ("
+        if {${os.major} > 9} {
+            append portsandbox_profile "subpath \"${dir}\"))"
+        } else {
+            append portsandbox_profile "regex #\"^${dir}/\"))"
+        }
+    }
+}

Modified: branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portstartupitem.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,7 +3,7 @@
 #
 # $Id$
 #
-# Copyright (c) 2004-2011 The MacPorts Project
+# Copyright (c) 2004-2012 The MacPorts Project
 # Copyright (c) 2006-2007 James D. Berry
 # Copyright (c) 2004,2005 Markus W. Weissman <mww at macports.org>
 # All rights reserved.
@@ -400,6 +400,7 @@
     global startupitem.name startupitem.uniquename startupitem.plist startupitem.location
     global startupitem.init startupitem.start startupitem.stop startupitem.restart startupitem.executable
     global startupitem.pidfile startupitem.logfile startupitem.logevents startupitem.netchange
+    global startupitem.install
 
     set scriptdir ${prefix}/etc/startup
     
@@ -602,8 +603,8 @@
 
     close ${plist}
 
-    # Make a symlink to the plist file
-    if {[getuid] == 0} {
+    if { [getuid] == 0 && 
+      ${startupitem.install} != "no" } {
         file mkdir "${destroot}/Library/${daemondest}"
         ln -sf "${itemdir}/${plistname}" "${destroot}/Library/${daemondest}"
     }

Deleted: branches/gsoc11-statistics/base/src/port1.0/portsubmit.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portsubmit.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portsubmit.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,264 +0,0 @@
-# et:ts=4
-# portsubmit.tcl
-# $Id$
-#
-# Copyright (c) 2007 - 2011 The MacPorts Project
-# Copyright (c) 2002 - 2004 Apple Inc.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-# 1. Redistributions of source code must retain the above copyright
-#    notice, this list of conditions and the following disclaimer.
-# 2. Redistributions in binary form must reproduce the above copyright
-#    notice, this list of conditions and the following disclaimer in the
-#    documentation and/or other materials provided with the distribution.
-# 3. Neither the name of Apple Inc. nor the names of its contributors
-#    may be used to endorse or promote products derived from this software
-#    without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-# POSSIBILITY OF SUCH DAMAGE.
-#
-
-package provide portsubmit 1.0
-package require portutil 1.0
-package require portportpkg 1.0
-
-set org.macports.submit [target_new org.macports.submit portsubmit::submit_main]
-target_runtype ${org.macports.submit} always
-target_provides ${org.macports.submit} submit
-target_requires ${org.macports.submit} portpkg
-
-namespace eval portsubmit {
-}
-
-set_ui_prefix
-
-
-# escape quotes, and things that make the shell cry
-proc portsubmit::shell_escape {str} {
-    regsub -all -- {\\} $str {\\\\} str
-    regsub -all -- {"} $str {\"} str
-    regsub -all -- {'} $str {\'} str
-    return $str
-}
-
-
-proc portsubmit::submit_main {args} {
-    global mp_remote_submit_url name version portverbose prefix UI_PREFIX workpath portpath
-
-    set submiturl $mp_remote_submit_url
-
-    # Preconditions for submit
-    if {$submitter_email == ""} {
-        return -code error [format [msgcat::mc "Submitter email is required to submit a port"]]
-    }
-
-    # Make sure we have a work directory
-    file mkdir ${workpath}
-
-    # Create portpkg.xar in the work directory
-    set pkgpath "${workpath}/${name}.portpkg"
-
-    # TODO: If a private key was provided, create a signed digest of the submission
-
-    # Submit to the submit url
-    set args "curl"
-    lappend args "--silent"
-    lappend args "--url ${submiturl}"
-    lappend args "--output ${workpath}/.portsubmit.out"
-    lappend args "-F machine=true"
-    lappend args "-F portpkg=@${pkgpath}"
-    #lappend args "-F signeddigest=${digest}"
-    set cmd [join $args]
-
-    if {[tbool portverbose]} {
-        ui_notice "Submitting portpkg $pkgpath for $name to $submiturl"
-    }
-
-    # Invoke curl to do the submit
-    ui_debug $cmd
-    if {[system $cmd] != ""} {
-        return -code error [format [msgcat::mc "Failure during submit of port %s"] $name]
-    }
-
-    # Parse the result
-    set fd [open ${workpath}/.portsubmit.out r]
-    array set result [list]
-    while {[gets $fd line] != -1} {
-        if {0 != [regexp -- {^([^:]+):\s*(.*)$} $line unused key value]} {
-            set result($key) $value
-        }
-    }
-    close $fd
-
-    # Interpret and act on the result
-    if {[info exists result(MESSAGE)] && [tbool portverbose]} {
-        ui_notice $result(MESSAGE)
-    }
-    if {[info exists result(STATUS)]} {
-        if { $result(STATUS) == 0 } {
-            ui_notice "Submitted portpkg for $name"
-            if {[info exists result(DOWNLOAD_URL)]} {
-                ui_notice "    download URL => $result(DOWNLOAD_URL)"
-            }
-            if {[info exists result(HUMAN_URL)]} {
-                ui_notice "    human readable URL => $result(HUMAN_URL)"
-            }
-        } else {
-            return -code error [format [msgcat::mc "Status %d reported during submit of port %s"] $result(STATUS) $name]
-        }
-    } else {
-        return -code error [format [msgcat::mc "Status not received during submit of port %s"] $name]
-    }
-
-    return
-
-    # REMNANTS OF KEVIN'S CODE
-
-    # start with the Portfile, and add the files directory if it exists.
-    # don't pick up any CVS directories, or .DS_Store turds
-    set cmd "tar czvf ${workpath}/Portfile.tar.gz "
-    append cmd "--exclude CVS --exclude .DS_Store "
-    append cmd "Portfile "
-    if {[file isdirectory "files"]} {
-        append cmd "files "
-    }
-
-    if {[system $cmd] != ""} {
-    return -code error [format [msgcat::mc "Failed to archive port : %s"] $name]
-    }
-
-    set portsource ""
-    set base_rev ""
-    if {![catch {set fd [open ".mports_source" r]}]} {
-        while {[gets $fd line] != -1} {
-            regexp -- {^(.*): (.*)$} $line unused key value
-            switch -- $key {
-                source { set portsource $value }
-                revision { set base_rev $value }
-            }
-        }
-        close $fd
-    }
-    if {$portsource == ""} {
-        ui_notice "$UI_PREFIX Submitting $name-$version"
-        puts -nonewline "URL: "
-        flush stdout
-        gets stdin portsource
-    }
-
-    ui_notice "$UI_PREFIX Submitting $name-$version to $portsource"
-
-    puts -nonewline "Username: "
-    flush stdout
-    gets stdin username
-    puts -nonewline "Password: "
-    flush stdout
-    exec stty -echo
-    gets stdin password
-    puts ""
-    exec stty echo
-
-    set vars {name version maintainers categories description \
-        long_description master_sites}
-    eval "global $vars"
-    foreach var $vars {
-        if {![info exists $var]} { set $var {} }
-    }
-
-    set cmd "curl "
-    append cmd "--silent "
-    append cmd "--url [regsub -- {^mports} $portsource {http}]/cgi-bin/portsubmit.cgi "
-    append cmd "--output ${workpath}/.portsubmit.out "
-    append cmd "-F name=${name} "
-    append cmd "-F version=${version} "
-    append cmd "-F base_rev=${base_rev} "
-    append cmd "-F md5=[md5 file ${workpath}/Portfile.tar.gz] "
-    append cmd "-F attachment=@${workpath}/Portfile.tar.gz "
-    append cmd "-F \"submitted_by=[shell_escape $username]\" "
-    append cmd "-F \"password=[shell_escape $password]\" "
-    append cmd "-F \"maintainers=[shell_escape $maintainers]\" "
-    append cmd "-F \"categories=[shell_escape $categories]\" "
-    append cmd "-F \"description=[shell_escape $description]\" "
-    append cmd "-F \"long_description=[shell_escape $long_description]\" "
-    append cmd "-F \"master_sites=[shell_escape $master_sites]\" "
-
-    ui_debug $cmd
-    if {[system $cmd] != ""} {
-    return -code error [format [msgcat::mc "Failed to submit port : %s"] $name]
-    }
-
-    #
-    # Parse the result from the remote index
-    # if ERROR: print the error message
-    # if OK: store the revision info
-    # if CONFLICT: attempt to merge the conflict
-    #
-
-    set fd [open ${workpath}/.portsubmit.out r]
-    array set result [list]
-    while {[gets $fd line] != -1} {
-        regexp -- {^(.*): (.*)$} $line unused key value
-        set result($key) $value
-    }
-    close $fd
-
-    if {[info exists result(OK)]} {
-        set fd [open ".mports_source" w]
-        puts $fd "source: $portsource"
-        puts $fd "port: $name"
-        puts $fd "version: $version"
-        puts $fd "revision: $result(revision)"
-        close $fd
-
-        ui_notice "$name-$version submitted successfully."
-        ui_notice "New revision: $result(revision)"
-    } elseif {[info exists result(ERROR)]} {
-        return -code error $result(ERROR)
-    } elseif {[info exists result(CONFLICT)]} {
-        # Fetch the newer revision from the index.
-        # XXX: many gross hacks here regarding paths, urls, etc.
-        set tmpdir [mktemp "/tmp/mports.XXXXXXXX"]
-        file mkdir $tmpdir/new
-        file mkdir $tmpdir/old
-        set worker [mport_open $portsource/files/$name/$version/$result(revision)/Portfile.tar.gz [list portdir $tmpdir/new subport $name]]
-        if {$base_rev != ""} {
-            set worker2 [mport_open $portsource/files/$name/$version/$base_rev/Portfile.tar.gz [list portdir $tmpdir/old subport $name]]
-            catch {system "diff3 -m -E -- $portpath/Portfile $tmpdir/old/$name-$version/Portfile $tmpdir/new/$name-$version/Portfile > $tmpdir/Portfile"}
-            file rename -force "${tmpdir}/Portfile" "${portpath}/Portfile"
-            mport_close $worker2
-        } else {
-            catch {system "diff3 -m -E -- $portpath/Portfile $portpath/Portfile $tmpdir/new/$name-$version/Portfile > $tmpdir/Portfile"}
-            file rename -force "${tmpdir}/Portfile" "${portpath}/Portfile"
-        }
-        mport_close $worker
-        catch {delete "${tmpdir}"}
-
-        set fd [open [file join "$portpath" ".mports_source"] w]
-        puts $fd "source: $portsource"
-        puts $fd "port: $name"
-        puts $fd "version: $version"
-        puts $fd "revision: $result(revision)"
-        close $fd
-
-        ui_error "A newer revision of this port has already been submitted."
-        ui_error "Portfile: $name-$version"
-        ui_error "Base revision: $base_rev"
-        ui_error "Current revision: $result(revision)"
-        ui_error "Please edit the Portfile to resolve any conflicts and resubmit."
-    }
-
-    return 0
-}

Modified: branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/porttrace.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -141,7 +141,7 @@
     # Get the list of violations.
     set violations [slave_send porttrace::slave_get_sandbox_violations]
 
-    foreach violation [lsort $violations] {
+    foreach violation [lsort -unique $violations] {
         ui_warn "An activity was attempted outside sandbox: $violation"
     }
 }
@@ -175,18 +175,25 @@
 # Private
 # Create the slave thread.
 proc porttrace::create_slave {workpath trace_fifo} {
-    global trace_thread prefix developer_dir
+    global trace_thread prefix developer_dir registry.path
     # Create the thread.
     set trace_thread [macports_create_thread]
 
-    # The slave thread requires the registry package.
-    thread::send $trace_thread "package require registry 1.0"
-    # and this file as well.
+    # The slave thred needs this file and macports 1.0
     thread::send $trace_thread "package require porttrace 1.0"
-    # slave needs ui_warn and ui_debug...
-    thread::send $trace_thread "macports::ui_init warn; macports::ui_init debug"
+    thread::send $trace_thread "package require macports 1.0"
+    # slave needs ui_{info,warn,debug,error}...
+    # make sure to sync this with ../pextlib1.0/tracelib.c!
+    thread::send $trace_thread "macports::ui_init debug"
+    thread::send $trace_thread "macports::ui_init info"
+    thread::send $trace_thread "macports::ui_init warn"
+    thread::send $trace_thread "macports::ui_init error"
     # and these variables
     thread::send $trace_thread "set prefix \"$prefix\"; set developer_dir \"$developer_dir\""
+    # The slave thread requires the registry package.
+    thread::send $trace_thread "package require registry 1.0"
+    # and an open registry
+    thread::send $trace_thread "registry::open [file join ${registry.path} registry registry.db]"
 
     # Initialize the slave
     thread::send $trace_thread "porttrace::slave_init $trace_fifo $workpath"

Modified: branches/gsoc11-statistics/base/src/port1.0/portunload.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portunload.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portunload.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
 # et:ts=4
-# portsubmit.tcl
+# portunload.tcl
 # $Id$
 #
 # Copyright (c) 2007, 2009, 2011 The MacPorts Project

Modified: branches/gsoc11-statistics/base/src/port1.0/portutil.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/portutil.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/port1.0/portutil.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -5,7 +5,7 @@
 # Copyright (c) 2002-2003 Apple Inc.
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
 # Copyright (c) 2006-2007 Markus W. Weissmann <mww at macports.org>
-# Copyright (c) 2004-2011 The MacPorts Project
+# Copyright (c) 2004-2013 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -208,7 +208,7 @@
             set PortInfo($option) $value
         }
         delete {
-            unset PortInfo($option)
+            unset -nocomplain PortInfo($option)
         }
     }
 }
@@ -355,12 +355,13 @@
 }
 
 # Given a command name, execute it with the options.
-# command_exec command [-notty] [command_prefix [command_suffix]]
+# command_exec command [-notty] [-varprefix variable_prefix] [command_prefix [command_suffix]]
 # command           name of the command
+# variable_prefix   name of the variable prefix to use (defaults to command)
 # command_prefix    additional command prefix (typically pipe command)
 # command_suffix    additional command suffix (typically redirection)
 proc command_exec {command args} {
-    global ${command}.env ${command}.env_array ${command}.nice env macosx_version
+    set varprefix "${command}"
     set notty ""
     set command_prefix ""
     set command_suffix ""
@@ -371,6 +372,11 @@
             set args [lrange $args 1 end]
         }
 
+        if {[lindex $args 0] == "-varprefix"} {
+            set varprefix [lindex $args 1]
+            set args [lrange $args 2 end]
+        }
+
         if {[llength $args] > 0} {
             set command_prefix [lindex $args 0]
             if {[llength $args] > 1} {
@@ -379,37 +385,35 @@
         }
     }
 
+    global ${varprefix}.env ${varprefix}.env_array ${varprefix}.nice env macosx_version
+
     # Set the environment.
     # If the array doesn't exist, we create it with the value
-    # coming from ${command}.env
+    # coming from ${varprefix}.env
     # Otherwise, it means the caller actually played with the environment
     # array already (e.g. configure flags).
-    if {![array exists ${command}.env_array]} {
-        parse_environment ${command}
+    if {![array exists ${varprefix}.env_array]} {
+        parse_environment ${varprefix}
     }
     if {[option macosx_deployment_target] ne ""} {
-        set ${command}.env_array(MACOSX_DEPLOYMENT_TARGET) [option macosx_deployment_target]
+        set ${varprefix}.env_array(MACOSX_DEPLOYMENT_TARGET) [option macosx_deployment_target]
     }
-    set ${command}.env_array(CC_PRINT_OPTIONS) "YES"
-    set ${command}.env_array(CC_PRINT_OPTIONS_FILE) [file join [option workpath] ".CC_PRINT_OPTIONS"]
+    set ${varprefix}.env_array(CC_PRINT_OPTIONS) "YES"
+    set ${varprefix}.env_array(CC_PRINT_OPTIONS_FILE) [file join [option workpath] ".CC_PRINT_OPTIONS"]
     if {[option compiler.cpath] ne ""} {
-        set ${command}.env_array(CPATH) [join [option compiler.cpath] :]
+        set ${varprefix}.env_array(CPATH) [join [option compiler.cpath] :]
     }
     if {[option compiler.library_path] ne ""} {
-        set ${command}.env_array(LIBRARY_PATH) [join [option compiler.library_path] :]
+        set ${varprefix}.env_array(LIBRARY_PATH) [join [option compiler.library_path] :]
     }
 
-    # When building, g-ir-scanner should not save its cache to $HOME
-    # See: https://trac.macports.org/ticket/26783
-    set ${command}.env_array(GI_SCANNER_DISABLE_CACHE) "1"
-
     # Debug that.
-    ui_debug "Environment: [environment_array_to_string ${command}.env_array]"
+    ui_debug "Environment: [environment_array_to_string ${varprefix}.env_array]"
 
     # Prepare nice value change
     set nice ""
-    if {[info exists ${command}.nice] && [set ${command}.nice] != ""} {
-        set nice "-nice [set ${command}.nice]"
+    if {[info exists ${varprefix}.nice] && [set ${varprefix}.nice] != ""} {
+        set nice "-nice [set ${varprefix}.nice]"
     }
 
     # Get the command string.
@@ -420,14 +424,17 @@
     # Save the environment.
     array set saved_env [array get env]
     # Set the overriden variables from the portfile.
-    array set env [array get ${command}.env_array]
+    array set env [array get ${varprefix}.env_array]
     # Call the command.
     set fullcmdstring "$command_prefix $cmdstring $command_suffix"
     ui_debug "Executing command line: $fullcmdstring"
     set code [catch {eval system $notty $nice \$fullcmdstring} result]
+    # Save variables in order to re-throw the same error code.
+    set errcode $::errorCode
+    set errinfo $::errorInfo
 
     # Unset the command array until next time.
-    array unset ${command}.env_array
+    array unset ${varprefix}.env_array
 
     # Restore the environment.
     array unset env *
@@ -437,7 +444,7 @@
     array set env [array get saved_env]
 
     # Return as if system had been called directly.
-    return -code $code $result
+    return -code $code -errorcode $errcode -errorinfo $errinfo $result
 }
 
 # default
@@ -781,8 +788,9 @@
 # This executes the given code in 'body' if we were opened as the specified
 # subport, and also adds it to the list of subports that are defined.
 proc subport {subname body} {
-    global subport PortInfo
-    if {![info exists PortInfo(subports)] || [lsearch -exact $PortInfo(subports) $subname] == -1} {
+    global subport name PortInfo
+    if {$subport == $name && $subname != $name && 
+        (![info exists PortInfo(subports)] || [lsearch -exact $PortInfo(subports) $subname] == -1)} {
         lappend PortInfo(subports) $subname
     }
     if {[string equal -nocase $subname $subport]} {
@@ -907,20 +915,36 @@
 # reinplace
 # Provides "sed in place" functionality
 proc reinplace {args}  {
-
+    global env worksrcpath macosx_version
     set extended 0
     set suppress 0
+    set oldlocale_exists 0
+    set oldlocale "" 
+    set locale ""
+    set dir ${worksrcpath}
     while 1 {
         set arg [lindex $args 0]
         if {[string index $arg 0] eq "-"} {
             set args [lrange $args 1 end]
             switch -- [string range $arg 1 end] {
+                locale {
+                    set oldlocale_exists [info exists env(LC_CTYPE)]
+                    if {$oldlocale_exists} {
+                        set oldlocale $env(LC_CTYPE)
+                    }
+                    set locale [lindex $args 0]
+                    set args [lrange $args 1 end]
+                }
                 E {
                     set extended 1
                 }
                 n {
                     set suppress 1
                 }
+                W {
+                    set dir [lindex $args 0]
+                    set args [lrange $args 1 end]
+                }
                 - {
                     break
                 }
@@ -933,12 +957,16 @@
         }
     }
     if {[llength $args] < 2} {
-        error "reinplace ?-E? pattern file ..."
+        error "reinplace ?-E? ?-n? ?-W dir? pattern file ..."
     }
     set pattern [lindex $args 0]
     set files [lrange $args 1 end]
 
     foreach file $files {
+        # if $file is an absolute path already, file join will just return the
+        # absolute path, otherwise it is $dir/$file
+        set file [file join $dir $file]
+
         if {[catch {set tmpfile [mkstemp "/tmp/[file tail $file].sed.XXXXXXXX"]} error]} {
             global errorInfo
             ui_debug "$errorInfo"
@@ -963,15 +991,39 @@
             lappend cmdline -n
         }
         set cmdline [concat $cmdline [list $pattern < $file >@ $tmpfd]]
+        if {$locale != ""} {
+            set env(LC_CTYPE) $locale
+        }
+        ui_debug "Executing reinplace: $cmdline"
         if {[catch {eval exec $cmdline} error]} {
             global errorInfo
             ui_debug "$errorInfo"
             ui_error "reinplace: $error"
             file delete "$tmpfile"
+            if {$locale != ""} {
+                if {$oldlocale_exists} {
+                    set env(LC_CTYPE) $oldlocale
+                } else {
+                    unset env(LC_CTYPE)
+                    if {$macosx_version == "10.5"} {
+                        unsetenv LC_CTYPE
+                    }
+                }
+            }
             close $tmpfd
             return -code error "reinplace sed(1) failed"
         }
 
+        if {$locale != ""} {
+            if {$oldlocale_exists} {
+                set env(LC_CTYPE) $oldlocale
+            } else {
+                unset env(LC_CTYPE)
+                if {$macosx_version == "10.5"} {
+                    unsetenv LC_CTYPE
+                }
+            }
+        }
         close $tmpfd
 
         set attributes [file attributes $file]
@@ -1264,11 +1316,16 @@
 set ports_dry_last_skipped ""
 
 proc target_run {ditem} {
-    global target_state_fd workpath portpath ports_trace PortInfo ports_dryrun ports_dry_last_skipped worksrcpath prefix subport
+    global target_state_fd workpath portpath ports_trace PortInfo ports_dryrun \
+           ports_dry_last_skipped worksrcpath prefix subport env portdbpath \
+           macosx_version
     set portname $subport
     set result 0
     set skipped 0
     set procedure [ditem_key $ditem procedure]
+    set savedhome [file join $portdbpath home]
+    set env(HOME) "${workpath}/.home"
+    set env(TMPDIR) "${workpath}/.tmp"
 
     if {[ditem_key $ditem state] != "no"} {
         set target_state_fd [open_statefile]
@@ -1277,6 +1334,7 @@
     if {$procedure != ""} {
         set targetname [ditem_key $ditem name]
         set target [ditem_key $ditem provides]
+        portsandbox::set_profile $target
         global ${target}.asroot
         if { [tbool ${target}.asroot] } {
             elevateToRoot $targetname
@@ -1284,6 +1342,9 @@
 
         if {[ditem_contains $ditem init]} {
             set result [catch {[ditem_key $ditem init] $targetname} errstr]
+            # Save variables in order to re-throw the same error code.
+            set errcode $::errorCode
+            set errinfo $::errorInfo
         }
 
         if {$result == 0} {
@@ -1315,6 +1376,9 @@
                 # Execute pre-run procedure
                 if {[ditem_contains $ditem prerun]} {
                     set result [catch {[ditem_key $ditem prerun] $targetname} errstr]
+                    # Save variables in order to re-throw the same error code.
+                    set errcode $::errorCode
+                    set errinfo $::errorInfo
                 }
 
                 #start tracelib
@@ -1368,39 +1432,58 @@
                         }
                     }
 
-                    # Dependencies are in the form verb:[param:]port
-                    set depsPorts {}
+                    # Recursively collect all dependencies from registry for tracing
+                    set deplist {}
                     foreach depspec $depends {
-                        # grab the portname portion of the depspec
-                        set dep_portname [lindex [split $depspec :] end]
-                        lappend depsPorts $dep_portname
+                        # Resolve dependencies to actual ports
+                        set name [_get_dep_port $depspec]
+
+                        # If portname is empty, the dependency is already satisfied by other means,
+                        # for example a bin: dependency on a file not installed by MacPorts
+                        if {$name != ""} {
+                            if {[lsearch -exact $deplist $name] == -1} {
+                                lappend deplist $name
+                                set deplist [recursive_collect_deps $name $deplist]
+                            }
+                        }
                     }
 
-                    set portlist $depsPorts
-                    foreach depName $depsPorts {
-                        set portlist [recursive_collect_deps $depName $deptypes $portlist]
+                    # Add ccache port for access to ${prefix}/bin/ccache binary
+                    if [option configure.ccache] {
+                        lappend deplist ccache
                     }
 
-                    if {[llength $deptypes] > 0} {tracelib setdeps $portlist}
+                    ui_debug "Tracemode will respect recursively collected port dependencies: [lsort $deplist]"
+
+                    if {[llength $deptypes] > 0} {tracelib setdeps $deplist}
                 }
 
                 if {$result == 0} {
                     foreach pre [ditem_key $ditem pre] {
                         ui_debug "Executing $pre"
                         set result [catch {$pre $targetname} errstr]
+                        # Save variables in order to re-throw the same error code.
+                        set errcode $::errorCode
+                        set errinfo $::errorInfo
                         if {$result != 0} { break }
                     }
                 }
 
                 if {$result == 0} {
-                ui_debug "Executing $targetname ($portname)"
-                set result [catch {$procedure $targetname} errstr]
+                    ui_debug "Executing $targetname ($portname)"
+                    set result [catch {$procedure $targetname} errstr]
+                    # Save variables in order to re-throw the same error code.
+                    set errcode $::errorCode
+                    set errinfo $::errorInfo
                 }
 
                 if {$result == 0} {
                     foreach post [ditem_key $ditem post] {
                         ui_debug "Executing $post"
                         set result [catch {$post $targetname} errstr]
+                        # Save variables in order to re-throw the same error code.
+                        set errcode $::errorCode
+                        set errinfo $::errorInfo
                         if {$result != 0} { break }
                     }
                 }
@@ -1409,6 +1492,9 @@
                     set postrun [ditem_key $ditem postrun]
                     ui_debug "Executing $postrun"
                     set result [catch {$postrun $targetname} errstr]
+                    # Save variables in order to re-throw the same error code.
+                    set errcode $::errorCode
+                    set errinfo $::errorInfo
                 }
 
                 # Check dependencies & file creations outside workpath.
@@ -1448,9 +1534,9 @@
             write_statefile target $targetname $target_state_fd
             }
         } else {
-            global errorInfo
-            ui_error "Target $targetname returned: $errstr"
-            ui_debug "Backtrace: $errorInfo"
+            ui_error "$targetname for port $portname returned: $errstr"
+            ui_debug "Error code: $errcode"
+            ui_debug "Backtrace: $errinfo"
             set result 1
         }
 
@@ -1463,44 +1549,35 @@
         close $target_state_fd
     }
 
+    set env(HOME) $savedhome
+    if {[info exists env(TMPDIR)]} {
+        unset env(TMPDIR)
+        if {$macosx_version == "10.5"} {
+            unsetenv TMPDIR
+        }
+    }
+
     return $result
 }
 
 # recursive dependency search for portname
-proc recursive_collect_deps {portname deptypes {depsfound {}}} \
+proc recursive_collect_deps {portname {depsfound {}}} \
 {
-    set res [mport_lookup $portname]
-    if {[llength $res] < 2} \
-    {
-        # Even if this port cannot be found in the index,
-        # it is still listed as dependency
-        if {[lsearch -exact $depsfound $portname] == -1} {
-            lappend depsfound $portname
-        }
-        return $depsfound
-    }
+    # Get the active port from the registry
+    # There can be only one port active at a time, so take the first result only
+    set regentry [lindex [registry_active $portname] 0]
+    # Get port dependencies from the registry
+    set deplist [registry_list_depends [lindex $regentry 0] [lindex $regentry 1] [lindex $regentry 2] [lindex $regentry 3]]
 
-    set depends {}
-
-    array set portinfo [lindex $res 1]
-    foreach deptype $deptypes \
-    {
-        if {[info exists portinfo($deptype)] && $portinfo($deptype) != ""} \
-        {
-            set depends [concat $depends $portinfo($deptype)]
+    foreach item $deplist {
+        set name [lindex $item 0]
+        if {[lsearch -exact $depsfound $name] == -1} {
+            lappend depsfound $name
+            set depsfound [recursive_collect_deps $name $depsfound]
         }
     }
 
-    set portdeps $depsfound
-    foreach depspec $depends \
-    {
-        set portname [lindex [split $depspec :] end]
-        if {[lsearch -exact $portdeps $portname] == -1} {
-            lappend portdeps $portname
-            set portdeps [recursive_collect_deps $portname $deptypes $portdeps]
-        }
-    }
-    return $portdeps
+    return $depsfound
 }
 
 
@@ -1524,7 +1601,7 @@
                 # run the activate target but ignore its (completed) dependencies
                 set result [target_run [lindex [dlist_search $dlist provides $target] 0]]
                 if {[getuid] == 0 && [geteuid] != 0} {
-                    setegid 0; seteuid 0
+                    seteuid 0; setegid 0
                 }
                 return $result
             }
@@ -1547,12 +1624,12 @@
     set dlist [dlist_eval $dlist "" target_run]
 
     if {[getuid] == 0 && [geteuid] != 0} {
-        setegid 0; seteuid 0
+        seteuid 0; setegid 0
     }
 
     if {[llength $dlist] > 0} {
         # somebody broke!
-        set errstring "Warning: the following items did not execute (for $subport):"
+        set errstring "Warning: targets not executed for $subport:"
         foreach ditem $dlist {
             append errstring " [ditem_key $ditem name]"
         }
@@ -1568,8 +1645,8 @@
 # open_statefile
 # open file to store name of completed targets
 proc open_statefile {args} {
-    global workpath worksymlink place_worksymlink subport portpath ports_ignore_older ports_dryrun
-    global usealtworkpath altprefix env applications_dir subbuildpath
+    global workpath worksymlink place_worksymlink subport portpath ports_ignore_different ports_dryrun \
+           usealtworkpath altprefix env applications_dir subbuildpath
 
     if {$usealtworkpath} {
          ui_warn_once "privileges" "MacPorts running without privileges.\
@@ -1594,9 +1671,19 @@
         }
     }
 
-    if {![file isdirectory $workpath] && ![tbool ports_dryrun]} {
-        file mkdir $workpath
-        chownAsRoot $subbuildpath
+    if {![tbool ports_dryrun]} {
+        set need_chown 0
+        if {![file isdirectory $workpath/.home]} {
+            file mkdir $workpath/.home
+            set need_chown 1
+        }
+        if {![file isdirectory $workpath/.tmp]} {
+            file mkdir $workpath/.tmp
+            set need_chown 1
+        }
+        if {$need_chown} {
+            chownAsRoot $subbuildpath
+        }
         # Create a symlink to the workpath for port authors
         if {[tbool place_worksymlink] && ![file isdirectory $worksymlink]} {
             ui_debug "Attempting ln -sf $workpath $worksymlink"
@@ -1609,22 +1696,74 @@
 
     # flock Portfile
     set statefile [file join $workpath .macports.${subport}.state]
+    set fresh_build yes
+    set checksum_portfile [sha256 file ${portpath}/Portfile]
     if {[file exists $statefile]} {
+        set fresh_build no
         if {![file writable $statefile] && ![tbool ports_dryrun]} {
             return -code error "$statefile is not writable - check permission on port directory"
         }
         if {[file mtime ${portpath}/Portfile] > [clock seconds]} {
             return -code error "Portfile is from the future - check date and time of your system"
         }
-        if {!([info exists ports_ignore_older] && $ports_ignore_older == "yes") && [file mtime $statefile] < [file mtime ${portpath}/Portfile]} {
-            if {![tbool ports_dryrun]} {
-                ui_notice "Portfile changed since last build; discarding previous state."
-                chownAsRoot $subbuildpath
-                delete $workpath
-                file mkdir $workpath
-            } else {
-                ui_notice "Portfile changed since last build but not discarding previous state (dry run)"
+        if {![tbool ports_ignore_different]} {
+            # start by assuming the statefile is current
+            set portfile_changed no
+
+            # open the statefile, determine the statefile version
+            set readfd [open $statefile r]
+            set statefile_version 1
+            if {[get_statefile_value "version" $readfd result] != 0} {
+                set statefile_version $result
             }
+
+            # check for outdated statefiles depending on what version the
+            # statefile is; we explicitly support older statefiles here, because
+            # all previously built archives would be invalidated (e.g., when
+            # using mpkg) if we didn't
+            switch $statefile_version {
+                1 {
+                    # statefile version 1
+                    # this statefile doesn't have a checksum, fall back to
+                    # comparing the Portfile modification date with the
+                    # statefile modification date
+                    if {[file mtime $statefile] < [file mtime ${portpath}/Portfile]} {
+                        ui_debug "Statefile has version 1 and is older than Portfile"
+                        set portfile_changed yes
+                    }
+                }
+                2 {
+                    # statefile version 2
+                    # this statefile has a sha256 checksum of the Portfile in
+                    # the "checksum" key
+                    set checksum_statefile ""
+                    if {[get_statefile_value "checksum" $readfd checksum_statefile] == 0} {
+                        ui_warn "Statefile has version 2 but didn't contain a checksum"
+                        set portfile_changed yes
+                    } else {
+                        if {$checksum_portfile != $checksum_statefile} {
+                            ui_debug "Checksum recorded in statefile '$checksum_statefile' differs from Portfile checksum '$checksum_portfile'"
+                            set portfile_changed yes
+                        }
+                    }
+                }
+                default {
+                    ui_warn "Unsupported statefile version '$statefile_version'"
+                    ui_warn "Please run 'port selfupdate' to update to the latest version of MacPorts"
+                }
+            }
+            if {[tbool portfile_changed]} {
+                if {![tbool ports_dryrun]} {
+                    ui_notice "Portfile changed since last build; discarding previous state."
+                    chownAsRoot $subbuildpath
+                    delete $workpath
+                    file mkdir $workpath
+                    set fresh_build yes
+                } else {
+                    ui_notice "Portfile changed since last build but not discarding previous state (dry run)"
+                }
+            }
+            close $readfd
         }
     } elseif {[tbool ports_dryrun]} {
         set statefile /dev/null
@@ -1644,9 +1783,28 @@
             }
         }
     }
+    if {[tbool fresh_build]} {
+        write_statefile "version" 2 $fd
+        write_statefile "checksum" $checksum_portfile $fd
+    }
     return $fd
 }
 
+# get_statefile_value
+# Check for a given $class in the statefile $fd and write the first match to
+# $result, if any. Returns 1 if a line matched, 0 otherwise
+proc get_statefile_value {class fd result} {
+    upvar $result upresult
+    seek $fd 0
+    while {[gets $fd line] >= 0} {
+        if {[regexp "$class: (.*)" $line match value]} {
+            set upresult $value
+            return 1
+        }
+    }
+    return 0
+}
+
 # check_statefile
 # Check completed/selected state of target/variant $name
 proc check_statefile {class name fd} {
@@ -1683,19 +1841,24 @@
 
     array set upoldvariations {}
 
-    seek $fd 0 end
-    if {[tell $fd] == 0} {
-        # Statefile is empty, skipping further tests
-        return 0
-    }
-
+    set variants_found no
+    set targets_found no
     seek $fd 0
     while {[gets $fd line] >= 0} {
         if {[regexp "variant: (.*)" $line match name]} {
             set upoldvariations([string range $name 1 end]) [string range $name 0 0]
+            set variants_found yes
         }
+        if {[regexp "target: .*" $line]} {
+            set targets_found yes
+        }
     }
 
+    if {![tbool variants_found] && ![tbool targets_found]} {
+        # Statefile is "empty", skipping further tests
+        return 0
+    }
+
     set mismatch 0
     if {[array size upoldvariations] != [array size upvariations]} {
         set mismatch 1
@@ -1790,7 +1953,7 @@
 }
 
 proc eval_variants {variations} {
-    global all_variants ports_force PortInfo portvariants negated_variants
+    global all_variants ports_force PortInfo requested_variations portvariants negated_variants
     set dlist $all_variants
     upvar $variations upvariations
     set chosen [choose_variants $dlist upvariations]
@@ -1801,16 +1964,18 @@
     # Check to make sure the requested variations are available with this
     # port, if one is not, warn the user and remove the variant from the
     # array.
+    # Save the originally requested set in requested_variations.
+    array set requested_variations [array get upvariations]
     foreach key [array names upvariations *] {
         if {![info exists PortInfo(variants)] ||
             [lsearch $PortInfo(variants) $key] == -1} {
-            ui_debug "Requested variant $key is not provided by port $portname."
+            ui_debug "Requested variant $upvariations($key)$key is not provided by port $portname."
             array unset upvariations $key
         }
     }
 
     # now that we've selected variants, change all provides [a b c] to [a-b-c]
-    # this will eliminate ambiguity between item a, b, and a-b while fulfilling requirments.
+    # this will eliminate ambiguity between item a, b, and a-b while fulfilling requirements.
     #foreach obj $dlist {
     #    $obj set provides [list [join [$obj get provides] -]]
     #}
@@ -1954,9 +2119,7 @@
     foreach target $args {
         set origproc [ditem_key $ditem procedure]
         set ident [ditem_key $ditem name]
-        if {[info commands $target] != ""} {
-            ui_debug "$ident registered provides '$target', a pre-existing procedure. Target override will not be provided"
-        } else {
+        if {[info commands $target] == ""} {
             proc $target {args} "
                 variable proc_index
                 set proc_index \[llength \[ditem_key $ditem proc\]\]
@@ -2239,17 +2402,32 @@
     set groupFile [getportresourcepath $porturl "port1.0/group/${group}-${version}.tcl"]
 
     if {[file exists $groupFile]} {
-        ui_debug "Using group file $groupFile"
         uplevel "source $groupFile"
     } else {
-        ui_warn "Group file could not be located."
+        ui_warn "PortGroup ${group} ${version} could not be located. ${group}-${version}.tcl does not exist."
     }
 }
 
-# return path where the image/archive for this port will be stored
+# return filename of the archive for this port
+proc get_portimage_name {} {
+    global portdbpath subport version revision portvariants os.platform os.major portarchivetype
+    set ret "${subport}-${version}_${revision}${portvariants}.${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"
+    # should really look up NAME_MAX here, but it's 255 for all OS X so far
+    # (leave 10 chars for an extension like .rmd160 on the sig file)
+    if {[string length $ret] > 245 && ${portvariants} != ""} {
+        # try hashing the variants
+        set ret "${subport}-${version}_${revision}+[rmd160 string ${portvariants}].${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"
+    }
+    if {[string length $ret] > 245} {
+        error "filename too long: $ret"
+    }
+    return $ret
+}
+
+# return path where a newly created image/archive for this port will be stored
 proc get_portimage_path {} {
-    global registry.path subport version revision portvariants os.platform os.major portarchivetype
-    return [file join ${registry.path} software ${subport} "${subport}-${version}_${revision}${portvariants}.${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"]
+    global portdbpath subport
+    return [file join ${portdbpath} software ${subport} [get_portimage_name]]
 }
 
 # return list of archive types that we can extract
@@ -2257,7 +2435,7 @@
     global supported_archive_types
     if {![info exists supported_archive_types]} {
         set supported_archive_types {}
-        foreach type {tbz2 tbz tgz tar txz tlz xar xpkg zip cpgz cpio} {
+        foreach type {tbz2 tbz tgz tar txz tlz xar zip cpgz cpio} {
             if {[catch {archiveTypeIsSupported $type}] == 0} {
                 lappend supported_archive_types $type
             }
@@ -2266,6 +2444,28 @@
     return $supported_archive_types
 }
 
+# return path to a downloaded or installed archive for this port
+proc find_portarchive_path {} {
+    global portdbpath subport version revision portvariants
+    set installed 0
+    if {[registry_exists $subport $version $revision $portvariants]} {
+        set installed 1
+    }
+    set archiverootname [file rootname [get_portimage_name]]
+    foreach unarchive.type [supportedArchiveTypes] {
+        set fullarchivename "${archiverootname}.${unarchive.type}"
+        if {$installed} {
+            set fullarchivepath [file join $portdbpath software $subport $fullarchivename]
+        } else {
+            set fullarchivepath [file join $portdbpath incoming/verified $fullarchivename]
+        }
+        if {[file isfile $fullarchivepath]} {
+            return $fullarchivepath
+        }
+    }
+    return ""
+}
+
 # check if archive type is supported by current system
 # returns an error code if it is not
 proc archiveTypeIsSupported {type} {
@@ -2311,7 +2511,7 @@
                 }
             }
         }
-        xar|xpkg {
+        xar {
             set xar "xar"
             if {[catch {set xar [findBinary $xar ${portutil::autoconf::xar_path}]} errmsg] == 0} {
                 return 0
@@ -2472,8 +2672,8 @@
     if { [getuid] == 0 } {
         if {[geteuid] != 0} {
             # if started with sudo but have dropped the privileges
+            seteuid $euid
             setegid $egid
-            seteuid $euid
             ui_debug "euid/egid changed to: [geteuid]/[getegid]"
             chown  ${path} ${macportsuser}
             ui_debug "chowned $path to $macportsuser"
@@ -2497,8 +2697,8 @@
     if {[getuid] == 0} {
         if {[geteuid] != 0} {
             # Started as root, but not root now
+            seteuid $euid
             setegid $egid
-            seteuid $euid
             ui_debug "euid/egid changed to: [geteuid]/[getegid]"
             ui_debug "setting attributes on $file"
             eval file attributes {$file} $attributes
@@ -2525,8 +2725,8 @@
     if { [getuid] == 0 && [geteuid] != 0 } {
     # if started with sudo but have dropped the privileges
         ui_debug "Can't run $action on this port without elevated privileges. Escalating privileges back to root."
+        seteuid $euid
         setegid $egid
-        seteuid $euid
         ui_debug "euid changed to: [geteuid]. egid changed to: [getegid]."
     } elseif { [getuid] != 0 } {
         return -code error "MacPorts requires root privileges for this action"
@@ -2749,15 +2949,20 @@
                 set ok 3.2
                 set rec 3.2.6
             }
-            default {
+            10.7 {
                 set min 4.1
                 set ok 4.1
-                set rec 4.1
+                set rec 4.5.2
             }
+            default {
+                set min 4.4
+                set ok 4.4
+                set rec 4.5.2
+            }
         }
         if {$xcodeversion == "none"} {
             ui_warn "Xcode does not appear to be installed; most ports will likely fail to build."
-            if {[file exists "/Applications/Install XCode.app"]} {
+            if {[file exists "/Applications/Install Xcode.app"]} {
                 ui_warn "You downloaded Xcode from the Mac App Store but didn't install it. Run \"Install Xcode\" in the /Applications folder."
             }
         } elseif {[vercmp $xcodeversion $min] < 0} {
@@ -2766,34 +2971,81 @@
         } elseif {[vercmp $xcodeversion $ok] < 0} {
             ui_warn "The installed version of Xcode (${xcodeversion}) is known to cause problems. Version $rec or later is recommended on Mac OS X ${macosx_version}."
         }
+
+        # Xcode 4.3 requires the command-line utilities package to be
+        # installed. 
+        if {[vercmp $xcodeversion 4.3] >= 0 ||
+            ($xcodeversion == "none" && [file exists "/Applications/Xcode.app"])} {
+            if {![file exists "/usr/bin/make"]} {
+                ui_warn "The Command Line Tools for Xcode don't appear to be installed; most ports will likely fail to build."
+                ui_warn "See http://guide.macports.org/chunked/installing.xcode.html for more information."
+            }
+        }
+        
     }
     return 0
 }
 
 # check if we can unarchive this port
 proc _archive_available {} {
-    global subport version revision portvariants ports_source_only workpath \
-           registry.path os.platform os.major porturl
+    global ports_source_only porturl portutil::archive_available_result
 
+    if {[info exists archive_available_result]} {
+        return $archive_available_result
+    }
+
     if {[tbool ports_source_only]} {
+        set archive_available_result 0
         return 0
     }
 
-    set found 0
-    foreach unarchive.type [supportedArchiveTypes] {
-        set fullarchivepath [file join ${registry.path} software ${subport} "${subport}-${version}_${revision}${portvariants}.${os.platform}_${os.major}.[join [get_canonical_archs] -].${unarchive.type}"]
-        if {[file isfile $fullarchivepath]} {
-            set found 1
-            break
-        }
+    if {[find_portarchive_path] != ""} {
+        set archive_available_result 1
+        return 1
     }
 
-    if {!$found && [file rootname [file tail $porturl]] == [file rootname [file tail [get_portimage_path]]] && [file extension $porturl] != ""} {
-        set found 1
+    set archiverootname [file rootname [get_portimage_name]]
+    if {[file rootname [file tail $porturl]] == $archiverootname && [file extension $porturl] != ""} {
+        set archive_available_result 1
+        return 1
     }
 
-    # TODO: maybe check if there's an archive available on the server - this
-    # is much less useful otherwise now that archive == installed image
+    # check if there's an archive available on the server
+    global archive_sites
+    set mirrors macports_archives
+    if {[lsearch $archive_sites macports_archives::*] == -1} {
+        set mirrors [lindex [split [lindex $archive_sites 0] :] 0]
+    }
+    if {$mirrors == {}} {
+        set archive_available_result 0
+        return 0
+    }
+    set archivetype $portfetch::mirror_sites::archive_type($mirrors)
+    set archivename "${archiverootname}.${archivetype}"
+    # grab first site, should conventionally be the master mirror
+    set sites_entry [lindex $portfetch::mirror_sites::sites($mirrors) 0]
+    # look for and strip off any tag, which will start with the first colon after the
+    # first slash after the ://
+    set lastcolon [string last : $sites_entry]
+    set aftersep [expr [string first : $sites_entry] + 3]
+    set firstslash [string first / $sites_entry $aftersep]
+    if {$firstslash != -1 && $firstslash < $lastcolon} {
+        incr lastcolon -1
+        set site [string range $sites_entry 0 $lastcolon]
+    } else {
+        set site $sites_entry
+    }
+    if {[string index $site end] != "/"} {
+        append site "/[option archive.subdir]"
+    } else {
+        append site [option archive.subdir]
+    }
+    set url [portfetch::assemble_url $site $archivename]
+    if {![catch {curl getsize $url} result]} {
+        set archive_available_result 1
+        return 1
+    }
 
-    return $found
+    set archive_available_result 0
+    return 0
 }

Copied: branches/gsoc11-statistics/base/src/port1.0/tests/common.tcl (from rev 105084, trunk/base/src/port1.0/tests/common.tcl)
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/tests/common.tcl	                        (rev 0)
+++ branches/gsoc11-statistics/base/src/port1.0/tests/common.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -0,0 +1,18 @@
+proc test_equal {statement value} {
+    uplevel 1 "\
+        puts -nonewline {checking if $statement == \"$value\"... }
+        if {\[catch {
+                set actual $statement
+                if {\$actual == \[subst {$value}\]} { \n\
+                    puts yes
+                } else { \n\
+                    puts \"no (was \$actual)\" \n\
+                    exit 1 \n\
+                } \n\
+            } msg\]} { \n\
+                puts \"caught error: \$msg\" \n\
+                exit 1 \n\
+            }"
+}
+
+

Copied: branches/gsoc11-statistics/base/src/port1.0/tests/portdestroot.tcl (from rev 105084, trunk/base/src/port1.0/tests/portdestroot.tcl)
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/tests/portdestroot.tcl	                        (rev 0)
+++ branches/gsoc11-statistics/base/src/port1.0/tests/portdestroot.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -0,0 +1,40 @@
+source [file join [lindex $argv 0] macports1.0 macports_fastload.tcl]
+package require macports
+mportinit
+
+source [file dirname [info script]]/../portdestroot.tcl
+source [file dirname [info script]]/common.tcl
+
+namespace eval tests {
+
+proc "when destroot cmd is not gmake no -w argument is added" {} {
+    global build.type build.cmd destroot.cmd destroot.target
+
+    set build.type "gnu"
+    set build.cmd "gmake"
+    set destroot.cmd "_destroot_cmd_"
+    set destroot.target "_target_"
+
+    test_equal {[portdestroot::destroot_getargs]} "_target_"
+}
+
+proc "when destroot cmd is gmake a -w argument is added" {} {
+    global build.type build.cmd destroot.cmd destroot.target
+
+    set build.type "gnu"
+    set build.cmd "_build_cmd_"
+    set destroot.cmd "gmake"
+    set destroot.target "_target_"
+
+    test_equal {[portdestroot::destroot_getargs]} "-w _target_"
+}
+
+
+# run all tests
+foreach proc [info procs *] {
+    puts "* ${proc}"
+    $proc
+}
+
+# namespace eval tests
+}

Copied: branches/gsoc11-statistics/base/src/port1.0/tests/portfetch.tcl (from rev 105084, trunk/base/src/port1.0/tests/portfetch.tcl)
===================================================================
--- branches/gsoc11-statistics/base/src/port1.0/tests/portfetch.tcl	                        (rev 0)
+++ branches/gsoc11-statistics/base/src/port1.0/tests/portfetch.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -0,0 +1,58 @@
+source [file join [lindex $argv 0] macports1.0 macports_fastload.tcl]
+package require macports
+mportinit
+
+set scriptdir [file dirname [info script]]
+source ${scriptdir}/../portfetch.tcl
+source ${scriptdir}/common.tcl
+
+namespace eval tests {
+
+proc "mirror tags are parsed correctly" {} {
+    global distfiles master_sites name dist_subdir filespath scriptdir
+
+    set name test
+    set filespath $scriptdir
+    set dist_subdir tset
+    set portfetch::mirror_sites::sites(macports_test) {
+        http://distfiles.macports.org/:mirror
+        http://distfiles2.macports.org:80/:mirror
+        http://distfiles3.macports.org:80/
+        http://distfiles4.macports.org:80/some/subdir/
+        http://distfiles5.macports.org:80/some/subdir/:mirror
+    }
+    set distfiles test.tar.bz2
+    set master_sites macports_test
+    set fetch_urls {}
+    portfetch::checksites [list master_sites {}] ""
+    portfetch::checkdistfiles fetch_urls
+
+    global portfetch::urlmap
+    foreach {url_var distfile} $fetch_urls {
+        if {![info exists urlmap($url_var)]} {
+            set urlmap($url_var) $urlmap(master_sites)
+        }
+        foreach site $urlmap($url_var) {
+            set file_url [portfetch::assemble_url $site $distfile]
+            lappend all_file_urls $file_url
+        }
+    }
+    set all_file_urls [lsort $all_file_urls]
+
+    set expected [list http://distfiles.macports.org/tset/test.tar.bz2 \
+                       http://distfiles2.macports.org:80/tset/test.tar.bz2 \
+                       http://distfiles3.macports.org:80/test/test.tar.bz2 \
+                       http://distfiles4.macports.org:80/some/subdir/test/test.tar.bz2 \
+                       http://distfiles5.macports.org:80/some/subdir/tset/test.tar.bz2]
+
+    test_equal {$all_file_urls} {$expected}
+}
+
+# run all tests
+foreach proc [info procs *] {
+    puts "* ${proc}"
+    $proc
+}
+
+# namespace eval tests
+}

Modified: branches/gsoc11-statistics/base/src/programs/daemondo/main.c
===================================================================
--- branches/gsoc11-statistics/base/src/programs/daemondo/main.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/programs/daemondo/main.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -921,7 +921,9 @@
     header.msgh_id          = sig;
     
     mach_msg_return_t status = mach_msg_send(&header);
-    status = 0;
+    if (status != 0) {
+        LogMessage("mach_msg_send failed in handle_child_signal!\n");
+    }
 }
 
 
@@ -939,7 +941,9 @@
     header.msgh_id          = sig;
     
     mach_msg_return_t status = mach_msg_send(&header);
-    status = 0;
+    if (status != 0) {
+        LogMessage("mach_msg_send failed in handle_generic_signal!\n");
+    }
 }
 
 

Modified: branches/gsoc11-statistics/base/src/registry2.0/entry.c
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/entry.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/entry.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/registry2.0/graph.c
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/graph.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/graph.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -43,7 +43,7 @@
 
 void DeleteGraph(graph* g) {
     sqlite3_stmt* stmt;
-    if ((sqlite3_prepare(g->db, "DETACH DATABASE registry", -1, &stmt, NULL)
+    if ((sqlite3_prepare_v2(g->db, "DETACH DATABASE registry", -1, &stmt, NULL)
                 != SQLITE_OK)
             || (sqlite3_step(stmt) != SQLITE_DONE)) {
         fprintf(stderr, "error: registry db not detached correctly (%s)\n",
@@ -80,11 +80,11 @@
             printf("initializing\n");
         }
 
-        if ((sqlite3_prepare(db, query, -1, &stmt, NULL) == SQLITE_OK)
+        if ((sqlite3_prepare_v2(db, query, -1, &stmt, NULL) == SQLITE_OK)
                 && (sqlite3_step(stmt) == SQLITE_DONE)) {
             sqlite3_finalize(stmt);
             if (!needsInit
-                    || ((sqlite3_prepare(db, "CREATE TABLE registry.ports "
+                    || ((sqlite3_prepare_v2(db, "CREATE TABLE registry.ports "
                                 "(name, portfile, url, location, epoch, "
                                 "version, revision, variants, state)", -1,
                                 &stmt, NULL)

Modified: branches/gsoc11-statistics/base/src/registry2.0/item.c
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/item.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/item.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -44,7 +44,7 @@
     sqlite_int64 rowid = ((item_t*)clientData)->rowid;
     sqlite3* db = ((item_t*)clientData)->db;
     sqlite3_stmt* stmt;
-    sqlite3_prepare(db, "DELETE FROM items WHERE rowid=?", -1, &stmt, NULL);
+    sqlite3_prepare_v2(db, "DELETE FROM items WHERE rowid=?", -1, &stmt, NULL);
     sqlite3_bind_int(stmt, rowid, 1);
     sqlite3_step(stmt);
     sqlite3_finalize(stmt);
@@ -67,7 +67,7 @@
                 == TCL_OK) {
         sqlite3_stmt* stmt;
         /* record the proc name in case we need to return it in a search */
-        if ((sqlite3_prepare(db, "UPDATE items SET proc=? WHERE rowid=?", -1,
+        if ((sqlite3_prepare_v2(db, "UPDATE items SET proc=? WHERE rowid=?", -1,
                     &stmt, NULL) == SQLITE_OK)
                 && (sqlite3_bind_text(stmt, 1, name, -1, SQLITE_STATIC)
                     == SQLITE_OK)
@@ -194,7 +194,7 @@
             insert_size -= 7 + strlen(key);
         }
     }
-    r = sqlite3_prepare(db, query, -1, &stmt, NULL);
+    r = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
     free(query);
     for (i=2; i<objc; i++) {
         char* val;

Modified: branches/gsoc11-statistics/base/src/registry2.0/itemobj.c
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/itemobj.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/itemobj.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -51,7 +51,7 @@
         Tcl_WrongNumArgs(interp, 2, objv, "");
         return TCL_ERROR;
     }
-    sqlite3_prepare(item->db, "UPDATE items SET refcount = refcount+1 WHERE "
+    sqlite3_prepare_v2(item->db, "UPDATE items SET refcount = refcount+1 WHERE "
             "rowid=?", -1, &stmt, NULL);
     sqlite3_bind_int64(stmt, 1, item->rowid);
     sqlite3_step(stmt);
@@ -72,12 +72,12 @@
         Tcl_WrongNumArgs(interp, 2, objv, "");
         return TCL_ERROR;
     }
-    sqlite3_prepare(item->db, "UPDATE items SET refcount = refcount-1 "
+    sqlite3_prepare_v2(item->db, "UPDATE items SET refcount = refcount-1 "
             "WHERE rowid=?", -1, &stmt, NULL);
     sqlite3_bind_int64(stmt, 1, item->rowid);
     sqlite3_step(stmt);
     sqlite3_finalize(stmt);
-    sqlite3_prepare(item->db, "SELECT refcount FROM items WHERE rowid=?", -1,
+    sqlite3_prepare_v2(item->db, "SELECT refcount FROM items WHERE rowid=?", -1,
             &stmt, NULL);
     sqlite3_bind_int64(stmt, 1, item->rowid);
     sqlite3_step(stmt);
@@ -111,7 +111,7 @@
             const char* result;
             Tcl_Obj* resultObj;
             snprintf(query, sizeof(query), "SELECT %s FROM items WHERE rowid=?", key);
-            sqlite3_prepare(item->db, query, -1, &stmt, NULL);
+            sqlite3_prepare_v2(item->db, query, -1, &stmt, NULL);
             sqlite3_bind_int64(stmt, 1, item->rowid);
             sqlite3_step(stmt);
             /* eliminate compiler warning about signedness */
@@ -134,7 +134,7 @@
             char* key = Tcl_GetString(objv[2]);
             char* value = Tcl_GetString(objv[3]);
             snprintf(query, sizeof(query), "UPDATE items SET %s=? WHERE rowid=?", key);
-            sqlite3_prepare(item->db, query, -1, &stmt, NULL);
+            sqlite3_prepare_v2(item->db, query, -1, &stmt, NULL);
             sqlite3_bind_text(stmt, 1, value, -1, SQLITE_STATIC);
             sqlite3_bind_int64(stmt, 2, item->rowid);
             sqlite3_step(stmt);

Modified: branches/gsoc11-statistics/base/src/registry2.0/portimage.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/portimage.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/portimage.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -372,7 +372,7 @@
                     throw MACPORTS "No '$tar' was found on this system!"
                 }
             }
-            xar|xpkg {
+            xar {
                 set xar "xar"
                 if {[catch {set xar [macports::findBinary $xar ${macports::autoconf::xar_path}]} errmsg] == 0} {
                     ui_debug "Using $xar"

Modified: branches/gsoc11-statistics/base/src/registry2.0/portuninstall.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/portuninstall.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/portuninstall.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -217,7 +217,9 @@
         # files so just ignore the failure
         catch {file delete [::file dirname $imagefile]}
 
-        registry::entry delete $port
+        registry::write {
+            registry::entry delete $port
+        }
     }
     
     # uninstall dependencies if requested

Modified: branches/gsoc11-statistics/base/src/registry2.0/receipt_flat.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/receipt_flat.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/receipt_flat.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,7 +1,7 @@
 # receipt_flat.tcl
 # $Id$
 #
-# Copyright (c) 2005, 2007-2009 The MacPorts Project
+# Copyright (c) 2005, 2007-2012 The MacPorts Project
 # Copyright (c) 2004 Will Barton <wbb4 at opendarwin.org>
 # Copyright (c) 2004 Paul Guyot, The MacPorts Project.
 # Copyright (c) 2002 Apple Inc.

Modified: branches/gsoc11-statistics/base/src/registry2.0/registry.c
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/registry.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/registry.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/registry2.0/registry.tcl
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/registry.tcl	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/registry.tcl	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,6 +1,6 @@
 # registry.tcl
 #
-# Copyright (c) 2004-2005, 2007-2010 The MacPorts Project
+# Copyright (c) 2004-2005, 2007-2012 The MacPorts Project
 # Copyright (c) 2004 Will Barton <wbb4 at opendarwin.org>
 # Copyright (c) 2002 Apple Inc.
 # All rights reserved.

Modified: branches/gsoc11-statistics/base/src/registry2.0/util.c
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/util.c	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/util.c	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/src/registry2.0/util.h
===================================================================
--- branches/gsoc11-statistics/base/src/registry2.0/util.h	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/src/registry2.0/util.h	2013-04-09 18:46:31 UTC (rev 105085)
@@ -3,6 +3,7 @@
  * $Id$
  *
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
+ * Copyright (c) 2012 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-statistics/base/tests/Makefile
===================================================================
--- branches/gsoc11-statistics/base/tests/Makefile	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/Makefile	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,6 +1,6 @@
 include ../Mk/macports.autoconf.mk
 
-TESTS?=checksums-1 svn-and-patchsites envvariables site-tags trace universal universal-2 xcodeversion dependencies-c dependencies-d dependencies-e case-insensitive-deactivate variants
+TESTS?=checksums-1 svn-and-patchsites envvariables site-tags trace universal universal-2 xcodeversion dependencies-c dependencies-d dependencies-e case-insensitive-deactivate variants statefile-version1 statefile-version1-outdated statefile-version2 statefile-version2-outdated statefile-version2-invalid statefile-unknown-version
 
 PWD=$(shell pwd)
 
@@ -64,6 +64,10 @@
 				rm -f difference output.sed; \
 			fi) && \
 			success=$$(( success + 1 )); \
+			if [ -n "`PORTSRC=$(PWD)/test-macports.conf $(bindir)/port -q echo installed`" ]; then \
+			    PORTSRC=$(PWD)/test-macports.conf $(bindir)/port -f clean --all installed > /dev/null && \
+			    PORTSRC=$(PWD)/test-macports.conf $(bindir)/port -f uninstall installed > /dev/null; \
+			fi; \
 		fi; \
 		num=$$(( num + 1 )); \
 	done; \

Modified: branches/gsoc11-statistics/base/tests/test/checksums-1/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/checksums-1/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/checksums-1/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
---->  Fetching checksum
---->  Verifying checksum(s) for checksum
+--->  Fetching distfiles for checksum
+--->  Verifying checksums for checksum
 --->  Extracting checksum
 --->  Configuring checksum
 --->  Building checksum

Modified: branches/gsoc11-statistics/base/tests/test/dependencies-c/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/dependencies-c/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/dependencies-c/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,8 +1,7 @@
 --->  Computing dependencies for dependencies-c
 --->  Dependencies to be installed: dependencies-a dependencies-b
---->  Fetching archive for dependencies-b
---->  Fetching dependencies-b
---->  Verifying checksum(s) for dependencies-b
+--->  Fetching distfiles for dependencies-b
+--->  Verifying checksums for dependencies-b
 --->  Extracting dependencies-b
 --->  Configuring dependencies-b
 --->  Building dependencies-b
@@ -10,9 +9,8 @@
 --->  Installing dependencies-b @1_0
 --->  Activating dependencies-b @1_0
 --->  Cleaning dependencies-b
---->  Fetching archive for dependencies-a
---->  Fetching dependencies-a
---->  Verifying checksum(s) for dependencies-a
+--->  Fetching distfiles for dependencies-a
+--->  Verifying checksums for dependencies-a
 --->  Extracting dependencies-a
 --->  Configuring dependencies-a
 --->  Building dependencies-a
@@ -20,8 +18,8 @@
 --->  Installing dependencies-a @1_0+i_want_b
 --->  Activating dependencies-a @1_0+i_want_b
 --->  Cleaning dependencies-a
---->  Fetching dependencies-c
---->  Verifying checksum(s) for dependencies-c
+--->  Fetching distfiles for dependencies-c
+--->  Verifying checksums for dependencies-c
 --->  Extracting dependencies-c
 --->  Configuring dependencies-c
 --->  Building dependencies-c

Modified: branches/gsoc11-statistics/base/tests/test/dependencies-d/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/dependencies-d/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/dependencies-d/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,8 +1,9 @@
 Warning: depends option is not handled yet
 Warning: depends option is not handled yet
 --->  Computing dependencies for dependencies-d
---->  Fetching dependencies-b
---->  Verifying checksum(s) for dependencies-b
+--->  Dependencies to be installed: dependencies-a dependencies-b
+--->  Fetching distfiles for dependencies-b
+--->  Verifying checksums for dependencies-b
 --->  Extracting dependencies-b
 --->  Configuring dependencies-b
 --->  Building dependencies-b
@@ -10,8 +11,8 @@
 --->  Installing dependencies-b @1_0
 --->  Activating dependencies-b @1_0
 --->  Cleaning dependencies-b
---->  Fetching dependencies-a
---->  Verifying checksum(s) for dependencies-a
+--->  Fetching distfiles for dependencies-a
+--->  Verifying checksums for dependencies-a
 --->  Extracting dependencies-a
 --->  Configuring dependencies-a
 --->  Building dependencies-a
@@ -19,8 +20,8 @@
 --->  Installing dependencies-a @1_0+i_want_b
 --->  Activating dependencies-a @1_0+i_want_b
 --->  Cleaning dependencies-a
---->  Fetching dependencies-d
---->  Verifying checksum(s) for dependencies-d
+--->  Fetching distfiles for dependencies-d
+--->  Verifying checksums for dependencies-d
 --->  Extracting dependencies-d
 --->  Configuring dependencies-d
 --->  Building dependencies-d

Modified: branches/gsoc11-statistics/base/tests/test/dependencies-e/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/dependencies-e/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/dependencies-e/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,4 +1,5 @@
 --->  Computing dependencies for dependencies-e
 Error: Dependency 'docbook-xml-4.1.2' not found.
-Error: Status 1 encountered during processing.
-To report a bug, see <http://guide.macports.org/#project.tickets>
+To report a bug, follow the instructions in the guide:
+    http://guide.macports.org/#project.tickets
+Error: Processing of port dependencies-e failed

Modified: branches/gsoc11-statistics/base/tests/test/envvariables/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/envvariables/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/envvariables/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
---->  Fetching envvariables
---->  Verifying checksum(s) for envvariables
+--->  Fetching distfiles for envvariables
+--->  Verifying checksums for envvariables
 --->  Extracting envvariables
 --->  Configuring envvariables
 --->  Building envvariables

Modified: branches/gsoc11-statistics/base/tests/test/site-tags/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/site-tags/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/site-tags/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,7 +1,7 @@
---->  Fetching site-tags
+--->  Fetching distfiles for site-tags
 --->  Attempting to fetch app-bm.tar.gz from http://www.douglas.stebila.ca/files/code/vim/app/
 --->  Attempting to fetch doc.tar.gz from http://www.douglas.stebila.ca/files/code/vim/doc/
---->  Verifying checksum(s) for site-tags
+--->  Verifying checksums for site-tags
 --->  Extracting site-tags
 --->  Configuring site-tags
 --->  Building site-tags

Modified: branches/gsoc11-statistics/base/tests/test/svn-and-patchsites/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/svn-and-patchsites/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/svn-and-patchsites/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,6 +1,6 @@
---->  Fetching svn-and-patchsites
+--->  Fetching distfiles for svn-and-patchsites
 --->  Attempting to fetch patch-1.5.14.dgc.xlabel_ext.9 from http://home.uchicago.edu/~dgc/sw/mutt/
---->  Verifying checksum(s) for svn-and-patchsites
+--->  Verifying checksums for svn-and-patchsites
 --->  Extracting svn-and-patchsites
 --->  Configuring svn-and-patchsites
 --->  Building svn-and-patchsites

Modified: branches/gsoc11-statistics/base/tests/test/trace/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/trace/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/trace/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
---->  Fetching trace
---->  Verifying checksum(s) for trace
+--->  Fetching distfiles for trace
+--->  Verifying checksums for trace
 --->  Extracting trace
 --->  Configuring trace
 --->  Building trace

Modified: branches/gsoc11-statistics/base/tests/test/variants/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/variants/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/variants/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,7 +1,7 @@
 Utopia variant -- 2
 Utopia variant -- 2
---->  Fetching variants
---->  Verifying checksum(s) for variants
+--->  Fetching distfiles for variants
+--->  Verifying checksums for variants
 --->  Extracting variants
 --->  Configuring variants
 --->  Building variants

Modified: branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile
===================================================================
--- branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/xcodeversion/Portfile	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,30 +1,31 @@
 # $Id$
 
 PortSystem 1.0
-name		xcodeversion
-version		1
-categories	test
-maintainers	pguyot at kallisys.net
-description	Test port for \$xcodeversion
-homepage	http://www.macports.org/
-platforms	darwin
+name        xcodeversion
+version     1
+categories  test
+maintainers pguyot at kallisys.net
+description Test port for \$xcodeversion
+homepage    http://www.macports.org/
+platforms   darwin
 
 long_description ${description}
 
 distfiles
 use_configure no
-build		{}
-destroot	{
-	system "touch ${destroot}${prefix}/lib/${name}"
+build       {}
+destroot    {
+    system "touch ${destroot}${prefix}/lib/${name}"
 }
 
 test {
-	# rpm-vercomp is now deprecated, change it here too when removed
-	# from all ports and base (but keep this test here, meanwhile...)
-	if {$xcodeversion != "" && [rpm-vercomp $xcodeversion 2.1] >= 0} {
-		ui_msg "xcodeversion >= 2.1"
-	} else {
-		ui_msg "xcodeversion = $xcodeversion"
-	}
-	ui_msg "xcodebuildcmd = $xcodebuildcmd"
+    # rpm-vercomp is now deprecated, change it here too when removed
+    # from all ports and base (but keep this test here, meanwhile...)
+    # rpm-vercomp removed from ports r89810, from base r89911
+    if {$xcodeversion != "" && [vercmp $xcodeversion 2.1] >= 0} {
+        ui_msg "xcodeversion >= 2.1"
+    } else {
+        ui_msg "xcodeversion = $xcodeversion"
+    }
+    ui_msg "xcodebuildcmd = $xcodebuildcmd"
 }

Modified: branches/gsoc11-statistics/base/tests/test/xcodeversion/master
===================================================================
--- branches/gsoc11-statistics/base/tests/test/xcodeversion/master	2013-04-09 15:33:21 UTC (rev 105084)
+++ branches/gsoc11-statistics/base/tests/test/xcodeversion/master	2013-04-09 18:46:31 UTC (rev 105085)
@@ -1,5 +1,5 @@
---->  Fetching xcodeversion
---->  Verifying checksum(s) for xcodeversion
+--->  Fetching distfiles for xcodeversion
+--->  Verifying checksums for xcodeversion
 --->  Extracting xcodeversion
 --->  Configuring xcodeversion
 --->  Building xcodeversion
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130409/d626a0da/attachment-0001.html>


More information about the macports-changes mailing list