# +--------------------------------------------------------------------------+
# | Copyright 1993 - 2002 Rational Software Corporation. All Rights Reserved.|
# | This software contains proprietary and confidential information of       |
# | Rational and its suppliers. Use, disclosure or reproduction is           |
# | prohibited without the prior express written consent of Rational.        |
# +--------------------------------------------------------------------------+
# @(#)$Revision: 1.190 $  $Date: 06/18/2002 12:06:33 $
#
#  MODULE SPECIFICATION
#  Name:
#    post_install
#
#  Subsystem:
#    install
#
#  Description:  (for all but Rose)
#    fix up .Rational_Locations for subsystems.
#    fix up imports
#    fix up compiler key in all switch files
#    run apex set_location, remodel, compile, link
#  For Rose:
#    Create the configuration files.
#  For AXI as make_tests:
#    Make test programs.
#    So user can just do relocations, allow 'dont_build' as an argument
#------------------------------------------------------------------------

#-----------------------------------------------------------------
usage() {
#-----------------------------------------------------------------

    status=$1
    echo  "
Usage: $command [<options>]

    <options>:"

    case $command in

    post_install )
        echo "
    -help or -h
        Show this usage message.

    -unfreeze or -uf
        If post_install encounters a frozen view it will unfreeze it first.
        This is useful to re-run post_install for an Apex layered product
        to upgrade it to use a newer, yet compatible release of Apex.

    -askunfreeze or -auf
        Same as the -unfreeze option except that the installer is asked
        if they wish to unfreeze each view.

    -install_crypt or -ic
        If there are any encrypted components, decrypt and install them.

    -install_paches or -ip
        If there are any patches in ${disk_install_dir:-$install_dir}
        then use this option to install these patches.
        If there is a post_patch file, run it.

    -patch <patch_id>
        Used to install new subsystem views where the description of these
        views needs to be in $TARGET_ARCH/prod_desc.<patch_id> file.

NOTE:

    The -unfreeze and -askunfreeze options have no effect if
    $product_name has no views
    or the views that are shipped with it have not been frozen.
"
        ;;

    make_tests )
        echo "
    -help or -h
        Show this usage message.

    dont_build
        Used to prevent compiling and linking the demonstration clients.

See also:
    Ada X Interface Installation Guide, Installation Verfication.
"
        ;;
    esac

    exit $status
}

#------------------------------------------------------------------------
set_home_vars() {
#------------------------------------------------------------------------
# Check/set product home var and APEX_HOME (if product is a layered product).

    if [ -z "$prod_home" ]
    then
        prod_home=`get_var INST_HOMEDIR`
    fi
    PROD_HOME=$prod_home

    if [ -n "$home_var" ]
    then
        eval val=\$$home_var
        if [ -z "$val" ]
        then
            eval $home_var=$PROD_HOME
        fi
        export $home_var
        case $home_var in
        APEX_VW_HOME|APEX_LX_HOME|APEX_RT_HOME )
            APEX_EMBEDDED_HOME=$PROD_HOME
            export APEX_EMBEDDED_HOME
            ;;
        esac
    fi

    if [ -n "$prod_base" ]
    then
        APEX_BASE=$prod_base
        export APEX_BASE
    fi

    set_flexlm_version
    flex_dir=$prod_base/cots/flexlm.$flexlm_version/$ARCH
    if [ -d $flex_dir ]
    then
        PATH=$flex_dir:$PATH
        export PATH
    fi

    apex_layered_product=${apex_layered_product:-no}
    if [ $apex_layered_product = no ]
    then
        return
    fi

    # At this point we are installing either Apex, Summit or a layered product.
    set_apex_home

    # Make sure that we have PATHs to where we need to run things from
    # and that the appropriate architecture is set.
    # Final path setting stuff... include directories touched by architecture.
    _dirs="$prod_home/bin  $prod_home/$ARCH/bin"
    if [ $product != apex  -a  -n "$APEX_HOME" ]
    then
        _dirs="$APEX_HOME/bin $APEX_HOME/$ARCH/bin $_dirs"
    fi

    for _dir in $_dirs
    do
        if [ -d $_dir ]
        then
            PATH=$_dir:$PATH
        fi
    done
    export PATH
}

#------------------------------------------------------------------------
tell_about_steps() {
#------------------------------------------------------------------------

    echo "
$SEP

This part of the installation process will do the final steps needed to
complete the installation of $product_name $banner_version."
    press_cr
}

#------------------------------------------------------------------------
just_say_yes() {
#------------------------------------------------------------------------

    for y in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    do
        echo yes
    done
}

#------------------------------------------------------------------------
install_patch_now() {
#------------------------------------------------------------------------

    patch_name=`$BASENAME $patch_program`
    test -x ./$patch_name || $CHMOD u+x $patch_name 2>/dev/null
    show_patch_description no-more

    # Check if this patch install program supports -auto_commit.
    if $GREP DO_AUTO_COMMIT $patch_name >/dev/null
    then
        echo
        echo "Installing patch $patch_id..."
        ./$patch_name -auto_commit && return
        echo
        echo Error encountered while installing patch $patch_id.
        return
    fi

    # It does not, so install patch and then run with -commit option.
    echo
    $ECHON "Installing patch $patch_id...$NOCR"
    if just_say_yes | ./$patch_name >> $patch_log 2>&1
    then
        echo Done.
        if [ -x $install_dir/patches/$patch_name ]
        then
            $ECHON "Committing patch $patch_id...$NOCR"
            $install_dir/patches/$patch_name -commit >> $patch_log 2>&1
            echo Done.
        fi
    else
        echo
        echo Error encountered while installing patch $patch_id.
        echo Messages have been recorded in:
        echo "  $patch_log"
    fi
}

#------------------------------------------------------------------------
extract_pid_from_install() {
#------------------------------------------------------------------------
    eval `grep "^PID=" $patch_inst`
    echo $PID
}

#------------------------------------------------------------------------
set_patch_list() {
#------------------------------------------------------------------------

    # First, look for any loose patch files in the install directory.
    # their own PID directory.
    for patch_inst in \
        $install_dir/install_????????_?? \
        $install_dir/install_?????????_?
    do
        test -f $patch_inst || continue
        pid=`(extract_pid_from_install)`
        test -n "$pid" || continue
        num_patches=`$EXPR $num_patches + 1`
        patch_list="$patch_list
$pid $install_dir"
    done

    # Now check for patches in patch PID directories in these 2 locations:
    for pdir in $disk_install_dir $install_dir
    do
        for patch_dir in $pdir/????????-?? $pdir/?????????-?
        do
            if [ -d $patch_dir ]
            then
                pid=`$BASENAME $patch_dir`
                if [ "$pdir" = "$disk_install_dir" ]
                then
                    # This patch has already been copied to the install area.
                    if [ -d $install_dir/$pid ]
                    then
                        continue
                    fi
                fi

                for ip_file in $patch_dir/install_*
                do
                    if [ -f $ip_file ]
                    then
                        num_patches=`$EXPR $num_patches + 1`
                        patch_list="$patch_list
$pid $patch_dir"
                        break
                    fi
                done
            fi
        done
    done
}

#------------------------------------------------------------------------
not_in_list() {
#------------------------------------------------------------------------
# Check if arg1 in arg2..argN (the list).
# If it is, return false.
# If not in the list, return true.

    _i_=$1
    shift
    for _j_ in $*
    do
        if [ "$_i_" = "$_j_" ]
        then
            unset _i_ _j_
            return 1
        fi
    done
    unset _i_ _j_
    return 0
}

#------------------------------------------------------------------------
sort_patch_list() {
#------------------------------------------------------------------------
# Sort the list of patches so that any required patches install before
# the patch that requires it.  To this, go through the list of patches
# and extract the REQ_PID settings.  Some of them will require a series id
# or a specific patch number.  Will need to determine the patch id for each
# series id.

    n=0
    unset pid_seq_list
    set -- $patch_list
    while [ $# -gt 0 ]
    do
        patch_id=$1
        patch_dir=$2
        shift 2
        for patch_inst in $patch_dir/install_*
        do
            test -f $patch_inst && break
            continue 2
        done

        n=`expr $n + 1`
        pid_seq_list="$pid_seq_list $n"
        eval patch_dir$n=$patch_dir
        eval patch_id$n=$patch_id
        patch_date=`echo $patch_id | cut -c1-8`
        eval patch_date$n=$patch_date

        unset sid SERIES_ID
        eval `grep "^SERIES_ID=" $patch_inst`
        if [ -n "$SERIES_ID" ]
        then
            for sid in $SERIES_ID
            do
                break
            done
            eval patch_sid$n=$sid
        fi

        # Set the required id list for this patch.
        eval `grep "^REQ_PID.*=" $patch_inst`
        if [ -n "$REQ_PID1" ]
        then
            req_pid=$REQ_PID1
            unset REQ_PID1
        else
            eval `grep "^REQ_SERIES=" $patch_inst`
            if [ -n "$REQ_SERIES" ]
            then
                req_pid=`echo "$REQ_SERIES" | awk '{print $3,$1,$2}`
                unset REQ_SERIES
            fi
        fi
        r=1
        unset reqs
        while [ -n "$req_pid" ]
        do
            first_req=true second_req=false third_req=false
            for req in $req_pid
            do
                case $req in
                [1-9]????????-[0-9]|[1-9]???????-[0-9][0-9] )
                    reqs="$reqs $req"
                    ;;
                * )
                    if $first_req
                    then
                        reqs="$reqs $req"
                        first_req=false
                        second_req=true
                    elif $second_req
                    then
                        second_req=false
                        third_req=true
                    elif $third_req
                    then
                        third_req=false
                        first_req=true
                    fi
                    ;;
                esac
            done
            r=`expr $r + 1`
            eval req_pid=\$REQ_PID$r
            unset REQ_PID$r
        done
        if [ -n "$reqs" ]
        then
            eval patch_req$n=\$reqs
        fi
    done

    # Convert patch req_ids to their patch dates.
    for n in $pid_seq_list
    do
        eval patch_req=\$patch_req$n
        if [ -n "$patch_req" ]
        then
            unset reqs
            for req in $patch_req
            do
                case $req in
                [1-9]????????-[0-9]|[1-9]???????-[0-9][0-9] )
                    patch_date=`echo $req | cut -c1-8`
                    reqs="$reqs $patch_date"
                    for k in $pid_seq_list
                    do
                        eval pdk=\$patch_date$k
                        if [ "$pdk" = "$patch_date" ]
                        then
                            eval pd$patch_date=$k
                            break
                        fi
                    done
                    continue
                    ;;
                esac

                # Lookup the patch date for this series dependency.
                for k in $pid_seq_list
                do
                    eval sid=\$patch_sid$k
                    if [ "$sid" = "$req" ]
                    then
                        eval patch_date=\$patch_date$k
                        reqs="$reqs $patch_date"
                        break
                    fi
                done
                eval pd$patch_date=$k
            done
            eval patch_req$n=\$reqs
        fi
    done

    # Assemble a new list.  Insert any required patches ahead of the
    # current patch unless it is already in the new list.
    unset n_list
    for n in $pid_seq_list
    do
        eval patch_req=\$patch_req$n
        if [ -n "$patch_req" ]
        then
            for req in $patch_req
            do
                eval pdn=\$pd$req
                if [ -n "$pdn" ]
                then
                    if not_in_list $pdn $n_list
                    then
                        n_list="$n_list $pdn"
                    fi
                fi
            done
        fi

        if not_in_list $n $n_list
        then
            n_list="$n_list $n"
        fi
    done

    unset patch_list
    for n in $n_list
    do
        eval patch_id=\$patch_id$n
        eval patch_dir=\$patch_dir$n
        patch_list="$patch_list $patch_id $patch_dir"
    done
}

