From 49bbb29ac86d90a82bd582bbe1c9adc64144e51d Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Mon, 15 Dec 2008 22:06:54 +0100
Subject: [PATCH] update build scripts and etc/apps/paraview3 settings for
 paraview-3.5 (cvs)

- The new cmake seems to be even smarter. If we try to use env variables in
  the .cmake files (eg, with And's sed fixup), they are rewritten in a
  subsequent re-make and take much longer).  Adjusting the compiler values
  themselves causes a full remake. On the positive side, disabling the rpath
  seems to mean we may not need any of this.

  In summary - yuck!
---
 bin/buildParaView3.3-cvs-python      |   1 -
 bin/buildParaView3.5-cvs             | 169 +++++++++++++++++++++++++++
 bin/buildParaView3.5-cvs-python      |   1 +
 bin/{ => tools}/buildParaView3.3-cvs |  17 +--
 bin/tools/buildParaViewFunctions     | 129 +++++++++++---------
 etc/apps/paraview3/bashrc            |  26 +++--
 etc/apps/paraview3/cshrc             |  38 +++---
 7 files changed, 290 insertions(+), 91 deletions(-)
 delete mode 120000 bin/buildParaView3.3-cvs-python
 create mode 100755 bin/buildParaView3.5-cvs
 create mode 120000 bin/buildParaView3.5-cvs-python
 rename bin/{ => tools}/buildParaView3.3-cvs (91%)

diff --git a/bin/buildParaView3.3-cvs-python b/bin/buildParaView3.3-cvs-python
deleted file mode 120000
index db5ce4641b1..00000000000
--- a/bin/buildParaView3.3-cvs-python
+++ /dev/null
@@ -1 +0,0 @@
-buildParaView3.3-cvs
\ No newline at end of file
diff --git a/bin/buildParaView3.5-cvs b/bin/buildParaView3.5-cvs
new file mode 100755
index 00000000000..c809cd8f7e9
--- /dev/null
+++ b/bin/buildParaView3.5-cvs
@@ -0,0 +1,169 @@
+#!/bin/sh
+#------------------------------------------------------------------------------
+# =========                 |
+# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
+#  \\    /   O peration     |
+#   \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
+#    \\/     M anipulation  |
+#------------------------------------------------------------------------------
+# License
+#     This file is part of OpenFOAM.
+#
+#     OpenFOAM is free software; you can redistribute it and/or modify it
+#     under the terms of the GNU General Public License as published by the
+#     Free Software Foundation; either version 2 of the License, or (at your
+#     option) any later version.
+#
+#     OpenFOAM 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 GNU General Public License
+#     for more details.
+#
+#     You should have received a copy of the GNU General Public License
+#     along with OpenFOAM; if not, write to the Free Software Foundation,
+#     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Script
+#     buildParaView3.5-cvs
+#
+# Description
+#     Build and install ParaView
+#     - run from folder above ParaView source folder or place the
+#       ParaView source under $WM_THIRD_PARTY_DIR
+#
+#------------------------------------------------------------------------------
+. $WM_PROJECT_DIR/bin/tools/buildParaViewFunctions
+
+PARAVIEW_SRC=paraview-3.5-cvs
+PARAVIEW_MAJOR_VERSION=3.5
+
+# User options:
+# ~~~~~~~~~~~~~
+
+# MPI support:
+WITH_MPI=OFF
+MPI_MAX_PROCS=32
+
+# Python support:
+# note: script will try to determine the appropriate python library.
+#       If it fails, specify the path using the PYTHON_LIBRARY variable
+WITH_PYTHON=OFF
+PYTHON_LIBRARY=""
+# PYTHON_LIBRARY="/usr/lib64/libpython2.5.so.1.0"
+
+# MESA graphics support:
+WITH_MESA=OFF
+
+#
+# No further editing below this line
+#------------------------------------------------------------------------------
+Script=${0##*/}
+
+usage() {
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
+
+usage: ${0##*/} [OPTION]
+options:
+  -fast      skip configure for repeated builds - use with caution
+  -mpi       with mpi (if not already enabled)
+  -python    with python (if not already enabled)
+  -mesa      with mesa (if not already enabled)
+  -verbose   verbose output in Makefiles
+  -help
+
+For finer control, the build stages can be also selected individually
+(mutually exclusive)
+  -config
+  -make
+  -install
+
+Build and install $PARAVIEW_SRC
+  - run from folder above the ParaView source folder or place the
+    ParaView source under \$WM_THIRD_PARTY_DIR
+
+USAGE
+   exit 1
+}
+
+# options based on the script name:
+case "$Script" in *-fast*)   CMAKE_SKIP=ON;; esac
+case "$Script" in *-mpi*)    WITH_MPI=ON;; esac
+case "$Script" in *-python*) WITH_PYTHON=ON;; esac
+case "$Script" in *-mesa*)   WITH_MESA=ON;; esac
+
+runCONFIG=true
+runMAKE=true
+runINSTALL=true
+
+# parse options
+while [ "$#" -gt 0 ]
+do
+    case "$1" in
+    -h | -help)
+        usage
+        ;;
+    -config)             # stage 1: config only
+        runCONFIG=true
+        runMAKE=false
+        runINSTALL=false
+        shift
+        ;;
+    -make)               # stage 2: make only
+        runCONFIG=false
+        runMAKE=true
+        runINSTALL=false
+        shift
+        ;;
+    -install)            # stage 3: install only
+        runCONFIG=false
+        runMAKE=false
+        runINSTALL=true
+        shift
+        ;;
+    -fast)               # shortcut for rebuild
+        runCONFIG=false
+        runMAKE=true
+        runINSTALL=true
+        shift
+        ;;
+    -mpi)
+        WITH_MPI=ON
+        shift
+        ;;
+    -python)
+        WITH_PYTHON=ON
+        shift
+        ;;
+    -mesa)
+        WITH_MESA=ON
+        shift
+        ;;
+    -verbose)
+        VERBOSE=ON
+        shift
+        ;;
+    *)
+        usage "unknown option/argument: '$*'"
+        ;;
+    esac
+done
+
+# Set configure options
+#~~~~~~~~~~~~~~~~~~~~~~
+addVerbosity        # verbose makefiles
+addMpiSupport       # set MPI-specific options
+addPythonSupport    # set Python-specific options
+addMesaSupport      # set MESA-specific options
+
+getPaths            # discover where things are or should be put
+
+# Build and install
+# ~~~~~~~~~~~~~~~~~
+[ $runCONFIG  = true ] && configParaView
+[ $runMAKE    = true ] && makeParaView
+[ $runINSTALL = true ] && installParaView
+
+echo "done"
+
+#------------------------------------------------------------------------------
diff --git a/bin/buildParaView3.5-cvs-python b/bin/buildParaView3.5-cvs-python
new file mode 120000
index 00000000000..d3ed3924a89
--- /dev/null
+++ b/bin/buildParaView3.5-cvs-python
@@ -0,0 +1 @@
+buildParaView3.5-cvs
\ No newline at end of file
diff --git a/bin/buildParaView3.3-cvs b/bin/tools/buildParaView3.3-cvs
similarity index 91%
rename from bin/buildParaView3.3-cvs
rename to bin/tools/buildParaView3.3-cvs
index 79d5bbc79d4..138de35166e 100755
--- a/bin/buildParaView3.3-cvs
+++ b/bin/tools/buildParaView3.3-cvs
@@ -34,8 +34,8 @@
 #------------------------------------------------------------------------------
 . $WM_PROJECT_DIR/bin/tools/buildParaViewFunctions
 
