Subversion Repositories DevTools

Rev

Rev 227 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
#!/bin/sh
2
# -*- mode: sh; tabs: 8; show-tabs: yes; hard-tabs: yes; -*-
3
################################################################################
4
# Module name   : Build system
5
# Module type   : makefile util
6
# Environment(s): WIN32, Unix(Solaris/Linux)
7
#
8
#    Merge multiple archives
9
#
10
# Version   Who      Date        Description
11
# 1.0       APY      09/06/99    Created
12
# 2.0       APY      31/07/01    WIN32 support
13
# 3.0       DDP      04/02/04    Microtec support
14
#                                Added a "-m libraian_path" switch to interwork
15
#                                with the MRI68K and MRICF toolsets
16
#                                Use -m \$(mri_librarian) to access the librarian
17
#                                to be used.
18
#           APY       20/05/04   -t and -a options
19
#                                1.2.0
20
#           DDP       23-Nov-04  1.3.0:
21
#                                Remove use of basename.
22
#                                Under Win32 $0 contains \\ and basename
23
#                                does not work.
24
#                                Added -n switch
25
#                                Prevent redirection to /dev/null for systems
26
#                                in which this doesn't work.
27
#           DDP     10-Jan-05   There is no windows/solaris way to determine the
28
#                               srcipt name - just name it.            
29
#
30
#
31
# $Source: /cvsroot/etm/devl/TOOLS/armerge,v $
32
# $Revision: 1.3 $ $Date: 2004/05/25 10:49:32 $ $State: Exp $
33
# $Author: adamy $ $Locker:  $
34
#################################################################################
35
#
36
 
37
SCRIPT=armerge
38
VERSION="1.3.0"
39
 
40
#..     Parse command line
41
#
42
FLAG_MACHTYPE=""
43
FLAG_DIR=""
44
FLAG_LIB=""
45
FLAG_AR=""
46
FLAG_V=0
47
FLAG_MICROTEC=""
48
FLAG_NULL="/dev/null"
49
 
50
while [ "$#" -gt "0" -a "${FLAG_LIB}" = "" ]; do
51
	case $1 in
52
	-h | -\? )
53
	cat << EOF
54
Archive Merge Utility (${VERSION})
55
Copyright ERG (c) 1998-2004, All Rights Reserved
56
 
57
usage:          
58
    ${SCRIPT} [-?h] [-d tmpdir] [-v] [-t machtype] [-a librarian] 
59
        [-m librarian] {dest-library} source [source ...]
60
 
61
Where:
62
    -h, -?      Help
63
    -v          Verbose
64
    -d <dir>    Destination directory
65
    -t          Override GBE_MACHTYPE host selection.
66
    -a          Alternative librarian.
67
    -m          Microtec (exclusive to -t and -a)
68
    -n file     Replace null device
69
 
70
EOF
71
		exit 0
72
		;;
73
 
74
	-v)	FLAG_V=1
75
		;;
76
 
77
	-d)	if [ "${FLAG_DIR}" != "" ]; then
78
			echo ${SCRIPT} "You must specify only one -d.  Aborting."
79
			exit 1
80
		fi
81
		if [ "$2" = "" ]; then
82
			echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
83
			exit 1
84
		fi
85
		FLAG_DIR=$2
86
		shift
87
		;;
88
 
89
	-m)	if [ "$2" = "" ]; then
90
			echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
91
			exit 1
92
		fi
93
		FLAG_MICROTEC=$2
94
		shift
95
		;;
96
 
97
	-t)	if [ "$2" = "" ]; then
98
			echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
99
			exit 1
100
		fi
101
		FLAG_MACHTYPE=$2
102
		shift
103
		;;
104
 
105
	-a)	if [ "$2" = "" ]; then
106
			echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
107
			exit 1
108
		fi
109
		FLAG_AR=$2
110
		shift
111
		;;
112
 
113
	-n)	if [ "$2" = "" ]; then
114
			echo "${SCRIPT}: The $1 switch requires a command to be executed.  Aborting."
115
			exit 1
116
		fi
117
		FLAG_NULL=$2
118
		shift
119
		;;
120
 
121
 
122
	* )	FLAG_LIB=$1
123
		;;
124
	esac
125
	shift
126
done
127
 
128
if [ "${FLAG_MACHTYPE}" = "" ]; then
129
if [ "${GBE_MACHTYPE}" = "" ]; then
130
	echo ${SCRIPT} "GBE_MACHTYPE unknown.  Aborting."
131
	exit 1
132
fi
133
FLAG_MACHTYPE=${GBE_MACHTYPE}
134
fi
135
if [ "${FLAG_LIB}" = "" ]; then
136
	echo ${SCRIPT} "You must specify a destination library.  Aborting."
137
	exit 1
