# This patch removes all need for the ThirdParty files of OpenFOAM:
# we use EB dependencies for everything. It adjusts the paths, variables, etc
# We also let the install dir, compiler, etc be set by EB.
# Lastly, we also fix a small compile issue in 'ptscotchDecomp.C'
# Ward Poelmans <wpoely86@gmail.com>, Kenneth Hoste <kenneth.hoste@ugent.be>
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/applications/utilities/mesh/manipulation/setSet/Allwmake OpenFOAM-3.0.x-version-3.0.1/applications/utilities/mesh/manipulation/setSet/Allwmake
--- OpenFOAM-3.0.x-version-3.0.1.orig/applications/utilities/mesh/manipulation/setSet/Allwmake	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/applications/utilities/mesh/manipulation/setSet/Allwmake	2016-10-25 11:51:45.000000000 +0200
@@ -6,11 +6,11 @@
 #
 # use readline if available
 #
-if [ -f /usr/include/readline/readline.h ]
+if [ -f $EBROOTLIBREADLINE/include/readline/readline.h ]
 then
     echo "Found <readline/readline.h>  --  enabling readline support."
     export COMP_FLAGS="-DHAS_READLINE"
-    export LINK_FLAGS="-lreadline"
+    export LINK_FLAGS="-L$EBROOTLIBREADLINE/lib -lreadline -L$EBROOTNCURSES -lncurses"
 fi
 
 wmake
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/applications/utilities/postProcessing/graphics/PV3Readers/Allwmake OpenFOAM-3.0.x-version-3.0.1/applications/utilities/postProcessing/graphics/PV3Readers/Allwmake
--- OpenFOAM-3.0.x-version-3.0.1.orig/applications/utilities/postProcessing/graphics/PV3Readers/Allwmake	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/applications/utilities/postProcessing/graphics/PV3Readers/Allwmake	2016-10-25 12:00:41.000000000 +0200
@@ -12,7 +12,7 @@
         }
 
         # ensure CMake gets the correct C++ compiler
-        [ -n "$WM_CXX" ] && export CXX="$WM_CXX"
+#        [ -n "$WM_CXX" ] && export CXX="$WM_CXX"
 
         wmake libso vtkPV3Readers
         PV3blockMeshReader/Allwmake
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/applications/utilities/postProcessing/graphics/PV4Readers/Allwmake OpenFOAM-3.0.x-version-3.0.1/applications/utilities/postProcessing/graphics/PV4Readers/Allwmake
--- OpenFOAM-3.0.x-version-3.0.1.orig/applications/utilities/postProcessing/graphics/PV4Readers/Allwmake	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/applications/utilities/postProcessing/graphics/PV4Readers/Allwmake	2016-10-25 12:00:41.000000000 +0200
@@ -12,7 +12,7 @@
         }
 
         # ensure CMake gets the correct C++ compiler
-        [ -n "$WM_CXX" ] && export CXX="$WM_CXX"
+#        [ -n "$WM_CXX" ] && export CXX="$WM_CXX"
 
         wmake libso vtkPV4Readers
         PV4blockMeshReader/Allwmake
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/bashrc	2016-11-08 12:21:21.478604080 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/bashrc	2016-11-08 12:21:27.978572000 +0100
@@ -32,7 +32,7 @@
 #------------------------------------------------------------------------------
 
 export WM_PROJECT=OpenFOAM
-export WM_PROJECT_VERSION=3.0.x
+export WM_PROJECT_VERSION=3.0.1
 
 ################################################################################
 # USER EDITABLE PART: Changes made here may be lost with the next upgrade
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/cshrc	2016-11-08 12:21:43.478604102 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/cshrc	2016-11-08 12:21:50.258390000 +0100
@@ -31,7 +31,7 @@
 #------------------------------------------------------------------------------
 
 setenv WM_PROJECT OpenFOAM
