Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # ======================================================================== |
| 4 | # FILE: ld_so_aix |
| 5 | # TYPE: executable, uses makexp_aix |
| 6 | # SYSTEM: AIX |
| 7 | # |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 8 | # DESCRIPTION: Creates a shareable .o from a set of pre-compiled |
| 9 | # (unshared) .o files |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 10 | # |
Guido van Rossum | a93b504 | 1996-08-08 19:06:31 +0000 | [diff] [blame] | 11 | # USAGE: ld_so_aix [CC] [arguments] |
| 12 | # |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 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): |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 16 | # |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 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 |
Guido van Rossum | fb84255 | 1997-08-06 23:42:07 +0000 | [diff] [blame] | 23 | # -bhalt:[Number] -bhalt:4 |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 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 |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 47 | # about the commands executed in the script. |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 48 | # |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 49 | # |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 50 | # HISTORY: Oct-1996 -- Support added for multiple .o files -- |
| 51 | # -- and optional arguments processing. -- |
| 52 | # Chris Myers (myers@tc.cornell.edu), Keith Kwok |
| 53 | # (kkwok@tc.cornell.edu) and Vladimir Marangozov |
| 54 | # |
| 55 | # Aug-6-1996 -- Take care of the compiler specific -- |
Guido van Rossum | a93b504 | 1996-08-08 19:06:31 +0000 | [diff] [blame] | 56 | # -- args by leaving CC to invoke "ld". -- |
| 57 | # Vladimir Marangozov |
| 58 | # |
| 59 | # Jul-1-1996 -- Make sure to use /usr/ccs/bin/ld -- |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 60 | # -- Use makexp_aix for the export list. -- |
| 61 | # Vladimir Marangozov (Vladimir.Marangozov@imag.fr) |
| 62 | # |
| 63 | # Manus Hand (mhand@csn.net) -- Initial code -- 6/24/96 |
| 64 | # ======================================================================== |
| 65 | # |
| 66 | |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 67 | usage="Usage: ld_so_aix [CC command] [ld arguments]" |
| 68 | if test ! -n "$*"; then |
| 69 | echo $usage; exit 2 |
| 70 | fi |
Guido van Rossum | a93b504 | 1996-08-08 19:06:31 +0000 | [diff] [blame] | 71 | |
Guido van Rossum | 5ade084 | 1997-09-03 00:45:30 +0000 | [diff] [blame] | 72 | makexp=`dirname $0`/makexp_aix |
| 73 | |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 74 | # Check for existence of compiler. |
| 75 | CC=$1; shift |
| 76 | whichcc=`which $CC` |
| 77 | |
| 78 | if test ! -x "$whichcc"; then |
| 79 | echo "ld_so_aix: Compiler '$CC' not found; exiting." |
| 80 | exit 2 |
| 81 | fi |
| 82 | |
| 83 | if test ! -n "$*"; then |
| 84 | echo $usage; exit 2 |
| 85 | fi |
| 86 | |
| 87 | # Default import file for Python |
| 88 | # Can be overriden by providing a -bI: argument. |
| 89 | impfile="./python.exp" |
| 90 | |
| 91 | # Parse arguments |
| 92 | while test -n "$1" |
| 93 | do |
| 94 | case "$1" in |
| 95 | -e | -Wl,-e) |
| 96 | if test -z "$2"; then |
| 97 | echo "ld_so_aix: The -e flag needs a parameter; exiting."; exit 2 |
| 98 | else |
| 99 | shift; entry=$1 |
| 100 | fi |
| 101 | ;; |
| 102 | -e* | -Wl,-e*) |
| 103 | entry=`echo $1 | sed -e "s/-Wl,//" -e "s/-e//"` |
| 104 | ;; |
| 105 | -o) |
| 106 | if test -z "$2"; then |
| 107 | echo "ld_so_aix: The -o flag needs a parameter; exiting."; exit 2 |
| 108 | else |
| 109 | shift; objfile=$1 |
| 110 | fi |
| 111 | ;; |
| 112 | -o*) |
| 113 | objfile=`echo $1 | sed "s/-o//"` |
| 114 | ;; |
| 115 | -bI:* | -Wl,-bI:*) |
| 116 | impfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bI://"` |
| 117 | ;; |
| 118 | -bE:* | -Wl,-bE:*) |
| 119 | expfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bE://"` |
| 120 | ;; |
| 121 | *.o | *.a) |
| 122 | objs="$objs $1" |
| 123 | args="$args $1" |
| 124 | ;; |
| 125 | -bM:* | -Wl,-bM:* | -H* | -Wl,-H* | -T* | -Wl,-T* | -lm) |
| 126 | ;; |
| 127 | *) |
| 128 | args="$args $1" |
| 129 | ;; |
| 130 | esac |
| 131 | shift |
| 132 | done |
| 133 | |
Georg Brandl | 9a829be | 2011-02-15 15:44:51 +0000 | [diff] [blame] | 134 | if test "$objfile" = "libpython@VERSION@@ABIFLAGS@.so"; then |
Antoine Pitrou | 8e6b407 | 2010-09-10 19:44:44 +0000 | [diff] [blame] | 135 | ldsocoremode="true" |
| 136 | fi |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 137 | |
| 138 | if test -z "$objs"; then |
| 139 | echo "ld_so_aix: No input files; exiting." |
| 140 | exit 2 |
Antoine Pitrou | 8e6b407 | 2010-09-10 19:44:44 +0000 | [diff] [blame] | 141 | elif test ! -r "$impfile" -a -z "$ldsocoremode"; then |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 142 | echo "ld_so_aix: Import file '$impfile' not found or not readable; exiting." |
| 143 | exit 2 |
| 144 | fi |
| 145 | |
| 146 | # If -o wasn't specified, assume "-o shr.o" |
| 147 | if test -z "$objfile"; then |
| 148 | objfile=shr.o |
| 149 | fi |
| 150 | |
| 151 | filename=`basename $objfile | sed "s/\.[^.]*$//"` |
| 152 | |
| 153 | # If -bE: wasn't specified, assume "-bE:$filename.exp" |
| 154 | if test -z "$expfile"; then |
| 155 | expfile="$filename.exp" |
| 156 | fi |
| 157 | |
| 158 | # Default entry symbol for Python modules = init[modulename] |
| 159 | # Can be overriden by providing a -e argument. |
| 160 | if test -z "$entry"; then |
Antoine Pitrou | 8e6b407 | 2010-09-10 19:44:44 +0000 | [diff] [blame] | 161 | entry=PyInit_`echo $filename | sed "s/module.*//"` |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 162 | fi |
| 163 | |
Guido van Rossum | fb84255 | 1997-08-06 23:42:07 +0000 | [diff] [blame] | 164 | #echo "ld_so_aix: Debug info section" |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 165 | #echo " -> output file : $objfile" |
| 166 | #echo " -> import file : $impfile" |
| 167 | #echo " -> export file : $expfile" |
| 168 | #echo " -> entry point : $entry" |
| 169 | #echo " -> object files: $objs" |
| 170 | #echo " -> CC arguments: $args" |
Guido van Rossum | a93b504 | 1996-08-08 19:06:31 +0000 | [diff] [blame] | 171 | |
Antoine Pitrou | 8e6b407 | 2010-09-10 19:44:44 +0000 | [diff] [blame] | 172 | if test -z "$ldsocoremode"; then |
| 173 | CCOPT="-Wl,-e$entry -Wl,-bE:$expfile -Wl,-bI:$impfile -Wl,-bhalt:4" |
| 174 | else |
| 175 | CCOPT="-Wl,-bnoentry -Wl,-bE:$expfile -Wl,-bhalt:4" |
| 176 | fi |
| 177 | CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -Wl,-brtl -Wl,-bnortllib -lm -o $objfile" |
Neal Norwitz | a45770d | 2005-10-03 03:57:09 +0000 | [diff] [blame] | 178 | |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 179 | CCARGS="$args" |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 180 | |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 181 | # Export list generation. |
Guido van Rossum | 5ade084 | 1997-09-03 00:45:30 +0000 | [diff] [blame] | 182 | #echo $makexp $expfile "$objfile" $objs |
| 183 | $makexp $expfile "$objfile" $objs |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 184 | |
| 185 | # Perform the link. |
Guido van Rossum | a93b504 | 1996-08-08 19:06:31 +0000 | [diff] [blame] | 186 | #echo $CC $CCOPT $CCARGS |
| 187 | $CC $CCOPT $CCARGS |
Antoine Pitrou | 8966c99 | 2009-05-01 21:18:27 +0000 | [diff] [blame] | 188 | retval=$? |
Guido van Rossum | b4ae6a3 | 1996-08-08 19:05:09 +0000 | [diff] [blame] | 189 | |
| 190 | # Delete the module's export list file. |
| 191 | # Comment this line if you need it. |
Guido van Rossum | a1b1cdb | 1996-10-21 15:10:39 +0000 | [diff] [blame] | 192 | rm -f $expfile |
Antoine Pitrou | 8966c99 | 2009-05-01 21:18:27 +0000 | [diff] [blame] | 193 | |
| 194 | exit $retval |