#!/bin/bash
# Script generated by dpconfigure on May 23 2009
#
#   Configure script for Linux, Mac OS X and Unix
#
# copyright (C) 2002-2009 Marc Wathelet. All rights reserved.
#
#  This script is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
# Useless with new structure that better use .pro files
# $1 is the path in the mingw form: /c/usr/... or "/c/usr/..."
#function winPath()
#{
#  echo $1 | sed -r "s/^\"(.*)\"$/\1/" | sed -r "s/^\/([a-zA-Z])/\1:/" | sed "s/\//\\\\/g"
#}
#function cWinPath()
#{
#  winPath $1 | sed "s/\\\\/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/g"
#}
# Accept 1 argument the basename of file to replace
function replaceFile()
{
  if [ -e $1 ] && diff $1 $1.new > /dev/null; then
    rm $1.new
  else
    mv $1.new $1
  fi
}

#Platform options
case "$(uname)" in
  Linux) PLATFORM=LINUX ;;
  SunOS) PLATFORM=SUNOS ;;
  Darwin) PLATFORM=MAC ;;
  MINGW*) PLATFORM=MINGW ;;
  *)
    echo "Unknown platform $(uname)"
    exit 2
  ;;
esac

#Compiler options
if [ "$PLATFORM" = "MINGW" ]; then
  # grep installed with msys has no option -o, change following line when current version of gcc changes in mingw
  GCC_VERSION="3.4.5"
else
  GCC_VERSION=$(gcc --version | grep -o "[0-9]*\.[0-9]*\.[0-9]*" | head -n 1)
fi
GCC_VERSION_NUM=$(echo $GCC_VERSION | awk 'BEGIN{FS="."}{print $1*1000000+$2*1000+$3}')
if [ $GCC_VERSION_NUM -gt 3004005 ]; then
  PCH="yes"
else
  PCH="no"
fi

#Check if Qt is compiled statically
QT_SHARED="yes"
TEMP_DIR=$(echo "/tmp/file"4035)
rm -rf $TEMP_DIR
mkdir $TEMP_DIR
ORIG_DIR=$(pwd)
cd $TEMP_DIR
if [ "$PLATFORM" = "MINGW" ]; then
  (
    cat << END
#include <qglobal.h>
int main(int argc, int argv)
{
#ifdef QT_DLL
  return 2;
#else
  return 0;
#endif
}
END
  ) > $TEMP_DIR/main.cpp
  if qmake -project -o test.pro > /dev/null 2>&1 &&     qmake "CONFIG-=app_bundle" "CONFIG-=debug" "CONFIG+=release" > /dev/null 2>&1 &&     make > /dev/null 2>&1 &&     release/test; then
    QT_SHARED="no"
    echo "Qt build statically"
  fi
else
  (
    cat << END
#include <qglobal.h>
int main(int argc, int argv)
{
#ifdef QT_SHARED
  return 2;
#else
  return 0;
#endif
}
END
  ) > $TEMP_DIR/main.cpp
  if qmake -project -o test.pro > /dev/null 2>&1 &&     qmake "CONFIG-=app_bundle" "CONFIG-=debug" "CONFIG+=release" > /dev/null 2>&1 &&     make > /dev/null 2>&1 &&     test; then
    QT_SHARED="no"
    echo "Qt build statically"
  fi
fi
cd $ORIG_DIR
rm -rf $TEMP_DIR

