File: qt.m4

package info (click to toggle)
myodbc 5.1.6-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,096 kB
  • ctags: 2,202
  • sloc: ansic: 31,914; sh: 10,400; cpp: 3,472; xml: 1,328; makefile: 389; perl: 43
file content (383 lines) | stat: -rw-r--r-- 10,679 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# Copyright (C) 2001 David Johnson
# This file is free software; the author gives unlimited permission to  copy
# and/or distribute it, with or without modifications, as long as this notice
# is preserved.

#
# This was pulled from a gettext example on a SuSE 9.1 distro and has since been 
# enhanced to serve the purposes of unixODBC.
#
# Peter Harvey <pharvey@codebydesign.com> 30.AUG.05
#

# FUN_CHECK_QT([qt_min_version],[qt_max_version])
# check for qt headers, libs, progs and compilation
# substs QT_CXXFLAGS, QT_LDFLAGS, and QT_LIBS
# substs QTVERSION, MOC and UIC
# MOC and UIC 'precious' variables

AC_DEFUN([FUN_CHECK_QT],
[
  AC_REQUIRE([AC_PROG_CXX])
  AC_REQUIRE([AC_PATH_X])
  AC_REQUIRE([AC_PATH_XTRA])

  # some 'precious' variables for configure --help
  AC_ARG_VAR(QTMIN, minimum version of Qt to search for  e.g. export QTMIN=020400)
  AC_ARG_VAR(QTMAX, maximum version of Qt to search for  e.g. export QTMAX=030305)
  AC_ARG_VAR(MOC, QT meta object compiler command)
  AC_ARG_VAR(UIC, Qt UI compiler command)

  AC_CACHE_SAVE

  AC_MSG_NOTICE([checking for Qt])

  # process our args
  if test -z "$1" ; then
    qt_min_version=0
  else
    qt_min_version=$1
  fi
  if test -z "$2" ; then
    qt_max_version=99999
  else
    qt_max_version=$2
  fi
  # adjust for user preferences
  if test "x$QTMIN" != "x" ; then
      qt_min_version=$QTMIN;
#    fi
  fi
  if test "x$QTMAX" != "x" ; then
    if expr $QTMAX '<' $qt_max_version > /dev/null ; then
      qt_max_version=$QTMAX;
    fi
  fi

  # set up our configuration options
  qt_dir=""
  qt_includes=""
  qt_libraries=""
  qt_programs=""
  AC_ARG_WITH([qt_dir], AC_HELP_STRING([--with-qt-dir=DIR],
                        [where the Qt package is installed]),
    [ qt_dir="$withval"
      qt_includes="$withval"/include
      qt_libraries="$withval"/lib
      qt_programs="$withval"/bin
      QT_PATH_ARG="--with-qt-dir=$qt_dir"
    ])
  AC_SUBST(QT_PATH_ARG)
  AC_ARG_WITH([qt_includes], AC_HELP_STRING([--with-qt-includes=DIR],
                             [where the Qt includes are installed]),
    [qt_includes="$withval"])
  AC_ARG_WITH([qt_libraries], AC_HELP_STRING([--with-qt-libraries=DIR],
                              [where the Qt libraries are installed]),
    [qt_libraries="$withval"])
  AC_ARG_WITH([qt_programs], AC_HELP_STRING([--with-qt-programs=DIR],
                             [where the Qt programs are installed]),
    [qt_programs="$withval"])

  QTVERSION="00000"

  FUN_QT_HEADERS

  AC_MSG_NOTICE([Found Qt version $QTVERSION])

  FUN_QT_LIBRARIES
  FUN_QT_PROGRAMS
  FUN_QT_COMPILE

  AC_SUBST(QTVERSION)
  AC_SUBST(MOC)
  AC_SUBST(UIC)
  QT_CXXFLAGS="-I$qt_includes"
  AC_SUBST(QT_CXXFLAGS)
  QT_LDFLAGS="-L$qt_libraries"
  AC_SUBST(QT_LDFLAGS)
  QT_LIBS="$qt_libs"
  AC_SUBST(QT_LIBS)

  have_qt="yes"

])#FUN_CHECK_QT

# FUN_QT_HEADERS
# helper function for FUN_CHECK_QT
# check for qt headers in standard locations