#------------------------------------------------------------------------
sed_patch_desc() {
#------------------------------------------------------------------------
    echo
    if [ $num_patches -gt 1 ]
    then
        echo "$patch_num of $num_patches: Description of patch $patch_id:"
    else
        echo "Description of patch $patch_id:"
    fi
    $SED -e 's?^?   ?' $1
}

#------------------------------------------------------------------------
show_patch_description() {
#------------------------------------------------------------------------

    test "$shown_patch_desc" = yes && return

    if [ "$1" = more ]
    then
         sed_patch_desc $patch_description | more
    else
         sed_patch_desc `$BASENAME $patch_description`
    fi
    shown_patch_desc=yes
}

#------------------------------------------------------------------------
run_post_patch() {
#------------------------------------------------------------------------
# Check for post_patch script and run it if it exists.
# Check for patches under disk_install_dir or install_dir.

    patch_log=$install_dir/install.patch.log

    if [ -f $install_dir/post_patch ]
    then
        # If post_patch runs post_install, check for recursion.
        POST_PATCH=`get_var POST_PATCH`
        if [ "$POST_PATCH" != STARTED ]
        then
            separator
            put_var POST_PATCH STARTED
            . $install_dir/post_patch
            put_var POST_PATCH COMPLETED
        fi
    fi

    if [ -n "$PID" ]
    then
        # Currently installing a patch, return to avoid recursion.
        return
    fi

    if [ -f $ARCH/disk_install_dir ]
    then
        . $ARCH/disk_install_dir
    fi


    echo
    num_patches=0
    set_patch_list

    case "$num_patches" in
    0 )
        return
        ;;
    1 )
        echo "Found 1 $product_name patch to install."
        ;;
    * )
        echo "Found $num_patches $product_name patches to install."
        sort_patch_list
        ;;
    esac

    patch_num=0

    set -- $patch_list
    while [ $# -gt 0 ]
    do
        patch_id=$1
        patch_dir=$2
        shift 2

        patch_num=`$EXPR $patch_num + 1`

        if [ -f patches/$patch_id ]
        then
            echo
            echo Patch $patch_id has already been installed.
            continue
        fi

        _pid=`echo $patch_id | $SED -e "s?-?_?"`
        patch_program=`$LS $patch_dir/install*$_pid 2>/dev/null`
        if [ -z "$patch_program" ]
        then
            echo
            echo Patch $patch_id cannot be installed. \
                 The install script is missing.
            continue
        fi

        shown_patch_desc=no
        patch_description=$patch_dir/description.$patch_id
        if [ ! -f $patch_description ]
        then
            $SED -e "1,/^#DESCRIPTION/d" \
                 -e '/^#END_DESCRIPTION/,$d' \
                 -e 's/^#     //' \
                $patch_program > $patch_dir/description.$patch_id
        fi

        if [ -f $patch_dir/optional ]
        then
            show_patch_description more
            get_yn "Would you like to install patch $patch_id?" yes
            if [ $result = no ]
            then
                echo "Will not install patch $patch_id."
                echo "If you want to install it later you can run:"
                echo "    % ./$command -ip"
                continue
            fi
        fi

        if [ ! -s $patch_log ]
        then
            echo "Ignore any messages in this log about committing or restoring
patches since they have already been committed by post_install.
$SEP" > $patch_log
            $CHMOD a+w $patch_log
        fi

        if [ "$patch_dir" = "$install_dir" ]
        then
            install_patch_now
        else
            ( cd $patch_dir ; install_patch_now )
        fi
    done
}

#------------------------------------------------------------------------
run_pre_apexinit_patch() {
#------------------------------------------------------------------------

    if [ -n "$PID" ]
    then
        # Currently installing a patch, return to avoid recursion.
        return
    fi

    patch_sub_dir=pre_apexinit
    if [ ! -d $patch_sub_dir ]
    then
        return
    fi

    num_patches=0
    for patch_dir in $patch_sub_dir/?????????-?
    do
        for ip_file in $patch_dir/install_*
        do
            if [ -f $ip_file ]
            then
                num_patches=`$EXPR $num_patches + 1`
                pid=`$BASENAME $patch_dir`
                patch_list="$patch_list
$pid $patch_dir"
                break
            fi
        done
    done

    case "$num_patches" in
    0 )
        return
        ;;
    1 )
        echo
        echo "Found 1 $product_name patch to install before"
        echo "running apexinit."
        ;;
    * )
        echo
        echo "Found $num_patches $product_name patches to install before"
        echo "running apexinit."
        sort_patch_list
        ;;
    esac

    patch_log=$install_dir/install.patch.log
    patch_num=0

    set -- $patch_list
    while [ $# -gt 0 ]
    do
        patch_id=$1
        patch_dir=$2
        shift 2

        patch_num=`$EXPR $patch_num + 1`

        shown_patch_desc=no
        patch_description=$patch_dir/description.$patch_id
        patch_program=`$LS $patch_dir/install*$_pid 2>/dev/null`
        if [ ! -f $patch_description ]
        then
            $SED -e "1,/^#DESCRIPTION/d" \
                 -e '/^#END_DESCRIPTION/,$d' \
                 -e 's/^#     //' \
                $patch_program > $patch_dir/description.$patch_id
        fi

        if [ -f $patch_dir/optional ]
        then
            show_patch_description more
            get_yn "Would you like to install patch $patch_id?" yes
            if [ $result = no ]
            then
                echo "Will not install patch $patch_id."
                echo "If you want to install it later you can run:"
                echo "    % ./$command -ip"
                continue
            fi
        fi

        if [ ! -s $patch_log ]
        then
            echo "Ignore any messages in this log about committing or restoring
patches since they have already been committed by post_install.
$SEP" > $patch_log
            $CHMOD a+w $patch_log
        fi

        if [ "$patch_dir" = "$install_dir" ]
        then
            install_patch_now
        else
            ( cd $patch_dir ; install_patch_now )
        fi
    done
}

#------------------------------------------------------------------------
cmp_move_file() {
#------------------------------------------------------------------------

    if cmp -s $2 $1 >/dev/null
    then
        echo okay.
        return $FALSE
    else
        $MV $1 $2
        echo fixed.
        return $TRUE
    fi
}

#------------------------------------------------------------------------
location_not_set() {
#------------------------------------------------------------------------

    $ECHON "  Checking .Rational_Location: $NOCR"
    if _loc=`is_a_link $1/.Rational_Location`
    then
        if [ "$_loc" = "$ss_path" ]
        then
            return $FALSE
        else
            return $TRUE
        fi
    else
        return $TRUE
    fi
}

#------------------------------------------------------------------------
warn_of_missing_model() {
#------------------------------------------------------------------------

    logit warn "Cannot remodel this view--this Apex $2 model does not exist:"
    logit cont "  $3"
    logit cont "You need to install the base Apex $1 $2 Subsystems."
}

#------------------------------------------------------------------------
check_ss_view_key() {
#------------------------------------------------------------------------
# Check that the BUILD_KEY or COMPILER_KEY exists.
# If one is not specified, return true.
# Warn installer if it does not exist.

    set -- 1 `$EGREP "COMPILER_KEY:|BUILD_KEY:" $Switches`
    if [ $# -lt 3 ]
    then
        return $TRUE
    fi

    _key_name=$2
    _key=$3
    if [ -d "$_key" ]
    then
        return $TRUE
    fi

    # If this is an Ada view and it imports LRM, check the LRM
    # switch file for the COMPILER_KEY.
    if [ "$layer_lang" = ada ]
    then
        _key_name=COMPILER_KEY
        lrm_view=`$GREP /lrm.ss/ $view_path/Imports/Description.cfg`
        lrm_switches=$lrm_view/Policy/Switches
        if [ -f "$lrm_switches" ]
        then
            set -- 1 `$GREP "COMPILER_KEY:" $lrm_switches`
            if [ $# -eq 3 ]
            then
                _lrm_key=$3
                if [ -d "$_lrm_key" ]
                then
                    $ECHON "  Checking compiler key switch: $NOCR"
                    $SED -e "s?COMPILER_KEY:.*?COMPILER_KEY: $_lrm_key?" \
                         $Switches > $temp
                    cmp_move_file $temp $Switches
                    return $TRUE
                fi
            fi
        fi
    fi

    case $_key_name in
    B* ) _key_name=BUILD_KEY ;;
    C* ) _key_name=COMPILER_KEY ;;
    esac

    logit warn "Cannot remodel this view--the $_key_name does not exist:"
    logit cont "  $_key"
    logit cont "Skipping $ss_name/$view_name"
    return $FALSE
}

#------------------------------------------------------------------------
set_chk_asis_asis95() {
#------------------------------------------------------------------------

    if [ -s $APEX_HOME/.asis_version ]
    then
        asis83_ver=`$CAT $APEX_HOME/.asis_version`
        chk_asis=asis.ss
    else
        chk_asis=
    fi

    if [ -s $APEX_HOME/.asis95_version ]
    then
        asis95_ver=`$CAT $APEX_HOME/.asis95_version`
        chk_asis95=asis.ada95.ss
    else
        chk_asis95=
    fi
}

#------------------------------------------------------------------------
set_apex_pver_etc() {
#------------------------------------------------------------------------

    if [ $product = apex ]
    then
        apex_ver=$product_version
        apex_pver=$version_patch
    elif [ -n "$APEX_HOME" ]
    then
        if [ -f $APEX_HOME/.apex_version ]
        then
            apex_ver=`$CAT $APEX_HOME/.apex_version`
            apex_version=$apex_ver
            apex_pl=`$CAT $APEX_HOME/.patch_level 2>/dev/null`
            case $apex_pl in
            [b-z] )
                apex_pver=${apex_ver}$apex_pl
                ;;
            * )
                apex_pver=$apex_ver
                ;;
            esac
            set_chk_asis_asis95
        fi
    fi
}

#------------------------------------------------------------------------
set_check_lists() {
#------------------------------------------------------------------------

    if [ -n "$check_lists_set" ]
    then
        return
    fi

    # Check Ada 83 subsystems
    for ss in \
        apex_ada.ss \
        checker_utilities.ss \
        code_rule_checker.ss \
        vads_exec.ss
    do
        if [ -d $prod_base/ada/$ss/. ]
        then
            ada83_check_list="$ada83_check_list $ss"
        fi
    done


    # Check both Ada 95 and Ada 83 subsystems
    for ss in \
        $chk_asis \
        $chk_asis95 \
        lrm.ss \
        posix.ss \
        predefined.ss \
        pure.ss \
        pure_api.ss \
        rational.ss \
        rts_trace.ss \
        rts_vads_exec.ss \
        stack_trace.ss \
        vads_compatibility.ss \
        vads_compatibility_static.ss
    do
        if [ -d $prod_base/ada/$ss/. ]
        then
            common_check_list="$common_check_list $ss"
        fi
    done

    # Check Ada 95 subsystems
        # distributed_systems.ss
        # information_systems.ss
    for ss in \
        numerics.ss \
        systems_programming.ss \
        real_time_systems.ss
    do
        if [ -d $prod_base/ada/$ss/. ]
        then
            ada95_check_list="$ada95_check_list $ss"
        fi
    done
    check_lists_set=yes
}

