#!/bin/ksh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# bos720 src/bos/usr/ccs/bin/ranlib/ranlib.sh 1.11 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1989,1993 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
# @(#)62	1.11  src/bos/usr/ccs/bin/ranlib/ranlib.sh, cmdaout, bos720 3/13/09 03:55:16
#
# COMPONENT_NAME: CMDAOUT (ranlib command)
#
#	ranlib script
#		Call the ar command with appropiate options
#
export PATH=/usr/bin:$PATH
AR_S="ar -s"
AR_H="ar -h"
AR_CMD=$AR_S
RET_CODE=0
OBJ_FLAG=
#
while getopts :tX: Opt
do
	case "$Opt" in
	        \?)     dspmsg ranlib.cat 1 \
		        "Usage: ranlib [-t] [-X {32|64|32_64}] [--] file ...\n"
                        exit 1
			;;
		t)	AR_CMD=$AR_H
			;;
		X)	OBJ_FLAG="$OPTARG"
			;;
	esac
done
shift OPTIND-1

#Verify the specified OBJECT mode
if [ "$OBJ_FLAG" != "" -a "$OBJ_FLAG" != "32"  \
     -a "$OBJ_FLAG" != "64" -a "$OBJ_FLAG" != "32_64" ]
then
    dspmsg ranlib.cat 3 "The specified object mode is not valid.\n\
\tSpecify -X32, -X64, or -X32_64.\n"
    exit 1
fi

#
if [ $# -eq 0 ]; then
    dspmsg ranlib.cat 1 "Usage: ranlib [-t] [-X {32|64|32_64}] [--] file ...\n"
    exit 1
fi

#If no -X given, look for OBJECT_MODE from environment
if [ "$OBJ_FLAG" = "" ]
then
    OBJ_FLAG=$OBJECT_MODE
    if [ "$OBJ_FLAG" != "" -a "$OBJ_FLAG" != "32"  \
         -a "$OBJ_FLAG" != "64" -a "$OBJ_FLAG" != "32_64" ]
    then
            dspmsg ranlib.cat 4 "The OBJECT_MODE environment variable has an \
invalid setting.\n\tOBJECT_MODE must be 32, 64, or 32_64.\n"
        exit 1
    fi
fi

if [ "$OBJ_FLAG" = "" ]; then
    OBJ_FLAG=32
fi

#
for OPT in "$@"
do
	$AR_CMD -X $OBJ_FLAG -- "$OPT"
	if [ $? -ne 0 ] ; then
		dspmsg ranlib.cat 2 "ranlib: 0654-601 Execution of ar failed\n"
		RET_CODE=`expr $RET_CODE + 1`
	fi
done

if [ $RET_CODE -ne 0 ]; then
    dspmsg ranlib.cat 1 "Usage: ranlib [-t] [-X {32|64|32_64}] [--] file ...\n"
fi
exit $RET_CODE