build_visit_BGQ 38.6 KB
Newer Older
whitlocb's avatar
whitlocb committed
1 2
#!/bin/bash

whitlocb's avatar
whitlocb committed
3
VISIT_VERSION="2.10.0"
whitlocb's avatar
whitlocb committed
4 5 6 7 8 9 10

################################################################################
## DEFAULT VALUES FOR VARIABLES
################################################################################

# Global variables
ARCH=linux-ppc64_gcc-4.4
whitlocb's avatar
whitlocb committed
11 12
PREFIXARCH=linux-ppc64-BGQ
PREFIX="$PWD/$PREFIXARCH"
whitlocb's avatar
whitlocb committed
13

whitlocb's avatar
whitlocb committed
14
BG_CC=bgxlc_r
15
BG_C_OPT_FLAGS="-qarch=qp -qtune=qp"
whitlocb's avatar
whitlocb committed
16
BG_CXX=bgxlC_r
17
BG_CXX_OPT_FLAGS="-qarch=qp -qtune=qp"
whitlocb's avatar
whitlocb committed
18 19 20 21 22

# Compiler used for Mesa.
BG_GNU_CC=powerpc64-bgq-linux-gcc
BG_GNU_CXX=powerpc64-bgq-linux-g++

whitlocb's avatar
whitlocb committed
23
BG_MPI_GNU_CC=mpicc # not used
whitlocb's avatar
whitlocb committed
24 25
BG_MPI_GNU_CXX=mpicxx

26 27 28 29
BG_MPI_CC=mpixlc_r
BG_MPI_C_OPT_FLAGS="-qarch=qp -qtune=qp"
BG_MPI_CXX=mpixlcxx_r
BG_MPI_CXX_OPT_FLAGS="-qarch=qp -qtune=qp"
whitlocb's avatar
whitlocb committed
30

31
BUILD_MODE="Release"
whitlocb's avatar
whitlocb committed
32 33 34 35 36
CC=gcc
C_OPT_FLAGS=""
CXX=g++
CXX_OPT_FLAGS=""
EXTRA_ARGS=""
whitlocb's avatar
whitlocb committed
37
GROUP="bdiv"
whitlocb's avatar
whitlocb committed
38
INSTALLATION_BUILD_DIR="builds_static"
whitlocb's avatar
whitlocb committed
39 40
IO_PACKAGES="--szip --hdf5 --silo"
VISIT_SELECTED_DATABASE_PLUGINS="BOV;Cale;CaleHDF5;Curve2D;EnSight;Miranda;PDB;PlainText;SAMRAI;Silo;VTK"
whitlocb's avatar
whitlocb committed
41 42 43 44 45 46 47
MAKE=make
MAKE_OPT_FLAGS=""
NO_VISIT=""
DO_SVN=""
DO_SVN_ANON=""
SVN=""
TAR=tar
48
THIRD_PARTY_PATH="`pwd`/thirdparty_static"
whitlocb's avatar
whitlocb committed
49
TARBALL="--tarball visit${VISIT_VERSION}.tar.gz"
whitlocb's avatar
whitlocb committed
50

whitlocb's avatar
whitlocb committed
51 52
export CMAKE_VERSION=3.0.2
export CMAKE_SHORT_VERSION=3.0
whitlocb's avatar
whitlocb committed
53 54 55 56

export MESA_FILE=${MESA_FILE:-"MesaLib-7.8.2.tar.gz"}
export MESA_VERSION=${MESA_VERSION:-"7.8.2"}
export MESA_BUILD_DIR=${MESA_BUILD_DIR:-"Mesa-7.8.2"}
57
export MESA_URL="http://visit.ilight.com/svn/visit/trunk/third_party"
whitlocb's avatar
whitlocb committed
58

whitlocb's avatar
whitlocb committed
59 60 61
export ZLIB_FILE=${ZLIB_FILE:-"zlib-1.2.8.tar.gz"}
export ZLIB_VERSION=${ZLIB_VERSION:-"1.2.8"}
export ZLIB_BUILD_DIR=${ZLIB_BUILD_DIR:-"zlib-1.2.8"}
whitlocb's avatar
whitlocb committed
62 63
export ZLIB_URL="http://zlib.net/"

whitlocb's avatar
whitlocb committed
64
export VTK_VERSION="6.1.0"
whitlocb's avatar
whitlocb committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

################################################################################
## CODE BORROWED FROM build_visit
################################################################################

#First step download the support directory from svn repository..
bv_PATH=`dirname $0`

bv_PREFIX=$bv_PATH/bv_support/

function configure_support_files
{
    if [ ! -d $bv_PREFIX ]; then 
        #check current directory
        bv_PREFIX=$PWD/bv_support/

        if [ ! -d $bv_PREFIX ]; then 

            for choice in `echo "curl wget svn"`
            do
                echo "Trying to fetch support files using: $choice"

                #if choice successful then exit, else try next..
88
                webaddr="http://visit.ilight.com/svn/visit/trunk/src/svn_bin/bv_support/"
whitlocb's avatar
whitlocb committed
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
                tmp_choice=`which $choice`

                if [ $? != 0 ]; then
                    continue
                fi
                if [[ $choice == "curl" ]]; then
                    tmp_curl=`curl -s ${webaddr}/ | grep 'sh\|xml' | grep li|sed s/.*bv_/bv_/g | sed -e s/\.sh.*/\.sh/g | sed -e s/.*href\=\"//g;`

                    if [ $? != 0 ]; then 
                        continue
                    fi

                    mkdir -p bv_support_tmp
                    is_successful=1
                    #fetch each file..
                    for curl_files in `echo $tmp_curl`
                    do 
                        curl -s ${webaddr}/${curl_files} -o bv_support_tmp/$curl_files 
                        if [ $? != 0 ]; then
                            is_successful=0
                            break
                        fi
                    done

                    #if not successful cleanup and try next option..
                    if [ $is_successful == 0 ]; then 
                        rm -fR bv_support_tmp
                    else
                        mv bv_support_tmp bv_support
                    fi
                elif [[ $choice == "wget" ]]; then
                    wget -r -nH --cut-dirs=5 --no-parent --reject="index.html" -q ${webaddr}
                else
                    svn co ${webaddr} bv_support
                fi

                if [ ! -d $bv_PREFIX ]; then
                    echo "$choice failed to retrieve support files"
                else
                    echo "Success. downloaded support, continuing"
                    break
                fi
            done
        fi

        if [ ! -d $bv_PREFIX ]; then
            echo "Failed to detect or fetch support files, please contact visit-users mailing list with error. Quitting..."
            exit 2
        fi
    fi
}

#configure the support files if needed..
configure_support_files

#import initialize and run functions..
. $bv_PREFIX/bv_main.sh

#import helper functions..
. $bv_PREFIX/helper_funcs.sh

