diff --git a/legacyCompile/README.md b/legacyCompile/README.md
index 791f64900ae3d0765b3d2f8ad24a830f8af1e181..e1c1a20491cf8aaf789f0a2038657b92e4441236 100644
--- a/legacyCompile/README.md
+++ b/legacyCompile/README.md
@@ -34,6 +34,7 @@ and package versions, it may not work for all users and environments.
      * MesaLib-x.y.z files (replace by mesa-x.y.z)
      * llvm-x.y.z.src TarFile (remove .src part in filename and in subdir)
      * cfe-x.y.z.src TarFile must be moved to llvm-x.y.z/tools/clang
+     * openmp-x.y.z.src TarFile must be moved to llvm-x.y.z/tools/openmp
      * ParaView-v* TarFile (remove -source part in filename and in subdir)
         Note: when unpacking ParaView, it may create a subdir with suffix
         -source. Please remove this suffix as well and tar the package
@@ -52,18 +53,17 @@ and package versions, it may not work for all users and environments.
 
 ---
 
-## Script Configuration
+## Configuration
 
 Users need to define the desired packages and versions to use for the
 OpenFOAM compilation. The packages and versions need to be input under the
-paragraph `USER INPUT (2)`, stating whether the default version is to be
+section `[software]`, stating whether the default version is to be
 used, or the user needs to use a different version. If both entries have
 information, the user-preference will prevail. In any case, a suitable
 tar/zip file with packageName-versionNumber needs to be placed under subdir
 `packages/`.  The value `ompiType` refers to the openmpi type (system|third).
 
-    # USER INPUT (2)
-    # ~~~~~~~~~~~~~~
+    [software]
     # Preferred software versions etc. Use 'third' for ThirdParty.
     #---------------------+-------------------+-------------------+
     #   package           | default           | user-preference   |
@@ -95,23 +95,21 @@ tar/zip file with packageName-versionNumber needs to be placed under subdir
 
 ## Usage
 
-    ./legacyCompile [OPTION] OPERATION [...OPERATION]
+    ./legacyCompile [OPTIONS] OPERATION [...OPERATION] configFile
+    options:
+      -purge                Purge old directories before unpacking (CAUTION)
+      -int32  | -int64      Label width
+      -SP     | -DP         Precision
+      -sigfpe | -no-sigfpe  Activate/deactivate FOAM_SIGFPE handling
+      -help
+
     operations:
       -unpack           Unpack sources, configure
       -third            Compile ThirdParty
       -foam             Compile OpenFOAM
       -list             List configured versions only
-      -all              Alias for  -unpack -third -foam
-      -rebuild          Alias for  -third -foam
-
-    options:
-      -purge            Purge old directories before unpacking (CAUTION)
-      -help
-
-    Config options:
-      -int32  | -int64      Label width (default: 32)
-      -SP     | -DP         Precision (default: DP)
-      -sigfpe |-no-sigfpe   Activate/deactivate FOAM_SIGFPE handling
+      -all              Alias for -unpack -third -foam
+      -rebuild          Alias for -third -foam
 
 
 The script contains the three essential operations:
@@ -127,43 +125,43 @@ unpack stage).
 
 * To compile first time (from scratch) with default label size and precision:
 
-    ./legacyCompile -all
+    ./legacyCompile -all configFile
 
 * To repeat the same, **overwriting** any existing installation:
 
-    ./legacyCompile -all -purge
+    ./legacyCompile -all -purge configFile
 
 
 * To unpack all packages and configure some OpenFOAM settings without
   compiling:
 
-    ./legacyCompile -unpack
-    ./legacyCompile -unpack -purge   # caution: removes existing installation
+    ./legacyCompile -unpack  configFile
+    ./legacyCompile -unpack -purge configFile # Caution: removes existing installation
 
 
 To compile with 64 bit label size in single precission:
 
-    ./legacyCompile -all -int64 -SP
+    ./legacyCompile -all -int64 -SP configFile
 
 
 If you change your third-party package selections or the preferred
 configuration (SP, DP etc), you will need the `-unpack` operation,
 which also includes some configuration operations.
 
-    ./legacyCompile -unpack
+    ./legacyCompile -unpack configFile
 
 
 To (re)compile ThirdParty and OpenFOAM individually:
 
-    ./legacyCompile -unpack -third -purge
+    ./legacyCompile -unpack -third -purge configFile
     (to compile ThirdParty from scratch)
 
-    ./legacyCompile -foam
+    ./legacyCompile -foam configFile
     (to compile OpenFOAM from existing ThirdParty)
 
 To compile with 32 bit label size in single precission:
 
-    ./legacyCompile -all -int64 -SP
+    ./legacyCompile -all -int64 -SP configFile
 
 ---
 
@@ -183,4 +181,4 @@ building Clang), you should remove the corrsponding logfile(s) before
 recompiling with the '-unpack -third` options.
 
 ---
-2016-12-21
+2017-06-29
diff --git a/legacyCompile/legacyCompile b/legacyCompile/legacyCompile
index 62556700d3a2b073e6359e14dffce9a0d1f160f1..dd54c5848374b0f802ab178fe2909fcdfb2be65e 100755
--- a/legacyCompile/legacyCompile
+++ b/legacyCompile/legacyCompile
@@ -7,220 +7,50 @@
 #     Simple convenience script to install OpenFOAM on older systems.
 #     Use ThirdParty compiler, but retain most default software versions.
 #
-#     Adjust the relevant USER INPUT sections below prior to running.
-#     - INPUT (1) has the top-level packaging
-#     - INPUT (2) has version preferences
+#     [package]             - Top-level package information
+#     [arch]                - Architecture
+#     [software]            - Preferred software versions
 #
 #     Input Directory:
-#     - ./packages              # Contains the tar files
+#     - ./packages          - Contains the tar files
 #
 #     Output Directories
-#     - ./install               # The compiled installation
-#     - ./log                   # Log files from the build scripts
+#     - ./install           - The compiled installation
+#     - ./log               - Log files from the build scripts
 #
 # License
 #    GPL v3 or later
-#    Copyright (C) 2016 Roger Almenar, ESI GmbH.
+#    Copyright (C) 2016-2017 Roger Almenar, ESI GmbH.
 #------------------------------------------------------------------------------