-setenv WM_PROJECT_VERSION 3.0.x
+setenv WM_PROJECT_VERSION 3.0.1
 
 ################################################################################
 # USER EDITABLE PART: Changes made here may be lost with the next upgrade
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/CGAL.sh OpenFOAM-3.0.x-version-3.0.1/etc/config/CGAL.sh
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/CGAL.sh	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/config/CGAL.sh	2016-10-25 12:04:22.000000000 +0200
@@ -29,29 +29,5 @@
 #     Sourced from OpenFOAM-<VERSION>/etc/bashrc
 #------------------------------------------------------------------------------
 
-boost_version=boost-system
-cgal_version=CGAL-4.7
-
-export BOOST_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version
-export CGAL_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version
-
-if [ "$FOAM_VERBOSE" -a "$PS1" ]
-then
-    echo "Using CGAL and boost" 1>&2
-    echo "    $cgal_version at $CGAL_ARCH_PATH" 1>&2
-    echo "    $boost_version at $BOOST_ARCH_PATH" 1>&2
-fi
-
-if [ -d "$CGAL_ARCH_PATH" ]
-then
-    _foamAddLib $CGAL_ARCH_PATH/lib
-fi
-
-if [ -d "$BOOST_ARCH_PATH" ]
-then
-    _foamAddLib $BOOST_ARCH_PATH/lib
-fi
-
-unset boost_version cgal_version
-
-# -----------------------------------------------------------------------------
+export CGAL_ARCH_PATH=$EBROOTCGAL                                                                                      
+export BOOST_ARCH_PATH=$EBROOTBOOST
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/gperftools.sh OpenFOAM-3.0.x-version-3.0.1/etc/config/gperftools.sh
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/gperftools.sh	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/config/gperftools.sh	2016-10-25 12:05:33.000000000 +0200
@@ -29,13 +29,7 @@
 #
 #------------------------------------------------------------------------------
 
-version=svn
-gperftools_install=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER
-
-GPERFTOOLS_VERSION=gperftools-$version
-GPERFTOOLS_ARCH_PATH=$gperftools_install/$GPERFTOOLS_VERSION
-
-export PATH=$GPERFTOOLS_ARCH_PATH/bin:$PATH
-export LD_LIBRARY_PATH=$GPERFTOOLS_ARCH_PATH/lib:$LD_LIBRARY_PATH
+PERFTOOLS_VERSION=gperftools-$EBVERSIONGPERFTOOLS                                                                     
+GPERFTOOLS_ARCH_PATH=$EBROOTGPERFTOOLS
 
 # -----------------------------------------------------------------------------
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/metis.sh OpenFOAM-3.0.x-version-3.0.1/etc/config/metis.sh
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/metis.sh	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/config/metis.sh	2016-10-25 12:06:03.000000000 +0200
@@ -33,7 +33,7 @@
 #     during the wmake process
 #------------------------------------------------------------------------------
 
-export METIS_VERSION=metis-5.1.0
-export METIS_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$METIS_VERSION
+export METIS_VERSION=metis-$EBVERSIONMETIS                                                                             
+export METIS_ARCH_PATH=$EBROOTMETIS 
 
 # -----------------------------------------------------------------------------
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/paraview.sh OpenFOAM-3.0.x-version-3.0.1/etc/config/paraview.sh
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/paraview.sh	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/config/paraview.sh	2016-10-25 12:09:26.000000000 +0200
@@ -36,29 +36,16 @@
 # clean the PATH
 cleaned=`$WM_PROJECT_DIR/bin/foamCleanPath "$PATH" "$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"` && PATH="$cleaned"
 
-# determine the cmake to be used
-unset CMAKE_HOME
-for cmake in cmake-3.2.1 cmake-2.8.12.1 cmake-2.8.8 cmake-2.8.4 cmake-2.8.3 cmake-2.8.1
-do
-    cmake=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cmake
-    if [ -r $cmake ]
-    then
-        export CMAKE_HOME=$cmake
-        export PATH=$CMAKE_HOME/bin:$PATH
-        break
-    fi
-done
-
 
 #- ParaView version, automatically determine major version
 #export ParaView_VERSION=3.12.0
 #export ParaView_VERSION=4.0.1
 #export ParaView_VERSION=4.1.0
 #export ParaView_VERSION=4.3.1
