Subversion Repositories DevTools

Rev

Rev 227 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/sh
# -*- mode: sh; tabs: 8; show-tabs: yes; hard-tabs: yes; -*-
################################################################################
# Module name   : Build system
# Module type   : makefile util
# Environment(s): WIN32, Unix(Solaris/Linux)
#
#    Merge multiple archives
#
# Version   Who      Date        Description
# 1.0       APY      09/06/99    Created
# 2.0       APY      31/07/01    WIN32 support
# 3.0       DDP      04/02/04    Microtec support
#                                Added a "-m libraian_path" switch to interwork
#                                with the MRI68K and MRICF toolsets
#                                Use -m \$(mri_librarian) to access the librarian
#                                to be used.
#           APY       20/05/04   -t and -a options
#                                1.2.0
#           DDP       23-Nov-04  1.3.0:
#                                Remove use of basename.
#                                Under Win32 $0 contains \\ and basename
#                                does not work.
#                                Added -n switch
#                                Prevent redirection to /dev/null for systems
#                                in which this doesn't work.
#           DDP     10-Jan-05   There is no windows/solaris way to determine the
#                               srcipt name - just name it.            
#
#
# $Source: /cvsroot/etm/devl/TOOLS/armerge,v $
# $Revision: 1.3 $ $Date: 2004/05/25 10:49:32 $ $State: Exp $
# $Author: adamy $ $Locker:  $
#################################################################################
#

SCRIPT=armerge
VERSION="1.3.0"

#..     Parse command line
#
FLAG_MACHTYPE=""
FLAG_DIR=""
FLAG_LIB=""
FLAG_AR=""
FLAG_V=0
FLAG_MICROTEC=""
FLAG_NULL="/dev/null"

while [ "$#" -gt "0" -a "${FLAG_LIB}" = "" ]; do
        case $1 in
        -h | -\? )
        cat << EOF
Archive Merge Utility (${VERSION})
Copyright (c) VIX TECHNOLOGY (AUST) LTD

usage:          
    ${SCRIPT} [-?h] [-d tmpdir] [-v] [-t machtype] [-a librarian] 
        [-m librarian] {dest-library} source [source ...]

Where:
    -h, -?      Help
    -v          Verbose
    -d <dir>    Destination directory
    -t          Override GBE_MACHTYPE host selection.
    -a          Alternative librarian.
    -m          Microtec (exclusive to -t and -a)
    -n file     Replace null device

EOF
                exit 0
                ;;

        -v)     FLAG_V=1
                ;;

        -d)     if [ "${FLAG_DIR}" != "" ]; then
                        echo ${SCRIPT} "You must specify only one -d.  Aborting."
                        exit 1
                fi
                if [ "$2" = "" ]; then
                        echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
                        exit 1
                fi
                FLAG_DIR=$2
                shift
                ;;

        -m)     if [ "$2" = "" ]; then
                        echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
                        exit 1
                fi
                FLAG_MICROTEC=$2
                shift
                ;;

        -t)     if [ "$2" = "" ]; then
                        echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
                        exit 1
                fi
                FLAG_MACHTYPE=$2
                shift
                ;;
        
        -a)     if [ "$2" = "" ]; then
                        echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
                        exit 1
                fi
                FLAG_AR=$2
                shift
                ;;

        -n)     if [ "$2" = "" ]; then
                        echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
                        exit 1
                fi
                FLAG_NULL=$2
                shift
                ;;
        
  
        * )     FLAG_LIB=$1
                ;;
        esac
        shift
done

if [ "${FLAG_MACHTYPE}" = "" ]; then
if [ "${GBE_MACHTYPE}" = "" ]; then
        echo ${SCRIPT} "GBE_MACHTYPE unknown.  Aborting."
        exit 1
fi
FLAG_MACHTYPE=${GBE_MACHTYPE}
fi
if [ "${FLAG_LIB}" = "" ]; then
        echo ${SCRIPT} "You must specify a destination library.  Aborting."
        exit 1