-
-# ~~~~~~~~~~~~~~
-# USER INPUT (1)
-# ~~~~~~~~~~~~~~
-FoamVersion=v1612+
-OFdirName=OpenFOAM-$FoamVersion
-TPdirName=ThirdParty-$FoamVersion
-
-# Source package names may differ from the directory names above
-# uncomment and change if needed)
-# OFsource=OpenFOAM-plus
-# TPsource=ThirdParty-plus
-
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-# User input continues below at USER INPUT (2)
-# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-#------------------------------------------------------------------------------
-_preferences()
-{
-    # 'package default version' lines=>packageDefault, packageVersion variable
-    local line pkg def val
-    while read -r line
-    do
-        set -- $line; pkg="$1"; def="$2"; val="$3"
-        if [ "$pkg" = "${pkg#[a-z]}" ]
-        then
-            continue # Packages must start with lowercase
-        elif [ $# -eq 2 -o $# -eq 3 ]
-        then
-            val="${3:-$def}"  # Use default if not specified
-            eval "${pkg}Default=\"\$def\""; eval "${pkg}Version=\"\$val\""
-        else
-            echo "Bad input while setting versions"; echo "   $line"
-            exit 1
-        fi
-    done
-}
-_preferences <<-USER_INPUT
-# ~~~~~~~~~~~~~~
-# USER INPUT (2)
-# ~~~~~~~~~~~~~~
-# Preferred software versions etc. Use 'third' for ThirdParty.
-#---------------------+-------------------+-------------------+
-#   package           | default           | user-preference   |
-#---------------------+-------------------+-------------------+
-    boost               boost_1_62_0
-    cgal                CGAL-4.9
-    fftw                fftw-3.3.5
-    openmpi             openmpi-1.10.4
-    scotch              scotch_6.0.3
-    paraview            ParaView-5.0.1
-    cmake               cmake-system        cmake-3.5.2
-    vtk                 none                VTK-7.1.0
-    mesa                none                mesa-13.0.1
-    qt                  qt-system           qt-4.8.7
-    llvm                llvm-3.7.0
-    gcc                 system              gcc-4.8.5
-    gmp                 system              gmp-6.1.1
-    mpfr                system              mpfr-3.1.5
-    mpc                 system              mpc-1.0.3
-    label               32
-    precision           DP
-
-    ompiType            system              third
-    compilerType        system              third
-    compiler            Gcc                 Clang
-# -----------------------------------------------------------------------------
-USER_INPUT
-#
-# NO NORMAL EDITING BELOW THIS LINE
-#------------------------------------------------------------------------------
-
 # Local directories
 INSTALL_DIR=$PWD/install
 PACKAGE_DIR=$PWD/packages
 LOGFILE_DIR=$PWD/log
 
-# Special treatment for gcc sub-components (needs rethinking)
-case "$compilerVersion" in
-Gcc | Gcc48)
-    gccVersion=gcc-4.8.5    # match value in config.sh/compiler
-    ;;
-Gcc49)
-    gccVersion=gcc-4.9.3    # match value in config.sh/compiler
-    ;;
-Gcc62)
-    gccVersion=gcc-6.2.0    # match value in config.sh/compiler
-    ;;
-Gcc*)
-    echo "Error: unconfigured gcc version '$compilerVersion'"
-    exit 1 # Really exit, since this must be an input error
-    ;;
-esac
-# -----------------------------------------------------------------------------
-# NO FURTHER EDITING BELOW THIS LINE
-#------------------------------------------------------------------------------
-
-# Name of qt source directory is a fixed value
-qtSource="qt-everywhere-opensource-src-${qtVersion##*-}"
-
-# Change 'system' into 'gmp-system' etc
-for check in gcc gmp mpfr mpc
-do
-    if eval test "\$${check}Version = system"
-    then
-        eval "${check}Version=${check}-system"
-        eval "${check}Default=${check}-system"
-    fi
-done
-
-# No gcc/gmp/mpfr/mpc for system compilers or non-Gcc compilers
-case "$compilerTypeVersion:$compilerVersion" in
-    third:Gcc*)
-        ;;
-    third:Clang* | system:Clang* | system:Gcc | system:Icc | system:*)
-        # System, or known non-gcc
-        for check in gcc gmp mpfr mpc
-        do
-            eval "unset ${check}Version ${check}Default"
-        done
-        ;;
-    *)
-        echo "Error: unknown $compilerTypeVersion-compiler '$compilerVersion'"
-        exit 1
-        ;;
-esac
-
-# Separator lines
-_line()
-{
-    echo  " ====================  ====================  ===================="
-}
-
-# Various formatting for -list output
-# formatted print
-_fmt2()
-{
-    local arg1="${1:-????}"
-    local arg2="${2:-undefined}"
-    printf "  %-20s  %-20s\n"  "$arg1"  "$arg2"
-}
-
-# formatted print
-# name version default [-nocheck]
-_fmt3()
-{
-    local what="${1:-????}"
-    local arg1="${2:-undefined}"
-    local arg2="${3:-undefined}"
-
-    if [ "$#" -eq 2 ]
-    then
-        _fmt2 "$what"  "$arg1"
-    elif [ "$#" -eq 3 -a "$arg1" = "$arg2" ]
-    then
-        _fmt2 "$what" "$arg1"
-    else
-        printf "  %-20s  %-20s  %-20s\n"  "$what"  "$arg1"  "$arg2"
-    fi
-}
-
-# input:  'package'
-# output: 'package' packageDefault packageVersion
-_fmtDefVer()
-{
-    local pkg="$1"
-    eval local "def=\$${pkg}Default"
-    eval local "val=\$${pkg}Version"
-
-    _fmt3 "$pkg"  "$def"  "$val"
-}
-
 #------------------------------------------------------------------------------
 usage() {
     exec 1>&2
     while [ "$#" -ge 1 ]; do echo "$1"; shift; done
     cat<<USAGE
 
-usage: ${0##*/} [OPTION] OPERATION [...OPERATION]
+usage: ${0##*/} [OPTIONS] OPERATION [...OPERATION] configFile
+options:
+  -purge                Purge old directories before unpacking (CAUTION)
+  -int32 | -int64       Label width
+  -SP | -DP             Precision
+  -sigfpe | -no-sigfpe  Activate/deactivate FOAM_SIGFPE handling [defunct]
+  -help
+
 operations:
   -unpack           Unpack sources, configure
   -third            Compile ThirdParty
   -foam             Compile OpenFOAM
   -list             List configured versions only
-  -all              Alias for  -unpack -third -foam
-  -rebuild          Alias for  -third -foam
-
-options:
-  -purge            Purge old directories before unpacking (CAUTION)
-  -help
-
-Config options:
-  -int32  | -int64      Label width (default: ${labelDefault:-?})
-  -SP     | -DP         Precision (default: ${precisionDefault:-?})
-  -sigfpe |-no-sigfpe   Activate/deactivate FOAM_SIGFPE handling
-
+  -all              Alias for -unpack -third -foam
+  -rebuild          Alias for -third -foam
 
 =========================
-Make and install $OFdirName / $TPdirName
+Make and install OpenFOAM/ThirdParty
       package = $PWD/packages
       logdir  = $PWD/log
       install = $PWD/install
@@ -228,7 +58,7 @@ Make and install $OFdirName / $TPdirName
 USAGE
     exit 1
 }
-#------------------------------------------------------------------------------
+
 # Report error and exit
 die()
 {
@@ -240,17 +70,11 @@ die()
     exit 1
 }
 #------------------------------------------------------------------------------
-# Location of the OpenFOAM bashrc
-BASHRC_FILE=$INSTALL_DIR/$OFdirName/etc/bashrc
 
-# Various building operations
+# OpenFOAM options, various build options
+unset optLabel optPrec optVerbose optFpe configFile
 unset runLIST runUNPACK runTHIRD runFOAM purgeOLDFILES
 
-# Pre-load options
-unset optLabel optPrec optFpe
-case "$labelVersion"     in (32|64) optLabel="-int$labelVersion";; esac
-case "$precisionVersion" in (DP|SP) optPrec="-$precisionVersion";; esac
-
 # Parse options
 while [ "$#" -gt 0 ]
 do
@@ -283,6 +107,9 @@ do
     -list)
         optList=true
         ;;
+    -verbose)
+        optVerbose=true
+        ;;
 
     -int32 | -int64)
         optLabel="$1"
