diff --git a/lib/spack/env/cc b/lib/spack/env/cc
index 4a3e6eddc9438bcd3da73ff0202656a9409b658b..2eb6f46afe5af25864741919b9f2ee9f1076e0e6 100755
--- a/lib/spack/env/cc
+++ b/lib/spack/env/cc
@@ -65,7 +65,7 @@ function die {
 }
 
 for param in $parameters; do
-    if [ -z "${!param}" ]; then
+    if [[ -z ${!param} ]]; then
         die "Spack compiler must be run from spack!  Input $param was missing!"
     fi
 done
@@ -78,12 +78,17 @@ done
 # 'command' is set based on the input command to $SPACK_[CC|CXX|F77|F90]
 #
 # 'mode' is set to one of:
+#    cpp     preprocess
 #    cc      compile
+#    as      assemble
 #    ld      link
 #    ccld    compile & link
-#    cpp     preprocessor
 #    vcheck  version check
 #
+# Depending on the mode, we may or may not add extra rpaths.
+# This variable controls whether they are added.
+add_rpaths=true
+
 command=$(basename "$0")
 case "$command" in
     cc|c89|c99|gcc|clang|icc|pgcc|xlc)
@@ -107,13 +112,26 @@ case "$command" in
         ;;
     ld)
         mode=ld
+
+        # Darwin's linker has a -r argument that merges object files
+        # together. It doesn't work with -rpath.
+        if [[ $OSTYPE = darwin* ]]; then
+            for arg in "$@"; do
+                if [ "$arg" = -r ]; then
+                    add_rpaths=false
+                    break
+	            fi
+            done
+        fi
         ;;
     *)
         die "Unkown compiler: $command"
         ;;
 esac
 
-# If any of the arguments below is present then the mode is vcheck. In vcheck mode nothing is added in terms of extra search paths or libraries
+# If any of the arguments below is present then the mode is vcheck. In
+# vcheck mode nothing is added in terms of extra search paths or
+# libraries
 if [ -z "$mode" ]; then
     for arg in "$@"; do
         if [ "$arg" = -v -o "$arg" = -V -o "$arg" = --version -o "$arg" = -dumpversion ]; then
@@ -124,13 +142,15 @@ if [ -z "$mode" ]; then
 fi
 
 # Finish setting up the mode.
-
 if [ -z "$mode" ]; then
     mode=ccld
     for arg in "$@"; do
         if [ "$arg" = -E ]; then
             mode=cpp
             break
+        elif [ "$arg" = -S ]; then
+            mode=as
+            break
         elif [ "$arg" = -c ]; then
             mode=cc
             break
@@ -146,168 +166,56 @@ fi
 
 # Check that at least one of the real commands was actually selected,
 # otherwise we don't know what to execute.
-if [ -z "$command" ]; then
+if [[ -z $command ]]; then
     die "ERROR: Compiler '$SPACK_COMPILER_SPEC' does not support compiling $language programs."
 fi
 
-# Save original command for debug logging
-input_command="$@"
-
 if [ "$mode" == vcheck ] ; then
     exec ${command} "$@"
 fi
 
-#
-# Now do real parsing of the command line args, trying hard to keep
-# non-rpath linker arguments in the proper order w.r.t. other command
-# line arguments.  This is important for things like groups.
-#
-includes=()
-libraries=()
-libs=()
-rpaths=()
-other_args=()
-
-while [ -n "$1" ]; do
-    case "$1" in
-        -I*)
-            arg="${1#-I}"
-            if [ -z "$arg" ]; then shift; arg="$1"; fi
-            includes+=("$arg")
-            ;;
-        -L*)
-            arg="${1#-L}"
-            if [ -z "$arg" ]; then shift; arg="$1"; fi
-            libraries+=("$arg")
-            ;;
-        -l*)
-            arg="${1#-l}"
-            if [ -z "$arg" ]; then shift; arg="$1"; fi
-            libs+=("$arg")
-            ;;
-        -Wl,*)
-            arg="${1#-Wl,}"
-            # TODO: Handle multiple -Wl, continuations of -Wl,-rpath
-            if [[ $arg == -rpath=* ]]; then
-                arg="${arg#-rpath=}"
-                for rpath in ${arg//,/ }; do
-                    rpaths+=("$rpath")
-                done
-            elif [[ $arg == -rpath,* ]]; then
-                arg="${arg#-rpath,}"
-                for rpath in ${arg//,/ }; do
-                    rpaths+=("$rpath")
-                done
-            elif [[ $arg == -rpath ]]; then
-                shift; arg="$1"
-                if [[ $arg != '-Wl,'* ]]; then
-                    die "-Wl,-rpath was not followed by -Wl,*"
-                fi
-                arg="${arg#-Wl,}"
-                for rpath in ${arg//,/ }; do
-                    rpaths+=("$rpath")
-                done
-            else
-                other_args+=("-Wl,$arg")
-            fi
-            ;;
-        -Xlinker)
-            shift; arg="$1";
-            if [[ $arg = -rpath=* ]]; then
-                rpaths+=("${arg#-rpath=}")
-            elif [[ $arg = -rpath ]]; then
-                shift; arg="$1"
-                if [[ $arg != -Xlinker ]]; then
-                    die "-Xlinker -rpath was not followed by -Xlinker <arg>"
-                fi
-                shift; arg="$1"
-                rpaths+=("$arg")
-            else
-                other_args+=("-Xlinker")
-                other_args+=("$arg")
-            fi
-            ;;
-        *)
-            other_args+=("$1")
-            ;;
-    esac
-    shift
-done
-
-# Dump parsed values for unit testing if asked for
-if [ -n "$SPACK_TEST_COMMAND" ]; then
-    IFS=$'\n'
-    case "$SPACK_TEST_COMMAND" in
-        dump-includes)   echo "${includes[*]}";;
-        dump-libraries)  echo "${libraries[*]}";;
-        dump-libs)       echo "${libs[*]}";;
-        dump-rpaths)     echo "${rpaths[*]}";;
-        dump-other-args) echo "${other_args[*]}";;
-        dump-all)
-            echo "INCLUDES:"
-            echo "${includes[*]}"
-            echo
-            echo "LIBRARIES:"
-            echo "${libraries[*]}"
-            echo
-            echo "LIBS:"
-            echo "${libs[*]}"
-            echo
-            echo "RPATHS:"
-            echo "${rpaths[*]}"
-            echo
-            echo "ARGS:"
-            echo "${other_args[*]}"
-            ;;
-        *)
-            echo "ERROR: Unknown test command"
-            exit 1 ;;
-    esac
-    exit
-fi
+# Save original command for debug logging
+input_command="$@"
+args=("$@")
 
 # Read spack dependencies from the path environment variable
 IFS=':' read -ra deps <<< "$SPACK_DEPENDENCIES"
 for dep in "${deps[@]}"; do
