#! /bin/sh
#                                               -*- Shell-script -*-
#
#  openturns-config-build.in / openturns-config-build / openturns-config
#
#  Copyright 2005-2017 Airbus-EDF-IMACS-Phimeca
#
#  Permission to copy, use, modify, sell and distribute this software
#  is granted provided this copyright notice appears in all copies.
#  This software is provided "as is" without express or implied
#  warranty, and with no claim as to its suitability for any purpose.
#
#
#
#  This script provides external information on how and where OpenTURNS is installed
#

# Set this variable to yes if the script is located in its target directory
installed=yes

# The installation process renames the script (by removing an extra -build to its name)
case $0 in
  *-build) installed=no ;;
esac

abs_top_srcdir=/home/travis/build/openturns/build/openturns
top_srcdir=/home/travis/build/openturns/build/openturns
srcdir=/home/travis/build/openturns/build/openturns/lib/src
top_builddir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32

version=1.9
bugreport=bugs@openturns.org
package=openturns

#swig=
R=/home/travis/build/openturns/build/openturns/distro/windows/openturns-developers-windeps/opt/R-2.12.0/bin/R.exe

win32=1

prefix=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install
exec_prefix=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install
bindir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install//bin
sbindir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install//bin
libdir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install//lib
libexecdir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install//lib
sysconfdir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/etc
datarootdir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share/$package
mandir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share
localedir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share
infodir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share
datadir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share
m4dir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share/m4
includedir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/include
localstatedir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share
sharedstatedir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/share

pkgincludedir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/include
pkglibdir=/home/travis/build/openturns/build/openturns/build-x86_64-w64-mingw32/install/lib
pkgswigdir=$pkgincludedir/swig

if test $installed = yes 
then
  cppflags="-I$pkgincludedir  -I/home/travis/build/openturns/build/openturns/distro/windows/openturns-developers-windeps/mingw-w64-x86_64/usr/x86_64-w64-mingw32/lib/cmake/hmat/../../../include/hmat -I/home/travis/build/openturns/build/openturns/distro/windows/openturns-developers-windeps/mingw-w64-x86_64/usr/x86_64-w64-mingw32/include/libxml2"

  if test "$win32" = 1
  then
    ldflags="-L$bindir "
  else
    ldflags="-L$pkglibdir "
  fi 
  libs="-lOT "
  swigflags="-I$pkgswigdir "
else
  cppflags=`echo '' | sed -e 's/\$(\([^)]*\))/${\1}/g'`
  ldflags=`echo '' | sed -e 's/\$(\([^)]*\))/${\1}/g'`
  libs=`echo '' | sed -e 's/\$(\([^)]*\))/${\1}/g'`
fi

CC="/home/travis/build/openturns/build/openturns/distro/windows/openturns-developers-windeps/mingw-w64-x86_64/usr/bin/x86_64-w64-mingw32-gcc"
CXX="/home/travis/build/openturns/build/openturns/distro/windows/openturns-developers-windeps/mingw-w64-x86_64/usr/bin/x86_64-w64-mingw32-g++"
F77="x86_64-w64-mingw32-gfortran"

########################################

print_usage()
{
  cat <<EOT
Usage: $0 [option]
where option is:
[misc]
 --help            This help
 --installed       Return non-zero value if project is not installed yet (development version)

[paths]
 --prefix          Print 'prefix' directory
 --exec-prefix     Print 'exec-prefix' directory
 --bindir          Print 'bindir' directory
 --sbindir         Print 'sbindir' directory
 --libdir          Print 'libdir' directory
 --libexecdir      Print 'libexecdir' directory
 --sysconfdir      Print 'sysconfdir' directory
 --datarootdir     Print 'datarootdir' directory
 --mandir          Print 'mandir' directory
 --localedir       Print 'localedir' directory
 --infodir         Print 'infodir' directory
 --datadir         Print 'datadir' directory
 --includedir      Print 'includedir' directory
 --localstatedir   Print 'localstatedir' directory
 --sharedstatedir  Print 'sharedstatedir' directory
 --m4dir           Print autoconf m4 directory

[project]
 --version         Print version number
 --bugreport       Print bug report mail
 --package         Print package name

[tools]
 --R               Print R path
 --R-version       Print R version

[flags]
 --cppflags        Print CPPFLAGS
 --ldflags         Print LDFLAGS
 --libs            Print LIBS
 --swigflags       Print SWIGFLAGS
 --cc              Print CC
 --cxx             Print CXX
 --f77             Print F77

EOT
  return 1
}

print_prefix()
{
  echo ${prefix}
  return 0
}

print_exec_prefix()
{
  echo ${exec_prefix}
  return 0
}

print_bindir()
{
  echo ${bindir}
  return 0
}