whitlocb's avatar
whitlocb committed
150 151 152 153 154 155 156 157 158
function banner
{
    echo "===================================================================================="
    echo "$1"
    echo "===================================================================================="

    return 0
}

whitlocb's avatar
whitlocb committed
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
################################################################################
## build_mesa_BGQ
################################################################################

function build_mesa_BGQ
{
    PF=$THIRD_PARTY_PATH/mesa/$MESA_VERSION/${ARCH}_BGQ

    #
    # Test whether Mesa has already been installed.
    #
    if test -d $PF ; then
        return 0
    fi

    #
    # Download file if needed
    #
    if ! test -e $MESA_FILE ; then
        download_file $MESA_FILE $MESA_URL
        if [[ $? == 1 ]] ; then
            warn "Unable to download Mesa sources $MESA_FILE. Giving Up!"
            return 1
        fi
    fi

    #
    # prepare build dir
    #
    prepare_build_dir $MESA_BUILD_DIR $MESA_FILE
    untarred_mesa=$?

    if [[ $untarred_mesa == -1 ]] ; then
        warn "Unable to prepare Mesa build directory. Giving Up!"
        return 1
    fi

whitlocb's avatar
whitlocb committed
196 197 198 199 200 201 202 203 204
    if test -e $MESA_BUILD_DIR ; then
        echo "Moving $MESA_BUILD_DIR into ${INSTALLATION_BUILD_DIR}_BGQ"
        if test -e ${INSTALLATION_BUILD_DIR}_BGQ/$MESA_BUILD_DIR ; then
            rm -rf ${INSTALLATION_BUILD_DIR}_BGQ/$MESA_BUILD_DIR
        fi
        mv $MESA_BUILD_DIR ${INSTALLATION_BUILD_DIR}_BGQ/$MESA_BUILD_DIR
        cd ${INSTALLATION_BUILD_DIR}_BGQ
    fi

whitlocb's avatar
whitlocb committed
205 206 207
    #
    # Build bluegene-visit-osmesa config.
    #
whitlocb's avatar
whitlocb committed
208
    banner "Building Mesa (Compute Node)"
whitlocb's avatar
whitlocb committed
209 210 211 212 213 214 215 216 217 218
    cd $MESA_BUILD_DIR || error "Couldn't cd to mesa build dir."
    if test -e configs/bluegene-visit-osmesa ; then
        rm -f configs/bluegene-visit-osmesa
    fi
    cat << \EOF > configs/bluegene-visit-osmesa
include $(TOP)/configs/default
CONFIG_NAME = bluegene-visit-osmesa
# Compiler and flags
APP_CC = gcc
APP_CXX = g++
whitlocb's avatar
whitlocb committed
219 220
CFLAGS = -O3 -DNDEBUG -pedantic -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE
CXXFLAGS = -O3 -DNDEBUG -pedantic -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE
whitlocb's avatar
whitlocb committed
221
MKLIB_OPTIONS = -static
222
GL_LIB_NAME = libUsedToBeCalledGL.a
whitlocb's avatar
whitlocb committed
223 224 225
GLU_LIB_NAME = libGLU.a
GLUT_LIB_NAME = libglut.a
GLW_LIB_NAME = libGLw.a
226 227
OSMESA_LIB = OSMesa
OSMESA_LIB_NAME = libOSMesa.a
whitlocb's avatar
whitlocb committed
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
# Directories
SRC_DIRS = glsl mesa glu
DRIVER_DIRS = osmesa
PROGRAM_DIRS = osdemos
# Dependencies
GL_LIB_DEPS =
OSMESA_LIB_DEPS = -lm
GLU_LIB_DEPS = -L$(TOP)/$(LIB_DIR) -l$(OSMESA_LIB)
GLUT_LIB_DEPS =
GLW_LIB_DEPS =
APP_LIB_DEPS = -lOSMesa -lGLU -lm
EOF

    # Append the bluegene compilers and install location.
    echo "CC=$BG_GNU_CC" >> configs/bluegene-visit-osmesa
    echo "CXX=$BG_GNU_CXX" >> configs/bluegene-visit-osmesa
    echo "INSTALL_DIR=$PF" >> configs/bluegene-visit-osmesa

    sed "s/bluegene-osmesa/bluegene-osmesa bluegene-visit-osmesa/g" Makefile > Makefile.visit
    mv Makefile.visit Makefile

    cat configs/bluegene-visit-osmesa

    #
    # Build Mesa.
    #
    info "Building OSMesa as libGL replacement ..."
    ${MAKE} bluegene-visit-osmesa ${MAKE_OPT_FLAGS}
    if [[ $? != 0 ]] ; then
        warn "Mesa: 'make bluegene-visit-osmesa' failed.  Giving up"
        return 1
    fi
    info "Installing OSMesa as libGL replacement ..."
    ${MAKE} install
    if [[ $? != 0 ]] ; then
        warn "Mesa: 'make install' failed.  Giving up"
        return 1
    fi

    # Some versions of Mesa erroneously install GLEW as well.  We need to make
    # sure we get VisIt's GLEW when we include it, so remove the ones Mesa
    # installs.
    rm -f $PF/include/GL/gl*ew.h

    if [[ $? != 0 ]] ; then
        warn "Mesa build failed.  Giving up"
        return 1
    fi

    chmod -R ug+w,a+rX "$THIRD_PARTY_PATH/mesa"
    chgrp -R ${GROUP} "$THIRD_PARTY_PATH/mesa"

    info "Done with Mesa"
    return 0
}