-export ParaView_VERSION=4.4.0
+#export ParaView_VERSION=4.4.0
+export ParaView_VERSION=$EBVERSIONPARAVIEW 
 export ParaView_MAJOR=detect
 
-
 # Evaluate command-line parameters for ParaView
 _foamParaviewEval()
 {
@@ -95,16 +82,12 @@
 paraviewInstDir=$WM_THIRD_PARTY_DIR/ParaView-$ParaView_VERSION
 paraviewArchName=ParaView-$ParaView_VERSION
 
-export ParaView_DIR=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$paraviewArchName
+export ParaView_DIR=$EBROOTPARAVIEW 
 
 # set paths if binaries or source are present
 if [ -r $ParaView_DIR -o -r $paraviewInstDir ]
 then
     export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview-$ParaView_MAJOR
-    if [ ! -d $ParaView_INCLUDE_DIR -a -d $ParaView_DIR/include/paraview ]
-    then
-        export ParaView_INCLUDE_DIR=$ParaView_DIR/include/paraview
-    fi
 
     ParaView_LIB_DIR=$ParaView_DIR/lib/paraview-$ParaView_MAJOR
     if [ ! -d $ParaView_LIB_DIR -a -d $ParaView_DIR/lib/paraview ]
@@ -112,8 +95,6 @@
         ParaView_LIB_DIR=$ParaView_DIR/lib/paraview
     fi
 
-    export PATH=$ParaView_DIR/bin:$PATH
-    export LD_LIBRARY_PATH=$ParaView_LIB_DIR:$LD_LIBRARY_PATH
     export PV_PLUGIN_PATH=$FOAM_LIBBIN/paraview-$ParaView_MAJOR
 
     if [ "$FOAM_VERBOSE" -a "$PS1" ]
@@ -125,17 +106,6 @@
         echo "    PV_PLUGIN_PATH       : $PV_PLUGIN_PATH"
     fi
 
-    # add in python libraries if required
-    paraviewPython=$ParaView_DIR/Utilities/VTKPythonWrapping
-    if [ -r $paraviewPython ]
-    then
-        if [ "$PYTHONPATH" ]
-        then
-            export PYTHONPATH=$PYTHONPATH:$paraviewPython:$ParaView_LIB_DIR
-        else
-            export PYTHONPATH=$paraviewPython:$ParaView_LIB_DIR
-        fi
-    fi
 else
     unset PV_PLUGIN_PATH
 fi
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/scotch.sh OpenFOAM-3.0.x-version-3.0.1/etc/config/scotch.sh
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/scotch.sh	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/config/scotch.sh	2016-10-25 12:12:06.000000000 +0200
@@ -33,7 +33,7 @@
 #     during the wmake process
 #------------------------------------------------------------------------------
 
-export SCOTCH_VERSION=scotch_6.0.3
-export SCOTCH_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER$WM_LABEL_OPTION/$SCOTCH_VERSION
+export SCOTCH_VERSION=scotch_$EBVERSIONSCOTCH                                                                          
+export SCOTCH_ARCH_PATH=$EBROOTSCOTCH 
 
 # -----------------------------------------------------------------------------
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/settings.sh OpenFOAM-3.0.x-version-3.0.1/etc/config/settings.sh
--- OpenFOAM-3.0.x-version-3.0.1.orig/etc/config/settings.sh	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/etc/config/settings.sh	2016-10-25 12:13:20.000000000 +0200
@@ -87,11 +87,11 @@
         64)
             WM_ARCH=linux64
             export WM_COMPILER_LIB_ARCH=64
