1#!/bin/sh
2#
3# ldAix ldCmd ldArg ldArg ...
4#
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.
12#
13# RCS: @(#) $Id: ldAix,v 1.4.18.1 2010/08/12 00:11:23 hobbs Exp $
14
15# Extract from the arguments the names of all of the object files.
16
17args=$*
18ofiles=""
19for i do
20    x=`echo $i | grep '[^.].o$'`
21    if test "$x" != ""; then
22	ofiles="$ofiles $i"
23    fi
24done
25
26# Extract the name of the object file that we're linking.
27outputFile=`echo $args | sed -e 's/.*-o \([^ ]*\).*/\1/'`
28
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:
31#
32# - Use the -X32_64 switch to nm to handle 32 or 64bit compiles.
33# - Eliminate lines that end in ":": these are the names of object files
34# - Eliminate entries with the "U" key letter;  these are undefined symbols
35# - If a line starts with ".", delete the leading ".", since this will just
36#   cause confusion later
37# - Eliminate everything after the first field in a line, so that we're
38#   left with just the symbol name
39
40nmopts="-g -C -h -X32_64"
41rm -f lib.exp
42echo "#! $outputFile" >lib.exp
43/usr/ccs/bin/nm $nmopts $ofiles | sed -e '/:$/d' -e '/ U /d' -e 's/^\.//' -e 's/[ 	|].*//' | sort | uniq >>lib.exp
44
45# If we're linking a .a file, then link all the objects together into a 
46# single file "shr.o" and then put that into the archive.  Otherwise link 
47# the object files directly into the .a file.
48
49noDotA=`echo $outputFile | sed -e '/\.a$/d'`
50echo "noDotA=\"$noDotA\""
51if test "$noDotA" = "" ; then
52    linkArgs=`echo $args | sed -e 's/-o .*\.a /-o shr.o /'`
53    echo $linkArgs
54    eval $linkArgs
55    echo ar cr $outputFile shr.o
56    ar cr $outputFile shr.o
57    rm -f shr.o
58else
59    eval $args
60fi
61