function write_platform_file
{
    # Remove the platform file if it exists.
    if test -e $1 ; then
        rm -f $1
    fi

    # Write boilerplate platform file.
    cat << \EOF > $1
# From BlueGeneP-base.cmake

#
# For BGQ builds, we're cross compiling, but we don't want to re-root things
# (e.g. with CMAKE_FIND_ROOT_PATH) because users may have libraries anywhere on
# the shared filesystems, and this may lie outside the root.  Instead, we set the
# system directories so that the various system BGQ CNK library locations are
# searched first.  This is not the clearest thing in the world, given IBM's driver
# layout, but this should cover all the standard ones.
#
set(CMAKE_SYSTEM_LIBRARY_PATH
  /bgsys/drivers/ppcfloor/comm/default/lib                # default comm layer (used by mpi compiler wrappers)
  /bgsys/drivers/ppcfloor/comm/sys/lib                    # DCMF, other lower-level comm libraries
  /bgsys/drivers/ppcfloor/runtime/SPI                     # other low-level stuff
  /bgsys/drivers/ppcfloor/gnu-linux/lib                   # CNK python installation directory
  /bgsys/drivers/ppcfloor/gnu-linux/powerpc-BGQ-linux/lib # CNK Linux image -- standard runtime libs, pthread, etc.
)

#
# This adds directories that find commands should specifically ignore for cross compiles.
# Most of these directories are the includeand lib directories for the frontend on BG/P systems.
# Not ignoring these can cause things like FindX11 to find a frontend PPC version mistakenly.
# We use this on BG instead of re-rooting because backend libraries are typically strewn about
# the filesystem, and we can't re-root ALL backend libraries to a single place.
#
set(CMAKE_SYSTEM_IGNORE_PATH
  /lib             /lib64             /include
  /usr/lib         /usr/lib64         /usr/include
  /usr/local/lib   /usr/local/lib64   /usr/local/include
  /usr/X11/lib     /usr/X11/lib64     /usr/X11/include
  /usr/lib/X11     /usr/lib64/X11     /usr/include/X11
  /usr/X11R6/lib   /usr/X11R6/lib64   /usr/X11R6/include
  /usr/X11R7/lib   /usr/X11R7/lib64   /usr/X11R7/include
)

#
# Indicate that this is a unix-like system
#
set(UNIX 1)

#
# Library prefixes, suffixes, extra libs.
#
set(CMAKE_LINK_LIBRARY_SUFFIX "")
set(CMAKE_STATIC_LIBRARY_PREFIX "lib")     # lib
set(CMAKE_STATIC_LIBRARY_SUFFIX ".a")      # .a

set(CMAKE_SHARED_LIBRARY_PREFIX "lib")     # lib
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")     # .so
set(CMAKE_EXECUTABLE_SUFFIX "")            # .exe
set(CMAKE_DL_LIBS "dl")

#
# This macro needs to be called for dynamic library support.  Unfortunately on BGQ,
# We can't support both static and dynamic links in the same platform file.  The
# dynamic link platform file needs to call this explicitly to set up dynamic linking.
#
macro(__BlueGeneP_set_dynamic_flags compiler_id lang)
  if (${compiler_id} STREQUAL XL)
    # Flags for XL compilers if we explicitly detected XL
    set(CMAKE_${lang}_COMPILE_OPTIONS_PIC            "-qpic")
    set(CMAKE_${lang}_COMPILE_OPTIONS_PIE            "-qpie")
    set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-qpic")
    set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-qmkshrobj -qnostaticlink")
    set(BGQ_${lang}_DYNAMIC_EXE_FLAGS                "-qnostaticlink -qnostaticlink=libgcc")
  else()
    # Assume flags for GNU compilers (if the ID is GNU *or* anything else).
    set(CMAKE_${lang}_COMPILE_OPTIONS_PIC            "-fPIC")
    set(CMAKE_${lang}_COMPILE_OPTIONS_PIE            "-fPIE")
    set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS           "-fPIC")
    set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS    "-shared")
    set(BGQ_${lang}_DYNAMIC_EXE_FLAGS                "-dynamic")
  endif()

  # Both toolchains use the GNU linker on BG/P, so these options are shared.
  set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG      "-Wl,-rpath,")
  set(CMAKE_SHARED_LIBRARY_RPATH_LINK_${lang}_FLAG   "-Wl,-rpath-link,")
  set(CMAKE_SHARED_LIBRARY_SONAME_${lang}_FLAG       "-Wl,-soname,")
  set(CMAKE_EXE_EXPORTS_${lang}_FLAG                 "-Wl,--export-dynamic")
  set(CMAKE_SHARED_LIBRARY_LINK_${lang}_FLAGS        "")  # +s, flag for exe link to use shared lib
  set(CMAKE_SHARED_LIBRARY_RUNTIME_${lang}_FLAG_SEP  ":") # : or empty

  set(BGQ_${lang}_DEFAULT_EXE_FLAGS
    "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
  set(CMAKE_${lang}_LINK_EXECUTABLE
    "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGQ_${lang}_DYNAMIC_EXE_FLAGS} ${BGQ_${lang}_DEFAULT_EXE_FLAGS}")
endmacro()

#
# This macro needs to be called for static builds.  Right now it just adds -Wl,-relax
# to the link line.
#
macro(__BlueGeneQ_set_static_flags compiler_id lang)
  set(BGQ_${lang}_DEFAULT_EXE_FLAGS
    "<FLAGS> <CMAKE_${lang}_LINK_FLAGS> <LINK_FLAGS> <OBJECTS>  -o <TARGET> <LINK_LIBRARIES>")
  set(CMAKE_${lang}_LINK_EXECUTABLE
    "<CMAKE_${lang}_COMPILER> -Wl,-relax ${BGQ_${lang}_DEFAULT_EXE_FLAGS}")
endmacro()

# From BlueGeneP-static.cmake, which has a broken include
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS FALSE)
set(CMAKE_FIND_LIBRARY_PREFIXES "lib")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

# Use the XL compilers
__BlueGeneQ_set_static_flags(XL CXX)
EOF
  
    return 0
}

#
# Build cmake with the regular compiler. Make a link to the regular version
# so we can have a "BGQ" version too.
#
function build_cmake
{
    if test -d $THIRD_PARTY_PATH/cmake/$CMAKE_VERSION/${ARCH}_BGQ ; then
        info "CMake is already installed."
        return 0
    fi

    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
417
        MAKEARGS="--makeflags \"$MAKE_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
418 419 420 421 422 423 424 425 426 427
    fi
    CFLAGSARGS=""
    if test -n "$C_OPT_FLAGS" ; then
        CFLAGSARGS="--cflags \"$C_OPT_FLAGS\""
    fi
    CXXFLAGSARGS=""
    if test -n "$CXX_OPT_FLAGS" ; then
        CXXFLAGSARGS="--cxxflags \"$CXX_OPT_FLAGS\""
    fi

whitlocb's avatar
whitlocb committed
428
    banner "Building CMake"
429 430
    (export BUILD_VISIT_BGQ="yes"
     eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
431
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
432
        --console --static --no-visit $SVN $TARBALL\
whitlocb's avatar
whitlocb committed
433 434 435
        --no-thirdparty --cmake\
        --log-file building_cmake.txt \
        --arch "${ARCH}" \
whitlocb's avatar
whitlocb committed
436
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
437 438 439
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}" \
440 441 442
        --cc $CC $CFLAGSARGS  \
        --cxx $CXX $CXXFLAGSARGS  $MAKEARGS \
        --group $GROUP || error "Cannot build cmake for login node.")
whitlocb's avatar
whitlocb committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465

   # Create a symlink to make a "BGQ" version of the login node cmake.
   STARTDIR=`pwd`
   cd $THIRD_PARTY_PATH/cmake/$CMAKE_VERSION
   if ! test -e "${ARCH}_BGQ" ; then
       ln -s $ARCH "${ARCH}_BGQ"
   fi
   cd $STARTDIR

   # The BlueGeneP-static-XL-CXX platform files are hosed in cmake's install.
   # Overwrite.
   TOOLCHAIN="$THIRD_PARTY_PATH/cmake/$CMAKE_VERSION/$ARCH/share/cmake-$CMAKE_SHORT_VERSION/Modules/Platform/BlueGeneP-static-XL-CXX.cmake"
   write_platform_file "$TOOLCHAIN"

   cd $STARTDIR

   return 0
}

