summaryrefslogtreecommitdiff
path: root/m4/common/efl_check_funcs.m4
blob: d72fb34344e70068670129bb0898e4083cc39c42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
dnl Copyright (C) 2012 Vincent Torri <vincent dot torri at gmail dot com>
dnl This code is public domain and can be freely used or copied.

dnl Macros that check functions availability for the EFL:

dnl dirfd
dnl dladdr
dnl dlopen
dnl fnmatch
dnl iconv
dnl setxattr (an al.)
dnl shm_open


dnl _EFL_CHECK_FUNC_DIRFD is for internal use
dnl _EFL_CHECK_FUNC_DIRFD(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_DIRFD],
[
AC_LINK_IFELSE(
   [
    AC_LANG_PROGRAM(
       [[
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
       ]],
       [[
int main(void)
{
  DIR *dirp;
  return dirfd(dirp);
}
       ]])
   ],
   [_efl_have_fct="yes"],
   [_efl_have_fct="no"])

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])
])

dnl _EFL_CHECK_FUNC_DLADDR_PRIV is for internal use
dnl _EFL_CHECK_FUNC_DLADDR_PRIV(EFL, LIB, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_DLADDR_PRIV],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

LIBS_save="${LIBS}"
LIBS="${LIBS} $2"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
       [[
#define _GNU_SOURCE
#include <dlfcn.h>
         ]],
         [[
int res = dladdr(0, 0);
       ]])],
   [
    m4_defn([UPEFL])[]_LIBS="${m4_defn([UPEFL])[]_LIBS} $2"
    requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} $2"
    _efl_have_fct="yes"
   ],
   [_efl_have_fct="no"])

LIBS="${LIBS_save}"

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$3], [$4])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_DLADDR is for internal use
dnl _EFL_CHECK_FUNC_DLADDR(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_DLADDR],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

case "$host_os" in
   mingw*)
      _efl_have_fct="yes"
      requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} -ldl"
      m4_defn([UPEFL])[]_LIBS="${m4_defn([UPEFL])[]_LIBS} -ldl"
   ;;
   *)
      _efl_have_fct="no"

dnl Check is dladdr is in libc
      _EFL_CHECK_FUNC_DLADDR_PRIV([$1], [], [_efl_have_fct="yes"], [_efl_have_fct="no"])

dnl Check is dlopen is in libdl
      if test "x${_efl_have_fct}" = "xno" ; then
         _EFL_CHECK_FUNC_DLADDR_PRIV([$1], [-ldl], [_efl_have_fct="yes"], [_efl_have_fct="no"])
      fi
   ;;
esac

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_DLOPEN_PRIV is for internal use
dnl _EFL_CHECK_FUNC_DLOPEN_PRIV(EFL, LIB, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_DLOPEN_PRIV],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

LIBS_save="${LIBS}"
LIBS="${LIBS} $2"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
       [[
#include <dlfcn.h>
         ]],
         [[
void *h = dlopen(0, 0);
       ]])],
   [
    m4_defn([UPEFL])[]_LIBS="${m4_defn([UPEFL])[]_LIBS} $2"
    requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} $2"
    _efl_have_fct="yes"
   ],
   [_efl_have_fct="no"])

LIBS="${LIBS_save}"

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$3], [$4])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_DLOPEN is for internal use
dnl _EFL_CHECK_FUNC_DLOPEN(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_DLOPEN],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

case "$host_os" in
   mingw*)
      _efl_have_fct="yes"
      requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} -ldl"
      m4_defn([UPEFL])[]_LIBS="${m4_defn([UPEFL])[]_LIBS} -ldl"
   ;;
   *)
      _efl_have_fct="no"

dnl Check is dlopen is in libc
      _EFL_CHECK_FUNC_DLOPEN_PRIV([$1], [], [_efl_have_fct="yes"], [_efl_have_fct="no"])

dnl Check is dlopen is in libdl
      if test "x${_efl_have_fct}" = "xno" ; then
         _EFL_CHECK_FUNC_DLOPEN_PRIV([$1], [-ldl], [_efl_have_fct="yes"], [_efl_have_fct="no"])
      fi
   ;;
esac

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_FNMATCH_PRIV is for internal use
dnl _EFL_CHECK_FUNC_FNMATCH_PRIV(EFL, LIB, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_FNMATCH_PRIV],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

