Make sure that the args array is initialized
[sxemacs] / m4 / sxe-emodffi.m4
1 dnl sxe-emodffi.m4 -- Everything that extends SXE functionality on the fly
2 dnl
3 dnl Copyright (C) 2006-2008 Sebastian Freundt
4 dnl
5 dnl Author: Sebastian Freundt <hroptatyr@sxemacs.org>
6 dnl
7 dnl Redistribution and use in source and binary forms, with or without
8 dnl modification, are permitted provided that the following conditions
9 dnl are met:
10 dnl
11 dnl 1. Redistributions of source code must retain the above copyright
12 dnl    notice, this list of conditions and the following disclaimer.
13 dnl
14 dnl 2. Redistributions in binary form must reproduce the above copyright
15 dnl    notice, this list of conditions and the following disclaimer in the
16 dnl    documentation and/or other materials provided with the distribution.
17 dnl
18 dnl 3. Neither the name of the author nor the names of any contributors
19 dnl    may be used to endorse or promote products derived from this
20 dnl    software without specific prior written permission.
21 dnl
22 dnl THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
23 dnl IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 dnl WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 dnl DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 dnl FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 dnl CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 dnl SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
29 dnl BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 dnl WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
31 dnl OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
32 dnl IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 dnl
34 dnl This file is part of SXEmacs.
35
36 dnl module voodoo
37 AC_DEFUN([SXE_REGISTER_MODULE], [dnl
38         ## arg #1 is module name
39         pushdef([emodname], [$1])
40         pushdef([EMODNAME], [translit([$1], [a-z], [A-Z])])
41
42         AM_CONDITIONAL([DESCEND_]EMODNAME, [dnl
43                 test "$have_static_modules_[]emodname[]" = "yes" -o \
44                 "$have_modules_[]emodname[]" = "yes"])
45         AC_CONFIG_FILES([modules/]emodname[/Makefile])
46
47         popdef([EMODNAME])
48         popdef([emodname])
49 ])
50
51 AC_DEFUN([SXE_EMOD], [dnl
52         ## arg #1 is module name
53         ## arg #2 is short description (unused atm)
54         pushdef([emodname], [$1])
55         pushdef([EMODNAME], [translit([$1], [a-z], [A-Z])])
56
57         SXE_REGISTER_MODULE([$1])
58         AM_CONDITIONAL([EMOD_]EMODNAME, [dnl
59                 test "$have_modules_[]emodname[]" = "yes"])
60
61         popdef([EMODNAME])
62         popdef([emodname])
63 ])dnl SXE_EMOD
64
65 AC_DEFUN([SXE_STATMOD], [dnl
66         ## arg #1 is module name
67         ## arg #2 is short description (unused atm)
68         pushdef([emodname], [$1])
69         pushdef([EMODNAME], [translit([$1], [a-z], [A-Z])])
70
71         SXE_REGISTER_MODULE([$1])
72         if test "$have_module_support" = "yes" -a \
73                 "$have_static_modules_[]emodname[]" = "yes"; then
74                 AC_DEFINE([USE_STATIC_]EMODNAME, [1], [dnl
75                         Whether to use the module] emodname [statically])
76                 SXE_ADD_STATMOD_A([$emodblddir/]emodname[/lib]emodname[.a])
77                 echo "syms_of_[]emodname[]();" >> emod_static_syms.c
78                 echo "vars_of_[]emodname[]();" >> emod_static_vars.c
79         fi
80         AM_CONDITIONAL([STATIC_]EMODNAME, [dnl
81                 test "$have_static_modules_[]emodname[]" = "yes"])
82
83         popdef([EMODNAME])
84         popdef([emodname])
85 ])dnl SXE_STATMOD
86
87 AC_DEFUN([SXE_EMOD_STATMOD], [dnl
88         ## arg #1 is module name
89         ## arg #2 is short description
90         SXE_REGISTER_MODULE([$1])
91         pushdef([SXE_REGISTER_MODULE], [])
92         SXE_EMOD([$1], [$2])
93         SXE_STATMOD([$1], [$2])
94         popdef([SXE_REGISTER_MODULE])
95 ])dnl SXE_EMOD_STATMOD
96
97 AC_DEFUN([SXE_FFI_TRY_PKGCONFIG], [dnl
98         ## arg1 what to do in case of success
99         ## arg2 what to do in case of failure
100         pushdef([MM_SUCC], [$1])
101         pushdef([MM_FAIL], [$2])
102
103         AC_REQUIRE([SXE_CHECK_PKGCONFIG])
104         if test "$sxe_cv_prog_pkg_config" = "no" -o -z "$PKG_CONFIG"; then
105                 AS_MESSAGE([*** pkg-config not found.])
106                 AS_MESSAGE([*** Cannot check for FFI with pkg-config.])
107                 sxe_cv_feat_ffi="no"
108                 MM_FAIL
109         else
110                 FFI_CPPFLAGS=$($PKG_CONFIG --cflags libffi)
111                 FFI_LIBS=$($PKG_CONFIG --libs libffi)
112                 SXE_DUMP_LIBS
113                 CPPFLAGS="$CPPFLAGS $FFI_CPPFLAGS"
114                 SXE_CHECK_HEADERS([ffi.h])
115                 if test "$ac_cv_header_ffi_h" = "yes"; then
116                         AC_CHECK_LIB([ffi], [ffi_call], [dnl
117                                 sxe_cv_feat_ffi="yes"
118                                 have_ffi="yes"], [:])
119                 fi
120                 SXE_RESTORE_LIBS
121                 if test "$ac_cv_header_ffi_h" = "yes" -a \
122                         "$ac_cv_lib_ffi_ffi_call" = "yes"; then
123                         MM_SUCC
124                 fi
125         fi
126
127         popdef([MM_SUCC])
128         popdef([MM_FAIL])
129 ])dnl SXE_FFI_TRY_PKGCONFIG
130
131 AC_DEFUN([SXE_FFI_TRY_STANDARD_PREFIX], [dnl
132         ## arg1 what to do in case of success
133         ## arg2 what to do in case of failure
134         ## defines sxe_cv_feat_ffi
135         pushdef([MM_SUCC], [$1])
136         pushdef([MM_FAIL], [$2])
137
138         SXE_CHECK_HEADERS([ffi.h])
139         if test "$ac_cv_header_ffi_h" != "yes"; then
140                 sxe_cv_feat_ffi="no"
141                 MM_FAIL
142         else
143                 sxe_cv_feat_ffi="yes"
144                 MM_SUCC
145         fi
146
147         popdef([MM_SUCC])
148         popdef([MM_FAIL])
149 ])dnl SXE_FFI_TRY_STANDARD_PREFIX
150
151 AC_DEFUN([_SXE_FFI_TRY_GCC_PREFIX], [dnl
152         ## arg 1 is the path we should try
153         ## defines sxe_cv_cc_ffi_path
154         ## assumes to be called in a (shell) for-loop
155         pushdef([_FFI_PATH], [$1])
156
157         sxe_cv_cc_ffi_path=${sxe_cv_cc_ffi_path:-[]_FFI_PATH[]}
158         AC_MSG_CHECKING([for ffi headers in])
159         if test -n "${sxe_cv_cc_ffi_path}" -a \
160                 -d "${sxe_cv_cc_ffi_path}"; then
161                 SXE_CANONICALISE_PATH([sxe_cv_cc_ffi_path])
162
163                 AC_MSG_RESULT([${sxe_cv_cc_ffi_path}])
164
165                 FFI_CPPFLAGS="-I${sxe_cv_cc_ffi_path}"
166                 SXE_DUMP_LIBS
167                 CPPFLAGS="$CPPFLAGS $FFI_CPPFLAGS"
168                 SXE_CHECK_HEADERS([ffi.h])
169                 SXE_RESTORE_LIBS
170         else
171                 AC_MSG_RESULT([non-existing directory ${sxe_cv_cc_ffi_path}])
172         fi
173
174         if test "$ac_cv_header_ffi_h" != "yes"; then
175                 unset ac_cv_header_ffi_h
176                 unset sxe_cv_cc_ffi_path
177                 FFI_CPPFLAGS=
178         else
179                 break
180         fi
181
182         popdef([_FFI_PATH])
183 ])dnl _SXE_FFI_TRY_GCC_PREFIX
184
185 AC_DEFUN([SXE_FFI_TRY_GCC_PREFIX], [dnl
186         ## arg1 what to do in case of success
187         ## arg2 what to do in case of failure
188         ## maybe defines FFI_CPPFLAGS
189         ## defines sxe_cv_feat_ffi
190         ## assumes CC points to a gcc
191
192         pushdef([MM_SUCC], [$1])
193         pushdef([MM_FAIL], [$2])
194
195         for i in \
196                 pushdef([libffi_a_fn], [$($CC -print-file-name=libffi.a)])dnl
197                 pushdef([libgcc_a_fn], [$($CC -print-libgcc-file-name)])dnl
198                 pushdef([cc_version], [$($CC -dumpversion)])dnl
199                 "$(dirname []libffi_a_fn[])/include/libffi" \
200                 "$(dirname []libffi_a_fn[])/../include" \
201                 "$(dirname []libffi_a_fn[])/../[]cc_version[]/include" \
202                 "$(dirname []libffi_a_fn[])/../../[]cc_version[]/include" \
203                 "$(dirname []libgcc_a_fn[])/include/libffi" \
204                 "$(dirname []libgcc_a_fn[])/../include" \
205                 "$(dirname []libgcc_a_fn[])/../[]cc_version[]/include" \
206                 "$(dirname []libgcc_a_fn[])/../../[]cc_version[]/include"
207                 popdef([cc_version])dnl
208                 popdef([libgcc_a_fn])dnl
209                 popdef([libffi_a_fn])dnl
210         do
211                 _SXE_FFI_TRY_GCC_PREFIX([$i])
212         done
213
214         if test "$ac_cv_header_ffi_h" != "yes"; then
215                 sxe_cv_feat_ffi="no"
216                 MM_FAIL
217         else
218                 sxe_cv_feat_ffi="yes"
219                 MM_SUCC
220         fi
221
222         popdef([MM_SUCC])
223         popdef([MM_FAIL])
224 ])dnl SXE_FFI_TRY_GCC_PREFIX
225
226 AC_DEFUN([SXE_CHECK_FFI], [dnl
227         ## defines sxe_cv_feat_ffi (by side effect)
228         ## defines have_ffi
229
230         SXE_FFI_TRY_PKGCONFIG([ffi_from_pkgconfig=yes], [:])
231         if test "$ffi_from_pkgconfig" != "yes"; then
232                 SXE_FFI_TRY_STANDARD_PREFIX([:], [unset ac_cv_header_ffi_h])
233                 if test "$sxe_cv_feat_ffi" = "no" -a \
234                         "$GCC" = "yes"; then
235                         SXE_FFI_TRY_GCC_PREFIX([:], [dnl
236                                 AC_MSG_WARN([GCC FFI not found.])])
237                 fi
238
239                 AC_CHECK_LIB([ffi], [ffi_call], [:], [dnl
240                         AC_MSG_WARN([Cannot find a usable libffi, not compiling FFI support])])
241                 if test "$ac_cv_header_ffi_h" = "yes" -a \
242                         "$ac_cv_lib_ffi_ffi_call" = "yes"; then
243                         sxe_cv_feat_ffi="yes"
244                         have_ffi="yes"
245                         FFI_LIBS=-lffi
246                 else
247                         sxe_cv_feat_ffi="no"
248                         have_ffi="no"
249                 fi
250         fi
251
252         AC_SUBST([FFI_CPPFLAGS])
253         AC_SUBST([FFI_LDFLAGS])
254         AC_SUBST([FFI_LIBS])
255 ])dnl SXE_CHECK_FFI
256
257
258 AC_DEFUN([SXE_CHECK_DLOPEN], [
259         have_dlopen=no
260         try_on=yes
261         SXE_CHECK_HEADERS([dlfcn.h])
262
263         if test "$ac_cv_header_dlfcn_h" != "yes"; then
264                 try_on=no
265         else
266                 AC_MSG_CHECKING([for dlopen in -lc])
267                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
268                         [[
269                         #include <dlfcn.h>
270                         ]],
271                         [[dlopen ("", 0);]])], [
272                         AC_MSG_RESULT([yes])
273                         have_dlopen=yes], [
274                         AC_MSG_RESULT([no])
275                         have_dlopen=no])
276         fi
277
278         if test "$have_dlopen" = "yes" -o "$try_on" = "no"; then
279                 try_on=no
280         else
281                 AC_MSG_CHECKING([for dlopen in -ldl])
282                 ac_save_LIBS="$LIBS"
283                 LIBS="$LIBS -ldl"
284                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
285                         [[
286                         #include <dlfcn.h>
287                         ]],
288                         [[dlopen ("", 0);]])], [
289                         AC_MSG_RESULT([yes])
290                         have_dlopen=yes], [
291                         AC_MSG_RESULT([no])
292                         have_dlopen=no])
293         fi
294
295         if test "$have_dlopen" = "yes" -o "$try_on" = "no"; then
296                 try_on=no
297         else
298                 AC_MSG_CHECKING([for dlopen in -lsvld])
299                 LIBS="$ac_save_LIBS -lsvld"
300                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
301                         [[
302                         #include <dlfcn.h>
303                         ]],
304                         [[dlopen ("", 0);]])], [
305                         AC_MSG_RESULT([yes])
306                         have_dlopen=yes], [
307                         AC_MSG_RESULT([no])
308                         have_dlopen=no])
309         fi
310
311         if test "$have_dlopen" = "yes"; then
312                 AC_DEFINE([HAVE_DLOPEN], [1], [Description here!])
313                 have_dl=yes
314         else
315                 LIBS="$ac_save_LIBS"
316         fi
317 ])dnl SXE_CHECK_DL
318
319 AC_DEFUN([SXE_CHECK_SHL_LOAD], [
320         dnl Check for HP/UX shl_load
321         have_shl_load=no
322         try_on=yes
323         SXE_CHECK_HEADERS([dl.h])
324
325         if test "$ac_cv_header_dl_h" != "yes"; then
326                 try_on=no
327         else
328                 AC_MSG_CHECKING([for shl_load in -lc])
329                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
330                         [[
331                         #include <dl.h>
332                         ]],
333                         [[shl_load ("", 0, 0);]])], [
334                         AC_MSG_RESULT([yes])
335                         have_shl_load=yes], [
336                         AC_MSG_RESULT([no])
337                         have_shl_load=no])
338         fi
339
340         if test "$have_shl_load" = "yes" -o "$try_on" = "no"; then
341                 try_on=no
342         else
343                 AC_MSG_CHECKING([for shl_load in -ldl])
344                 ac_save_LIBS="$LIBS"
345                 LIBS="$LIBS -ldld"
346                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
347                         [[
348                         #include <dl.h>
349                         ]],
350                         [[shl_load ("", 0, 0);]])], [
351                         AC_MSG_RESULT([yes])
352                         have_shl_load=yes], [
353                         AC_MSG_RESULT([no])
354                         have_shl_load=no])
355         fi
356
357         if test "$have_shl_load" = "yes"; then
358                 AC_DEFINE([HAVE_SHL_LOAD], [1], [Description here!])
359                 have_dl=yes
360         else
361                 LIBS="$ac_save_LIBS"
362         fi
363 ])dnl SXE_CHECK_SHL_LOAD
364
365 AC_DEFUN([SXE_CHECK_LT_DLINIT], [
366         dnl Check for libtool's libltdl
367         have_lt_dlinit=no
368         try_on=yes
369         SXE_CHECK_HEADERS([ltdl.h])
370
371         if test "$ac_cv_header_ltdl_h" != "yes"; then
372                 try_on=no
373         else
374                 AC_MSG_CHECKING([for lt_dlinit in -lltdl])
375                 ac_save_LIBS="$LIBS"
376                 LIBS="$LIBS -lltdl"
377                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
378                         [[
379                         #include <ltdl.h>
380                         ]],
381                         [[lt_dlinit ();]])], [
382                         AC_MSG_RESULT([yes])
383                         have_lt_dlinit=yes], [
384                         AC_MSG_RESULT([no])
385                         have_lt_dlinit=no])
386         fi
387
388         if test "$have_lt_dlinit" = "yes"; then
389                 AC_DEFINE([HAVE_LTDL], [1], [Description here!])
390                 have_dl=yes
391         else
392                 LIBS="$ac_save_LIBS"
393         fi
394 ])dnl SXE_CHECK_LT_DLINIT
395
396
397 dnl sxe-emodffi.m4 ends here