print_sbindir()
{
  echo ${sbindir}
  return 0
}

print_libdir()
{
  echo ${libdir}
  return 0
}

print_libexecdir()
{
  echo ${libexecdir}
  return 0
}

print_datarootdir()
{
  echo ${datarootdir}
  return 0
}

print_mandir()
{
  echo ${mandir}
  return 0
}

print_localedir()
{
  echo ${localedir}
  return 0
}

print_infodir()
{
  echo ${infodir}
  return 0
}

print_datadir()
{
  echo ${datadir}
  return 0
}

print_includedir()
{
  echo ${includedir}
  return 0
}

print_sysconfdir()
{
  echo ${sysconfdir}
  return 0
}

print_localstatedir()
{
  echo ${localstatedir}
  return 0
}

print_sharedstatedir()
{
  echo ${sharedstatedir}
  return 0
}

print_m4dir()
{
  echo ${m4dir}
  return 0
}

print_version()
{
  echo ${version}
  return 0
}

print_bugreport()
{
  echo ${bugreport}
  return 0
}

print_package()
{
  echo ${package}
  return 0
}

is_installed()
{
  test $installed = yes && return 0
  return 1
}

print_cppflags()
{
  echo ${cppflags}
  return 0
}

print_ldflags()
{
  echo ${ldflags}
  return 0
}

print_libs()
{
  echo ${libs}
  return 0
}

print_swigflags()
{
  echo ${swigflags}
  return 0
}

# print_swig()
# {
#   echo ${swig}
#   return 0
# }

# print_swig_version()
# {
#   test -x ${swig} || return 1
#   ${swig} -version | awk 'BEGIN {IGNORECASE=1;} /version/ && /[0-9]+\.[0-9]+\.[0-9]+/ {match($0,/[0-9]+\.[0-9]+\.[0-9]+/);print substr($0,RSTART,RLENGTH);}'
#   return 0
# }

print_R()
{
  echo ${R}
  return 0
}

print_R_version()
{
  test -x ${R} || return 1
  ${R} --version | awk 'BEGIN {IGNORECASE=1;} /version/ && /[0-9]+\.[0-9]+\.[0-9]+/ {match($0,/[0-9]+\.[0-9]+\.[0-9]+/);print substr($0,RSTART,RLENGTH);}'
  return 0
}

print_CC()
{
  echo ${CC}
  return 0
}

print_CXX()
{
  echo ${CXX}
  return 0
}

print_F77()
{
  echo ${F77}
  return 0
}

########################################

# The return code of this script (0=OK, 1=Error)
rc=0

test $# != 1 && { print_usage ; rc=$? ; exit 1 ; }

opt=$1
case $opt in
  "--help") print_usage ; rc=$? ;;

  "--prefix") print_prefix ; rc=$? ;;
  "--exec-prefix") print_exec_prefix ; rc=$? ;;
  "--bindir") print_bindir ; rc=$? ;;
  "--sbindir") print_sbindir ; rc=$? ;;
  "--libdir") print_libdir ; rc=$? ;;
  "--libexecdir") print_libexecdir ; rc=$? ;;
  "--datarootdir") print_datarootdir ; rc=$? ;;
  "--mandir") print_mandir ; rc=$? ;;
  "--localedir") print_localedir ; rc=$? ;;
  "--infodir") print_infodir ; rc=$? ;;
  "--datadir") print_datadir ; rc=$? ;;
  "--includedir") print_includedir ; rc=$? ;;
  "--sysconfdir") print_sysconfdir ; rc=$? ;;
  "--localstatedir") print_localstatedir ; rc=$? ;;
  "--sharedstatedir") print_sharedstatedir ; rc=$? ;;
  "--m4dir") print_m4dir ; rc=$? ;;

  "--version") print_version ; rc=$? ;;
  "--bugreport") print_bugreport ; rc=$? ;;
  "--package") print_package ; rc=$? ;;

  # "--swig") print_swig ; rc=$? ;;
  # "--swig-version") print_swig_version ; rc=$? ;;
  "--R") print_R ; rc=$? ;;
  "--R-version") print_R_version ; rc=$? ;;

  "--installed") is_installed ; rc=$? ;;

  "--cppflags") print_cppflags ; rc=$? ;;
  "--ldflags") print_ldflags ; rc=$? ;;
  "--libs") print_libs ; rc=$? ;;
  "--swigflags") print_swigflags ; rc=$? ;;
  "--cc") print_CC ; rc=$? ;;
  "--cxx") print_CXX ; rc=$? ;;
  "--f77") print_F77 ; rc=$? ;;

 *) print_usage ; rc=$? ; echo "Error: unknown option '$opt'" ;;
esac

exit $rc
