Install gettext-0.18.1.1.tar.gz
[msysgit.git] / mingw / share / doc / gettext / examples / hello-c++-qt / m4 / qt.m4
blobb734356a129fbd864c3cf1e968b7eb138ddcd873
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
4 # is preserved.
6 # FUN_TYPE BOOL
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])
13     
14   AC_LANG_PUSH(C++)
15   AC_CHECK_TYPE(bool, ac_check_bool=yes, ac_check_bool=no) 
16   AC_LANG_POP(C++)
17   if test "x$ac_check_bool" = "xyes" ; then
18     AC_DEFINE(HAVE_BOOL,,[define if bool is a built-in type])
19   fi
21   AH_BOTTOM([#ifndef HAVE_BOOL])
22   AH_BOTTOM([enum booltyp { false, true }; typedef enum booltyp bool;])
23   AH_BOTTOM([#endif])
24 ])# FUN_TYPE_BOOL
26 # FUN_HEADER_STDCXX
27 # check for standard ISO C++ headers
29 AC_DEFUN([FUN_HEADER_STDCXX],
31   AC_REQUIRE([AC_PROG_CXX])
33   AC_LANG_PUSH(C++)
35   ac_check_headers=no
36   AC_CHECK_HEADER(cstdlib,
37       ac_check_headers=yes,
38       ac_check_headers=no)
39   AC_CHECK_HEADER(cstring,
40       ac_check_headers=$ac_check_headers,
41       ac_check_headers=no)
42   AC_CHECK_HEADER(iostream,
43       ac_check_headers=$ac_check_headers,
44       ac_check_headers=no)
46   AC_LANG_POP(C++)
48   if test "x$ac_check_headers" = "xno" ; then
49     AC_MSG_ERROR(standard ISO C++ headers not found!)
50   fi
51 ])#FUN_HEADER_STDCXX
53 # FUN_CHECK_PTHREAD
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])
63   PTHREAD_LIBS=""
64   PTHREAD_CFLAGS=""
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
84         AC_MSG_RESULT([yes])
85         PTHREAD_CFLAGS="-pthread"
86       else
87         AC_MSG_RESULT([no])
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)
92         fi
93         if test "x$ac_thread_library" = "xnone" ; then
94           AC_CHECK_LIB(pthread, pthread_self, ac_thread_library=pthread)
95         fi
96         if test "x$ac_thread_library" = "xnone" ; then
97           AC_CHECK_LIB(pthreads, pthread_self, ac_thread_library=pthreads)
98         fi
99         if test "x$ac_thread_library" = "xnone" ; then
100           AC_CHECK_LIB(thread, pthread_self, ac_thread_library=thread)
101         fi
102         if test "x$ac_thread_library" = "xnone" ; then
103           AC_CHECK_LIB(gthreads, pthread_self, ac_thread_library=gthreads)
104         fi
105         if test "x$ac_thread_library" = "xnone" ; then
106           AC_CHECK_LIB(c, pthread_self, ac_thread_library=c)
107         fi
108         if test "x$ac_thread_library" = "xnone" ; then
109           ac_use_threads=no
110         else
111           PTHREAD_LIBS="-l$ac_thread_library"
112         fi
113       fi
114     else
115       ac_use_threads=no
116     fi
117   fi
119   if test "x$ac_use_threads" = "xyes" ; then
120     AC_DEFINE(HAVE_PTHREAD, 1, [Define if you have POSIX threads])
121     case $host_os in
122       aix* | freebsd*)
123         PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_THREAD_SAFE"
124         ;;
125       linux* | solaris*)
126         PTHREAD_CFLAGS="$PTHREAD_CFLAGS -D_REENTRANT"
127         ;;
128       *)
129         ;;
130     esac
131   fi
132 ])#FUN_CHECK_PTHREAD
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)
154   AC_CACHE_SAVE
156   AC_MSG_NOTICE([checking for Qt])
158   # process our args
159   if test -z "$1" ; then
160     qt_min_version=0
161   else
162     qt_min_version=$1
163   fi
164   if test -z "$2" ; then
165     qt_max_version=9999
166   else
167     qt_max_version=$2
168   fi
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;
173     fi
174   fi
175   if test "x$QTMAX" != "x" ; then
176     if expr $QTMAX '<' $qt_max_version > /dev/null ; then
177       qt_max_version=$QTMAX;
178     fi
179   fi
181   # set up our configuration options
182   qt_dir=""
183   qt_includes=""
184   qt_libraries=""
185   qt_programs=""
186   AC_ARG_WITH([qt_dir], AC_HELP_STRING([--with-qt-dir=DIR],
187                         [where the Qt package is installed]),
188     [ qt_dir="$withval"
189       qt_includes="$withval"/include
190       qt_libraries="$withval"/lib
191       qt_programs="$withval"/bin
192     ])
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"])
203   QTVERSION="000"
205   FUN_QT_HEADERS
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"
212   fi
214   FUN_QT_LIBRARIES
215   FUN_QT_PROGRAMS
216   FUN_QT_COMPILE
218   AC_MSG_NOTICE([Found Qt version $QTVERSION])
220   AC_SUBST(QTVERSION)
221   AC_SUBST(MOC)
222   AC_SUBST(UIC)
223   QT_CXXFLAGS="-I$qt_includes"
224   AC_SUBST(QT_CXXFLAGS)
225   QT_LDFLAGS="-L$qt_libraries"
226   AC_SUBST(QT_LDFLAGS)
227   QT_LIBS="$LIBQT"
228   AC_SUBST(QT_LIBS)
229 ])#FUN_CHECK_QT
231 # FUN_QT_HEADERS
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
241     qt_found_dirs=""
242     qt_include_dirs="
243       $QTDIR
244       /usr/include
245       /usr/local/include
246       /usr/X11R6/include
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"
258       fi
259     done
261     # find the latest version between min_version and max_version
262     qt_prev_version=$qt_min_version
263     qt_found_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
269           qt_includes=$n
270           qt_prev_version=$qt_current_version
271         fi
272       fi
273     done
274   fi
276   if test "x$qt_includes" = "x" ; then
277     AC_MSG_RESULT([no])
278     AC_MSG_ERROR([cannot find correct Qt headers!])
279   else
280     dnl TODO need to strip out white space
281     QTVERSION=$qt_prev_version;
282     AC_MSG_RESULT([$qt_includes])
283   fi
284 ])#FUN_QT_HEADERS
286 # FUN_QT_LIBRARIES
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
299       LIBQT="-lqt-mt"
300     else
301       LIBQT="-lqt"
302     fi
303   fi
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
314         break
315       else
316         # lop off tail of path
317         dnl not as portable as it should be...
318         qt_tree="`dirname $qt_tree`"
319       fi
320     done
321   fi  
323   if test "x$qt_libraries" = "x" ; then
324     AC_MSG_RESULT([no])
325     AC_MSG_ERROR([cannot find Qt libraries!])
326   else
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])
330     else
331       AC_MSG_RESULT([no])
332       if test "x$ac_use_threads" = "xyes" ; then
333         AC_MSG_ERROR([cannot find the threaded Qt library in $qt_libraries!])
334       else
335         AC_MSG_ERROR([cannot find the non-threaded Qt library in $qt_libraries!])
336       fi
337     fi
338   fi
339 ])#FUN_QT_LIBRARIES
341 # FUN_QT_PROGRAMS
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
358         break
359       else
360         # lop off tail of path
361         dnl not as portable as it should be...
362         qt_tree="`dirname $qt_tree`"
363       fi
364     done
365     # if we haven't found the progs, there's not much more we can do
366   fi  
368   if test "x$qt_programs" = "x" ; then
369     AC_MSG_RESULT([no])
370     AC_MSG_ERROR([cannot find Qt utilities!])
371   else
372     AC_MSG_RESULT([$qt_programs])
373     # find the right moc
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"
380         else
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"
384             fi
385           else
386             if expr "$QTVERSION" '>=' "300" > /dev/null ; then
387               if $qt_programs/moc3 > /dev/null 2> /dev/null ; then
388                 MOC="$qt_programs/moc3"
389               fi
390             fi
391           fi
392         fi
393       fi
394       if test "x$MOC" = "x" ; then
395         AC_MSG_RESULT([no])
396         AC_MSG_ERROR([cannot find Qt meta object compiler!])
397       fi
398     fi
400     # find the right uic
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"
408           else
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"
412               fi
413             fi
414           fi
415         fi
416       fi
417     else
418       # if uic is important to the build, change this
419       UIC=""
420     fi
421   fi
422 ])#FUN_QT_PROGRAMS
424 # FUN_QT_COMPILE
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])
436   AC_LANG_PUSH(C++)
438   ac_cxxflags_save="$CXXFLAGS"
439   ac_ldflags_save="$LDFLAGS"
440   ac_libs_save="$LIBS"
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"
445   AC_TRY_LINK([
446     #include <qglobal.h>
447     #include <qmessagebox.h>
448     #include <qstring.h>],
449     [QString s = "hello world";
450     QMessageBox::information(0, s, "no he is not");
451     return 0;],
452   qt_compile=yes, qt_compile=no)
454   CXXFLAGS="$ac_cxxflags_save"
455   LDFLAGS="$ac_ldflags_save"
456   LIBS="$ac_libs_save"
458   AC_LANG_POP(C++)
460   if test "x$qt_compile" = "xyes" ; then
461     AC_MSG_RESULT([yes])
462   else
463     AC_MSG_RESULT([no])
464     AC_MSG_ERROR([cannot compile a Qt program!])
465   fi
466 ])#FUN_QT_COMPILE