#Default options
PREFIX="/usr"
DEST_PREFIX="$(pwd)"
BINDIR="$PREFIX/bin"
LIBDIR="$PREFIX/lib"
INCDIR="$PREFIX/include"
SHAREDIR="$PREFIX/share"
LIBTYPE=shared
EXTINCDIR=""
EXTLIBDIR=""
RPATHDIR=""
DEFINES=""
BATCH_MODE="no"
COMMANDLINE=""
SILENT_MARK=""
SKIP_QT_CHECK="no"
PROFILING="no"
DISTRIBUTION=""
QMAKE_SPEC=""
MAC_SDK=""
MAC_ARCH="x86"
#Parse options
while [ "$1" ]; do
  case "$1" in
    "-prefix" | "--prefix")
      shift
      PREFIX=$1
      BINDIR="$PREFIX/bin"
      LIBDIR="$PREFIX/lib"
      RPATHDIR="$RPATHDIR \"$LIBDIR\""
      INCDIR="$PREFIX/include"
      SHAREDIR="$PREFIX/share/geopsy"
      COMMANDLINE="$COMMANDLINE -prefix \"$1\""
    ;;
    "-bindir" | "--bindir")
      shift
      BINDIR=$1
      COMMANDLINE="$COMMANDLINE -bindir \"$1\""
    ;;
    "-libdir" | "--libdir")
      shift
      LIBDIR=$1
      RPATHDIR="$RPATHDIR \"$LIBDIR\""
      COMMANDLINE="$COMMANDLINE -libdir \"$1\""
    ;;
    "-incdir" | "--incdir")
      shift
      INCDIR=$1
      COMMANDLINE="$COMMANDLINE -incdir \"$1\""
    ;;
    "-sharedir" | "--sharedir")
      shift
      SHAREDIR=$1
      COMMANDLINE="$COMMANDLINE -sharedir \"$1\""
    ;;
    "-dest-prefix" | "--dest-prefix")
      shift
      DEST_PREFIX=$1
      COMMANDLINE="$COMMANDLINE -dest-prefix \"$1\""
    ;;
    "-shared" | "--shared")
      LIBTYPE="shared"
      COMMANDLINE="$COMMANDLINE -shared"
    ;;
    "-static" | "--static")
      LIBTYPE="static"
      COMMANDLINE="$COMMANDLINE -static"
    ;;
    "-batch" | "--batch")
      BATCH_MODE="yes"
      COMMANDLINE="$COMMANDLINE -batch"
    ;;
    "-I")
      shift
      EXTINCDIR="$EXTINCDIR \"$1\""
      COMMANDLINE="$COMMANDLINE -I \"$1\""
    ;;
    "-L")
      shift
      EXTLIBDIR="$EXTLIBDIR \"$1\""
      COMMANDLINE="$COMMANDLINE -L \"$1\""
    ;;
    "-rpath" | "--rpath")
      if [ "${2:0:1}" = "-" ]; then
        RPATHDIR=""
        COMMANDLINE="$COMMANDLINE -rpath"
      else
        shift
        RPATHDIR="$RPATHDIR \"$1\""
        COMMANDLINE="$COMMANDLINE -rpath \"$1\""
      fi
    ;;
    "-D")
      shift
      DEFINES="$DEFINES $1"
      COMMANDLINE="$COMMANDLINE -D \"$1\""
    ;;
    "-skip-qt-check" | "--skip-qt-check")
      SKIP_QT_CHECK="yes"
      COMMANDLINE="$COMMANDLINE $1"
    ;;
    "-profile" | "--profile")
      PROFILING="yes"
      COMMANDLINE="$COMMANDLINE $1"
    ;;
    "-silent" | "--silent")
      SILENT_MARK="@"
      COMMANDLINE="$COMMANDLINE $1"
    ;;
    "-no-pch" | "--no-pch")
      PCH="no"
      COMMANDLINE="$COMMANDLINE $1"
    ;;
    "-distribution" | "--distribution")
      shift
      DISTRIBUTION=$1
      COMMANDLINE="$COMMANDLINE -distribution \"$1\""
    ;;
    "-win32" | "--win32")
      PLATFORM="MINGW"
      GCC_VERSION=$(i686-mingw32-gcc --version | grep -o "[0-9]*\.[0-9]*\.[0-9]*" | head -n 1)
      PCH="yes"
      QMAKE_SPEC="-spec win32-x-g++ -win32"
      COMMANDLINE="$COMMANDLINE $1"
    ;;
    "-mac-sdk" | "--mac-sdk")
      if [ "LINUX" = "MAC" ]; then
        shift
        MAC_SDK=$1
        COMMANDLINE="$COMMANDLINE -mac-sdk \"$1\""
      fi
    ;;
    "-mac-arch" | "--mac-arch")
      if [ "LINUX" = "MAC" ]; then
        shift
        MAC_ARCH=$1
        COMMANDLINE="$COMMANDLINE -mac-arch \"$1\""
      fi
    ;;
    "-h" | "-help" | "--help")
      echo
      echo "Usage: configure [options]"
      echo
      echo "Options:"
      echo
      echo " -batch              Switch to batch mode"
      echo " -silent             Minimal output during \"make install\""
      echo " -no-pch             Set precompiled headers off"
      echo "                       (default on if gcc>=3.4)"
      echo
      echo "Installation paths:"
      echo
      echo " -prefix <DIR>       Base directory for installation"
      echo "                       (default /usr, must be before -*dir)"
      echo " -bindir <DIR>       Executables will be installed to DIR"
      echo "                       (default PREFIX/bin)"
      echo " -libdir <DIR>       Libraries will be installed to DIR"
      echo "                       (default PREFIX/lib)"
      echo " -incdir <DIR>       Headers will be installed to DIR"
      echo "                       (default PREFIX/include)"
      echo " -sharedir <DIR>     Shared files and translations will be installed"
      echo "                     to DIR (default PREFIX/share/geopsy)"
      echo
      echo "Configuration:"
      echo
      echo " -shared             Create and use shared libraries"
      echo " -static             Create and use static libraries"
      echo
      echo " -D <MACRO>          Defines MACRO"
      echo
      echo " -dest-prefix <DIR>  Destination prefix for all binaries"
      echo "                       (default $DEST_PREFIX)"
      echo " -rpath <DIR>        Add DIR to library rutime search path"
      echo "                       (without DIR, reset to null)"
      echo " -skip-qt-check      Do not check current Qt version"
      echo " -profile            Turn profiling on, add gcc option '-pg'"
      echo "                       (for development under Linux only)"
      echo " -win32              Turn on cross compilation with i686-mingw32"
      echo "                       (under Linux only)"
      echo " -mac-sdk <SDK>       Switch to SDK, e.g. /Developer/SDKs/MacOSX10.4u.sdk"
      echo "                       (under Mac only)"
      echo " -mac-arch <ARCH>     Switch to ARCH, e.g. x86 or ppc"
      echo "                       (under Mac only)"
      echo
      echo "Third party libraries:"
      echo
      echo " -I dir              Add dir to the list of directories to be"
      echo "                     searched for headers"
      echo " -L dir              Add dir to the list of directories to be"
      echo "                     searched for libraries"
      echo
      exit
    ;;
    *)
      echo "Bad option $1, see './configure -h' for help"
      exit 2
    ;;
  esac
  shift
