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