Include screen.h in dialog.h for definition of WScreen
[wmaker-crm.git] / m4 / windowmaker.m4
blob7ebf501e6728ca026a4d9995b36aa7da9366be0b
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_DENY_ARG_WITH(PACKAGE, ACTION-IF-GIVEN)
29 # Check if the argument "--with-PACKAGE" was used, and if it is the case
30 # execute ACTION-IF-GIVEN which is supposed to call AC_MSG_ERROR to
31 # stop any further processing and tell the user its arguments are bad
32 AC_DEFUN([WM_DENY_ARG_WITH],
33 [m4_divert_push([INIT_PREPARE])dnl
34  AS_IF([test "${[with_]m4_translit([$1], [-+.], [___])+set}" = set], [$2])
35  m4_divert_pop([INIT_PREPARE])])
38 # WM_CHECK_XFT_VERSION(MIN_VERSION, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
40 # $XFT_CFLAGS should be defined before calling this macro,
41 # else it will not be able to find Xft.h
43 AC_DEFUN([WM_CHECK_XFT_VERSION],
44 [m4_define([XFT_REQUIRED_VERSION],
45     m4_eval(m4_bregexp($1, [^\([[0-9]]*\)\.\([[0-9]]*\)\.\([[0-9]]*\)],
46                        [\1 * 10000 + \2 * 100 + \3]) ) )dnl
47  AC_CACHE_CHECK([whether libXft is at least version $1], [ac_cv_lib_xft_version_ok],
48     [CPPFLAGS_save="$CPPFLAGS"
49      CPPFLAGS="$CPPFLAGS $XFT_CFLAGS $inc_search_path"
50      AC_TRY_LINK([
51 #include <X11/Xlib.h>
52 #include <X11/Xft/Xft.h>
53 ], [
54 #if !defined(XFT_VERSION) || XFT_VERSION < ]XFT_REQUIRED_VERSION[
55 #error libXft on this system is too old. Consider upgrading to at least $1
56 #endif
57 ], [ac_cv_lib_xft_version_ok=yes], [ac_cv_lib_xft_version_ok=no])
58      CPPFLAGS="$CPPFLAGS_save"])
59  m4_undefine([XFT_REQUIRED_VERSION])dnl
60  AS_IF([test "x$ac_cv_lib_xft_version_ok" != "xyes"], [$3], [$2])dnl
64 # WM_CHECK_LIBPANGO
65 # -----------------
67 # If the support was not disabled by user, check for the pango library using
68 # pkg-config, and if found place the appropriate stuff in the variables
69 # PANGO_CFLAGS (for compiler) and PANGO_LIBS (for linker)
70 AC_DEFUN([WM_CHECK_LIBPANGO],
71 [AS_IF([test "x$enable_pango" != "xno"],
72     [PKG_CHECK_MODULES([PANGO], [pangoxft],
73         [AC_DEFINE([USE_PANGO], [1], [defined when the pango library is used in WINGs])
74          pango="yes"],
75         [pango="no"])
76      AS_IF([test "x$enable_pango$pango" == "xyesno"],
77         [AC_MSG_ERROR([Pango library was not found - $PANGO_PKG_ERRORS])])
78     ],
79     [pango="no"])
80  AC_SUBST([PANGO_CFLAGS])dnl
81  AC_SUBST([PANGO_LIBS])dnl
85 # _WM_LIB_CHECK_FUNCTS
86 # --------------------
87 # (internal shell functions)
89 # Create 2 shell functions:
90 #  wm_fn_imgfmt_try_link: try to link against library
91 #  wm_fn_imgfmt_try_compile: try to compile against header
93 AC_DEFUN_ONCE([_WM_LIB_CHECK_FUNCTS],
94 [@%:@ wm_fn_lib_try_link FUNCTION LFLAGS
95 @%:@ ----------------------------------
96 @%:@ Try linking against library in $LFLAGS using function named $FUNCTION
97 @%:@ Assumes that LIBS have been saved in 'wm_save_LIBS' by caller
98 wm_fn_lib_try_link ()
100   LIBS="$wm_save_LIBS $[]2"
101   AC_TRY_LINK_FUNC([$[]1],
102     [wm_retval=0],
103     [wm_retval=1])
104   AS_SET_STATUS([$wm_retval])
107 @%:@ wm_fn_lib_try_compile HEADER GVARDEF FUNC_CALL CFLAGS
108 @%:@ -----------------------------------------------------
109 @%:@ Try to compile using header $HEADER and trying to call a function
110 @%:@ using the $FUNC_CALL expression and using extra $CFLAGS in the
111 @%:@ compiler's command line; GVARDEF can be used to include one line
112 @%:@ in the global context of the source.
113 @%:@ Assumes that CFLAGS have been saved in 'wm_save_CFLAGS' by caller
114 wm_fn_lib_try_compile ()
116   CFLAGS="$wm_save_CFLAGS $[]4"
117   AC_COMPILE_IFELSE(
118     [AC_LANG_PROGRAM([@%:@include <$[]1>
120 $[]2], [  $[]3;])],
121     [wm_retval=0],
122     [wm_retval=1])
123   AS_SET_STATUS([$wm_retval])
128 # WM_APPEND_ONCE
129 # --------------
131 # Append flags to a variable, but only if not already present
133 # Usage: WM_APPEND_ONCE([libflags], [variable])
134 #   $1 libflags: the list of flag to append
135 #   $2 variable: the variable, if unset use LIBS
136 AC_DEFUN([WM_APPEND_ONCE],
137 [AS_VAR_PUSHDEF([VAR], [m4_ifnblank([$2], [$2], [LIBS])])dnl
138 for wm_arg in $1 ; do
139   AS_IF([echo " $VAR " | grep " $wm_arg " 2>&1 >/dev/null],
140         [@%:@ Flag already present in VAR],
141         [VAR="$VAR $wm_arg"])
142 done
143 AS_VAR_POPDEF([VAR])dnl
147 # WM_LIB_CHECK
148 # ------------
150 # Check if a library exists (can be linked to) and check if its header can
151 # compile (using code in parameter to the macro), then update the appropriate
152 # stuff accordingly
154 # Usage: WM_LIB_CHECK([name], [lflaglist], [lfunc], [extralibs], [headercheck], [supvar], [libvar], [enable_var], [cond_name])
155 #   $1 name: name of the feature used in messages and in supvar
156 #   $2 lflaglist: the list of linker '-l' options to try, stopping on first success
157 #   $3 lfunc: the name of the function to look for when linking
158 #   $4 extralibs: optional, additional libraries included in the link check
159 #   $5 headercheck: the code that checks for the header
160 #   $6 supvar: if the library was found, append $name to this variable,
161 #              otherwise append $name to 'unsupported'
162 #   $7 libvar: if the library was found, append the working $lflag to this variable
163 #   $8 enable_var: variable to check for user's feature request, if empty we use "lowercase(enable_$1)"
164 #   $9 cond_name: name of the AC_DEFINE and the AM_CONDITIONAL
165 #                 if empty, use "uppercase(USE_$1)", if equals "-" same but do not create AM_CONDITIONAL
166 AC_DEFUN([WM_LIB_CHECK],
167 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
168 m4_pushdef([ENABLEVAR], [m4_ifnblank([$8], [$8], enable_[]m4_tolower($1))])dnl
169 m4_pushdef([CACHEVAR], [wm_cv_libchk_[]m4_tolower($1)])dnl
170 m4_pushdef([USEVAR], [m4_bmatch([$9], [^-?$], [USE_[]m4_toupper($1)], [$9])])dnl
171 AS_IF([test "x$ENABLEVAR" = "xno"],
172     [unsupported="$unsupported $1"],
173     [AC_CACHE_CHECK([for $1 support library], CACHEVAR,
174         [CACHEVAR=no
175          wm_save_LIBS="$LIBS"
176          dnl
177          dnl We check that the library is available
178          m4_bmatch([$2], [ ], dnl Any space in 'lflaglist' means we have a list of flags
179             [for wm_arg in $2 ; do
180                AS_IF([wm_fn_lib_try_link "$3" "$4 $wm_arg"],
181                  [CACHEVAR="$wm_arg" ; break])
182              done],
183             [AS_IF([wm_fn_lib_try_link "$3" "$4 $2"],
184                 [CACHEVAR="$2"]) ])
185          LIBS="$wm_save_LIBS"
186          AS_IF([test "x$ENABLEVAR$CACHEVAR" = "xyesno"],
187             [AC_MSG_ERROR([explicit $1 support requested but no library found])])
188          dnl
189          dnl A library was found, check if header is available and compile
190          AS_IF([test "x$CACHEVAR" != "xno"], [$5])
191         ])
192     AS_IF([test "x$CACHEVAR" = "xno"],
193         [unsupported="$unsupported $1"
194          ENABLEVAR="no"],
195         [$6="$$6 $1"
196          WM_APPEND_ONCE([$CACHEVAR], [$7])
197          AC_DEFINE(USEVAR, [1],
198             [defined when valid $1 library with header was found])])
199     ])
200 m4_bmatch([$9], [^-$], [],
201     [AM_CONDITIONAL(USEVAR, [test "x$ENABLEVAR" != "xno"])])dnl
202 m4_popdef([ENABLEVAR])dnl
203 m4_popdef([CACHEVAR])dnl
204 m4_popdef([USEVAR])dnl
208 # WM_CHECK_WEBREPODIR
209 # -------------------
211 # If the maintainer's option --with-web-repo was specified, check that the path provided is a valid
212 # existing directory and that it is a GIT repository that looks like Window Maker's Website repo.
213 AC_DEFUN_ONCE([WM_CHECK_WEBREPODIR],
214 [AS_IF([test "x$WEB_REPO_ROOT" != "x"],
215     [AS_IF([test ! -d "$WEB_REPO_ROOT"],
216          [AC_MSG_ERROR([The path "$with_web_repo" is not a directory, for --with-web-repo])])
218      # Convert to an Absolute path in the case it is not
219      WEB_REPO_ROOT=`cd "$WEB_REPO_ROOT" ; pwd`
221      AS_IF([test ! -d "$WEB_REPO_ROOT/.git"],
222          [AC_MSG_ERROR([The path "$WEB_REPO_ROOT" is not a GIT repository, for --with-web-repo])])
223      AS_IF([test ! -f "$WEB_REPO_ROOT/_config.yml"],
224          [AC_MSG_ERROR([The path "$WEB_REPO_ROOT" does not look like Window Maker's website repository, for --with-web-repo])])
226      # This is used to convert MAN pages into HTML pages
227      AC_CACHE_CHECK([how to convert man to html], [ac_cv_path_GROFF],
228          [AC_PATH_PROGS_FEATURE_CHECK([GROFF], [groff],
229              [echo '.TH dummy 0' | $ac_path_GROFF -man -Dutf8 -Thtml > /dev/null 2> /dev/null
230               test $? -eq 0 && ac_cv_path_GROFF=$ac_path_GROFF ac_path_GROFF_found=:],
231              [AC_MSG_ERROR([no working "groff" found -- If you have "groff-base" it is not enough for HTML support])]) ])
232      AC_SUBST([GROFF], [$ac_cv_path_GROFF])
233     ])
234  AM_CONDITIONAL([WITH_WEB_REPO], [test "x$WEB_REPO_ROOT" != "x"])
235  AC_SUBST([WEB_REPO_ROOT])
239 # WM_FUNC_SECURE_GETENV
240 # ---------------------
242 # Check if the function 'secure_getenv' is available
243 # If found, defines HAVE_SECURE_GETENV
244 AC_DEFUN_ONCE([WM_FUNC_SECURE_GETENV],
245 [AC_REQUIRE([_WM_LIB_CHECK_FUNCTS])
246 AC_CACHE_CHECK([for secure_getenv], [wm_cv_func_secure_getenv],
247     [wm_cv_func_secure_getenv=no
248      wm_save_CFLAGS="$CFLAGS"
249      for wm_arg in "% yes" "-D_GNU_SOURCE"; do
250          AS_IF([wm_fn_lib_try_compile "stdlib.h" "const char *h;" "h = secure_getenv(\"HOME\")" dnl
251                     "`echo "$wm_arg" | sed -e 's, *%.*$,,' ` -Werror=implicit-function-declaration"],
252              [wm_cv_func_secure_getenv="`echo "$wm_arg" | sed -e 's,^.*% *,,' `"
253               break])
254      done
255      CFLAGS="$wm_save_CFLAGS"])
256 AS_IF([test "x$wm_cv_func_secure_getenv" != "xno"],
257     [AS_IF([test "x$wm_cv_func_secure_getenv" != "xyes"],
258          [WM_APPEND_ONCE([$wm_cv_func_secure_getenv], [CPPFLAGS])])
259      AC_DEFINE([HAVE_SECURE_GETENV], [1],
260          [defined when GNU's secure_getenv function is available])])
264 # WM_FUNC_OPEN_NOFOLLOW
265 # ---------------------
267 # Check if the flag 'O_NOFOLLOW' is supported, for the function 'open'
268 AC_DEFUN_ONCE([WM_FUNC_OPEN_NOFOLLOW],
269 [AC_CACHE_CHECK([for O_NOFOLLOW], [wm_cv_func_open_nofollow],
270     [wm_cv_func_open_nofollow=no
271      wm_save_CPPFLAGS="$CPPFLAGS"
272      for wm_arg in dnl
273 "yes"  dnl natively supported, nothing to do
274 "-D_POSIX_C_SOURCE=200809L"  dnl the flag was officially added in POSIX.1-2008
275 "-D_XOPEN_SOURCE=700"  dnl for recent glibc
276 "-D_GNU_SOURCE"  dnl for older glibc
277      ; do
278          AS_IF([test "x$wm_arg" != "xyes"], [CPPFLAGS="$wm_save_CPPFLAGS $wm_arg"])
279          AC_LINK_IFELSE([AC_LANG_PROGRAM([dnl
280 @%:@include <sys/types.h>
281 @%:@include <sys/stat.h>
282 @%:@include <fcntl.h>], [dnl
283   int fd;
285   fd = open("/dev/null", O_RDONLY | O_NOFOLLOW);
286   return fd;])], [found=1], [found=0])
287          AS_IF([test $found = 1],
288              [wm_cv_func_open_nofollow="$wm_arg"
289               break])
290      done
291      CPPFLAGS="$wm_save_CPPFLAGS"])
292 AS_CASE([$wm_cv_func_open_nofollow],
293     [yes], [],
294     [no],  [AC_DEFINE([O_NOFOLLOW], [0],
295                 [defined by configure if the attribute is not defined on your platform])
296             AC_MSG_WARN([flag O_NOFOLLOW is not defined on your platform])],
297     [CPPFLAGS="$CPPFLAGS $wm_cv_func_open_nofollow"])
301 # WM_TYPE_SIGNAL
302 # --------------
304 # Check the return type for the function 'signal'
305 # Autoconf now claims we can assume the type is 'void' as it is in the C89 standard,
306 # but as Window Maker is supposed to be lightweight enough for old machines, we
307 # prefer to keep the check for portability
308 AC_DEFUN_ONCE([WM_TYPE_SIGNAL],
309 [AC_CACHE_CHECK([return type of signal handlers], [wm_cv_type_signal],
310     [AC_COMPILE_IFELSE(
311         [AC_LANG_PROGRAM([#include <sys/types.h>
312 #include <signal.h>
314             [return *(signal (0, 0)) (0) == 1;])],
315         [wm_cv_type_signal=int],
316         [wm_cv_type_signal=void])dnl
317     ])
318 AC_DEFINE_UNQUOTED([RETSIGTYPE], [$wm_cv_type_signal],
319     [Define as the return type of signal handlers (`int' or `void')])dnl