Merge branch 'new_eth' of http://gnuradio.org/git/eb into new_eth
[debian/gnuradio] / config / gr_qwt.m4
index 3481873b7400840f10390140c7fafd9da4f7558a..16ec63819def72c53d4dc5034af55077b8f89084 100644 (file)
@@ -1,11 +1,11 @@
 dnl
 dnl
-dnl Copyright 2007 Free Software Foundation, Inc.
+dnl Copyright 2007,2008 Free Software Foundation, Inc.
 dnl 
 dnl This file is part of GNU Radio
 dnl 
 dnl GNU Radio is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
 dnl 
 dnl This file is part of GNU Radio
 dnl 
 dnl GNU Radio is free software; you can redistribute it and/or modify
 dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 2, or (at your option)
+dnl the Free Software Foundation; either version 3, or (at your option)
 dnl any later version.
 dnl 
 dnl GNU Radio is distributed in the hope that it will be useful,
 dnl any later version.
 dnl 
 dnl GNU Radio is distributed in the hope that it will be useful,
@@ -21,7 +21,7 @@ dnl
 
 dnl Configure paths for library qwt.
 dnl
 
 dnl Configure paths for library qwt.
 dnl
-dnl GR_PATH_QWT([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
+dnl GR_QWT([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
 dnl
 dnl Test for library qwt, set QWT_CFLAGS and QWT_LIBS if found. Assumes 
 dnl QT_CFLAGS and QT_LIBS have already been correctly set.
 dnl
 dnl Test for library qwt, set QWT_CFLAGS and QWT_LIBS if found. Assumes 
 dnl QT_CFLAGS and QT_LIBS have already been correctly set.
@@ -29,12 +29,17 @@ dnl
 
 AC_DEFUN([GR_QWT],
 [
 
 AC_DEFUN([GR_QWT],
 [
+    dnl QWT Library Version
+    QWT_LIBRARY1=-lqwt-qt4
+    QWT_LIBRARY2=-lqwt
+
     dnl Save the environment
     AC_LANG_PUSH(C++)
     qwt_save_CPPFLAGS="$CPPFLAGS"
     qwt_save_LIBS="$LIBS"
     libqwt_ok=yes
 
     dnl Save the environment
     AC_LANG_PUSH(C++)
     qwt_save_CPPFLAGS="$CPPFLAGS"
     qwt_save_LIBS="$LIBS"
     libqwt_ok=yes
 
+    dnl QWT Info
     dnl Allow user to specify where QWT files are
     AC_ARG_WITH([qwt-libdir],
                [  --with-qwt-libdir=path  Prefix where QWT library is installed (optional)],
     dnl Allow user to specify where QWT files are
     AC_ARG_WITH([qwt-libdir],
                [  --with-qwt-libdir=path  Prefix where QWT library is installed (optional)],
@@ -43,41 +48,89 @@ AC_DEFUN([GR_QWT],
     AC_ARG_WITH([qwt-incdir],
                [  --with-qwt-incdir=path  Prefix where QWT include files are (optional)],
                [qwt_incdir="$withval"], [qwt_incdir=""])
     AC_ARG_WITH([qwt-incdir],
                [  --with-qwt-incdir=path  Prefix where QWT include files are (optional)],
                [qwt_incdir="$withval"], [qwt_incdir=""])
+    AC_ARG_WITH([qwt-lib],
+               [  --with-qwt-lib=library  QWT library name (optional)],
+               [qwt_lib="$withval"], [qwt_lib=""])
+
+    dnl Check for presence of header files
+    dnl if not user-specified, try the first include dir (Ubuntu), then
+    dnl try the second include dir (Fedora)
+    CPPFLAGS="$CPPFLAGS $QTCORE_CFLAGS"
 
 
-    dnl Create QWT_CFLAGS based on user input
-    AC_MSG_CHECKING(QWT_CFLAGS)
-    if test "$qwt_incdir" != "" ; then
+    dnl if not set by user
+    if test "$qwt_incdir" = "" ; then
+        dnl check qwt/qwt.h (as in Fedora)
+        AC_CHECK_HEADER(
+            [qwt/qwt.h],
+           [qwt_qwt_h=yes],
+            [qwt_qwt_h=no]
+        )
+        dnl If it was found, set the flags and move on
+        if test "$qwt_qwt_h" = "yes" ; then
+            QWT_CFLAGS="$QWT_CFLAGS -I/usr/include/qwt"
+        else
+            dnl otherwise, check qwt-qt4/qwt.h (as in Ubuntu)
+            AC_CHECK_HEADER(
+                [qwt-qt4/qwt.h],
+                [qwt_qt4_qwt_h=yes],
+                [qwt_qt4_qwt_h=no]
+            )
+            dnl if it was found, set the flags and move on
+            if test "$qwt_qt4_qwt_h" = "yes" ; then
+                QWT_CFLAGS="$QWT_CFLAGS -I/usr/include/qwt-qt4"
+            else
+                dnl otherwise, qwt.h wasn't found, so set the flag to no
+                libqwt_ok=no
+            fi
+        fi
+    else
+       dnl Using the user-specified include directory
        QWT_CFLAGS="$QWT_CFLAGS -I$qwt_incdir"
        QWT_CFLAGS="$QWT_CFLAGS -I$qwt_incdir"
+        AC_CHECK_HEADER(
+            [$qwt_incdir/qwt.h],
+           [],
+           [libqwt_ok=no])
     fi
     fi
-    AC_MSG_RESULT($QWT_CFLAGS)
-    
-    dnl Set CPPFLAGS so C++ tests can operate
-    CPPFLAGS="$CPPFLAGS $QT_CFLAGS $QWT_CFLAGS"
 
 
-    dnl Check for presence of header files
-    AC_CHECK_HEADERS([qwt/qwt.h], 
-                    [],
-                    [libqwt_ok=no;AC_MSG_RESULT([cannot find usable qwt headers])]
-    )
-
-    dnl Set QWT_LIBS based on user input
-    AC_MSG_CHECKING(QWT_LIBS)
-    QWT_LIBS="-lqwt"
-    if test "$qwt_libdir" != "" ; then
-       QWT_LIBS="$QWT_LIBS -L$qwt_libdir"
+    dnl Don't bother going on if we can't find the headers
+    if test "$libqwt_ok" = "yes" ; then
+
+        dnl Check for QWT library (qwt or qwt-qt4)
+
+        dnl User-defined QWT library path
+        if test "$qwt_libdir" != "" ; then
+            QWT_LIBS="-L$qwt_libdir $QWT_LIBS"
+        fi
+
+        dnl temporarily set these so the AC_CHECK_LIB works
+        CPPFLAGS="$CPPFLAGS $QWT_CFLAGS"
+        LIBS="$qwt_save_LIBS $QT_LIBS $QWT_LIBS -lqwt"
+
+        dnl If the user specified a qwt library name, use it here
+        if test "$qwt_lib" != "" ; then
+            AC_CHECK_LIB([$qwt_lib], [main], [libqwt_ok=yes], [libqwt_ok=no])
+
+        else            
+            dnl Check for 'main' in libqwt (Fedora)
+            AC_CHECK_LIB([qwt], [main], [libqwt_ok=yes], [libqwt_ok=no])
+
+            dnl If library found properly, set the flag and move on
+            if test "$libqwt_ok" = "yes" ; then
+                QWT_LIBS="$QWT_LIBS -lqwt"
+            else
+                dnl Otherwise, check for 'main' in libqwt-qt4 (Ubuntu)
+                LIBS="$qwt_save_LIBS $QT_LIBS $QWT_LIBS -lqwt-qt4"
+                AC_CHECK_LIB([qwt-qt4], [main], [libqwt_ok=yes], [libqwt_ok=no])
+                if test "$libqwt_ok" = "yes" ; then
+                    QWT_LIBS="$QWT_LIBS -lqwt-qt4"
+                else
+                    AC_MSG_RESULT([Could not link to libqwt.so])
+                fi
+            fi
+        fi
+    else
+        AC_MSG_RESULT([Could not find qwt headers])
     fi
     fi
-    AC_MSG_RESULT($QWT_LIBS)
-
-    dnl Set LIBS so C++ link test can operate
-    LIBS="$QWT_LIBS $QT_LIBS $LIBS"
-
-    dnl Check that library files can be linked in
-    dnl This references an arbitrary static class method 
-    AC_TRY_LINK([#include <qwt/qwt_text.h>],
-               [Qt::TextFormat tf = QwtText::defaultFormat()],
-               [],
-                [libqwt_ok=no]
-    )
 
     dnl Restore saved variables
     LIBS="$qwt_save_LIBS"
 
     dnl Restore saved variables
     LIBS="$qwt_save_LIBS"