#! /bin/bash
export CFLAGS='-I/usr/local/include -fPIC -g -O2'
export CXXFLAGS='-I/usr/local/include -fPIC -g -O2'
export CPPFLAGS='-I/usr/local/include -fPIC -g -O2'
export LDFLAGS=-L/usr/local/lib
#export LDFLAGS='-L/usr/X11/lib'
# export LIBS="$LIBS -framework AGL -framework OpenGL -framework ApplicationServices -framework Cocoa -isysroot /Developer/SDKs/MacOSX10.6.sdk"
#./configure --prefix=/Applications/usr
make -j2
cd src
sh mklocal
make
sh mkxlocal
make install
rm -rf /Applications/usr/bin/xcas.app
cp -f xcas /Applications/usr/bin/
rm -f /Applications/usr/lib/libgiac.a
#cp -f icas /Applications/usr/bin
#cd ~/64/newgiac/src
sh mkdylib10
cp .libs/libgiac.0.dylib /Applications/usr/lib
cp .libs/libgiac.la /Applications/usr/lib
sh mkdyn10
cp icas /Applications/usr/bin
#sh mkxdyn10
#cp xcas /Applications/usr/bin/xcasdyn
install_name_tool -change "/usr/local/lib/libpari.dylib" "/Applications/usr/local/lib/libpari.dylib" /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/lib/libgsl.0.dylib" "/Applications/usr/64/local/lib/libgsl.0.dylib" /Applications/usr/64/local/lib/libgsl.0.dylib
install_name_tool -change "/usr/local/lib/libgsl.0.dylib" "/Applications/usr/64/local/lib/libgsl.0.dylib" /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/lib/libgslcblas.0.dylib" "/Applications/usr/64/local/lib/libgslcblas.0.dylib" /Applications/usr/64/local/lib/libgslcblas.0.dylib
install_name_tool -change "/usr/local/lib/libgslcblas.0.dylib" "/Applications/usr/64/local/lib/libgslcblas.0.dylib" /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/opt/gettext/lib/libintl.8.dylib" "/Applications/usr/64/local/lib/libintl.8.dylib" /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/lib/libmpfr.4.dylib" "/Applications/usr/64/local/lib/libmpfr.4.dylib" /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/lib/libgmp.10.dylib" "/Applications/usr/64/local/lib/libgmp.10.dylib" /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/lib/libmpfi.0.dylib" "/Applications/usr/64/local/lib/libmpfi.0.dylib"  /Applications/usr/lib/libgiac.0.dylib
install_name_tool -change "/usr/local/lib/libgmp.10.dylib" "/Applications/usr/64/local/lib/libgmp.10.dylib"  /Applications/usr/64/local/lib/libmpfr.4.dylib
install_name_tool -change "/usr/local/lib/libgmp.10.dylib" "/Applications/usr/64/local/lib/libgmp.10.dylib"  /Applications/usr/64/local/lib/libmpfi.0.dylib
install_name_tool -change "/usr/local/lib/libmpfr.4.dylib" "/Applications/usr/64/local/lib/libmpfr.4.dylib"  /Applications/usr/64/local/lib/libmpfi.0.dylib
install_name_tool -change "/usr/local/opt/libusb/lib/libusb-1.0.0.dylib" "/Applications/usr/64/local/lib/libusb-1.0.0.dylib" /Applications/usr/bin/dfu-util
#cd ~/64/newgiac/giacpy-nox-0.4.4
#sh mkgiacpy
cd /Applications/usr/bin
fltk-config --post xcas
install_name_tool -change "/usr/local/lib/libao.4.dylib" "/Applications/usr/64/local/lib/libao.4.dylib"  /Applications/usr/bin/xcas.app/Contents/MacOS/xcas
install_name_tool -change "/usr/local/opt/jpeg/lib/libjpeg.9.dylib" "/Applications/usr/64/local/lib/libjpeg.9.dylib"  /Applications/usr/bin/xcas.app/Contents/MacOS/xcas
install_name_tool -change "/usr/local/lib/libpng16.16.dylib" "/Applications/usr/64/local/lib/libpng16.16.dylib"  /Applications/usr/bin/xcas.app/Contents/MacOS/xcas
install_name_tool -change "/usr/local/opt/libpng/lib/libpng16.16.dylib" "/Applications/usr/64/local/lib/libpng16.16.dylib"  /Applications/usr/bin/xcas.app/Contents/MacOS/xcas

install_name_tool -change "/usr/local/lib/libao.4.dylib" "/Applications/usr/64/local/lib/libao.4.dylib"  /Applications/usr/bin/icas
install_name_tool -change "/usr/local/opt/jpeg/lib/libjpeg.9.dylib" "/Applications/usr/64/local/lib/libjpeg.9.dylib"  /Applications/usr/bin/icas
install_name_tool -change "/usr/local/lib/libpng16.16.dylib" "/Applications/usr/64/local/lib/libpng16.16.dylib"  /Applications/usr/bin/icas
install_name_tool -change "/usr/local/opt/libpng/lib/libpng16.16.dylib" "/Applications/usr/64/local/lib/libpng16.16.dylib"  /Applications/usr/bin/icas
open ~/Desktop/xcas.pmdoc
