Added all documentation.
[python/dscho.git] / BeOS / ar-fake
blobb4f5996c58d1ddfa7ce5a4c99bfc90d1a076391f
1 #! /bin/sh
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.
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?
16 # Called via:
18 # ar-fake cr lib-name objects
19 # ar-fake d lib-name objects
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.
25 AR_COMMAND=$1 ; shift
26 AR_LIB=$1 ; shift
27 AR_LIB_NAME=$(basename $AR_LIB)
28 AR_SO_LIB_NAME=${AR_LIB_NAME/.a/.so}
29 AR_LIB_PATH=${AR_LIB/$AR_LIB_NAME/}
30 if [ "$AR_LIB_PATH" = "" ] ; then
31 AR_LIB_PATH="."
33 AR_CRUD=${AR_LIB_PATH}/.ar-${AR_LIB_NAME}
35 AR_CWD=$(pwd)
37 # Function to tell is if the arg is an absolute path. Use it like this:
39 # if is_abs pathname ; then ...
40 is_abs() {
41 if [ "$1" != "$(echo $1 | sed -e "s,^/,,")" ] ; then
42 return 0
44 return 1
47 # Function to build the shared library. It does the right thing for
48 # PowerPC or x86 systems running BeOS.
49 build_lib() {
50 LIB=$1 ; shift
51 SO_LIB=${LIB/.a/.so}
52 SO_NAME=$1 ; shift
53 CRUD_NAME=$1 ; shift
55 # maybe too much...
56 EXTRA_LIBS="-lroot -lbe -lnet"
58 case $BE_HOST_CPU in
59 ppc)
60 case $(uname -r) in
61 4.0*) AR_CC="mwcc -xms -export pragma -nodup" ;;
62 *) AR_CC="mwcc -shared -export pragma -nodup" ;;
63 esac
64 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"
68 x86)
69 AR_CC="gcc -nostart -Wl,-soname=${SO_NAME}"
70 AR_GLUE=
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
78 esac
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
86 $AR_CC -o $SO_LIB $PARTS $AR_GLUE $EXTRA_LIBS > /dev/null 2>&1
88 return 0
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.
93 if [ -e $AR_CRUD ] ; then
94 mv -f $AR_CRUD ${AR_CRUD}.old
95 cp ${AR_CRUD}.old $AR_CRUD
96 else
97 touch $AR_CRUD
100 if [ -e ${AR_CRUD}.grepper ] ; then
101 rm -f ${AR_CRUD}.grepper
104 case $AR_COMMAND in
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}
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
122 echo $OBJ_NAME $OBJ_PATH >> $AR_CRUD
123 done
125 # Now build a library from the files.
126 build_lib $AR_LIB $AR_SO_LIB_NAME $AR_CRUD
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}
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
145 # Now build a library from the remaining objects.
146 build_lib $AR_LIB $AR_SO_LIB_NAME $AR_CRUD
150 echo "$0 error:"
151 echo " Unsupported command: $AR_COMMAND"
152 exit 1
154 esac
156 # If we make it here, all went well. Hopefully.
157 exit 0