1 # Copyright (C) 2001 David Johnson
2 # This file is free software; the author gives unlimited permission to copy
3 # and/or distribute it, with or without modifications, as long as this notice
7 # check for a built-in bool type
8 # HAVE_BOOL will be defined in the config header
10 AC_DEFUN([FUN_TYPE_BOOL],
12 AC_REQUIRE([AC_PROG_CXX])
15 AC_CHECK_TYPE(bool, ac_check_bool=yes, ac_check_bool=no)
17 if test "x$ac_check_bool" = "xyes" ; then
18 AC_DEFINE(HAVE_BOOL,,[define if bool is a built-in type])
21 AH_BOTTOM([#ifndef HAVE_BOOL])
22 AH_BOTTOM([enum booltyp { false, true }; typedef enum booltyp bool;])
27 # check for standard ISO C++ headers
29 AC_DEFUN([FUN_HEADER_STDCXX],
31 AC_REQUIRE([AC_PROG_CXX])
36 AC_CHECK_HEADER(cstdlib,
39 AC_CHECK_HEADER(cstring,
40 ac_check_headers=$ac_check_headers,
42 AC_CHECK_HEADER(iostream,
43 ac_check_headers=$ac_check_headers,
48 if test "x$ac_check_headers" = "xno" ; then
49 AC_MSG_ERROR(standard ISO C++ headers not found!)
54 # check for posix pthreads
55 # sets PTHREAD_LIBS and PTHREAD_CFLAGS
56 # sets HAVE_PTHREADS in the configuration header
58 AC_DEFUN([FUN_CHECK_PTHREAD],
60 AC_REQUIRE([AC_CANONICAL_HOST])
61 AC_REQUIRE([AC_PROG_CC])
66 AC_ARG_ENABLE(threads, AC_HELP_STRING([--enable-threads],
67 [enable the use of the threads [[default=no]]]),
68 ac_use_threads=$enableval, ac_use_threads=no)
70 if test "x$ac_use_threads" = "xyes" ; then
72 AC_CHECK_HEADER(pthread.h, ac_posix_threads=yes, ac_posix_threads=no)
74 if test "x$ac_posix_threads" = "xyes" ; then
76 AC_MSG_CHECKING([whether ${CC} accepts -pthread])
77 ac_cflags_save="$CFLAGS"
78 CFLAGS="$CFLAGS -pthread"
79 AC_TRY_COMPILE([#include <pthread.h>], [pthread_attr_init(0)],
80 ac_cc_pthread=yes, ac_cc_pthread=no)
81 CFLAGS="$ac_cflags_save"
83 if test "x$ac_cc_pthread" = "xyes" ; then
85 PTHREAD_CFLAGS="-pthread"
88 ac_thread_library=none
90 if test "x$ac_thread_library" = "xnone" ; then
91 AC_CHECK_LIB(c_r, pthread_self, ac_thread_library=c_r)
93 if test "x$ac_thread_library" = "xnone" ; then
94 AC_CHECK_LIB(pthread, pthread_self, ac_thread_library=pthread)
96 if test "x$ac_thread_library" = "xnone" ; then
97 AC_CHECK_LIB(pthreads, pthread_self, ac_thread_library=pthreads)
99 if test "x$ac_thread_library" = "xnone" ; then
100 AC_CHECK_LIB(thread, pthread_self, ac_thread_library=thread)
102 if test "x$ac_thread_library" = "xnone" ; then
103 AC_CHECK_LIB(gthreads, pthread_self, ac_thread_library=gthreads)
105 if test "x$ac_thread_library" = "xnone" ; then
106 AC_CHECK_LIB(c, pthread_self, ac_thread_library=c)
108 if test "x$ac_thread_library" = "xnone" ; then
111 PTHREAD_LIBS="-l$ac_thread_library"
119 if test "x$ac_use_threads" = "xyes" ; then
120 AC_DEFINE(HAVE_PTHREAD, 1, [Define if you have POSIX threads])
123 PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_THREAD_SAFE"
126 PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_REENTRANT"
134 # FUN_CHECK_QT([qt_min_version],[qt_max_version])
135 # check for qt headers, libs, progs and compilation
136 # substs QT_CXXFLAGS, QT_LDFLAGS, and QT_LIBS
137 # substs QTVERSION, MOC and UIC
138 # LIBQT, MOC and UIC 'precious' variables
140 AC_DEFUN([FUN_CHECK_QT],
142 AC_REQUIRE([AC_PROG_CXX])
143 AC_REQUIRE([AC_PATH_X])
144 AC_REQUIRE([AC_PATH_XTRA])
145 AC_REQUIRE([FUN_CHECK_PTHREAD])
147 # some 'precious' variables for configure --help
148 AC_ARG_VAR(QTMIN, minimum version of Qt to search for e.g. 220)
149 AC_ARG_VAR(QTMAX, maximum version of Qt to search for e.g. 399)
150 AC_ARG_VAR(LIBQT, library flag for the Qt libary e.g. -lqt)
151 AC_ARG_VAR(MOC, QT meta object compiler command)
152 AC_ARG_VAR(UIC, Qt UI compiler command)
156 AC_MSG_NOTICE([checking for Qt])
159 if test -z "$1" ; then
164 if test -z "$2" ; then
169 # adjust for user preferences
170 if test "x$QTMIN" != "x" ; then
171 if expr $QTMIN '>' $qt_min_version > /dev/null ; then
172 qt_min_version=$QTMIN;
175 if test "x$QTMAX" != "x" ; then
176 if expr $QTMAX '<' $qt_max_version > /dev/null ; then
177 qt_max_version=$QTMAX;
181 # set up our configuration options
186 AC_ARG_WITH([qt_dir], AC_HELP_STRING([--with-qt-dir=DIR],
187 [where the Qt package is installed]),
189 qt_includes="$withval"/include
190 qt_libraries="$withval"/lib
191 qt_programs="$withval"/bin
193 AC_ARG_WITH([qt_includes], AC_HELP_STRING([--with-qt-includes=DIR],
194 [where the Qt includes are installed]),
195 [qt_includes="$withval"])
196 AC_ARG_WITH([qt_libraries], AC_HELP_STRING([--with-qt-libraries=DIR],
197 [where the Qt libraries are installed]),
198 [qt_libraries="$withval"])
199 AC_ARG_WITH([qt_programs], AC_HELP_STRING([--with-qt-programs=DIR],
200 [where the Qt programs are installed]),
201 [qt_programs="$withval"])
207 # check for a traditional qt installation tree
208 if ls $qt_includes/../lib/libqt* > /dev/null 2> /dev/null; then
209 qt_dir="`echo $qt_includes | sed s,'/include',,`"
210 qt_libraries="$qt_dir/lib"
211 qt_programs="$qt_dir/bin"
218 AC_MSG_NOTICE([Found Qt version $QTVERSION])
223 QT_CXXFLAGS="-I$qt_includes"
224 AC_SUBST(QT_CXXFLAGS)
225 QT_LDFLAGS="-L$qt_libraries"
232 # helper function for FUN_CHECK_QT
233 # check for qt headers in standard locations
235 AC_DEFUN([FUN_QT_HEADERS],
237 AC_MSG_CHECKING([for Qt headers])
239 if test "x$qt_includes" = "x" ; then
240 # look in standard locations
247 `ls -dr /usr/include/qt* 2>/dev/null`
248 `ls -dr /usr/local/include/qt* 2>/dev/null`
249 `ls -dr /usr/X11R6/include/qt* 2>/dev/null`
250 `ls -dr /usr/lib/qt*/include 2>/dev/null`
251 `ls -dr /usr/local/lib/qt*/include 2>/dev/null`
252 `ls -dr /usr/X11R6/lib/qt*/include 2>/dev/null`
253 `ls -dr /usr/local/qt*/include 2>/dev/null`
254 `ls -dr /opt/qt*/include 2>/dev/null` "
255 for n in $qt_include_dirs ; do
256 if test -r "$n/qglobal.h"; then
257 qt_found_dirs="$qt_found_dirs $n"
261 # find the latest version between min_version and max_version
262 qt_prev_version=$qt_min_version
264 for n in $qt_found_dirs ; do
265 qt_current_version=`grep -w '#define QT_VERSION' $n/qglobal.h |
266 sed s/'#define QT_VERSION'//`
267 if expr $qt_current_version '>=' $qt_prev_version > /dev/null ; then
268 if expr $qt_current_version '<=' $qt_max_version > /dev/null ; then
270 qt_prev_version=$qt_current_version
276 if test "x$qt_includes" = "x" ; then
278 AC_MSG_ERROR([cannot find correct Qt headers!])
280 dnl TODO need to strip out white space
281 QTVERSION=$qt_prev_version;
282 AC_MSG_RESULT([$qt_includes])
287 # helper function for FUN_CHECK_QT
288 # check for qt libs in standard locations
290 AC_DEFUN([FUN_QT_LIBRARIES],
292 AC_REQUIRE([FUN_QT_HEADERS])
294 AC_MSG_CHECKING([for Qt libraries])
296 # check which library to look for
297 if test -z "$LIBQT" ; then
298 if test "x$ac_use_threads" = "xyes" ; then
305 lib_qt=`echo $LIBQT | sed s/'-l'//`
307 if test "x$qt_libraries" = "x" ; then
308 # see if it is relative to the includes
309 qt_tree="$qt_includes"
310 while test "x$qt_tree" != "x" ; do
311 # first go around will fail...
312 if ls $qt_tree/lib/libqt* > /dev/null 2> /dev/null ; then
313 qt_libraries=$qt_tree/lib
316 # lop off tail of path
317 dnl not as portable as it should be...
318 qt_tree="`dirname $qt_tree`"
323 if test "x$qt_libraries" = "x" ; then
325 AC_MSG_ERROR([cannot find Qt libraries!])
327 # check that we're looking at the right library
328 if ls $qt_libraries/lib$lib_qt.* > /dev/null 2> /dev/null ; then
329 AC_MSG_RESULT([$qt_libraries])
332 if test "x$ac_use_threads" = "xyes" ; then
333 AC_MSG_ERROR([cannot find the threaded Qt library in $qt_libraries!])
335 AC_MSG_ERROR([cannot find the non-threaded Qt library in $qt_libraries!])
342 # helper function for FUN_CHECK_QT
343 # searches for moc and uic
345 AC_DEFUN([FUN_QT_PROGRAMS],
347 AC_REQUIRE([FUN_QT_LIBRARIES])
349 AC_MSG_CHECKING([for Qt utilities])
351 if test "x$q_programs" = "x" ; then
352 # see if it is relative to the libraries
353 qt_tree="$qt_libraries"
354 while test "x$qt_tree" != "x" ; do
355 # first go around will fail
356 if ls $qt_tree/bin/moc* > /dev/null 2> /dev/null ; then
357 qt_programs=$qt_tree/bin
360 # lop off tail of path
361 dnl not as portable as it should be...
362 qt_tree="`dirname $qt_tree`"
365 # if we haven't found the progs, there's not much more we can do
368 if test "x$qt_programs" = "x" ; then
370 AC_MSG_ERROR([cannot find Qt utilities!])
372 AC_MSG_RESULT([$qt_programs])
374 if test -z "$MOC" ; then
375 AC_CHECK_PROG(MOC, moc, moc)
376 if test "x$MOC" = "x" ; then
377 # could be renamed to avoid clashes
378 if ls $qt_programs/moc > /dev/null 2> /dev/null ; then
379 MOC="$qt_programs/moc"
381 if expr "$QTVERSION" '>=' "200" > /dev/null ; then
382 if ls $qt_programs/moc2 > /dev/null 2> /dev/null ; then
383 MOC="$qt_programs/moc2"
386 if expr "$QTVERSION" '>=' "300" > /dev/null ; then
387 if $qt_programs/moc3 > /dev/null 2> /dev/null ; then
388 MOC="$qt_programs/moc3"
394 if test "x$MOC" = "x" ; then
396 AC_MSG_ERROR([cannot find Qt meta object compiler!])
401 if expr "$QTVERSION" '>=' "220" > /dev/null ; then
402 if test -z "$UIC" ; then
403 AC_CHECK_PROG(UIC, uic, uic)
404 if test "x$UIC" = "x" ; then
405 # could be renamed to avoid clashes
406 if ls $qt_programs/uic > /dev/null 2> /dev/null ; then
407 UIC="$qt_programs/uic"
409 if expr "$QTVERSION" '>=' "300" > /dev/null ; then
410 if ls $qt_programs/uic3 > /dev/null 2> /dev/null ; then
411 UIC="$qt_programs/uic3"
418 # if uic is important to the build, change this
425 # helper function for FUN_CHECK_QT
426 # compile a simple qt program
428 AC_DEFUN([FUN_QT_COMPILE],
430 AC_REQUIRE([FUN_QT_HEADERS])
431 AC_REQUIRE([FUN_QT_LIBRARIES])
432 AC_REQUIRE([FUN_QT_PROGRAMS])
434 AC_MSG_CHECKING([whether a simple Qt program compiles])
438 ac_cxxflags_save="$CXXFLAGS"
439 ac_ldflags_save="$LDFLAGS"
441 CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS -I$qt_includes $X_CFLAGS $all_includes"
442 LDFLAGS="$LDFLAGS -L$qt_libraries $X_LIBS "
443 LIBS="$LIBS $PTHREAD_LIBS $X_PRE_LIBS $X_EXTRA_LIBS -lXext -lX11 $LIBQT"
447 #include <qmessagebox.h>
448 #include <qstring.h>],
449 [QString s = "hello world";
450 QMessageBox::information(0, s, "no he is not");
452 qt_compile=yes, qt_compile=no)
454 CXXFLAGS="$ac_cxxflags_save"
455 LDFLAGS="$ac_ldflags_save"
460 if test "x$qt_compile" = "xyes" ; then
464 AC_MSG_ERROR([cannot compile a Qt program!])