function build_zlib_BGQ
{
    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
466
        MAKEARGS="--makeflags \"$MAKE_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
467 468 469
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
470
        CFLAGSARGS="--cflag \"${BG_C_OPT_FLAGS}\""
whitlocb's avatar
whitlocb committed
471 472 473
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
474
        CXXFLAGSARGS="--cxxflag \"${BG_CXX_OPT_FLAGS}\""
whitlocb's avatar
whitlocb committed
475 476 477
    fi

    # Build some packages that require GNU compilers.
whitlocb's avatar
whitlocb committed
478
    banner "Building zlib (Compute Node)"
479
    (eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
480
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
481
        --console --static --no-visit $SVN $TARBALL --engine-only \
whitlocb's avatar
whitlocb committed
482 483
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
whitlocb's avatar
whitlocb committed
484
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
485 486 487 488 489
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}_BGQ" \
        --cc $BG_CC $CFLAGSARGS \
        --cxx $BG_CXX $CXXFLAGSARGS $MAKEARGS \
whitlocb's avatar
whitlocb committed
490
        --no-thirdparty --zlib \
491
        --group $GROUP)
whitlocb's avatar
whitlocb committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505
    if [[ $? != 0 ]] ; then
        warn "ZLIB build failed.  Giving up"
        return 1
    fi

    return 0
}

function build_vtk_BGQ
{
    # Come up with some extra arguments for VTK's cmake line.
    MESADIR="$THIRD_PARTY_PATH/mesa/$MESA_VERSION/${ARCH}_BGQ"
    ZLIBDIR="$THIRD_PARTY_PATH/zlib/$ZLIB_VERSION/${ARCH}_BGQ"
    VTKDIR="$THIRD_PARTY_PATH/vtk/$VTK_VERSION/${ARCH}_BGQ"
whitlocb's avatar
whitlocb committed
506
    VTK_SRC_DIR="${INSTALLATION_BUILD_DIR}_BGQ/VTK-${VTK_VERSION}"
whitlocb's avatar
whitlocb committed
507 508 509 510 511 512 513 514 515 516
    VTK_BUILD_DIR="${INSTALLATION_BUILD_DIR}_BGQ/VTK-${VTK_VERSION}-build"

    # If the VTK installation directory already exists, return.
    if test -d $VTKDIR ; then
        info "VTK is already installed."
        return 0
    fi

    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
517
        MAKEARGS="--makeflags \"$MAKE_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
518 519 520
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
521
        CFLAGSARGS="--cflags \"$BG_C_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
522 523 524
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
525
        CXXFLAGSARGS="--cxxflags \"$BG_CXX_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
526 527 528
    fi

    # Form extra arguments that we'll pass to cmake for VTK.
whitlocb's avatar
whitlocb committed
529
    vopts="-DCMAKE_CROSSCOMPILING:BOOL=ON -DVTK_OPENGL_HAS_OSMESA:BOOL=ON"
whitlocb's avatar
whitlocb committed
530
    vopts="${vopts} -DOPENGL_INCLUDE_DIR:PATH=$MESADIR/include"
531
    vopts="${vopts} -DOPENGL_gl_LIBRARY:PATH=$MESADIR/lib/libOSMesa.a"
whitlocb's avatar
whitlocb committed
532 533
    vopts="${vopts} -DOPENGL_glu_LIBRARY:PATH=$MESADIR/lib/libGLU.a"
    vopts="${vopts} -DVTK_USE_X:BOOL=OFF"
534
    vopts="${vopts} -DOSMESA_LIBRARY:FILEPATH=$MESADIR/lib/libOSMesa.a"
whitlocb's avatar
whitlocb committed
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552
    vopts="${vopts} -DOSMESA_INCLUDE_DIR:FILEPATH=$MESADIR/include"

    vopts="${vopts} -DVTK_USE_SYSTEM_ZLIB:BOOL=ON"
    vopts="${vopts} -DZLIB_INCLUDE_DIR:PATH=$ZLIBDIR/include"
    vopts="${vopts} -DZLIB_LIBRARY:FILEPATH=$ZLIBDIR/lib/libz.a"

    vopts="${vopts} -DCMAKE_REQUIRE_LARGE_FILE_SUPPORT:INTERNAL=1"
    vopts="${vopts} -DVTK_TYPE_CHAR_IS_SIGNED:INTERNAL=1"
    vopts="${vopts} -DVTK_ANSI_STREAM_EOF_RESULT:INTERNAL=0"
    vopts="${vopts} -DKWSYS_LFS_WORKS:INTERNAL=0"
    vopts="${vopts} -DKWSYS_CHAR_IS_SIGNED:INTERNAL=0"

    # Delete the old cache file if there is one.
    if test -e $VTK_BUILD_DIR/CMakeCache.txt ; then
        rm -f $VTK_BUILD_DIR/CMakeCache.txt
    fi

    # Call build_visit.
whitlocb's avatar
whitlocb committed
553
    banner "Building VTK (Compute Node)"
554 555 556 557
    (export VTK_EXTRA_OPTIONS="${vopts}"
     export C_COMPILER=$BG_CC
     export BUILD_VISIT_BGQ="yes"
     eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
558
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
559
        --console --static --no-visit $SVN $TARBALL --engine-only \
whitlocb's avatar
whitlocb committed
560 561 562 563 564 565 566
        --no-thirdparty --cmake --vtk \
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}_BGQ" \
        --cc $BG_CC $CFLAGSARGS \
whitlocb's avatar
whitlocb committed
567
        --cxx $BG_CXX $CXXFLAGSARGS $MAKEARGS \
568
        --group $GROUP)
whitlocb's avatar
whitlocb committed
569 570 571

    rm -rf $VTK_SRC_DIR
    rm -rf $VTK_BUILD_DIR
whitlocb's avatar
whitlocb committed
572 573 574 575 576 577 578 579

    return $?
}

