Eet: add nice m4 macros to check functions and libraries. Will be usable easily in...
[framework/uifw/eet.git] / m4 / efl_check_libs.m4
1 dnl Copyright (C) 2012 Vincent Torri <vincent dot torri at gmail dot com>
2 dnl This code is public domain and can be freely used or copied.
3
4 dnl Macro that check dependencies libraries for the EFL:
5
6 dnl libjpeg
7 dnl zlib
8
9 dnl _EFL_CHECK_LIB_LIBJPEG is for internal use
10 dnl _EFL_CHECK_LIB_LIBJPEG(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
11
12 AC_DEFUN([_EFL_CHECK_LIB_LIBJPEG],
13 [
14 m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
15 m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl
16
17 AC_CHECK_HEADER([jpeglib.h],
18    [have_dep="yes"],
19    [
20     AC_MSG_ERROR(["Cannot find jpeglib.h. Make sure your CFLAGS environment variable contains include lines for the location of this file"])
21     have_dep="no"
22    ])
23
24 if test "x${have_dep}" = "xyes" ; then
25    AC_CHECK_LIB([jpeg], [jpeg_std_error],
26       [
27        have_dep="yes"
28        requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} -ljpeg"
29       ],
30       [
31        AC_MSG_ERROR("Cannot find libjpeg library. Make sure your LDFLAGS environment variable contains include lines for the location of this file")
32        have_dep="no"
33       ])
34 fi
35
36 AS_IF([test "x${have_dep}" = "xyes"], [$2], [$3])
37
38 m4_popdef([DOWNEFL])
39 m4_popdef([UPEFL])
40 ])
41
42 dnl _EFL_CHECK_LIB_ZLIB is for internal use
43 dnl _EFL_CHECK_LIB_ZLIB(EFL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
44
45 AC_DEFUN([_EFL_CHECK_LIB_ZLIB],
46 [
47 m4_pushdef([UPEFL], m4_translit([$1], [-a-z], [_A-Z]))dnl
48 m4_pushdef([DOWNEFL], m4_translit([$1], [-A-Z], [_a-z]))dnl
49
50 PKG_CHECK_EXISTS([zlib],
51    [
52     _efl_have_lib="yes"
53     requirements_pc_[]m4_defn([DOWNEFL])="${requirements_pc_[]m4_defn([DOWNEFL])} zlib"
54    ],
55    [
56     AC_MSG_ERROR(["Cannot find zlib.PC. Make sure your PKG_CONFIG_PATH environment variable contains include lines for the location of this file"])
57     _efl_have_lib="no"
58    ])
59
60 if test "x${_efl_have_lib}" = "xno" ; then
61    AC_CHECK_HEADER([zlib.h],
62       [_efl_have_lib="yes"],
63       [
64        AC_MSG_ERROR(["Cannot find zlib.h. Make sure your CFLAGS environment variable contains include lines for the location of this file"])
65        _efl_have_lib="no"
66       ])
67
68    if test "x${_efl_have_lib}" = "xyes" ; then
69       AC_CHECK_LIB([z], [zlibVersion],
70          [
71           _efl_have_lib="yes"
72           requirements_libs_[]m4_defn([DOWNEFL])="${requirements_libs_[]m4_defn([DOWNEFL])} -lz"
73          ],
74          [
75           AC_MSG_ERROR(["Cannot find libjpeg library. Make sure your LDFLAGS environment variable contains include lines for the location of this file"])
76           _efl_have_lib="no"
77          ])
78    fi
79 fi
80
81 AS_IF([test "x${_efl_have_lib}" = "xyes"], [$2], [$3])
82
83 m4_popdef([DOWNEFL])
84 m4_popdef([UPEFL])
85 ])
86
87 dnl Macro that checks for a library
88 dnl
89 dnl EFL_CHECK_LIB(EFL, LIBRARY)
90 dnl AC_DEFINE : EFL_HAVE_LIBRARY (LIBRARY being replaced by its value)
91
92 AC_DEFUN([EFL_CHECK_LIB],
93 [
94 m4_pushdef([UP], m4_translit([$2], [-a-z], [_A-Z]))dnl
95 m4_pushdef([DOWN], m4_translit([$2], [-A-Z], [_a-z]))dnl
96
97 m4_default([_EFL_CHECK_LIB_]m4_defn([UP]))($1, [have_lib="yes"], [have_lib="no"])
98
99 AC_MSG_CHECKING([for ]m4_defn([DOWN]))
100 AC_MSG_RESULT([${have_lib}])
101
102 if test "x${have_lib}" = "xyes" ; then
103    AC_DEFINE([HAVE_]m4_defn([UP]), [1], [Define to 1 if the `]m4_defn([DOWN])[' library is installed.])
104 fi
105
106 efl_lib_[]m4_defn([DOWN])="${have_lib}"
107
108 m4_popdef([DOWN])
109 m4_popdef([UP])
110 ])
111
112 dnl Macro that iterates over a sequence of white separated libraries
113 dnl and that calls EFL_CHECK_LIB() for each of these libraries
114 dnl
115 dnl EFL_CHECK_LIBS(EFL, LIBRARIES)
116
117 AC_DEFUN([EFL_CHECK_LIBS],
118 [
119 m4_foreach_w([lib], [$2], [EFL_CHECK_LIB($1, m4_defn([lib]))])
120 ])