#------------------------------------------------------------------------
check_ss_imports() {
#------------------------------------------------------------------------
# Substitute imports for the ones installed with Apex.

    set_check_lists

    if [ "$layer_dialect" = ada95 ]
    then
        ss_check_list="$common_check_list $ada95_check_list"
    else
        ss_check_list="$common_check_list $ada83_check_list"
    fi

    for ss in $ss_check_list
    do
        for ss_arch in \
            $ss/${ARCH_OS}.ada95.thread.relaxed \
            $ss/${ARCH_OS}.ada95.thread \
            $ss/${ARCH_OS}.ada95.relaxed \
            $ss/${ARCH_OS}.ada95.aio \
            $ss/${ARCH_OS}.ada95 \
            $ss/${ARCH_OS}.ada83.thread \
            $ss/${ARCH_OS}.ada83.aio \
            $ss/${ARCH_OS}.ada83
        do
            case $ss_arch in
            asis.ss* )
                a_view=$prod_base/$layer_lang/$ss_arch.$asis83_ver.rel
                ;;
            asis.ada95.ss* )
                a_view=$prod_base/$layer_lang/$ss_arch.$asis95_ver.rel
                ;;
            * )
                a_view=$prod_base/$layer_lang/$ss_arch.$apex_ver.rel
                    ;;
            esac

            # Look to see if a_view's are installed.
            if [ ! -d $a_view ]
            then
                continue
            fi

            # Replace it with a_view if one in there does not exist.
            if c_view=`$GREP "/$ss_arch\." $import_file`
            then
                if [ -n "$c_view" ]
                then
                    $ECHON "    Checking $ss import: $NOCR"
                    $SED -e "s?.*/$ss_arch.*?$a_view?" \
                         $import_file > $temp
                    cmp_move_file $temp $import_file
                    break
                fi
            fi
        done
    done
}

#------------------------------------------------------------------------
customize_imports() {
#------------------------------------------------------------------------

    echo "  Checking imports ..."

    import_file=$view_path/Imports/Description.cfg

    $ECHON "    Checking base location in imports: $NOCR"
    # Set the base location
    $SED -e "s?%%APEX_BASE%%?$prod_base?g" \
         -e "s?.*/base/$layer_lang?$prod_base/$layer_lang?g" \
         -e "s?/sierra/products/base/?$prod_base/?g" \
         -e "s?/aloha/products/base/?$prod_base/?g" \
        $import_file > $temp
    cmp_move_file $temp $import_file

    if [ -s $view_path/Imports/Mutual_Description.cfg ]
    then
        mutual_file=$view_path/Imports/Mutual_Description.cfg
        $ECHON "    Checking base location in mutual imports: $NOCR"
        $SED -e "s?%%APEX_BASE%%?$prod_base?g" \
             -e "s?.*/base/$layer_lang?$prod_base/$layer_lang?g" \
             -e "s?/sierra/products/base/?$prod_base/?g" \
             -e "s?/aloha/products/base/?$prod_base/?g" \
            $mutual_file > $temp
        cmp_move_file $temp $mutual_file
    else
        mutual_file=
    fi

    if [ $product = apex ]
    then
        e_cpp_comp=" "
    else
        if [ "$layer_lang" = ada ]
        then
            check_ss_imports
        fi
    fi

    if [ $check_sw_imp = yes ]
    then
        if $GREP -v "^#" $import_file | $EGREP "/sierra|/ned"
        then
            echo more $import_file >> $install_dir/sierra_ned
        fi
        if [ -n "$mutual_file" ]
        then
            if $GREP -v "^#" $mutual_file | $EGREP "/sierra|/ned"
            then
                echo more $mutual_file >> $install_dir/sierra_ned
            fi
        fi
    fi
}

#------------------------------------------------------------------------
customize_switches() {
#------------------------------------------------------------------------

    Switches=$view_path/Policy/Switches

    if [ "$layer_dialect" = "$layer_lang" ]
    then
        arch_key=$ARCH_OS
    else
        arch_key=${ARCH_OS}_$layer_dialect
    fi

    $ECHON "  Checking view property switches: $NOCR"
    $SED -e "s?/sierra/products/base/?$prod_base/?g" \
         -e "s?/aloha/products/base/?$prod_base/?g" \
         $view_properties > $temp
    set -- 1 `$GREP MODEL: $temp`
    if [ -n "$3" ]
    then
        if [ ! -d $3 ]
        then
            # Model not installed, remove.
            $GREP -v "MODEL:" $temp > $temp.2
            $MV $temp.2 $temp
        fi
    fi
    cmp_move_file $temp $view_properties

    if [ -f $view_path/Policy/TestMate.sw ]
    then
        $ECHON "  Checking TestMate switches: $NOCR"
        $SED -e "s?%%APEX_BASE%%?$prod_base?g" \
             -e "s?/sierra/products/base/?$prod_base/?g" \
             -e "s?/aloha/products/base/?$prod_base/?g" \
        $view_path/Policy/TestMate.sw > $temp
        cmp_move_file $temp $view_path/Policy/TestMate.sw
    fi

    if [ -f $ss_path/Policy/Taskmgmt.sw ]
    then
        $ECHON "  Checking Summit switches: $NOCR"
        $SED -e "s?%%APEX_BASE%%?$prod_base?g" \
             -e "s?/sierra/products/base/?$prod_base/?g" \
             -e "s?/aloha/products/base/?$prod_base/?g" \
             -e "s?/all\.rel/?/$view_name/?g" \
             -e "s?/all\.wrk/?/$view_name/?g" \
        $ss_path/Policy/Taskmgmt.sw > $temp
        cmp_move_file $temp $ss_path/Policy/Taskmgmt.sw
    fi

    # Determine if the latest migrate patch build key is installed.
    if [ -z "$MIGRATE" ]
    then
        if [ -d $prod_base/c++/keys/$ARCH_OS.$cpp_base_version.migrate ]
        then
            MIGRATE=$cpp_base_version.migrate
        elif [ -d $prod_base/c++/keys/$ARCH_OS.$apex_pver.migrate ]
        then
            MIGRATE=$apex_pver.migrate
        else
            MIGRATE=$apex_ver.migrate
        fi
    fi

    # Determine if the latest C++ patch build key is installed.
    if [ -z "$BUILD_KEY" ]
    then
        if [ -d $prod_base/c++/keys/standard.$cpp_base_version ]
        then
            BUILD_KEY=$prod_base/c++/keys/standard.$cpp_base_version
        elif [ -d $prod_base/c++/keys/standard.$apex_pver ]
        then
            BUILD_KEY=$prod_base/c++/keys/standard.$apex_pver
        else
            BUILD_KEY=$prod_base/c++/keys/standard.$apex_ver
        fi
    fi

    # Determine if the latest C++ compiler is installed.
    if [ "$layer_lang" = c++  -a  -z "$e_sienna_home" ]
    then
        set -- 1 `$GREP SIENNA_HOME: $Switches |
                  $SED -e 's?:? ?g' -e "s?/[^ ]*/base/?$prod_base/?"`
        if [ -n "$3" ]
        then
            if [ ! -d "$3" ]
            then
                # C++ compiler not installed.
                e_sienna_home="-e s?SIENNA_HOME:.*?SIENNA_HOME:nil?"
            fi
        fi
    fi

    if [ "$product" = axi ]
    then
        unset del_alt_key
    else
        del_alt_key="-e /^ALTERNATE_KEY:/d"
    fi

    if [ "${skip_cpp_home:-no}" = yes ]
    then
        unset e_cpp_comp
    elif [ "$layer_lang" = c++  -a  -z "$e_cpp_comp" ]
    then
        if [ -d $prod_base/c++/model.ss/$ARCH_OS.$cpp_base_version.rel ]
        then
            cpp_model=$prod_base/c++/model.ss/$ARCH_OS.$cpp_base_version.rel
        elif [ -d $prod_base/c++/model.ss/$ARCH_OS.$apex_pver.rel ]
        then
            cpp_model=$prod_base/c++/model.ss/$ARCH_OS.$apex_pver.rel
        elif [ -d $prod_base/c++/model.ss/$ARCH_OS.$apex_ver.rel ]
        then
            cpp_model=$prod_base/c++/model.ss/$ARCH_OS.$apex_ver.rel
        fi

        if [ -f $cpp_model/Policy/Switches ]
        then
            cpp_sw_file=$cpp_model/Policy/Switches
            comp_key=`$GREP "CPP_COMPILER_HOME:" $cpp_sw_file |
                      $AWK '{print $2}'`
            if [ -n "$comp_key" ]
            then
                e_cpp_comp="-e s?CPP_COMPILER_HOME:.*?CPP_COMPILER_HOME:$comp_key?"
            fi
        fi
    fi

    $ECHON "  Checking view switches: $NOCR"
    $SED -e "s?%%APEX_BASE%%?$prod_base?g" \
         -e "s?/sierra/products/apex.*.dev/?$APEX_HOME/?g" \
         -e "s?/aloha/products/apex_embedded.*.dev/?$prod_home/?g" \
         -e "s?/[^ ]*/base/?$prod_base/?g" \
         -e "s?%%APEX_VER%%?$apex_ver?g" \
         -e "s?%%ARCH_VER%%?$arch_key.$apex_ver?g" \
         -e "s?/keys/$ARCH_OS\..*.migrate?/keys/$arch_key.$MIGRATE?" \
         -e "s?/keys/$ARCH_OS\.[0-9\.]*\$?/keys/$arch_key.$apex_ver?" \
         -e "s?/key.ss/$arch_key\.[0-9\.]*.rel?/key.ss/$arch_key.$apex_ver.rel?" \
         -e "s?BUILD_KEY:.*/c++/keys/standard\..*?BUILD_KEY: $BUILD_KEY?" \
         -e "/^RCI_TARGET_DIRECTORY:/d" \
         $del_alt_key $e_sienna_home $e_cpp_comp \
         -e "/^ALIGNMENT:/d" -e 's?:nil$?: nil?' -e "s?:/?: /?" \
         $Switches > $temp

    cmp_move_file $temp $Switches

    if [ $check_sw_imp = yes ]
    then
        if $GREP -v "^#" $Switches $view_properties |
           $EGREP "/sierra/|/aloha/|/ned/|/accts/"
        then
            echo more $Switches >> $install_dir/sierra_ned
        fi
    fi

    $RM -f $view_path/.Rational/Compilation/Compiler_Key.times
}