function build_icet_BGQ
{
    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
580
        MAKEARGS="--makeflags \"$MAKE_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
581 582 583
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
584
        CFLAGSARGS="--cflag \"$BG_C_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
585 586 587
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
588
        CXXFLAGSARGS="--cxxflag \"$BG_CXX_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
589 590 591 592
    fi

    # Call build_visit just to build Ice-T. Use the gnu compilers to build
    # it but use the XL/MPI compilers to detect MPI.
whitlocb's avatar
whitlocb committed
593
    banner "Building Ice-T (Compute Node)"
594 595 596
    (export PAR_COMPILER=$BG_MPI_CC
     export C_COMPILER=$BG_CC
     eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
597
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
598
        --console --static --no-visit $SVN $TARBALL --engine-only \
whitlocb's avatar
whitlocb committed
599
        --no-thirdparty --cmake --icet \
whitlocb's avatar
whitlocb committed
600 601
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
whitlocb's avatar
whitlocb committed
602
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
603 604 605 606
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}_BGQ" \
        --cc $BG_GNU_CC $CFLAGSARGS \
whitlocb's avatar
whitlocb committed
607
        --cxx $BG_GNU_CXX $CXXFLAGSARGS $MAKEARGS \
608
        --group $GROUP)
whitlocb's avatar
whitlocb committed
609 610

    rm -rf ${INSTALLATION_BUILD_DIR}_BGQ/IceT-1-0-0
whitlocb's avatar
whitlocb committed
611 612 613 614 615 616 617

    return $?
}

# 0 on success, Non-zero on failure.
function build_for_compute_node
{
whitlocb's avatar
whitlocb committed
618
    banner "BUILDING FOR COMPUTE NODE"
whitlocb's avatar
whitlocb committed
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656

    # We need to build Mesa with a special config file.
    STARTDIR=`pwd`
    build_mesa_BGQ
    if [[ $? != 0 ]] ; then
        warn "Mesa build failed.  Giving up"
        return 1
    fi
    cd $STARTDIR

    # We need to build zlib
    build_zlib_BGQ
    if [[ $? != 0 ]] ; then
        warn "ZLIB build failed.  Giving up"
        return 1
    fi
    cd $STARTDIR

    # We need to build VTK
    build_vtk_BGQ
    if [[ $? != 0 ]] ; then
        warn "VTK build failed.  Giving up"
        return 1
    fi
    cd $STARTDIR

    # We need to build Ice-T
    build_icet_BGQ
    if [[ $? != 0 ]] ; then
        warn "Ice-T build failed.  Giving up"
        return 1
    fi
    cd $STARTDIR

    # Build the other packages (and VisIt) that don't need special treatment. 

    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
657
        MAKEARGS="--makeflags \"$MAKE_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
658 659 660
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
661
        CFLAGSARGS="--cflag \"$BG_C_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
662 663 664
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
665
        CXXFLAGSARGS="--cxxflag \"$BG_CXX_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
666 667 668
    fi

    # Build some packages that require GNU compilers.
whitlocb's avatar
whitlocb committed
669
    banner "Building I/O libraries (Compute Node)"
670 671 672
    (export SILO_EXTRA_OPTIONS="--disable-browser --disable-hzip --disable-fpzip"
     export BUILD_VISIT_BGQ="yes"
     eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
673
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
674
        --console --static --no-visit $SVN $TARBALL --engine-only \
whitlocb's avatar
whitlocb committed
675 676
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
whitlocb's avatar
whitlocb committed
677
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
678 679 680 681 682
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}_BGQ" \
        --cc $BG_GNU_CC $CFLAGSARGS \
        --cxx $BG_GNU_CXX $CXXFLAGSARGS $MAKEARGS \
whitlocb's avatar
whitlocb committed
683
        --no-thirdparty --zlib $IO_PACKAGES \
684
        --group $GROUP)
whitlocb's avatar
whitlocb committed
685 686 687 688 689
    if [[ $? != 0 ]] ; then
        warn "3rd party I/O build failed.  Giving up"
        return 1
    fi

whitlocb's avatar
whitlocb committed
690 691
    # Call build_visit to build VisIt itself. Note that we set PAR_COMPILER, 
    # C_COMPILER, BUILD_VISIT_BGQ to trigger special behaviors in build_visit.
whitlocb's avatar
whitlocb committed
692 693 694 695 696
    #
    # NOTE: We do not build with Mesa support because we're already using Mesa
    #       as our GL library. This way, we use the VTK rendering classes since
    #       they are working better than the VisIt Mesa-based ones.
    #
697 698 699 700 701 702
    
    DBPLUGINSARGS=""
    if test -n "${VISIT_SELECTED_DATABASE_PLUGINS}" ; then
        DBPLUGINSARGS="--database-plugins \"${VISIT_SELECTED_DATABASE_PLUGINS}\""
    fi

whitlocb's avatar
whitlocb committed
703
    banner "Building VisIt (Compute Node)"
704 705 706 707
    (export PAR_COMPILER=$BG_MPI_CC
     export C_COMPILER=$BG_CC
     export BUILD_VISIT_BGQ="yes"
     eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
708
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
709
        --console --static $NO_VISIT $SVN $TARBALL --engine-only\
whitlocb's avatar
whitlocb committed
710 711
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
whitlocb's avatar
whitlocb committed
712
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
713 714 715 716 717
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}_BGQ" \
        --cc $BG_CC $CFLAGSARGS \
        --cxx $BG_CXX $CXXFLAGSARGS $MAKEARGS \
718
        --no-thirdparty --boost --zlib $IO_PACKAGES \
whitlocb's avatar
whitlocb committed
719 720
        --parallel --cmake --icet \
        --group $GROUP \
721
          ${DBPLUGINSARGS})
whitlocb's avatar
whitlocb committed
722 723 724 725 726
    if [[ $? != 0 ]] ; then
        warn "VisIt build failed.  Giving up"
        return 1
    fi

727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
    # If we built VisIt then move the libsim lib directory because otherwise
    # we'll clobber it with the login node version later.
    if test "$NO_VISIT" = "" ; then
        LIBSIM_BGQ=""
        if test -d $PREFIX/${VISIT_VERSION}/linux-ppc64/libsim/V2/lib ; then
            LIBSIM_BGQ=$PREFIX/${VISIT_VERSION}/linux-ppc64/libsim/V2/libBGQ
            mv $PREFIX/${VISIT_VERSION}/linux-ppc64/libsim/V2/lib  ${LIBSIM_BGQ}
        fi
        if test -d $PREFIX/${VISIT_VERSION}b/linux-ppc64/libsim/V2/lib ; then
            LIBSIM_BGQ=$PREFIX/${VISIT_VERSION}b/linux-ppc64/libsim/V2/libBGQ
            mv $PREFIX/${VISIT_VERSION}b/linux-ppc64/libsim/V2/lib ${LIBSIM_BGQ}
        fi
        # copy static libs, which are dependencies for the static libsimV2 libs
        if [ ! -z "${LIBSIM_BGQ}" ]; then
            cp builds_static_BGQ/src/lib/libsimV2runtime_par.a    ${LIBSIM_BGQ}
            cp builds_static_BGQ/src/lib/libengine_par.a          ${LIBSIM_BGQ}
            cp builds_static_BGQ/src/lib/libsimV2_static_par.a    ${LIBSIM_BGQ}
            cp builds_static_BGQ/src/lib/libcognomen.a            ${LIBSIM_BGQ}
            cp builds_static_BGQ/src/lib/libvisit_vtk.a           ${LIBSIM_BGQ}
        fi
    fi