-    if [ -d "$dep/include" ]; then
-        includes+=("$dep/include")
+    # Prepend include directories
+    if [[ -d $dep/include ]]; then
+        if [[ $mode = cpp || $mode = cc || $mode = as || $mode = ccld ]]; then
+            args=("-I$dep/include" "${args[@]}")
+        fi
     fi
 
-    if [ -d "$dep/lib" ]; then
-        libraries+=("$dep/lib")
-        rpaths+=("$dep/lib")
+    # Prepend lib and RPATH directories
+    if [[ -d $dep/lib ]]; then
+        if [[ $mode = ccld ]]; then
+            $add_rpaths && args=("-Wl,-rpath,$dep/lib" "${args[@]}")
+            args=("-L$dep/lib" "${args[@]}")
+        elif [[ $mode = ld ]]; then
+            $add_rpaths && args=("-rpath" "$dep/lib" "${args[@]}")
+            args=("-L$dep/lib" "${args[@]}")
+        fi
     fi
 
-    if [ -d "$dep/lib64" ]; then
-        libraries+=("$dep/lib64")
-        rpaths+=("$dep/lib64")
+    # Prepend lib64 and RPATH directories
+    if [[ -d $dep/lib64 ]]; then
+        if [[ $mode = ccld ]]; then
+            $add_rpaths && args=("-Wl,-rpath,$dep/lib64" "${args[@]}")
+            args=("-L$dep/lib64" "${args[@]}")
+        elif [[ $mode = ld ]]; then
+            $add_rpaths && args=("-rpath" "$dep/lib64" "${args[@]}")
+            args=("-L$dep/lib64" "${args[@]}")
+        fi
     fi
 done
 
 # Include all -L's and prefix/whatever dirs in rpath
-for dir in "${libraries[@]}"; do
-    [[ dir = $SPACK_INSTALL* ]] && rpaths+=("$dir")
-done
-rpaths+=("$SPACK_PREFIX/lib")
-rpaths+=("$SPACK_PREFIX/lib64")
-
-# Put the arguments together
-args=()
-for dir in "${includes[@]}";  do args+=("-I$dir"); done
-args+=("${other_args[@]}")
-for dir in "${libraries[@]}"; do args+=("-L$dir"); done
-for lib in "${libs[@]}";      do args+=("-l$lib"); done
-
-if [ "$mode" = ccld ]; then
-    for dir in "${rpaths[@]}"; do
-        args+=("-Wl,-rpath")
-        args+=("-Wl,$dir");
-    done
-elif [ "$mode" = ld ]; then
-    for dir in "${rpaths[@]}"; do
-        args+=("-rpath")
-        args+=("$dir");
-    done
+if [[ $mode = ccld ]]; then
+    $add_rpaths && args=("-Wl,-rpath,$SPACK_PREFIX/lib" "-Wl,-rpath,$SPACK_PREFIX/lib64" "${args[@]}")
+elif [[ $mode = ld ]]; then
+    $add_rpaths && args=("-rpath" "$SPACK_PREFIX/lib" "-rpath" "$SPACK_PREFIX/lib64" "${args[@]}")
 fi
 
 #
@@ -323,34 +231,37 @@ unset DYLD_LIBRARY_PATH
 #
 IFS=':' read -ra env_path <<< "$PATH"
 IFS=':' read -ra spack_env_dirs <<< "$SPACK_ENV_PATH"
-spack_env_dirs+=(".")
+spack_env_dirs+=("" ".")
 PATH=""
 for dir in "${env_path[@]}"; do
     remove=""
     for rm_dir in "${spack_env_dirs[@]}"; do
-        if [ "$dir" = "$rm_dir" ]; then remove=True; fi
+        if [[ $dir = $rm_dir ]]; then remove=True; fi
     done
-    if [ -z "$remove" ]; then
-        if [ -z "$PATH" ]; then
-            PATH="$dir"
-        else
-            PATH="$PATH:$dir"
-        fi
+    if [[ -z $remove ]]; then
+        PATH="${PATH:+$PATH:}$dir"
     fi
 done
 export PATH
 
-full_command=("$command")
-full_command+=("${args[@]}")
+full_command=("$command" "${args[@]}")
+
+# In test command mode, write out full command for Spack tests.
+if [[ $SPACK_TEST_COMMAND = dump-args ]]; then
+    echo "${full_command[@]}"
+    exit
+elif [[ -n $SPACK_TEST_COMMAND ]]; then
+    die "ERROR: Unknown test command"
+fi
 
 #
 # Write the input and output commands to debug logs if it's asked for.
 #
-if [ "$SPACK_DEBUG" = "TRUE" ]; then
+if [[ $SPACK_DEBUG = TRUE ]]; then
     input_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.in.log"
     output_log="$SPACK_DEBUG_LOG_DIR/spack-cc-$SPACK_SHORT_SPEC.out.log"
-    echo "$input_command"     >> $input_log
-    echo "$mode       ${full_command[@]}" >> $output_log
+    echo "[$mode] $command $input_command" >> $input_log
+    echo "[$mode] ${full_command[@]}" >> $output_log
 fi
 
 exec "${full_command[@]}"
