#!/bin/sh

TARGET=icc_examin
TARGET_NAME="ICC Examin"
BINTARGET="`echo $TARGET | sed s/_//g`"
ERROR=0
test -f error.tmp && rm error.tmp
test -f config.sh && rm config.sh

CONF_H=config.h
CONF=makefile
CONF_I18N=fl_i18n/makefile
SPEC=$TARGET.spec
VERS="$TARGET"_version.h
zeile="$0 $@"
MAKEFILE_DIR=". fl_i18n"; export MAKEFILE_DIR

export CONF_H CONF CONF_I18N

VERSION_A=0
VERSION_B=4
VERSION_C=5
RELEASE=0
ZEIT="May 2004 - September 2007"
VERSION=$VERSION_A.$VERSION_B$VERSION_C
if [ $VERSION_A -gt 9 ]; then
  VERSION_L="$VERSION_A"
else
  VERSION_L="0$VERSION_A"
fi
if [ $VERSION_B -gt 9 ]; then
  VERSION_L="$VERSION_L$VERSION_B"
else
  VERSION_L="${VERSION_L}0$VERSION_B"
fi
if [ $VERSION_C -gt 9 ]; then
  VERSION_L="$VERSION_L$VERSION_C"
else
  VERSION_L="${VERSION_L}0$VERSION_C"
fi
VERSION_L=`echo $VERSION_L | sed 's/^0*//g'`

INFOECHO="echo"

cwdebug=0
debug=0
nodeps=0

# find a suitable fltk-config script
fltkconfig="fltk-config"
old_IFS=$IFS; 
IFS=:
for i in $PATH; do
  test -x "$i/$fltkconfig" && fltkconfig_="$i/$fltkconfig"
done
if [ -z "$fltkconfig_" ]; then
  for i in $PATH; do
    test -x "$i/fltk-utf8-config" && fltkconfig_="$i/fltk-utf8-config"
  done
fi
if [ -n "$fltkconfig_" ]; then
  fltkconfig="$fltkconfig_"
fi
IFS=$old_IFS

echo ""
echo "################################################################"
echo "#                                                              #"
echo "        Welcome to $TARGET_NAME Version $VERSION configurator"
echo "#                                                              #"
echo "#                       Configuration                          #"

