#!/bin/sh
CFLAGS="-Wno-four-char-constants -arch ppc"
PREPROCESS="cc -traditional-cpp -dD -E"
GEN="ffigen -Wno-four-char-constants"

PREPROCESSOBJC="-Wp,-lang-objc"
GENOBJC="-fobjc"

while [ $# -gt 1 ]
do 
    case ${1} in
      +no-objc)
        GENOBJC=""
        PREPROCESSOBJC=""
      ;;
      *)
        CFLAGS="${CFLAGS} ${1}"
      ;;
    esac
    shift
done

CFLAGS="${CFLAGS} ${PREPROCESSOBJC}"
GEN="${GEN} ${GENOBJC}"


echo +++ ${1}
mkdir -p .`dirname ${1}`
OFILE=.`dirname ${1}`/`basename ${1} .h`.ffi
IFILE=.`dirname ${1}`/`basename ${1} .h`.i

((${PREPROCESS} ${CFLAGS}  ${1} -o ${IFILE}) && (${GEN} < ${IFILE} > ${OFILE})) || rm -f ${OFILE}
rm -f ${IFILE}