done

###############################################################
# Store configure options
###############################################################
# If configure called from ./configure.cache, do not overwrite
if [ "$QTB_SAVE_CONFIGURE_OPTIONS_IN_CACHE" != "no" ]; then
  (
  cat << END
export QTB_SAVE_CONFIGURE_OPTIONS_IN_CACHE="no"
$SHELL configure $COMMANDLINE
END
  ) > configure.cache
  chmod a+x configure.cache
fi
###############################################################
# Check that Qt is correctly installed
###############################################################
echo "* Check Qt..."
if [ "$SKIP_QT_CHECK" = "no" ]; then
  if qmake -v > /dev/null 2>&1; then
    QT_VERSION=$(qmake -v | awk '{if (NR==2) print $4}')
    QT_VERSION_NUM=$(echo $QT_VERSION | awk 'BEGIN{FS="."}{print $1*1000000+$2*1000+$3}')
    if [ $QT_VERSION_NUM -lt 4005000 ]; then
      echo "*** ERROR *** : your Qt version is $QT_VERSION. At least version 4.5.0 is required."
      echo "                If you want to skip this version check,"
      echo "                add option -skip-qt-check."
      exit 2
    fi
  else
    echo "*** ERROR *** : qmake command is not available."
    echo "                Either Qt is not correctly installed"
    echo "                or PATH does not point to Qt binaries."
    exit 2
  fi
  if ! lrelease -version > /dev/null 2>&1; then
    echo "*** ERROR *** : lrelease command is not available."
    echo "                Either Qt is not correctly installed"
    echo "                or PATH does not point to Qt binaries."
    exit 2
  fi
fi

###############################################################
# Platform dependent initialisation
###############################################################
echo "* Platform initializations..."
case "$PLATFORM" in
  "LINUX")
    LIBS="-lqtbtools -lqtbguitools "
  ;;
  "SUNOS")
    LIBS="-lqtbtools -lqtbguitools "
  ;;
  "MINGW")
    SHELL=/bin/sh
    #if [ "$EXTINCDIR" ]; then
    #   WIN_EXTINCDIR=""
    #   for p in $(echo $EXTINCDIR); do
    #     WIN_EXTINCDIR="$WIN_EXTINCDIR $(winPath $p)"
    #   done
    #   EXTINCDIR=$WIN_EXTINCDIR
    #fi
    #if [ "$EXTLIBDIR" ]; then
    #   WIN_EXTLIBDIR=""
    #   for p in $(echo $EXTLIBDIR); do
    #     WIN_EXTLIBDIR="$WIN_EXTLIBDIR $(winPath $p)"
    #   done
    #   EXTLIBDIR=$WIN_EXTLIBDIR
    #fi
    #DEST_PREFIX=$(winPath $DEST_PREFIX)
    LIBS="-lqtbtools1 -lqtbguitools1 "
  ;;
  "MAC")
    LIBS="-framework qtbtools -framework qtbguitools "
  ;;
esac

###############################################################
# Show license if .pro file does not exist
###############################################################
echo "* License..."
if [ ! -e scifigs.pro ] && [ "$BATCH_MODE" = "no" ]; then
  echo
  echo "scifigs package is licensed to you under the terms"
  echo "of the GNU General Public License (GPL) version 2."
  LICENSE_ACCEPT=""
  while [ "$LICENSE_ACCEPT" != "no" ] && [ "$LICENSE_ACCEPT" != "yes" ]; do
    echo
    echo "Type 'view' to view the GNU General Public License."
    echo "Type 'yes' to accept this license offer."
    echo "Type 'no' to decline this license offer."
    echo
    echo -n "Do you accept this license? "
    read LICENSE_ACCEPT
    if [ "$LICENSE_ACCEPT" = "view" ]; then
      echo "#######################################################"
      echo "Type SPACE BAR or RETURN to move down"
      echo "#######################################################"
      sleep 2
      more LICENSE.GPL
      echo "#######################################################"
    fi
  done
  if [ "$LICENSE_ACCEPT" = "no" ]; then
    echo "You are not allowed to use this package."
    exit 2
  fi
