debian: Update with version 0.95.7-2 packaging.
[wmaker-crm.git] / m4 / windowmaker.m4
blobef56af8b2aef68ed9e40baa0e7984cd5a3408957
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 # WM_CHECK_XFT_VERSION(MIN_VERSION, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
29 # $XFTFLAGS should be defined before calling this macro,
30 # else it will not be able to find Xft.h
32 AC_DEFUN([WM_CHECK_XFT_VERSION],
34 CPPFLAGS_old="$CPPFLAGS"
35 CPPFLAGS="$CPPFLAGS $XFTFLAGS $inc_search_path"
36 xft_major_version=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
37 xft_minor_version=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
38 xft_micro_version=`echo $1 | sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
39 AC_MSG_CHECKING([whether libXft is at least version $1])
40 AC_CACHE_VAL(ac_cv_lib_xft_version_ok,
41 [AC_TRY_LINK(
42 [/* Test version of libXft we have */
43 #include <X11/Xlib.h>
44 #include <X11/Xft/Xft.h>
46 #if !defined(XFT_VERSION) || XFT_VERSION < $xft_major_version*10000 + $xft_minor_version*100 + $xft_micro_version
47 #error libXft on this system is too old. Consider upgrading to at least $1
48 #endif
49 ], [],
50 eval "ac_cv_lib_xft_version_ok=yes",
51 eval "ac_cv_lib_xft_version_ok=no")])
52 if eval "test \"`echo '$ac_cv_lib_xft_version_ok'`\" = yes"; then
53   AC_MSG_RESULT(yes)
54   ifelse([$2], , :, [$2])
55 else
56   AC_MSG_RESULT(no)
57   ifelse([$3], , , [$3])
59 CPPFLAGS="$CPPFLAGS_old"
63 # _WM_LIB_CHECK_FUNCTS
64 # --------------------
65 # (internal shell functions)
67 # Create 2 shell functions:
68 #  wm_fn_imgfmt_try_link: try to link against library
69 #  wm_fn_imgfmt_try_compile: try to compile against header
71 AC_DEFUN_ONCE([_WM_LIB_CHECK_FUNCTS],
72 [@%:@ wm_fn_lib_try_link FUNCTION LFLAGS
73 @%:@ ----------------------------------
74 @%:@ Try linking against library in $LFLAGS using function named $FUNCTION
75 @%:@ Assumes that LIBS have been saved in 'wm_save_LIBS' by caller
76 wm_fn_lib_try_link ()
78   LIBS="$wm_save_LIBS $[]2"
79   AC_TRY_LINK_FUNC([$[]1],
80     [wm_retval=0],
81     [wm_retval=1])
82   AS_SET_STATUS([$wm_retval])
85 @%:@ wm_fn_lib_try_compile HEADER GVARDEF FUNC_CALL CFLAGS
86 @%:@ -----------------------------------------------------
87 @%:@ Try to compile using header $HEADER and trying to call a function
88 @%:@ using the $FUNC_CALL expression and using extra $CFLAGS in the
89 @%:@ compiler's command line; GVARDEF can be used to include one line
90 @%:@ in the global context of the source.
91 @%:@ Assumes that CFLAGS have been saved in 'wm_save_CFLAGS' by caller
92 wm_fn_lib_try_compile ()
94   CFLAGS="$wm_save_CFLAGS $[]4"
95   AC_COMPILE_IFELSE(
96     [AC_LANG_PROGRAM([@%:@include <$[]1>
98 $[]2], [  $[]3;])],
99     [wm_retval=0],
100     [wm_retval=1])
101   AS_SET_STATUS([$wm_retval])
106 # WM_APPEND_ONCE
107 # --------------
109 # Append flags to a variable, but only if not already present
111 # Usage: WM_APPEND_ONCE([libflags], [variable])
112 #   $1 libflags: the list of flag to append
113 #   $2 variable: the variable, if unset use LIBS
114 AC_DEFUN([WM_APPEND_ONCE],
115 [AS_VAR_PUSHDEF([VAR], [m4_ifnblank([$2], [$2], [LIBS])])dnl
116 for wm_arg in $1 ; do
117   AS_IF([echo " $VAR " | grep " $wm_arg " 2>&1 >/dev/null],
118         [@%:@ Flag already present in VAR],
119         [VAR="$VAR $wm_arg"])
120 done
121 AS_VAR_POPDEF([VAR])dnl
125 # WM_LIB_CHECK
126 # ------------
128 # Check if a library exists (can be linked to) and check if its header can
129 # compile (using code in parameter to the macro), then update the appropriate
130 # stuff accordingly
132 # Usage: WM_LIB_CHECK([name], [lflaglist], [lfunc], [extralibs], [headercheck], [supvar], [libvar], [enable_var], [cond_name])
133 #   $1 name: name of the feature used in messages and in supvar
134 #   $2 lflaglist: the list of linker '-l' options to try, stopping on first success
135 #   $3 lfunc: the name of the function to look for when linking
136 #   $4 extralibs: optional, additional libraries included in the link check
137 #   $5 headercheck: the code that checks for the header
138 #   $6 supvar: if the library was found, append $name to this variable,
139 #              otherwise append $name to 'unsupported'
140 #   $7 libvar: if the library was found, append the working $lflag to this variable
141 #   $8 enable_var: variable to check for user's feature request, if empty we use "lowercase(enable_$1)"
142 #   $9 cond_name: name of the AC_DEFINE and the AM_CONDITIONAL
143 #                 if empty, use "uppercase(USE_$1)", if equals "-" same but do not create AM_CONDITIONAL
144 AC_DEFUN([WM_LIB_CHECK],
145 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
146 m4_pushdef([ENABLEVAR], [m4_ifnblank([$8], [$8], enable_[]m4_tolower($1))])dnl
147 m4_pushdef([CACHEVAR], [wm_cv_libchk_[]m4_tolower($1)])dnl
148 m4_pushdef([USEVAR], [m4_bmatch([$9], [^-?$], [USE_[]m4_toupper($1)], [$9])])dnl
149 AS_IF([test "x$ENABLEVAR" = "xno"],
150     [unsupported="$unsupported $1"],
151     [AC_CACHE_CHECK([for $1 support library], CACHEVAR,
152         [CACHEVAR=no
153          wm_save_LIBS="$LIBS"
154          dnl
155          dnl We check that the library is available
156          m4_bmatch([$2], [ ], dnl Any space in 'lflaglist' means we have a list of flags
157             [for wm_arg in $2 ; do
158                AS_IF([wm_fn_lib_try_link "$3" "$4 $wm_arg"],
159                  [CACHEVAR="$wm_arg" ; break])
160              done],
161             [AS_IF([wm_fn_lib_try_link "$3" "$4 $2"],
162                 [CACHEVAR="$2"]) ])
163          LIBS="$wm_save_LIBS"
164          AS_IF([test "x$ENABLEVAR$CACHEVAR" = "xyesno"],
165             [AC_MSG_ERROR([explicit $1 support requested but no library found])])
166          dnl
167          dnl A library was found, check if header is available and compile
168          AS_IF([test "x$CACHEVAR" != "xno"], [$5])
169         ])
170     AS_IF([test "x$CACHEVAR" = "xno"],
171         [unsupported="$unsupported $1"
172          ENABLEVAR="no"],
173         [$6="$$6 $1"
174          WM_APPEND_ONCE([$CACHEVAR], [$7])
175          AC_DEFINE(USEVAR, [1],
176             [defined when valid $1 library with header was found])])
177     ])
178 m4_bmatch([$9], [^-$], [],
179     [AM_CONDITIONAL(USEVAR, [test "x$ENABLEVAR" != "xno"])])dnl
180 m4_popdef([ENABLEVAR])dnl
181 m4_popdef([CACHEVAR])dnl
182 m4_popdef([USEVAR])dnl
186 # WM_FUNC_SECURE_GETENV
187 # ---------------------
189 # Check if the function 'secure_getenv' is available
190 # If found, defines HAVE_SECURE_GETENV
191 AC_DEFUN_ONCE([WM_FUNC_SECURE_GETENV],
192 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
193 AC_CACHE_CHECK([for secure_getenv], [wm_cv_func_secure_getenv],
194     [wm_cv_func_secure_getenv=no
195      wm_save_CFLAGS="$CFLAGS"
196      for wm_arg in "% yes" "-D_GNU_SOURCE"; do
197          AS_IF([wm_fn_lib_try_compile "stdlib.h" "const char *h;" "h = secure_getenv(\"HOME\")" dnl
198                     "`echo "$wm_arg" | sed -e 's, *%.*$,,' ` -Werror=implicit-function-declaration"],
199              [wm_cv_func_secure_getenv="`echo "$wm_arg" | sed -e 's,^.*% *,,' `"
200               break])
201      done
202      CFLAGS="$wm_save_CFLAGS"])
203 AS_IF([test "x$wm_cv_func_secure_getenv" != "xno"],
204     [AS_IF([test "x$wm_cv_func_secure_getenv" != "xyes"],
205          [WM_APPEND_ONCE([$wm_cv_func_secure_getenv], [CPPFLAGS])])
206      AC_DEFINE([HAVE_SECURE_GETENV], [1],
207          [defined when GNU's secure_getenv function is available])])
211 # WM_FUNC_OPEN_NOFOLLOW
212 # ---------------------
214 # Check if the flag 'O_NOFOLLOW' is supported, for the function 'open'
215 AC_DEFUN_ONCE([WM_FUNC_OPEN_NOFOLLOW],
216 [AC_CACHE_CHECK([for O_NOFOLLOW], [wm_cv_func_open_nofollow],
217     [wm_cv_func_open_nofollow=no
218      wm_save_CPPFLAGS="$CPPFLAGS"
219      for wm_arg in dnl
220 "yes"  dnl natively supported, nothing to do
221 "-D_POSIX_C_SOURCE=200809L"  dnl the flag was officially added in POSIX.1-2008
222 "-D_XOPEN_SOURCE=700"  dnl for recent glibc
223 "-D_GNU_SOURCE"  dnl for older glibc
224      ; do
225          AS_IF([test "x$wm_arg" != "xyes"], [CPPFLAGS="$wm_save_CPPFLAGS $wm_arg"])
226          AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
227 @%:@include <sys/types.h>
228 @%:@include <sys/stat.h>
229 @%:@include <fcntl.h>], [dnl
230   int fd;
232   fd = open("/dev/null", O_RDONLY | O_NOFOLLOW);
233   return fd;])], [found=1], [found=0])
234          AS_IF([test $found = 1],
235              [wm_cv_func_open_nofollow="$wm_arg"
236               break])
237      done
238      CPPFLAGS="$wm_save_CPPFLAGS"])
239 AS_CASE([$wm_cv_func_open_nofollow],
240     [yes], [],
241     [no],  [AC_DEFINE([O_NOFOLLOW], [0],
242                 [defined by configure if the attribute is not defined on your platform])
243             AC_MSG_WARN([flag O_NOFOLLOW is not defined on your platform])],
244     [CPPFLAGS="$CPPFLAGS $wm_cv_func_open_nofollow"])
248 # WM_TYPE_SIGNAL
249 # --------------
251 # Check the return type for the function 'signal'
252 # Autoconf now claims we can assume the type is 'void' as it is in the C89 standard,
253 # but as Window Maker is supposed to be lightweight enough for old machines, we
254 # prefer to keep the check for portability
255 AC_DEFUN_ONCE([WM_TYPE_SIGNAL],
256 [AC_CACHE_CHECK([return type of signal handlers], [wm_cv_type_signal],
257     [AC_COMPILE_IFELSE(
258         [AC_LANG_PROGRAM([#include <sys/types.h>
259 #include <signal.h>
261             [return *(signal (0, 0)) (0) == 1;])],
262         [wm_cv_type_signal=int],
263         [wm_cv_type_signal=void])dnl
264     ])
265 AC_DEFINE_UNQUOTED([RETSIGTYPE], [$wm_cv_type_signal],
266     [Define as the return type of signal handlers (`int' or `void')])dnl