-PARAVIEW_SRC="ParaView3.3-cvs"
-PARAVIEW_MAJOR_VERSION="3.3"
+PARAVIEW_SRC=ParaView3.3-cvs
+PARAVIEW_MAJOR_VERSION=3.3
 
 # User options:
 # ~~~~~~~~~~~~~
@@ -65,14 +65,15 @@ usage() {
 
 usage: ${0##*/} [OPTION]
 options:
-  -fast      skip cmake for repeated builds - use with caution
+  -fast      skip configure for repeated builds - use with caution
   -mpi       with mpi (if not already enabled)
   -python    with python (if not already enabled)
   -mesa      with mesa (if not already enabled)
-  -verbose   verbose cmake output
+  -verbose   verbose output in Makefiles
   -help
 
-For finer control, the build stages can be selected (mutually exclusive)
+For finer control, the build stages can be also selected individually
+(mutually exclusive)
   -config
   -make
   -install
@@ -150,7 +151,7 @@ done
 
 # Set configure options
 #~~~~~~~~~~~~~~~~~~~~~~
-addVerbosity
+addVerbosity        # verbose makefiles
 addMpiSupport       # set MPI-specific options
 addPythonSupport    # set Python-specific options
 addMesaSupport      # set MESA-specific options
@@ -159,8 +160,8 @@ getPaths            # discover where things are or should be put
 
 # Build and install
 # ~~~~~~~~~~~~~~~~~
-[ $runCONFIG = true ] && configParaView
-[ $runMAKE = true ] && makeParaView
+[ $runCONFIG  = true ] && configParaView
+[ $runMAKE    = true ] && makeParaView
 [ $runINSTALL = true ] && installParaView
 
 echo "done"
diff --git a/bin/tools/buildParaViewFunctions b/bin/tools/buildParaViewFunctions
index c8a500748c8..77381e69982 100644
--- a/bin/tools/buildParaViewFunctions
+++ b/bin/tools/buildParaViewFunctions
@@ -208,7 +208,7 @@ configParaView()
     echo cmake \
         -DCMAKE_INSTALL_PREFIX:PATH=$ParaView_DIR \
         $CMAKE_VARIABLES \
-        $ParaView_INST_DIR
+        ../..
     echo
     echo "----"
     echo
@@ -217,7 +217,7 @@ configParaView()
     cmake \
         -DCMAKE_INSTALL_PREFIX:PATH=$ParaView_DIR \
         $CMAKE_VARIABLES \
-        $ParaView_INST_DIR
+        ../..
 
 }
 
@@ -232,106 +232,123 @@ makeParaView()
         WM_NCOMPPROCS=$(egrep "^processor" /proc/cpuinfo | wc -l)
         [ $WM_NCOMPPROCS -le 8 ] || WM_NCOMPPROCS=8
 
-        make -j $WM_NCOMPPROCS
+        time make -j $WM_NCOMPPROCS
     else
-        make
+        time make
     fi
-    make install
     echo "    Done make"
 }
 
 
 # adjust hard-links
 # Note: use loop with grep to avoid touching too many files
