WINGs: Added a few missing const attributes
[wmaker-crm.git] / m4 / windowmaker.m4
blob8ff1bd6254fd080582609af0a8fba9202fafaeac
1 # windowmaker.m4 - General macros for Window Maker autoconf
3 # Copyright (c) 2004 Dan Pascu
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 dnl Tell m4 to not allow stuff starting with "WM_" in the generated file
21 dnl because this is likely a problem of a macro that was not expanded as
22 dnl expected (with an exception for an already used variable name)
23 m4_pattern_forbid([^_?WM_])
24 m4_pattern_allow([^WM_OSDEP(_[A-Z]*)?$])
27 dnl
28 dnl WM_CHECK_XFT_VERSION(MIN_VERSION, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
29 dnl
30 dnl # $XFTFLAGS should be defined before calling this macro,
31 dnl # else it will not be able to find Xft.h
32 dnl
33 AC_DEFUN([WM_CHECK_XFT_VERSION],
35 CPPFLAGS_old="$CPPFLAGS"
36 CPPFLAGS="$CPPFLAGS $XFTFLAGS $inc_search_path"
37 xft_major_version=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
38 xft_minor_version=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
39 xft_micro_version=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
40 AC_MSG_CHECKING([whether libXft is at least version $1])
41 AC_CACHE_VAL(ac_cv_lib_xft_version_ok,
42 [AC_TRY_LINK(
43 [/* Test version of libXft we have */
44 #include <X11/Xlib.h>
45 #include <X11/Xft/Xft.h>
47 #if !defined(XFT_VERSION) || XFT_VERSION < $xft_major_version*10000 + $xft_minor_version*100 + $xft_micro_version
48 #error libXft on this system is too old. Consider upgrading to at least $1
49 #endif
50 ], [],
51 eval "ac_cv_lib_xft_version_ok=yes",
52 eval "ac_cv_lib_xft_version_ok=no")])
53 if eval "test \"`echo '$ac_cv_lib_xft_version_ok'`\" = yes"; then
54   AC_MSG_RESULT(yes)
55   ifelse([$2], , :, [$2])
56 else
57   AC_MSG_RESULT(no)
58   ifelse([$3], , , [$3])
60 CPPFLAGS="$CPPFLAGS_old"
64 dnl _WM_LIB_CHECK_FUNCTS
65 dnl -----------------------
66 dnl (internal shell functions)
67 dnl
68 dnl Create 2 shell functions:
69 dnl  wm_fn_imgfmt_try_link: try to link against library
70 dnl  wm_fn_imgfmt_try_compile: try to compile against header
71 dnl
72 AC_DEFUN_ONCE([_WM_LIB_CHECK_FUNCTS],
73 [@%:@ wm_fn_lib_try_link FUNCTION LFLAGS
74 @%:@ ----------------------------------
75 @%:@ Try linking against library in $LFLAGS using function named $FUNCTION
76 @%:@ Assumes that LIBS have been saved in 'wm_save_LIBS' by caller
77 wm_fn_lib_try_link ()
79   LIBS="$wm_save_LIBS $[]2"
80   AC_TRY_LINK_FUNC([$[]1],
81     [wm_retval=0],
82     [wm_retval=1])
83   AS_SET_STATUS([$wm_retval])
86 @%:@ wm_fn_lib_try_compile HEADER GVARDEF FUNC_CALL CFLAGS
87 @%:@ -----------------------------------------------------
88 @%:@ Try to compile using header $HEADER and trying to call a function
89 @%:@ using the $FUNC_CALL expression and using extra $CFLAGS in the
90 @%:@ compiler's command line; GVARDEF can be used to include one line
91 @%:@ in the global context of the source.
92 @%:@ Assumes that CFLAGS have been saved in 'wm_save_CFLAGS' by caller
93 wm_fn_lib_try_compile ()
95   CFLAGS="$wm_save_CFLAGS $[]4"
96   AC_COMPILE_IFELSE(
97     [AC_LANG_PROGRAM([@%:@include <$[]1>
99 $[]2], [  $[]3;])],
100     [wm_retval=0],
101     [wm_retval=1])
102   AS_SET_STATUS([$wm_retval])
107 # WM_APPEND_ONCE
108 # --------------
110 # Append flags to a variable, but only if not already present
112 # Usage: WM_APPEND_ONCE([libflags], [variable])
113 #   $1 libflags: the list of flag to append
114 #   $2 variable: the variable, if unset use LIBS
115 AC_DEFUN([WM_APPEND_ONCE],
116 [AS_VAR_PUSHDEF([VAR], [m4_ifnblank([$2], [$2], [LIBS])])dnl
117 for wm_arg in $1 ; do
118   AS_IF([echo " $VAR " | grep " $wm_arg " 2>&1 >/dev/null],
119         [@%:@ Flag already present in VAR],
120         [VAR="$VAR $wm_arg"])
121 done
122 AS_VAR_POPDEF([VAR])dnl
126 # WM_LIB_CHECK
127 # ------------
129 # Check if a library exists (can be linked to) and check if its header can
130 # compile (using code in parameter to the macro), then update the appropriate
131 # stuff accordingly
133 # Usage: WM_LIB_CHECK([name], [lflaglist], [lfunc], [extralibs], [headercheck], [supvar], [libvar], [enable_var], [cond_name])
134 #   $1 name: name of the feature used in messages and in supvar
135 #   $2 lflaglist: the list of linker '-l' options to try, stopping on first success
136 #   $3 lfunc: the name of the function to look for when linking
137 #   $4 extralibs: optional, additional libraries included in the link check
138 #   $5 headercheck: the code that checks for the header
139 #   $6 supvar: if the library was found, append $name to this variable,
140 #              otherwise append $name to 'unsupported'
141 #   $7 libvar: if the library was found, append the working $lflag to this variable
142 #   $8 enable_var: variable to check for user's feature request, if empty we use "lowercase(enable_$1)"
143 #   $9 cond_name: name of the AC_DEFINE and the AM_CONDITIONAL
144 #                 if empty, use "uppercase(USE_$1)", if equals "-" same but do not create AM_CONDITIONAL
145 AC_DEFUN([WM_LIB_CHECK],
146 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
147 m4_pushdef([ENABLEVAR], [m4_ifnblank([$8], [$8], enable_[]m4_tolower($1))])dnl
148 m4_pushdef([CACHEVAR], [wm_cv_libchk_[]m4_tolower($1)])dnl
149 m4_pushdef([USEVAR], [m4_bmatch([$9], [^-?$], [USE_[]m4_toupper($1)], [$9])])dnl
150 AS_IF([test "x$ENABLEVAR" = "xno"],
151     [unsupported="$unsupported $1"],
152     [AC_CACHE_CHECK([for $1 support library], CACHEVAR,
153         [CACHEVAR=no
154          wm_save_LIBS="$LIBS"
155          dnl
156          dnl We check that the library is available
157          m4_bmatch([$2], [ ], dnl Any space in 'lflaglist' means we have a list of flags
158             [for wm_arg in $2 ; do
159                AS_IF([wm_fn_lib_try_link "$3" "$4 $wm_arg"],
160                  [CACHEVAR="$wm_arg" ; break])
161              done],
162             [AS_IF([wm_fn_lib_try_link "$3" "$4 $2"],
163                 [CACHEVAR="$2"]) ])
164          LIBS="$wm_save_LIBS"
165          AS_IF([test "x$ENABLEVAR$CACHEVAR" = "xyesno"],
166             [AC_MSG_ERROR([explicit $1 support requested but no library found])])
167          dnl
168          dnl A library was found, check if header is available and compile
169          AS_IF([test "x$CACHEVAR" != "xno"], [$5])
170         ])
171     AS_IF([test "x$CACHEVAR" = "xno"],
172         [unsupported="$unsupported $1"
173          ENABLEVAR="no"],
174         [$6="$$6 $1"
175          WM_APPEND_ONCE([$CACHEVAR], [$7])
176          AC_DEFINE(USEVAR, [1],
177             [defined when valid $1 library with header was found])])
178     ])
179 m4_bmatch([$9], [^-$], [],
180     [AM_CONDITIONAL(USEVAR, [test "x$ENABLEVAR" != "xno"])])dnl
181 m4_popdef([ENABLEVAR])dnl
182 m4_popdef([CACHEVAR])dnl
183 m4_popdef([USEVAR])dnl