e363eab0c96a6ecf6d823cd0e17e255c6655405e
[expresskeys.git] / configure.in
1 dnl --- Process this file with autoconf to produce a configure script ---
2
3 dnl --- Style and some code below nicked from the linuxwacom package ;-) ---
4
5 AC_INIT(src-expresskeys/main_setup.c)
6 AM_CONFIG_HEADER(config.h)
7 AM_INIT_AUTOMAKE(expresskeys, 0.4.1)
8 AM_MAINTAINER_MODE
9 AC_PROG_CC
10
11 dnl --- Check for the presence of header files not included in a standard check.
12 AC_CHECK_HEADERS([stdio.h ctype.h signal.h libgen.h])
13
14 dnl --- Specify our source directories. OBS: If they change, AC_OUTPUT must
15 dnl also be changed accordingly (at the end of this file) ---
16
17 SRC_DIRS=""
18 SRC_EXPRESSKEYS=src-expresskeys
19
20 dnl --- Specify some old monolithic X paths. 
21
22 if test -d /usr/X11R6/lib64 ; then
23         XLIBDIR_X11R6=/usr/X11R6/lib64
24 else
25         XLIBDIR_X11R6=/usr/X11R6/lib
26 fi
27
28 XINCDIR_X11R6=/usr/X11R6/include
29
30 dnl --- Start with a clean slate.
31
32 ENV_XLIB=no
33 ENV_XINC=no
34
35 dnl --- Begin function for checking Xlib library environment ---
36
37 AC_DEFUN([AC_CHECK_XLIB],[
38 XLIBDIR=
39 AC_ARG_WITH(xlib,
40 AS_HELP_STRING([--with-xlib=dir], [use a specified X library directory]),
41 [XLIBDIR=$withval])
42
43 AC_MSG_CHECKING(for X library directory)
44
45 if test "$XLIBDIR" == ""; then
46         XLIBDIR_X11R7=$(pkg-config --variable=libdir x11 2>/dev/null)
47         if test $? != 0 || test ! -d $XLIBDIR_X11R7; then
48                 if test -d $XLIBDIR_X11R6; then
49                         XLIBDIR=$XLIBDIR_X11R6
50                         ENV_XLIB=yes
51                         AC_MSG_RESULT(found $XLIBDIR)
52                 else
53                         ENV_XLIB=no
54                         AC_MSG_RESULT(not found - tried $XLIBDIR_X11R6)
55                 fi
56         else
57                 XLIBDIR=$XLIBDIR_X11R7
58                 ENV_XLIB=yes
59                 AC_MSG_RESULT(found $XLIBDIR)
60         fi
61 elif test -d $XLIBDIR; then
62         ENV_XLIB=yes
63         AC_MSG_RESULT(found $XLIBDIR)
64 else
65         ENV_XLIB=no
66         AC_MSG_RESULT(not found - tried $XLIBDIR)
67 fi
68 ])
69
70 dnl --- End function for checking Xlib library environment ---
71
72 dnl --- Begin function for checking Xlib include environment ---
73
74 AC_DEFUN([AC_CHECK_XINC],[
75 XINCDIR=
76 AC_ARG_WITH(xinc,
77 AS_HELP_STRING([--with-xinc=dir], [use a specified X include directory]),
78 [XINCDIR=$withval])
79
80 AC_MSG_CHECKING(for X include directory)
81
82 if test "$XINCDIR" == ""; then
83         XINCDIR_X11R7=$(pkg-config --variable=includedir x11 2>/dev/null)
84         if test $? != 0 || test ! -d $XINCDIR_X11R7; then
85                 if test -d $XINCDIR_X11R6; then
86                         XINCDIR=$XINCDIR_X11R6
87                         ENV_XINC=yes
88                         AC_MSG_RESULT(found $XINCDIR)
89                 else
90                         ENV_XINC=no
91                         AC_MSG_RESULT(not found - tried $XINCDIR_X11R6)
92                 fi
93         else
94                 XINCDIR=$XINCDIR_X11R7
95                 ENV_XINC=yes
96                 AC_MSG_RESULT(found $XINCDIR)
97         fi
98 elif test -d $XINCDIR; then
99         ENV_XINC=yes
100         AC_MSG_RESULT(found $XINCDIR)
101 else
102         ENV_XINC=no
103         AC_MSG_RESULT(not found - tried $XINCDIR)
104 fi
105 ])
106
107 dnl --- End function for checking Xlib include environment ---
108
109 dnl --- Begin function for checking Xlib details ---
110
111 AC_DEFUN([AC_CHECK_XDETAIL],[
112
113 SOMEERROR=0
114
115 echo $'\nChecking the X compiling environment in detail...\n'
116
117 echo $'main(){}'|$CC -L$XLIBDIR -lX11 -xc - -o dum 2> /dev/null
118 if test $? != 0 ; then
119    echo "Can not link with X11 $XLIBDIR/libX11.so library!"
120    SOMEERROR=1
121 else
122    echo "$XLIBDIR/libX11.so OK"
123 fi
124
125 echo $'main(){}'|$CC -L$XLIBDIR -lXext -xc - -o dum 2> /dev/null
126 if test $? != 0 ; then
127    echo "Can not link with Xext $XLIBDIR/libXext.so library!"
128    SOMEERROR=1
129 else
130    echo "$XLIBDIR/libXext.so OK"
131 fi
132
133 echo $'main(){}'|$CC -L$XLIBDIR -lXi -xc - -o dum 2> /dev/null
134 if test $? != 0 ; then
135    echo "Can not link with Xi $XLIBDIR/libXi.so library!"
136    SOMEERROR=1
137 else
138    echo "$XLIBDIR/libXi.so OK"
139 fi
140
141 echo $'main(){}'|$CC -L$XLIBDIR -lXtst -xc - -o dum 2> /dev/null
142 if test $? != 0 ; then
143    echo "Can not link with Xtst $XLIBDIR/libXtst.so library!"
144    SOMEERROR=1
145 else
146    echo "$XLIBDIR/libXtst.so OK"
147 fi
148
149 echo $'#include <X11/Xlib.h>\nmain(){}'|$CC -I$XINCDIR -xc - -o dum 2> /dev/null
150 if test $? != 0 ; then
151    echo "Can not include $XINCDIR/X11/Xlib.h header file!"
152    SOMEERROR=1
153 else
154    echo "$XINCDIR/X11/Xlib.h OK"
155 fi
156
157 echo $'#include <X11/Xutil.h>\nmain(){}'|$CC -I$XINCDIR -xc - -o dum 2> /dev/null
158 if test $? != 0 ; then
159    echo "Can not include $XINCDIR/X11/Xutil.h header file!"
160    SOMEERROR=1
161 else
162    echo "$XINCDIR/X11/Xutil.h OK"
163 fi
164
165 echo $'#include <X11/extensions/XInput.h>\nmain(){}'|$CC -I$XINCDIR -xc - -o dum 2>/dev/null
166 if test $? != 0 ; then
167    echo "Can not include $XINCDIR/X11/extensions/XInput.h header file!"
168    SOMEERROR=1
169 else
170    echo "$XINCDIR/X11/extensions/XInput.h OK"
171 fi
172
173 echo $'#include <X11/extensions/XIproto.h>\nmain(){}'|$CC -I$XINCDIR -xc - -o dum 2>/dev/null
174 if test $? != 0 ; then
175    echo "Can not include $XINCDIR/X11/extensions/XIproto.h header file!"
176    SOMEERROR=1
177 else
178    echo "$XINCDIR/X11/extensions/XIproto.h OK"
179 fi
180
181 echo $'#include <X11/extensions/XTest.h>\nmain(){}'|$CC -I$XINCDIR -xc - -o dum 2>/dev/null
182 if test $? != 0 ; then
183    echo "Can not include $XINCDIR/X11/extensions/XTest.h header file!"
184    SOMEERROR=1
185 else
186    echo "$XINCDIR/X11/extensions/XTest.h OK"
187 fi
188
189 rm -f dum
190
191 if test $SOMEERROR != 0 ; then
192    echo $'\nThe X compiling environment is NOT complete!
193 Some linux distributions omit parts of, or sometimes
194 the whole, X development environment. Based on the
195 error message(s) above you should be able to hunt down
196 which package(s) you need to install. For example, one
197 distribution call their xinput and xtest packages
198 libxi-dev and libxtst-dev\n'
199    exit
200 else
201    echo $'\nThe X compiling environment seems to be all OK\n'
202 fi
203
204 ])
205
206 dnl --- End function for checking Xlib details ---
207
208 dnl --- Call functions to check X libraries and includes ---
209
210 AC_CHECK_XLIB
211 AC_CHECK_XINC
212
213 dnl --- Check if we should build expresskeys (default yes) ---
214
215 EXPRESSKEYS_DEFAULT=yes
216 OPTION_EXPRESSKEYS=no
217 AC_ARG_ENABLE(expresskeys,
218 AC_HELP_STRING([--enable-expresskeys], [Enable building expresskeys [[default=yes]]]),
219         , enable_expresskeys=$EXPRESSKEYS_DEFAULT)
220 if test "$enable_expresskeys" != "no"; then
221         if test x$ENV_XLIB != xyes; then
222                 echo "***"; echo "*** WARNING libraries:";
223                 echo "*** We failed to locate a full Xlib environment,"
224                 echo "*** and will therefore not build expresskeys."
225                 echo "*** Try './configure --with-xlib=/some/directory'"
226                 echo "*** where your Xlib libraries can be found."
227                 echo "*** By default we test what is returned from the"
228                 echo "*** command 'pkg-config --variable=libdir x11'"
229                 echo "*** which works in the modular X11R7 releases."
230                 echo "*** If that fails, we try a hardcoded $XLIBDIR_X11R6"
231                 echo "*** for the monolithic X11R6 releases. Both these"
232                 echo "*** tests have obviously failed to produce a path."
233                 echo "*** "
234                 echo "***"
235                 exit
236         else
237                 OPTION_EXPRESSKEYS=yes
238                 EXPRESSKEYS_LIBS="-L$XLIBDIR -lX11 -lXi -lXtst"
239                 SRC_DIRS="$SRC_DIRS $SRC_EXPRESSKEYS"
240         fi
241         if test x$ENV_XINC != xyes; then
242                 echo "***"; echo "*** WARNING include files:";
243                 echo "*** We failed to locate a full Xlib environment,"
244                 echo "*** and will therefore not build expresskeys."
245                 echo "*** Try './configure --with-xinc=/some/directory'"
246                 echo "*** where your Xlib include files can be found."
247                 echo "*** By default we test what is returned from the"
248                 echo "*** command 'pkg-config --variable=includedir x11'"
249                 echo "*** which works in the modular X11R7 releases."
250                 echo "*** If that fails, we try a hardcoded $XINCDIR_X11R6"
251                 echo "*** for the monolithic X11R6 releases. Both these"
252                 echo "*** tests have obviously failed to produce a path."
253                 echo "*** "
254                 echo "***"
255                 exit
256         else
257                 EXPRESSKEYS_INCL="-I$XINCDIR"
258         fi
259 fi
260
261 dnl --- Call function to check X in detail ---
262
263 AC_CHECK_XDETAIL
264
265 dnl --- Separate test output from file-generation output ---
266
267 AC_SUBST(SRC_DIRS)
268 AC_SUBST(EXPRESSKEYS_LIBS)
269 AC_SUBST(EXPRESSKEYS_INCL)
270
271 dnl --- Create the files ---
272
273 AC_OUTPUT(Makefile
274         src-expresskeys/Makefile)
275
276 dnl --- Show the result ---
277
278 echo ""
279 echo "----------------------------------------"
280 echo "  BUILD ENVIRONMENT:"
281 echo "      X libraries - $ENV_XLIB $XLIBDIR"
282 echo "       X includes - $ENV_XINC $XINCDIR"
283 echo ""
284 echo "  BUILD OPTIONS:"
285 echo "      expresskeys - $OPTION_EXPRESSKEYS"
286 echo "----------------------------------------"
287 echo ""
288