070afc7e41feeeacef22317b23ca6cdeaaef4d0b
[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 ## D-Bus
98 AC_DEFUN([SXE_CHECK_DBUS], [dnl
99         ## Check for d-bus
100         PKG_CHECK_MODULES([DBUS], [dbus-1], [dnl
101                 AC_SUBST([DBUS_CFLAGS])
102                 AC_SUBST([DBUS_LIBS])
103                 AC_DEFINE([HAVE_DBUS], [1], [Defined if d-bus is available])
104                 have_dbus=yes], [dnl
105                 have_dbus=no])
106 ])dnl SXE_CHECK_DBUS
107
108 AC_DEFUN([SXE_FFI_TRY_PKGCONFIG], [dnl
109         ## arg1 what to do in case of success
110         ## arg2 what to do in case of failure
111         pushdef([MM_SUCC], [$1])
112         pushdef([MM_FAIL], [$2])
113
114         AC_REQUIRE([SXE_CHECK_PKGCONFIG])
115         if test "$sxe_cv_prog_pkg_config" = "no" -o -z "$PKG_CONFIG"; then
116                 AS_MESSAGE([*** pkg-config not found.])
117                 AS_MESSAGE([*** Cannot check for FFI with pkg-config.])
118                 sxe_cv_feat_ffi="no"
119                 MM_FAIL
120         else
121                 SXE_CHECK_HEADERS([ffi.h])
122                 SXE_PC_CHECK_EXISTS([libffi])
123                 SXE_PC_CHECK_VERSION([libffi])
124                 SXE_PC_CHECK_CPPFLAGS([libffi])
125                 SXE_PC_CHECK_LDFLAGS([libffi])
126                 SXE_PC_CHECK_LIBS([libffi])
127                 SXE_DUMP_LIBS
128                 CPPFLAGS="$CPPFLAGS $FFI_CPPFLAGS"
129                 if test "$ac_cv_header_ffi_h" = "yes"; then
130                         AC_CHECK_LIB([ffi], [ffi_call], [dnl
131                                 sxe_cv_feat_ffi="yes"
132                                 have_ffi="yes"], [:])
133                 fi
134                 SXE_RESTORE_LIBS
135                 if test "$ac_cv_header_ffi_h" = "yes" -a \
136                         "$ac_cv_lib_ffi_ffi_call" = "yes"; then
137                         MM_SUCC
138                 fi
139         fi
140
141         popdef([MM_SUCC])
142         popdef([MM_FAIL])
143 ])dnl SXE_FFI_TRY_PKGCONFIG
144
145 AC_DEFUN([SXE_FFI_TRY_STANDARD_PREFIX], [dnl
146         ## arg1 what to do in case of success
147         ## arg2 what to do in case of failure
148         ## defines sxe_cv_feat_ffi
149         pushdef([MM_SUCC], [$1])
150         pushdef([MM_FAIL], [$2])
151
152         SXE_CHECK_HEADERS([ffi.h])
153         if test "$ac_cv_header_ffi_h" != "yes"; then
154                 sxe_cv_feat_ffi="no"
155                 MM_FAIL
156         else
157                 sxe_cv_feat_ffi="yes"
158                 MM_SUCC
159         fi
160
161         popdef([MM_SUCC])
162         popdef([MM_FAIL])
163 ])dnl SXE_FFI_TRY_STANDARD_PREFIX
164
165 AC_DEFUN([_SXE_FFI_TRY_GCC_PREFIX], [dnl
166         ## arg 1 is the path we should try
167         ## defines sxe_cv_cc_ffi_path
168         ## assumes to be called in a (shell) for-loop
169         pushdef([_FFI_PATH], [$1])
170
171         sxe_cv_cc_ffi_path=${sxe_cv_cc_ffi_path:-[]_FFI_PATH[]}
172         AC_MSG_CHECKING([for ffi headers in])
173         if test -n "${sxe_cv_cc_ffi_path}" -a \
174                 -d "${sxe_cv_cc_ffi_path}"; then
175                 SXE_CANONICALISE_PATH([sxe_cv_cc_ffi_path])
176
177                 AC_MSG_RESULT([${sxe_cv_cc_ffi_path}])
178
179                 FFI_CPPFLAGS="-I${sxe_cv_cc_ffi_path}"
180                 SXE_DUMP_LIBS
181                 CPPFLAGS="$CPPFLAGS $FFI_CPPFLAGS"
182                 SXE_CHECK_HEADERS([ffi.h])
183                 SXE_RESTORE_LIBS
184         else
185                 AC_MSG_RESULT([non-existing directory ${sxe_cv_cc_ffi_path}])
186         fi
187
188         if test "$ac_cv_header_ffi_h" != "yes"; then
189                 unset ac_cv_header_ffi_h
190                 unset sxe_cv_cc_ffi_path
191                 FFI_CPPFLAGS=
192         else
193                 break
194         fi
195
196         popdef([_FFI_PATH])
197 ])dnl _SXE_FFI_TRY_GCC_PREFIX
198
199 AC_DEFUN([SXE_FFI_TRY_GCC_PREFIX], [dnl
200         ## arg1 what to do in case of success
201         ## arg2 what to do in case of failure
202         ## maybe defines FFI_CPPFLAGS
203         ## defines sxe_cv_feat_ffi
204         ## assumes CC points to a gcc
205
206         pushdef([MM_SUCC], [$1])
207         pushdef([MM_FAIL], [$2])
208
209         for i in \
210                 pushdef([libffi_a_fn], [$($CC -print-file-name=libffi.a)])dnl
211                 pushdef([libgcc_a_fn], [$($CC -print-libgcc-file-name)])dnl
212                 pushdef([cc_version], [$($CC -dumpversion)])dnl
213                 "$(dirname []libffi_a_fn[])/include/libffi" \
214                 "$(dirname []libffi_a_fn[])/../include" \
215                 "$(dirname []libffi_a_fn[])/../[]cc_version[]/include" \
216                 "$(dirname []libffi_a_fn[])/../../[]cc_version[]/include" \
217                 "$(dirname []libgcc_a_fn[])/include/libffi" \
218                 "$(dirname []libgcc_a_fn[])/../include" \
219                 "$(dirname []libgcc_a_fn[])/../[]cc_version[]/include" \
220                 "$(dirname []libgcc_a_fn[])/../../[]cc_version[]/include"
221                 popdef([cc_version])dnl
222                 popdef([libgcc_a_fn])dnl
223                 popdef([libffi_a_fn])dnl
224         do
225                 _SXE_FFI_TRY_GCC_PREFIX([$i])
226         done
227
228         if test "$ac_cv_header_ffi_h" != "yes"; then
229                 sxe_cv_feat_ffi="no"
230                 MM_FAIL
231         else
232                 sxe_cv_feat_ffi="yes"
233                 MM_SUCC
234         fi
235
236         popdef([MM_SUCC])
237         popdef([MM_FAIL])
238 ])dnl SXE_FFI_TRY_GCC_PREFIX
239
240 AC_DEFUN([SXE_CHECK_FFI], [dnl
241         ## defines sxe_cv_feat_ffi (by side effect)
242         ## defines have_ffi
243
244         SXE_FFI_TRY_PKGCONFIG([ffi_from_pkgconfig=yes], [:])
245         if test "$ffi_from_pkgconfig" != "yes"; then
246                 SXE_FFI_TRY_STANDARD_PREFIX([:], [unset ac_cv_header_ffi_h])
247                 if test "$sxe_cv_feat_ffi" = "no" -a \
248                         "$GCC" = "yes"; then
249                         SXE_FFI_TRY_GCC_PREFIX([:], [dnl
250                                 AC_MSG_WARN([GCC FFI not found.])])
251                 fi
252
253                 AC_CHECK_LIB([ffi], [ffi_call], [:], [dnl
254                         AC_MSG_WARN([Cannot find a usable libffi, not compiling FFI support])])
255                 if test "$ac_cv_header_ffi_h" = "yes" -a \
256                         "$ac_cv_lib_ffi_ffi_call" = "yes"; then
257                         sxe_cv_feat_ffi="yes"
258                         have_ffi="yes"
259                         FFI_LIBS=-lffi
260                 else
261                         sxe_cv_feat_ffi="no"
262                         have_ffi="no"
263                 fi
264         fi
265
266         AC_SUBST([FFI_CPPFLAGS])
267         AC_SUBST([FFI_LDFLAGS])
268         AC_SUBST([FFI_LIBS])
269 ])dnl SXE_CHECK_FFI
270
271
272 AC_DEFUN([SXE_CHECK_DLOPEN], [
273         have_dlopen=no
274         try_on=yes
275         SXE_CHECK_HEADERS([dlfcn.h])
276
277         if test "$ac_cv_header_dlfcn_h" != "yes"; then
278                 try_on=no
279         else
280                 AC_MSG_CHECKING([for dlopen in -lc])
281                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
282                         [[
283                         #include <dlfcn.h>
284                         ]],
285                         [[dlopen ("", 0);]])], [
286                         AC_MSG_RESULT([yes])
287                         have_dlopen=yes], [
288                         AC_MSG_RESULT([no])
289                         have_dlopen=no])
290         fi
291
292         if test "$have_dlopen" = "yes" -o "$try_on" = "no"; then
293                 try_on=no
294         else
295                 AC_MSG_CHECKING([for dlopen in -ldl])
296                 ac_save_LIBS="$LIBS"
297                 LIBS="$LIBS -ldl"
298                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
299                         [[
300                         #include <dlfcn.h>
301                         ]],
302                         [[dlopen ("", 0);]])], [
303                         AC_MSG_RESULT([yes])
304                         have_dlopen=yes], [
305                         AC_MSG_RESULT([no])
306                         have_dlopen=no])
307         fi
308
309         if test "$have_dlopen" = "yes" -o "$try_on" = "no"; then
310                 try_on=no
311         else
312                 AC_MSG_CHECKING([for dlopen in -lsvld])
313                 LIBS="$ac_save_LIBS -lsvld"
314                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
315                         [[
316                         #include <dlfcn.h>
317                         ]],
318                         [[dlopen ("", 0);]])], [
319                         AC_MSG_RESULT([yes])
320                         have_dlopen=yes], [
321                         AC_MSG_RESULT([no])
322                         have_dlopen=no])
323         fi
324
325         if test "$have_dlopen" = "yes"; then
326                 AC_DEFINE([HAVE_DLOPEN], [1], [Description here!])
327                 have_dl=yes
328         else
329                 LIBS="$ac_save_LIBS"
330         fi
331 ])dnl SXE_CHECK_DL
332
333 AC_DEFUN([SXE_CHECK_SHL_LOAD], [
334         dnl Check for HP/UX shl_load
335         have_shl_load=no
336         try_on=yes
337         SXE_CHECK_HEADERS([dl.h])
338
339         if test "$ac_cv_header_dl_h" != "yes"; then
340                 try_on=no
341         else
342                 AC_MSG_CHECKING([for shl_load in -lc])
343                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
344                         [[
345                         #include <dl.h>
346                         ]],
347                         [[shl_load ("", 0, 0);]])], [
348                         AC_MSG_RESULT([yes])
349                         have_shl_load=yes], [
350                         AC_MSG_RESULT([no])
351                         have_shl_load=no])
352         fi
353
354         if test "$have_shl_load" = "yes" -o "$try_on" = "no"; then
355                 try_on=no
356         else
357                 AC_MSG_CHECKING([for shl_load in -ldl])
358                 ac_save_LIBS="$LIBS"
359                 LIBS="$LIBS -ldld"
360                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
361                         [[
362                         #include <dl.h>
363                         ]],
364                         [[shl_load ("", 0, 0);]])], [
365                         AC_MSG_RESULT([yes])
366                         have_shl_load=yes], [
367                         AC_MSG_RESULT([no])
368                         have_shl_load=no])
369         fi
370
371         if test "$have_shl_load" = "yes"; then
372                 AC_DEFINE([HAVE_SHL_LOAD], [1], [Description here!])
373                 have_dl=yes
374         else
375                 LIBS="$ac_save_LIBS"
376         fi
377 ])dnl SXE_CHECK_SHL_LOAD
378
379 AC_DEFUN([SXE_CHECK_LT_DLINIT], [
380         dnl Check for libtool's libltdl
381         have_lt_dlinit=no
382         try_on=yes
383         SXE_CHECK_HEADERS([ltdl.h])
384
385         if test "$ac_cv_header_ltdl_h" != "yes"; then
386                 try_on=no
387         else
388                 AC_MSG_CHECKING([for lt_dlinit in -lltdl])
389                 ac_save_LIBS="$LIBS"
390                 LIBS="$LIBS -lltdl"
391                 AC_LINK_IFELSE([AC_LANG_PROGRAM(
392                         [[
393                         #include <ltdl.h>
394                         ]],
395                         [[lt_dlinit ();]])], [
396                         AC_MSG_RESULT([yes])
397                         have_lt_dlinit=yes], [
398                         AC_MSG_RESULT([no])
399                         have_lt_dlinit=no])
400         fi
401
402         if test "$have_lt_dlinit" = "yes"; then
403                 AC_DEFINE([HAVE_LTDL], [1], [Description here!])
404                 have_dl=yes
405         else
406                 LIBS="$ac_save_LIBS"
407         fi
408 ])dnl SXE_CHECK_LT_DLINIT
409
410
411 dnl sxe-emodffi.m4 ends here