home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Python 1.4 / Python 1.4 source / Modules / ld_so_aix < prev    next >
Encoding:
Text File  |  1996-10-22  |  5.7 KB  |  181 lines  |  [TEXT/R*ch]

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