Merge branch 'master' into release_0_8_9
[gnash.git] / macros / gnashpkgtool.m4
blobef636a3deed5e96b03ec18846568349ed814f915
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"; 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     if test -f ${with_$1_lib}/lib$name.a -o -f ${with_$1_lib}/lib$name.${shlibext}; then
171       tmp="`(cd ${with_$1_lib}; pwd)`"
172       ac_cv_path_$1_lib="-L${tmp} -l$name"
173       AC_MSG_RESULT([yes])
174           else
175       AC_MSG_ERROR([${with_$1_lib} directory doesn't contain library $name.])
176       AC_MSG_RESULT([no])
177           fi
178   fi
179   ])
181   dnl If the header doesn't exist, there is no point looking for the library.
182   if test x$cross_compiling = xno; then
183     if test x"$PKG_CONFIG" != x -a x"${ac_cv_path_$1_lib}" = x; then
184       AC_MSG_CHECKING([for lib$1 library using pkg-config])
185       $PKG_CONFIG --exists [lib]DASHDOWN && ac_cv_path_$1_lib="`$PKG_CONFIG --libs [lib]DASHDOWN`"
186       $PKG_CONFIG --exists DASHDOWN && ac_cv_path_$1_lib="`$PKG_CONFIG --libs DASHDOWN`"
187       $PKG_CONFIG --exists lib$name && ac_cv_path_$1_lib="`$PKG_CONFIG --libs lib$name`"
188       $PKG_CONFIG --exists $name && ac_cv_path_$1_lib="`$PKG_CONFIG --libs $name`"
189       if test x"${ac_cv_path_$1_lib}" != x; then
190         AC_MSG_RESULT(${ac_cv_path_$1_lib})
191         ac_manual=no
192       else
193         AC_MSG_RESULT([not found])
194       fi
195     fi
196     if test x"${ac_cv_path_$1_lib}" = x; then
197       AC_PATH_PROG(UP[]_CONFIG, $1-config)
198       if test x"${UP[]_CONFIG}" != x; then
199         AC_MSG_CHECKING([for lib$1 library using $1-config])
200         ac_cv_path_$1_lib="`${UP[]_CONFIG} --libs`"
201         AC_MSG_RESULT(${ac_cv_path_$1_lib})
202       fi
203       if test x"${ac_cv_path_$1_lib}" = x; then
204                 ac_manual=no
205       fi
206     fi
207   fi
208   
209   if test x"${ac_manual}" != xyes -a x"${ac_cv_path_$1_lib}" = x; then
210         ac_manual=yes
211   fi  
212   
213   if test x"${ac_cv_path_$1_lib}" = x; then
214     ac_save_LIBS=$LIBS
215     LIBS=""
216     for i in $libslist; do
217       if test -f $i/lib$1.a -o -f $i/lib$1.${shlibext}; then
218         if test -f "$i/lib$1.a" -o -f "$i/lib$1.${shlibext}"; then
219           if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
220             ac_cv_path_$1_lib="-L$i -l$1 $5"
221           else
222             ac_cv_path_$1_lib="-l$1 $5"
223           fi
224           break
225         fi
226       else
227         if test -f "$i/lib$name.a" -o -f "$i/lib$name.${shlibext}"; then
228           if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
229             ac_cv_path_$1_lib="-L$i -l$name $5"
230           else
231             ac_cv_path_$1_lib="-l$name $5"
232           fi
233         break
234         fi
235       fi
236     done
237     LIBS=$ac_save_LIBS
238   fi
240   if test x"${ac_cv_path_$1_lib}" = x ; then
241     AC_SEARCH_LIBS($2, $1 $name, [ac_cv_path_$1_lib="$LIBS $5"])
242   fi
243   
244   if test x"${ac_manual}" = xyes ; then
245         AC_MSG_CHECKING([for lib$1 library]) 
246         if test x"${ac_cv_path_$1_lib}" != x ; then
247     AC_MSG_RESULT(${ac_cv_path_$1_lib})
248         else
249     AC_MSG_RESULT([not found])
250     fi          
251   fi
252   
253   if test x"${ac_cv_path_$1_lib}" != x ; then
254     UP[]_LIBS="${ac_cv_path_$1_lib}"
255     has_$1=yes
256   else
257     UP[]_LIBS=""
258   fi
261 AC_SUBST(UP[]_LIBS)
263 popdef([UP])
264 popdef([DOWN])
265 popdef([DASHDOWN])
268 dnl Example: GNASH_PKG_FIND(fltk, [FL_API.h], [fltk gui], fl_xmap, [], [-lfltk_gl])
269 AC_DEFUN([GNASH_PKG_FIND],
271 GNASH_PKG_INCLUDES($1, $2, $3, $5)
272 GNASH_PKG_LIBS($1, $4, $3, $5, $6)
275 # Local Variables:
276 # c-basic-offset: 2
277 # tab-width: 2
278 # indent-tabs-mode: nil
279 # End: