#!/bin/sh

#       Building on Mac OSX.  Note: only compiles in OGG and MP3
#       support if the libraries are already setup within libs/,
#       otherwise omits them.  To get an idea of how to build the
#       libraries, see the 'mk-libmad-linux' and 'mk-tremor-linux'
#       scripts.  The only difference is that on Mac OSX the
#       'authgen.sh' line doesn't work, and you have to run
#       './configure' instead.  Also it might be necessary to run
#       'ranlib' on the resulting .a files.

CFLAGS="-m32 -mmacosx-version-min=10.4 -DT_MACOSX"
CFLAGS="$CFLAGS -I/System/Library/Frameworks/Carbon.framework/Headers -fpascal-strings"
LIBS="-framework Carbon -framework CoreAudio"

xx=libs/macosx-intel32-libmad.a
[ -f $xx ] && {
    CFLAGS="-DMP3_DECODE $CFLAGS"
    LIBS="$LIBS $xx"
    ranlib $xx	# OSX is fussy if you copy .a files and insists you run 'ranlib' on them
}

xx=libs/macosx-intel32-libvorbisidec.a
[ -f $xx ] && {
    CFLAGS="-DOGG_DECODE $CFLAGS"
    LIBS="$LIBS $xx"
    ranlib $xx	# OSX is fussy if you copy .a files and insists you run 'ranlib' on them
}

CC="cc $CFLAGS -Wall -O3 $LIBS -lm -lpthread"

$CC sbagen.c -o sbagen || exit 1
strip sbagen || exit 1