LIBS_save="${LIBS}"
LIBS="${LIBS} $2"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
       [[
#include <stdlib.h>
#include <fnmatch.h>
         ]],
         [[
int g = fnmatch(NULL, NULL, 0);
       ]])],
   [
    m4_defn([UPEFL])[]_LIBS="${m4_defn([UPEFL])[]_LIBS} $2"
    requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} $2"
    _efl_have_fct="yes"
   ],
   [_efl_have_fct="no"])

LIBS="${LIBS_save}"

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$3], [$4])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_FNMATCH is for internal use
dnl _EFL_CHECK_FUNC_FNMATCH(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_FNMATCH],
[
case "$host_os" in
   mingw*)
      _efl_have_fct="yes"
   ;;
   *)
dnl Check is fnmatch is in libc
      _EFL_CHECK_FUNC_FNMATCH_PRIV([$1], [], [_efl_have_fct="yes"], [_efl_have_fct="no"])

dnl Check is fnmatch is in libfnmatch
      if test "x${_efl_have_fct}" = "xno" ; then
         _EFL_CHECK_FUNC_FNMATCH_PRIV([$1], [-lfnmatch], [_efl_have_fct="yes"], [_efl_have_fct="no"])
      fi

dnl Check is fnmatch is in libiberty
      if test "x${_efl_have_fct}" = "xno" ; then
         _EFL_CHECK_FUNC_FNMATCH_PRIV([$1], [-liberty], [_efl_have_fct="yes"], [_efl_have_fct="no"])
      fi
   ;;
esac

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])
])

dnl _EFL_CHECK_FUNC_ICONV_PRIV is for internal use
dnl _EFL_CHECK_FUNC_ICONV_PRIV(EFL, LIB, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_ICONV_PRIV],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

LIBS_save="${LIBS}"
LIBS="${LIBS} $2"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
       [[
#include <stdlib.h>
#include <iconv.h>
         ]],
         [[
iconv_t ic;
size_t count = iconv(ic, NULL, NULL, NULL, NULL);
       ]])],
   [
    m4_defn([UPEFL])[]_LIBS="${m4_defn([UPEFL])[]_LIBS} $2"
    requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} $2"
    _efl_have_fct="yes"
   ],
   [_efl_have_fct="no"])

LIBS="${LIBS_save}"

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$3], [$4])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_ICONV is for internal use
dnl _EFL_CHECK_FUNC_ICONV(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_ICONV],
[
AC_ARG_WITH([iconv-link],
   AC_HELP_STRING([--with-iconv-link=ICONV_LINK], [explicitly specify an iconv link option]),
   [
    _efl_have_fct="yes"
    iconv_libs=${withval}
   ],
   [_efl_have_fct="no"])

AC_MSG_CHECKING([for explicit iconv link options])
if test "x${iconv_libs}" = "x" ; then
   AC_MSG_RESULT([no explicit iconv link option])
else
   AC_MSG_RESULT([${iconv_libs}])
fi

dnl Check is iconv is in libc
if test "x${_efl_have_fct}" = "xno" ; then
   _EFL_CHECK_FUNC_ICONV_PRIV([$1], [], [_efl_have_fct="yes"], [_efl_have_fct="no"])
fi

dnl Check is iconv is in libiconv
if test "x${_efl_have_fct}" = "xno" ; then
   _EFL_CHECK_FUNC_ICONV_PRIV([$1], [-liconv], [_efl_have_fct="yes"], [_efl_have_fct="no"])
fi

dnl Check is iconv is in libiconv_plug
if test "x${_efl_have_fct}" = "xno" ; then
   _EFL_CHECK_FUNC_ICONV_PRIV([$1], [-liconv_plug], [_efl_have_fct="yes"], [_efl_have_fct="no"])
fi

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])
])

dnl _EFL_CHECK_FUNC_SETXATTR is for internal use
dnl _EFL_CHECK_FUNC_SETXATTR(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_SETXATTR],
[
AC_COMPILE_IFELSE(
   [AC_LANG_PROGRAM(
       [[
#include <stdlib.h>
#include <sys/types.h>
#include <sys/xattr.h>
       ]],
       [[
size_t tmp = listxattr("/", NULL, 0);
tmp = getxattr("/", "user.ethumb.md5", NULL, 0);
setxattr("/", "user.ethumb.md5", NULL, 0, 0);
       ]])],
   [_efl_have_fct="yes"],
   [_efl_have_fct="no"])

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])
])