#------------------------------------------------------------------------
customize_dependency() {
#------------------------------------------------------------------------
# Check the RELEASE_NAME in the Apex LP Ada dependency files.
# Make sure the posix lib release name is valid for the release of Apex.

    if [ "$layer_lang" != ada  -o  "$skip_dependency" = yes ]
    then
        return
    fi

    if [ "$product" = apex  -o  "$apex_layered_product" != yes ]
    then
        # No need for Apex or non-layered products of Apex.
        skip_dependency=yes
        return
    fi

    if [ -z "$pdss" ]
    then
        pdss=$prod_base/ada/predefined.ss
        if [ -f $APEX_HOME/.ada_base_version ]
        then
            ada_bv=`$CAT $APEX_HOME/.ada_base_version`
        else
            ada_bv=$apex_ver
        fi

        if [ -f $pdss/$ARCH_OS.$ada_bv.rel/libposix.a ]
        then
            NEW_ADA83_RN=$ARCH_OS.$ada_bv.rel
        fi

        if [ -f $pdss/${ARCH_OS}.ada95.$ada_bv.rel/libposix.a ]
        then
            NEW_ADA95_RN=$ARCH_OS.$ada_bv.rel
        fi

        if [ -z "${NEW_ADA83_RN}${NEW_ADA83_RN}" ]
        then
            # Cannot find posix replacements.
            skip_dependency=yes
            return
        fi
    fi

    if [ "$layer_dialect" = ada95 ]
    then
        if [ -z "$NEW_ADA95_RN" ]
        then
            # No Ada 95 replacement
            return
        fi
        THIS_RELEASE_NAME=$NEW_ADA83_RN
    else
        if [ -z "$NEW_ADA83_RN" ]
        then
            # No Ada 83 replacement
            return
        fi
        THIS_RELEASE_NAME=$NEW_ADA83_RN
    fi

    for dependency in `/bin/ls $view_path/*.dependency 2>/dev/null`
    do
        # Check for posix RELEASE_NAME
        set -- 1 `$GREP "API_NAME => posix,.* RELEASE_NAME => " $dependency`
        if [ $# -le 1 ]
        then
            continue
        fi

        while [ $# -ge 3 ]
        do
            if [ "$1" = RELEASE_NAME ]
            then
                RELEASE_NAME=$3
                break
            fi
            shift
        done

        _lib=`$BASENAME $dependency .dependency`

        if [ -z "$RELEASE_NAME" ]
        then
            # No RELEASE_NAME to customize
            echo "  Checking posix $_lib dependencies: okay."
            continue
        fi

        if [ "$RELEASE_NAME" = "$THIS_RELEASE_NAME" ]
        then
            # Posix lib dependency okay
            echo "  Checking posix $_lib dependencies: okay."
            continue
        fi

        # Do not match, need to fix.
        $ECHON "  Checking posix $_lib dependencies: $NOCR"
        $SED -e "s?$RELEASE_NAME?$THIS_RELEASE_NAME?" \
            $dependency > $temp
        cmp_move_file $temp $dependency
    done
}

#------------------------------------------------------------------------
freeze_view() {
#------------------------------------------------------------------------
# Freeze .rel views only.

    if [ "$do_freeze" = yes  -a  "$view_type" = rel ]
    then
        FREEZE="$FREEZE $view_path"
        n_freeze=`$EXPR $n_freeze + 1`
    fi
}

#------------------------------------------------------------------------
customize_view() {
#------------------------------------------------------------------------

    echo
    echo "$SEP"

    ss_path=$ss_base/$layer_lang/$ss_name
    view_path=$ss_path/$view_name

    if [ "$layer_arch" = $ARCH  -o  "$layer_arch" = share ]
    then
        :
    else
        logit warn "Skipping $ss_name/$view_name"
        logit cont "The $command command needs to be run on $SYSTEM_NAME machine,"
        logit cont "if you have not already done so."
        return
    fi

    case $layer_dialect in
        ada95 )
            fmt_mesg "Ada 95 subsystem $ss_name
                view $view_name"
            comp_files=".ada"
            ;;
        ada* )
            fmt_mesg "Ada 83 subsystem $ss_name
                view $view_name"
            comp_files=".ada"
            ;;
        c++ )
            fmt_mesg "C/C++ subsystem $ss_name
                view $view_name"
            comp_files=".c"
            ;;
        task* )
            fmt_mesg "Summit subsystem $ss_name
                view $view_name"
            comp_files=
            ;;
        * )
            fmt_mesg "layer_dialect subsystem $ss_name
                view $view_name"
            comp_files=
            ;;
    esac
    echo

    # Verify if the view has been frozen. If so, we do not want to
    # do any of the view_steps (remodel, compile, link, freeze, etc.)
    view_properties=$view_path/.Rational/View_Control/View_Properties
    if [ -s $view_properties.prop ]
    then
        # New name:
        view_properties=$view_properties.prop
    fi
    case `$GREP "RELEASE_KIND:" $view_properties` in
        *frozen )
            if [ "$do_unfreeze" = no ]
            then
                echo "!!! Okay, This view has been frozen."
                return
            fi

            if [ "$do_unfreeze" = ask ]
            then
                get_yn "Unfreeze view?" no
                if [ "$result" = no ]
                then
                    echo "!!! Okay, This view will be left frozen."
                    return
                fi
            fi

            # Unfreeze view
            $ECHON "  Unfreezing view: $NOCR"
            if $CHMOD -R +w $view_path
            then
                $SED -e "s?frozen?development?" $view_properties > $temp
                $CP $temp $view_properties
                MAINTAIN="$MAINTAIN $view_path"
                n_maintain=`$EXPR $n_maintain + 1`
                echo okay.
            else
                echo failed.
                return
            fi
    esac

    # Move RC to .Rational/Compilation, where it belongs.  It was
    # moved there by makeprod to avoid tar's 100 character filename limit.
    if [ -d  $view_path/RC ]
    then
        if [ -d $view_path/.Rational/Compilation ]
        then
            $CHMOD -R u+x $view_path/.Rational/Compilation 2>/dev/null
            $RM -fr $view_path/.Rational/Compilation
        fi
        mv $view_path/RC $view_path/.Rational/Compilation
    fi

    customize_imports
    customize_switches
    customize_dependency

    if [ -d $view_path/.Rational/Rci ]
    then
         compiler_class=`grep "COMPILER_CLASS:" $view_properties`
         case "$compiler_class" in
         *Extended )
             $ECHON "  Checking RCI view properties: $NOCR"
             # Make Standard for the remodel.
             $SED -e "s?COMPILER_CLASS:.*?COMPILER_CLASS: Standard?" \
                 $view_properties > $temp
             cmp_move_file $temp $view_properties
             ;;
         esac
    fi

    do_set_location=no
    do_remodel=no
    do_refresh=no
    do_freeze=no
    do_install=no
    do_compile=no
    do_link=no
    for _step in $layer_view_steps
    do
        eval do_$_step=yes
    done

    if [ "$do_set_location" = yes ]
    then
        if location_not_set $ss_path
        then
            echo will fix.
            SET_LOCATION="$SET_LOCATION
$ss_path"
            n_set_location=`$EXPR $n_set_location + 1`
        else
            echo okay.
        fi
    fi

    if [ "$do_refresh" = yes ]
    then
        REFRESH="$REFRESH $view_path"
        n_refresh=`$EXPR $n_refresh + 1`
    fi

    case "$ss_name" in
    model.ss )
        if [ $product != apex -a "$do_refresh" = no ]
        then
            # Must refresh model views.
            MODEL_REFRESH="$MODEL_REFRESH $view_path"
            n_model_refresh=`$EXPR $n_model_refresh + 1`
        fi

        if check_ss_view_key
        then
            freeze_view
        fi
        return
        ;;
    key.ss )
        # Make link in keys for backaward compatibility.
        keys=$ss_base/$layer_lang/keys
        key_dir=$keys/`$BASENAME $view_name .rel`
        if [ ! -d $key_dir  -a  ! $sym_link $key_dir ]
        then
            mkdir_p $keys
            $LN -s $view_path/key $key_dir
        fi
        freeze_view
        return
        ;;
    esac

    if [ "$do_remodel" = yes ]
    then
        check_ss_view_key
        if [ $? -ne $TRUE ]
        then
            return
        fi

        if [ "$layer_lang" = 'c++' ]
        then
            CPP_REMODEL="$CPP_REMODEL $view_path"
            n_cpp_remodel=`$EXPR $n_cpp_remodel + 1`
        else
            case $view_path in
            *64.ada95.thread.relaxed.* )
                if [ ! -d $ada95_64_thread_relaxed_model ]
                then
                    warn_of_missing_model "64-bit Ada 95" Threaded/Relaxed \
                        $ada95_64_thread_relaxed_model
                    return
                fi
                ADA95_64_REMODELTR="$ADA95_64_REMODELTR $view_path"
                n_ada95_64_remodeltr=`$EXPR $n_ada95_64_remodeltr + 1`
                ;;
            *64.ada95.thread* )
                if [ ! -d $ada95_64_thread_model ]
                then
                    warn_of_missing_model "64-bit Ada 95" Threaded $ada95_64_thread_model
                    return
                fi
                ADA95_64_REMODELT="$ADA95_64_REMODELT $view_path"
                n_ada95_64_remodelt=`$EXPR $n_ada95_64_remodelt + 1`
                ;;
            *64.ada95.relaxed* )
                if [ ! -d $ada95_64_relaxed_model ]
                then
                    warn_of_missing_model "64-bit Ada 95" Relaxed $ada95_64_relaxed_model
                    return
                fi
                ADA95_64_REMODELR="$ADA95_64_REMODELR $view_path"
                n_ada95_64_remodelr=`$EXPR $n_ada95_64_remodelr + 1`
                ;;
            *64.ada83.thread* )
                if [ ! -d $ada83_64_thread_model ]
                then
                    warn_of_missing_model "64-bit Ada 83" Threaded $ada83_64_thread_model
                    return
                fi
                ADA83_64_REMODELT="$ADA83_64_REMODELT $view_path"
                n_ada83_64_remodelt=`$EXPR $n_ada83_64_remodelt + 1`
                ;;
            *64.ada95* )
                if [ ! -d $ada95_64_model ]
                then
                    warn_of_missing_model "64-bit Ada 95" Regular $ada95_64_model
                    return
                fi
                ADA95_64_REMODEL="$ADA95_64_REMODEL $view_path"
                n_ada95_64_remodel=`$EXPR $n_ada95_64_remodel + 1`
                ;;
            *64.ada83* )
                if [ ! -d $ada83_64_model ]
                then
                    warn_of_missing_model "64-bit Ada 83" Regular $ada83_64_model
                    return
                fi
                ADA83_64_REMODEL="$ADA83_64_REMODEL $view_path"
                n_ada83_64_remodel=`$EXPR $n_ada83_64_remodel + 1`
                ;;
            *ada95.thread.relaxed.* )
                if [ ! -d $ada95_thread_relaxed_model ]
                then
                    warn_of_missing_model "Ada 95" Threaded/Relaxed \
                        $ada95_thread_relaxed_model
                    return
                fi
                ADA95_REMODELTR="$ADA95_REMODELTR $view_path"
                n_ada95_remodeltr=`$EXPR $n_ada95_remodeltr + 1`
                ;;
            *ada95.thread* )
                if [ ! -d $ada95_thread_model ]
                then
                    warn_of_missing_model "Ada 95" Threaded $ada95_thread_model
                    return
                fi
                ADA95_REMODELT="$ADA95_REMODELT $view_path"
                n_ada95_remodelt=`$EXPR $n_ada95_remodelt + 1`
                ;;
            *ada95.relaxed* )
                if [ ! -d $ada95_relaxed_model ]
                then
                    warn_of_missing_model "Ada 95" Relaxed $ada95_relaxed_model
                    return
                fi
                ADA95_REMODELR="$ADA95_REMODELR $view_path"
                n_ada95_remodelr=`$EXPR $n_ada95_remodelr + 1`
                ;;
            *ada83.thread* )
                if [ ! -d $ada83_thread_model ]
                then
                    warn_of_missing_model "Ada 83" Threaded $ada83_thread_model
                    return
                fi
                ADA83_REMODELT="$ADA83_REMODELT $view_path"
                n_ada83_remodelt=`$EXPR $n_ada83_remodelt + 1`
                ;;
            *ada95.aio* )
                if [ ! -d $ada95_aio_model ]
                then
                    warn_of_missing_model "Ada 95" AIO $ada95_aio_model
                    return
                fi
                ADA95_REMODELA="$ADA95_REMODELA $view_path"
                n_ada95_remodela=`$EXPR $n_ada95_remodela + 1`
                ;;
            *ada83.aio* )
                if [ ! -d $ada83_aio_model ]
                then
                    warn_of_missing_model "Ada 83" AIO $ada83_aio_model
                    return
                fi
                ADA83_REMODELA="$ADA83_REMODELA $view_path"
                n_ada83_remodela=`$EXPR $n_ada83_remodela + 1`
                ;;
            *ada95* )
                if [ ! -d $ada95_model ]
                then
                    warn_of_missing_model "Ada 95" Regular $ada95_model
                    return
                fi
                ADA95_REMODEL="$ADA95_REMODEL $view_path"
                n_ada95_remodel=`$EXPR $n_ada95_remodel + 1`
                ;;
            *ada83* )
                if [ ! -d $ada83_model ]
                then
                    warn_of_missing_model "Ada 83" Regular $ada83_model
                    return
                fi
                ADA83_REMODEL="$ADA83_REMODEL $view_path"
                n_ada83_remodel=`$EXPR $n_ada83_remodel + 1`
                ;;
            * )
                MODEL_REFRESH="$MODEL_REFRESH $view_path"
                n_model_refresh=`$EXPR $n_model_refresh + 1`
                ;;
            esac
        fi
    fi


    # Create links in prod_base/api/lib/ARCH to API's in view_path.
    # The link will be named "<lib_api>.<view_name>.a" (without the /'s)
    # For example, if view_path contained the API "libposix.a", then:
    #   libposix.sun4_solaris2.1.6.1.rel.a -> view_path/libposix.a
    if [ ! -d   $prod_base/api/lib/$ARCH ]
    then
        mkdir_p $prod_base/api/lib/$ARCH
    fi

    for lib_api_a in `$LS $view_path/*.a 2>/dev/null`
    do
        $CHMOD 444 $lib_api_a
        lib_api=`$BASENAME $lib_api_a .a`
        vn=`echo $view_name | $SED -e "s?/?.?g"`      # (remove the /'s)
        if [ -z "$vn" -o -z "$lib_api" ]
        then
            continue
        fi
        $RM -f $prod_base/api/lib/$ARCH/$lib_api.$vn.a
        $LN -s $lib_api_a $prod_base/api/lib/$ARCH/$lib_api.$vn.a
    done

    freeze_view

    # If ada or C units can be found in this view, add it to the list of
    # views to be installed, compiled or linked.
    if [ -z "$comp_files" ]
    then
        return
    fi

    if [ `$FIND $view_path -type f -name \*$comp_files -print | wc -l` -gt 0 ]
    then
        if [ "$do_install" = yes  -a  $code_link = yes ]
        then
            INSTALL="$INSTALL $view_path"
            n_install=`$EXPR $n_install + 1`
        fi

        if [ "$do_compile" = yes  -a  $code_link = yes ]
        then
            if [ "$layer_lang" = c++ ]
            then
                COMPILECPP="$COMPILECPP $view_path"
                n_compilecpp=`$EXPR $n_compilecpp + 1`
            elif [ "$layer_dialect" = ada95 ]
            then
                COMPILE95="$COMPILE95 $view_path"
                n_compile95=`$EXPR $n_compile95 + 1`
            else # ada83
                case $tiny_integer/$ss_name/$view_name in
                    yes/lrm.ss/$ARCH_OS.$product_version* )
                        CLEAN="$CLEAN $view_path"
                        RADA="$RADA $view_path"
                        n_rada=`$EXPR $n_rada + 1`
                        ;;
                    * )
                        COMPILE83="$COMPILE83 $view_path"
                        n_compile83=`$EXPR $n_compile83 + 1`
                        ;;
                esac
            fi
        fi

        if [ "$do_link" = yes  -a  $code_link = yes ]
        then
            LINK="$LINK $view_path"
            n_link=`$EXPR $n_link + 1`
        fi
    fi
}

