18b30338255fca86400af3e261e79fc89f2f5ef6~suv#!/bin/sh
18b30338255fca86400af3e261e79fc89f2f5ef6~suvCOMPILER='@@@'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvSUFFIX='---'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvPREFIX='&&&'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvOUTPUT_O='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvOUTPUT=''
18b30338255fca86400af3e261e79fc89f2f5ef6~suvNAMED_OUTPUT=''
18b30338255fca86400af3e261e79fc89f2f5ef6~suvLASTFILE=''
18b30338255fca86400af3e261e79fc89f2f5ef6~suvINTEL='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvSIZE32='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvSIZE64='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suvNEWARGS=''
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvSKIP='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvfor arg in $@
18b30338255fca86400af3e261e79fc89f2f5ef6~suvdo
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $SKIP = 'ARCH' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # intercept -arch option and set SIZEXX
18b30338255fca86400af3e261e79fc89f2f5ef6~suv SKIP='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $arg = 'x86_64' ] || [ $arg = 'ppc64' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv SIZE64='YES'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv SIZE32='YES'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # which architecture are we compiling for?
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $arg = 'x86_64' ] || [ $arg = 'i386' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv INTEL='YES'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv elif [ $arg = '-arch' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv SKIP='ARCH'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv elif [ $arg = '--version' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv ${COMPILER} --version
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 0
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv NEWARGS+="$arg "
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # if the -c option is given, the output is .o
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $arg = '-c' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv OUTPUT_O='YES'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # if the output file is given by a -o option, record it
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $SKIP = 'O' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv SKIP='NO'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv NAMED_OUTPUT=$arg
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $arg = '-o' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv SKIP='O'
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # Note each file ending by ${SUFFIX} and remember the last one
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # Transform them in .o
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if `echo $arg | grep -q "${SUFFIX}$"`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv LASTFILE=$arg
18b30338255fca86400af3e261e79fc89f2f5ef6~suv OUTPUT+=`echo $arg | sed "s/${SUFFIX}/\.o/"`
18b30338255fca86400af3e261e79fc89f2f5ef6~suv OUTPUT+=' '
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suvdone
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv# What is the output?
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvif [ ${NAMED_OUTPUT}"X" != "X" ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv OUTPUT=$NAMED_OUTPUT
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvelif [ $OUTPUT_O = 'NO' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # It is an executable whose is name is the LASTFILE without suffix
18b30338255fca86400af3e261e79fc89f2f5ef6~suv OUTPUT=`echo ${LASTFILE} | sed "s/${SUFFIX}//"`
18b30338255fca86400af3e261e79fc89f2f5ef6~suvfi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv# Othewise, the output is just the ${OUTPUT} variable as computed before
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv# For some reason, -dynamiclib and -lpython2.6 are missing when linking
18b30338255fca86400af3e261e79fc89f2f5ef6~suv# .so files. Add them, except if -bundle is set (incompatible switches)
18b30338255fca86400af3e261e79fc89f2f5ef6~suvif [ `echo $OUTPUT | sed -E 's|.*\.||'` = "so" ] && \
18b30338255fca86400af3e261e79fc89f2f5ef6~suv ! `echo $NEWARGS | grep -q bundle`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv NEWARGS="${NEWARGS} ${PREFIX}/lib/libpython2.6.dylib -dynamiclib"
18b30338255fca86400af3e261e79fc89f2f5ef6~suvfi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv# Now, compile
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvif [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'NO' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # No size indication given, just proceed with default
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if `${COMPILER} $NEWARGS`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 0
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 1
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvelif [ $SIZE32 = 'YES' ] && [ $SIZE64 = 'NO' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # 32-bit
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if `${COMPILER} -m32 $NEWARGS`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 0
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 1
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvelif [ $SIZE32 = 'NO' ] && [ $SIZE64 = 'YES' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # 64-bit
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if `${COMPILER} -m64 $NEWARGS`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 0
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 1
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suvelse
18b30338255fca86400af3e261e79fc89f2f5ef6~suv # Universal case
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if `${COMPILER} -m32 $NEWARGS`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv for filename in ${OUTPUT}
18b30338255fca86400af3e261e79fc89f2f5ef6~suv do
18b30338255fca86400af3e261e79fc89f2f5ef6~suv mv ${filename} ${filename}.32
18b30338255fca86400af3e261e79fc89f2f5ef6~suv done
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if `${COMPILER} -m64 $NEWARGS`; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv for filename in ${OUTPUT}
18b30338255fca86400af3e261e79fc89f2f5ef6~suv do
18b30338255fca86400af3e261e79fc89f2f5ef6~suv mv ${filename} ${filename}.64
18b30338255fca86400af3e261e79fc89f2f5ef6~suv if [ $INTEL = 'YES' ]; then
18b30338255fca86400af3e261e79fc89f2f5ef6~suv lipo -create -arch x86_64 ${filename}.64 \
18b30338255fca86400af3e261e79fc89f2f5ef6~suv -arch i386 ${filename}.32 \
18b30338255fca86400af3e261e79fc89f2f5ef6~suv -output ${filename}
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv lipo -create -arch ppc64 ${filename}.64 \
18b30338255fca86400af3e261e79fc89f2f5ef6~suv -arch ppc ${filename}.32 \
18b30338255fca86400af3e261e79fc89f2f5ef6~suv -output ${filename}
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv
18b30338255fca86400af3e261e79fc89f2f5ef6~suv rm -f ${filename}.32 ${filename}.64
18b30338255fca86400af3e261e79fc89f2f5ef6~suv done
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 1
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suv else
18b30338255fca86400af3e261e79fc89f2f5ef6~suv exit 1
18b30338255fca86400af3e261e79fc89f2f5ef6~suv fi
18b30338255fca86400af3e261e79fc89f2f5ef6~suvfi
18b30338255fca86400af3e261e79fc89f2f5ef6~suvexit 0