[98880] branches/gsoc11-post-destroot/base

raimue at macports.org raimue at macports.org
Fri Oct 19 09:03:11 PDT 2012


Revision: 98880
          http://trac.macports.org//changeset/98880
Author:   raimue at macports.org
Date:     2012-10-19 09:03:11 -0700 (Fri, 19 Oct 2012)
Log Message:
-----------
Merge from trunk

Modified Paths:
--------------
    branches/gsoc11-post-destroot/base/ChangeLog
    branches/gsoc11-post-destroot/base/LICENSE
    branches/gsoc11-post-destroot/base/Makefile.in
    branches/gsoc11-post-destroot/base/Mk/macports.autoconf.mk.in
    branches/gsoc11-post-destroot/base/NEWS
    branches/gsoc11-post-destroot/base/aclocal.m4
    branches/gsoc11-post-destroot/base/config/RELEASE_URL
    branches/gsoc11-post-destroot/base/config/macports_version
    branches/gsoc11-post-destroot/base/configure
    branches/gsoc11-post-destroot/base/configure.ac
    branches/gsoc11-post-destroot/base/doc/Makefile
    branches/gsoc11-post-destroot/base/doc/macports.conf.5
    branches/gsoc11-post-destroot/base/doc/macports.conf.in
    branches/gsoc11-post-destroot/base/doc/port.1
    branches/gsoc11-post-destroot/base/doc/portfile.7
    branches/gsoc11-post-destroot/base/doc/portgroup.7
    branches/gsoc11-post-destroot/base/doc/porthier.7
    branches/gsoc11-post-destroot/base/doc/prefix.mtree.in
    branches/gsoc11-post-destroot/base/doc/sources.conf
    branches/gsoc11-post-destroot/base/m4/tcl.m4
    branches/gsoc11-post-destroot/base/macports-pubkey.pem
    branches/gsoc11-post-destroot/base/portmgr/ReleaseProcess
    branches/gsoc11-post-destroot/base/portmgr/dmg/InstallationCheck
    branches/gsoc11-post-destroot/base/portmgr/dmg/License.html
    branches/gsoc11-post-destroot/base/portmgr/dmg/ReadMe.rtf
    branches/gsoc11-post-destroot/base/portmgr/dmg/postflight
    branches/gsoc11-post-destroot/base/portmgr/fedora/macports.spec
    branches/gsoc11-post-destroot/base/portmgr/jobs/GuideRegen.sh
    branches/gsoc11-post-destroot/base/portmgr/jobs/PortIndex2MySQL.tcl
    branches/gsoc11-post-destroot/base/portmgr/jobs/mirror_macports.sh
    branches/gsoc11-post-destroot/base/portmgr/jobs/mprsyncup
    branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.PortIndex2MySQL.plist
    branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.mprsyncup.plist
    branches/gsoc11-post-destroot/base/portmgr/jobs/port_binary_distributable.tcl
    branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_lint.pl
    branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_mirror.pl
    branches/gsoc11-post-destroot/base/portmgr/packaging/dpkgall.tcl
    branches/gsoc11-post-destroot/base/portmgr/packaging/mpkgall.tcl
    branches/gsoc11-post-destroot/base/portmgr/packaging/packageall.tcl
    branches/gsoc11-post-destroot/base/portmgr/packaging/rpmall.tcl
    branches/gsoc11-post-destroot/base/setupenv.bash.in
    branches/gsoc11-post-destroot/base/src/Makefile.in
    branches/gsoc11-post-destroot/base/src/config.h.in
    branches/gsoc11-post-destroot/base/src/cregistry/Makefile
    branches/gsoc11-post-destroot/base/src/cregistry/entry.c
    branches/gsoc11-post-destroot/base/src/cregistry/entry.h
    branches/gsoc11-post-destroot/base/src/cregistry/registry.c
    branches/gsoc11-post-destroot/base/src/cregistry/registry.h
    branches/gsoc11-post-destroot/base/src/cregistry/sql.c
    branches/gsoc11-post-destroot/base/src/cregistry/sql.h
    branches/gsoc11-post-destroot/base/src/cregistry/vercomp.c
    branches/gsoc11-post-destroot/base/src/darwintracelib1.0/Makefile
    branches/gsoc11-post-destroot/base/src/darwintracelib1.0/darwintrace.c
    branches/gsoc11-post-destroot/base/src/images_to_archives.tcl
    branches/gsoc11-post-destroot/base/src/macports1.0/Makefile
    branches/gsoc11-post-destroot/base/src/macports1.0/macports.tcl
    branches/gsoc11-post-destroot/base/src/macports1.0/macports_autoconf.tcl.in
    branches/gsoc11-post-destroot/base/src/macports1.0/macports_dlist.tcl
    branches/gsoc11-post-destroot/base/src/macports1.0/macports_fastload.tcl.in
    branches/gsoc11-post-destroot/base/src/macports1.0/macports_index.tcl
    branches/gsoc11-post-destroot/base/src/macports1.0/macports_util.tcl
    branches/gsoc11-post-destroot/base/src/macports1.0/tests/macports_dlist.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/package.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portarchivefetch.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portdmg.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portdpkg.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portmdmg.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portmpkg.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portpkg.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portportpkg.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portrpm.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portsrpm.tcl
    branches/gsoc11-post-destroot/base/src/package1.0/portunarchive.tcl
    branches/gsoc11-post-destroot/base/src/pextlib1.0/Makefile
    branches/gsoc11-post-destroot/base/src/pextlib1.0/Pextlib.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/curl.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/md_wrappers.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/system.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/base32.tcl
    branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/curl.tcl
    branches/gsoc11-post-destroot/base/src/pextlib1.0/tracelib.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.h
    branches/gsoc11-post-destroot/base/src/pkg_mkindex.sh.in
    branches/gsoc11-post-destroot/base/src/port/Makefile
    branches/gsoc11-post-destroot/base/src/port/port-help.tcl
    branches/gsoc11-post-destroot/base/src/port/port.tcl
    branches/gsoc11-post-destroot/base/src/port/portindex.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/Makefile
    branches/gsoc11-post-destroot/base/src/port1.0/fetch_common.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/port.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/port_autoconf.tcl.in
    branches/gsoc11-post-destroot/base/src/port1.0/portactivate.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portbuild.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portchecksum.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portclean.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portconfigure.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portdeactivate.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portdepends.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portdestroot.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portdistcheck.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portdistfiles.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portextract.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portfetch.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portinstall.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portlint.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portlivecheck.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portload.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portmain.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portmirror.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portpatch.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portstartupitem.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portsubmit.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/porttrace.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portuninstall.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portunload.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portutil.tcl
    branches/gsoc11-post-destroot/base/src/portindex/portregister.pl
    branches/gsoc11-post-destroot/base/src/portindex/portsubmit.pl
    branches/gsoc11-post-destroot/base/src/programs/daemondo/Makefile.in
    branches/gsoc11-post-destroot/base/src/programs/daemondo/main.c
    branches/gsoc11-post-destroot/base/src/registry2.0/Makefile
    branches/gsoc11-post-destroot/base/src/registry2.0/entry.c
    branches/gsoc11-post-destroot/base/src/registry2.0/graph.c
    branches/gsoc11-post-destroot/base/src/registry2.0/item.c
    branches/gsoc11-post-destroot/base/src/registry2.0/itemobj.c
    branches/gsoc11-post-destroot/base/src/registry2.0/portimage.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/portuninstall.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/receipt_flat.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/receipt_sqlite.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/registry.c
    branches/gsoc11-post-destroot/base/src/registry2.0/registry.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/registry_autoconf.tcl.in
    branches/gsoc11-post-destroot/base/src/registry2.0/registry_util.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/util.c
    branches/gsoc11-post-destroot/base/src/registry2.0/util.h
    branches/gsoc11-post-destroot/base/src/upgrade_sources_conf_default.tcl
    branches/gsoc11-post-destroot/base/tests/Makefile
    branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Makefile
    branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Portfile.in
    branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/README
    branches/gsoc11-post-destroot/base/tests/test/checksums-1/master
    branches/gsoc11-post-destroot/base/tests/test/dependencies-a/Portfile
    branches/gsoc11-post-destroot/base/tests/test/dependencies-b/Portfile
    branches/gsoc11-post-destroot/base/tests/test/dependencies-c/Portfile
    branches/gsoc11-post-destroot/base/tests/test/dependencies-c/master
    branches/gsoc11-post-destroot/base/tests/test/dependencies-d/Portfile
    branches/gsoc11-post-destroot/base/tests/test/dependencies-d/master
    branches/gsoc11-post-destroot/base/tests/test/dependencies-e/Portfile
    branches/gsoc11-post-destroot/base/tests/test/dependencies-e/master
    branches/gsoc11-post-destroot/base/tests/test/envvariables/Portfile
    branches/gsoc11-post-destroot/base/tests/test/envvariables/master
    branches/gsoc11-post-destroot/base/tests/test/site-tags/Portfile
    branches/gsoc11-post-destroot/base/tests/test/site-tags/master
    branches/gsoc11-post-destroot/base/tests/test/trace/Portfile
    branches/gsoc11-post-destroot/base/tests/test/trace/master
    branches/gsoc11-post-destroot/base/tests/test/universal/Portfile
    branches/gsoc11-post-destroot/base/tests/test/universal-2/Portfile
    branches/gsoc11-post-destroot/base/tests/test/variants/Portfile
    branches/gsoc11-post-destroot/base/tests/test/variants/master
    branches/gsoc11-post-destroot/base/tests/test/xcodeversion/Portfile
    branches/gsoc11-post-destroot/base/tests/test/xcodeversion/master

Added Paths:
-----------
    branches/gsoc11-post-destroot/base/doc/archive_sites.conf
    branches/gsoc11-post-destroot/base/doc/base.mtree.in
    branches/gsoc11-post-destroot/base/portmgr/dmg/Distribution
    branches/gsoc11-post-destroot/base/src/cregistry/file.c
    branches/gsoc11-post-destroot/base/src/cregistry/file.h
    branches/gsoc11-post-destroot/base/src/cregistry/util.c
    branches/gsoc11-post-destroot/base/src/cregistry/util.h
    branches/gsoc11-post-destroot/base/src/machista1.0/
    branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/vercomp.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/portsandbox.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/tests/common.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/tests/portdestroot.tcl
    branches/gsoc11-post-destroot/base/src/port1.0/tests/portfetch.tcl
    branches/gsoc11-post-destroot/base/src/registry2.0/file.c
    branches/gsoc11-post-destroot/base/src/registry2.0/file.h
    branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.c
    branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.h
    branches/gsoc11-post-destroot/base/tests/test/statefile-unknown-version/
    branches/gsoc11-post-destroot/base/tests/test/statefile-version1/
    branches/gsoc11-post-destroot/base/tests/test/statefile-version1-outdated/
    branches/gsoc11-post-destroot/base/tests/test/statefile-version2/
    branches/gsoc11-post-destroot/base/tests/test/statefile-version2-invalid/
    branches/gsoc11-post-destroot/base/tests/test/statefile-version2-outdated/
    branches/gsoc11-post-destroot/base/tests/test/svn-and-patchsites/

Removed Paths:
-------------
    branches/gsoc11-post-destroot/base/tests/test/cvs-and-patchsites/

Property Changed:
----------------
    branches/gsoc11-post-destroot/base/
    branches/gsoc11-post-destroot/base/doc/
    branches/gsoc11-post-destroot/base/portmgr/fedora/macports.spec
    branches/gsoc11-post-destroot/base/src/machista1.0/tests/
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha2.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha2.h
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.c
    branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.h
    branches/gsoc11-post-destroot/base/src/registry2.0/receipt_sqlite.tcl


Property changes on: branches/gsoc11-post-destroot/base
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base:37343-46937
/branches/gsoc09-logging/base:51231-60371
/branches/universal-sanity/base:51872-52323
/branches/variant-descs-14482/base:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/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:78761-98879
/users/perry/base-bugs_and_notes:45682-46060
/users/perry/base-select:44044-44692

Modified: branches/gsoc11-post-destroot/base/ChangeLog
===================================================================
--- branches/gsoc11-post-destroot/base/ChangeLog	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/ChangeLog	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,8 +3,357 @@
 # $Id$
 ###
 
-Unreleased changes:
+Release 2.1.3 (unreleased)
+    - 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)
+
+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)
+
+    - 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)
+
+Release 2.0.2 (2011-09-01 by jmr):
+    - Messages recommending running selfupdate will no longer be printed when
+      selfupdate is being run. (#23094, jmr in r83270, r83391)
+
+    - The PortIndex will not be regenerated during selfupdate when base is
+      outdated. This avoids failure to index ports that use features only
+      available in the current version. (#30739, jmr in r83271)
+
+    - Fixed build failures when the TMPDIR environment variable is set to a
+      directory that is not writable by the macports user.
+      (#30749, jmr in r83267)
+
+    - Fixed error when checksumming distfiles with names containing spaces.
+      (#28568, jmr in r83149)
+
+    - The uninstall and deactivate actions now sort the port list so that
+      dependents are processed before the ports they depend on.
+      (#8431, jmr in r82947)
+
+    - Fixed an issue where a non-universal version of a port could be
+      installed as a dependency as well as the universal version, with
+      unpredictable results, when some ports in the dependency graph needed
+      the universal version but others didn't. (jmr in r82924)
+
+    - Now using a temp dir inside ${prefix} when activating, as /tmp or
+      /var/folders may be on a different volume. (jmr in r82767)
+
+    - Fixed extracting portfile-only archives. (#31033, jmr in r81830)
+
+    - Fixed adduser and addgroup procedures not re-dropping privileges when
+      done. (jmr in r81630)
+
+    - Fixed error activating ports with names containing the string "cpio".
+      (#30532, jmr in r81577)
+
+Release 2.0.1 (2011-08-02 by jmr):
+    - Fixed errors when installing some archives built on a case-sensitive
+      filesystem onto a case-insensitive one. (#30373, jmr in r81562)
+
+    - Fixed users created by MacPorts showing up in the GUI in some places on
+      Lion. (#30168, jeremyhu in r81558)
+
+    - Added replaced_by pseudo-portname selector. (afb in r81475)
+
+    - Added progress output to port image conversion script.
+      (#30347, jmr in r81464)
+
+    - Now doing a better job of avoiding UID conflicts with non-local users
+      when creating the 'macports' user. (#30464, jmr in r81414, r81415) Also
+      improved Tiger compatibility in this area. (jmr in r81454, r81467)
+
+    - Fixed 'port selfupdate' exiting with non-zero status after installing a
+      new version of base. (jmr in r81371)
+
+    - Added --subports to options accepted by 'port info'. (jmr in r81234)
+
+    - Fixed incorrect info sometimes being added to PortIndex entries when
+      using subports. (#30463, jmr in r81361)
+
+    - Fixed descriptions not being shown for default variants. (jmr in r80971)
+
+    - Fixed 'port variants --index'. (jmr in r80969)
+
+Release 2.0.0 (2011-07-22 by jmr):
+
+    - Multiple ports can now be defined in one Portfile using the 'subport'
+      procedure. This reduces code duplication when several ports use very
+      similar code. (jmr in r78062)
+
+    - Privilege dropping is now on by default. The runtime user can be changed
+      when building from source but defaults to 'macports'; this user is
+      created at install time. (jmr in r79025)
+
+    - Fetching from some extremely slow or partially unresponsive servers
+      should now time out as expected. (raimue in r71038)
+
+    - The registry is now "vacuumed" (compacted/defragmented) after
+      uninstalling ports. (jmr in r70608)
+
+    - Downloaded archives are now checked for integrity using digital
+      signatures. Sync and selfupdate can also use a signed tarball. New
+      pubkeys.conf file allows configuring keys to trust.
+      (jmr in r68996, r79093)
+
+    - Added 'actinact' pseudo-portname that expands to installed ports with an
+      active version and at least one inactive version.
+      (#27666, jmr in r79421, based on patch from gmail.com:ww.galen)
+
+    - Added --size option for 'contents' action that makes it print the size
+      of each file. (#27245, jmr in r79365, based on patch from
+      gmail.com:ww.galen)
+
+    - Added 'space' action to show the disk space used by ports' active files.
+      (#27244, jmr in r79349, based on patch from gmail.com:ww.galen)
+
+    - Actions can be abbreviated to an unambiguous prefix of the full name.
+      (#27242, patch from gmail.com:ww.galen committed in r79259)
+
+    - Fixed error when activating ports whose version contains an underscore
+      followed by an integer and a dash. (#28084, jmr in r79167)
+
+    - Deactivating a port that has dependents no longer needs to be forced
+      when the dependents are all inactive. (#29505, jmr in r78086)
+
+    - New option 'add_users' has been added. Setting it will ensure that the
+      listed users are created before all operations that may require them to
+      exist. (#11563, jmr in r78660)
+
+    - 'port info --index' should be much faster and will work with the
+      'current' pseudo-port provided the port has been indexed.
+      (#13673, jmr in r78621)
+
+    - Relocation is explicitly disabled when building pkgs on 10.6, so Apple's
+      Installer won't attempt to overwrite other copies of the same software
+      not installed by MacPorts. (#25174, jmr in r78178)
+
+    - Non-Darwin platforms can once again build base against OpenSSL for
+      checksum support. (#26813, afb in r77865)
+
+    - It is now safe to set svn.post_args, rather than that option being
+      reserved for svn.url. (#27454, jmr in r73825)
+
+    - Variants specified when running 'port mpkg' are now set in the
+      dependencies as well. (#27231, jmr in r73303)
+
+    - Fixed various issues with privilege dropping.
+      (#26899, jmr in r69453 etc.)
+
+    - Trace mode no longer fails on 10.6. (#21582, jmr in r74318, r74369)
+
+    - Ports that create StartupItems (aka launchd plists) should now be
+      installable by unprivileged users. (#10879, jmr in r66700, r75143)
+
+    - Fixed incorrect output from 'port dependents' when using newer SQLite
+      versions. (#27506, patch from gmail.com:mmpestorich committed in r76827)
+
+    - The flat registry format is no longer available. Setting portdbformat to
+      'flat' in macports.conf will result in the sqlite registry being used.
+      (jmr in r77681)
+
+    - Port images are now stored as archives. Archive mode is now effectively
+      always on. Among other benefits, this fixes some bugs with the handling
+      of hard links installed by ports (e.g. #13601).
+
+      Direct mode is no longer available. Existing port image directories, and
+      installed files for direct mode, will be converted to archives when
+      upgrading.
+
+      (#19458, branch by blb, merged by jmr in r77511)
+
+    - master_site_local, patch_site_local, and archive_site_local can be set
+      in macports.conf, with the same effects as the corresponding environment
+      variables. (jmr in r74924)
+
+    - Added 'logfile' action that prints the path to a port's log file.
+      (jmr in r74655)
+
+    - Computing large dependency trees that contain the same port(s) multiple
+      times should be considerably faster. (jmr in r73133)
+
+    - 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)
 
     - Add new ccache_dir and ccache_size options, default path is

Modified: branches/gsoc11-post-destroot/base/LICENSE
===================================================================
--- branches/gsoc11-post-destroot/base/LICENSE	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/LICENSE	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,5 @@
 Copyright (c) 2002 - 2003, Apple Inc.
-Copyright (c) 2004 - 2010, The MacPorts Project.
+Copyright (c) 2004 - 2012, The MacPorts Project.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-post-destroot/base/Makefile.in
===================================================================
--- branches/gsoc11-post-destroot/base/Makefile.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/Makefile.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -8,7 +8,7 @@
 DISTNAME	= MacPorts-${DISTVER}
 DISTARCTAG	= ${DISTTAG}-archive
 DISTARCNAME	= ${DISTNAME}-archive
-SVNURL		= http://svn.macports.org/repository/macports
+SVNURL		= https://svn.macports.org/repository/macports
 
 
 include Mk/macports.autoconf.mk
@@ -32,19 +32,76 @@
 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/"
 # Only run these scripts when not building in a destroot
 ifeq ($(DESTDIR),)
+# create run user if it doesn't exist
+	@if test -n "${DSCL}" -a -n "${DSEDITGROUP}" ; then \
+        if ! ${DSCL} -q . -read /Groups/${RUNUSR} > /dev/null 2>&1 ; then \
+            if test `id -u` -eq 0; then \
+                echo "Creating group \"${RUNUSR}\"" ; \
+                ${DSEDITGROUP} -q -o create ${RUNUSR} ; \
+            else \
+                echo "Not creating group \"${RUNUSR}\" (not root)" ; \
+            fi ; \
+        fi ; \
+        if ! ${DSCL} -q . -list /Users/${RUNUSR} > /dev/null 2>&1 ; then \
+            if test `id -u` -eq 0; then \
+                echo "Creating user \"${RUNUSR}\"" ; \
+                NEXTUID=501; \
+                while test -n "`${DSCL} -q /Search -search /Users UniqueID $$NEXTUID`"; do \
+                    let "NEXTUID=NEXTUID+1"; \
+                done; \
+                ${DSCL} -q . -create /Users/${RUNUSR} UniqueID $$NEXTUID ; \
+                \
+                ${DSCL} -q . -delete /Users/${RUNUSR} AuthenticationAuthority ; \
+                ${DSCL} -q . -delete /Users/${RUNUSR} PasswordPolicyOptions ; \
+                ${DSCL} -q . -delete /Users/${RUNUSR} dsAttrTypeNative:KerberosKeys ; \
+                ${DSCL} -q . -delete /Users/${RUNUSR} dsAttrTypeNative:ShadowHashData ; \
+                \
+                ${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 "${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 \
+                echo "Fixing PrimaryGroupID for user \"${RUNUSR}\"" ; \
+                ${DSCL} -q . -create /Users/${RUNUSR} PrimaryGroupID $$GID ; \
+                ${DSCL} -q . -create /Users/${RUNUSR} RealName MacPorts ; \
+            fi ; \
+        fi ; \
+    else \
+        echo "Can't find ${DSCL} / ${DSEDITGROUP}, not creating user \"${RUNUSR}\"" ; \
+    fi
 # Add [default] tag to the central MacPorts repository, if it isn't already
 	$(TCLSH) src/upgrade_sources_conf_default.tcl "${prefix}"
 # Convert image directories (and direct mode installs) to image archives
 	$(TCLSH) src/images_to_archives.tcl "${macports_tcl_dir}"
 endif
+ifndef SELFUPDATING
 	@echo ""; echo "Congratulations, you have successfully installed the MacPorts system. To get the Portfiles and update the system, add ${prefix}/bin to your PATH and run:"; echo ""
 	@echo "sudo port -v selfupdate"; echo ""
-	@echo "Please read \"man port\", the MacPorts guide at http://guide.macports.org/ and Wiki at http://trac.macports.org/ for full documentation."; echo ""
+	@echo "Please read \"man port\", the MacPorts guide at http://guide.macports.org/ and Wiki at https://trac.macports.org/ for full documentation."; echo ""
+else
+	@echo ""; echo "Congratulations, you have successfully upgraded the MacPorts system."; echo ""
+endif
 
 group::
 	@echo "creating a macports group..." && sudo dseditgroup -o create -n . macports && echo "done! use './configure --with-install-group=macports --with-shared-directory' if you haven't already"
@@ -71,7 +128,7 @@
 	cd ${DISTDIR}; COPY_EXTENDED_ATTRIBUTES_DISABLE=true tar -c ${PKGNAME} | gzip > ${PKGNAME}.tar.gz
 	cd ${DISTDIR}; COPY_EXTENDED_ATTRIBUTES_DISABLE=true tar -c ${PKGNAME} | bzip2 > ${PKGNAME}.tar.bz2
 	cd ${DISTDIR}; for tarball in ${PKGNAME}.tar.*; do { \
-		for type in -md5 -sha1 -ripemd160; do { \
+		for type in -md5 -sha1 -ripemd160 -sha256; do { \
 			openssl dgst $$type $$tarball; \
 		}; done >> ${DISTNAME}.chk.txt; \
 	}; done

Modified: branches/gsoc11-post-destroot/base/Mk/macports.autoconf.mk.in
===================================================================
--- branches/gsoc11-post-destroot/base/Mk/macports.autoconf.mk.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/Mk/macports.autoconf.mk.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -7,12 +7,13 @@
 VPATH			= @srcdir@
 
 CC			= @CC@
-CFLAGS			= @CFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_WERROR)
-OBJCFLAGS		= @OBJCFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_WERROR)
+CFLAGS			= @CFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_PEDANTIC) $(CFLAGS_WERROR)
+OBJCFLAGS		= @OBJCFLAGS@ $(CFLAGS_QUICHEEATERS) $(CFLAGS_PEDANTIC) $(CFLAGS_WERROR)
 CPPFLAGS		= @CPPFLAGS@ @DEFS@ @INCLUDES@ @TCL_INCLUDES@
 TCL_DEFS		= @TCL_DEFS@
 SHLIB_CFLAGS		= @SHLIB_CFLAGS@
 CFLAGS_QUICHEEATERS	= @CFLAGS_QUICHEEATERS@
+CFLAGS_PEDANTIC		= @CFLAGS_PEDANTIC@
 CFLAGS_WERROR		= @CFLAGS_WERROR@
 
 READLINE_CFLAGS		=
@@ -52,11 +53,13 @@
 TCL_PACKAGE_DIR		= @TCL_PACKAGE_DIR@
 macports_tcl_dir	= @macports_tcl_dir@
 
+DSCL			= @DSCL@
+DSEDITGROUP		= @DSEDITGROUP@
 DSTUSR			= @DSTUSR@
 DSTGRP			= @DSTGRP@
 DSTMODE			= @DSTMODE@
+RUNUSR			= @RUNUSR@
 
-
 prefix			= @prefix@
 sysconfdir		= @sysconfdir@
 exec_prefix		= @exec_prefix@

Modified: branches/gsoc11-post-destroot/base/NEWS
===================================================================
--- branches/gsoc11-post-destroot/base/NEWS	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/NEWS	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,3 +1,67 @@
+== 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:
+
+*) Downloaded archives are now checked for integrity using digital signatures.
+   New pubkeys.conf file allows configuring keys to trust.
+
+*) Actions can be abbreviated to an unambiguous prefix of the full name.
+
+*) Ports that create StartupItems (aka launchd plists) should now be
+   installable by unprivileged users.
+
+*) Port images are now stored as archives. Archive mode is now effectively
+   always on. Direct mode and the flat registry format are no longer
+   available. Conversion will happen automatically.
+
+# For Portfile writers:
+
+*) Multiple ports can now be defined in one Portfile using the 'subport'
+   procedure.
+
+*) New option 'add_users' can be set to ensure that the listed users are
+   created at the right times during the install process.
+
+*) SHA256 checksums are now supported.
+
 == Overview of changes from MacPorts 1.8.2 to 1.9.0 ==
 
 # For regular users:
@@ -140,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-post-destroot/base/aclocal.m4
===================================================================
--- branches/gsoc11-post-destroot/base/aclocal.m4	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/aclocal.m4	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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])
@@ -327,9 +327,15 @@
 		AC_MSG_RESULT([$DSTGRP])
 		AC_SUBST(DSTGRP)
 
+		# Set run-user to current user
+		AC_MSG_CHECKING([for macports user])
+		RUNUSR=`id -un`
+		AC_MSG_RESULT([$RUNUSR])
+		AC_SUBST(RUNUSR)
+
 		# Set Tcl package directory to ~/Library/Tcl
 	    AC_MSG_CHECKING(for Tcl package directory)
-		ac_cv_c_tclpkgd="~$DSTUSR/Library/Tcl"
+		ac_cv_c_tclpkgd=`eval echo ~$DSTUSR/Library/Tcl`
 	    # Convert to a native path and substitute into the output files.
 	    PACKAGE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclpkgd}`
 	    TCL_PACKAGE_DIR=${PACKAGE_DIR_NATIVE}
@@ -354,7 +360,7 @@
 	
 	AC_MSG_CHECKING([for macports user])
 	if test "x$RUNUSR" = "x" ; then
-	   RUNUSR=nobody
+	   RUNUSR=macports
 	fi
 
 	AC_MSG_RESULT([$RUNUSR])
@@ -640,7 +646,7 @@
 			        fi
 			    fi
 			elif test "$path" = "~/Library/Tcl"; then
-			    ac_cv_c_tclpkgd="~$DSTUSR/Library/Tcl"
+			    ac_cv_c_tclpkgd=`eval echo ~$DSTUSR/Library/Tcl`
 			    break
 			fi
 			done
@@ -804,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"
@@ -1058,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-post-destroot/base/config/RELEASE_URL
===================================================================
--- branches/gsoc11-post-destroot/base/config/RELEASE_URL	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/config/RELEASE_URL	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1 +1 @@
-http://svn.macports.org/repository/macports/tags/release_1_9_2/base
+https://svn.macports.org/repository/macports/tags/release_2_1_2/base

Modified: branches/gsoc11-post-destroot/base/config/macports_version
===================================================================
--- branches/gsoc11-post-destroot/base/config/macports_version	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/config/macports_version	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1 +1 @@
-1.9.99
+2.1.99

Modified: branches/gsoc11-post-destroot/base/configure
===================================================================
--- branches/gsoc11-post-destroot/base/configure	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/configure	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,13 +1,11 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.68 for MacPorts 1.9.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='1.9.99'
-PACKAGE_STRING='MacPorts 1.9.99'
+PACKAGE_VERSION='2.1.99'
+PACKAGE_STRING='MacPorts 2.1.99'
 PACKAGE_BUGREPORT='macports-dev at lists.macosforge.org'
 PACKAGE_URL=''
 
@@ -647,8 +667,8 @@
 MPFRAMEWORKSDIR
 MPAPPLICATIONSDIR
 DSTMODE
+TCL_PACKAGE_DIR
 RUNUSR
-TCL_PACKAGE_DIR
 DSTGRP
 DSTUSR
 MPCONFIGDIR
@@ -674,55 +694,64 @@
 PTHREAD_LIBS
 acx_pthread_config
 CFLAGS_WERROR
+CFLAGS_PEDANTIC
 CFLAGS_QUICHEEATERS
 TAR_CMD
 TAR_Q
 SED_EXT
-OPEN
-XAR
-PAX
-MKBOM
-LSBOM
-BZIP2
-GNUPATCH
-GNUMAKE
-GNUTAR
-XCODEBUILD
-LAUNCHCTL
 HAVE_LAUNCHD
-HDIUTIL
-MAKE
-BSDMAKE
 ZIP
+XZ
+XCRUN
+XCODEBUILD
+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
 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
@@ -792,6 +821,7 @@
 enable_werror
 with_objc_runtime
 with_objc_foundation
+with_unsupported_prefix
 with_ports_dir
 with_no_root_privileges
 with_install_user
@@ -823,28 +853,25 @@
 CPPFLAGS
 OBJC
 OBJCFLAGS
-LDFLAGS
-LIBS
-CPPFLAGS
-OBJC
+BSDMAKE
+BZIP2
+CVS
+GNUMAKE
+GNUTAR
+LZMA
+MAKE
 MTREE
-CVS
-SVN
+OPEN
 OPENSSL
 RSYNC
 SED
+SVN
+SWIG
 TAR
-MAKE
-GNUTAR
-BSDMAKE
-GNUMAKE
-BZIP2
 XAR
-OPEN
+XZ
 OBJCPP
-CPPFLAGS
-CPP
-CPPFLAGS'
+CPP'
 ac_subdirs_all='src/thread2.6'
 
 # Initialize some variables set by options.
@@ -1300,8 +1327,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
@@ -1387,7 +1412,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 1.9.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]...
 
@@ -1453,7 +1478,7 @@
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of MacPorts 1.9.99:";;
+     short | recursive ) echo "Configuration of MacPorts 2.1.99:";;
    esac
   cat <<\_ACEOF
 
@@ -1471,6 +1496,9 @@
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
   --with-objc-runtime     Specify either "GNU" or "apple"
   --with-objc-foundation  Specify either "GNUstep" or "apple"
+  --with-unsupported-prefix
+                          Acknowledge that you accept the consequences of
+                          using an unsupported prefix.
   --with-ports-dir=DIR    Specify alternate ports directory
   --with-no-root-privileges
                           Specify that MacPorts should be installed in your
@@ -1510,20 +1538,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
   XAR         path to xar command
-  OPEN        path to open command
+  XZ          path to xz command
   OBJCPP      Objective C preprocessor
   CPP         C preprocessor
 
@@ -1593,10 +1624,10 @@
 test -n "$ac_init_help" && exit $ac_status
 if $ac_init_version; then
   cat <<\_ACEOF
-MacPorts configure 1.9.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
@@ -1710,7 +1741,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
@@ -1957,7 +1988,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
@@ -2262,8 +2293,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 1.9.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 $@
 
@@ -2757,7 +2788,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=1.9.99
+MACPORTS_VERSION=2.1.99
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $MACPORTS_VERSION" >&5
 $as_echo "$MACPORTS_VERSION" >&6; }
 
@@ -2807,7 +2838,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
@@ -2847,7 +2878,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
@@ -2887,7 +2918,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
@@ -2923,36 +2954,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-3])
+  10.4.[0-9]|10.4.10|10.5.[0-7]|10.6.[0-7]|10.7.[0-2])
     { $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.4*|10.5*|10.6*|10.7*)
         ;;
   *)
     ;;
 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
@@ -2973,7 +3017,7 @@
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Please consider upgrading as some ports fail compiling" >&5
 $as_echo "$as_me: WARNING: Please consider upgrading as some ports fail compiling" >&2;}
     ;;
-  2.*|3.*)
+  2.*|3.*|4.*)
         ;;
   *)
     ;;
@@ -3002,7 +3046,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
@@ -3042,7 +3086,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
@@ -3095,7 +3139,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
@@ -3136,7 +3180,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
@@ -3194,7 +3238,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
@@ -3238,7 +3282,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
@@ -3684,8 +3728,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);
@@ -3770,6 +3813,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'
@@ -3794,7 +3972,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
@@ -3838,7 +4016,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
@@ -4021,162 +4199,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
@@ -4187,10 +4315,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; }
@@ -4216,7 +4344,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
@@ -4256,7 +4384,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
@@ -4296,7 +4424,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
@@ -4318,6 +4446,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
@@ -4336,7 +4504,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
@@ -4376,7 +4544,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
@@ -4398,6 +4566,46 @@
 fi
 
 
+# Extract the first word of "dseditgroup", so it can be a program name with args.
+set dummy dseditgroup; 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_DSEDITGROUP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $DSEDITGROUP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_DSEDITGROUP="$DSEDITGROUP" # 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_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
+  fi
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+esac
+fi
+DSEDITGROUP=$ac_cv_path_DSEDITGROUP
+if test -n "$DSEDITGROUP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $DSEDITGROUP" >&5
+$as_echo "$DSEDITGROUP" >&6; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
 # Extract the first word of "file", so it can be a program name with args.
 set dummy file; ac_word=$2
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
@@ -4416,7 +4624,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
@@ -4438,16 +4646,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 "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_BZR+:} false; then :
+if ${ac_cv_path_GIT+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $BZR in
+  case $GIT in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_BZR="$BZR" # 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
@@ -4456,8 +4664,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_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
@@ -4468,36 +4676,39 @@
   ;;
 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; }
+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 "cvs", so it can be a program name with args.
-set dummy cvs; 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_CVS+:} false; then :
+if ${ac_cv_path_GNUMAKE+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $CVS in
+  case $GNUMAKE in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_CVS="$CVS" # 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_CVS="$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
@@ -4508,36 +4719,131 @@
   ;;
 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; }
+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 "svn", so it can be a program name with args.
-set dummy svn; 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_SVN+:} false; then :
+if ${ac_cv_path_GNUPATCH+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $SVN in
+  case $GNUPATCH in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_SVN="$SVN" # 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
+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 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
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+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; }
+else
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
+
+  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_GNUTAR+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GNUTAR in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GNUTAR="$GNUTAR" # 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
+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_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
+done
+  done
+IFS=$as_save_IFS
+
+  ;;
+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; }
+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
+$as_echo_n "checking for $ac_word... " >&6; }
+if ${ac_cv_path_GZIP+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  case $GZIP in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_GZIP="$GZIP" # 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_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_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
   fi
@@ -4548,26 +4854,26 @@
   ;;
 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; }
+GZIP=$ac_cv_path_GZIP
+if test -n "$GZIP"; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GZIP" >&5
+$as_echo "$GZIP" >&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
+# 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_GIT+:} false; then :
+if ${ac_cv_path_HDIUTIL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GIT in
+  case $HDIUTIL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GIT="$GIT" # 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
@@ -4576,8 +4882,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_GIT="$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
@@ -4588,10 +4894,10 @@
   ;;
 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; }
+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; }
@@ -4616,7 +4922,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_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
@@ -4638,16 +4944,16 @@
 fi
 
 
-# Extract the first word of "gzip", so it can be a program name with args.
-set dummy gzip; 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_GZIP+:} false; then :
+if ${ac_cv_path_LAUNCHCTL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GZIP in
+  case $LAUNCHCTL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GZIP="$GZIP" # 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
@@ -4656,8 +4962,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_GZIP="$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
@@ -4668,10 +4974,10 @@
   ;;
 esac
 fi
-GZIP=$ac_cv_path_GZIP
-if test -n "$GZIP"; then
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $GZIP" >&5
-$as_echo "$GZIP" >&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; }
@@ -4696,7 +5002,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_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
@@ -4718,16 +5024,16 @@
 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 "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_PATCH+:} false; then :
+if ${ac_cv_path_LSBOM+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $PATCH in
+  case $LSBOM in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_PATCH="$PATCH" # 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
@@ -4736,8 +5042,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_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
@@ -4748,26 +5054,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; }
+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 "rmdir", so it can be a program name with args.
-set dummy rmdir; 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_RMDIR+:} false; then :
+if ${ac_cv_path_LZMA+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $RMDIR in
+  case $LZMA in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_RMDIR="$RMDIR" # 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
@@ -4776,8 +5082,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_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
@@ -4788,26 +5094,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; }
+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 "rsync", so it can be a program name with args.
-set dummy rsync; 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_RSYNC+:} false; then :
+if ${ac_cv_path_MAKE+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $RSYNC in
+  case $MAKE in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_RSYNC="$RSYNC" # 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
@@ -4816,8 +5122,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_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
@@ -4828,26 +5134,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; }
+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 "openssl", so it can be a program name with args.
-set dummy openssl; 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_OPENSSL+:} false; then :
+if ${ac_cv_path_MDFIND+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $OPENSSL in
+  case $MDFIND in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_OPENSSL="$OPENSSL" # 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
@@ -4856,8 +5162,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_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
@@ -4868,26 +5174,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; }
+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 "sed", so it can be a program name with args.
-set dummy sed; 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_SED+:} false; then :
+if ${ac_cv_path_MDLS+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $SED in
+  case $MDLS in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_SED="$SED" # 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
@@ -4896,8 +5202,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_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
@@ -4908,26 +5214,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; }
+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
 
 
-# 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 "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_TAR+:} false; then :
+if ${ac_cv_path_MKBOM+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $TAR in
+  case $MKBOM in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_TAR="$TAR" # 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
@@ -4936,8 +5242,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_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
@@ -4948,36 +5254,37 @@
   ;;
 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; }
+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
 
 
-# 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 "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_UNZIP+:} false; then :
+if ${ac_cv_path_MTREE+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $UNZIP in
+  case $MTREE in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_UNZIP="$UNZIP" # Let the user override the test with a path.
+  ac_cv_path_MTREE="$MTREE" # 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/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 { 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_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
@@ -4988,26 +5295,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; }
+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 "zip", so it can be a program name with args.
-set dummy zip; ac_word=$2
+# 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_ZIP+:} false; then :
+if ${ac_cv_path_OPEN+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $ZIP in
+  case $OPEN in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_ZIP="$ZIP" # 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
@@ -5016,8 +5323,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_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
@@ -5028,28 +5335,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; }
+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
 
 
-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 "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_BSDMAKE+:} false; then :
+if ${ac_cv_path_OPENSSL+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $BSDMAKE in
+  case $OPENSSL in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_BSDMAKE="$BSDMAKE" # 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
@@ -5058,8 +5363,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_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
@@ -5070,29 +5375,66 @@
   ;;
 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; }
+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
 
 
-  test -n "$BSDMAKE" && break
+# 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_path_PATCH+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  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 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
 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
+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 "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_MAKE+:} false; then :
+if ${ac_cv_path_PAX+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MAKE in
+  case $PAX in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_MAKE="$MAKE" # 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
@@ -5101,8 +5443,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_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
@@ -5113,26 +5455,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; }
+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 "hdiutil", so it can be a program name with args.
-set dummy hdiutil; 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_HDIUTIL+:} false; then :
+if ${ac_cv_path_RMDIR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $HDIUTIL in
+  case $RMDIR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_HDIUTIL="$HDIUTIL" # 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
@@ -5141,8 +5483,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_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
@@ -5153,34 +5495,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; }
+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
 
 
-# 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 "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_prog_HAVE_LAUNCHD+:} false; then :
+if ${ac_cv_path_RSYNC+:} 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 $RSYNC in
+  [\\/]* | ?:[\\/]*)
+  ac_cv_path_RSYNC="$RSYNC" # 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_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
@@ -5188,38 +5532,39 @@
   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; }
+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
 
 
-# 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 "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_LAUNCHCTL+:} false; then :
+if ${ac_cv_path_SANDBOX_EXEC+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $LAUNCHCTL in
+  case $SANDBOX_EXEC in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_LAUNCHCTL="$LAUNCHCTL" # 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
-for as_dir in $PATH
+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_LAUNCHCTL="$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
@@ -5230,26 +5575,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; }
+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
 
 
-# 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 "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_XCODEBUILD+:} false; then :
+if ${ac_cv_path_SED+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $XCODEBUILD in
+  case $SED in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_XCODEBUILD="$XCODEBUILD" # 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
@@ -5258,8 +5603,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_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
@@ -5270,39 +5615,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; }
+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
 
 
-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 "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_GNUTAR+:} false; then :
+if ${ac_cv_path_SVN+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GNUTAR in
+  case $SVN in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GNUTAR="$GNUTAR" # 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
-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_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
@@ -5313,31 +5655,26 @@
   ;;
 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; }
+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
 
 
-  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 "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_GNUMAKE+:} false; then :
+if ${ac_cv_path_SWIG+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GNUMAKE in
+  case $SWIG in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GNUMAKE="$GNUMAKE" # 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
@@ -5347,8 +5684,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_GNUMAKE="$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
@@ -5359,42 +5696,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; }
+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
 
 
-  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 "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_GNUPATCH+:} false; then :
+if ${ac_cv_path_TAR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $GNUPATCH in
+  case $TAR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_GNUPATCH="$GNUPATCH" # 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
-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_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
@@ -5405,29 +5736,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; }
+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
 
 
-  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 "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_BZIP2+:} false; then :
+if ${ac_cv_path_UNZIP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $BZIP2 in
+  case $UNZIP in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_BZIP2="$BZIP2" # 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
@@ -5436,8 +5764,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_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
@@ -5448,26 +5776,26 @@
   ;;
 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; }
+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 "lsbom", so it can be a program name with args.
-set dummy lsbom; 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_LSBOM+:} false; then :
+if ${ac_cv_path_XAR+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $LSBOM in
+  case $XAR in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_LSBOM="$LSBOM" # 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
@@ -5476,8 +5804,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_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
@@ -5488,26 +5816,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; }
+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 "mkbom", so it can be a program name with args.
-set dummy mkbom; 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_MKBOM+:} false; then :
+if ${ac_cv_path_XCODEBUILD+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $MKBOM in
+  case $XCODEBUILD in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_MKBOM="$MKBOM" # 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
@@ -5516,8 +5844,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_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
@@ -5528,26 +5856,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; }
+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 "pax", so it can be a program name with args.
-set dummy pax; 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_PAX+:} false; then :
+if ${ac_cv_path_XCRUN+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $PAX in
+  case $XCRUN in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_PAX="$PAX" # 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
@@ -5556,8 +5884,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_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
@@ -5568,26 +5896,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; }
+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 "xar", so it can be a program name with args.
-set dummy xar; 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_XAR+:} false; then :
+if ${ac_cv_path_XZ+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $XAR in
+  case $XZ in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_XAR="$XAR" # 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
@@ -5596,8 +5924,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_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
@@ -5608,26 +5936,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; }
+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 "open", so it can be a program name with args.
-set dummy open; 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_OPEN+:} false; then :
+if ${ac_cv_path_ZIP+:} false; then :
   $as_echo_n "(cached) " >&6
 else
-  case $OPEN in
+  case $ZIP in
   [\\/]* | ?:[\\/]*)
-  ac_cv_path_OPEN="$OPEN" # 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
@@ -5636,8 +5964,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_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
@@ -5648,10 +5976,10 @@
   ;;
 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; }
+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; }
@@ -5659,6 +5987,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
 
 
@@ -5676,6 +6042,13 @@
 
 
 
+
+
+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
@@ -5694,7 +6067,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
@@ -5764,7 +6137,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
@@ -5819,7 +6192,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
@@ -5859,7 +6232,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
@@ -5924,7 +6297,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
@@ -5964,7 +6337,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
@@ -6007,11 +6380,13 @@
 
 # Quiche eaters options.
 if test x$GCC = xyes; then
-	CFLAGS_QUICHEEATERS='-W -Wall -pedantic'
+	CFLAGS_QUICHEEATERS='-Wextra -Wall'
+	CFLAGS_PEDANTIC='-pedantic'
 fi
 
 
 
+
 	# Check whether --enable-werror was given.
 if test "${enable_werror+set}" = set; then :
   enableval=$enable_werror; enable_werror=${enableval}
@@ -6240,7 +6615,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
@@ -6549,7 +6924,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
@@ -6615,7 +6990,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
@@ -7598,13 +7973,23 @@
 
 # Check for paths
 
-if test x$prefix = x/usr/local; then
-    as_fn_error $? "Installing MacPorts into /usr/local is not supported" "$LINENO" 5
+
+# Check whether --with-unsupported-prefix was given.
+if test "${with_unsupported_prefix+set}" = set; then :
+  withval=$with_unsupported_prefix; with_unsupported_prefix=$withval
+else
+  with_unsupported_prefix=no
 fi
 
+if test x$prefix = x/usr/local -o x$prefix = x/usr && test x$with_unsupported_prefix != xyes; then
+    as_fn_error $? "Installing MacPorts into $prefix is not supported. If \
+you understand this and wish to do so anyway, pass --with-unsupported-prefix \
+to configure." "$LINENO" 5
+fi
 
 
 
+
 # Check whether --with-ports-dir was given.
 if test "${with_ports_dir+set}" = set; then :
   withval=$with_ports_dir;  portsdir="$withval"
@@ -7682,10 +8067,18 @@
 $as_echo "$DSTGRP" >&6; }
 
 
+		# Set run-user to current user
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for macports user" >&5
+$as_echo_n "checking for macports user... " >&6; }
+		RUNUSR=`id -un`
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $RUNUSR" >&5
+$as_echo "$RUNUSR" >&6; }
+
+
 		# Set Tcl package directory to ~/Library/Tcl
 	    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Tcl package directory" >&5
 $as_echo_n "checking for Tcl package directory... " >&6; }
-		ac_cv_c_tclpkgd="~$DSTUSR/Library/Tcl"
+		ac_cv_c_tclpkgd=`eval echo ~$DSTUSR/Library/Tcl`
 	    # Convert to a native path and substitute into the output files.
 	    PACKAGE_DIR_NATIVE=`${CYGPATH} ${ac_cv_c_tclpkgd}`
 	    TCL_PACKAGE_DIR=${PACKAGE_DIR_NATIVE}
@@ -7768,7 +8161,7 @@
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for macports user" >&5
 $as_echo_n "checking for macports user... " >&6; }
 	if test "x$RUNUSR" = "x" ; then
-	   RUNUSR=nobody
+	   RUNUSR=macports
 	fi
 
 	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $RUNUSR" >&5
@@ -9030,7 +9423,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
@@ -9073,7 +9466,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
@@ -9148,7 +9541,7 @@
 			        fi
 			    fi
 			elif test "$path" = "~/Library/Tcl"; then
-			    ac_cv_c_tclpkgd="~$DSTUSR/Library/Tcl"
+			    ac_cv_c_tclpkgd=`eval echo ~$DSTUSR/Library/Tcl`
 			    break
 			fi
 			done
@@ -9227,7 +9620,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
@@ -9268,7 +9661,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
@@ -9322,7 +9715,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; }
@@ -9340,7 +9741,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
@@ -9362,27 +9763,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"
@@ -9446,6 +9841,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=
 
@@ -9566,7 +10040,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
@@ -9592,7 +10066,7 @@
 
 
 # Output
-ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/prefix.mtree doc/macosx.mtree doc/macports.conf doc/pubkeys.conf portmgr/freebsd/Makefile src/Makefile src/macports1.0/macports_autoconf.tcl src/port1.0/port_autoconf.tcl src/registry2.0/registry_autoconf.tcl src/programs/Makefile src/macports1.0/macports_fastload.tcl setupenv.bash"
+ac_config_files="$ac_config_files Doxyfile Makefile Mk/macports.autoconf.mk doc/base.mtree doc/prefix.mtree doc/macosx.mtree doc/macports.conf doc/pubkeys.conf portmgr/freebsd/Makefile src/Makefile src/machista1.0/Makefile src/macports1.0/macports_autoconf.tcl src/port1.0/port_autoconf.tcl src/registry2.0/registry_autoconf.tcl src/programs/Makefile src/macports1.0/macports_fastload.tcl setupenv.bash"
 
 
 ac_config_files="$ac_config_files src/pkg_mkindex.sh"
@@ -10005,16 +10479,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
@@ -10074,29 +10548,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'"
 
@@ -10116,8 +10578,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 1.9.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
@@ -10178,11 +10640,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 1.9.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."
 
@@ -10271,7 +10733,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'
@@ -10305,12 +10767,14 @@
     "Doxyfile") CONFIG_FILES="$CONFIG_FILES Doxyfile" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "Mk/macports.autoconf.mk") CONFIG_FILES="$CONFIG_FILES Mk/macports.autoconf.mk" ;;
+    "doc/base.mtree") CONFIG_FILES="$CONFIG_FILES doc/base.mtree" ;;
     "doc/prefix.mtree") CONFIG_FILES="$CONFIG_FILES doc/prefix.mtree" ;;
     "doc/macosx.mtree") CONFIG_FILES="$CONFIG_FILES doc/macosx.mtree" ;;
     "doc/macports.conf") CONFIG_FILES="$CONFIG_FILES doc/macports.conf" ;;
     "doc/pubkeys.conf") CONFIG_FILES="$CONFIG_FILES doc/pubkeys.conf" ;;
     "portmgr/freebsd/Makefile") CONFIG_FILES="$CONFIG_FILES portmgr/freebsd/Makefile" ;;
     "src/Makefile") CONFIG_FILES="$CONFIG_FILES src/Makefile" ;;
+    "src/machista1.0/Makefile") CONFIG_FILES="$CONFIG_FILES src/machista1.0/Makefile" ;;
     "src/macports1.0/macports_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/macports1.0/macports_autoconf.tcl" ;;
     "src/port1.0/port_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/port1.0/port_autoconf.tcl" ;;
     "src/registry2.0/registry_autoconf.tcl") CONFIG_FILES="$CONFIG_FILES src/registry2.0/registry_autoconf.tcl" ;;

Modified: branches/gsoc11-post-destroot/base/configure.ac
===================================================================
--- branches/gsoc11-post-destroot/base/configure.ac	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/configure.ac	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-3]])
+  10.4.[[0-9]]|10.4.10|10.5.[[0-7]]|10.6.[[0-7]]|10.7.[[0-2]])
     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.4*|10.5*|10.6*|10.7*)
     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
@@ -73,7 +86,7 @@
     AC_MSG_WARN([This version of Xcode Tools is out of date])
     AC_MSG_WARN([Please consider upgrading as some ports fail compiling])
     ;;
-  2.*|3.*)
+  2.*|3.*|4.*)
     dnl Supported version
     ;;
   *)
@@ -82,64 +95,81 @@
 
 # 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(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(XAR, [xar], [])
+AC_PATH_PROG(XCODEBUILD, [xcodebuild], [])
+AC_PATH_PROG(XCRUN, [xcrun], [])
+AC_PATH_PROG(XZ, [xz], [])
 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(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(LSBOM, [lsbom], [])
-AC_PATH_PROG(MKBOM, [mkbom], [])
-AC_PATH_PROG(PAX, [pax], [])
-AC_PATH_PROG(XAR, [xar], [])
-AC_PATH_PROG(OPEN, [open], [])
 
 # 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(XAR, [path to xar command])
-AC_ARG_VAR(OPEN, [path to open command])
+AC_ARG_VAR(XZ, [path to xz 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
@@ -147,9 +177,11 @@
 
 # Quiche eaters options.
 if test x$GCC = xyes; then
-	CFLAGS_QUICHEEATERS='-W -Wall -pedantic'
+	CFLAGS_QUICHEEATERS='-Wextra -Wall'
+	CFLAGS_PEDANTIC='-pedantic'
 fi
 AC_SUBST(CFLAGS_QUICHEEATERS)
+AC_SUBST(CFLAGS_PEDANTIC)
 MP_WERROR
 
 MP_COMPILER_ATTRIBUTE_UNUSED
@@ -169,8 +201,16 @@
 
 # Check for paths
 AC_PREFIX_DEFAULT(/opt/local)
-if test x$prefix = x/usr/local; then
-    AC_MSG_ERROR([Installing MacPorts into /usr/local is not supported])
+AC_ARG_WITH(
+		unsupported-prefix,
+		AS_HELP_STRING([--with-unsupported-prefix],
+		[Acknowledge that you accept the consequences of using an unsupported prefix.]),
+		[with_unsupported_prefix=$withval],
+		[with_unsupported_prefix=no])
+if test x$prefix = x/usr/local -o x$prefix = x/usr && test x$with_unsupported_prefix != xyes; then
+    AC_MSG_ERROR([Installing MacPorts into $prefix is not supported. If \
+you understand this and wish to do so anyway, pass --with-unsupported-prefix \
+to configure.])
 fi
 MP_PATH_PORTSDIR([$PORTS_DIR_DEFAULT])
 MP_PATH_MPCONFIGDIR
@@ -213,7 +253,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], [], [],
 	[
@@ -253,6 +293,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=
 
@@ -346,12 +391,14 @@
 	Doxyfile
 	Makefile
 	Mk/macports.autoconf.mk
+	doc/base.mtree
 	doc/prefix.mtree
 	doc/macosx.mtree
 	doc/macports.conf
 	doc/pubkeys.conf
 	portmgr/freebsd/Makefile
 	src/Makefile
+	src/machista1.0/Makefile
 	src/macports1.0/macports_autoconf.tcl
 	src/port1.0/port_autoconf.tcl
 	src/registry2.0/registry_autoconf.tcl


Property changes on: branches/gsoc11-post-destroot/base/doc
___________________________________________________________________
Modified: svn:ignore
   - macports.conf
pubkeys.conf
prefix.mtree
macosx.mtree
*[0-9].gz

   + macports.conf
pubkeys.conf
base.mtree
prefix.mtree
macosx.mtree
*[0-9].gz


Modified: branches/gsoc11-post-destroot/base/doc/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/doc/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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 whitelist.conf
+CONF=		archive_sites.conf macports.conf pubkeys.conf sources.conf variants.conf whitelist.conf
 INSTALLDIR=	${DESTDIR}${prefix}
 TOPSRCDIR=	..
 
@@ -17,7 +17,7 @@
 test:
 
 distclean: clean
-	rm -f macports.conf macosx.mtree prefix.mtree pubkeys.conf
+	rm -f macports.conf base.mtree macosx.mtree prefix.mtree pubkeys.conf
 
 %.1.gz: %.1
 	gzip -c $^ > $@
@@ -29,37 +29,39 @@
 	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
+	< 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
 
 	if test ! -e "${INSTALLDIR}/man" ; then \
-		$(LN_S) share/man ${INSTALLDIR}/man; \
+		$(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 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-post-destroot/base/doc/archive_sites.conf (from rev 98879, trunk/base/doc/archive_sites.conf)
===================================================================
--- branches/gsoc11-post-destroot/base/doc/archive_sites.conf	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/doc/archive_sites.conf	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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

Copied: branches/gsoc11-post-destroot/base/doc/base.mtree.in (from rev 98879, trunk/base/doc/base.mtree.in)
===================================================================
--- branches/gsoc11-post-destroot/base/doc/base.mtree.in	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/doc/base.mtree.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,28 @@
+# $Id$
+#
+# MacPorts filesystem hierarchy, for internal use only. Changes to this file will not stick across installations.
+#
+
+/set type=dir uname=@DSTUSR@ gname=@DSTGRP@ mode=@DSTMODE@
+.
+    var
+        macports
+            build
+            ..
+            distfiles
+            ..
+            home
+                Library
+                    Preferences
+                    ..
+                ..
+            ..
+            logs
+            ..
+            registry
+            ..
+            software
+            ..
+        ..
+    ..
+..

Modified: branches/gsoc11-post-destroot/base/doc/macports.conf.5
===================================================================
--- branches/gsoc11-post-destroot/base/doc/macports.conf.5	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/macports.conf.5	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,6 @@
 .\" Copyright (c) 2005 Matt Anton <matt at opendarwin.org>
 .\" Copyright (c) 2007 Juan Manuel Palacios <jmpp at macports.org>
+.\" Copyright (c) 2007-2011 The MacPorts Project
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -91,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
@@ -203,13 +212,35 @@
 -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
 .It Va extra_env
 List of extra environment variables MacPorts should keep in the user's environment when sanitizing it.
+Changing this is unsupported.
+.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-post-destroot/base/doc/macports.conf.in
===================================================================
--- branches/gsoc11-post-destroot/base/doc/macports.conf.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/macports.conf.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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,24 +83,26 @@
 #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.
-# Known mirrors at time of writing (see http://trac.macports.org/wiki/Mirrors
+# Known mirrors at time of writing (see https://trac.macports.org/wiki/Mirrors
 # for the current list):
 #   rsync.macports.org        - California, USA (master)
 #   trd.no.rsync.macports.org - Trondheim, Norway
 #rsync_server		rsync.macports.org
 
 # Rsync directory from which to pull the base/ component (infrastructure) of MacPorts
-#rsync_dir			release/base/
+# 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 options
 #rsync_options		-rtzv --delete-after
@@ -99,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
@@ -117,15 +140,22 @@
 # 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
+#proxy_skip		internal1, internal2, internal3
+
+# 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-post-destroot/base/doc/port.1
===================================================================
--- branches/gsoc11-post-destroot/base/doc/port.1	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/port.1	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +1,7 @@
 .\" port.1
 .\"
-.\" Copyright (c) 2002 Apple Computer, Inc.
+.\" Copyright (c) 2004-2011 The MacPorts Project
+.\" Copyright (c) 2002-2003 Apple Inc.
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -11,7 +12,7 @@
 .\" 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 Computer, Inc. nor the names of its
+.\" 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.
 .\"
@@ -104,6 +105,10 @@
 set of installed but inactive ports.
 .Pp
 .It
+.Ar actinact :
+set of installed ports that have both an active version and one or more inactive versions.
+.Pp
+.It
 .Ar installed :
 set of all installed ports.
 .Pp
@@ -247,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
@@ -362,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
@@ -377,6 +382,31 @@
 .Dl "port uninstall vim"
 .Dl "port -u uninstall"
 .Dl "port uninstall --follow-dependents python24"
+.Ss select
+For a given
+.Ar group ,
+selects a
+.Ar version
+to be the default by creating appropriate symbolic links.
+For instance,
+.Ic "python"
+might be linked to
+.Ic "python2.6" .
+Available select groups are installed as subdirectories of
+.Ar ${prefix}/etc/select/ .
+To list the available versions in a group, use
+.Fl -list .
+To see which version is currently selected for a group, use
+.Fl -show .
+To change the selected version for a group, use
+.Fl -set .
+.Pp
+For example:
+.Pp
+.Dl "port select --list python"
+.Dl "port select --show gcc"
+.Dl "port select --set gcc mp-gcc44"
+.Pp
 .Ss activate
 Activate the installed
 .Ar portname .
@@ -462,6 +492,27 @@
 upgrade will not normally rebuild a port only to change the selected 
 variants; you can either specify --enforce-variants, or deactivate the port and reinstall it 
 with different variants. 
+.Pp
+After the upgrade MacPorts will automatically run \fBrev-upgrade\fP to check for
+broken ports that need to be rebuilt. If there are known problems with
+\fBrev-upgrade\fP or other reasons why you would want to avoid running this
+step, you can disable it by running \fBport upgrade\fP with the
+\fB--no-rev-upgrade\fP switch:
+.Pp
+.Dl "port upgrade --no-rev-upgrade outdated"
+.Ss rev-upgrade
+Manually check for broken binaries and rebuild ports containing broken binaries.
+\fBrev-upgrade\fP is usually automatically run after each upgrade, unless you
+specify the \fB--no-rev-upgrade\fP option.
+.Pp
+\fBrev-upgrade\fP can run more checks against a special loadcommand in Mach-O
+binaries that should always be referencing the file itself. This check is most
+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 .
@@ -493,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 .
@@ -581,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-post-destroot/base/doc/portfile.7
===================================================================
--- branches/gsoc11-post-destroot/base/doc/portfile.7	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/portfile.7	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +1,7 @@
 .\" portfile.7
 .\"
-.\" Copyright (c) 2002 Apple Computer, Inc.
+.\" Copyright (c) 2004-2011 The MacPorts Project
+.\" Copyright (c) 2002-2003 Apple Inc.
 .\" All rights reserved.
 .\"
 .\" Redistribution and use in source and binary forms, with or without
@@ -11,7 +12,7 @@
 .\" 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 Computer, Inc. nor the names of its
+.\" 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.
 .\"
@@ -83,9 +84,14 @@
 If a port's version numbering changes such that a newer version looks
 older than the previous version, the
 .Ic epoch
-should be increased. Often the
+should be increased. Some
+.Nm Portfile
+authors have used large
 .Ic epoch
-is formatted like a date.
+values that look like a date, but there is no reason to do so. The
+.Ic epoch
+is simply an unsigned integer, and the only requirement is that it never be
+decreased.
 .br
 .Sy Type:
 .Em optional
@@ -94,7 +100,7 @@
 .Em 0
 .br
 .Sy Example:
-.Dl epoch 20041231
+.Dl epoch 1
 .It Ic description
 One line description of the software and what it does.  To appear in the
 description, brackets and semi-colons need to be escaped with a backslash (i.e.
@@ -200,6 +206,28 @@
 .br
 .Sy Example:
 .Dl platforms darwin
+.It Ic supported_archs
+The CPU architectures for which this port can be built. Archs currently
+supported by Mac OS X are: i386, ppc, ppc64, x86_64. If this option is not set,
+it is assumed that the port can build for all archs. If a port does not install
+any architecture-specific files, use the special value noarch.
+.br
+If the building architecture isn't among supported_archs, port fails with an
+error message except when building on x86_64 (or ppc64) and supported_archs
+contains i386 (or ppc). In this case, the port will be built in 32-bit mode.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Values:
+.Em i386 x86_64 ppc ppc64 noarch
+.br
+.Sy Default:
+.Em i386 x86_64 ppc ppc64
+.br
+.Sy Examples:
+.Dl supported_archs i386 x86_64
+.Dl supported_archs noarch
 .It Ic homepage
 Project homepage for the port.
 .br
@@ -256,7 +284,7 @@
 .Ic distfiles .
 The checksum
 .Ar type
-can currently be md5, rmd160 or sha1. The
+can currently be md5, sha1, rmd160 or sha256. The
 .Ar filename
 can be omitted if there is only one distfile.
 .br
@@ -300,10 +328,10 @@
 .Em optional
 .br
 .Sy Default:
-.Em no
+.Em yes
 .br
 .Sy Example:
-.Dl use_parallel_build yes
+.Dl use_parallel_build no
 .It Ic use_automake
 If set to yes, run the
 .Cm automake
@@ -401,6 +429,43 @@
 .Dl add_users squid group=squid realname=Squid\e Proxy home=${prefix}/var/squid
 .sp
 .Dl add_users user1 group=mygroup user2 group=mygroup
+.It Ic installs_libs
+By default, it is assumed that ports may install libraries or headers that can
+be incorporated into their dependents. If this is not the case, set
+.Cm installs_libs
+to
+.Em no .
+This means that this port's dependents need not check that it is installed
+for the same architectures as them; that it is permissible to distribute
+binaries of the dependents even if their licenses conflict with the license
+of this port; and that updates to this port can never result in broken dynamic
+linking in its dependents.
+.br
+.Sy Type:
+.Em optional
+.br
+.Sy Default:
+.Em none
+.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
@@ -438,7 +503,7 @@
 basis.
 .br
 .Sy Example:
-.Dl configure.env CPP=/usr/bin/cpp-4.0
+.Dl build.env CC="${configure.cc} [get_canonical_archflags]"
 .It Va target Ns Ic .pre_args
 Additional arguments passed before the main arguments.
 .br
@@ -574,7 +639,7 @@
 .Em read-only
 .br
 .Sy Default:
-.Em /Applications/Macports
+.Em /Applications/MacPorts
 .It Ic frameworks_dir
 Absolute path to the final location to install Mac OS X framework
 bundles (.framework directories).
@@ -586,7 +651,7 @@
 .Em ${prefix}/Library/Frameworks
 .El
 .Sh DEPENDENCY OPTIONS
-Port dependencies should refer to other MacPort ports
+Port dependencies should refer to other MacPorts ports
 whenever possible, therefore each dependency should be
 expressed in the format:
 .Bl -tag -width ls
@@ -649,7 +714,7 @@
 .Em optional
 .br
 .Sy Example:
-.Dl depends_extract port:xz-devel
+.Dl depends_extract path:bin/xz:xz
 .It Ic depends_build
 List of dependencies to check before
 .Cm configure ,
@@ -767,7 +832,7 @@
 .Em optional
 .br
 .Sy Example:
-.Dl patchfiles japanese-widechar-fix.diff japanese-localization.diff
+.Dl patchfiles patch-Makefile.in.diff patch-main.c.diff
 .It Ic use_zip
 Use zip.
 .br
@@ -944,9 +1009,9 @@
 .Em none
 .br
 .Sy Example:
-.Dl svn.url http://www.domain.com/svn-repo/mydirectory
-      svn.url svn://www.domain.com/svn-repo/mydirectory
-.It Ic svn.tag
+.Dl svn.url https://www.example.com/svn/project/tags/1.2.3
+      svn.url svn://www.example.com/svn/project/tags/1.2.3
+.It Ic svn.revision
 Specify a tag from which svn should fetch files. This
 corresponds to the -r option to the svn cli.  Note that you
 will need to use backslashes to escape characters that have
@@ -960,8 +1025,8 @@
 .Em none
 .br
 .Sy Example:
-.Dl svn.tag 37192
-      svn.tag \\{\\"2006-02-17 15:30 +0230\\"\\}
+.Dl svn.revision 37192
+      svn.revision \\{\\"2006-02-17 15:30 +0230\\"\\}
 .El
 .Ss FETCHING FROM GIT
 As an alternative to fetching distribution files, pulling the sources
@@ -1172,32 +1237,30 @@
 .Em gcc-3.3
 .Em gcc-4.0
 .Em gcc-4.2
-use the standard system compiler suites,
 .Em llvm-gcc-4.2
 .Em clang
-use the newer, non-default compilers installed by Xcode,
-.Em apple-gcc-3.3
+use the standard Xcode compiler suites,
 .Em apple-gcc-4.0
 .Em apple-gcc-4.2
 use Apple's gcc suite installed via MacPorts,
-.Em macports-gcc-3.3
-.Em macports-gcc-3.4
-.Em macports-gcc-4.0
-.Em macports-gcc-4.1
 .Em macports-gcc-4.2
 .Em macports-gcc-4.3
 .Em macports-gcc-4.4
 .Em macports-gcc-4.5
-use the vanilla gcc installed via MacPorts.
+.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
 .Sy Type:
 .Em optional
 .br
 .Sy Values:
-.Em gcc-3.3 gcc-4.0 gcc-4.2 llvm-gcc-4.2 clang apple-gcc-3.3 apple-gcc-4.0 apple-gcc-4.2 macports-gcc-3.3 macports-gcc-3.4 macports-gcc-4.0 macports-gcc-4.1 macports-gcc-4.2 macports-gcc-4.3 macports-gcc-4.4 macports-gcc-4.5
+.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 gcc-4.0
+.Dl configure.compiler llvm-gcc-4.2
 .\" FOOBAR
 .El
 .Ss UNIVERSAL TARGET HOOKS
@@ -1611,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
@@ -1636,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.
@@ -1680,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
@@ -1726,7 +1789,7 @@
 .Bd -literal -offset indent -compact
 variant gnome requires glib { configure.args-append --with-gnome \e\
 
-    depends_lib-append lib:gnome-session:gnome-session }
+    depends_lib-append port:gnome-session }
 .Ed
 .It Ic default_variants
 If variants are defined, then the
@@ -1775,7 +1838,7 @@
 .Xc
 The body is executed if the given platform/version/arch combination matches
 os.platform or os.subplatform and/or os.major and/or os.arch.
-The following examples are from the databases/db4 and devel/libidl1
+The following examples are from the lang/php5, audio/flac and sysutils/getopt
 .Nm Portfiles
 respectively.
 .br
@@ -1784,20 +1847,18 @@
 .br
 .Sy Example:
 .Bd -literal -offset indent -compact
-platform darwin 6 { configure.args-append   --enable-tcl \e\
-
-        --with-tcl=/System/Library/Tcl/8.3 }
+platform darwin 10 { configure.env-append LIBS=-lresolv }
 .Ed
 .br
 .Sy Example:
 .Bd -literal -offset indent -compact
-platform darwin powerpc { configure.args-append \e\
-
-        --host=${os.arch}-apple-rhapsody${os.version} }
-platform darwin i386 { configure.args-append \e\
-
-        --host=i386-gnu-rhapsody${os.version} }
+platform darwin i386 { configure.args-append --disable-asm-optimizations }
 .Ed
+.br
+.Sy Example:
+.Bd -literal -offset indent -compact
+platform darwin 8 powerpc { configure.universal_ldflags-append -liconv }
+.Ed
 .El
 .Sh PORTGROUP
 To factorize the work with similar ports, MacPorts provides the notion of
@@ -2032,7 +2093,11 @@
 .It Ic ln
 .br
 Built-in command mimicking the BSD ln command.
-.It Ic system Ar commandline
+.It Xo
+.Ic system
+.Op Fl W Ar dir
+.Ar commandline
+.Xc
 Execute a program. See
 .Xr system 3 .
 For calls to
@@ -2046,6 +2111,12 @@
 or similar, please use the built-in commands or
 .Nm file
 if they don't meet your requirements.
+.Bl -tag -width indent
+.It Fl W
+Change to
+.Ar dir
+before working.
+.El
 .It Ic variant_isset Ar variant
 Checks if the given
 .Ar variant
@@ -2098,10 +2169,10 @@
 .Xr mkdtemp 3 .
 .It Ic md5 Ar
 Compute the MD5 hashes of the file(s).
-.It Ic rpm-vercomp Ar versionA Ar versionB
-Compare two RPM-format versions for equality.  The return value is like
+.It Ic vercmp Ar versionA Ar versionB
+Compare two EVR-format versions for equality.  The return value is like
 strcmp(), returning -1, 0, or 1 when versionA is earlier, equal to, or
-later than versionB, respectively.  Note that some comparisions featuring
+later than versionB, respectively.  Note that some comparisons featuring
 floating-point notation may compare incorrectly, e.g. 2.101 is considered
 later than 2.2 (101 is larger than 2) which may be incorrect per some
 projects versioning methods (see ticket #11873).

Modified: branches/gsoc11-post-destroot/base/doc/portgroup.7
===================================================================
--- branches/gsoc11-post-destroot/base/doc/portgroup.7	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/portgroup.7	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,7 +11,7 @@
 .\" 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 Computer, Inc. nor the names of its
+.\" 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.
 .\"

Modified: branches/gsoc11-post-destroot/base/doc/porthier.7
===================================================================
--- branches/gsoc11-post-destroot/base/doc/porthier.7	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/porthier.7	2012-10-19 16:03:11 UTC (rev 98880)
@@ -99,7 +99,10 @@
 .It Pa distfiles/
 Holds the distfiles of the fetched ports
 .It Pa receipts/
-Holds the registry information and receipts for the installed ports
+Obsolete. Formerly held the registry information and receipts for the installed ports,
+in flat-file format.
+.It Pa registry/
+Contains the registry database in sqlite format.
 .It Pa software/
 Holds compressed images of the installed ports. These
 are extracted to ${prefix} when activated.

Modified: branches/gsoc11-post-destroot/base/doc/prefix.mtree.in
===================================================================
--- branches/gsoc11-post-destroot/base/doc/prefix.mtree.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/prefix.mtree.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -240,20 +240,6 @@
     src
     ..
     var
-        macports
-            build
-            ..
-            distfiles
-            ..
-            logs
-            ..
-            packages
-            ..
-            receipts
-            ..
-            registry
-            ..
-        ..
     ..
     www
     ..

Modified: branches/gsoc11-post-destroot/base/doc/sources.conf
===================================================================
--- branches/gsoc11-post-destroot/base/doc/sources.conf	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/doc/sources.conf	2012-10-19 16:03:11 UTC (rev 98880)
@@ -23,5 +23,9 @@
 #      rsync://rsync.macports.org/release/ports/
 #  To get it from the mirror in Trondheim, Norway use:
 #      rsync://trd.no.rsync.macports.org/release/ports/
-#  A current list of mirrors is available at http://trac.macports.org/wiki/Mirrors
-rsync://rsync.macports.org/release/ports/ [default]
+#  A current list of mirrors is available at https://trac.macports.org/wiki/Mirrors
+
+# If an rsync URL 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://rsync.macports.org/release/tarballs/ports.tar [default]

Modified: branches/gsoc11-post-destroot/base/m4/tcl.m4
===================================================================
--- branches/gsoc11-post-destroot/base/m4/tcl.m4	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/m4/tcl.m4	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,5 @@
 # This file is based on the tcl.m4 file distributed with Tcl 8.4
-# Portions Copyright (2003) Apple Computer, Inc.
+# Portions Copyright (2003) Apple Inc.
 #
 # Copyright and License for this file, copied verbatim from the official
 # Tcl distribution, follows:

Modified: branches/gsoc11-post-destroot/base/macports-pubkey.pem
===================================================================
--- branches/gsoc11-post-destroot/base/macports-pubkey.pem	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/macports-pubkey.pem	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,9 +1,14 @@
 -----BEGIN PUBLIC KEY-----
-MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxPlw2FSMEavmtuHq5O+f
-XPUXndBnUyoX8iJvQ7NlsNY+hleE307kOAly79WFq2aAGIyKB/Ob8V+qCLW4FGOO
-4NfvOnte1WxQP8oVxOM9ai3CeN6AnUxDWUTYVJ1R+a5ZQVnJyGBKkV+jLlj0PD/z
-d8PCJ/j7Wzizw3d4s9uBIR1zpLY8lVgTivsj5FM3RP6hS7ww7I47goQshoL+YFVg
-NhE9I63oZXqFF130l9jJI9axHUqza7a42WCv04J8iv8SQhgv6fY9ZQnIBMQ4hPDH
-klGusdf4HlCbUViKhxmUpfj6FJabh2jV48ymaoTZB767GJyACF4mvnNDkenEXf41
-/wIDAQAB
+MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAv2bUqZgZmQNtkInIcery
+c/DQIbGdKgrdJ2+x45jOCITEf7QubgNmJAtw4OSNt30EXWGOrJXGD5Vb81o4ycEr
+f+bdTgCAG9fOipMxxDhT8AbSkAzYx9vGIcEwQP6VX5QhPlFxJJweeefEINNHkrm5
+KdmGpGxwe5AtTzxJiabWmJookKuoPxdy+5Am/EaCOIU6+HyM8i163L+DYDT+MF+e
+LFUVtpoZ4xVzvHhLMDwIsZWdpBrJcj9MVv3TOL0PQDAjyo/Gp2TWWRbiMaQ8vkfO
+NVSDAfvtOUlTBFcdt0oeLYL0F5Yj8wt5HYdL9GE6u+JOl+ee/dEUUhcmoFew9x9W
+YznHujitbmbQVPV1IYi4qIE4MyZPlmPmSyVg1bnt9UIgSTccqwUV6VzxF2fpwjvP
+tTo/sNLdtI3S/mprvzxTgv/gaB//1JAHXDKgUAtsgUyb6+RREjF2mFnAJb99H7sN
+5E89dIbI9v9CW5gJr0BoPYiDIZ1+HTUhW3+FCw+eNvPET+p8H5b9E+VXG/ctjac2
+7Lkexo4TOVJCN0p9kTdgCNzHrsJpyMkvsP8sR1SVvv94uC1X7sspIgFNcf/+YQ9t
+hzq+5L7GZgAyYy06xi+DYL4xR4oAOkirp/va1Yu4PaYGqly/Fbuw8ibJH1lmnu0G
+u3jRn1M2GBkVDNlb9oUHiecCAwEAAQ==
 -----END PUBLIC KEY-----

Modified: branches/gsoc11-post-destroot/base/portmgr/ReleaseProcess
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/ReleaseProcess	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/ReleaseProcess	2012-10-19 16:03:11 UTC (rev 98880)
@@ -31,17 +31,17 @@
 
 === Create a Release Branch ===
 
-For each major release (i.e. 1.5.x, 1.6.x, etc.) an appropriate branch is created with a
+For each major release (i.e. 1.9.x, 2.0.x, etc.) an appropriate branch is created with a
 consistent name. To do this, two things are required:
 
  * Choose the svn revision from which to create the branch, most likely based off trunk.
- * Create the branch (e.g. release_1_6) through the svn "copy" command for history preservation,
+ * Create the branch (e.g. release_2_0) through the svn "copy" command for history preservation,
    first creating the needed branch directory to preserve the required directory structure
    (the 'base' directory level *needs* to exist in each release branch, otherwise selfupdate breaks):
 
- svn mkdir -m "commit-message" http://svn.macports.org/repository/macports/branches/release_1_6
- svn cp [-r<rev>] -m "commit-message" http://svn.macports.org/repository/macports/trunk/base \
-     http://svn.macports.org/repository/macports/branches/release_1_6
+ svn mkdir -m "commit-message" https://svn.macports.org/repository/macports/branches/release_2_0
+ svn cp [-r<rev>] -m "commit-message" https://svn.macports.org/repository/macports/trunk/base \
+     https://svn.macports.org/repository/macports/branches/release_2_0
 
 The actual release, alpha or beta releases, release candidates, and any point releases will all
 live on this branch, and tagged appropriately and if necessary (a must for the actual releases,
@@ -81,19 +81,20 @@
 
 Tagging conventions:
 
- * release_1_6_0-rc1 (release candidate 1 for release 1.6.0)
- * release_1_6_0 (tagged release 1.6.0)
- * release_1_6_0-archive (tagged release 1.6.0 -- complete archive)
- * release_1_6_1 (1.6.1 release)
+ * release_2_0_0-beta2 (beta 2 for release 2.0.0)
+ * release_2_0_0-rc1 (release candidate 1 for release 2.0.0)
+ * release_2_0_0 (tagged release 2.0.0)
+ * release_2_0_0-archive (tagged release 2.0.0 -- complete archive)
+ * release_2_0_1 (2.0.1 release)
 
 We first tag the branched base directory to make up the final release:
 
- svn cp -m "commit-message" http://svn.macports.org/repository/macports/branches/release_1_6 \
-     http://svn.macports.org/repository/macports/tags/release_1_6_0
+ svn cp -m "commit-message" https://svn.macports.org/repository/macports/branches/release_2_0 \
+     https://svn.macports.org/repository/macports/tags/release_2_0_0
 
 Although only the base subdirectory is branched and tagged for a given major release, we also create a
 separate tag for the entire tree (base sources and full ports tree) at the time the final release tag is
-created (only for major releases, 1.x.0), in order to provide a stake in the ground that specifies a set
+created (only for major releases, x.y.0), in order to provide a stake in the ground that specifies a set
 of ports intended to work with that release. Note that this tag incorporates the entire svn trunk directory
 at the revision number at which the final release was tagged.
 
@@ -101,14 +102,14 @@
 revision of the final tagging of base and then switching the base directory to the appropriate release
 tag URL. For instance:
 
- svn co [-r<rev>] http://svn.macports.org/repository/macports/trunk release_1.6.0-archive
- cd release_1.6.0-archive/base
- svn switch http://svn.macports.org/repository/macports/tags/release_1_6_0/base
+ svn co [-r<rev>] https://svn.macports.org/repository/macports/trunk release_2.0.0-archive
+ cd release_2.0.0-archive/base
+ svn switch https://svn.macports.org/repository/macports/tags/release_2_0_0/base
 
-And finally we tag the entire directory as release_1_6_0-archive:
+And finally we tag the entire directory as release_2_0_0-archive:
 
  cd ../../
- svn cp -m "commit-message" release_1.6.0-archive http://svn.macports.org/repository/macports/tags/release_1_6_0-archive
+ svn cp -m "commit-message" release_2.0.0-archive https://svn.macports.org/repository/macports/tags/release_2_0_0-archive
 
 
 === Create & Post Release Tarballs ===
@@ -116,49 +117,58 @@
 The release tarballs are tar.bz2 and tar.gz archives of the base directory only and of the entire svn tree
 for a particular release. They are named with the following naming convention:
 
- MacPorts-1.6.0.tar.{bz2,gz} (base directory only, corresponding to tag release_1_6_0)
- MacPorts-1.6.0-archive.tar.{bz2,gz} (complete archives corresponding to tag release_1_6_0-archive)
+ MacPorts-2.0.0.tar.{bz2,gz} (base directory only, corresponding to tag release_2_0_0)
+ MacPorts-2.0.0-archive.tar.{bz2,gz} (complete archives corresponding to tag release_2_0_0-archive)
 
 The following commands issued to the top level Makefile will generate all the tarballs and checksums:
 
- make ARC=yes DISTVER=1.6.0 distfromsvn
+ make ARC=yes DISTVER=2.0.0 distfromsvn
 
 Note that if you omit the "ARC=yes" flag at the start of the make call then the full archive tarballs will not be produced.
 
 All these tarballs are uploaded to the http://distfiles.macports.org/MacPorts/ directory. At present, this must
 be done with the help of the MacOSForge sysadmin.
 
-Additionally, a file is created, and posted to the same location, that contains md5, sha1, and rmd160 checksums
+Additionally, a file is created, and posted to the same location, that contains md5, sha1, rmd160, and sha256 checksums
 for each of the files:
 
- MacPorts-1.6.0.chk.txt
+ MacPorts-2.0.0.chk.txt
  (We should have a way to sign these checksums, and have the signer's keys posted somewhere.
  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 (1.x.0), named in a consistent fashion and incorporating the OS version for which it
+MacPorts releases (x.y.0), named in a consistent fashion and incorporating the OS version for which it
 was built.
 
- MacPorts-1.6.0-10.4-Tiger.dmg
- MacPorts-1.6.0-10.5-Leopard.dmg
+For 10.6 and newer, we now build flat packages, so an enclosing dmg is not necessary.
 
-To create a disk image, use the MacPorts port. The Portfile will need to be updated to incorporate the
+ MacPorts-2.0.0-10.5-Leopard.dmg
+ MacPorts-2.0.0-10.6-SnowLeopard.pkg
+ MacPorts-2.0.0-10.7-Lion.pkg
+
+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-1.6.0.dmg MacPorts-1.6.0-10.5-Leopard.dmg
- for dmg in MacPorts-1.6.0-*.dmg; do for type in -md5 -sha1 -ripemd160; do openssl dgst $type $dmg; done >> MacPorts-1.6.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
@@ -206,8 +216,9 @@
 
 
 === Update trunk's version for next release ===
+
 Once trunk is to be used for development of the next major version, increase its version information to
-indicate it's moved past the release version by setting the patch-level version to 99, e.g., 1.8.99 (in
+indicate it's moved past the release version by setting the patch-level version to 99, e.g. 2.0.99 (in
 trunk/base/config/macports_version).
 
 
@@ -216,12 +227,21 @@
 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.
- * [http://trac.macports.org/news/] The MacOSforge news section (submitter: portmgr@)
- * [http://www.apple.com/downloads/macosx/unix_open_source/macports.html Apple's downloads page] (submitter: jmpp@)
- * [http://freshmeat.net/projects/macports/ Freshmeat] (submitter: mww@)
+ * 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://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: ???)
  * [http://twitter.com/macports twitter] (submitter: raimue@)
  * (Where else?)
+
+
+=== Use of new features in Portfiles ===
+
+Using new features introduced by a release should be delayed for 14 days. This
+should allow users to upgrade their installations to the new release. This
+delay matches the warning about outdated ports tree sources.
+
+

Copied: branches/gsoc11-post-destroot/base/portmgr/dmg/Distribution (from rev 98879, trunk/base/portmgr/dmg/Distribution)
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/dmg/Distribution	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/portmgr/dmg/Distribution	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/portmgr/dmg/InstallationCheck
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/dmg/InstallationCheck	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/dmg/InstallationCheck	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # $Id$
 #

Modified: branches/gsoc11-post-destroot/base/portmgr/dmg/License.html
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/dmg/License.html	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/dmg/License.html	2012-10-19 16:03:11 UTC (rev 98880)
@@ -15,7 +15,7 @@
 
     <body>
     
-        <p>Copyright (c) 2002 - 2003, Apple Computer, Inc.<br>Copyright (c) 2004 - 2010, The MacPorts Project.</p>
+        <p>Copyright (c) 2002 - 2003, Apple Inc.<br>Copyright (c) 2004 - 2012, The MacPorts Project.</p>
         <p>All rights reserved.</p>
         <p><br></p>
         
@@ -26,7 +26,7 @@
             <li>Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.</li>
             <li>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.</li>
-            <li>Neither the name of Apple Computer, Inc., The MacPorts Project nor the names of its contributors may be used to endorse or
+            <li>Neither the name of Apple Inc., 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.</li>
         </ol>
         <p><br></p>

Modified: branches/gsoc11-post-destroot/base/portmgr/dmg/ReadMe.rtf
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/dmg/ReadMe.rtf	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/dmg/ReadMe.rtf	2012-10-19 16:03:11 UTC (rev 98880)
@@ -18,7 +18,7 @@
 System Requirements:
 \f0\b0 \
 \
-This disk image is built for Mac OS X __XVERS__.x and requires valid TCL, curl and OpenSSL installations to function - all present by default on Mac OS X. Also required is the installation of Apple's Xcode programing suite, available as a separate installation from your OS X CDs or DVD, or preferably the latest version from Apple's Developer site: {\field{\*\fldinst{HYPERLINK "http://developer.apple.com/tools/xcode/index.html"}}{\fldrslt http://developer.apple.com/tools/xcode/index.html}}.\
+This disk image is built for Mac OS X __XVERS__.x and requires valid Tcl, cURL and OpenSSL installations to function - all present by default on Mac OS X. Also required is the installation of Apple's Xcode programing suite, available as a separate installation from your OS X CDs or DVD, or preferably the latest version from Apple's Developer site: {\field{\*\fldinst{HYPERLINK "http://developer.apple.com/tools/xcode/index.html"}}{\fldrslt http://developer.apple.com/tools/xcode/index.html}}.\
 \
 \
 
@@ -99,7 +99,7 @@
 \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural
 
 \f0\b0 \cf0 \
-The MacPorts Wiki is available at: {\field{\*\fldinst{HYPERLINK "http://trac.macports.org/projects/macports/wiki/"}}{\fldrslt http://trac.macports.org}} and should be consulted for further documentation and support. Also provided are man pages for 
+The MacPorts Wiki is available at: {\field{\*\fldinst{HYPERLINK "https://trac.macports.org/wiki"}}{\fldrslt https://trac.macports.org}} and should be consulted for further documentation and support. Also provided are man pages for 
 \f2\i port
 \f0\i0 , 
 \f2\i macports.conf

Modified: branches/gsoc11-post-destroot/base/portmgr/dmg/postflight
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/dmg/postflight	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/dmg/postflight	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +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-2012 The MacPorts Project
 # Copyright (c) 2002-2007 Juan Manuel Palacios <jmpp at macports.org>, The MacPorts Project.
 # All rights reserved.
 #
@@ -12,7 +13,7 @@
 # 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., The MacPorts Project nor the
+# 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.
 #
@@ -35,7 +36,7 @@
 #set -x
 
 # Script identification ('cause more often than not the svn Id is not expanded):
-VERSION=1.9.0
+VERSION=2.1.0
 
 # Abstraction variables:
 PREFIX=__PREFIX__
@@ -45,6 +46,8 @@
 MANPAGES=${PREFIX}/share/man
 MACPORTS_TCL_DIR=${PREFIX}/share/macports/Tcl
 REG1DIR=${MACPORTS_TCL_DIR}/registry1.0
+DSCL=/usr/bin/dscl
+RUNUSR=macports
 TCLSH=/usr/bin/tclsh
 TCL_PACKAGE_DIR=/Library/Tcl
 TIMESTAMP=$(date +"%Y-%m-%d_at_%H:%M:%S")
@@ -53,8 +56,8 @@
 
 # Create config files from defaults if not present
 function setup_configs {
-    for f in macports.conf sources.conf variants.conf ; do
-        if [ ! -f ${CONFIGPATH}/${f} ]; then
+    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}
             /bin/chmod 644 ${CONFIGPATH}/${f}
@@ -64,6 +67,14 @@
 
 # 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} ${SCRIPT_DIR}/upgrade_sources_conf_default.tcl ${PREFIX}
+    # Convert image directories (and direct mode installs) to image archives
+    echo "Updating port image format..."
+    ${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 
         echo "An attempt to synchronize your recent MacPorts installation with the project's rsync server failed!"
@@ -71,30 +82,25 @@
     else
         echo "Successful!"
     fi
-    
-    # Add [default] tag to the central MacPorts repository, if it isn't already
-    ${TCLSH} ${PACKAGE_PATH}/Contents/Resources/upgrade_sources_conf_default.tcl ${PREFIX}
-    # Convert image directories (and direct mode installs) to image archives
-    ${TCLSH} ${PACKAGE_PATH}/Contents/Resources/images_to_archives.tcl ${MACPORTS_TCL_DIR}
 }
 
 # Through this command we write an environment variable to an appropriate shell configuration file,
 # backing up the original only if it exists and if it doesn't contain the ${OUR_STRING} identification string,
 # which hints that we've already tweaked it and therefore already backed it up.
 function write_setting () {
-    if [ -f ${HOME}/.${CONF_FILE} ] && ! grep "${OUR_STRING}" ${HOME}/.${CONF_FILE} > /dev/null; then
+    if [[ -f "${HOME}/.${CONF_FILE}" ]] && ! grep "${OUR_STRING}" "${HOME}/.${CONF_FILE}" > /dev/null; then
         echo "Backing up your ${HOME}/.${CONF_FILE} shell confguration file as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX} before adapting it for MacPorts."
-        /bin/cp -fp ${HOME}/.${CONF_FILE} "${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}" || {
+        /bin/cp -fp "${HOME}/.${CONF_FILE}" "${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}" || {
             echo "An attempt to backup your original configuration file failed! Please set your MacPorts compatible environment manually."
             update_macports
             exit 1
         }
-        echo -e "\n##\n# Your previous ${HOME}/.${CONF_FILE} file was backed up as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}\n##" >> ${HOME}/.${CONF_FILE}
+        echo -e "\n##\n# Your previous ${HOME}/.${CONF_FILE} file was backed up as ${HOME}/.${CONF_FILE}.${BACKUP_SUFFIX}\n##" >> "${HOME}/.${CONF_FILE}"
     fi
-    echo -e "\n# ${OUR_STRING}: adding an appropriate ${1} variable for use with MacPorts." >> ${HOME}/.${CONF_FILE}
-    echo "${ENV_COMMAND} ${1}${ASSIGN}${2}" >> ${HOME}/.${CONF_FILE}
-    echo -e "# Finished adapting your ${1} environment variable for use with MacPorts.\n" >> ${HOME}/.${CONF_FILE}
-    chown ${USER} ${HOME}/.${CONF_FILE} || echo "Warning: unable to adapt permissions on your ${HOME}/.${CONF_FILE} shell configuration file!"
+    echo -e "\n# ${OUR_STRING}: adding an appropriate ${1} variable for use with MacPorts." >> "${HOME}/.${CONF_FILE}"
+    echo "${ENV_COMMAND} ${1}${ASSIGN}${2}" >> "${HOME}/.${CONF_FILE}"
+    echo -e "# Finished adapting your ${1} environment variable for use with MacPorts.\n" >> "${HOME}/.${CONF_FILE}"
+    chown ${USER} "${HOME}/.${CONF_FILE}" || echo "Warning: unable to adapt permissions on your ${HOME}/.${CONF_FILE} shell configuration file!"
     echo "An appropriate ${1} variable has been added to your shell environment by the MacPorts installer."
 }
 
@@ -112,7 +118,7 @@
 
 # Delete the old registry1.0 directory
 function delete_reg1 {
-    if [ -d ${REG1DIR} ]; then
+    if [[ -d ${REG1DIR} ]]; then
         rm -vrf ${REG1DIR}
     fi
 }
@@ -120,16 +126,67 @@
 # link macports1.0 into tcl package dir if possible
 function link_tcl_package {
     # delete old directory if present
-    if ! test -L "${TCL_PACKAGE_DIR}/macports1.0" && test -d "${TCL_PACKAGE_DIR}/macports1.0"; then
-        rm -vrf "${TCL_PACKAGE_DIR}/macports1.0" || true
-    fi
-    if ! test -e "${TCL_PACKAGE_DIR}/macports1.0" && test -w "${TCL_PACKAGE_DIR}"; then
-		ln -vs "${MACPORTS_TCL_DIR}/macports1.0" "${TCL_PACKAGE_DIR}/macports1.0" || true
+    if [[ ! -L "${TCL_PACKAGE_DIR}/macports1.0" ]]; then
+        if [[ ! -e "${TCL_PACKAGE_DIR}" ]]; then
+            /usr/bin/install -d "${TCL_PACKAGE_DIR}" || true
+        fi
+        if [[ -d "${TCL_PACKAGE_DIR}/macports1.0" ]]; then
+            rm -vrf "${TCL_PACKAGE_DIR}/macports1.0" || true
+        fi
+        if [[ ! -e "${TCL_PACKAGE_DIR}/macports1.0" && -d "${TCL_PACKAGE_DIR}" ]]; then
+            ln -vs "${MACPORTS_TCL_DIR}/macports1.0" "${TCL_PACKAGE_DIR}/macports1.0" || true
+        fi
 	fi
 }
 
+# create the user to use for privilege dropping
+function create_run_user {
+    DSEDITGROUP=/usr/sbin/dseditgroup
+    if ! ${DSCL} -q . -read /Groups/${RUNUSR} > /dev/null 2>&1 ; then
+        echo "Creating group \"${RUNUSR}\""
+        ${DSEDITGROUP} -q -o create ${RUNUSR}
+    fi
+    if ! ${DSCL} -q . -list /Users/${RUNUSR} > /dev/null 2>&1 ; then
+        echo "Creating user \"${RUNUSR}\""
+        NEXTUID=501
+        while [[ -n "`${DSCL} -q /Search -search /Users UniqueID $NEXTUID`" ]]; do
+            let "NEXTUID=NEXTUID+1"
+        done
+        ${DSCL} -q . -create /Users/${RUNUSR} UniqueID $NEXTUID
+
+        # These are implicitly added on Mac OSX Lion.  AuthenticationAuthority
+        # causes the user to be visible in the Users & Groups Preference Pane,
+        # and the others are just noise, so delete them.
+        # https://trac.macports.org/ticket/30168
+        ${DSCL} -q . -delete /Users/${RUNUSR} AuthenticationAuthority
+        ${DSCL} -q . -delete /Users/${RUNUSR} PasswordPolicyOptions
+        ${DSCL} -q . -delete /Users/${RUNUSR} dsAttrTypeNative:KerberosKeys
+        ${DSCL} -q . -delete /Users/${RUNUSR} dsAttrTypeNative:ShadowHashData
+
+        ${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 ${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
+        GID=$(${DSCL} -q . -read /Groups/${RUNUSR} PrimaryGroupID | /usr/bin/awk '{print $2}')
+        if [[ "$(${DSCL} -q . -read /Users/${RUNUSR} PrimaryGroupID 2>/dev/null | /usr/bin/awk '{print $2}')" != "$GID" ]]; then
+            echo "Fixing PrimaryGroupID for user \"${RUNUSR}\""
+            ${DSCL} -q . -create /Users/${RUNUSR} PrimaryGroupID $GID
+            ${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}\"."
 
+# create macports user
+create_run_user
 # Set up config files
 setup_configs
 # link macports1.0 pkg
@@ -141,7 +198,7 @@
 
 # Determine the user's shell, in order to choose an appropriate configuration file we'll be tweaking.
 # Exit nicely if the shell is any other than bash or tcsh, as that's considered non-standard.
-USHELL=$(dscl . -read /users/${USER} shell | awk -F'/' '{print $NF}') || {
+USHELL=$(${DSCL} . -read /Users/${USER} shell | awk -F'/' '{print $NF}') || {
     echo "An attempt to determine your shell name failed! Please set your MacPorts compatible environment manually."
     update_macports
     exit 1
@@ -152,9 +209,9 @@
         LOGIN_FLAG=""
         ENV_COMMAND="setenv"
         ASSIGN=" "
-        if [ -f ${HOME}/.tcshrc ]; then
+        if [[ -f "${HOME}/.tcshrc" ]]; then
             CONF_FILE=tcshrc
-        elif [ -f ${HOME}/.cshrc ]; then
+        elif [[ -f "${HOME}/.cshrc" ]]; then
             CONF_FILE=cshrc
         else
             CONF_FILE=tcshrc
@@ -165,9 +222,9 @@
         LOGIN_FLAG="-l"
         ENV_COMMAND="export"
         ASSIGN="="
-        if [ -f ${HOME}/.bash_profile ]; then
+        if [[ -f "${HOME}/.bash_profile" ]]; then
             CONF_FILE=bash_profile
-        elif [ -f ${HOME}/.bash_login ]; then
+        elif [[ -f "${HOME}/.bash_login" ]]; then
             CONF_FILE=bash_login
         else
             CONF_FILE=profile
@@ -193,15 +250,15 @@
 # Adding our setting to the MANPATH variable only if it exists:
 if ! ${SHELL} ${LOGIN_FLAG} -c "/usr/bin/env | grep MANPATH" > /dev/null || \
 # and following that, if it's not empty:
-  [ -z "${ORIGINAL_MANPATH}" ] || \
+  [[ -z "${ORIGINAL_MANPATH}" ]] || \
 # or if it doesn't already contain our path:
   echo "${ORIGINAL_MANPATH}" | grep ${MANPAGES} > /dev/null || \
 # or if there's no empty component somewhere in the middle of it:
   echo "${ORIGINAL_MANPATH}" | grep :: > /dev/null || \
 # or at the start of it:
-  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ] || \
+  [[ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $1}')" ]] || \
 # or at the end of it:
-  [ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]; then
+  [[ -z "$(echo "${ORIGINAL_MANPATH}" | awk -F : '{print $NF}')" ]]; then
     echo "Your shell already has the right MANPATH environment variable for use with MacPorts!"
 else
     write_setting MANPATH "${MANPAGES}:\$MANPATH"
@@ -217,6 +274,7 @@
 
 # Postflight script is done with its job, update MacPorts and exit gracefully!
 update_macports
-echo "You have succesfully installed the MacPorts system, launch a terminal and try it out!"
-echo "Read the port(1) manual page and http://guide.macports.org for help, http://www.macports.org/contact.php if you need to get in touch with The MacPorts Project."
+echo "You have successfully installed the MacPorts system. Launch a terminal and try it out!"
+echo "Read the port(1) manual page and http://guide.macports.org/ for help."
+echo "See http://www.macports.org/contact.php if you need to get in touch with The MacPorts Project."
 exit 0

Modified: branches/gsoc11-post-destroot/base/portmgr/fedora/macports.spec
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/fedora/macports.spec	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/fedora/macports.spec	2012-10-19 16:03:11 UTC (rev 98880)
@@ -4,8 +4,8 @@
 Release: 0%{?dist}
 License: BSD
 Group: System Environment/Base
-URL: http://www.macports.org
-Source: http://svn.macosforge.org/repository/macports/distfiles/MacPorts/MacPorts-%{version}.tar.bz2
+URL: http://www.macports.org/
+Source: https://svn.macports.org/repository/macports/distfiles/MacPorts/MacPorts-%{version}.tar.bz2
 Prefix: /opt/local
 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
 


Property changes on: branches/gsoc11-post-destroot/base/portmgr/fedora/macports.spec
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/portmgr/fedora/macports.spec:37343-46937
/branches/universal-sanity/base/portmgr/fedora/macports.spec:51872-52323
/branches/variant-descs-14482/base/portmgr/fedora/macports.spec:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/portmgr/fedora/macports.spec.in:30388-57826
/users/perry/base-bugs_and_notes/portmgr/fedora/macports.spec:45682-46060
/users/perry/base-select/portmgr/fedora/macports.spec:44044-44692
   + /branches/gsoc08-privileges/base/portmgr/fedora/macports.spec:37343-46937
/branches/gsoc11-rev-upgrade/base/portmgr/fedora/macports.spec:78828-88375
/branches/universal-sanity/base/portmgr/fedora/macports.spec:51872-52323
/branches/variant-descs-14482/base/portmgr/fedora/macports.spec:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/portmgr/fedora/macports.spec:78761-98879
/trunk/base/portmgr/fedora/macports.spec.in:30388-57826
/users/perry/base-bugs_and_notes/portmgr/fedora/macports.spec:45682-46060
/users/perry/base-select/portmgr/fedora/macports.spec:44044-44692

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/GuideRegen.sh
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/GuideRegen.sh	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/GuideRegen.sh	2012-10-19 16:03:11 UTC (rev 98880)
@@ -17,7 +17,7 @@
 
 # Other settings (probably don't need to be changed).
 SVN_CONFIG_DIR=${ROOT}/svnconfig
-REPO_BASE=http://svn.macports.org/repository/macports
+REPO_BASE=https://svn.macports.org/repository/macports
 SVN="/opt/local/bin/svn -q --non-interactive --config-dir $SVN_CONFIG_DIR"
 # Where to checkout the source code. This needs to exist!
 SRCTREE=${ROOT}/source

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/PortIndex2MySQL.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/PortIndex2MySQL.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/PortIndex2MySQL.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -9,7 +9,7 @@
 # $Id$
 #
 # Copyright (c) 2007 Juan Manuel Palacios, The MacPorts Project.
-# Copyright (c) 2003 Apple Computer, Inc.
+# Copyright (c) 2003 Apple Inc.
 # Copyright (c) 2002 Kevin Van Vechten. 
 # All rights reserved.
 #
@@ -21,7 +21,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/mirror_macports.sh
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/mirror_macports.sh	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/mirror_macports.sh	2012-10-19 16:03:11 UTC (rev 98880)
@@ -7,7 +7,7 @@
 ####
 
 # regexp of ports that we do not mirror
-EXCLUSIONS='^(molden)$'
+EXCLUSIONS='^(molden|metis)$'
 
 # macports really wants this, so lets appease it
 export COLUMNS=80

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/mprsyncup
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/mprsyncup	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/mprsyncup	2012-10-19 16:03:11 UTC (rev 98880)
@@ -20,7 +20,7 @@
 #
 # Lastly, it is required of every 3rd party mirrors to keep track of this script
 # and the base/portmgr/rsync.repos file and always maintain local copies in as
-# close sync as possible. 
+# close sync as possible.
 #
 #
 # Created by fkr at opendarwin.org, jberry at macports.org and yeled at macports.org,
@@ -38,10 +38,11 @@
 RM="/bin/rm"
 MKDIR="/bin/mkdir"
 LN="/bin/ln"
+TAR="/usr/bin/tar"
+OPENSSL="/usr/bin/openssl"
 
 # Paths we'll work on:
 ROOT=/var/tmp/macports
-TMPDIR=mp_trunk/base
 PREFIX=${ROOT}/opt/local
 TCLPKG=${PREFIX}/lib/tcl
 SVNROOT=/var/tmp/macports
@@ -54,17 +55,16 @@
 PATH=${PREFIX}/bin:/bin:/usr/bin:/usr/sbin:/opt/local/bin
 
 # platforms we generate indexes for
-PLATFORMS="8_ppc 8_i386 9_ppc 9_i386 10_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"
 
-MP_USER=nobody
-MP_GROUP=nobody
-
 # Sources information:
-SVNURL=http://svn.macports.org/repository/macports
+SVNURL=https://svn.macports.org/repository/macports
 RELEASE_URL_FILE=config/RELEASE_URL
 
+# private key to use for signing
+# XXX set real path
+PRIVKEY=""
+
 # cleanup up the working copy if it is locked
 if [ -f ${TBASE}/.svn/lock ]; then
     ${CLEANUP} ${TBASE}
@@ -85,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
@@ -97,7 +97,7 @@
 if [ ! -d ${RSYNCROOT}/release/base ]; then
     ${MKDIR} -p ${RSYNCROOT}/release/base
 fi
-${RSYNC} -aIC --delete ${RBASE}/ ${RSYNCROOT}/release/base 
+${RSYNC} -aIC --delete ${RBASE}/ ${RSYNCROOT}/release/base
 
 # clean up the working copy if it is locked
 if [ -f ${PORTS}/.svn/lock ]; then
@@ -106,7 +106,7 @@
 
 # Update/checkout the ports tree, export it and rsync it to ${RSYNCROOT}/release/ports:
 if [ -d ${PORTS}/.svn ]; then
-    ${SVN} update ${PORTS}  
+    ${SVN} update ${PORTS}
 else
     ${SVN} checkout ${SVNURL}/trunk/dports ${PORTS}
 fi
@@ -114,24 +114,20 @@
 # generate platform-specific indexes
 pushd ${PORTS} >> /dev/null
 # build MP trunk in a private location for indexing
-pushd ${ROOT}/${TMPDIR} >> /dev/null
-mkdir -p ${TCLPKG} 
+pushd ${TBASE} >> /dev/null
+${MKDIR} -p ${TCLPKG}
 ./configure \
     --prefix=${PREFIX} \
-    --with-tclpackage=${TCLPKG} \
-    --with-install-user=${MP_USER} \
-    --with-install-group=${MP_GROUP} 
-make clean 
+    --with-tclpackage=${TCLPKG}
+make clean
 make
-make install 
+make install
 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
@@ -146,3 +142,22 @@
     ${RM} -rf dports && ${LN} -s ../release/ports dports
 fi
 
+# generate and sign tarballs of base and dports
+# the signature always needs to match, so we try to make this look atomic to
+# clients by switching a symlink target
+
+TAR_CURDIR=${RSYNCROOT}/release/tarballs_current
+${MKDIR} -p ${TAR_CURDIR}
+cp -pR ${TAR_CURDIR} ${RSYNCROOT}/release/tarballs_old
+${LN} -sfh tarballs_old ${RSYNCROOT}/release/tarballs
+${TAR} -C ${RSYNCROOT}/release/ -cf ${TAR_CURDIR}/base.tar base
+${TAR} --exclude 'PortIndex*' -C ${RSYNCROOT}/release/ -cf ${TAR_CURDIR}/ports.tar ports
+cp -pR ${RSYNCROOT}/release/ports/PortIndex_* ${TAR_CURDIR}
+# XXX needs PRIVKEY to be set above
+#${OPENSSL} dgst -ripemd160 -sign ${PRIVKEY} -out ${TAR_CURDIR}/base.tar.rmd160 ${TAR_CURDIR}/base.tar
+#${OPENSSL} dgst -ripemd160 -sign ${PRIVKEY} -out ${TAR_CURDIR}/ports.tar.rmd160 ${TAR_CURDIR}/ports.tar
+for index in ${TAR_CURDIR}/PortIndex_*/PortIndex; do
+    #${OPENSSL} dgst -ripemd160 -sign ${PRIVKEY} -out ${index}.rmd160 ${index}
+done
+${LN} -sfh tarballs_current ${RSYNCROOT}/release/tarballs
+${RM} -rf ${RSYNCROOT}/release/tarballs_old

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.PortIndex2MySQL.plist
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.PortIndex2MySQL.plist	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.PortIndex2MySQL.plist	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
     <dict>
         <key>Label</key>
@@ -11,17 +11,17 @@
         <key>StartCalendarInterval</key>
         <array>
             <dict>
-	        <key>Hour</key>
-	        <integer>4</integer>
-	        <key>Minute</key>
-	        <integer>15</integer>
-	    </dict>
-	    <dict>
-	        <key>Hour</key>
-		<integer>16</integer>
-		<key>Minute</key>
-		<integer>15</integer>
-	    </dict>
+                <key>Hour</key>
+                <integer>4</integer>
+                <key>Minute</key>
+                <integer>15</integer>
+            </dict>
+            <dict>
+                <key>Hour</key>
+                <integer>16</integer>
+                <key>Minute</key>
+                <integer>15</integer>
+            </dict>
         </array>
         <key>UserName</key>
         <string>mysql</string>

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.mprsyncup.plist
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.mprsyncup.plist	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/org.macports.mprsyncup.plist	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
     <dict>
         <key>Label</key>
@@ -11,13 +11,13 @@
         <key>StartCalendarInterval</key>
         <array>
             <dict>
-	        <key>Minute</key>
-	        <integer>00</integer>
-	    </dict>
-	    <dict>
-		<key>Minute</key>
-		<integer>30</integer>
-	    </dict>
+                <key>Minute</key>
+                <integer>00</integer>
+            </dict>
+            <dict>
+                <key>Minute</key>
+                <integer>30</integer>
+            </dict>
         </array>
     </dict>
 </plist>

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/port_binary_distributable.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/port_binary_distributable.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/port_binary_distributable.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -6,6 +6,8 @@
 # Check that binaries of a port are distributable by looking at its license
 # and the licenses of its dependencies.
 #
+# Expected format: A {B C} means the license is A plus either B or C.
+#
 # Exit status:
 # 0: distributable
 # 1: non-distributable
@@ -18,30 +20,78 @@
 
 set check_deptypes {depends_build depends_lib}
 
-set good_licenses {agpl apache apsl artistic boost bsd cecill cpl curl \
-                   fontconfig freebsd gfdl gpl ibmpl ijg jasper lgpl libpng \
-                   mit mpl openssl php psf qpl public-domain ruby sleepycat \
-                   ssleay x11 zlib zpl}
+
+# Notes:
+# 'Restrictive/Distributable' means a non-free license that nonetheless allows
+# distributing binaries.
+# 'Restrictive' means a non-free license that does not allow distributing
+# binaries, and is thus not in the list.
+# 'Permissive' is a catchall for other licenses that allow
+# modification and distribution of source and binaries.
+# 'Copyleft' means a license that requires source code to be made available,
+# and derivative works to be licensed the same as the original.
+# 'GPLConflict' should be added if the license conflicts with the GPL (and its
+# variants like CeCILL and the AGPL) and is not in the list of licenses known
+# 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 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 \
+                   mpl ncsa noncommercial openldap openssl permissive php \
+                   psf public-domain qpl restrictive/distributable ruby \
+                   sleepycat ssleay tcl/tk vim w3c wtfpl wxwidgets x11 zlib zpl}
 foreach lic $good_licenses {
     set license_good($lic) 1
 }
+
+proc all_licenses_except { args } {
+    global good_licenses
+    set remaining $good_licenses
+    foreach arg $args {
+        set remaining [lsearch -inline -all -not -exact $remaining $arg]
+    }
+    return [list $remaining]
+}
+
 # keep these values sorted
 array set license_conflicts \
-    {agpl {cecill gpl} \
-    apache {cecill gpl} \
-    apsl {cecill gpl} \
-    cpl {cecill gpl} \
-    cecill {agpl apache apsl cpl ibmpl mpl openssl php qpl ssleay zpl-1} \
-    freetype {gpl-2} \
-    gpl {agpl apache apsl cpl ibmpl mpl openssl php qpl ssleay zpl-1} \
-    gpl-2 {freetype} \
-    ibmpl {cecill gpl} \
-    mpl {cecill gpl} \
-    openssl {cecill gpl} \
-    php {cecill gpl} \
-    qpl {cecill gpl} \
-    ssleay {cecill gpl}
-    zpl-1 {cecill gpl}}
+    "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 {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 {agpl cecill gpl}
+    qpl {agpl cecill gpl}
+    restrictive/distributable {agpl 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...\]"
@@ -80,7 +130,17 @@
         }
     }
 
-    return [list $dependencyList $portInfo(license)]
+    set ret [list $dependencyList $portInfo(license)]
+    if {[info exists portInfo(installs_libs)]} {
+        lappend ret $portInfo(installs_libs)
+    } else {
+        # 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
 }
 
 # return license with any trailing dash followed by a number and/or plus sign removed
@@ -97,52 +157,105 @@
     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 full_lic $top_license {
-        # chop off any trailing version number
-        set lic [remove_version [string tolower $full_lic]]
-        # add name to the list for later
-        lappend top_license_names $lic
-        if {![info exists license_good($lic)]} {
+    foreach sublist $top_license {
+        # each element may be a list of alternatives (i.e. only one need apply)
+        set any_good 0
+        set sub_names {}
+        foreach full_lic $sublist {
+            # chop off any trailing version number
+            set lic [remove_version [string tolower $full_lic]]
+            # add name to the list for later
+            lappend sub_names $lic
+            if {[info exists license_good($lic)]} {
+                set any_good 1
+            }
+        }
+        lappend top_license_names $sub_names
+        if {!$any_good} {
             if {$verbose} {
                 puts "'$portName' has license '$lic' which is not known to be distributable"
             }
             return 1
         }
     }
+
     # start with deps of top-level port
     set portList [lindex $top_info 0]
     while {[llength $portList] > 0} {
         set aPort [lindex $portList 0]
+        # 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]
-        foreach full_lic $aPortLicense {
+        set installs_libs [lindex $aPortInfo 2]
+        if {!$installs_libs} {
+            continue
+        }
+        foreach sublist $aPortLicense {
+            set any_good 0
+            set any_compatible 0
             # check that this dependency's license(s) are good
-            set lic [remove_version [string tolower $full_lic]]
-            if {![info exists license_good($lic)]} {
+            foreach full_lic $sublist {
+                set lic [remove_version [string tolower $full_lic]]
+                if {[info exists license_good($lic)]} {
+                    set any_good 1
+                } else {
+                    # no good being compatible with other licenses if it's not distributable itself
+                    continue
+                }
+
+                # ... and that they don't conflict with the top-level port's
+                set any_conflict 0
+                foreach top_sublist [concat $top_license $top_license_names] {
+                    set any_sub_compatible 0
+                    foreach top_lic $top_sublist {
+                        if {![info exists license_conflicts([string tolower $top_lic])]
+                            || ([lsearch -sorted $license_conflicts([string tolower $top_lic]) $lic] == -1
+                            && [lsearch -sorted $license_conflicts([string tolower $top_lic]) [string tolower $full_lic]] == -1)} {
+                            set any_sub_compatible 1
+                            break
+                        }
+                    }
+                    if {!$any_sub_compatible} {
+                        set any_conflict 1
+                        break
+                    }
+                }
+                if {!$any_conflict} {
+                    set any_compatible 1
+                    break
+                }
+            }
+
+            if {!$any_good} {
                 if {$verbose} {
-                    puts "dependency '$aPort' has license '$lic' which is not known to be distributable"
+                    puts "${portName}'s dependency '$aPort' has license '$lic' which is not known to be distributable"
                 }
                 return 1
             }
-            # ... and that they don't conflict with the top-level port's
-            foreach top_lic [concat $top_license $top_license_names] {
-                if {[info exists license_conflicts([string tolower $top_lic])]
-                    && ([lsearch -sorted $license_conflicts([string tolower $top_lic]) $lic] != -1
-                    || [lsearch -sorted $license_conflicts([string tolower $top_lic]) [string tolower $full_lic]] != -1)} {
-                    if {$verbose} {
-                        puts "dependency '$aPort' has license '$full_lic' which conflicts with license '$top_lic' from '$portName'"
-                    }
-                    return 1
+            if {!$any_compatible} {
+                if {$verbose} {
+                    puts "dependency '$aPort' has license '$full_lic' which conflicts with license '$top_lic' from '$portName'"
                 }
+                return 1
             }
         }
 
-        # mark it seen and add its deps to the list
-        set portSeen($aPort) 1
-        set portList [lreplace $portList 0 0]
+        # add its deps to the list
         foreach possiblyNewPort [lindex $aPortInfo 0] {
             if {![info exists portSeen($possiblyNewPort)]} {
                 lappend portList $possiblyNewPort

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_lint.pl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_lint.pl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_lint.pl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -14,7 +14,7 @@
 $ENV{'LANG'} = 'en_US.UTF-8';
 
 my $REPOPATH = "/svn/repositories/macports/";
-my $REPOHOST = "http://svn.macosforge.org/repository/macports";
+my $REPOHOST = "https://svn.macports.org/repository/macports";
 my $SVNLOOK = "/opt/local/bin/svnlook";
 
 # use a release (non-trunk) version of port
@@ -96,7 +96,7 @@
 	     To => "$author, $maintainers",
 	     From => 'noreply at macports.org',
 	     Subject => "[$rev] $port Lint Report",
-	     Message => "Change: http://trac.macports.org/changeset/$rev\nPortfile: $port\n\n$errors \n\n",
+	     Message => "Change: https://trac.macports.org/changeset/$rev\nPortfile: $port\n\n$errors \n\n",
 	     smtp => 'relay.apple.com',
 	     );
 

Modified: branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_mirror.pl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_mirror.pl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/jobs/portfile_mirror.pl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,7 +11,7 @@
 my $EXCLUSIONS = ('molden');
 
 my $REPOPATH = "/svn/repositories/macports/";
-my $REPOHOST = "http://svn.macosforge.org/repository/macports";
+my $REPOHOST = "https://svn.macports.org/repository/macports";
 my $SVNLOOK = "/opt/local/bin/svnlook";
 my $PORTCMD = "/opt/local/bin/port";
 my $SVN = "/opt/local/bin/svn -q --non-interactive";
@@ -20,7 +20,7 @@
 my $rev = $ARGV[0] or usage();
 my $TMPROOT = "/tmp/mp_mirror/$rev";
 
-my @changes = `$SVNLOOK changed $REPOPATH -r $rev`;
+my @changes = `$SVNLOOK changed $REPOPATH -r $rev | grep '/Portfile' | grep -vE '^[ ]+D'`;
 
 foreach my $change (@changes) {
     if ($change =~ /Portfile/) { 

Modified: branches/gsoc11-post-destroot/base/portmgr/packaging/dpkgall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/packaging/dpkgall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/packaging/dpkgall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,9 +2,10 @@
 # dpkgbuild.tcl
 # $Id$
 #
+# Copyright (c) 2009-2011 The MacPorts Project
 # Copyright (c) 2004 Landon Fuller <landonf at macports.org>
 # Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -15,7 +16,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -708,7 +709,7 @@
 			set port [lindex $portlist 0]
 
 			ui_msg "Uninstalling $port."
-			if { [catch {registry_uninstall::uninstall $portname $portversion} result] } {
+			if { [catch {registry_uninstall::uninstall $portname $portversion "" 0 [array get options]} result] } {
 				global errorInfo
 				ui_debug "$errorInfo"
 				ui_noisy_errorr "Fatal error: Uninstalling $port failed: $result"

Modified: branches/gsoc11-post-destroot/base/portmgr/packaging/mpkgall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/packaging/mpkgall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/packaging/mpkgall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,7 +3,7 @@
 # $Id$
 #
 # Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -102,7 +102,7 @@
 proc write_description_plist {infofile portname portversion description} {
 	set infofd [open ${infofile} w+]
 	puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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>
@@ -174,7 +174,7 @@
 
 	set infofd [open ${infofile} w+]
 	puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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>

Modified: branches/gsoc11-post-destroot/base/portmgr/packaging/packageall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/packaging/packageall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/packaging/packageall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # packageall.tcl
 # $Id$
 #
+# Copyright (c) 2009-2011 The MacPorts Project
 # Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/portmgr/packaging/rpmall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/portmgr/packaging/rpmall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/portmgr/packaging/rpmall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,9 +2,10 @@
 # rpmall.tcl
 # $Id$
 #
+# Copyright (c) 2009-2011 The MacPorts Project
 # Copyright (c) 2003 Benjamin Reed <ranger at befunk.com>
 # Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -15,7 +16,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/setupenv.bash.in
===================================================================
--- branches/gsoc11-post-destroot/base/setupenv.bash.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/setupenv.bash.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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=""

Modified: branches/gsoc11-post-destroot/base/src/Makefile.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/Makefile.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/Makefile.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -5,7 +5,8 @@
 			package1.0 \
 			pextlib1.0 \
 			registry2.0 \
-			darwintracelib1.0
+			darwintracelib1.0 \
+			machista1.0
 SUBDIR=		${TCLPKG} port programs
 
 all::

Modified: branches/gsoc11-post-destroot/base/src/config.h.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/config.h.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/config.h.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/cregistry/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +1,6 @@
 # $Id$
 
-OBJS = registry.o entry.o sql.o vercomp.o
+OBJS = registry.o entry.o sql.o vercomp.o util.o file.o
 STLIB_NAME = cregistry.a
 RANLIB = ranlib
 

Modified: branches/gsoc11-post-destroot/base/src/cregistry/entry.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/entry.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/entry.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,6 +2,7 @@
  * entry.c
  * $Id$
  *
+ * Copyright (c) 2010-2011 The MacPorts Project
  * Copyright (c) 2007 Chris Pickel <sfiera at macports.org>
  * All rights reserved.
  *
@@ -33,10 +34,11 @@
 #include "entry.h"
 #include "registry.h"
 #include "sql.h"
+#include "util.h"
 
-#include <string.h>
-#include <stdlib.h>
 #include <sqlite3.h>
+#include <stdlib.h>
+#include <string.h>
 
 /*
  * TODO: possibly, allow reg_entry_search to take different matching strategies
@@ -52,9 +54,6 @@
  *       always have very discrete values. These could be more efficiently dealt
  *       with as integers.
  *
- * TODO: move the utility functions to util.h or something. Not important until
- *       there are more types in the registry than entry, though.
- *
  * TODO: considering a "weak" flag in registry.files. The meaning of this would
  *       be "I wish for my version of this file to be activated when I am, but
  *       not to be deactivated when I am; nor should other ports be prevented
@@ -68,85 +67,6 @@
  */
 
 /**
- * Concatenates `src` to string `dst`. Simple concatenation. Only guaranteed to
- * work with strings that have been allocated with `malloc`. Amortizes cost of
- * expanding string buffer for O(N) concatenation and such. Uses `memcpy` in
- * favor of `strcpy` in hopes it will perform a bit better.
- *
- * @param [in,out] dst       a reference to a null-terminated string
- * @param [in,out] dst_len   number of characters currently in `dst`
- * @param [in,out] dst_space number of characters `dst` can hold
- * @param [in] src           string to concatenate to `dst`
- */
-static int reg_strcat(char** dst, size_t* dst_len, size_t* dst_space, char* src) {
-    size_t src_len = strlen(src);
-    size_t result_len = *dst_len + src_len;
-    if (result_len > *dst_space) {
-        char* new_dst;
-        *dst_space *= 2;
-        if (*dst_space < result_len) {
-            *dst_space = result_len;
-        }
-        new_dst = realloc(*dst, *dst_space * sizeof(char) + 1);
-        if (!new_dst)
-            return 0;
-        else
-            *dst = new_dst;
-    }
-    memcpy(*dst + *dst_len, src, src_len+1);
-    *dst_len = result_len;
-    return 1;
-}
-
-/**
- * Appends element `src` to the list `dst`. It's like `reg_strcat`, except `src`
- * represents a single element and not a sequence of `char`s.
- *
- * @param [in,out] dst       a reference to a list of pointers
- * @param [in,out] dst_len   number of elements currently in `dst`
- * @param [in,out] dst_space number of elements `dst` can hold
- * @param [in] src           elements to append to `dst`
- */
-static int reg_listcat(void*** dst, int* dst_len, int* dst_space, void* src) {
-    if (*dst_len == *dst_space) {
-        void** new_dst;
-        *dst_space *= 2;
-        new_dst = realloc(*dst, *dst_space * sizeof(void*));
-        if (!new_dst)
-            return 0;
-        else
-            *dst = new_dst;
-    }
-    (*dst)[*dst_len] = src;
-    (*dst_len)++;
-    return 1;
-}
-
-/**
- * Returns an expression to use for the given strategy. This should be passed as
- * the `fmt` argument of `sqlite3_mprintf`, with the key and value following.
- *
- * @param [in] strategy a strategy (one of the `reg_strategy_*` constants)
- * @param [out] errPtr  on error, a description of the error that occurred
- * @return              a sqlite3 expression if success; NULL if failure
- */
-static char* reg_strategy_op(reg_strategy strategy, reg_error* errPtr) {
-    switch (strategy) {
-        case reg_strategy_exact:
-            return "%q = '%q'";
-        case reg_strategy_glob:
-            return "%q GLOB '%q'";
-        case reg_strategy_regexp:
-            return "REGEXP(%q, '%q')";
-        default:
-            errPtr->code = REG_INVALID;
-            errPtr->description = "invalid matching strategy specified";
-            errPtr->free = NULL;
-            return NULL;
-    }
-}
-
-/**
  * Converts a `sqlite3_stmt` into a `reg_entry`. The first column of the stmt's
  * row must be the id of an entry; the second either `SQLITE_NULL` or the
  * address of the entry in memory.
@@ -158,7 +78,7 @@
  * @return              true if success; false if failure
  */
 static int reg_stmt_to_entry(void* userdata, void** entry, void* stmt,
-        reg_error* errPtr UNUSED) {
+        void* calldata UNUSED, reg_error* errPtr UNUSED) {
     int is_new;
     reg_registry* reg = (reg_registry*)userdata;
     sqlite_int64 id = sqlite3_column_int64(stmt, 0);
@@ -201,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)
@@ -261,9 +181,16 @@
         char* revision, char* variants, char* epoch, reg_error* errPtr) {
     sqlite3_stmt* stmt = NULL;
     reg_entry* entry = NULL;
-    char* query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
+    int lower_bound = 0;
+    char* query;
+    if (strlen(epoch) > 0) {
+        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)
+    } else {
+        query = "SELECT id FROM registry.ports WHERE name=? AND version=? "
+        "AND revision=? AND variants=? AND epoch!=?";
+    }
+    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)
@@ -279,7 +206,7 @@
             r = sqlite3_step(stmt);
             switch (r) {
                 case SQLITE_ROW:
-                    reg_stmt_to_entry(reg, (void**)&entry, stmt, errPtr);
+                    reg_stmt_to_entry(reg, (void**)&entry, stmt, &lower_bound, errPtr);
                     break;
                 case SQLITE_DONE:
                     errPtr->code = REG_NOT_FOUND;
@@ -322,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;
@@ -409,72 +336,6 @@
 }
 
 /**
- * Convenience method for returning all objects of a given type from the
- * registry.
- *
- * @param [in] reg       registry to select objects from
- * @param [in] query     the select query to execute
- * @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 [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
- */
-static int reg_all_objects(reg_registry* reg, char* query, int query_len,
-        void*** objects, cast_function* fn, free_function* del,
-        reg_error* errPtr) {
-    void** results = malloc(10*sizeof(void*));
-    int result_count = 0;
-    int result_space = 10;
-    sqlite3_stmt* stmt = NULL;
-    if (!results || !fn) {
-        return -1;
-    }
-    if (sqlite3_prepare(reg->db, query, query_len, &stmt, NULL) == SQLITE_OK) {
-        int r;
-        reg_entry* entry;
-        do {
-            r = sqlite3_step(stmt);
-            switch (r) {
-                case SQLITE_ROW:
-                    if (fn(reg, (void**)&entry, stmt, errPtr)) {
-                        if (!reg_listcat(&results, &result_count, &result_space, entry)) {
-                            r = SQLITE_ERROR;
-                        }
-                    } else {
-                        r = SQLITE_ERROR;
-                    }
-                    break;
-                case SQLITE_DONE:
-                case SQLITE_BUSY:
-                    break;
-                default:
-                    reg_sqlite_error(reg->db, errPtr, query);
-                    break;
-            }
-        } while (r == SQLITE_ROW || r == SQLITE_BUSY);
-        sqlite3_finalize(stmt);
-        if (r == SQLITE_DONE) {
-            *objects = results;
-            return result_count;
-        } else if (del) {
-            int i;
-            for (i=0; i<result_count; i++) {
-                del(NULL, results[i]);
-            }
-        }
-    } else {
-        if (stmt) {
-            sqlite3_finalize(stmt);
-        }
-        reg_sqlite_error(reg->db, errPtr, query);
-    }
-    free(results);
-    return -1;
-}
-
-/**
  * Type-safe version of `reg_all_objects` for `reg_entry`.
  *
  * @param [in] reg       registry to select entries from
@@ -486,8 +347,9 @@
  */
 static int reg_all_entries(reg_registry* reg, char* query, int query_len,
         reg_entry*** objects, reg_error* errPtr) {
+    int lower_bound = 0;
     return reg_all_objects(reg, query, query_len, (void***)objects,
-            reg_stmt_to_entry, NULL, errPtr);
+            reg_stmt_to_entry, &lower_bound, NULL, errPtr);
 }
 
 /**
@@ -633,7 +495,8 @@
     int result = 0;
     sqlite3_stmt* stmt = NULL;
     char* query = "SELECT id FROM registry.files WHERE actual_path=? AND active";
-    if ((sqlite3_prepare(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
+    int lower_bound = 0;
+    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;
@@ -642,7 +505,7 @@
             switch (r) {
                 case SQLITE_ROW:
                     result = reg_stmt_to_entry(reg, (void**)entry, stmt,
-                            errPtr);
+                            &lower_bound, errPtr);
                     break;
                 case SQLITE_DONE:
                     *entry = NULL;
@@ -680,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;
@@ -717,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);
@@ -775,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);
@@ -823,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++) {
@@ -875,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++) {
@@ -932,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;
@@ -1000,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;
@@ -1083,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++) {
@@ -1175,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)
@@ -1276,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-post-destroot/base/src/cregistry/entry.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/entry.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/entry.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -36,12 +37,6 @@
 
 #include <sqlite3.h>
 
-typedef enum {
-    reg_strategy_exact = 1,
-    reg_strategy_glob = 2,
-    reg_strategy_regexp = 3
-} reg_strategy;
-
 typedef struct {
     sqlite_int64 id; /* rowid in database */
     reg_registry* reg; /* associated registry */

Copied: branches/gsoc11-post-destroot/base/src/cregistry/file.c (from rev 98879, trunk/base/src/cregistry/file.c)
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/file.c	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/cregistry/file.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,353 @@
+/*
+ * file.c
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "file.h"
+#include "util.h"
+#include "registry.h"
+#include "sql.h"
+
+#include <sqlite3.h>
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * Converts a `sqlite3_stmt` into a `reg_file`. The first column of the stmt's
+ * row must be the id of a file; the second column must be the path of a file;
+ * the third either `SQLITE_NULL` or the address of the entry in memory.
+ *
+ * @param [in] userdata sqlite3 database
+ * @param [out] file    file described by `stmt`
+ * @param [in] stmt     `sqlite3_stmt` with appropriate columns
+ * @param [out] errPtr  unused
+ * @return              true if success; false if failure
+ */
+static int reg_stmt_to_file(void* userdata, void** file, void* stmt,
+        void* calldata UNUSED, reg_error* errPtr UNUSED) {
+    int is_new;
+    reg_registry* reg = (reg_registry*)userdata;
+    reg_file_pk key;
+    Tcl_HashEntry* hash;
+    char* hashkey;
+
+    key.id = sqlite3_column_int64(stmt, 0);
+    key.path = strdup((const char*) sqlite3_column_text(stmt, 1));
+    if (!key.path) {
+        return 0;
+    }
+
+    hashkey = sqlite3_mprintf("%lld:%s", key.id, key.path);
+    if (!hashkey) {
+        free(key.path);
+        return 0;
+    }
+    hash = Tcl_CreateHashEntry(&reg->open_files,
+            hashkey, &is_new);
+    sqlite3_free(hashkey);
+
+    if (is_new) {
+        reg_file* f = malloc(sizeof(reg_file));
+        if (!f) {
+            free(key.path);
+            return 0;
+        }
+        f->reg = reg;
+        f->key = key;
+        f->proc = NULL;
+        *file = f;
+        Tcl_SetHashValue(hash, f);
+    } else {
+        free(key.path);
+        *file = Tcl_GetHashValue(hash);
+    }
+    return 1;
+}
+
+/**
+ * Opens an existing file in the registry.
+ *
+ * @param [in] reg      registry to open entry in
+ * @param [in] id       port id in the dabatase
+ * @param [in] path     file path in the database
+ * @param [out] errPtr  on error, a description of the error that occures
+ * @return              the file if success, NULL if failure
+ */
+reg_file* reg_file_open(reg_registry* reg, char* id, char* name,
+        reg_error* errPtr) {
+    sqlite3_stmt* stmt = NULL;
+    reg_file* file = NULL;
+    char* query = "SELECT id, path FROM registry.files WHERE id=? AND path=?";
+    int lower_bound = 0;
+
+    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)
+                == SQLITE_OK)) {
+        int r;
+        do {
+            r = sqlite3_step(stmt);
+            switch (r) {
+                case SQLITE_ROW:
+                    reg_stmt_to_file(reg, (void**)&file, stmt, &lower_bound,
+                            errPtr);
+                    break;
+                case SQLITE_DONE:
+                    errPtr->code = REG_NOT_FOUND;
+                    errPtr->description = sqlite3_mprintf("no matching file found for: "
+                            "id=%s, name=%s", id, name);
+                    errPtr->free = (reg_error_destructor*) sqlite3_free;
+                    break;
+                case SQLITE_BUSY:
+                    continue;
+                default:
+                    reg_sqlite_error(reg->db, errPtr, query);
+                    break;
+            }
+        } while (r == SQLITE_BUSY);
+    } else {
+        reg_sqlite_error(reg->db, errPtr, query);
+    }
+    if (stmt) {
+        sqlite3_finalize(stmt);
+    }
+    return file;
+}
+
+/**
+ * Type-safe version of `reg_all_objects` for `reg_file`.
+ *
+ * @param [in] reg       registry to select entries from
+ * @param [in] query     the select query to execute
+ * @param [in] query_len length of the query (or -1 for automatic)
+ * @param [out] objects  the files selected
+ * @param [out] errPtr   on error, a description of the error that occurred
+ * @return               the number of entries if success; negative if failure
+ */
+static int reg_all_files(reg_registry* reg, char* query, int query_len,
+        reg_file*** objects, reg_error* errPtr) {
+    int lower_bound = 0;
+    return reg_all_objects(reg, query, query_len, (void***)objects,
+            reg_stmt_to_file, &lower_bound, NULL, errPtr);
+}
+
+/**
+ * Searches the registry for files for which each key's value is equal to the
+ * given value. To find all files, pass a key_count of 0.
+ *
+ * Bad keys should cause sqlite3 errors but not permit SQL injection attacks.
+ * Pass it good keys anyway.
+ *
+ * @param [in] reg       registry to search in
+ * @param [in] keys      a list of keys to search by
+ * @param [in] vals      a list of values to search by, matching keys
+ * @param [in] strats    a list of strategies to use when searching
+ * @param [in] key_count the number of key/value pairs passed
+ * @param [out] files    a list of matching files
+ * @param [out] errPtr   on error, a description of the error that occurred
+ * @return               the number of entries if success; false if failure
+ */
+int reg_file_search(reg_registry* reg, char** keys, char** vals, int* strats,
+        int key_count, reg_file*** files, reg_error* errPtr) {
+    int i;
+    char* kwd = " WHERE ";
+    char* query;
+    size_t query_len, query_space;
+    int result;
+
+    /* build the query */
+    query = strdup("SELECT id, path FROM registry.files");
+    if (!query) {
+        return -1;
+    }
+    query_len = query_space = strlen(query);
+
+    for (i = 0; i < key_count; i++) {
+        char* op;
+        char* cond;
+
+        /* get the strategy */
+        if ((op = reg_strategy_op(strats[i], errPtr)) == NULL) {
+            free(query);
+            return -1;
+        }
+
+        cond = sqlite3_mprintf(op, keys[i], vals[i]);
+        if (!cond || !reg_strcat(&query, &query_len, &query_space, kwd)
+            || !reg_strcat(&query, &query_len, &query_space, cond)) {
+            free(query);
+            return -1;
+        }
+        sqlite3_free(cond);
+        kwd = " AND ";
+    }
+
+    /* do the query */
+    result = reg_all_files(reg, query, -1, files, errPtr);
+    free(query);
+    return result;
+}
+
+/**
+ * Gets a named property of a file. That property can be set using
+ * `reg_file_propset`. The property named must be one that exists in the table
+ * and must not be one with internal meaning such as `id`.
+ *
+ * @param [in] file    file to get property from
+ * @param [in] key     property to get
+ * @param [out] value  the value of the property
+ * @param [out] errPtr on error, a description of the error that occurred
+ * @return             true if success; false if failure
+ */
+int reg_file_propget(reg_file* file, char* key, char** value,
+        reg_error* errPtr) {
+    reg_registry* reg = file->reg;
+    int result = 0;
+    sqlite3_stmt* stmt = NULL;
+    char* query;
+    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_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+        int r;
+        do {
+            r = sqlite3_step(stmt);
+            switch (r) {
+                case SQLITE_ROW:
+                    text = (const char*)sqlite3_column_text(stmt, 0);
+                    if (text) {
+                        *value = strdup(text);
+                        result = 1;
+                    } else {
+                        reg_sqlite_error(reg->db, errPtr, query);
+                    }
+                    break;
+                case SQLITE_DONE:
+                    errPtr->code = REG_INVALID;
+                    errPtr->description = "an invalid file was passed";
+                    errPtr->free = NULL;
+                    break;
+                case SQLITE_BUSY:
+                    continue;
+                default:
+                    reg_sqlite_error(reg->db, errPtr, query);
+                    break;
+            }
+        } while (r == SQLITE_BUSY);
+    } else {
+        reg_sqlite_error(reg->db, errPtr, query);
+    }
+    if (stmt) {
+        sqlite3_finalize(stmt);
+    }
+    sqlite3_free(query);
+    return result;
+}
+
+/**
+ * Sets a named property of a file. That property can be later retrieved using
+ * `reg_file_propget`. The property named must be one that exists in the table
+ * and must not be one with internal meaning such as `id`.
+ *
+ * @param [in] file    file to set property for
+ * @param [in] key     property to set
+ * @param [in] value   the desired value of the property
+ * @param [out] errPtr on error, a description of the error that occurred
+ * @return             true if success; false if failure
+ */
+int reg_file_propset(reg_file* file, char* key, char* value,
+        reg_error* errPtr) {
+    reg_registry* reg = file->reg;
+    int result = 0;
+    sqlite3_stmt* stmt = NULL;
+    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_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK) {
+        int r;
+        do {
+            r = sqlite3_step(stmt);
+            switch (r) {
+                case SQLITE_DONE:
+                    result = 1;
+                    break;
+                case SQLITE_BUSY:
+                    continue;
+                default:
+                    if (sqlite3_reset(stmt) == SQLITE_CONSTRAINT) {
+                        errPtr->code = REG_CONSTRAINT;
+                        errPtr->description = "a constraint was disobeyed";
+                        errPtr->free = NULL;
+                    } else {
+                        reg_sqlite_error(reg->db, errPtr, query);
+                    }
+                    break;
+            }
+        } while (r == SQLITE_BUSY);
+    } else {
+        reg_sqlite_error(reg->db, errPtr, query);
+    }
+    if (stmt) {
+        sqlite3_finalize(stmt);
+    }
+    sqlite3_free(query);
+    return result;
+}
+
+/**
+ * Fetches a list of all open files
+ *
+ * @param [in] reg      registry to fetch files from
+ * @param [out] files   a list of open files
+ * @return              the number of open entries, -1 on error
+ */
+int reg_all_open_files(reg_registry* reg, reg_file*** files) {
+    reg_file* file;
+    int file_count = 0;
+    int file_space = 10;
+    Tcl_HashEntry* hash;
+    Tcl_HashSearch search;
+    *files = malloc(10 * sizeof(void*));
+    if (!*files) {
+        return -1;
+    }
+    for (hash = Tcl_FirstHashEntry(&reg->open_files, &search); hash != NULL;
+            hash = Tcl_NextHashEntry(&search)) {
+        file = Tcl_GetHashValue(hash);
+        if (!reg_listcat((void***)files, &file_count, &file_space, file)) {
+            free(*files);
+            return -1;
+        }
+    }
+    return file_count;
+}
+

Copied: branches/gsoc11-post-destroot/base/src/cregistry/file.h (from rev 98879, trunk/base/src/cregistry/file.h)
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/file.h	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/cregistry/file.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,66 @@
+/*
+ * file.h
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+#ifndef _CFILE_H
+#define _CFILE_H
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "registry.h"
+
+#include <sqlite3.h>
+
+typedef struct {
+    /* rowid and path form the primary key */
+    /* unfortunately, we don't have a surrogate key in this db */
+    sqlite_int64 id; /* rowid in the database */
+    char* path; /* path in the database */
+} reg_file_pk;
+
+typedef struct {
+    reg_file_pk key;
+    reg_registry* reg; /* associated registry */
+    char* proc; /* name of Tcl proc, if using Tcl */
+} reg_file;
+
+reg_file* reg_file_open(reg_registry* reg, char* id, char* path,
+        reg_error* errPtr);
+
+int reg_file_search(reg_registry* reg, char** keys, char** vals, int* strats,
+        int key_count, reg_file*** files, reg_error* errPtr);
+
+int reg_file_propget(reg_file* file, char* key, char** value,
+        reg_error* errPtr);
+int reg_file_propset(reg_file* file, char* key, char* value,
+        reg_error* errPtr);
+
+int reg_all_open_files(reg_registry* reg, reg_file*** files);
+
+#endif /* _CFILE_H */

Modified: branches/gsoc11-post-destroot/base/src/cregistry/registry.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/registry.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/registry.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,8 +1,10 @@
 /*
  * registry.c
  * $Id$
+ * 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
@@ -31,6 +33,7 @@
 #endif
 
 #include "entry.h"
+#include "file.h"
 #include "sql.h"
 
 #include <stdio.h>
@@ -109,6 +112,12 @@
         return 0;
     }
     if (sqlite3_open(NULL, &reg->db) == SQLITE_OK) {
+        /* Enable extended result codes, requires SQLite >= 3.3.8
+         * Check added for compatibility with Tiger. */
+#if SQLITE_VERSION_NUMBER >= 3003008
+        sqlite3_extended_result_codes(reg->db, 1);
+#endif
+
         if (init_db(reg->db, errPtr)) {
             reg->status = reg_none;
             *regPtr = reg;
@@ -187,10 +196,8 @@
             if (!(sb.st_mode & S_IWGRP)) {
                 can_write = 0;
             }
-        } else {
-            if (!(sb.st_mode & S_IWOTH)) {
-                can_write = 0;
-            }
+        } else if (!(sb.st_mode & S_IWOTH) && getuid() != 0) {
+            can_write = 0;
         }
     }
     if (initialized || can_write) {
@@ -198,7 +205,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 */
@@ -210,6 +217,8 @@
                         if (initialized || (create_tables(reg->db, errPtr))) {
                             Tcl_InitHashTable(&reg->open_entries,
                                     sizeof(sqlite_int64)/sizeof(int));
+                            Tcl_InitHashTable(&reg->open_files,
+                                    TCL_STRING_KEYS);
                             reg->status |= reg_attached;
                             result = 1;
                         }
@@ -220,6 +229,13 @@
                         reg_sqlite_error(reg->db, errPtr, query);
                 }
             } while (r == SQLITE_BUSY);
+
+            sqlite3_finalize(stmt);
+            stmt = NULL;
+
+            if (result) {
+                result &= update_db(reg->db, errPtr);
+            }
         } else {
             reg_sqlite_error(reg->db, errPtr, query);
         }
@@ -251,7 +267,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;
@@ -271,6 +287,15 @@
                         free(entry);
                     }
                     Tcl_DeleteHashTable(&reg->open_entries);
+                    for (curr = Tcl_FirstHashEntry(&reg->open_files, &search);
+                            curr != NULL; curr = Tcl_NextHashEntry(&search)) {
+                        reg_file* file = Tcl_GetHashValue(curr);
+
+                        free(file->proc);
+                        free(file->key.path);
+                        free(file);
+                    }
+                    Tcl_DeleteHashTable(&reg->open_files);
                     reg->status &= ~reg_attached;
                     result = 1;
                     break;
@@ -350,7 +375,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");
@@ -362,7 +387,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;
     }
@@ -377,7 +402,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 {
@@ -394,7 +419,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 {
@@ -425,7 +450,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-post-destroot/base/src/cregistry/registry.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/registry.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/registry.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,8 +1,10 @@
 /*
  * registry.h
+ * vim:tw=80:expandtab
  * $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
@@ -56,7 +58,7 @@
 void reg_throw(reg_error* errPtr, char* code, char* fmt, ...);
 
 typedef int (cast_function)(void* userdata, void** dst, void* src,
-        reg_error* errPtr);
+        void* calldata, reg_error* errPtr);
 typedef void (free_function)(void* userdata, void* item);
 
 enum {
@@ -70,6 +72,7 @@
     sqlite3* db;
     int status;
     Tcl_HashTable open_entries;
+    Tcl_HashTable open_files;
 } reg_registry;
 
 int reg_open(reg_registry** regPtr, reg_error* errPtr);

Modified: branches/gsoc11-post-destroot/base/src/cregistry/sql.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/sql.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/sql.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -34,8 +35,9 @@
 #include "sql.h"
 #include "vercomp.h"
 
+#include <sqlite3.h>
+#include <string.h>
 #include <tcl.h>
-#include <sqlite3.h>
 #include <time.h>
 
 /**
@@ -50,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;
+    }
 }
 
 /**
@@ -108,7 +129,7 @@
 
         /* metadata table */
         "CREATE TABLE registry.metadata (key UNIQUE, value)",
-        "INSERT INTO registry.metadata (key, value) VALUES ('version', 1.000)",
+        "INSERT INTO registry.metadata (key, value) VALUES ('version', 1.100)",
         "INSERT INTO registry.metadata (key, value) VALUES ('created', strftime('%s', 'now'))",
 
         /* ports table */
@@ -130,11 +151,12 @@
 
         /* file map */
         "CREATE TABLE registry.files (id INTEGER, path TEXT, actual_path TEXT, "
-            "active INT, mtime DATETIME, md5sum TEXT, editable INT, "
+            "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)",
+        "CREATE INDEX registry.file_binary ON files(binary)",
 
         /* dependency map */
         "CREATE TABLE registry.dependencies (id INTEGER, name TEXT, variants TEXT, "
@@ -148,6 +170,186 @@
 }
 
 /**
+ * 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
+ *
+ * @param [in] db      database to update
+ * @param [out] errPtr on error, a description of the error that occurred
+ * @return             true if success; false if failure
+ */
+int update_db(sqlite3* db, reg_error* errPtr) {
+    const char* version;
+    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;
+
+    do {
+        did_update = 0;
+
+        /* 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;
+        }
+
+        if ((r = sqlite3_step(stmt)) != SQLITE_DONE) {
+            break;
+        }
+
+        sqlite3_finalize(stmt);
+        stmt = NULL;
+
+        /* query current version number */
+        query = q_version;
+        if ((r = sqlite3_prepare_v2(db, query, -1, &stmt, NULL)) != SQLITE_OK) {
+            break;
+        }
+
+        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;
+        }
+
+        /* 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);
+    switch (r) {
+        case SQLITE_OK:
+        case SQLITE_DONE:
+        case SQLITE_ROW:
+            return 1;
+        default:
+            reg_sqlite_error(db, errPtr, query);
+            return 0;
+    }
+}
+
+/**
  * Initializes database connection. This function creates all the temporary
  * tables used by the registry. It also registers the user functions and
  * collations declared here, making them available.

Modified: branches/gsoc11-post-destroot/base/src/cregistry/sql.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/sql.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/sql.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -38,5 +39,6 @@
 
 int create_tables(sqlite3* db, reg_error* errPtr);
 int init_db(sqlite3* db, reg_error* errPtr);
+int update_db(sqlite3* db, reg_error* errPtr);
 
 #endif /* _SQL_H */

Copied: branches/gsoc11-post-destroot/base/src/cregistry/util.c (from rev 98879, trunk/base/src/cregistry/util.c)
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/util.c	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/cregistry/util.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,184 @@
+/*
+ * util.c
+ * vim:tw=80:expandtab
+ * $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
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include "util.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/**
+ * Concatenates `src` to string `dst`. Simple concatenation. Only guaranteed to
+ * work with strings that have been allocated with `malloc`. Amortizes cost of
+ * expanding string buffer for O(N) concatenation and such. Uses `memcpy` in
+ * favor of `strcpy` in hopes it will perform a bit better.
+ *
+ * @param [in,out] dst       a reference to a null-terminated string
+ * @param [in,out] dst_len   number of characters currently in `dst`
+ * @param [in,out] dst_space number of characters `dst` can hold
+ * @param [in] src           string to concatenate to `dst`
+ */
+int reg_strcat(char** dst, size_t* dst_len, size_t* dst_space, char* src) {
+    size_t src_len = strlen(src);
+    size_t result_len = *dst_len + src_len;
+    if (result_len > *dst_space) {
+        char* new_dst;
+        *dst_space *= 2;
+        if (*dst_space < result_len) {
+            *dst_space = result_len;
+        }
+        new_dst = realloc(*dst, *dst_space * sizeof(char) + 1);
+        if (!new_dst)
+            return 0;
+        else
+            *dst = new_dst;
+    }
+    memcpy(*dst + *dst_len, src, src_len+1);
+    *dst_len = result_len;
+    return 1;
+}
+
+/**
+ * Appends element `src` to the list `dst`. It's like `reg_strcat`, except `src`
+ * represents a single element and not a sequence of `char`s.
+ *
+ * @param [in,out] dst       a reference to a list of pointers
+ * @param [in,out] dst_len   number of elements currently in `dst`
+ * @param [in,out] dst_space number of elements `dst` can hold
+ * @param [in] src           elements to append to `dst`
+ */
+int reg_listcat(void*** dst, int* dst_len, int* dst_space, void* src) {
+    if (*dst_len == *dst_space) {
+        void** new_dst;
+        *dst_space *= 2;
+        new_dst = realloc(*dst, *dst_space * sizeof(void*));
+        if (!new_dst)
+            return 0;
+        else
+            *dst = new_dst;
+    }
+    (*dst)[*dst_len] = src;
+    (*dst_len)++;
+    return 1;
+}
+
+/**
+ * Returns an expression to use for the given strategy. This should be passed as
+ * the `fmt` argument of `sqlite3_mprintf`, with the key and value following.
+ *
+ * @param [in] strategy a strategy (one of the `reg_strategy_*` constants)
+ * @param [out] errPtr  on error, a description of the error that occurred
+ * @return              a sqlite3 expression if success; NULL if failure
+ */
+char* reg_strategy_op(reg_strategy strategy, reg_error* errPtr) {
+    switch (strategy) {
+        case reg_strategy_exact:
+            return "%q = '%q'";
+        case reg_strategy_glob:
+            return "%q GLOB '%q'";
+        case reg_strategy_regexp:
+            return "REGEXP(%q, '%q')";
+        case reg_strategy_null:
+            return "%q IS NULL";
+        default:
+            errPtr->code = REG_INVALID;
+            errPtr->description = "invalid matching strategy specified";
+            errPtr->free = NULL;
+            return NULL;
+    }
+}
+
+/**
+ * Convenience method for returning all objects of a given type from the
+ * registry.
+ *
+ * @param [in] reg       registry to select objects from
+ * @param [in] query     the select query to execute
+ * @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
+ */
+int reg_all_objects(reg_registry* reg, char* query, int query_len,
+        void*** objects, cast_function* fn, void* castcalldata,
+        free_function* del, reg_error* errPtr) {
+    void** results = malloc(10*sizeof(void*));
+    int result_count = 0;
+    int result_space = 10;
+    sqlite3_stmt* stmt = NULL;
+    if (!results || !fn) {
+        return -1;
+    }
+    if (sqlite3_prepare_v2(reg->db, query, query_len, &stmt, NULL) == SQLITE_OK) {
+        int r;
+        void* row;
+        do {
+            r = sqlite3_step(stmt);
+            switch (r) {
+                case SQLITE_ROW:
+                    if (fn(reg, &row, stmt, castcalldata, errPtr)) {
+                        if (!reg_listcat(&results, &result_count, &result_space, row)) {
+                            r = SQLITE_ERROR;
+                        }
+                    } else {
+                        r = SQLITE_ERROR;
+                    }
+                    break;
+                case SQLITE_DONE:
+                    break;
+                case SQLITE_BUSY:
+                    continue;
+                default:
+                    reg_sqlite_error(reg->db, errPtr, query);
+                    break;
+            }
+        } while (r == SQLITE_ROW || r == SQLITE_BUSY);
+        sqlite3_finalize(stmt);
+        if (r == SQLITE_DONE) {
+            *objects = results;
+            return result_count;
+        } else if (del) {
+            int i;
+            for (i=0; i<result_count; i++) {
+                del(NULL, results[i]);
+            }
+        }
+    } else {
+        if (stmt) {
+            sqlite3_finalize(stmt);
+        }
+        reg_sqlite_error(reg->db, errPtr, query);
+    }
+    free(results);
+    return -1;
+}
+

Copied: branches/gsoc11-post-destroot/base/src/cregistry/util.h (from rev 98879, trunk/base/src/cregistry/util.h)
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/util.h	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/cregistry/util.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,53 @@
+/*
+ * util.h
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+#ifndef _CUTIL_H
+#define _CUTIL_H
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "registry.h"
+
+typedef enum {
+    reg_strategy_exact = 1,
+    reg_strategy_glob = 2,
+    reg_strategy_regexp = 3,
+    reg_strategy_null = 4
+} reg_strategy;
+
+int reg_strcat(char** dst, size_t* dst_len, size_t* dst_space, char* src);
+int reg_listcat(void*** dst, int* dst_len, int* dst_space, void* src);
+int reg_all_objects(reg_registry* reg, char* query, int query_len,
+        void*** objects, cast_function* fn, void* castcalldata,
+        free_function* del, reg_error* errPtr);
+char* reg_strategy_op(reg_strategy strategy, reg_error* errPtr);
+
+#endif /* _CUTIL_H */
+

Modified: branches/gsoc11-post-destroot/base/src/cregistry/vercomp.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/cregistry/vercomp.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/cregistry/vercomp.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -47,7 +47,7 @@
  */
 
 /**
- * RPM version comparison. Shamelessly copied from Pextlib, with some changes to
+ * EVR version comparison. Shamelessly copied from Pextlib, with some changes to
  * use string lengths instead of strlen by default. That's necessary to make it
  * work with sqlite3 collations. It should be shared with Pextlib, rather than
  * just copied though.
@@ -58,7 +58,7 @@
  * @param [in] lengthA  length of second version string, or -1 to use strlen
  * @return              -1 if A < B; 0 if A = B; 1 if A > B
  */
-static int rpm_vercomp (const char *versionA, int lengthA, const char *versionB,
+static int vercmp (const char *versionA, int lengthA, const char *versionB,
         int lengthB) {
     const char *endA, *endB;
 	const char *ptrA, *ptrB;
@@ -173,7 +173,7 @@
 
 /**
  * VERSION collation for sqlite3. This function collates text according to
- * pextlib's rpm-vercomp function. This allows direct comparison and sorting of
+ * pextlib's vercmp function. This allows direct comparison and sorting of
  * version columns, such as port.version and port.revision.
  *
  * @param [in] userdata unused
@@ -185,5 +185,5 @@
  */
 int sql_version(void* userdata UNUSED, int alen, const void* a, int blen,
         const void* b) {
-    return rpm_vercomp((const char*)a, alen, (const char*)b, blen);
+    return vercmp((const char*)a, alen, (const char*)b, blen);
 }

Modified: branches/gsoc11-post-destroot/base/src/darwintracelib1.0/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/darwintracelib1.0/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/darwintracelib1.0/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -6,7 +6,8 @@
 
 include ../../Mk/macports.autoconf.mk
 
-CFLAGS+= -fPIC
+CFLAGS+= -fPIC -Wno-deprecated-declarations
+CFLAGS_PEDANTIC=
 
 all:: ${SHLIB_NAME}
 

Modified: branches/gsoc11-post-destroot/base/src/darwintracelib1.0/darwintrace.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/darwintracelib1.0/darwintrace.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/darwintracelib1.0/darwintrace.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2005 Apple Inc. All rights reserved.
  * Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
  * All rights reserved.
  *
@@ -16,7 +16,7 @@
  * 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 Computer, Inc. ("Apple") nor the names of
+ * 3.  Neither the name of Apple Inc. ("Apple") nor the names of
  *     its contributors may be used to endorse or promote products derived
  *     from this software without specific prior written permission. 
  * 
@@ -163,15 +163,15 @@
 
 #if __STDC_VERSION__>=199901L
 #if DARWINTRACE_DEBUG_OUTPUT
-#define dprintf(...) fprintf(stderr, __VA_ARGS__)
+#define debug_printf(...) fprintf(stderr, __VA_ARGS__)
 #else
-#define dprintf(...)
+#define debug_printf(...)
 #endif
 #else
 #if DARWINTRACE_DEBUG_OUTPUT
 __attribute__ ((format (printf, 1, 2)))
 static inline
-int dprintf(const char *format, ...) {
+int debug_printf(const char *format, ...) {
     int ret;
     va_list args;
     va_start(args, format);
@@ -180,7 +180,7 @@
     return ret;
 }
 #else
-#define dprintf(format, param)
+#define debug_printf(format, param)
 #endif
 #endif
 
@@ -362,11 +362,11 @@
 			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)
 			{
-				dprintf("darwintrace: connect successful. socket %d\n", sock);
+				debug_printf("darwintrace: connect successful. socket %d\n", sock);
 				__darwintrace_fd=sock;
 				ask_for_filemap();
 			} else {
-				dprintf("connect failed: %s\n", strerror(errno));
+				debug_printf("connect failed: %s\n", strerror(errno));
 				abort();
 			}
 			errno = olderrno;
@@ -469,7 +469,7 @@
     }
   }
 
-  dprintf("darwintrace: cleanup resulted in %s\n", path);
+  debug_printf("darwintrace: cleanup resulted in %s\n", path);
 }
 
 /*
@@ -663,7 +663,7 @@
 		__darwintrace_setup();
 		isInSandbox = __darwintrace_is_in_sandbox(path, newpath);
 		if (isInSandbox == 0) {
-			dprintf("darwintrace: creation/writing was forbidden at %s\n", path);
+			debug_printf("darwintrace: creation/writing was forbidden at %s\n", path);
 			errno = EACCES;
 			result = -1;
 		}
@@ -809,10 +809,10 @@
 	int result = 0;
 	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
 	if (isInSandbox == 1) {
-		dprintf("darwintrace: unlink was allowed at %s\n", path);
+		debug_printf("darwintrace: unlink was allowed at %s\n", path);
 	} else if (isInSandbox == 0) {
 		/* outside sandbox, but sandbox is defined: forbid */
-		dprintf("darwintrace: unlink was forbidden at %s\n", path);
+		debug_printf("darwintrace: unlink was forbidden at %s\n", path);
 		errno = EACCES;
 		result = -1;
 	}
@@ -831,7 +831,7 @@
 	int result = 0;
 	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
 	if (isInSandbox == 1) {
-		dprintf("darwintrace: mkdir was allowed at %s\n", path);
+		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. */
@@ -840,7 +840,7 @@
 		err = lstat(path, &theInfo);
 		if ((err == -1) && (errno == ENOENT))
 		{
-			dprintf("darwintrace: mkdir was forbidden at %s\n", path);
+			debug_printf("darwintrace: mkdir was forbidden at %s\n", path);
 			errno = EACCES;
 			result = -1;
 		} /* otherwise, mkdir will do nothing (directory exists) or fail
@@ -861,10 +861,10 @@
 	int result = 0;
 	int isInSandbox = __darwintrace_is_in_sandbox(path, 0);
 	if (isInSandbox == 1) {
-		dprintf("darwintrace: rmdir was allowed at %s\n", path);
+		debug_printf("darwintrace: rmdir was allowed at %s\n", path);
 	} else if (isInSandbox == 0) {
 		/* outside sandbox, but sandbox is defined: forbid */
-		dprintf("darwintrace: removing directory %s was forbidden\n", path);
+		debug_printf("darwintrace: removing directory %s was forbidden\n", path);
 		errno = EACCES;
 		result = -1;
 	}
@@ -883,10 +883,10 @@
 	int result = 0;
 	int isInSandbox = __darwintrace_is_in_sandbox(from, 0);
 	if (isInSandbox == 1) {
-		dprintf("darwintrace: rename was allowed at %s\n", from);
+		debug_printf("darwintrace: rename was allowed at %s\n", from);
 	} else if (isInSandbox == 0) {
 		/* outside sandbox, but sandbox is defined: forbid */
-		dprintf("darwintrace: renaming from %s was forbidden\n", from);
+		debug_printf("darwintrace: renaming from %s was forbidden\n", from);
 		errno = EACCES;
 		result = -1;
 	}
@@ -894,10 +894,10 @@
 	if (result == 0) {
 		isInSandbox = __darwintrace_is_in_sandbox(to, 0);
 		if (isInSandbox == 1) {
-			dprintf("darwintrace: rename was allowed at %s\n", to);
+			debug_printf("darwintrace: rename was allowed at %s\n", to);
 		} else if (isInSandbox == 0) {
 			/* outside sandbox, but sandbox is defined: forbid */
-			dprintf("darwintrace: renaming to %s was forbidden\n", to);
+			debug_printf("darwintrace: renaming to %s was forbidden\n", to);
 			errno = EACCES;
 			result = -1;
 		}

Modified: branches/gsoc11-post-destroot/base/src/images_to_archives.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/images_to_archives.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/images_to_archives.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -8,9 +8,15 @@
 source [file join [lindex $argv 0] macports1.0 macports_fastload.tcl]
 package require macports 1.0
 package require registry 1.0
+package require registry2 2.0
+package require Pextlib 1.0
 
-mportinit
+umask 022
 
+array set ui_options {ports_verbose yes}
+
+mportinit ui_options
+
 # always converting to tbz2 should be fine as both these programs are
 # needed elsewhere and assumed to be available
 set tarcmd [macports::findBinary tar ${macports::autoconf::tar_path}]
@@ -24,7 +30,14 @@
 
 puts "This could take a while..."
 
+# list of ports we successfully create an archive of, to be used to update
+# the registry only after we know all creation attempts were successful.
+set archived_list {}
+set installed_len [llength $ilist]
+set counter 0
+
 foreach installed $ilist {
+    incr counter
     set iname [lindex $installed 0]
     set iversion [lindex $installed 1]
     set irevision [lindex $installed 2]
@@ -74,31 +87,26 @@
 
         # compute new name and location of archive
         set archivename "${iname}-${iversion}_${irevision}${ivariants}.${macports::os_platform}_${macports::os_major}.[join $archs -].${archivetype}"
+        ui_msg "Processing ${counter} of ${installed_len}: ${archivename}"
         if {$installtype == "image"} {
             set targetdir [file dirname $location]
         } else {
             set targetdir [file join ${macports::registry.path} software ${iname}]
-            file mkdir $targetdir
-            if {${macports::registry.format} == "receipt_sqlite"} {
-                set contents [$iref imagefiles]
-            } else {
-                set contents {}
-                set rawcontents [registry::property_retrieve $iref contents]
-                foreach entry $rawcontents {
-                    lappend contents [lindex $entry 0]
-                }
-            }
         }
+        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 {
@@ -109,51 +117,43 @@
             file delete -force ${targetdir}/tarlist ${targetdir}/error.log
         }
 
+        lappend archived_list [list $installtype $iref $location $newlocation]
+    }
+}
+
+set archived_len [llength $archived_list]
+set counter 0
+
+registry::write {
+    foreach archived $archived_list {
+        incr counter
+        ui_msg "Updating registry: ${counter} of ${archived_len}"
+        set installtype [lindex $archived 0]
+        set iref [lindex $archived 1]
+        set newlocation [lindex $archived 3]
+    
         if {$installtype == "direct"} {
             # change receipt to image
-            if {${macports::registry.format} == "receipt_sqlite"} {
-                $iref installtype image
-                $iref state imaged
-                $iref activate [$iref imagefiles]
-                $iref state installed
-            } else {
-                registry::property_store $iref installtype image
-                foreach entry $contents {
-                    registry::register_file $entry $iname
-                }
-                registry::property_store $iref active 1
-            }
+            $iref installtype image
+            $iref state imaged
+            $iref activate [$iref imagefiles]
+            $iref state installed
         }
+    
+        # set the new location in the registry and delete the old dir
+        $iref location $newlocation
+    }
+}
 
-        if {${macports::registry.format} == "flat" && $installtype == "image"} {
-            # flat receipts also need file paths in contents trimmed to exclude image dir
-            set loclen [string length $location]
-            set locend [expr $loclen - 1]
-            set oldcontents [registry::property_retrieve $iref contents]
-            set newcontents {}
-            foreach fe $contents {
-                set oldfilepath [lindex $fe 0]
-                if {[string range $oldfilepath 0 $locend] == $location} {
-                    set newfilepath [string range $oldfilepath $loclen end]
-                    set newentry [list $newfilepath]
-                    foreach other [lrange $fe 1 end] {
-                        lappend newentry $other
-                    }
-                    lappend newcontents $newentry
-                } else {
-                    lappend newcontents $fe
-                }
-            }
-            registry::property_store $iref contents $newcontents
+set counter 0
+foreach archived $archived_list {
+    incr counter
+    set location [lindex $archived 2]
+    ui_msg "Deleting ${counter} of ${archived_len}: ${location}"
+    if {$location != "" && [file isdirectory $location]} {
+        if {[catch {file delete -force $location} result]} {
+            ui_warn "Failed to delete ${location}: $result"
         }
-        # set the new location in the registry and delete the old dir
-        registry::property_store $iref location $newlocation
-        if {${macports::registry.format} == "flat"} {
-            registry::write_entry $iref
-        }
-        if {$location != "" && [file isdirectory $location]} {
-            file delete -force $location
-        }
     }
 }
 


Property changes on: branches/gsoc11-post-destroot/base/src/machista1.0
___________________________________________________________________
Added: svn:ignore
   + machista.dylib
pkgIndex.tcl
Makefile


Modified: branches/gsoc11-post-destroot/base/src/macports1.0/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -32,11 +32,16 @@
 	$(INSTALL) -o ${DSTUSR} -g ${DSTGRP} -m 444 pkgIndex.tcl ${INSTALLDIR}
 
 	echo "${TCL_PACKAGE_DIR}" > ${DESTDIR}${prefix}/var/macports/.tclpackage
-	if test -z "${DESTDIR}" && test "${INSTALLPKGLINK}" != "${INSTALLDIR}" && test -w "${TCL_PACKAGE_DIR}"; then \
-		if ! test -L "${INSTALLPKGLINK}" && test -d "${INSTALLPKGLINK}"; then \
-			rm -rf "${INSTALLPKGLINK}" || true; \
-		fi; \
-		if ! test -e "${INSTALLPKGLINK}"; then \
-			ln -s "${INSTALLDIR}" "${INSTALLPKGLINK}" || true; \
-		fi; \
+	if test -z "${DESTDIR}" -a "${INSTALLPKGLINK}" != "${INSTALLDIR}"; then \
+		if test ! -L "${INSTALLPKGLINK}"; then \
+            if test ! -e "${TCL_PACKAGE_DIR}"; then \
+                $(INSTALL) -d -o ${DSTUSR} -g ${DSTGRP} -m ${DSTMODE} "${TCL_PACKAGE_DIR}" || true; \
+            fi; \
+            if test -d "${INSTALLPKGLINK}"; then \
+                rm -vrf "${INSTALLPKGLINK}" || true; \
+            fi; \
+            if test ! -e "${INSTALLPKGLINK}"; then \
+                ln -vs "${INSTALLDIR}" "${INSTALLPKGLINK}" || true; \
+            fi; \
+        fi; \
 	fi

Modified: branches/gsoc11-post-destroot/base/src/macports1.0/macports.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/macports.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/macports.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,10 +2,11 @@
 # macports.tcl
 # $Id$
 #
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 - 2003 Apple Inc.
 # 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 - 2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -16,7 +17,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -43,32 +44,38 @@
         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 \
+        rsync_dir startupitem_type startupitem_install place_worksymlink xcodeversion xcodebuildcmd \
         mp_remote_url mp_remote_submit_url 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"
+        master_site_local patch_site_local archive_site_local buildfromsource \
+        revupgrade_autorun revupgrade_mode revupgrade_check_id_loadcmds \
+        host_blacklist preferred_hosts\
+        packagemaker_path default_compiler"
     variable user_options "submitter_name submitter_email submitter_key"
     variable portinterp_options "\
         portdbpath porturl portpath portbuildpath auto_path prefix prefix_frozen portsharepath \
         files_whitelist folders_whitelist \
-        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 \
+        rsync_server rsync_options rsync_dir startupitem_type startupitem_install place_worksymlink macportsuser \
         mp_remote_url mp_remote_submit_url 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_compiler $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"
+    variable portinterp_deferred_options "xcodeversion xcodebuildcmd developer_dir"
 
     variable open_mports {}
 
     variable ui_priorities "error warn msg notice info debug any"
     variable port_phases "any fetch checksum"
     variable current_phase "main"
+
+    variable ui_prefix "---> "
 }
 
 # Provided UI instantiations
@@ -130,7 +137,7 @@
 proc macports::ch_logging {mport} {
     global ::debuglog ::debuglogname
 
-    set portname [_mportkey $mport name]
+    set portname [_mportkey $mport subport]
     set portpath [_mportkey $mport portpath]
 
     ui_debug "Starting logging for $portname"
@@ -362,7 +369,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"
@@ -370,7 +377,13 @@
                 if {[regexp {Xcode ([0-9.]+)} $xcodebuildversion - xcode_v] == 1} {
                     set macports::xcodeversion $xcode_v
                 } elseif {[regexp "DevToolsCore-(.*);" $xcodebuildversion - devtoolscore_v] == 1} {
-                    if {$devtoolscore_v >= 921.0} {
+                    if {$devtoolscore_v >= 1809.0} {
+                        set macports::xcodeversion "3.2.6"
+                    } elseif {$devtoolscore_v >= 1204.0} {
+                        set macports::xcodeversion "3.1.4"
+                    } elseif {$devtoolscore_v >= 1100.0} {
+                        set macports::xcodeversion "3.1"
+                    } elseif {$devtoolscore_v >= 921.0} {
                         set macports::xcodeversion "3.0"
                     } elseif {$devtoolscore_v >= 798.0} {
                         set macports::xcodeversion "2.5"
@@ -408,6 +421,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 {}
@@ -474,18 +584,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"
-    }
-
     # set up platform info variables
     set os_arch $tcl_platform(machine)
     if {$os_arch == "Power Macintosh"} { set os_arch "powerpc" }
@@ -501,6 +606,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"
@@ -519,7 +641,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
                     }
@@ -552,7 +674,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
                 }
@@ -657,6 +779,7 @@
         }
     }
 
+    set env(HOME) [file join $portdbpath home]
     set registry.path $portdbpath
 
     # Format for receipts; currently only "sqlite" is allowed
@@ -672,8 +795,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
     }
@@ -695,11 +818,29 @@
             set macports::porttrace $macports::global_options(ports_trace)
         }
     }
+    # Check command line override for source/binary only mode
+    if {![info exists macports::global_options(ports_binary_only)]
+        && ![info exists macports::global_options(ports_source_only)]
+        && [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"
+        }
+    }
 
     # Duplicate prefix into prefix_frozen, so that port actions
     # 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"
@@ -726,7 +867,7 @@
         global macports::rsync_server
     }
     if {![info exists rsync_dir]} {
-        set macports::rsync_dir release/base/
+        set macports::rsync_dir release/tarballs/base.tar
         global macports::rsync_dir
     }
     if {![info exists rsync_options]} {
@@ -754,6 +895,11 @@
         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
@@ -835,14 +981,29 @@
         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
+
     # ENV cleanup.
     set keepenvkeys {
         DISPLAY DYLD_FALLBACK_FRAMEWORK_PATH
         DYLD_FALLBACK_LIBRARY_PATH DYLD_FRAMEWORK_PATH
         DYLD_LIBRARY_PATH DYLD_INSERT_LIBRARIES
         HOME JAVA_HOME MASTER_SITE_LOCAL ARCHIVE_SITE_LOCAL
-        PATCH_SITE_LOCAL PATH PORTSRC RSYNC_PROXY TMP TMPDIR
-        USER GROUP
+        PATCH_SITE_LOCAL PATH PORTSRC RSYNC_PROXY
+        USER GROUP LANG
         http_proxy HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY
         COLUMNS LINES
     }
@@ -850,6 +1011,30 @@
         set keepenvkeys [concat ${keepenvkeys} ${extra_env}]
     }
 
+    if {[file isdirectory $libpath]} {
+        lappend auto_path $libpath
+        set macports::auto_path $auto_path
+
+        # XXX: not sure if this the best place, but it needs to happen
+        # early, and after auto_path has been set.  Or maybe Pextlib
+        # should ship with macports1.0 API?
+        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"
+    }
+
+    # don't keep unusable TMPDIR/TMP values
+    foreach var {TMP TMPDIR} {
+        if {[info exists env($var)] && [file writable $env($var)] && 
+            ([getuid] != 0 || $macportsuser == "root" ||
+             [file attributes $env($var) -owner] == $macportsuser)} {
+            lappend keepenvkeys $var
+        }
+    }
+
     set env_names [array names env]
     foreach envkey $env_names {
         if {[lsearch -exact $keepenvkeys $envkey] == -1} {
@@ -857,12 +1042,40 @@
         }
     }
 
+    # unset environment an extra time, to work around bugs in Leopard Tcl
+    if {$macosx_version == "10.5"} {
+        foreach envkey $env_names {
+            if {[lsearch -exact $keepenvkeys $envkey] == -1} {
+                unsetenv $envkey
+            }
+        }
+    }
+
     if {![info exists xcodeversion] || ![info exists xcodebuildcmd]} {
         # We'll resolve these later (if needed)
         trace add variable macports::xcodeversion read macports::setxcodeinfo
         trace add variable macports::xcodebuildcmd read macports::setxcodeinfo
     }
 
+    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
@@ -878,29 +1091,6 @@
         set env(ARCHIVE_SITE_LOCAL) "$archive_site_local"
     }
 
-    if {[file isdirectory $libpath]} {
-        lappend auto_path $libpath
-        set macports::auto_path $auto_path
-
-        # XXX: not sure if this the best place, but it needs to happen
-        # early, and after auto_path has been set.  Or maybe Pextlib
-        # should ship with macports1.0 API?
-        package require Pextlib 1.0
-        package require registry 1.0
-        package require registry2 2.0
-    } else {
-        return -code error "Library directory '$libpath' must exist"
-    }
-
-    # unset environment an extra time, to work around bugs in Leopard Tcl
-    if {$macosx_version == "10.5"} {
-        foreach envkey $env_names {
-            if {[lsearch -exact $keepenvkeys $envkey] == -1} {
-                unsetenv $envkey
-            }
-        }
-    }
-
     # Proxy handling (done this late since Pextlib is needed)
     if {![info exists proxy_override_env] } {
         set proxy_override_env "no"
@@ -945,48 +1135,101 @@
     # 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
 
-    set default_source_url [lindex ${sources_default} 0]
-    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"
+    if {![info exists macports::ui_options(ports_no_old_index_warning)]} {
+        set default_source_url [lindex ${sources_default} 0]
+        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 updating them by running 'port selfupdate'."
+            }
         }
     }
-    
-    # init registry if needed
-    if {${registry.format} == "receipt_sqlite"} {
-        set db_path [file join ${registry.path} registry registry.db]
-        set db_exists [file exists $db_path]
-        registry::open $db_path
-        # for the benefit of the portimage code that is called from multiple interpreters
-        global registry_open
-        set registry_open yes
-        # convert any flat receipts if we just created a new db
-        if {$db_exists == 0 && [file writable $db_path]} {
-            ui_warn "Converting your registry to sqlite format, this might take a while..."
-            if {[catch {registry::convert_to_sqlite}]} {
-                ui_debug "$::errorInfo"
-                file delete -force $db_path
-                error "Failed to convert your registry to sqlite!"
-            } else {
-                ui_warn "Successfully converted your registry to sqlite!"
-            }
+
+    # init registry
+    set db_path [file join ${registry.path} registry registry.db]
+    set db_exists [file exists $db_path]
+    registry::open $db_path
+    # for the benefit of the portimage code that is called from multiple interpreters
+    global registry_open
+    set registry_open yes
+    # convert any flat receipts if we just created a new db
+    if {$db_exists == 0 && [file exists ${registry.path}/receipts] && [file writable $db_path]} {
+        ui_warn "Converting your registry to sqlite format, this might take a while..."
+        if {[catch {registry::convert_to_sqlite}]} {
+            ui_debug "$::errorInfo"
+            file delete -force $db_path
+            error "Failed to convert your registry to sqlite!"
+        } else {
+            ui_warn "Successfully converted your registry to sqlite!"
         }
     }
 }
 
 # call this just before you exit
 proc mportshutdown {} {
-    global macports::registry.format
-    if {${registry.format} == "receipt_sqlite"} {
-        # close it down so the cleanup stuff is called, e.g. vacuuming the db
-        registry::close
+    # 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
 
@@ -1057,6 +1300,7 @@
     $workername alias registry_exists_for_name registry::entry_exists_for_name
     $workername alias registry_activate portimage::activate
     $workername alias registry_deactivate portimage::deactivate
+    $workername alias registry_deactivate_composite portimage::deactivate_composite
     $workername alias registry_uninstall registry_uninstall::uninstall
     $workername alias registry_register_deps registry::register_dependencies
     $workername alias registry_fileinfo_for_index registry::fileinfo_for_index
@@ -1069,6 +1313,13 @@
     # 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
@@ -1140,25 +1391,82 @@
     return $result
 }
 
-proc macports::fetch_port {url} {
+proc macports::get_tar_flags {suffix} {
+    switch -- $suffix {
+        .tbz -
+        .tbz2 {
+            return "-j"
+        }
+        .tgz {
+            return "-z"
+        }
+        .txz {
+            return "--use-compress-program [findBinary xz {}] -"
+        }
+        .tlz {
+            return "--use-compress-program [findBinary lzma {}] -"
+        }
+        default {
+            return "-"
+        }
+    }
+}
+
+proc macports::fetch_port {url {local 0}} {
     global macports::portdbpath
     set fetchdir [file join $portdbpath portdirs]
-    set fetchfile [file tail $url]
     file mkdir $fetchdir
     if {![file writable $fetchdir]} {
         return -code error "Port remote fetch failed: You do not have permission to write to $fetchdir"
     }
-    if {[catch {curl fetch $url [file join $fetchdir $fetchfile]} result]} {
-        return -code error "Port remote fetch failed: $result"
+    if {$local} {
+        set fetchfile $url
+    } else {
+        set fetchfile [file tail $url]
+        if {[catch {curl fetch $url [file join $fetchdir $fetchfile]} result]} {
+            return -code error "Port remote fetch failed: $result"
+        }
     }
+    set oldpwd [pwd]
     cd $fetchdir
-    if {[catch {exec [findBinary tar $macports::autoconf::tar_path] -zxf $fetchfile} result]} {
+    # check if this is a binary archive or just the port dir
+    set tarcmd [findBinary tar $macports::autoconf::tar_path]
+    set tarflags [get_tar_flags [file extension $fetchfile]]
+    set qflag ${macports::autoconf::tar_q}
+    set cmdline "$tarcmd ${tarflags}${qflag}xOf \"$fetchfile\" +CONTENTS"
+    ui_debug "$cmdline"
+    if {![catch {set contents [eval exec $cmdline]}]} {
+        set binary 1
+        ui_debug "getting port name from binary archive"
+        # get the portname from the contents file
+        foreach line [split $contents "\n"] {
+            if {[lindex $line 0] == "@name"} {
+                # actually ${name}-${version}_${revision}
+                set portname [lindex $line 1]
+            }
+        }
+        ui_debug "port name is '$portname'"
+        file mkdir $portname
+        cd $portname
+    } else {
+        set binary 0
+        set portname [file rootname $fetchfile]
+    }
+
+    # extract the portfile (and possibly files dir if not a binary archive)
+    ui_debug "extracting port archive to [pwd]"
+    if {$binary} {
+        set cmdline "$tarcmd ${tarflags}${qflag}xOf \"$fetchfile\" +PORTFILE > Portfile"
+    } else {
+        set cmdline "$tarcmd ${tarflags}xf \"$fetchfile\""
+    }
+    ui_debug "$cmdline"
+    if {[catch {eval exec $cmdline} result]} {
         return -code error "Port extract failed: $result"
     }
-    if {[regexp {(.+).tgz} $fetchfile match portdir] != 1} {
-        return -code error "Can't decipher portdir from $fetchfile"
-    }
-    return [file join $fetchdir $portdir]
+
+    cd $oldpwd
+    return [file join $fetchdir $portname]
 }
 
 proc macports::getprotocol {url} {
@@ -1174,10 +1482,20 @@
 # fetched port will be downloaded to (currently only applies to
 # mports:// sources).
 proc macports::getportdir {url {destdir "."}} {
+    global macports::extracted_portdirs
     set protocol [macports::getprotocol $url]
     switch ${protocol} {
         file {
-            return [file normalize [string range $url [expr [string length $protocol] + 3] end]]
+            set path [file normalize [string range $url [expr [string length $protocol] + 3] end]]
+            if {![file isfile $path]} {
+                return $path
+            } else {
+                # need to create a local dir for the exracted port, but only once
+                if {![info exists macports::extracted_portdirs($url)]} {
+                    set macports::extracted_portdirs($url) [macports::fetch_port $path 1]
+                }
+                return $macports::extracted_portdirs($url)
+            }
         }
         mports {
             return [macports::index::fetch_port $url $destdir]
@@ -1185,7 +1503,10 @@
         https -
         http -
         ftp {
-            return [macports::fetch_port $url]
+            if {![info exists macports::extracted_portdirs($url)]} {
+                set macports::extracted_portdirs($url) [macports::fetch_port $url 0]
+            }
+            return $macports::extracted_portdirs($url)
         }
         default {
             return -code error "Unsupported protocol $protocol"
@@ -1313,7 +1634,7 @@
         error "Error evaluating variants"
     }
 
-    ditem_key $mport provides [$workername eval return \$name]
+    ditem_key $mport provides [$workername eval return \$subport]
 
     return $mport
 }
@@ -1321,10 +1642,7 @@
 # mportopen_installed
 # opens a portfile stored in the registry
 proc mportopen_installed {name version revision variants options} {
-    global macports::registry.format macports::registry.path
-    if {${registry.format} != "receipt_sqlite"} {
-        return -code error "mportopen_installed requires sqlite registry"
-    }
+    global macports::registry.path
     set regref [lindex [registry::entry imaged $name $version $revision $variants] 0]
     set portfile_dir [file join ${registry.path} registry portfiles $name "${version}_${revision}${variants}"]
     file mkdir $portfile_dir
@@ -1350,11 +1668,11 @@
 # close mport opened with mportopen_installed and clean up associated files
 proc mportclose_installed {mport} {
     global macports::registry.path
-    foreach key {name version revision portvariants} {
+    foreach key {subport version revision portvariants} {
         set $key [_mportkey $mport $key]
     }
     mportclose $mport
-    set portfiles_dir [file join ${registry.path} registry portfiles $name]
+    set portfiles_dir [file join ${registry.path} registry portfiles $subport]
     set portfile [file join $portfiles_dir "${version}_${revision}${portvariants}" Portfile]
     file delete -force $portfile [file dirname $portfile]
     if {[llength [glob -nocomplain -directory $portfiles_dir *]] == 0} {
@@ -1449,13 +1767,13 @@
 proc _mportinstalled {mport} {
     # Check for the presence of the port in the registry
     set workername [ditem_key $mport workername]
-    return [$workername eval registry_exists_for_name \${name}]
+    return [$workername eval registry_exists_for_name \${subport}]
 }
 
 # Determine if a port is active
 proc _mportactive {mport} {
     set workername [ditem_key $mport workername]
-    if {![catch {set reslist [$workername eval registry_active \${name}]}] && [llength $reslist] > 0} {
+    if {![catch {set reslist [$workername eval registry_active \${subport}]}] && [llength $reslist] > 0} {
         set i [lindex $reslist 0]
         set name [lindex $i 0]
         set version [lindex $i 1]
@@ -1510,37 +1828,49 @@
     }
 }
 
-### _mportconflictsinstalled is private; may change without notice
+### _mporterrorifconflictsinstalled is private; may change without notice
 
-# Determine if the port, per the conflicts option, has any conflicts with
-# what is installed.
+# Determine if the port, per the conflicts option, has any conflicts
+# with what is installed. If it does, raises an error unless force
+# option is set.
 #
 # mport   the port to check for conflicts
-# Returns a list of which installed ports conflict, or an empty list if none
-proc _mportconflictsinstalled {mport conflictinfo} {
+proc _mporterrorifconflictsinstalled {mport} {
     set conflictlist {}
-    if {[llength $conflictinfo] > 0} {
-        ui_debug "Checking for conflicts against [_mportkey $mport name]"
-        foreach conflictport ${conflictinfo} {
+    array set portinfo [mportinfo $mport]
+
+    if {[info exists portinfo(conflicts)] &&
+        [llength $portinfo(conflicts)] > 0} {
+        ui_debug "Checking for conflicts against [_mportkey $mport subport]"
+        foreach conflictport $portinfo(conflicts) {
             if {[_mportispresent $mport port:${conflictport}]} {
                 lappend conflictlist $conflictport
             }
         }
     } else {
-        ui_debug "[_mportkey $mport name] has no conflicts"
+        ui_debug "[_mportkey $mport subport] has no conflicts"
     }
 
-    return $conflictlist
+    if {[llength ${conflictlist}] != 0} {
+        if {[macports::global_option_isset ports_force]} {
+            ui_warn "Force option set; installing $portinfo(name) despite conflicts with: ${conflictlist}"
+        } else {
+            if {![macports::ui_isset ports_debug]} {
+                ui_msg ""
+            }
+            return -code error "Can't install $portinfo(name) because conflicting ports are installed: ${conflictlist}"
+        }
+    }
 }
 
-
 ### _mportexec is private; may change without notice
 
 proc _mportexec {target mport} {
-    set portname [_mportkey $mport name]
+    set portname [_mportkey $mport subport]
     macports::push_log $mport
     # xxx: set the work path?
     set workername [ditem_key $mport workername]
+    $workername eval validate_macportsuser
     if {![catch {$workername eval check_variants $target} result] && $result == 0 &&
         ![catch {$workername eval check_supported_archs} result] && $result == 0 &&
         ![catch {$workername eval eval_targets $target} result] && $result == 0} {
@@ -1563,8 +1893,9 @@
         # An error occurred.
         global ::logenabled ::debuglogname
         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
@@ -1576,30 +1907,38 @@
 proc mportexec {mport target} {
     set workername [ditem_key $mport workername]
 
+    # check for existence of macportsuser and use fallback if necessary
+    $workername eval validate_macportsuser
     # check variants
     if {[$workername eval check_variants $target] != 0} {
         return 1
     }
-    set portname [_mportkey $mport name]
+    set portname [_mportkey $mport subport]
     if {$target != "clean"} {
         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]]} {
         registry::exclusive_lock
         # see if we actually need to build this port
         if {($target != "activate" && $target != "install") ||
-            ![$workername eval registry_exists \$name \$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
-            }
+            ![$workername eval registry_exists \$subport \$version \$revision \$portvariants]} {
     
             # upgrade dependencies that are already installed
             if {![macports::global_option_isset ports_nodeps]} {
@@ -1607,7 +1946,7 @@
             }
         }
 
-        ui_msg -nonewline "--->  Computing dependencies for [_mportkey $mport name]"
+        ui_msg -nonewline "$macports::ui_prefix Computing dependencies for [_mportkey $mport subport]"
         if {[macports::ui_isset ports_debug]} {
             # play nice with debug messages
             ui_msg ""
@@ -1627,7 +1966,7 @@
         
         # print the dep list
         if {[llength $dlist] > 0} {
-            set depstring "--->  Dependencies to be installed:"
+            set depstring "$macports::ui_prefix Dependencies to be installed:"
             foreach ditem $dlist {
                 append depstring " [ditem_key $ditem provides]"
             }
@@ -1655,6 +1994,11 @@
         foreach ditem $dlist {
             mportclose $ditem
         }
+    } else {
+        # No dependencies, but we still need to check for conflicts.
+        if {$target == "" || $target == "install" || $target == "activate"} {
+            _mporterrorifconflictsinstalled $mport
+        }
     }
 
     set clean 0
@@ -1677,7 +2021,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
     }
@@ -1700,7 +2044,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]
@@ -1722,7 +2066,12 @@
                         set res [mportlookup $dep_portname]
                         array unset dep_portinfo
                         array set dep_portinfo [lindex $res 1]
-                        if {[info exists dep_portinfo(variants)] && [lsearch $dep_portinfo(variants) universal] != -1} {
+                        if {[info exists dep_portinfo(installs_libs)] && !$dep_portinfo(installs_libs)} {
+                            set missing {}
+                        }
+                    }
+                    if {[llength $missing] > 0} {
+                        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
@@ -1733,7 +2082,7 @@
                                     }
                                 }
                                 if {[llength $missing] > 0} {
-                                    ui_error "Cannot install [_mportkey $mport name] for the arch(s) '$required_archs' because"
+                                    ui_error "Cannot install [_mportkey $mport subport] for the arch(s) '$required_archs' because"
                                     ui_error "its dependency $dep_portname is only installed for the arch '$active_archs'"
                                     ui_error "and the configured universal_archs '$macports::universal_archs' are not sufficient."
                                     return -code error "architecture mismatch"
@@ -1745,12 +2094,12 @@
                                 }
                             } else {
                                 # already universal
-                                ui_error "Cannot install [_mportkey $mport name] for the arch(s) '$required_archs' because"
+                                ui_error "Cannot install [_mportkey $mport subport] for the arch(s) '$required_archs' because"
                                 ui_error "its dependency $dep_portname is only installed for the archs '$active_archs'."
                                 return -code error "architecture mismatch"
                             }
                         } else {
-                            ui_error "Cannot install [_mportkey $mport name] for the arch(s) '$required_archs' because"
+                            ui_error "Cannot install [_mportkey $mport subport] for the arch(s) '$required_archs' because"
                             ui_error "its dependency $dep_portname is only installed for the arch '$active_archs'"
                             ui_error "and does not have a universal variant."
                             return -code error "architecture mismatch"
@@ -1803,7 +2152,7 @@
     upvar $filename myfilename
     upvar $extension myextension
 
-    if {[regexp {^(?:https?|ftp)://.+/(.+\.(tar\.gz|tar\.bz2))$} $url -> f e]} {
+    if {[regexp {^(?:https?|ftp|rsync)://.+/(.+\.(tar\.gz|tar\.bz2|tar))$} $url -> f e]} {
         set myfilename $f
         set myextension $e
 
@@ -1847,12 +2196,15 @@
 proc mportsync {{optionslist {}}} {
     global macports::sources macports::portdbpath macports::rsync_options tcl_platform
     global macports::portverbose
-    global macports::autoconf::rsync_path
+    global macports::autoconf::rsync_path macports::autoconf::tar_path macports::autoconf::openssl_path
     array set options $optionslist
+    if {[info exists options(no_reindex)]} {
+        upvar $options(needed_portindex_var) any_needed_portindex
+    }
 
     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]
@@ -1865,8 +2217,12 @@
         switch -regexp -- [macports::getprotocol $source] {
             {^file$} {
                 set portdir [macports::getportdir $source]
-                if {[file exists $portdir/.svn]} {
-                    set svn_commandline "[macports::findBinary svn] update --non-interactive ${portdir}"
+                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
                     if {
                         [catch {
@@ -1889,6 +2245,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
             }
@@ -1899,13 +2279,21 @@
                 # Where to, boss?
                 set indexfile [macports::getindex $source]
                 set destdir [file dirname $indexfile]
+                set is_tarball [_source_is_snapshot $source]
                 file mkdir $destdir
-                # Keep rsync happy with a trailing slash
-                if {[string index $source end] != "/"} {
-                    append source "/"
+
+                if {$is_tarball} {
+                    set exclude_option ""
+                    # need to do a few things before replacing the ports tree in this case
+                    set destdir [file dirname $destdir]
+                } else {
+                    # Keep rsync happy with a trailing slash
+                    if {[string index $source end] != "/"} {
+                        append source "/"
+                    }
+                    # don't sync PortIndex yet; we grab the platform specific one afterwards
+                    set exclude_option "'--exclude=/PortIndex*'"
                 }
-                # don't sync PortIndex yet; we grab the platform specific one afterwards
-                set exclude_option "'--exclude=/PortIndex*'"
                 # Do rsync fetch
                 set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source} ${destdir}"
                 ui_debug $rsync_commandline
@@ -1914,21 +2302,110 @@
                     incr numfailed
                     continue
                 }
+
+                if {$is_tarball} {
+                    # verify signature for tarball
+                    global macports::archivefetch_pubkeys
+                    set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${exclude_option} ${source}.rmd160 ${destdir}"
+                    ui_debug $rsync_commandline
+                    if {[catch {system $rsync_commandline}]} {
+                        ui_error "Synchronization of the ports tree signature failed doing rsync"
+                        incr numfailed
+                        continue
+                    }
+                    set tarball "${destdir}/[file tail $source]"
+                    set signature "${tarball}.rmd160"
+                    set openssl [macports::findBinary openssl $macports::autoconf::openssl_path]
+                    set verified 0
+                    foreach pubkey ${macports::archivefetch_pubkeys} {
+                        if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
+                            set verified 1
+                            ui_debug "successful verification with key $pubkey"
+                            break
+                        } else {
+                            ui_debug "failed verification with key $pubkey"
+                            ui_debug "openssl output: $result"
+                        }
+                    }
+                    if {!$verified} {
+                        ui_error "Failed to verify signature for ports tree!"
+                        incr numfailed
+                        continue
+                    }
+
+                    # extract tarball and move into place
+                    set tar [macports::findBinary tar $macports::autoconf::tar_path]
+                    file mkdir ${destdir}/tmp
+                    set tar_cmd "$tar -C ${destdir}/tmp -xf ${tarball}"
+                    ui_debug $tar_cmd
+                    if {[catch {system $tar_cmd}]} {
+                        ui_error "Failed to extract ports tree from tarball!"
+                        incr numfailed
+                        continue
+                    }
+                    # save the local PortIndex data
+                    if {[file isfile $indexfile]} {
+                        file copy -force $indexfile ${destdir}/
+                        file rename -force $indexfile ${destdir}/tmp/ports/
+                        if {[file isfile ${indexfile}.quick]} {
+                            file rename -force ${indexfile}.quick ${destdir}/tmp/ports/
+                        }
+                    }
+                    file delete -force ${destdir}/ports
+                    file rename ${destdir}/tmp/ports ${destdir}/ports
+                    file delete -force ${destdir}/tmp
+                }
+
+                set needs_portindex 1
                 # now sync the index if the local file is missing or older than a day
-                if {![file isfile $indexfile] || [expr [clock seconds] - [file mtime $indexfile]] > 86400} {
-                    set remote_indexfile "${source}PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
+                if {![file isfile $indexfile] || [expr [clock seconds] - [file mtime $indexfile]] > 86400
+                      || [info exists options(no_reindex)]} {
+                    if {$is_tarball} {
+                        # chop ports.tar off the end
+                        set index_source [string range $source 0 end-[string length [file tail $source]]]
+                    } else {
+                        set index_source $source 
+                    }
+                    set remote_indexfile "${index_source}PortIndex_${macports::os_platform}_${macports::os_major}_${macports::os_arch}/PortIndex"
                     set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} $remote_indexfile ${destdir}"
                     ui_debug $rsync_commandline
                     if {[catch {system $rsync_commandline}]} {
                         ui_debug "Synchronization of the PortIndex failed doing rsync"
                     } else {
-                        mports_generate_quickindex $indexfile
+                        set ok 1
+                        set needs_portindex 0
+                        if {$is_tarball} {
+                            set ok 0
+                            set needs_portindex 1
+                            # verify signature for PortIndex
+                            set rsync_commandline "${macports::autoconf::rsync_path} ${rsync_options} ${remote_indexfile}.rmd160 ${destdir}"
+                            ui_debug $rsync_commandline
+                            if {![catch {system $rsync_commandline}]} {
+                                foreach pubkey ${macports::archivefetch_pubkeys} {
+                                    if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature ${destdir}/PortIndex.rmd160 ${destdir}/PortIndex} result]} {
+                                        set ok 1
+                                        set needs_portindex 0
+                                        ui_debug "successful verification with key $pubkey"
+                                        break
+                                    } else {
+                                        ui_debug "failed verification with key $pubkey"
+                                        ui_debug "openssl output: $result"
+                                    }
+                                }
+                                if {$ok} {
+                                    # move PortIndex into place
+                                    file rename -force ${destdir}/PortIndex ${destdir}/ports/
+                                }
+                            }
+                        }
+                        if {$ok} {
+                            mports_generate_quickindex $indexfile
+                        }
                     }
                 }
                 if {[catch {system "chmod -R a+r \"$destdir\""}]} {
                     ui_warn "Setting world read permissions on parts of the ports tree failed, need root?"
                 }
-                set needs_portindex 1
             }
             {^https?$|^ftp$} {
                 if {[_source_is_snapshot $source filename extension]} {
@@ -1990,8 +2467,6 @@
                     }
 
                     file delete $tarpath
-                    
-                    set needs_portindex 1
                 } else {
                     # sync just a PortIndex file
                     set indexfile [macports::getindex $source]
@@ -2006,10 +2481,13 @@
         }
         
         if {$needs_portindex} {
-            global macports::prefix
-            set indexdir [file dirname [macports::getindex $source]]
-            if {[catch {system "${macports::prefix}/bin/portindex $indexdir"}]} {
-                ui_error "updating PortIndex for $source failed"
+            set any_needed_portindex 1
+            if {![info exists options(no_reindex)]} {
+                global macports::prefix
+                set indexdir [file dirname [macports::getindex $source]]
+                if {[catch {system "${macports::prefix}/bin/portindex $indexdir"}]} {
+                    ui_error "updating PortIndex for $source failed"
+                }
             }
         }
     }
@@ -2118,7 +2596,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
@@ -2275,7 +2753,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
@@ -2296,11 +2774,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
             }
         }
@@ -2308,6 +2788,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]
@@ -2320,7 +2801,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'."
     }
 }
 
@@ -2411,11 +2892,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
@@ -2424,24 +2904,14 @@
         flush stdout
     }
     
-    if {[info exists portinfo(conflicts)] && ($target == "" || $target == "install" || $target == "activate")} {
-        set conflictports [_mportconflictsinstalled $mport $portinfo(conflicts)]
-        if {[llength ${conflictports}] != 0} {
-            if {[macports::global_option_isset ports_force]} {
-                ui_warn "Force option set; installing $portinfo(name) despite conflicts with: ${conflictports}"
-            } else {
-                if {![macports::ui_isset ports_debug]} {
-                    ui_msg ""
-                }
-                return -code error "Can't install $portinfo(name) because conflicting ports are installed: ${conflictports}"
-            }
-        }
+    if {$target == "" || $target == "install" || $target == "activate"} {
+        _mporterrorifconflictsinstalled $mport
     }
 
     set workername [ditem_key $mport workername]
     set deptypes [macports::_deptypes_for_target $target $workername]
 
-    set subPorts {}
+    set depPorts {}
     if {[llength $deptypes] > 0} {
         array set optionsarray [ditem_key $mport options]
         # avoid propagating requested flag from parent
@@ -2460,12 +2930,29 @@
             continue
         }
         foreach depspec $portinfo($deptype) {
-            # skip depspec/archs combos we've already seen
-            set seenkey "${depspec},[join $required_archs ,]"
-            if {[info exists depspec_seen($seenkey)]} {
-                if {$depspec_seen($seenkey) != 0} {
+            # 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 port_seen($seenkey)]} {
+                set seen 1
+            } else {
+                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 {$key_archs == "noarch" || $required_archs == "noarch" || [llength $key_archs] > $nrequired} {
+                        set seen 1
+                        set seenkey $key
+                        break
+                    }
+                }
+            }
+            if {$seen} {
+                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
             }
@@ -2474,8 +2961,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]
             }
@@ -2508,43 +2993,46 @@
                     }
                     ui_error "Dependency '$dep_portname' not found."
                     return 1
+                } elseif {[info exists dep_portinfo(installs_libs)] && !$dep_portinfo(installs_libs)} {
+                    set check_archs 0
                 }
-                lappend options subport $dep_portname
-                # Figure out the subport. Check the open_mports list first, since
+                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 subport [dlist_match_multi $macports::open_mports [list porturl $dep_portinfo(porturl) options $options variations $variations]]
-                
-                if {$subport == {}} {
+                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 subport [mportopen $dep_portinfo(porturl) $options $variations]
+                    set depport [mportopen $dep_portinfo(porturl) $dep_options $variations]
                 }
             }
 
             # check archs
             if {$parse && $check_archs
-                && ![macports::_mport_supports_archs $subport $required_archs]} {
+                && ![macports::_mport_supports_archs $depport $required_archs]} {
 
-                set supported_archs [_mportkey $subport supported_archs]
-                mportclose $subport
+                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 subport [mportopen $dep_portinfo(porturl) $options [array get variation_array]]
-                        if {[macports::_mport_supports_archs $subport $required_archs]} {
+                        set depport [mportopen $dep_portinfo(porturl) $dep_options [array get variation_array]]
+                        if {[macports::_mport_supports_archs $depport $required_archs]} {
                             set arch_mismatch 0
                         }
                     }
                 }
                 if {$arch_mismatch} {
-                    macports::_explain_arch_mismatch [_mportkey $mport name] $dep_portname $required_archs $supported_archs $has_universal
+                    macports::_explain_arch_mismatch [_mportkey $mport subport] $dep_portname $required_archs $supported_archs $has_universal
                     return -code error "architecture mismatch"
                 }
             }
@@ -2552,24 +3040,26 @@
             if {$parse} {
                 if {$recurseDeps} {
                     # Add to the list we need to recurse on.
-                    lappend subPorts $subport
+                    lappend depPorts $depport
                 }
-    
+
                 # Append the sub-port's provides to the port's requirements list.
-                set subport_provides "[ditem_key $subport provides]"
-                ditem_append_unique $mport requires $subport_provides
-                set depspec_seen($seenkey) $subport_provides
-            } else {
-                set depspec_seen($seenkey) 0
+                set depport_provides "[ditem_key $depport provides]"
+                ditem_append_unique $mport requires $depport_provides
+                # 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
             }
         }
     }
 
-    # Loop on the subports.
+    # Loop on the depports.
     if {$recurseDeps} {
-        foreach subport $subPorts {
+        foreach depport $depPorts {
             # Sub ports should be installed (all dependencies must be satisfied).
-            set res [mportdepends $subport "" $recurseDeps $skipSatisfied 1]
+            set res [mportdepends $depport "" $recurseDeps $skipSatisfied 1]
             if {$res != 0} {
                 return $res
             }
@@ -2584,8 +3074,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
     }
@@ -2597,17 +3086,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
     }
@@ -2619,6 +3112,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
@@ -2703,7 +3206,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"
@@ -2712,8 +3216,9 @@
         install     -
         activate    -
         ""          {
-            if {[$workername eval registry_exists \$name \$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"
@@ -2727,6 +3232,7 @@
 proc macports::selfupdate {{optionslist {}} {updatestatusvar ""}} {
     global macports::prefix macports::portdbpath macports::libpath macports::rsync_server macports::rsync_dir macports::rsync_options
     global macports::autoconf::macports_version macports::autoconf::rsync_path tcl_platform
+    global macports::autoconf::openssl_path macports::autoconf::tar_path
     array set options $optionslist
     
     # variable that indicates whether we actually updated base
@@ -2735,27 +3241,68 @@
         set updatestatus no
     }
 
-    # syncing ports tree.
-    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
-        ui_msg "--->  Updating the ports tree"
-        if {[catch {mportsync $optionslist} result]} {
-            return -code error "Couldn't sync the ports tree: $result"
+    # are we syncing a tarball? (implies detached signature)
+    set is_tarball 0
+    if {[string range ${rsync_dir} end-3 end] == ".tar"} {
+        set is_tarball 1
+        set mp_source_path [file join $portdbpath sources ${rsync_server} [file dirname ${rsync_dir}]]
+    } else {
+        if {[string index $rsync_dir end] != "/"} {
+            append rsync_dir "/"
         }
+        set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}]
     }
-
     # create the path to the to be downloaded sources if it doesn't exist
-    set mp_source_path [file join $portdbpath sources ${rsync_server} ${rsync_dir}/]
     if {![file exists $mp_source_path]} {
         file mkdir $mp_source_path
     }
     ui_debug "MacPorts sources location: $mp_source_path"
 
     # sync the MacPorts sources
-    ui_msg "--->  Updating MacPorts base sources using rsync"
+    ui_msg "$macports::ui_prefix Updating MacPorts base sources using rsync"
     if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir} $mp_source_path" } result ] } {
        return -code error "Error synchronizing MacPorts sources: $result"
     }
 
+    if {$is_tarball} {
+        # verify signature for tarball
+        global macports::archivefetch_pubkeys
+        if { [catch { system "$rsync_path $rsync_options rsync://${rsync_server}/${rsync_dir}.rmd160 $mp_source_path" } result ] } {
+            return -code error "Error synchronizing MacPorts source signature: $result"
+        }
+        set openssl [findBinary openssl $macports::autoconf::openssl_path]
+        set tarball "${mp_source_path}/[file tail $rsync_dir]"
+        set signature "${tarball}.rmd160"
+        set verified 0
+        foreach pubkey ${macports::archivefetch_pubkeys} {
+            if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature $tarball} result]} {
+                set verified 1
+                ui_debug "successful verification with key $pubkey"
+                break
+            } else {
+                ui_debug "failed verification with key $pubkey"
+                ui_debug "openssl output: $result"
+            }
+        }
+        if {!$verified} {
+            return -code error "Failed to verify signature for MacPorts source!"
+        }
+        
+        # extract tarball and move into place
+        set tar [macports::findBinary tar $macports::autoconf::tar_path]
+        file mkdir ${mp_source_path}/tmp
+        set tar_cmd "$tar -C ${mp_source_path}/tmp -xf ${tarball}"
+        ui_debug $tar_cmd
+        if {[catch {system $tar_cmd}]} {
+            return -code error "Failed to extract MacPorts sources from tarball!"
+        }
+        file delete -force ${mp_source_path}/base
+        file rename ${mp_source_path}/tmp/base ${mp_source_path}/base
+        file delete -force ${mp_source_path}/tmp
+        # set the final extracted source path
+        set mp_source_path ${mp_source_path}/base
+    }
+
     # echo current MacPorts version
     ui_msg "MacPorts base version $macports::autoconf::macports_version installed,"
 
@@ -2781,12 +3328,25 @@
     }
 
     # check if we we need to rebuild base
-    set comp [rpm-vercomp $macports_version_new $macports::autoconf::macports_version]
+    set comp [vercmp $macports_version_new $macports::autoconf::macports_version]
+
+    # syncing ports tree.
+    if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
+        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
+            lappend optionslist no_reindex 1 needed_portindex_var needed_portindex
+        }
+        if {[catch {mportsync $optionslist} result]} {
+            return -code error "Couldn't sync the ports tree: $result"
+        }
+    }
+
     if {$use_the_force_luke == "yes" || $comp > 0} {
         if {[info exists options(ports_dryrun)] && $options(ports_dryrun) == "yes"} {
-            ui_msg "--->  MacPorts base is outdated, selfupdate would install $macports_version_new (dry run)"
+            ui_msg "$macports::ui_prefix MacPorts base is outdated, selfupdate would install $macports_version_new (dry run)"
         } else {
-            ui_msg "--->  MacPorts base is outdated, installing new version $macports_version_new"
+            ui_msg "$macports::ui_prefix MacPorts base is outdated, installing new version $macports_version_new"
 
             # get installation user/group and permissions
             set owner [file attributes ${prefix} -owner]
@@ -2816,16 +3376,19 @@
                 ui_warn "Disabling readline support due to readline in /usr/local"
             }
 
+            if {$prefix == "/usr/local" || $prefix == "/usr"} {
+                append configure_args " --with-unsupported-prefix"
+            }
+
+            # Choose a sane compiler
             set cc_arg ""
-            switch -glob -- $::macports::macosx_version {
-                10.[45] { set cc_arg "CC=/usr/bin/gcc-4.0 " }
-                10.6     { set cc_arg "CC=/usr/bin/gcc-4.2 " }
-                10.*     { set cc_arg "CC=/usr/bin/llvm-gcc-4.2 " }
+            if {$::macports::os_platform == "darwin"} {
+                set cc_arg "CC=/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" } result] } {
+            if { [catch { system "cd $mp_source_path && ${cc_arg}./configure $configure_args && make && make install SELFUPDATING=1" } result] } {
                 return -code error "Error installing new MacPorts base: $result"
             }
             if {[info exists updatestatus]} {
@@ -2833,9 +3396,9 @@
             }
         }
     } elseif {$comp < 0} {
-        ui_msg "--->  MacPorts base is probably trunk or a release candidate"
+        ui_msg "$macports::ui_prefix MacPorts base is probably trunk or a release candidate"
     } else {
-        ui_msg "--->  MacPorts base is already the latest version"
+        ui_msg "$macports::ui_prefix MacPorts base is already the latest version"
     }
 
     # set the MacPorts sources to the right owner
@@ -2846,8 +3409,13 @@
     }
 
     if {![info exists options(ports_selfupdate_nosync)] || $options(ports_selfupdate_nosync) != "yes"} {
-        ui_msg "\nThe ports tree has been updated. To upgrade your installed ports, you should run"
-        ui_msg "  port upgrade outdated"
+        if {[info exists needed_portindex]} {
+            ui_msg "Not all sources could be fully synced using the old version of MacPorts."
+            ui_msg "Please run selfupdate again now that MacPorts base has been updated."
+        } else {
+            ui_msg "\nThe ports tree has been updated. To upgrade your installed ports, you should run"
+            ui_msg "  port upgrade outdated"
+        }
     }
 
     return 0
@@ -2879,6 +3447,7 @@
     if {!$orig_nodeps} {
         unset -nocomplain macports::global_options(ports_nodeps)
     }
+
     return $status
 }
 
@@ -2886,7 +3455,6 @@
 proc macports::_upgrade {portname dspec variationslist optionslist {depscachename ""}} {
     global macports::global_variations
     array set options $optionslist
-    set options(subport) $portname
 
     if {![string match "" $depscachename]} {
         upvar $depscachename depscache
@@ -2898,6 +3466,16 @@
         set is_dryrun yes
     }
 
+    # Is this a rev-upgrade-called run?
+    set is_revupgrade no
+    if {[info exists options(ports_revupgrade)] && $options(ports_revupgrade)} {
+        set is_revupgrade yes
+    }
+    set is_revupgrade_second_run no
+    if {[info exists options(ports_revupgrade_second_run)] && $options(ports_revupgrade_second_run)} {
+        set is_revupgrade_second_run yes
+    }
+
     # check if the port is in tree
     if {[catch {mportlookup $portname} result]} {
         global errorInfo
@@ -2914,6 +3492,7 @@
     array set portinfo [lindex $result 1]
     # set portname again since the one we were passed may not have had the correct case
     set portname $portinfo(name)
+    set options(subport) $portname
 
     set ilist {}
     if { [catch {set ilist [registry::installed $portname ""]} result] } {
@@ -2944,7 +3523,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
@@ -3001,9 +3580,9 @@
         set revision [lindex $i 2]
         set epoch [lindex $i 5]
         if { $version_installed == {} || ($epoch > $epoch_installed && $version != $version_installed) ||
-                ($epoch >= $epoch_installed && [rpm-vercomp $version $version_installed] > 0)
+                ($epoch >= $epoch_installed && [vercmp $version $version_installed] > 0)
                 || ($epoch >= $epoch_installed
-                    && [rpm-vercomp $version $version_installed] == 0
+                    && [vercmp $version $version_installed] == 0
                     && $revision > $revision_installed)} {
             set version_installed $version
             set revision_installed $revision
@@ -3090,7 +3669,7 @@
     
     # at this point we need to check if a different port will be replacing this one
     if {[info exists portinfo(replaced_by)] && ![info exists options(ports_upgrade_no-replace)]} {
-        ui_msg "--->  $portname is replaced by $portinfo(replaced_by)"
+        ui_msg "$macports::ui_prefix $portname is replaced by $portinfo(replaced_by)"
         if {[catch {mportlookup $portinfo(replaced_by)} result]} {
             global errorInfo
             ui_debug "$errorInfo"
@@ -3135,9 +3714,9 @@
     set build_override 0
     set will_install yes
     # check installed version against version in ports
-    if { ( [rpm-vercomp $version_installed $version_in_tree] > 0
-            || ([rpm-vercomp $version_installed $version_in_tree] == 0
-                && [rpm-vercomp $revision_installed $revision_in_tree] >= 0 ))
+    if { ( [vercmp $version_installed $version_in_tree] > 0
+            || ([vercmp $version_installed $version_in_tree] == 0
+                && [vercmp $revision_installed $revision_in_tree] >= 0 ))
         && ![info exists options(ports_upgrade_force)] } {
         if {$portname != $newname} { 
             ui_debug "ignoring versions, installing replacement port"
@@ -3152,6 +3731,13 @@
                   || [_mportkey $workername "{os.major}"] != $os_major_installed)} {
             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 {
             if {[info exists portinfo(canonical_active_variants)] && $portinfo(canonical_active_variants) != $oldvariant} {
                 if {[llength $variationslist] > 0} {
@@ -3167,15 +3753,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)])} {
+    if {$will_install &&
+        ([info exists options(ports_upgrade_force)]
+            || $build_override == 1
+            || !$already_installed)} {
         set will_build yes
     }
 
     # first upgrade dependencies
-    if {![info exists options(ports_nodeps)]} {
-        set status [_upgrade_dependencies portinfo depscache variationslist options $will_build]
+    if {![info exists options(ports_nodeps)] && !$is_revupgrade} {
+        # 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
@@ -3226,9 +3816,8 @@
         }
     }
 
-    global macports::registry.format
     # 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
@@ -3238,8 +3827,8 @@
         set newregref [registry::open_entry $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants) $existing_epoch]
         if {$is_dryrun eq "yes"} {
             ui_msg "Skipping uninstall $newname @${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) (dry run)"
-        } elseif {!(${registry.format} == "receipt_sqlite" && [registry::run_target $newregref uninstall [array get options]])
-                  && [catch {registry_uninstall::uninstall $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) [array get options]} result]} {
+        } elseif {![registry::run_target $newregref uninstall [array get options]]
+                  && [catch {registry_uninstall::uninstall $newname $version_in_tree $revision_in_tree $portinfo(canonical_active_variants) [array get options]} result]} {
             global errorInfo
             ui_debug "$errorInfo"
             ui_error "Uninstall $newname ${version_in_tree}_${revision_in_tree}$portinfo(canonical_active_variants) failed: $result"
@@ -3262,8 +3851,8 @@
         if {$is_dryrun eq "yes"} {
             ui_msg "Skipping deactivate $portname @${version_active}_${revision_active}${variant_active} (dry run)"
         } elseif {![catch {registry::active $portname}] &&
-                  !(${registry.format} == "receipt_sqlite" && [registry::run_target $regref deactivate [array get options]])
-                  && [catch {portimage::deactivate $portname ${version_active}_${revision_active}${variant_active} [array get options]} result]} {
+                  ![registry::run_target $regref deactivate [array get options]]
+                  && [catch {portimage::deactivate $portname $version_active $revision_active $variant_active [array get options]} result]} {
             global errorInfo
             ui_debug "$errorInfo"
             ui_error "Deactivating $portname @${version_active}_${revision_active}${variant_active} failed: $result"
@@ -3338,8 +3927,8 @@
             set regref [registry::open_entry $portname $version $revision $variant $epoch]
             if {$is_dryrun eq "yes"} {
                 ui_msg "Skipping uninstall $portname @${version}_${revision}${variant} (dry run)"
-            } elseif {!(${registry.format} == "receipt_sqlite" && [registry::run_target $regref uninstall $optionslist])
-                      && [catch {registry_uninstall::uninstall $portname ${version}_${revision}${variant} $optionslist} result]} {
+            } elseif {![registry::run_target $regref uninstall $optionslist]
+                      && [catch {registry_uninstall::uninstall $portname $version $revision $variant $optionslist} result]} {
                 global errorInfo
                 ui_debug "$errorInfo"
                 # replaced_by can mean that we try to uninstall all versions of the old port, so handle errors due to dependents
@@ -3360,7 +3949,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
@@ -3378,17 +3967,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 != ""} {
@@ -3532,3 +4122,579 @@
         return "/tmp"
     }
 }
+
+# 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
+}
+
+# returns 1 if ports were rebuilt and revupgrade_scanandrebuild should be called again
+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]
+    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 {$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
+                        }
+                    }
+                    set fpath [$f actual_path]
+                    ui_debug "Updating binary flag for file $i of $files_count: $fpath"
+                    incr i
+
+                    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"
+                throw
+            }
+        }
+        ui_msg ""
+    }
+
+    set broken_files {};
+    set binaries [registry::file search active 1 binary 1]
+    ui_msg -nonewline "$macports::ui_prefix Scanning binaries for linking errors"
+    set binary_count [llength $binaries]
+    if {$binary_count > 0} {
+        set handle [machista::create_handle]
+        if {$handle == "NULL"} {
+            error "Error creating libmachista handle"
+        }
+        array unset files_warned_about
+        array set files_warned_about [list]
+
+        set i 1
+        foreach b $binaries {
+            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
+                }
+            }
+            set bpath [$b actual_path]
+            #ui_debug "$i/$binary_count: $bpath"
+            incr i
+
+            set resultlist [machista::parse_file $handle $bpath]
+            set returncode [lindex $resultlist 0]
+            set result     [lindex $resultlist 1]
+
+            if {$returncode != $machista::SUCCESS} {
+                if {$returncode == $machista::EMAGIC} {
+                    # not a Mach-O file
+                    # ignore silently, these are only static libs anyway
+                    #ui_debug "Error parsing file ${bpath}: [machista::strerror $returncode]"
+                } else {
+                    if {$fancy_output} {
+                        ui_msg ""
+                    }
+                    ui_warn "Error parsing file ${bpath}: [machista::strerror $returncode]"
+                }
+                continue;
+            }
+
+            set architecture [$result cget -mt_archs]
+            while {$architecture != "NULL"} {
+                if {[info exists options(ports_rev-upgrade_id-loadcmd-check)] && $options(ports_rev-upgrade_id-loadcmd-check) == "yes"} {
+                    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 $bpath [$architecture cget -mat_install_name]]}]} {
+                            if {[string index $idloadcmdpath 0] != "/"} {
+                                set port [registry::entry owner $bpath]
+                                if {$port != ""} {
+                                    set portname [$port name]
+                                } else {
+                                    set portname "<unknown-port>"
+                                }
+                                if {$fancy_output} {
+                                    ui_msg ""
+                                }
+                                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 $bpath]
+                                if {$port != ""} {
+                                    set portname [$port name]
+                                } else {
+                                    set portname "<unknown-port>"
+                                }
+                                if {$fancy_output} {
+                                    ui_msg ""
+                                }
+                                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 $bpath]
+                                set hash_idloadcmd [sha256 file $idloadcmdpath]
+    
+                                if {$hash_this != $hash_idloadcmd} {
+                                    set port [registry::entry owner $bpath]
+                                    if {$port != ""} {
+                                        set portname [$port name]
+                                    } else {
+                                        set portname "<unknown-port>"
+                                    }
+                                    if {$fancy_output} {
+                                        ui_msg ""
+                                    }
+                                    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 $bpath [$loadcommand cget -mlt_install_name]]}]} {
+                        set loadcommand [$loadcommand cget -next]
+                        continue;
+                    }
+
+                    set libresultlist [machista::parse_file $handle $filepath]
+                    set libreturncode [lindex $libresultlist 0]
+                    set libresult     [lindex $libresultlist 1]
+
+                    if {$libreturncode != $machista::SUCCESS} {
+                        if {![info exists files_warned_about($filepath)]} {
+                            if {[macports::ui_isset ports_verbose]} {
+                                ui_msg ""
+                            }
+                            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 $bpath as broken"
+                            lappend broken_files $bpath
+                        }
+                        set loadcommand [$loadcommand cget -next]
+                        continue;
+                    }
+
+                    set libarchitecture [$libresult cget -mt_archs]
+                    set libarch_found false;
+                    while {$libarchitecture != "NULL"} {
+                        if {[$architecture cget -mat_arch] != [$libarchitecture cget -mat_arch]} {
+                            set libarchitecture [$libarchitecture cget -next]
+                            continue;
+                        }
+
+                        if {[$loadcommand cget -mlt_version] != [$libarchitecture cget -mat_version] && [$loadcommand cget -mlt_comp_version] > [$libarchitecture cget -mat_comp_version]} {
+                            if {[macports::ui_isset ports_verbose]} {
+                                ui_msg ""
+                            }
+                            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;
+                        break;
+                    }
+
+                    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 $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 $bpath"
+                            # ui_debug "   How did you get that compiled anyway?"
+                        }
+                    }
+                    set loadcommand [$loadcommand cget -next]
+                }
+
+                set architecture [$architecture cget -next]
+            }
+        }
+        ui_msg ""
+
+        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 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 != ""} {
+                lappend broken_ports $port
+                lappend broken_files_by_port($port) $file
+            } else {
+                ui_error "Broken file $file doesn't belong to any port."
+            }
+        }
+        set broken_ports [lsort -unique $broken_ports]
+
+        set temp_broken_ports $broken_ports
+        set broken_ports {}
+
+        foreach port $temp_broken_ports {
+            set portname [$port name]
+            # don't try to rebuild ports that don't exist in the tree
+            if {${macports::revupgrade_mode} == "rebuild"} {
+                if {[catch {mportlookup $portname} result]} {
+                    ui_debug "$::errorInfo"
+                    error "lookup of portname $portname failed: $result"
+                }
+                if {[llength $result] < 2} {
+                    ui_warn "No port $portname found in the index; can't rebuild"
+                    unset broken_files_by_port($port)
+                    continue
+                }
+            }
+            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 rebuiling 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
+        foreach port $broken_ports {
+            # initialize with empty list
+            set adjlist($port) {}
+            set revadjlist($port) {}
+            ui_debug "Broken: [$port name]"
+        }
+
+        array set visited {}
+        foreach port $broken_ports {
+            # stack of broken nodes we've come across
+            set stack {}
+            lappend stack $port
+
+            # build graph
+            if {![info exists visited($port)]} {
+                revupgrade_buildgraph $port stack adjlist revadjlist visited
+            }
+        }
+
+        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 {
+                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
+                    # remove from unsorted list
+                    set index [lsearch -exact $unsorted_ports $port]
+                    set unsorted_ports [lreplace $unsorted_ports $index $index]
+
+                    # remove edges 
+                    foreach target $revadjlist($port) {
+                        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"
+        foreach port $topsort_ports {
+            ui_msg "     [$port name] @[$port version] [$port variants][$port negated_variants]"
+        }
+
+        # 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 {
+            set portname [$port name]
+            if {![info exists depscache(port:$portname)]} {
+                # set rev-upgrade options and nodeps if this is not the first run
+                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 my_options(ports_source_only) yes
+                }
+
+                # call macports::upgrade with ports_revupgrade option to rebuild the port
+                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 $portname"
+                }
+            }
+        }
+
+        if {[info exists options(ports_dryrun)] && $options(ports_dryrun) == "yes"} {
+            ui_warn "If this was no dry run, rev-upgrade would now run the checks again to find unresolved and newly created problems"
+            return 0
+        }
+        return 1
+    }
+
+    return 0
+}
+
+# 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 macports::path_is_in_prefix {path} {
+    global macports::prefix macports::applications_dir
+    if {[string first $macports::prefix $path] == 0} {
+        return yes
+    }
+    if {[string first $macports::applications_dir $path] == 0} {
+        return yes
+    }
+    return no
+}
+
+# Function to replace macros in loadcommand paths with their proper values (which are usually determined at load time)
+# Usage: revupgrade_handle_special_paths name_of_file path_from_loadcommand
+# Returns the corrected path on success or an error in case of failure.
+# 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 macports::revupgrade_handle_special_paths {fname path} {
+    set corrected_path $path
+
+    set loaderpath_idx [string first "@loader_path" $corrected_path]
+    if {$loaderpath_idx != -1} {
+        set corrected_path [string replace $corrected_path $loaderpath_idx $loaderpath_idx+11 [file dirname $fname]]
+    }
+
+    set executablepath_idx [string first "@executable_path" $corrected_path]
+    if {$executablepath_idx != -1} {
+        ui_debug "Ignoring loadcommand containing @executable_path in $fname"
+        error "@executable_path in loadcommand"
+    }
+
+    set rpath_idx [string first "@rpath" $corrected_path]
+    if {$rpath_idx != -1} {
+        ui_debug "Ignoring loadcommand containing @rpath in $fname"
+        error "@rpath in loadcommand"
+    }
+
+    return $corrected_path
+}
+
+# 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 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 {
+        set is_broken_port false
+
+        if {[info exists adjlist($dep)]} {
+            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
+            lappend adjlist($dep) [lindex $stack 0]
+            # make this port the new last broken port by prepending it to the stack
+            set stack [linsert $stack 0 $dep]
+            
+            set is_broken_port true
+        }
+        if {![info exists visited($dep)]} {
+            revupgrade_buildgraph $dep stack adjlist revadjlist visited
+        }
+        if {$is_broken_port} {
+            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-post-destroot/base/src/macports1.0/macports_autoconf.tcl.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/macports_autoconf.tcl.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/macports_autoconf.tcl.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # macports-autoconf.tcl.in
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2006 - 2009, 2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -39,11 +40,17 @@
     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@"
     variable rsync_path "@RSYNC@"
     variable tar_command "@TAR_CMD@"
     variable tar_path "@TAR@"
+    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-post-destroot/base/src/macports1.0/macports_dlist.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/macports_dlist.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/macports_dlist.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,8 +1,9 @@
 # macports1.0/macports_dlist.tcl
 # $Id$
 #
+# Copyright (c) 2004-2005, 2007, 2009, 2011 The MacPorts Project
 # Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -305,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-post-destroot/base/src/macports1.0/macports_fastload.tcl.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/macports_fastload.tcl.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/macports_fastload.tcl.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # macports_fastload.tcl.in
 # $Id$
 #
-# Copyright (c) 2004 Paul Guyot, The MacPorts Project.
+# Copyright (c) 2005-2007, 2009-2010 The MacPorts Project
+# Copyright (c) 2004-2005 Paul Guyot, The MacPorts Project.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/macports1.0/macports_index.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/macports_index.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/macports_index.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,7 @@
 # macports_index.tcl
 # $Id$
 #
-# Copyright (c) 2004 Apple Computer, Inc.
+# Copyright (c) 2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -12,7 +12,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/macports1.0/macports_util.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/macports_util.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/macports_util.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -12,7 +12,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/macports1.0/tests/macports_dlist.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/macports1.0/tests/macports_dlist.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/macports1.0/tests/macports_dlist.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,6 +2,7 @@
 # macports1.0/test_dlist.tcl
 # $Id$
 #
+# Copyright (c) 2007 The MacPorts Project
 # Copyright (c) 2003 Kevin Van Vechten <kevin at opendarwin.org>
 
 # Test suite for macports_dlist package.
@@ -70,7 +71,7 @@
 }
 
 # Replicate Shantonu's Bug #354 to test dlist functionality.
-# http://trac.macports.org/projects/macports/ticket/354
+# https://trac.macports.org/ticket/354
 # A depends on B, C.
 # B depends on C.
 # C has no dependencies.

Modified: branches/gsoc11-post-destroot/base/src/package1.0/package.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/package.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/package.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # package.tcl
 # $Id$
 #
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2004, 2007-2008, 2010 The MacPorts Project
+# Copyright (c) 2002-2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portarchivefetch.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portarchivefetch.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portarchivefetch.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # $Id$
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
-# Copyright (c) 2004-2010 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
@@ -59,35 +59,76 @@
 default archivefetch.ignore_sslcert no
 default archivefetch.pubkeys {$archivefetch_pubkeys}
 
-default archive_sites macports_archives
+default archive_sites {[portarchivefetch::filter_sites]}
 default archive_sites.listfile {"archive_sites.tcl"}
 default archive_sites.listpath {"port1.0/fetch"}
 default archive.subdir {${subport}}
 
+proc portarchivefetch::filter_sites {} {
+    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] {
+        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)
+        }
+    }
+
+    # 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
+}
+
 set_ui_prefix
 
 # 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
-
-    if {[file isfile ${archive.path}]} {
-        ui_debug "Found archive: ${archive.path}"
-        set all_archive_files {}
-        set fetch_urls {}
-    } else {
-        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
         }
     }
 }
@@ -128,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
@@ -159,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}]
@@ -204,9 +237,9 @@
                     ui_debug "$::errorInfo"
                     return -code error "Failed to fetch signature for archive: $result"
                 }
+                set openssl [findBinary openssl $portutil::autoconf::openssl_path]
                 set verified 0
                 foreach pubkey [option archivefetch.pubkeys] {
-                    set openssl [findBinary openssl $portutil::autoconf::openssl_path]
                     if {![catch {exec $openssl dgst -ripemd160 -verify $pubkey -signature $signature "${incoming_path}/${archive}.TMP"} result]} {
                         set verified 1
                         break
@@ -224,9 +257,11 @@
                 }
                 file delete -force $signature
                 set archive_exists 1
+                break
             }
         } else {
             set archive_exists 1
+            break
         }
     }
     if {[info exists archive_exists]} {
@@ -245,14 +280,16 @@
 }
 
 # Initialize archivefetch target and call checkfiles.
-proc portarchivefetch::archivefetch_init {args} {
-    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} {

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portdmg.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portdmg.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portdmg.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portdmg.tcl
 # $Id$
 #
-# Copyright (c) 2003 Apple Computer, Inc.
+# Copyright (c) 2007, 2009-2011  The MacPorts Project
+# Copyright (c) 2003, 2005 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portdpkg.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portdpkg.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portdpkg.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portdpkg.tcl
 # $Id$
 #
+# Copyright (c) 2005, 2007, 2009, 2011 The MacPorts Project
 # Copyright (c) 2004 Landon Fuller <landonf at macports.org>
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -52,7 +53,7 @@
 set_ui_prefix
 
 proc portdpkg::main {args} {
-	global UI_PREFIX destpath os.arch os.platform
+	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]]"
 
@@ -130,8 +131,9 @@
 	# 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 ${os.arch} {
+	switch -regex ${configure.build_arch} {
 		i[3-9]86 { set pkg_arch "i386" }
+		x86_64 { set pkg_arch "x86_64" }
 		default { set pkg_arch ${os.arch} }
 	}
 
@@ -139,7 +141,14 @@
 	# the operating system name
 	if {${os.platform} != "linux"} {
 		set pkg_arch "${os.platform}-${pkg_arch}"
+	} elseif {${pkg_arch} == "x86_64"} {
+		set pkg_arch "amd64"
 	}
+	
+	# An architecture-independent package
+	if {$supported_archs == "noarch"} {
+		set pkg_arch "all"
+	}
 
 	puts $controlfd "Package: [option subport]"
 	puts $controlfd "Architecture: ${pkg_arch}"

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portmdmg.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portmdmg.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portmdmg.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portmdmg.tcl
 # $Id$
 #
-# Copyright (c) 2003 Apple Computer, Inc.
+# Copyright (c) 2005, 2007-2011 The MacPorts Project
+# Copyright (c) 2003-2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portmpkg.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portmpkg.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portmpkg.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portmpkg.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
+# Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -47,10 +48,12 @@
 set_ui_prefix
 
 proc portmpkg::mpkg_main {args} {
-    global subport version revision package.destpath package.flat UI_PREFIX
+    global subport 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]
 }
@@ -94,7 +97,6 @@
     }
 
     lappend result [list $portinfo(name) $portinfo(version) $mport]
-	ui_debug "dependencies for ${portname}: $result"
 	return $result
 }
 
@@ -105,8 +107,11 @@
 	}
 
     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
@@ -116,16 +121,25 @@
 }
 
 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
+    global portdbpath os.major destpath workpath prefix porturl description package.destpath package.flat long_description homepage depends_run depends_lib
 
-	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"
 
+    if {${package.flat} && ${os.major} >= 10} {
+        set pkgpath ${package.destpath}/${portname}-${portversion}-component.pkg
+        set packages_path ${workpath}/mpkg_packages
+        set resources_path ${workpath}/mpkg_resources
+    } else {
+        set pkgpath ${package.destpath}/${portname}-${portversion}.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 ${mpkgpath}/Contents/Packages]
+	set deps [make_dependency_list $portname $packages_path]
 	set deps [lsort -unique $deps]
 	foreach dep $deps {
 		set name [lindex $dep 0]
@@ -134,17 +148,28 @@
 		# don't re-package ourself
 		if {$name != $portname} {
 			make_one_package $name $vers $mport
-			lappend dependencies ${name}-${vers}.pkg
+			if {${package.flat} && ${os.major} >= 10} {
+			    lappend dependencies org.macports.${name} ${name}-${vers}-component.pkg
+			} else {
+			    lappend dependencies ${name}-${vers}.pkg
+			}
 		}
 	}
+	if {${package.flat} && ${os.major} >= 10} {
+	    lappend dependencies org.macports.${portname} ${portname}-${portversion}-component.pkg
+	} else {
+	    lappend dependencies ${portname}-${portversion}.pkg
+	}
 
-	# 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
+    # 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]} {
@@ -153,12 +178,53 @@
             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 $portversion $pkg_long_description $pkg_description $pkg_homepage
+    file copy -force -- [getportresourcepath $porturl "port1.0/package/background.tiff"] ${resources_path}/background.tiff
 
+    if {${package.flat} && ${os.major} >= 10} {
+        write_distribution ${workpath}/Distribution $portname $dependencies
+        set productbuild [findBinary productbuild]
+        set cmdline "$productbuild --resources ${resources_path} --identifier org.macports.mpkg.${portname} --distribution ${workpath}/Distribution --package-path ${packages_path} ${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
@@ -191,7 +257,7 @@
 
 	set infofd [open ${infofile} w+]
 	puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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>

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portpkg.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portpkg.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portpkg.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portpkg.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -37,60 +38,86 @@
 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 version 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 $version $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 $version
+    }
+}
+
 proc portpkg::pkg_main {args} {
-    global subport version revision package.type package.destpath package.flat UI_PREFIX
+    global subport version revision UI_PREFIX
 
     ui_msg "$UI_PREFIX [format [msgcat::mc "Creating pkg for %s-%s"] ${subport} ${version}]"
 
+    if {[getuid] == 0 && [geteuid] != 0} {
+        elevateToRoot "pkg"
+    }
+
     return [package_pkg $subport $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
+    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 pkgpath "${package.destpath}/${portname}-${portversion}.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}]"
         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.
@@ -106,42 +133,63 @@
         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} {
                 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 ${portname} ${portversion} ${pkgpath} ${destpath}
 
     }
 
@@ -176,7 +224,7 @@
 
     set infofd [open ${infofile} w+]
     puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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>
@@ -224,7 +272,7 @@
 
     set infofd [open ${infofile} w+]
     puts $infofd {<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<!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>
@@ -303,14 +351,37 @@
     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 portversion} {
+    global macosx_deployment_target
+    set portname [xml_escape $portname]
+    set portversion [xml_escape $portversion]
+    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}-${portversion}-component.pkg</pkg-ref>
+</installer-gui-script>
+"
+    close $dfd
+}

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portportpkg.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portportpkg.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portportpkg.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # portportpkg.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2004 Apple Computer, Inc.
+# Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portrpm.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portrpm.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portrpm.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portrpm.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2005 - 2007, 2009 - 2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portsrpm.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portsrpm.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portsrpm.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portsrpm.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2007, 2009, 2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/package1.0/portunarchive.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/package1.0/portunarchive.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/package1.0/portunarchive.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portunarchive.tcl
 # $Id$
 #
+# Copyright (c) 2005, 2007-2012 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -61,7 +62,7 @@
 set_ui_prefix
 
 proc portunarchive::unarchive_init {args} {
-    global target_state_fd unarchive.skip \
+    global target_state_fd unarchive.skip destroot \
            ports_force ports_source_only ports_binary_only \
            subport version revision portvariants \
            unarchive.type unarchive.file unarchive.path
@@ -73,26 +74,18 @@
     } elseif {[info exists ports_source_only] && $ports_source_only == "yes"} {
         ui_debug "Skipping unarchive ($subport) since source-only is set"
         set skipped 1
-    } elseif {[check_statefile target org.macports.destroot $target_state_fd]} {
+    } elseif {[check_statefile target org.macports.destroot $target_state_fd]
+              && [file isdirectory $destroot]} {
         ui_debug "Skipping unarchive ($subport) since destroot completed"
         set skipped 1
     } elseif {[info exists ports_force] && $ports_force == "yes"} {
         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"} {

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -16,10 +16,11 @@
 .PHONY: test
 
 test:: ${SHLIB_NAME}
-	${TCLSH} tests/checksums.tcl ${SHLIB_NAME}
-	${TCLSH} tests/curl.tcl ${SHLIB_NAME}
-	${TCLSH} tests/filemap.tcl ${SHLIB_NAME}
-	${TCLSH} tests/fs-traverse.tcl ${SHLIB_NAME}
-	${TCLSH} tests/symlink.tcl ${SHLIB_NAME}
-	${TCLSH} tests/unsetenv.tcl ${SHLIB_NAME}
+	${TCLSH} tests/checksums.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/curl.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/filemap.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/fs-traverse.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/symlink.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/unsetenv.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/vercomp.tcl ./${SHLIB_NAME}
 	${TCLSH} tests/macho.tcl ${SHLIB_NAME}

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/Pextlib.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/Pextlib.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/Pextlib.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,9 +2,10 @@
  * Pextlib.c
  * $Id$
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * 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
@@ -15,7 +16,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 
@@ -46,6 +47,7 @@
 #include <grp.h>
 #include <limits.h>
 #include <pwd.h>
+#include <stdbool.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -53,6 +55,11 @@
 #include <strings.h>
 #include <unistd.h>
 
+#ifdef __MACH__
+#include <mach-o/loader.h>
+#include <mach-o/fat.h>
+#endif
+
 #include <tcl.h>
 
 #include "Pextlib.h"
@@ -94,147 +101,147 @@
 static char *
 ui_escape(const char *source)
 {
-	char *d, *dest;
-	const char *s;
-	size_t dlen;
+    char *d, *dest;
+    const char *s;
+    size_t dlen;
 
-	s = source;
-	dlen = strlen(source) * 2 + 1;
-	d = dest = malloc(dlen);
-	if (dest == NULL) {
-		return NULL;
-	}
-	while(*s != '\0') {
-		switch(*s) {
-			case '\\':
-			case '}':
-			case '{':
-				*d = '\\';
-				d++;
-				*d = *s;
-				d++;
-				s++;
-				break;
-			case '\n':
-				s++;
-				break;
-			default:
-				*d = *s;
-				d++;
-				s++;
-				break;
-		}
-	}
-	*d = '\0';
-	return dest;
+    s = source;
+    dlen = strlen(source) * 2 + 1;
+    d = dest = malloc(dlen);
+    if (dest == NULL) {
+        return NULL;
+    }
+    while(*s != '\0') {
+        switch(*s) {
+            case '\\':
+            case '}':
+            case '{':
+                *d = '\\';
+                d++;
+                *d = *s;
+                d++;
+                s++;
+                break;
+            case '\n':
+                s++;
+                break;
+            default:
+                *d = *s;
+                d++;
+                s++;
+                break;
+        }
+    }
+    *d = '\0';
+    return dest;
 }
 
 int
 ui_info(Tcl_Interp *interp, char *mesg)
 {
-	const char ui_proc_start[] = "ui_info [subst -nocommands -novariables {";
-	const char ui_proc_end[] = "}]";
-	char *script, *string;
-	size_t scriptlen, len, remaining;
-	int rval;
+    const char ui_proc_start[] = "ui_info [subst -nocommands -novariables {";
+    const char ui_proc_end[] = "}]";
+    char *script, *string;
+    size_t scriptlen, len, remaining;
+    int rval;
 
-	string = ui_escape(mesg);
-	if (string == NULL)
-		return TCL_ERROR;
+    string = ui_escape(mesg);
+    if (string == NULL)
+        return TCL_ERROR;
 
-	len = strlen(string);
-	scriptlen = sizeof(ui_proc_start) + len + sizeof(ui_proc_end) - 1;
-	script = malloc(scriptlen);
-	if (script == NULL)
-		return TCL_ERROR;
+    len = strlen(string);
+    scriptlen = sizeof(ui_proc_start) + len + sizeof(ui_proc_end) - 1;
+    script = malloc(scriptlen);
+    if (script == NULL)
+        return TCL_ERROR;
 
-	memcpy(script, ui_proc_start, sizeof(ui_proc_start));
-	remaining = scriptlen - sizeof(ui_proc_start);
-	strncat(script, string, remaining);
-	remaining -= len;
-	strncat(script, ui_proc_end, remaining);
-	free(string);
-	rval = Tcl_EvalEx(interp, script, -1, 0);
-	free(script);
-	return rval;
+    memcpy(script, ui_proc_start, sizeof(ui_proc_start));
+    remaining = scriptlen - sizeof(ui_proc_start);
+    strncat(script, string, remaining);
+    remaining -= len;
+    strncat(script, ui_proc_end, remaining);
+    free(string);
+    rval = Tcl_EvalEx(interp, script, -1, 0);
+    free(script);
+    return rval;
 }
 
 int StrsedCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	char *pattern, *string, *res;
-	int range[2];
-	Tcl_Obj *tcl_result;
+    char *pattern, *string, *res;
+    int range[2];
+    Tcl_Obj *tcl_result;
 
-	if (objc != 3) {
-		Tcl_WrongNumArgs(interp, 1, objv, "string pattern");
-		return TCL_ERROR;
-	}
+    if (objc != 3) {
+        Tcl_WrongNumArgs(interp, 1, objv, "string pattern");
+        return TCL_ERROR;
+    }
 
-	string = Tcl_GetString(objv[1]);
-	pattern = Tcl_GetString(objv[2]);
-	res = strsed(string, pattern, range);
-	if (!res) {
-		Tcl_SetResult(interp, "strsed failed", TCL_STATIC);
-		return TCL_ERROR;
-	}
-	tcl_result = Tcl_NewStringObj(res, -1);
-	Tcl_SetObjResult(interp, tcl_result);
-	free(res);
-	return TCL_OK;
+    string = Tcl_GetString(objv[1]);
+    pattern = Tcl_GetString(objv[2]);
+    res = strsed(string, pattern, range);
+    if (!res) {
+        Tcl_SetResult(interp, "strsed failed", TCL_STATIC);
+        return TCL_ERROR;
+    }
+    tcl_result = Tcl_NewStringObj(res, -1);
+    Tcl_SetObjResult(interp, tcl_result);
+    free(res);
+    return TCL_OK;
 }
 
 int ExistsuserCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	Tcl_Obj *tcl_result;
-	struct passwd *pwent;
-	char *user;
+    Tcl_Obj *tcl_result;
+    struct passwd *pwent;
+    char *user;
 
-	if (objc != 2) {
-		Tcl_WrongNumArgs(interp, 1, objv, "user");
-		return TCL_ERROR;
-	}
+    if (objc != 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "user");
+        return TCL_ERROR;
+    }
 
-	user = strdup(Tcl_GetString(objv[1]));
-	if (isdigit(*(user)))
-		pwent = getpwuid(strtol(user, 0, 0));
-	else
-		pwent = getpwnam(user);
-	free(user);
+    user = strdup(Tcl_GetString(objv[1]));
+    if (isdigit(*(user)))
+        pwent = getpwuid(strtol(user, 0, 0));
+    else
+        pwent = getpwnam(user);
+    free(user);
 
-	if (pwent == NULL)
-		tcl_result = Tcl_NewIntObj(0);
-	else
-		tcl_result = Tcl_NewIntObj(pwent->pw_uid);
+    if (pwent == NULL)
+        tcl_result = Tcl_NewIntObj(0);
+    else
+        tcl_result = Tcl_NewIntObj(pwent->pw_uid);
 
-	Tcl_SetObjResult(interp, tcl_result);
-	return TCL_OK;
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
 }
 
 int ExistsgroupCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
-	Tcl_Obj *tcl_result;
-	struct group *grent;
-	char *group;
+    Tcl_Obj *tcl_result;
+    struct group *grent;
+    char *group;
 
-	if (objc != 2) {
-		Tcl_WrongNumArgs(interp, 1, objv, "groupname");
-		return TCL_ERROR;
-	}
+    if (objc != 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "groupname");
+        return TCL_ERROR;
+    }
 
-	group = strdup(Tcl_GetString(objv[1]));
-	if (isdigit(*(group)))
-		grent = getgrgid(strtol(group, 0, 0));
-	else
-		grent = getgrnam(group);
-	free(group);
+    group = strdup(Tcl_GetString(objv[1]));
+    if (isdigit(*(group)))
+        grent = getgrgid(strtol(group, 0, 0));
+    else
+        grent = getgrnam(group);
+    free(group);
 
-	if (grent == NULL)
-		tcl_result = Tcl_NewIntObj(0);
-	else
-		tcl_result = Tcl_NewIntObj(grent->gr_gid);
+    if (grent == NULL)
+        tcl_result = Tcl_NewIntObj(0);
+    else
+        tcl_result = Tcl_NewIntObj(grent->gr_gid);
 
-	Tcl_SetObjResult(interp, tcl_result);
-	return TCL_OK;
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
 }
 
 /* Find the first unused UID > 500
@@ -242,81 +249,81 @@
    but UIDs < 500 are reserved by Apple */
 int NextuidCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
 {
-	Tcl_Obj *tcl_result;
-	int cur;
+    Tcl_Obj *tcl_result;
+    int cur;
 
-	cur = MIN_USABLE_UID;
+    cur = MIN_USABLE_UID;
 
-	while (getpwuid(cur) != NULL) {
-		cur++;
-	}
+    while (getpwuid(cur) != NULL) {
+        cur++;
+    }
 
-	tcl_result = Tcl_NewIntObj(cur);
-	Tcl_SetObjResult(interp, tcl_result);
-	return TCL_OK;
+    tcl_result = Tcl_NewIntObj(cur);
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
 }
 
 /* Just as with NextuidCmd, return the first unused gid > 500 */
 int NextgidCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
 {
-	Tcl_Obj *tcl_result;
-	int cur;
+    Tcl_Obj *tcl_result;
+    int cur;
 
-	cur = MIN_USABLE_GID;
+    cur = MIN_USABLE_GID;
 
-	while (getgrgid(cur) != NULL) {
-		cur++;
-	}
+    while (getgrgid(cur) != NULL) {
+        cur++;
+    }
 
-	tcl_result = Tcl_NewIntObj(cur);
-	Tcl_SetObjResult(interp, tcl_result);
-	return TCL_OK;
+    tcl_result = Tcl_NewIntObj(cur);
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
 }
 
 int UmaskCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc UNUSED, Tcl_Obj *CONST objv[] UNUSED)
 {
-	Tcl_Obj *tcl_result;
-	char *tcl_mask, *p;
-	const size_t stringlen = 5; /* 4 digits & \0 */
-	int i;
-	mode_t *set;
-	mode_t newmode;
-	mode_t oldmode;
+    Tcl_Obj *tcl_result;
+    char *tcl_mask, *p;
+    const size_t stringlen = 5; /* 4 digits & \0 */
+    int i;
+    mode_t *set;
+    mode_t newmode;
+    mode_t oldmode;
 
-	if (objc != 2) {
-		Tcl_WrongNumArgs(interp, 1, objv, "mode");
-		return TCL_ERROR;
-	}
+    if (objc != 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "mode");
+        return TCL_ERROR;
+    }
 
-	tcl_mask = Tcl_GetString(objv[1]);
-	if ((set = setmode(tcl_mask)) == NULL) {
-		Tcl_SetResult(interp, "Invalid umask mode", TCL_STATIC);
-		return TCL_ERROR;
-	}
+    tcl_mask = Tcl_GetString(objv[1]);
+    if ((set = setmode(tcl_mask)) == NULL) {
+        Tcl_SetResult(interp, "Invalid umask mode", TCL_STATIC);
+        return TCL_ERROR;
+    }
 
-	newmode = getmode(set, 0);
-	free(set);
+    newmode = getmode(set, 0);
+    free(set);
 
-	oldmode = umask(newmode);
+    oldmode = umask(newmode);
 
-	tcl_mask = calloc(1, stringlen); /* 4 digits & \0 */
-	if (!tcl_mask) {
-		return TCL_ERROR;
-	}
+    tcl_mask = calloc(1, stringlen); /* 4 digits & \0 */
+    if (!tcl_mask) {
+        return TCL_ERROR;
+    }
 
-	/* Totally gross and cool */
-	p = tcl_mask + stringlen - 1;
-	for (i = stringlen - 1; i > 0; i--) {
-		p--;
-		*p = (oldmode & 7) + '0';
-		oldmode >>= 3;
-	}
+    /* Totally gross and cool */
+    p = tcl_mask + stringlen - 1;
+    for (i = stringlen - 1; i > 0; i--) {
+        p--;
+        *p = (oldmode & 7) + '0';
+        oldmode >>= 3;
+    }
 
-	tcl_result = Tcl_NewStringObj(p, -1);
-	free(tcl_mask);
+    tcl_result = Tcl_NewStringObj(p, -1);
+    free(tcl_mask);
 
-	Tcl_SetObjResult(interp, tcl_result);
-	return TCL_OK;
+    Tcl_SetObjResult(interp, tcl_result);
+    return TCL_OK;
 }
 
 /**
@@ -400,6 +407,7 @@
 #ifndef __APPLE__
         /* Crashes on Linux without this. */
         setenv("MACPORTS_DUMMY", "", 0);
+        unsetenv("MACPORTS_DUMMY");
 #endif
     } else {
         (void) unsetenv(name);
@@ -464,10 +472,107 @@
     return TCL_OK;
 }
 
+#ifdef __MACH__
+/**
+ * Tcl function to determine whether a file given by path is binary (in terms of being Mach-O)
+ * Defined on Mac-Systems only, because the necessary headers are only available there.
+ *
+ * Synopsis: fileIsBinary filename
+ */
+static int fileIsBinaryCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
+    const char *path;
+    FILE *file;
+    uint32_t magic;
+    struct stat st;
+
+    if (objc != 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "filename");
+        return TCL_ERROR;
+    }
+
+    path = Tcl_GetString(objv[1]);
+    if (-1 == lstat(path, &st)) {
+        /* an error occured */
+        Tcl_SetErrno(errno);
+        Tcl_ResetResult(interp);
+        Tcl_AppendResult(interp, "lstat(", path, "):", (char *)Tcl_PosixError(interp), NULL);
+        return TCL_ERROR;
+    }
+    if (!S_ISREG(st.st_mode)) {
+        /* not a regular file, haven't seen directories which are binaries yet */
+        Tcl_SetObjResult(interp, Tcl_NewBooleanObj(false));
+        return TCL_OK;
+    }
+    if (NULL == (file = fopen(path, "r"))) {
+        Tcl_SetErrno(errno);
+        Tcl_ResetResult(interp);
+        Tcl_AppendResult(interp, "fopen(", path, "): ", (char *)Tcl_PosixError(interp), NULL);
+        return TCL_ERROR;
+    }
+    if (1 != fread(&magic, sizeof(uint32_t), 1, file)) {
+        if (feof(file)) {
+            fclose(file);
+            /* file is shorter than 4 byte, probably not a binary */
+            Tcl_SetObjResult(interp, Tcl_NewBooleanObj(false));
+            return TCL_OK;
+        }
+        /* error while reading */
+        Tcl_SetErrno(errno);
+        Tcl_ResetResult(interp);
+        Tcl_AppendResult(interp, "fread(&magic, 4, 1, ", path, "): ", (char *)Tcl_PosixError(interp), NULL);
+        fclose(file);
+        return TCL_ERROR;
+    }
+    if (magic == MH_MAGIC || magic == MH_MAGIC_64) {
+        fclose(file);
+        /* this is a mach-o file */
+        Tcl_SetObjResult(interp, Tcl_NewBooleanObj(true));
+        return TCL_OK;
+    }
+    if (magic == htonl(FAT_MAGIC)) {
+        uint32_t archcount;
+        /* either universal binary or java class (FAT_MAGIC == 0xcafebabe)
+           see /use/share/file/magic/cafebabe for an explanation of what I'm doing here */
+        if (1 != fread(&archcount, sizeof(uint32_t), 1, file)) {
+            if (feof(file)) {
+                fclose(file);
+                /* file shorter than 8 byte, probably not a binary either */
+                Tcl_SetObjResult(interp, Tcl_NewBooleanObj(false));
+                return TCL_OK;
+            }
+            /* error while reading */
+            Tcl_SetErrno(errno);
+            Tcl_ResetResult(interp);
+            Tcl_AppendResult(interp, "fread(&archcount, 4, 1, ", path, "): ", (char *)Tcl_PosixError(interp), NULL);
+            fclose(file);
+            return TCL_ERROR;
+        }
+
+        /* universal binary header is always big endian */
+        archcount = ntohl(archcount);
+        if (archcount > 0 && archcount < 20) {
+            fclose(file);
+            /* universal binary */
+            Tcl_SetObjResult(interp, Tcl_NewBooleanObj(true));
+            return TCL_OK;
+        }
+
+        fclose(file);
+        /* probably java class */
+        Tcl_SetObjResult(interp, Tcl_NewBooleanObj(false));
+        return TCL_OK;
+    }
+    fclose(file);
+
+    Tcl_SetObjResult(interp, Tcl_NewBooleanObj(false));
+    return TCL_OK;
+}
+#endif
+
 int Pextlib_Init(Tcl_Interp *interp)
 {
-	if (Tcl_InitStubs(interp, "8.4", 0) == NULL)
-		return TCL_ERROR;
+    if (Tcl_InitStubs(interp, "8.4", 0) == NULL)
+        return TCL_ERROR;
 
 	Tcl_CreateObjCommand(interp, "system", SystemCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "flock", FlockCmd, NULL, NULL);
@@ -484,7 +589,11 @@
 	Tcl_CreateObjCommand(interp, "xinstall", InstallCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "fs-traverse", FsTraverseCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "filemap", FilemapCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "rpm-vercomp", RPMVercompCmd, NULL, NULL);
+#if 1
+	/* the name "rpm-vercomp" is deprecated, use "vercmp" instead */
+	Tcl_CreateObjCommand(interp, "rpm-vercomp", VercompCmd, NULL, NULL);
+#endif
+	Tcl_CreateObjCommand(interp, "vercmp", VercompCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "rmd160", RMD160Cmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "sha256", SHA256Cmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "base32encode", Base32EncodeCmd, NULL, NULL);
@@ -497,32 +606,35 @@
 	Tcl_CreateObjCommand(interp, "unsetenv", UnsetEnvCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "lchown", lchownCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "realpath", RealpathCmd, NULL, NULL);
+#ifdef __MACH__
+    Tcl_CreateObjCommand(interp, "fileIsBinary", fileIsBinaryCmd, NULL, NULL);
+#endif
 
-	Tcl_CreateObjCommand(interp, "readline", ReadlineCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "rl_history", RLHistoryCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "readline", ReadlineCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "rl_history", RLHistoryCmd, NULL, NULL);
 
-	Tcl_CreateObjCommand(interp, "getuid", getuidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "geteuid", geteuidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "getgid", getgidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "getegid", getegidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "setuid", setuidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "seteuid", seteuidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "setgid", setgidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "setegid", setegidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "name_to_uid", name_to_uidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "uid_to_name", uid_to_nameCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "uname_to_gid", uname_to_gidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "name_to_gid", name_to_gidCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "gid_to_name", gid_to_nameCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "getuid", getuidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "geteuid", geteuidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "getgid", getgidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "getegid", getegidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "setuid", setuidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "seteuid", seteuidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "setgid", setgidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "setegid", setegidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "name_to_uid", name_to_uidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "uid_to_name", uid_to_nameCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "uname_to_gid", uname_to_gidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "name_to_gid", name_to_gidCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "gid_to_name", gid_to_nameCmd, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "list_dlibs", list_dlibs, NULL, NULL);
 	Tcl_CreateObjCommand(interp, "list_archs", list_archs, NULL, NULL);
 
-	Tcl_CreateObjCommand(interp, "tracelib", TracelibCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "isatty", IsattyCmd, NULL, NULL);
-	Tcl_CreateObjCommand(interp, "term_get_size", TermGetSizeCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "tracelib", TracelibCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "isatty", IsattyCmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "term_get_size", TermGetSizeCmd, NULL, NULL);
 
-	if (Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
-		return TCL_ERROR;
+    if (Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
+        return TCL_ERROR;
 
-	return TCL_OK;
+    return TCL_OK;
 }

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 
@@ -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-post-destroot/base/src/pextlib1.0/base32cmd.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/base32cmd.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/curl.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/curl.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/curl.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -237,6 +237,20 @@
 			break;
 		}
 
+#if LIBCURL_VERSION_NUM >= 0x071304 && LIBCURL_VERSION_NUM <= 0x071307
+        /* FTP_PROXY workaround for Snow Leopard */
+        if (strncmp(theURL, "ftp:", 4) == 0) {
+            char *ftp_proxy = getenv("FTP_PROXY");
+            if (ftp_proxy) {
+                theCurlCode = curl_easy_setopt(theHandle, CURLOPT_PROXY, ftp_proxy);
+                if (theCurlCode != CURLE_OK) {
+                    theResult = SetResultFromCurlErrorCode(interp, theCurlCode);
+                    break;
+                }
+            }
+        }
+#endif
+
 		/* -L option */
 		theCurlCode = curl_easy_setopt(theHandle, CURLOPT_FOLLOWLOCATION, 1);
 		if (theCurlCode != CURLE_OK) {

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -5,7 +5,7 @@
  * Find files and execute arbitrary expressions on them.
  * Author: Jordan K. Hubbard, Kevin Ballard, Rainer Mueller
  *
- * Copyright (c) 2004 Apple Computer, Inc.
+ * Copyright (c) 2004 Apple Inc.
  * Copyright (c) 2010 The MacPorts Project
  * All rights reserved.
  *
@@ -17,7 +17,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 
@@ -146,6 +146,8 @@
             xpath = ".";
         } else if (*(xpath + tlen) == '/') {
             xpath += tlen + 1;
+        } else if (*(target + tlen - 1) == '/') {
+            xpath += tlen;
         }
     }
 
@@ -247,8 +249,14 @@
         }
     }
     /* check errno before calling fts_close in case it sets errno to 0 on success */
-    if (errno != 0 || (fts_close(root_fts) != 0 && !(flags & F_IGNORE_ERRORS))) {
+    if (errno != 0) {
         Tcl_SetErrno(errno);
+        Tcl_ResetResult(interp);
+        Tcl_AppendResult(interp, root_fts->fts_path, ": ", (char *)Tcl_PosixError(interp), NULL);
+        fts_close(root_fts);
+        return TCL_ERROR;
+    } else if (fts_close(root_fts) != 0 && !(flags & F_IGNORE_ERRORS)) {
+        Tcl_SetErrno(errno);
         Tcl_SetResult(interp, (char *)Tcl_PosixError(interp), TCL_STATIC);
         return TCL_ERROR;
     }

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/fs-traverse.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
  * fs-traverse.h
  * $Id$
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
  * md5cmd.c
  * $Id$
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2004 - 2005, 2009, 2011 The MacPorts Project
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/md5cmd.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
  * md5cmd.h
  * $Id$
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/md_wrappers.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/md_wrappers.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/md_wrappers.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,6 +2,7 @@
  * rmd160cmd.c
  * $Id$
  *
+ * Copyright (c) 2006, 2009-2011 The MacPorts Project
  * Copyright (c) 2005 Paul Guyot <pguyot at kallisys.net>.
  * All rights reserved.
  *
@@ -13,7 +14,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/rmd160cmd.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,7 +3,8 @@
  * $Id$
  * Copied from md5cmd.c 20040903 EH
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2004 - 2005, 2009 - 2011 The MacPorts Project
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/sha1cmd.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,7 +3,7 @@
  * $Id$
  * Copied from md5cmd.h 20040903 EH
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -14,7 +14,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 


Property changes on: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha2.c
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.c:37343-46937
/branches/universal-sanity/base/src/pextlib1.0/sha2.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.c:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.c:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.c:37343-46937
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha2.c:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/sha2.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha2.c:78761-98879
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.c:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.c:44044-44692


Property changes on: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha2.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.h:37343-46937
/branches/universal-sanity/base/src/pextlib1.0/sha2.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.h:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.h:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/sha2.h:37343-46937
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha2.h:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/sha2.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/sha2.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha2.h:78761-98879
/users/perry/base-bugs_and_notes/src/pextlib1.0/sha2.h:45682-46060
/users/perry/base-select/src/pextlib1.0/sha2.h:44044-44692

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
  * sha256cmd.c
  * $Id$
  *
- * Copyright (c) 2009 The MacPorts Project
+ * Copyright (c) 2009, 2011 The MacPorts Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 


Property changes on: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.c
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.c:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.c:51231-60371
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.c:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.c:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.c:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.c:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha256cmd.c:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.c:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.c:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha256cmd.c:78761-98879
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.c:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.c:44044-44692

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -13,7 +13,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 


Property changes on: branches/gsoc11-post-destroot/base/src/pextlib1.0/sha256cmd.h
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.h:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.h:51231-60371
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.h:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.h:44044-44692
   + /branches/gsoc08-privileges/base/src/pextlib1.0/rmd160cmd.h:37343-46937
/branches/gsoc09-logging/base/src/pextlib1.0/sha256cmd.h:51231-60371
/branches/gsoc11-rev-upgrade/base/src/pextlib1.0/sha256cmd.h:78828-88375
/branches/universal-sanity/base/src/pextlib1.0/rmd160cmd.h:51872-52323
/branches/variant-descs-14482/base/src/pextlib1.0/rmd160cmd.h:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/pextlib1.0/sha256cmd.h:78761-98879
/users/perry/base-bugs_and_notes/src/pextlib1.0/rmd160cmd.h:45682-46060
/users/perry/base-select/src/pextlib1.0/rmd160cmd.h:44044-44692

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/system.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/system.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/system.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/pextlib1.0/tests/base32.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/base32.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/base32.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/pextlib1.0/tests/curl.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/curl.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/curl.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -24,8 +24,8 @@
 	test {![curl isnewer $dummyroot/dummy [clock scan 2007-06-17Z]]}
 	
 	# use --disable-epsv
-	curl fetch --disable-epsv ftp://ftp.cup.hp.com/dist/networking/benchmarks/netperf/archive/netperf-2.2pl5.tar.gz $tempfile
-	test {[md5 file $tempfile] == "a4b0f4a5fbd8bec23002ad8023e01729"}
+	#curl fetch --disable-epsv ftp://ftp.cup.hp.com/dist/networking/benchmarks/netperf/archive/netperf-2.2pl5.tar.gz $tempfile
+	#test {[md5 file $tempfile] == "a4b0f4a5fbd8bec23002ad8023e01729"}
 	
 	# use -u
 	# This URL does not work anymore, disabled the test

Copied: branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/vercomp.tcl (from rev 98879, trunk/base/src/pextlib1.0/tests/vercomp.tcl)
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/vercomp.tcl	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/tests/vercomp.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,47 @@
+# Test file for Pextlib's vercmp command.
+# Syntax:
+# tclsh vercomp.tcl <Pextlib name>
+
+proc main {pextlibname} {
+	load $pextlibname
+	
+	# 2.0 > 1.0
+	if {[vercmp 2.0 1.0] <= 0} {
+		puts {[vercmp 2.0 1.0] <= 0}
+		exit 1
+	}
+	# 1.0 = 1.0
+	if {[vercmp 1.0 1.0] != 0} {
+		puts {[vercmp 1.0 1.0] != 0}
+		exit 1
+	}
+	# 1.0 < 2.0
+	if {[vercmp 1.0 2.0] >= 0} {
+		puts {[vercmp 1.0 2.0] >= 0}
+		exit 1
+	}
+
+	# def > abc
+	if {[vercmp def abc] <= 0} {
+		puts {[vercmp def abc] <= 0}
+		exit 1
+	}
+	# abc = abc
+	if {[vercmp abc abc] != 0} {
+		puts {[vercmp abc abc] != 0}
+		exit 1
+	}
+	# abc < def
+	if {[vercmp abc def] >= 0} {
+		puts {[vercmp abc def] >= 0}
+		exit 1
+	}
+
+	# a < 1 (digits beats alpha)
+	if {[vercmp a 1] >= 0} {
+		puts {[vercmp a 1] >= 0}
+		exit 1
+	}
+}
+
+main $argv

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/tracelib.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/tracelib.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/tracelib.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/pextlib1.0/tty.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -5,6 +5,7 @@
  *
  * Author: Rainer Mueller <raimue at macports.org>
  *
+ * Copyright (c) 2009 The MacPorts Project
  * Copyright (c) 2008 Rainer Mueller <raimue at macports.org>
  * All rights reserved.
  *
@@ -16,7 +17,7 @@
  * 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 Computer, Inc. nor the names of its
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/tty.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -16,7 +16,7 @@
  * 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 Computer, Inc. nor the names of its
+ * 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.
  * 

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,11 +1,11 @@
 /*
  * vercomp.c
  * $Id$
- * RPM compatible version comparison
+ * version comparison
  *
  * Author: Landon Fuller <landonf at macports.org>
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * Copyright (c) 2004 Landon Fuller <landonf at macports.org>
  * All rights reserved.
  *
@@ -17,7 +17,7 @@
  * 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 Computer, Inc. nor the names of its
+ * 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.
  * 
@@ -48,10 +48,10 @@
 /*
  * If A is newer than B, return an integer > 0
  * If A and B are equal, return 0
- * If B is newer than A, retun an integer < 0
+ * If B is newer than A, return an integer < 0
  */
 
-static int rpm_vercomp (const char *versionA, const char *versionB) {
+static int vercmp (const char *versionA, const char *versionB) {
 	const char *ptrA, *ptrB;
 	const char *eptrA, *eptrB;
 
@@ -155,7 +155,7 @@
 		return -1;
 }
 
-int RPMVercompCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
+int VercompCmd(ClientData clientData UNUSED, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
 {
 	Tcl_Obj *tcl_result;
 	const char *versionA, *versionB;
@@ -169,7 +169,7 @@
 	versionA = Tcl_GetString(objv[1]);
 	versionB = Tcl_GetString(objv[2]);
 
-	rval = rpm_vercomp(versionA, versionB);
+	rval = vercmp(versionA, versionB);
 
 	tcl_result = Tcl_NewIntObj(rval);
 	Tcl_SetObjResult(interp, tcl_result);

Modified: branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pextlib1.0/vercomp.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,7 +3,7 @@
  * $Id$
  * Author: Landon Fuller <landonf at macports.org>
  *
- * Copyright (c) 2002 - 2003 Apple Computer, Inc.
+ * Copyright (c) 2002 - 2003 Apple Inc.
  * Copyright (c) 2004 Landon Fuller
  * All rights reserved.
  *
@@ -15,7 +15,7 @@
  * 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 Computer, Inc. nor the names of its contributors
+ * 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.
  * 
@@ -32,4 +32,4 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-int RPMVercompCmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
+int VercompCmd(ClientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);

Modified: branches/gsoc11-post-destroot/base/src/pkg_mkindex.sh.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/pkg_mkindex.sh.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/pkg_mkindex.sh.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -12,7 +12,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/port/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/port/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -22,7 +22,8 @@
 	${edit} port.tcl > $@
 
 mkdirs:
-	<../../doc/prefix.mtree $(MTREE) -U -d -e -p ${INSTALLDIR} > /dev/null
+	< ../../doc/prefix.mtree $(MTREE) -U -d -e -p ${INSTALLDIR} > /dev/null
+	< ../../doc/base.mtree $(MTREE) -U -d -e -p ${INSTALLDIR} > /dev/null
 
 clean:
 	rm -f ${SCRIPTS}

Modified: branches/gsoc11-post-destroot/base/src/port/port-help.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port/port-help.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port/port-help.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -135,8 +135,6 @@
 Edit given ports
 }
 
-set porthelp(ed) $porthelp(edit)
-
 set porthelp(exit) {
 Exit port
 
@@ -253,6 +251,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
 }
@@ -277,7 +291,7 @@
 specifying any version.
 
 One example is the set of python ports, where there are (among others)
-python25, python26, and python30.  The select action lets you set which
+python25, python26, and python31.  The select action lets you set which
 of these becomes the version run when you simply use 'python'.
 
 <arguments> must include the group upon which to be acted, and may include
@@ -293,6 +307,13 @@
 Upgrade MacPorts itself and run the sync target
 }
 
+set porthelp(space) {
+Show the disk space used by the given ports
+
+--units <units> Specify units to use. Accepted units are: B, kB, KiB, MB, MiB,
+                GB, GiB. The 'B' may be omitted.
+}
+
 set porthelp(srpm) {
 Creates a srpm for each of the given ports
 }
@@ -324,7 +345,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-post-destroot/base/src/port/port.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port/port.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port/port.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -5,9 +5,9 @@
 # port.tcl
 # $Id$
 #
-# Copyright (c) 2002-2007 The MacPorts Project.
+# Copyright (c) 2004-2012 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002-2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -18,7 +18,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -87,8 +87,8 @@
 ----------------
 Pseudo-portnames are words that may be used in place of a portname, and
 which expand to some set of ports. The common pseudo-portnames are:
-all, current, active, inactive, installed, uninstalled, outdated, obsolete,
-requested, unrequested and leaves.
+all, current, active, inactive, actinact, installed, uninstalled, outdated,
+obsolete, requested, unrequested and leaves.
 These pseudo-portnames expand to the set of ports named.
 
 Pseudo-portnames starting with variants:, variant:, description:, depends:,
@@ -154,7 +154,58 @@
 }
 
 
+# Format an integer representing bytes using given units
+proc bytesize {siz {unit {}}} {
+    if {$unit == {}} {
+        if {$siz > 0x40000000} {
+            set unit "GiB"
+        } elseif {$siz > 0x100000} {
+            set unit "MiB"
+        } elseif {$siz > 0x400} {
+            set unit "KiB"
+        } else {
+            set unit "B"
+        }
+    }
+    switch -- $unit {
+        KiB {
+            set siz [expr $siz / 1024.0]
+        }
+        kB {
+            set siz [expr $siz / 1000.0]
+        }
+        MiB {
+            set siz [expr $siz / 1048576.0]
+        }
+        MB {
+            set siz [expr $siz / 1000000.0]
+        }
+        GiB {
+            set siz [expr $siz / 1073741824.0]
+        }
+        GB {
+            set siz [expr $siz / 1000000000.0]
+        }
+        B { }
+        default {
+            ui_warn "Unknown file size unit '$unit' specified"
+            set unit "B"
+        }
+    }
+    if {[expr round($siz)] != $siz} {
+        set siz [format {%.3f} $siz]
+    }
+    return "$siz $unit"
+}
 
+proc filesize {fil {unit {}}} {
+    set siz {@}
+    catch {
+        set siz [bytesize [file size $fil] $unit]
+    }
+    return $siz
+}
+
 # Produce an error message, and exit, unless
 # we're handling errors in a soft fashion, in which
 # case we continue
@@ -185,7 +236,9 @@
 
 # show the URL for the ticket reporting instructions
 proc print_tickets_url {args} {
-    ui_notice "To report a bug, see <http://guide.macports.org/#project.tickets>"
+    if {${macports::prefix} != "/usr/local" && ${macports::prefix} != "/usr"} {
+        ui_notice "To report a bug, follow the instructions in the guide:\n    http://guide.macports.org/#project.tickets"
+    }
 }
 
 # Form a composite version as is sometimes used for registry functions
@@ -281,11 +334,10 @@
 }
 
 
-proc add_to_portlist {listname portentry} {
-    upvar $listname portlist
+proc entry_for_portlist {portentry} {
     global global_options global_variations
 
-    # The portlist currently has the following elements in it:
+    # Each portlist entry currently has the following elements in it:
     #   url             if any
     #   name
     #   version         (version_revision)
@@ -313,15 +365,21 @@
         }
     }
 
-
     # Form the fully discriminated portname: portname/version_revison+-variants
     set port(fullname) "$port(name)/[composite_version $port(version) $port(variants)]"
     
-    # Add it to our portlist
-    lappend portlist [array get port]
+    return [array get port]
 }
 
 
+proc add_to_portlist {listname portentry} {
+    upvar $listname portlist
+    
+    # Form portlist entry and add to portlist
+    lappend portlist [entry_for_portlist $portentry]
+}
+
+
 proc add_ports_to_portlist {listname ports {overridelist ""}} {
     upvar $listname portlist
 
@@ -429,9 +487,9 @@
     }
     set avr_ [split $a_(version) "_"]
     set bvr_ [split $b_(version) "_"]
-    set vercmp [rpm-vercomp [lindex $avr_ 0] [lindex $bvr_ 0]]
-    if {$vercmp != 0} {
-        return $vercmp
+    set versioncmp [vercmp [lindex $avr_ 0] [lindex $bvr_ 0]]
+    if {$versioncmp != 0} {
+        return $versioncmp
     }
     set ar_ [lindex $avr_ 1]
     set br_ [lindex $bvr_ 1]
@@ -460,6 +518,43 @@
     return [lsort -command portlist_compareint $list]
 }
 
+# sort portlist so dependents come before their dependencies
+proc portlist_sortdependents { portlist } {
+    foreach p $portlist {
+        array set pvals $p
+        lappend entries($pvals(name)) $p
+        if {![info exists dependents($pvals(name))]} {
+            set dependents($pvals(name)) {}
+            foreach result [registry::list_dependents $pvals(name)] {
+                lappend dependents($pvals(name)) [lindex $result 2]
+            }
+        }
+        array unset pvals
+    }
+    set ret {}
+    foreach p $portlist {
+        portlist_sortdependents_helper $p entries dependents seen ret
+    }
+    return $ret
+}
+
+proc portlist_sortdependents_helper {p up_entries up_dependents up_seen up_retlist} {
+    upvar $up_seen seen
+    if {![info exists seen($p)]} {
+        set seen($p) 1
+        upvar $up_entries entries $up_dependents dependents $up_retlist retlist
+        array set pvals $p
+        foreach dependent $dependents($pvals(name)) {
+            if {[info exists entries($dependent)]} {
+                foreach entry $entries($dependent) {
+                    portlist_sortdependents_helper $entry entries dependents seen retlist
+                }
+            }
+        }
+        lappend retlist $p
+    }
+}
+
 proc regex_pat_sanitize { s } {
     set sanitized [regsub -all {[\\(){}+$.^]} $s {\\&}]
     return $sanitized
@@ -596,30 +691,35 @@
 ##########################################
 # Port selection
 ##########################################
+proc unique_results_to_portlist {infos} {
+    set result {}
+    array unset unique
+    foreach {name info} $infos {
+        array unset portinfo
+        array set portinfo $info
+        
+        set portentry [entry_for_portlist [list url $portinfo(porturl) name $name]]
+        
+        array unset entry
+        array set entry $portentry
+        
+        if {[info exists unique($entry(fullname))]} continue
+        set unique($entry(fullname)) 1
+        
+        lappend result $portentry
+    }
+    return $result
+}
+
+
 proc get_matching_ports {pattern {casesensitive no} {matchstyle glob} {field name}} {
     if {[catch {set res [mportsearch $pattern $casesensitive $matchstyle $field]} result]} {
         global errorInfo
         ui_debug "$errorInfo"
         fatal "search for portname $pattern failed: $result"
     }
-
-    set results {}
-    foreach {name info} $res {
-        array unset portinfo
-        array set portinfo $info
-
-        #set variants {}
-        #if {[info exists portinfo(variants)]} {
-        #   foreach variant $portinfo(variants) {
-        #       lappend variants $variant "+"
-        #   }
-        #}
-        # For now, don't include version or variants with all ports list
-        #"$portinfo(version)_$portinfo(revision)"
-        #$variants
-        add_to_portlist results [list url $portinfo(porturl) name $name]
-    }
-
+    set results [unique_results_to_portlist $res]
+    
     # Return the list of all ports, sorted
     return [portlist_sort $results]
 }
@@ -634,13 +734,7 @@
             ui_debug "$errorInfo"
             fatal "listing all ports failed: $result"
         }
-        set results {}
-        foreach {name info} $res {
-            array unset portinfo
-            array set portinfo $info
-            add_to_portlist results [list url $portinfo(porturl) name $name]
-        }
-
+        set results [unique_results_to_portlist $res]
         set all_ports_cache [portlist_sort $results]
     }
     return $all_ports_cache
@@ -713,7 +807,35 @@
     return [get_installed_ports no no]
 }
 
+proc get_actinact_ports {} {
+    set inactive_ports [get_inactive_ports]
+    set active_ports [get_active_ports]
+    set results {}
 
+    foreach port $inactive_ports {
+        array set portspec $port
+        set portname $portspec(name)
+        lappend inact($portname) $port
+    }
+
+    foreach port $active_ports {
+        array set portspec $port
+        set portname $portspec(name)
+
+        if {[info exists inact($portname)]} {
+            if {![info exists added_inact($portname)]} {
+                foreach inact_spec $inact($portname) {
+                    lappend results $inact_spec
+                }
+                set added_inact($portname) 1
+            }
+            lappend results $port
+        }
+    }
+    return $results
+}
+
+
 proc get_outdated_ports {} {
     # Get the list of installed ports
     set ilist {}
@@ -774,7 +896,7 @@
             if {$installed_version != $latest_version} {
                 set comp_result [expr $installed_epoch - $latest_epoch]
                 if { $comp_result == 0 } {
-                    set comp_result [rpm-vercomp $installed_version $latest_version]
+                    set comp_result [vercmp $installed_version $latest_version]
                 }
             }
             if { $comp_result == 0 } {
@@ -933,7 +1055,7 @@
     set porturl $portinfo(porturl)
 
     # open portfile
-    if {[catch {set mport [mportopen $porturl [list subport $portname] [array get global_variations]]} result]} {
+    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"
     }
@@ -979,7 +1101,7 @@
                     set porturl $portinfo(porturl)
                 
                     # open its portfile
-                    if {[catch {set mport [mportopen $porturl [list subport $depname] [array get global_variations]]} result]} {
+                    if {[catch {set mport [mportopen $porturl [list subport $portinfo(name)] [array get global_variations]]} result]} {
                         ui_debug "$::errorInfo"
                         ui_error "Unable to open port: $result"
                         continue
@@ -1050,7 +1172,7 @@
             set reslist [opUnion $reslist $blist]
         }
     }
-
+    
     return $result
 }
 
@@ -1163,6 +1285,7 @@
         ^uninstalled(@.*)?$ -
         ^active(@.*)?$      -
         ^inactive(@.*)?$    -
+        ^actinact(@.*)?$    -
         ^leaves(@.*)?$      -
         ^outdated(@.*)?$    -
         ^obsolete(@.*)?$    -
@@ -1200,6 +1323,7 @@
         ^depends_run:       -
         ^depends_extract:   -
         ^depends_fetch:     -
+        ^replaced_by:       -
         ^revision:          -
         ^license:           { # Handle special port selectors
             advance
@@ -1317,22 +1441,28 @@
 }
 
 
-proc opUnion { a b } {
+proc unique_entries { entries } {
+    # Form the list of all the unique elements in the list a,
+    # considering only the port fullname, and taking the first
+    # found element first
     set result {}
-    
-    # Walk through both lists a and b, adding to result only unique ports
     array unset unique
-    foreach item [concat $a $b] {
+    foreach item $entries {
         array set port $item
         if {[info exists unique($port(fullname))]} continue
         set unique($port(fullname)) 1
         lappend result $item
     }
-    
     return $result
 }
 
 
+proc opUnion { a b } {
+    # Return the unique elements in the combined two lists
+    return [unique_entries [concat $a $b]]
+}
+
+
 proc opIntersection { a b } {
     set result {}
     
@@ -1350,14 +1480,14 @@
     # First create a list of the fully discriminated names in b
     array unset bfull
     set i 0
-    foreach bitem $b {
+    foreach bitem [unique_entries $b] {
         array set port $bitem
         set bfull($port(fullname)) $i
         incr i
     }
     
     # Walk through each item in a, matching against b
-    foreach aitem $a {
+    foreach aitem [unique_entries $a] {
         array set port $aitem
         
         # Quote the fullname and portname to avoid special characters messing up the regexp
@@ -1692,6 +1822,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
@@ -1709,7 +1840,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"]
@@ -1766,6 +1904,7 @@
             set index_only 1
         }
         puts -nonewline $separator
+        array unset portinfo
         # If we have a url, use that, since it's most specific
         # otherwise try to map the portname to a url
         if {$porturl == "" || $index_only} {
@@ -1777,7 +1916,6 @@
             if {[llength $result] < 2} {
                 break_softcontinue "Port $portname not found" 1 status
             }
-            array unset portinfo
             array set portinfo [lindex $result 1]
             set porturl $portinfo(porturl)
             set portdir $portinfo(portdir)
@@ -1794,7 +1932,11 @@
                 } 
             }
             if {![info exists options(subport)]} {
-                set options(subport) $portname
+                if {[info exists portinfo(name)]} {
+                    set options(subport) $portinfo(name)
+                } else {
+                    set options(subport) $portname
+                }
             }
  
             if {[catch {set mport [mportopen $porturl [array get options] [array get merged_variations]]} result]} {
@@ -1889,7 +2031,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
@@ -2010,7 +2152,7 @@
                             array unset variant
                             array set variant $vinfo($v)
                             if {[info exists variant(is_default)]} {
-                                set varmodifier "\[+]"
+                                set varmodifier "\[$variant(is_default)]"
                             }
                         }
                         lappend inf "$varmodifier$v"
@@ -2119,6 +2261,7 @@
 
     set status 0
     foreachport $portlist {
+        array unset portinfo
         if {$porturl eq ""} {
             # Look up the port.
             if {[catch {mportlookup $portname} result]} {
@@ -2131,7 +2274,6 @@
             }
 
             # Retrieve the port's URL.
-            array unset portinfo
             array set portinfo [lindex $result 1]
             set porturl $portinfo(porturl)
         }
@@ -2146,7 +2288,11 @@
             } 
         }
         if {![info exists options(subport)]} {
-            set options(subport) $portname
+            if {[info exists portinfo(name)]} {
+                set options(subport) $portinfo(name)
+            } else {
+                set options(subport) $portname
+            }
         }
 
         # Open the Portfile associated with this port.
@@ -2217,15 +2363,13 @@
 
 
 proc action_activate { action portlist opts } {
-    global macports::registry.format
     set status 0
     if {[require_portlist portlist] || [prefix_unwritable]} {
         return 1
     }
     foreachport $portlist {
         set composite_version [composite_version $portversion [array get variations]]
-        if {${macports::registry.format} == "receipt_sqlite"
-            && ![info exists options(ports_activate_no-exec)]
+        if {![info exists options(ports_activate_no-exec)]
             && ![catch {set ilist [registry::installed $portname $composite_version]}]
             && [llength $ilist] == 1} {
 
@@ -2236,7 +2380,7 @@
             }
         }
         if {![macports::global_option_isset ports_dryrun]} {
-            if { [catch {portimage::activate $portname $composite_version [array get options]} result] } {
+            if { [catch {portimage::activate_composite $portname $composite_version [array get options]} result] } {
                 global errorInfo
                 ui_debug "$errorInfo"
                 break_softcontinue "port activate failed: $result" 1 status
@@ -2251,15 +2395,14 @@
 
 
 proc action_deactivate { action portlist opts } {
-    global macports::registry.format
     set status 0
     if {[require_portlist portlist] || [prefix_unwritable]} {
         return 1
     }
+    set portlist [portlist_sortdependents $portlist]
     foreachport $portlist {
         set composite_version [composite_version $portversion [array get variations]]
-        if {${macports::registry.format} == "receipt_sqlite"
-            && ![info exists options(ports_deactivate_no-exec)]
+        if {![info exists options(ports_deactivate_no-exec)]
             && ![catch {set ilist [registry::active $portname]}]} {
 
             set i [lindex $ilist 0]
@@ -2274,7 +2417,7 @@
             }
         }
         if {![macports::global_option_isset ports_dryrun]} {
-            if { [catch {portimage::deactivate $portname $composite_version [array get options]} result] } {
+            if { [catch {portimage::deactivate_composite $portname $composite_version [array get options]} result] } {
                 global errorInfo
                 ui_debug "$errorInfo"
                 break_softcontinue "port deactivate failed: $result" 1 status
@@ -2298,7 +2441,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} {
@@ -2412,7 +2557,6 @@
 
 
 proc action_setrequested { action portlist opts } {
-    global macports::registry.format
     set status 0
     if {[require_portlist portlist] || [prefix_unwritable]} {
         return 1
@@ -2426,9 +2570,6 @@
             foreach i $ilist {
                 set regref [registry::open_entry $portname [lindex $i 1] [lindex $i 2] [lindex $i 3] [lindex $i 5]]
                 registry::property_store $regref requested $val
-                if {${macports::registry.format} != "receipt_sqlite"} {
-                    registry::write_entry $regref
-                }
             }
         } else {
             global errorInfo
@@ -2445,6 +2586,7 @@
     if {[require_portlist portlist] || ([prefix_unwritable] && ![macports::global_option_isset ports_dryrun])} {
         return 1
     }
+
     # shared depscache for all ports in the list
     array set depscache {}
     set status 0
@@ -2460,12 +2602,25 @@
     
     if {$status != 0} {
         print_tickets_url
+    } else {
+        array set options $opts
+        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]
+        }
     }
 
     return $status
 }
 
+proc action_revupgrade { action portlist opts } {
+    set status [macports::revupgrade $opts]
+    if {$status != 0} {
+        print_tickets_url
+    }
+    return $status
+}
 
+
 proc action_version { action portlist opts } {
     puts "Version: [macports::version]"
     return 0
@@ -2603,7 +2758,8 @@
         } else {
             set deptypes {depends_fetch depends_extract depends_build depends_lib depends_run}
         }
-        
+
+        array unset portinfo
         # If we have a url, use that, since it's most specific
         # otherwise try to map the portname to a url
         if {$porturl eq ""} {
@@ -2615,7 +2771,6 @@
             if {[llength $result] < 2} {
                 break_softcontinue "Port $portname not found" 1 status
             }
-            array unset portinfo
             array set portinfo [lindex $result 1]
             set porturl $portinfo(porturl)
         } elseif {$porturl ne "file://."} {
@@ -2634,8 +2789,13 @@
             if {[llength $result] < 2} {
                 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]
+            }
         }
 
         if {!([info exists options(ports_${action}_index)] && $options(ports_${action}_index) eq "yes")} {
@@ -2649,7 +2809,11 @@
                 } 
             }
             if {![info exists options(subport)]} {
-                set options(subport) $portname
+                if {[info exists portinfo(name)]} {
+                    set options(subport) $portinfo(name)
+                } else {
+                    set options(subport) $portname
+                }
             }
             if {[catch {set mport [mportopen $porturl [array get options] [array get merged_variations]]} result]} {
                 ui_debug "$::errorInfo"
@@ -2729,7 +2893,7 @@
                     array unset portinfo
                     array set portinfo [lindex $result 1]
                     set porturl $portinfo(porturl)
-                    set options(subport) $depname
+                    set options(subport) $portinfo(name)
                     
                     # open the portfile if requested
                     if {!([info exists options(ports_${action}_index)] && $options(ports_${action}_index) eq "yes")} {
@@ -2809,7 +2973,6 @@
 
 
 proc action_uninstall { action portlist opts } {
-    global macports::registry.format
     set status 0
     if {[macports::global_option_isset port_uninstall_old]} {
         # if -u then uninstall all inactive ports
@@ -2825,14 +2988,15 @@
         return 1
     }
 
+    set portlist [portlist_sortdependents $portlist]
+
     foreachport $portlist {
         if {![registry::entry_exists_for_name $portname]} {
             ui_info "$portname is already uninstalled"
             continue
         }
         set composite_version [composite_version $portversion [array get variations]]
-        if {${macports::registry.format} == "receipt_sqlite"
-            && ![info exists options(ports_uninstall_no-exec)]
+        if {![info exists options(ports_uninstall_no-exec)]
             && ![catch {set ilist [registry::installed $portname $composite_version]}]
             && [llength $ilist] == 1} {
 
@@ -2844,7 +3008,7 @@
             }
         }
 
-        if { [catch {registry_uninstall::uninstall $portname $composite_version [array get options]} result] } {
+        if { [catch {registry_uninstall::uninstall_composite $portname $composite_version [array get options]} result] } {
             global errorInfo
             ui_debug "$errorInfo"
             break_softcontinue "port uninstall failed: $result" 1 status
@@ -3006,7 +3170,7 @@
             
             # Compare versions, first checking epoch, then version, then revision
             set epoch_comp_result [expr $installed_epoch - $latest_epoch]
-            set comp_result [rpm-vercomp $installed_version $latest_version]
+            set comp_result [vercmp $installed_version $latest_version]
             if { $comp_result == 0 } {
                 set comp_result [expr $installed_revision - $latest_revision]
             }
@@ -3068,10 +3232,20 @@
 
 
 proc action_contents { action portlist opts } {
-    set status 0
+    global global_options
     if {[require_portlist portlist]} {
         return 1
     }
+    if {[info exists global_options(ports_contents_size)]} {
+        set units {}
+        if {[info exists global_options(ports_contents_units)]} {
+            set units [complete_size_units $global_options(ports_contents_units)]
+        }
+        set outstring {[format "%12s $file" [filesize $file $units]]}
+    } else {
+        set outstring {  $file}
+    }
+
     foreachport $portlist {
         if { ![catch {set ilist [registry::installed $portname]} result] } {
             # set portname again since the one we were passed may not have had the correct case
@@ -3082,7 +3256,7 @@
             if { [llength $files] > 0 } {
                 ui_notice "Port $portname contains:"
                 foreach file $files {
-                    puts "  $file"
+                    puts [subst $outstring]
                 }
             } else {
                 ui_notice "Port $portname does not contain any files or is not active."
@@ -3093,9 +3267,67 @@
     }
     registry::close_file_map
 
-    return $status
+    return 0
 }
 
+# expand abbreviations of size units
+proc complete_size_units {units} {
+    if {$units == "K" || $units == "Ki"} {
+        return "KiB"
+    } elseif {$units == "k"} {
+        return "kB"
+    } elseif {$units == "Mi"} {
+        return "MiB"
+    } elseif {$units == "M"} {
+        return "MB"
+    } elseif {$units == "Gi"} {
+        return "GiB"
+    } elseif {$units == "G"} {
+        return "GB"
+    } else {
+        return $units
+    }
+}
+
+# Show space used by the given ports' files
+proc action_space {action portlist opts} {
+    global global_options
+    require_portlist portlist
+
+    set units {}
+    if {[info exists global_options(ports_space_units)]} {
+        set units [complete_size_units $global_options(ports_space_units)]
+    }
+    set spaceall 0.0
+    foreachport $portlist {
+        set space 0.0
+        set files [registry::port_registered $portname]
+        if { $files != 0 } {
+            if { [llength $files] > 0 } {
+                foreach file $files {
+                    catch {
+                        set space [expr $space + [file size $file] ]
+                    }
+                }
+                set msg "[bytesize $space $units] $portname"
+                if { $portversion != {} } {
+                    append msg " @$portversion"
+                }
+                puts $msg
+                set spaceall [expr $space + $spaceall]
+            } else {
+                puts "Port $portname does not contain any file or is not active."
+            }
+        } else {
+            puts "Port $portname is not installed."
+        }
+    }
+    if {[llength $portlist] > 1} {
+        puts "[bytesize $spaceall $units] total"
+    }
+    return 0
+}
+
 proc action_variants { action portlist opts } {
     global global_variations
     set status 0
@@ -3103,6 +3335,7 @@
         return 1
     }
     foreachport $portlist {
+        array unset portinfo
         if {$porturl eq ""} {
             # look up port
             if {[catch {mportlookup $portname} result]} {
@@ -3114,7 +3347,6 @@
                 break_softcontinue "Port $portname not found" 1 status
             }
 
-            array unset portinfo
             array set portinfo [lindex $result 1]
 
             set porturl $portinfo(porturl)
@@ -3123,7 +3355,11 @@
 
         if {!([info exists options(ports_variants_index)] && $options(ports_variants_index) eq "yes")} {
             if {![info exists options(subport)]} {
-                set options(subport) $portname
+                if {[info exists portinfo(name)]} {
+                    set options(subport) $portinfo(name)
+                } else {
+                    set options(subport) $portname
+                }
             }
             if {[catch {set mport [mportopen $porturl [array get options] [array get variations]]} result]} {
                 ui_debug "$::errorInfo"
@@ -3160,6 +3396,7 @@
             ui_notice "$portname has the variants:"
             foreach v [lsort $portinfo(variants)] {
                 unset -nocomplain vconflicts vdescription vrequires
+                set varmodifier "   "
                 # Retrieve variants' information from the new format.
                 if {[info exists vinfo]} {
                     array unset variant
@@ -3181,9 +3418,7 @@
                         # selected by variants.conf, prefixed with (+)/(-)
                         set varmodifier "($global_variations($v))"
                     } elseif {[info exists variant(is_default)]} {
-                        set varmodifier "\[+]"
-                    } else {
-                        set varmodifier "   "
+                        set varmodifier "\[$variant(is_default)\]"
                     }
                     if {[info exists variant(requires)]} {
                         set vrequires $variant(requires)
@@ -3326,7 +3561,13 @@
             } 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
 
@@ -3402,12 +3643,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]
@@ -3453,6 +3698,7 @@
             }
             array set portinfo [lindex $res 1]
             set porturl $portinfo(porturl)
+            set portname $portinfo(name)
         }
         
         
@@ -3473,7 +3719,7 @@
                     close $f
                 }
                 
-                ed - edit {
+                edit {
                     # Edit the port's portfile with the user's editor
                     
                     # Restore our entire environment from start time.
@@ -3619,6 +3865,7 @@
         return 1
     }
     foreachport $portlist {
+        array unset portinfo
         # If we have a url, use that, since it's most specific
         # otherwise try to map the portname to a url
         if {$porturl == ""} {
@@ -3637,7 +3884,6 @@
                     break_softcontinue "Port $portname not found" 1 status
                 }
             }
-            array unset portinfo
             array set portinfo [lindex $res 1]
             set porturl $portinfo(porturl)
         }
@@ -3672,7 +3918,11 @@
             set target $action
         }
         if {![info exists options(subport)]} {
-            set options(subport) $portname
+            if {[info exists portinfo(name)]} {
+                set options(subport) $portinfo(name)
+            } else {
+                set options(subport) $portname
+            }
         }
         if {[catch {set workername [mportopen $porturl [array get options] [array get requested_variations]]} result]} {
             global errorInfo
@@ -3690,12 +3940,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
@@ -3779,6 +4033,7 @@
     unsetrequested [list action_setrequested  [ACTION_ARGS_PORTS]] \
     \
     upgrade     [list action_upgrade        [ACTION_ARGS_PORTS]] \
+    rev-upgrade [list action_revupgrade     [ACTION_ARGS_NONE]] \
     \
     version     [list action_version        [ACTION_ARGS_NONE]] \
     platform    [list action_platform       [ACTION_ARGS_NONE]] \
@@ -3788,6 +4043,7 @@
     installed   [list action_installed      [ACTION_ARGS_PORTS]] \
     outdated    [list action_outdated       [ACTION_ARGS_PORTS]] \
     contents    [list action_contents       [ACTION_ARGS_PORTS]] \
+    space       [list action_space          [ACTION_ARGS_PORTS]] \
     dependents  [list action_dependents     [ACTION_ARGS_PORTS]] \
     rdependents [list action_dependents     [ACTION_ARGS_PORTS]] \
     deps        [list action_deps           [ACTION_ARGS_PORTS]] \
@@ -3797,7 +4053,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]] \
@@ -3843,17 +4098,51 @@
     exit        [list action_exit           [ACTION_ARGS_NONE]] \
 ]
 
+# Expand "action".
+# Returns an action proc, or a list of matching action procs, or the action passed in
+proc find_action { action } {
+    global action_array
+    
+    if { ! [info exists action_array($action)] } {
+        set guess [guess_action $action]
+        if { [info exists action_array($guess)] } {
+            return $guess
+        }
+        return $guess
+    }
+    
+    return $action
+}
+
+# Expand action
+# If there's more than one match, return the next possibility
 proc find_action_proc { action } {
     global action_array
     
     set action_proc ""
     if { [info exists action_array($action)] } {
         set action_proc [lindex $action_array($action) 0]
+    } else {
+        set action [complete_action $action]
+        if { [info exists action_array($action)] } {
+            set action_proc [lindex $action_array($action) 0]
+        }
     }
     
     return $action_proc
 }
 
+proc get_action_proc { action } {
+    global action_array
+    
+    set action_proc ""
+    if { [info exists action_array($action)] } {
+        set action_proc [lindex $action_array($action) 0]
+    }
+    
+    return $action_proc
+}
+
 # Returns whether an action expects text arguments at all,
 # expects text arguments or wants an expanded list of ports
 # Return values are constants:
@@ -3879,13 +4168,13 @@
 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
                  line long_description
                  maintainer maintainers name platform platforms portdir pretty
-                 replaced_by revision variant variants version}
+                 replaced_by revision subports variant variants version}
+    contents    {size {units 1}}
     deps        {index no-build}
     rdeps       {index no-build full}
     rdependents {full}
@@ -3895,8 +4184,10 @@
                  long_description maintainer maintainers name platform
                  platforms portdir regex revision variant variants version}
     selfupdate  {nosync}
+    space       {{units 1}}
     activate    {no-exec}
     deactivate  {no-exec}
+    install     {no-rev-upgrade}
     uninstall   {follow-dependents follow-dependencies no-exec}
     variants    {index}
     clean       {all dist work logs}
@@ -3904,13 +4195,14 @@
     lint        {nitpick}
     select      {list set show}
     log         {{phase 1} {level 1}}
-    upgrade     {force enforce-variants no-replace}
+    upgrade     {force enforce-variants no-replace no-rev-upgrade}
+    rev-upgrade {id-loadcmd-check}
 }
 
 ##
 # Checks whether the given option is valid
 #
-# œparam action for which action
+# @param action for which action
 # @param option the prefix of the option to check
 # @return list of pairs {name argc} for all matching options
 proc cmd_option_matches {action option} {
@@ -3979,7 +4271,7 @@
                         foreach e $kopts {
                             lappend errlst "--[lindex $e 0]"
                         }
-                        return -code error "${action} --${key} is ambiguous: \n  [join $errlst "\n  "]"
+                        return -code error "\"port ${action} --${key}\" is ambiguous: \n  port ${action} [join $errlst "\n  port ${action} "]"
                     }
                     set key   [lindex [lindex $kopts 0] 0]
                     set kargc [lindex [lindex $kopts 0] 1]
@@ -4023,7 +4315,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
@@ -4130,9 +4422,16 @@
         array set global_options $global_options_base
         
         # Find an action to execute
-        set action_proc [find_action_proc $action]
-        if { $action_proc == "" } {
-            puts "Unrecognized action \"$action\""
+        set actions [find_action $action]
+        if {[llength $actions] == 1} {
+            set action [lindex $actions 0]
+            set action_proc [get_action_proc $action]
+        } else {
+            if {[llength $actions] > 1} {
+                ui_error "\"port ${action}\" is ambiguous: \n  port [join $actions "\n  port "]"
+            } else {
+                ui_error "Unrecognized action \"port $action\""
+            }
             set action_status 1
             break
         }
@@ -4222,6 +4521,7 @@
 }
 
 
+# return text action beginning with $text
 proc complete_action { text state } {   
     global action_array
     global complete_choices complete_position
@@ -4237,7 +4537,19 @@
     return $word
 }
 
+# return all actions beginning with $text
+proc guess_action { text } {   
+    global action_array
 
+    return [array names action_array "[string tolower $text]*"]
+
+    if { [llength $complete_choices ] == 1 } {
+        return [lindex $complete_choices 0]
+    }
+
+    return {}
+}
+
 proc attempt_completion { text word start end } {
     # If the word starts with '~', or contains '.' or '/', then use the build-in
     # completion to complete the word
@@ -4443,6 +4755,9 @@
 # interactive mode
 if { [llength $remaining_args] == 0 && ![info exists ui_options(ports_commandfiles)] } {
     lappend ui_options(ports_commandfiles) -
+} elseif {[lookahead] == "selfupdate" || [lookahead] == "sync"} {
+    # tell mportinit not to tell the user they should selfupdate
+    set ui_options(ports_no_old_index_warning) 1
 }
 
 # Initialize mport
@@ -4476,6 +4791,9 @@
 if { ($exit_status == 0 || [macports::ui_isset ports_processall]) && [info exists ui_options(ports_commandfiles)] } {
     set exit_status [process_command_files $ui_options(ports_commandfiles)]
 }
+if {$exit_status == -999} {
+    set exit_status 0
+}
 
 # shut down macports1.0
 mportshutdown

Modified: branches/gsoc11-post-destroot/base/src/port/portindex.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port/portindex.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port/portindex.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -146,6 +146,7 @@
                 incr stats(failed)
             } else {
                 set prefix $save_prefix
+                array unset portinfo
                 array set portinfo [mportinfo $interp]
                 mportclose $interp
                 set portinfo(portdir) $portdir
@@ -164,7 +165,7 @@
     }
 }
 
-if {[expr $argc > 4]} {
+if {[expr $argc > 8]} {
     print_usage
     exit 1
 }
@@ -186,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
@@ -259,7 +264,7 @@
 foreach key {categories depends_fetch depends_extract depends_build \
              depends_lib depends_run description epoch homepage \
              long_description maintainers name platforms revision variants \
-             version portdir portarchive replaced_by license} {
+             version portdir portarchive replaced_by license installs_libs} {
     set keepkeys($key) 1
 }
 mporttraverse pindex $directory

Modified: branches/gsoc11-post-destroot/base/src/port1.0/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -7,7 +7,7 @@
 	portdeactivate.tcl portsubmit.tcl port_autoconf.tcl portstartupitem.tcl \
 	porttrace.tcl portlivecheck.tcl portdistcheck.tcl portmirror.tcl \
 	portload.tcl portunload.tcl portdistfiles.tcl fetch_common.tcl \
-	portcheckdestroot.tcl
+	portsandbox.tcl portcheckdestroot.tcl
 
 include ../../Mk/macports.subdir.mk
 include ../../Mk/macports.autoconf.mk
@@ -34,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-post-destroot/base/src/port1.0/fetch_common.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/fetch_common.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/fetch_common.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # $Id$
 #
 # Copyright (c) 2002 - 2003 Apple Inc.
-# Copyright (c) 2004-2010 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
@@ -241,13 +248,18 @@
         }
 
         foreach site $urllist {
+            if {[string range $site 0 6] == "file://"} {
+                set pingtimes(localhost) 0
+                continue
+            }
+            
             regexp $hostregex $site -> host
-
+            
             if { [info exists seen($host)] } {
                 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
@@ -256,25 +268,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]} {
@@ -284,8 +300,15 @@
 
         set pinglist {}
         foreach site $urllist {
-            regexp $hostregex $site -> host
-            lappend pinglist [ list $site $pingtimes($host) ]
+            if {[string range $site 0 6] == "file://"} {
+                set host localhost
+            } else {
+                regexp $hostregex $site -> host
+            }
+            # -1 means blacklisted
+            if {$pingtimes($host) != "-1"} {
+                lappend pinglist [ list $site $pingtimes($host) ]
+            }
         }
 
         set pinglist [ lsort -real -index 1 $pinglist ]

Modified: branches/gsoc11-post-destroot/base/src/port1.0/port.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/port.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/port.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # port.tcl
 # $Id$
 #
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -59,3 +59,4 @@
 package require portunload 1.0
 
 package require portdistfiles 1.0
+package require portsandbox 1.0

Modified: branches/gsoc11-post-destroot/base/src/port1.0/port_autoconf.tcl.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/port_autoconf.tcl.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/port_autoconf.tcl.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,8 @@
 # port_autoconf.tcl.in
 # $Id$
 #
-# Copyright (c) 2002 - 2004 Apple Computer, Inc.
+# Copyright (c) 2005 - 2011 The MacPorts Project
+# Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -12,7 +13,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -32,6 +33,8 @@
 
 namespace eval portutil::autoconf {
 	variable bzip2_path "@BZIP2@"
+	variable lzma_path "@LZMA@"
+	variable xz_path "@XZ@"
 	variable cp_path "@CP@"
 	variable cpio_path "@CPIO@"
 	variable diff_path "@DIFF@"
@@ -59,12 +62,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 "@SWIG@"
 	variable have_launchd "@HAVE_LAUNCHD@"
 	variable launchctl_path "@LAUNCHCTL@"
 	variable install_command "@INSTALL@"

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portactivate.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portactivate.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portactivate.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portactivate.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2005, 2007, 2009-2011 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -60,7 +61,7 @@
 proc portactivate::activate_main {args} {
     global env subport version revision portvariants user_options PortInfo
 
-    registry_activate $subport "${version}_${revision}${portvariants}" [array get user_options]
+    registry_activate $subport $version $revision $portvariants [array get user_options]
 
     # Display notes at the end of the activation phase.
     if {[info exists PortInfo(notes)] && $PortInfo(notes) ne {}} {

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portbuild.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portbuild.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portbuild.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portbuild.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2007 - 2012 The MacPorts Project
+# Copyright (c) 2002 - 2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -42,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
@@ -55,12 +57,38 @@
 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
 
+# proc to add dependency on bsdmake, if necessary
+option_proc build.type portbuild::set_build_type
+
 set_ui_prefix
 
+proc portbuild::set_build_type {option action args} {
+    array set build_type_map {
+        bsd     {bin:bsdmake:bsdmake}
+    }
+
+    if {$action == "set"} {
+        switch $option {
+            build.type {
+                # using [exists foo] doesn't work with arrays!
+                if {[info exists build_type_map([option build.type])]} {
+                    # remove dependencies added before when setting build.type more than once
+                    eval depends_build-delete $build_type_map([option build.type])
+                }
+                if {[info exists build_type_map($args)]} {
+                    # add dependency if needed
+                    eval depends_build-append $build_type_map($args)
+                }
+            }
+        }
+    }
+}
+
 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] {
@@ -123,7 +151,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-post-destroot/base/src/port1.0/portchecksum.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portchecksum.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portchecksum.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portchecksum.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2004 Apple Computer, Inc.
+# Copyright (c) 2002 - 2004 Apple Inc.
 # Copyright (c) 2004 - 2005 Paul Guyot <pguyot at kallisys.net>
+# Copyright (c) 2006-2011 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -58,7 +59,7 @@
 set checksum_types_count [llength $checksum_types]
 
 # types to recommend if none are specified in the portfile
-set default_checksum_types {sha1 rmd160}
+set default_checksum_types {rmd160 sha256}
 
 # Using global all_dist_files, parse the checksums and store them into the
 # global array checksums_array.
@@ -85,7 +86,7 @@
         && [expr $nb_checksum / 2] <= $checksum_types_count
         && [lsearch -exact $checksum_types [lindex $checksums_str 0]] >= 0} {
         # Convert to format #2
-        set checksums_str [linsert $checksums_str 0 $all_dist_files]
+        set checksums_str [linsert $checksums_str 0 [lindex $all_dist_files 0]]
         # We increased the size.
         incr nb_checksum
     }
@@ -220,6 +221,9 @@
     # Set the list of checksums as the option checksums.
     set checksums_str [option checksums]
 
+    # store the calculated checksums to avoid repeated calculations
+    set sums ""
+
     # if everything is fine with the syntax, keep on and check the checksum of
     # the distfiles.
     if {[parse_checksums $checksums_str] == "yes"} {
@@ -238,10 +242,20 @@
                 }
             }
 
+            if {[llength $all_dist_files] > 1} {
+                lappend sums $distfile
+            }
+
             # check that there is at least one checksum for the distfile.
             if {![info exists checksums_array($distfile)] || [llength $checksums_array($distfile)] < 1} {
                 ui_error "[format [msgcat::mc "No checksum set for %s"] $distfile]"
                 set fail yes
+
+                # no checksums specified; output the default set
+                foreach type $default_checksum_types {
+                    lappend sums [format "%-8s%s" $type [calc_$type $fullpath]]
+                }
+
             } else {
                 # retrieve the list of types/values from the array.
                 set portfile_checksums $checksums_array($distfile)
@@ -249,6 +263,7 @@
                 # iterate on this list to check the actual values.
                 foreach {type sum} $portfile_checksums {
                     set calculated_sum [calc_$type $fullpath]
+                    lappend sums [format "%-8s%s" $type $calculated_sum]
                     if {[string equal $sum $calculated_sum]} {
                         ui_debug "[format [msgcat::mc "Correct (%s) checksum for %s"] $type $distfile]"
                     } else {
@@ -277,28 +292,6 @@
     if {[tbool fail]} {
 
         # Show the desired checksum line for easy cut-paste
-        set sums ""
-        foreach distfile $all_dist_files {
-            if {[llength $all_dist_files] > 1} {
-                lappend sums $distfile
-            }
-
-            set fullpath [file join $distpath $distfile]
-            if {![file isfile $fullpath] && (!$usealtworkpath && [file isfile "${altprefix}${fullpath}"])} {
-                set fullpath "${altprefix}${fullpath}"
-            }
-            if {![info exists checksums_array($distfile)] || [llength $checksums_array($distfile)] < 1} {
-                # no checksums specified; output the default set
-                foreach type $default_checksum_types {
-                    lappend sums [format "%-8s%s" $type [calc_$type $fullpath]]
-                }
-            } else {
-                # output just the types that were already used
-                foreach {type sum} $checksums_array($distfile) {
-                    lappend sums [format "%-8s%s" $type [calc_$type $fullpath]]
-                }
-            }
-        }
         ui_info "The correct checksum line may be:"
         ui_info [format "%-20s%s" "checksums" [join $sums [format " \\\n%-20s" ""]]]
 
@@ -310,7 +303,7 @@
             ui_notice "***"
             ui_notice "The non-matching file appears to be HTML. See this page for possible reasons"
             ui_notice "for the checksum mismatch:"
-            ui_notice "<http://trac.macports.org/wiki/MisbehavingServers>"
+            ui_notice "<https://trac.macports.org/wiki/MisbehavingServers>"
             ui_notice "***"
         }
 

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portclean.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portclean.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portclean.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portclean.tcl
 # $Id$
 #
+# Copyright (c) 2005-2007, 2009-2011 The MacPorts Project
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -50,9 +51,13 @@
 set_ui_prefix
 
 proc portclean::clean_start {args} {
-    global UI_PREFIX
+    global UI_PREFIX prefix
 
     ui_notice "$UI_PREFIX [format [msgcat::mc "Cleaning %s"] [option subport]]"
+
+    if {[getuid] == 0 && [geteuid] != 0} {
+        elevateToRoot "clean"
+    }
 }
 
 proc portclean::clean_main {args} {

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portconfigure.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portconfigure.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portconfigure.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portconfigure.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2007 - 2012 The MacPorts Project
 # Copyright (c) 2007 Markus W. Weissmann <mww at macports.org>
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -170,7 +171,10 @@
 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}}
@@ -183,6 +187,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
 
@@ -193,24 +200,29 @@
 
     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-3.3 { set name "MacPorts Apple gcc 3.3" }
         apple-gcc-4.0 { set name "MacPorts Apple gcc 4.0" }
         apple-gcc-4.2 { set name "MacPorts Apple gcc 4.2" }
-        macports-gcc-4.0 { set name "MacPorts gcc 4.0" }
-        macports-gcc-4.1 { set name "MacPorts gcc 4.1" }
+        macports-gcc     { set name "MacPorts gcc (port select)" }
         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-gcc-4.7 { set name "MacPorts gcc 4.7" }
+        macports-gcc-4.8 { set name "MacPorts gcc 4.8" }
         macports-llvm-gcc-4.2 { set name "MacPorts llvm-gcc 4.2" }
-        macports-clang { set name "MacPorts clang" }
+        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" }
+        macports-clang-3.2 { set name "MacPorts clang 3.2" }
         default { return -code error "Invalid value for configure.compiler" }
     }
     ui_debug "Using compiler '$name'"
@@ -218,16 +230,26 @@
     # Additional ccache directory setup
     global configureccache ccache_dir ccache_size macportsuser
     if {${configureccache}} {
+        # 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
-                exec ccache -M ${ccache_size} >/dev/null
             } result] {
-            ui_warn "ccache_dir ${ccache_dir} could not be initialized; disabling ccache: $result"
+            ui_warn "ccache_dir ${ccache_dir} could not be created; disabling ccache: $result"
             set configureccache no
         }
         dropPrivileges
+
+        # Initialize ccache directory with the given maximum size
+        if {${configureccache}} {
+            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
+            }
+        }
     }
 }
 
@@ -291,13 +313,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
@@ -340,6 +367,10 @@
         clang -
         apple-gcc-4.0 -
         apple-gcc-4.2 -
+        macports-clang-2.9 -
+        macports-clang-3.0 -
+        macports-clang-3.1 -
+        macports-clang-3.2 -
         macports-clang {
             return yes
         }
@@ -349,82 +380,176 @@
     }
 }
 
+# check if a compiler comes from a port
+proc portconfigure::compiler_is_port {compiler} {
+    switch $compiler {
+        clang -
+        llvm-gcc-4.2 -
+        gcc-4.2 -
+        gcc-4.0 -
+        gcc-3.3 {return no}
+        default {return yes}
+    }
+}
+
+# maps compiler names to the port that provides them
+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
+}
+
 # internal function to determine the default compiler
 proc portconfigure::configure_get_default_compiler {args} {
-    global macosx_deployment_target
-    switch -exact ${macosx_deployment_target} {
-        "10.4"      -
-        "10.5"      { return gcc-4.0 }
-        "10.6"      { return gcc-4.2 }
-        "10.7"      { return llvm-gcc-4.2 }
-        default     { return gcc }
+    global compiler.blacklist compiler.whitelist compiler.fallback
+    if {${compiler.whitelist} != {}} {
+        set search_list ${compiler.whitelist}
+    } else {
+        set search_list ${compiler.fallback}
     }
+    foreach compiler $search_list {
+        if {[lsearch -exact ${compiler.blacklist} $compiler] == -1} {
+            if {[file executable [configure_get_compiler cc $compiler]] 
+                || [compiler_is_port $compiler]} {
+                return $compiler
+            }
+        }
+    }
+    ui_warn "All compilers are either blacklisted or unavailable; using first fallback entry as last resort"
+    return [lindex ${compiler.fallback} 0]
 }
 
+# internal function to choose compiler fallback list based on platform
+proc portconfigure::get_compiler_fallback {} {
+    global xcodeversion macosx_deployment_target default_compiler
+    if {[info exists default_compiler]} {
+        return $default_compiler
+    } elseif {$xcodeversion == "none" || $xcodeversion == ""} {
+        return {cc}
+    } elseif {[vercmp $xcodeversion 4.2] >= 0} {
+        return {clang llvm-gcc-4.2 apple-gcc-4.2}
+    } elseif {[vercmp $xcodeversion 4.0] >= 0} {
+        return {llvm-gcc-4.2 clang 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 gcc-4.0}
+        }
+    } elseif {[vercmp $xcodeversion 3.0] >= 0} {
+        return {gcc-4.2 apple-gcc-4.2 macports-clang-3.0 gcc-4.0}
+    } else {
+        return {gcc-4.0 apple-gcc-4.2 macports-clang-3.0 gcc-3.3}
+    }
+}
+
+# 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
+proc portconfigure::configure_get_compiler {type {compiler {}}} {
+    global configure.compiler prefix
     set ret ""
-    switch -exact ${configure.compiler} {
+    if {$compiler == {}} {
+        set compiler ${configure.compiler}
+    }
+
+    # Set defaults
+    switch -exact ${type} {
+        cc   { set ret [find_developer_tool cc] }
+        objc { set ret [find_developer_tool cc] }
+        cxx  { set ret [find_developer_tool c++] }
+        cpp  { set ret [find_developer_tool cpp] }
+    }
+
+    switch -exact ${compiler} {
         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 }
+                cc   { set ret [find_developer_tool gcc] }
+                objc { set ret [find_developer_tool gcc] }
+                cxx  { set ret [find_developer_tool g++] }
+                cpp  { set ret [find_developer_tool cpp] }
             }
         }
         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 }
+                cc   { set ret [find_developer_tool gcc-3.3] }
+                objc { set ret [find_developer_tool gcc-3.3] }
+                cxx  { set ret [find_developer_tool g++-3.3] }
+                cpp  { set ret [find_developer_tool cpp-3.3] }
             }
         }
         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 }
+                cc   { set ret [find_developer_tool gcc-4.0] }
+                objc { set ret [find_developer_tool gcc-4.0] }
+                cxx  { set ret [find_developer_tool g++-4.0] }
+                cpp  { set ret [find_developer_tool 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 }
+                cc   { set ret [find_developer_tool gcc-4.2] }
+                objc { set ret [find_developer_tool gcc-4.2] }
+                cxx  { set ret [find_developer_tool g++-4.2] }
+                cpp  { set ret [find_developer_tool 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 }
+                cc   { set ret [find_developer_tool llvm-gcc-4.2] }
+                objc { set ret [find_developer_tool llvm-gcc-4.2] }
+                cxx  { set ret [find_developer_tool llvm-g++-4.2] }
+                cpp  { set ret [find_developer_tool llvm-cpp-4.2] }
             }
         }
         clang {
             switch -exact ${type} {
-                cc   { set ret ${developer_dir}/usr/bin/clang }
-                objc { set ret ${developer_dir}/usr/bin/clang }
+                cc   { set ret [find_developer_tool clang] }
+                objc { set ret [find_developer_tool clang] }
                 cxx  {
-                    if {[file executable ${developer_dir}/usr/bin/clang++]} {
-                        set ret ${developer_dir}/usr/bin/clang++
+                    set clangpp [find_developer_tool clang++]
+                    if {[file executable ${clangpp}]} {
+                        set ret ${clangpp}
                     } else {
-                        set ret ${developer_dir}/usr/bin/llvm-g++-4.2
+                        set ret [find_developer_tool llvm-g++-4.2]
                     }
                 }
             }
         }
-        apple-gcc-3.3 {
-            switch -exact ${type} {
-                cc  { set ret ${prefix}/bin/gcc-apple-3.3 }
-                cpp { set ret ${prefix}/bin/cpp-apple-3.3 }
-            }
-        }
         apple-gcc-4.0 {
             switch -exact ${type} {
                 cc   { set ret ${prefix}/bin/gcc-apple-4.0 }
@@ -437,30 +562,20 @@
                 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 }
             }
         }
-        macports-gcc-4.0 {
+        macports-gcc {
             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 }
+                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 }
             }
         }
-        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 }
-            }
-        }
         macports-gcc-4.2 {
             switch -exact ${type} {
                 cc   { set ret ${prefix}/bin/gcc-mp-4.2 }
@@ -516,6 +631,28 @@
                 f90  { set ret ${prefix}/bin/gfortran-mp-4.6 }
             }
         }
+        macports-gcc-4.7 {
+            switch -exact ${type} {
+                cc   { set ret ${prefix}/bin/gcc-mp-4.7 }
+                objc { set ret ${prefix}/bin/gcc-mp-4.7 }
+                cxx  { set ret ${prefix}/bin/g++-mp-4.7 }
+                cpp  { set ret ${prefix}/bin/cpp-mp-4.7 }
+                fc   { set ret ${prefix}/bin/gfortran-mp-4.7 }
+                f77  { set ret ${prefix}/bin/gfortran-mp-4.7 }
+                f90  { set ret ${prefix}/bin/gfortran-mp-4.7 }
+            }
+        }
+        macports-gcc-4.8 {
+            switch -exact ${type} {
+                cc   { set ret ${prefix}/bin/gcc-mp-4.8 }
+                objc { set ret ${prefix}/bin/gcc-mp-4.8 }
+                cxx  { set ret ${prefix}/bin/g++-mp-4.8 }
+                cpp  { set ret ${prefix}/bin/cpp-mp-4.8 }
+                fc   { set ret ${prefix}/bin/gfortran-mp-4.8 }
+                f77  { set ret ${prefix}/bin/gfortran-mp-4.8 }
+                f90  { set ret ${prefix}/bin/gfortran-mp-4.8 }
+            }
+        }
         macports-llvm-gcc-4.2 {
             switch -exact ${type} {
                 cc   { set ret ${prefix}/bin/llvm-gcc-4.2 }
@@ -534,6 +671,34 @@
                 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 }
+            }
+        }
+        macports-clang-3.2 {
+            switch -exact ${type} {
+                cc   { set ret ${prefix}/bin/clang-mp-3.2 }
+                objc { set ret ${prefix}/bin/clang-mp-3.2 }
+                cxx  { set ret ${prefix}/bin/clang++-mp-3.2 }
+            }
+        }
     }
     return $ret
 }
@@ -570,13 +735,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

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portdeactivate.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portdeactivate.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portdeactivate.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # portdeactivate.tcl
 # $Id$
 #
-# Copyright (c) 2010 The MacPorts Project
+# Copyright (c) 2010-2011 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -58,6 +58,6 @@
 
 proc portdeactivate::deactivate_main {args} {
     global subport version revision portvariants user_options
-    registry_deactivate $subport "${version}_${revision}${portvariants}" [array get user_options]
+    registry_deactivate $subport $version $revision $portvariants [array get user_options]
     return 0
 }

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portdepends.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portdepends.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portdepends.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portdepends.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2005, 2007-2009 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portdestroot.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portdestroot.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portdestroot.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portdestroot.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2002 - 2003 Apple Inc.
 # Copyright (c) 2004 - 2005 Robert Shaw <rshaw at opendarwin.org>
+# Copyright (c) 2004-2005, 2007-2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -51,7 +52,7 @@
 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
@@ -82,11 +83,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]"

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portdistcheck.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portdistcheck.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portdistcheck.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,6 +3,7 @@
 #
 # $Id$
 #
+# Copyright (c) 2007-2011 The MacPorts Project
 # Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
 # All rights reserved.
 #
@@ -15,7 +16,7 @@
 # 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 Computer, Inc. nor the names of its
+# 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.
 #
@@ -46,15 +47,11 @@
 }
 
 # define options
-options distcheck.type distcheck.check
+options distcheck.type
 
 # defaults
 default distcheck.type moddate
-default distcheck.check moddate
 
-# Deprecation
-option_deprecate distcheck.check distcheck.type
-
 proc portdistcheck::distcheck_main {args} {
     global distcheck.type
     global fetch.type

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portdistfiles.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portdistfiles.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portdistfiles.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # portdistfiles.tcl
 # $Id$
 #
-# Copyright (c) 2008 MacPorts Project
+# Copyright (c) 2008-2011 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +13,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -53,10 +53,12 @@
 }
 
 proc portdistfiles::distfiles_main {args} {
-    global UI_PREFIX master_sites checksums_array portdbpath dist_subdir
+    global UI_PREFIX master_sites patch_sites patchfiles checksums_array \
+           portdbpath dist_subdir all_dist_files
     
     # give up on ports that do not provide URLs
-    if {![info exists master_sites] || $master_sites == "{}"} {
+    if {(![info exists master_sites] || $master_sites == "{}")
+        && (![info exists patchfiles] || ![info exists patch_sites] || $patch_sites == "{}")} {
         return 0
     }
 
@@ -64,6 +66,11 @@
     set fetch_urls {}
     portfetch::checkfiles fetch_urls
 
+    # also give up on ports that don't have any distfiles
+    if {![info exists all_dist_files]} {
+        return 0
+    }
+
     # get checksum data from the portfile and parse it
     set checksums_str [option checksums]
     set result [portchecksum::parse_checksums $checksums_str]

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portextract.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portextract.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portextract.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portextract.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2005, 2007-2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # Copyright (c) 2007 Markus W. Weissmann <mww at macports.org>
 # All rights reserved.
 #
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -91,9 +92,9 @@
     if {[tbool use_bzip2]} {
         option extract.cmd [findBinary bzip2 ${portutil::autoconf::bzip2_path}]
     } elseif {[tbool use_lzma]} {
-        option extract.cmd [binaryInPath "lzma"]
+        option extract.cmd [findBinary lzma ${portutil::autoconf::lzma_path}]
     } elseif {[tbool use_xz]} {
-        option extract.cmd [binaryInPath "xz"]
+        option extract.cmd [findBinary xz ${portutil::autoconf::xz_path}]
     } elseif {[tbool use_zip]} {
         option extract.cmd [findBinary unzip ${portutil::autoconf::unzip_path}]
         option extract.pre_args -q

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portfetch.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portfetch.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portfetch.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portfetch.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2004 - 2012 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -103,7 +104,7 @@
 default hg.tag {tip}
 
 # Set distfiles
-default distfiles {[portfetch::suffix $distname]}
+default distfiles {[list [portfetch::suffix $distname]]}
 default dist_subdir {${name}}
 
 # user name & password
@@ -121,9 +122,6 @@
 default mirror_sites.listfile {"mirror_sites.tcl"}
 default mirror_sites.listpath {"port1.0/fetch"}
 
-# Deprecation
-option_deprecate svn.tag svn.revision
-
 # Option-executed procedures
 option_proc use_bzip2 portfetch::set_extract_type
 option_proc use_lzma  portfetch::set_extract_type
@@ -167,6 +165,9 @@
 proc portfetch::set_fetch_type {option action args} {
     global os.platform os.major
     if {[string equal ${action} "set"]} {
+        if {$args != "standard"} {
+            distfiles
+        }
         switch $args {
             bzr {
                 depends_fetch-append bin:bzr:bzr
@@ -206,16 +207,8 @@
 
 # Given a distname, return the distname with extract.suffix appended
 proc portfetch::suffix {distname} {
-    global extract.suffix fetch.type
-    switch -- "${fetch.type}" {
-        bzr         -
-        cvs         -
-        svn         -
-        git         -
-        hg          { return "" }
-        standard    -
-        default     { return "${distname}${extract.suffix}" }
-    }
+    global extract.suffix
+    return "${distname}${extract.suffix}"
 }
 # XXX import suffix into the global namespace as it is currently used from
 # Portfiles, but should better go somewhere else
@@ -228,7 +221,7 @@
 
     if {[info exists patchfiles]} {
         foreach file $patchfiles {
-            if {![file exists $filespath/$file]} {
+            if {![file exists "${filespath}/${file}"]} {
                 set distsite [getdisttag $file]
                 set file [getdistname $file]
                 lappend all_dist_files $file
@@ -251,7 +244,7 @@
 
     if {[info exists distfiles]} {
         foreach file $distfiles {
-            if {![file exists $filespath/$file]} {
+            if {![file exists "${filespath}/${file}"]} {
                 set distsite [getdisttag $file]
                 set file [getdistname $file]
                 lappend all_dist_files $file
@@ -286,10 +279,40 @@
 
 # Perform a bzr fetch
 proc portfetch::bzrfetch {args} {
-    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]
     }
@@ -343,9 +366,34 @@
     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_parts [split $env(http_proxy) :]
+        set proxy_host [lindex $proxy_parts 0]
+        set proxy_port [lindex $proxy_parts 1]
+        return "--config-option servers:global:http-proxy-host=${proxy_host} --config-option servers:global:http-proxy-port=${proxy_port}"
+    } elseif {   [string compare -length 8 {https://} ${url}] == 0
+              && [info exists env(HTTPS_PROXY)]} {
+        set proxy_parts [split $env(HTTPS_PROXY) :]
+        set proxy_host [lindex $proxy_parts 0]
+        set proxy_port [lindex $proxy_parts 1]
+        return "--config-option servers:global:http-proxy-host=${proxy_host} --config-option servers:global:http-proxy-port=${proxy_port}"
+    } else {
+        return ""
+    }
+}
+
 # Perform an svn fetch
 proc portfetch::svnfetch {args} {
-    global svn.args svn.method svn.revision svn.url
+    global svn.args svn.method svn.revision svn.url patchfiles
 
     if {[regexp {\s} ${svn.url}]} {
         return -code error [msgcat::mc "Subversion URL cannot contain whitespace"]
@@ -354,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"]
     }
@@ -369,7 +420,7 @@
 
 # Perform a git fetch
 proc portfetch::gitfetch {args} {
-    global worksrcpath
+    global worksrcpath patchfiles
     global git.url git.branch git.sha1 git.cmd
 
     set options "-q"
@@ -401,10 +452,15 @@
 
 # Perform a mercurial fetch.
 proc portfetch::hgfetch {args} {
-    global worksrcpath prefix_frozen
-    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"]
@@ -476,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"
                 }
             }
@@ -520,21 +576,27 @@
 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]
+            }
+        }
     }
 }
 

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portinstall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portinstall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portinstall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,8 +2,9 @@
 # portinstall.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2002 - 2004 Apple Inc.
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
+# Copyright (c) 2005, 2007 - 2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -54,7 +55,7 @@
 
 proc portinstall::install_start {args} {
     global UI_PREFIX subport version revision portvariants
-    global prefix registry_open registry.format registry.path
+    global prefix registry_open registry.path
     ui_notice "$UI_PREFIX [format [msgcat::mc "Installing %s @%s_%s%s"] $subport $version $revision $portvariants]"
     
     # start gsoc08-privileges
@@ -66,7 +67,7 @@
     }
     # end gsoc08-privileges
     
-    if {${registry.format} == "receipt_sqlite" && ![info exists registry_open]} {
+    if {![info exists registry_open]} {
         registry::open [file join ${registry.path} registry registry.db]
         set registry_open yes
     }
@@ -297,12 +298,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}"
                  }
              }
          }
@@ -422,19 +423,19 @@
     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"
@@ -483,132 +484,77 @@
     homepage depends_run package-install workdir workpath \
     worksrcdir UI_PREFIX destroot revision maintainers user_options \
     portvariants negated_variants targets depends_lib PortInfo epoch license \
-    registry.format os.platform os.major portarchivetype installPlist
+    os.platform os.major portarchivetype installPlist
 
     set oldpwd [pwd]
     if {$oldpwd == ""} {
         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]
-    }
-
-    if {[string equal ${registry.format} "receipt_sqlite"]} {
-        # registry2.0
-
-        # 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} {
-            if {[info exists $deplist]} {
-                foreach dep [set $deplist] {
-                    set dep_portname [_get_dep_port $dep]
-                    if {$dep_portname != ""} {
-                        lappend dep_portnames $dep_portname
-                    }
+    # 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} {
+        if {[info exists $deplist]} {
+            foreach dep [set $deplist] {
+                set dep_portname [_get_dep_port $dep]
+                if {$dep_portname != ""} {
+                    lappend dep_portnames $dep_portname
                 }
             }
         }
+    }
 
-        registry::write {
+    registry::write {
 
-            set regref [registry::entry create $subport $version $revision $portvariants $epoch]
+        set regref [registry::entry create $subport $version $revision $portvariants $epoch]
 
-            if {[info exists user_options(ports_requested)]} {
-                $regref requested $user_options(ports_requested)
-            } else {
-                $regref requested 0
-            }
-            $regref os_platform ${os.platform}
-            $regref os_major ${os.major}
-            $regref archs [get_canonical_archs]
-            # Trick to have a portable GMT-POSIX epoch-based time.
-            $regref date [expr [clock scan now -gmt true] - [clock scan "1970-1-1 00:00:00" -gmt true]]
-            if {[info exists negated_variants]} {
-                $regref negated_variants $negated_variants
-            }
-
-            foreach dep_portname $dep_portnames {
-                $regref depends $dep_portname
-            }
-
-            $regref installtype image
-            $regref state imaged
-            $regref location $location
-
-            if {[info exists installPlist]} {
-                # register files
-                $regref map $installPlist
-            }
-            
-            # store portfile
-            set fd [open [file join ${portpath} Portfile]]
-            $regref portfile [read $fd]
-            close $fd
+        if {[info exists user_options(ports_requested)]} {
+            $regref requested $user_options(ports_requested)
+        } else {
+            $regref requested 0
         }
-    } else {
-        # Begin the registry entry
-        set regref [registry_new $subport $version $revision $portvariants $epoch]
+        $regref os_platform ${os.platform}
+        $regref os_major ${os.major}
+        $regref archs [get_canonical_archs]
+        # Trick to have a portable GMT-POSIX epoch-based time.
+        $regref date [expr [clock scan now -gmt true] - [clock scan "1970-1-1 00:00:00" -gmt true]]
         if {[info exists negated_variants]} {
-            registry_prop_store $regref negated_variants $negated_variants
+            $regref negated_variants $negated_variants
         }
 
-        registry_prop_store $regref location $location
-
-        if {[info exists user_options(ports_requested)]} {
-            registry_prop_store $regref requested $user_options(ports_requested)
-        } else {
-            registry_prop_store $regref requested 0
+        foreach dep_portname $dep_portnames {
+            $regref depends $dep_portname
         }
-        registry_prop_store $regref categories $categories
 
-        registry_prop_store $regref os_platform ${os.platform}
-        registry_prop_store $regref os_major ${os.major}
-        registry_prop_store $regref archs [get_canonical_archs]
+        $regref installtype image
+        $regref state imaged
+        $regref location $location
 
-        if {[info exists description]} {
-            registry_prop_store $regref description [string map {\n \\n} ${description}]
-        }
-        if {[info exists long_description]} {
-            registry_prop_store $regref long_description [string map {\n \\n} ${long_description}]
-        }
-        if {[info exists license]} {
-            registry_prop_store $regref license ${license}
-        }
-        if {[info exists homepage]} {
-            registry_prop_store $regref homepage ${homepage}
-        }
-        if {[info exists maintainers]} {
-            registry_prop_store $regref maintainers ${maintainers}
-        }
-        if {[info exists depends_run]} {
-            registry_prop_store $regref depends_run $depends_run
-            registry_register_deps $depends_run $subport
-        }
-        if {[info exists depends_lib]} {
-            registry_prop_store $regref depends_lib $depends_lib
-            registry_register_deps $depends_lib $subport
-        }
         if {[info exists installPlist]} {
-            registry_prop_store $regref contents [_fake_fileinfo_for_index $installPlist]
+            # register files
+            $regref map $installPlist
         }
-        if {[info exists package-install]} {
-            registry_prop_store $regref package-install ${package-install}
-        }
-        if {[info proc pkg_uninstall] == "pkg_uninstall"} {
-            registry_prop_store $regref pkg_uninstall [proc_disasm pkg_uninstall]
-        }
-
-        registry_write $regref
+        
+        # store portfile
+        set fd [open [file join ${portpath} Portfile]]
+        $regref portfile [read $fd]
+        close $fd
     }
 
     _cd $oldpwd

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portlint.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portlint.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portlint.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -43,6 +43,7 @@
     "homepage" \
     "master_sites" \
     "checksums" \
+    "license"
     ]
 
 set lint_optional [list \
@@ -190,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
@@ -203,13 +204,13 @@
             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"
+                ui_error "Line $lineno repeats inclusion of PortGroup $portgroup"
                 incr errors
             } else {
                 set portgroups($portgroup) $portgroupversion
@@ -249,6 +250,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
@@ -285,15 +291,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 homepage master_sites checksums patchfiles
-    global depends_fetch depends_extract depends_lib depends_build depends_run distfiles fetch.type
-    
-    global lint_portsystem lint_platforms
-    global lint_required lint_optional
 
     if (!$seen_portsystem) {
         ui_error "Didn't find PortSystem specification"
@@ -489,15 +493,70 @@
         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"
+    if {$license == "unknown"} {
+        ui_warn "no license set"
         incr warnings
+    } else {
+
+        # If maintainer set license, it must follow correct format
+
+        set prev ''
+        foreach test [split [string map { \{ '' \} ''} $license] '\ '] {
+            ui_debug "Checking format of license '${test}'"
+
+            # space instead of hyphen
+            if {[string is double -strict $test]} {
+                ui_error "Invalid license '${prev} ${test}': missing hyphen between ${prev} ${test}"
+
+            # missing hyphen
+            } elseif {![string equal -nocase "X11" $test]} {
+                foreach subtest [split $test '-'] {
+                    ui_debug "testing ${subtest}"
+
+                    # license names start with letters: versions and empty strings need not apply
+                    if {[string is alpha -strict [string index $subtest 0]]} {
+
+                        # if the last character of license name is a number or plus sign
+                        # then a hyphen is missing
+                        set license_end [string index $subtest end]
+                        if {[string equal "+" $license_end] || [string is integer -strict $license_end]} {
+                            ui_error "invalid license '${test}': missing hyphen before version"
+                        }
+                    }
+                }
+            }
+
+            if {[string equal -nocase "BSD-2" $test]} {
+                # BSD-2 => BSD
+                ui_error "Invalid license '${test}': use BSD instead"
+            } elseif {[string equal -nocase "BSD-3" $test]} {
+                # BSD-3 => BSD
+                ui_error "Invalid license '${test}': use BSD instead"
+            } elseif {[string equal -nocase "BSD-4" $test]} {
+                # BSD-4 => BSD-old
+                ui_error "Invalid license '${test}': use BSD-old instead"
+            }
+
+            set prev $test
+        }
+
     }
 
     # these checks are only valid for ports stored in the regular tree directories
@@ -547,8 +606,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-post-destroot/base/src/port1.0/portlivecheck.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portlivecheck.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portlivecheck.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,7 +3,8 @@
 #
 # $Id$
 #
-# Copyright (c) 2005-2006 Paul Guyot <pguyot at kallisys.net>,
+# Copyright (c) 2007-2011 The MacPorts Project
+# Copyright (c) 2005-2007 Paul Guyot <pguyot at kallisys.net>,
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -15,7 +16,7 @@
 # 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 Computer, Inc. nor the names of its
+# 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.
 #
@@ -46,11 +47,10 @@
 }
 
 # define options
-options livecheck.url livecheck.type livecheck.check livecheck.md5 livecheck.regex livecheck.name livecheck.distname livecheck.version livecheck.ignore_sslcert
+options livecheck.url livecheck.type livecheck.md5 livecheck.regex livecheck.name livecheck.distname livecheck.version livecheck.ignore_sslcert
 
 # defaults
 default livecheck.url {$homepage}
-default livecheck.check default
 default livecheck.type default
 default livecheck.md5 ""
 default livecheck.regex ""
@@ -59,9 +59,6 @@
 default livecheck.version {$version}
 default livecheck.ignore_sslcert yes
 
-# Deprecation
-option_deprecate livecheck.check livecheck.type
-
 proc portlivecheck::livecheck_main {args} {
     global livecheck.url livecheck.type livecheck.md5 livecheck.regex livecheck.name livecheck.distname livecheck.version
     global livecheck.ignore_sslcert
@@ -90,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"} {
@@ -100,6 +97,14 @@
         if {$has_master_sites} {
             foreach {master_site} ${master_sites} {
                 if {[regexp "^($available_types)(?::(\[^:\]+))?" ${master_site} _ site subdir]} {
+                    set subdirs [split $subdir /]
+                    if {[llength $subdirs] > 1} {
+                        if {[lindex $subdirs 0] == "project"} {
+                            set subdir [lindex $subdirs 1]
+                        } else {
+                            set subdir ""
+                        }
+                    }
                     if {${subdir} ne "" && ${livecheck.name} eq "default"} {
                         set livecheck.name ${subdir}
                     }
@@ -164,12 +169,15 @@
                     set updated_version 0
                     set foundmatch 0
                     while {[gets $chan line] >= 0} {
-                        if {[regexp $the_re $line matched upver]} {
+                        set lastoff 0
+                        while {[regexp -start $lastoff -indices $the_re $line offsets]} {
+                            regexp -start $lastoff $the_re $line matched upver
                             set foundmatch 1
-                            if {$updated_version == 0 || [rpm-vercomp $upver $updated_version] > 0} {
+                            if {$updated_version == 0 || [vercmp $upver $updated_version] > 0} {
                                 set updated_version $upver
                             }
                             ui_debug "The regex matched \"$matched\", extracted \"$upver\""
+                            set lastoff [lindex $offsets end]
                         }
                     }
                     if {$foundmatch == 1} {

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portload.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portload.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portload.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # portsubmit.tcl
 # $Id$
 #
-# Copyright (c) 2007 MacPorts Project
+# Copyright (c) 2007, 2009, 2011 The MacPorts Project
 # Copyright (c) 2007 James D. Berry
 # All rights reserved.
 #
@@ -14,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -36,6 +36,7 @@
 
 set org.macports.load [target_new org.macports.load portload::load_main]
 target_runtype ${org.macports.load} always
+target_state ${org.macports.load} no
 target_provides ${org.macports.load} load 
 target_requires ${org.macports.load} main
 

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portmain.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portmain.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portmain.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portmain.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2004 - 2005, 2007 - 2012 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -43,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 \
@@ -51,10 +54,10 @@
         os.platform os.subplatform os.version os.major os.arch os.endian \
         platforms default_variants install.user install.group \
         macosx_deployment_target universal_variant os.universal_supported \
-        supported_archs depends_skip_archcheck \
-        copy_log_files \
+        supported_archs depends_skip_archcheck installs_libs \
+        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.
 
@@ -64,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
+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 {} {
@@ -88,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
@@ -143,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-post-destroot/base/src/port1.0/portmirror.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portmirror.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portmirror.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,6 +3,7 @@
 #
 # $Id$
 #
+# Copyright (c) 2007-2011 The MacPorts Project
 # Copyright (c) 2006 Paul Guyot <pguyot at kallisys.net>,
 # All rights reserved.
 #
@@ -15,7 +16,7 @@
 # 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 Computer, Inc. nor the names of its
+# 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.
 #

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portpatch.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portpatch.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portpatch.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portpatch.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2003 Apple Computer, Inc.
+# Copyright (c) 2004, 2006-2007, 2009-2011 The MacPorts Project
+# Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -96,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-post-destroot/base/src/port1.0/portsandbox.tcl (from rev 98879, trunk/base/src/port1.0/portsandbox.tcl)
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portsandbox.tcl	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portsandbox.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,83 @@
+# -*- 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
+
+    switch $target {
+        activate -
+        deactivate -
+        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}]
+        }
+    }
+
+    # TODO: remove altprefix support
+    lappend allow_dirs $workpath $altprefix
+
+    set portsandbox_profile "(version 1) (allow default) (deny file-write*) \
+(allow file-write-data (literal \"/dev/null\")) (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-post-destroot/base/src/port1.0/portstartupitem.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portstartupitem.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portstartupitem.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,7 +3,7 @@
 #
 # $Id$
 #
-# Copyright (c) 2004-2007 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.
@@ -17,7 +17,7 @@
 # 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 Computer, Inc. nor the names of its
+# 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.
 # 
@@ -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
     
@@ -573,7 +574,7 @@
     set plist [open "${destroot}${itemdir}/${plistname}" w 0644]
     
     puts ${plist} "<?xml version='1.0' encoding='UTF-8'?>"
-    puts ${plist} "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\""
+    puts ${plist} "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\""
     puts ${plist} "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\" >"
     puts ${plist} "<plist version='1.0'>"
     puts ${plist} "<dict>"
@@ -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}"
     }

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portsubmit.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portsubmit.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portsubmit.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,8 @@
 # portsubmit.tcl
 # $Id$
 #
-# Copyright (c) 2002 - 2004 Apple Computer, Inc.
+# 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
@@ -13,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -136,7 +137,7 @@
     }
 
     if {[system $cmd] != ""} {
-    return -code error [format [msgcat::mc "Failed to archive port : %s"] $name]
+    return -code error [format [msgcat::mc "Failed to archive port %s"] $name]
     }
 
     set portsource ""
@@ -196,7 +197,7 @@
 
     ui_debug $cmd
     if {[system $cmd] != ""} {
-    return -code error [format [msgcat::mc "Failed to submit port : %s"] $name]
+    return -code error [format [msgcat::mc "Failed to submit port %s"] $name]
     }
 
     #

Modified: branches/gsoc11-post-destroot/base/src/port1.0/porttrace.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/porttrace.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/porttrace.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -15,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its
+# 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.
 #
@@ -183,8 +183,12 @@
     thread::send $trace_thread "package require registry 1.0"
     # and this file as well.
     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"
+    # 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\""
 

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portuninstall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portuninstall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portuninstall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # portuninstall.tcl
 # $Id$
 #
-# Copyright (c) 2010 The MacPorts Project
+# Copyright (c) 2010-2011 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -50,7 +50,7 @@
 
 proc portuninstall::uninstall_start {args} {
     global prefix
-    if { ![file writable $prefix] } {
+    if {![file writable $prefix] || ([getuid] == 0 && [geteuid] != 0)} {
         # if install location is not writable, need root privileges
         elevateToRoot "uninstall"
     }
@@ -58,6 +58,6 @@
 
 proc portuninstall::uninstall_main {args} {
     global subport version revision portvariants user_options
-    registry_uninstall $subport "${version}_${revision}${portvariants}" [array get user_options]
+    registry_uninstall $subport $version $revision $portvariants [array get user_options]
     return 0
 }

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portunload.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portunload.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portunload.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,7 +2,7 @@
 # portsubmit.tcl
 # $Id$
 #
-# Copyright (c) 2007 MacPorts Project
+# Copyright (c) 2007, 2009, 2011 The MacPorts Project
 # Copyright (c) 2007 James D. Berry
 # All rights reserved.
 #
@@ -14,7 +14,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -36,6 +36,7 @@
 
 set org.macports.unload [target_new org.macports.unload portunload::unload_main]
 target_runtype ${org.macports.unload} always
+target_state ${org.macports.unload} no
 target_provides ${org.macports.unload} unload 
 target_requires ${org.macports.unload} main
 

Modified: branches/gsoc11-post-destroot/base/src/port1.0/portutil.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/portutil.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/port1.0/portutil.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,9 +2,10 @@
 # portutil.tcl
 # $Id$
 #
+# Copyright (c) 2002-2003 Apple Inc.
 # Copyright (c) 2004 Robert Shaw <rshaw at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
-# Copyright (c) 2006, 2007 Markus W. Weissmann <mww at macports.org>
+# Copyright (c) 2006-2007 Markus W. Weissmann <mww at macports.org>
+# Copyright (c) 2004-2012 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -15,7 +16,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 #
@@ -131,11 +132,11 @@
 }
 
 ##
-# Handle option-replace
+# Handle option-strsed
 #
 # @param option name of the option
 # @param args arguments
-proc handle_option-replace {option args} {
+proc handle_option-strsed {option args} {
     global $option user_options option_procs
 
     if {![info exists user_options($option)] && [info exists $option]} {
@@ -147,6 +148,36 @@
     }
 }
 
+##
+# Handle option-replace
+#
+# @param option name of the option
+# @param args arguments
+proc handle_option-replace {option args} {
+    global $option user_options option_procs deprecated_options
+
+    # Deprecate -replace with only one argument, for backwards compatibility call -strsed
+    # XXX: Remove this in 2.2.0
+    if {[llength $args] == 1} {
+        if {![info exists deprecated_options(${option}-replace)]} {
+            set deprecated_options(${option}-replace) [list ${option}-strsed 0]
+        }
+        set refcount [lindex $deprecated_options(${option}-replace) 1]
+        lset deprecated_options(${option}-replace) 1 [expr $refcount + 1]
+        return [eval handle_option-strsed $option $args]
+    }
+
+    if {![info exists user_options($option)] && [info exists $option]} {
+        foreach {old new} $args {
+            set index [lsearch -exact [set $option] $old]
+            if {$index == -1} {
+                continue
+            }
+            set $option [lreplace [set $option] $index $index $new]
+        }
+    }
+}
+
 # options
 # Exports options in an array as externally callable procedures
 # Thus, "options name date" would create procedures named "name"
@@ -159,6 +190,7 @@
         interp alias {} $option {} handle_option $option
         interp alias {} $option-append {} handle_option-append $option
         interp alias {} $option-delete {} handle_option-delete $option
+        interp alias {} $option-strsed {} handle_option-strsed $option
         interp alias {} $option-replace {} handle_option-replace $option
     }
 }
@@ -176,7 +208,7 @@
             set PortInfo($option) $value
         }
         delete {
-            unset PortInfo($option)
+            unset -nocomplain PortInfo($option)
         }
     }
 }
@@ -323,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 ""
@@ -339,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} {
@@ -347,33 +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] :]
     }
 
     # 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.
@@ -384,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 *
@@ -401,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
@@ -745,11 +788,12 @@
 # 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 {$subname == $subport} {
+    if {[string equal -nocase $subname $subport]} {
         set PortInfo(name) $subname
         uplevel 1 $body
     }
@@ -871,20 +915,36 @@
 # reinplace
 # Provides "sed in place" functionality
 proc reinplace {args}  {
-
+    global env worksrcpath
     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
                 }
@@ -897,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"
@@ -927,15 +991,33 @@
             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)
+                }
+            }
             close $tmpfd
             return -code error "reinplace sed(1) failed"
         }
 
+        if {$locale != ""} {
+            if {$oldlocale_exists} {
+                set env(LC_CTYPE) $oldlocale
+            } else {
+                unset env(LC_CTYPE)
+            }
+        }
         close $tmpfd
 
         set attributes [file attributes $file]
@@ -1228,11 +1310,14 @@
 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
     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"
 
     if {[ditem_key $ditem state] != "no"} {
         set target_state_fd [open_statefile]
@@ -1241,6 +1326,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
@@ -1248,6 +1334,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} {
@@ -1273,13 +1362,17 @@
 
             # otherwise execute the task.
             if {$skipped == 0} {
-                set target [ditem_key $ditem provides]
+                # change current phase shown in log
+                set_phase $target
 
                 # 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
                 }
-                set_phase  $target
+
                 #start tracelib
                 if {($result ==0
                   && [info exists ports_trace]
@@ -1351,19 +1444,28 @@
                     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 }
                     }
                 }
@@ -1372,6 +1474,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.
@@ -1411,9 +1516,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
         }
 
@@ -1426,6 +1531,8 @@
         close $target_state_fd
     }
 
+    set env(HOME) $savedhome
+
     return $result
 }
 
@@ -1478,7 +1585,7 @@
             ui_debug "Skipping $target ($subport) since this port is already installed"
             return 0
         } elseif {$target == "activate"} {
-            set regref [registry_open $subport $version $revision $portvariants $epoch]
+            set regref [registry_open $subport $version $revision $portvariants ""]
             if {[registry_prop_retr $regref active] != 0} {
                 # Something to close the registry entry may be called here, if it existed.
                 ui_debug "Skipping $target ($subport @${version}_${revision}${portvariants}) since this port is already active"
@@ -1515,7 +1622,7 @@
 
     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]"
         }
@@ -1531,8 +1638,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.\
@@ -1557,9 +1664,11 @@
         }
     }
 
-    if {![file isdirectory $workpath] && ![tbool ports_dryrun]} {
-        file mkdir $workpath
-        chownAsRoot $subbuildpath
+    if {![tbool ports_dryrun]} {
+        if {![file isdirectory $workpath]} {
+            file mkdir "${workpath}/.home"
+            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"
@@ -1572,22 +1681,75 @@
 
     # 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]} {
+        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
@@ -1607,9 +1769,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} {
@@ -1646,19 +1827,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
@@ -1767,7 +1953,7 @@
     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
         }
     }
@@ -2018,20 +2204,18 @@
             array set vinfo $PortInfo(vinfo)
 
             foreach v $value {
-                if {[regexp {([-+])([-A-Za-z0-9_]+)} $v whole val variant]} {
+                if {[regexp {([-+])([-A-Za-z0-9_]+)} $v whole val variant] && ![info exists variations($variant)]} {
                     # Retrieve the information associated with this variant.
                     if {![info exists vinfo($variant)]} {
                         set vinfo($variant) {}
                     }
+                    array unset info
                     array set info $vinfo($variant)
+                    # Set is_default and update vinfo.
+                    set info(is_default) $val
+                    array set vinfo [list $variant [array get info]]
 
-                    if {![info exists variations($variant)]} {
-                        # Set is_default and update vinfo.
-                        array set info [list is_default val]
-                        array set vinfo [list $variant [array get info]]
-
-                        set variations($variant) $val
-                    }
+                    set variations($variant) $val
                 }
             }
             # Update PortInfo(vinfo).
@@ -2075,14 +2259,15 @@
         return
     } elseif {[geteuid] != 0} {
         seteuid 0; setegid 0
+        set escalated 1
     }
 
     set passwd {*}
     set uid [nextuid]
     set gid [existsgroup nogroup]
     set realname ${name}
-    set home /dev/null
-    set shell /dev/null
+    set home /var/empty
+    set shell /usr/bin/false
 
     foreach arg $args {
         if {[regexp {([a-z]*)=(.*)} $arg match key val]} {
@@ -2096,10 +2281,20 @@
 
     if {${os.platform} eq "darwin"} {
         set dscl [findBinary dscl $portutil::autoconf::dscl_path]
+        exec $dscl . -create /Users/${name} UniqueID ${uid}
+
+        # These are implicitly added on Mac OSX Lion.  AuthenticationAuthority
+        # causes the user to be visible in the Users & Groups Preference Pane,
+        # and the others are just noise, so delete them.
+        # https://trac.macports.org/ticket/30168
+        exec $dscl . -delete /Users/${name} AuthenticationAuthority
+        exec $dscl . -delete /Users/${name} PasswordPolicyOptions
+        exec $dscl . -delete /Users/${name} dsAttrTypeNative:KerberosKeys
+        exec $dscl . -delete /Users/${name} dsAttrTypeNative:ShadowHashData
+
+        exec $dscl . -create /Users/${name} RealName ${realname}
         exec $dscl . -create /Users/${name} Password ${passwd}
-        exec $dscl . -create /Users/${name} UniqueID ${uid}
         exec $dscl . -create /Users/${name} PrimaryGroupID ${gid}
-        exec $dscl . -create /Users/${name} RealName ${realname}
         exec $dscl . -create /Users/${name} NFSHomeDirectory ${home}
         exec $dscl . -create /Users/${name} UserShell ${shell}
     } else {
@@ -2107,6 +2302,10 @@
         ui_warn "adduser is not implemented on ${os.platform}."
         ui_warn "The requested user '$name' was not created."
     }
+
+    if {[info exists escalated]} {
+        dropPrivileges
+    }
 }
 
 proc addgroup {name args} {
@@ -2118,6 +2317,7 @@
         return
     } elseif {[geteuid] != 0} {
         seteuid 0; setegid 0
+        set escalated 1
     }
 
     set gid [nextgid]
@@ -2148,6 +2348,10 @@
         ui_warn "addgroup is not implemented on ${os.platform}."
         ui_warn "The requested group was not created."
     }
+
+    if {[info exists escalated]} {
+        dropPrivileges
+    }
 }
 
 # proc to calculate size of a directory
@@ -2191,10 +2395,16 @@
     }
 }
 
-# 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
+    return "${subport}-${version}_${revision}${portvariants}.${os.platform}_${os.major}.[join [get_canonical_archs] -].${portarchivetype}"
+}
+
+# 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
@@ -2211,6 +2421,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} {
@@ -2506,6 +2738,15 @@
     }
 }
 
+proc validate_macportsuser {} {
+    global macportsuser
+    if {[getuid] == 0 && $macportsuser != "root" && 
+        ([existsuser $macportsuser] == 0 || [existsgroup $macportsuser] == 0 )} {
+        ui_warn "configured user/group $macportsuser does not exist, will build as root"
+        set macportsuser "root"
+    }
+}
+
 # dependency analysis helpers
 
 ### _libtest is private; subject to change without notice
@@ -2633,6 +2874,18 @@
     }
 }
 
+# returns the flags that should be passed to the compiler to choose arch(s)
+proc get_canonical_archflags {{tool cc}} {
+    if {![variant_exists universal] || ![variant_isset universal]} {
+        return [option configure.${tool}_archflags]
+    } else {
+        if {$tool == "cc" || $tool == "objc"} {
+            set tool c
+        }
+        return [option configure.universal_${tool}flags]
+    }
+}
+
 # check that the selected archs are supported
 proc check_supported_archs {} {
     global supported_archs build_arch universal_archs configure.build_arch configure.universal_archs subport
@@ -2668,45 +2921,103 @@
                 set ok 3.1
                 set rec 3.1.4
             }
-            default {
+            10.6 {
                 set min 3.2
                 set ok 3.2
-                set rec 3.2.4
+                set rec 3.2.6
             }
+            default {
+                set min 4.1
+                set ok 4.1
+                set rec 4.1
+            }
         }
         if {$xcodeversion == "none"} {
             ui_warn "Xcode does not appear to be installed; most ports will likely fail to build."
-        } elseif {[rpm-vercomp $xcodeversion $min] < 0} {
+            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} {
             ui_error "The installed version of Xcode (${xcodeversion}) is too old to use on the installed OS version. Version $rec or later is recommended on Mac OS X ${macosx_version}."
             return 1
-        } elseif {[rpm-vercomp $xcodeversion $ok] < 0} {
+        } 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
+    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
     }
-    
-    # TODO: also check if porturl points to an archive
-    # maybe check if there's an archive available on the server too - this
-    # is kind of useless otherwise now that archive == installed image
 
-    return $found
+    set archiverootname [file rootname [get_portimage_name]]
+    if {[file rootname [file tail $porturl]] == $archiverootname && [file extension $porturl] != ""} {
+        set archive_available_result 1
+        return 1
+    }
+
+    # 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
+    }
+
+    set archive_available_result 0
+    return 0
 }

Copied: branches/gsoc11-post-destroot/base/src/port1.0/tests/common.tcl (from rev 98879, trunk/base/src/port1.0/tests/common.tcl)
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/tests/common.tcl	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/port1.0/tests/common.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/port1.0/tests/portdestroot.tcl (from rev 98879, trunk/base/src/port1.0/tests/portdestroot.tcl)
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/tests/portdestroot.tcl	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/port1.0/tests/portdestroot.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/port1.0/tests/portfetch.tcl (from rev 98879, trunk/base/src/port1.0/tests/portfetch.tcl)
===================================================================
--- branches/gsoc11-post-destroot/base/src/port1.0/tests/portfetch.tcl	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/port1.0/tests/portfetch.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/portindex/portregister.pl
===================================================================
--- branches/gsoc11-post-destroot/base/src/portindex/portregister.pl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/portindex/portregister.pl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# Copyright (c) 2003-2004 Apple Computer, Inc.
+# Copyright (c) 2003-2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/portindex/portsubmit.pl
===================================================================
--- branches/gsoc11-post-destroot/base/src/portindex/portsubmit.pl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/portindex/portsubmit.pl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# Copyright (c) 2003-2004 Apple Computer, Inc.
+# Copyright (c) 2003-2004 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -11,7 +11,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/programs/daemondo/Makefile.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/programs/daemondo/Makefile.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/programs/daemondo/Makefile.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -8,7 +8,7 @@
 mandir=		@mandir@
 mandircat8=	${mandir}/cat8
 
-CFLAGS_QUICHEEATERS	= -W -Wall
+CFLAGS_PEDANTIC	=
 CPPFLAGS	+= -I../..
 SRCS		= main.c
 OBJS		= main.o

Modified: branches/gsoc11-post-destroot/base/src/programs/daemondo/main.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/programs/daemondo/main.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/programs/daemondo/main.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/registry2.0/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,6 +3,7 @@
 SRCS = registry.tcl registry_autoconf.tcl registry_util.tcl receipt_flat.tcl receipt_sqlite.tcl portimage.tcl portuninstall.tcl
 OBJS = registry.o util.o \
 	entry.o entryobj.o \
+	file.o fileobj.o \
 	../cregistry/cregistry.a
 	#graph.o graphobj.o
 
@@ -20,8 +21,8 @@
 .PHONY: test
 
 test:: ${SHLIB_NAME}
-	${TCLSH} tests/entry.tcl ${SHLIB_NAME}
-	${TCLSH} tests/depends.tcl ${SHLIB_NAME}
+	${TCLSH} tests/entry.tcl ./${SHLIB_NAME}
+	${TCLSH} tests/depends.tcl ./${SHLIB_NAME}
 
 distclean:: clean
 	rm -f registry_autoconf.tcl

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/entry.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/entry.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/entry.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -35,6 +36,8 @@
 #include <tcl.h>
 #include <sqlite3.h>
 
+#include <cregistry/util.h>
+
 #include "entry.h"
 #include "entryobj.h"
 #include "registry.h"
@@ -112,7 +115,7 @@
                 variants, epoch, &error);
         if (entry != NULL) {
             Tcl_Obj* result;
-            if (entry_to_obj(interp, &result, entry, &error)) {
+            if (entry_to_obj(interp, &result, entry, NULL, &error)) {
                 Tcl_SetObjResult(interp, result);
                 return TCL_OK;
             }
@@ -192,7 +195,7 @@
                 variants, epoch, &error);
         if (entry != NULL) {
             Tcl_Obj* result;
-            if (entry_to_obj(interp, &result, entry, &error)) {
+            if (entry_to_obj(interp, &result, entry, NULL, &error)) {
                 Tcl_SetObjResult(interp, result);
                 return TCL_OK;
             }
@@ -209,7 +212,7 @@
  */
 static int entry_close(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
     if (objc != 3) {
-        Tcl_WrongNumArgs(interp, 1, objv, "delete entry");
+        Tcl_WrongNumArgs(interp, 1, objv, "close entry");
         return TCL_ERROR;
     } else {
         reg_error error;
@@ -455,7 +458,7 @@
                 return TCL_OK;
             } else {
                 Tcl_Obj* result;
-                if (entry_to_obj(interp, &result, entry, &error)) {
+                if (entry_to_obj(interp, &result, entry, NULL, &error)) {
                     Tcl_SetObjResult(interp, result);
                     return TCL_OK;
                 }

Copied: branches/gsoc11-post-destroot/base/src/registry2.0/file.c (from rev 98879, trunk/base/src/registry2.0/file.c)
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/file.c	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/file.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,292 @@
+/*
+ * file.c
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sqlite3.h>
+#include <stdlib.h>
+#include <string.h>
+#include <tcl.h>
+
+#include <cregistry/file.h>
+#include <cregistry/util.h>
+
+#include "file.h"
+#include "fileobj.h"
+#include "registry.h"
+#include "util.h"
+
+/**
+ * Converts a command name into a `reg_file`.
+ *
+ * @param [in] interp  Tcl interpreter to check within
+ * @param [in] name    name of file to get
+ * @param [out] errPtr description of error if the file can't be found
+ * @return             a file, or NULL if one couldn't be found
+ * @see get_object
+ */
+static reg_file* get_file(Tcl_Interp* interp, char* name, reg_error* errPtr) {
+    return (reg_file*)get_object(interp, name, "file", file_obj_cmd, errPtr);
+}
+
+/**
+ * Removes the file from the Tcl interpreter. Doesn't actually delete it since
+ * that's the registry's job. This is written to be used as the
+ * `Tcl_CmdDeleteProc` for an file object command.
+ *
+ * @param [in] clientData address of a reg_file to remove
+ */
+void delete_file(ClientData clientData) {
+    reg_file* file = (reg_file*)clientData;
+    free(file->proc);
+    free(file->key.path);
+    file->proc = NULL;
+}
+
+/**
+ * registry::file open portid path
+ *
+ * Opens a file matching the given parameters.
+ */
+static int file_open(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
+	reg_registry* reg = registry_for(interp, reg_attached);
+	if (objc != 4) {
+		Tcl_WrongNumArgs(interp, 1, objv, "open portid path");
+		return TCL_ERROR;
+	} else if (reg == NULL) {
+		return TCL_ERROR;
+	} else {
+		char* id = Tcl_GetString(objv[2]);
+		char* path = Tcl_GetString(objv[3]);
+		reg_error error;
+		reg_file* file = reg_file_open(reg, id, path, &error);
+		if (file != NULL) {
+			Tcl_Obj* result;
+			if (file_to_obj(interp, &result, file, NULL, &error)) {
+				Tcl_SetObjResult(interp, result);
+				return TCL_OK;
+			}
+		}
+		return registry_failed(interp, &error);
+	}
+	return TCL_ERROR;
+}
+
+/**
+ * registry::file close file
+ *
+ * Closes a file. It will remain in the registry.
+ */
+static int file_close(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
+	if (objc != 3) {
+		Tcl_WrongNumArgs(interp, 1, objv, "close file");
+		return TCL_ERROR;
+	} else {
+		reg_error error;
+		char* proc = Tcl_GetString(objv[2]);
+		reg_file* file = get_file(interp, proc, &error);
+		if (file == NULL) {
+			return registry_failed(interp, &error);
+		} else {
+			Tcl_DeleteCommand(interp, proc);
+			return TCL_OK;
+		}
+	}
+}
+
+typedef struct {
+    char* name;
+    reg_strategy strategy;
+} strategy_type;
+
+static strategy_type strategies[] = {
+    { "-exact",  reg_strategy_exact },
+    { "-glob",   reg_strategy_glob },
+    { "-regexp", reg_strategy_regexp },
+    { "-null",   reg_strategy_null },
+    { "--",      reg_strategy_exact },
+    { NULL, 0 }
+};
+
+/*
+ * registry::file search ?key value ...?
+ *
+ * Searches the registry for files for which each key's value is equal to the
+ * given value. To find all files, call `file search` with no key-value pairs.
+ * For each key, can be given an option of -exact, -glob, -regexp or -null to
+ * specify the matching strategy; defaults to exact.
+ */
+static int file_search(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
+    int i, j;
+    reg_registry* reg = registry_for(interp, reg_attached);
+    if (reg == NULL) {
+        return TCL_ERROR;
+    } else {
+        char** keys;
+        char** vals;
+        int* strats;
+        int key_count = 0;
+        reg_file** files;
+        reg_error error;
+        int file_count;
+        for (i = 2; i < objc;) {
+            int index, strat_index, val_length;
+            if (Tcl_GetIndexFromObj(interp, objv[i], file_props, "search key",
+                        0, &index) != TCL_OK) {
+                return TCL_ERROR;
+            }
+
+            /* we ate the key value */
+            i++;
+
+            /* check whether there's a strategy */
+            if (Tcl_GetString(objv[i])[0] == '-'
+                    && Tcl_GetIndexFromObjStruct(interp, objv[i], strategies,
+                        sizeof(strategy_type), "option", 0, &strat_index)
+                    != TCL_ERROR) {
+                /* this key has a strategy specified, eat the strategy parameter */
+                i++;
+
+                if (strategies[strat_index].strategy != reg_strategy_null) {
+                    /* this key must also have a value */
+
+                    if (Tcl_GetStringFromObj(objv[i], &val_length) == NULL
+                            || val_length == 0) {
+                        Tcl_WrongNumArgs(interp, 2, objv,
+                                "search ?key ?options? value ...?");
+                        return TCL_ERROR;
+                    }
+
+                    i++;
+                }
+            } else {
+                /* this key must also have a value */
+
+                if (Tcl_GetStringFromObj(objv[i], &val_length) == NULL
+                        || val_length == 0) {
+                    Tcl_WrongNumArgs(interp, 2, objv,
+                            "search ?key ?options? value ...?");
+                    return TCL_ERROR;
+                }
+
+                i++;
+            }
+
+            key_count++;
+        }
+
+        keys = malloc(key_count * sizeof(char*));
+        vals = malloc(key_count * sizeof(char*));
+        strats = malloc(key_count * sizeof(int));
+        if (!keys || !vals || !strats) {
+            return TCL_ERROR;
+        }
+        for (i = 2, j = 0; i < objc && j < key_count; j++) {
+            int strat_index;
+
+            keys[j] = Tcl_GetString(objv[i++]);
+
+            /* try to get the strategy */
+            if (Tcl_GetString(objv[i])[0] == '-'
+                    && Tcl_GetIndexFromObjStruct(interp, objv[i], strategies,
+                        sizeof(strategy_type), "option", 0, &strat_index)
+                    != TCL_ERROR) {
+                /* this key has a strategy specified */
+                i++;
+
+                strats[j] = strategies[strat_index].strategy;
+            } else {
+                /* use default strategy */
+                strats[j] = reg_strategy_exact;
+            }
+
+            if (strats[j] != reg_strategy_null) {
+                vals[j] = Tcl_GetString(objv[i++]);
+            } else {
+                vals[j] = NULL;
+            }
+        }
+        file_count = reg_file_search(reg, keys, vals, strats, key_count,
+                &files, &error);
+        free(keys);
+        free(vals);
+        free(strats);
+        if (file_count >= 0) {
+            int retval;
+            Tcl_Obj* resultObj;
+            Tcl_Obj** objs;
+            if (list_file_to_obj(interp, &objs, files, file_count, &error)){
+                resultObj = Tcl_NewListObj(file_count, objs);
+                Tcl_SetObjResult(interp, resultObj);
+                free(objs);
+                retval = TCL_OK;
+            } else {
+                retval = registry_failed(interp, &error);
+            }
+            free(files);
+            return retval;
+        }
+        return registry_failed(interp, &error);
+    }
+}
+
+typedef struct {
+    char* name;
+    int (*function)(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
+} file_cmd_type;
+
+static file_cmd_type file_cmds[] = {
+    /* Global commands */
+    { "open", file_open },
+    { "close", file_close },
+    { "search", file_search },
+    { NULL, NULL }
+};
+
+/*
+ * registry::file cmd ?arg ...?
+ *
+ * Commands manipulating file entries in the registry. This can be called `registry::file`
+ */
+int file_cmd(ClientData clientData UNUSED, Tcl_Interp* interp, int objc,
+        Tcl_Obj* CONST objv[]) {
+    int cmd_index;
+    if (objc < 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "cmd ?arg ...?");
+        return TCL_ERROR;
+    }
+    if (Tcl_GetIndexFromObjStruct(interp, objv[1], file_cmds,
+                sizeof(file_cmd_type), "cmd", 0, &cmd_index) == TCL_OK) {
+        file_cmd_type* cmd = &file_cmds[cmd_index];
+        return cmd->function(interp, objc, objv);
+    }
+    return TCL_ERROR;
+}

Copied: branches/gsoc11-post-destroot/base/src/registry2.0/file.h (from rev 98879, trunk/base/src/registry2.0/file.h)
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/file.h	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/file.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,44 @@
+/*
+ * file.h
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+#ifndef _FILE_H
+#define _FILE_H
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <tcl.h>
+
+void delete_file(ClientData clientData);
+
+int file_cmd(ClientData clientData UNUSED, Tcl_Interp* interp, int objc,
+        Tcl_Obj* CONST objv[]);
+
+#endif /* _FILE_H */
+

Copied: branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.c (from rev 98879, trunk/base/src/registry2.0/fileobj.c)
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.c	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,142 @@
+/*
+ * fileobj.c
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+#include <tcl.h>
+#include <sqlite3.h>
+
+#include "fileobj.h"
+#include "registry.h"
+#include "util.h"
+
+const char* file_props[] = {
+    "path",
+    "actual_path",
+    "active",
+    "mtime",
+    "md5sum",
+    "editable",
+    "binary",
+    NULL
+};
+
+/* ${file} prop ?value? */
+static int file_obj_prop(Tcl_Interp* interp, reg_file* file, int objc,
+        Tcl_Obj* CONST objv[]) {
+    int index;
+    if (objc > 3) {
+        Tcl_WrongNumArgs(interp, 2, objv, "?value?");
+        return TCL_ERROR;
+    }
+    if (objc == 2) {
+        /* ${file} prop; return the current value */
+        reg_registry* reg = registry_for(interp, reg_attached);
+        if (reg == NULL) {
+            return TCL_ERROR;
+        }
+        if (Tcl_GetIndexFromObj(interp, objv[1], file_props, "prop", 0, &index)
+                == TCL_OK) {
+            char* key = Tcl_GetString(objv[1]);
+            char* value;
+            reg_error error;
+            if (reg_file_propget(file, key, &value, &error)) {
+                Tcl_Obj* result = Tcl_NewStringObj(value, -1);
+                Tcl_SetObjResult(interp, result);
+                free(value);
+                return TCL_OK;
+            }
+            return registry_failed(interp, &error);
+        }
+        return TCL_ERROR;
+    } else {
+        /* ${file} prop name value; set a new value */
+        reg_registry* reg = registry_for(interp, reg_attached);
+        if (reg == NULL) {
+            return TCL_ERROR;
+        }
+        if (Tcl_GetIndexFromObj(interp, objv[1], file_props, "prop", 0, &index)
+                == TCL_OK) {
+            char* key = Tcl_GetString(objv[1]);
+            char* value = Tcl_GetString(objv[2]);
+            reg_error error;
+            if (reg_file_propset(file, key, value, &error)) {
+                return TCL_OK;
+            }
+            return registry_failed(interp, &error);
+        }
+        return TCL_ERROR;
+    }
+}
+
+typedef struct {
+    char* name;
+    int (*function)(Tcl_Interp* interp, reg_file* file, int objc,
+            Tcl_Obj* CONST objv[]);
+} file_obj_cmd_type;
+
+static file_obj_cmd_type file_cmds[] = {
+    /* keys */
+    { "path", file_obj_prop },
+    { "actual_path", file_obj_prop },
+    { "active", file_obj_prop },
+    { "mtime", file_obj_prop },
+    { "md5sum", file_obj_prop },
+    { "editable", file_obj_prop },
+    { "binary", file_obj_prop },
+    { NULL, NULL }
+};
+
+/* ${file} cmd ?arg ...? */
+/* This function implements the command that will be called when a file
+ * created by `registry::file` is used as a procedure. Since all data is kept
+ * in a temporary sqlite3 database that is created for the current interpreter,
+ * none of the sqlite3 functions used have any error checking. That should be a
+ * safe assumption, since nothing outside of registry:: should ever have the
+ * chance to touch it.
+ */
+int file_obj_cmd(ClientData clientData, Tcl_Interp* interp, int objc,
+        Tcl_Obj* CONST objv[]) {
+    int cmd_index;
+    if (objc < 2) {
+        Tcl_WrongNumArgs(interp, 1, objv, "cmd ?arg ...?");
+        return TCL_ERROR;
+    }
+    if (Tcl_GetIndexFromObjStruct(interp, objv[1], file_cmds,
+                sizeof(file_obj_cmd_type), "cmd", 0, &cmd_index) == TCL_OK) {
+        file_obj_cmd_type* cmd = &file_cmds[cmd_index];
+        return cmd->function(interp, (reg_file*)clientData, objc, objv);
+    }
+    return TCL_ERROR;
+}
+

Copied: branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.h (from rev 98879, trunk/base/src/registry2.0/fileobj.h)
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.h	                        (rev 0)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/fileobj.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -0,0 +1,44 @@
+/*
+ * fileobj.h
+ * vim:tw=80:expandtab
+ * $Id$
+ *
+ * Copyright (c) 2011 Clemens Lang <cal at macports.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+#ifndef _FILE_OBJ_CMD_H
+#define _FILE_OBJ_CMD_H
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <tcl.h>
+#include <sqlite3.h>
+
+extern const char* file_props[];
+
+int file_obj_cmd(ClientData clientData, Tcl_Interp* interp, int objc,
+        Tcl_Obj* CONST objv[]);
+
+#endif /* _FILE_OBJ_CMD_H */

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/graph.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/graph.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/graph.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/registry2.0/item.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/item.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/item.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/registry2.0/itemobj.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/itemobj.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/itemobj.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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-post-destroot/base/src/registry2.0/portimage.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/portimage.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/portimage.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,6 +2,7 @@
 # portimage.tcl
 # $Id$
 #
+# Copyright (c) 2004-2005, 2007-2011 The MacPorts Project
 # Copyright (c) 2004 Will Barton <wbb4 at opendarwin.org>
 # Copyright (c) 2002 Apple Inc.
 # All rights reserved.
@@ -61,15 +62,23 @@
 namespace eval portimage {
 
 variable force 0
-variable use_reg2 0
 variable noexec 0
 
+# takes a composite version spec rather than separate version,revision,variants
+proc activate_composite {name {v ""} {optionslist ""}} {
+    if {$v == ""} {
+        return [activate $name "" "" 0 $optionslist]
+    } elseif {[registry::decode_spec $v version revision variants]} {
+        return [activate $name $version $revision $variants $optionslist]
+    }
+    throw registry::invalid "Registry error: Invalid version '$v' specified for ${name}. Please specify a version as recorded in the port registry."
+}
+
 # Activate a "Port Image"
-proc activate {name v optionslist} {
-    global macports::prefix macports::registry.format macports::registry.path registry_open UI_PREFIX
+proc activate {name {version ""} {revision ""} {variants 0} {optionslist ""}} {
+    global macports::prefix macports::registry.path registry_open UI_PREFIX
     array set options $optionslist
     variable force
-    variable use_reg2
     variable noexec
 
     if {[info exists options(ports_force)] && [string is true -strict $options(ports_force)] } {
@@ -78,128 +87,67 @@
     if {[info exists options(ports_activate_no-exec)]} {
         set noexec $options(ports_activate_no-exec)
     }
-    if {[string equal ${macports::registry.format} "receipt_sqlite"]} {
-        set use_reg2 1
-        if {![info exists registry_open]} {
-            registry::open [file join ${macports::registry.path} registry registry.db]
-            set registry_open yes
-        }
+    if {![info exists registry_open]} {
+        registry::open [::file join ${macports::registry.path} registry registry.db]
+        set registry_open yes
     }
     set todeactivate [list]
 
-    if {$use_reg2} {
-        registry::read {
+    registry::read {
 
-            set requested [_check_registry $name $v]
-            # set name again since the one we were passed may not have had the correct case
-            set name [$requested name]
-            set version [$requested version]
-            set revision [$requested revision]
-            set variants [$requested variants]
-            set specifier "${version}_${revision}${variants}"
-            set location [$requested location]
-
-            # if another version of this port is active, deactivate it first
-            set current [registry::entry installed $name]
-            foreach i $current {
-                if { ![string equal $specifier "[$i version]_[$i revision][$i variants]"] } {
-                    lappend todeactivate $i
-                }
-            }
-
-            # this shouldn't be possible
-            if { ![string equal [$requested installtype] "image"] } {
-                return -code error "Image error: ${name} @${version}_${revision}${variants} not installed as an image."
-            }
-            if {![file isfile $location]} {
-                return -code error "Image error: Can't find image file $location"
-            }
-            if { [string equal [$requested state] "installed"] } {
-                return -code error "Image error: ${name} @${version}_${revision}${variants} is already active."
-            }
-        }
-        foreach a $todeactivate {
-            if {$noexec || ![registry::run_target $a deactivate [list ports_nodepcheck 1]]} {
-                deactivate $name "[$a version]_[$a revision][$a variants]" [list ports_nodepcheck 1]
-            }
-        }
-    } else {
-        # registry1.0
-        set ilist [_check_registry $name $v]
+        set requested [_check_registry $name $version $revision $variants]
         # set name again since the one we were passed may not have had the correct case
-        set name [lindex $ilist 0]
-        set version [lindex $ilist 1]
-        set revision [lindex $ilist 2]
-        set variants [lindex $ilist 3]
+        set name [$requested name]
+        set version [$requested version]
+        set revision [$requested revision]
+        set variants [$requested variants]
+        set specifier "${version}_${revision}${variants}"
+        set location [$requested location]
 
         # if another version of this port is active, deactivate it first
-        set ilist [registry::installed $name]
-        if { [llength $ilist] > 1 } {
-            foreach i $ilist {
-                set iversion [lindex $i 1]
-                set irevision [lindex $i 2]
-                set ivariants [lindex $i 3]
-                set iactive [lindex $i 4]
-                if { ![string equal "${iversion}_${irevision}${ivariants}" "${version}_${revision}${variants}"] && $iactive == 1 } {
-                    lappend todeactivate "${iversion}_${irevision}${ivariants}"
-                }
+        set current [registry::entry installed $name]
+        foreach i $current {
+            if { ![string equal $specifier "[$i version]_[$i revision][$i variants]"] } {
+                lappend todeactivate $i
             }
         }
 
-        set ref [registry::open_entry $name $version $revision $variants]
-
-        if { ![string equal [registry::property_retrieve $ref installtype] "image"] } {
-            return -code error "Image error: ${name} @${version}_${revision}${variants} not installed as an image."
+        # this shouldn't be possible
+        if { ![string equal [$requested installtype] "image"] } {
+            return -code error "Image error: ${name} @${specifier} not installed as an image."
         }
-        set location [registry::property_retrieve $ref location]
-        if {![file isfile $location]} {
+        if {![::file isfile $location]} {
             return -code error "Image error: Can't find image file $location"
         }
-        if { [registry::property_retrieve $ref active] != 0 } {
-            return -code error "Image error: ${name} @${version}_${revision}${variants} is already active."
+        if { [string equal [$requested state] "installed"] } {
+            return -code error "Image error: ${name} @${specifier} is already active."
         }
-
-        foreach a $todeactivate {
-            deactivate $name $a [list ports_nodepcheck 1]
+    }
+    foreach a $todeactivate {
+        if {$noexec || ![registry::run_target $a deactivate [list ports_nodepcheck 1]]} {
+            deactivate $name [$a version] [$a revision] [$a variants] [list ports_nodepcheck 1]
         }
     }
 
-    if {$v != ""} {
-        ui_msg "$UI_PREFIX [format [msgcat::mc "Activating %s @%s"] $name $v]"
-    } else {
-        ui_msg "$UI_PREFIX [format [msgcat::mc "Activating %s"] $name]"
-    }
+    ui_msg "$UI_PREFIX [format [msgcat::mc "Activating %s @%s"] $name $specifier]"
 
-    if {$use_reg2} {
-        _activate_contents $requested
-        $requested state installed
-    } else {
-        set contents [registry::property_retrieve $ref contents]
+    _activate_contents $requested
+    $requested state installed
+}
 
-        set imagefiles {}
-        foreach content_element $contents {
-            lappend imagefiles [lindex $content_element 0]
-        }
-
-        registry::open_file_map
-        _activate_contents $name $imagefiles $location
-
-        registry::property_store $ref active 1
-
-        registry::write_entry $ref
-
-        foreach file $imagefiles {
-            registry::register_file $file $name
-        }
-        registry::write_file_map
-        registry::close_file_map
+# takes a composite version spec rather than separate version,revision,variants
+proc deactivate_composite {name {v ""} {optionslist ""}} {
+    if {$v == ""} {
+        return [deactivate $name "" "" 0 $optionslist]
+    } elseif {[registry::decode_spec $v version revision variants]} {
+        return [deactivate $name $version $revision $variants $optionslist]
     }
+    throw registry::invalid "Registry error: Invalid version '$v' specified for ${name}. Please specify a version as recorded in the port registry."
 }
 
-proc deactivate {name v optionslist} {
-    global UI_PREFIX macports::registry.format macports::registry.path registry_open
+proc deactivate {name {version ""} {revision ""} {variants 0} {optionslist ""}} {
+    global UI_PREFIX macports::registry.path registry_open
     array set options $optionslist
-    variable use_reg2
 
     if {[info exists options(ports_force)] && [string is true -strict $options(ports_force)] } {
         # this not using the namespace variable is correct, since activate
@@ -209,157 +157,89 @@
     } else {
         set force 0
     }
-    if {[string equal ${macports::registry.format} "receipt_sqlite"]} {
-        set use_reg2 1
-        if {![info exists registry_open]} {
-            registry::open [file join ${macports::registry.path} registry registry.db]
-            set registry_open yes
-        }
+    if {![info exists registry_open]} {
+        registry::open [::file join ${macports::registry.path} registry registry.db]
+        set registry_open yes
     }
 
-    if {$use_reg2} {
-        if { [string equal $name ""] } {
-            throw registry::image-error "Registry error: Please specify the name of the port."
-        }
-        set ilist [registry::entry installed $name]
-        if { [llength $ilist] == 1 } {
-            set requested [lindex $ilist 0]
-        } else {
-            throw registry::image-error "Image error: port ${name} is not active."
-        }
-        # set name again since the one we were passed may not have had the correct case
-        set name [$requested name]
-        set version [$requested version]
-        set revision [$requested revision]
-        set variants [$requested variants]
-        set specifier "${version}_${revision}${variants}"
+    if { [string equal $name ""] } {
+        throw registry::image-error "Registry error: Please specify the name of the port."
+    }
+    set ilist [registry::entry installed $name]
+    if { [llength $ilist] == 1 } {
+        set requested [lindex $ilist 0]
     } else {
-        set ilist [registry::active $name]
-        if { [llength $ilist] > 1 } {
-            return -code error "Registry error: Please specify the name of the port."
-        } else {
-            set ilist [lindex $ilist 0]
-        }
-        # set name again since the one we were passed may not have had the correct case
-        set name [lindex $ilist 0]
-        set version [lindex $ilist 1]
-        set revision [lindex $ilist 2]
-        set variants [lindex $ilist 3]
-        set specifier "${version}_${revision}${variants}"
+        throw registry::image-error "Image error: port ${name} is not active."
     }
+    # set name again since the one we were passed may not have had the correct case
+    set name [$requested name]
+    set specifier "[$requested version]_[$requested revision][$requested variants]"
 
-    if { $v != "" && ![string equal $specifier $v] } {
+    if {$version != "" && ($version != [$requested version] ||
+        ($revision != "" && ($revision != [$requested revision] || $variants != [$requested variants])))} {
+        set v $version
+        if {$revision != ""} {
+            append v _${revision}${variants}
+        }
         return -code error "Active version of $name is not $v but ${specifier}."
     }
 
-    if {$v != ""} {
-        ui_msg "$UI_PREFIX [format [msgcat::mc "Deactivating %s @%s"] $name $v]"
-    } else {
-        ui_msg "$UI_PREFIX [format [msgcat::mc "Deactivating %s"] $name]"
+    ui_msg "$UI_PREFIX [format [msgcat::mc "Deactivating %s @%s"] $name $specifier]"
+
+    if { ![string equal [$requested installtype] "image"] } {
+        return -code error "Image error: ${name} @${specifier} not installed as an image."
     }
+    # this shouldn't be possible
+    if { [$requested state] != "installed" } {
+        return -code error "Image error: ${name} @${specifier} is not active."
+    }
 
-    if {$use_reg2} {
-        if { ![string equal [$requested installtype] "image"] } {
-            return -code error "Image error: ${name} @${specifier} not installed as an image."
-        }
-        # this shouldn't be possible
-        if { [$requested state] != "installed" } {
-            return -code error "Image error: ${name} @${specifier} is not active."
-        }
-
-        if {![info exists options(ports_nodepcheck)] || ![string is true -strict $options(ports_nodepcheck)]} {
-            registry::check_dependents $requested $force "deactivate"
-        }
-
-        _deactivate_contents $requested [$requested files] $force
-        $requested state imaged
-    } else {
-        set ref [registry::open_entry $name $version $revision $variants]
-
-        if { ![string equal [registry::property_retrieve $ref installtype] "image"] } {
-            return -code error "Image error: ${name} @${specifier} not installed as an image."
-        }
-        if { [registry::property_retrieve $ref active] != 1 } {
-            return -code error "Image error: ${name} @${specifier} is not active."
-        }
-
-        registry::open_file_map
-        set imagefiles [registry::port_registered $name]
-
-        _deactivate_contents $name $imagefiles
-
-        foreach file $imagefiles {
-            registry::unregister_file $file
-        }
-        registry::write_file_map
-        registry::close_file_map
-
-        registry::property_store $ref active 0
-
-        registry::write_entry $ref
+    if {![info exists options(ports_nodepcheck)] || ![string is true -strict $options(ports_nodepcheck)]} {
+        registry::check_dependents $requested $force "deactivate"
     }
+
+    _deactivate_contents $requested [$requested files] $force
+    $requested state imaged
 }
 
-proc _check_registry {name v} {
+proc _check_registry {name version revision variants} {
     global UI_PREFIX
-    variable use_reg2
 
-    if {$use_reg2} {
-        if { [registry::decode_spec $v version revision variants] } {
-            set ilist [registry::entry imaged $name $version $revision $variants]
-            set valid 1
-        } else {
-            set valid [string equal $v {}]
-            set ilist [registry::entry imaged $name]
+    set searchkeys $name
+    set composite_spec ""
+    if {$version != ""} {
+        lappend searchkeys $version
+        set composite_spec $version
+        # restriction imposed by underlying registry API (see entry.c):
+        # if a revision is specified, so must variants be
+        if {$revision != ""} {
+            lappend searchkeys $revision $variants
+            append composite_spec _${revision}${variants}
         }
+    }
+    set ilist [eval registry::entry imaged $searchkeys]
 
-        if { [llength $ilist] > 1 || (!$valid && [llength $ilist] == 1) } {
-            ui_msg "$UI_PREFIX [msgcat::mc "The following versions of $name are currently installed:"]"
-            foreach i $ilist {
-                set iname [$i name]
-                set iversion [$i version]
-                set irevision [$i revision]
-                set ivariants [$i variants]
-                if { [$i state] == "installed" } {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s (active)"] $iname $iversion $irevision $ivariants]"
-                } else {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s"] $iname $iversion $irevision $ivariants]"
-                }
-            }
-            if { $valid } {
-                throw registry::invalid "Registry error: Please specify the full version as recorded in the port registry."
+    if { [llength $ilist] > 1 } {
+        ui_msg "$UI_PREFIX [msgcat::mc "The following versions of $name are currently installed:"]"
+        foreach i $ilist {
+            set iname [$i name]
+            set iversion [$i version]
+            set irevision [$i revision]
+            set ivariants [$i variants]
+            if { [$i state] == "installed" } {
+                ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s (active)"] $iname $iversion $irevision $ivariants]"
             } else {
-                throw registry::invalid "Registry error: Invalid version specified. Please specify a version as recorded in the port registry."
+                ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s"] $iname $iversion $irevision $ivariants]"
             }
-        } elseif { [llength $ilist] == 1 } {
-            return [lindex $ilist 0]
         }
-        throw registry::invalid "Registry error: No port of $name installed."
-    } else {
-        # registry1.0
-        set ilist [registry::installed $name $v]
-        if { [string equal $v ""] && [llength $ilist] > 1 } {
-            # set name again since the one we were passed may not have had the correct case
-            set name [lindex [lindex $ilist 0] 0]
-            ui_msg "$UI_PREFIX [msgcat::mc "The following versions of $name are currently installed:"]"
-            foreach i $ilist { 
-                set iname [lindex $i 0]
-                set iversion [lindex $i 1]
-                set irevision [lindex $i 2]
-                set ivariants [lindex $i 3]
-                set iactive [lindex $i 4]
-                if { $iactive == 0 } {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s"] $iname $iversion $irevision $ivariants]"
-                } elseif { $iactive == 1 } {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s (active)"] $iname $iversion $irevision $ivariants]"
-                }
-            }
-            return -code error "Registry error: Please specify the full version as recorded in the port registry."
-        } elseif {[llength $ilist] == 1} {
-            return [lindex $ilist 0]
-        }
-        return -code error "Registry error: No port of $name installed."
+        throw registry::invalid "Registry error: Please specify the full version as recorded in the port registry."
+    } elseif { [llength $ilist] == 1 } {
+        return [lindex $ilist 0]
     }
+    if {$composite_spec != ""} {
+        set composite_spec " @${composite_spec}"
+    }
+    throw registry::invalid "Registry error: ${name}${composite_spec} is not installed."
 }
 
 ## Activates a file from an image into the filesystem. Deals with symlinks,
@@ -369,28 +249,38 @@
 ## @param [in] dstfile path to activate file to
 ## @return 1 if file needs to be explicitly deleted if we have to roll back, 0 otherwise
 proc _activate_file {srcfile dstfile} {
-    switch [file type $srcfile] {
+    if {[catch {set filetype [::file type $srcfile]} result]} {
+        # this can happen if the archive was built on case-sensitive and we're case-insensitive
+        # we know any existing dstfile is ours because we checked for conflicts earlier
+        if {![catch {file type $dstfile}]} {
+            ui_debug "skipping case-conflicting file: $srcfile"
+            return 0
+        } else {
+            error $result
+        }
+    }
+    switch $filetype {
         directory {
             # Don't recursively copy directories
             ui_debug "activating directory: $dstfile"
             # Don't do anything if the directory already exists.
-            if { ![file isdirectory $dstfile] } {
-                file mkdir $dstfile
+            if { ![::file isdirectory $dstfile] } {
+                ::file mkdir $dstfile
                 # fix attributes on the directory.
                 if {[getuid] == 0} {
-                    eval file attributes {$dstfile} [file attributes $srcfile]
+                    eval ::file attributes {$dstfile} [::file attributes $srcfile]
                 } else {
                     # not root, so can't set owner/group
-                    eval file attributes {$dstfile} -permissions [file attributes $srcfile -permissions ]
+                    eval ::file attributes {$dstfile} -permissions [::file attributes $srcfile -permissions]
                 }
                 # set mtime on installed element
-                file mtime $dstfile [file mtime $srcfile]
+                ::file mtime $dstfile [::file mtime $srcfile]
             }
             return 0
         }
         default {
             ui_debug "activating file: $dstfile"
-            file rename $srcfile $dstfile
+            ::file rename $srcfile $dstfile
             return 1
         }
     }
@@ -399,10 +289,11 @@
 # extract an archive to a temporary location
 # returns: path to the extracted directory
 proc extract_archive_to_tmpdir {location} {
-    set extractdir [mkdtemp [file join [macports::gettmpdir] mpextractXXXXXXXX]]
+    global macports::registry.path
+    set extractdir [mkdtemp [::file dirname $location]/mpextractXXXXXXXX]
+    set startpwd [pwd]
 
     try {
-        set startpwd [pwd]
         if {[catch {cd $extractdir} err]} {
             throw MACPORTS $err
         }
@@ -414,7 +305,7 @@
         set unarchive.pre_args {}
         set unarchive.args {}
         set unarchive.pipe_cmd ""
-        set unarchive.type [file tail $location]
+        set unarchive.type [::file extension $location]
         switch -regex ${unarchive.type} {
             cp(io|gz) {
                 set pax "pax"
@@ -522,7 +413,7 @@
         }
         system $cmdstring
     } catch {*} {
-        file delete -force $extractdir
+        ::file delete -force $extractdir
         throw
     } finally {
         cd $startpwd
@@ -534,18 +425,13 @@
 ## Activates the contents of a port
 proc _activate_contents {port {imagefiles {}} {location {}}} {
     variable force
-    variable use_reg2
     variable noexec
     global macports::prefix
 
     set files [list]
     set baksuffix .mp_[clock seconds]
-    if {$use_reg2} {
-        set location [$port location]
-        set imagefiles [$port imagefiles]
-    } else {
-        set name $port
-    }
+    set location [$port location]
+    set imagefiles [$port imagefiles]
     set extracted_dir [extract_archive_to_tmpdir $location]
 
     set backups [list]
@@ -556,272 +442,171 @@
     # Last, if the file exists, and belongs to another port, and force is set
     #  we remove the file from the file_map, take ownership of it, and
     #  clobber it
-    if {$use_reg2} {
-        array set todeactivate {}
-        try {
-            registry::write {
-                foreach file $imagefiles {
-                    set srcfile "${extracted_dir}${file}"
+    array set todeactivate {}
+    try {
+        registry::write {
+            foreach file $imagefiles {
+                set srcfile "${extracted_dir}${file}"
 
-                    # To be able to install links, we test if we can lstat the file to
-                    # figure out if the source file exists (file exists will return
-                    # false for symlinks on files that do not exist)
-                    if { [catch {file lstat $srcfile dummystatvar}] } {
-                        throw registry::image-error "Image error: Source file $srcfile does not appear to exist (cannot lstat it).  Unable to activate port [$port name]."
-                    }
+                # To be able to install links, we test if we can lstat the file to
+                # figure out if the source file exists (file exists will return
+                # false for symlinks on files that do not exist)
+                if { [catch {::file lstat $srcfile dummystatvar}] } {
+                    throw registry::image-error "Image error: Source file $srcfile does not appear to exist (cannot lstat it).  Unable to activate port [$port name]."
+                }
 
-                    set owner [registry::entry owner $file]
+                set owner [registry::entry owner $file]
 
-                    if {$owner != {} && $owner != $port} {
-                        # deactivate conflicting port if it is replaced_by this one
-                        set result [mportlookup [$owner name]]
-                        array unset portinfo
-                        array set portinfo [lindex $result 1]
-                        if {[info exists portinfo(replaced_by)] && [lsearch -regexp $portinfo(replaced_by) "(?i)^[$port name]\$"] != -1} {
-                            # we'll deactivate the owner later, but before activating our files
-                            set todeactivate($owner) yes
-                            set owner "replaced"
-                        }
+                if {$owner != {} && $owner != $port} {
+                    # deactivate conflicting port if it is replaced_by this one
+                    set result [mportlookup [$owner name]]
+                    array unset portinfo
+                    array set portinfo [lindex $result 1]
+                    if {[info exists portinfo(replaced_by)] && [lsearch -regexp $portinfo(replaced_by) "(?i)^[$port name]\$"] != -1} {
+                        # we'll deactivate the owner later, but before activating our files
+                        set todeactivate($owner) yes
+                        set owner "replaced"
                     }
+                }
 
-                    if {$owner != "replaced"} {
-                        if { [string is true -strict $force] } {
-                            # if we're forcing the activation, then we move any existing
-                            # files to a backup file, both in the filesystem and in the
-                            # registry
-                            if { [file exists $file] } {
-                                set bakfile "${file}${baksuffix}"
-                                ui_warn "File $file already exists.  Moving to: $bakfile."
-                                file rename -force -- $file $bakfile
-                                lappend backups $file
-                            }
-                            if { $owner != {} } {
-                                $owner deactivate [list $file]
-                                $owner activate [list $file] [list "${file}${baksuffix}"]
-                            }
-                        } else {
-                            # if we're not forcing the activation, then we bail out if
-                            # we find any files that already exist, or have entries in
-                            # the registry
-                            if { $owner != {} && $owner != $port } {
-                                throw registry::image-error "Image error: $file is being used by the active [$owner name] port.  Please deactivate this port first, or use 'port -f activate [$port name]' to force the activation."
-                            } elseif { $owner == {} && ![catch {file type $file}] } {
-                                throw registry::image-error "Image error: $file already exists and does not belong to a registered port.  Unable to activate port [$port name]. Use 'port -f activate [$port name]' to force the activation."
-                            }
+                if {$owner != "replaced"} {
+                    if { [string is true -strict $force] } {
+                        # if we're forcing the activation, then we move any existing
+                        # files to a backup file, both in the filesystem and in the
+                        # registry
+                        if { ![catch {::file type $file}] } {
+                            set bakfile "${file}${baksuffix}"
+                            ui_warn "File $file already exists.  Moving to: $bakfile."
+                            ::file rename -force -- $file $bakfile
+                            lappend backups $file
                         }
+                        if { $owner != {} } {
+                            $owner deactivate [list $file]
+                            $owner activate [list $file] [list "${file}${baksuffix}"]
+                        }
+                    } else {
+                        # if we're not forcing the activation, then we bail out if
+                        # we find any files that already exist, or have entries in
+                        # the registry
+                        if { $owner != {} && $owner != $port } {
+                            throw registry::image-error "Image error: $file is being used by the active [$owner name] port.  Please deactivate this port first, or use 'port -f activate [$port name]' to force the activation."
+                        } elseif { $owner == {} && ![catch {::file type $file}] } {
+                            throw registry::image-error "Image error: $file already exists and does not belong to a registered port.  Unable to activate port [$port name]. Use 'port -f activate [$port name]' to force the activation."
+                        }
                     }
-
-                    # Split out the filename's subpaths and add them to the
-                    # imagefile list.
-                    # We need directories first to make sure they will be there
-                    # before links. However, because file mkdir creates all parent
-                    # directories, we don't need to have them sorted from root to
-                    # subpaths. We do need, nevertheless, all sub paths to make sure
-                    # we'll set the directory attributes properly for all
-                    # directories.
-                    set directory [file dirname $file]
-                    while { [lsearch -exact $files $directory] == -1 } {
-                        lappend files $directory
-                        set directory [file dirname $directory]
-                    }
-
-                    # Also add the filename to the imagefile list.
-                    lappend files $file
                 }
-            }
 
-            # deactivate ports replaced_by this one
-            foreach owner [array names todeactivate] {
-                if {$noexec || ![registry::run_target $owner deactivate [list ports_nodepcheck 1]]} {
-                    deactivate [$owner name] "" [list ports_nodepcheck 1]
+                # Split out the filename's subpaths and add them to the
+                # imagefile list.
+                # We need directories first to make sure they will be there
+                # before links. However, because file mkdir creates all parent
+                # directories, we don't need to have them sorted from root to
+                # subpaths. We do need, nevertheless, all sub paths to make sure
+                # we'll set the directory attributes properly for all
+                # directories.
+                set directory [::file dirname $file]
+                while { [lsearch -exact $files $directory] == -1 } {
+                    lappend files $directory
+                    set directory [::file dirname $directory]
                 }
-            }
 
-            # Sort the list in forward order, removing duplicates.
-            # Since the list is sorted in forward order, we're sure that
-            # directories are before their elements.
-            # We don't have to do this as mentioned above, but it makes the
-            # debug output of activate make more sense.
-            set files [lsort -increasing -unique $files]
-            set rollback_filelist {}
-
-            registry::write {
-                # Activate it, and catch errors so we can roll-back
-                try {
-                    $port activate $imagefiles
-                    foreach file $files {
-                        if {[_activate_file "${extracted_dir}${file}" $file] == 1} {
-                            lappend rollback_filelist $file
-                        }
-                    }
-                } catch {*} {
-                    ui_debug "Activation failed, rolling back."
-                    # can't do it here since we're already inside a transaction
-                    set deactivate_this yes
-                    throw
-                }
+                # Also add the filename to the imagefile list.
+                lappend files $file
             }
-        } catch {*} {
-            # roll back activation of this port
-            if {[info exists deactivate_this]} {
-                _deactivate_contents $port $rollback_filelist yes yes
-            }
-            # if any errors occurred, move backed-up files back to their original
-            # locations, then rethrow the error. Transaction rollback will take care
-            # of this in the registry.
-            foreach file $backups {
-                file rename -force -- "${file}${baksuffix}" $file
-            }
-            # reactivate deactivated ports
-            foreach entry [array names todeactivate] {
-                if {[$entry state] == "imaged" && ($noexec || ![registry::run_target $entry activate ""])} {
-                    set pvers "[$entry version]_[$entry revision][$entry variants]"
-                    activate [$entry name] $pvers [list ports_activate_no-exec $noexec]
-                }
-            }
-            # remove temp image dir
-            file delete -force $extracted_dir
-            throw
         }
-    } else {
-        # registry1.0
-        set deactivated [list]
-        foreach file $imagefiles {
-            set srcfile "${extracted_dir}${file}"
 
-            # To be able to install links, we test if we can lstat the file to
-            # figure out if the source file exists (file exists will return
-            # false for symlinks on files that do not exist)
-            if { [catch {file lstat $srcfile dummystatvar}] } {
-                file delete -force $extracted_dir
-                return -code error "Image error: Source file $srcfile does not appear to exist (cannot lstat it).  Unable to activate port $name."
+        # deactivate ports replaced_by this one
+        foreach owner [array names todeactivate] {
+            if {$noexec || ![registry::run_target $owner deactivate [list ports_nodepcheck 1]]} {
+                deactivate [$owner name] "" "" 0 [list ports_nodepcheck 1]
             }
-
-            set port [registry::file_registered $file]
-            
-            if {$port != 0  && $port != $name} {
-                # deactivate conflicting port if it is replaced_by this one
-                if {[catch {mportlookup $port} result]} {
-                    global errorInfo
-                    ui_debug "$errorInfo"
-                    file delete -force $extracted_dir
-                    return -code error "port lookup failed: $result"
-                }
-                array unset portinfo
-                array set portinfo [lindex $result 1]
-                if {[info exists portinfo(replaced_by)] && [lsearch -regexp $portinfo(replaced_by) "(?i)^${name}\$"] != -1} {
-                    lappend deactivated [lindex [registry::active $port] 0]
-                    deactivate $port "" ""
-                    set port 0
-                }
-            }
-    
-            if { $port != 0  && $force != 1 && $port != $name } {
-                file delete -force $extracted_dir
-                return -code error "Image error: $file is being used by the active $port port.  Please deactivate this port first, or use 'port -f activate $name' to force the activation."
-            } elseif { [file exists $file] && $force != 1 } {
-                file delete -force $extracted_dir
-                return -code error "Image error: $file already exists and does not belong to a registered port.  Unable to activate port $name. Use 'port -f activate $name' to force the activation."
-            } elseif { $force == 1 && [file exists $file] || $port != 0 } {
-                set bakfile "${file}${baksuffix}"
-
-                if {[file exists $file]} {
-                    ui_warn "File $file already exists.  Moving to: $bakfile."
-                    file rename -force -- $file $bakfile
-                    lappend backups $file
-                }
-
-                if { $port != 0 } {
-                    set bakport [registry::file_registered $file]
-                    registry::unregister_file $file
-                    if {[file exists $bakfile]} {
-                        registry::register_file $bakfile $bakport
-                    }
-                }
-            }
-
-            # Split out the filename's subpaths and add them to the imagefile list.
-            # We need directories first to make sure they will be there before
-            # links. However, because file mkdir creates all parent directories,
-            # we don't need to have them sorted from root to subpaths. We do need,
-            # nevertheless, all sub paths to make sure we'll set the directory
-            # attributes properly for all directories.
-            set directory [file dirname $file]
-            while { [lsearch -exact $files $directory] == -1 } { 
-                lappend files $directory
-                set directory [file dirname $directory]
-            }
-
-            # Also add the filename to the imagefile list.
-            lappend files $file
         }
-        registry::write_file_map
 
         # Sort the list in forward order, removing duplicates.
-        # Since the list is sorted in forward order, we're sure that directories
-        # are before their elements.
+        # Since the list is sorted in forward order, we're sure that
+        # directories are before their elements.
         # We don't have to do this as mentioned above, but it makes the
         # debug output of activate make more sense.
         set files [lsort -increasing -unique $files]
         set rollback_filelist {}
 
-        # Activate it, and catch errors so we can roll-back
-        if { [catch { foreach file $files {
-                        if {[_activate_file "${extracted_dir}${file}" $file] == 1} {
-                            lappend rollback_filelist $file
-                        }
-                    }} result]} {
-            ui_debug "Activation failed, rolling back."
-            _deactivate_contents $name $rollback_filelist yes yes
-            # return backed up files to their old locations
-            foreach f $backups {
-                set bakfile "${f}${baksuffix}"
-                set bakport [registry::file_registered $bakfile]
-                if {$bakport != 0} {
-                    registry::unregister_file $bakfile
-                    registry::register_file $f $bakport
+        registry::write {
+            # Activate it, and catch errors so we can roll-back
+            try {
+                $port activate $imagefiles
+                foreach file $files {
+                    if {[_activate_file "${extracted_dir}${file}" $file] == 1} {
+                        lappend rollback_filelist $file
+                    }
                 }
-                file rename -force -- $bakfile $file
+            } catch {*} {
+                ui_debug "Activation failed, rolling back."
+                # can't do it here since we're already inside a transaction
+                set deactivate_this yes
+                throw
             }
-            # reactivate deactivated ports
-            foreach entry $deactivated {
-                set pname [lindex $entry 0]
-                set pvers "[lindex $entry 1]_[lindex $entry 2][lindex $entry 3]"
-                activate $pname $pvers ""
+        }
+    } catch {*} {
+        # roll back activation of this port
+        if {[info exists deactivate_this]} {
+            _deactivate_contents $port $rollback_filelist yes yes
+        }
+        # if any errors occurred, move backed-up files back to their original
+        # locations, then rethrow the error. Transaction rollback will take care
+        # of this in the registry.
+        foreach file $backups {
+            ::file rename -force -- "${file}${baksuffix}" $file
+        }
+        # reactivate deactivated ports
+        foreach entry [array names todeactivate] {
+            if {[$entry state] == "imaged" && ($noexec || ![registry::run_target $entry activate ""])} {
+                activate [$entry name] [$entry version] [$entry revision] [$entry variants] [list ports_activate_no-exec $noexec]
             }
-            registry::write_file_map
-
-            file delete -force $extracted_dir
-            return -code error $result
         }
+        # remove temp image dir
+        ::file delete -force $extracted_dir
+        throw
     }
-    file delete -force $extracted_dir
+    ::file delete -force $extracted_dir
 }
 
+# These directories should not be removed during deactivation even if they are empty.
+# TODO: look into what other dirs should go here
+variable precious_dirs
+array set precious_dirs { /Library/LaunchDaemons 1 /Library/LaunchAgents 1 }
+
 proc _deactivate_file {dstfile} {
-    if { [file type $dstfile] == "link" } {
+    if {[catch {::file type $dstfile} filetype]} {
+        ui_debug "$dstfile does not exist"
+        return
+    }
+    if { $filetype == "link" } {
         ui_debug "deactivating link: $dstfile"
         file delete -- $dstfile
-    } elseif { [file isdirectory $dstfile] } {
+    } elseif { $filetype == "directory" } {
         # 0 item means empty.
         if { [llength [readdir $dstfile]] == 0 } {
-            ui_debug "deactivating directory: $dstfile"
-            file delete -- $dstfile
+            variable precious_dirs
+            if {![info exists precious_dirs($dstfile)]} {
+                ui_debug "deactivating directory: $dstfile"
+                ::file delete -- $dstfile
+            } else {
+                ui_debug "directory $dstfile does not belong to us"
+            }
         } else {
             ui_debug "$dstfile is not empty"
         }
     } else {
         ui_debug "deactivating file: $dstfile"
-        file delete -- $dstfile
+        ::file delete -- $dstfile
     }
 }
 
 proc _deactivate_contents {port imagefiles {force 0} {rollback 0}} {
-    variable use_reg2
     set files [list]
 
     foreach file $imagefiles {
-        if { [file exists $file] || (![catch {file type $file}] && [file type $file] == "link") } {
+        if { [::file exists $file] || (![catch {::file type $file}] && [::file type $file] == "link") } {
             # Normalize the file path to avoid removing the intermediate
             # symlinks (remove the empty directories instead)
             # Remark: paths in the registry may be not normalized.
@@ -832,14 +617,14 @@
             # belong to any port.
             # The custom realpath proc is necessary because file normalize
             # does not resolve symlinks on OS X < 10.6
-            set directory [realpath [file dirname $file]]
-            lappend files [file join $directory [file tail $file]]
+            set directory [realpath [::file dirname $file]]
+            lappend files [::file join $directory [::file tail $file]]
 
             # Split out the filename's subpaths and add them to the image list
             # as well.
             while { [lsearch -exact $files $directory] == -1 } {
                 lappend files $directory
-                set directory [file dirname $directory]
+                set directory [::file dirname $directory]
             }
         } else {
             ui_debug "$file does not exist."
@@ -852,7 +637,7 @@
     set files [lsort -decreasing -unique $files]
 
     # Remove all elements.
-    if {$use_reg2 && !$rollback} {
+    if {!$rollback} {
         registry::write {
             $port deactivate $imagefiles
             foreach file $files {

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/portuninstall.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/portuninstall.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/portuninstall.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -2,6 +2,7 @@
 # portuninstall.tcl
 # $Id$
 #
+# Copyright (c) 2004-2005, 2008-2011 The MacPorts Project
 # Copyright (c) 2002 - 2003 Apple Inc.
 # All rights reserved.
 #
@@ -40,10 +41,25 @@
 
 namespace eval registry_uninstall {
 
-proc uninstall {portname {v ""} optionslist} {
+# takes a composite version spec rather than separate version,revision,variants
+proc uninstall_composite {portname {v ""} {optionslist ""}} {
+    if {$v == ""} {
+        return [uninstall $portname "" "" 0 $optionslist]
+    } elseif {[registry::decode_spec $v version revision variants]} {
+        return [uninstall $portname $version $revision $variants $optionslist]
+    }
+    throw registry::invalid "Registry error: Invalid version '$v' specified for ${portname}. Please specify a version as recorded in the port registry."
+}
+
+proc uninstall {portname {version ""} {revision ""} {variants 0} {optionslist ""}} {
     global uninstall.force uninstall.nochecksum UI_PREFIX \
-           macports::registry.format macports::portimagefilepath
+           macports::portimagefilepath
     array set options $optionslist
+    if {[info exists options(subport)]} {
+        # don't want this set when calling registry::run_target
+        unset options(subport)
+        set optionslist [array get options]
+    }
 
     if {![info exists uninstall.force]} {
         set uninstall.force no
@@ -56,172 +72,89 @@
     if {[info exists options(ports_uninstall_no-exec)]} {
         set options(ports_deactivate_no-exec) $options(ports_uninstall_no-exec)
     }
-    # check which registry API to use
-    set use_reg2 [string equal ${macports::registry.format} "receipt_sqlite"]
 
-    if {$use_reg2} {
-        if { [registry::decode_spec $v version revision variants] } {
-            set ilist [registry::entry imaged $portname $version $revision $variants]
-            set valid 1
-        } else {
-            set valid [string equal $v {}]
-            set ilist [registry::entry imaged $portname]
+    set searchkeys $portname
+    set composite_spec ""
+    if {$version != ""} {
+        lappend searchkeys $version
+        set composite_spec $version
+        # restriction imposed by underlying registry API (see entry.c):
+        # if a revision is specified, so must variants be
+        if {$revision != ""} {
+            lappend searchkeys $revision $variants
+            append composite_spec _${revision}${variants}
         }
-    } else {
-        set ilist [registry::installed $portname $v]
-        set valid 1
     }
+    set ilist [eval registry::entry imaged $searchkeys]
     if { [llength $ilist] > 1 } {
         # set portname again since the one we were passed may not have had the correct case
-        if {$use_reg2} {
-            set portname [[lindex $ilist 0] name]
-        } else {
-            set portname [lindex [lindex $ilist 0] 0]
-        }
+        set portname [[lindex $ilist 0] name]
         ui_msg "$UI_PREFIX [msgcat::mc "The following versions of $portname are currently installed:"]"
         foreach i [portlist_sortint $ilist] {
-            if {$use_reg2} {
-                set ispec "[$i version]_[$i revision][$i variants]"
-                if { [string equal [$i state] installed] } {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s (active)"] [$i name] $ispec]"
-                } else {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s"] [$i name] $ispec]"
-                }
+            set ispec "[$i version]_[$i revision][$i variants]"
+            if { [string equal [$i state] installed] } {
+                ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s (active)"] [$i name] $ispec]"
             } else {
-                set iname [lindex $i 0]
-                set iversion [lindex $i 1]
-                set irevision [lindex $i 2]
-                set ivariants [lindex $i 3]
-                set iactive [lindex $i 4]
-                if { $iactive == 1 } {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s (active)"] $iname $iversion $irevision $ivariants]"
-                } else {
-                    ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s_%s%s"] $iname $iversion $irevision $ivariants]"
-                }
+                ui_msg "$UI_PREFIX [format [msgcat::mc "    %s @%s"] [$i name] $ispec]"
             }
         }
-        if { $valid } {
-            throw registry::invalid "Registry error: Please specify the full version as recorded in the port registry."
-        } else {
-            throw registry::invalid "Registry error: Invalid version specified. Please specify a version as recorded in the port registry."
-        }
+        throw registry::invalid "Registry error: Please specify the full version as recorded in the port registry."
     } elseif { [llength $ilist] == 1 } {
-        if {$use_reg2} {
-            set port [lindex $ilist 0]
-            set version [$port version]
-            set revision [$port revision]
-            set variants [$port variants]
-        } else {
-            set version [lindex [lindex $ilist 0] 1]
-            set revision [lindex [lindex $ilist 0] 2]
-            set variants [lindex [lindex $ilist 0] 3]
-            set active [lindex [lindex $ilist 0] 4]
-        }
-        if {$v == ""} {
-            set v "${version}_${revision}${variants}"
-        }
+        set port [lindex $ilist 0]
+        set version [$port version]
+        set revision [$port revision]
+        set variants [$port variants]
+        set composite_spec "${version}_${revision}${variants}"
     } else {
-        throw registry::invalid "Registry error: $portname not registered as installed"
+        if {$composite_spec != ""} {
+            set composite_spec " @${composite_spec}"
+        }
+        throw registry::invalid "Registry error: ${portname}${composite_spec} not registered as installed"
     }
 
-    if {$use_reg2} {
-        # uninstall dependents if requested
-        if {[info exists options(ports_uninstall_follow-dependents)] && $options(ports_uninstall_follow-dependents) eq "yes"} {
-            foreach depport [$port dependents] {
-                # make sure it's still installed, since a previous dep uninstall may have removed it
-                if {[registry::entry exists $depport] && ([$depport state] == "imaged" || [$depport state] == "installed")} {
-                    if {[info exists options(ports_uninstall_no-exec)] || ![registry::run_target $depport uninstall $optionslist]} {
-                        set depname [$depport name]
-                        set depver "[$depport version]_[$depport revision][$depport variants]"
-                        registry_uninstall::uninstall $depname $depver $optionslist
-                    }
-                }
-            }
-        } else {
-            # check its dependents
-            registry::check_dependents $port ${uninstall.force} "uninstall"
+    # uninstall dependents if requested
+    if {[info exists options(ports_uninstall_follow-dependents)] && $options(ports_uninstall_follow-dependents) eq "yes"} {
+        # don't uninstall dependents' dependencies
+        if {[info exists options(ports_uninstall_follow-dependencies)]} {
+            set orig_follow_dependencies $options(ports_uninstall_follow-dependencies)
+            unset options(ports_uninstall_follow-dependencies)
+            set optionslist [array get options]
         }
-        # if it's active, deactivate it
-        if { [string equal [$port state] installed] } {
-            if {[info exists options(ports_dryrun)] && [string is true -strict $options(ports_dryrun)]} {
-                ui_msg "For $portname @${v}: skipping deactivate (dry run)"
-            } else {
-                if {[info exists options(ports_uninstall_no-exec)] || ![registry::run_target $port deactivate $optionslist]} {
-                    portimage::deactivate $portname $v [array get options]
+        foreach depport [$port dependents] {
+            # make sure it's still installed, since a previous dep uninstall may have removed it
+            if {[registry::entry exists $depport] && ([$depport state] == "imaged" || [$depport state] == "installed")} {
+                if {[info exists options(ports_uninstall_no-exec)] || ![registry::run_target $depport uninstall $optionslist]} {
+                    registry_uninstall::uninstall [$depport name] [$depport version] [$depport revision] [$depport variants] $optionslist
                 }
             }
         }
+        if {[info exists orig_follow_dependencies]} {
+            set options(ports_uninstall_follow-dependencies) $orig_follow_dependencies
+            set optionslist [array get options]
+        }
     } else {
-        # registry1.0
-        
-        # determine if it's the only installed port with that name or not.
-        if {$v == ""} {
-            set nb_versions_installed 1
+        # check its dependents
+        registry::check_dependents $port ${uninstall.force} "uninstall"
+    }
+    # if it's active, deactivate it
+    if { [string equal [$port state] installed] } {
+        if {[info exists options(ports_dryrun)] && [string is true -strict $options(ports_dryrun)]} {
+            ui_msg "For $portname @${composite_spec}: skipping deactivate (dry run)"
         } else {
-            set ilist [registry::installed $portname ""]
-            set nb_versions_installed [llength $ilist]
-        }
-    
-        set ref [registry::open_entry $portname $version $revision $variants]
-    
-        # Check and make sure no ports depend on this one
-        registry::open_dep_map  
-        set deplist [registry::list_dependents $portname $version $revision $variants]
-        if { [llength $deplist] > 0 } {
-            set dl [list]
-            # Check the deps first
-            foreach dep $deplist { 
-                set depport [lindex $dep 2]
-                ui_debug "$depport depends on this port"
-                if {[registry::entry_exists_for_name $depport]} {
-                    lappend dl $depport
-                }
+            if {[info exists options(ports_uninstall_no-exec)] || ![registry::run_target $port deactivate $optionslist]} {
+                portimage::deactivate $portname $version $revision $variants [array get options]
             }
-            # Now see if we need to error
-            if { [llength $dl] > 0 } {
-                if {[info exists options(ports_uninstall_follow-dependents)] && $options(ports_uninstall_follow-dependents) eq "yes"} {
-                    foreach depport $dl {
-                        # make sure it's still installed, since a previous dep uninstall may have removed it
-                        if {[registry::entry_exists_for_name $depport]} {
-                            registry_uninstall::uninstall $depport "" $optionslist
-                        }
-                    }
-                } else {
-                    # will need to change this when we get version/variant dependencies
-                    if {$nb_versions_installed == 1 || $active == 1} {
-                        ui_msg "$UI_PREFIX [format [msgcat::mc "Unable to uninstall %s %s_%s%s, the following ports depend on it:"] $portname $version $revision $variants]"
-                        foreach depport $dl {
-                            ui_msg "$UI_PREFIX [format [msgcat::mc "    %s"] $depport]"
-                        }
-                        if { [string is true -strict ${uninstall.force}] } {
-                            ui_warn "Uninstall forced.  Proceeding despite dependencies."
-                        } else {
-                            return -code error "Please uninstall the ports that depend on $portname first."
-                        }
-                    }
-                }
-            }
         }
-    
-        if { [registry::property_retrieve $ref active] == 1} {
-            if {[info exists options(ports_dryrun)] && [string is true -strict $options(ports_dryrun)]} {
-                ui_msg "For $portname @${version}_${revision}${variants}: skipping deactivate (dry run)"
-            } else {
-                portimage::deactivate $portname ${version}_${revision}${variants} $optionslist
-            }
-        }
     }
 
-    if {$use_reg2} {
-        set ref $port
-    }
+    set ref $port
 
     # note deps before we uninstall if we're going to uninstall them too
     if {[info exists options(ports_uninstall_follow-dependencies)] && [string is true -strict $options(ports_uninstall_follow-dependencies)]} {
         set deptypes {depends_fetch depends_extract depends_build depends_lib depends_run}
         set all_dependencies {}
         # look up deps from the saved portfile if possible
-        if {$use_reg2 && ![catch {set mport [mportopen_installed [$port name] [$port version] [$port revision] [$port variants] $optionslist]}]} {
+        if {![catch {set mport [mportopen_installed [$port name] [$port version] [$port revision] [$port variants] $optionslist]}]} {
             array set depportinfo [mportinfo $mport]
             mportclose_installed $mport
             foreach type $deptypes {
@@ -273,52 +206,27 @@
     }
 
     if {[info exists options(ports_dryrun)] && [string is true -strict $options(ports_dryrun)]} {
-        ui_msg "For $portname @${v}: skipping uninstall (dry run)"
+        ui_msg "For $portname @${composite_spec}: skipping uninstall (dry run)"
     } else {
-        ui_msg "$UI_PREFIX [format [msgcat::mc "Uninstalling %s @%s"] $portname $v]"
-    
-        if {!$use_reg2} {
-            # Look to see if the port has registered an uninstall procedure
-            set uninstall [registry::property_retrieve $ref pkg_uninstall] 
-            if { $uninstall != 0 } {
-                if {![catch {eval [string map { \\n \n } $uninstall]} err]} {
-                    ui_info "Executing pkg_uninstall procedure"
-                    if {[catch {pkg_uninstall $portname "${version}_${revision}${variants}" } err]} {
-                        ui_error [format [msgcat::mc "Error executing pkg_uninstall procedure: %s"] $err]
-                    }
-                } else {
-                    global errorInfo
-                    ui_debug "$errorInfo"
-                    ui_error [format [msgcat::mc "Could not evaluate pkg_uninstall procedure: %s"] $err]
-                }
-            }
-        
-            # Remove the port from the dep_map if only one version was installed.
-            # This is a temporary fix for a deeper problem that is that the dependency
-            # map doesn't take the port version into account (but should).
-            # Fixing it means transitioning to a new dependency map format.
-            if {$nb_versions_installed == 1} {
-                registry::unregister_dependencies $portname
-            }
-        }
-    
+        ui_msg "$UI_PREFIX [format [msgcat::mc "Uninstalling %s @%s"] $portname $composite_spec]"
+
         # Get the full path to the image file
         set imagefile [registry::property_retrieve $ref location]
         file delete $imagefile
         # Try to delete the port's image dir; will fail if there are more image
         # files so just ignore the failure
-        catch {file delete [file dirname $imagefile]}
+        catch {file delete [::file dirname $imagefile]}
 
-        if {$use_reg2} {
-            registry::entry delete $port
-        } else {
-            ui_info "$UI_PREFIX [format [msgcat::mc "Uninstall is removing %s from the port registry."] $portname]"
-            registry::delete_entry $ref
-        }
+        registry::entry delete $port
     }
     
     # uninstall dependencies if requested
     if {[info exists options(ports_uninstall_follow-dependencies)] && [string is true -strict $options(ports_uninstall_follow-dependencies)]} {
+        # don't uninstall dependencies' dependents
+        if {[info exists options(ports_uninstall_follow-dependents)]} {
+            unset options(ports_uninstall_follow-dependents)
+            set optionslist [array get options]
+        }
         while 1 {
             set remaining_list {}
             foreach dep $all_dependencies {
@@ -330,9 +238,8 @@
                         set ivariants [lindex $i 3]
                         if {[llength [registry::list_dependents $dep $iversion $irevision $ivariants]] == 0} {
                             set regref [registry::open_entry $dep $iversion $irevision $ivariants [lindex $i 5]]
-                            if {![registry::property_retrieve $regref requested] && (!$use_reg2 || [info exists options(ports_uninstall_no-exec)] || ![registry::run_target $regref uninstall $optionslist])} {
-                                set depver "${iversion}_${irevision}${ivariants}"
-                                registry_uninstall::uninstall $dep $depver $optionslist
+                            if {![registry::property_retrieve $regref requested] && ([info exists options(ports_uninstall_no-exec)] || ![registry::run_target $regref uninstall $optionslist])} {
+                                registry_uninstall::uninstall $dep $iversion $irevision $ivariants $optionslist
                             }
                         } else {
                             set remaining 1

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/receipt_flat.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/receipt_flat.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/receipt_flat.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,9 +1,10 @@
 # receipt_flat.tcl
 # $Id$
 #
+# 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 Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -14,7 +15,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -74,7 +75,7 @@
 
     # regex match case
     if {$portversion == 0} {
-	set x [glob -nocomplain -directory [file join ${macports::registry.path} receipts] -- ${portname}-*]
+	set x [glob -nocomplain -directory [::file join ${macports::registry.path} receipts] -- ${portname}-*]
 	if {[string length $x]} {
 	    set matchfile [lindex $x 0]
 		# Remove trailing .bz2, if any.
@@ -83,7 +84,7 @@
 	    set matchfile ""
 	}
     } else {
-	set matchfile [file join ${macports::registry.path} receipts ${portname}-${portversion}]
+	set matchfile [::file join ${macports::registry.path} receipts ${portname}-${portversion}]
     }
 
     # Might as well bail out early if no file to match
@@ -91,7 +92,7 @@
 		return ""
     }
 
-    if {[file exists $matchfile] || [file exists ${matchfile}.bz2]} {
+    if {[::file exists $matchfile] || [::file exists ${matchfile}.bz2]} {
 		return $matchfile
     }
     return ""
@@ -109,11 +110,11 @@
 	    return $ref_index($name,$version,$revision,$variants)
 	}
 
-	set receipt_path [file join ${macports::registry.path} receipts ${name}]
+	set receipt_path [::file join ${macports::registry.path} receipts ${name}]
 
 	# If the receipt path ${name} doesn't exist, then the receipt probably is
 	# in the old HEAD format.
-	if { ![file isdirectory $receipt_path] } {
+	if { ![::file isdirectory $receipt_path] } {
 		set receipt_file [get_head_entry_receipt_path $name $version]
 		
 		if {![string length $receipt_file]} {
@@ -126,7 +127,7 @@
 		
 		# Extract the version from the path.
 		if { $version == "" } {
-			set theFileName [file tail $receipt_file]
+			set theFileName [::file tail $receipt_file]
 			regexp "^$name-(.*)\$" $theFileName match version
 		}
 	} else {
@@ -136,7 +137,7 @@
 			# version given to us.  How should we handle this?
 			set x [glob -nocomplain -directory ${receipt_path} *]
 			if { [string length $x] } {
-				set v [lindex [file split [lindex $x 0]] end]
+				set v [lindex [::file split [lindex $x 0]] end]
 				regexp {([-_a-zA-Z0-9\.]+)_([0-9]*)([+-_a-zA-Z0-9]*)$} $v match version revision variants
 			} else {
 				return -code error "Registry error: ${name} not registered as installed."
@@ -147,15 +148,15 @@
 			return -code error "Registry error: ${name} @${version}_${revision}${variants} not registered as installed."
 		}
 	
-		set receipt_path [file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
+		set receipt_path [::file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
 	
-		set receipt_file [file join ${receipt_path} receipt]
+		set receipt_file [::file join ${receipt_path} receipt]
 	}
 
-	if { [file exists ${receipt_file}.bz2] && [file exists ${registry::autoconf::bzip2_path}] } {
+	if { [::file exists ${receipt_file}.bz2] && [::file exists ${registry::autoconf::bzip2_path}] } {
 		set receipt_file ${receipt_file}.bz2
 		set receipt_contents [exec ${registry::autoconf::bzip2_path} -d -c ${receipt_file}]
-	} elseif { [file exists ${receipt_file}] } {
+	} elseif { [::file exists ${receipt_file}] } {
 		set receipt_handle [open ${receipt_file} r]
 		set receipt_contents [read $receipt_handle]
 		close $receipt_handle
@@ -176,7 +177,7 @@
 		convert_entry_from_HEAD $name $version $revision $variants $receipt_contents $ref
 		
 		# move the old receipt
-		set convertedDirPath [file join ${macports::registry.path} receipts_converted]
+		set convertedDirPath [::file join ${macports::registry.path} receipts_converted]
 		file mkdir $convertedDirPath
 		file rename -- $receipt_file $convertedDirPath
 	} elseif {[string match "# Version: *" $receipt_contents]} {
@@ -273,15 +274,15 @@
 	foreach file $contents {
 		if {[llength $file]} {
 			set theFilePath [lindex $file 0]
-			if {[file isfile $theFilePath]} {
-				set previousPort [file_registered $theFilePath]
+			if {[::file isfile $theFilePath]} {
+				set previousPort [::file_registered $theFilePath]
 				if {$previousPort != 0} {
 					ui_warn "Conflict detected for file $theFilePath between $previousPort and $name."
 				}
 				if {[catch {register_file $theFilePath $name}]} {
 					ui_warn "An error occurred while adding $theFilePath to the file_map database."
 				}
-			} elseif {![file exists $theFilePath]} {
+			} elseif {![::file exists $theFilePath]} {
 				ui_warn "Port $name refers to $theFilePath which doesn't exist."
 			}
 			lappend theActualContents $file
@@ -313,10 +314,10 @@
 
 	set receipt_contents [array get receipt_$ref]
 
-	set receipt_path [file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
-	set receipt_file [file join ${receipt_path} receipt]
+	set receipt_path [::file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
+	set receipt_file [::file join ${receipt_path} receipt]
 
-	if { ![file isdirectory ${receipt_path}] } {
+	if { ![::file isdirectory ${receipt_path}] } {
 		file mkdir ${receipt_path}
 	}
 
@@ -325,15 +326,15 @@
 	puts $receipt_handle $receipt_contents
 	close $receipt_handle
 
-	if { [file exists ${receipt_file}] } {
+	if { [::file exists ${receipt_file}] } {
 		file delete -force -- "${receipt_file}"
-	} elseif { [file exists ${receipt_file}.bz2] } {
+	} elseif { [::file exists ${receipt_file}.bz2] } {
 		file delete -force -- "${receipt_file}.bz2"
 	}
 
 	file rename -force -- "${receipt_file}.tmp" "${receipt_file}"
 
-	if { [file exists ${receipt_file}] && [file exists ${registry::autoconf::bzip2_path}] && ![info exists registry.nobzip] } {
+	if { [::file exists ${receipt_file}] && [::file exists ${registry::autoconf::bzip2_path}] && ![info exists registry.nobzip] } {
 		system "${registry::autoconf::bzip2_path} -f ${receipt_file}"
 	}
 
@@ -344,12 +345,12 @@
 proc entry_exists {name version {revision 0} {variants ""}} {
 	global macports::registry.path
 
-	set receipt_path [file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
-	set receipt_file [file join ${receipt_path} receipt]
+	set receipt_path [::file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
+	set receipt_file [::file join ${receipt_path} receipt]
 
-	if { [file exists $receipt_file] } {
+	if { [::file exists $receipt_file] } {
 		return 1
-	} elseif { [file exists ${receipt_file}.bz2] } {
+	} elseif { [::file exists ${receipt_file}.bz2] } {
 		return 1
 	}
 
@@ -360,7 +361,7 @@
 proc entry_exists_for_name {name} {
 	global macports::registry.path
 
-	set receipt_path [file join ${macports::registry.path} receipts ${name}]
+	set receipt_path [::file join ${macports::registry.path} receipts ${name}]
 
 	if {[llength [glob -nocomplain -directory $receipt_path */receipt{,.bz2}]] > 0} {
 		return 1
@@ -416,14 +417,14 @@
 	    array unset ref_index "$name,$version,$revision,$variants"
 	}
 
-	set receipt_path [file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
-	if { [file exists ${receipt_path}] } {
+	set receipt_path [::file join ${macports::registry.path} receipts ${name} ${version}_${revision}${variants}]
+	if { [::file exists ${receipt_path}] } {
 		# remove port receipt directory
 		ui_debug "deleting directory: ${receipt_path}"
 		file delete -force -- ${receipt_path}
 		# remove port receipt parent directory (if empty)
-		set receipt_dir [file join ${macports::registry.path} receipts ${name}]
-		if { [file isdirectory ${receipt_dir}] } {
+		set receipt_dir [::file join ${macports::registry.path} receipts ${name}]
+		if { [::file isdirectory ${receipt_dir}] } {
 			# 0 item means empty.
 			if { [llength [readdir ${receipt_dir}]] == 0 } {
 				ui_debug "deleting directory: ${receipt_dir}"
@@ -448,12 +449,12 @@
 proc installed {{name ""} {version ""}} {
 	global macports::registry.path
 
-	set query_path [file join ${macports::registry.path} receipts]
+	set query_path [::file join ${macports::registry.path} receipts]
 	
 	if { $name == "" } {
-		set query_path [file join ${query_path} *]
+		set query_path [::file join ${query_path} *]
 		if { $version == "" } {
-			set query_path [file join ${query_path} *]
+			set query_path [::file join ${query_path} *]
 		}
 		# [PG] Huh?
 	} else {
@@ -461,32 +462,32 @@
 	    # returned with the correct case even if it's wrong when given. To get the
 	    # correct case on a case-insensitive FS, we have to list the directory and
 	    # compare against each entry.
-	    set name_path [file join ${query_path} *]
+	    set name_path [::file join ${query_path} *]
 	    set name_entries [glob -nocomplain -types d ${name_path}]
 	    foreach entry $name_entries {
-	        set basename [file tail $entry]
+	        set basename [::file tail $entry]
 	        if {[string equal -nocase $basename $name]} {
 	            set name $basename
 	            break
 	        }
 	    }
-		set query_path [file join ${query_path} ${name}]
+		set query_path [::file join ${query_path} ${name}]
 		if { $version != "" } {
-			set query_path [file join ${query_path} ${version}]
+			set query_path [::file join ${query_path} ${version}]
 		} else {
-			set query_path [file join ${query_path} *]
+			set query_path [::file join ${query_path} *]
 		}
 	}
 
 	set x [glob -nocomplain -types d ${query_path}]
 	set rlist [list]
 	foreach p $x {
-		if {![file isfile [file join $p receipt.bz2]] && ![file isfile [file join $p receipt]]} {
+		if {![::file isfile [::file join $p receipt.bz2]] && ![::file isfile [::file join $p receipt]]} {
 			continue
 		}
 		set plist [list]
-		regexp {([-_a-zA-Z0-9\.]+)_([0-9]*)([+-_a-zA-Z0-9]*)$} [lindex [file split $p] end] match version revision variants
-		lappend plist [lindex [file split $p] end-1]
+		regexp {([-_a-zA-Z0-9\.]+)_([0-9]*)([+-_a-zA-Z0-9]*)$} [lindex [::file split $p] end] match version revision variants
+		lappend plist [lindex [::file split $p] end-1]
 		lappend plist $version
 		lappend plist $revision
 		lappend plist $variants
@@ -495,13 +496,13 @@
 
 	# append the ports in old HEAD format.
 	if { $name == "" } {
-		set query_path [file join ${macports::registry.path} receipts *]
+		set query_path [::file join ${macports::registry.path} receipts *]
 	} else {
-		set query_path [file join ${macports::registry.path} receipts ${name}-*]
+		set query_path [::file join ${macports::registry.path} receipts ${name}-*]
 	}
     set receiptglob [glob -nocomplain -types f ${query_path}]
     foreach receipt_file $receiptglob {
-		set theFileName [file tail $receipt_file]
+		set theFileName [::file tail $receipt_file]
 
     	# Remark: these regexes do not always work.
    		set theName ""
@@ -538,14 +539,14 @@
 	global macports::registry.path
 	variable file_map
 
-	set receipt_path [file join ${macports::registry.path} receipts]
-	set map_file [file join ${receipt_path} file_map]
+	set receipt_path [::file join ${macports::registry.path} receipts]
+	set map_file [::file join ${receipt_path} file_map]
 
 	# Don't reopen it (it actually would deadlock us), unless it was open r/o.
 	# and we want it r/w.
 	if { [info exists file_map] } {
 		if { $readonly == 0 } {
-			if {[filemap isreadonly file_map]} {
+			if {[::filemap isreadonly file_map]} {
 				filemap close file_map
 				filemap open file_map ${map_file}.db
 			}
@@ -555,11 +556,11 @@
 
 	set old_filemap [list]
 
-	if { ![file exists ${map_file}.db] } {
+	if { ![::file exists ${map_file}.db] } {
 		# Convert to new format
-		if { [file exists ${map_file}.bz2] && [file exists ${registry::autoconf::bzip2_path}] } {
+		if { [::file exists ${map_file}.bz2] && [::file exists ${registry::autoconf::bzip2_path}] } {
 			set old_filemap [exec ${registry::autoconf::bzip2_path} -d -c ${map_file}.bz2]
-		} elseif { [file exists $map_file] } {		
+		} elseif { [::file exists $map_file] } {		
 			set map_handle [open ${map_file} r]
 			set old_filemap [read $map_handle]
 			close $map_handle
@@ -607,8 +608,8 @@
 
 	open_file_map 1
 
-	if {[filemap exists file_map $file]} {
-		return [filemap get file_map $file]
+	if {[::filemap exists file_map $file]} {
+		return [::filemap get file_map $file]
 	} else {
 		return 0
 	}
@@ -629,7 +630,7 @@
 
 	open_file_map 1
 
-	set files [filemap list file_map $name]
+	set files [::filemap list file_map $name]
 
 	if { [llength $files] > 0 } {
 		return $files
@@ -640,7 +641,7 @@
 			# Convert the port and retry.
 			open_entry $name
 			
-			set files [filemap list file_map $name]
+			set files [::filemap list file_map $name]
 			
 			return $files
 		} else {
@@ -661,7 +662,7 @@
 
 	open_file_map
 
-	if { [file type $file] == "link" } {
+	if { [::file type $file] == "link" } {
 		ui_debug "Adding link to file_map: $file for: $port"
 	} else {
 		ui_debug "Adding file to file_map: $file for: $port"
@@ -683,7 +684,7 @@
 
 	foreach f $files {
 		set file [lindex $f 0]
-		if { [file type $file] == "link" } {
+		if { [::file type $file] == "link" } {
 			ui_debug "Adding link to file_map: $file for: $port"
 		} else {
 			ui_debug "Adding file to file_map: $file for: $port"
@@ -742,13 +743,13 @@
 	global macports::registry.path
 	variable dep_map
 
-	set receipt_path [file join ${macports::registry.path} receipts]
+	set receipt_path [::file join ${macports::registry.path} receipts]
 
-	set map_file [file join ${receipt_path} dep_map]
+	set map_file [::file join ${receipt_path} dep_map]
 
-	if { [file exists ${map_file}.bz2] && [file exists ${registry::autoconf::bzip2_path}] } {
+	if { [::file exists ${map_file}.bz2] && [::file exists ${registry::autoconf::bzip2_path}] } {
 		set dep_map [exec ${registry::autoconf::bzip2_path} -d -c ${map_file}.bz2]
-	} elseif { [file exists ${map_file}] } {
+	} elseif { [::file exists ${map_file}] } {
 		set map_handle [open ${map_file} r]
 		set dep_map [read $map_handle]
 		close $map_handle
@@ -836,9 +837,9 @@
 	global macports::registry.path
 	variable dep_map
 
-	set receipt_path [file join ${macports::registry.path} receipts]
+	set receipt_path [::file join ${macports::registry.path} receipts]
 
-	set map_file [file join ${receipt_path} dep_map]
+	set map_file [::file join ${receipt_path} dep_map]
 
 	set map_handle [open ${map_file}.tmp w 0644]
 	puts $map_handle $dep_map
@@ -849,7 +850,7 @@
 
     file rename -- ${map_file}.tmp ${map_file}
 
-	if { [file exists ${map_file}] && [file exists ${registry::autoconf::bzip2_path}] && ![info exists registry.nobzip] } {
+	if { [::file exists ${map_file}] && [::file exists ${registry::autoconf::bzip2_path}] && ![info exists registry.nobzip] } {
 		system "${registry::autoconf::bzip2_path} -f ${map_file}"
 	}
 

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/receipt_sqlite.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/receipt_sqlite.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/receipt_sqlite.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,7 @@
 # receipt_sqlite.tcl
 # $Id$
 #
-# Copyright (c) 2010 The MacPorts Project
+# Copyright (c) 2010-2011 The MacPorts Project
 # Copyright (c) 2004 Will Barton <wbb4 at opendarwin.org>
 # Copyright (c) 2002 Apple Inc.
 # All rights reserved.
@@ -160,26 +160,22 @@
 # If version is "", return all ports of that name.
 # Otherwise, return only ports that exactly match this version.
 # What we call version here is version_revision+variants.
+# The syntax for that can be ambiguous if there's an underscore and dash in
+# version for example, so we don't attempt to split up the composite version
+# into its components, we just compare the whole thing.
 proc installed {{name ""} {version ""}} {
 	if { $name == "" && $version == "" } {
 	    set ports [registry::entry imaged]
 	} elseif { $name != "" && $version == ""} {
 	    set ports [registry::entry imaged $name]
 	} else {
-	    set cmd "registry::entry imaged $name"
-	    registry::decode_spec $version version revision variants
-	    if {[info exists version] && $version != ""} {
-                append cmd " $version"
-                if {[info exists revision] && $revision != ""} {
-                    append cmd " $revision"
-                    if {![info exists variants]} {
-                        set variants ""
-                    }
-                    append cmd " {$variants}"
-                }
-        }
-	    if {[catch {set ports [eval $cmd]}]} {
-	        set ports [list]
+	    set ports {}
+	    set possible_ports [registry::entry imaged $name]
+	    foreach p $possible_ports {
+	        if {"[$p version]_[$p revision][$p variants]" == $version
+	            || [$p version] == $version} {
+	            lappend ports $p
+	        }
 	    }
 	}
 


Property changes on: branches/gsoc11-post-destroot/base/src/registry2.0/receipt_sqlite.tcl
___________________________________________________________________
Modified: svn:mergeinfo
   - /branches/gsoc08-privileges/base/src/registry1.0/receipt_sqlite.tcl:37343-46937
/branches/gsoc09-logging/base/src/registry1.0/receipt_sqlite.tcl:51231-60371
/branches/universal-sanity/base/src/registry1.0/receipt_sqlite.tcl:51872-52323
/branches/variant-descs-14482/base/src/registry1.0/receipt_sqlite.tcl:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/users/perry/base-bugs_and_notes/src/registry1.0/receipt_sqlite.tcl:45682-46060
/users/perry/base-select/src/registry1.0/receipt_sqlite.tcl:44044-44692
   + /branches/gsoc08-privileges/base/src/registry1.0/receipt_sqlite.tcl:37343-46937
/branches/gsoc09-logging/base/src/registry1.0/receipt_sqlite.tcl:51231-60371
/branches/gsoc11-rev-upgrade/base/src/registry2.0/receipt_sqlite.tcl:78828-88375
/branches/universal-sanity/base/src/registry1.0/receipt_sqlite.tcl:51872-52323
/branches/variant-descs-14482/base/src/registry1.0/receipt_sqlite.tcl:34469-34855,34900-37508,37511-37512,41040-41463,42575-42626,42640-42659
/trunk/base/src/registry2.0/receipt_sqlite.tcl:78761-98879
/users/perry/base-bugs_and_notes/src/registry1.0/receipt_sqlite.tcl:45682-46060
/users/perry/base-select/src/registry1.0/receipt_sqlite.tcl:44044-44692

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/registry.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/registry.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/registry.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -38,12 +39,14 @@
 
 #include <cregistry/registry.h>
 #include <cregistry/entry.h>
+#include <cregistry/file.h>
 
-#include "registry.h"
+#include "entry.h"
+#include "entryobj.h"
+#include "file.h"
 #include "graph.h"
 #include "item.h"
-#include "entry.h"
-#include "entryobj.h"
+#include "registry.h"
 #include "util.h"
 
 int registry_failed(Tcl_Interp* interp, reg_error* errPtr) {
@@ -54,6 +57,8 @@
     return TCL_ERROR;
 }
 
+/* we don't need delete_file_list and restore_file_list unless we allow deletion
+   of files via the file interface */
 static void delete_entry_list(ClientData list, Tcl_Interp* interp UNUSED) {
     entry_list* curr = *(entry_list**)list;
     while (curr) {
@@ -80,8 +85,11 @@
 int registry_tcl_detach(Tcl_Interp* interp, reg_registry* reg,
         reg_error* errPtr) {
     reg_entry** entries;
-    int entry_count = reg_all_open_entries(reg, &entries);
+    reg_file** files;
+    int entry_count;
+    int file_count;
     int i;
+    entry_count = reg_all_open_entries(reg, &entries);
     if (entry_count == -1) {
         return 0;
     }
@@ -91,6 +99,16 @@
         }
     }
     free(entries);
+    file_count = reg_all_open_files(reg, &files);
+    if (file_count == -1) {
+        return 0;
+    }
+    for (i = 0; i < file_count; i++) {
+        if (files[i]->proc) {
+            Tcl_DeleteCommand(interp, files[i]->proc);
+        }
+    }
+    free(files);
     if (!reg_detach(reg, errPtr)) {
         return registry_failed(interp, errPtr);
     }
@@ -319,6 +337,7 @@
     /* Tcl_CreateObjCommand(interp, "registry::graph", GraphCmd, NULL, NULL); */
     /* Tcl_CreateObjCommand(interp, "registry::item", item_cmd, NULL, NULL); */
     Tcl_CreateObjCommand(interp, "registry::entry", entry_cmd, NULL, NULL);
+    Tcl_CreateObjCommand(interp, "registry::file", file_cmd, NULL, NULL);
     if (Tcl_PkgProvide(interp, "registry2", "2.0") != TCL_OK) {
         return TCL_ERROR;
     }

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/registry.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/registry.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/registry.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,8 @@
 # registry.tcl
 #
+# Copyright (c) 2004-2005, 2007-2012 The MacPorts Project
 # Copyright (c) 2004 Will Barton <wbb4 at opendarwin.org>
-# Copyright (c) 2002 Apple Computer, Inc.
+# Copyright (c) 2002 Apple Inc.
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
@@ -12,7 +13,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 
@@ -319,7 +320,7 @@
     # (we won't store the md5 of the target of links since it's meaningless
     # and $statvar(mode) tells us that links are links).
     if {![catch {file lstat $fname statvar}]} {
-	if {[file isfile $fname] && [file type $fname] != "link"} {
+	if {[::file isfile $fname] && [::file type $fname] != "link"} {
 	    if {[catch {md5 file $fname} md5sum] == 0} {
 		# Create a line that matches md5(1)'s output
 		# for backwards compatibility
@@ -346,7 +347,7 @@
 	set rval [list]
 	foreach file $flist {
 		if {[string index $file 0] != "/"} {
-			set file [file join $prefix $file]
+			set file [::file join $prefix $file]
 		}
 		lappend rval [fileinfo_for_file $file]
 	}
@@ -395,9 +396,9 @@
     if {$nlocked > 1} {
         return
     }
-    set lockpath [file join ${registry.path} registry .registry.lock]
+    set lockpath [::file join ${registry.path} registry .registry.lock]
     if {![info exists lockfd]} {
-        if {![file writable [file dirname $lockpath]]} {
+        if {![::file writable [::file dirname $lockpath]]} {
             # skip locking, registry can't be modified anyway
             return
         }

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/registry_autoconf.tcl.in
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/registry_autoconf.tcl.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/registry_autoconf.tcl.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -12,7 +12,7 @@
 # 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 Computer, Inc. nor the names of its contributors
+# 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.
 # 

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/registry_util.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/registry_util.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/registry_util.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -3,6 +3,7 @@
 # $Id$
 #
 # Copyright (c) 2007 Chris Pickel
+# Copyright (c) 2010-2011 The MacPorts Project
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/util.c
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/util.c	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/util.c	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -36,6 +37,7 @@
 
 #include "util.h"
 #include "entryobj.h"
+#include "fileobj.h"
 
 /**
  * Generates a unique proc name starting with prefix.
@@ -45,24 +47,28 @@
  * Tcl interp context. This behavior is similar to that of the builtin
  * `interp create` command, and is intended to generate names for created
  * objects of a similar nature.
- *
- * TODO: add a int* parameter so that functions which need large numbers of
- * unique names can keep track of the lower bound between calls,thereby turning
- * N^2 to N. It'll be alchemy for the 21st century.
  */
-char* unique_name(Tcl_Interp* interp, char* prefix) {
+char* unique_name(Tcl_Interp* interp, char* prefix, int* lower_bound) {
     int result_size = strlen(prefix) + TCL_INTEGER_SPACE + 1;
     char* result = malloc(result_size);
     Tcl_CmdInfo info;
     int i;
     if (!result)
         return NULL;
-    for (i=0; ; i++) {
+    if (lower_bound == NULL) {
+        i = 0;
+    } else {
+        i = *lower_bound;
+    }
+    for (; ; i++) {
         snprintf(result, result_size, "%s%d", prefix, i);
         if (Tcl_GetCommandInfo(interp, result, &info) == 0) {
             break;
         }
     }
+    if (lower_bound != NULL) {
+        *lower_bound = i + 1;
+    }
     return result;
 }
 
@@ -175,18 +181,39 @@
         reg_error* errPtr) {
     if (set_object(interp, name, entry, "entry", entry_obj_cmd, NULL,
                 errPtr)) {
-        int size = strlen(name) + 1;
-        entry->proc = malloc(size*sizeof(char));
+        entry->proc = strdup(name);
         if (!entry->proc) {
             return 0;
         }
-        memcpy(entry->proc, name, size);
         return 1;
     }
     return 0;
 }
 
 /**
+ * Sets a given name to be a file object.
+ *
+ * @param [in] interp  Tcl interpreter to create the file within
+ * @param [in] name    name to associate the given file with
+ * @param [in] file    file to associate with the given name
+ * @param [out] errPtr description of error if it couldn't be set
+ * @return             true if success; false if failure
+ * @see set_object
+ */
+int set_file(Tcl_Interp* interp, char* name, reg_file* file,
+        reg_error* errPtr) {
+    if (set_object(interp, name, file, "file", file_obj_cmd, NULL,
+                errPtr)) {
+        file->proc = strdup(name);
+        if (!file->proc) {
+            return 0;
+        }
+        return 1;
+    }
+    return 0;
+}
+
+/**
  * Reports a sqlite3 error to Tcl.
  *
  * Queries the database for the most recent error message and sets it as the
@@ -204,47 +231,6 @@
     }
 }
 
-/**
- * Sets the result of the interpreter to all objects returned by a query.
- *
- * This function executes `query` on `db` It expects that the query will return
- * records of a single column, `rowid`. It will then use `prefix` to construct
- * unique names for these records, and call `setter` to construct their proc
- * objects. The result of `interp` will be set to a list of all such objects.
- *
- * If TCL_OK is returned, then a list is in the result. If TCL_ERROR is, then an
- * error is there.
- */
-int all_objects(Tcl_Interp* interp, sqlite3* db, char* query, char* prefix,
-        set_object_function* setter) {
-    sqlite3_stmt* stmt;
-    if (sqlite3_prepare(db, query, -1, &stmt, NULL) == SQLITE_OK) {
-        Tcl_Obj* result = Tcl_NewListObj(0, NULL);
-        Tcl_SetObjResult(interp, result);
-        while (sqlite3_step(stmt) == SQLITE_ROW) {
-            sqlite_int64 rowid = sqlite3_column_int64(stmt, 0);
-            char* name = unique_name(interp, prefix);
-            if (!name) {
-                return TCL_ERROR;
-            }
-            if (setter(interp, name, rowid) == TCL_OK) {
-                Tcl_Obj* element = Tcl_NewStringObj(name, -1);
-                Tcl_ListObjAppendElement(interp, result, element);
-                free(name);
-            } else {
-                free(name);
-                return TCL_ERROR;
-            }
-        }
-        sqlite3_finalize(stmt);
-        return TCL_OK;
-    } else {
-        sqlite3_finalize(stmt);
-        set_sqlite_result(interp, db, query);
-        return TCL_ERROR;
-    }
-}
-
 const char* string_or_null(Tcl_Obj* obj) {
     const char* string = Tcl_GetString(obj);
     if (string[0] == '\0') {
@@ -254,15 +240,16 @@
     }
 }
 
-int recast(void* userdata, cast_function* fn, free_function* del, void*** outv,
-        void** inv, int inc, reg_error* errPtr) {
+int recast(void* userdata, cast_function* fn, void* castcalldata,
+        free_function* del, void*** outv, void** inv, int inc,
+        reg_error* errPtr) {
     void** result = malloc(inc*sizeof(void*));
     int i;
     if (!result) {
         return 0;
     }
     for (i=0; i<inc; i++) {
-        if (!fn(userdata, &result[i], inv[i], errPtr)) {
+        if (!fn(userdata, &result[i], inv[i], castcalldata, errPtr)) {
             if (del != NULL) {
                 for ( ; i>=0; i--) {
                     del(userdata, result[i]);
@@ -277,9 +264,9 @@
 }
 
 int entry_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_entry* entry,
-        reg_error* errPtr) {
+        int* lower_bound, reg_error* errPtr) {
     if (entry->proc == NULL) {
-        char* name = unique_name(interp, "::registry::entry");
+        char* name = unique_name(interp, "::registry::entry", lower_bound);
         if (!name) {
             return 0;
         }
@@ -293,26 +280,51 @@
     return 1;
 }
 
+int file_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_file* file,
+        int* lower_bound, reg_error* errPtr) {
+    if (file->proc == NULL) {
+        char* name = unique_name(interp, "::registry::file", lower_bound);
+        if (!name) {
+            return 0;
+        }
+        if (!set_file(interp, name, file, errPtr)) {
+            free(name);
+            return 0;
+        }
+        free(name);
+    }
+    *obj = Tcl_NewStringObj(file->proc, -1);
+    return 1;
+}
+
 int list_entry_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
         reg_entry** entries, int entry_count, reg_error* errPtr) {
-    return recast(interp, (cast_function*)entry_to_obj, NULL, (void***)objs,
-            (void**)entries, entry_count, errPtr);
+    int lower_bound = 0;
+    return recast(interp, (cast_function*)entry_to_obj, &lower_bound, NULL,
+            (void***)objs, (void**)entries, entry_count, errPtr);
 }
 
+int list_file_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
+        reg_file** files, int file_count, reg_error* errPtr) {
+    int lower_bound = 0;
+    return recast(interp, (cast_function*)file_to_obj, &lower_bound, NULL,
+            (void***)objs, (void**)files, file_count, errPtr);
+}
+
 static int obj_to_string(void* userdata UNUSED, char** string, Tcl_Obj* obj,
-        reg_error* errPtr UNUSED) {
+        void* param UNUSED, reg_error* errPtr UNUSED) {
     *string = Tcl_GetString(obj);
     return 1;
 }
 
 int list_obj_to_string(char*** strings, Tcl_Obj** objv, int objc,
         reg_error* errPtr) {
-    return recast(NULL, (cast_function*)obj_to_string, NULL, (void***)strings,
+    return recast(NULL, (cast_function*)obj_to_string, NULL, NULL, (void***)strings,
             (void**)objv, objc, errPtr);
 }
 
 static int string_to_obj(void* userdata UNUSED, Tcl_Obj** obj, char* string,
-        reg_error* errPtr UNUSED) {
+        void* param UNUSED, reg_error* errPtr UNUSED) {
     *obj = Tcl_NewStringObj(string, -1);
     return 1;
 }
@@ -323,6 +335,6 @@
 
 int list_string_to_obj(Tcl_Obj*** objv, char** strings, int objc,
         reg_error* errPtr) {
-    return recast(NULL, (cast_function*)string_to_obj, (free_function*)free_obj,
+    return recast(NULL, (cast_function*)string_to_obj, NULL, (free_function*)free_obj,
             (void***)objv, (void**)strings, objc, errPtr);
 }

Modified: branches/gsoc11-post-destroot/base/src/registry2.0/util.h
===================================================================
--- branches/gsoc11-post-destroot/base/src/registry2.0/util.h	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/registry2.0/util.h	2012-10-19 16:03:11 UTC (rev 98880)
@@ -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
@@ -37,6 +38,7 @@
 
 #include <cregistry/registry.h>
 #include <cregistry/entry.h>
+#include <cregistry/file.h>
 
 typedef struct {
     char* option;
@@ -45,7 +47,7 @@
 
 #define END_FLAGS 0
 
-char* unique_name(Tcl_Interp* interp, char* prefix);
+char* unique_name(Tcl_Interp* interp, char* prefix, int* lower_bound);
 
 int parse_flags(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[], int* start,
         option_spec options[], int* flags);
@@ -56,23 +58,25 @@
         Tcl_ObjCmdProc* proc, Tcl_CmdDeleteProc* deleteProc, reg_error* errPtr);
 int set_entry(Tcl_Interp* interp, char* name, reg_entry* entry,
         reg_error* errPtr);
+int set_file(Tcl_Interp* interp, char* name, reg_file* file,
+        reg_error* errPtr);
 
 void set_sqlite_result(Tcl_Interp* interp, sqlite3* db, const char* query);
 
-typedef int set_object_function(Tcl_Interp* interp, char* name,
-        sqlite_int64 rowid);
-int all_objects(Tcl_Interp* interp, sqlite3* db, char* query, char* prefix,
-        set_object_function* setter);
-
 const char* string_or_null(Tcl_Obj* obj);
 
-int recast(void* userdata, cast_function* fn, free_function* del, void*** outv,
-        void** inv, int inc, reg_error* errPtr);
+int recast(void* userdata, cast_function* fn, void* castcalldata,
+        free_function* del, void*** outv, void** inv, int inc,
+        reg_error* errPtr);
 
 int entry_to_obj(Tcl_Interp* interp, Tcl_Obj** obj, reg_entry* entry,
-        reg_error* errPtr);
+        int* lower_bound, reg_error* errPtr);
 int list_entry_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
         reg_entry** entries, int entry_count, reg_error* errPtr);
+int file_to_obj(Tcl_Interp* interp, Tcl_Obj** ibj, reg_file* file,
+        int* lower_bound, reg_error* errPtr);
+int list_file_to_obj(Tcl_Interp* interp, Tcl_Obj*** objs,
+        reg_file** files, int file_count, reg_error* errPtr);
 
 void free_strings(void* userdata UNUSED, char** strings, int count);
 

Modified: branches/gsoc11-post-destroot/base/src/upgrade_sources_conf_default.tcl
===================================================================
--- branches/gsoc11-post-destroot/base/src/upgrade_sources_conf_default.tcl	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/src/upgrade_sources_conf_default.tcl	2012-10-19 16:03:11 UTC (rev 98880)
@@ -68,18 +68,15 @@
                      regexp {^URL: (.*)} $svnLine -> svnURL
                   }
                   if {[catch {close $svnChannel} err]} {
-                     if {![string match "*This client is too old to work with working copy*" $err]} {
-                        return -code error $err
-                     } else {
-                        puts $err
-                        puts "WARNING: Unable to check svn URL for '$filepath' as it has been checked out with a newer Subversion client; please manually verify $sourcesConf!"
-                     }
+                     puts $err
+                     puts "WARNING: Unable to check svn URL for '$filepath'; please manually verify $sourcesConf!"
                   }
                   if {[regexp {^https?://svn\.(macports|macosforge)\.org/repository/macports/trunk/dports} $svnURL]} {
                      set addDefault true
                   }
                } else {
-                  return -code error $err
+                  puts $err
+                  puts "WARNING: Unable to check svn URL for '$filepath'; please manually verify $sourcesConf!"
                }
             }
          }

Modified: branches/gsoc11-post-destroot/base/tests/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,6 +1,6 @@
 include ../Mk/macports.autoconf.mk
 
-TESTS?=checksums-1 cvs-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)
 
@@ -47,7 +47,7 @@
 	for testname in $(TESTS); do\
 		subdir=test/$$testname; \
 		echo ===\> test ${DIRPRFX}$$subdir; \
-		if [ -e ${DIRPRFX}$$subdir/Makefile ]; then \
+		if [ -e $$subdir/Makefile ]; then \
 			( cd $$subdir && \
 				$(MAKE) DIRPRFX=${DIRPRFX}$$subdir/ PORTSRC=$(PWD)/test-macports.conf test) && \
 			success=$$(( success + 1 )); \
@@ -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-post-destroot/base/tests/test/case-insensitive-deactivate/Makefile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Makefile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Makefile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,7 @@
 include ../../../Mk/macports.autoconf.mk
 
 # see test-macports.conf for the value of prefix
-TESTFILE=/tmp/macports-tests/opt/local/var/macports/case
+TESTFILE=/tmp/macports-tests/opt/local/var/test/case
 TESTPORT1=casesensitive
 TESTPORT2=CaseSensitivE
 

Modified: branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Portfile.in
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Portfile.in	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/Portfile.in	2012-10-19 16:03:11 UTC (rev 98880)
@@ -12,11 +12,10 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
-	system "touch ${destroot}${prefix}/var/macports/case"
+	xinstall -d ${destroot}${prefix}/var/test
+	system "touch ${destroot}${prefix}/var/test/case"
 }

Modified: branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/README
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/README	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/case-insensitive-deactivate/README	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,2 +1,2 @@
 See ticket #11759,
-http://trac.macosforge.org/projects/macports/ticket/11759
+https://trac.macports.org/ticket/11759

Modified: branches/gsoc11-post-destroot/base/tests/test/checksums-1/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/checksums-1/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/checksums-1/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,4 @@
---->  Computing dependencies for checksum
---->  Fetching checksum
+--->  Fetching distfiles for checksum
 --->  Verifying checksum(s) for checksum
 --->  Extracting checksum
 --->  Configuring checksum

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-a/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-a/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-a/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-b/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-b/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-b/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-c/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-c/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-c/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-c/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-c/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-c/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,6 @@
 --->  Computing dependencies for dependencies-c
---->  Fetching dependencies-b
+--->  Dependencies to be installed: dependencies-a dependencies-b
+--->  Fetching distfiles for dependencies-b
 --->  Verifying checksum(s) for dependencies-b
 --->  Extracting dependencies-b
 --->  Configuring dependencies-b
@@ -8,7 +9,7 @@
 --->  Installing dependencies-b @1_0
 --->  Activating dependencies-b @1_0
 --->  Cleaning dependencies-b
---->  Fetching dependencies-a
+--->  Fetching distfiles for dependencies-a
 --->  Verifying checksum(s) for dependencies-a
 --->  Extracting dependencies-a
 --->  Configuring dependencies-a
@@ -17,7 +18,7 @@
 --->  Installing dependencies-a @1_0+i_want_b
 --->  Activating dependencies-a @1_0+i_want_b
 --->  Cleaning dependencies-a
---->  Fetching dependencies-c
+--->  Fetching distfiles for dependencies-c
 --->  Verifying checksum(s) for dependencies-c
 --->  Extracting dependencies-c
 --->  Configuring dependencies-c

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-d/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-d/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-d/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-d/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-d/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-d/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,8 @@
 Warning: depends option is not handled yet
 Warning: depends option is not handled yet
 --->  Computing dependencies for dependencies-d
---->  Fetching dependencies-b
+--->  Dependencies to be installed: dependencies-a dependencies-b
+--->  Fetching distfiles for dependencies-b
 --->  Verifying checksum(s) for dependencies-b
 --->  Extracting dependencies-b
 --->  Configuring dependencies-b
@@ -10,7 +11,7 @@
 --->  Installing dependencies-b @1_0
 --->  Activating dependencies-b @1_0
 --->  Cleaning dependencies-b
---->  Fetching dependencies-a
+--->  Fetching distfiles for dependencies-a
 --->  Verifying checksum(s) for dependencies-a
 --->  Extracting dependencies-a
 --->  Configuring dependencies-a
@@ -19,7 +20,7 @@
 --->  Installing dependencies-a @1_0+i_want_b
 --->  Activating dependencies-a @1_0+i_want_b
 --->  Cleaning dependencies-a
---->  Fetching dependencies-d
+--->  Fetching distfiles for dependencies-d
 --->  Verifying checksum(s) for dependencies-d
 --->  Extracting dependencies-d
 --->  Configuring dependencies-d

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-e/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-e/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-e/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/dependencies-e/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/dependencies-e/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/dependencies-e/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,3 +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, follow the instructions in the guide:
+    http://guide.macports.org/#project.tickets
+Error: Processing of port dependencies-e failed

Modified: branches/gsoc11-post-destroot/base/tests/test/envvariables/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/envvariables/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/envvariables/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/envvariables/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/envvariables/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/envvariables/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,4 @@
---->  Computing dependencies for envvariables
---->  Fetching envvariables
+--->  Fetching distfiles for envvariables
 --->  Verifying checksum(s) for envvariables
 --->  Extracting envvariables
 --->  Configuring envvariables

Modified: branches/gsoc11-post-destroot/base/tests/test/site-tags/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/site-tags/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/site-tags/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -26,7 +26,7 @@
 					rmd160 3cbae7e39e8c78eca03a0db709cf520003896a12
 
 extract		{}
-configure	{}
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/site-tags/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/site-tags/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/site-tags/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,4 @@
---->  Computing dependencies for site-tags
---->  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

Modified: branches/gsoc11-post-destroot/base/tests/test/trace/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/trace/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/trace/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"

Modified: branches/gsoc11-post-destroot/base/tests/test/trace/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/trace/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/trace/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,5 +1,4 @@
---->  Computing dependencies for trace
---->  Fetching trace
+--->  Fetching distfiles for trace
 --->  Verifying checksum(s) for trace
 --->  Extracting trace
 --->  Configuring trace

Modified: branches/gsoc11-post-destroot/base/tests/test/universal/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/universal/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/universal/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,9 +11,7 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
+distfiles
 configure	{}
 build		{}
 destroot	{

Modified: branches/gsoc11-post-destroot/base/tests/test/universal-2/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/universal-2/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/universal-2/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,9 +11,7 @@
 
 long_description ${description}
 
-fetch		{}
-checksum	{}
-extract		{}
+distfiles
 configure	{}
 build		{}
 destroot	{

Modified: branches/gsoc11-post-destroot/base/tests/test/variants/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/variants/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/variants/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -11,10 +11,8 @@
 
 long_description ${description}
 
-fetch 		{}
-checksum	{}
-extract		{}
-configure	{}
+distfiles
+use_configure no
 build		{}
 destroot	{
 	system "touch ${destroot}${prefix}/lib/${name}"
@@ -24,8 +22,6 @@
 	# test is actually installing this.
 }
 
-use_configure	no
-
 # We override universal variant.
 variant universal {
 	puts "Universal Variant"

Modified: branches/gsoc11-post-destroot/base/tests/test/variants/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/variants/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/variants/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,7 +1,6 @@
 Utopia variant -- 2
 Utopia variant -- 2
---->  Computing dependencies for variants
---->  Fetching variants
+--->  Fetching distfiles for variants
 --->  Verifying checksum(s) for variants
 --->  Extracting variants
 --->  Configuring variants

Modified: branches/gsoc11-post-destroot/base/tests/test/xcodeversion/Portfile
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/xcodeversion/Portfile	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/xcodeversion/Portfile	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,26 +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}
 
-fetch		{}
-checksum	{}
-extract		{}
-configure	{}
-build		{}
-destroot	{
-	system "touch ${destroot}${prefix}/lib/${name}"
+distfiles
+use_configure no
+build       {}
+destroot    {
+    system "touch ${destroot}${prefix}/lib/${name}"
 }
 
 test {
-	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-post-destroot/base/tests/test/xcodeversion/master
===================================================================
--- branches/gsoc11-post-destroot/base/tests/test/xcodeversion/master	2012-10-19 14:18:44 UTC (rev 98879)
+++ branches/gsoc11-post-destroot/base/tests/test/xcodeversion/master	2012-10-19 16:03:11 UTC (rev 98880)
@@ -1,9 +1,8 @@
---->  Computing dependencies for xcodeversion
---->  Fetching xcodeversion
+--->  Fetching distfiles for xcodeversion
 --->  Verifying checksum(s) for xcodeversion
 --->  Extracting xcodeversion
 --->  Configuring xcodeversion
 --->  Building xcodeversion
 --->  Testing xcodeversion
-xcodeversion = 2.1
-xcodebuildcmd = xcodebuild
+xcodeversion >= 2.1
+xcodebuildcmd = /usr/bin/xcodebuild
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20121019/b3349ba5/attachment-0001.html>


More information about the macports-changes mailing list