@@ -294,22 +121,263 @@ do
         optFpe="$1"
         ;;
 
+    --)
+        shift
+        break
+        ;;
+    -*)
+        die "unknown option: '$1'"
+        ;;
     *)
-        die "unknown option/argument: '$1'"
+        break
         ;;
     esac
     shift
 done
 
+configFile="$1"
+[ "$#" -eq 1 ] || die "expecting a config filename"
+[ -f "$configFile" ] || die "No such file: $configFile"
+
 [ -n "$runUNPACK$runTHIRD$runFOAM$optList" ] || die "No operations specified"
 
 #------------------------------------------------------------------------------
-# Set some of the architecture configuration
+# [package]
+
+# Get [config] section with these types of entries (as shell variables)
+# FoamVersion=value
+# OFdirName=value
+# TPdirName=value
+# ---------------
+
+# Extract name=value - ignore blank and comment lines
+eval $(
+sed -n \
+    -e '/^ *[;#]/d' \
+    -e '/^\[package\]/,/^\s*\[/{ /^[^ =][^ =]*\=[^ =][^ =]/p }' \
+    $configFile
+)
+
+# These must be defined
+for envar in FoamVersion OFdirName TPdirName
+do
+    if [ "$optVerbose" ]
+    then
+        eval echo "$envar=\$$envar"
+    fi
+    eval test "\$$envar" || die "variable \$$envar not set"
+done
+
+# Alternative tar file names
+: ${OFsource:=$OFdirName}
+: ${TPsource:=$TPdirName}
+
+#------------------------------------------------------------------------------
+# [arch]
+
+# Get [arch] section with these types of entries
+# label=32
+# precision=DP
+# sigfpe=false
+# ---------------
+
+# Extract name=value - ignore blank and comment lines
+values=$(
+sed -n \
+    -e '/^ *[;#]/d' \
+    -e '/^\[arch\]/,/^\s*\[/{ /^[^ =][^ =]*\=[^ =][^ =]/p }' \
+    $configFile
+)
+
+for line in $values
+do
+    case "$line" in
+    (label=32 | label=64)
+        optLabel="-int${line#*=}"
+        ;;
+    (scalar=32 | precision=SP | precision=sp)
+        optPrec="-SP"
+        ;;
+    (scalar=64 | precision=DP | precision=dp)
+        optPrec="-DP"
+        ;;
+    (sigfpe=true)
+        optFpe="-sigfpe"
+        ;;
+    (sigfpe=false)
+        optFpe="-no-sigfpe"
+        ;;
+    esac
+done
+
+# Set part of the architecture configuration
 configArch="$optLabel $optPrec $optFpe"
 