dnl _EFL_CHECK_FUNC_SHM_OPEN_PRIV is for internal use
dnl _EFL_CHECK_FUNC_SHM_OPEN_PRIV(EFL, LIB, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_SHM_OPEN_PRIV],
[
m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl

LIBS_save="${LIBS}"
LIBS="${LIBS} $2"
AC_LINK_IFELSE(
   [AC_LANG_PROGRAM(
       [[
#include <sys/mman.h>
#include <sys/stat.h>        /* For mode constants */
#include <fcntl.h>           /* For O_* constants */
       ]],
       [[
int fd;

fd = shm_open("/dev/null", O_RDONLY, S_IRWXU | S_IRWXG | S_IRWXO);
       ]])],
   [
    m4_defn([UPEFL])[]_LIBS="$m4_defn([UPEFL])[]_LIBS $2"
    requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} $2"
    _efl_have_fct="yes"
   ],
   [_efl_have_fct="no"])

LIBS="${LIBS_save}"

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$3], [$4])

m4_popdef([DOWNEFL])
m4_popdef([UPEFL])
])

dnl _EFL_CHECK_FUNC_SHM_OPEN is for internal use
dnl _EFL_CHECK_FUNC_SHM_OPEN(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)

AC_DEFUN([_EFL_CHECK_FUNC_SHM_OPEN],
[
_efl_have_fct="no"

dnl Check is shm_open is in libc
_EFL_CHECK_FUNC_SHM_OPEN_PRIV([$1], [],
   [_efl_have_fct="yes"],
   [_efl_have_fct="no"])

dnl Check is shm_open is in librt
if test "x${_efl_have_fct}" = "xno" ; then
   _EFL_CHECK_FUNC_SHM_OPEN_PRIV([$1], [-lrt],
      [_efl_have_fct="yes"],
      [_efl_have_fct="no"])
fi

AS_IF([test "x${_efl_have_fct}" = "xyes"], [$2], [$3])
])

dnl Macro that checks function availability
dnl
dnl EFL_CHECK_FUNC(EFL, FUNCTION)
dnl AC_SUBST : EFL_CFLAGS and EFL_LIBS (EFL being replaced by its value)
dnl AC_DEFINE : EFL_HAVE_FUNCTION (FUNCTION being replaced by its value)
dnl result in efl_func_function (function being replaced by its value)

AC_DEFUN([EFL_CHECK_FUNC],
[
m4_pushdef([UP], m4_translit([$2], [-a-z], [_A-Z]))dnl
m4_pushdef([DOWN], m4_translit([$2], [-A-Z], [_a-z]))dnl

m4_default([_EFL_CHECK_FUNC_]m4_defn([UP]))($1, [have_fct="yes"], [have_fct="no"])

if test "x$2" = "xsetxattr" ; then
   AC_MSG_CHECKING([for extended attributes])
else
   AC_MSG_CHECKING([for ]m4_defn([DOWN]))
fi

AC_MSG_RESULT([${have_fct}])

if test "x${have_fct}" = "xyes" ; then
   if test "x$2" = "xsetxattr" ; then
      AC_DEFINE([HAVE_XATTR], [1], [Define to 1 if you have the `listxattr', `setxattr' and `getxattr' functions.])
   else
      AC_DEFINE([HAVE_]m4_defn([UP]), [1], [Define to 1 if you have the `]m4_defn([DOWN])[' function.])
   fi
fi

efl_func_[]m4_defn([DOWN])="${have_fct}"

m4_popdef([DOWN])
m4_popdef([UP])
])

dnl Macro that iterates over a sequence of space separated functions
dnl and that calls EFL_CHECK_FUNC() for each of these functions
dnl
dnl EFL_CHECK_FUNCS(EFL, FUNCTIONS)

AC_DEFUN([EFL_CHECK_FUNCS],
[
m4_foreach_w([fct], [$2], [EFL_CHECK_FUNC($1, m4_defn([fct]))])
])