#!/bin/bash

package=ImageMagick
#version=-6.9.5-4
version=-6.9.10-33

progname=$0

source ../cascade-make/lib/cascade-lib.bash GEXTIMAGEMAGICK ../.. $*

prefix=$GEXTIMAGEMAGICK_INSTALLED

export CFLAGS="$CFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
export CPPFLAGS="$CPPFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
export CXXFLAGS="$CXXFLAGS -I$GEXTIMAGEMAGICK_INSTALLED/include"
# We need to add libz to LDFLAGS to get the configure test for libtiff to succeed
# (only found to be necessary on an uncooperative mac)
export LDFLAGS="$LDFLAGS -L$GEXTIMAGEMAGICK_INSTALLED/lib -lz"
export LD_LIBRARY_PATH="$GEXTIMAGEMAGICK_INSTALLED/lib"

# If on darwin, check if clang exists. If so, use that as CC, in place of gcc
# use command -v instead of which to check if a program exists. 
# http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script
if [ "x$GSDLOS" = "xdarwin" ] ; then
    if command -v clang > /dev/null 2>&1; then
	echo "Found clang compiler. Switching CC to clang"
	CROSSCONFIGURE_VARS="CC=clang"
    fi
fi

# it's going to generate the ghostscript binary not ghostscript library
# so --without-gslib
opt_run_untar $force_untar $auto_untar $package $version
opt_run_configure $force_config $auto_config $package $version $prefix --without-gslib --disable-shared 

opt_run_make $compile $package $version
opt_run_make $install $package $version "install"
opt_run_make $clean $package $version "clean"
opt_run_make $distclean $package $version "distclean"

opt_run_tarclean $tarclean $package $version
