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

whitlocb's avatar
whitlocb committed
3
VISIT_VERSION="2.7.0"
whitlocb's avatar
whitlocb committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

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

# Global variables
ARCH=linux-ppc64_gcc-4.4

BG_CC=bgxlc
BG_C_OPT_FLAGS=""
BG_CXX_OPT_FLAGS=""
BG_CXX=bgxlC

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

whitlocb's avatar
whitlocb committed
21
BG_MPI_GNU_CC=mpicc # not used
whitlocb's avatar
whitlocb committed
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
BG_MPI_GNU_CXX=mpicxx

BG_MPI_CC=mpixlc
BG_MPI_C_OPT_FLAGS=""
BG_MPI_CXX_OPT_FLAGS=""
BG_MPI_CXX=mpixlC

BUILD_MODE="Release"
CC=gcc
C_OPT_FLAGS=""
CXX=g++
CXX_OPT_FLAGS=""
EXTRA_ARGS=""
GROUP="visit"
INSTALLATION_BUILD_DIR="builds_static"
IO_PACKAGES="--szip --hdf5 --silo --netcdf --mili"
MAKE=make
MAKE_OPT_FLAGS=""
NO_VISIT=""
DO_SVN=""
DO_SVN_ANON=""
SVN=""
TAR=tar
THIRD_PARTY_PATH="thirdparty_static"

export CMAKE_VERSION=2.8.10.2
export CMAKE_SHORT_VERSION=2.8

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"}
export MESA_URL="ftp://ftp.freedesktop.org/pub/mesa/7.8.2/"

export ZLIB_FILE=${ZLIB_FILE:-"zlib-1.2.7.tar.gz"}
export ZLIB_VERSION=${ZLIB_VERSION:-"1.2.7"}
export ZLIB_BUILD_DIR=${ZLIB_BUILD_DIR:-"zlib-1.2.7"}
export ZLIB_URL="http://zlib.net/"

whitlocb's avatar
whitlocb committed
60
export VTK_VERSION=5e3c539
whitlocb's avatar
whitlocb committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182

################################################################################
## 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..
                webaddr="http://portal.nersc.gov/svn/visit/trunk/src/svn_bin/bv_support/"
                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

################################################################################
## 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
183
184
185
186
187
188
189
190
191
    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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
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
417
    #
    # Build bluegene-visit-osmesa config.
    #
    info "Building Mesa . . . (~2 minutes)"
    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++
CFLAGS = -O3 -pedantic -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE
CXXFLAGS = -O3 -pedantic -D_POSIX_SOURCE -D_POSIX_C_SOURCE=199309L -D_SVID_SOURCE -D_BSD_SOURCE
MKLIB_OPTIONS = -static
GL_LIB_NAME = libGL.a
GLU_LIB_NAME = libGLU.a
GLUT_LIB_NAME = libglut.a
GLW_LIB_NAME = libGLw.a
OSMESA_LIB = GL
OSMESA_LIB_NAME = libGL.a
# 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

    # VTK will later want an OSMesa, which we've called GL. Make a copy.
    cp $PF/lib/libGL.a $PF/lib/libOSMesa.a

    # 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
        MAKEARGS="--makeflags $MAKE_OPT_FLAGS"
    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
418
    echo "***Building CMake"
whitlocb's avatar
whitlocb committed
419
420
421
422
423
424
425
426
427
    $bv_PATH/build_visit --console --static $NO_VISIT $SVN \
        --no-thirdparty --cmake\
        --log-file building_cmake.txt \
        --arch "${ARCH}" \
        --prefix $ARCH \
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir "${INSTALLATION_BUILD_DIR}" \
        --cc $CC $CFLAGSARGS \
whitlocb's avatar
whitlocb committed
428
429
        --cxx $CXX $CXXFLAGSARGS $MAKEARGS \
        --group $GROUP
whitlocb's avatar
whitlocb committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464

   # 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
        MAKEARGS="--makeflags $MAKE_OPT_FLAGS"
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
        CFLAGSARGS="--cflag $BG_C_OPT_FLAGS"
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
        CXXFLAGSARGS="--cxxflag $BG_CXX_OPT_FLAGS"
    fi

    # Build some packages that require GNU compilers.
