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