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