1dnl
2dnl  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3dnl  2011 Free Software Foundation, Inc.
4dnl
5dnl  This program is free software; you can redistribute it and/or modify
6dnl  it under the terms of the GNU General Public License as published by
7dnl  the Free Software Foundation; either version 3 of the License, or
8dnl  (at your option) any later version.
9dnl
10dnl  This program is distributed in the hope that it will be useful,
11dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
12dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13dnl  GNU General Public License for more details.
14dnl  You should have received a copy of the GNU General Public License
15dnl  along with this program; if not, write to the Free Software
16dnl  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
19AC_DEFUN([GNASH_PATH_GLIB],
20[
21    dnl Look for the header
22  AC_ARG_WITH(glib_incl, AC_HELP_STRING([--with-glib-incl], [directory where libglib header is]), with_glib_incl=${withval})
23  AC_CACHE_VAL(ac_cv_path_glib_incl,[
24    if test x"${with_glib_incl}" != x ; then
25      if test -f ${with_glib_incl}/glib.h ; then
26        ac_cv_path_glib_incl="-I`(cd ${with_glib_incl}; pwd)`"
27        gnash_glib_topdir=`basename ${with_glib_incl}`
28        gnash_glib_version=`echo ${gnash_glib_topdir} | sed -e 's:glib-::'`
29      else
30    	  AC_MSG_ERROR([${with_glib_incl} directory doesn't contain glib.h])
31      fi
32    fi
33  ])
34
35  dnl Try with pkg-config
36  if test x${cross_compiling} = xno; then
37    if test x"$PKG_CONFIG" != x -a x"${ac_cv_path_glib_incl}" = x; then
38	    $PKG_CONFIG --exists glib-2.0 && gnash_glib_version=`$PKG_CONFIG --modversion glib-2.0`
39	    $PKG_CONFIG --exists glib-2.0 && ac_cv_path_glib_incl=`$PKG_CONFIG --cflags glib-2.0`
40    fi
41  fi
42
43  dnl Attempt to find the top level directory, which unfortunately has a
44  dnl version number attached. At least on Debain based systems, this
45  dnl doesn't seem to get a directory that is unversioned.
46  AC_MSG_CHECKING([for Glib header])
47  if test x"${ac_cv_path_glib_incl}" = x -a x"${gnash_glib_version}" = x; then
48    gnash_glib_topdir=""
49    gnash_glib_version=""
50    for i in $incllist; do
51      for j in `ls -dr $i/glib-[[0-9]].[[0-9]] $i/glib/glib-[[0-9]].[[0-9]] 2>/dev/null`; do
52        if test -f $j/glib.h; then
53          gnash_glib_topdir=`basename $j`
54          gnash_glib_version=`echo ${gnash_glib_topdir} | sed -e 's:glib-::'`
55          ac_cv_path_glib_incl="-I$j"
56          gnash_glib_config=`echo $j | sed -e 's:include:lib:' -e 's:lib/glib/:lib/:'`
57          if test -f ${gnash_glib_config}/include/glibconfig.h; then
58            ac_cv_path_glib_incl="${ac_cv_path_glib_incl} -I${gnash_glib_config}/include"
59          fi
60          break 2
61        fi
62      done
63    done
64  fi
65
66  if test x"${ac_cv_path_glib_incl}" = x; then
67    AC_MSG_RESULT(no)
68  else
69    AC_MSG_RESULT(${ac_cv_path_glib_incl})
70  fi
71
72
73  dnl Look for the library
74  AC_ARG_WITH(glib_lib, AC_HELP_STRING([--with-glib-lib], [directory where glib library is]), with_glib_lib=${withval})
75  AC_CACHE_VAL(ac_cv_path_glib_lib,[
76    if test x"${with_glib_lib}" != x ; then
77      if test -f ${with_glib_lib}/libglib-${gnash_glib_version}.a -o -f ${with_glib_lib}/libglib-${gnash_glib_version}.${shlibext}; then
78        ac_cv_path_glib_lib="-L`(cd ${with_glib_lib}; pwd)` -lglib-${gnash_glib_version}"
79      else
80        AC_MSG_ERROR([${with_glib_lib} directory doesn't contain libglib.])
81      fi
82    fi
83  ])
84
85  if test x${cross_compiling} = xno; then
86    if test x"$PKG_CONFIG" != x -a x"${ac_cv_path_glib_lib}" = x; then
87      $PKG_CONFIG --exists glib-2.0 && ac_cv_path_glib_lib=`$PKG_CONFIG --libs glib-2.0`
88    fi
89  fi
90
91  AC_MSG_CHECKING([for glib library])
92  if test x"${ac_cv_path_glib_lib}" = x; then
93    for i in $libslist; do
94      if test -f $i/libglib-${gnash_glib_version}.a -o -f $i/libglib-${gnash_glib_version}.${shlibext}; then
95        if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64" -a ! x"$i" = x"/usr"; then
96          ac_cv_path_glib_lib="-L$i -lglib-${gnash_glib_version}"
97          break
98        else
99          ac_cv_path_glib_lib="-lglib-${gnash_glib_version}"
100          break
101        fi
102      fi
103    done
104  fi
105  AC_MSG_RESULT(${ac_cv_path_glib_lib})
106
107  if test x"${ac_cv_path_glib_incl}" != x; then
108	  GLIB_CFLAGS="${ac_cv_path_glib_incl} $GLIB_CFLAGS"
109	  AC_DEFINE([HAVE_GLIB], [1], [Has GLIB library installed])
110  else
111	  GLIB_CFLAGS=""
112  fi
113
114  if test x"${ac_cv_path_glib_lib}" != x ; then
115	  GLIB_LIBS="${ac_cv_path_glib_lib}"
116  else
117  	GLIB_LIBS=""
118  fi
119
120  AC_SUBST(GLIB_CFLAGS)
121  AC_SUBST(GLIB_LIBS)
122])
123
124# Local Variables:
125# c-basic-offset: 2
126# tab-width: 2
127# indent-tabs-mode: nil
128# End:
129