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]*)?$])
28 dnl WM_CHECK_XFT_VERSION(MIN_VERSION, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
30 dnl # $XFTFLAGS should be defined before calling this macro,
31 dnl # else it will not be able to find Xft.h
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,
43 [/* Test version of libXft we have */
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
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
55 ifelse([$2], , :, [$2])
58 ifelse([$3], , , [$3])
60 CPPFLAGS="$CPPFLAGS_old"
64 dnl _WM_LIB_CHECK_FUNCTS
65 dnl -----------------------
66 dnl (internal shell functions)
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
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
79 LIBS="$wm_save_LIBS $[]2"
80 AC_TRY_LINK_FUNC([$[]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"
97 [AC_LANG_PROGRAM([@%:@include <$[]1>
102 AS_SET_STATUS([$wm_retval])
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"])
122 AS_VAR_POPDEF([VAR])dnl
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
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,
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])
162 [AS_IF([wm_fn_lib_try_link "$3" "$4 $2"],
165 AS_IF([test "x$ENABLEVAR$CACHEVAR" = "xyesno"],
166 [AC_MSG_ERROR([explicit $1 support requested but no library found])])
168 dnl A library was found, check if header is available and compile
169 AS_IF([test "x$CACHEVAR" != "xno"], [$5])
171 AS_IF([test "x$CACHEVAR" = "xno"],
172 [unsupported="$unsupported $1"
175 WM_APPEND_ONCE([$CACHEVAR], [$7])
176 AC_DEFINE(USEVAR, [1],
177 [defined when valid $1 library with header was found])])
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
187 # WM_FUNC_SECURE_GETENV
188 # ---------------------
190 # Check if the function 'secure_getenv' is available
191 # If found, defines HAVE_SECURE_GETENV
192 AC_DEFUN_ONCE([WM_FUNC_SECURE_GETENV],
193 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
194 AC_CACHE_CHECK([for secure_getenv], [wm_cv_func_secure_getenv],
195 [wm_cv_func_secure_getenv=no
196 wm_save_CFLAGS="$CFLAGS"
197 for wm_arg in "% yes" "-D_GNU_SOURCE"; do
198 AS_IF([wm_fn_lib_try_compile "stdlib.h" "const char *h;" "h = secure_getenv(\"HOME\")" dnl
199 "`echo "$wm_arg" | sed -e 's, *%.*$,,' ` -Werror=implicit-function-declaration"],
200 [wm_cv_func_secure_getenv="`echo "$wm_arg" | sed -e 's,^.*% *,,' `"
203 CFLAGS="$wm_save_CFLAGS"])
204 AS_IF([test "x$wm_cv_func_secure_getenv" != "xno"],
205 [AS_IF([test "x$wm_cv_func_secure_getenv" != "xyes"],
206 [WM_APPEND_ONCE([$wm_cv_func_secure_getenv], [CPPFLAGS])])
207 AC_DEFINE([HAVE_SECURE_GETENV], [1],
208 [defined when GNU's secure_getenv function is available])])