blob: 57fbdeb493db572a4e715e271db024daa6f932ba [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
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
Guido van Rossumb4ae6a31996-08-08 19:05:09 +000046# about the commands executed in the script.
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000047#
Guido van Rossumb4ae6a31996-08-08 19:05:09 +000048#
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000049# 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 --
Guido van Rossuma93b5041996-08-08 19:06:31 +000055# -- args by leaving CC to invoke "ld". --
56# Vladimir Marangozov
57#
58# Jul-1-1996 -- Make sure to use /usr/ccs/bin/ld --
Guido van Rossumb4ae6a31996-08-08 19:05:09 +000059# -- 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
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000066usage="Usage: ld_so_aix [CC command] [ld arguments]"
67if test ! -n "$*"; then
68 echo $usage; exit 2
69fi
Guido van Rossuma93b5041996-08-08 19:06:31 +000070
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +000071# Check for existence of compiler.
72CC=$1; shift
73whichcc=`which $CC`
74
75if test ! -x "$whichcc"; then
76 echo "ld_so_aix: Compiler '$CC' not found; exiting."
77 exit 2
78fi
79
80if test ! -n "$*"; then
81 echo $usage; exit 2
82fi
83
84# Default import file for Python
85# Can be overriden by providing a -bI: argument.
86impfile="./python.exp"
87
88# Parse arguments
89while test -n "$1"
90do
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
129done
130
131
132if test -z "$objs"; then
133 echo "ld_so_aix: No input files; exiting."
134 exit 2
135elif test ! -r "$impfile"; then
136 echo "ld_so_aix: Import file '$impfile' not found or not readable; exiting."
137 exit 2
138fi
139
140# If -o wasn't specified, assume "-o shr.o"
141if test -z "$objfile"; then
142 objfile=shr.o
143fi
144
145filename=`basename $objfile | sed "s/\.[^.]*$//"`
146
147# If -bE: wasn't specified, assume "-bE:$filename.exp"
148if test -z "$expfile"; then
149 expfile="$filename.exp"
150fi
151
152# Default entry symbol for Python modules = init[modulename]
153# Can be overriden by providing a -e argument.
154if test -z "$entry"; then
155 entry=init`echo $filename | sed "s/module.*//"`
156fi
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"
Guido van Rossuma93b5041996-08-08 19:06:31 +0000165
166CCOPT="-Wl,-e$entry -Wl,-bE:$expfile -Wl,-bI:$impfile"
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000167CCOPT="$CCOPT -Wl,-bM:SRE -Wl,-T512 -Wl,-H512 -lm -o $objfile"
168CCARGS="$args"
Guido van Rossumb4ae6a31996-08-08 19:05:09 +0000169
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000170# Export list generation.
171#echo makexp_aix $expfile "$objfile" $objs
172makexp_aix $expfile "$objfile" $objs
Guido van Rossumb4ae6a31996-08-08 19:05:09 +0000173
174# Perform the link.
Guido van Rossuma93b5041996-08-08 19:06:31 +0000175#echo $CC $CCOPT $CCARGS
176$CC $CCOPT $CCARGS
Guido van Rossumb4ae6a31996-08-08 19:05:09 +0000177
178# Delete the module's export list file.
179# Comment this line if you need it.
Guido van Rossuma1b1cdb1996-10-21 15:10:39 +0000180rm -f $expfile