diff --git a/lib/spack/spack/fetch_strategy.py b/lib/spack/spack/fetch_strategy.py
index 0d0a7db8a9146d952d3d7f7173a970601881af1b..4ea87bea7ea3e71b61b2766b464e1a1acf2b24e3 100644
--- a/lib/spack/spack/fetch_strategy.py
+++ b/lib/spack/spack/fetch_strategy.py
@@ -289,8 +289,14 @@ def reset(self):
         if not self.archive_file:
             raise NoArchiveFileError("Tried to reset URLFetchStrategy before fetching",
                                      "Failed on reset() for URL %s" % self.url)
-        if self.stage.source_path:
-            shutil.rmtree(self.stage.source_path, ignore_errors=True)
+
+        # Remove everythigng but the archive from the stage
+        for filename in os.listdir(self.stage.path):
+            abspath = os.path.join(self.stage.path, filename)
+            if abspath != self.archive_file:
+                shutil.rmtree(abspath, ignore_errors=True)
+
+        # Expand the archive again
         self.expand()
 
     def __repr__(self):
diff --git a/lib/spack/spack/test/cc.py b/lib/spack/spack/test/cc.py
index f3f6d4a22e682f25c8b6b60888af734316d89ecb..0b1aeb2a8fe86de5ef05e9e6036079a5c8724c88 100644
--- a/lib/spack/spack/test/cc.py
+++ b/lib/spack/spack/test/cc.py
@@ -28,6 +28,8 @@
 """
 import os
 import unittest
+import tempfile
+import shutil
 
 from llnl.util.filesystem import *
 import spack
@@ -55,13 +57,40 @@ def setUp(self):
         self.ld = Executable(join_path(spack.build_env_path, "ld"))
         self.cpp = Executable(join_path(spack.build_env_path, "cpp"))
 
-        os.environ['SPACK_CC'] = "/bin/mycc"
-        os.environ['SPACK_PREFIX'] = "/usr"
+        self.realcc = "/bin/mycc"
+        self.prefix = "/spack-test-prefix"
+
+        os.environ['SPACK_CC'] = self.realcc
+        os.environ['SPACK_PREFIX'] = self.prefix
         os.environ['SPACK_ENV_PATH']="test"
         os.environ['SPACK_DEBUG_LOG_DIR'] = "."
         os.environ['SPACK_COMPILER_SPEC'] = "gcc@4.4.7"
         os.environ['SPACK_SHORT_SPEC'] = "foo@1.2"
 
+        # Make some fake dependencies
+        self.tmp_deps = tempfile.mkdtemp()
+        self.dep1 = join_path(self.tmp_deps, 'dep1')
+        self.dep2 = join_path(self.tmp_deps, 'dep2')
+        self.dep3 = join_path(self.tmp_deps, 'dep3')
+        self.dep4 = join_path(self.tmp_deps, 'dep4')
+
+        mkdirp(join_path(self.dep1, 'include'))
+        mkdirp(join_path(self.dep1, 'lib'))
+
+        mkdirp(join_path(self.dep2, 'lib64'))
+
+        mkdirp(join_path(self.dep3, 'include'))
+        mkdirp(join_path(self.dep3, 'lib64'))
+
+        mkdirp(join_path(self.dep4, 'include'))
+
+        if 'SPACK_DEPENDENCIES' in os.environ:
+            del os.environ['SPACK_DEPENDENCIES']
+
+
+    def tearDown(self):
+        shutil.rmtree(self.tmp_deps, True)
+
 
     def check_cc(self, command, args, expected):
         os.environ['SPACK_TEST_COMMAND'] = command
@@ -92,6 +121,10 @@ def test_cpp_mode(self):
         self.check_cpp('dump-mode', [], "cpp")
 
 
+    def test_as_mode(self):
+        self.check_cc('dump-mode', ['-S'], "as")
+
+
     def test_ccld_mode(self):
         self.check_cc('dump-mode', [], "ccld")
         self.check_cc('dump-mode', ['foo.c', '-o', 'foo'], "ccld")
@@ -104,27 +137,85 @@ def test_ld_mode(self):
         self.check_ld('dump-mode', ['foo.o', 'bar.o', 'baz.o', '-o', 'foo', '-Wl,-rpath,foo'], "ld")
 
 
-    def test_includes(self):
-        self.check_cc('dump-includes', test_command,
-                      "\n".join(["/test/include", "/other/include"]))
+    def test_dep_rpath(self):
+        """Ensure RPATHs for root package are added."""
+        self.check_cc('dump-args', test_command,
+                      self.realcc + ' ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib64 ' +
+                      ' '.join(test_command))
+
+
+    def test_dep_include(self):
+        """Ensure a single dependency include directory is added."""
+        os.environ['SPACK_DEPENDENCIES'] = self.dep4
+        self.check_cc('dump-args', test_command,
+                      self.realcc + ' ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib64 ' +
+                      '-I' + self.dep4 + '/include ' +
+                      ' '.join(test_command))
+
+
+    def test_dep_lib(self):
+        """Ensure a single dependency RPATH is added."""
+        os.environ['SPACK_DEPENDENCIES'] = self.dep2
+        self.check_cc('dump-args', test_command,
+                      self.realcc + ' ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib64 ' +
+                      '-L' + self.dep2 + '/lib64 ' +
+                      '-Wl,-rpath,' + self.dep2 + '/lib64 ' +
+                      ' '.join(test_command))
+
+
+    def test_all_deps(self):
+        """Ensure includes and RPATHs for all deps are added. """
+        os.environ['SPACK_DEPENDENCIES'] = ':'.join([
+            self.dep1, self.dep2, self.dep3, self.dep4])
+
+        # This is probably more constrained than it needs to be; it
+        # checks order within prepended args and doesn't strictly have
+        # to.  We could loosen that if it becomes necessary
+        self.check_cc('dump-args', test_command,
+                      self.realcc + ' ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib ' +
+                      '-Wl,-rpath,' + self.prefix + '/lib64 ' +
+
+                      '-I' + self.dep4 + '/include ' +
+
+                      '-L' + self.dep3 + '/lib64 ' +
+                      '-Wl,-rpath,' + self.dep3 + '/lib64 ' +
+                      '-I' + self.dep3 + '/include ' +
+
+                      '-L' + self.dep2 + '/lib64 ' +
+                      '-Wl,-rpath,' + self.dep2 + '/lib64 ' +
+
+                      '-L' + self.dep1 + '/lib ' +
+                      '-Wl,-rpath,' + self.dep1 + '/lib ' +
+                      '-I' + self.dep1 + '/include ' +
+
+                      ' '.join(test_command))
 
 
-    def test_libraries(self):
-        self.check_cc('dump-libraries', test_command,
-                      "\n".join(["/test/lib", "/other/lib"]))
+    def test_ld_deps(self):
+        """Ensure no (extra) -I args or -Wl, are passed in ld mode."""
+        os.environ['SPACK_DEPENDENCIES'] = ':'.join([
+            self.dep1, self.dep2, self.dep3, self.dep4])
 
+        self.check_ld('dump-args', test_command,
+                      'ld ' +
+                      '-rpath ' + self.prefix + '/lib ' +
+                      '-rpath ' + self.prefix + '/lib64 ' +
 
-    def test_libs(self):
-        self.check_cc('dump-libs', test_command,
-                      "\n".join(["lib1", "lib2", "lib3", "lib4"]))
+                      '-L' + self.dep3 + '/lib64 ' +
+                      '-rpath ' + self.dep3 + '/lib64 ' +
 
+                      '-L' + self.dep2 + '/lib64 ' +
+                      '-rpath ' + self.dep2 + '/lib64 ' +
 
-    def test_rpaths(self):
-        self.check_cc('dump-rpaths', test_command,
-                      "\n".join(["/first/rpath", "/second/rpath", "/third/rpath", "/fourth/rpath"]))
+                      '-L' + self.dep1 + '/lib ' +
+                      '-rpath ' + self.dep1 + '/lib ' +
 
+                      ' '.join(test_command))
 
-    def test_other_args(self):
-        self.check_cc('dump-other-args', test_command,
-                      "\n".join(["arg1", "-Wl,--start-group", "arg2", "arg3", "arg4",
-                                 "-Wl,--end-group", "arg5", "arg6"]))
diff --git a/var/spack/repos/builtin/packages/astyle/package.py b/var/spack/repos/builtin/packages/astyle/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..7260fd74a1d6f156652263ba8b02f7f32e47c2f9
--- /dev/null
+++ b/var/spack/repos/builtin/packages/astyle/package.py
@@ -0,0 +1,17 @@
+from spack import *
+import os
+
+class Astyle(Package):
+    """A Free, Fast, and Small Automatic Formatter for C, C++, C++/CLI, Objective-C, C#, and Java Source Code."""
+    homepage = "http://astyle.sourceforge.net/"
+    url      = "http://downloads.sourceforge.net/project/astyle/astyle/astyle%202.04/astyle_2.04_linux.tar.gz"
+
+    version('2.04', '30b1193a758b0909d06e7ee8dd9627f6')
+
+    def install(self, spec, prefix):
+
+        with working_dir('src'):
+            make('-f',
+                join_path(self.stage.source_path,'build','clang','Makefile'),
+                parallel=False)
+            install(join_path(self.stage.source_path, 'src','bin','astyle'), self.prefix.bin)
diff --git a/var/spack/repos/builtin/packages/boost/package.py b/var/spack/repos/builtin/packages/boost/package.py
index 82ce6fbb7440a59ba67a080a953dffd8a46217e9..f889da21f2586d38a50dad755f006c6c02937e47 100644
--- a/var/spack/repos/builtin/packages/boost/package.py
+++ b/var/spack/repos/builtin/packages/boost/package.py
@@ -2,6 +2,9 @@
 import spack
 import sys
 
