Home | History | Annotate | Download | only in Modules
      1 #!/bin/sh
      2 #
      3 #   ========================================================================
      4 #   FILE:           ld_so_aix
      5 #   TYPE:           executable, uses makexp_aix
      6 #   SYSTEM:         AIX
      7 #
      8 #   DESCRIPTION:    Creates a shareable .o from a set of pre-compiled 
      9 #                   (unshared) .o files
     10 #
     11 #   USAGE:          ld_so_aix [CC] [arguments]
     12 #
     13 #   ARGUMENTS:      Same as for "ld". The following arguments are processed
     14 #                   or supplied by this script (those marked with an asterisk
     15 #                   can be overridden from command line):
     16 #
     17 #                       Argument                     Default value
     18 #                   (*) -o [OutputFileName]          -o shr.o
     19 #                   (*) -e [EntryPointLabel]         -e init[OutputBaseName]
     20 #                   (*) -bE:[ExportFile]             -bE:[OutputBaseName].exp
     21 #                   (*) -bI:[ImportFile]             -bI:./python.exp
     22 #                       -bM:[ModuleType]             -bM:SRE
     23 #                       -bhalt:[Number]              -bhalt:4
     24 #                       -T[Number]                   -T512
     25 #                       -H[Number]                   -H512
     26 #                       -lm
     27 #
     28 #                   The compiler specific ("-lc" or "-lc_r", "-lpthreads",...)
     29 #                   arguments will be automatically passed to "ld" according
     30 #                   to the CC command provided as a first argument to this
     31 #                   script. Usually, the same CC command was used to produce
     32 #                   the pre-compiled .o file(s).
     33 #
     34 #   NOTES:          1.  Since "ld_so_aix" was originally written for building
     35 #                       shared modules for the Python interpreter, the -e and
     36 #                       -bI default values match Python's conventions. In
     37 #                       Python, the entry point for a shared module is based
     38 #                       on the module's name (e.g., the "mathmodule" will
     39 #                       expect an  entry point of "initmath").
     40 #                   2.  The script accepts multiple .o or .a input files and
     41 #                       creates a single (shared) output file. The export list
     42 #                       that is created is based on the output file's basename
     43 #                       with the suffix ".exp".
     44 #                   3.  The resulting shared object file is left in the
     45 #                       current directory.
     46 #                   4.  Uncommenting the "echo" lines gives detailed output
     47 #                       about the commands executed in the script.
     48 #
     49 #                       
     50 #   HISTORY:        Oct-1996    -- Support added for multiple .o files --
     51 #                               -- and optional arguments processing.  --
     52 #                   Chris Myers (myers (at] tc.cornell.edu), Keith Kwok
     53 #                   (kkwok (at] tc.cornell.edu) and Vladimir Marangozov
     54 #
     55 #                   Aug-6-1996  -- Take care of the compiler specific  --
     56 #                               -- args by leaving CC to invoke "ld".  --
     57 #                   Vladimir Marangozov
     58 #
     59 #                   Jul-1-1996  -- Make sure to use /usr/ccs/bin/ld    --
     60 #                               -- Use makexp_aix for the export list. --
     61 #                   Vladimir Marangozov     (Vladimir.Marangozov (at] imag.fr)
     62 #
     63 #                   Manus Hand (mhand (at] csn.net) -- Initial code -- 6/24/96
     64 #   ========================================================================
     65 #
     66 
     67 usage="Usage: ld_so_aix [CC command] [ld arguments]"
     68 if test ! -n "$*"; then
     69   echo $usage; exit 2
     70 fi
     71 
     72 makexp=`dirname $0`/makexp_aix
     73 test -x "${makexp}" || makexp="@abs_srcdir@/makexp_aix"
     74 
     75 # Check for existence of compiler.
     76 CC=$1; shift
     77 whichcc=`which $CC`
     78 
     79 if test ! -x "$whichcc"; then
     80   echo "ld_so_aix: Compiler '$CC' not found; exiting."
     81   exit 2
     82 fi
     83 
     84 if test ! -n "$*"; then
     85   echo $usage; exit 2
     86 fi
     87 
     88 # Default import file for Python
     89 # Can be overridden by providing a -bI: argument.
     90 impfile="./python.exp"
     91 
     92 # Parse arguments
     93 while test -n "$1"
     94 do
     95   case "$1" in
     96     -e | -Wl,-e)
     97         if test -z "$2"; then
     98 	  echo "ld_so_aix: The -e flag needs a parameter; exiting."; exit 2
     99 	else
    100 	  shift; entry=$1
    101 	fi
    102 	;;
    103     -e* | -Wl,-e*)
    104 	entry=`echo $1 | sed -e "s/-Wl,//" -e "s/-e//"`
    105 	;;
    106     -o)
    107 	if test -z "$2"; then
    108 	  echo "ld_so_aix: The -o flag needs a parameter; exiting."; exit 2
    109 	else
    110 	  shift; objfile=$1
    111 	fi
    112 	;;
    113     -o*)
    114 	objfile=`echo $1 | sed "s/-o//"`
    115 	;;
    116     -bI:* | -Wl,-bI:*)
    117 	impfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bI://"`
    118 	;;
    119     -bE:* | -Wl,-bE:*)
    120 	expfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bE://"`
    121 	;;
    122     *.o | *.a)
    123 	objs="$objs $1"
    124 	args="$args $1"
    125 	;;
    126     -bM:* | -Wl,-bM:* | -H* | -Wl,-H* | -T* | -Wl,-T* | -lm)
    127 	;;
    128     *)
    129         args="$args $1"
    130 	;;
    131   esac
    132   shift
    133 done
    134 
    135 if test "$objfile" = "libpython@VERSION@.so"; then
    136   ldsocoremode="true" 
    137 fi
    138 
    139 if test -z "$objs"; then
    140   echo "ld_so_aix: No input files; exiting."
    141   exit 2
    142 elif test ! -r "$impfile" -a -z "$ldsocoremode"; then
    143   echo "ld_so_aix: Import file '$impfile' not found or not readable; exiting."
    144   exit 2
    145 fi
    146 
    147 # If -o wasn't specified, assume "-o shr.o"
    148 if test -z "$objfile"; then
    149   objfile=shr.o
    150 fi
    151 
    152 filename=`basename $objfile | sed "s/\.[^.]*$//"`
    153 
    154 # If -bE: wasn't specified, assume "-bE:$filename.exp"
    155 if test -z "$expfile"; then
    156   expfile="$filename.exp"
    157 fi
    158 
    159 # Default entry symbol for Python modules = init[modulename]
    160 # Can be overridden by providing a -e argument.
    161 if test -z "$entry"; then
    162   entry=init`echo $filename | sed "s/module.*//"`
    163 fi
    164 
    165 #echo "ld_so_aix: Debug info section"
    166 #echo "  -> output file : $objfile"
    167 #echo "  -> import file : $impfile"
    168 #echo "  -> export file : $expfile"
    169 #echo "  -> entry point : $entry"
    170 #echo "  -> object files: $objs"
    171 #echo "  -> CC arguments: $args"
    172 
    173 if test -z "$ldsocoremode"; then
    174   CCOPT="-Wl,-e$entry -Wl,-bE:$expfile -Wl,-bI:$impfile -Wl,-bhalt:4"
    175 else
    176   CCOPT="-Wl,-bnoentry -Wl,-bE:$expfile -Wl,-bhalt:4"
    177 fi
    178 CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -Wl,-brtl -Wl,-bnortllib -lm -o $objfile"
    179 
    180 CCARGS="$args"
    181 
    182 # Export list generation.
    183 #echo $makexp $expfile "$objfile" $objs
    184 $makexp $expfile "$objfile" $objs
    185 
    186 # Perform the link.
    187 #echo $CC $CCOPT $CCARGS
    188 $CC $CCOPT $CCARGS
    189 retval=$?
    190 
    191 # Delete the module's export list file.
    192 # Comment this line if you need it.
    193 rm -f $expfile
    194 
    195 exit $retval
    196