-fixCMakeHardLinks()
+fixHardLinks()
 {
-    fileSpec=$1
+    envName=$1
     string=$2
-    envName=$3
+    shift 2
 
-    echo -n "    for \$$envName "
-    for i in $(find . -type f -iname "$fileSpec")
+    echo "-- Replacing path hard links for \$$envName"
+
+    for fileSpec
     do
-        if grep -q "$string" $i
-        then
-            echo -n "#"
-            sed -i "s,$string,\$ENV{$envName},g" $i
-        fi
+        echo -n "   $fileSpec: "
+        for i in $(find . -type f -iname "$fileSpec")
+        do
+            if grep -q "$string" $i
+            then
+                echo -n "#"
+                sed -i "s,$string,\$ENV{$envName},g" $i
+            fi
+        done
+        echo
     done
-    echo
 }
 
 
-installParaView()
+fixCMakeFiles()
 {
-    [ -e "$ParaView_DIR/bin/paraview" ] || {
-        echo "    Cannot install - no paraview binary found"
-        return
-    }
-
     # change to build/install folder
     cd $ParaView_DIR || exit 1
 
-    echo "    Installing ParaView"
-    echo "    Replacing path hard links"
+    # Replace path with env variable: ParaView_DIR
+    fixHardLinks ParaView_DIR "$ParaView_DIR" '*.cmake'
 
-    # Replace local ParaView_INST_DIR path with ParaView_INST_DIR
-    # environment variable
-    fixCMakeHardLinks '*.cmake' "$ParaView_INST_DIR" ParaView_INST_DIR
+    # Replace path with env variable: ParaView_INST_DIR
+    fixHardLinks ParaView_INST_DIR "$ParaView_INST_DIR" '*.cmake'
 
-    # Replace local MPI_ARCH_PATH path with MPI_ARCH_PATH
-    # environment variable
+    # Replace path with env variable: MPI_ARCH_PATH
     if [ "$WITH_MPI" = ON ]
     then
-        fixCMakeHardLinks '*.cmake' "$MPI_ARCH_PATH" MPI_ARCH_PATH
+        fixHardLinks MPI_ARCH_PATH "$MPI_ARCH_PATH" '*.cmake'
     fi
 
-    # Replace local CMAKE_HOME path with CMAKE_HOME
-    # environment variable
+    # Replace path with env variable: CMAKE_HOME
     if [ -r "$CMAKE_HOME" ]
     then
-        fixCMakeHardLinks '*cmake*' "$CMAKE_HOME" CMAKE_HOME
+        fixHardLinks CMAKE_HOME "$CMAKE_HOME" '*cmake*'
     fi
 
-    # Replace local WM_COMPILER_DIR path with WM_COMPILER_DIR
-    # environment variable
-    fixCMakeHardLinks '*cmake*' "$WM_COMPILER_DIR" WM_COMPILER_DIR
+    # Replace path with env variable: WM_COMPILER_DIR
+    # (include cmake.check_cache)
+    ## SKIP THIS - it (it always triggers a complete rebuild)
+    ## when using cmake-2.6.2
+    ## fixHardLinks WM_COMPILER_DIR "$WM_COMPILER_DIR" '*cmake*'
+}
+
+
+installParaView()
+{
+    [ -e "$ParaView_DIR/bin/paraview" ] || {
+        echo "    Cannot install - no paraview binary found"
+        return
+    }
+
+    # change to build/install folder
+    cd $ParaView_DIR || exit 1
+
+    echo "    Installing ParaView"
+    ## This triggers a partial rebuild, but might let us find our files
+    ## fixCMakeFiles
 
-    # create a softlink to the $ParaView_DIR/bin folder
-    # - workaround for chosen install location
-    echo "    Creating lib/paraview-$PARAVIEW_MAJOR_VERSION soft link to 'bin'"
+    # skip the normal 'make install' in favour of simply creating
+    # a softlink to the $ParaView_DIR/bin folder
+    # - this seems to keep things portable (except documentation)
+    echo "    Creating link  lib/paraview-$PARAVIEW_MAJOR_VERSION/ -> bin/ "
     rm -rf lib/paraview-$PARAVIEW_MAJOR_VERSION
-    [ -d lib ] || mkdir lib
+    mkdir lib 2>/dev/null
     ( cd lib && ln -s ../bin paraview-$PARAVIEW_MAJOR_VERSION )
 
     # info on symlinks to screen
-    echo ""
-    echo "    ---"
-    echo "    Installation complete"
-    echo "    Set environment variables:"
-    echo "    - ParaView_INST_DIR to $ParaView_INST_DIR"
-    echo "    - ParaView_DIR to $ParaView_DIR"
-    echo "    - PV_PLUGIN_PATH to $FOAM_LIBBIN"
-    echo "    Add $ParaView_DIR/bin to PATH"
-    # echo "   Add $ParaView_INST_DIR/lib to LD_LIBRARY_PATH"
-    echo "    ---"
+cat << INFO
+    ---
+    Installation complete
+    Set environment variables:
+
+        export ParaView_INST_DIR=$ParaView_INST_DIR
+        export ParaView_DIR=$ParaView_DIR
+        export PV_PLUGIN_PATH=$FOAM_LIBBIN
+        export PATH=\$ParaView_DIR/bin:\$PATH
+
+    ---
+    NB: if you move the paraview installation, you will need to change this file
+        \$ParaView_DIR/bin/pqClientDocFinder.txt
+    ---
+INFO
 }
 
 
 # clear all the variables used before using any of the functions
 
 unset VERBOSE
