blob: 687a9b5ff579ccaa2cddd470aaf545925266c1c2 [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)
60 AR_CC="mwcc -xms -export pragma -nodup"
61 GLUE_LOC=/boot/develop/lib/ppc
62 AR_GLUE="${GLUE_LOC}/glue-noinit.a ${GLUE_LOC}/init_term_dyn.o ${GLUE_LOC}/start_dyn.o"
63 ;;
64
65 x86)
66 AR_CC="gcc -nostart -Wl,-soname=${SO_NAME}"
67 AR_GLUE=
68 ;;
69
70 *)
71 # Send me the mystery system (soo-pah aitch!), then we'll talk...
72 echo "No, no, no... $0 doesn't support $BE_HOST_CPU"
73 exit 2
74 ;;
75 esac
76
77 # Build a list of the objects...
78 PARTS=""
79 while read OBJ_FILE OBJ_PATH ; do
80 PARTS="$PARTS ${OBJ_PATH}${OBJ_FILE}"
81 done < $CRUD_NAME
82
Guido van Rossume89d4501999-01-04 16:49:09 +000083 $AR_CC -o $SO_LIB $PARTS $AR_GLUE $EXTRA_LIBS > /dev/null 2>&1
Guido van Rossum060f24c1998-12-18 15:37:14 +000084
85 return 0
86}
87
88# Make a backup of the old AR_CRUD file, just to be nice, and clean up
89# any of our temp files that may be laying around.
90if [ -e $AR_CRUD ] ; then
91 mv -f $AR_CRUD ${AR_CRUD}.old
92 cp ${AR_CRUD}.old $AR_CRUD
93else
94 touch $AR_CRUD
95fi
96
97if [ -e ${AR_CRUD}.grepper ] ; then
98 rm -f ${AR_CRUD}.grepper
99fi
100
101case $AR_COMMAND in
102 cr)
103 # Add the extra bits to the $AR_CRUD file.
104 for OBJECT in "$@" ; do
105 OBJ_NAME=$(basename $OBJECT)
106 OBJ_PATH=${OBJECT%$OBJ_NAME}
107 if ! is_abs $OBJ_PATH ; then
108 OBJ_PATH=${AR_CWD}/${OBJECT}
109 OBJ_PATH=${OBJ_PATH%$OBJ_NAME}
110 fi
111
112 # If this is already in there, we have to blow it away so
113 # we can replace it with the new one.
114 if egrep -q "^$OBJ_NAME " $AR_CRUD ; then
115 egrep -v "^$OBJ_NAME " < $AR_CRUD > ${AR_CRUD}.grepper
116 mv -f ${AR_CRUD}.grepper $AR_CRUD
117 fi
118
119 echo $OBJ_NAME $OBJ_PATH >> $AR_CRUD
120 done
121
122 # Now build a library from the files.
123 build_lib $AR_LIB $AR_SO_LIB_NAME $AR_CRUD
124 ;;
125
126 d)
127 # Remove files from the $AR_CRUD file. This isn't terribly
128 # efficient.
129 for OBJECT in "$@" ; do
130 OBJ_NAME=$(basename $OBJECT)
131 OBJ_PATH=${OBJECT%$OBJ_NAME}
132 if ! is_abs $OBJ_PATH ; then
133 OBJ_PATH=${AR_CWD}/${OBJECT}
134 OBJ_PATH=${OBJ_PATH%$OBJ_NAME}
135 fi
136
137 # Strip the objects from the list, if they're in there.
138 egrep -v "^$OBJ_NAME " < $AR_CRUD > ${AR_CRUD}.grepper
139 mv -f ${AR_CRUD}.grepper $AR_CRUD
140 done
141
142 # Now build a library from the remaining objects.
143 build_lib $AR_LIB $AR_SO_LIB_NAME $AR_CRUD
144 ;;
145
146 *)
147 echo "$0 error:"
148 echo " Unsupported command: $AR_COMMAND"
149 exit 1
150 ;;
151esac
152
153# If we make it here, all went well. Hopefully.
154exit 0