dnl Process this file with autoconf to produce a configure script.
dnl ====================================================================
dnl
dnl     configure.in
dnl
dnl     configure script for eCos USB host-side support
dnl
dnl ====================================================================
dnl ####ECOSGPLCOPYRIGHTBEGIN####                                           
dnl -------------------------------------------                             
dnl This file is part of eCos, the Embedded Configurable Operating System.  
dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005 Free Software Foundation, Inc.
dnl
dnl eCos is free software; you can redistribute it and/or modify it under   
dnl the terms of the GNU General Public License as published by the Free    
dnl Software Foundation; either version 2 or (at your option) any later     
dnl version.                                                                
dnl
dnl eCos is distributed in the hope that it will be useful, but WITHOUT     
dnl ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or   
dnl FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   
dnl for more details.                                                       
dnl
dnl You should have received a copy of the GNU General Public License       
dnl along with eCos; if not, write to the Free Software Foundation, Inc.,   
dnl 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.           
dnl
dnl As a special exception, if other files instantiate templates or use     
dnl macros or inline functions from this file, or you compile this file     
dnl and link it with other works to produce a work based on this file,      
dnl this file does not by itself cause the resulting work to be covered by  
dnl the GNU General Public License. However the source code for this file   
dnl must still be made available in accordance with section (3) of the GNU  
dnl General Public License v2.                                              
dnl
dnl This exception does not invalidate any other reasons why a work based   
dnl on this file might be covered by the GNU General Public License.        
dnl -------------------------------------------                             
dnl ####ECOSGPLCOPYRIGHTEND####                                             
dnl ====================================================================
dnl#####DESCRIPTIONBEGIN####
dnl
dnl Author(s):	bartv
dnl Contact(s):	bartv
dnl Date:	2002/01/10
dnl Version:	0.01
dnl
dnl####DESCRIPTIONEND####
dnl ====================================================================


AC_INIT(usbhost.c)

dnl Pick up the support files from the top-level acsupport directory.
AC_CONFIG_AUX_DIR(../../../../../../acsupport)

ECOS_CHECK_BUILD_ne_SRC
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE(usbhost,0.1,0)
AM_MAINTAINER_MODE
AC_PROG_CC
AC_PROG_LN_S
AC_OBJEXT
AC_EXEEXT
ECOS_PROG_STANDARD_COMPILER_FLAGS

dnl The current version of the USB testing support depends on 
dnl functionality provided only by Linux platforms, and has only been
dnl tested on x86 machines, so a test is appropriate here. However
dnl it is not a good idea for the configure script to report an error:
dnl that would prevent any top-level configury working for other
dnl platforms. Instead an automake conditional is used to suppress adding
dnl targets to the build.
case "${host}" in
    *-*-linux-gnu* ) SUPPORTED="yes";;
    * ) SUPPORTED="no"
esac

if test "${SUPPORTED}" = "no" ; then
    AC_MSG_WARN([USB testing is only supported on Linux hosts])
else   

    
    ECOS_PACKAGE_DIRS

    ECOS_PATH_TCL
    dnl Check that the version of tcl is sufficiently recent.
    dnl e.g. "end" only became a valid index for the
    dnl string commands after 8.1
    if test "${TK_MAJOR_VERSION}" = "8" ; then
        if test ${TK_MINOR_VERSION} -lt 2 ; then
	    AC_MSG_WARN([Version 8.2 or greater of Tcl/Tk is required])
	    SUPPORTED="no"
        fi
    fi
    if test "${SUPPORTED}" = "yes" ; then
        AC_CHECK_HEADERS("linux/usb/ch9.h" "linux/usbdevice_fs.h",,SUPPORTED="no")
        if test "${SUPPORTED}" = "no" ; then
	    AC_MSG_WARN([Required Linux kernel functionality does not appear to be available])
	else
	  AC_TRY_COMPILE([
	          #include <linux/usbdevice_fs.h>
              ], [
	          static struct usbdevfs_ctrltransfer xx = { .bRequestType = 0 };
	      ],
	          AC_DEFINE(CYGBLD_USE_NEW_FIELD_NAMES,[1],["use later version of Linux usb data structures])
	      )
        fi
    fi
fi
	
if test "${SUPPORTED}" = "no" ; then
    AC_MSG_WARN([The USB testing support cannot be built on this platform.])
fi
	
AM_CONDITIONAL(SUPPORTED, test "${SUPPORTED}" = "yes")

AM_CONFIG_HEADER(config.h:config.h.in)
AC_OUTPUT(Makefile:Makefile.in)
