##
## Copyright (C) 2004-2009  Autodesk, Inc.
## 
## This library is free software; you can redistribute it and/or
## modify it under the terms of version 2.1 of the GNU Lesser
## General Public License as published by the Free Software Foundation.
## 
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## Lesser General Public License for more details.
## 
## You should have received a copy of the GNU Lesser General Public
## License along with this library; if not, write to the Free Software
## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
##

#------------------configure.in----------------------------------------
dnl Configure.in for OSGeo FDO Core (Fdo, Utilities, Thirdparty)
#----------------------------------------------------------------------
# Variables
# Following are the makefile directories 
#----------------------------------------------------------------------
AC_INIT(FDO,4.2.0,http://fdo.osgeo.org)
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR(configure.in)
AM_INIT_AUTOMAKE([subdir-objects])

# We need C++11 support
m4_include([m4/ax_cxx_compile_stdcxx.m4])
AX_CXX_COMPILE_STDCXX([11], [ext], [mandatory])

# Enable silent rules if supported. Allows for less verbose output while still displaying any compiler/linker warnings/errors
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])

AC_PREFIX_DEFAULT(/usr/local/fdo-4.2.0)

AC_LANG_C
AC_PROG_CC
AC_LANG_CPLUSPLUS
AC_PROG_CXX
AC_PROG_YACC
AC_DISABLE_STATIC
AM_PROG_LIBTOOL

AC_SUBST(VERSION, "4.2.0")

dnl *******************************************************
dnl FDO 4.2.0 Configuration
dnl FDO / FDO Utilities / FDO Thirdpary paths
dnl *******************************************************
# custom Fdo path specification 

AC_ARG_WITH([fdo],
	    FDO_HELP_STRING([--with-fdo],
              	        [specifies directory for FDO API files [[default=DEFAULT]]]),
		[custom_fdo=$withval],
		[custom_fdo=DEFAULT])