+import os
+import sys
+
 class Boost(Package):
     """Boost provides free peer-reviewed portable C++ source
        libraries, emphasizing libraries that work well with the C++
@@ -173,6 +176,16 @@ def determine_b2_options(self, spec, options):
         return threadingOpts
 
     def install(self, spec, prefix):
+        # On Darwin, Boost expects the Darwin libtool. However, one of the
+        # dependencies may have pulled in Spack's GNU libtool, and these two are
+        # not compatible. We thus create a symlink to Darwin's libtool and add
+        # it at the beginning of PATH.
+        if sys.platform == 'darwin':
+            newdir = os.path.abspath('darwin-libtool')
+            mkdirp(newdir)
+            force_symlink('/usr/bin/libtool', join_path(newdir, 'libtool'))
+            env['PATH'] = newdir + ':' + env['PATH']
+
         withLibs = list()
         for lib in Boost.all_libs:
             if "+{0}".format(lib) in spec:
diff --git a/var/spack/repos/builtin/packages/gcc/darwin/gcc-4.9.patch1 b/var/spack/repos/builtin/packages/gcc/darwin/gcc-4.9.patch1
new file mode 100644
index 0000000000000000000000000000000000000000..444e292786df41346a3a1cc6267bba587408a007
--- /dev/null
+++ b/var/spack/repos/builtin/packages/gcc/darwin/gcc-4.9.patch1
@@ -0,0 +1,42 @@
+diff --git a/gcc/configure b/gcc/configure
+index 9523773..52b0bf7 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -24884,7 +24884,7 @@ if test "${gcc_cv_as_ix86_filds+set}" = set; then :
+ else
+   gcc_cv_as_ix86_filds=no
+   if test x$gcc_cv_as != x; then
+-    $as_echo 'filds mem; fists mem' > conftest.s
++    $as_echo 'filds (%ebp); fists (%ebp)' > conftest.s
+     if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+   (eval $ac_try) 2>&5
+@@ -24915,7 +24915,7 @@ if test "${gcc_cv_as_ix86_fildq+set}" = set; then :
+ else
+   gcc_cv_as_ix86_fildq=no
+   if test x$gcc_cv_as != x; then
+-    $as_echo 'fildq mem; fistpq mem' > conftest.s
++    $as_echo 'fildq (%ebp); fistpq (%ebp)' > conftest.s
+     if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+   (eval $ac_try) 2>&5
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 68b0ee8..bd53978 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -3869,13 +3869,13 @@ foo:	nop
+ 
+     gcc_GAS_CHECK_FEATURE([filds and fists mnemonics],
+        gcc_cv_as_ix86_filds,,,
+-       [filds mem; fists mem],,
++       [filds (%ebp); fists (%ebp)],,
+        [AC_DEFINE(HAVE_AS_IX86_FILDS, 1,
+          [Define if your assembler uses filds and fists mnemonics.])])
+ 
+     gcc_GAS_CHECK_FEATURE([fildq and fistpq mnemonics],
+        gcc_cv_as_ix86_fildq,,,
+-       [fildq mem; fistpq mem],,
++       [fildq (%ebp); fistpq (%ebp)],,
+        [AC_DEFINE(HAVE_AS_IX86_FILDQ, 1,
+          [Define if your assembler uses fildq and fistq mnemonics.])])
+ 
diff --git a/var/spack/repos/builtin/packages/gcc/darwin/gcc-4.9.patch2 b/var/spack/repos/builtin/packages/gcc/darwin/gcc-4.9.patch2
new file mode 100644
index 0000000000000000000000000000000000000000..b065997f453926e20d285f8a5e6555d9cd2e8f96
--- /dev/null
+++ b/var/spack/repos/builtin/packages/gcc/darwin/gcc-4.9.patch2
@@ -0,0 +1,28 @@
+From 82f81877458ea372176eabb5de36329431dce99b Mon Sep 17 00:00:00 2001
+From: Iain Sandoe <iain@codesourcery.com>
+Date: Sat, 21 Dec 2013 00:30:18 +0000
+Subject: [PATCH] don't try to mark local symbols as no-dead-strip
+
+---
+ gcc/config/darwin.c | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
+index 40804b8..0080299 100644
+--- a/gcc/config/darwin.c
++++ b/gcc/config/darwin.c
+@@ -1259,6 +1259,11 @@ darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
+ void
+ darwin_mark_decl_preserved (const char *name)
+ {
++  /* Actually we shouldn't mark any local symbol this way, but for now
++     this only happens with ObjC meta-data.  */
++  if (darwin_label_is_anonymous_local_objc_name (name))
++    return;
++
+   fprintf (asm_out_file, "\t.no_dead_strip ");
+   assemble_name (asm_out_file, name);
+   fputc ('\n', asm_out_file);
+-- 
+2.2.1
+
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
index f8958ee290777d85f832a99340492c0305aa6a04..6043b6227932de76ac64fa3298dc87c9ad132312 100644
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -26,6 +26,8 @@
 
 from contextlib import closing
 from glob import glob
+import sys
+import os
 
 class Gcc(Package):
     """The GNU Compiler Collection includes front ends for C, C++,
