helper_funcs.sh 65.6 KB
Newer Older
1 2
export LOG_FILE=${LOG_FILE:-"${0##*/}_log"}

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
# *************************************************************************** #
# Function: errorFunc                                                         #
#                                                                             #
# Purpose: Error messages                                                     #
#                                                                             #
# *************************************************************************** #
function errorFunc
{
  echo $1
  exit 0
}

# *************************************************************************** #
# Function: log                                                               #
#                                                                             #
# Purpose: Log message for the log.                                           #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:37:51 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #
function log
{
    echo "$@" >> ${LOG_FILE}
}


# *************************************************************************** #
# Function: warn                                                              #
#                                                                             #
# Purpose: Echo to screen and log.                                            #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Tue Nov 18 15:09:47 PST 2008                                          #
#                                                                             #
# Modifications:                                                              #
#                                                                             #
#   Hank Childs, Fri Jan 28 10:32:06 PST 2011                                 #
#   Add -e to echo so tabs are printed.                                       #
#                                                                             #
# *************************************************************************** #
function warn
{
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        echo -e "$@" 1>&3
    else
        echo -e "$@"
    fi
    
    if [[ "${LOG_FILE}" != "/dev/tty" ]] ; then
        # write message to log as well
        log "$@"
    fi
}

# *************************************************************************** #
# Function: error                                                             #
#                                                                             #
# Purpose: Report an error message and exit.                                  #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:37:51 MDT 2008                                          #
#                                                                             #
# Modifications:                                                              #
#    Jeremy Meredith, Fri Jul 22 10:36:20 EDT 2011                            #
#    Added a little more text to help users.                                  #
# *************************************************************************** #

function error
{
    warn "$@"
    if test "${LOG_FILE}" != "/dev/tty" ; then
        warn "Error in build process.  See ${LOG_FILE} for more information."\
             "If the error is unclear, please include ${LOG_FILE} in a "\
             "message to the visit-users@ornl.gov list.  You will probably "\
             "need to compress the ${LOG_FILE} using a program like gzip "\
             "so it will fit within the size limits for email attachments."
    fi
    exit 1
}

84 85 86 87 88 89 90 91 92 93 94 95 96 97
# *************************************************************************** #
# Function: issue_command                                                     #
#                                                                             #
# Purpose: Print a command and execute it too.                                #
#                                                                             #
# Programmer: Brad Whitlock,                                                  #
# Date: Tue Feb 28 17:04:43 PST 2012                                          #
#                                                                             #
# Modifications:                                                              #
#
# *************************************************************************** #

function issue_command
{
98 99
    echo "$@"
    "$@"
100 101 102
    return $?
}

103 104 105 106 107 108 109 110
# *************************************************************************** #
# Function: add_extra_commandline_args                                        #
#                                                                             #
# Purpose: Allows modules to add extra arguments to VisIt                     #
#                                                                             #
# Programmer: Hari Krishnan,                                                  #
# Date: Thu Dec 15 14:38:36 PST 2011                                          #
#                                                                             #
brugger's avatar
 
brugger committed
111 112 113 114 115
# Modifications:                                                              #
#   Eric Brugger, Wed Jan 18 08:17:48 PST 2012                                #
#   I re-enabled the code that replaces dashes with underscores in the        #
#   name of the enable function.                                              #
#                                                                             #
116 117 118 119 120 121 122 123 124 125 126 127 128 129
# *************************************************************************** #
#global argument list for extra args..
declare -a extra_commandline_args
export EXTRA_COMMANDLINE_ARG_CALL=""

