#Use external CGAL and METIS (via CGAL_ROOT, BOOST_ROOT and METIS_ROOT in easyconfig)
#B. Hajgato OCT 23,2014
--- OpenFOAM-2.4.0.ORIG/etc/config/CGAL.csh	2014-02-11 12:59:42.000000000 +0100
+++ OpenFOAM-2.4.0/etc/config/CGAL.csh	2014-10-23 07:33:17.186624521 +0200
@@ -29,26 +29,36 @@
 #     Sourced from OpenFOAM-<VERSION>/etc/cshrc
 ##------------------------------------------------------------------------------
 
-set boost_version=boost-system
-set cgal_version=CGAL-4.6
+if ( ${?EBROOTCGAL} != 0 ) then
+   setenv BOOST_ARCH_PATH $EBROOTBOOST
+   setenv CGAL_ARCH_PATH $EBROOTCGAL
+
+elif ( ${?CGAL_ROOT} != 0 ) then
+   setenv BOOST_ARCH_PATH $CGAL_ROOT
+   setenv CGAL_ARCH_PATH $CGAL_ROOT
+
+else
+    set boost_version=boost-system
+    set cgal_version=CGAL-4.6
+
+    setenv BOOST_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version
+    setenv CGAL_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version
+
+    if ($?FOAM_VERBOSE && $?prompt) then
+        echo "Using CGAL and boost"
+        echo "    $cgal_version at $CGAL_ARCH_PATH"
+        echo "    $boost_version at $BOOST_ARCH_PATH"
+    endif
+
+    if ( -d "$CGAL_ARCH_PATH" ) then
+        _foamAddLib $CGAL_ARCH_PATH/lib
+    endif
+
+    if ( -d "$BOOST_ARCH_PATH" ) then
+        _foamAddLib $BOOST_ARCH_PATH/lib
+    endif
 
-setenv BOOST_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$boost_version
-setenv CGAL_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$cgal_version
-
-if ($?FOAM_VERBOSE && $?prompt) then
-    echo "Using CGAL and boost"
-    echo "    $cgal_version at $CGAL_ARCH_PATH"
-    echo "    $boost_version at $BOOST_ARCH_PATH"
-endif
-
-if ( -d "$CGAL_ARCH_PATH" ) then
-    _foamAddLib $CGAL_ARCH_PATH/lib
+    unset boost_version cgal_version
 endif
 
-if ( -d "$BOOST_ARCH_PATH" ) then
-    _foamAddLib $BOOST_ARCH_PATH/lib
-endif
-
-unset boost_version cgal_version
-
 # -----------------------------------------------------------------------------
--- OpenFOAM-2.4.0.ORIG/etc/config/CGAL.sh	2014-02-11 12:59:42.000000000 +0100
+++ OpenFOAM-2.4.0/etc/config/CGAL.sh	2014-10-23 07:33:00.706674383 +0200
@@ -29,29 +29,39 @@
 #     Sourced from OpenFOAM-<VERSION>/etc/bashrc
 #------------------------------------------------------------------------------
 
-boost_version=boost-system
-cgal_version=CGAL-4.6
+if [ -n "${EBROOTCGAL}" ]; then
+    export CGAL_ARCH_PATH="${EBROOTCGAL}"
+    export BOOST_ARCH_PATH="${EBROOTBOOST}"
+
+elif [ -n "${CGAL_ROOT}" ]; then
+    export CGAL_ARCH_PATH="${CGAL_ROOT}"
+    export BOOST_ARCH_PATH="${CGAL_ROOT}"
+
+else
+    boost_version=boost-system
+    cgal_version=CGAL-4.6
+
+    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"
+        echo "    $cgal_version at $CGAL_ARCH_PATH"
+        echo "    $boost_version at $BOOST_ARCH_PATH"
+    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
 
-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"
-    echo "    $cgal_version at $CGAL_ARCH_PATH"
-    echo "    $boost_version at $BOOST_ARCH_PATH"
-fi
-
-if [ -d "$CGAL_ARCH_PATH" ]
-then
-    _foamAddLib $CGAL_ARCH_PATH/lib
+    unset boost_version cgal_version
 fi
 
-if [ -d "$BOOST_ARCH_PATH" ]
-then
-    _foamAddLib $BOOST_ARCH_PATH/lib
-fi
-
-unset boost_version cgal_version
-
 # -----------------------------------------------------------------------------
--- OpenFOAM-2.4.0.ORIG/etc/config/metis.sh	2014-02-11 12:59:42.000000000 +0100
+++ OpenFOAM-2.4.0/etc/config/metis.sh	2014-10-23 07:55:07.920637398 +0200
@@ -33,7 +33,15 @@
 #     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
+if [ -n "${EBROOTMETIS}" ] ; then
+    export METIS_ARCH_PATH=$EBROOTMETIS
+
+elif [ -n "${METIS_ROOT}" ] ; then
+    export METIS_ARCH_PATH=$METIS_ROOT
+
+else
+    export METIS_VERSION=metis-5.1.0
+    export METIS_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$METIS_VERSION
+fi
 
 # -----------------------------------------------------------------------------