if [ $# -gt 0 ]; then
  prefix=""
  while [ $# -gt 0 ]; do
    arg=$1
    # prefix exec_prefix bindir sbindir libdir includedir datadir mandir
    switch=prefix
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      prefix="`echo \"$1\" | sed s/\"--$switch=\"//`"
    fi
    switch="exec-prefix"
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      exec_prefix="`echo $1 | sed s/--$switch=//`"
    fi
    switch=bindir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      bindir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=sbindir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      sbindir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=libdir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      libdir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=includedir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      includedir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=datadir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      datadir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=mandir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      mandir="`echo $1 | sed s/--$switch=//`"
    fi
    # pixmapdir desktopdir
    switch=pixmapdir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      pixmapdir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=desktopdir
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      desktopdir="`echo $1 | sed s/--$switch=//`"
    fi
    switch=with-fltk-config
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      fltkconfig="`echo $1 | sed s/--$switch=//`"
    fi
    switch=argyll-internal
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      internalargyll="`echo $1 | sed s/--$switch=//`"
    fi
    switch=enable-cwdebug
    if [ "`echo \"$1\" | sed s/\"--$switch=\"//`" != "$1" ]; then
      cwdebug="`echo $1 | sed s/--$switch=//`"
    fi
    switch=enable-cwdebug
    if [ "`echo \"$1\" | sed s/\"--$switch\"//`" != "$1" ]; then
      cwdebug="1"
    fi
    switch=quick
    if [ "`echo \"$1\" | sed s/\"--$switch\"//`" != "$1" ]; then
      quick="1"
    fi
    switch=enable-debug
    if [ "`echo \"$1\" | sed s/\"--$switch\"//`" != "$1" ]; then
      debug="1"
    fi
    switch=disable-dependency-tracking
    if [ "`echo \"$1\" | sed s/\"--$switch\"//`" != "$1" ]; then
      nodeps="1"
    fi
    switch=help
    if [ "`echo \"$1\" | sed s/\"--$switch\"//`" != "$1" ]; then
      echo "Usage:"
      echo "   --prefix=[/usr/local]                package prefix"
      echo "   --exec-prefix=[\$prefix]              package exec-prefix"
      echo "   --bindir=[\$exec-prefix/bin]          binary installation path"
      echo "   --sbindir=[\$exec-prefix/sbin]        super user binary installation path"
      echo "   --libdir=[\$exec-prefix/lib]          library installation path"
      echo "   --includedir=[\$prefix/include]       include file installation"
      echo "   --datadir=[\$prefix/data]             application data base path"
      echo "   --mandir=[\$datadir/man]              manual installation path"
      echo "   --pixmapdir=[\$datadir/pixmaps]       icon installation path"
      echo "   --desktopdir=[\$datadir/applications] xdg installation path"
      echo ""
      echo "   --with-fltk-config=[fltk-config]     alternative fltk version"
      echo "   --enable-debug                       debug version"
      echo "   --disable-dependency-tracking        no dependencies [default check]"
      echo "   --enable-cwdebug=[\$cwdebugdir]       deploy cwlibary for debugging"
      echo "   --quick                              generate config files only"
      echo "   --help"
      echo ""
      echo " Optionally set the CC, CXX, CFLAGS, CXXFLAGS and LDFLAGS environment variables."
      echo ""
      exit
    fi
    shift
  done
fi

ECHO="echo";

echo ""
echo "################################################################"
echo "#                                                              #"
echo "        Welcome to $TARGET_NAME Version $VERSION configurator"
echo "#                                                              #"
echo "#                       Configuration                          #"


echo "$zeile \$@" > config.log
chmod 0755 config.log

src_dir="`(cd ..;pwd)`/""$TARGET"-"$VERSION"

#prefix
if [ -z "$prefix" ]; then
  prefix=/usr/local
fi

if [ -z "$datadir" ]; then
  test -f $prefix/share/config.site && . $prefix/share/config.site
else
  test -f $datadir/config.site && . $datadir/config.site
fi

test -f error.txt && rm error.txt
if [ -z "$quick" ]; then
  test -f mkdepend && rm mkdepend config.h
fi

echo "# automatically generated file by configure - do not edit" > $CONF
echo "# automatically generated file by configure - do not edit" > $CONF_I18N
echo "/* automatically generated file by configure - do not edit */" > $CONF_H
echo "#ifndef ICCEXAMIN_CONFIG_H" >> $CONF_H
echo "#define ICCEXAMIN_CONFIG_H" >> $CONF_H
echo "" >> $CONF_H
echo "" >> $CONF
echo "TARGET = $TARGET" >> $CONF
echo "BINTARGET = $BINTARGET" >> $CONF
echo "" >> $CONF

echo ""


# detect System

UNAME_=`uname`
OSUNAME=BSD
if [ $? = 0 ] && [ $UNAME_ = "Darwin" ]; then
  echo "Darwin PPC              detected"
  echo "APPLE = 1" >> $CONF
  echo "#define APPLE 1" >> $CONF_H
  echo "OSX_H =" >> $CONF
  OSUNAME=Darwin
else
  if [ $UNAME_ = "Linux" ]; then
    osuname="LINUX = 1"
    echo "#define LINUX 1" >> $CONF_H
    echo "Linux system            detected"
    OSUNAME=Linux
  else
    if [ $UNAME_ = "SunOS" ]; then
      osuname="SOLARIS = 1"
      echo "#define SOLARIS 1" >> $CONF_H
      echo "SunOS                   detected"
      OSUNAME=SunOS
    else
      if [ $UNAME_ = "OpenBSD" ] || [ $UNAME_ = "NetBSD" ] || [ $UNAME_ = "FreeBSD" ]; then
        osuname="BSD = 1"
        OS_EXT=.bsd
        echo "#define BSD 1" >> $CONF_H
        echo "BSD $UNAME_             detected"
        OSUNAME=BSD
      else
        if [ `uname -a | grep W32 | wc -l` -gt 0 ];then
          osuname="WIN32 = 1"
          echo "#define WIN32 1" >> $CONF_H
          echo "Windows $UNAME_             detected"
          echo "EXEC_END = .exe" >> $CONF
          EXEC_END=.exe; export EXEC_END
          OSUNAME=Windows
        else
          echo "ICC Examin may or may not compile on your $UNAME_ system"
        fi
      fi
    fi
  fi
fi
echo "$osuname" >> $CONF
echo "$osuname" >> $CONF_I18N
echo "MAKEFILE_ARCH = Makefile$OS_EXT"  >> $CONF
MACH_=`uname -m`
MACH=BUILD_32
if [ $? = 0 ]; then
  if [ "$MACH_" = "i686" ]; then
    echo "32-bit system           detected"
  else
    if [ "$MACH_" = "x86_64" ]; then
      MACH=BUILD_64
      echo "BUILD_64 = 1" >> $CONF
      echo "X86_64                  try build in 64 bit mode"
      BARCH="64"
    else
      if [ "$MACH_" = "sun4u" ]; then
        MACH=BUILD_64
        echo "BUILD_64 = 1" >> $CONF
        echo "spark ultra 4           try build in 64 bit mode"
        BARCH="64"
        LINE_ARCH="-64"
      fi
    fi
  fi
fi
LIBDIR="lib"$BARCH
export MACH OSUNAME LIBDIR BARCH LINE_ARCH

if [ $OSUNAME = Windows ]; then
  up="`echo $USERPROFILE | sed s%\\\\\\\%/%g`"
  srcdir=`pwd | sed s%/%"C:/MinGW/"%1`
#  srcdir=`echo $srcdir | sed s%$USERNAME/%%`
#  srcdir=`echo $srcdir | sed s%/%%1`
  srcdir=`echo $srcdir | sed s%/%\\\\\\\\\\\\\\\\\\%g`
  test -z "$srcdir" && echo srcdir not detected in `pwd`
else
  srcdir="`pwd`"
fi

if [ -z "$CC" ]; then
  if [ $OSUNAME = Windows ]; then
    CC=gcc
  else
    CC=cc
  fi
#$LINE_ARCH
fi
if [ -z "$CXX" ]; then
  CXX=c++
#$LINE_ARCH
fi

echo "CXX = $CXX" >> $CONF
echo "CC = $CC" >> $CONF
echo "CXX = $CXX" >> $CONF_I18N
echo "CC = $CC" >> $CONF_I18N
export CC CXX

CFLAGS_COMMON="$CFLAGS"
CXXFLAGS_COMMON="$CXXFLAGS"
LDFLAGS_COMMON="$LDFLAGS"
MAKE_CFLAGS="\$(INCL) \$(ARGYLL_H) \$(DEBUG)"
MAKE_CXXFLAGS="\$(INCL) \$(ARGYLL_H) \$(DEBUG)"
MAKE_LDFLAGS="\$(ARGYLL_LIBS)"

# exec_prefix bindir sbindir libdir includedir datadir
if [ -z "$exec_prefix" ]; then
  exec_prefix="$prefix"
fi
if [ "`echo $exec_prefix | grep 64 | wc -l`" -eq "1" ]; then
  BARCH=""
  LIBDIR="lib"
  echo unset BARCH LIBDIR
  export BARCH LIBDIR
fi
if [ -z "$bindir" ]; then
  bindir="$exec_prefix/bin"
fi
if [ -z "$sbindir" ]; then
  sbindir="$exec_prefix/sbin"
fi
if [ -z "$libdir" ]; then
  libdir="$exec_prefix/$LIBDIR"
fi
if [ -z "$includedir" ]; then
  includedir="$prefix/include"
fi
if [ -z "$datadir" ]; then
  datadir="$prefix/share"
fi
if [ -z "$mandir" ]; then
  mandir="$datadir/man"
fi
# pixmapdir desktopdir
if [ -z "$pixmapdir" ]; then
  pixmapdir="$datadir/pixmaps"
fi
if [ -z "$desktopdir" ]; then
  desktopdir="$datadir/applications"
fi
if [ "$cwdebug" -eq "1" ]; then
  cwdebug="$libdir"
else
  if [ `echo $cwdebug | wc -m` -eq 2 ]; then
    if [ "$cwdebug" -eq "0" ]; then
      unset cwdebug
    fi
  fi
fi
export prefix exec_prefix bindir sbindir libdir includedir datadir mandir
export pixmapdir desktopdir
export fltkconfig cwdebug debug

PATH=$bindir:$PATH
export PATH



# detect Libraries

if [ "$internalargyll" != "no" ]; then
  ARGYLL_VERSION="argyll-0.60"
  export ARGYLL_VERSION
fi
export internalargyll

# walk into sub dirs and configure there
if [ -n "$ECHO" ]; then
  if [ "$internalargyll" != "no" ] && [ -z "$quick" ]; then
    if [ -d $ARGYLL_VERSION ]; then
      cd $ARGYLL_VERSION
      if [ -n "$ECHO" ]; then
        test -n "$INFOECHO" && $INFOECHO ./configure --enable-static $nodeps_config_opt --prefix=$prefix
      fi
      ./configure --enable-static $nodeps_config_opt --prefix=$prefix
      cd $srcdir
    fi
  fi
fi

if [ $nodeps -eq 1 ]; then
  GCC_MM="echo \"\#disable dependency tracking\""
  nodeps_config_opt=--disable-dependency-tracking
else
  GCC_MM="$CC -MM"
fi

echo "LIB=/"$LIBDIR >> $CONF

# set some compiler and linker options

echo "RM = rm -f $DEBUG_SWITCH" >> $CONF
echo "MAKEDEPEND	= $GCC_MM" >> $CONF
if [ $OSUNAME = "Darwin" ]; then
  echo "" >> $CONF
  echo "COPY = cp -p $DEBUG_SWITCH" >> $CONF
  LDFLAGS="-L."
  MAKE_LDFLAGS="\$(dl) \$(iconv)"
  echo "DBG_LIBS = #-lMallocDebug" >> $CONF
  echo "I18N_LIB = \$(intl) \$(LIBNAME)" >> $CONF
  echo "I18N_LIBSTAT = /opt/local/lib/libintl.a \$(LIBNAME) \$(iconv)" >> $CONF
  echo "INCL=-I\$(includedir) -I/usr/X11R6/include -I./ -I/usr/include/gcc/darwin/default/c++" >> $CONF
  echo "LIBEXT = .dylib" >> $CONF
  echo "LINK_FLAGS = -dynamiclib -L." >> $CONF
  echo "MSGMERGE = msgmerge" >> $CONF
  CFLAGS="-Wall -g -DPIC -Wunused"
  CXXFLAGS="-Wall -g -DPIC"
  echo "REZ = \$(fltkconfig) --post \$@" >> $CONF
  echo "OSX_CPP = \$(OSX_CPPFILES)" >> $CONF
  echo "XGETTEXT_OPTIONS = --keyword=gettext \
        --keyword=_ \
        --keyword=N_" >> $CONF
  echo "INSTALL = install $DEBUG_SWITCH" >> $CONF
else
  echo "LIBMID = .so" >> $CONF
  echo "LIBNAMEFULL = lib\$(TARGET)\$(LIBMID).\$(VERSION_A).\$(VERSION_B).\$(VERSION_C)" >> $CONF
  echo "MSGMERGE = msgmerge" >> $CONF
  echo "MSGMERG_OPTS = --update" >> $CONF
  echo "XGETTEXT_OPTIONS = --keyword=gettext --flag=gettext:1:pass-c-format \
        --keyword=_ --flag=_:1:pass-c-format \
        --keyword=N_ --flag=N_:1:pass-c-format \
        --copyright-holder='Kai-Uwe Behrmann' \
        --msgid-bugs-address='ku.b@gmx.de' \
        --from-code=utf-8" >> $CONF
  if [ $OSUNAME = "Linux" ]; then
    echo "" >> $CONF
    echo "COPY = cp $DEBUG_SWITCH -dpa" >> $CONF
    LDFLAGS="-L."
    MAKE_LDFLAGS="\$(dl) \$(iconv)"
    echo "I18N_LIB = \$(LIBNAME)" >> $CONF
    echo "I18N_LIBSTAT = \$(LIBNAME)" >> $CONF
    echo "INCL=-I\$(includedir) -I/usr/X11R6/include -I. -I/usr/include/g++ -I/usr/include" >> $CONF
    echo "LINK_FLAGS = -shared \$(dl) -fPIC -L. -lpthread" >> $CONF
    echo "LIBNAMEV = lib\$(TARGET)\$(LIBMID).\$(VERSION_A)" >> $CONF
    echo "LINK_FLAGS_STATIC = $LDFLAGS_COMMON" >> $CONF
    echo "LINK_NAME = -Wl,-soname -Wl,\$(LIBNAMEFULL)" >> $CONF
    echo "INSTALL = install $DEBUG_SWITCH" >> $CONF
  else
    echo "COPY = cp -p" >> $CONF
    echo "INCL=-I\$(includedir) -I/usr/X11R6/include -I. -I/usr/include/g++ -I/usr/include" >> $CONF
    PIC=-fPIC
    if [ $OSUNAME = "BSD" ]; then
      MAKE_LDFLAGS="\$(iconv)"
      INSTALL="install $DEBUG_SWITCH"
      test -n "$ECHO" && $ECHO "LINK_FLAGS = -shared \$(iconv)" >> $CONF
      test -n "$ECHO" && $ECHO "INSTALL = install $DEBUG_SWITCH" >> $CONF
    fi
    if [ $OSUNAME = "SunOS" ]; then
      LDFLAGS="-mimpure-text -lrt"
      MAKE_LDFLAGS="\$(dl) \$(iconv)"
      INSTALL="install"
    else
      LDFLAGS="-mimpure-text"
      MAKE_LDFLAGS="\$(dl) \$(iconv)"
      INSTALL="install"
      echo "LINK_FLAGS = -shared \$(dl) \$(iconv)" >> $CONF
      echo "INSTALL = install" >> $CONF
    fi
    CFLAGS="-L. -fPIC"
    CXXFLAGS="-L. $PIC"
    if [ $OSUNAME = "Windows" ]; then
      PIC=""
      LDFLAGS=""
      CFLAGS="-L."
      CXXFLAGS="-L."
    fi
    echo "I18N_LIB = \$(iconv) \$(intl) \$(LIBNAMEV)" >> $CONF
    echo "I18N_LIBSTAT = \$(iconv) \$(intl) \$(LIBNAMEV)" >> $CONF
    echo "RM = rm -f" >> $CONF
  fi
fi
if [ -n "$cwdebug" ]; then
  echo "" >> $CONF
  echo "cwdebug = $cwdebug" >> $CONF
  echo "CWLIB = -L$cwdebug -lcwd"  >> $CONF
  echo "CCFILES = \$(DEBUG_CC)" >> $CONF
  echo "#define CWDEBUG 1" >> $CONF_H
fi

CFLAGS="$CFLAGS $CFLAGS_COMMON"
CXXFLAGS="$CXXFLAGS $CXXFLAGS_COMMON"
LDFLAGS="$LDFLAGS $LDFLAGS_COMMON"

echo "CFLAGS   = $CFLAGS $MAKE_CFLAGS"       >> $CONF
echo "CXXFLAGS = $CXXFLAGS $MAKE_CXXFLAGS" >> $CONF
echo "LDFLAGS  = $LDFLAGS $MAKE_LDFLAGS"    >> $CONF
echo "CFLAGS   = $CFLAGS $MAKE_CFLAGS"       >> $CONF_I18N
echo "CXXFLAGS = $CXXFLAGS $MAKE_CXXFLAGS" >> $CONF_I18N
echo "LDFLAGS  = $LDFLAGS $MAKE_LDFLAGS"    >> $CONF_I18N

echo "" >> $CONF
echo "" >> $CONF
echo ""
echo ""

LIBS_TEST="dl iconv intl"; export LIBS_TEST
X_ADD="Xpm Xext"; export X_ADD


ECHO="echo"; export ECHO
LIBS=1; export LIBS
ARGYLL=1; export ARGYLL
#export ELEKTRA=1
OYRANOS=1; export OYRANOS
LCMS=1; export LCMS
FTGL=2; export FTGL
FLTK=1; export FLTK
LIBPNG=0; export LIBPNG
LIBTIFF=1; export LIBTIFF
#FLU=2; export FLU
if [ $OSUNAME != "Darwin" ] && [ $OSUNAME != "Windows" ]; then
X11=1;   export X11
fi
XINERAMA=1; export XINERAMA
XF86VMODE=1; export XF86VMODE
DEBUG=1; export DEBUG
PO=1; export PO
GETTEXT=1; export GETTEXT
./configure.sh
LIBS=0; export LIBS

ARGYLL=0; export ARGYLL
ELEKTRA=0; export ELEKTRA
OYRANOS=0; export OYRANOS
LCMS=0; export LCMS
FTGL=0; export FTGL
FLTK=0; export FLTK
LIBPNG=0; export LIBPNG
LIBTIFF=0; export LIBTIFF
FLU=0; export FLU
X11=0; export X11
XINERAMA=0; export XINERAMA
XF86VMODE=0; export XF86VMODE
DEBUG=0; export DEBUG
PO=0; export PO
GETTEXT=0; export GETTEXT

if [ -d ../../../plug-ins/icc_examin/ ]; then
  build_plug_in_only=1
  CP_CONFIG=../../../cinepainttool
  CP_FLAGS="$CP_CONFIG --cflags-local"
  CP_LIBS="$CP_CONFIG --libs-local"
  CP_VERSION=`$CP_CONFIG --version`
  echo "CP_DIR=`$CP_CONFIG --install-dir`" >> $CONF
  echo "INSTALL_TARGET=install_cp" >> $CONF
  echo "local CinePaint $CP_VERSION  detected"
  echo "CINEPAINT = icc_examin_cp" >> $CONF
else
  echo "INSTALL_TARGET=install_global" >> $CONF
fi
if [ -z "$CP_CONFIG" ]; then
  CP_CONFIG=`which cinepainttool 2>/dev/null`
  if [ -n "$CP_CONFIG" ]; then
    CP_FLAGS="cinepainttool --cflags"
    CP_LIBS="cinepainttool --libs"
    CP_VERSION=`cinepainttool --version`
    CP_N_VERSION=`cinepainttool --version | sed "s/\.// ; s/-.//"`
    echo "Gtk CinePaint $CP_VERSION    detected"
    cp_reqired=22
    if [ "$CP_N_VERSION" -ge $cp_reqired ]; then
      echo "CINEPAINT = icc_examin_cp" >> $CONF
    else
      echo "too old CinePaint version - need at least 0.$cp_reqired"
    fi
  fi
fi
 
if [ -n "$CP_VERSION" ]; then
  echo "CP_FLAGS=$CP_FLAGS" >> $CONF
  echo "CP_LIBS=$CP_LIBS" >> $CONF
  echo "#define ICC_CINEPAINT_VERSION \"Gtk CinePaint $CP_VERSION\"" >> $VERS
fi

echo ""
echo ""



# Alle ifdefs landen hier

echo "" >> $CONF
echo "VERSION_A = $VERSION_A" >> $CONF
echo "VERSION_B = $VERSION_B" >> $CONF
echo "VERSION_C = $VERSION_C" >> $CONF
echo "VERSION   = $VERSION" >> $CONF
echo "VERSION_L = $VERSION_L" >> $CONF
echo "" >> $CONF

echo "#ifndef ICC_VERSION_H" > $VERS
echo "#define ICC_VERSION_H" >> $VERS
echo "" >> $VERS
echo "#define ICC_EXAMIN_VERSION_A $VERSION_A" >> $VERS
echo "#define ICC_EXAMIN_VERSION_B $VERSION_B" >> $VERS
echo "#define ICC_EXAMIN_VERSION_C $VERSION_C" >> $VERS
echo "#define ICC_EXAMIN_VERSION $VERSION_L" >> $VERS
echo "#define ICC_EXAMIN_V \"$VERSION\"" >> $VERS
echo "#define ICC_EXAMIN_D _(\"$ZEIT\")" >> $VERS
if [ -n "$CP_VERSION" ]; then
  echo "#define ICC_CINEPAINT_VERSION \"Gtk CinePaint $CP_VERSION\"" >> $VERS
fi
echo "" >> $VERS
echo "#endif //ICC_VERSION_H" >> $VERS

echo "Version: $VERSION" > $SPEC
echo "Source:  $TARGET"-"$VERSION".tar.gz >> $SPEC
echo "Release: $RELEASE" >> $SPEC
echo "%define pixmapdir       $pixmapdir" >> $SPEC
echo "%define desktopdir      $desktopdir" >> $SPEC
cat  "$SPEC.in" >> $SPEC
echo generated $SPEC from "$SPEC.in"


echo "prefix =                $prefix"

echo ""
echo "################################################################"
echo "#                       Configuration                          #"
echo "prefix          =       $prefix"
echo "exec_prefix     =       $exec_prefix"
echo "bindir          =       $bindir"
echo "sbindir         =       $sbindir"
echo "libdir          =       $libdir"
echo "includedir      =       $includedir"
echo "datadir         =       $datadir"
echo "mandir          =       $mandir"
echo "pixmapdir       =       $pixmapdir"
echo "desktopdir      =       $desktopdir"
echo "srcdir          =       $srcdir" 
if [ -n "$cwdebug" ]; then
echo "cwdebug         =       $cwdebug"
fi
echo "CC              =       $CC"
echo "CXX             =       $CXX"
echo "CFLAGS          =       $CFLAGS"
echo "CXXFLAGS        =       $CXXFLAGS"
echo "LDFLAGS         =       $LDFLAGS"
echo "INCL            =       $INCL"
echo "################################################################"
echo ""

echo "src_dir = $src_dir" >> $CONF
echo "srcdir = $srcdir" >> $CONF
echo "prefix=$prefix" >> $CONF
echo "exec_prefix=$exec_prefix" >> $CONF
echo "bindir=$bindir" >> $CONF
echo "sbindir=$sbindir" >> $CONF
echo "libdir=$libdir" >> $CONF
echo "includedir=$includedir" >> $CONF
echo "datadir=$datadir" >> $CONF
echo "mandir=$mandir" >> $CONF
echo "pixmapdir=$pixmapdir" >> $CONF
echo "desktopdir=$desktopdir" >> $CONF
echo "" >> $CONF

echo "#define PREFIX         \"$prefix\"" >> $CONF_H
echo "#define ICCEXAMIN_DATADIR        \"$datadir\"" >> $CONF_H
echo "#define LOCALEDIR      \"$datadir/locale\"" >> $CONF_H
echo "#define PIXMAPDIR      \"$pixmapdir\"" >> $CONF_H
echo "#define SRCDIR         \"$srcdir\"" >> $CONF_H
if [ $OSUNAME = Windows ]; then
  echo "#define SRC_LOCALEDIR  \"$srcdir\\\\po\"" >> $CONF_H
else
  echo "#define SRC_LOCALEDIR  \"$srcdir/po\"" >> $CONF_H
fi

echo "" >> $CONF


if [ -z "$quick" ]; then
  echo "" > mkdepend
fi

# prepare makefile from MAKEFILE_DIR
PREPARE_MAKEFILES=1; export PREPARE_MAKEFILES
./configure.sh
PREPARE_MAKEFILES=0; export PREPARE_MAKEFILES

echo "" >> $CONF_H
echo "#endif /* ICCEXAMIN_CONFIG_H */" >> $CONF_H

test -f error.tmp && ERROR=1
test -f error.tmp && rm error.tmp
if [ "$ERROR" -ne "0" ]; then
  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  echo "!!!                     An ERROR occured                     !!!"
  echo "!!!                     See Log above                        !!!"
  echo "!!!                     remove  $CONF                     !!!"
  echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
  echo ""
  rm Makefile $CONF_H $CONF_SH $SPEC $PKGC $MPKG
  exit
else
  if [ -z "$quick" ]; then
    make depend
  fi
fi


if [ `cat error.txt | wc -l` -lt 1 ]; then
  rm error.txt
fi