-if [ "$ompiTypeVersion" != "$ompiTypeDefault" ]
+echo "arch: $configArch"
+
+#------------------------------------------------------------------------------
+# [software]
+
+# Get [software] section with these types of entries
+# boost       boost_1_62_0
+# cmake       cmake-system    cmake-3.5.2
+# ---------------
+# Ensure that these are always defined
+for pkg in cmake qt gcc gmp mpfr mpc
+do
+    eval "${pkg}DEFAULT='${pkg}-system';${pkg}VERSION='${pkg}-system'"
+done
+
+#
+# parse 'package default version' lines
+# and transform to => packageDEFAULT, packageVERSION variables
+#
+_software()
+{
+    local line pkg def val
+    while read -r line
+    do
+        # Packages must start with lowercase. Also removes rubbish
+        set -- $(echo $line | sed -e 's/=/ /g')
+        pkg="$1"; def="$2"; val="$3"
+
+        ## echo "Using $# package=$pkg default='$def' version='$val'" 1>&2
+
+        if [ "$pkg" = "${pkg#[a-z]}" ]
+        then
+            continue # Packages must start with lowercase
+        elif [ $# -eq 2 ]
+        then
+            echo "${pkg}DEFAULT='${def}';${pkg}VERSION='${def}'"
+        elif [ $# -eq 3 ]
+        then
+            echo "${pkg}DEFAULT='${def}';${pkg}VERSION='${val}'"
+        else
+            echo "Bad input while setting versions"  1>&2
+            echo "   $line" 1>&2
+            exit 1
+        fi
+    done
+}
+
+eval $(
+sed -n \
+    -e '/^ *[;#]/d' \
+    -e '/^\[software\]/,/^\s*\[/{ s/^ *//g; s/ *$//g; s/  */=/g; p }' \
+    $configFile | \
+    _software
+)
+
+#------------------------------------------------------------------------------
+
+# Special treatment for gcc sub-components (needs rethinking)
+case "$compilerVERSION" in
+Gcc | Gcc48)
+    gccVERSION=gcc-4.8.5   # match value in config.sh/compiler
+    ;;
+Gcc49)
+    gccVERSION=gcc-4.9.3   # match value in config.sh/compiler
+    ;;
+Gcc62)
+    gccVERSION=gcc-6.2.0   # match value in config.sh/compiler
+    ;;
+Gcc63)
+    gccVERSION=gcc-6.3.0   # match value in config.sh/compiler
+    ;;
+Gcc71)
+    gccVERSION=gcc-7.1.0   # match value in config.sh/compiler
+    ;;
+Gcc*)
+    echo "Error: unconfigured gcc version '$compilerVERSION'"
+    exit 1 # Really exit, since this must be an input error
+    ;;
+esac
+# -----------------------------------------------------------------------------
+# NO FURTHER EDITING BELOW THIS LINE
+#------------------------------------------------------------------------------
+
+# Name of qt source directory is a fixed value
+qtSource="qt-everywhere-opensource-src-${qtVERSION##*-}"
+
+# Change 'system' into 'gmp-system' etc
+for pkg in gcc gmp mpfr mpc
+do
+    if eval test "\$${pkg}VERSION = system"
+    then
+        eval "${pkg}VERSION='${pkg}-system'"
+        eval "${pkg}DEFAULT='${pkg}-system'"
+    fi
+done
+
+# No gcc/gmp/mpfr/mpc for system compilers or non-Gcc compilers
+case "$compilerTypeVERSION:$compilerVERSION" in
+third:Gcc*)
+    ;;
+third:Clang* | system:Clang* | system:Gcc | system:Icc | system:*)
+    # System, or known non-gcc
+    for check in gcc gmp mpfr mpc
+    do
+        eval "unset ${check}VERSION ${check}DEFAULT"
+    done
+    ;;
+*)
+    echo "Error: unknown ${compilerTypeVERSION}-compiler '$compilerVERSION'"
+    exit 1
+    ;;
+esac
+
+# Separator lines
+_line()
+{
+    echo  " ====================  ====================  ===================="
+}
+
+# Various formatting for -list output
+# formatted print
+_fmt2()
+{
+    local arg1="${1:-????}"
+    local arg2="${2:-undefined}"
+    printf "  %-20s  %-20s\n"  "$arg1"  "$arg2"
+}
+
+# formatted print
+# name version default [-nocheck]
+_fmt3()
+{
+    local what="${1:-????}"
+    local arg1="${2:-undefined}"
+    local arg2="${3:-undefined}"
+
+    if [ "$#" -eq 2 ]
+    then
+        _fmt2 "$what"  "$arg1"
+    elif [ "$#" -eq 3 -a "$arg1" = "$arg2" ]
+    then
+        _fmt2 "$what" "$arg1"
+    else
+        printf "  %-20s  %-20s  %-20s\n"  "$what"  "$arg1"  "$arg2"
+    fi
+}
+
+# input:  'package'
+# output: 'package' packageDEFAULT packageVERSION
+_fmtDefVer()
+{
+    local pkg="$1"
+    eval local "def=\$${pkg}DEFAULT"
+    eval local "val=\$${pkg}VERSION"
+
+    _fmt3 "$pkg"  "$def"  "$val"
+}
+
+
+# Location of the OpenFOAM bashrc
+BASHRC_FILE=$INSTALL_DIR/$OFdirName/etc/bashrc
+
+if [ "$ompiTypeVERSION" != "$ompiTypeDEFAULT" ]
 then
-    configArch="$configArch -openmpi-$ompiTypeVersion"
+    configArch="$configArch -openmpi-$ompiTypeVERSION"
 fi
 
 #------------------------------------------------------------------------------
@@ -326,6 +394,7 @@ _listSettings()
     _fmtDefVer fftw
     _fmtDefVer openmpi
     _fmtDefVer scotch
+    _fmtDefVer kahip
     _fmtDefVer paraview
     _fmtDefVer cmake
     _fmtDefVer vtk
@@ -333,14 +402,14 @@ _listSettings()
     _fmtDefVer qt
     _fmtDefVer ompiType
     _fmtDefVer llvm
-    _fmt3 gcc       "${gccDefault:-system}"  "${gccVersion:-system}"
-    _fmt3 gmp       "${gmpDefault:-system}"  "${gmpVersion:-system}"
-    _fmt3 mpfr      "${mpfrDefault:-system}" "${mpfrVersion:-system}"
-    _fmt3 mpc       "${mpcDefault:-system}"  "${mpcVersion:-system}"
+    _fmt3 gcc  "${gccDEFAULT:-system}"  "${gccVERSION:-system}"
+    _fmt3 gmp  "${gmpDEFAULT:-system}"  "${gmpVERSION:-system}"
+    _fmt3 mpfr "${mpfrDEFAULT:-system}" "${mpfrVERSION:-system}"
+    _fmt3 mpc  "${mpcDEFAULT:-system}"  "${mpcVERSION:-system}"
     _line
     echo
     echo  "  configure:  $configArch"
-    echo  "  compiler:   -$compilerTypeVersion  $compilerVersion"
+    echo  "  compiler:   -$compilerTypeVERSION  $compilerVERSION"
     echo
 }
 
@@ -493,11 +562,11 @@ unpackAllFiles()
     # Unpack OpenFOAM and ThirdParty
     # Source package names may differ from the directory names
     # Also handle '-plus' extensions (common problem?)
-    _unpack "${OFsource:=$OFdirName}"
+    _unpack "$OFsource"
     _mvdir "$OFsource" "$OFdirName"
     _mvdir OpenFOAM-plus "$OFdirName"
 
-    _unpack "${TPsource:=$TPdirName}";
+    _unpack "$TPsource";
     _mvdir "$TPsource" "$TPdirName"
     _mvdir ThirdParty-plus "$TPdirName"
 
@@ -517,13 +586,13 @@ unpackAllFiles()
     if true
     then
         # Compiler configuration (already sanity checked much further above)
-        compilerOpt="-$compilerTypeVersion $compilerVersion"
-        case "$compilerTypeVersion:$compilerVersion" in
+        compilerOpt="-$compilerTypeVERSION $compilerVERSION"
+        case "$compilerTypeVERSION:$compilerVERSION" in
         third:Clang*)
-            compilerOpt="$compilerOpt -clang $llvmVersion"
+            compilerOpt="$compilerOpt -clang $llvmVERSION"
             ;;
         third:Gcc*)
-            compilerOpt="$compilerOpt $gmpVersion $mpfrVersion $mpcVersion"
+            compilerOpt="$compilerOpt $gmpVERSION $mpfrVERSION $mpcVERSION"
             ;;
         esac
 