if test $custom_fdo = "DEFAULT"; then
  FDO="$PWD"/Fdo
  if test -d $FDO; then
  	AC_MSG_NOTICE([Building with default location of FDO API files at $FDO])
  else
 	AC_MSG_ERROR([The default FDO API path $FDO is not a vsvn checkout https://fdocore.osgeo.org/svn/fdocore/trunkalid directory. Please use the custom option])
  fi
else 
  if test -d $custom_fdo; then
  	FDO="$custom_fdo"
  	AC_MSG_NOTICE([Building with custom location of FDO API directory at $FDO])
  else 
	AC_MSG_ERROR([The specified FDO API path $custom_fdo is not a valid directory])
  fi
fi

AC_ARG_WITH([fdo-utilities],
	    FDO_HELP_STRING([--with-fdo-utilities],
              	        [specifies directory for FDO API Utility files [[default=DEFAULT]]]),
		[custom_fdo_utilities=$withval],
		[custom_fdo_utilities=DEFAULT])

if test $custom_fdo_utilities = "DEFAULT"; then
  FDOUTILITIES="$PWD/Utilities"
  if test -d $FDOUTILITIES; then
  	AC_MSG_NOTICE([Building with default location of FDO Utility files at $FDOUTILITIES])
  else
 	AC_MSG_ERROR([the default FDO Utilities path $FDOUTILITIES is not a valid directory. Please use the custom option])
  fi
else 
  if test -d $custom_fdo_utilities; then
  	FDOUTILITIES="$custom_fdo_utilities"
  	AC_MSG_NOTICE([Building with custom location of FDO Utilities directory at $FDOUTILITIES])
  else 
	AC_MSG_ERROR([The specified FDO Utilities path $custom_fdo_utilities is not a valid directory])
  fi
fi

AC_ARG_WITH([fdo-thirdparty],
	    FDO_HELP_STRING([--with-fdo-thirdparty],
              	        [specifies directory for FDO API Thirdparty files [[default=DEFAULT]]]),
		[custom_fdo_thirdparty=$withval],
		[custom_fdo_thirdparty=DEFAULT])

if test $custom_fdo_thirdparty = "DEFAULT"; then
  FDOTHIRDPARTY="$PWD/Thirdparty"
  if test -d $FDOTHIRDPARTY; then
  	AC_MSG_NOTICE([Building with default location of FDO Thirdparty files at $FDOTHIRDPARTY])
  else
 	AC_MSG_ERROR([The default FDO Thirdparty path $custom_fdo_thirdparty is not a valid directory. Please use the custom option])
  fi
else 
  if test -d $custom_fdo_thirdparty; then
  	FDOTHIRDPARTY="$custom_fdo_thirdparty"
  	AC_MSG_NOTICE([Building with custom location of FDO Thirdperty directory at $FDOTHIRDPARTY])
  else 
	AC_MSG_ERROR([The specified FDO Thirdparty path $custom_fdo_thirdparty is not a valid directory])
  fi
fi

AC_SUBST(FDO)
AC_SUBST(FDOUTILITIES)
AC_SUBST(FDOTHIRDPARTY)

# Check for Debug or Release build settings
AC_ARG_ENABLE([debug],
               FDO_HELP_STRING([--enable-debug],
              	             [enable debug build [[default=no]]]),
	      	             [enable_debug=$enableval],
	      	             [enable_debug=no])

if test $enable_debug = yes; then
 AC_MSG_NOTICE([Using debug configuration])
 CXXFLAGS="-g -MMD -MT "
 AC_SUBST(CXXFLAGS, ["-g -MMD -MT "])
else
 AC_MSG_NOTICE([Using optimized configuration])
 CXXFLAGS="-O2 -MMD -MT "
 AC_SUBST(CXXFLAGS, ["-O2 -MMD -MT "])
fi

##output Makefiles##
AC_CONFIG_FILES(Makefile)
AC_CONFIG_FILES(Fdo/Makefile)
AC_CONFIG_FILES(Utilities/Makefile)
AC_CONFIG_FILES(Thirdparty/Makefile)

#############################################
## Fdo
#############################################
#Unmanaged: Src Inc
#Src: McToMsf Message FileToHdr Nls Common Geometry Spatial Fdo
AC_CONFIG_FILES([Fdo/Unmanaged/Makefile \
                 Fdo/Unmanaged/Src/Makefile \
                 Fdo/Unmanaged/Src/McToMsf/Makefile \
                 Fdo/Unmanaged/Src/Message/Makefile \
                 Fdo/Unmanaged/Src/FileToHdr/Makefile \
                 Fdo/Unmanaged/Src/Nls/Makefile \
                 Fdo/Unmanaged/Src/Common/Makefile \
                 Fdo/Unmanaged/Src/Geometry/Makefile \
                 Fdo/Unmanaged/Src/Spatial/Makefile \
                 Fdo/Unmanaged/Src/Fdo/Makefile \
                 Fdo/Unmanaged/Inc/Makefile])

#Managed
AC_CONFIG_FILES(Fdo/Managed/Makefile)

#fdo: Install
AC_CONFIG_FILES([Fdo/Install/Makefile \
                 Fdo/Install/XsdInstallPaths/Makefile])

#fdo: Docs
AC_CONFIG_FILES([Fdo/Docs/Makefile \
                 Fdo/Docs/doc_src/Makefile \
                 Fdo/Docs/doc_src/group_and_page_definitions/Makefile \
                 Fdo/Docs/doc_src/headers_and_footers/Makefile \
                 Fdo/Docs/XmlSchema/Makefile])

#fdo: UnitTest
AC_CONFIG_FILES(Fdo/UnitTest/Makefile)

#############################################
## Utilities
#############################################
#FdoCommon
AC_CONFIG_FILES([Utilities/Common/Makefile])

#TestCommon
AC_CONFIG_FILES([Utilities/TestCommon/Makefile])

#SQLiteInterface
AC_CONFIG_FILES([Utilities/SQLiteInterface/Makefile])

#OWS
AC_CONFIG_FILES([Utilities/OWS/Makefile \
                 Utilities/OWS/Src/Makefile])

#ExpressionEngine
AC_CONFIG_FILES([Utilities/ExpressionEngine/Makefile \
                 Utilities/ExpressionEngine/Src/Makefile \
                 Utilities/ExpressionEngine/Inc/Makefile])


#SchemaMgr
AC_CONFIG_FILES([Utilities/SchemaMgr/Makefile \
                 Utilities/SchemaMgr/Inc/Makefile \
                 Utilities/SchemaMgr/Nls/Makefile \
                 Utilities/SchemaMgr/Src/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Lp/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Ov/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Ph/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Ph/Cfg/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Ph/Mt/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Ph/Rb/Makefile \
                 Utilities/SchemaMgr/Src/Sm/Ph/Rd/Makefile])


AC_OUTPUT