@@ -47,24 +49,33 @@ class Gcc(Package):
     version('4.6.4', 'b407a3d1480c11667f293bfb1f17d1a4')
     version('4.5.4', '27e459c2566b8209ab064570e1b378f7')
 
-    variant('gold', default=True, description="Build the gold linker plugin for ld-based LTO")
+    variant('binutils', default=sys.platform != 'darwin',
+        description="Build via binutils")
+    variant('gold', default=sys.platform != 'darwin',
+        description="Build the gold linker plugin for ld-based LTO")
 
     depends_on("mpfr")
     depends_on("gmp")
     depends_on("mpc", when='@4.5:')
     depends_on("isl", when='@5.0:')
-    depends_on("binutils~libiberty", when='~gold')
-    depends_on("binutils~libiberty+gold", when='+gold')
+    depends_on("binutils~libiberty", when='+binutils ~gold')
+    depends_on("binutils~libiberty+gold", when='+binutils +gold')
 
+    # TODO: integrate these libraries.
     #depends_on("ppl")
     #depends_on("cloog")
+    if sys.platform == 'darwin':
+        patch('darwin/gcc-4.9.patch1', when='@4.9.3')
+        patch('darwin/gcc-4.9.patch2', when='@4.9.3')
 
     def install(self, spec, prefix):
         # libjava/configure needs a minor fix to install into spack paths.
-        filter_file(r"'@.*@'", "'@[[:alnum:]]*@'", 'libjava/configure', string=True)
+        filter_file(r"'@.*@'", "'@[[:alnum:]]*@'", 'libjava/configure',
+            string=True)
 
         enabled_languages = set(('c', 'c++', 'fortran', 'java', 'objc'))
-        if spec.satisfies("@4.7.1:"):
+
+        if spec.satisfies("@4.7.1:") and sys.platform != 'darwin':
             enabled_languages.add('go')
 
         # Generic options to compile GCC
@@ -72,32 +83,40 @@ def install(self, spec, prefix):
                    "--libdir=%s/lib64" % prefix,
                    "--disable-multilib",
                    "--enable-languages=" + ','.join(enabled_languages),
-                   "--with-mpc=%s"    % spec['mpc'].prefix,
-                   "--with-mpfr=%s"   % spec['mpfr'].prefix,
-                   "--with-gmp=%s"    % spec['gmp'].prefix,
+                   "--with-mpc=%s" % spec['mpc'].prefix,
+                   "--with-mpfr=%s" % spec['mpfr'].prefix,
+                   "--with-gmp=%s" % spec['gmp'].prefix,
                    "--enable-lto",
-                   "--with-gnu-ld",
-                   "--with-gnu-as",
                    "--with-quad"]
         # Binutils
-        static_bootstrap_flags = "-static-libstdc++ -static-libgcc"
-        binutils_options = ["--with-sysroot=/",
-                            "--with-stage1-ldflags=%s %s" % (self.rpath_args, static_bootstrap_flags),
-                            "--with-boot-ldflags=%s %s"   % (self.rpath_args, static_bootstrap_flags),
-                            "--with-ld=%s/bin/ld" % spec['binutils'].prefix,
-                            "--with-as=%s/bin/as" % spec['binutils'].prefix]
-        options.extend(binutils_options)
+        if spec.satisfies('+binutils'):
+            static_bootstrap_flags = "-static-libstdc++ -static-libgcc"
+            binutils_options = ["--with-sysroot=/",
+                                "--with-stage1-ldflags=%s %s" %
+                                    (self.rpath_args, static_bootstrap_flags),
+                                "--with-boot-ldflags=%s %s" %
+                                    (self.rpath_args, static_bootstrap_flags),
+                                "--with-gnu-ld",
+                                "--with-ld=%s/bin/ld" % spec['binutils'].prefix,
+                                "--with-gnu-as",
+                                "--with-as=%s/bin/as" % spec['binutils'].prefix]
+            options.extend(binutils_options)
         # Isl
         if 'isl' in spec:
             isl_options = ["--with-isl=%s" % spec['isl'].prefix]
             options.extend(isl_options)
 