-unset WITH_MPI
-unset WITH_MESA
-unset WITH_PYTHON
-unset PYTHON_LIBRARY
+unset WITH_MPI WITH_MESA
+unset WITH_PYTHON PYTHON_LIBRARY
 unset CMAKE_VARIABLES
 unset OBJ_ADD
 
 # start with these general settings
 addCMakeVariable  VTK_USE_TK=FALSE
-addCMakeVariable  BUILD_SHARED_LIBS:BOOL=ON
-addCMakeVariable  VTK_USE_RPATH:BOOL=OFF
+addCMakeVariable  BUILD_SHARED_LIBS:BOOL=ON VTK_USE_RPATH:BOOL=OFF
 addCMakeVariable  CMAKE_BUILD_TYPE:STRING=Release
 
 # ----------------------------------------------------------------- end-of-file
diff --git a/etc/apps/paraview3/bashrc b/etc/apps/paraview3/bashrc
index 21c750a10b9..9dc6c7683c7 100644
--- a/etc/apps/paraview3/bashrc
+++ b/etc/apps/paraview3/bashrc
@@ -26,16 +26,16 @@
 #     paraview3/bashrc
 #
 # Description
-#     Setup file for ParaView3.
+#     Setup file for paraview-3.x
 #     Sourced from OpenFOAM-?.?/etc/bashrc
 #
 #------------------------------------------------------------------------------
 
+# determine the cmake to be used
 unset CMAKE_HOME
 for cmake in cmake-2.6.2 cmake-2.4.6
 do
     cmake=$WM_THIRD_PARTY_DIR/$cmake/platforms/$WM_ARCH
-
     if [ -r $cmake ]
     then
         export CMAKE_HOME=$cmake
@@ -43,26 +43,30 @@ do
         break
     fi
 done
-unset cmake
 
-export ParaView_VERSION="3.3-cvs"
+paraviewMajor=paraview-3.5
+export ParaView_VERSION=3.5-cvs
 