@@ -532,12 +601,13 @@ unpackAllFiles()
             $configArch $compilerOpt \
             $(
                 # package versions
-                _ifDifferent -cmake   $cmakeVersion   $cmakeDefault
-                _ifDifferent -boost   $boostVersion   $boostDefault
-                _ifDifferent -cgal    $cgalVersion    $cgalDefault
-                _ifDifferent -fftw    $fftwVersion    $fftwDefault
-                _ifDifferent -scotch  $scotchVersion  $scotchDefault
-                _ifDifferent -openmpi $openmpiVersion $openmpiDefault
+                _ifDifferent -cmake   $cmakeVERSION   $cmakeDEFAULT
+                _ifDifferent -boost   $boostVERSION   $boostDEFAULT
+                _ifDifferent -cgal    $cgalVERSION    $cgalDEFAULT
+                _ifDifferent -fftw    $fftwVERSION    $fftwDEFAULT
+                _ifDifferent -scotch  $scotchVERSION  $scotchDEFAULT
+                _ifDifferent -kahip   $kahipVERSION   $kahipDEFAULT
+                _ifDifferent -openmpi $openmpiVERSION $openmpiDEFAULT
             )
 
         echo "foam-configure with settings:"
@@ -557,76 +627,88 @@ unpackAllFiles()
         exit 1
     }
 
-    _unpackIfDifferent $cmakeVersion    $cmakeDefault
-    _unpackIfDifferent $boostVersion    $boostDefault
-    _unpackIfDifferent $cgalVersion     $cgalDefault
-    _unpackIfDifferent $fftwVersion     $fftwDefault
-    _unpackIfDifferent $scotchVersion   $scotchDefault
-    _unpackIfDifferent $openmpiVersion  $openmpiDefault
+    _unpackIfDifferent $cmakeVERSION    $cmakeDEFAULT
+    _unpackIfDifferent $boostVERSION    $boostDEFAULT
+    _unpackIfDifferent $cgalVERSION     $cgalDEFAULT
+    _unpackIfDifferent $fftwVERSION     $fftwDEFAULT
+    _unpackIfDifferent $scotchVERSION   $scotchDEFAULT
+    _unpackIfDifferent $kahipVERSION    $kahipDEFAULT
+    _unpackIfDifferent $openmpiVERSION  $openmpiDEFAULT
 
-    case "$compilerTypeVersion:$compilerVersion" in
+    case "$compilerTypeVERSION:$compilerVERSION" in
     third:Gcc*)
-        echo "# ThirdParty Compiler: $compilerVersion"
-        _unpack $gccVersion
-        _unpack $gmpVersion
-        _unpack $mpfrVersion
-        _unpack $mpcVersion
+        echo "# ThirdParty Compiler: $compilerVERSION"
+        _unpack $gccVERSION
+        _unpack $gmpVERSION
+        _unpack $mpfrVERSION
+        _unpack $mpcVERSION
         ;;
     third:Clang*)
-        echo "# ThirdParty Compiler: $compilerVersion"
+        echo "# ThirdParty Compiler: $compilerVERSION"
         # Mostly unpacks to llvm-x.y.z.src, relocate to llvm-x.y.z
-        _unpack $llvmVersion
-        _mvdir "$llvmVersion.src" "$llvmVersion"          # (*.src -> *)
+        _unpack $llvmVERSION
+        _mvdir "$llvmVERSION.src" "$llvmVERSION"          # (*.src -> *)
 
         # Check if matching cfe (clang) version is required
         clangDir=tools/clang
-        cfeVersion="cfe${llvmVersion#llvm}"
+        cfeVERSION="cfe${llvmVERSION#llvm}"
+
+        if [ -d "$llvmVERSION" -a ! -d "$llvmVERSION/$clangDir" ]
+        then
+            _unpack $cfeVERSION
+            _mvdir "$cfeVERSION.src" "$cfeVERSION"        # As above (*.src -> *)
+            _mvdir "$cfeVERSION" "$llvmVERSION/$clangDir" # Relocate to tools/clang
+        fi
+
+        # Check if matching openmp version is required
+        ompDir=tools/openmp
+        ompVERSION="openmp${llvmVERSION#llvm}"
 
-        if [ -d "$llvmVersion" -a ! -d "$llvmVersion/$clangDir" ]
+        if [ -d "$llvmVERSION" -a ! -d "$llvmVERSION/$ompDir" ]
         then
-            _unpack $cfeVersion
-            _mvdir "$cfeVersion.src" "$cfeVersion"        # As above (*.src -> *)
-            _mvdir "$cfeVersion" "$llvmVersion/$clangDir" # Relocate to tools/clang
+            _unpack $ompVERSION
+            _mvdir "$ompVERSION.src" "$ompVERSION"        # As above (*.src -> *)
+            _mvdir "$ompVERSION" "$llvmVERSION/$ompDir"   # Relocate to tools/openmp
         fi
         ;;
     esac
 
     echo "# Graphics"
-    _unpackIfDifferent $paraviewVersion $paraviewDefault
+    _unpackIfDifferent $paraviewVERSION $paraviewDEFAULT
     # Mostly unpacks to ParaView-vx.y.z | ParaView-vx.y.z-source,
     # relocate to ParaView-x.y.z
 
     # This is why bash
-    _mvdir "${paraviewVersion}-source"          "$paraviewVersion"
-    _mvdir "${paraviewVersion/-/-v}"            "$paraviewVersion"
-    _mvdir "${paraviewVersion/-/-v}-source"     "$paraviewVersion"
+    _mvdir "${paraviewVERSION}-source"          "$paraviewVERSION"
+    _mvdir "${paraviewVERSION/-/-v}"            "$paraviewVERSION"
+    _mvdir "${paraviewVERSION/-/-v}-source"     "$paraviewVERSION"
 
-    _unpack $mesaVersion
+    _unpack $mesaVERSION
 
     # May not really need QT (paraview only)
     _unpack $qtSource
 
     # VTK is a link to ParaView VTK
-    if [ -n "$vtkVersion" ]
+    if [ -n "$vtkVERSION" ]
     then
-        if readlink "$vtkVersion" > /dev/null
+        if readlink "$vtkVERSION" > /dev/null
         then
-            echo "  Remove old link to $vtkVersion"
-            rm "$vtkVersion"
+            echo "  Remove old link to $vtkVERSION"
+            rm "$vtkVERSION"
         fi
-        if [ -d "${paraviewVersion:-paraview#undef}/VTK" ]
+        if [ -d "${paraviewVERSION:-paraview#undef}/VTK" ]
         then
-            echo "  Create new link  $paraviewVersion/VTK $vtkVersion"
-            ln -sv $paraviewVersion/VTK $vtkVersion
+            echo "  Create new link  $paraviewVERSION/VTK $vtkVERSION"
+            ln -sv $paraviewVERSION/VTK $vtkVERSION
         else
-            echo "  did not make link for vtk $vtkVersion"
-            echo "  perhaps no paraview directory? ${paraviewVersion:-???}/VTK"
+            echo "  did not make link for vtk $vtkVERSION"
+            echo "  perhaps no paraview directory? ${paraviewVERSION:-???}/VTK"
         fi
     fi
 
     ## Check if these may be required (again, in the future)