fi
###############################################################
# Generate .pro file
###############################################################
echo "* Qt project..."
(
echo "CONFIG += debug_and_release"
echo "TARGET = scifigs"
echo "TEMPLATE = lib"
echo "VERSION = 2.2.5"
echo "UI_DIR = ui"
echo "INCLUDEPATH += src ui"
echo "DEPENDPATH += src ui"
if [ "$PCH" = "yes" ]; then
  echo "CONFIG += precompile_header"
  echo "PRECOMPILED_HEADER = src/stable.h"
fi
if [ "$QT_SHARED" = "no" ]; then
  echo "QTPLUGIN += qjpeg qgif qmng"
fi
if [ "$PLATFORM" = "MAC" ] && [ -e images/scifigs.icns ]; then
  echo "ICON=images/scifigs.icns"
elif [ "$PLATFORM" = "MINGW" ] && [ -e images/scifigs.rc ]; then
  echo "RC_FILE= images/scifigs.rc"
fi 
if [ "$PLATFORM" = "MAC" ]; then
  echo "CONFIG += $MAC_ARCH"
  if [ "$MAC_SDK" ]; then
    echo "QMAKE_MAC_SDK = $MAC_SDK"
  fi
  if [ "$LIBTYPE" = "shared"  ]; then
    echo "CONFIG += lib_bundle"
    echo "FRAMEWORK_HEADERS.version = Versions"
cat << END
FRAMEWORK_HEADERS.files += \\
           src/qtbabstractdynline.h \\
           src/qtbabstractdynlinelayer.h \\
           src/qtbaxis.h \\
           src/qtbaxisformatproperties.h \\
           src/qtbaxisproperties.h \\
           src/qtbaxisscaleproperties.h \\
           src/qtbaxiswindow.h \\
           src/qtbbrush.h \\
           src/qtbcircleviewer.h \\
           src/qtbcolorpalettelayer.h \\
           src/qtbcolorpalettewidget.h \\
           src/qtbcoordtip.h \\
           src/qtbdynline.h \\
           src/qtbdynline2d.h \\
           src/qtbdynline2dlayer.h \\
           src/qtbdynlinedelegate.h \\
           src/qtbdynlineeditor.h \\
           src/qtbdynlineitem.h \\
           src/qtbdynlinelayerproperties.h \\
           src/qtbdynnameline.h \\
           src/qtbdynxycolorlines.h \\
           src/qtbgraphcontent.h \\
           src/qtbgraphcontentformatproperties.h \\
           src/qtbgraphcontentlayer.h \\
           src/qtbgraphcontentlayerproperties.h \\
           src/qtbgraphcontentoptions.h \\
           src/qtbgraphicobject.h \\
           src/qtbgraphicobjectgeometryproperties.h \\
           src/qtbgraphicobjectidproperties.h \\
           src/qtbgraphicobjectprintproperties.h \\
           src/qtbgraphicsheet.h \\
           src/qtbgraphicsheetmenu.h \\
           src/qtbgraphicsheetproperties.h \\
           src/qtbgridmaxfollower.h \\
           src/qtbgridplot.h \\
           src/qtbgridproperties.h \\
           src/qtbgridviewer.h \\
           src/qtbimagelayer.h \\
           src/qtbimagelayerproperties.h \\
           src/qtbimagescalingpoint.h \\
           src/qtbimagewidget.h \\
           src/qtbimagewidgetproperties.h \\
           src/qtbirregulargrid2ddraw.h \\
           src/qtbirregulargrid2dplot.h \\
           src/qtblayerlocker.h \\
           src/qtblayermousetracking.h \\
           src/qtblayerpainter.h \\
           src/qtblayerpainterrequest.h \\
           src/qtblayerpainterthread.h \\
           src/qtblegend.h \\
           src/qtblegendformatproperties.h \\
           src/qtblegenditem.h \\
           src/qtblegenditemwidget.h \\
           src/qtblegendproperties.h \\
           src/qtblegendtable.h \\
           src/qtblegendwidget.h \\
           src/qtblivegridlayer.h \\
           src/qtblivegridlayerproperties.h \\
           src/qtbmakeupfilter.h \\
           src/qtbmousetracking.h \\
           src/qtbordertip.h \\
           src/qtbpagelimit.h \\
           src/qtbpaintprogress.h \\
           src/qtbpaletteinterpole.h \\
           src/qtbpaletteproperties.h \\
           src/qtbpalettetable.h \\
           src/qtbparallelband.h \\
           src/qtbparallelbands.h \\
           src/qtbpen.h \\
           src/qtbpointproperties.h \\
           src/qtbpolargridplot.h \\
           src/qtbscale.h \\
           src/qtbscifigsplugin.h \\
           src/qtbscifigspreferences.h \\
           src/qtbselectionwidget.h \\
           src/qtbslopeestimator.h \\
           src/qtbsymbol.h \\
           src/qtbtextedit.h \\
           src/qtbtexteditproperties.h \\
           src/qtbxmlscifigs.h \\
           src/qtbxuniqueycolorlines.h \\
           src/qtbxycolorlines.h \\
           src/qtbxycolorlinesproperties.h \\
           src/qtbxycolorplot.h \\
           src/qtbxynameplot.h \\
           src/qtbxynameplotproperties.h \\
           src/qtbxyplot.h \\
           src/qtbxyplotproperties.h \\
           src/qtbxyvaluelines.h \\
           src/qtbxyvalueplot.h \\
           src/scifigs.h \\
           src/scifigsdllexport.h \\
           src/scifigsversion.h
END
    echo "FRAMEWORK_HEADERS.path = Headers"
    echo "QMAKE_BUNDLE_DATA += FRAMEWORK_HEADERS"
  fi
fi
if [ "$PLATFORM" = "MINGW" ]; then
  if [ "$LIBTYPE" = "shared" ]; then
    echo "CONFIG+= dll"
  fi
fi
if [ "$LIBTYPE" = "static" ]; then
  echo "CONFIG += staticlib"
  echo "QMAKE_CXXFLAGS_DEBUG += -fPIC"
  echo "QMAKE_CXXFLAGS_RELEASE += -fPIC"
  echo "QMAKE_CFLAGS_DEBUG += -fPIC"
  echo "QMAKE_CFLAGS_RELEASE += -fPIC"
fi
if [ "$PROFILING" = "yes" ]; then
  echo "CONFIG(debug) {"
  echo "  QMAKE_CXXFLAGS_DEBUG += -pg"
  echo "  QMAKE_CFLAGS_DEBUG += -pg"
  echo "  QMAKE_LFLAGS_DEBUG += -pg"
  echo "} else {"
  echo "  QMAKE_CXXFLAGS_RELEASE += -pg"
  echo "  QMAKE_CFLAGS_RELEASE += -pg"
  echo "  QMAKE_LFLAGS_RELEASE += -pg"
  echo "}"
fi
if [ "$EXTINCDIR" ]; then
  echo "INCLUDEPATH += $EXTINCDIR"
  echo "DEPENDPATH += $EXTINCDIR"
fi
if [ "$EXTLIBDIR" ]; then
  for p in $(echo $EXTLIBDIR); do
    echo "LIBS += -L$p"
    if [ "$PLATFORM" = "MAC" ]; then
      echo "LIBS += -F$p"
    fi
  done
  for p in $(echo $RPATHDIR); do
    if [ "$PLATFORM" = "LINUX" ]; then
      echo "LIBS += -Wl,-rpath,$p"
    elif [ "$PLATFORM" = "SUNOS" ]; then
      echo "LIBS += -Wl,-R,$p"
    fi
  done
fi
if [ "$LIBS" ]; then
   echo "LIBS += $LIBS"
fi
if [ "$PLATFORM" = "MINGW" ]; then
  echo "QMAKE_LFLAGS_RELEASE = -Wl,-S"
fi
if [ "$DEFINES" ] || [ "" ]; then
  echo "DEFINES += $DEFINES "
fi
  if [ "$LIBTYPE" = "shared" ]; then
    echo "DEFINES += MAKE_SCIFIGS_DLL"
  else
    echo "DEFINES += SCIFIGS_STATIC"
  fi
  echo "DESTDIR = $DEST_PREFIX/lib"
echo "RESOURCES=scifigs.qrc"
cat << END
SOURCES += \\
           src/qtbabstractdynline.cpp \\
           src/qtbabstractdynlinelayer.cpp \\
           src/qtbaxis.cpp \\
           src/qtbaxisformatproperties.cpp \\
           src/qtbaxisproperties.cpp \\
           src/qtbaxisscaleproperties.cpp \\
           src/qtbaxiswindow.cpp \\
           src/qtbbrush.cpp \\
           src/qtbcircleviewer.cpp \\
           src/qtbcolorpalettelayer.cpp \\
           src/qtbcolorpalettewidget.cpp \\
           src/qtbcoordtip.cpp \\
           src/qtbdynline.cpp \\
           src/qtbdynline2d.cpp \\
           src/qtbdynline2dlayer.cpp \\
           src/qtbdynlinedelegate.cpp \\
           src/qtbdynlineeditor.cpp \\
           src/qtbdynlineitem.cpp \\
           src/qtbdynlinelayerproperties.cpp \\
           src/qtbdynnameline.cpp \\
           src/qtbdynxycolorlines.cpp \\
           src/qtbgraphcontent.cpp \\
           src/qtbgraphcontentformatproperties.cpp \\
           src/qtbgraphcontentlayer.cpp \\
           src/qtbgraphcontentlayerproperties.cpp \\
           src/qtbgraphcontentoptions.cpp \\
           src/qtbgraphicobject.cpp \\
           src/qtbgraphicobjectgeometryproperties.cpp \\
           src/qtbgraphicobjectidproperties.cpp \\
           src/qtbgraphicobjectprintproperties.cpp \\
           src/qtbgraphicsheet.cpp \\
           src/qtbgraphicsheetmenu.cpp \\
           src/qtbgraphicsheetproperties.cpp \\
           src/qtbgridmaxfollower.cpp \\
           src/qtbgridplot.cpp \\
           src/qtbgridproperties.cpp \\
           src/qtbgridviewer.cpp \\
           src/qtbimagelayer.cpp \\
           src/qtbimagelayerproperties.cpp \\
           src/qtbimagescalingpoint.cpp \\
           src/qtbimagewidget.cpp \\
           src/qtbimagewidgetproperties.cpp \\
           src/qtbirregulargrid2ddraw.cpp \\
           src/qtbirregulargrid2dplot.cpp \\
           src/qtblayerlocker.cpp \\
           src/qtblayermousetracking.cpp \\
           src/qtblayerpainter.cpp \\
           src/qtblayerpainterrequest.cpp \\
           src/qtblayerpainterthread.cpp \\
           src/qtblegend.cpp \\
           src/qtblegendformatproperties.cpp \\
           src/qtblegenditem.cpp \\
           src/qtblegenditemwidget.cpp \\
           src/qtblegendproperties.cpp \\
           src/qtblegendtable.cpp \\
           src/qtblegendwidget.cpp \\
           src/qtblivegridlayer.cpp \\
           src/qtblivegridlayerproperties.cpp \\
           src/qtbmakeupfilter.cpp \\
           src/qtbmousetracking.cpp \\
           src/qtbordertip.cpp \\
           src/qtbpagelimit.cpp \\
           src/qtbpaintprogress.cpp \\
           src/qtbpaletteinterpole.cpp \\
           src/qtbpaletteproperties.cpp \\
           src/qtbpalettetable.cpp \\
           src/qtbparallelband.cpp \\
           src/qtbparallelbands.cpp \\
           src/qtbpen.cpp \\
           src/qtbpointproperties.cpp \\
           src/qtbpolargridplot.cpp \\
           src/qtbscale.cpp \\
           src/qtbscifigsplugin.cpp \\
           src/qtbscifigspreferences.cpp \\
           src/qtbselectionwidget.cpp \\
           src/qtbslopeestimator.cpp \\
           src/qtbsymbol.cpp \\
           src/qtbtextedit.cpp \\
           src/qtbtexteditproperties.cpp \\
           src/qtbxmlscifigs.cpp \\
           src/qtbxuniqueycolorlines.cpp \\
           src/qtbxycolorlines.cpp \\
           src/qtbxycolorlinesproperties.cpp \\
           src/qtbxycolorplot.cpp \\
           src/qtbxynameplot.cpp \\
           src/qtbxynameplotproperties.cpp \\
           src/qtbxyplot.cpp \\
           src/qtbxyplotproperties.cpp \\
           src/qtbxyvaluelines.cpp \\
           src/qtbxyvalueplot.cpp \\
           src/scifigs.cpp
HEADERS += \\
           src/qtbabstractdynline.h \\
           src/qtbabstractdynlinelayer.h \\
           src/qtbaxis.h \\
           src/qtbaxisformatproperties.h \\
           src/qtbaxisproperties.h \\
           src/qtbaxisscaleproperties.h \\
           src/qtbaxiswindow.h \\
           src/qtbbrush.h \\
           src/qtbcircleviewer.h \\
           src/qtbcolorpalettelayer.h \\
           src/qtbcolorpalettewidget.h \\
           src/qtbcoordtip.h \\
           src/qtbdynline.h \\
           src/qtbdynline2d.h \\
           src/qtbdynline2dlayer.h \\
           src/qtbdynlinedelegate.h \\
           src/qtbdynlineeditor.h \\
           src/qtbdynlineitem.h \\
           src/qtbdynlinelayerproperties.h \\
           src/qtbdynnameline.h \\
           src/qtbdynxycolorlines.h \\
           src/qtbgraphcontent.h \\
           src/qtbgraphcontentformatproperties.h \\
           src/qtbgraphcontentlayer.h \\
           src/qtbgraphcontentlayerproperties.h \\
           src/qtbgraphcontentoptions.h \\
           src/qtbgraphicobject.h \\
           src/qtbgraphicobjectgeometryproperties.h \\
           src/qtbgraphicobjectidproperties.h \\
           src/qtbgraphicobjectprintproperties.h \\
           src/qtbgraphicsheet.h \\
           src/qtbgraphicsheetmenu.h \\
           src/qtbgraphicsheetproperties.h \\
           src/qtbgridmaxfollower.h \\
           src/qtbgridplot.h \\
           src/qtbgridproperties.h \\
           src/qtbgridviewer.h \\
           src/qtbimagelayer.h \\
           src/qtbimagelayerproperties.h \\
           src/qtbimagescalingpoint.h \\
           src/qtbimagewidget.h \\
           src/qtbimagewidgetproperties.h \\
           src/qtbirregulargrid2ddraw.h \\
           src/qtbirregulargrid2dplot.h \\
           src/qtblayerlocker.h \\
           src/qtblayermousetracking.h \\
           src/qtblayerpainter.h \\
           src/qtblayerpainterrequest.h \\
           src/qtblayerpainterthread.h \\
           src/qtblegend.h \\
           src/qtblegendformatproperties.h \\
           src/qtblegenditem.h \\
           src/qtblegenditemwidget.h \\
           src/qtblegendproperties.h \\
           src/qtblegendtable.h \\
           src/qtblegendwidget.h \\
           src/qtblivegridlayer.h \\
           src/qtblivegridlayerproperties.h \\
           src/qtbmakeupfilter.h \\
           src/qtbmousetracking.h \\
           src/qtbordertip.h \\
           src/qtbpagelimit.h \\
           src/qtbpaintprogress.h \\
           src/qtbpaletteinterpole.h \\
           src/qtbpaletteproperties.h \\
           src/qtbpalettetable.h \\
           src/qtbparallelband.h \\
           src/qtbparallelbands.h \\
           src/qtbpen.h \\
           src/qtbpointproperties.h \\
           src/qtbpolargridplot.h \\
           src/qtbscale.h \\
           src/qtbscifigsplugin.h \\
           src/qtbscifigspreferences.h \\
           src/qtbselectionwidget.h \\
           src/qtbslopeestimator.h \\
           src/qtbsymbol.h \\
           src/qtbtextedit.h \\
           src/qtbtexteditproperties.h \\
           src/qtbxmlscifigs.h \\
           src/qtbxuniqueycolorlines.h \\
           src/qtbxycolorlines.h \\
           src/qtbxycolorlinesproperties.h \\
           src/qtbxycolorplot.h \\
           src/qtbxynameplot.h \\
           src/qtbxynameplotproperties.h \\
           src/qtbxyplot.h \\
           src/qtbxyplotproperties.h \\
           src/qtbxyvaluelines.h \\
           src/qtbxyvalueplot.h \\
           src/scifigs.h \\
           src/scifigsdllexport.h \\
           src/scifigsversion.h
FORMS   += \\
           src/qtbaxisformatproperties.ui \\
           src/qtbaxisproperties.ui \\
           src/qtbaxisscaleproperties.ui \\
           src/qtbdynlinelayerproperties.ui \\
           src/qtbgraphcontentformatproperties.ui \\
           src/qtbgraphcontentlayerproperties.ui \\
           src/qtbgraphicobjectgeometryproperties.ui \\
           src/qtbgraphicobjectidproperties.ui \\
           src/qtbgraphicobjectprintproperties.ui \\
           src/qtbgraphicsheetproperties.ui \\
           src/qtbgridproperties.ui \\
           src/qtbimagelayerproperties.ui \\
           src/qtbimagescalingpoint.ui \\
           src/qtbimagewidgetproperties.ui \\
           src/qtblegendformatproperties.ui \\
           src/qtblegendproperties.ui \\
           src/qtblivegridlayerproperties.ui \\
           src/qtbmakeupfilter.ui \\
           src/qtbpaletteinterpole.ui \\
           src/qtbpaletteproperties.ui \\
           src/qtbpointproperties.ui \\
           src/qtbscifigspreferences.ui \\
           src/qtbtexteditproperties.ui \\
           src/qtbxycolorlinesproperties.ui \\
           src/qtbxynameplotproperties.ui \\
           src/qtbxyplotproperties.ui
FORMS_HEADERS += \\
           ui/ui_qtbaxisformatproperties.h \\
           ui/ui_qtbaxisproperties.h \\
           ui/ui_qtbaxisscaleproperties.h \\
           ui/ui_qtbdynlinelayerproperties.h \\
           ui/ui_qtbgraphcontentformatproperties.h \\
           ui/ui_qtbgraphcontentlayerproperties.h \\
           ui/ui_qtbgraphicobjectgeometryproperties.h \\
           ui/ui_qtbgraphicobjectidproperties.h \\
           ui/ui_qtbgraphicobjectprintproperties.h \\
           ui/ui_qtbgraphicsheetproperties.h \\
           ui/ui_qtbgridproperties.h \\
           ui/ui_qtbimagelayerproperties.h \\
           ui/ui_qtbimagescalingpoint.h \\
           ui/ui_qtbimagewidgetproperties.h \\
           ui/ui_qtblegendformatproperties.h \\
           ui/ui_qtblegendproperties.h \\
           ui/ui_qtblivegridlayerproperties.h \\
           ui/ui_qtbmakeupfilter.h \\
           ui/ui_qtbpaletteinterpole.h \\
           ui/ui_qtbpaletteproperties.h \\
           ui/ui_qtbpointproperties.h \\
           ui/ui_qtbscifigspreferences.h \\
           ui/ui_qtbtexteditproperties.h \\
           ui/ui_qtbxycolorlinesproperties.h \\
           ui/ui_qtbxynameplotproperties.h \\
           ui/ui_qtbxyplotproperties.h
TRANSLATIONS = lang/scifigs.fr.ts \\
               lang/scifigs.de.ts \\
               lang/scifigs.es.ts \\
               lang/scifigs.it.ts
END
echo "target.path = $LIBDIR"
echo "includes.files = \$\$HEADERS \$\$FORMS_HEADERS"
echo "includes.path = $INCDIR"
echo "INSTALLS += target includes"
cat << END
lang.path = $SHAREDIR/lang
lang.files = lang/scifigs.fr.qm \\
             lang/scifigs.de.qm \\
             lang/scifigs.es.qm \\
             lang/scifigs.it.qm
INSTALLS += lang
END
) > scifigs.pro.new
replaceFile scifigs.pro
###############################################################
# Generate .qrc file
###############################################################
echo "* Qt resource..."
(
cat << END
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
  <file>images/QtbAxisWindow.png</file>
  <file>images/QtbColorPaletteWidget.png</file>
  <file>images/QtbImageWidget.png</file>
  <file>images/QtbLegendWidget.png</file>
  <file>images/QtbTextEdit.png</file>
  <file>images/arrow_down.png</file>
  <file>images/arrow_up.png</file>
  <file>images/autolimits.png</file>
  <file>images/bdiagpattern-black-64x64.png</file>
  <file>images/cross.png</file>
  <file>images/editcopy.png</file>
  <file>images/editcursor.png</file>
  <file>images/editcut.png</file>
  <file>images/editpaste.png</file>
  <file>images/editredo.png</file>
  <file>images/editundo.png</file>
  <file>images/filenew.png</file>
  <file>images/fileopen4.png</file>
  <file>images/fileprint.png</file>
  <file>images/filesave4.png</file>
  <file>images/historgramcursor.png</file>
  <file>images/ordertool.png</file>
  <file>images/pickcursor.png</file>
  <file>images/pickorderedcursor.png</file>
  <file>images/qsa.png</file>
  <file>images/scalecursor.png</file>
  <file>images/selectcursor.png</file>
  <file>images/zoom.png</file>
  <file>images/zoomcursor.png</file>
</qresource>
</RCC>
END
) > scifigs.qrc.new
replaceFile scifigs.qrc
###############################################################
# Generate binary lang files
###############################################################
echo "* Qt translations..."
lrelease -silent scifigs.pro
###############################################################
# src/scifigsinstallpath.h file
###############################################################
echo "* src/scifigsinstallpath.h..."
(
cat << END
#ifndef SCIFIGS_INSTALL_PATHS
#define SCIFIGS_INSTALL_PATHS
#define SCIFIGS_BINDIR "$BINDIR"
#define SCIFIGS_LIBDIR "$LIBDIR"
#define SCIFIGS_INCDIR "$INCDIR"
#define SCIFIGS_SHAREDIR "$SHAREDIR"
#define SCIFIGS_DISTRIBUTION "$DISTRIBUTION"
#define SCIFIGS_BUILDTIME "$(date -u +%Y%m%d%H%M%S)"
#endif // SCIFIGS_INSTALL_PATHS
END
) > src/scifigsinstallpath.h.new
replaceFile src/scifigsinstallpath.h
###############################################################
# Generate Makefile
###############################################################
echo "* Makefile..."
qmake $QMAKE_SPEC
###############################################################
# Final user message
###############################################################
echo
if [ "$PLATFORM" = "MINGW" ]; then
  CONFIGURE_COMMAND="sh configure"
else
  CONFIGURE_COMMAND="./configure"
fi
echo "  scifigs is now configured for building, Just run 'make'."
echo "  Once everything is built, you must run either"
echo
echo "    $ su -c \"make install\", if root privileges are needed;"
echo "  or"
echo "    $ make install, if user permissions are sufficient."
echo
echo "  The current configuration options are stored in 'configure.cache'."
echo "  To change the configuration, run '$CONFIGURE_COMMAND [options]'."
echo