whitlocb's avatar
whitlocb committed
749 750 751 752 753
    return 0
}

function build_for_login_node
{
whitlocb's avatar
whitlocb committed
754
    banner "BUILDING FOR LOGIN NODE"
whitlocb's avatar
whitlocb committed
755 756 757

    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
758
        MAKEARGS="--makeflags \"$MAKE_OPT_FLAGS\""
whitlocb's avatar
whitlocb committed
759
    fi
whitlocb's avatar
whitlocb committed
760

whitlocb's avatar
whitlocb committed
761 762 763 764 765 766 767 768
    CFLAGSARGS=""
    if test -n "$C_OPT_FLAGS" ; then
        CFLAGSARGS="--cflag \"$C_OPT_FLAGS\""
    fi
    CXXFLAGSARGS=""
    if test -n "$CXX_OPT_FLAGS" ; then
        CXXFLAGSARGS="--cxxflag \"$CXX_OPT_FLAGS\""
    fi
769 770 771 772
    DBPLUGINSFLAGSARGS=""
    if test -n "$VISIT_SELECTED_DATABASE_PLUGINS" ; then
        DBPLUGINSFLAGSARGS="--database-plugins \"$VISIT_SELECTED_DATABASE_PLUGINS\""
    fi    
whitlocb's avatar
whitlocb committed
773

whitlocb's avatar
whitlocb committed
774 775 776
    # Build cmake, python, VTK. We pass BUILD_VISIT_BGQ in the environment so
    # VTK will be configured using a script. This works around a glitch in
    # identifying the compiler.
whitlocb's avatar
whitlocb committed
777
    banner "Building Dependencies (Login Node)"
778
    (eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
779
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
780
        --console --static --no-visit $SVN $TARBALL --server-components-only \
whitlocb's avatar
whitlocb committed
781 782
        --log-file login_node.txt \
        --arch $ARCH \
whitlocb's avatar
whitlocb committed
783
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
784 785 786 787 788 789
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir $INSTALLATION_BUILD_DIR \
        --cc $CC $CFLAGSARGS \
        --cxx $CXX $CXXFLAGSARGS $MAKEARGS \
        --no-thirdparty --cmake --vtk --python \
790
        --group $GROUP)
whitlocb's avatar
whitlocb committed
791 792 793 794 795 796 797
    if [[ $? != 0 ]] ; then
        warn "VisIt build failed.  Giving up"
        return 1
    fi

    # Do another build_visit pass with no BUILD_VISIT_BGQ since we don't want what
    # it would do to the resulting config-site file.
whitlocb's avatar
whitlocb committed
798
    banner "Building VisIt (Login Node)"
799
    (eval $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
800
        --version ${VISIT_VERSION} \
bonnell's avatar
bonnell committed
801
        --console --static $NO_VISIT $SVN $TARBALL --server-components-only \
whitlocb's avatar
whitlocb committed
802 803
        --log-file login_node.txt \
        --arch $ARCH \
whitlocb's avatar
whitlocb committed
804
        --prefix "${PREFIX}" \
whitlocb's avatar
whitlocb committed
805 806 807 808 809
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir $INSTALLATION_BUILD_DIR \
        --cc $CC $CFLAGSARGS \
        --cxx $CXX $CXXFLAGSARGS $MAKEARGS \
810
        --no-thirdparty --boost --cmake --vtk $IO_PACKAGES --python \
whitlocb's avatar
whitlocb committed
811
        --group $GROUP \
812
        ${DBPLUGINSFLAGSARGS})
whitlocb's avatar
whitlocb committed
813 814 815 816 817 818 819 820 821 822 823
    if [[ $? != 0 ]] ; then
        warn "VisIt build failed.  Giving up"
        return 1
    fi

    return 0
}


function printvars
{
whitlocb's avatar
whitlocb committed
824 825 826 827 828
    echo "========================================================================"
    echo "The following variables will be used during the build process:"
    echo ""
    echo "Build Settings"
    echo "==============="
whitlocb's avatar
whitlocb committed
829
    echo "ARCH=$ARCH"
whitlocb's avatar
whitlocb committed
830 831 832
    echo "BUILD_MODE=$BUILD_MODE"
    echo "THIRD_PARTY_PATH=$THIRD_PARTY_PATH"
    echo "INSTALLATION_BUILD_DIR=$INSTALLATION_BUILD_DIR"
whitlocb's avatar
whitlocb committed
833
    echo "PREFIX=$PREFIX"
whitlocb's avatar
whitlocb committed
834 835 836 837 838 839
    echo "EXTRA_ARGS=$EXTRA_ARGS"
    echo "GROUP=$GROUP"
    echo "IO_PACKAGES=$IO_PACKAGES"
    echo "MAKE_OPT_FLAGS=$MAKE_OPT_FLAGS"
    echo "NO_VISIT=$NO_VISIT"
    echo "SVN=$SVN"
whitlocb's avatar
whitlocb committed
840
    echo "VISIT_SELECTED_DATABASE_PLUGINS=$VISIT_SELECTED_DATABASE_PLUGINS"
whitlocb's avatar
whitlocb committed
841 842 843 844 845 846 847 848 849 850
    echo ""
    echo "Login Node"
    echo "==========="
    echo "CC=$CC"
    echo "C_OPT_FLAGS=$C_OPT_FLAGS"
    echo "CXX=$CXX"
    echo "CXX_OPT_FLAGS=$CXX_OPT_FLAGS"
    echo ""
    echo "Compute Node"
    echo "============="
whitlocb's avatar
whitlocb committed
851 852 853
    echo "BG_CC=$BG_CC"
    echo "BG_C_OPT_FLAGS=$BG_C_OPT_FLAGS"
    echo "BG_CXX=$BG_CXX"
whitlocb's avatar
whitlocb committed
854 855
    echo "BG_CXX_OPT_FLAGS=$BG_CXX_OPT_FLAGS"
    echo ""
whitlocb's avatar
whitlocb committed
856 857
    echo "BG_GNU_CC=$BG_GNU_CC"
    echo "BG_GNU_CXX=$BG_GNU_CXX"
whitlocb's avatar
whitlocb committed
858
    echo ""
whitlocb's avatar
whitlocb committed
859 860 861
    echo "BG_MPI_CC=$BG_MPI_CC"
    echo "BG_MPI_C_OPT_FLAGS=$BG_MPI_C_OPT_FLAGS"
    echo "BG_MPI_CXX=$BG_MPI_CXX"
whitlocb's avatar
whitlocb committed
862 863
    echo "BG_MPI_CXX_OPT_FLAGS=$BG_MPI_CXX_OPT_FLAGS"
    echo "========================================================================"
whitlocb's avatar
whitlocb committed
864 865 866 867 868 869 870 871 872 873 874 875

    return 0
}