-    ## _unpack $automakeVersion
-    ## _unpack $autoconfVersion
+    ## _unpack $automakeVERSION
+    ## _unpack $autoconfVERSION
 
     echo
     echo "Finished unpacking"
@@ -648,7 +730,7 @@ compileThirdParty()
     echo "   ... we are probably just going to build it now"
     echo
 
-    . $BASHRC_FILE
+    . $BASHRC_FILE ''
 
     cd $WM_THIRD_PARTY_DIR || {
         echo "Error: cannot change to ThirdParty directory - $WM_THIRD_PARTY_DIR"
@@ -667,12 +749,12 @@ compileThirdParty()
     # Cmake (build with system gcc to avoid circular dependency)
     echo
     echo "cmake:"
-    if [ -d "$WM_THIRD_PARTY_DIR/${cmakeVersion:-cmake#undef}" ]
+    if [ -d "$WM_THIRD_PARTY_DIR/${cmakeVERSION:-cmake#undef}" ]
     then
         makeCommand=makeCmake
-        makeOptions="-gcc $cmakeVersion"
+        makeOptions="-gcc $cmakeVERSION"
 
-        makeTarget="$platforms/$WM_ARCH$WM_COMPILER/$cmakeVersion"
+        makeTarget="$platforms/$WM_ARCH$WM_COMPILER/$cmakeVERSION"
         logFile="$LOGFILE_DIR/log.$makeCommand-$WM_OPTIONS.txt"
         if [ -f "$logFile" ]
         then
@@ -687,26 +769,26 @@ compileThirdParty()
 
             # Pickup changes (but should already be there)
             # - foamPV function should also work
-            . $BASHRC_FILE 2>/dev/null
+            . $BASHRC_FILE '' 2>/dev/null
         fi
     else
         echo "  not specified or not found"
     fi
 
     ## Check if these may be required (again, in the future)
-    ## ( cd $automakeVersion && some more stuff )
-    ## ( cd $autoconfVersion && some more stuff )
+    ## ( cd $automakeVERSION && some more stuff )
+    ## ( cd $autoconfVERSION && some more stuff )
 
 
     # Compiler ... this can take a while
     echo
     echo "compiler:"
-    case "$compilerTypeVersion:$compilerVersion" in
+    case "$compilerTypeVERSION:$compilerVERSION" in
     third:Gcc*)
         makeCommand=makeGcc
-        makeOptions="-no-threadsafe $gccVersion $gmpVersion $mpfrVersion $mpcVersion"
+        makeOptions="-no-threadsafe $gccVERSION $gmpVERSION $mpfrVERSION $mpcVERSION"
 
-        makeTarget="$platforms/$WM_ARCH/$gccVersion"
+        makeTarget="$platforms/$WM_ARCH/$gccVERSION"
         logFile="$LOGFILE_DIR/log.$makeCommand-$WM_OPTIONS.txt"
         if [ -f "$logFile" ]
         then
@@ -720,7 +802,7 @@ compileThirdParty()
             ./$makeCommand $makeOptions >> $logFile 2>&1
 
             # Pickup changes (but should already be there)
-            . $BASHRC_FILE
+            . $BASHRC_FILE ''
         fi
         ;;
     third:Clang*)
@@ -728,7 +810,7 @@ compileThirdParty()
         makeOptions=""
         # makeOptions="-gcc"
 
-        makeTarget="$platforms/$WM_ARCH/$llvmVersion"
+        makeTarget="$platforms/$WM_ARCH/$llvmVERSION"
         logFile="$LOGFILE_DIR/log.$makeCommand-$WM_OPTIONS.txt"
         if [ -f "$logFile" ]
         then
@@ -742,7 +824,7 @@ compileThirdParty()
             ./$makeCommand $makeOptions >> $logFile 2>&1
 
             # Pickup changes (but should already be there)
-            . $BASHRC_FILE
+            . $BASHRC_FILE ''
         fi
         ;;
     esac
@@ -790,11 +872,11 @@ compileThirdParty()
     # but need to check how it manages relocating the package
     echo
     echo "mesa:"
-    mesaPREFIX="$platforms/$WM_ARCH$WM_COMPILER/$mesaVersion"
-    if [ -d "$WM_THIRD_PARTY_DIR/${mesaVersion:-mesa#undef}" ]
+    mesaPREFIX="$platforms/$WM_ARCH$WM_COMPILER/$mesaVERSION"
+    if [ -d "$WM_THIRD_PARTY_DIR/${mesaVERSION:-mesa#undef}" ]
     then
         makeCommand=makeMesa
-        makeOptions="$mesaVersion"
+        makeOptions="$mesaVERSION"
 
         makeTarget="$mesaPREFIX"
         logFile="$LOGFILE_DIR/log.$makeCommand-$WM_OPTIONS.txt"
@@ -821,12 +903,12 @@ compileThirdParty()
 
     echo
     echo "VTK (with mesa)"
-    if [ -d "$mesaPREFIX" -a -d "$WM_THIRD_PARTY_DIR/${vtkVersion:-vtk#undef}" ]
+    if [ -d "$mesaPREFIX" -a -d "$WM_THIRD_PARTY_DIR/${vtkVERSION:-vtk#undef}" ]
     then
         makeCommand=makeVTK
-        makeOptions="$vtkVersion -osmesa -mesa-prefix $mesaPREFIX"
+        makeOptions="$vtkVERSION -osmesa -mesa-prefix $mesaPREFIX"
 
-        makeTarget="$platforms/$WM_ARCH$WM_COMPILER/$vtkVersion"
+        makeTarget="$platforms/$WM_ARCH$WM_COMPILER/$vtkVERSION"
         logFile="$LOGFILE_DIR/log.$makeCommand-$WM_OPTIONS.txt"
         if [ -f "$logFile" ]
         then
@@ -845,11 +927,11 @@ compileThirdParty()
 
     echo
     echo "QT (needed for paraview)"
-    qtPREFIX="$platforms/$WM_ARCH$WM_COMPILER/$qtVersion"
+    qtPREFIX="$platforms/$WM_ARCH$WM_COMPILER/$qtVERSION"
     if [ -d "$WM_THIRD_PARTY_DIR/${qtSource:-qt#undef}" ]
     then
         makeCommand=makeQt
-        makeOptions="$qtVersion"
+        makeOptions="$qtVERSION"
         case "$WM_COMPILER" in
         Clang*)
             # Some build issues with clang, use system gcc instead
@@ -872,12 +954,12 @@ compileThirdParty()
         fi
     else
         echo "  not specified or not found"
