Add detection of WITH_PKGNG, get defaults from make.conf.

With ports now supporting an alternative packaging software some refractoring
is required to support both pkg (as in base) and pkgng (alternative that can
be activated using WITH_PKGNG).
Refactor environment variables from make.conf and build target handling.

Allow extra values to be specified when initialising the environment variables
based on make.conf.  This allows an external setup program to setup state based
on the contents of make.conf.

Remove the use of flags["package"] and add flags["target"].  The target flag
corresponds to the DEPENDS_TARGET value.  This will facilitate better mimicking
of the port infrastructure.

While here change flags["pkg_sys"] to flags["pkg_mgmt"] to reflect that the
flag controls which package manager is used.
Update TODO list to reflect recent changes.
Add documentation and refactor _get_os_version().

_get_os_version() now tries all param.h files until one is found, then falls
back to using sysctl.
Refactor option setting code.

Split set_options() into set_early_options() and set_options() where the former
sets options required when loading defaults from /etc/make.conf.

Refactor /etc/make.conf handling code into load_defaults() which configures the
state flags based on defaults present in /etc/make.conf and os.environ.

Move all os.environ cleaning code into env.setup_env().
If a variable from env_master is specified in env then null it from env_master.

If a variable is specified in env then it is explicitly expected by the user
and should not be hidden by env_master so assign None to the env_master value
to ensure the variable is always specified when calling make(1).
Add handling for DEPENDS_TARGET (aka flags["target"]).

The supported values are:
 - DEPENDS_TARGET (with checks for supported targets)
 - DEPENDS_CLEAN
 - DEPENDS_PRECLEAN

At this time the clean targets are not handled.
Update TODO to reflect changes from this branch (make_conf).
Refine handling of packages.

The local package directory is ${PKGREPOSITORY}, not ${PACKAGES} and no not
attempt to install a port from packages if it does not allow packages to be
built.
Merge branch 'make_conf'
Refactor pkg_add handling into the ``pkg'' module.

This is in preparation for introducing support for pkgng.  No functional change.
Move pkg_version() into the ``pkg'' module.

This is in preparation for introducing support for pkgng.  No functional change.
Refactor mk.status() into the ``pkg'' module.

This is in preparation for introducing support for pkgng.

Instead of inspecting the PKG_DBDIR directly call pkg.info, which will rely on
the public API (via `pkg_info').

Fix a bug where the distfile was incorrectly joined with the flags["chroot"]
path.  os.path.join ignores the previous parameters if one starts with '/', so
flags["chroot"] needs to be added before being passed to os.path.join.
Use the pkg.db object to load all ports (instead of calling `pkg_info').
Load the package database with an explicit command.

This prevents the importing of libpb.pkg from taking a long time.
Update TODO to reflect changes from pkg branch.
Merge branch 'pkg'

Conflicts:
	TODO
Update TODO to reflect revised planned versions.

Sticking with 0.1.x was unnecessarily conservative as once, then 0.1.9, now 0.7
is achieved it is basically a stable release, ready for 1.0.
Conditionally clean ports pre-build and post-build.

Extend Port.clean() to return the job used to clean and to allow forcing the
clean in-case an existing dirty (but unknown) state needs to be cleaned.

Once a port is added to the build stage queue it for building if pre-cleaning is
required.  The cleaning will be done in parallel to other stages and will only
delay the build stage, if needed.
Some minor fixups re handling of cleaning.

Do not mark the port as not-working after cleaning as the port may actually be
busy with a non-dirty activity (like fetching files).

Do not pass NODEPENDSCLEAN when building port, cleaning is now handled
separately.