#------------------------------------------------------------------------
add_apex_script() {
#------------------------------------------------------------------------

    echo "echo
echo '$SEP'
$*" >> $apex_script
}

#------------------------------------------------------------------------
add_apex_cmds_nochk() {
#------------------------------------------------------------------------

    eval apex_cmd=\"\$APEX_$1\"
    skip_tag=$2

    eval set -- \$$1
    if [ $# -eq 0 ]
    then
        return
    fi

    if [ -z "$skip_tag" ]
    then
        echo "
echo
echo '$SEP'
$apex_cmd $*
        " >> $apex_script
        return
    fi

    echo "
if [ \"\$$skip_tag\" != skip ]
then
    echo
    echo '$SEP'
    $apex_cmd $*
fi
    " >> $apex_script
}

#------------------------------------------------------------------------
add_cond_apex_cmds_nc() {
#------------------------------------------------------------------------

    if [ "${1:-0}" -gt 0 ]
    then
        shift
        add_apex_cmds_nochk $*
    fi
}

#------------------------------------------------------------------------
add_cond_apex_cmds() {
#------------------------------------------------------------------------

    if [ "${1:-0}" -gt 0 ]
    then
        shift
        add_apex_cmds $*
    fi
}

#------------------------------------------------------------------------
add_apex_cmds() {
#------------------------------------------------------------------------

    add_apex_cmds_nochk $*
    add_error_check "$apex_cmd"
}

#------------------------------------------------------------------------
add_silent_script() {
#------------------------------------------------------------------------
    echo "$* >/dev/null 2>&1" >> $apex_script
    echo ": null returns true" >> $apex_script
}

#------------------------------------------------------------------------
add_error_check() {
#------------------------------------------------------------------------
# Ignore error 141 if it comes up.

    echo "status=\$?
case \$status in
0|141 )
    status=0
    ;;
* )
    echo \"Error in $* [status=\$status]\"
    exit \$status
    ;;
esac
    " >> $apex_script
}

