Link libraries directly to compile on some systems (debian).
[dana/openbox.git] / m4 / x11.m4
1 # X11_DEVEL()
2 #
3 # Check for the presence of the X Window System headers and libraries.
4 # Sets the CPPFLAGS and LIBS variables as appropriate.
5 AC_DEFUN([X11_DEVEL],
6 [
7   AC_PATH_XTRA
8   test "$no_x" = "yes" && \
9     AC_MSG_ERROR([The X Window System could not be found.])
10
11   # Store these
12   OLDLIBS=$LIBS
13   OLDCPPFLAGS=$CPPFLAGS
14      
15   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
16   X_LIBS="$X_PRE_LIBS $X_LIBS -lX11"
17   LIBS="$LIBS $X_LIBS"
18
19   # Check for required functions in -lX11
20   AC_CHECK_LIB(
21     [X11], [XOpenDisplay],
22     ,
23     AC_MSG_ERROR([Could not find XOpenDisplay in -lX11.])
24   )
25
26   # Restore the old values. Use X_CFLAGS and X_LIBS in
27   # the Makefiles
28   LIBS=$OLDLIBS
29   CPPFLAGS=$OLDCPPFLAGS
30 ])
31
32 # X11_EXT_XKB()
33 #
34 # Check for the presence of the "Xkb" X Window System extension.
35 # Defines "XKB" and sets the $(XKB) variable to "yes" if the extension is
36 # present.
37 AC_DEFUN([X11_EXT_XKB],
38 [
39   AC_REQUIRE([X11_DEVEL])
40
41   # Store these
42   OLDLIBS=$LIBS
43   OLDCPPFLAGS=$CPPFLAGS
44      
45   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
46   LIBS="$LIBS $X_LIBS"
47
48   AC_CHECK_LIB([X11], [XkbBell],
49     AC_MSG_CHECKING([for X11/XKBlib.h])
50     AC_TRY_LINK(
51     [
52       #include <X11/Xlib.h>
53       #include <X11/Xutil.h>
54       #include <X11/XKBlib.h>
55     ],
56     [
57       Display *d;
58       Window w;
59       XkbBell(d, w, 0, 0);
60     ],
61     [
62       AC_MSG_RESULT([yes])
63       XKB="yes"
64       AC_DEFINE([XKB], [1], [Found the XKB extension])
65
66       XKB_CFLAGS=""
67       XKB_LIBS=""
68       AC_SUBST(XKB_CFLAGS)
69       AC_SUBST(XKB_LIBS)
70     ],
71     [ 
72       AC_MSG_RESULT([no])
73       XKB="no"
74     ])
75   )
76
77   LIBS=$OLDLIBS
78   CPPFLAGS=$OLDCPPFLAGS
79
80   AC_MSG_CHECKING([for the Xkb extension])
81   if test "$XKB" = "yes"; then
82     AC_MSG_RESULT([yes])
83   else
84     AC_MSG_RESULT([no])
85   fi
86 ])
87
88 # X11_EXT_XRANDR()
89 #
90 # Check for the presence of the "XRandR" X Window System extension.
91 # Defines "XRANDR" and sets the $(XRANDR) variable to "yes" if the extension is
92 # present.
93 AC_DEFUN([X11_EXT_XRANDR],
94 [
95   AC_REQUIRE([X11_DEVEL])
96
97   # Store these
98   OLDLIBS=$LIBS
99   OLDCPPFLAGS=$CPPFLAGS
100      
101   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
102   LIBS="$LIBS $X_LIBS -lXext -lXrender -lXrandr"
103
104   AC_CHECK_LIB([Xrandr], [XRRSelectInput],
105     AC_MSG_CHECKING([for X11/extensions/Xrandr.h])
106     AC_TRY_LINK(
107     [
108       #include <X11/Xlib.h>
109       #include <X11/extensions/Xrandr.h>
110     ],
111     [
112       Display *d;
113       Drawable r;
114       int i;
115       XRRQueryExtension(d, &i, &i);
116       XRRGetScreenInfo(d, r);
117     ],
118     [
119       AC_MSG_RESULT([yes])
120       XRANDR="yes"
121       AC_DEFINE([XRANDR], [1], [Found the XRandR extension])
122
123       XRANDR_CFLAGS=""
124       XRANDR_LIBS="-lXext -lXrender -lXrandr"
125       AC_SUBST(XRANDR_CFLAGS)
126       AC_SUBST(XRANDR_LIBS)
127     ],
128     [ 
129       AC_MSG_RESULT([no])
130       XRANDR="no"
131     ])
132   )
133
134   LIBS=$OLDLIBS
135   CPPFLAGS=$OLDCPPFLAGS
136
137   AC_MSG_CHECKING([for the XRandR extension])
138   if test "$XRANDR" = "yes"; then
139     AC_MSG_RESULT([yes])
140   else
141     AC_MSG_RESULT([no])
142   fi
143 ])
144
145 # X11_EXT_SHAPE()
146 #
147 # Check for the presence of the "Shape" X Window System extension.
148 # Defines "SHAPE", sets the $(SHAPE) variable to "yes", and sets the $(LIBS)
149 # appropriately if the extension is present.
150 AC_DEFUN([X11_EXT_SHAPE],
151 [
152   AC_REQUIRE([X11_DEVEL])
153
154   # Store these
155   OLDLIBS=$LIBS
156   OLDCPPFLAGS=$CPPFLAGS
157      
158   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
159   LIBS="$LIBS $X_LIBS"
160
161   AC_CHECK_LIB([Xext], [XShapeCombineShape],
162     AC_MSG_CHECKING([for X11/extensions/shape.h])
163     AC_TRY_LINK(
164     [
165       #include <X11/Xlib.h>
166       #include <X11/Xutil.h>
167       #include <X11/extensions/shape.h>
168     ],
169     [
170       long foo = ShapeSet;
171     ],
172     [
173       AC_MSG_RESULT([yes])
174       SHAPE="yes"
175       AC_DEFINE([SHAPE], [1], [Found the XShape extension])
176
177       XSHAPE_CFLAGS=""
178       XSHAPE_LIBS="-lXext"
179       AC_SUBST(XSHAPE_CFLAGS)
180       AC_SUBST(XSHAPE_LIBS)
181     ],
182     [ 
183       AC_MSG_RESULT([no])
184       SHAPE="no"
185     ])
186   )
187
188   LIBS=$OLDLIBS
189   CPPFLAGS=$OLDCPPFLAGS
190  
191   AC_MSG_CHECKING([for the Shape extension])
192   if test "$SHAPE" = "yes"; then
193     AC_MSG_RESULT([yes])
194   else
195     AC_MSG_RESULT([no])
196   fi
197 ])
198
199
200 # X11_EXT_XINERAMA()
201 #
202 # Check for the presence of the "Xinerama" X Window System extension.
203 # Defines "XINERAMA", sets the $(XINERAMA) variable to "yes", and sets the
204 # $(LIBS) appropriately if the extension is present.
205 AC_DEFUN([X11_EXT_XINERAMA],
206 [
207   AC_REQUIRE([X11_DEVEL])
208
209   # Store these
210   OLDLIBS=$LIBS
211   OLDCPPFLAGS=$CPPFLAGS
212      
213   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
214   LIBS="$LIBS $X_LIBS -lXext"
215
216   AC_CHECK_LIB([Xinerama], [XineramaQueryExtension],
217   [
218     AC_MSG_CHECKING([for X11/extensions/Xinerama.h])
219     AC_TRY_LINK(
220     [
221       #include <X11/Xlib.h>
222       #include <X11/extensions/Xinerama.h>
223     ],
224     [
225       XineramaScreenInfo foo;
226     ],
227     [
228       AC_MSG_RESULT([yes])
229       XINERAMA="yes"
230       AC_DEFINE([XINERAMA], [1], [Enable support of the Xinerama extension])
231       XINERAMA_LIBS="-lXext -lXinerama"
232       AC_SUBST(XINERAMA_LIBS)
233     ],
234     [
235       AC_MSG_RESULT([no])
236       XINERAMA="no"
237     ])
238   ])
239
240   LIBS=$OLDLIBS
241   CPPFLAGS=$OLDCPPFLAGS
242
243   AC_MSG_CHECKING([for the Xinerama extension])
244   if test "$XINERAMA" = "yes"; then
245     AC_MSG_RESULT([yes])
246   else
247     AC_MSG_RESULT([no])
248   fi
249 ])
250
251 # X11_EXT_SYNC()
252 #
253 # Check for the presence of the "Sync" X Window System extension.
254 # Defines "SYNC", sets the $(SYNC) variable to "yes", and sets the $(LIBS)
255 # appropriately if the extension is present.
256 AC_DEFUN([X11_EXT_SYNC],
257 [
258   AC_REQUIRE([X11_DEVEL])
259
260   # Store these
261   OLDLIBS=$LIBS
262   OLDCPPFLAGS=$CPPFLAGS
263      
264   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
265   LIBS="$LIBS $X_LIBS"
266
267   AC_CHECK_LIB([Xext], [XSyncInitialize],
268     AC_MSG_CHECKING([for X11/extensions/sync.h])
269     AC_TRY_LINK(
270     [
271       #include <X11/Xlib.h>
272       #include <X11/Xutil.h>
273       #include <X11/extensions/sync.h>
274     ],
275     [
276       XSyncValueType foo;
277     ],
278     [
279       AC_MSG_RESULT([yes])
280       SYNC="yes"
281       AC_DEFINE([SYNC], [1], [Found the XSync extension])
282
283       XSYNC_CFLAGS=""
284       XSYNC_LIBS="-lXext"
285       AC_SUBST(XSYNC_CFLAGS)
286       AC_SUBST(XSYNC_LIBS)
287     ],
288     [ 
289       AC_MSG_RESULT([no])
290       SYNC="no"
291     ])
292   )
293
294   LIBS=$OLDLIBS
295   CPPFLAGS=$OLDCPPFLAGS
296  
297   AC_MSG_CHECKING([for the Sync extension])
298   if test "$SYNC" = "yes"; then
299     AC_MSG_RESULT([yes])
300   else
301     AC_MSG_RESULT([no])
302   fi
303 ])
304
305 # X11_EXT_AUTH()
306 #
307 # Check for the presence of the "Xau" X Window System extension.
308 # Defines "AUTH, sets the $(AUTH) variable to "yes", and sets the $(LIBS)
309 # appropriately if the extension is present.
310 AC_DEFUN([X11_EXT_AUTH],
311 [
312   AC_REQUIRE([X11_DEVEL])
313
314   # Store these
315   OLDLIBS=$LIBS
316   OLDCPPFLAGS=$CPPFLAGS
317
318   CPPFLAGS="$CPPFLAGS $X_CFLAGS"
319   LIBS="$LIBS $X_LIBS"
320
321   AC_CHECK_LIB([Xau], [XauReadAuth],
322     AC_MSG_CHECKING([for X11/Xauth.h])
323     AC_TRY_LINK(
324     [
325       #include <X11/Xlib.h>
326       #include <X11/Xutil.h>
327       #include <X11/Xauth.h>
328     ],
329     [
330     ],
331     [
332       AC_MSG_RESULT([yes])
333       AUTH="yes"
334       AC_DEFINE([AUTH], [1], [Found the Xauth extension])
335
336       XAUTH_CFLAGS=""
337       XAUTH_LIBS="-lXau"
338       AC_SUBST(XAUTH_CFLAGS)
339       AC_SUBST(XAUTH_LIBS)
340     ],
341     [
342       AC_MSG_RESULT([no])
343       AUTH="no"
344     ])
345   )
346
347   LIBS=$OLDLIBS
348   CPPFLAGS=$OLDCPPFLAGS
349
350   AC_MSG_CHECKING([for the Xauth extension])
351   if test "$AUTH" = "yes"; then
352     AC_MSG_RESULT([yes])
353   else
354     AC_MSG_RESULT([no])
355   fi
356 ])
357
358 # X11_SM()
359 #
360 # Check for the presence of SMlib for session management.
361 # Defines "USE_SM" if SMlib is present.
362 AC_DEFUN([X11_SM],
363 [
364   AC_REQUIRE([X11_DEVEL])
365
366   AC_ARG_ENABLE([session-management],
367   AC_HELP_STRING(
368   [--disable-session-management], [build without support for session managers [[default=enabled]]]),
369   [SM=$enableval], [SM="yes"])
370   
371   if test "$SM" = "yes"; then
372     # Store these
373     OLDLIBS=$LIBS
374     OLDCPPFLAGS=$CPPFLAGS
375      
376     CPPFLAGS="$CPPFLAGS $X_CFLAGS"
377     LIBS="$LIBS $X_LIBS"
378
379     SM="no"
380
381     AC_CHECK_LIB([SM], [SmcSaveYourselfDone], [
382       AC_CHECK_HEADERS([X11/SM/SMlib.h], [
383         SM_CFLAGS="$X_CFLAGS"
384         SM_LIBS="-lSM -lICE"
385         AC_DEFINE(USE_SM, 1, [Use session management])
386         AC_SUBST(SM_CFLAGS)
387         AC_SUBST(SM_LIBS)
388         SM="yes"
389       ])
390     ])
391   fi
392
393   LIBS=$OLDLIBS
394   CPPFLAGS=$OLDCPPFLAGS
395
396   AC_MSG_CHECKING([for session management support])
397   if test "$SM" = "yes"; then
398     AC_MSG_RESULT([yes])
399   else
400     AC_MSG_RESULT([no])
401   fi
402 ])