function usage
{
    echo "Usage: build_visit_BGQ [arguments]"
    echo ""
    echo "This script builds statically-linked VisIt server components for BlueGene-Q "
    echo "computers. The parallel compute engine is built for the compute nodes and the"
    echo "mdserver, vcl, and engine_ser components are built for the login nodes."
    echo ""
whitlocb's avatar
whitlocb committed
876 877
    echo "Argument                      Description"
    echo "============================= =========================================================="
whitlocb's avatar
whitlocb committed
878
    echo "--database-plugins list       A list of database plugins to build (e.g. Curve2D;Silo)"
whitlocb's avatar
whitlocb committed
879 880 881 882 883 884 885
    echo "--installation-build-dir dir  The build directory to be used to build the code."
    echo "--thirdparty-path path        The directory where 3rd party libraries will be installed."
    echo "--build-mode mode             The build mode: Debug or Release"
    echo "--group group                 Set the group for installed 3rd party libraries."
    echo "-h/--help                     Print the help and exit."
    echo "--print                       Print the variables that will be used for the build."
    echo "--makeflags flags             Build the code, passing flags to make."
whitlocb's avatar
whitlocb committed
886 887
    echo "--no-compute                  Do not build the compute node version."
    echo "--no-login                    Do not build the login node version."
whitlocb's avatar
whitlocb committed
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
    echo "--no-visit                    Do not build the VisIt sources."
    echo "--svn                         Download sources from svn."
    echo "--svn-anonymous               Download sources from anonymous svn."
    echo ""
    echo "Login Node"
    echo "==========="
    echo "--cc path                     The C compiler to use for login node compilation."
    echo "--cflag flag                  Append a flag to the CFLAGS used with the --cc compiler."
    echo "--cflags flags                Set the CFLAGS used with the --cc compiler."
    echo "--cxx path                    The C++ compiler to use for login node compilation."
    echo "--cxxflag flag                Append a flag to the CXXFLAGS used with the --cxx compiler."
    echo "--cxxflags flags              Set the CXXFLAGS used with the --cxx compiler."
    echo ""
    echo ""
    echo "Compute Node"
    echo "============="
    echo "--bgcc path                   The serial C compiler to use for compute node compilation."
    echo "--bgcflag flag                Append a flag to the CFLAGS used with the --bgcc/--bggnucc compilers."
    echo "--bgcflags flags              Set the CFLAGS used with the --bgcc/--bggnucc compilers."
    echo "--bgcxx path                  The serial C++ compiler to use for compute node compilation."
    echo "--bgcxxflag flag              Append a flag to the CXXFLAGS used with the --bgcxx/--bggnucxx compilers."
    echo "--bgcxxflags flags            Set the CXXFLAGS used with the --bgcxx/--bggnucxx compilers."
    echo ""
    echo "--bggnucc path                The serial GNU C compiler to use for compute node compilation."
    echo "                              This compiler is used for 3rd party packages that have autoconf"
    echo "                              build systems: Mesa, Silo, ... The CFLAGS specified using "
    echo "                              --bgcflag/--bgcflags are used."
    echo "--bggnucxx path               The serial GNU C++ compiler to use for compute node compilation."
    echo "                              The CXXFLAGS specified using --bgcxxflag/--bgcxxflags are used."
    echo
    echo "--bgmpicc path                The parallel C compiler to use for compute node compilation."
    echo "--bgmpicflag flag             Append a flag to the CFLAGS used with the --bgmpicc compiler."
    echo "--bgmpicflags flags           Set the CFLAGS used with the --bgmpicc compiler."
    echo "--bgmpicxx path               The parallel C++ compiler to use for compute node compilation."
    echo "--bgmpicxxflag flag           Append a flag to the CXXFLAGS used with the --bgmpicxx compiler."
    echo "--bgmpicxxflags flags         Set the CXXFLAGS used with the --bgmpicxx compiler."

whitlocb's avatar
whitlocb committed
925 926 927 928 929
    return 0
}

function main
{
whitlocb's avatar
whitlocb committed
930 931
    DO_COMPUTE="yes"
    DO_LOGIN="yes"
whitlocb's avatar
whitlocb committed
932 933 934 935 936 937 938 939 940 941 942 943 944 945
    next_action=""
    next_arg=""
    for arg in "$@" ; do
        # Was the last option something that took an argument?
        if test -n "$next_arg" ; then
            # Yep.  Which option was it?
            case $next_arg in
                installation-build-dir) INSTALLATION_BUILD_DIR="$arg";;
                build-mode) BUILD_MODE="${arg}";;

                append-cflags) C_OPT_FLAGS="${C_OPT_FLAGS} ${arg}";;
                append-cxxflags) CXX_OPT_FLAGS="${CXX_OPT_FLAGS} ${arg}";;
                cflags) C_OPT_FLAGS="${arg}";;
                cxxflags) CXX_OPT_FLAGS="${arg}";;
whitlocb's avatar
whitlocb committed
946 947
                cc) CC="${arg}";;
                cxx) CXX="${arg}";;
whitlocb's avatar
whitlocb committed
948 949 950 951 952

                append-bgcflags) BG_C_OPT_FLAGS="${BG_C_OPT_FLAGS} ${arg}";;
                append-bgcxxflags) BG_CXX_OPT_FLAGS="${BG_CXX_OPT_FLAGS} ${arg}";;
                bgcflags) BG_C_OPT_FLAGS="${arg}";;
                bgcxxflags) BG_CXX_OPT_FLAGS="${arg}";;
whitlocb's avatar
whitlocb committed
953 954 955 956
                bgcc) BG_CC="${arg}";;
                bgcxx) BG_CXX="${arg}";;
                bggnucc) BG_GNU_CC="${arg}";;
                bggnucxx) BG_GNU_CXX="${arg}";;
whitlocb's avatar
whitlocb committed
957

958 959
                append-bgmpicflags) BG_MPI_C_OPT_FLAGS="${BG_MPI_C_OPT_FLAGS} ${arg}";;
                append-bgmpicxxflags) BG_MPI_CXX_OPT_FLAGS="${BG_MPI_CXX_OPT_FLAGS} ${arg}";;
whitlocb's avatar
whitlocb committed
960 961
                bgmpicflags) BG_MPI_C_OPT_FLAGS="${arg}";;
                bgmpicxxflags) BG_MPI_CXX_OPT_FLAGS="${arg}";;
whitlocb's avatar
whitlocb committed
962 963
                bgmpicc) BG_MPI_CC="${arg}";;
                bgmpicxx) BG_MPI_CXX="${arg}";;
whitlocb's avatar
whitlocb committed
964