#------------------------------------------------------------------------
add_model_check() {
#------------------------------------------------------------------------

    echo "
if [ -z \"\$$1\" ]
then

    echo
    echo '$SEP'
    echo \"\`date +%T\` !!! Cannot remodel $2 views, Apex/$2 not installed.\"
    $3=skip

else" >> $apex_script
}

#------------------------------------------------------------------------
customize_subsystems() {
#------------------------------------------------------------------------

    if [ ${layer_count:-0} -eq 0 ]
    then
        return $TRUE
    fi

    echo
    echo "$SEP"
    header "$product_name Subsystem Setup"

    # Make the Ada config directory for this product/arch.
    if [ ! -d $prod_base/ada ]
    then
        $MKDIR $prod_base/ada
    fi

    if [ "$make_cfg_files" = yes ]
    then
        CFG_DIR=$prod_base/ada/configs

        if [ ! -d $CFG_DIR ]
        then
            $MKDIR $CFG_DIR
            $CHMOD a+w $CFG_DIR
        else
            $CHMOD a+w $CFG_DIR 2>/dev/null
        fi
    fi

    case $ARCH_OS in
    sun4_solaris2 )
        ARCH64_OS=sun4_solaris_64
        ;;
    * )
        ARCH64_OS=${ARCH_OS}64
        ;;
    esac

    ada_95=$prod_base/ada/model.ss/$ARCH_OS.ada95
    ada_83=$prod_base/ada/model.ss/$ARCH_OS.ada83
    ada_95_64=$prod_base/ada/model.ss/$ARCH64_OS.ada95
    ada_83_64=$prod_base/ada/model.ss/$ARCH64_OS.ada83
    ada95_thread_model=$ada_95.thread.$apex_version.rel
    ada95_relaxed_model=$ada_95.relaxed.$apex_version.rel
    ada95_thread_relaxed_model=$ada_95.thread.relaxed.$apex_version.rel
    ada95_aio_model=$ada_95.aio.$apex_version.rel
    ada95_model=$ada_95.$apex_version.rel
    ada83_thread_model=$ada_83.thread.$apex_version.rel
    ada83_aio_model=$ada_83.aio.$apex_version.rel
    ada83_model=$ada_83.$apex_version.rel
    ada83_64_model=$ada_83_64.$apex_version.rel
    ada83_64_thread_model=$ada_83_64.thread.$apex_version.rel
    ada95_64_model=$ada_95_64.$apex_version.rel
    ada95_64_thread_model=$ada_95_64.thread.$apex_version.rel
    ada95_64_relaxed_model=$ada_95_64.relaxed.$apex_version.rel
    ada95_64_thread_relaxed_model=$ada_95_64.thread.relaxed.$apex_version.rel
    unset ada_95 ada_83 ada_95_64 ada_83_64

    APEX_SET_LOCATION="apex set_location -replace"
    APEX_REFRESH="apex remodel -refresh -force"
    APEX_MODEL_REFRESH="apex remodel -refresh -force"
    APEX_ADA83_REMODEL="apex remodel -model \$APEX_ADA83_MODEL -force"
    APEX_ADA95_REMODEL="apex remodel -model \$APEX_ADA95_MODEL -force"
    APEX_ADA83_REMODELT="apex remodel -model $ada83_thread_model -force"
    APEX_ADA95_REMODELT="apex remodel -model $ada95_thread_model -force"
    APEX_ADA95_REMODELR="apex remodel -model $ada95_relaxed_model -force"
    APEX_ADA95_REMODELTR="apex remodel -model $ada95_thread_relaxed_model -force"
    APEX_ADA83_REMODELA="apex remodel -model $ada83_aio_model -force"
    APEX_ADA95_REMODELA="apex remodel -model $ada95_aio_model -force"
    APEX_ADA83_64_REMODEL="apex remodel -model $ada83_64_model -force"
    APEX_ADA95_64_REMODEL="apex remodel -model $ada95_64_model -force"
    APEX_ADA83_64_REMODELT="apex remodel -model $ada83_64_thread_model -force"
    APEX_ADA95_64_REMODELT="apex remodel -model $ada95_64_thread_model -force"
    APEX_ADA95_64_REMODELR="apex remodel -model $ada95_64_relaxed_model -force"
    APEX_ADA95_64_REMODELTR="apex remodel -model $ada95_64_thread_relaxed_model -force"



    export APEX_ADA83_REMODELT APEX_ADA95_REMODELT
    export APEX_ADA95_REMODELR APEX_ADA95_REMODELTR
    export APEX_ADA83_REMODELA APEX_ADA95_REMODELA
    APEX_CPP_REMODEL="apex remodel -model \$APEX_CPP_MODEL -force"
    APEX_INSTALL="apex install"
    APEX_MAINTAIN="apex maintain -version_control -history all -permissions"
    APEX_COMPILE83="apex compile"
    APEX_COMPILE95="apex compile"
    APEX_COMPILECPP="apex compile"
    APEX_CLEAN="apex clean"
    APEX_RADA="rada -flag tiny_integer"
    APEX_LINK="apex link"
    APEX_FREEZE="apex remodel -release_kind frozen"

    n_set_location=0
    n_refresh=0
    n_model_refresh=0
    n_ada83_remodel=0
    n_ada83_remodelt=0
    n_ada83_remodela=0
    n_ada95_remodel=0
    n_ada95_remodelt=0
    n_ada95_remodelr=0
    n_ada95_remodeltr=0
    n_ada95_remodela=0
    n_ada83_64_remodel=0
    n_ada83_64_remodelt=0
    n_ada95_64_remodel=0
    n_ada95_64_remodelt=0
    n_ada95_64_remodelr=0
    n_ada95_64_remodeltr=0
    n_cpp_remodel=0
    n_freeze=0
    n_install=0
    n_compile83=0
    n_compile95=0
    n_compilecpp=0
    n_maintain=0
    n_rada=0
    n_link=0

    unset SET_LOCATION REFRESH MAINTAIN MODEL_REFRESH
    unset ADA95_REMODEL ADA83_REMODEL CPP_REMODEL FREEZE INSTALL
    unset ADA95_REMODELT ADA83_REMODELT ADA95_REMODELR ADA95_REMODELTR
    unset ADA95_REMODELA ADA83_REMODELA
    unset COMPILE83 COMPILE95 COMPILECPP LINK CLEAN RADA

    i=1
    while [ $i -le $layer_count ]
    do
        eval layer_arch=\$layer_${i}_arch
        eval view_name=\$layer_${i}_view_name
        eval layer_lang=\$layer_${i}_lang
        eval layer_dialect=\$layer_${i}_dialect
        eval layer_ss_count=\$layer_${i}_ss_count
        eval layer_view_steps=\"\${layer_${i}_view_steps:-$view_steps}\"
        layer_dialect=${layer_dialect:-$layer_lang}
        if [ -z "$view_name" ]
        then
            eval layer_hwarch=\$layer_${i}_hwarch
            eval layer_arch=\$layer_${i}_arch
            eval layer_ver=\$layer_${i}_ver
            if [ "$view_type" = rel ]
            then
                view_name=${layer_arch}.${layer_ver}.$view_type
            else
                view_name=${layer_arch}.$view_type
            fi
            layer_arch=$layer_hwarch
        fi
        j=1
        while [ $j -le $layer_ss_count ]
        do
            eval ss_name=\$layer_${i}_ss_${j}_name
            if [ -d $ss_base/$layer_lang/$ss_name/$view_name ]
            then
                # View was installed.
                customize_view
            fi
            j=`$EXPR $j + 1`
        done
        i=`$EXPR $i + 1`
    done

    if [ $check_sw_imp = yes  -a  -s $install_dir/sierra_ned ]
    then
        error "Switches/Imports have paths to /sierra/, /aloha/, /ned/ or /accts/:"
        $CAT $install_dir/sierra_ned
        exit 1
    fi

    apex_script=/tmp/apex_script.$$
    if [ "$make_cfg_files" = yes ]
    then
        add_apex_script apex_upgrade -create_cfg_files
    fi

    add_cond_apex_cmds "$n_set_location" SET_LOCATION
    add_cond_apex_cmds "$n_refresh" REFRESH
    add_cond_apex_cmds "$n_maintain" MAINTAIN

    if [ $n_ada83_remodel -gt 0 ]
    then
        add_model_check APEX_ADA83_MODEL "Ada 83" do_ada83
        add_apex_cmds ADA83_REMODEL
        echo "fi" >> $apex_script
    fi

    add_cond_apex_cmds "$n_ada83_remodelt" ADA83_REMODELT
    add_cond_apex_cmds "$n_ada83_remodela" ADA83_REMODELA
    add_cond_apex_cmds "$n_ada83_64_remodel" ADA83_64_REMODEL
    add_cond_apex_cmds "$n_ada83_64_remodelt" ADA83_64_REMODELT

    if [ $n_ada95_remodel -gt 0 ]
    then
        add_model_check APEX_ADA95_MODEL "Ada 95" do_ada95
        add_apex_cmds ADA95_REMODEL
        echo "fi" >> $apex_script
    fi

    add_cond_apex_cmds "$n_ada95_remodelt" ADA95_REMODELT
    add_cond_apex_cmds "$n_ada95_remodeltr" ADA95_REMODELTR
    add_cond_apex_cmds "$n_ada95_remodelr" ADA95_REMODELR
    add_cond_apex_cmds "$n_ada95_remodela" ADA95_REMODELA
    add_cond_apex_cmds "$n_ada95_64_remodel" ADA95_64_REMODEL
    add_cond_apex_cmds "$n_ada95_64_remodelt" ADA95_64_REMODELT
    add_cond_apex_cmds "$n_ada95_64_remodeltr" ADA95_64_REMODELTR
    add_cond_apex_cmds "$n_ada95_64_remodelr" ADA95_64_REMODELR
    add_cond_apex_cmds_nc "$n_model_refresh" MODEL_REFRESH
    echo ":" >> $apex_script

    if [ $n_cpp_remodel -gt 0 ]
    then
        add_model_check APEX_CPP_MODEL C++ do_cpp
        add_apex_cmds CPP_REMODEL
        echo "fi" >> $apex_script
        do_cpp='-cpp'
    fi

    add_cond_apex_cmds_nc "$n_install" INSTALL
    add_cond_apex_cmds_nc "$n_rada" CLEAN
    add_cond_apex_cmds "$n_rada" RADA
    add_cond_apex_cmds_nc "$n_compile83" COMPILE83 do_ada83
    add_cond_apex_cmds_nc "$n_compile95" COMPILE95 do_ada95
    add_cond_apex_cmds_nc "$n_compilecpp" COMPILECPP do_cpp
    add_cond_apex_cmds "$n_link" LINK

    if [ -n "$task_domain"  -a  -n "$task_ss" ]
    then
        if [ ! -d $task_domain ]
        then
            add_apex_script "create_subsystem $task_ss"
            add_error_check "create_subsystem"
            add_apex_script "create_task_domain $task_domain"
            add_error_check "create_task_domain"
            if [ -n "$task_ss_chmod" ]
            then
                add_apex_script "$task_ss_chmod"
            fi
        fi
    fi

    if [ -x $prod_home/bin/aemacs ]
    then
        add_silent_script "aemacs -batch -f apex-check-all-menu-files"
    fi

    if [ -f $install_dir/share/apex_script ]
    then
        add_apex_script "product_version=$product_version"
        add_apex_script ". $install_dir/share/apex_script"
    fi

    add_cond_apex_cmds_nc "$n_freeze" FREEZE
    echo ":" >> $apex_script

    apex_status=$TRUE
    if [ -s $apex_script ]
    then
        add_cleanup_file $apex_script
        separator
        $APEXINIT -batch -reset $do_cpp /bin/sh $apex_script
        apex_status=$?
    fi

    return $apex_status
}

#------------------------------------------------------------------------
err_warn() {
#------------------------------------------------------------------------

    error_func=$1
    must_should=$2
    cont=$3
    err_mesg=$4
    $error_func "$err_mesg
        You $must_should run get_license_info, then add the license, and
        then run the start_lm script before running this script."
    ask_continue $cont
    unset error_func must_should cont err_mesg
}

#------------------------------------------------------------------------
run_ranlib() {
#------------------------------------------------------------------------
#   arg1: on_arch:  architecture
#   arg2: sys_name: system name  (ignored)
# arg3-N: lib_path: library path name

    on_arch=$1
    shift 2

    for lib_path in $*
    do
        if [ ! -f $lib_path ]
        then
            continue
        fi

        if [ "$ARCH" = "$on_arch" ]
        then
            if [ -z "$ranlib_header" ]
            then
                echo
                echo "Running ranlib on..."
                ranlib_header=no
            fi
            echo "    $lib_path"
            if [ ! -w $lib_path ]
            then
                $CHMOD a+w $lib_path
                ranlib -t $lib_path >/dev/null 2>&1
                $CHMOD a-w $lib_path
            else
                ranlib -t $lib_path >/dev/null 2>&1
            fi
        fi
    done
}

#------------------------------------------------------------------------
feature_exists() {
#------------------------------------------------------------------------
# Check if feature (arg1) exists in license file.
# If it does, return feature line in feature_line.

    WS=" 	"
    unset increment_lines feature_line
    if $using_multiple_lic_files
    then
        eval lic_file=\$license_file$fn
    else
        lic_file=$LM_LICENSE_FILE
    fi

    if [ ! -f "$lic_file" ]
    then
        # Cannot check--ask user if they have licensed feature.
        get_yn "Have you licensed feature '$1'?" no
        if [ $result = yes ]
        then
            return $TRUE
        else
            return $FALSE
        fi
    else
        feature_line=`$GREP "^FEATURE[$WS]*$1[$WS]" $lic_file | $HEAD -1`
        if increment_lines=`$GREP "^INCREMENT[$WS]*$1[$WS]" $lic_file`
        then
            return $TRUE
        elif [ -n "$feature_line" ]
        then
            return $TRUE
        else
            # No FEATURE or INCREMENT lines.
            return $FALSE
        fi
    fi
}

#------------------------------------------------------------------------
set_opt_file() {
#------------------------------------------------------------------------

    # Default to rational.opt in the license dir.
    LICENSE_DIR=$prod_base/cots/flexlm.$flexlm_version/$SV_LICENSE_ARCH
    if [ -f $LICENSE_DIR/rational.opt ]
    then
        opt_file=$LICENSE_DIR/rational.opt
        return 0
    else
        # Check on DAEMON line in license file.
        set -- `$GREP "^DAEMON rational" $LM_LICENSE_FILE`
        if [ "$#" -eq 4 ]
        then
            if [ -f $4 ]
            then
                # It is fully qualified.
                opt_file=$4
                return 0
            elif [ -f $3/$4 ]
            then
                # Found in the daemon path (arg 3).
                opt_file=$3/$4
                return 0
            fi
        fi

        # Check on VENDOR line in license file.
        set -- `$GREP "^VENDOR rational" $LM_LICENSE_FILE`
        if [ "$#" -eq 3 ]
        then
            if [ -f $3 ]
            then
                # It is fully qualified.
                opt_file=$3
                return 0
            elif [ -f $LICENSE_DIR/$3 ]
            then
                # Found in the license dir.
                opt_file=$LICENSE_DIR/$3
                return 0
            fi
        fi
    fi
    return 1
}

#------------------------------------------------------------------------
warn_no_opt_file() {
#------------------------------------------------------------------------

    warn "This product has USER_BASED licenses.
        This requires an options file to be set.
        Could not determine the location of the options file.
        This should be set on the DAEMON or VENDOR line in your
        license file ($LM_LICENSE_FILE).
        Example: DAEMON rational $LICENSE_DIR rational.opt
        where rational.opt is located in
        $LICENSE_DIR.
        The rational.opt file must contain one or more lines specifying
        the users of this product.
        Example: INCLUDE purifyapex USER $USER"
}

#------------------------------------------------------------------------
warn_no_opt_include() {
#------------------------------------------------------------------------
    warn "The '$LFN' license is USER_BASED.
        This requires one or more entries in the options file,
        $opt_file.
        Example: INCLUDE $LFN USER $USER
        where $USER would be a user of $LFN."
}

