sl@0
|
1 |
#!/bin/sh
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# ldAix ldCmd ldArg ldArg ...
|
sl@0
|
4 |
#
|
sl@0
|
5 |
# This shell script provides a wrapper for ld under AIX in order to
|
sl@0
|
6 |
# create the .exp file required for linking. Its arguments consist
|
sl@0
|
7 |
# of the name and arguments that would normally be provided to the
|
sl@0
|
8 |
# ld command. This script extracts the names of the object files
|
sl@0
|
9 |
# from the argument list, creates a .exp file describing all of the
|
sl@0
|
10 |
# symbols exported by those files, and then invokes "ldCmd" to
|
sl@0
|
11 |
# perform the real link.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# RCS: @(#) $Id: ldAix,v 1.4 2002/09/27 01:28:26 hobbs Exp $
|
sl@0
|
14 |
|
sl@0
|
15 |
# Extract from the arguments the names of all of the object files.
|
sl@0
|
16 |
|
sl@0
|
17 |
args=$*
|
sl@0
|
18 |
ofiles=""
|
sl@0
|
19 |
for i do
|
sl@0
|
20 |
x=`echo $i | grep '[^.].o$'`
|
sl@0
|
21 |
if test "$x" != ""; then
|
sl@0
|
22 |
ofiles="$ofiles $i"
|
sl@0
|
23 |
fi
|
sl@0
|
24 |
done
|
sl@0
|
25 |
|
sl@0
|
26 |
# Extract the name of the object file that we're linking.
|
sl@0
|
27 |
outputFile=`echo $args | sed -e 's/.*-o \([^ ]*\).*/\1/'`
|
sl@0
|
28 |
|
sl@0
|
29 |
# Create the export file from all of the object files, using nm followed
|
sl@0
|
30 |
# by sed editing. Here are some tricky aspects of this:
|
sl@0
|
31 |
#
|
sl@0
|
32 |
# 1. Nm produces different output under AIX 4.1 than under AIX 3.2.5;
|
sl@0
|
33 |
# the following statements handle both versions.
|
sl@0
|
34 |
# 2. Use the -g switch to nm instead of -e under 4.1 (this shows just
|
sl@0
|
35 |
# externals, not statics; -g isn't available under 3.2.5, though).
|
sl@0
|
36 |
# 3. Use the -X32_64 switch to nm on AIX-4+ to handle 32 or 64bit compiles.
|
sl@0
|
37 |
# 4. Eliminate lines that end in ":": these are the names of object
|
sl@0
|
38 |
# files (relevant in 4.1 only).
|
sl@0
|
39 |
# 5. Eliminate entries with the "U" key letter; these are undefined
|
sl@0
|
40 |
# symbols (relevant in 4.1 only).
|
sl@0
|
41 |
# 6. Eliminate lines that contain the string "0|extern" preceded by space;
|
sl@0
|
42 |
# in 3.2.5, these are undefined symbols (address 0).
|
sl@0
|
43 |
# 7. Eliminate lines containing the "unamex" symbol. In 3.2.5, these
|
sl@0
|
44 |
# are also undefined symbols.
|
sl@0
|
45 |
# 8. If a line starts with ".", delete the leading ".", since this will
|
sl@0
|
46 |
# just cause confusion later.
|
sl@0
|
47 |
# 9. Eliminate everything after the first field in a line, so that we're
|
sl@0
|
48 |
# left with just the symbol name.
|
sl@0
|
49 |
|
sl@0
|
50 |
nmopts="-g -C"
|
sl@0
|
51 |
osver=`uname -v`
|
sl@0
|
52 |
if test $osver -eq 3; then
|
sl@0
|
53 |
nmopts="-e"
|
sl@0
|
54 |
fi
|
sl@0
|
55 |
if test $osver -gt 3; then
|
sl@0
|
56 |
nmopts="$nmopts -X32_64"
|
sl@0
|
57 |
fi
|
sl@0
|
58 |
rm -f lib.exp
|
sl@0
|
59 |
echo "#! $outputFile" >lib.exp
|
sl@0
|
60 |
/usr/ccs/bin/nm $nmopts -h $ofiles | sed -e '/:$/d' -e '/ U /d' -e '/[ ]0|extern/d' -e '/unamex/d' -e 's/^\.//' -e 's/[ |].*//' | sort | uniq >>lib.exp
|
sl@0
|
61 |
|
sl@0
|
62 |
# If we're linking a .a file, then link all the objects together into a
|
sl@0
|
63 |
# single file "shr.o" and then put that into the archive. Otherwise link
|
sl@0
|
64 |
# the object files directly into the .a file.
|
sl@0
|
65 |
|
sl@0
|
66 |
outputFile=`echo $args | sed -e 's/.*-o \([^ ]*\).*/\1/'`
|
sl@0
|
67 |
noDotA=`echo $outputFile | sed -e '/\.a$/d'`
|
sl@0
|
68 |
echo "noDotA=\"$noDotA\""
|
sl@0
|
69 |
if test "$noDotA" = "" ; then
|
sl@0
|
70 |
linkArgs=`echo $args | sed -e 's/-o .*\.a /-o shr.o /'`
|
sl@0
|
71 |
echo $linkArgs
|
sl@0
|
72 |
eval $linkArgs
|
sl@0
|
73 |
echo ar cr $outputFile shr.o
|
sl@0
|
74 |
ar cr $outputFile shr.o
|
sl@0
|
75 |
rm -f shr.o
|
sl@0
|
76 |
else
|
sl@0
|
77 |
eval $args
|
sl@0
|
78 |
fi
|