138
fi
139
if [ $# -eq 0 ]; then
140
	echo ${SCRIPT} "You must specify one or source libraries.  Aborting."
141
	exit 1
142
fi
143
 
144
SOURCE_LIBS=""
145
while [ "$1" != "" ]; do
146
	SOURCE_LIBS="${SOURCE_LIBS} ${1}"
147
	shift
148
done
149
 
150
[ ${FLAG_V} -ne 0 ] && echo "${SCRIPT}: MACHTYPE = ${FLAG_MACHTYPE}"
151
 
152
##  Mictotec linker
153
#..
154
if [ $FLAG_MICROTEC ] ; then
155
 
156
	#..     Merge Libraries
157
	#
158
	if [ -f ${FLAG_LIB} ]; then
159
		rm ${FLAG_LIB}
160
	fi
161
 
162
	#..     Check/create work directory
163
	#
164
	if [ "${FLAG_DIR}" = "" ]; then
165
		FLAG_DIR="."
166
	elif [ ! -d ${FLAG_DIR} ]; then
167
		mkdir -p ${FLAG_DIR}
168
		if [ ! -d ${FLAG_DIR} ]; then
169
			echo ${SCRIPT} "Unable to create target directory.  Aborting."
170
			exit 1
171
		fi
172
	fi
173
 
174
	#.. Create a command file
175
	#
176
	CMDFILE="${FLAG_DIR}/armerge.cmd"
177
	rm -f $CMDFILE
178
	echo >>$CMDFILE "create ${FLAG_LIB}"
179
	for LIB in ${SOURCE_LIBS}; do
180
		echo >>$CMDFILE "ADDL ${LIB}"
181
	done
182
	echo >>$CMDFILE "save"
183
	echo >>$CMDFILE "exit"
184
 
185
	$FLAG_MICROTEC < $CMDFILE
186
	if [ $? -ne 0 ]; then
187
		exit 1
188
	fi
189
	rm -f $CMDFILE
190
 
191
##  WIN32
192
#...
193
elif [ "${FLAG_MACHTYPE}" = "win32" -o "${FLAG_MACHTYPE}" = "MSVC" ]; then
194
 
195
	#..     Merge Libraries
196
	#
197
	if [ "${FLAG_AR}" = "" ]; then		# default librarian
198
		FLAG_AR=lib
199
	fi;
200
	if [ -f ${FLAG_LIB} ]; then
201
		rm ${FLAG_LIB}
202
	fi
203
	[ ${FLAG_V} -ne 0 ] && echo "${SCRIPT}: ${FLAG_AR} -nologo -out:${FLAG_LIB} ${SOURCE_LIBS}"
204
	${FLAG_AR} -nologo -out:${FLAG_LIB} ${SOURCE_LIBS}
205
	if [ $? -ne 0 ]; then
206
		exit 1
207
	fi
208
 
209
## UNIX (default)
210
#...
211
else
212
 
213
	[ ${FLAG_V} -ne 0 ] && echo "${SCRIPT}: .. Unix AR Merge"
214
 
215
	#..     Check/create work directory
216
	#
217
	if [ "${FLAG_DIR}" = "" ]; then
218
		FLAG_DIR="."
219
	elif [ ! -d ${FLAG_DIR} ]; then
220
		mkdir -p ${FLAG_DIR}
221
		if [ ! -d ${FLAG_DIR} ]; then
222
			echo ${SCRIPT} "Unable to create target directory.  Aborting."
223
			exit 1
224
		fi
225
	fi
226
 
227
	#..     Extract objects
228
	#             
229
	if [ "${FLAG_AR}" = "" ]; then		# default librarian
230
		FLAG_AR=ar
231
	fi;    
232
 
233
	SOURCE_OBJS=""
234
	for LIB in ${SOURCE_LIBS}; do
235
		echo "${SCRIPT}: scanning ${LIB}"
236
		OBJS=`${FLAG_AR} -t ${LIB}`
237
		for OBJ in ${OBJS}; do
238
			if [ ${FLAG_V} -ne 0 ]; then
239
				echo "${SCRIPT}: .. extracting ${OBJ}"
240
			fi
241
			`${FLAG_AR} -p ${LIB} ${OBJ} > ${FLAG_DIR}/${OBJ}`
242
		done
243
		SOURCE_OBJS="${SOURCE_OBJS} ${OBJS}"
244
	done
245
 
246
	#..     Merge
247
	#
248
	if [ -f ${FLAG_LIB} ]; then
249
		rm ${FLAG_LIB}
250
	fi
251
	for OBJ in ${SOURCE_OBJS}; do
252
		${FLAG_AR} -q ${FLAG_LIB} ${FLAG_DIR}/${OBJ}
253
		if [ $? -ne 0 ]; then
254
			exit 1
255
		fi
256
	done
257
	${FLAG_AR} -ts ${FLAG_LIB} > ${FLAG_NULL}
258
	if [ $? -ne 0 ]; then
259
		exit 1
260
	fi
261
	for OBJ in ${SOURCE_OBJS}; do
262
		rm ${FLAG_DIR}/${OBJ}
263
	done
264
fi
265
 
266
exit 0
267
 
268
 
269
 
270
 
271