#------------------------------------------------------------------------
check_license_features() {
#------------------------------------------------------------------------
# Check if license server knows about features in the license list.
# This is done only if licenses are not uncounted, DEMO.

    if [ "$check_license" = no  -o "$command" != post_install ]
    then
        return
    fi

    if [ "$have_demo" = yes -a -z "$have_non_demo" ]
    then
        if [ $using_port_at_host = yes ]
        then
            echo "
There are only demo (evaluation) licenses for this product.
Since you are using the port@host feature of FLEXlm, licenses
cannot be checked."
            return
        fi

        # Do not use lmstat to check licenses since none of them need to
        # be counted by the server.
        use_lmstat=no
    else
        use_lmstat=yes
    fi

    separator

    # Will use this command to check license codes.
    if [ $using_port_at_host = no  -a  -x $flex_dir/exinstal ]
    then
        EXINSTAL=exinstal
        TMP_DAT=/tmp/exinstal.$$.dat
        add_cleanup_file $TMP_DAT
    fi

    case $EXINSTAL/$use_lmstat in
    exinstal/yes )
        echo "Verifying licenses with the license server daemon using lmstat"
        echo "  and in the license file using exinstal..."
        ;;
    exinstal/no )
        echo "Verifying licenses in the license file using exinstal..."
        ;;
    /no )
        echo "Verifying licenses in the license file..."
        ;;
    /yes )
        echo "Verifying licenses with the license server daemon using lmstat..."
        ;;
    esac

    Not_added_server_line=true
    num_server_keys=0
    unset no_license_list
    OKAY_LIST=/tmp/$product.post_install.license.okay.$$
    add_cleanup_file $OKAY_LIST
    for fn in ${fn_list:-${license_list:-$lic_list_all}}
    do
        eval LFN=\$license_feature$fn
        eval NUM=\$num_feature$fn
        if [ $using_port_at_host = no ]
        then
            feature_exists $LFN
            num_lic=`echo "${feature_line:-0 0 0 0 0 0}
                           ${increment_lines:-0 0 0 0 0 0}" |
                     $AWK 'BEGIN {n=0} {n+=$6} END {print n}'`
            # Add SERVER and DAEMON/VENDOR lines.
            if $Not_added_server_line
            then
                egrep "^SERVER|^DAEMON|^VENDOR" $lic_file >> $TMP_DAT
                Not_added_server_line=false
            fi
            echo "$feature_line" >> $TMP_DAT
            echo "$increment_lines" >> $TMP_DAT
        fi

        case "${using_port_at_host}-${num_lic:-${NUM:-0}}" in
        no-demo|no-0 )
            # Skip DEMO, Uncounted
            continue
            ;;
        esac

        num_server_keys=`$EXPR $num_server_keys + 1`
        lmstat_out=`lmstat -f $LFN 2>&1`
        avail=`echo "$lmstat_out" |
               $GREP "Total of.*licenses available" |
               head -1"`
        if lic_avail=`echo "$avail" | $GREP "Total of.*licenses available"`
        then
            echo
            echo "$lic_avail"
            echo $LFN >> $OKAY_LIST
        else
            # Save license error message and when all done, check if any
            # of the alternate licenses for this license are okay.
            no_license_list="$no_license_list $fn"
            lm_err=`echo "$lmstat_out" | $EGREP -v '^lmstat - |^Flexible|^$'`
            eval lm_err$fn=\$lm_err
        fi

        # Check if license is user-based. If so, check later for entry
        # in the options file.
        case "$feature_line$increment_lines" in
        *USER_BASED* )
            user_based="$user_based $fn"
            ;;
        esac
    done

    # Check if missing licenses have valid alternate licenses.
    for fn in $no_license_list
    do
        eval LFN=\$license_feature$fn

        # Determine the alternate name of the missing license.
        unset alt_lfn
        case $LFN in
        *.alpha ) alt_lfn=`echo "$LFN" | sed -e 's?\.alpha?.any?'` ;;
        *.any   ) alt_lfn=`echo "$LFN" | sed -e 's?\.any?\\.?'` ;;
        *.any.* ) alt_lfn=`echo "$LFN" | sed -e 's?\.any\.?.*.?'` ;;
        *.axp.* ) alt_lfn=`echo "$LFN" | sed -e 's?\.axp\.?.any.?'` ;;
        *.hp.*  ) alt_lfn=`echo "$LFN" | sed -e 's?\.hp\.?.any.?'` ;;
        *.hppa  ) alt_lfn=`echo "$LFN" | sed -e 's?\.hppa?.any?'` ;;
        *.ibm.* ) alt_lfn=`echo "$LFN" | sed -e 's?\.ibm\.?.any.?'` ;;
        *.mips  ) alt_lfn=`echo "$LFN" | sed -e 's?\.mips?.any?'` ;;
        *.rs6k  ) alt_lfn=`echo "$LFN" | sed -e 's?\.rs6k?.any?'` ;;
        *.sgi.* ) alt_lfn=`echo "$LFN" | sed -e 's?\.sgi\.?.any.?'` ;;
        *.sun4  ) alt_lfn=`echo "$LFN" | sed -e 's?\.sun4?.any?'` ;;
        *.sun4.*) alt_lfn=`echo "$LFN" | sed -e 's?\.sun4\.?.any.?'` ;;
        esac

        if [ -n "$alt_lfn" ]
        then
            # Can ignore this if alternate form is in the okay file
            if grep "^$alt_lfn" $OKAY_LIST >/dev/null 2>&1
            then
                continue
            fi
        fi

        # Show the lmstat errror.
        eval lm_err=\$lm_err$fn
        echo
        echo "The 'lmstat -f $LFN' command returned this message:"
        echo "$lm_err"
        echo

        eval DESC=\$license_desc$fn
        mesg_not_licensed="It appears that $DESC
license has not been activated in the license server."

        case $LFN in
        apex|apex.base.*|env_base.*|summit_base.*|*.c++|*.rada )
            # These licenses are required.
            err_warn error must no \
               "$mesg_not_licensed
                Have you run start_lm?"
            ;;
        * )
            echo "$mesg_not_licensed"
            ask_continue yes
            ;;
        esac
    done

    if [ -n "$EXINSTAL"  -a  $num_server_keys -gt 0 ]
    then
        if [ -s $TMP_DAT ]
        then
            # The exinstal program returns a count of the number of licenses
            # that have some sort of problem.
            $EXINSTAL $TMP_DAT > $TMP_DAT.out
            _n=$?

            # Show the installer what exinstal emitted, excluding some lines.
            $EGREP -v "^Feature:|^License path:|^FLEXlm error:" $TMP_DAT.out
            $RM -f $TMP_DAT.out

            echo
            case $_n in
            0 )
                logit pos "exinstal: All of the license keys are fine."
                ;;
            1 )
                logit neg "exinstal: There is a problem with one of the license keys."
                ask_continue no
                ;;
            * )
                logit neg "exinstal: There are problems with $_n of the license keys."
                ask_continue no
                ;;
            esac
        fi
    fi

    # Check USER_BASED licenses.
    for fn in $user_based
    do
        if [ -z "$opt_file" ]
        then
            set_opt_file
            if [ $? -ne 0 ]
            then
                warn_no_opt_file
                break
            fi
        fi
        eval LFN=\$license_feature$fn
        if GREP "^INCLUDE$[WS]*$LFN$[$WS]*USER" $opt_file >/dev/null
        then
            continue
        else
            warn_no_opt_include
        fi
    done
}

#------------------------------------------------------------------------
set_lm_license_file() {
#------------------------------------------------------------------------
# SV_LIC_FILE_NAME should be set to the full path of license.dat.
# It is set in the .license_data file.
# Check the .license_data files first and LM_LICENSE_FILE last.
# Verify each feature in the license_list list is in the file.

    if [ "$check_license" = no  -o "$command" != post_install ]
    then
        return
    fi

    separator

    get_lic_file_name

    # Check license file exists or their using port@host.
    unset new_license_file
    using_port_at_host=no
    using_multiple_lic_files=false
    while true
    do
        unset new_license_file
        using_port_at_host=no
        using_multiple_lic_files=false
        get_input "Enter license file or port@host:" $SV_LIC_FILE_NAME
        for lic_file in `(IFS=':'; echo $result)`
        do
            case $lic_file in
            *@* )
                using_port_at_host=yes
                ;;
            * )
                if [ ! -f "$lic_file" ]
                then
                    echo "$lic_file not found."
                    get_yn "Use anyway?" no
                    if [ "$result" = no ]
                    then
                        continue
                    fi
                fi
                ;;
            esac
            if [ -n "$new_license_file" ]
            then
                new_license_file="$new_license_file:$lic_file"
                using_multiple_lic_files=true
            else
                new_license_file="$lic_file"
            fi
        done
        if [ -n "$new_license_file" ]
        then
            break
        else
            error "You did not specify a valid license file or port@host."
            ask_continue no
        fi
    done

    SV_LIC_FILE_NAME=$new_license_file
    LM_LICENSE_FILE=$SV_LIC_FILE_NAME
    export LM_LICENSE_FILE
    save_vars
    save_defaults -g SV_LIC_FILE_NAME

    fmt_mesg "You can have the $command check the license server to
        verify that licensing is functioning for $product_name.
        To do so requires access to the full license.dat file
        and/or access to the lmstat command."
    get_yn "Would you like to verify licenses now?" ${check_license:-yes}
    check_license=$result
    if [ $check_license = no  -o  $using_port_at_host = yes ]
    then
        return
    fi

    _pause=':'
    lic_file=`$BASENAME $LM_LICENSE_FILE`

    separator
    if $using_multiple_lic_files
    then
        echo "Checking licenses in these license files:"
        for lic_file in `(IFS=':'; echo $SV_LIC_FILE_NAME)`
        do
            echo "  $lic_file"
        done
    else
        echo "Checking licenses in the license file:"
        echo "  $SV_LIC_FILE_NAME"
    fi

    # Look for FEATURE lines with Rational product license features.
    unset all_feat_list
    for fn in ${license_list:-$lic_list_all}
    do
        eval LFN=\$license_feature$fn
        if [ -n "$LFN" ]
        then
            all_feat_list="$all_feat_list $LFN"
        fi
        if is_an_any_license $LFN
        then
            lic_type=any
        elif is_a_host_license $LFN
        then
            lic_type=host_specific
        else
            lic_type=generic
        fi

        if $using_multiple_lic_files
        then
            unset _warn_mesg   _error_mesg
            unset _warn_status _error_status
            unset _warn_file   _error_file
            for _lic_file in `(IFS=':'; echo $SV_LIC_FILE_NAME)`
            do
                _lic_mesg=`check_feature -v $fn $_lic_file 2>&1`
                _lic_status=$?
                case $_lic_status in
                0 )
                    break
                    ;;
                3|4|5 )
                    _warn_status=$_lic_status
                    _warn_mesg="$_lic_mesg"
                    _warn_file=$_lic_file
                    unset _lic_status _error_status
                    ;;
                * )
                    _error_status=$_lic_status
                    _error_mesg="$_lic_mesg"
                    _error_file=$_lic_file
                    unset _lic_status
                    ;;
                esac
            done

            if [ -n "$_lic_status" ]
            then
                echo "$_lic_mesg"
                eval license_file$fn=$_lic_file
            elif [ -n "$_warn_status" ]
            then
                echo "$_warn_mesg"
                _lic_status=$_warn_status
                eval license_file$fn=$_warn_file
            elif [ -n "$_error_status" ]
            then
                echo "$_error_mesg"
                _lic_status=$_error_status
                eval license_file$fn=$_error_file
            fi
            unset _lic_mesg _warn_mesg _error_mesg _warn_status _error_status
            unset _lic_file _warn_file _error_file
        else
            check_feature -v $fn
            _lic_status=$?
        fi

        case $_lic_status in
        0 )
            fn_list="$fn_list $fn"
            eval using_$lic_type=yes
            ;;
        3|4|5 )
            # The non-zero return codes are mismatches between what is in
            # the license file and what is in the install_defaults
            # from get_license_info. The mismatches are warnings only.
            fn_list="$fn_list $fn"
            _pause=press_cr
            ;;
        * )
            eval missing_$lic_type=\"\$missing_$lic_type $LFN\"
            ;;
        esac
    done
    echo

    for lic_type in any host_specific generic
    do
        eval using=\$using_$lic_type
        eval missing=\$missing_$lic_type
        if [ "$using" = yes  -a  -n "$missing" ]
        then
            warning "Using '$lic_type' license keys but these licenses
                     have not been configured:  $missing"
            _pause="ask_continue no"
        fi
    done

    if [ -z "$fn_list" ]
    then
        if [ -n "$all_feat_list" ]
        then
            echo "Checked for these keys:"
            for LFN in $all_feat_list
            do
                echo "    $LFN"
            done
            err_warn warning should yes \
            "Cannot find any FEATURE or INCREMENT lines for $product_name
            in the license file.  Has $distributor given you your license key(s)?"
        else
            echo "There are no license keys to check for."
            check_license=no
        fi
    else
        eval $_pause
        unset _pause
    fi
}