AC_DEFUN([FUN_QT_HEADERS],
[
  AC_MSG_CHECKING([for Qt headers])

  qt_found_version=""

  # Have not been told where Qt is so search for it...
  if test "x$qt_includes" = "x" ; then
    # look in standard locations
    qt_found_dirs=""
    qt_include_dirs="
      $QTDIR/include
      /usr/include
      /usr/local/include
      /usr/X11R6/include
      `ls -dr /usr/include/qt* 2>/dev/null`
      `ls -dr /usr/local/include/qt* 2>/dev/null`
      `ls -dr /usr/X11R6/include/qt* 2>/dev/null`
      `ls -dr /usr/lib/qt*/include 2>/dev/null`
      `ls -dr /usr/local/lib/qt*/include 2>/dev/null`
      `ls -dr /usr/X11R6/lib/qt*/include 2>/dev/null`
      `ls -dr /usr/local/qt*/include 2>/dev/null`
      `ls -dr /usr/local/Trolltech/Qt*/include 2>/dev/null`
      `ls -dr /opt/qt*/include 2>/dev/null` "
    for n in $qt_include_dirs ; do
      if test -r "$n/qglobal.h"; then
        qt_found_dirs="$qt_found_dirs $n"
      else
        if test -r "$n/Qt/qglobal.h"; then
          qt_found_dirs="$qt_found_dirs $n"
	fi
      fi
    done

    # find the latest version between min_version and max_version
    qt_prev_version=$qt_min_version
    for n in $qt_found_dirs ; do

AC_MSG_NOTICE([Checking dir $n])
      FUN_QT_VERSION($n)	

      if expr $qt_current_version '>=' $qt_prev_version > /dev/null ; then
        if expr $qt_current_version '<=' $qt_max_version > /dev/null ; then
          qt_includes=$n
          qt_prev_version=$qt_current_version
          qt_found_version=$qt_current_version
        fi
      fi
    done
  fi

  if test "x$qt_includes" = "x" ; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([cannot find correct Qt headers!])
  else
    # Ensure we have a version...
    if test "x$qt_found_version" = "x" ; then
      FUN_QT_VERSION($qt_includes)
      qt_found_version=$qt_current_version
    fi
    if test "x$qt_found_version" = "x" ; then
      AC_MSG_RESULT([no])
      AC_MSG_ERROR([cannot find version of Qt!])
    fi

    dnl TODO need to strip out white space
    QTVERSION=$qt_found_version;
    AC_MSG_RESULT([$qt_includes])
  fi
])#FUN_QT_HEADERS

# FUN_QT_VERSION(qt_include_dir)
# helper function for FUN_QT_HEADERS
# get version from qglobal.h

AC_DEFUN([FUN_QT_VERSION],
[
  dnl the 2x versions need the extra sed 
  if test -r "$1/qglobal.h"; then
    qt_current_version=`grep '#define QT_VERSION ' "$1"/qglobal.h |
      sed s/'#define QT_VERSION 0x'// | sed s/'#define QT_VERSION  *'//`
  else
    if test -r "$1/Qt/qglobal.h"; then
# if test "x$qt_current_version" = "x" ; then
      qt_current_version=`grep '#define QT_VERSION ' "$1"/Qt/qglobal.h |
        sed s/'#define QT_VERSION 0x'// | sed s/'#define QT_VERSION  *'//`
    fi
  fi
])#FUN_QT_VERSION

# FUN_QT_LIBRARIES
# helper function for FUN_CHECK_QT
# check for qt libs in standard locations

AC_DEFUN([FUN_QT_LIBRARIES],
[
  AC_REQUIRE([FUN_QT_HEADERS])

  AC_MSG_CHECKING([for Qt libraries])

  # Ensure we have the lib dir...
  if test "x$qt_libraries" = "x"; then
    # see if it is relative to the includes
    qt_tree="$qt_includes"
    while test "x$qt_tree" != "x" -a "x$qt_tree" != "x/" ; do
      # Old test used "ls $qt_tree/lib/libQt*" but on Mac OS X 10.3 and
      # NetBSD 1.4 "ls" always return zero. Also different shells have
      # behaviour when there is no match, return the patter or empty string.
      qt_match_pat="$qt_tree/lib/lib[[qQ]]t*"
      qt_match_res=`echo $qt_match_pat 2>/dev/null`
      if test -n "$qt_match_res" -a "$qt_match_res" != "$qt_match_pat" ; then
	qt_libraries="$qt_tree/lib"
	break
      else
	# lop off tail of path
	dnl not as portable as it should be...
	qt_tree="`dirname $qt_tree`"
      fi
    done
  fi  

  # Use QTVERSION to set libs we need...
  if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
    qt_libs="-lQtGui -lQtCore"
  else
    qt_libs="-lqt-mt"
  fi

  # Return...
  if test "x$qt_libraries" = "x" ; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([cannot find Qt libraries!])
  else
    AC_MSG_RESULT([$qt_libraries])
  fi
])#FUN_QT_LIBRARIES

# FUN_QT_PROGRAMS
# helper function for FUN_CHECK_QT
# searches for moc and uic

