Minor documentation improvements and fixes.
[ttfautohint.git] / m4 / autotroll.m4
blobcb20086b43dae2aac54b4988596650ec1838c73a
1 # Build Qt apps with the autotools (Autoconf/Automake).
2 # M4 macros.
4 # This file is part of AutoTroll.
6 # Copyright (C) 2006  Benoit Sigoure <benoit.sigoure@lrde.epita.fr>
7 #   modified 2012-2013 by Werner Lemberg <wl@gnu.org>
9 # AutoTroll is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
24 # In addition, as a special exception, the copyright holders of
25 # AutoTroll give you unlimited permission to copy, distribute and
26 # modify the configure scripts that are the output of Autoconf when
27 # processing the macros of AutoTroll.  You need not follow the terms
28 # of the GNU General Public License when using or distributing such
29 # scripts, even though portions of the text of AutoTroll appear in
30 # them.  The GNU General Public License (GPL) does govern all other
31 # use of the material that constitutes AutoTroll.
33 # This special exception to the GPL applies to versions of AutoTroll
34 # released by the copyright holders of AutoTroll.  Note that people
35 # who make modified versions of AutoTroll are not obligated to grant
36 # this special exception for their modified versions; it is their
37 # choice whether to do so.  The GNU General Public License gives
38 # permission to release a modified version without this exception;
39 # this exception also makes it possible to release a modified version
40 # which carries forward this exception.
42  # ------------- #
43  # DOCUMENTATION #
44  # ------------- #
46 # Disclaimer: Tested with Qt 4.2 and 4.8 only.  Feedback welcome.
47 # Simply invoke AT_WITH_QT in your configure.ac.  AT_WITH_QT can take
48 # arguments which are documented in depth below.  The default
49 # arguments are equivalent to the default .pro file generated by
50 # qmake.
52 # Invoking AT_WITH_QT will do the following:
54 #  - Add option `--with-qt[=ARG]' to your configure script.  Possible
55 #    values for ARG are `yes' (which is the default) and `no' to
56 #    enable and disable Qt support, respectively, or a path to the
57 #    directory which contains the Qt binaries in case you have a
58 #    non-stardard location.
59 #  - Add option `--without-qt', which is equivalent to `--with-qt=no'.
60 #  - If Qt support is enabled, define C preprocessor macro HAVE_QT.
61 #  - Find the programs `qmake', `moc', `uic', and `rcc' and save them
62 #    in the make variables $(QMAKE), $(MOC), $(UIC), and $(RCC).
63 #  - Save the path to Qt binaries in $(QT_PATH).
64 #  - Find the flags necessary to compile and link Qt, that is:
65 #     * $(QT_DEFINES): -D's defined by qmake.
66 #     * $(QT_CFLAGS): CFLAGS as defined by qmake (C?!)
67 #     * $(QT_CXXFLAGS): CXXFLAGS as defined by qmake.
68 #     * $(QT_INCPATH): -I's defined by qmake.
69 #     * $(QT_CPPFLAGS): Same as $(QT_DEFINES) + $(QT_INCPATH).
70 #     * $(QT_LFLAGS): LFLAGS defined by qmake.
71 #     * $(QT_LDFLAGS): Same thing as $(QT_LFLAGS).
72 #     * $(QT_LIBS): LIBS defined by qmake.
74 # You *MUST* invoke $(MOC) and/or $(UIC) by yourself where necessary.
75 # AutoTroll provides you with Makerules to ease this; here is a sample
76 # Makefile.am to use with AutoTroll which builds the code given in
77 # chapter 7 of the Qt Tutorial
78 # (http://doc.trolltech.com/4.2/tutorial-t7.html).
80 # -------------------------------------------------------------------------
81 # include $(top_srcdir)/build-aux/autotroll.mk
83 # ACLOCAL_AMFLAGS = -I build-aux
85 # bin_PROGRAMS = lcdrange
86 # lcdrange_SOURCES  = $(BUILT_SOURCES) lcdrange.cpp lcdrange.h main.cpp
87 # lcdrange_CXXFLAGS = $(QT_CXXFLAGS) $(AM_CXXFLAGS)
88 # lcdrange_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS)
89 # lcdrange_LDFLAGS  = $(QT_LDFLAGS) $(LDFLAGS)
90 # lcdrange_LDADD    = $(QT_LIBS) $(LDADD)
92 # BUILT_SOURCES = lcdrange.moc.cpp
93 # -------------------------------------------------------------------------
95 # Note that your MOC, UIC, and RRC files *MUST* be listed explicitly
96 # in BUILT_SOURCES.  If you name them properly (e.g. `.moc.cc',
97 # `.qrc.cc', `.ui.cc' -- of course you can use `.cpp' or `.cxx' or
98 # `.C' rather than `.cc') AutoTroll will build them automagically for
99 # you, using implicit rules defined in `autotroll.mk'.
101 m4_define([_AUTOTROLL_SERIAL],
102   [m4_translit([
103 # serial 10
104 ], [#
105 ], [])])
108 m4_ifdef([AX_INSTEAD_IF],
109   [],
110   [AC_DEFUN([AX_INSTEAD_IF],
111     [m4_ifval([$1],
112       [AC_MSG_WARN([$2])
113        [$1]],
114       [AC_MSG_ERROR([$2])])])])
117 # AX_PATH_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR, [VALUE-IF-NOT-FOUND], [PATH])
118 # -------------------------------------------------------------------------
119 AC_DEFUN([AX_PATH_TOOLS],
120   [for ax_tool in $2; do
121      AC_PATH_TOOL([$1], [$ax_tool], , [$4])
122      test -n "$$1" && break
123    done
124    m4_ifval([$3], [test -n "$$1" || $1="$3"])
125   ])
128 m4_pattern_forbid([^AT_])
129 m4_pattern_forbid([^_AT_])
132 # AT_WITH_QT([QT_modules], [QT_config], [QT_misc], [RUN-IF-FAILED], [RUN-IF-OK])
133 # ------------------------------------------------------------------------------
134 # Enable Qt support and add an option --with-qt to the configure
135 # script.
137 # The QT_modules argument is optional and defines extra modules to
138 # enable or disable (it's equivalent to the QT variable in .pro
139 # files).  Modules can be specified as follows:
141 # AT_WITH_QT   => No argument -> No QT value.
142 #                                Qmake sets it to "core gui" by
143 #                                default.
144 # AT_WITH_QT([xml])   => QT += xml
145 # AT_WITH_QT([+xml])  => QT += xml
146 # AT_WITH_QT([-gui])  => QT -= gui
147 # AT_WITH_QT([xml -gui +sql svg])  => QT += xml sql svg
148 #                                     QT -= gui
150 # The QT_config argument is also optional and follows the same
151 # convention as QT_modules.  Instead of changing the QT variable, it
152 # changes the CONFIG variable, which is used to tweak configuration
153 # and compiler options.
155 # The last argument, QT_misc (also optional) will be copied as-is the
156 # .pro file used to guess how to compile Qt apps.  You may use it to
157 # further tweak the build process of Qt apps if tweaking the QT or
158 # CONFIG variables isn't enough for you.
160 # RUN-IF-FAILED is arbitrary code to execute if Qt cannot be found or
161 # if any problem happens.  If this argument is omitted, then
162 # AC_MSG_ERROR will be called.  RUN-IF-OK is arbitrary code to execute
163 # if Qt was successfully found.
165 AC_DEFUN([AT_WITH_QT],
166   [AC_REQUIRE([AC_CANONICAL_HOST])
167    AC_REQUIRE([AC_CANONICAL_BUILD])
168    AC_REQUIRE([AC_PROG_CXX])
170    echo "$as_me: this is autotroll.m4[]_AUTOTROLL_SERIAL" \
171      >& AS_MESSAGE_LOG_FD
173    # This is a hack to get decent flow control with `break'.
174    for _qt_ignored in once; do
176      AC_ARG_WITH([qt],
177        AS_HELP_STRING([--with-qt@<:@=ARG@:>@],
178          [Qt support.  ARG can be `yes' (the default), `no',
179           or a path to Qt binaries; if `yes' or empty,
180           use PATH and some default directories to find Qt binaries]))
182      if test x"$with_qt" = x"no"; then
183        break
184      else
185        AC_DEFINE([HAVE_QT],[1],
186          [Define if the Qt framework is available.])
187      fi
189      if test x"$with_qt" = x"yes"; then
190        QT_PATH=
191      else
192        QT_PATH=$with_qt
193      fi
195      # Find Qt.
196      AC_ARG_VAR([QT_PATH],
197        [path to Qt binaries])
198      if test -d /usr/local/Trolltech; then
199        # Try to find the latest version.
200        tmp_qt_paths=`echo /usr/local/Trolltech/*/bin \
201                      | tr ' ' '\n' \
202                      | sort -nr \
203                      | xargs \
204                      | sed 's/  */:/g'`
205      fi
207      # Path to which recent MacPorts (~v1.7) install Qt4.
208      test -d /opt/local/libexec/qt4-mac/bin \
209      && tmp_qt_paths="$tmp_qt_paths:/opt/local/libexec/qt4-mac/bin"
211      # Find qmake.
212      AC_ARG_VAR([QMAKE],
213        [Qt Makefile generator command])
214      AX_PATH_TOOLS([QMAKE],
215        [qmake qmake-qt5 qmake-qt4 qmake-qt3],
216        [missing],
217        [$QT_DIR:$QT_PATH:$PATH:$tmp_qt_paths])
218      if test x"$QMAKE" = xmissing; then
219        AX_INSTEAD_IF([$4],
220          [Cannot find qmake.  Try --with-qt=PATH.])
221        break
222      fi
224      # Find moc (Meta Object Compiler).
225      AC_ARG_VAR([MOC],
226        [Qt Meta Object Compiler command])
227      AX_PATH_TOOLS([MOC],
228        [moc moc-qt5 moc-qt4 moc-qt3],
229        [missing],
230        [$QT_PATH:$PATH:$tmp_qt_paths])
231      if test x"$MOC" = xmissing; then
232        AX_INSTEAD_IF([$4],
233          [Cannot find moc (Meta Object Compiler).  Try --with-qt=PATH.])
234        break
235      fi
237      # Find uic (User Interface Compiler).
238      AC_ARG_VAR([UIC],
239        [Qt User Interface Compiler command])
240      AX_PATH_TOOLS([UIC],
241        [uic uic-qt5 uic-qt4 uic-qt3 uic3],
242        [missing],
243        [$QT_PATH:$PATH:$tmp_qt_paths])
244      if test x"$UIC" = xmissing; then
245        AX_INSTEAD_IF([$4],
246          [Cannot find uic (User Interface Compiler).  Try --with-qt=PATH.])
247        break
248      fi
250      # Find rcc (Qt Resource Compiler).
251      AC_ARG_VAR([RCC],
252        [Qt Resource Compiler command])
253      AX_PATH_TOOLS([RCC],
254        [rcc rcc-qt5],
255        [missing],
256        [$QT_PATH:$PATH:$tmp_qt_paths])
257      if test x"$RCC" = xmissing; then
258        AC_MSG_WARN(
259          [Cannot find rcc (Qt Resource Compiler).  Try --with-qt=PATH.])
260      fi
262      AC_MSG_CHECKING([whether host operating system is Darwin])
263      at_darwin=no
264      at_qmake_args=
265      case $host_os in
266        darwin*)
267          at_darwin=yes
268          at_qmake_args='-spec macx-g++'
269          ;;
270      esac
271      AC_MSG_RESULT([$at_darwin])
273      # If we don't know the path to Qt, guess it from the path to
274      # qmake.
275      if test x"$QT_PATH" = x; then
276        QT_PATH=`dirname "$QMAKE"`
277      fi
278      if test x"$QT_PATH" = x; then
279        AX_INSTEAD_IF([$4],
280          [Cannot find your Qt installation.  Try --with-qt=PATH.])
281        break
282      fi
283      AC_SUBST([QT_PATH])
285      # Get ready to build a test-app with Qt.
286      if mkdir conftest.dir \
287         && cd conftest.dir; then
288        :
289      else
290        AX_INSTEAD_IF([$4],
291          [Cannot mkdir conftest.dir or cd to that directory.])
292        break
293      fi
295      cat >conftest.h <<_ASEOF
297 #include <QObject>
299 class Foo: public QObject
301   Q_OBJECT;
302 public:
303   Foo();
304   ~Foo() {}
305 public Q_SLOTS:
306   void setValue(int value);
307 Q_SIGNALS:
308   void valueChanged(int newValue);
309 private:
310   int value_;
313 _ASEOF
315      cat >conftest.cpp <<_ASEOF
317 #include "conftest.h"
319 Foo::Foo()
320   : value_ (42)
322   connect(this, SIGNAL(valueChanged(int)),
323           this, SLOT(setValue(int)));
326 void Foo::setValue(int value)
328   value_ = value;
331 int main()
333   Foo f;
336 _ASEOF
338      if $QMAKE -project; then
339        :
340      else
341        AX_INSTEAD_IF([$4],
342          [Calling $QMAKE -project failed.])
343        break
344      fi
346      # Find the .pro file generated by qmake.
347      pro_file=conftest.dir.pro
348      test -f $pro_file || pro_file=`echo *.pro`
349      if test -f "$pro_file"; then
350        :
351      else
352        AX_INSTEAD_IF([$4],
353          [Can't find the .pro file generated by Qmake.])
354        break
355      fi
357      dnl This is for Qt5; for Qt4 it does nothing special.
358      _AT_TWEAK_PRO_FILE([QT], [+widgets])
360      dnl Tweak the value of QT in the .pro if have been the 1st arg.
361      m4_ifval([$1],
362        [_AT_TWEAK_PRO_FILE([QT], [$1])])
364      dnl Tweak the value of CONFIG in the .pro if have been given a
365      dnl 2nd arg.
366      m4_ifval([$2],
367        [_AT_TWEAK_PRO_FILE([CONFIG], [$2])])
369      m4_ifval([$3],
370        [ # Add the extra-settings the user wants to set in the .pro.
371          echo "$3" >>"$pro_file"
372        ])
374      echo "$as_me:$LINENO: Invoking $QMAKE on $pro_file" \
375        >& AS_MESSAGE_LOG_FD
376      sed 's/^/| /' "$pro_file" >& AS_MESSAGE_LOG_FD
378      if $QMAKE $at_qmake_args; then
379        :
380      else
381        AX_INSTEAD_IF([$4],
382          [Calling $QMAKE $at_qmake_args failed.])
383        break
384      fi
386      # QMake has a very annoying misfeature: Sometimes it generates
387      # Makefiles where all the references to the files from the Qt
388      # installation are relative.  We can't use them as-is because if
389      # we take, say, a -I../../usr/include/Qt from that Makefile, the
390      # flag is invalid as soon as we use it in another (sub)
391      # directory.  So what this perl pass does is that it rewrites all
392      # relative paths to absolute paths.  Another problem when
393      # building on Cygwin is that QMake mixes paths with backslashes
394      # and forward slashes and paths must be handled with extra care
395      # because of the stupid Windows drive letters.
396      echo "$as_me:$LINENO: fixing the Makefiles:" Makefile* \
397        >& AS_MESSAGE_LOG_FD
398      cat >fixmk.pl <<\EOF
401  use strict;
402  use Cwd qw(cwd abs_path);
404  # This variable is useful on Cygwin for the following reason: Say
405  # that you are in `/' (that is, in fact you are in C:/cygwin, or
406  # something like that).  If you `cd ..' then obviously you remain in
407  # `/' (that is in C:/cygwin).  QMake generates paths that are
408  # relative to C:/ (or another drive letter, whatever) so the trick to
409  # get the `..' resolved properly is to prepend the absolute path of
410  # the current working directory in a Windows-style.  C:/cygwin/../
411  # will properly become C:/.
412  my $d = "";
413  my $r2a = 0;
414  my $b2f = 0;
416  my $cygwin = 0;
417  if ($^O eq "cygwin") {
418    $cygwin = 1;
419    $d = cwd();
420    $d = `cygpath --mixed '$d'`;
421    chomp($d);
422    $d .= "/";
425  sub rel2abs($)
427    my $p = $d . shift;
428    # print "r2a p=$p";
429    -e $p || return $p;
430    if ($cygwin) {
431      $p = `cygpath --mixed '$p'`;
432      chomp($p);
433    }
434    else {
435     # Do not use abs_path on Cygwin: it incorrectly resolves the paths
436     # that are relative to C:/ rather than `/'.
437      $p = abs_path($p);
438    }
439    # print " -> $p\n";
440    ++$r2a;
441    return $p;
444  # Only useful on Cygwin.
445  sub back2forward($)
447    my $p = shift;
448    # print "b2f p=$p";
449    -e $p || return $p;
450    $p = `cygpath --mixed '$p'`;
451    chomp($p);
452    # print " -> $p\n";
453    ++$b2f;
454    return $p;
457  foreach my $mk (@ARGV)
459    next if $mk =~ /~$/;
460    open(MK, $mk) or die("open $mk: $!");
461    # print "mk=$mk\n";
462    my $file = join("", <MK>);
463    close(MK) or die("close $mk: $!");
464    rename $mk, $mk . "~" or die("rename $mk: $!");
465    $file =~ s{(?:\.\.[\\/])+(?:[^"'\s:]+)}{rel2abs($&)}gse;
466    $file =~ s{(?:[a-zA-Z]:[\\/])?(?:[^"\s]+\\[^"\s:]+)+}
467              {back2forward($&)}gse if $cygwin;
468    open(MK, ">", $mk) or die("open >$mk: $!");
469    print MK $file;
470    close(MK) or die("close >$mk: $!");
471    print "$mk: updated $r2a relative paths and $b2f backslash-style paths\n";
472    $r2a = 0;
473    $b2f = 0;
479      perl >& AS_MESSAGE_LOG_FD -w fixmk.pl Makefile* \
480      || AC_MSG_WARN([failed to fix the Makefiles generated by $QMAKE])
481      rm -f fixmk.pl
483      # Try to compile a simple Qt app.
484      AC_CACHE_CHECK([whether we can build a simple Qt application],
485        [at_cv_qt_build],
486        [at_cv_qt_build=ko
487         : ${MAKE=make}
489         if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
490           at_cv_qt_build='ok, looks like Qt 4 or Qt 5'
491         else
492           echo "$as_me:$LINENO: Build failed, trying to #include <qobject.h> instead" \
493             >& AS_MESSAGE_LOG_FD
494           sed 's/<QObject>/<qobject.h>/' conftest.h > tmp.h \
495             && mv tmp.h conftest.h
496           if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
497             at_cv_qt_build='ok, looks like Qt 3'
498           else
499             # Sometimes (such as on Debian) build will fail because Qt
500             # hasn't been installed in debug mode and qmake tries (by
501             # default) to build apps in debug mode => Try again in
502             # release mode.
503             echo "$as_me:$LINENO: Build failed, trying to enforce release mode" \
504               >& AS_MESSAGE_LOG_FD
506             _AT_TWEAK_PRO_FILE([CONFIG], [+release])
508             sed 's/<qobject.h>/<QObject>/' conftest.h > tmp.h \
509               && mv tmp.h conftest.h
510             if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
511               at_cv_qt_build='ok, looks like Qt 4 or Qt 5, release mode forced'
512             else
513               echo "$as_me:$LINENO: Build failed, trying to #include <qobject.h> instead" \
514                 >& AS_MESSAGE_LOG_FD
515               sed 's/<QObject>/<qobject.h>/' conftest.h > tmp.h \
516                 && mv tmp.h conftest.h
517               if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
518                 at_cv_qt_build='ok, looks like Qt 3, release mode forced'
519               else
520                 at_cv_qt_build=ko
521                 echo "$as_me:$LINENO: failed program was:" \
522                   >& AS_MESSAGE_LOG_FD
523                 sed 's/^/| /' conftest.h >& AS_MESSAGE_LOG_FD
524                 echo "$as_me:$LINENO: failed program was:" \
525                   >& AS_MESSAGE_LOG_FD
526                 sed 's/^/| /' conftest.cpp >& AS_MESSAGE_LOG_FD
527               fi # if make with Qt3-style #include and release mode forced.
528             fi # if make with Qt4/5-style #include and release mode forced.
529           fi # if make with Qt3-style #include.
530         fi # if make with Qt4/5-style #include.
531        ])dnl end: AC_CACHE_CHECK(at_cv_qt_build)
533      if test x"$at_cv_qt_build" = xko; then
534        AX_INSTEAD_IF([$4],
535          [Cannot build a test Qt program])
536        cd ..
537        break
538      fi
540      QT_VERSION_MAJOR=`echo "$at_cv_qt_build" | sed 's/[[^0-9]]*//g'`
541      AC_SUBST([QT_VERSION_MAJOR])
543      # This sed filter is applied after an expression of the form:
544      # /^FOO.*=/!d; it starts by removing the beginning of the line,
545      # removing references to SUBLIBS, removing unnecessary
546      # whitespaces at the beginning, and prefixes all variable uses by
547      # QT_.
548      qt_sed_filter='s///;
549                     s/$(SUBLIBS)//g;
550                     s/^ *//;
551                     s/\$(\(@<:@A-Z_@:>@@<:@A-Z_@:>@*\))/$(QT_\1)/g'
553      # Find the Makefile (qmake happens to generate a fake Makefile
554      # which invokes a Makefile.Debug or Makefile.Release).  If we
555      # have both, we'll pick the Makefile.Release.  The reason is that
556      # that release uses -Os and debug -g.  We can override -Os by
557      # passing another -O but we usually don't override -g.
558      if test -f Makefile.Release; then
559        at_mfile='Makefile.Release'
560      else
561        at_mfile='Makefile'
562      fi
563      if test -f $at_mfile; then
564        :
565      else
566        AX_INSTEAD_IF([$4],
567          [Cannot find the Makefile generated by qmake.])
568        cd ..
569        break
570      fi
572      # Find the DEFINES of Qt (should have been named CPPFLAGS).
573      AC_CACHE_CHECK([for the DEFINES to use with Qt],
574        [at_cv_env_QT_DEFINES],
575        [at_cv_env_QT_DEFINES=`sed "/^DEFINES@<:@^A-Z=@:>@*=/!d;
576                                    $qt_sed_filter" $at_mfile`])
577      AC_SUBST([QT_DEFINES],
578        [$at_cv_env_QT_DEFINES])
580      # Find the CFLAGS of Qt.  (We can use Qt in C?!)
581      AC_CACHE_CHECK([for the CFLAGS to use with Qt],
582        [at_cv_env_QT_CFLAGS],
583        [at_cv_env_QT_CFLAGS=`sed "/^CFLAGS@<:@^A-Z=@:>@*=/!d;
584                                   $qt_sed_filter" $at_mfile`])
585      AC_SUBST([QT_CFLAGS],
586        [$at_cv_env_QT_CFLAGS])
588      # Find the CXXFLAGS of Qt.
589      AC_CACHE_CHECK([for the CXXFLAGS to use with Qt],
590        [at_cv_env_QT_CXXFLAGS],
591        [at_cv_env_QT_CXXFLAGS=`sed "/^CXXFLAGS@<:@^A-Z=@:>@*=/!d;
592                                     $qt_sed_filter" $at_mfile`])
593      AC_SUBST([QT_CXXFLAGS],
594        [$at_cv_env_QT_CXXFLAGS])
596      # Find the INCPATH of Qt.
597      AC_CACHE_CHECK([for the INCPATH to use with Qt],
598        [at_cv_env_QT_INCPATH],
599        [at_cv_env_QT_INCPATH=`sed "/^INCPATH@<:@^A-Z=@:>@*=/!d;
600                                    $qt_sed_filter" $at_mfile`])
601      AC_SUBST([QT_INCPATH],
602        [$at_cv_env_QT_INCPATH])
604      AC_SUBST([QT_CPPFLAGS],
605        ["$at_cv_env_QT_DEFINES $at_cv_env_QT_INCPATH"])
607      # Find the LFLAGS of Qt (Should have been named LDFLAGS).
608      AC_CACHE_CHECK([for the LDFLAGS to use with Qt],
609        [at_cv_env_QT_LDFLAGS],
610        [at_cv_env_QT_LDFLAGS=`sed "/^LFLAGS@<:@^A-Z=@:>@*=/!d;
611                                    $qt_sed_filter" $at_mfile`])
612      AC_SUBST([QT_LFLAGS],
613        [$at_cv_env_QT_LDFLAGS])
614      AC_SUBST([QT_LDFLAGS],
615        [$at_cv_env_QT_LDFLAGS])
617      # Find the LIBS of Qt.
618      AC_CACHE_CHECK([for the LIBS to use with Qt],
619       [at_cv_env_QT_LIBS],
620       [at_cv_env_QT_LIBS=`sed "/^LIBS@<:@^A-Z@:>@*=/!d;
621                                $qt_sed_filter" $at_mfile`
622        if test x$at_darwin = xyes; then
623          # Fix QT_LIBS: as of today Libtool (GNU Libtool 1.5.23a)
624          # doesn't handle -F properly.  The "bug" has been fixed on 22
625          # October 2006 by Peter O'Gorman but we provide backward
626          # compatibility here.
627          at_cv_env_QT_LIBS=`echo "$at_cv_env_QT_LIBS" \
628                             | sed 's/^-F/-Wl,-F/;
629                                    s/ -F/ -Wl,-F/g'`
630        fi])
631      AC_SUBST([QT_LIBS],
632        [$at_cv_env_QT_LIBS])
634      cd .. && rm -rf conftest.dir
636      # Run the user code
637      $5
639    done  # end hack (useless FOR to be able to use break)
640   ])
643 # AT_REQUIRE_QT_VERSION(QT_version, [RUN-IF-FAILED], [RUN-IF-OK])
644 # ---------------------------------------------------------------
645 # Check (using qmake) that Qt's version "matches" QT_version.  Must be
646 # run *after* AT_WITH_QT.  Requires autoconf 2.60.
648 # This macro is ignored if Qt support has been disabled (using
649 # `--with-qt=no' or `--without-qt').
651 # RUN-IF-FAILED is arbitrary code to execute if Qt cannot be found or
652 # if any problem happens.  If this argument is omitted, then
653 # AC_MSG_ERROR will be called.  RUN-IF-OK is arbitrary code to execute
654 # if Qt was successfully found.
656 AC_DEFUN([AT_REQUIRE_QT_VERSION],
657   [AC_PREREQ([2.60])
659    # this is a hack to get decent flow control with `break'
660    for _qt_ignored in once; do
662      if test x"$with_qt" = x"no"; then
663        break
664      fi
666      if test x"$QMAKE" = x; then
667        AX_INSTEAD_IF([$2],
668         [\$QMAKE is empty.  Did you invoke AT@&t@_WITH_QT before AT@&t@_REQUIRE_QT_VERSION?])
669        break
670      fi
672      AC_CACHE_CHECK([for Qt's version],
673        [at_cv_QT_VERSION],
674        [echo "$as_me:$LINENO: Running $QMAKE --version:" \
675           >& AS_MESSAGE_LOG_FD
676         $QMAKE --version >& AS_MESSAGE_LOG_FD 2>&1
677         qmake_version_sed=['/^.*\([0-9]\.[0-9]\.[0-9]\).*$/!d;s//\1/']
678         at_cv_QT_VERSION=`$QMAKE --version 2>&1 \
679                           | sed "$qmake_version_sed"`])
680      if test x"$at_cv_QT_VERSION" = x; then
681        AX_INSTEAD_IF([$2],
682          [Cannot detect Qt's version.])
683        break
684      fi
685      AC_SUBST([QT_VERSION],
686        [$at_cv_QT_VERSION])
687      AS_VERSION_COMPARE([$QT_VERSION], [$1],
688        [AX_INSTEAD_IF([$2],
689           [This package requires Qt $1 or above.])
690         break])
692      # Run the user code
693      $3
695    done  # end hack (useless for to be able to use break)
696   ])
699 # _AT_TWEAK_PRO_FILE(QT_VAR, VALUE)
700 # ---------------------------------
701 # @internal.  Tweak the variable QT_VAR in the .pro file.  VALUE is an
702 # IFS-separated list of value, and each value is rewritten as follows:
704 #   +value  => QT_VAR += value
705 #   -value  => QT_VAR -= value
706 #    value  => QT_VAR += value
708 AC_DEFUN([_AT_TWEAK_PRO_FILE],
709   [ # Tweak the value of $1 in the .pro file for $2.
710    qt_conf=''
711    for at_mod in $2; do
712      at_mod=`echo "$at_mod" | sed 's/^-//; tough
713                                    s/^+//; beef
714                                    :ough
715                                    s/^/$1 -= /;n
716                                    :eef
717                                    s/^/$1 += /'`
718      qt_conf="\
719 $qt_conf
720 $at_mod"
721    done
722     echo "$qt_conf" | sed 1d >>"$pro_file"
723   ])