#========================================================================
# Main
#========================================================================

temp=/tmp/$command.$$
code_link=yes
check_sw_imp=no
do_unfreeze=no
install_crypt=false
unset PID

set -- $args
while [ $# -gt 0 ]
do
    case $1 in
        -h* )
            usage 1
            ;;
        -askunfreeze|-auf )
            do_unfreeze=ask
            ;;
        -unfreeze|-uf )
            do_unfreeze=yes
            ;;
        -check )
            # Check for /sierra/, /aloha/, /ned/ or /accts/:
            # in switches and imports.
            check_sw_imp=yes
            ;;
        [Dd][Oo][Nn][Tt]_[Bb][Uu][Ii][Ll][Dd] )
            code_link=no
            ;;
        -patch )
            PID=$2
            prod_desc_patch=$install_dir/$TARGET_ARCH/prod_desc.$PID
            if [ -f $prod_desc_patch ]
            then
                . $prod_desc_patch
                if [ $product = apex  ]
                then
                    $TOUCH /tmp/lp.start.$$
                elif [ -f $prod_home/bin/$product.init ]
                then
                    echo "$product.$product_version $prod_home" > \
                        /tmp/lp.start.$$
                fi
            else
                echo "$command: $prod_desc_patch not found."
                echo "$command: <patch_id> is '$PID'"
                usage 1
            fi
            shift
            ;;
        -install_crypt|-ic )
            echo
            echo "Option '$1' specified."
            echo "Will install encrypted components only."
            install_crypt=true
            ;;
        -install_patches|-ip )
            echo
            echo "Option '$1' specified. Will install patches only."
            run_post_patch
            exit 0
            ;;
        -* )
            echo "$command: Option '$1' is not recognized."
            usage 1
            ;;
    esac
    shift
done

case $command in
    post_install )
        NAME="Post Install:"
        CMND="POST_INSTALL"
        ss_base=$prod_base
        view_type=rel
        ;;
    make_tests )
        NAME="Make Tests:"
        CMND="MAKE_TESTS"
        ss_base=$prod_home
        view_steps="$view_steps link"
        view_type=wrk
        save_defaults code_link
        ;;
esac

if [ -n "$release_type" ]
then
    banner_version="$product_version$patch_level ($release_type)"
else
    banner_version="$product_version$patch_level"
fi

banner "$NAME" \
    "${rprod_name:-$product_name}, $target_os_name" \
    "$banner_version" \
    "$product_date" \
    "$copyright_year" \
    "$vendor"

echo
echo "Product directory: $prod_home"

put_var $CMND STARTED
add_cleanup_file $temp

if [ "$check_sw_imp" = yes ]
then
     echo "Will check for /sierra/, /aloha/, /ned & /accts/ in import and switch files."
     $RM -f $install_dir/sierra_ned
fi

if [ -z "$PID" ]
then
    set_home_vars
fi
set_apex_pver_etc

#------------------------------------------------------------------------
# Check system requirements
#------------------------------------------------------------------------
if [ -z "$PID" -a  -x ./check_reqs ]
then
    case $product in
    rose* )
        if [ ! -x ./check_rose_reqs  ]
        then
            $CP check_reqs check_rose_reqs
        fi
        check_reqs=check_rose_reqs
        ;;
    * )
        check_reqs=check_reqs
        ;;
    esac

    ./$check_reqs -install
    case $? in
    0 )
        ;;
    1 )
        ask_continue no
        ;;
    * )
        # Abort this script
        fatal "Cannot continue until required system parameters
               have been satisfied."
        ;;
    esac
fi

#------------------------------------------------------------------------
set_library_path () {
#------------------------------------------------------------------------

    library_path=$1
    unset _path
    shift
    for _dir in $*
    do
        if [ -d $_dir ]
        then
            if [ -n "$_path" ]
            then
                _path=$_path:$_dir
            else
                _path=$_dir
            fi
        fi
    done
    eval $library_path=\$_path
    eval export $library_path
}

#------------------------------------------------------------------------
# Set architecture specific linker/loader search paths.
#------------------------------------------------------------------------
case $ARCH in
   sun4_solaris2 )
       set_library_path LD_LIBRARY_PATH /usr/ucblib /usr/lib
       ;;
   mips_irix5 )
       set_library_path LD_LIBRARY_PATH /usr/lib /lib /usr/local/lib \
           $prod_home/mips_irix5/lib
       ;;
   mips_irix_n32 )
       set_library_path LD_LIBRARY_PATH $APEX_HOME/mips_irix5/lib \
           /usr/lib /lib /usr/local/lib
       set_library_path LD_LIBRARYN32_PATH /usr/lib32 /lib32 /usr/local/lib32
       set_library_path LD_LIBRARYN64_PATH /usr/lib64 /lib64 /usr/local/lib64
       ;;
   rs6k* )
       set_library_path LIBPATH /usr/lib /lib $prod_home/rs6k*/lib
       ;;
   hp* )
       set_library_path SHLIB_PATH /usr/lib $prod_home/$ARCH/lib
       ;;
esac

#------------------------------------------------------------------------
# Set and verify license server installation
#------------------------------------------------------------------------
if [ -z "$PID" ]
then
    set_lm_license_file
    check_license_features
fi

#------------------------------------------------------------------------
# Main post_install starts here. Run product specific post_install scripts.
#------------------------------------------------------------------------
if $install_crypt
then
    cn=1
    no_need_dopi=true
    n_crypt=0
    while [ $cn -le $cmps ]
    do
        eval cmp_crypt=\$cmp_${cn}_crypt
        if [ -n "$cmp_crypt" ]
        then
            n_crypt=`$EXPR $n_crypt + 1`
            . $install_dir/$ARCH/disk_install_dir
            ndevice=$disk_install_dir/file$cn
            if do_decrypt_file true
            then
                eval cmp_${cn}_dopi=true
                no_need_dopi=false
            fi
        fi
        cn=`$EXPR $cn + 1`
    done
    if $no_need_dopi
    then
        case $n_crypt in
        0 )
            echo "There are no encrypted components."
            ;;
        1 )
            echo "Failed to install the encrypted component."
            echo "There are no components that need to be post-installed."
            ;;
        * )
            echo "Failed to install $n_crypt encrypted components."
            echo "There are no components that need to be post-installed."
            ;;
        esac
        exit 0
    fi
elif [ -z "$PID" -a  $command = post_install ]
then
    #--------------------------------------------------------------------
    # Check for pre_patch and do_install_patch scripts.
    #--------------------------------------------------------------------
    if [ -f $install_dir/pre_patch ]
    then
        separator
        . $install_dir/pre_patch
    fi

    if [ -f $install_dir/share/do_install_patch ]
    then
        separator
        . $install_dir/share/do_install_patch
    fi

    # Install any patches that are designated to be installed
    # before running apexinit.
    run_pre_apexinit_patch

    #--------------------------------------------------------------------
    # Run installation-group-supplied post_install '.sh' file
    #--------------------------------------------------------------------
    if [ -f $install_dir/share/$product.sh ]
    then
        . $install_dir/share/$product.sh
    fi

    #--------------------------------------------------------------------
    # Run product-group-supplied post_install file
    #--------------------------------------------------------------------
    if [ -f $install_dir/share/$product.post_install ]
    then
        . $install_dir/share/$product.post_install
    fi

    #--------------------------------------------------------------------
    # Create links to the shared bin directory in the ARCH/bin directory.
    # make_bin_links must be defined in PRODUCT.prod_desc.preamble file.
    #--------------------------------------------------------------------
    if [ "$make_bin_links" = yes  -a  ! -f $prod_home/$ARCH/bin/.bin_link ]
    then
        echo
        echo Making links to shared bin directory in $ARCH/bin...
        # Make links to all files in prod_home/bin in prod_home/ARCH/bin
        (
         cd $prod_home/$ARCH/bin
         for _file in $prod_home/bin/*
         do
             _name=`$BASENAME $_file`
             if [ $sym_link $_name ]
             then
                 rm -f $_name
             elif [ -f $_name ]
             then
                 # Do not create link.  File already exists of the same name.
                 continue
             fi

             if _link_to=`is_a_link $_file`
             then
                 # It is a link to some file in bin.
                 case $_link_to in
                     /* )  # Absolute link
                         $LN -s $_link_to $_name
                         ;;
                      * )  # relative link
                         $LN -s $prod_home/bin/$_link_to $_name
                         ;;
                 esac
             else
                 # Make it a link to the one in prod_home/bin
                 $LN -s $_file $_name
             fi
         done
         $TOUCH .bin_link
        )
    fi

    if [ -z "$view_steps" ]
    then
        run_post_patch
        put_var $CMND COMPLETED
        exit 0
    fi
fi

#------------------------------------------------------------------------
# You only want to reach this point if the product has subsystem/views that
# need apex set_location, remodel, compile, link and/or frozen (view_steps)
# commands applied to them.
#------------------------------------------------------------------------
# Make sure apexinit is installed properly.
#------------------------------------------------------------------------
if [ -x $APEX_HOME/bin/apexinit ]
then
    if [ -f /tmp/lp.start.$$ ]
    then
        # Tell apexinit to load the layered product's init file.
        add_cleanup_file /tmp/lp.start.$$
        APEXINIT="$APEX_HOME/bin/apexinit -startup /tmp/lp.start.$$"
    elif [ "$apex_layered_product" = yes ]
    then
        echo "$product.$product_version $prod_home" > /tmp/lp.start.$$
        add_cleanup_file /tmp/lp.start.$$
        APEXINIT="$APEX_HOME/bin/apexinit -startup /tmp/lp.start.$$"
    else
        APEXINIT=$APEX_HOME/bin/apexinit
    fi
else
    fatal "Cannot find apexinit in $APEX_HOME/bin.
           Check that APEX_HOME is set correctly and that
           Rational Apex installation is complete."
fi

#------------------------------------------------------------------------
# Set location, remodel, install, compile, link and freeze subsystems.
#------------------------------------------------------------------------
customize_subsystems
if [ $? -ne 0 ]
then
    fatal "$product_name '$command' command failed."
fi

run_post_patch

if [ -z "$PID" ]
then
    put_var $CMND COMPLETED
fi

