Fix OTS warning about `maxp.maxSizeOfInstructions`.
[ttfautohint.git] / m4 / autotroll.m4
blobb0b5e70a3d4ec42ac993720cfd2d62793fb99061
1 # Build Qt apps with the autotools (Autoconf/Automake).
2 # M4 macros.
4 # This file is part of AutoTroll.
6 # Copyright (C) 2006-2018  Benoit Sigoure <benoit.sigoure@lrde.epita.fr>
7 # Copyright (C) 2012-2017  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, 4.8, and Qt 5.x only.  Feedback
47 # welcome.  Simply invoke AT_WITH_QT in your configure.ac.  AT_WITH_QT
48 # can take 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.
60 #  - Add option `--without-qt', which is equivalent to `--with-qt=no'.
62 #  - On MacOS, add `-spec macx-g++' to qmake.  This can be overridden
63 #    with the QMAKESPEC environment variable, for example
65 #      QMAKESPEC='macx-clang' ./configure ...
67 #    (The QMAKESPEC variable is honoured for non-MacOS builds also.)
69 #  - If Qt support is enabled, define C preprocessor macro HAVE_QT.
71 #  - Find the programs `qmake', `moc', `uic', and `rcc' and save them
72 #    in the make variables $(QMAKE), $(MOC), $(UIC), and $(RCC).
74 #  - Save the path to Qt binaries in $(QT_PATH).
76 #  - Find the flags necessary to compile and link Qt, that is:
78 #     * $(QT_DEFINES): -D's defined by qmake.
79 #     * $(QT_CFLAGS): CFLAGS as defined by qmake (C?!)
80 #     * $(QT_CXXFLAGS): CXXFLAGS as defined by qmake.
81 #     * $(QT_INCPATH): -I's defined by qmake.
82 #     * $(QT_CPPFLAGS): Same as $(QT_DEFINES) + $(QT_INCPATH).
83 #     * $(QT_LFLAGS): LFLAGS defined by qmake.
84 #     * $(QT_LDFLAGS): Same thing as $(QT_LFLAGS).
85 #     * $(QT_LIBS): LIBS defined by qmake.
87 #  - Provide @QT_STATIC_PLUGINS@, which holds some additional C++
88 #    declarations necessary for linking with static Qt plugins (for
89 #    dynamic Qt builds it contains a dummy typedef declaration
90 #    instead).  Use this substitution in a `foo.cpp.in' C++ template
91 #    file or something similar, which must be registered in
92 #    configure.ac's call to AC_CONFIG_FILES so that a proper `foo.cpp'
93 #    file gets created.  Then compile and link `foo.cpp' with your
94 #    program in the usual automake way.
96 #    NOTE: It is not possible to automatically detect whether a Qt
97 #    release earlier than version 5 is built as a static library!  For
98 #    this reason, @QT_STATIC_PLUGINS@ always contains the dummy
99 #    typedef declaration if not using Qt5.
101 # You *MUST* invoke $(MOC) and/or $(UIC) by yourself where necessary.
102 # AutoTroll provides you with Makerules to ease this; here is a sample
103 # Makefile.am to use with AutoTroll which builds the code given in
104 # chapter 7 of the Qt Tutorial
105 # (http://doc.trolltech.com/4.2/tutorial-t7.html).
107 # -------------------------------------------------------------------------
108 # include $(top_srcdir)/build-aux/autotroll.mk
110 # ACLOCAL_AMFLAGS = -I build-aux
112 # bin_PROGRAMS = lcdrange
113 # lcdrange_SOURCES  = $(BUILT_SOURCES) lcdrange.cpp lcdrange.h main.cpp
114 # lcdrange_CXXFLAGS = $(QT_CXXFLAGS) $(AM_CXXFLAGS)
115 # lcdrange_CPPFLAGS = $(QT_CPPFLAGS) $(AM_CPPFLAGS)
116 # lcdrange_LDFLAGS  = $(QT_LDFLAGS) $(LDFLAGS)
117 # lcdrange_LDADD    = $(QT_LIBS) $(LDADD)
119 # BUILT_SOURCES = lcdrange.moc.cpp
120 # -------------------------------------------------------------------------
122 # Note that your MOC, UIC, and RCC files *MUST* be listed explicitly
123 # in BUILT_SOURCES.  If you name them properly (e.g. `.moc.cc',
124 # `.qrc.cc', `.ui.cc' -- of course you can use `.cpp' or `.cxx' or
125 # `.C' rather than `.cc') AutoTroll will build them automagically for
126 # you, using implicit rules defined in `autotroll.mk'.
128 m4_define([_AUTOTROLL_SERIAL],
129   [m4_translit([
130 # serial 16
131 ], [#
132 ], [])])
135 m4_ifdef([AX_INSTEAD_IF],
136   [],
137   [AC_DEFUN([AX_INSTEAD_IF],
138     [m4_ifval([$1],
139       [AC_MSG_WARN([$2])
140        [$1]],
141       [AC_MSG_ERROR([$2])])])])
144 # AX_PATH_TOOLS(VARIABLE, PROGS-TO-CHECK-FOR, [VALUE-IF-NOT-FOUND], [PATH])
145 # -------------------------------------------------------------------------
146 AC_DEFUN([AX_PATH_TOOLS],
147   [for ax_tool in $2; do
148      AC_PATH_TOOL([$1], [$ax_tool], [], [$4])
149      test -n "$$1" && break
150    done
151    m4_ifval([$3], [test -n "$$1" || $1="$3"])
152   ])
155 m4_pattern_forbid([^AT_])
156 m4_pattern_forbid([^_AT_])
159 # AT_WITH_QT([QT_modules], [QT_config], [QT_misc], [RUN-IF-FAILED], [RUN-IF-OK])
160 # ------------------------------------------------------------------------------
161 # Enable Qt support and add an option --with-qt to the configure
162 # script.
164 # The QT_modules argument is optional and defines extra modules to
165 # enable or disable (it's equivalent to the QT variable in .pro
166 # files).  Modules can be specified as follows:
168 # AT_WITH_QT   =>  No argument -> No QT value.
169 #                                 Qmake sets it to "core gui" by
170 #                                 default.
171 # AT_WITH_QT([xml])   =>  QT += xml
172 # AT_WITH_QT([+xml])  =>  QT += xml
173 # AT_WITH_QT([-gui])  =>  QT -= gui
174 # AT_WITH_QT([xml -gui +sql svg])  =>  QT += xml sql svg
175 #                                      QT -= gui
177 # The QT_config argument is also optional and follows the same
178 # convention as QT_modules.  Instead of changing the QT variable, it
179 # changes the CONFIG variable, which is used to tweak configuration
180 # and compiler options.
182 # The last argument, QT_misc (also optional) will be copied as-is the
183 # .pro file used to guess how to compile Qt apps.  You may use it to
184 # further tweak the build process of Qt apps if tweaking the QT or
185 # CONFIG variables isn't enough for you (for example, to control which
186 # static plugins get used).
188 # RUN-IF-FAILED is arbitrary code to execute if Qt cannot be found or
189 # if any problem happens.  If this argument is omitted, then
190 # AC_MSG_ERROR will be called.  RUN-IF-OK is arbitrary code to execute
191 # if Qt was successfully found.
193 AC_DEFUN([AT_WITH_QT],
194   [AC_REQUIRE([AC_CANONICAL_HOST])
195    AC_REQUIRE([AC_CANONICAL_BUILD])
196    AC_REQUIRE([AC_PROG_CXX])
198    echo "$as_me: this is autotroll.m4[]_AUTOTROLL_SERIAL" \
199      >& AS_MESSAGE_LOG_FD
201    # This is a hack to get decent flow control with `break'.
202    for _qt_ignored in once; do
204      AC_ARG_WITH([qt],
205        AS_HELP_STRING([--with-qt@<:@=ARG@:>@],
206          [Qt support.  ARG can be `yes' (the default), `no',
207           or a path to Qt binaries; if `yes' or empty,
208           use PATH and some default directories to find Qt binaries]))
210      if test x"$with_qt" = x"no"; then
211        break
212      else
213        AC_DEFINE([HAVE_QT],[1],
214          [Define if the Qt framework is available.])
215      fi
217      if test x"$with_qt" = x"yes"; then
218        QT_PATH=
219      else
220        QT_PATH=$with_qt
221      fi
223      # Find Qt.
224      AC_ARG_VAR([QT_PATH],
225        [path to Qt binaries])
227      # Find qmake.
228      AC_ARG_VAR([QMAKE],
229        [Qt Makefile generator command])
230      AX_PATH_TOOLS([QMAKE],
231        [qmake qmake-qt5 qmake-qt4 qmake-qt3],
232        [missing],
233        [$QT_PATH:$PATH])
234      if test x"$QMAKE" = xmissing; then
235        AX_INSTEAD_IF([$4],
236          [Cannot find qmake.  Try --with-qt=PATH.])
237        break
238      fi
240      # Find moc (Meta Object Compiler).
241      AC_ARG_VAR([MOC],
242        [Qt Meta Object Compiler command])
243      AX_PATH_TOOLS([MOC],
244        [moc moc-qt5 moc-qt4 moc-qt3],
245        [missing],
246        [$QT_PATH:$PATH])
247      if test x"$MOC" = xmissing; then
248        AX_INSTEAD_IF([$4],
249          [Cannot find moc (Meta Object Compiler).  Try --with-qt=PATH.])
250        break
251      fi
253      # Find uic (User Interface Compiler).
254      AC_ARG_VAR([UIC],
255        [Qt User Interface Compiler command])
256      AX_PATH_TOOLS([UIC],
257        [uic uic-qt5 uic-qt4 uic-qt3 uic3],
258        [missing],
259        [$QT_PATH:$PATH])
260      if test x"$UIC" = xmissing; then
261        AX_INSTEAD_IF([$4],
262          [Cannot find uic (User Interface Compiler).  Try --with-qt=PATH.])
263        break
264      fi
266      # Find rcc (Qt Resource Compiler).
267      AC_ARG_VAR([RCC],
268        [Qt Resource Compiler command])
269      AX_PATH_TOOLS([RCC],
270        [rcc rcc-qt5],
271        [missing],
272        [$QT_PATH:$PATH])
273      if test x"$RCC" = xmissing; then
274        AC_MSG_WARN(
275          [Cannot find rcc (Qt Resource Compiler).  Try --with-qt=PATH.])
276      fi
278      AC_MSG_CHECKING([whether host operating system is Darwin])
279      at_darwin=no
280      at_qmake_args=
281      case $host_os in
282        dnl (
283        darwin*)
284          at_darwin=yes
285          ;;
286      esac
287      AC_MSG_RESULT([$at_darwin])
289      AC_MSG_CHECKING([whether QMAKESPEC environment variable is set])
290      if test x"$QMAKESPEC" = x; then
291        if test x"$at_darwin" = xyes; then
292          at_qmake_args='-spec macx-g++'
293          AC_MSG_RESULT([no, using $at_qmake_args])
294        else
295          AC_MSG_RESULT([no])
296        fi
297      else
298        AC_MSG_RESULT([yes, using $QMAKESPEC])
299      fi
301      # If we don't know the path to Qt, guess it from the path to
302      # qmake.
303      if test x"$QT_PATH" = x; then
304        QT_PATH=`dirname "$QMAKE"`
305      fi
306      if test x"$QT_PATH" = x; then
307        AX_INSTEAD_IF([$4],
308          [Cannot find your Qt installation.  Try --with-qt=PATH.])
309        break
310      fi
311      AC_SUBST([QT_PATH])
313      # Get ready to build a test-app with Qt.
314      if mkdir conftest.dir \
315         && cd conftest.dir; then
316        :
317      else
318        AX_INSTEAD_IF([$4],
319          [Cannot mkdir conftest.dir or cd to that directory.])
320        break
321      fi
323      cat >conftest.h <<_ASEOF
325 #include <QObject>
327 class Foo: public QObject
329   Q_OBJECT;
330 public:
331   Foo();
332   ~Foo() {}
333 public Q_SLOTS:
334   void setValue(int value);
335 Q_SIGNALS:
336   void valueChanged(int newValue);
337 private:
338   int value_;
341 _ASEOF
343      cat >conftest.cpp <<_ASEOF
345 #include "conftest.h"
347 Foo::Foo()
348   : value_ (42)
350   connect(this, SIGNAL(valueChanged(int)),
351           this, SLOT(setValue(int)));
354 void Foo::setValue(int value)
356   value_ = value;
359 int main()
361   Foo f;
364 _ASEOF
366      if $QMAKE -project; then
367        :
368      else
369        AX_INSTEAD_IF([$4],
370          [Calling $QMAKE -project failed.])
371        break
372      fi
374      # Find the .pro file generated by qmake.
375      pro_file=conftest.dir.pro
376      test -f $pro_file || pro_file=`echo *.pro`
377      if test -f "$pro_file"; then
378        :
379      else
380        AX_INSTEAD_IF([$4],
381          [Can't find the .pro file generated by Qmake.])
382        break
383      fi
385      dnl This is for Qt5; for Qt4 it does nothing special.
386      _AT_TWEAK_PRO_FILE([QT], [+widgets])
388      dnl Tweak the value of QT in the .pro file if we have a first
389      dnl argument.
390      m4_ifval([$1],
391        [_AT_TWEAK_PRO_FILE([QT], [$1])])
393      dnl Tweak the value of CONFIG in the .pro file if we have a
394      dnl second argument.
395      m4_ifval([$2],
396        [_AT_TWEAK_PRO_FILE([CONFIG], [$2])])
398      m4_ifval([$3],
399        [ # Add the extra-settings the user wants to set in the .pro
400          # file.
401          echo "$3" >>"$pro_file"
402        ])
404      echo "$as_me:$LINENO: Invoking $QMAKE on $pro_file" \
405        >& AS_MESSAGE_LOG_FD
406      sed 's/^/| /' "$pro_file" >& AS_MESSAGE_LOG_FD
408      if $QMAKE $at_qmake_args; then
409        :
410      else
411        AX_INSTEAD_IF([$4],
412          [Calling $QMAKE $at_qmake_args failed.])
413        break
414      fi
416      # QMake has a very annoying misfeature: Sometimes it generates
417      # Makefiles where all the references to the files from the Qt
418      # installation are relative.  We can't use them as-is because if
419      # we take, say, a -I../../usr/include/Qt from that Makefile, the
420      # flag is invalid as soon as we use it in another (sub)
421      # directory.  So what this perl pass does is that it rewrites all
422      # relative paths to absolute paths.  Another problem when
423      # building on Cygwin is that QMake mixes paths with backslashes
424      # and forward slashes and paths must be handled with extra care
425      # because of the stupid Windows drive letters.
426      echo "$as_me:$LINENO: fixing the Makefiles:" Makefile* \
427        >& AS_MESSAGE_LOG_FD
428      cat >fixmk.pl <<\EOF
431  use strict;
432  use Cwd qw(cwd abs_path);
434  # This variable is useful on Cygwin for the following reason: Say
435  # that you are in `/' (that is, in fact you are in C:/cygwin, or
436  # something like that).  If you `cd ..' then obviously you remain in
437  # `/' (that is in C:/cygwin).  QMake generates paths that are
438  # relative to C:/ (or another drive letter, whatever) so the trick to
439  # get the `..' resolved properly is to prepend the absolute path of
440  # the current working directory in a Windows-style.  C:/cygwin/../
441  # will properly become C:/.
442  my $d = "";
443  my $r2a = 0;
444  my $b2f = 0;
446  my $cygwin = 0;
447  if ($^O eq "cygwin") {
448    $cygwin = 1;
449    $d = cwd();
450    $d = `cygpath --mixed '$d'`;
451    chomp($d);
452    $d .= "/";
455  sub rel2abs($)
457    my $p = $d . shift;
458    # print "r2a p=$p";
459    -e $p || return $p;
460    if ($cygwin) {
461      $p = `cygpath --mixed '$p'`;
462      chomp($p);
463    }
464    else {
465     # Do not use abs_path on Cygwin: it incorrectly resolves the paths
466     # that are relative to C:/ rather than `/'.
467      $p = abs_path($p);
468    }
469    # print " -> $p\n";
470    ++$r2a;
471    return $p;
474  # Only useful on Cygwin.
475  sub back2forward($)
477    my $p = shift;
478    # print "b2f p=$p";
479    -e $p || return $p;
480    $p = `cygpath --mixed '$p'`;
481    chomp($p);
482    # print " -> $p\n";
483    ++$b2f;
484    return $p;
487  foreach my $mk (@ARGV)
489    next if $mk =~ /~$/;
490    open(MK, $mk) or die("open $mk: $!");
491    # print "mk=$mk\n";
492    my $file = join("", <MK>);
493    close(MK) or die("close $mk: $!");
494    rename $mk, $mk . "~" or die("rename $mk: $!");
495    $file =~ s{(?:\.\.[\\/])+(?:[^"'\s:]+)}{rel2abs($&)}gse;
496    $file =~ s{(?:[a-zA-Z]:[\\/])?(?:[^"\s]+\\[^"\s:]+)+}
497              {back2forward($&)}gse if $cygwin;
498    open(MK, ">", $mk) or die("open >$mk: $!");
499    print MK $file;
500    close(MK) or die("close >$mk: $!");
501    print "$mk: updated $r2a relative paths and $b2f backslash-style paths\n";
502    $r2a = 0;
503    $b2f = 0;
509      perl >& AS_MESSAGE_LOG_FD -w fixmk.pl Makefile* \
510      || AC_MSG_WARN([failed to fix the Makefiles generated by $QMAKE])
511      rm -f fixmk.pl
513      # Try to compile a simple Qt app.
514      AC_CACHE_CHECK([whether we can build a simple Qt application],
515        [at_cv_qt_build],
516        [at_cv_qt_build=ko
517         : ${MAKE=make}
519         if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
520           at_cv_qt_build='ok, looks like Qt 4 or Qt 5'
521         else
522           echo "$as_me:$LINENO: Build failed, trying to #include <qobject.h> instead" \
523             >& AS_MESSAGE_LOG_FD
524           sed 's/<QObject>/<qobject.h>/' conftest.h > tmp.h \
525             && mv tmp.h conftest.h
526           if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
527             at_cv_qt_build='ok, looks like Qt 3'
528           else
529             # Sometimes (such as on Debian) build will fail because Qt
530             # hasn't been installed in debug mode and qmake tries (by
531             # default) to build apps in debug mode => Try again in
532             # release mode.
533             echo "$as_me:$LINENO: Build failed, trying to enforce release mode" \
534               >& AS_MESSAGE_LOG_FD
536             _AT_TWEAK_PRO_FILE([CONFIG], [+release])
538             sed 's/<qobject.h>/<QObject>/' conftest.h > tmp.h \
539               && mv tmp.h conftest.h
540             if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
541               at_cv_qt_build='ok, looks like Qt 4 or Qt 5, release mode forced'
542             else
543               echo "$as_me:$LINENO: Build failed, trying to #include <qobject.h> instead" \
544                 >& AS_MESSAGE_LOG_FD
545               sed 's/<QObject>/<qobject.h>/' conftest.h > tmp.h \
546                 && mv tmp.h conftest.h
547               if $MAKE >& AS_MESSAGE_LOG_FD 2>&1; then
548                 at_cv_qt_build='ok, looks like Qt 3, release mode forced'
549               else
550                 at_cv_qt_build=ko
551                 echo "$as_me:$LINENO: failed program was:" \
552                   >& AS_MESSAGE_LOG_FD
553                 sed 's/^/| /' conftest.h >& AS_MESSAGE_LOG_FD
554                 echo "$as_me:$LINENO: failed program was:" \
555                   >& AS_MESSAGE_LOG_FD
556                 sed 's/^/| /' conftest.cpp >& AS_MESSAGE_LOG_FD
557               fi # if make with Qt3-style #include and release mode forced.
558             fi # if make with Qt4/5-style #include and release mode forced.
559           fi # if make with Qt3-style #include.
560         fi # if make with Qt4/5-style #include.
561        ])dnl end: AC_CACHE_CHECK(at_cv_qt_build)
563      if test x"$at_cv_qt_build" = xko; then
564        AX_INSTEAD_IF([$4],
565          [Cannot build a test Qt program])
566        cd ..
567        break
568      fi
570      QT_VERSION_MAJOR=`echo "$at_cv_qt_build" | sed 's/[[^0-9]]*//g'`
571      AC_SUBST([QT_VERSION_MAJOR])
573      # This sed filter is applied after an expression of the form
574      # /^FOO.*=/!d; it starts by removing the beginning of the line
575      # (using the empty regular expression //, which repeats the last
576      # regular expression match), removing references to SUBLIBS,
577      # removing unnecessary whitespace at the beginning, then prefixing
578      # our exported variables with QT_.  Note that `LDFLAGS' is
579      # intentionally omitted.
580      qt_sed_filter='s///;
581                     s/$(SUBLIBS)//g;
582                     s/^ *//;
583                     s/\$(DEFINES)/$(QT_DEFINES)/g;
584                     s/\$(CFLAGS)/$(QT_CFLAGS)/g;
585                     s/\$(CXXFLAGS)/$(QT_CXXFLAGS)/g;
586                     s/\$(INCPATH)/$(QT_INCPATH)/g;
587                     s/\$(CPPFLAGS)/$(QT_CPPFLAGS)/g;
588                     s/\$(LFLAGS)/$(QT_LFLAGS)/g;
589                     s/\$(LIBS)/$(QT_LIBS)/g'
591      # Find the Makefile (qmake happens to generate a fake Makefile
592      # which invokes a Makefile.Debug or Makefile.Release).  If we
593      # have both, we'll pick the Makefile.Release.  The reason is that
594      # this release uses -Os and debug -g.  We can override -Os by
595      # passing another -O but we usually don't override -g.
596      if test -f Makefile.Release; then
597        at_mfile='Makefile.Release'
598      else
599        at_mfile='Makefile'
600      fi
601      if test -f $at_mfile; then
602        :
603      else
604        AX_INSTEAD_IF([$4],
605          [Cannot find the Makefile generated by qmake.])
606        cd ..
607        break
608      fi
610      # Find the DEFINES of Qt (should have been named CPPFLAGS).
611      AC_CACHE_CHECK([for the DEFINES to use with Qt],
612        [at_cv_env_QT_DEFINES],
613        [at_cv_env_QT_DEFINES=`sed "/^DEFINES@<:@^A-Z=@:>@*=/!d;
614                                    $qt_sed_filter" $at_mfile`])
615      AC_SUBST([QT_DEFINES],
616        [$at_cv_env_QT_DEFINES])
618      # Find the CFLAGS of Qt.  (We can use Qt in C?!)
619      AC_CACHE_CHECK([for the CFLAGS to use with Qt],
620        [at_cv_env_QT_CFLAGS],
621        [at_cv_env_QT_CFLAGS=`sed "/^CFLAGS@<:@^A-Z=@:>@*=/!d;
622                                   $qt_sed_filter" $at_mfile`])
623      AC_SUBST([QT_CFLAGS],
624        [$at_cv_env_QT_CFLAGS])
626      # Find the CXXFLAGS of Qt.
627      AC_CACHE_CHECK([for the CXXFLAGS to use with Qt],
628        [at_cv_env_QT_CXXFLAGS],
629        [at_cv_env_QT_CXXFLAGS=`sed "/^CXXFLAGS@<:@^A-Z=@:>@*=/!d;
630                                     $qt_sed_filter" $at_mfile`])
631      AC_SUBST([QT_CXXFLAGS],
632        [$at_cv_env_QT_CXXFLAGS])
634      # Find the INCPATH of Qt.
635      AC_CACHE_CHECK([for the INCPATH to use with Qt],
636        [at_cv_env_QT_INCPATH],
637        [at_cv_env_QT_INCPATH=`sed "/^INCPATH@<:@^A-Z=@:>@*=/!d;
638                                    $qt_sed_filter" $at_mfile`])
639      AC_SUBST([QT_INCPATH],
640        [$at_cv_env_QT_INCPATH])
642      AC_SUBST([QT_CPPFLAGS],
643        ["$at_cv_env_QT_DEFINES $at_cv_env_QT_INCPATH"])
645      # Find the LFLAGS of Qt (should have been named LDFLAGS).
646      AC_CACHE_CHECK([for the LDFLAGS to use with Qt],
647        [at_cv_env_QT_LDFLAGS],
648        [at_cv_env_QT_LDFLAGS=`sed "/^LFLAGS@<:@^A-Z=@:>@*=/!d;
649                                    $qt_sed_filter" $at_mfile`])
650      AC_SUBST([QT_LFLAGS],
651        [$at_cv_env_QT_LDFLAGS])
652      AC_SUBST([QT_LDFLAGS],
653        [$at_cv_env_QT_LDFLAGS])
655      # Find the LIBS of Qt.
656      AC_CACHE_CHECK([for the LIBS to use with Qt],
657       [at_cv_env_QT_LIBS],
658       [at_cv_env_QT_LIBS=`sed "/^LIBS@<:@^A-Z@:>@*=/!d;
659                                $qt_sed_filter" $at_mfile`
660        if test x$at_darwin = xyes; then
661          # Fix QT_LIBS: as of today Libtool (GNU Libtool 1.5.23a)
662          # doesn't handle -F properly.  The "bug" has been fixed on 22
663          # October 2006 by Peter O'Gorman but we provide backward
664          # compatibility here.
665          at_cv_env_QT_LIBS=`echo "$at_cv_env_QT_LIBS" \
666                             | sed 's/^-F/-Wl,-F/;
667                                    s/ -F/ -Wl,-F/g'`
668        fi])
669      AC_SUBST([QT_LIBS],
670        [$at_cv_env_QT_LIBS])
672      # We can't use AC_CACHE_CHECK for data that contains newlines.
673      AC_MSG_CHECKING([for necessary static plugin code])
674      # find static plugin data generated by qmake
675      if test -f conftest.dir_plugin_import.cpp; then
676        QT_STATIC_PLUGINS=`cat conftest.dir_plugin_import.cpp`
677      else
678        QT_STATIC_PLUGINS="\
679 // We have Qt earlier than version 5 or a dynamic build.
680 // Provide dummy typedef to avoid empty source code.
681 typedef int _qt_not_a_static_build;"
682      fi
683      AC_SUBST([QT_STATIC_PLUGINS])
684      AM_SUBST_NOTMAKE([QT_STATIC_PLUGINS])
685      AC_MSG_RESULT([$QT_STATIC_PLUGINS])
687      cd .. && rm -rf conftest.dir
689      # Run the user code
690      $5
692    done  # end hack (useless FOR to be able to use break)
693   ])
696 # AT_REQUIRE_QT_VERSION(QT_version, [RUN-IF-FAILED], [RUN-IF-OK])
697 # ---------------------------------------------------------------
698 # Check (using qmake) that Qt's version "matches" QT_version.  Must be
699 # run *AFTER* AT_WITH_QT.  Requires autoconf 2.60.
701 # This macro is ignored if Qt support has been disabled (using
702 # `--with-qt=no' or `--without-qt').
704 # RUN-IF-FAILED is arbitrary code to execute if Qt cannot be found or
705 # if any problem happens.  If this argument is omitted, then
706 # AC_MSG_ERROR will be called.  RUN-IF-OK is arbitrary code to execute
707 # if Qt was successfully found.
709 # This macro provides the Qt version in $(QT_VERSION).
711 AC_DEFUN([AT_REQUIRE_QT_VERSION],
712   [AC_PREREQ([2.60])
714    # This is a hack to get decent flow control with `break'.
715    for _qt_ignored in once; do
717      if test x"$with_qt" = x"no"; then
718        break
719      fi
721      if test x"$QMAKE" = x; then
722        AX_INSTEAD_IF([$2],
723         [\$QMAKE is empty.  Did you invoke AT@&t@_WITH_QT before AT@&t@_REQUIRE_QT_VERSION?])
724        break
725      fi
727      AC_CACHE_CHECK([for Qt's version],
728        [at_cv_QT_VERSION],
729        [echo "$as_me:$LINENO: Running $QMAKE --version:" \
730           >& AS_MESSAGE_LOG_FD
731         $QMAKE --version >& AS_MESSAGE_LOG_FD 2>&1
732         qmake_version_sed=['/^.*\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*$/!d;s//\1/']
733         at_cv_QT_VERSION=`$QMAKE --version 2>&1 \
734                           | sed "$qmake_version_sed"`])
735      if test x"$at_cv_QT_VERSION" = x; then
736        AX_INSTEAD_IF([$2],
737          [Cannot detect Qt's version.])
738        break
739      fi
740      AC_SUBST([QT_VERSION],
741        [$at_cv_QT_VERSION])
742      AS_VERSION_COMPARE([$QT_VERSION], [$1],
743        [AX_INSTEAD_IF([$2],
744           [This package requires Qt $1 or above.])
745         break])
747      # Run the user code
748      $3
750    done  # end hack (useless FOR to be able to use break)
751   ])
754 # _AT_TWEAK_PRO_FILE(QT_VAR, VALUE)
755 # ---------------------------------
756 # @internal.  Tweak the variable QT_VAR in the .pro file.  VALUE is an
757 # IFS-separated list of values, and each value is rewritten as
758 # follows:
760 #   +value  => QT_VAR += value
761 #   -value  => QT_VAR -= value
762 #    value  => QT_VAR += value
764 AC_DEFUN([_AT_TWEAK_PRO_FILE],
765   [ # Tweak the value of $1 in the .pro file for $2.
766    qt_conf=''
767    for at_mod in $2; do
768      at_mod=`echo "$at_mod" | sed 's/^-//; tough
769                                    s/^+//; beef
770                                    :ough
771                                    s/^/$1 -= /;n
772                                    :eef
773                                    s/^/$1 += /'`
774      qt_conf="\
775 $qt_conf
776 $at_mod"
777    done
778     echo "$qt_conf" | sed 1d >>"$pro_file"
779   ])
781 # eof