function add_extra_commandline_args 
{

  if [[ $# != 4 ]]; then
   echo "extra command line usage requires 4 parameters"
   return
  fi

  #replace all occurrences of "-" with "_"
brugger's avatar
 
brugger committed
130
  local enable_func="bv_$1_${2//-/_}"
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

  #check if function exists..
  #maybe this should be moved to build_visit rather than here..
  #in case some bash consoles don't have declare -F capabilities?
  declare -F "$enable_func" &>/dev/null || errorFunc "function pointer $enable_func not found"

  #add parameters..
  for f in "$@"; do
    extra_commandline_args[${#extra_commandline_args[*]}]="$f"
  done

  #add function pointer..
  extra_commandline_args[${#extra_commandline_args[*]}]="$enable_func"
}


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 183 184
function verify_required_module_exists
{
    local reqlib=$1
    #check if required functions exist..
    declare -F "bv_${reqlib}_enable" &>/dev/null || errorFunc "${reqlib} enable not found"
    declare -F "bv_${reqlib}_disable" &>/dev/null || errorFunc "${reqlib} disable not found"
    declare -F "bv_${reqlib}_initialize" &>/dev/null || errorFunc "${reqlib} initialize not found"
    declare -F "bv_${reqlib}_info" &>/dev/null || errorFunc "${reqlib} info not found"
    declare -F "bv_${reqlib}_ensure" &>/dev/null || errorFunc "${reqlib} ensure not found"
    declare -F "bv_${reqlib}_build" &>/dev/null || errorFunc "${reqlib} build not found"
    declare -F "bv_${reqlib}_depends_on" &>/dev/null || errorFunc "${reqlib} depends_on not found"
    declare -F "bv_${reqlib}_print" &>/dev/null || errorFunc "${reqlib} print not found"
    declare -F "bv_${reqlib}_print_usage" &>/dev/null || errorFunc "${reqlib} print_usage not found"
    declare -F "bv_${reqlib}_dry_run" &>/dev/null || errorFunc "${reqlib} dry_run not found"
    declare -F "bv_${reqlib}_is_installed" &>/dev/null || errorFunc "${reqlib} is_installed not found"
    declare -F "bv_${reqlib}_is_enabled" &>/dev/null || errorFunc "${reqlib} is_enabled not found"
}


function verify_optional_module_exists
{
    local optlib=$1
    declare -F "bv_${optlib}_enable" &>/dev/null || errorFunc "${optlib} enable not found"
    declare -F "bv_${optlib}_disable" &>/dev/null || errorFunc "${optlib} disable not found"
    declare -F "bv_${optlib}_initialize" &>/dev/null || errorFunc "${optlib} info not found"
    declare -F "bv_${optlib}_info" &>/dev/null || errorFunc "${optlib} info not found"
    declare -F "bv_${optlib}_ensure" &>/dev/null || errorFunc "${optlib} ensure not found"
    declare -F "bv_${optlib}_build" &>/dev/null || errorFunc "${optlib} build not found"
    declare -F "bv_${optlib}_depends_on" &>/dev/null || errorFunc "${optlib} depends_on not found"
    declare -F "bv_${optlib}_print" &>/dev/null || errorFunc "${optlib} print not found"
    declare -F "bv_${optlib}_print_usage" &>/dev/null || errorFunc "${optlib} print_usage not found"
    declare -F "bv_${optlib}_host_profile" &>/dev/null || errorFunc "${optlib} host_profile not found"
    declare -F "bv_${optlib}_graphical" &>/dev/null || errorFunc "${optlib} graphical not found"
    declare -F "bv_${optlib}_dry_run" &>/dev/null || errorFunc "${optlib} dry_run not found"
    declare -F "bv_${optlib}_is_installed" &>/dev/null || errorFunc "${optlib} is_installed not found"
    declare -F "bv_${optlib}_is_enabled" &>/dev/null || errorFunc "${optlib} is_enabled not found"
}

185 186 187 188 189 190 191 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
# *************************************************************************** #
# Function: info_box                                                          #
#                                                                             #
# Purpose: Show an information box with a message.                            #
#                                                                             #
# Programmer: Brad Whitlock,                                                  #
# Date: Thu Apr 5 14:38:36 PST 2007                                           #
#                                                                             #
# *************************************************************************** #

function info_box
{
    if [[ "$GRAPHICAL" == "yes" ]] ; then
        $DLG --backtitle "$DLG_BACKTITLE" --infobox "$1" $DLG_HEIGHT $DLG_WIDTH
    fi
    return 0
}

# *************************************************************************** #
# Function: info                                                              #
#                                                                             #
# Purpose: Give an informative message to the user.                           #
#                                                                             #
# Programmer: Tom Fogal                                                       #
# Date: Fri Oct  3 09:41:50 MDT 2008                                          #
#                                                                             #
# *************************************************************************** #
function info
{
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        if test "${GRAPHICAL}" = "yes" ; then
            info_box "$@" 1>&3
        else
            echo "$@" 1>&3
        fi
    else
        if test "${GRAPHICAL}" = "yes" ; then
            info_box "$@"
        else
            echo "$@"
        fi
    fi

    if [[ "${LOG_FILE}" != "/dev/tty" ]] ; then
        # write message to log as well
        log "$@"
    fi
}

# *************************************************************************** #
# Function: info_box_large                                                    #
#                                                                             #
# Purpose: Show a large information box with a message.                       #
#                                                                             #
# Programmer: Eric Brugger,                                                   #
# Date: Thu Jul 21 08:25:52 PDT 2011                                          #
#                                                                             #
# *************************************************************************** #

function info_box_large
{
brugger's avatar
 
brugger committed
246 247 248 249 250 251 252 253
    if [[ "$REDIRECT_ACTIVE" == "yes" ]] ; then
        if [[ "$GRAPHICAL" == "yes" ]] ; then
            $DLG --backtitle "$DLG_BACKTITLE" --infobox "$1" $DLG_HEIGHT_TALL $DLG_WIDTH 1>&3
        fi
    else
        if [[ "$GRAPHICAL" == "yes" ]] ; then
            $DLG --backtitle "$DLG_BACKTITLE" --infobox "$1" $DLG_HEIGHT_TALL $DLG_WIDTH
        fi
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
    fi
    return 0
}

# *************************************************************************** #
# Function: uncompress_untar
#                                                                             #
# Purpose: Uncompress and untar the file, checking if GNU tar can be used.    #
#                                                                             #
# Programmer: Thomas R. Treadway                                              #
# Date: Tue May 15 16:48:01 PDT 2007                                          #
#                                                                             #
# *************************************************************************** #

function uncompress_untar
{
    # Check if GNU tar
    if [[ $(echo $1 | egrep "\.gz$" ) != "" ]] ; then
        COMPRESSTYPE="gzip"
    elif [[ $(echo $1 | egrep "\.bz2$" ) != "" ]] ; then
        COMPRESSTYPE="bzip"
    elif [[ $(echo $1 | egrep "\.tgz$" ) != "" ]] ; then
        COMPRESSTYPE="targzip"
    else
        warn "unsupported uncompression method"
        return 1
    fi
    TARVERSION=$($TAR --version >/dev/null 2>&1)
    if [[ $? == 0 ]] ; then
        case $COMPRESSTYPE in
            gzip|targzip) $TAR zxf $1;;
            bzip) $TAR jxf $1;;
        esac
    else
        case $COMPRESSTYPE in
            gzip) 
               gunzip $1
               $TAR xf ${1%.gz}
               ;;
            targzip) 
               gunzip $1
               $TAR xf "${1%.tgz}.tar"
               ;;
            bzip)
               bunzip2 $1
               $TAR xf ${1%.bz2}
               ;;
        esac
    fi
}

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
# *************************************************************************** #
# Function: verify_checksum                                                   #
#                                                                             #
# Purpose: Verify the checksum of given file                                  #
#                                                                             #
# verify_md5_checksum: checks md5                                             #
# verify_sha_checksum: checks sha (256,512)                                   #
# Programmer: Hari Krishnan                                                   #
# *************************************************************************** #

function verify_md5_checksum
{
    checksum=$1
    dfile=$2

    tmp=`which md5sum`
    if [[ $? != 0 ]]; then
        info "could not find md5sum, disabling check"
        return 0
    fi
    tmp=`md5sum $dfile | awk '{print $1}'`
    if [[ $tmp == ${checksum} ]]; then
        info "verified"
        return 0
    fi

    info "md5sum failed: looking for $checksum got $tmp"
    return 1
}

function verify_sha_checksum
{
    checksum_algo=$1
    checksum=$2
    dfile=$3

    tmp=`which shasum`
    if [[ $? != 0 ]]; then
        info "could not find shasum, disabling check"
        return 0
    fi

    tmp=`shasum -a $checksum_algo $dfile`
    if [[ $? == 0 ]]; then
        tmp=`echo $tmp| awk '{print $1}'`
        if [[ $tmp == $checksum ]]; then
            info "verified"
            return 0
        else
            info "shasum -a $checksum_algo failed: looking for $checksum got $tmp"
            return 1
        fi
    fi

    info "shasum does not support $checksum_algo, check disabled"
    return 0
}

function verify_checksum
{
    checksum_type=$1
    checksum=$2
    dfile=$3

    info "verifying type $checksum_type, checksum $checksum for $dfile . . ."

    if [[ "$checksum_type" == "MD5" ]]; then
        verify_md5_checksum $checksum $dfile
        return $?
    fi

    if [[ $checksum_type = "SHA256" ]]; then
        verify_sha_checksum 256 $checksum $dfile
        return $?
    fi

    if [[ $checksum_type = "SHA512" ]]; then
        verify_sha_checksum 512 $checksum $dfile
        return $?
    fi

    #since this is an optional check, all cases should pass if it gets here..
    info "checksum string not MD5, SHA256, or SHA512, check disabled"
    return 0
}


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 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
# *************************************************************************** #
# Function: download_file                                                     #
#                                                                             #
# Purpose: Downloads a file using wget and show a dialog screen.              #
#                                                                             #
# Programmer: Brad Whitlock,                                                  #
# Date: Thu Apr 5 14:38:36 PST 2007                                           #
#                                                                             #
# Modifications:                                                              #
#                                                                             #
#   Hank Childs, Mon Oct 15 15:55:22 PDT 2007                                 #
#   Fail gracefully if wget is not available.                                 #
#                                                                             #
#   Thomas R. Treadway, Tue Nov 27 16:37:21 PST 2007                          # 
#   Deal with LLNL's invalid certificates                                     #
#                                                                             #
#   Cyrus Harrison, Mon Nov 17 16:22:54 PST 2008                              # 
#   Check return value of svn cat or download for errors. Clean up a          #
#   partially downloaded file.                                                #
#                                                                             #
#   Hank Childs, Fri Dec 12 09:28:35 PST 2008                                 #
#   Add special logic for Ice-T.                                              #
#                                                                             #
#   Mark C. Miller, Thu Feb 19 09:16:46 PST 2009                              #
#   Added argument to specify a download_path. Removed special IceT coding.   #
#                                                                             #
#   Mark C. Miller, Thu Feb 19 12:21:55 PST 2009                              #
#   Changed to support multiple sites as well as default visit places.        #
#                                                                             #
#   Cyrus Harrison, Thu Feb 19 12:21:55 PST 2009                              #
#   Fixed problem where if a download path was given, svn mode was skipped    #
#                                                                             #
#   Cyrus Harrison, Thu Apr  9 19:21:13 PDT 2009                              #
#   Applied patch from Rick Wagner to fix curl downloads on OSX.              #
#                                                                             #
#   Mark C. Miller, Wed Feb  3 09:47:52 PST 2010                              #
#   Made it fall back to anon svn checkout                                    #
#                                                                             #
#   Eric Brugger, Mon Jan 10 16:00:13 PST 2011                                #
#   I made it always fall back to anonymous svn checkout.                     #
#                                                                             #
#   Eric Brugger, Tue Jul 19 10:19:50 PDT 2011                                #
#   I made it use the anonymous svn site as the fallback download site        #
#   instead of llnl's web site.                                               #
#                                                                             #
# *************************************************************************** #

function download_file
{
# $1 is the file name to download
# $2...$* [OPTIONAL] list of sites to obtain the file from
#
# Since we always pass optional download sites to this function for
# some third party libs - we can't skip svn mode just b/c this info is given.
#
    typeset dfile=$1
    info "Downloading $dfile . . ." 
    shift
    
451 452
    SVN_ROOT_PREFIX="${SVN_ROOT_PATH}/${SVN_THIRDPARTY_PATH}"
    SVN_ANON_ROOT_PREFIX="${SVN_ANON_ROOT_PATH}/${SVN_THIRDPARTY_PATH}"
453 454
    # If SVN is requested, try that first before anything else
    if [[ "$DO_SVN" == "yes" ]] ; then
455
        svn cat $SVN_ROOT_PREFIX/$dfile > $dfile
456
        if [[ $? == 0 && -e $dfile ]] ; then
457
            info "SVN download succeeded: $SVN_ROOT_PREFIX/$dfile"
458 459 460
            return 0
        else
            warn "Normal svn failed. Trying anonymous svn." 
461
            svn cat $SVN_ANON_ROOT_PREFIX/$dfile > $dfile
462
            if [[ $? == 0 && -e $dfile ]] ; then
463
                info "Anonymous SVN download succeeded: $SVN_ANON_ROOT_PREFIX/$dfile"
464 465 466
                return 0
            fi
        fi
467 468
        warn "SVN download attempt failed: $SVN_ROOT_PATH/$SVN_THIRDPARTY_PATH/$dfile"
        warn "Anonymous SVN download attempt failed: $SVN_ANON_ROOT_PREFIX/$dfile"
469 470
        rm -f $dfile
    elif [[ "$DO_SVN_ANON" == "yes" ]] ; then
471
        svn cat $SVN_ANON_ROOT_PREFIX/$dfile > $dfile
472
        if [[ $? == 0 && -e $dfile ]] ; then
473
            info "Anonymous SVN download succeeded: $SVN_ANON_ROOT_PREFIX/$dfile"
474 475
            return 0
        fi
476
        warn "Anonymous SVN download attempt failed: $SVN_ANON_ROOT_PREFIX/$dfile"
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
        rm -f $dfile
    fi

    # If the visit source code is requested try that next.
    if [[ "$dfile" == "$VISIT_FILE" ]] ; then
        try_download_file $SVN_ANON_ROOT_PATH/trunk/releases/$VISIT_VERSION/$dfile $dfile
        if [[ $? == 0 ]] ; then
            return 0
        fi
    fi

    # Now try the various places listed.
    if [[ "$1" != "" ]] ; then
        for site in $* ; do
            try_download_file $site/$dfile $dfile
            if [[ $? == 0 ]] ; then
                return 0
            fi
        done
    fi

    # Now try anonymous svn unless we tried it above.
    if [[ "$DO_SVN" != "yes" && "$DO_ANON_SVN" != "yes" ]] ; then
500
        svn cat $SVN_ANON_ROOT_PREFIX/$dfile > $dfile
501
        if [[ $? == 0 && -e $dfile ]] ; then
502
            info "Anonymous SVN download succeeded: $SVN_ANON_ROOT_PREFIX/$dfile"
503 504
            return 0
        fi
505
        warn "Anonymous SVN download attempt failed: $SVN_ANON_ROOT_PREFIX/$dfile"
506 507 508 509
        rm -f $dfile
    fi

    # Now try the anonymous svn site with wget or curl.
510
    try_download_file $SVN_ANON_ROOT_PREFIX/$dfile $dfile
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 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 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
    if [[ $? == 0 ]] ; then
        return 0
    fi
    info "Failed to download $dfile"
    return 1
}

# *************************************************************************** 
# Function: try_download_file
#
# Purpose: DONT USE THIS FUNCTION. USE download_file.
# Downloads a file using wget or curl. 
#
# Programmer: Refactored from other sources (Mark C. Miller)
# Creation: February 19, 2009
#
#   Cyrus Harrison, Tue 24 Mar 13:44:31 PST 2009 
#   As an extra guard, check that the downloaded file actually exisits. 
#   (Firewalls can cause strange files to be created.)
# 
#   Cyrus Harrison, Thu Apr  9 19:21:13 PDT 2009
#   Applied patch from Rick Wagner to fix curl downloads on OSX.
#
#   Tom Fogal, Sun Jul 26 17:19:26 MDT 2009
#   Follow redirects.  Don't use a second argument.
#
#   Gunther H. Weber, Fri Oct 23 13:17:34 PDT 2009
#   Specify explicit path to system curl so that we do not use another
#   version without SSL support
#
# *************************************************************************** 

function try_download_file
{
    if [[ "$OPSYS" == "Darwin" ]]; then
        # MaxOS X comes with curl
        /usr/bin/curl -ksfLO $1
    else
        check_wget
        if [[ $? != 0 ]] ; then
            error "Need to download $1, but \
                   cannot locate the wget utility to do so."
        fi
        wget $WGET_OPTS -o /dev/null $1
    fi

    if [[ $? == 0 && -e `basename $1` ]] ; then
        info "Download succeeded: $1"
        return 0
    else    
        warn "Download attempt failed: $1"
        rm -f `basename $1`
        return 1
    fi
}


# *************************************************************************** #
# Function: check_svn_client                                                  #
#                                                                             #
# Purpose: Helper that checks if a svn client is available.                    #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date:  Mon Nov 17 14:52:37 PST 2008                                         #
#                                                                             #
# *************************************************************************** #

function check_svn_client
{
    # check for svn client
    SVN_CLIENT=$(which svn)
    if [[ $SVN_CLIENT == "" ]] ; then
        return 1
    fi
    return 0
}

# *************************************************************************** #
# Function: check_wget                                                        #
#                                                                             #
# Purpose: Helper that checks if a wget is available.                         #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date:  Mon Nov 17 14:52:37 PST 2008                                         #
#                                                                             #
# *************************************************************************** #

function check_wget
{
    WGET_CLIENT=$(which wget)
    # check for wget
    if [[ $WGET_CLIENT == "" ]] ; then
        return 1
    fi
    return 0
}

# *************************************************************************** #
# Function: check_if_installed                                                #
#                                                                             #
# Purpose: Checks if $VISITDIR/$1/$2/$VISITARCH exists.                       #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Wed Nov 19 07:31:08 PST 2008                                          #
#                                                                             #
# *************************************************************************** #
function check_if_installed
{
    BUILD_NAME=$1
    BUILD_VERSION=""

    if [[ $# == 2 ]]; then
        BUILD_VERSION=$2
    fi
    
    if [[ $BUILD_VERSION != "" ]]; then
        INSTALL_DIR=$VISITDIR/$BUILD_NAME/$BUILD_VERSION/$VISITARCH
    else
        INSTALL_DIR=$VISITDIR/$BUILD_NAME/$VISITARCH
    fi

    if [[ -d ${INSTALL_DIR} ]] ; then
        return 0
    else
        return 1
    fi
}

# *************************************************************************** #
# Function: ensure_built_or_ready                                             #
#                                                                             #
# Purpose: Helper that checks for proper installed version. If this doesn't   #
#  exist, makes sure the source file is avalaible for building.               #
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Fri Nov 14 08:23:26 PST 2008                                          #
#                                                                             #
# *************************************************************************** #
function ensure_built_or_ready
{
    BUILD_NAME=$1
    BUILD_VERSION=$2
    INSTALL_DIR=$VISITDIR/$BUILD_NAME/$BUILD_VERSION/$VISITARCH
    BUILD_DIR=$3
    SRC_FILE=$4
    DOWNLOAD_PATH=$5

    info "Checking for ${BUILD_NAME}-${BUILD_VERSION}"
    
    ALREADY_INSTALLED="NO"
    HAVE_TARBALL="NO"
    
    check_if_installed $BUILD_NAME $BUILD_VERSION
    if [[ $? == 0 || -d $BUILD_DIR ]] ; then
        ALREADY_INSTALLED="YES"
    fi
    if [[ -e ${SRC_FILE%.gz} || -e ${SRC_FILE} ]] ; then
        HAVE_TARBALL="YES"
    fi
    
    if [[ "$ALREADY_INSTALLED" == "NO" && "$HAVE_TARBALL" == "NO" ]] ; then
        download_file ${SRC_FILE} ${DOWNLOAD_PATH}
        if [[ $? != 0 ]] ; then
            warn "Error: Cannot obtain source for $BUILD_NAME."
            return 1
        fi
    fi
    return 0
}


# *************************************************************************** #
# Function: prepare_build_dir                                                 #
#                                                                             #
# Purpose: Helper that prepares a build directory from a src file.            #
#                                                                             #
# Returns:                                                                    #
#          -1 on failure                                                      #
#           0 for success without untar                                       #
#           1 for success with untar                                          #
691
#           2 for failure with checksum                                       #
692 693 694 695 696 697 698 699 700 701
#                                                                             #
# Programmer: Cyrus Harrison                                                  #
# Date: Thu Nov 13 09:28:26 PST 2008                                          #
#                                                                             #
# *************************************************************************** #
function prepare_build_dir
{
    BUILD_DIR=$1
    SRC_FILE=$2
    
702 703 704 705
    #optional
    CHECKSUM_TYPE=$3
    CHECKSUM_VALUE=$4

706 707 708 709 710
    untarred_src=0
    if [[ -d ${BUILD_DIR} ]] ; then
       info "Found ${BUILD_DIR} . . ."
       untarred_src=0
    elif [[ -f ${SRC_FILE} ]] ; then
711 712 713 714 715 716
       if [[ $CHECKSUM != "" && $CHECKSUM_TYPE != "" ]]; then
            verify_checksum $CHECKSUM_TYPE $CHECKSUM ${SRC_FILE}
            if [[ $? != 0 ]]; then
                return 2
            fi
       fi
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
       info "Unzipping/Untarring ${SRC_FILE} . . ."
       uncompress_untar ${SRC_FILE}
       untarred_src=1
       if [[ $? != 0 ]] ; then
          warn \
"Unable to untar $SRC_FILE  Corrupted file or out of space on device?"
          return -1
       fi
    elif [[ -f ${SRC_FILE%.*} ]] ; then
       info "Untarring ${SRC_FILE%.*} . . ."
       $TAR xf ${SRC_FILE%.*}
       untarred_src=1
       if [[ $? != 0 ]] ; then
          warn \
"Unable to untar ${SRC_FILE%.*}.  Corrupted file or out of space on device?"
          return -1
       fi
    fi
    
    return $untarred_src
}

# *************************************************************************** #
#                   Function 1.3, check_optional_3rdparty                     #
# --------------------------------------------------------------------------- #
# This function will check to make sure that all of the necessary source      #
# files for the optional 3rd party libraries actually exist.                  #
#
# *************************************************************************** #

function check_optional_3rdparty
{
    info "Checking optional 3rd party libs"

    for (( i = 0; i < ${#optlibs[*]}; ++i ))
    do
        ensure="bv_${optlibs[$i]}_ensure"
        $ensure
        if [[ $? != 0 ]] ; then
            return 1
        fi
    done
}


# *************************************************************************** #
#                    Function 1.1, check_required_3rdparty                    #
# --------------------------------------------------------------------------- #
# This function will check to make sure that all of the necessary files       #
# for the required third party libraries actually exist.                      #
# *************************************************************************** #

function check_required_3rdparty
{
    info "Checking for files . . ."

    for (( i = 0; i < ${#reqlibs[*]}; ++i ))
    do
        ensure="bv_${reqlibs[$i]}_ensure"
        $ensure
        if [[ $? != 0 ]] ; then
            return 1
        fi
    done

    return 0
}


# *************************************************************************** #
#                         Function 1.0, check_files                           #
# --------------------------------------------------------------------------- #
# This function will check to make sure that all of the necessary files       #
# actually exist.                                                             #
# *************************************************************************** #

function check_files
{
    check_required_3rdparty
    if [[ $? != 0 ]]; then
        return 1
    fi

    if [[ "$DO_VISIT" == "yes" ]] ;  then
brugger's avatar
 
brugger committed
801
       bv_visit_ensure_built_or_ready
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
       if [[ $? != 0 ]]; then
           return 1
       fi
    fi

    check_optional_3rdparty
    if [[ $? != 0 ]]; then
        return 1
    fi
    return 0
}


# *************************************************************************** #
#                         Function 2.0, check_more_options                    #
# --------------------------------------------------------------------------- #
# This function will display variables and optionally allow changing          #
# *************************************************************************** #

function check_more_options
{

    # Override variable settings dialog
    #
    if [[ "$DO_MORE" == "yes" && "$GRAPHICAL" == "yes" ]] ; then
827
        result=$($DLG --backtitle "$DLG_BACKTITLE" \
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
        --title "More build options" \
        --checklist \
"Version: specify version of VisIt to download and build\n"\
"Build: build VisIt, disable to build 3rd party only\n"\
"Required: build required 3rd party libraries\n"\
"Logging: display build log to stdout\n"\
"Symbol: turn on -g, debugging flag\n"\
"Group: specify the group name for install\n"\
"Path: specify the root directory for libraries\n"\
"to use the given Path rather than the default [@executable_path/../lib]\n"\
"Trace: print a trace of commands and arguments during build\n\n"\
"Select build and installed options:" 0 0 0 \
           "Version"   "specify VisIt version [$VISIT_VERSION]" $ON_VERSION \
           "Build"     "enable building VisIt"                  $ON_VISIT \
           "Logging"   "disable logging to file"                $ON_LOG \
           "Symbol"    "enable debug compiling"                 $ON_DEBUG \
           "Group"     "specify group name for install"         $ON_GROUP \
           "HostConf"  "create host.conf file"                  $ON_HOSTCONF \
           "Path"      "specify library path [$THIRD_PARTY_PATH]" $ON_PATH \
847
           "Trace"     "enable SHELL debugging"      $ON_VERBOSE 3>&1 1>&2 2>&3)
848 849 850
        retval=$?

    # Remove the extra quoting, new dialog has --single-quoted
851
        choice="$(echo $result | sed 's/"//g' )"
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
        case $retval in
          0)
            DO_VERSION="no"
            DO_VISIT="no"
            DO_REQUIRED_THIRD_PARTY="no"
            DO_LOG="no"
            DO_DEBUG="no"
            DO_GROUP="no"
            DO_HOSTCONF="no"
            DO_PATH="no"
            DO_VERBOSE="no"
            for OPTION in $choice
            do
                case $OPTION in
                  Version)
867
                     result=$($DLG --backtitle "$DLG_BACKTITLE" \
868
                        --nocancel --inputbox \
869 870
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$VISIT_VERSION"   3>&1 1>&2 2>&3) 
                     VISIT_VERSION="$result"
871 872 873 874 875 876 877 878 879
                     VISIT_FILE="visit${VISIT_VERSION}.tar.gz"
                     DO_VERSION="yes";;
                  Build)
                     DO_VISIT="yes";;
                  Logging)
                     DO_LOG="yes";;
                  Symbol)
                     DO_DEBUG="yes";;
                  Group)
880
                     result=$($DLG --backtitle "$DLG_BACKTITLE" \
881
                        --nocancel --inputbox \
882 883
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$GROUP" 3>&1 1>&2 2>&3)
                     GROUP="$result"
884 885 886 887
                     DO_GROUP="yes";;
                  HostConf)
                      DO_HOSTCONF="yes";;
                  Path)
888
                     result=$($DLG --backtitle "$DLG_BACKTITLE" \
889
                        --nocancel --inputbox \
890 891
"Enter $OPTION value:" 0 $DLG_WIDTH_WIDE "$THIRD_PARTY_PATH" 3>&1 1>&2 2>&3)
                     THIRD_PARTY_PATH="$result"
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 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
                     DO_PATH="yes";;
                  Trace)
                     DO_VERBOSE="yes";;
                esac
            done
            ;;
          1)
            warn "Cancel pressed."
            exit 1;;
          255)
            warn "ESC pressed.";;
          *)
            warn "Unexpected return code: $retval";;
        esac
    fi
    return 0
}