whitlocb's avatar
whitlocb committed
465
    echo "***Building zlib"
whitlocb's avatar
whitlocb committed
466
467
468
469
470
471
472
473
474
475
    $bv_PATH/build_visit \
        --console --static --no-visit $SVN --engine-only \
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
        --prefix $ARCH \
        --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
476
477
        --no-thirdparty --zlib \
        --group $GROUP
whitlocb's avatar
whitlocb committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
    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
492
    VTK_SRC_DIR="${INSTALLATION_BUILD_DIR}_BGQ/VTK-${VTK_VERSION}"
whitlocb's avatar
whitlocb committed
493
494
495
496
497
498
499
500
501
502
503
504
505
506
    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
        MAKEARGS="--makeflags $MAKE_OPT_FLAGS"
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
whitlocb's avatar
whitlocb committed
507
        CFLAGSARGS="--cflags $BG_C_OPT_FLAGS"
whitlocb's avatar
whitlocb committed
508
509
510
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
whitlocb's avatar
whitlocb committed
511
        CXXFLAGSARGS="--cxxflags $BG_CXX_OPT_FLAGS"
whitlocb's avatar
whitlocb committed
512
513
514
    fi

    # Form extra arguments that we'll pass to cmake for VTK.
whitlocb's avatar
whitlocb committed
515
    vopts="-DCMAKE_CROSSCOMPILING:BOOL=ON -DVTK_OPENGL_HAS_OSMESA:BOOL=ON"
whitlocb's avatar
whitlocb committed
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
    vopts="${vopts} -DOPENGL_INCLUDE_DIR:PATH=$MESADIR/include"
    vopts="${vopts} -DOPENGL_gl_LIBRARY:PATH=$MESADIR/lib/libGL.a"
    vopts="${vopts} -DOPENGL_glu_LIBRARY:PATH=$MESADIR/lib/libGLU.a"
    vopts="${vopts} -DVTK_USE_X:BOOL=OFF"
    vopts="${vopts} -DOSMESA_LIBRARY:FILEPATH=$MESADIR/lib/libGL.a"
    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
539
540
    echo "***Building VTK"
    env VTK_EXTRA_OPTIONS="${vopts}" C_COMPILER=$BG_CC BUILD_VISIT_BGQ="yes" $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
541
542
543
544
545
546
547
548
        --console --static --no-visit $SVN --engine-only \
        --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
549
550
551
552
553
        --cxx $BG_CXX $CXXFLAGSARGS $MAKEARGS \
        --group $GROUP

    rm -rf $VTK_SRC_DIR
    rm -rf $VTK_BUILD_DIR
whitlocb's avatar
whitlocb committed
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574

    return $?
}

function build_icet_BGQ
{
    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
        MAKEARGS="--makeflags $MAKE_OPT_FLAGS"
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
        CFLAGSARGS="--cflag $BG_C_OPT_FLAGS"
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
        CXXFLAGSARGS="--cxxflag $BG_CXX_OPT_FLAGS"
    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
575
    echo "***Building Ice-T"
whitlocb's avatar
whitlocb committed
576
577
578
579
580
581
582
583
584
585
    env PAR_COMPILER=$BG_MPI_CC C_COMPILER=$BG_CC  $bv_PATH/build_visit \
        --console --static --no-visit $SVN --engine-only \
        --no-thirdparty --icet \
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
        --prefix $ARCH \
        --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
586
587
588
589
        --cxx $BG_GNU_CXX $CXXFLAGSARGS $MAKEARGS \
        --group $GROUP

    rm -rf ${INSTALLATION_BUILD_DIR}_BGQ/IceT-1-0-0
whitlocb's avatar
whitlocb committed
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
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

    return $?
}