-            export WM_CC='gcc'
-            export WM_CXX='g++'
-            export WM_CFLAGS='-m64 -fPIC'
-            export WM_CXXFLAGS='-m64 -fPIC'
-            export WM_LDFLAGS='-m64'
+            export WM_CC=$CC
+            export WM_CXX=$CXX
+            export WM_CFLAGS=$CFLAGS
+            export WM_CXXFLAGS=$CXXFLAGS
+            export WM_LDFLAGS=$LDFLAGS
             ;;
         *)
             echo "Unknown WM_ARCH_OPTION '$WM_ARCH_OPTION', should be 32 or 64"\
@@ -598,6 +598,9 @@
     _foamAddPath    $MPI_ARCH_PATH/bin64
     _foamAddLib     $MPI_ARCH_PATH/lib64
     ;;
+EASYBUILDMPI)                                                                                                          
+    export FOAM_MPI=mpi                                                                                                
+    ;; 
 *)
     export FOAM_MPI=dummy
     ;;
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/src/parallel/decompose/ptscotchDecomp/Make/options OpenFOAM-3.0.x-version-3.0.1/src/parallel/decompose/ptscotchDecomp/Make/options
--- OpenFOAM-3.0.x-version-3.0.1.orig/src/parallel/decompose/ptscotchDecomp/Make/options	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/src/parallel/decompose/ptscotchDecomp/Make/options	2016-10-25 12:13:37.000000000 +0200
@@ -3,10 +3,8 @@
 
 EXE_INC = \
     $(PFLAGS) $(PINC) \
-    -I$(SCOTCH_ROOT)/include \
     -I$(SCOTCH_ARCH_PATH)/include/$(FOAM_MPI) \
-    -I/usr/include/scotch \
     -I../decompositionMethods/lnInclude
 
 LIB_LIBS = \
-    -L$(SCOTCH_ROOT)/lib -L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) -lptscotch -lptscotcherrexit -lscotch ${LINK_FLAGS} -lrt
+    -L$(SCOTCH_ARCH_PATH)/lib -L$(FOAM_EXT_LIBBIN)/$(FOAM_MPI) -lptscotch -lptscotcherrexit -lscotch ${LINK_FLAGS} -lrt
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C OpenFOAM-3.0.x-version-3.0.1/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C
--- OpenFOAM-3.0.x-version-3.0.1.orig/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/src/parallel/decompose/ptscotchDecomp/ptscotchDecomp.C	2016-10-25 12:13:37.000000000 +0200
@@ -119,10 +119,11 @@
 #include "globalIndex.H"
 #include "SubField.H"
 
+#include <mpi.h>
+
 extern "C"
 {
     #include <stdio.h>
-    #include <mpi.h>
     #include "ptscotch.h"
 }
 
diff -ru OpenFOAM-3.0.x-version-3.0.1.orig/src/parallel/decompose/scotchDecomp/Make/options OpenFOAM-3.0.x-version-3.0.1/src/parallel/decompose/scotchDecomp/Make/options
--- OpenFOAM-3.0.x-version-3.0.1.orig/src/parallel/decompose/scotchDecomp/Make/options	2015-12-15 12:20:08.000000000 +0100
+++ OpenFOAM-3.0.x-version-3.0.1/src/parallel/decompose/scotchDecomp/Make/options	2016-10-25 12:13:37.000000000 +0200
@@ -7,10 +7,8 @@
 
 EXE_INC = \
     $(PFLAGS) $(PINC) \
-    -I$(SCOTCH_ROOT)/include \
     -I$(SCOTCH_ARCH_PATH)/include \
-    -I/usr/include/scotch \
     -I../decompositionMethods/lnInclude
 
 LIB_LIBS = \
-    -L$(SCOTCH_ROOT)/lib -L$(FOAM_EXT_LIBBIN) -lscotch -lscotcherrexit -lrt
+    -L$(SCOTCH_ARCH_PATH)/lib -L$(FOAM_EXT_LIBBIN) -lscotch -lscotcherrexit -lrt
