diff --git a/var/spack/repos/builtin/packages/flang/package.py b/var/spack/repos/builtin/packages/flang/package.py
index d716ecaa067c7116b72b67132ee77ae2e6fbf7cc..73a016ad7fdd0942c63660a1cfc90754c2e2ee17 100644
--- a/var/spack/repos/builtin/packages/flang/package.py
+++ b/var/spack/repos/builtin/packages/flang/package.py
@@ -36,16 +36,23 @@ class Flang(CMakePackage):
     version('20180319', 'e659bad83b791f90af2c5cd672864669')
 
     depends_on(
-            "llvm+clang@4.0.1,5.0.0",
+            "llvm+clang@4.0.1,5.0.0,6.0.0",
         patches=[
             patch('https://github.com/llvm-mirror/clang/pull/33.diff',
                       sha256='e46d7ab305e5e95c51f4656d9b52058143cd85d859b312b3c80e93a02d54b4a5',
                       when='@4.0.1', level=1, working_dir='tools/clang'),
             patch('https://github.com/llvm-mirror/clang/pull/35.diff',
                       sha256='7f39555783993f78b75c380ca5ef167c1d8b88cc75c6542f6c94e0b6acfb7c5d',
-                      when='@5.0.0', level=1, working_dir='tools/clang')
+                      when='@5.0.0', level=1, working_dir='tools/clang'),
+            patch('https://github.com/llvm-mirror/llvm/pull/56.diff',
+                      sha256='2ee155aa1017766cdae3a860050d82ed48961a2f88bcef760d4922ff25ce381e',
+                      when='@6.0.0', level=1),
+            patch('https://github.com/llvm-mirror/clang/pull/40.diff',
+                      sha256='5021f2ea54e957eb1c712f9e9a87b3dc33616ebd2e84735b6735f788fd2c45e9',
+                      when='@6.0.0', level=1, working_dir='tools/clang')
         ]
     )
+    depends_on("pgmath@develop", when="@develop")
 
     def cmake_args(self):
         options = [
@@ -72,17 +79,30 @@ def post_install(self):
         flang = os.path.join(self.spec.prefix.bin, 'flang')
         with open(flang, 'w') as out:
             out.write('#!/bin/bash\n')
-            out.write(
-                '{0} -I{1} -L{2} {3}{4} -B{5} "$@"\n'.format(
-                    os.path.join(self.spec['llvm'].prefix.bin, 'flang'),
-                    self.prefix.include, self.prefix.lib,
-                    self.compiler.fc_rpath_arg, self.prefix.lib,
-                    self.spec.prefix.bin))
+            if '@develop' in self.spec:
+                out.write(
+                    '{0} -I{1} -L{2} -L{3} {4}{5} {6}{7} -B{8} "$@"\n'.format(
+                        self.spec['llvm'].prefix.bin.flang,
+                        self.prefix.include, self.prefix.lib,
+                        self.spec['pgmath'].prefix.lib,
+                        self.compiler.fc_rpath_arg, self.prefix.lib,
+                        self.compiler.fc_rpath_arg,
+                        self.spec['pgmath'].prefix.lib,
+                        self.spec.prefix.bin))
+            else:
+                out.write(
+                    '{0} -I{1} -L{2} {3}{4} -B{5} "$@"\n'.format(
+                        self.spec['llvm'].prefix.bin.flang,
+                        self.prefix.include, self.prefix.lib,
+                        self.compiler.fc_rpath_arg, self.prefix.lib,
+                        self.spec.prefix.bin))
             out.close()
         chmod = which('chmod')
         chmod('+x', flang)
 
     def setup_environment(self, spack_env, run_env):
+        # to find llvm's libc++.so
+        spack_env.set('LD_LIBRARY_PATH', self.spec['llvm'].prefix.lib)
         run_env.set('FC', join_path(self.spec.prefix.bin, 'flang'))
         run_env.set('F77', join_path(self.spec.prefix.bin, 'flang'))
         run_env.set('F90', join_path(self.spec.prefix.bin, 'flang'))
diff --git a/var/spack/repos/builtin/packages/pgmath/package.py b/var/spack/repos/builtin/packages/pgmath/package.py
new file mode 100644
index 0000000000000000000000000000000000000000..64742813db6fa1087288f63cbce3f4640e4d522e
--- /dev/null
+++ b/var/spack/repos/builtin/packages/pgmath/package.py
@@ -0,0 +1,37 @@
+##############################################################################
+# Copyright (c) 2018, Los Alamos National Security, LLC
+# Produced at the Los Alamos National Laboratory.
+#
+# This file is part of Spack.
+# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
+# LLNL-CODE-647188
+#
+# For details, see https://github.com/spack/spack
+# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License (as
+# published by the Free Software Foundation) version 2.1, February 1999.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
+# conditions of the GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##############################################################################
+
+from spack import *
+
+
+class Pgmath(CMakePackage):
+    """Flang's math library"""
+    homepage = "https://github.com/flang-compiler/flang"
+    url      = "https://github.com/flang-compiler/flang/archive/pgmath_20180319.tar.gz"
+
+    version('develop', git='https://github.com/flang-compiler/flang', branch='master')
+
+    conflicts("%gcc@:7.1.9999")
+    root_cmakelists_dir = 'runtime/libpgmath'