# 0 on success, Non-zero on failure.
function build_for_compute_node
{
    info "********************************************************************"
    info "                   BUILDING FOR COMPUTE NODE "
    info "********************************************************************"

    # 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
        MAKEARGS="--makeflags $MAKE_OPT_FLAGS"
    fi
    CFLAGSARGS=""
    if test -n "$BG_C_OPT_FLAGS" ; then
        CFLAGSARGS="--cflag $BG_C_OPT_FLAGS"
    fi
    CXXFLAGSARGS=""
    if test -n "$BG_CXX_OPT_FLAGS" ; then
        CXXFLAGSARGS="--cxxflag $BG_CXX_OPT_FLAGS"
    fi

    # Build some packages that require GNU compilers.
whitlocb's avatar
whitlocb committed
650
    echo "***Building I/O libraries"
whitlocb's avatar
whitlocb committed
651
652
653
654
655
656
657
658
659
660
    env SILO_EXTRA_OPTIONS="--disable-browser --disable-hzip --disable-fpzip" $bv_PATH/build_visit \
        --console --static --no-visit $SVN --engine-only \
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
        --prefix $ARCH \
        --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
661
662
        --no-thirdparty --szip --hdf5 --zlib --silo \
        --group $GROUP
whitlocb's avatar
whitlocb committed
663
664
665
666
667
    if [[ $? != 0 ]] ; then
        warn "3rd party I/O build failed.  Giving up"
        return 1
    fi

whitlocb's avatar
whitlocb committed
668
669
670
671
    # 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.
    echo "***Building VisIt"
    env PAR_COMPILER=$BG_MPI_CC C_COMPILER=$BG_CC BUILD_VISIT_BGQ="yes" $bv_PATH/build_visit \
whitlocb's avatar
whitlocb committed
672
673
674
675
676
677
678
679
680
681
        --console --static $NO_VISIT $SVN --engine-only\
        --log-file compute_node.txt \
        --arch "${ARCH}_BGQ" \
        --prefix $ARCH \
        --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 \
        --no-thirdparty --szip --hdf5 --zlib --silo \
whitlocb's avatar
whitlocb committed
682
683
        --parallel --icet \
        --group $GROUP
whitlocb's avatar
whitlocb committed
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
    if [[ $? != 0 ]] ; then
        warn "VisIt build failed.  Giving up"
        return 1
    fi

    return 0
}

function build_for_login_node
{
    info "********************************************************************"
    info "                   BUILDING FOR LOGIN NODE "
    info "********************************************************************"

    MAKEARGS=""
    if test -n "$MAKE_OPT_FLAGS" ; then
        MAKEARGS="--makeflags $MAKE_OPT_FLAGS"
    fi
    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

    $bv_PATH/build_visit --console --static $NO_VISIT $SVN --server-components-only \
        --log-file login_node.txt \
        --arch $ARCH \
        --prefix $ARCH \
        --build-mode $BUILD_MODE \
        --thirdparty-path $THIRD_PARTY_PATH \
        --installation-build-dir $INSTALLATION_BUILD_DIR \
        --cc $CC $CFLAGSARGS \
        --cxx $CXX $CXXFLAGSARGS $MAKEARGS \
whitlocb's avatar
whitlocb committed
720
721
        --no-thirdparty --cmake --vtk $IO_PACKAGES --python \
        --group $GROUP
whitlocb's avatar
whitlocb committed
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
    if [[ $? != 0 ]] ; then
        warn "VisIt build failed.  Giving up"
        return 1
    fi

    # Install into the $ARCH directory.
    if test "$NO_VISIT" = "" ; then
        cd visit${VISIT_VERSION}/src
        make install
        cd ../..
    fi

    return 0
}