+        if sys.platform == 'darwin' :
+            darwin_options = [ "--with-build-config=bootstrap-debug" ]
+            options.extend(darwin_options)
+
         build_dir = join_path(self.stage.path, 'spack-build')
         configure = Executable( join_path(self.stage.source_path, 'configure') )
         with working_dir(build_dir, create=True):
             # Rest of install is straightforward.
             configure(*options)
-            make()
+            if sys.platform == 'darwin' : make("bootstrap")
+            else: make()
             make("install")
 
         self.write_rpath_specs()
@@ -114,7 +133,8 @@ def write_rpath_specs(self):
         """Generate a spec file so the linker adds a rpath to the libs
            the compiler used to build the executable."""
         if not self.spec_dir:
-            tty.warn("Could not install specs for %s." % self.spec.format('$_$@'))
+            tty.warn("Could not install specs for %s." %
+                self.spec.format('$_$@'))
             return
 
         gcc = Executable(join_path(self.prefix.bin, 'gcc'))
@@ -124,5 +144,6 @@ def write_rpath_specs(self):
             for line in lines:
                 out.write(line + "\n")
                 if line.startswith("*link:"):
-                    out.write("-rpath %s/lib:%s/lib64 \\\n"% (self.prefix, self.prefix))
+                    out.write("-rpath %s/lib:%s/lib64 \\\n" %
+                        (self.prefix, self.prefix))
         set_install_permissions(specs_file)
diff --git a/var/spack/repos/builtin/packages/gdal/package.py b/var/spack/repos/builtin/packages/gdal/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..4f1f1ec2dd1eaa348ee985809cb4e85c26913793
--- /dev/null
+++ b/var/spack/repos/builtin/packages/gdal/package.py
@@ -0,0 +1,69 @@
+from spack import *
+
+class Gdal(Package):
+    """
+    GDAL is a translator library for raster and vector geospatial
+    data formats that is released under an X/MIT style Open Source
+    license by the Open Source Geospatial Foundation. As a library,
+    it presents a single raster abstract data model and vector
+    abstract data model to the calling application for all supported
+    formats. It also comes with a variety of useful command line
+    utilities for data translation and processing
+    """
+
+    homepage   = "http://www.gdal.org/"
+    url        = "http://download.osgeo.org/gdal/2.0.2/gdal-2.0.2.tar.gz"
+    list_url   = "http://download.osgeo.org/gdal/"
+    list_depth = 2
+
+    version('2.0.2', '573865f3f59ba7b4f8f4cddf223b52a5')
+
+    extends('python')
+
+    variant('hdf5', default=False, description='Enable HDF5 support')
+    variant('hdf', default=False, description='Enable HDF4 support')
+    variant('openjpeg', default=False, description='Enable JPEG2000 support')
+    variant('geos', default=False, description='Enable GEOS support')
+    variant('kea', default=False, description='Enable KEA support')
+    variant('netcdf', default=False, description='Enable netcdf support')
+
+    depends_on('swig')
+    depends_on("hdf5", when='+hdf5')
+    depends_on("hdf", when='+hdf')
+    depends_on("openjpeg", when='+openjpeg')
+    depends_on("geos", when='+geos')
+    depends_on("kealib", when='+kea')
+    depends_on("netcdf", when='+netcdf')
+    depends_on("libtiff")
+    depends_on("libpng")
+    depends_on("zlib")
+    depends_on("proj")
+    depends_on("py-numpy")
+
+    parallel = False
+
+    def install(self, spec, prefix):
+        args = []
+        args.append("--prefix=%s" % prefix)
+        args.append("--with-liblzma=yes")
+        args.append("--with-zlib=%s" % spec['zlib'].prefix)
+        args.append("--with-python=%s" % spec['python'].prefix.bin + "/python")
+        args.append("--without-libtool")
+
+        if '+geos' in spec:
+            args.append('--with-geos=yes')
+        if '+hdf' in spec:
+            args.append('--with-hdf4=%s' % spec['hdf'].prefix)
+        if '+hdf5' in spec:
+            args.append('--with-hdf5=%s' % spec['hdf5'].prefix)
+        if '+openjpeg' in spec:
+            args.append('--with-openjpeg=%s' % spec['openjpeg'].prefix)
+        if '+kea' in spec:
+            args.append('--with-kea=yes')
+        if '+netcdf' in spec:
+            args.append('--with-netcdf=%s' % spec['netcdf'].prefix)
+
+        configure(*args)
+
+        make()
+        make("install")
diff --git a/var/spack/repos/builtin/packages/hypre/package.py b/var/spack/repos/builtin/packages/hypre/package.py
index 0e9955329330c0d5fa1325c37514cf8847871988..4b915daa6877fc3cbc6b84ab9d300fb1b95321a3 100644
--- a/var/spack/repos/builtin/packages/hypre/package.py
+++ b/var/spack/repos/builtin/packages/hypre/package.py
@@ -42,6 +42,9 @@ def install(self, spec, prefix):
 
         if '~internal-superlu' in self.spec:
             configure_args.append("--without-superlu")
+            # MLI and FEI do not build without superlu on Linux
+            configure_args.append("--without-mli")
+            configure_args.append("--without-fei")
 
         # Hypre's source is staged under ./src so we'll have to manually
         # cd into it.
