3 # ldAix ldCmd ldArg ldArg ...
5 # This shell script provides a wrapper for ld under AIX in order to
6 # create the .exp file required for linking. Its arguments consist
7 # of the name and arguments that would normally be provided to the
8 # ld command. This script extracts the names of the object files
9 # from the argument list, creates a .exp file describing all of the
10 # symbols exported by those files, and then invokes "ldCmd" to
11 # perform the real link.
13 # RCS: @(#) $Id: ldAix,v 1.3 1999/03/10 05:52:52 stanton Exp $
15 # Extract from the arguments the names of all of the object files.
20 x=`echo $i | grep '[^.].o$'`
21 if test "$x" != ""; then
26 # Extract the name of the object file that we're linking.
27 outputFile=`echo $args | sed -e 's/.*-o \([^ ]*\).*/\1/'`
29 # Create the export file from all of the object files, using nm followed
30 # by sed editing. Here are some tricky aspects of this:
32 # 1. Nm produces different output under AIX 4.1 than under AIX 3.2.5;
33 # the following statements handle both versions.
34 # 2. Use the -g switch to nm instead of -e under 4.1 (this shows just
35 # externals, not statics; -g isn't available under 3.2.5, though).
36 # 3. Eliminate lines that end in ":": these are the names of object
37 # files (relevant in 4.1 only).
38 # 4. Eliminate entries with the "U" key letter; these are undefined
39 # symbols (relevant in 4.1 only).
40 # 5. Eliminate lines that contain the string "0|extern" preceded by space;
41 # in 3.2.5, these are undefined symbols (address 0).
42 # 6. Eliminate lines containing the "unamex" symbol. In 3.2.5, these
43 # are also undefined symbols.
44 # 7. If a line starts with ".", delete the leading ".", since this will
45 # just cause confusion later.
46 # 8. Eliminate everything after the first field in a line, so that we're
47 # left with just the symbol name.
51 if test $osver -eq 3; then
55 echo "#! $outputFile" >lib.exp
56 /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
58 # If we're linking a .a file, then link all the objects together into a
59 # single file "shr.o" and then put that into the archive. Otherwise link
60 # the object files directly into the .a file.
62 outputFile=`echo $args | sed -e 's/.*-o \([^ ]*\).*/\1/'`
63 noDotA=`echo $outputFile | sed -e '/\.a$/d'`
64 echo "noDotA=\"$noDotA\""
65 if test "$noDotA" = "" ; then
66 linkArgs=`echo $args | sed -e 's/-o .*\.a /-o shr.o /'`
69 echo ar cr $outputFile shr.o
70 ar cr $outputFile shr.o