version 0.3.0
[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.3.0)
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/XTest.h>\nmain(){}'|$CC -I$XINCDIR -xc - -o dum 2>/dev/null
174 if test $? != 0 ; then
175    echo "Can not include $XINCDIR/X11/extensions/XTest.h header file!"
176    SOMEERROR=1
177 else
178    echo "$XINCDIR/X11/extensions/XTest.h OK"
179 fi
180
181 rm -f dum
182
183 if test $SOMEERROR != 0 ; then
184    echo $'\nThe X compiling environment is NOT complete!
185 Some linux distributions omit parts of, or sometimes
186 the whole, X development environment. Based on the
187 error message(s) above you should be able to hunt down
188 which package(s) you need to install. For example, one
189 distribution call their xinput and xtest packages
190 libxi-dev and libxtst-dev\n'
191    exit
192 else
193    echo $'\nThe X compiling environment seems to be all OK\n'
194 fi
195
196 ])
197
198 dnl --- End function for checking Xlib details ---
199
200 dnl --- Call functions to check X libraries and includes ---
201
202 AC_CHECK_XLIB
203 AC_CHECK_XINC
204
205 dnl --- Check if we should build expresskeys (default yes) ---
206
207 EXPRESSKEYS_DEFAULT=yes
208 OPTION_EXPRESSKEYS=no
209 AC_ARG_ENABLE(expresskeys,
210 AC_HELP_STRING([--enable-expresskeys], [Enable building expresskeys [[default=yes]]]),
211         , enable_expresskeys=$EXPRESSKEYS_DEFAULT)
212 if test "$enable_expresskeys" != "no"; then
213         if test x$ENV_XLIB != xyes; then
214                 echo "***"; echo "*** WARNING libraries:";
215                 echo "*** We failed to locate a full Xlib environment,"
216                 echo "*** and will therefore not build expresskeys."
217                 echo "*** Try './configure --with-xlib=/some/directory'"
218                 echo "*** where your Xlib libraries can be found."
219                 echo "*** By default we test what is returned from the"
220                 echo "*** command 'pkg-config --variable=libdir x11'"
221                 echo "*** which works in the modular X11R7 releases."
222                 echo "*** If that fails, we try a hardcoded $XLIBDIR_X11R6"
223                 echo "*** for the monolithic X11R6 releases. Both these"
224                 echo "*** tests have obviously failed to produce a path."
225                 echo "*** "
226                 echo "***"
227                 exit
228         else
229                 OPTION_EXPRESSKEYS=yes
230                 EXPRESSKEYS_LIBS="-L$XLIBDIR -lX11 -lXi -lXtst"
231                 SRC_DIRS="$SRC_DIRS $SRC_EXPRESSKEYS"
232         fi
233         if test x$ENV_XINC != xyes; then
234                 echo "***"; echo "*** WARNING include files:";
235                 echo "*** We failed to locate a full Xlib environment,"
236                 echo "*** and will therefore not build expresskeys."
237                 echo "*** Try './configure --with-xinc=/some/directory'"
238                 echo "*** where your Xlib include files can be found."
239                 echo "*** By default we test what is returned from the"
240                 echo "*** command 'pkg-config --variable=includedir x11'"
241                 echo "*** which works in the modular X11R7 releases."
242                 echo "*** If that fails, we try a hardcoded $XINCDIR_X11R6"
243                 echo "*** for the monolithic X11R6 releases. Both these"
244                 echo "*** tests have obviously failed to produce a path."
245                 echo "*** "
246                 echo "***"
247                 exit
248         else
249                 EXPRESSKEYS_INCL="-I$XINCDIR"
250         fi
251 fi
252
253 dnl --- Call function to check X in detail ---
254
255 AC_CHECK_XDETAIL
256
257 dnl --- Separate test output from file-generation output ---
258
259 AC_SUBST(SRC_DIRS)
260 AC_SUBST(EXPRESSKEYS_LIBS)
261 AC_SUBST(EXPRESSKEYS_INCL)
262
263 dnl --- Create the files ---
264
265 AC_OUTPUT(Makefile
266         src-expresskeys/Makefile)
267
268 dnl --- Show the result ---
269
270 echo ""
271 echo "----------------------------------------"
272 echo "  BUILD ENVIRONMENT:"
273 echo "      X libraries - $ENV_XLIB $XLIBDIR"
274 echo "       X includes - $ENV_XINC $XINCDIR"
275 echo ""
276 echo "  BUILD OPTIONS:"
277 echo "      expresskeys - $OPTION_EXPRESSKEYS"
278 echo "----------------------------------------"
279 echo ""
280