Avoid overriding the check-local rule, hushing automake warning
[gnash.git] / macros / gnashpkgtool.m4
blobc16fe5ca95ab7633ab5d7b02be72f559ae359d42
1 dnl  
2 dnl    Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
3 dnl  
4 dnl  This program is free software; you can redistribute it and/or modify
5 dnl  it under the terms of the GNU General Public License as published by
6 dnl  the Free Software Foundation; either version 3 of the License, or
7 dnl  (at your option) any later version.
8 dnl  
9 dnl  This program is distributed in the hope that it will be useful,
10 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl  GNU General Public License for more details.
13 dnl  You should have received a copy of the GNU General Public License
14 dnl  along with this program; if not, write to the Free Software
15 dnl  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 dnl Generic macros for finding and setting include-paths and library-path
19 dnl for packages. Implements GNASH_PKG_INCLUDES() and GNASH_PKG_LIBS().
20 dnl 
21 dnl TODO:
22 dnl
23 dnl   - always run AC_CHECK_HEADERS and AC_CHECK_LIB so that config.h end
24 dnl     up with correct information about what's available and what not
25 dnl     and every provided info is verified before acceptance.
26 dnl
27 dnl   - Document the interface of the macro !!
28 dnl
30 AC_DEFUN([GNASH_PKG_INCLUDES],
32   pushdef([UP], translit([$1], [a-z], [A-Z]))dnl Uppercase
33   pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl Lowercase
34   pushdef([DASHDOWN], translit([$1], [A-Z_], [a-z-]))dnl Lowercase
35   pushdef([UPHEADER], translit([$2], [a-z./-], [A-Z___]))dnl Uppercase header
37     $1=yes
38     if test x$4 = x; then
39       name=DASHDOWN
40     else
41       name=DASHDOWN-$4
42     fi
43             
44     dnl Look for the header
45     if test x"${$1}" = x"yes"; then
46       AC_ARG_WITH($1_incl, AC_HELP_STRING([--with-$1-incl], [directory where $2 is]), with_$1_incl=${withval})
47       AC_CACHE_VAL(ac_cv_path_$1_incl, [
48       if test x"${with_$1_incl}" != x ; then
49         AC_MSG_CHECKING([for $2 header in specified directory])
50         if test -f ${with_$1_incl}/$2 ; then
51           ac_cv_path_$1_incl="-I`(cd ${with_$1_incl}; pwd)`"
52           found_$1_incl="yes"
53           AC_MSG_RESULT([yes])
54         else
55           AC_MSG_ERROR([${with_$1_incl} directory doesn't contain $2.])
56           AC_MSG_RESULT([no])
57         fi
58       fi
59     ])
61   if test x$cross_compiling = xno; then
62     if test x"$PKG_CONFIG" != x -a x"${ac_cv_path_$1_incl}" = x; then
63       AC_MSG_CHECKING([for $2 header using pkg-config])
64       $PKG_CONFIG --exists [lib]DASHDOWN && ac_cv_path_$1_incl="`$PKG_CONFIG --cflags [lib]DASHDOWN`"
65       $PKG_CONFIG --exists DASHDOWN[] && ac_cv_path_$1_incl="`$PKG_CONFIG --cflags DASHDOWN[]`"
66       $PKG_CONFIG --exists lib$name && ac_cv_path_$1_incl="`$PKG_CONFIG --cflags lib$name`"
67       $PKG_CONFIG --exists $name && ac_cv_path_$1_incl="`$PKG_CONFIG --cflags $name`"
68       if test x"${ac_cv_path_$1_incl}" != x; then
69         AC_MSG_RESULT(${ac_cv_path_$1_incl})
70         found_$1_incl="yes"
71       else
72         AC_MSG_RESULT([not found])
73       fi
74     fi
75     if test x"${ac_cv_path_$1_incl}" = x; then
76       AC_PATH_PROG(UP[]_CONFIG, $1-config)
77       if test x"${UP[]_CONFIG}" != x; then
78         AC_MSG_CHECKING([for $2 header using $1-config])
79         ac_cv_path_$1_incl="`${UP[]_CONFIG} --cxxflags 2>/dev/null`"
80         if test x"${ac_cv_path_$1_incl}" = x; then
81           ac_cv_path_$1_incl="`${UP[]_CONFIG} --cflags 2>/dev/null`"
82         fi
83         if test x"${ac_cv_path_$1_incl}" != x; then
84                 AC_MSG_RESULT(${ac_cv_path_$1_incl})
85                 found_$1_incl="yes"
86         else
87                 AC_MSG_RESULT([not found])
88         fi
89       fi
90     fi
91   fi
93   dnl If the path hasn't been specified, go look for it.
94   if test x"${ac_cv_path_$1_incl}" = x; then
95     AC_CHECK_HEADER($2, [ac_cv_path_$1_incl=""; found_$1_incl="yes"], [
96       AC_CHECK_HEADER($1/$2, [ac_cv_path_$1_incl="-I/usr/include/$1"; found_$1_incl="yes"], [
97         AC_CHECK_HEADER($name/$2, [ac_cv_path_$1_incl="-I/usr/include/$name"; found_$1_incl="yes"], [
98           AC_CHECK_HEADER($2, [ac_cv_path_$1_incl="-I/usr/include/$2"; found_$1_incl="yes"], [
99           if test x"${ac_cv_path_$1_incl}" = x; then
100             for i in $incllist; do
101               if test -f $i/$name; then
102                 found_$1_incl="yes"
103                 if test x"$i" != x"/usr/include"; then
104                   ac_cv_path_$1_incl="-I$i"
105                 else
106                   ac_cv_path_$1_incl=""
107                 fi
108                 break
109               else
110                 if test -f $i/$name/$2; then
111                   found_$1_incl="yes"
112                   ac_cv_path_$1_incl="-I$i/$name"
113                   break
114                 else
115                   if test -f $i/$2; then
116                     found_$1_incl="yes" 
117                     ac_cv_path_$1_incl="-I$i"
118                     break
119                   fi
120                 fi
121               fi
122             done
123           fi
124         ])
125       ])
126     ])
127   ])
128   fi
129   
130   AC_MSG_CHECKING([for $2 header]) 
131   if test x"${found_$1_incl}" = "xyes"; then
133       dnl It seems we need to explicitly call AC_DEFINE as AC_CHECK_HEADER doesn't
134       dnl do this automatically. AC_CHECK_HEADERS (not the final S) would do it.
135       AC_DEFINE([HAVE_]UPHEADER, 1, [Define if you have the $2 header])
136       AC_MSG_RESULT(${ac_cv_path_$1_incl})
137       if test x"${ac_cv_path_$1_incl}" != x -a x"${ac_cv_path_$1_incl}" != x"-I/usr/include"; then
138         UP[]_CFLAGS="${ac_cv_path_$1_incl}"        
139       else
140         UP[]_CFLAGS=""
141       fi
142   else
143           AC_MSG_RESULT([not found])
144     fi
145   fi
146   AC_SUBST(UP[]_CFLAGS)
148   popdef([UP])
149   popdef([DOWN])
150   popdef([DASHDOWN])
151   popdef([UPHEADER])
154 AC_DEFUN([GNASH_PKG_LIBS], dnl GNASH_PKG_LIBS(cairo, cairo_status, [cairo render library.])
156 pushdef([UP], translit([$1], [a-z], [A-Z]))dnl Uppercase
157 pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl Lowercase
158 pushdef([DASHDOWN], translit([$1], [A-Z_], [a-z-]))dnl Lowercase
160 has_$1=no
161 ac_manual=yes
163 if test x"${$1}" = x"yes"; then
164   dnl Look for the library
165   AC_ARG_WITH($1_lib, AC_HELP_STRING([--with-$1-lib], [directory where $1 library is]), with_$1_lib=${withval})
166   AC_CACHE_VAL(ac_cv_path_$1_lib,[
167   if test x"${with_$1_lib}" != x ; then
168     AC_MSG_CHECKING([for lib$1 library in specified directory])
169     if test -f ${with_$1_lib}/lib$name.a -o -f ${with_$1_lib}/lib$name.${shlibext}; then
170       tmp="`(cd ${with_$1_lib}; pwd)`"
171       ac_cv_path_$1_lib="-L${tmp} -l$name"
172       AC_MSG_RESULT([yes])
173           else
174       AC_MSG_ERROR([${with_$1_lib} directory doesn't contain library $name.])
175       AC_MSG_RESULT([no])
176           fi
177   fi
178   ])
180   dnl If the header doesn't exist, there is no point looking for the library.
181   if test x$cross_compiling = xno; then
182     if test x"$PKG_CONFIG" != x -a x"${ac_cv_path_$1_lib}" = x; then
183       AC_MSG_CHECKING([for lib$1 library using pkg-config])
184       $PKG_CONFIG --exists [lib]DASHDOWN && ac_cv_path_$1_lib="`$PKG_CONFIG --libs [lib]DASHDOWN`"
185       $PKG_CONFIG --exists DASHDOWN && ac_cv_path_$1_lib="`$PKG_CONFIG --libs DASHDOWN`"
186       $PKG_CONFIG --exists lib$name && ac_cv_path_$1_lib="`$PKG_CONFIG --libs lib$name`"
187       $PKG_CONFIG --exists $name && ac_cv_path_$1_lib="`$PKG_CONFIG --libs $name`"
188       if test x"${ac_cv_path_$1_lib}" != x; then
189         AC_MSG_RESULT(${ac_cv_path_$1_lib})
190         ac_manual=no
191       else
192         AC_MSG_RESULT([not found])
193       fi
194     fi
195     if test x"${ac_cv_path_$1_lib}" = x; then
196       AC_PATH_PROG(UP[]_CONFIG, $1-config)
197       if test x"${UP[]_CONFIG}" != x; then
198         AC_MSG_CHECKING([for lib$1 library using $1-config])
199         ac_cv_path_$1_lib="`${UP[]_CONFIG} --libs`"
200         AC_MSG_RESULT(${ac_cv_path_$1_lib})
201       fi
202       if test x"${ac_cv_path_$1_lib}" = x; then
203                 ac_manual=no
204       fi
205     fi
206   fi
207   
208   if test x"${ac_manual}" != xyes -a x"${ac_cv_path_$1_lib}" = x; then
209         ac_manual=yes
210   fi  
211   
212   if test x"${ac_cv_path_$1_lib}" = x; then
213     ac_save_LIBS=$LIBS
214     LIBS=""
215     for i in $libslist; do
216       if test -f $i/lib$1.a -o -f $i/lib$1.${shlibext}; then
217         if test -f "$i/lib$1.a" -o -f "$i/lib$1.${shlibext}"; then
218           if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
219             ac_cv_path_$1_lib="-L$i -l$1 $5"
220           else
221             ac_cv_path_$1_lib="-l$1 $5"
222           fi
223           break
224         fi
225       else
226         if test -f "$i/lib$name.a" -o -f "$i/lib$name.${shlibext}"; then
227           if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
228             ac_cv_path_$1_lib="-L$i -l$name $5"
229           else
230             ac_cv_path_$1_lib="-l$name $5"
231           fi
232         break
233         fi
234       fi
235     done
236     LIBS=$ac_save_LIBS
237   fi
239   if test x"${ac_cv_path_$1_lib}" = x ; then
240     AC_SEARCH_LIBS($2, $1 $name, [ac_cv_path_$1_lib="$LIBS $5"])
241   fi
242   
243   if test x"${ac_manual}" = xyes ; then
244         AC_MSG_CHECKING([for lib$1 library]) 
245         if test x"${ac_cv_path_$1_lib}" != x ; then
246     AC_MSG_RESULT(${ac_cv_path_$1_lib})
247         else
248     AC_MSG_RESULT([not found])
249     fi          
250   fi
251   
252   if test x"${ac_cv_path_$1_lib}" != x ; then
253     UP[]_LIBS="${ac_cv_path_$1_lib}"
254     has_$1=yes
255   else
256     UP[]_LIBS=""
257   fi
260 AC_SUBST(UP[]_LIBS)
262 popdef([UP])
263 popdef([DOWN])
264 popdef([DASHDOWN])
267 dnl Example: GNASH_PKG_FIND(fltk, [FL_API.h], [fltk gui], fl_xmap, [], [-lfltk_gl])
268 AC_DEFUN([GNASH_PKG_FIND],
270 GNASH_PKG_INCLUDES($1, $2, $3, $5)
271 GNASH_PKG_LIBS($1, $4, $3, $5, $6)
274 # Local Variables:
275 # c-basic-offset: 2
276 # tab-width: 2
277 # indent-tabs-mode: nil
278 # End: