configure: add a few warning flags for gcc and clang to help catch bugs
[wmaker-crm.git] / m4 / wm_xext_check.m4
blobcf6c70fff2c7deadd83758e4f9ac02a24ad671c5
1 # wm_xext_check.m4 - Macros to check for X extensions support libraries
3 # Copyright (c) 2013 Christophe CURIS
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.
19 # WM_XEXT_CHECK_XSHAPE
20 # --------------------
22 # Check for the X Shaped Window extension
23 # The check depends on variable 'enable_xshape' being either:
24 #   yes  - detect, fail if not found
25 #   no   - do not detect, disable support
26 #   auto - detect, disable if not found
28 # When found, append appropriate stuff in XLIBS, and append info to
29 # the variable 'supported_xext'
30 # When not found, append info to variable 'unsupported'
31 AC_DEFUN_ONCE([WM_XEXT_CHECK_XSHAPE],
32 [WM_LIB_CHECK([XShape], [-lXext], [XShapeSelectInput], [$XLIBS],
33     [wm_save_CFLAGS="$CFLAGS"
34      AS_IF([wm_fn_lib_try_compile "X11/extensions/shape.h" "Window win;" "XShapeSelectInput(NULL, win, 0)" ""],
35         [],
36         [AC_MSG_ERROR([found $CACHEVAR but cannot compile using XShape header])])
37      CFLAGS="$wm_save_CFLAGS"],
38     [supported_xext], [XLIBS], [enable_shape], [-])dnl
39 ]) dnl AC_DEFUN
42 # WM_XEXT_CHECK_XSHM
43 # ------------------
45 # Check for the MIT-SHM extension for Shared Memory support
46 # The check depends on variable 'enable_shm' being either:
47 #   yes  - detect, fail if not found
48 #   no   - do not detect, disable support
49 #   auto - detect, disable if not found
51 # When found, append appropriate stuff in XLIBS, and append info to
52 # the variable 'supported_xext'
53 # When not found, append info to variable 'unsupported'
54 AC_DEFUN_ONCE([WM_XEXT_CHECK_XSHM],
55 [WM_LIB_CHECK([XShm], [-lXext], [XShmAttach], [$XLIBS],
56     [wm_save_CFLAGS="$CFLAGS"
57      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([dnl
58 @%:@include <X11/Xlib.h>
59 @%:@include <X11/extensions/XShm.h>
60 ], [dnl
61   XShmSegmentInfo si;
63   XShmAttach(NULL, &si);])],
64         [],
65         [AC_MSG_ERROR([found $CACHEVAR but cannot compile using XShm header])])
66      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([dnl
67 @%:@include <sys/ipc.h>
68 @%:@include <sys/shm.h>
69 ], [dnl
70   shmget(IPC_PRIVATE, 1024, IPC_CREAT);])],
71         [],
72         [AC_MSG_ERROR([found $CACHEVAR but cannot compile using ipc/shm headers])])
73      CFLAGS="$wm_save_CFLAGS"],
74     [supported_xext], [XLIBS], [enable_shm], [-])dnl
75 ]) dnl AC_DEFUN
78 # WM_XEXT_CHECK_XMU
79 # -----------------
81 # Check for the libXmu (X Misceleanous Utilities)
82 # When found, append it to LIBXMU
83 # When not found, generate an error because we have no work-around for it
84 AC_DEFUN_ONCE([WM_EXT_CHECK_XMU],
85 [AC_CACHE_CHECK([for Xmu library], [wm_cv_xext_xmu],
86     [wm_cv_xext_xmu=no
87      dnl
88      dnl We check that the library is available
89      wm_save_LIBS="$LIBS"
90      AS_IF([wm_fn_lib_try_link "XmuLookupStandardColormap" "-lXmu"],
91          [wm_cv_xext_xmu="-lXmu"])
92      LIBS="$wm_save_LIBS"
93      AS_IF([test "x$wm_cv_xext_xmu" = "xno"],
94          [AC_MSG_ERROR([library Xmu not found])])
95      dnl
96      dnl A library was found, check if header is available and compile
97      wm_save_CFLAGS="$CFLAGS"
98      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([dnl
99 @%:@include <X11/Xlib.h>
100 @%:@include <X11/Xutil.h>
101 @%:@include <X11/Xmu/StdCmap.h>
103 Display *dpy;
104 Atom prop;
105 ], [dnl
106   XmuLookupStandardColormap(dpy, 0, 0, 0, prop, False, True);]) ],
107          [],
108          [AC_MSG_ERROR([found $wm_cv_xext_xmu but cannot compile with the header])])
109      CFLAGS="$wm_save_CFLAGS"])
110 dnl The cached check already reported problems when not found
111 LIBXMU="$wm_cv_xext_xmu"
112 AC_SUBST(LIBXMU)dnl
116 # WM_XEXT_CHECK_XINERAMA
117 # ----------------------
119 # Check for the Xinerama extension for multiscreen-as-one support
120 # The check depends on variable 'enable_xinerama' being either:
121 #   yes  - detect, fail if not found
122 #   no   - do not detect, disable support
123 #   auto - detect, disable if not found
125 # When found, append appropriate stuff in LIBXINERAMA, and append info to
126 # the variable 'supported_xext'
127 # When not found, append info to variable 'unsupported'
128 AC_DEFUN_ONCE([WM_XEXT_CHECK_XINERAMA],
129 [LIBXINERAMA=""
130 AS_IF([test "x$enable_xinerama" = "xno"],
131     [unsupported="$unsupported Xinerama"],
132     [AC_CACHE_CHECK([for Xinerama support library], [wm_cv_xext_xinerama],
133         [wm_cv_xext_xinerama=no
134          dnl
135          dnl We check that the library is available
136          wm_save_LIBS="$LIBS"
137          for wm_arg in dnl
138 dnl           Lib flag   % Function name        % info
139              "-lXinerama % XineramaQueryScreens" dnl
140              "-lXext     % XineramaGetInfo      % solaris" ; do
141            AS_IF([wm_fn_lib_try_link "`echo "$wm_arg" | dnl
142 sed -e 's,^[[^%]]*% *,,' | sed -e 's, *%.*$,,' `" dnl
143 "$XLFLAGS $XLIBS `echo "$wm_arg" | sed -e 's, *%.*$,,' `"],
144              [wm_cv_xext_xinerama="`echo "$wm_arg" | sed -e 's, *%[[^%]]*, ,' `"
145               break])
146          done
147          LIBS="$wm_save_LIBS"
148          AS_IF([test "x$wm_cv_xext_xinerama" = "xno"],
149              [AS_IF([test "x$enable_xinerama" = "xyesno"],
150                  [AC_MSG_ERROR([explicit Xinerama support requested but no library found])])],
151              [dnl
152               dnl A library was found, check if header is available and compiles
153               wm_save_CFLAGS="$CFLAGS"
154               AS_CASE([`echo "$wm_cv_xext_xinerama" | sed -e 's,^[[^%]]*,,' `],
155                   [*solaris*], [wm_header="X11/extensions/xinerama.h" ; wm_fct="XineramaGetInfo(NULL, 0, NULL, NULL, &intval)"],
156                   [wm_header="X11/extensions/Xinerama.h" ; wm_fct="XineramaQueryScreens(NULL, &intval)"])
157               AS_IF([wm_fn_lib_try_compile "$wm_header" "int intval;" "$wm_fct" ""],
158                   [],
159                   [AC_MSG_ERROR([found $wm_cv_xext_xinerama but cannot compile with the header])])
160               AS_UNSET([wm_header])
161               AS_UNSET([wm_fct])
162               CFLAGS="$wm_save_CFLAGS" dnl
163          ]) dnl
164      ])
165      AS_IF([test "x$wm_cv_xext_xinerama" = "xno"],
166         [unsupported="$unsupported Xinerama"
167          enable_xinerama="no"],
168         [LIBXINERAMA="`echo "$wm_cv_xext_xinerama" | sed -e 's, *%.*$,,' `"
169          AC_DEFINE([USE_XINERAMA], [1],
170              [defined when usable Xinerama library with header was found])
171          AS_CASE([`echo "$wm_cv_xext_xinerama" | sed -e 's,^[[^%]]*,,' `],
172              [*solaris*], [AC_DEFINE([SOLARIS_XINERAMA], [1],
173                  [defined when the Solaris Xinerama extension was detected])])
174          supported_xext="$supported_xext Xinerama"])
175     ])
176 AC_SUBST(LIBXINERAMA)dnl
180 # WM_XEXT_CHECK_XRANDR
181 # --------------------
183 # Check for the X RandR (Resize-and-Rotate) extension
184 # The check depends on variable 'enable_randr' being either:
185 #   yes  - detect, fail if not found
186 #   no   - do not detect, disable support
187 #   auto - detect, disable if not found
189 # When found, append appropriate stuff in LIBXRANDR, and append info to
190 # the variable 'supported_xext'
191 # When not found, append info to variable 'unsupported'
192 AC_DEFUN_ONCE([WM_XEXT_CHECK_XRANDR],
193 [WM_LIB_CHECK([RandR], [-lXrandr], [XRRQueryExtension], [$XLIBS],
194     [wm_save_CFLAGS="$CFLAGS"
195      AS_IF([wm_fn_lib_try_compile "X11/extensions/Xrandr.h" "Display *dpy;" "XRRQueryExtension(dpy, NULL, NULL)" ""],
196         [],
197         [AC_MSG_ERROR([found $CACHEVAR but cannot compile using XRandR header])])
198      CFLAGS="$wm_save_CFLAGS"],
199     [supported_xext], [LIBXRANDR], [], [-])dnl
200 AC_SUBST([LIBXRANDR])dnl
201 ]) dnl AC_DEFUN