diff --git a/var/spack/repos/builtin/packages/kealib/package.py b/var/spack/repos/builtin/packages/kealib/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..475d21e1d8059e0db02b67146dcf48004734f6c9
--- /dev/null
+++ b/var/spack/repos/builtin/packages/kealib/package.py
@@ -0,0 +1,35 @@
+from spack import *
+
+class Kealib(Package):
+    """An HDF5 Based Raster File Format
+    
+    KEALib provides an implementation of the GDAL data model.
+    The format supports raster attribute tables, image pyramids,
+    meta-data and in-built statistics while also handling very
+    large files and compression throughout.
+    
+    Based on the HDF5 standard, it also provides a base from which
+    other formats can be derived and is a good choice for long
+    term data archiving. An independent software library (libkea)
+    provides complete access to the KEA image format and a GDAL
+    driver allowing KEA images to be used from any GDAL supported software.
+    
+    Development work on this project has been funded by Landcare Research.
+    """
+    homepage = "http://kealib.org/"
+    url      = "https://bitbucket.org/chchrsc/kealib/get/kealib-1.4.5.tar.gz"
+
+    version('1.4.5', '112e9c42d980b2d2987a3c15d0833a5d')
+
+    depends_on("hdf5")
+
+    def install(self, spec, prefix):
+        with working_dir('trunk', create=False):
+            cmake_args = []
+            cmake_args.append("-DCMAKE_INSTALL_PREFIX=%s" % prefix)
+            cmake_args.append("-DHDF5_INCLUDE_DIR=%s" % spec['hdf5'].prefix.include)
+            cmake_args.append("-DHDF5_LIB_PATH=%s" % spec['hdf5'].prefix.lib)
+            cmake('.', *cmake_args)
+
+            make()
+            make("install")
diff --git a/var/spack/repos/builtin/packages/mumps/Makefile.inc b/var/spack/repos/builtin/packages/mumps/Makefile.inc
index 2e6a041878ce35d1344fa0cf759dff0435621dd8..22d8f5518a52ab2ad6697b25d025b782c21b868e 100644
--- a/var/spack/repos/builtin/packages/mumps/Makefile.inc
+++ b/var/spack/repos/builtin/packages/mumps/Makefile.inc
@@ -8,12 +8,9 @@ IORDERINGSF = $(ISCOTCH)
 IORDERINGSC = $(IMETIS) $(IPORD) $(ISCOTCH)
 
 PLAT    =
-LIBEXT  = .a
-OUTC    = -o 
+OUTC    = -o
 OUTF    = -o
 RM = /bin/rm -f
-AR = ar vr 
-RANLIB = ranlib
 
 INCSEQ  = -I$(topdir)/libseq
 LIBSEQ  = -L$(topdir)/libseq -lmpiseq
diff --git a/var/spack/repos/builtin/packages/mumps/package.py b/var/spack/repos/builtin/packages/mumps/package.py
index 5a254dfd00e45c82af2b6a15486ba13f8988eb6a..26440ab7c810d517af6cb8ce07e1e2492d9148d6 100644
--- a/var/spack/repos/builtin/packages/mumps/package.py
+++ b/var/spack/repos/builtin/packages/mumps/package.py
@@ -1,6 +1,5 @@
 from spack import *
-import os
-
+import os, sys
 
 class Mumps(Package):
     """MUMPS: a MUltifrontal Massively Parallel sparse direct Solver"""
@@ -19,6 +18,7 @@ class Mumps(Package):
     variant('float', default=True, description='Activate the compilation of smumps')
     variant('complex', default=True, description='Activate the compilation of cmumps and/or zmumps')
     variant('idx64', default=False, description='Use int64_t/integer*8 as default index type')
+    variant('shared', default=True, description='Build shared libraries')
 
 
     depends_on('scotch + esmumps', when='~ptscotch+scotch')
@@ -70,6 +70,9 @@ def write_makefile_inc(self):
 
         makefile_conf.append("ORDERINGSF = %s" % (' '.join(orderings)))
 
+        # when building shared libs need -fPIC, otherwise
+        # /usr/bin/ld: graph.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
+        fpic = '-fPIC' if '+shared' in self.spec else ''
         # TODO: test this part, it needs a full blas, scalapack and
         # partitionning environment with 64bit integers
         if '+idx64' in self.spec:
@@ -77,14 +80,14 @@ def write_makefile_inc(self):
                 # the fortran compilation flags most probably are
                 # working only for intel and gnu compilers this is
                 # perhaps something the compiler should provide
-                ['OPTF    = -O  -DALLOW_NON_INIT %s' % '-fdefault-integer-8' if self.compiler.name == "gcc" else '-i8',
-                 'OPTL    = -O ',
-                 'OPTC    = -O -DINTSIZE64'])
+                ['OPTF    = %s -O  -DALLOW_NON_INIT %s' % (fpic,'-fdefault-integer-8' if self.compiler.name == "gcc" else '-i8'),
+                 'OPTL    = %s -O ' % fpic,
+                 'OPTC    = %s -O -DINTSIZE64' % fpic])
         else:
             makefile_conf.extend(
-                ['OPTF    = -O  -DALLOW_NON_INIT',
-                 'OPTL    = -O ',
-                 'OPTC    = -O '])
+                ['OPTF    = %s -O  -DALLOW_NON_INIT' % fpic,
+                 'OPTL    = %s -O ' % fpic,
+                 'OPTC    = %s -O ' % fpic])
 
 
         if '+mpi' in self.spec:
@@ -105,6 +108,27 @@ def write_makefile_inc(self):
         # compiler possible values are -DAdd_, -DAdd__ and/or -DUPPER
         makefile_conf.append("CDEFS   = -DAdd_")
 
+        if '+shared' in self.spec:
+            if sys.platform == 'darwin':
+                # Building dylibs with mpif90 causes segfaults on 10.8 and 10.10. Use gfortran. (Homebrew)
+                makefile_conf.extend([
+                    'LIBEXT=.dylib',
+                    'AR=%s -dynamiclib -Wl,-install_name -Wl,%s/$(notdir $@) -undefined dynamic_lookup -o ' % (os.environ['FC'],prefix.lib),
+                    'RANLIB=echo'
+                ])
+            else:
+                makefile_conf.extend([
+                    'LIBEXT=.so',
+                    'AR=$(FL) -shared -Wl,-soname -Wl,%s/$(notdir $@) -o' % prefix.lib,
+                    'RANLIB=echo'
+                ])
+        else:
+            makefile_conf.extend([
+                'LIBEXT  = .a',
+                'AR = ar vr',
+                'RANLIB = ranlib'
+            ])
+
 
         makefile_inc_template = join_path(os.path.dirname(self.module.__file__),
                                           'Makefile.inc')
