# this script will invoke configure with the right set of parameters on macosx
# you need to properly set ARCH, PREFIX and DEVTOOLS before invoking the script


#---------------------------------------------------------------------------------------------------
# main parameters

#you need to set PREFIX to the root of the development tree (*/usr)
#you need to set DEVTOOLS to the root of the development tools (usually /Developer)

ARCH=i386
PREFIX=/Users/mgubi/t/e/i386-darwin10.4/usr
DEVTOOLS=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer


PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/

SDK=/Users/mgubi/t/SDKs/MacOSX10.6.sdk 
#SDK=$DEVTOOLS/SDKs/MacOSX10.9.sdk 

#---------------------------------------------------------------------------------------------------
# setup target architecure

case $ARCH in
 i386) 
 ;;
 x86_64) 
 ;;
 ppc) 
 ;;
 *)
  export ARCH=`arch` 
esac

TARGET_i386=i686-apple-darwin10
TARGET_x86_64=x86_64-apple-darwin10
TARGET_ppc=powerpc-apple-darwin10

TARGET_ARCH=TARGET_${ARCH}


# the TeXmacs configure script do not know how to use info from pkg-config
# so we override its behaviour to take into account this

#---------------------------------------------------------------------------------------------------
# Guile configuration

#---------------------------------------------------------------------------------------------------
# Freetype configuration

#---------------------------------------------------------------------------------------------------
# Qt configuration

# in general we cannot run qmake to obtain appopriate Qt build settings
# this is because maybe we are crossbuiling (e.g. the PPC version on i386 architecture)
# ideally we need to have a mkspec for this situation...

#---------------------------------------------------------------------------------------------------
# Let gos

#printenv


export PATH=$DEVTOOLS/usr/bin:$PREFIX/bin:$PATH
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig/
  ./configure \
  --host=${!TARGET_ARCH} \
  --enable-macosx-extensions\
  --enable-qt --enable-QtPlugins=imageformats \
  CC="gcc -arch $ARCH  -mmacosx-version-min=10.5 -isysroot $SDK  -I$SDK/usr/include/c++/4.2.1/i686-apple-darwin10" \
  CXX="g++ -arch $ARCH  -mmacosx-version-min=10.5 -isysroot $SDK -I$SDK/usr/include/c++/4.2.1/i686-apple-darwin10" \
  OBJC="clang -arch $ARCH  -mmacosx-version-min=10.5 -isysroot $SDK  -I$SDK/usr/include/c++/4.2.1/i686-apple-darwin10" \
  OBJCXX="clang++ -arch $ARCH  -mmacosx-version-min=10.5 -isysroot $SDK -I$SDK/usr/include/c++/4.2.1/i686-apple-darwin10" \
  CPP="gcc -arch $ARCH  -mmacosx-version-min=10.5 -isysroot $SDK -E" \
  CPPCXX="g++ -arch $ARCH  -mmacosx-version-min=10.5 -isysroot $SDK -E" \
  CPPFLAGS="-I$PREFIX/include" CFLAGS="-I$PREFIX/include" CXXFLAGS="-I$PREFIX/include" \
  LDFLAGS="-Wl,-search_paths_first -Wl,-syslibroot $SDK -L$PREFIX/lib" \
  GUILE_BIN=guile \
  GUILE_CFLAGS="`pkg-config --static --cflags guile-1.8`" \
  GUILE_LDFLAGS="`pkg-config --static --libs guile-1.8`" \
  GUILE_DATA_PATH="`pkg-config --variable=datadir guile-1.8`" \
  GUILE_VERSION="`pkg-config --modversion guile-1.8`" \
  FREETYPE_CFLAGS="`pkg-config --static --cflags freetype2`" \
  FREETYPE_LDFLAGS="`pkg-config --static --libs freetype2`" \
  QT_FRAMEWORKS_PATH="$PREFIX/lib" \
  QT_PLUGINS_PATH="$PREFIX/plugins" \
  QT_CPPFLAGS="-DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I$PREFIX/mkspecs/macx-g++ -I$PREFIX/lib/QtCore.framework/Versions/4/Headers -I$PREFIX/include/QtCore -I$PREFIX/lib/QtGui.framework/Versions/4/Headers -I$PREFIX/include/QtGui -I$PREFIX/include -F$PREFIX/lib" \
  QT_LDFLAGS="-Wl,-F$PREFIX/lib -L$PREFIX/lib -framework QtCore -framework QtGui "\
  QMAKE="$PREFIX/bin/qmake"\
  MOC="$PREFIX/bin/moc"\
  UIC="$PREFIX/bin/uic"