-export ParaView_INST_DIR=$WM_THIRD_PARTY_DIR/ParaView$ParaView_VERSION
+export ParaView_INST_DIR=$WM_THIRD_PARTY_DIR/paraview-$ParaView_VERSION
 export ParaView_DIR=$ParaView_INST_DIR/platforms/$WM_ARCH$WM_COMPILER
 
-if [ "$PYTHONPATH" ]
+# add in python libraries if required
+paraviewPython=$ParaView_DIR/Utilities/VTKPythonWrapping
+if [ -r $paraviewPython ]
 then
-    export PYTHONPATH=$PYTHONPATH:$ParaView_DIR/Utilities/VTKPythonWrapping:$ParaView_DIR/lib/paraview-3.3
-else
-    export PYTHONPATH=$ParaView_DIR/Utilities/VTKPythonWrapping:$ParaView_DIR/lib/paraview-3.3
+    if [ "$PYTHONPATH" ]
+    then
+        export PYTHONPATH=$PYTHONPATH:$paraviewPython:$ParaView_DIR/lib/$paraviewMajor
+    else
+        export PYTHONPATH=$paraviewPython:$ParaView_DIR/lib/$paraviewMajor
+    fi
 fi
 
-
 if [ -r $ParaView_DIR ]
 then
     export PATH=$ParaView_DIR/bin:$PATH
-    export LD_LIBRARY_PATH=$ParaView_DIR/bin:$LD_LIBRARY_PATH
     export PV_PLUGIN_PATH=$FOAM_LIBBIN
 fi
 
+unset cmake paraviewMajor paraviewPython
 # -----------------------------------------------------------------------------
diff --git a/etc/apps/paraview3/cshrc b/etc/apps/paraview3/cshrc
index 636b10eb75d..943371ff3e7 100644
--- a/etc/apps/paraview3/cshrc
+++ b/etc/apps/paraview3/cshrc
@@ -26,34 +26,42 @@
 #     paraview3/cshrc
 #
 # Description
-#     Startup File for Paraview3
+#     Startup File for paraview-3.x
 #     Sourced from OpenFOAM-?.?/etc/cshrc
 #
 #------------------------------------------------------------------------------
 
-setenv CMAKE_HOME $WM_THIRD_PARTY_DIR/cmake-2.4.6/platforms/$WM_ARCH
+# determine the cmake to be used
+unsetenv CMAKE_HOME
+foreach cmake ( cmake-2.6.2 cmake-2.4.6 )
+    set cmake=$WM_THIRD_PARTY_DIR/$cmake/platforms/$WM_ARCH
+    if ( -r $cmake ) then
+        setenv CMAKE_HOME $cmake
+        set path=($CMAKE_HOME/bin $path)
+        break
+    endif
+end
 
-if ( -r $CMAKE_HOME ) then
-    set path=($CMAKE_HOME/bin $path)
-else
-    unsetenv CMAKE_HOME
-endif
-
-setenv ParaView_VERSION 3.3-cvs
+set paraviewMajor=paraview-3.5
+setenv ParaView_VERSION 3.5-cvs
 
-setenv ParaView_INST_DIR $WM_THIRD_PARTY_DIR/ParaView$ParaView_VERSION
+setenv ParaView_INST_DIR $WM_THIRD_PARTY_DIR/paraview-$ParaView_VERSION
 setenv ParaView_DIR $ParaView_INST_DIR/platforms/$WM_ARCH$WM_COMPILER
 
-if ($?PYTHONPATH) then
-    setenv PYTHONPATH ${PYTHONPATH}:$ParaView_DIR/Utilities/VTKPythonWrapping:$ParaView_DIR/lib/paraview-3.3
-else
-    setenv PYTHONPATH $ParaView_DIR/Utilities/VTKPythonWrapping:$ParaView_DIR/lib/paraview-3.3
+# add in python libraries if required
+set paraviewPython=$ParaView_DIR/Utilities/VTKPythonWrapping
+if ( -r $paraviewPython ) then
+    if ($?PYTHONPATH) then
+        setenv PYTHONPATH ${PYTHONPATH}:$paraviewPython:$ParaView_DIR/lib/${paraviewMajor}
+    else
+        setenv PYTHONPATH $paraviewPython:$ParaView_DIR/lib/${paraviewMajor}
+    endif
 endif
 
 if ( -r $ParaView_INST_DIR ) then
     set path=($ParaView_DIR/bin $path)
-    setenv LD_LIBRARY_PATH $ParaView_DIR/bin:$LD_LIBRARY_PATH
     setenv PV_PLUGIN_PATH $FOAM_LIBBIN
 endif
 
+unset cmake paraviewMajor paraviewPython
 # -----------------------------------------------------------------------------
-- 
GitLab