-        unset qtVersion qtPREFIX # avoid using for paraview build
+        unset qtVERSION qtPREFIX # avoid using for paraview build
     fi
 
     echo
     echo "ParaView:"
-    if [ -d "$WM_THIRD_PARTY_DIR/${paraviewVersion:-paraview#undef}" ]
+    if [ -d "$WM_THIRD_PARTY_DIR/${paraviewVERSION:-paraview#undef}" ]
     then
         makeCommand=makeParaView
         makeOptions=""
@@ -885,12 +967,12 @@ compileThirdParty()
         then
             makeOptions="$makeOptions -mesa-prefix $mesaPREFIX"
         fi
-        if [ -n "$qtVersion" -a -x "$qtPREFIX/bin/qmake" ]
+        if [ -n "$qtVERSION" -a -x "$qtPREFIX/bin/qmake" ]
         then
-            makeOptions="$makeOptions -$qtVersion"
+            makeOptions="$makeOptions -$qtVERSION"
         fi
 
-        makeTarget="$platforms/$WM_ARCH$WM_COMPILER/$paraviewVersion"
+        makeTarget="$platforms/$WM_ARCH$WM_COMPILER/$paraviewVERSION"
         logFile="$LOGFILE_DIR/log.$makeCommand-$WM_OPTIONS.txt"
         if [ -f "$logFile" ]
         then
@@ -931,7 +1013,7 @@ compileOpenFOAM()
     echo "Starting compilation of OpenFOAM"
     echo
 
-    . $BASHRC_FILE
+    . $BASHRC_FILE ''
 
     cd $WM_PROJECT_DIR || {
         echo "Error: cannot change to OpenFOAM directory - $WM_PROJECT_DIR"
diff --git a/legacyCompile/v1612.cfg b/legacyCompile/v1612.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..a6d1d2be78e2003c0d24422ff78d60e36a533475
--- /dev/null
+++ b/legacyCompile/v1612.cfg
@@ -0,0 +1,53 @@
+#------------------------------------------------------------------------------
+# File
+#     v1612.cfg
+#
+# Description
+#     Configuration file for legacyCompile
+#------------------------------------------------------------------------------
+
+# Top-level package information
+[package]
+
+FoamVersion=v1612+
+OFdirName=OpenFOAM-v1612+
+TPdirName=ThirdParty-v1612+
+
+# If source packages differ from the directory names, uncomment and adjust
+
+# OFsource=OpenFOAM-plus
+# TPsource=ThirdParty-plus
+
+# Architecture
+[arch]
+label=32
+scalar=64
+sigfpe=false
+
+
+[software]
+# Preferred software versions etc. Use 'third' for ThirdParty.
+#---------------------+-------------------+-------------------+
+#   package           | default           | user-preference   |
+#---------------------+-------------------+-------------------+
+    boost               boost_1_62_0
+    cgal                CGAL-4.9
+    fftw                fftw-3.3.5
+    openmpi             openmpi-1.10.4
+    scotch              scotch_6.0.3
+    paraview            ParaView-5.0.1
+    cmake               cmake-system        cmake-3.5.2
+    vtk                 none                VTK-7.1.0
+    mesa                none                mesa-13.0.1
+    qt                  qt-system           qt-4.8.7
+    llvm                llvm-3.7.0
+    gcc                 system              gcc-4.8.5
+    gmp                 system              gmp-6.1.1
+    mpfr                system              mpfr-3.1.5
+    mpc                 system              mpc-1.0.3
+
+    ompiType            system              third
+    compilerType        system              third
+    compiler            Gcc                 Clang
+
+# -----------------------------------------------------------------------------
diff --git a/legacyCompile/v1706.cfg b/legacyCompile/v1706.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..983cf445c95a4f365d9178dbd0fbf506171dd2b4
--- /dev/null
+++ b/legacyCompile/v1706.cfg
@@ -0,0 +1,53 @@
+#------------------------------------------------------------------------------
+# File
+#     v1706.cfg
+#
+# Description
+#     Configuration file for legacyCompile
+#------------------------------------------------------------------------------
+
+# Top-level package information
+[package]
+
+FoamVersion=v1706
+OFdirName=OpenFOAM-v1706
+TPdirName=ThirdParty-v1706
+
+# If source packages differ from the directory names, uncomment and adjust
+
+# OFsource=OpenFOAM-plus
+# TPsource=ThirdParty-plus
+
+# Architecture
+[arch]
+label=32
+scalar=32
+sigfpe=false
+
+
+[software]
+# Preferred software versions etc. Use 'third' for ThirdParty.
+#---------------------+-------------------+-------------------+
+#   package           | default           | user-preference   |
+#---------------------+-------------------+-------------------+
+    boost               boost_1_64_0
+    cgal                CGAL-4.9.1
+    fftw                fftw-3.3.6-pl1
+    openmpi             openmpi-1.10.4
+    scotch              scotch_6.0.3
+    paraview            ParaView-5.4.0
+    cmake               cmake-system        cmake-3.5.2
+    vtk                 none                VTK-8.1.0
+    mesa                none                mesa-17.1.1
+    qt                  qt-system           qt-4.8.7
+    llvm                llvm-3.7.0
+    gcc                 system              gcc-4.8.5
+    gmp                 system              gmp-6.1.1
+    mpfr                system              mpfr-3.1.5
+    mpc                 system              mpc-1.0.3
+
+    ompiType            system              third
+    compilerType        system              third
+    compiler            Gcc                 Clang
+
+# -----------------------------------------------------------------------------
diff --git a/legacyCompile/v1712.cfg b/legacyCompile/v1712.cfg
new file mode 100644
index 0000000000000000000000000000000000000000..91e29e07ef2a36fb55514fd3279471ec03fc83bd
--- /dev/null
+++ b/legacyCompile/v1712.cfg
@@ -0,0 +1,53 @@
+#------------------------------------------------------------------------------
+# File
+#     v1712.cfg
+#
+# Description
+#     Configuration file for legacyCompile
+#------------------------------------------------------------------------------
+
+# Top-level package information
+[package]
+
+FoamVersion=v1712
+OFdirName=OpenFOAM-v1712
+TPdirName=ThirdParty-v1712
+
+# If source packages differ from the directory names, uncomment and adjust
+
+# OFsource=OpenFOAM-plus
+# TPsource=ThirdParty-plus
+
+# Architecture
+[arch]
+label=32
+scalar=32
+
+
+[software]
+# Preferred software versions etc. Use 'third' for ThirdParty.
+#---------------------+-------------------+-------------------+
+#   package           | default           | user-preference   |
+#---------------------+-------------------+-------------------+
+    boost               boost_1_64_0
+    cgal                CGAL-4.9.1
+    fftw                fftw-3.3.7
+    openmpi             openmpi-1.10.4
+    scotch              scotch_6.0.3
+    kahip               kahip-2.00
+    paraview            ParaView-5.4.1
+    cmake               cmake-system        cmake-3.6.0
+    vtk                 none                VTK-8.1.0
+    mesa                none                mesa-17.1.1
+    qt                  qt-system           qt-5.9.3
+    llvm                llvm-3.7.1
+    gcc                 system              gcc-4.8.5
+    gmp                 system              gmp-6.1.1
+    mpfr                system              mpfr-3.1.5
+    mpc                 system              mpc-1.0.3
+
+    ompiType            system              third
+    compilerType        system              third
+    compiler            Gcc                 Clang
+
+# -----------------------------------------------------------------------------
diff --git a/modules/foamCreateModuleInclude b/modules/foamCreateModuleInclude
index 25f3a5dfb619b57edd75b5dcffa129a0b8818748..994b36e8188e114c0fd651ec03757bdd1f7f9ba8 100755
--- a/modules/foamCreateModuleInclude
+++ b/modules/foamCreateModuleInclude
@@ -73,7 +73,7 @@ do
     '')
         # Ignore empty args
         ;;