# *************************************************************************** #
#                          extract_parallel_ldflags                           #
# --------------------------------------------------------------------------- #
# VisIt's cmake config wants lib names stripped of "-l"                       #
# If PAR_LIBS is used to pass parallel LDFLAGS we need to separate the libs   #
# from the linker flags and strip the "-l" prefixes.                          #
# This function accomplishes this and creates two new  variables:             #
#   PAR_LINKER_FLAGS & PAR_LIBRARY_NAMES                                      #
# *************************************************************************** #
function process_parallel_ldflags
{
    export PAR_LINKER_FLAGS=""
    export PAR_LIBRARY_NAMES=""

    for arg in $1; do
        pos=`echo "$arg" | awk '{ printf "%d", index($1,"-l"); }'`
        if [[ "$pos" != "0" ]] ; then
            # we have a lib, remove the "-l" prefix & add it to the running
            # list
            LIB_NAME=${arg#-l}
            export PAR_LIBRARY_NAMES="$PAR_LIBRARY_NAMES$LIB_NAME "
        else
            # we have a linker flag, add it to the running list.
            export PAR_LINKER_FLAGS="$PAR_LINKER_FLAGS$arg "
        fi
    done

}


# *************************************************************************** #
#                         Function 2.1, check_parallel                        #
# --------------------------------------------------------------------------- #
# This function will check to make sure that parallel options have been setup #
# if we're going to build a parallel version of VisIt.                        #
# *************************************************************************** #

function check_parallel
{
    rv=0

951 952 953 954
    if [[ "$DO_MPICH" == "yes" && "$parallel" == "no" ]] ; then
        parallel="yes"
    fi

955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974
    #
    # Parallelization
    #
    if [[ "$parallel" == "yes" ]] ; then

        #
        # VisIt's cmake build can obtain all necessary MPI flags from
        # a MPI compiler wrapper.
        # Check if PAR_COMPILER is set & if so use that.
        #
        export VISIT_MPI_COMPILER=""
        if [[ "$PAR_COMPILER" != "" ]] ; then
            export VISIT_MPI_COMPILER=$PAR_COMPILER
            info \
                "Configuring with mpi compiler wrapper: $VISIT_MPI_COMPILER"
            return 0
        fi

        #
        # Check the environment that mpicc would set up as a first stab.
975 976 977 978
        # Since VisIt currently only ever uses MPI's C interface, we need
        # only the information to link to MPI's implementation of its C
        # interface. So, although VisIt is largely a C++ code, it is fine
        # and correct to utilize an MPI C compiler here.
979 980 981
        #
        MPICC_CPPFLAGS=""
        MPICC_LDFLAGS=""
982
        MPIWRAPPER=$(which mpicc)
983 984 985 986
        if [[ "${MPIWRAPPER#no }" != "${MPIWRAPPER}" ]] ; then
           MPIWRAPPER=""
        fi
        if [[ "$MPIWRAPPER" == "" ]] ; then
987
            warn "Unable to find mpicc..."
988 989 990 991 992
        fi

        #
        # VisIt's cmake build can obtain all necessary MPI flags from
        # a MPI compiler wrapper. If we have found one & the user
993
        # did not set PAR_LIBS or PAR_INCLUDE we are done.
994 995 996
        #
        if [[ "$PAR_INCLUDE" == "" && "$PAR_LIBS" == "" && "$MPIWRAPPER" != "" ]] ; then
            export VISIT_MPI_COMPILER=$MPIWRAPPER
997
            export PAR_COMPILER=$MPIWRAPPER
998 999 1000 1001 1002
            info \
                "Configuring with mpi compiler wrapper: $VISIT_MPI_COMPILER"
            return 0
        fi

1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
        #
        # VisIt's build_visit can obtain all necessary MPI flags from
        # bv_mpich. If we are building mpich and the user
        # did not set PAR_LIBS or PAR_INCLUDE we are done.
        #
        if [[ "$DO_MPICH" == "yes" && "$PAR_INCLUDE" == "" && "$PAR_LIBS" == "" && "$MPIWRAPPER" == "" ]] ; then

            export MPICH_COMPILER="${VISITDIR}/mpich/$MPICH_VERSION/${VISITARCH}/bin/mpicc"
            export VISIT_MPI_COMPILER="$MPICH_COMPILER"
            export PAR_COMPILER="$MPICH_COMPILER"
            info \
                "Configuring with build mpich: $MPICH_COMPILER"
            return 0
        fi

1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
        #
        # If we have not found a MPI compiler wrapper. 
        # Keep trying to discover mpi setttings.
        #
        if [[ "$PAR_CPPFLAGS" == "" ]] ; then
            warn \
"We have no guesses as to where MPI might reside. Look for it..."
            if [[ -e /usr/include/mpi.h ]] ; then
                PAR_CPPFLAGS="-I/usr/include"
                PAR_LDFLAGS="-L/usr/lib -lmpi"
            fi
        fi

        if [[ "$GRAPHICAL" == "yes" ]] ; then
            # We have suggestions from the user or mpicc as to where mpi might
            # be located. See what the user thinks of the options.
            tryagain=1
            while [[ $tryagain == 1 ]]; do
                $DLG --backtitle "$DLG_BACKTITLE" --yesno \
"The CPPFLAGS for MPI are:\n\n$PAR_CPPFLAGS\n\nDo these look right?" \
brugger's avatar
 
brugger committed
1038
                15 $DLG_WIDTH 3>1& 1>&2 2>&3
1039 1040
                if [[ $? == 1 ]] ; then
                    tryagain=1
1041
                    result=$($DLG --backtitle "$DLG_BACKTITLE" \
1042
                    --nocancel --inputbox \
1043 1044
"Enter CPPFLAGS needed for MPI:" 0 $DLG_WIDTH_WIDE "$PAR_CPPFLAGS" 3>&1 1>&2 2>&3) 
                    PAR_CPPFLAGS="$result"
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
                else
                    tryagain=0
                fi
            done

            PAR_INCLUDE=$PAR_CPPFLAGS

            # We have suggestions from the user or mpicc as to where mpi might
            # be located. See what the user thinks of the options.
            tryagain=1
            while [[ $tryagain == 1 ]]; do
                $DLG --backtitle "$DLG_BACKTITLE" --yesno \
brugger's avatar
 
brugger committed
1057
"The LDFLAGS for MPI are:\n\n$PAR_LDFLAGS\n\nDo these look right?" 15 $DLG_WIDTH 3>1& 1>&2 2>&3
1058 1059
                if [[ $? == 1 ]] ; then
                    tryagain=1
1060
                    result=$($DLG --backtitle "$DLG_BACKTITLE" \
1061
                    --nocancel --inputbox \
1062 1063
"Enter LDFLAGS needed for MPI:" 0 $DLG_WIDTH_WIDE "$PAR_LDFLAGS"  3>&1 1>&2 2>&3) 
                    PAR_LDFLAGS="$result"
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
                else
                    tryagain=0
                fi
            done

            PAR_LIBS=$PAR_LDFLAGS
        fi

        # if we are using PAR_LIBS, call helper to split this into:
        # PAR_LIBRARY_NAMES & PAR_LINKER_FLAGS
        process_parallel_ldflags "$PAR_LIBS"

        # The script pretty much assumes that you *must* have some flags 
        # and libs to do a parallel build.  If that is *not* true, 
        # i.e. mpi.h is in your include path, then, congratulations, 
        # you are working on a better configured system than I have 
        # ever encountered.
        if [[ "$PAR_INCLUDE" == "" || "$PAR_LIBRARY_NAMES" == "" || "$PAR_LINKER_FLAGS" == "" ]] ; then
            warn \
"To configure parallel VisIt you must satisfy one of the following conditions:
1084 1085
    The PAR_COMPILER env var provides a path to a mpi compiler wrapper (such as mpicc).
    A mpi compiler wrapper (such as mpicc) to exists in your path.
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
    The PAR_INCLUDE & PAR_LIBS env vars provide necessary CXX & LDFLAGS to use mpi.

 To build ICE-T the PAR_INCLUDE env var must provide the include path to your mpi headers.
    "
            rv=1
        fi

        if [[ $rv != 0 ]] ; then
           return 1
        fi
    fi

    return 0
}

# *************************************************************************** #
#                         Function 2.2, check_variables                       #
# --------------------------------------------------------------------------- #
# This function will display variables and optionally allow changing          #
# *************************************************************************** #

1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
function check_variables_dialog
{
    local var="$1"
    local input="$2"

    result=$($DLG --backtitle "$DLG_BACKTITLE" \
                           --nocancel --inputbox \
"Enter $var value:" 0 $DLG_WIDTH_WIDE "$input"  3>&1 1>&2 2>&3)
    echo "$result"
}

1118 1119 1120 1121 1122 1123 1124
function check_variables
{

    # Override variable settings dialog
    #
    if [[ "$verify" == "yes" ]] ; then
        if [[ "$GRAPHICAL" == "yes" ]] ; then
1125
            result=$($DLG --backtitle "$DLG_BACKTITLE" \
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
            --title "Variable settings" \
            --checklist \
"These variables use these system dependent defaults, but can be overridden "\
"through this interface or using environment variables.\n\n"\
"OPSYS: the default value returned from 'uname -s'\n"\
"ARCH: architecure info (Darwin, linux, aix, irix64, ...)\n"\
"C_COMPILER and CXX_COMPILER: the C and C++ compiler, respectively\n"\
"CFLAGS and CXXFLAGS: the flags to use for all compiles (e.g. -fPIC)\n"\
"C_OPT_FLAGS and CXX_OPT_FLAGS: the optimization flags to use for C and C++\n"\
"VISITARCH: unique architecture info, appended to library path installation\n"\
"REVISION: checkout a cwspecific SVN revision using supplied argument\n\n"\
"Select the variables you wish to modify:" 28 $DLG_WIDTH 8 \
           "OPSYS"            "$OPSYS"             "off" \
           "ARCH"             "$ARCH"              "off" \
           "C_COMPILER"       "$C_COMPILER"        "off" \
           "CXX_COMPILER"     "$CXX_COMPILER"      "off" \
           "CFLAGS"           "$CFLAGS"       "off" \
           "CXXFLAGS"         "$CXXFLAGS"     "off" \
           "C_OPT_FLAGS"      "$C_OPT_FLAGS"       "off" \
           "CXX_OPT_FLAGS"    "$CXX_OPT_FLAGS"     "off" \
           "FC_COMPILER"      "$FC_COMPILER"       "off" \
           "FCFLAGS"          "$FCFLAGS"       "off" \
           "VISITARCH"        "$VISITARCHTMP"      "off" \
1149
           "REVISION"         "$SVNREVISION"       "off"   3>&1 1>&2 2>&3) 
1150 1151 1152
           retval=$?

           # Remove the extra quoting, new dialog has --single-quoted
1153 1154
           choice="$(echo $result | sed 's/"//g' )"
           tmp_var=0
1155 1156 1157 1158
           case $retval in
             0)
               for OPTION in $choice
               do
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171

                   #this code uses the name to get and set the option value
                   #please use this convention, otherwise you will have to create
                   #exception as the ones below..
                   [[ $OPTION == "VISITARCH" ]] && OPTION="VISITARCHTMP"
                   [[ $OPTION == "REVISION" ]] && OPTION="SVNREVISION"

                   eval "tmp_var=\"\$$OPTION\""
                   tmp_var=$(check_variables_dialog $OPTION "$tmp_var")
                   eval "$OPTION=\"$tmp_var\""

                   if [[ $OPTION == "SVNREVISION" ]]; then
                        echo "Revision set to $SVNREVISION"
1172 1173
                        DO_SVN="yes"
                        DO_REVISION="yes"
1174
                   fi
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204
               done
               ;;
             1)
               warn "Cancel pressed."
               ;;
             255)
               warn "ESC pressed.";;
             *)
               warn "Unexpected return code: $retval";;
           esac
       fi
    fi

    return 0
}