whitlocb's avatar
whitlocb committed
965
                database-plugins) VISIT_SELECTED_DATABASE_PLUGINS="${arg}";;
whitlocb's avatar
whitlocb committed
966
                group) GROUP="${arg}";;
whitlocb's avatar
whitlocb committed
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
                makeflags) MAKE_OPT_FLAGS="${arg}";;
                thirdparty-path) THIRD_PARTY_PATH="${arg}";;
                *) error "Unknown next_arg value '$next_arg'!"
            esac
            # Make sure we process the next option as an option and not an
            # argument to an option.
            next_arg=""
            continue
        fi
        case $arg in
            --installation-build-dir) next_arg="installation-build-dir";;
            --build-mode) next_arg="build-mode";;

            --cflag) next_arg="append-cflags";;
            --cflags) next_arg="cflags";;
            --cxxflag) next_arg="append-cxxflags";;
            --cxxflags) next_arg="cxxflags";;
            --cc) next_arg="cc";;
            --cxx) next_arg="cxx";;

            --bgcflag) next_arg="append-bgcflags";;
            --bgcflags) next_arg="bgcflags";;
            --bgcxxflag) next_arg="append-bgcxxflags";;
            --bgcxxflags) next_arg="bgcxxflags";;
            --bgcc) next_arg="bgcc";;
            --bgcxx) next_arg="bgcxx";;
whitlocb's avatar
whitlocb committed
993 994
            --bggnucc) next_arg="bggnucc";;
            --bggnucxx) next_arg="bggnucxx";;
whitlocb's avatar
whitlocb committed
995 996 997 998 999 1000 1001 1002

            --bgmpicflag) next_arg="append-bgmpicflags";;
            --bgmpicflags) next_arg="bgmpicflags";;
            --bgmpicxxflag) next_arg="append-bgmpicxxflags";;
            --bgmpicxxflags) next_arg="bgmpicxxflags";;
            --bgmpicc) next_arg="bgmpicc";;
            --bgmpicxx) next_arg="bgmpicxx";;

whitlocb's avatar
whitlocb committed
1003
            --database-plugins) next_arg="database-plugins";;
whitlocb's avatar
whitlocb committed
1004 1005 1006 1007
            --group) next_arg="group";;
            -h|--help) next_action="help";;
            --print) next_action="printvars";;
            --makeflags) next_arg="makeflags";;
whitlocb's avatar
whitlocb committed
1008 1009
            --no-compute) DO_COMPUTE="";;
            --no-login) DO_LOGIN="";;
whitlocb's avatar
whitlocb committed
1010
            --no-visit) NO_VISIT="--no-visit";;
whitlocb's avatar
whitlocb committed
1011 1012
            --svn) SVN="--svn" ; DO_SVN="yes" ; TARBALL="";;
            --svn-anonymous) SVN="--svn-anonymous"; DO_SVN_ANON="yes" ; TARBALL="";;
whitlocb's avatar
whitlocb committed
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
            --thirdparty-path) next_arg="thirdparty-path";;
        esac
    done

    if test -n "${next_action}" ; then
        case ${next_action} in
            printvars) printvars; exit 2;;
            help) usage; exit 2;;
        esac
    fi

whitlocb's avatar
whitlocb committed
1024 1025 1026 1027 1028 1029
    # Print the settings we're using for the build
    printvars

    # Make build directories.
    if ! test -d $INSTALLATION_BUILD_DIR ; then
        mkdir $INSTALLATION_BUILD_DIR
whitlocb's avatar
whitlocb committed
1030

whitlocb's avatar
whitlocb committed
1031 1032 1033 1034 1035
    fi
    if ! test -d ${INSTALLATION_BUILD_DIR}_BGQ ; then
        mkdir ${INSTALLATION_BUILD_DIR}_BGQ
    fi

whitlocb's avatar
whitlocb committed
1036
    # Make an installation directory.
1037 1038
    if ! test -d $THIRD_PARTY_PATH ; then
        mkdir $THIRD_PARTY_PATH
whitlocb's avatar
whitlocb committed
1039
    else
1040
        echo "$THIRD_PARTY_PATH already exists."
whitlocb's avatar
whitlocb committed
1041 1042
    fi

whitlocb's avatar
whitlocb committed
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
    if test "${SVN}" == "" && test "${NO_VISIT}" == "" ; then
        # We're building VisIt from a local source file (not svn) so check that
        # the file is present at the level of the build_visit_BGQ script.
        # If we find it then we'll copy it into the installation build dirs so
        # the build_visit scripts will locate it.
        if ! test -e visit${VISIT_VERSION}.tar.gz ; then
            error "VisIt source file visit${VISIT_VERSION}.tar.gz not found in $PWD. Exiting."
            exit 3
        fi

        # Copy local source file into installation build dirs if it's not there.
        if ! test -e $INSTALLATION_BUILD_DIR/visit${VISIT_VERSION}.tar.gz ; then
            cp visit${VISIT_VERSION}.tar.gz $INSTALLATION_BUILD_DIR
        fi
        if ! test -e ${INSTALLATION_BUILD_DIR}_BGQ/visit${VISIT_VERSION}.tar.gz ; then
            cp visit${VISIT_VERSION}.tar.gz ${INSTALLATION_BUILD_DIR}_BGQ
        fi
    fi

whitlocb's avatar
whitlocb committed
1062 1063 1064 1065
    # We build cmake specially so we can share the build between the login
    # node and compute node build stages.
    build_cmake

whitlocb's avatar
whitlocb committed
1066 1067 1068 1069 1070 1071 1072
    # We build the compute node version first.
    if test -n "${DO_COMPUTE}" ; then
        build_for_compute_node
        if [[ $? != 0 ]] ; then
            warn "Compute node build failed.  Giving up"
            exit 4
        fi
whitlocb's avatar
whitlocb committed
1073 1074
    fi

whitlocb's avatar
whitlocb committed
1075 1076 1077 1078 1079 1080 1081 1082
    # Now build for the login node so the engine_ser for the login node will
    # overwrite the compute node's version that was previously installed.
    if test -n "${DO_LOGIN}" ; then
        build_for_login_node
        if [[ $? != 0 ]] ; then
            warn "Login node build failed.  Giving up"
            exit 5
        fi
whitlocb's avatar
whitlocb committed
1083 1084 1085 1086 1087
    fi

    # We installed VisIt so tar up the binary distribution since it contains
    # binaries for both the login nodes and the compute nodes.
    if test "$NO_VISIT" = "" ; then
whitlocb's avatar
whitlocb committed
1088 1089
        VV=$(echo ${VISIT_VERSION} | tr "." "_")
        tar zcf visit${VV}.${PREFIXARCH}.tar.gz ${PREFIXARCH}
whitlocb's avatar
whitlocb committed
1090 1091 1092 1093 1094 1095 1096
    fi

    return 0
}

main $@
exit 0