AC_DEFUN([FUN_QT_PROGRAMS],
[
  AC_REQUIRE([FUN_QT_LIBRARIES])

  AC_MSG_CHECKING([for Qt utilities])

  if test "x$qt_programs" = "x" ; then
    # see if it is relative to the libraries
    qt_tree="$qt_libraries"
    while test "x$qt_tree" != "x" -a "x$qt_tree" != "x/" ; do
      # first go around will fail
      if test -x "$qt_tree/bin/moc" ; then
        qt_programs=$qt_tree/bin
        break
      else
        # lop off tail of path
        dnl not as portable as it should be...
        qt_tree="`dirname $qt_tree`"
      fi
    done
    # if we haven't found the progs, there's not much more we can do
  fi  

  if test "x$qt_programs" = "x" ; then
    AC_MSG_RESULT([no])
    AC_MSG_ERROR([cannot find Qt utilities!])
  else
    AC_MSG_RESULT([$qt_programs])
    if test "x$MOC" = "x" ; then
      # could be renamed to avoid clashes
      if test -x "$qt_programs/moc" ; then
	MOC="$qt_programs/moc"
      else
	if expr "$QTVERSION" '>=' "200" > /dev/null ; then
	  if test -x "$qt_programs/moc2" ; then
	    MOC="$qt_programs/moc2"
	  fi
	else
	  if expr "$QTVERSION" '>=' "300" > /dev/null ; then
	    if $qt_programs/moc3 > /dev/null 2> /dev/null ; then
	      MOC="$qt_programs/moc3"
	    fi
	  fi
	fi
      fi
      if test "x$MOC" = "x" ; then
        AC_MSG_RESULT([no])
        AC_MSG_ERROR([cannot find Qt meta object compiler!])
      fi
    fi

    # find the right uic
    if expr "$QTVERSION" '>=' "220" > /dev/null ; then
      if test "x$UIC" = "x" ; then
	# could be renamed to avoid clashes
	if test -x "$qt_programs/uic" ; then
	  UIC="$qt_programs/uic"
	else
	  if expr "$QTVERSION" '>=' "300" > /dev/null ; then
	    if test -x "$qt_programs/uic3" ; then
	      UIC="$qt_programs/uic3"
	    fi
	  fi
        fi
      fi
    else
      # if uic is important to the build, change this
      UIC=""
    fi
  fi
])#FUN_QT_PROGRAMS

# FUN_QT_COMPILE
# helper function for FUN_CHECK_QT
# compile a simple qt program

AC_DEFUN([FUN_QT_COMPILE],
[
  AC_REQUIRE([FUN_QT_HEADERS])
  AC_REQUIRE([FUN_QT_LIBRARIES])
  AC_REQUIRE([FUN_QT_PROGRAMS])

  AC_MSG_NOTICE([qt_libraries=$qt_libraries])
  AC_MSG_NOTICE([LDFLAGS=$LDFLAGS])
  AC_MSG_NOTICE([X_LIBS=$X_LIBS])

  AC_MSG_CHECKING([whether a simple Qt program compiles])

  AC_LANG_PUSH(C++)

  ac_cxxflags_save="$CXXFLAGS"
  ac_ldflags_save="$LDFLAGS"
  ac_libs_save="$LIBS"
  if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
    CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS -I$qt_includes -I$qt_includes/QtCore -I$qt_includes/QtGui $X_CFLAGS $all_includes"
  else
    CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS -I$qt_includes $X_CFLAGS $all_includes"
  fi
  LDFLAGS="$LDFLAGS -L$qt_libraries $X_LIBS $X_LDFLAGS"
  LIBS="$LIBS $PTHREAD_LIBS $qt_libs $X_EXTRA_LIBS $X_PRE_LIBS $EXTRA_XLIBS"

  if expr "$QTVERSION" '>=' "040000" > /dev/null ; then
    AC_TRY_LINK([
      #include <QMessageBox>
      #include <QString>],
      [QString s = "hello world";
      QMessageBox::information(0, s, "no he is not");
      return 0;],
    qt_compile=yes, qt_compile=no)
  else
    AC_TRY_LINK([
      #include <qmessagebox.h>
      #include <qstring.h>],
      [QString s = "hello world";
      QMessageBox::information(0, s, "no he is not");
      return 0;],
    qt_compile=yes, qt_compile=no)
  fi

  CXXFLAGS="$ac_cxxflags_save"
  LDFLAGS="$ac_ldflags_save"
  LIBS="$ac_libs_save"

  AC_LANG_POP(C++)

  if test "x$qt_compile" = "xyes" ; then
    AC_MSG_RESULT([yes])
  else
    AC_MSG_RESULT([no])
# We do not want to force everything to stop because we do not have 
# qt - let caller decide what to do.
#    AC_MSG_ERROR([cannot compile a Qt program!])
  fi
])#FUN_QT_COMPILE