# *************************************************************************** #
#                          Function 9, build_hostconf                         #
#                                                                             #
# Mark C. Miller, Wed Oct 27 19:29:19 PDT 2010                                #
# Adjusted ordering of database lib variables to ensure LIBDEP gets processed #
# correctly. Added comments to host conf file regarding ordering issue.       #
#                                                                             #
# Kathleen Bonnell, Wed Feb 16 08:35:40 PST 2011                              #
# Remove setting of CMAKE_BUILD_TYPE                                          #
#                                                                             #
# Kathleen Biagas, Mon Aug 8 08:12:37 MST 2011                                #
# Use FILEPATH type for compilers, STRING type for libdep.                    # 
# *************************************************************************** #
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230
hostconf_library_success=""
function hostconf_library
 {
    local build_lib=$1
    local depends_on=""

    # if already in success list then ignore..
    if [[ "$hostconf_library_success" == *$build_lib* ]]; then
        return
    fi

    depends_on=$("bv_${build_lib}_depends_on")

    #replace commas with spaces if there are any..
    depends_on=${depends_on//,/ }

    for depend_lib in `echo $depends_on`;
    do
        hostconf_library $depend_lib
    done

    #build ..
    $"bv_${build_lib}_host_profile"
    hostconf_library_success="${hostconf_library_success} ${build_lib}"
}

1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246

function build_hostconf
{
    #
    # Set up environment variables for the configure step.
    #
    PARFLAGS=""
    if [[ "$parallel" == "yes" ]] ; then
       PARFLAGS="--enable-parallel"
    fi

    #
    # Set up the config-site file, which gives configure the information it
    # needs about the third party libraries.

    export HOSTCONF="$(hostname).cmake"
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257

    if [[ "${VISIT_HOSTNAME}" != "" ]]; then
        info "VISIT_HOSTNAME env variable found: Using ${VISIT_HOSTNAME}.cmake"
        HOSTCONF="${VISIT_HOSTNAME}.cmake"
    fi

    if [[ "${EXTERNAL_HOSTNAME}" != "" ]]; then
        info "External Hostname variable found: Using ${EXTERNAL_HOSTNAME}"
        HOSTCONF="${EXTERNAL_HOSTNAME}"
    fi

1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
    info "Creating $HOSTCONF"

    # First line of config-site file provides a hint to the location
    # of cmake.

    THIRD_PARTY_ABS_PATH=$(pushd $THIRD_PARTY_PATH 1,2>/dev/null; pwd; popd 1,2>/dev/null)
    if [[ "$CMAKE_INSTALL" != "" ]]; then
        echo "#$CMAKE_INSTALL/cmake" > $HOSTCONF
    else
        echo "#$THIRD_PARTY_ABS_PATH/cmake/$CMAKE_VERSION/$VISITARCH/bin/cmake" > $HOSTCONF
    fi
    echo "##" >> $HOSTCONF
    echo "## $0 generated host.cmake" >> $HOSTCONF
    echo "## created: $(date)" >> $HOSTCONF
    echo "## system: $(uname -a)" >> $HOSTCONF
    echo "## by: $(whoami)" >> $HOSTCONF
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Setup VISITHOME & VISITARCH variables." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "SET(VISITHOME $VISITDIR)" >> $HOSTCONF
    echo "SET(VISITARCH $VISITARCH)" >> $HOSTCONF
    echo >> $HOSTCONF

#####
    echo "## Compiler flags." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_C_COMPILER $C_COMPILER TYPE FILEPATH)">> $HOSTCONF
    echo "VISIT_OPTION_DEFAULT(VISIT_CXX_COMPILER $CXX_COMPILER TYPE FILEPATH)" >> $HOSTCONF

    if [[ "$USE_VISIBILITY_HIDDEN" == "yes" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_C_FLAGS \"$CFLAGS -fvisibility=hidden\" TYPE STRING)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_CXX_FLAGS \"$CXXFLAGS -fvisibility=hidden\" TYPE STRING)" >> $HOSTCONF
    else
whitlocb's avatar
whitlocb committed
1292 1293 1294 1295 1296 1297
        if test -n "$CFLAGS" ; then
            echo "VISIT_OPTION_DEFAULT(VISIT_C_FLAGS \"$CFLAGS\" TYPE STRING)" >> $HOSTCONF
        fi
        if test -n "$CXXFLAGS" ; then
            echo "VISIT_OPTION_DEFAULT(VISIT_CXX_FLAGS \"$CXXFLAGS\" TYPE STRING)" >> $HOSTCONF
        fi
1298 1299
    fi

1300 1301 1302 1303
    if [[ "${DO_JAVA}" == "yes" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_JAVA ON TYPE BOOL)" >> $HOSTCONF
    fi

whitlocb's avatar
whitlocb committed
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
    if [[ "$BUILD_VISIT_BGQ" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## BG/Q-specific settings" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "SET(CMAKE_CROSSCOMPILING    ON)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_X            OFF)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_GLEW         OFF)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_SLIVR            OFF)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_BOOST        OFF)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_DISABLE_SELECT   ON)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_USE_NOSPIN_BCAST OFF)" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_OPENGL_DIR       \${VISITHOME}/mesa/$MESA_VERSION/\${VISITARCH})" >> $HOSTCONF
        echo >> $HOSTCONF
    fi

1320 1321 1322 1323 1324 1325 1326 1327
    if [[ "$parallel" == "yes" ]] ; then
        echo >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "## Parallel Build Setup." >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo "VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON TYPE BOOL)" >> $HOSTCONF
        # we either set an mpi wrapper compiler in the host conf
        if [[ "$VISIT_MPI_COMPILER" != "" ]] ; then
whitlocb's avatar
whitlocb committed
1328 1329 1330 1331 1332 1333
            if [[ "$BUILD_VISIT_BGQ" == "yes" ]] ; then
                echo "## (inserted by build_visit for BG/Q. Some adjustment may be needed)" >> $HOSTCONF
                echo "SET(BLUEGENEQ /bgsys/drivers/V1R2M0/ppc64)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_PARALLEL ON TYPE BOOL)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_CXX_FLAGS \"-I\${BLUEGENEQ} -I\${BLUEGENEQ}/comm/sys/include -I\${BLUEGENEQ}/spi/include -I\${BLUEGENEQ}/spi/include/kernel/cnk -I\${BLUEGENEQ}/comm/xl/include\" TYPE STRING)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_C_FLAGS   \"-I\${BLUEGENEQ} -I\${BLUEGENEQ}/comm/sys/include -I\${BLUEGENEQ}/spi/include -I\${BLUEGENEQ}/spi/include/kernel/cnk -I\${BLUEGENEQ}/comm/xl/include\" TYPE STRING)" >> $HOSTCONF
1334
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LD_FLAGS  \"-L\${BLUEGENEQ}/spi/lib -L\${BLUEGENEQ}/comm/sys/lib -L\${BLUEGENEQ}/spi/lib -L\${BLUEGENEQ}/comm/sys/lib -L\${BLUEGENEQ}/spi/lib -L\${BLUEGENEQ}/comm/xl/lib -R/opt/ibmcmp/lib64/bg\" TYPE STRING)" >> $HOSTCONF
whitlocb's avatar
whitlocb committed
1335 1336 1337 1338 1339
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LIBS     mpich opa mpl pami SPI SPI_cnk rt pthread stdc++ pthread TYPE STRING)" >> $HOSTCONF
            else
                echo "## (configured w/ mpi compiler wrapper)" >> $HOSTCONF
                echo "VISIT_OPTION_DEFAULT(VISIT_MPI_COMPILER $VISIT_MPI_COMPILER TYPE FILEPATH)"  >> $HOSTCONF
            fi
1340 1341
        else
            # or we just set the flags.
whitlocb's avatar
whitlocb committed
1342
            echo "## (configured w/ user provided CXX (PAR_INCLUDE) & LDFLAGS (PAR_LIBS) flags)" \
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
             >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_CXX_FLAGS \"$PAR_INCLUDE\" TYPE STRING)"     >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LD_FLAGS  \"$PAR_LINKER_FLAGS\" TYPE STRING)" >> $HOSTCONF
            echo "VISIT_OPTION_DEFAULT(VISIT_MPI_LIBS        $PAR_LIBRARY_NAMES TYPE STRING)" >> $HOSTCONF
        fi
    fi

    if [[ "$DO_STATIC_BUILD" == "yes" ]] ; then
        echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Static build" >> $HOSTCONF
        echo "##" >> $HOSTCONF
        echo \
        "VISIT_OPTION_DEFAULT(VISIT_STATIC ON TYPE BOOL)" >> $HOSTCONF
    fi

camp's avatar
camp committed
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368
    echo >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## VisIt Thread Option" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    if [[ "$DO_THREAD_BUILD" == "yes" ]] ; then
        echo "VISIT_OPTION_DEFAULT(VISIT_THREAD ON TYPE BOOL)" >> $HOSTCONF
    else
        echo "VISIT_OPTION_DEFAULT(VISIT_THREAD OFF TYPE BOOL)" >> $HOSTCONF
    fi

1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
    echo >> $HOSTCONF
    echo \
"##############################################################" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## Database reader plugin support libraries" >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## The HDF4, HDF5 and NetCDF libraries must be first so that" >> $HOSTCONF
    echo "## their libdeps are defined for any plugins that need them." >> $HOSTCONF
    echo "##" >> $HOSTCONF
    echo "## For libraries with LIBDEP settings, order matters." >> $HOSTCONF
    echo "## Libraries with LIBDEP settings that depend on other" >> $HOSTCONF
    echo "## Library's LIBDEP settings must come after them." >> $HOSTCONF
    echo \
"##############################################################" >> $HOSTCONF

hkrishna's avatar
hkrishna committed
1384
    for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
1385
    do
1386
        hostconf_library ${reqlibs[$bv_i]}
1387 1388
    done

hkrishna's avatar
hkrishna committed
1389
    for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
1390
    do
1391
        hostconf_library ${optlibs[$bv_i]}
1392 1393 1394 1395 1396 1397
    done
    echo >> $HOSTCONF

    #
    # Patch for Ubuntu 11.04
    #
1398 1399 1400 1401 1402 1403 1404 1405 1406
    #if test -d "/usr/lib/x86_64-linux-gnu" ; then
    #    numLibs=$(ls -1 /usr/lib/x86_64-linux-gnu | wc -l)
    #    if (( $numLibs > 10 )) ; then
    #       rm -f $HOSTCONF.tmp
    #       cat $HOSTCONF | sed "s/\/usr\/lib/\/usr\/lib\/x86_64-linux-gnu/" > $HOSTCONF.tmp
    #       rm $HOSTCONF
    #       mv $HOSTCONF.tmp $HOSTCONF
    #    fi
    #fi
1407 1408 1409 1410 1411 1412

    cd "$START_DIR"
    echo "Done creating $HOSTCONF"
    return 0
}

1413 1414
function printvariables  
{
1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438
  printf "The following is a list of user settable environment variables\n"
  printf "\n"
  printf "%s%s\n" "OPSYS=" "${OPSYS}"
  printf "%s%s\n" "PROC=" "${PROC}"
  printf "%s%s\n" "REL=" "${REL}"
  printf "%s%s\n" "ARCH=" "${ARCH}"
  printf "%s%s\n" "VISITARCH=" "${VISITARCHTMP}"

  printf "%s%s\n" "C_COMPILER=" "${C_COMPILER}"
  printf "%s%s\n" "CXX_COMPILER=" "${CXX_COMPILER}"
  printf "%s%s\n" "CFLAGS=" "${CFLAGS}"
  printf "%s%s\n" "CXXFLAGS=" "${CXXFLAGS}"
  printf "%s%s\n" "C_OPT_FLAGS=" "${C_OPT_FLAGS}"
  printf "%s%s\n" "CXX_OPT_FLAGS=" "${CXX_OPT_FLAGS}"
  printf "%s%s\n" "PAR_INCLUDE=" "${PAR_INCLUDE}"
  printf "%s%s\n" "PAR_LIBS=" "${PAR_LIBS}"

  printf "%s%s\n" "MAKE=" "${MAKE}"
  printf "%s%s\n" "THIRD_PARTY_PATH=" "${THIRD_PARTY_PATH}"
  printf "%s%s\n" "GROUP=" "${GROUP}"
  printf "%s%s\n" "LOG_FILE=" "${LOG_FILE}"
  printf "%s%s\n" "LOG_FILE=" "${LOG_FILE}"
  printf "%s%s\n" "WGET_OPTS=" "${WGET_OPTS}"
  printf "%s%s\n" "SVNREVISION=" "${SVNREVISION}"
1439 1440
  
  bv_visit_print
hkrishna's avatar
hkrishna committed
1441
  for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
1442
  do
hkrishna's avatar
hkrishna committed
1443
      initialize="bv_${reqlibs[$bv_i]}_print"
1444 1445 1446
      $initialize
  done

hkrishna's avatar
hkrishna committed
1447
  for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
1448
  do
hkrishna's avatar
hkrishna committed
1449
      initialize="bv_${optlibs[$bv_i]}_print"
1450 1451 1452 1453
      $initialize
  done
}

1454 1455
function usage  
{
1456 1457 1458 1459 1460
  printf "Usage: %s [options]\n" $0
  printf "A download attempt will be made for all files which do not exist."
  printf "\n\n"
  printf "BOOLEAN FLAGS\n"
  printf "\tThese are used to enable or disable specific functionality.  They do not take option values.\n\n"
1461
  printf "%-15s %s [%s]\n" "--dry-run"  "Dry run of the presented options" "false"
1462
  printf "%-15s %s [%s]\n" "--build-mode" "VisIt build mode (Debug or Release)" "$VISIT_BUILD_MODE"
1463 1464
  printf "%-15s %s [%s]\n" "--console" "Do not use dialog ('graphical') interface" "!$GRAPHICAL"
  printf "%-15s %s [%s]\n" "--dbio-only" "Disables EVERYTHING but I/O." "$DO_DBIO_ONLY"
1465
  printf "%-15s %s [%s]\n" "--engine-only" "Only build the compute engine." "$DO_ENGINE_ONLY"
1466 1467 1468 1469 1470 1471 1472 1473 1474
  printf "%-15s %s [%s]\n" "--debug"   "Enable debugging for this script" "false"
  printf "%-15s %s [%s]\n" "--download-only" "Only download the specified packages" "false"
  printf "%-15s %s [%s]\n" "--flags-debug" "Add '-g' to C[XX]FLAGS" "false"
  printf "%-15s %s [%s]\n" "--group" "Group name of installed libraries" "$GROUP"
  printf "%-15s %s [%s]\n" "-h" "Display this help message." "false"
  printf "%-15s %s [%s]\n" "--help" "Display this help message." "false"
  printf "%-15s %s [%s]\n" "--java" "Build with the Java client library" "${DO_JAVA}"
  printf "%-15s %s [%s]\n" "--no-hostconf" "Do not create host.conf file." "$ON_HOSTCONF"
  printf "%-15s %s [%s]\n" "--parallel" "Enable parallel build, display MPI prompt" "$parallel"
1475
  printf "%-15s %s [%s]\n" "--prefix" "The directory to which VisIt should be installed once it is built" "$VISIT_INSTALL_PREFIX"
1476
  printf "%-15s %s [%s]\n" "--print-vars" "Display user settable environment variables" "false"
1477
  printf "%-15s %s [%s]\n" "--server-components-only" "Only build VisIt's server components (mdserver,vcl,engine)." "$DO_SERVER_COMPONENTS_ONLY"
1478 1479 1480 1481
  printf "%-15s %s [%s]\n" "--slivr" "Build with SLIVR shader support" "$DO_SLIVR"
  printf "%-15s %s [%s]\n" "--static" "Build using static linking" "$DO_STATIC_BUILD"
  printf "%-15s %s [%s]\n" "--stdout" "Write build log to stdout" "$LOG_FILE"
  
1482 1483 1484 1485 1486 1487 1488
  for (( bv_i=0; bv_i<${#grouplibs_comment[*]}; ++bv_i ))
  do
        name=${grouplibs_name[$bv_i]}
        comment=${grouplibs_comment[$bv_i]}
        printf "%-15s %s [%s]\n" "--$name" "$comment" ""
  done

1489 1490
  bv_visit_print_usage

hkrishna's avatar
hkrishna committed
1491
  for (( bv_i=0; bv_i<${#reqlibs[*]}; ++bv_i ))
1492
  do
hkrishna's avatar
hkrishna committed
1493
      initialize="bv_${reqlibs[$bv_i]}_print_usage"
1494 1495 1496
      $initialize
  done

hkrishna's avatar
hkrishna committed
1497
  for (( bv_i=0; bv_i<${#optlibs[*]}; ++bv_i ))
1498
  do
hkrishna's avatar
hkrishna committed
1499
      initialize="bv_${optlibs[$bv_i]}_print_usage"
1500 1501 1502 1503 1504 1505
      $initialize
  done

  printf "%s\n" ""
  printf "OPTIONS\n"
  printf "These values all take a special value.  If given, they require an associated value to be provided as well.\n\n"
1506 1507
  printf "%-15s \n\t%s [%s]\n" "--installation-build-dir"  "Specify the directory visit will use for building" "output-filename"
  printf "%-15s \n\t%s [%s]\n" "--write-unified-file"  "Write single unified build_visit file" "output-filename"
1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
  printf "%s <%s> %s [%s]\n" "--arch" "architecture" "Set architecture" "$VISITARCHTMP"
  printf "\t  %s\n" "   This variable is used in constructing the 3rd party"
  printf "\t  %s\n" "   library path; usually set to something like"
  printf "\t  %s\n" "   'linux_gcc-3.4.6' or 'Darwin_gcc-4.0.1'"
  printf "%-11s %s [%s]\n" "--cflag"   "Append a flag to CFLAGS" "${CFLAGS}"
  printf "%-11s %s [%s]\n" "--cxxflag" "Append a flag to CXXFLAGS" "$CXXFLAGS"
  printf "%-11s %s [%s]\n" "--cflags"  "Explicitly set CFLAGS" "$CFLAGS"
  printf "%-11s %s [%s]\n" "--cxxflags" "Explicitly set CXXFLAGS" "$CXXFLAGS"
  printf "%-11s %s [%s]\n" "--cc"  "Explicitly set C_COMPILER" "$C_COMPILER"
  printf "%-11s %s [%s]\n" "--cxx" "Explicitly set CXX_COMPILER" "$CXX_COMPILER"
  printf "%-11s <%s> %s [%s]\n" "--makeflags" "flags" "Flags to 'make'" "$MAKE_OPT_FLAGS"
  printf "%s <%s> %s\n" "--svn" \
    "Obtain VisIt source code and third party libraries from the SVN server"
  printf "\t%s\n" "    [svn co $SVN_REPO_ROOT_PATH/$SVN_SOURCE_PATH]"
  printf "%s <%s> %s\n" "--svn-anonymous" \
    "Obtain VisIt source code and third party libraries using the anonymous SVN mirror."
  printf "\t%s\n" "    [svn co $SVN_ANON_ROOT_PATH/$SVN_SOURCE_PATH]"
  printf "%s <%s> %s\n" "--svn-revision" "revision" \
    "Specify the SVN revision of the VisIt source code and third party libraries to download.  Used in conjunction with --svn or --svn-anonymous."
  printf "%s <%s> %s [%s]\n" "--tarball" "file" "tarball to extract VisIt from" "$VISIT_FILE"
  printf "%-11s <%s> \n%s [%s]\n" "--thirdparty-path" "/path/to/directory" \
    "             Specify the root directory name under which the 3rd party
             libraries have been installed.  If defined, it would typically
             mean the 3rd party libraries are pre-built and are installed
             somewhere like /usr/gapps/visit." "${THIRD_PARTY_PATH}"
  printf "%s <%s> %s [%s]\n" "--version" "version" "The VisIt version to build" "$VISIT_VERSION"
}

1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574

#TODO: pass these two variables from command line..
mangle_src="VTK"
mangle_dest="MTK"
uc_mangled_src=`echo $mangle_src | tr '[a-z]' '[A-Z]'`
uc_mangled_dest=`echo $mangle_dest | tr '[a-z]' '[A-Z]'`
lc_mangled_src=`echo $mangle_src | tr '[A-Z]' '[a-z]'`
lc_mangled_dest=`echo $mangle_dest | tr '[A-Z]' '[a-z]'`

function mangle_file
{
    local input_file="$1"
    local output_file="$2"

    cat "$input_file" | sed -e s/${lc_mangled_src}/${lc_mangled_dest}/g -e s/${uc_mangled_src}/${uc_mangled_dest}/g > "$output_file"
    
    #chmod --reference=$input_file $output_file
    if [[ -r "$input_file" ]]; then
        chmod u+r "$output_file"
    fi
    if [[ -w "$input_file" ]]; then
        chmod u+r "$output_file"
    fi
    if [[ -x "$input_file" ]]; then
        chmod u+x "$output_file"
    fi
}

function mangle_libraries
{
    local