blob: b4f5996c58d1ddfa7ce5a4c99bfc90d1a076391f [file] [log] [blame]
Guido van Rossum060f24c1998-12-18 15:37:14 +00001#! /bin/sh
2#
3# Fake "ar" to build the Python shared library on BeOS. This "ar"
4# manipulates a .ar-libname file listing all the objects and regenerates
5# the shared lib every time it's called. This is probably only suitable
6# for things that get built like Python, and you'll probably have to make
7# some small modifications here and there.
8#
9# This stupid hackery is necessary due to the brain-damaged __declspec()
10# semantics on x86; on PowerPC, we could just build a static library
11# and turn that into a shared library using an exports list. On x86, you'd
12# need to use a fake table of pointers to every symbol you wanted to
13# export, otherwise you'd end up with an empty shared lib. This is
14# progress?
15#
16# Called via:
17#
18# ar-fake cr lib-name objects
19# ar-fake d lib-name objects
20#
21# This fake "ar" DOES NOT support any other POSIX "ar" commands! DO NOT
22# expect it to behave very intelligently, it's designed to build Python,
23# not any old shared lib.
24
25AR_COMMAND=$1 ; shift
26AR_LIB=$1 ; shift
27AR_LIB_NAME=$(basename $AR_LIB)
28AR_SO_LIB_NAME=${AR_LIB_NAME/.a/.so}
29AR_LIB_PATH=${AR_LIB/$AR_LIB_NAME/}
30if [ "$AR_LIB_PATH" = "" ] ; then
31 AR_LIB_PATH="."
32fi
33AR_CRUD=${AR_LIB_PATH}/.ar-${AR_LIB_NAME}
34
35AR_CWD=$(pwd)
36
37# Function to tell is if the arg is an absolute path. Use it like this:
38#
39# if is_abs pathname ; then ...
40is_abs() {
41 if [ "$1" != "$(echo $1 | sed -e "s,^/,,")" ] ; then
42 return 0
43 fi
44 return 1
45}
46
47# Function to build the shared library. It does the right thing for
48# PowerPC or x86 systems running BeOS.
49build_lib() {
50 LIB=$1 ; shift
Guido van Rossume89d4501999-01-04 16:49:09 +000051 SO_LIB=${LIB/.a/.so}
Guido van Rossum060f24c1998-12-18 15:37:14 +000052 SO_NAME=$1 ; shift
53 CRUD_NAME=$1 ; shift
54
55 # maybe too much...
56 EXTRA_LIBS="-lroot -lbe -lnet"
57
58 case $BE_HOST_CPU in
59 ppc)
Guido van Rossum6b9da451999-03-24 17:48:12 +000060 case $(uname -r) in
61 4.0*) AR_CC="mwcc -xms -export pragma -nodup" ;;
62 *) AR_CC="mwcc -shared -export pragma -nodup" ;;
63 esac
Guido van Rossum060f24c1998-12-18 15:37:14 +000064 GLUE_LOC=/boot/develop/lib/ppc
65 AR_GLUE="${GLUE_LOC}/glue-noinit.a ${GLUE_LOC}/init_term_dyn.o ${GLUE_LOC}/start_dyn.o"
66 ;;
67
68 x86)
69 AR_CC="gcc -nostart -Wl,-soname=${SO_NAME}"
70 AR_GLUE=
71 ;;
72
73 *)
74 # Send me the mystery system (soo-pah aitch!), then we'll talk...
75 echo "No, no, no... $0 doesn't support $BE_HOST_CPU"
76 exit 2
77 ;;
78 esac
79
80 # Build a list of the objects...
81 PARTS=""
82 while read OBJ_FILE OBJ_PATH ; do
83 PARTS="$PARTS ${OBJ_PATH}${OBJ_FILE}"
84 done < $CRUD_NAME
85
Guido van Rossume89d4501999-01-04 16:49:09 +000086 $AR_CC -o $SO_LIB $PARTS $AR_GLUE $EXTRA_LIBS > /dev/null 2>&1
Guido van Rossum060f24c1998-12-18 15:37:14 +000087
88 return 0
89}
90
91# Make a backup of the old AR_CRUD file, just to be nice, and clean up
92# any of our temp files that may be laying around.
93if [ -e $AR_CRUD ] ; then
94 mv -f $AR_CRUD ${AR_CRUD}.old
95 cp ${AR_CRUD}.old $AR_CRUD
96else
97 touch $AR_CRUD
98fi
99
100if [ -e ${AR_CRUD}.grepper ] ; then
101 rm -f ${AR_CRUD}.grepper
102fi
103
104case $AR_COMMAND in
105 cr)
106 # Add the extra bits to the $AR_CRUD file.
107 for OBJECT in "$@" ; do
108 OBJ_NAME=$(basename $OBJECT)
109 OBJ_PATH=${OBJECT%$OBJ_NAME}
110 if ! is_abs $OBJ_PATH ; then
111 OBJ_PATH=${AR_CWD}/${OBJECT}
112 OBJ_PATH=${OBJ_PATH%$OBJ_NAME}
113 fi
114
115 # If this is already in there, we have to blow it away so
116 # we can replace it with the new one.
117 if egrep -q "^$OBJ_NAME " $AR_CRUD ; then
118 egrep -v "^$OBJ_NAME " < $AR_CRUD > ${AR_CRUD}.grepper
119 mv -f ${AR_CRUD}.grepper $AR_CRUD
120 fi
121
122 echo $OBJ_NAME $OBJ_PATH >> $AR_CRUD
123 done
124
125 # Now build a library from the files.
126 build_lib $AR_LIB $AR_SO_LIB_NAME $AR_CRUD
127 ;;
128
129 d)
130 # Remove files from the $AR_CRUD file. This isn't terribly
131 # efficient.
132 for OBJECT in "$@" ; do
133 OBJ_NAME=$(basename $OBJECT)
134 OBJ_PATH=${OBJECT%$OBJ_NAME}
135 if ! is_abs $OBJ_PATH ; then
136 OBJ_PATH=${AR_CWD}/${OBJECT}
137 OBJ_PATH=${OBJ_PATH%$OBJ_NAME}
138 fi
139
140 # Strip the objects from the list, if they're in there.
141 egrep -v "^$OBJ_NAME " < $AR_CRUD > ${AR_CRUD}.grepper
142 mv -f ${AR_CRUD}.grepper $AR_CRUD
143 done
144
145 # Now build a library from the remaining objects.
146 build_lib $AR_LIB $AR_SO_LIB_NAME $AR_CRUD
147 ;;
148
149 *)
150 echo "$0 error:"
151 echo " Unsupported command: $AR_COMMAND"
152 exit 1
153 ;;
154esac
155
156# If we make it here, all went well. Hopefully.
157exit 0