-    -h | -help)
+    -h | -help*)
         usage
         ;;
     -debug)
@@ -178,11 +178,38 @@ else
 fi
 
 
+# Snapshot of aliases - sorted
+printAlias()
+{
+    alias | sort -f
+}
+
+
+# Snapshot of environment - without functions
+# Sorted as non-OpenFOAM, WM_*, FOAM_*
+printEnv()
+{
+    # Non FOAM_*, WM_* settings
+    echo "# non-OpenFOAM"
+    env | sed -n -e '\@^FOAM_@d' -e '\@^WM_@d' -e '\@^[^ {}]@p' \
+        | sort -f
+
+    # WM_* settings
+    echo "# OpenFOAM"
+    env | sed -n -e '\@^WM_@p' \
+        | sort -f
+
+    # FOAM_* settings
+    echo "# OpenFOAM"
+    env | sed -n -e '\@^FOAM_@p' \
+        | sort -f
+}
+
 #
-# Initial snapshot of the environment, without any functions
+# Initial snapshot of the environment (without functions)
 #
-env   | sed -n -e '/^[^ {}]/p' | sort -f > $tmpFiles.env.pre.log
-alias | sort -f > $tmpFiles.alias.pre.log
+printEnv   > $tmpFiles.env.pre.log
+printAlias > $tmpFiles.alias.pre.log
 
 # OpenFOAM settings
 . $projectDir/etc/bashrc ''
@@ -195,6 +222,9 @@ unset FOAM_JOB_DIR FOAM_RUN FOAM_SETTINGS FOAM_INST_DIR
 unset WM_PROJECT_USER_DIR WM_THIRD_PARTY_DIR
 unset SCOTCH_VERSION
 
+
+# Also remove user directories as being unreliable
+
 foamOldDirs="$CEI_HOME $BOOST_ARCH_PATH $CGAL_ARCH_PATH $FFTW_ARCH_PATH $MPI_ARCH_PATH $SCOTCH_ARCH_PATH \
 $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN $WM_PROJECT_SITE \
 $FOAM_USER_APPBIN $FOAM_USER_LIBBIN"
@@ -222,11 +252,6 @@ unset ENSIGHT10_INPUT ENSIGHT10_READER
 # Always consider site to be bogus. If needed, should be done elsewhere.
 unset FOAM_SITE_APPBIN FOAM_SITE_LIBBIN WM_PROJECT_SITE
 
-# Make user directories more generic.
-export FOAM_USER_APPBIN='$env(HOME)/OpenFOAM/$env(USER)-'"$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/bin"
-export FOAM_USER_LIBBIN='$env(HOME)/OpenFOAM/$env(USER)-'"$WM_PROJECT_VERSION/platforms/$WM_OPTIONS/lib"
-
-
 # Remove non-essential aliases
 unalias wmDP        2>/dev/null
 unalias wmInt32     2>/dev/null
@@ -247,11 +272,22 @@ unalias util        2>/dev/null
 
 #------------------------------------------------
 
+# Generalize environment.
+# This needs rethinking since it largely duplicates logic from the etc/config.sh/settings
+rewriteEnv()
+{
+    sed \
+    -e 's@^\(FOAM_USER_APPBIN=\).*@\1$env(HOME)/OpenFOAM/$env(USER)-$env(WM_PROJECT_VERSION)/platforms/$env(WM_OPTIONS)/bin@' \
+    -e 's@^\(FOAM_USER_LIBBIN=\).*@\1$env(HOME)/OpenFOAM/$env(USER)-$env(WM_PROJECT_VERSION)/platforms/$env(WM_OPTIONS)/lib@' \
+    ;
+}
+
 #
-# Updated snapshot of the environment, without any functions
+# Updated snapshot of the environment (without functions)
 #
-env   | sed -n -e '/^[^ {}]/p' | sort -f > $tmpFiles.env.post.log
-alias | sort -f > $tmpFiles.alias.post.log
+printEnv   | rewriteEnv > $tmpFiles.env.post.log
+printAlias > $tmpFiles.alias.post.log
+
 
 # Create a diff of the environment and aliases
 diff $tmpFiles.env.pre.log    $tmpFiles.env.post.log   > $tmpFiles.env.diff.log
@@ -259,7 +295,7 @@ diff $tmpFiles.alias.pre.log  $tmpFiles.alias.post.log > $tmpFiles.alias.diff.lo
 
 echo "# -------------------"  > $moduleOutput
 
-# -------------------
+# --------------------------------------------------
 # Environment other than PATH, LD_LIBRARY_PATH
 echo "# Environment"  >> $moduleOutput
 grep '> ' $tmpFiles.env.diff.log | \
@@ -270,7 +306,7 @@ sed \
     -e 's/=/ "/' -e 's/$/\"/' >> $moduleOutput
 
 
-# -------------------
+# --------------------------------------------------
 # Changes in PATH - without junk and system directories
 echo "# PATH"  >> $moduleOutput
 
@@ -290,9 +326,9 @@ sed \
     -e 's/^/append-path PATH "/' \
     -e 's/$/\"/' \
     $tmpFiles.path.diff.log  >> $moduleOutput
-# -------------------
+# --------------------------------------------------
 
-# -------------------
+# --------------------------------------------------
 # Changes in LD_LIBRARY_PATH - without junk and system directories
 echo "# LD_LIBRARY_PATH"  >> $moduleOutput