blob: 7106c0bca86bc021c977ad6803f6e560aab95c41 [file] [log] [blame]
Guido van Rossumb4ae6a31996-08-08 19:05:09 +00001#!/bin/sh
2#
3# ========================================================================
4# FILE: ld_so_aix
5# TYPE: executable, uses makexp_aix
6# SYSTEM: AIX
7#
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +00008# DESCRIPTION: Creates a shareable .o from a set of pre-compiled
9# (unshared) .o files
Guido van Rossumb4ae6a31996-08-08 19:05:09 +000010#
Guido van Rossuma93b5041996-08-08 19:06:31 +000011# USAGE: ld_so_aix [CC] [arguments]
12#
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000013# 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 Rossumb4ae6a31996-08-08 19:05:09 +000016#
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000017# 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 Rossumfb842551997-08-06 23:42:07 +000023# -bhalt:[Number] -bhalt:4
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000024# -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 Rossumb4ae6a31996-08-08 19:05:09 +000047# about the commands executed in the script.
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000048#
Guido van Rossumb4ae6a31996-08-08 19:05:09 +000049#
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000050# 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 Rossuma93b5041996-08-08 19:06:31 +000056# -- 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 Rossumb4ae6a31996-08-08 19:05:09 +000060# -- 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 Rossuma1b1cdb1996-10-21 15:10:39 +000067usage="Usage: ld_so_aix [CC command] [ld arguments]"
68if test ! -n "$*"; then
69 echo $usage; exit 2
70fi
Guido van Rossuma93b5041996-08-08 19:06:31 +000071
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000072# Check for existence of compiler.
73CC=$1; shift
74whichcc=`which $CC`
75
76if test ! -x "$whichcc"; then
77 echo "ld_so_aix: Compiler '$CC' not found; exiting."
78 exit 2
79fi
80
81if test ! -n "$*"; then
82 echo $usage; exit 2
83fi
84
85# Default import file for Python
86# Can be overriden by providing a -bI: argument.
87impfile="./python.exp"
88
89# Parse arguments
90while test -n "$1"
91do
92 case "$1" in
93 -e | -Wl,-e)
94 if test -z "$2"; then
95 echo "ld_so_aix: The -e flag needs a parameter; exiting."; exit 2
96 else
97 shift; entry=$1
98 fi
99 ;;
100 -e* | -Wl,-e*)
101 entry=`echo $1 | sed -e "s/-Wl,//" -e "s/-e//"`
102 ;;
103 -o)
104 if test -z "$2"; then
105 echo "ld_so_aix: The -o flag needs a parameter; exiting."; exit 2
106 else
107 shift; objfile=$1
108 fi
109 ;;
110 -o*)
111 objfile=`echo $1 | sed "s/-o//"`
112 ;;
113 -bI:* | -Wl,-bI:*)
114 impfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bI://"`
115 ;;
116 -bE:* | -Wl,-bE:*)
117 expfile=`echo $1 | sed -e "s/-Wl,//" -e "s/-bE://"`
118 ;;
119 *.o | *.a)
120 objs="$objs $1"
121 args="$args $1"
122 ;;
123 -bM:* | -Wl,-bM:* | -H* | -Wl,-H* | -T* | -Wl,-T* | -lm)
124 ;;
125 *)
126 args="$args $1"
127 ;;
128 esac
129 shift
130done
131
132
133if test -z "$objs"; then
134 echo "ld_so_aix: No input files; exiting."
135 exit 2
136elif test ! -r "$impfile"; then
137 echo "ld_so_aix: Import file '$impfile' not found or not readable; exiting."
138 exit 2
139fi
140
141# If -o wasn't specified, assume "-o shr.o"
142if test -z "$objfile"; then
143 objfile=shr.o
144fi
145
146filename=`basename $objfile | sed "s/\.[^.]*$//"`
147
148# If -bE: wasn't specified, assume "-bE:$filename.exp"
149if test -z "$expfile"; then
150 expfile="$filename.exp"
151fi
152
153# Default entry symbol for Python modules = init[modulename]
154# Can be overriden by providing a -e argument.
155if test -z "$entry"; then
156 entry=init`echo $filename | sed "s/module.*//"`
157fi
158
Guido van Rossumfb842551997-08-06 23:42:07 +0000159#echo "ld_so_aix: Debug info section"
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000160#echo " -> output file : $objfile"
161#echo " -> import file : $impfile"
162#echo " -> export file : $expfile"
163#echo " -> entry point : $entry"
164#echo " -> object files: $objs"
165#echo " -> CC arguments: $args"
Guido van Rossuma93b5041996-08-08 19:06:31 +0000166
Guido van Rossumfb842551997-08-06 23:42:07 +0000167CCOPT="-Wl,-e$entry -Wl,-bE:$expfile -Wl,-bI:$impfile -Wl,-bhalt:4"
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000168CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -lm -o $objfile"
169CCARGS="$args"
Guido van Rossumb4ae6a31996-08-08 19:05:09 +0000170
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000171# Export list generation.
172#echo makexp_aix $expfile "$objfile" $objs
173makexp_aix $expfile "$objfile" $objs
Guido van Rossumb4ae6a31996-08-08 19:05:09 +0000174
175# Perform the link.
Guido van Rossuma93b5041996-08-08 19:06:31 +0000176#echo $CC $CCOPT $CCARGS
177$CC $CCOPT $CCARGS
Guido van Rossumb4ae6a31996-08-08 19:05:09 +0000178
179# Delete the module's export list file.
180# Comment this line if you need it.
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000181rm -f $expfile