@@ -121,7 +145,7 @@ def write_makefile_inc(self):
     def install(self, spec, prefix):
         make_libs = []
 
-        # the coice to compile ?examples is to have kind of a sanity
+        # the choice to compile ?examples is to have kind of a sanity
         # check on the libraries generated.
         if '+float' in spec:
             make_libs.append('sexamples')
@@ -135,10 +159,24 @@ def install(self, spec, prefix):
 
         self.write_makefile_inc()
 
-        # Build fails in parallel, at least on OS-X
+        # Build fails in parallel
         make(*make_libs, parallel=False)
 
         install_tree('lib', prefix.lib)
         install_tree('include', prefix.include)
         if '~mpi' in spec:
-            install('libseq/libmpiseq.a', prefix.lib)
+            lib_dsuffix = '.dylib' if sys.platform == 'darwin' else '.so'
+            lib_suffix = lib_dsuffix if '+shared' in spec else '.a'
+            install('libseq/libmpiseq%s' % lib_suffix, prefix.lib)
+
+        # FIXME: extend the tests to mpirun -np 2 (or alike) when build with MPI
+        # FIXME: use something like numdiff to compare blessed output with the current
+        with working_dir('examples'):
+            if '+float' in spec:
+                os.system('./ssimpletest < input_simpletest_real')
+                if '+complex' in spec:
+                    os.system('./csimpletest < input_simpletest_real')
+            if '+double' in spec:
+                os.system('./dsimpletest < input_simpletest_real')
+                if '+complex' in spec:
+                    os.system('./zsimpletest < input_simpletest_cmplx')
diff --git a/var/spack/repos/builtin/packages/muparser/package.py b/var/spack/repos/builtin/packages/muparser/package.py
index a1a9ff90e5370f949588a2e7fea2908987c35677..19ca8ce28744a84f7364634453897496342be435 100644
--- a/var/spack/repos/builtin/packages/muparser/package.py
+++ b/var/spack/repos/builtin/packages/muparser/package.py
@@ -14,5 +14,5 @@ def install(self, spec, prefix):
 
         configure(*options)
 
-        make()
+        make(parallel=False)
         make("install")
diff --git a/var/spack/repos/builtin/packages/openjpeg/package.py b/var/spack/repos/builtin/packages/openjpeg/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..afec197d11242ad8076d872f8032c0e7376943c4
--- /dev/null
+++ b/var/spack/repos/builtin/packages/openjpeg/package.py
@@ -0,0 +1,26 @@
+from spack import *
+
+class Openjpeg(Package):
+    """
+    OpenJPEG is an open-source JPEG 2000 codec written in C language.
+    It has been developed in order to promote the use of JPEG 2000, a
+    still-image compression standard from the Joint Photographic
+    Experts Group (JPEG).
+    Since April 2015, it is officially recognized by ISO/IEC and
+    ITU-T as a JPEG 2000 Reference Software.
+    """
+    homepage = "https://github.com/uclouvain/openjpeg"
+    url      = "https://github.com/uclouvain/openjpeg/archive/version.2.1.tar.gz"
+
+    version('2.1'  , '3e1c451c087f8462955426da38aa3b3d')
+    version('2.0.1', '105876ed43ff7dbb2f90b41b5a43cfa5')
+    version('2.0'  , 'cdf266530fee8af87454f15feb619609')
+    version('1.5.2', '545f98923430369a6b046ef3632ef95c')
+    version('1.5.1', 'd774e4b5a0db5f0f171c4fc0aabfa14e')
+
+
+    def install(self, spec, prefix):
+        cmake('.', *std_cmake_args)
+
+        make()
+        make("install")
diff --git a/var/spack/repos/builtin/packages/py-libxml2/package.py b/var/spack/repos/builtin/packages/py-libxml2/package.py
deleted file mode 100644
index 59005428e4d1c9bcc520b0da5e8a107dee5573d0..0000000000000000000000000000000000000000
--- a/var/spack/repos/builtin/packages/py-libxml2/package.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from spack import *
-
-class PyLibxml2(Package):
-    """A Python wrapper around libxml2."""
-    homepage = "https://xmlsoft.org/python.html"
-    url      = "ftp://xmlsoft.org/libxml2/python/libxml2-python-2.6.21.tar.gz"
-
-    version('2.6.21', '229dd2b3d110a77defeeaa73af83f7f3')
-
-    extends('python')
-    depends_on('libxml2')
-    depends_on('libxslt')
-
-    def install(self, spec, prefix):
-        python('setup.py', 'install', '--prefix=%s' % prefix)
diff --git a/var/spack/repos/builtin/packages/py-tuiview/package.py b/var/spack/repos/builtin/packages/py-tuiview/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..984b4196b1989c8f3853cf9b0f35260c26ec4954
--- /dev/null
+++ b/var/spack/repos/builtin/packages/py-tuiview/package.py
@@ -0,0 +1,19 @@
+from spack import *
+
+class PyTuiview(Package):
+    """
+       TuiView is a lightweight raster GIS with powerful raster attribute
+       table manipulation abilities.
+    """
+    homepage = "https://bitbucket.org/chchrsc/tuiview"
+    url      = "https://bitbucket.org/chchrsc/tuiview/get/tuiview-1.1.7.tar.gz"
+
+    version('1.1.7', '4b3b38a820cc239c8ab4a181ac5d4c30')
+
+    extends("python")
+    depends_on("py-pyqt")
+    depends_on("py-numpy")
+    depends_on("gdal")
+
+    def install(self, spec, prefix):
+        python('setup.py', 'install', '--prefix=%s' % prefix)