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