fi
if [ $# -eq 0 ]; then
        echo ${SCRIPT} "You must specify one or source libraries.  Aborting."
        exit 1
fi

SOURCE_LIBS=""
while [ "$1" != "" ]; do
        SOURCE_LIBS="${SOURCE_LIBS} ${1}"
        shift
done

[ ${FLAG_V} -ne 0 ] && echo "${SCRIPT}: MACHTYPE = ${FLAG_MACHTYPE}"

##  Mictotec linker
#..
if [ $FLAG_MICROTEC ] ; then

        #..     Merge Libraries
        #
        if [ -f ${FLAG_LIB} ]; then
                rm ${FLAG_LIB}
        fi

        #..     Check/create work directory
        #
        if [ "${FLAG_DIR}" = "" ]; then
                FLAG_DIR="."
        elif [ ! -d ${FLAG_DIR} ]; then
                mkdir -p ${FLAG_DIR}
                if [ ! -d ${FLAG_DIR} ]; then
                        echo ${SCRIPT} "Unable to create target directory.  Aborting."
                        exit 1
                fi
        fi
    
        #.. Create a command file
        #
        CMDFILE="${FLAG_DIR}/armerge.cmd"
        rm -f $CMDFILE
        echo >>$CMDFILE "create ${FLAG_LIB}"
        for LIB in ${SOURCE_LIBS}; do
                echo >>$CMDFILE "ADDL ${LIB}"
        done
        echo >>$CMDFILE "save"
        echo >>$CMDFILE "exit"

        $FLAG_MICROTEC < $CMDFILE
        if [ $? -ne 0 ]; then
                exit 1
        fi
        rm -f $CMDFILE

##  WIN32
#...
elif [ "${FLAG_MACHTYPE}" = "win32" -o "${FLAG_MACHTYPE}" = "MSVC" ]; then

        #..     Merge Libraries
        #
        if [ "${FLAG_AR}" = "" ]; then          # default librarian
                FLAG_AR=lib
        fi;
        if [ -f ${FLAG_LIB} ]; then
                rm ${FLAG_LIB}
        fi
        [ ${FLAG_V} -ne 0 ] && echo "${SCRIPT}: ${FLAG_AR} -nologo -out:${FLAG_LIB} ${SOURCE_LIBS}"
        ${FLAG_AR} -nologo -out:${FLAG_LIB} ${SOURCE_LIBS}
        if [ $? -ne 0 ]; then
                exit 1
        fi

## UNIX (default)
#...
else

        [ ${FLAG_V} -ne 0 ] && echo "${SCRIPT}: .. Unix AR Merge"

        #..     Check/create work directory
        #
        if [ "${FLAG_DIR}" = "" ]; then
                FLAG_DIR="."
        elif [ ! -d ${FLAG_DIR} ]; then
                mkdir -p ${FLAG_DIR}
                if [ ! -d ${FLAG_DIR} ]; then
                        echo ${SCRIPT} "Unable to create target directory.  Aborting."
                        exit 1
                fi
        fi

        #..     Extract objects
        #             
        if [ "${FLAG_AR}" = "" ]; then          # default librarian
                FLAG_AR=ar
        fi;    
        
        SOURCE_OBJS=""
        for LIB in ${SOURCE_LIBS}; do
                echo "${SCRIPT}: scanning ${LIB}"
                OBJS=`${FLAG_AR} -t ${LIB}`
                for OBJ in ${OBJS}; do
                        if [ ${FLAG_V} -ne 0 ]; then
                                echo "${SCRIPT}: .. extracting ${OBJ}"
                        fi
                        `${FLAG_AR} -p ${LIB} ${OBJ} > ${FLAG_DIR}/${OBJ}`
                done
                SOURCE_OBJS="${SOURCE_OBJS} ${OBJS}"
        done

        #..     Merge
        #
        if [ -f ${FLAG_LIB} ]; then
                rm ${FLAG_LIB}
        fi
        for OBJ in ${SOURCE_OBJS}; do
                ${FLAG_AR} -q ${FLAG_LIB} ${FLAG_DIR}/${OBJ}
                if [ $? -ne 0 ]; then
                        exit 1
                fi
        done
        ${FLAG_AR} -ts ${FLAG_LIB} > ${FLAG_NULL}
        if [ $? -ne 0 ]; then
                exit 1
        fi
        for OBJ in ${SOURCE_OBJS}; do
                rm ${FLAG_DIR}/${OBJ}
        done
fi

exit 0