frontend/Makefile.am (AM_CPPFLAGS): Fix build in separate directory.
[ttfautohint.git] / configure.ac
blobed7cfe566c31a071b3a284ebd3b0bf344e6b47fa
1 # configure.ac
3 # Copyright (C) 2011-2021 by Werner Lemberg.
5 # This file is part of the ttfautohint library, and may only be used,
6 # modified, and distributed under the terms given in `COPYING'.  By
7 # continuing to use, modify, or distribute this file you indicate that you
8 # have read `COPYING' and understand and accept it fully.
10 # The file `COPYING' mentioned in the previous paragraph is distributed
11 # with the ttfautohint library.
13 AC_INIT([ttfautohint],
14         [m4_esyscmd(gnulib/git-version-gen VERSION)],
15         [freetype-devel@nongnu.org])
16 AC_CONFIG_AUX_DIR([gnulib])
17 AC_CONFIG_SRCDIR([lib/ttfautohint.pc.in])
19 AM_INIT_AUTOMAKE([-Wall -Werror tar-ustar]
20                  m4_bmatch(m4_defn([AC_PACKAGE_VERSION]),
21                            [-], [gnu],
22                            [gnits]))
24 AC_CONFIG_MACRO_DIRS([gnulib/m4
25                       m4])
27 AM_SILENT_RULES([yes])
29 dnl Derive version triplet (major, minor, revision) from package version
30 dnl string.
32 dnl If `AC_PACKAGE_VERSION' contains the suffix `-dirty', we remove it.  If
33 dnl it then still contains a dash, we have to remove the last dot and
34 dnl everything appended to it (this was added by the `git-version-gen'
35 dnl script to reflect git commits after the last tagged commit, which we
36 dnl ignore).
38 dnl No quotes around first argument of `m4_bpatsubst'.
39 dnl No quotes around `m4_bpatsubst'.
40 m4_define([ttfa_version], m4_bpatsubst(AC_PACKAGE_VERSION, [-dirty$]))
41 m4_define([ttfa_version], m4_bpatsubst(ttfa_version, [\.[^.]+-.+$]))
43 dnl No quotes around first argument of `m4_split'.
44 dnl No quotes around `m4_split'.
45 m4_define([ttfa_triplet], m4_split(ttfa_version, [\.]))
47 dnl No quotes around second argument of `m4_argn'.
48 dnl No quotes around `m4_argn'.
49 m4_define([ttfa_major], m4_argn([1], ttfa_triplet))
50 m4_define([ttfa_minor], m4_argn([2], ttfa_triplet))
51 m4_define([ttfa_revision], m4_argn([3], ttfa_triplet))
53 dnl No quotes around first two arguments of `m4_if'.
54 m4_if(ttfa_revision,
55       ,
56       [m4_define([ttfa_revision], [0])],
57       [])
59 m4_if(ttfa_version,
60       AC_PACKAGE_VERSION,
61       [],
62       [AC_MSG_WARN([Revision number of version tuplet set to ttfa_revision.])])
64 ttfautohint_major=ttfa_major
65 ttfautohint_minor=ttfa_minor
66 ttfautohint_revision=ttfa_revision
68 AC_SUBST([ttfautohint_major])
69 AC_SUBST([ttfautohint_minor])
70 AC_SUBST([ttfautohint_revision])
72 AC_USE_SYSTEM_EXTENSIONS
74 AC_PROG_LN_S
76 AC_PROG_CPP
77 AC_PROG_CC
78 AC_PROG_CXX
79 AC_C_INLINE
81 gl_EARLY
83 PKG_PROG_PKG_CONFIG([0.24])
85 # AM_PROG_AR is new in automake 1.11.2;
86 # however, MinGW doesn't have it yet (May 2012)
87 m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
89 AC_PATH_PROG([BISON], [bison])
90 AC_PATH_PROG([FLEX], [flex])
92 gl_INIT
94 PKG_CHECK_MODULES([HARFBUZZ], [harfbuzz >= 2.4.0])
96 AT_WITH_QT([], [], [QTPLUGIN.imageformats = -])
97 AT_REQUIRE_QT_VERSION([4.6])
99 if test x"$with_qt" != x"no"; then
100   AC_MSG_CHECKING([for QLocale::quoteString])
101   AS_VERSION_COMPARE([$QT_VERSION], [4.8],
102     [AC_MSG_RESULT(no)],
103     [AC_MSG_RESULT(no)],
104     [AC_MSG_RESULT(yes)
105      AC_DEFINE([HAVE_QT_QUOTESTRING], [1],
106        [Define if Qt function QLocale::quoteString is available.])])
109 AM_CONDITIONAL([USE_QT], [test x"$with_qt" != x"no"])
111 LT_INIT
112 LT_LTLIZE_LANG([C])
115 # We use libtool's convenient check for the math library.
116 LT_LIB_M
117 AC_SUBST([LIBM])
120 AC_ARG_WITH([doc],
121             [AS_HELP_STRING([--with-doc],
122                             [install documentation @<:@default=yes@:>@])],
123             [],
124             [with_doc=yes])
126 AC_ARG_WITH([freetype-config],
127             [AS_HELP_STRING([--with-freetype-config=PROG],
128                             [use FreeType configuration program PROG])],
129             [freetype_config=$withval],
130             [freetype_config=yes])
132 if test "$freetype_config" = "yes"; then
133   AC_PATH_TOOL(ft_config,
134                freetype-config,
135                no)
136 else
137   ft_config="$freetype_config"
140 if test "$ft_config" = "no"; then
141   # freetype-config tool not found or disabled; try pkg-config
142   PKG_CHECK_MODULES([FREETYPE], [freetype2 >= 2.4.5])
143   if { test -z "$FREETYPE_CFLAGS" || test -z "$FREETYPE_LIBS"; }; then
144     AC_MSG_ERROR([FreeType library is missing; see https://www.freetype.org/])
145   fi
146   FREETYPE_CPPFLAGS="$FREETYPE_CFLAGS"
147 else
148   FREETYPE_CPPFLAGS="`$ft_config --cflags`"
149   FREETYPE_LIBS="`$ft_config --libtool`"
151   # many platforms no longer install .la files for system libraries
152   if test ! -f "$FREETYPE_LIBS"; then
153     FREETYPE_LIBS="`$ft_config --libs`"
154   fi
157 AC_SUBST([FREETYPE_CPPFLAGS])
158 AC_SUBST([FREETYPE_LIBS])
161 AC_MSG_CHECKING([whether FreeType header files are version 2.4.5 or higher])
162 old_CPPFLAGS="$CPPFLAGS"
163 CPPFLAGS=$FREETYPE_CPPFLAGS
164 AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
166 #include <ft2build.h>
167 #include FT_FREETYPE_H
168 #if (FREETYPE_MAJOR*1000 + FREETYPE_MINOR)*1000 + FREETYPE_PATCH < 2004005
169 #error Freetype version too low.
170 #endif
172 ]])],
173 [AC_MSG_RESULT(yes)
174  CPPFLAGS="$old_CPPFLAGS"],
175 [AC_MSG_ERROR([Need FreeType version 2.4.5 or higher])])
178 AC_MSG_CHECKING([whether FreeType library is version 2.4.5 or higher])
179 old_CPPFLAGS="$CPPFLAGS"
180 CPPFLAGS=$FREETYPE_CPPFLAGS
181 old_LIBS="$LIBS"
182 LIBS=$FREETYPE_LIBS
183 AC_LANG_PUSH([LTLIZED C])
184 AC_RUN_IFELSE([AC_LANG_SOURCE([[
186 #include <stdlib.h>
187 #include <ft2build.h>
188 #include FT_FREETYPE_H
191 main()
193   FT_Error error;
194   FT_Library library;
195   FT_Int major, minor, patch;
197   error = FT_Init_FreeType(&library);
198   if (error)
199   {
200     printf("(test program reports error code %d)... ", error);
201     exit(EXIT_FAILURE);
202   }
204   FT_Library_Version(library, &major, &minor, &patch);
206   printf("(found %d.%d.%d)... ", major, minor, patch);
208   if (((major*1000 + minor)*1000 + patch) >= 2004005)
209     exit(EXIT_SUCCESS);
210   exit(EXIT_FAILURE);
213 ]])],
214 [AC_MSG_RESULT(yes)
215  CPPFLAGS="$old_CPPFLAGS"
216  LIBS="$old_LIBS"],
217 [AC_MSG_ERROR([Need FreeType version 2.4.5 or higher])],
218 [AC_MSG_RESULT([skipped due to cross-compilation])])
219 AC_LANG_POP
222 if test $cross_compiling = no; then
223   AM_MISSING_PROG(HELP2MAN, help2man)
224 else
225   HELP2MAN=:
228 # The documentation is part of the distributed bundle.  In the following,
229 # tests for the documentation building tools are made fatal in case those
230 # files are missing (which can happen during bootstrap).
232 AC_DEFUN([TA_DOC],
233   [if test -f "$1"; then
234      AC_MSG_WARN([$2])
235      with_doc=no
236    else
237      AC_MSG_ERROR([$2])
238    fi])
240 image_file=$srcdir/doc/img/ttfautohintGUI.png
241 html_file=$srcdir/doc/ttfautohint.html
242 pdf_file=$srcdir/doc/ttfautohint.pdf
244 # We use the Noto font family within the PDF documentation file, since it
245 # has the best Unicode coverage of all freely available fonts.
247 #   https://github.com/googlei18n/noto-fonts/
249 # To be more precise, we don't directly access the git repository; instead,
250 # we simply test the presence of a typical font file (using the `kpsewhich'
251 # program as provided by TeXLive and other TeX distributions); the user
252 # should set the TTFONTS environment variable to add the corresponding
253 # directory to the TrueType font search path.
255 # Example:
257 #   TTFONTS="/path/to/git/noto-fonts/unhinted/ttf//;"
259 # (note the trailing `;').
261 noto_font_file=NotoSerifYezidi-Regular.ttf
264 if test x"$with_doc" != x"no"; then
265   # snapshot image creation
266   if test x"$DISPLAY" == x; then
267     TA_DOC([$image_file],
268            [Need X11 to create snapshot image of ttfautohintGUI])
269   else
270     AC_CHECK_PROG([IMPORT], [import], [import], [no])
271     if test x"$IMPORT" == x"no"; then
272       TA_DOC([$image_file],
273              [Need ImageMagick to create snapshot image of ttfautohintGUI])
274     fi
275   fi
277   # conversion of SVG to PDF
278   AC_CHECK_PROG([INKSCAPE], [inkscape], [inkscape], [no])
279   if test x"$INKSCAPE" == x"no"; then
280     TA_DOC([$pdf_file],
281            [Need inkscape to convert SVG image files to PDF])
282   fi
284   # documentation creation
285   AC_CHECK_PROG([PANDOC], [pandoc], [pandoc], [no])
286   if test x"$PANDOC" == x"no"; then
287     TA_DOC([$html_file],
288            [Need pandoc to create PDF and HTML documentation files])
289   fi
291   # PDF documentation
292   # To support Devanagari and other Indic scripts properly,
293   # we currently can use XeTeX only.
294   AC_CHECK_PROGS([LATEX], [xelatex], [no])
295   if test x"$LATEX" == x"no"; then
296     TA_DOC([$pdf_file],
297            [Need xelatex to create documentation in PDF format])
298   else
299     AC_CHECK_PROGS([KPSEWHICH], [kpsewhich], [no])
300     if test x"$KPSEWHICH" == x"no"; then
301       AC_MSG_WARN([Can't find `kpsewhich' to check presence of Noto font files automatically.])
302       TA_DOC([$pdf_file],
303              [Need kpsewhich to find fonts for documentation in PDF format.])
304     else
305       AC_MSG_CHECKING([for font $noto_font_file])
306       $KPSEWHICH $noto_font_file &> /dev/null
307       if test $? -eq 0; then
308         AC_MSG_RESULT([yes])
309       else
310         AC_MSG_RESULT([no])
311         AC_MSG_WARN([Can't find `$noto_font_file'.])
312         TA_DOC([$pdf_file],
313                [Adjust the `TTFONTS' environment variable so that the Noto fonts are found.])
314       fi
315     fi
316   fi
319 AM_CONDITIONAL([WITH_DOC], [test x"$with_doc" != x"no"])
321 # Let autoconf create the `img' subdirectory, if necessary.
322 # `mkdir' is just a tag.
323 AC_CONFIG_COMMANDS([doc/img/mkdir], [true])
325 AC_CONFIG_HEADERS([config.h])
326 AC_CONFIG_FILES([Makefile
327                  gnulib/src/Makefile
328                  lib/Makefile
329                  frontend/Makefile
330                  frontend/static-plugins.cpp
331                  doc/Makefile])
332 AC_OUTPUT
334 # end of configure.ac