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
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.
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
33 AR_CRUD
=${AR_LIB_PATH}/.ar-
${AR_LIB_NAME}
37 # Function to tell is if the arg is an absolute path. Use it like this:
39 # if is_abs pathname ; then ...
41 if [ "$1" != "$(echo $1 | sed -e "s
,^
/,,")" ] ; then
47 # Function to build the shared library. It does the right thing for
48 # PowerPC or x86 systems running BeOS.
56 EXTRA_LIBS
="-lroot -lbe -lnet"
61 4.0*) AR_CC
="mwcc -xms -export pragma -nodup" ;;
62 *) AR_CC
="mwcc -shared -export pragma -nodup" ;;
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"
69 AR_CC
="gcc -nostart -Wl,-soname=${SO_NAME}"
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"
80 # Build a list of the objects...
82 while read OBJ_FILE OBJ_PATH
; do
83 PARTS
="$PARTS ${OBJ_PATH}${OBJ_FILE}"
86 $AR_CC -o $SO_LIB $PARTS $AR_GLUE $EXTRA_LIBS > /dev
/null
2>&1
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
100 if [ -e ${AR_CRUD}.grepper
] ; then
101 rm -f ${AR_CRUD}.grepper
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
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
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
145 # Now build a library from the remaining objects.
146 build_lib
$AR_LIB $AR_SO_LIB_NAME $AR_CRUD
151 echo " Unsupported command: $AR_COMMAND"
156 # If we make it here, all went well. Hopefully.