function printvars
{
whitlocb's avatar
whitlocb committed
740
741
742
743
744
    echo "========================================================================"
    echo "The following variables will be used during the build process:"
    echo ""
    echo "Build Settings"
    echo "==============="
whitlocb's avatar
whitlocb committed
745
    echo "ARCH=$ARCH"
whitlocb's avatar
whitlocb committed
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
    echo "BUILD_MODE=$BUILD_MODE"
    echo "THIRD_PARTY_PATH=$THIRD_PARTY_PATH"
    echo "INSTALLATION_BUILD_DIR=$INSTALLATION_BUILD_DIR"
    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"
    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
765
766
767
    echo "BG_CC=$BG_CC"
    echo "BG_C_OPT_FLAGS=$BG_C_OPT_FLAGS"
    echo "BG_CXX=$BG_CXX"
whitlocb's avatar
whitlocb committed
768
769
    echo "BG_CXX_OPT_FLAGS=$BG_CXX_OPT_FLAGS"
    echo ""
whitlocb's avatar
whitlocb committed
770
771
    echo "BG_GNU_CC=$BG_GNU_CC"
    echo "BG_GNU_CXX=$BG_GNU_CXX"
whitlocb's avatar
whitlocb committed
772
    echo ""
whitlocb's avatar
whitlocb committed
773
774
775
    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
776
777
    echo "BG_MPI_CXX_OPT_FLAGS=$BG_MPI_CXX_OPT_FLAGS"
    echo "========================================================================"
whitlocb's avatar
whitlocb committed
778
779
780
781
782
783
784
785
786
787
788
789

    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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
    echo "Argument                      Description"
    echo "============================= =========================================================="
    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."
    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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
    return 0
}

function main
{
    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
855
856
                cc) CC="${arg}";;
                cxx) CXX="${arg}";;
whitlocb's avatar
whitlocb committed
857
858
859
860
861

                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
862
863
864
865
                bgcc) BG_CC="${arg}";;
                bgcxx) BG_CXX="${arg}";;
                bggnucc) BG_GNU_CC="${arg}";;
                bggnucxx) BG_GNU_CXX="${arg}";;
whitlocb's avatar
whitlocb committed
866
867
868
869
870

                append-bgmpicflags) BG_C_OPT_FLAGS="${BG_MPI_C_OPT_FLAGS} ${arg}";;
                append-bgmpicxxflags) BG_CXX_OPT_FLAGS="${BG_MPI_CXX_OPT_FLAGS} ${arg}";;
                bgmpicflags) BG_MPI_C_OPT_FLAGS="${arg}";;
                bgmpicxxflags) BG_MPI_CXX_OPT_FLAGS="${arg}";;
whitlocb's avatar
whitlocb committed
871
872
                bgmpicc) BG_MPI_CC="${arg}";;
                bgmpicxx) BG_MPI_CXX="${arg}";;
whitlocb's avatar
whitlocb committed
873

whitlocb's avatar
whitlocb committed
874
                group) GROUP="${arg}";;
whitlocb's avatar
whitlocb committed
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
                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
901
902
            --bggnucc) next_arg="bggnucc";;
            --bggnucxx) next_arg="bggnucxx";;
whitlocb's avatar
whitlocb committed
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928

            --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";;

            --group) next_arg="group";;
            -h|--help) next_action="help";;
            --print) next_action="printvars";;
            --makeflags) next_arg="makeflags";;
            --no-visit) NO_VISIT="--no-visit";;
            --svn) SVN="--svn" ; DO_SVN="yes";;
            --svn-anonymous) SVN="--svn-anonymous"; DO_SVN_ANON="yes";;
            --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
929
930
931
932
933
934
935
936
937
938
939
    # Print the settings we're using for the build
    printvars

    # Make build directories.
    if ! test -d $INSTALLATION_BUILD_DIR ; then
        mkdir $INSTALLATION_BUILD_DIR
    fi
    if ! test -d ${INSTALLATION_BUILD_DIR}_BGQ ; then
        mkdir ${INSTALLATION_BUILD_DIR}_BGQ
    fi

whitlocb's avatar
whitlocb committed
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
    # Make an installation directory.
    if ! test -d $ARCH ; then
        mkdir $ARCH
    else
        echo "$ARCH already exists."
    fi

    # We build cmake specially so we can share the build between the login
    # node and compute node build stages.
    build_cmake

    # We build the compute node version first so the engine_ser will be 
    # overwritten by the login node version during installation.
    build_for_compute_node
    if [[ $? != 0 ]] ; then
        warn "Compute node build failed.  Giving up"
        return 1
    fi

    build_for_login_node
    if [[ $? != 0 ]] ; then
        warn "Login node build failed.  Giving up"
        return 1
    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
        cd visit${VISIT_VERSION}/src
        make install
        cd ../..
    fi

    return 0
}

main $@
exit 0