1AC_PREREQ([2.64])
2AC_INIT([HarfBuzz],
3        [1.2.6],
4        [http://bugs.freedesktop.org/enter_bug.cgi?product=harfbuzz],
5        [harfbuzz],
6        [http://harfbuzz.org/])
7
8AC_CONFIG_MACRO_DIR([m4])
9AC_CONFIG_SRCDIR([src/harfbuzz.pc.in])
10AC_CONFIG_HEADERS([config.h])
11
12AM_INIT_AUTOMAKE([1.11.1 gnits tar-ustar dist-bzip2 no-dist-gzip -Wall no-define color-tests -Wno-portability])
13AM_CONDITIONAL(AUTOMAKE_OLDER_THAN_1_13, test $am__api_version = 1.11 -o $am__api_version = 1.12)
14AM_SILENT_RULES([yes])
15
16# Initialize libtool
17m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
18LT_PREREQ([2.2])
19LT_INIT([disable-static])
20
21# Check for programs
22AC_PROG_CC
23AM_PROG_CC_C_O
24AC_PROG_CXX
25PKG_PROG_PKG_CONFIG([0.20])
26AM_MISSING_PROG([RAGEL], [ragel])
27AM_MISSING_PROG([GIT], [git])
28
29# Version
30m4_define(hb_version_triplet,m4_split(AC_PACKAGE_VERSION,[[.]]))
31m4_define(hb_version_major,m4_argn(1,hb_version_triplet))
32m4_define(hb_version_minor,m4_argn(2,hb_version_triplet))
33m4_define(hb_version_micro,m4_argn(3,hb_version_triplet))
34HB_VERSION_MAJOR=hb_version_major
35HB_VERSION_MINOR=hb_version_minor
36HB_VERSION_MICRO=hb_version_micro
37HB_VERSION=AC_PACKAGE_VERSION
38AC_SUBST(HB_VERSION_MAJOR)
39AC_SUBST(HB_VERSION_MINOR)
40AC_SUBST(HB_VERSION_MICRO)
41AC_SUBST(HB_VERSION)
42
43# Libtool version
44m4_define([hb_version_int],
45	  m4_eval(hb_version_major*10000 + hb_version_minor*100 + hb_version_micro))
46m4_if(m4_eval(hb_version_minor % 2), [1],
47      dnl for unstable releases
48      [m4_define([hb_libtool_revision], 0)],
49      dnl for stable releases
50      [m4_define([hb_libtool_revision], hb_version_micro)])
51m4_define([hb_libtool_age],
52	  m4_eval(hb_version_int - hb_libtool_revision))
53m4_define([hb_libtool_current],
54	  m4_eval(hb_libtool_age))
55HB_LIBTOOL_VERSION_INFO=hb_libtool_current:hb_libtool_revision:hb_libtool_age
56AC_SUBST(HB_LIBTOOL_VERSION_INFO)
57
58# Documentation
59have_gtk_doc=false
60m4_ifdef([GTK_DOC_CHECK], [
61GTK_DOC_CHECK([1.15],[--flavour no-tmpl])
62	if test "x$enable_gtk_doc" = xyes; then
63		have_gtk_doc=true
64	fi
65], [
66	AM_CONDITIONAL([ENABLE_GTK_DOC], false)
67])
68
69# Functions and headers
70AC_CHECK_FUNCS(atexit mprotect sysconf getpagesize mmap isatty)
71AC_CHECK_HEADERS(unistd.h sys/mman.h)
72
73# Compiler flags
74AC_CANONICAL_HOST
75AC_CHECK_ALIGNOF([struct{char;}])
76if test "x$GCC" = "xyes"; then
77
78	# Make symbols link locally
79	LDFLAGS="$LDFLAGS -Bsymbolic-functions"
80
81	# Make sure we don't link to libstdc++
82	CXXFLAGS="$CXXFLAGS -fno-rtti -fno-exceptions"
83
84	# Assorted warnings
85	CXXFLAGS="$CXXFLAGS -Wcast-align"
86
87	case "$host" in
88		*-*-mingw*)
89		;;
90		*)
91			# Hide inline methods
92			CXXFLAGS="$CXXFLAGS -fvisibility-inlines-hidden"
93		;;
94	esac
95
96	case "$host" in
97		arm-*-*)
98			if test "x$ac_cv_alignof_struct_char__" != x1; then
99				# Request byte alignment
100				CXXFLAGS="$CXXFLAGS -mstructure-size-boundary=8"
101			fi
102		;;
103	esac
104fi
105
106AM_CONDITIONAL(HAVE_GCC, test "x$GCC" = "xyes")
107
108hb_os_win32=no
109AC_MSG_CHECKING([for native Win32])
110case "$host" in
111  *-*-mingw*)
112    hb_os_win32=yes
113    ;;
114esac
115AC_MSG_RESULT([$hb_os_win32])
116AM_CONDITIONAL(OS_WIN32, test "$hb_os_win32" = "yes")
117
118have_pthread=false
119if test "$hb_os_win32" = no; then
120	AX_PTHREAD([have_pthread=true])
121fi
122if $have_pthread; then
123	AC_DEFINE(HAVE_PTHREAD, 1, [Have POSIX threads])
124fi
125AM_CONDITIONAL(HAVE_PTHREAD, $have_pthread)
126
127dnl ==========================================================================
128
129have_ot=true
130if $have_ot; then
131	AC_DEFINE(HAVE_OT, 1, [Have native OpenType Layout backend])
132fi
133AM_CONDITIONAL(HAVE_OT, $have_ot)
134
135have_fallback=true
136if $have_fallback; then
137	AC_DEFINE(HAVE_FALLBACK, 1, [Have simple TrueType Layout backend])
138fi
139AM_CONDITIONAL(HAVE_FALLBACK, $have_fallback)
140
141dnl ===========================================================================
142
143AC_ARG_WITH(glib,
144	[AS_HELP_STRING([--with-glib=@<:@yes/no/auto@:>@],
145			[Use glib @<:@default=auto@:>@])],,
146	[with_glib=auto])
147have_glib=false
148GLIB_DEPS="glib-2.0 >= 2.16"
149AC_SUBST(GLIB_DEPS)
150if test "x$with_glib" = "xyes" -o "x$with_glib" = "xauto"; then
151	PKG_CHECK_MODULES(GLIB, $GLIB_DEPS, have_glib=true, :)
152fi
153if test "x$with_glib" = "xyes" -a "x$have_glib" != "xtrue"; then
154	AC_MSG_ERROR([glib support requested but glib-2.0 not found])
155fi
156if $have_glib; then
157	AC_DEFINE(HAVE_GLIB, 1, [Have glib2 library])
158fi
159AM_CONDITIONAL(HAVE_GLIB, $have_glib)
160
161dnl ===========================================================================
162
163AC_ARG_WITH(gobject,
164	[AS_HELP_STRING([--with-gobject=@<:@yes/no/auto@:>@],
165			[Use gobject @<:@default=auto@:>@])],,
166	[with_gobject=no])
167have_gobject=false
168if test "x$with_gobject" = "xyes" -o "x$with_gobject" = "xauto"; then
169	PKG_CHECK_MODULES(GOBJECT, gobject-2.0 glib-2.0, have_gobject=true, :)
170fi
171if test "x$with_gobject" = "xyes" -a "x$have_gobject" != "xtrue"; then
172	AC_MSG_ERROR([gobject support requested but gobject-2.0 / glib-2.0 not found])
173fi
174if $have_gobject; then
175	AC_DEFINE(HAVE_GOBJECT, 1, [Have gobject2 library])
176	GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
177	AC_SUBST(GLIB_MKENUMS)
178fi
179AM_CONDITIONAL(HAVE_GOBJECT, $have_gobject)
180
181dnl ===========================================================================
182
183
184dnl ===========================================================================
185# Gobject-Introspection
186have_introspection=false
187m4_ifdef([GOBJECT_INTROSPECTION_CHECK], [
188	if $have_gobject; then
189		GOBJECT_INTROSPECTION_CHECK([1.34.0])
190		if test "x$found_introspection" = xyes; then
191			have_introspection=true
192		fi
193	else
194		AM_CONDITIONAL([HAVE_INTROSPECTION], false)
195	fi
196], [
197	AM_CONDITIONAL([HAVE_INTROSPECTION], false)
198])
199
200dnl ==========================================================================
201
202AC_ARG_WITH(cairo,
203	[AS_HELP_STRING([--with-cairo=@<:@yes/no/auto@:>@],
204			[Use cairo @<:@default=auto@:>@])],,
205	[with_cairo=auto])
206have_cairo=false
207if test "x$with_cairo" = "xyes" -o "x$with_cairo" = "xauto"; then
208	PKG_CHECK_MODULES(CAIRO, cairo >= 1.8.0, have_cairo=true, :)
209fi
210if test "x$with_cairo" = "xyes" -a "x$have_cairo" != "xtrue"; then
211	AC_MSG_ERROR([cairo support requested but not found])
212fi
213if $have_cairo; then
214	AC_DEFINE(HAVE_CAIRO, 1, [Have cairo graphics library])
215fi
216AM_CONDITIONAL(HAVE_CAIRO, $have_cairo)
217
218have_cairo_ft=false
219if $have_cairo; then
220	PKG_CHECK_MODULES(CAIRO_FT, cairo-ft, have_cairo_ft=true, :)
221fi
222if $have_cairo_ft; then
223	AC_DEFINE(HAVE_CAIRO_FT, 1, [Have cairo-ft support in cairo graphics library])
224fi
225AM_CONDITIONAL(HAVE_CAIRO_FT, $have_cairo_ft)
226
227dnl ==========================================================================
228
229AC_ARG_WITH(fontconfig,
230	[AS_HELP_STRING([--with-fontconfig=@<:@yes/no/auto@:>@],
231			[Use fontconfig @<:@default=auto@:>@])],,
232	[with_fontconfig=auto])
233have_fontconfig=false
234if test "x$with_fontconfig" = "xyes" -o "x$with_fontconfig" = "xauto"; then
235	PKG_CHECK_MODULES(FONTCONFIG, fontconfig, have_fontconfig=true, :)
236fi
237if test "x$with_fontconfig" = "xyes" -a "x$have_fontconfig" != "xtrue"; then
238	AC_MSG_ERROR([fontconfig support requested but not found])
239fi
240if $have_fontconfig; then
241	AC_DEFINE(HAVE_FONTCONFIG, 1, [Have fontconfig library])
242fi
243AM_CONDITIONAL(HAVE_FONTCONFIG, $have_fontconfig)
244
245dnl ==========================================================================
246
247AC_ARG_WITH(icu,
248	[AS_HELP_STRING([--with-icu=@<:@yes/no/builtin/auto@:>@],
249			[Use ICU @<:@default=auto@:>@])],,
250	[with_icu=auto])
251have_icu=false
252if test "x$with_icu" = "xyes" -o "x$with_icu" = "xbuiltin" -o "x$with_icu" = "xauto"; then
253	PKG_CHECK_MODULES(ICU, icu-uc, have_icu=true, :)
254
255	dnl Fallback to icu-config if ICU pkg-config files could not be found
256	if test "$have_icu" != "true"; then
257		AC_CHECK_TOOL(ICU_CONFIG, icu-config, no)
258		AC_MSG_CHECKING([for ICU by using icu-config fallback])
259		if test "$ICU_CONFIG" != "no" && "$ICU_CONFIG" --version >/dev/null; then
260			have_icu=true
261			# We don't use --cflags as this gives us a lot of things that we don't
262			# necessarily want, like debugging and optimization flags
263			# See man (1) icu-config for more info.
264			ICU_CFLAGS=`$ICU_CONFIG --cppflags`
265			ICU_LIBS=`$ICU_CONFIG --ldflags-searchpath --ldflags-libsonly`
266			AC_SUBST(ICU_CFLAGS)
267			AC_SUBST(ICU_LIBS)
268			AC_MSG_RESULT([yes])
269		else
270			AC_MSG_RESULT([no])
271		fi
272	fi
273fi
274if test \( "x$with_icu" = "xyes" -o "x$with_icu" = "xbuiltin" \) -a "x$have_icu" != "xtrue"; then
275	AC_MSG_ERROR([icu support requested but icu-uc not found])
276fi
277
278if $have_icu; then
279	CXXFLAGS="$CXXFLAGS `$PKG_CONFIG --variable=CXXFLAGS icu-uc`"
280	AC_DEFINE(HAVE_ICU, 1, [Have ICU library])
281	if test "x$with_icu" = "xbuiltin"; then
282		AC_DEFINE(HAVE_ICU_BUILTIN, 1, [Use hb-icu Unicode callbacks])
283	fi
284fi
285AM_CONDITIONAL(HAVE_ICU, $have_icu)
286AM_CONDITIONAL(HAVE_ICU_BUILTIN, $have_icu && test "x$with_icu" = "xbuiltin")
287
288dnl ===========================================================================
289
290have_ucdn=true
291if $have_glib || $have_icu && test "x$with_icu" = "xbuiltin"; then
292	have_ucdn=false
293fi
294if $have_ucdn; then
295	AC_DEFINE(HAVE_UCDN, 1, [Have UCDN Unicode functions])
296fi
297AM_CONDITIONAL(HAVE_UCDN, $have_ucdn)
298
299dnl ==========================================================================
300
301AC_ARG_WITH(graphite2,
302	[AS_HELP_STRING([--with-graphite2=@<:@yes/no/auto@:>@],
303			[Use the graphite2 library @<:@default=no@:>@])],,
304	[with_graphite2=no])
305have_graphite2=false
306GRAPHITE2_DEPS="graphite2"
307AC_SUBST(GRAPHITE2_DEPS)
308if test "x$with_graphite2" = "xyes" -o "x$with_graphite2" = "xauto"; then
309	PKG_CHECK_MODULES(GRAPHITE2, $GRAPHITE2_DEPS, have_graphite2=true, :)
310fi
311if test "x$with_graphite2" = "xyes" -a "x$have_graphite2" != "xtrue"; then
312	AC_MSG_ERROR([graphite2 support requested but libgraphite2 not found])
313fi
314if $have_graphite2; then
315	AC_DEFINE(HAVE_GRAPHITE2, 1, [Have Graphite2 library])
316fi
317AM_CONDITIONAL(HAVE_GRAPHITE2, $have_graphite2)
318
319dnl ==========================================================================
320
321AC_ARG_WITH(freetype,
322	[AS_HELP_STRING([--with-freetype=@<:@yes/no/auto@:>@],
323			[Use the FreeType library @<:@default=auto@:>@])],,
324	[with_freetype=auto])
325have_freetype=false
326FREETYPE_DEPS="freetype2 >= 12.0.6"
327AC_SUBST(FREETYPE_DEPS)
328if test "x$with_freetype" = "xyes" -o "x$with_freetype" = "xauto"; then
329	# See freetype/docs/VERSION.DLL; 12.0.6 means freetype-2.4.2
330	PKG_CHECK_MODULES(FREETYPE, $FREETYPE_DEPS, have_freetype=true, :)
331fi
332if test "x$with_freetype" = "xyes" -a "x$have_freetype" != "xtrue"; then
333	AC_MSG_ERROR([FreeType support requested but libfreetype2 not found])
334fi
335if $have_freetype; then
336	AC_DEFINE(HAVE_FREETYPE, 1, [Have FreeType 2 library])
337fi
338AM_CONDITIONAL(HAVE_FREETYPE, $have_freetype)
339
340dnl ===========================================================================
341
342AC_ARG_WITH(uniscribe,
343	[AS_HELP_STRING([--with-uniscribe=@<:@yes/no/auto@:>@],
344			[Use the Uniscribe library @<:@default=no@:>@])],,
345	[with_uniscribe=no])
346have_uniscribe=false
347if test "x$with_uniscribe" = "xyes" -o "x$with_uniscribe" = "xauto"; then
348	AC_CHECK_HEADERS(usp10.h windows.h, have_uniscribe=true)
349fi
350if test "x$with_uniscribe" = "xyes" -a "x$have_uniscribe" != "xtrue"; then
351	AC_MSG_ERROR([uniscribe support requested but not found])
352fi
353if $have_uniscribe; then
354	UNISCRIBE_CFLAGS=
355	UNISCRIBE_LIBS="-lusp10 -lgdi32 -lrpcrt4"
356	AC_SUBST(UNISCRIBE_CFLAGS)
357	AC_SUBST(UNISCRIBE_LIBS)
358	AC_DEFINE(HAVE_UNISCRIBE, 1, [Have Uniscribe library])
359fi
360AM_CONDITIONAL(HAVE_UNISCRIBE, $have_uniscribe)
361
362dnl ===========================================================================
363
364AC_ARG_WITH(directwrite,
365	[AS_HELP_STRING([--with-directwrite=@<:@yes/no/auto@:>@],
366			[Use the DirectWrite library (experimental) @<:@default=no@:>@])],,
367	[with_directwrite=no])
368have_directwrite=false
369AC_LANG_PUSH([C++])
370if test "x$with_directwrite" = "xyes" -o "x$with_directwrite" = "xauto"; then
371	AC_CHECK_HEADERS(dwrite.h, have_directwrite=true)
372fi
373AC_LANG_POP([C++])
374if test "x$with_directwrite" = "xyes" -a "x$have_directwrite" != "xtrue"; then
375	AC_MSG_ERROR([directwrite support requested but not found])
376fi
377if $have_directwrite; then
378	DIRECTWRITE_CXXFLAGS=
379	DIRECTWRITE_LIBS="-ldwrite"
380	AC_SUBST(DIRECTWRITE_CXXFLAGS)
381	AC_SUBST(DIRECTWRITE_LIBS)
382	AC_DEFINE(HAVE_DIRECTWRITE, 1, [Have DirectWrite library])
383fi
384AM_CONDITIONAL(HAVE_DIRECTWRITE, $have_directwrite)
385
386dnl ===========================================================================
387
388AC_ARG_WITH(coretext,
389	[AS_HELP_STRING([--with-coretext=@<:@yes/no/auto@:>@],
390			[Use CoreText @<:@default=no@:>@])],,
391	[with_coretext=no])
392have_coretext=false
393if test "x$with_coretext" = "xyes" -o "x$with_coretext" = "xauto"; then
394	AC_CHECK_TYPE(CTFontRef, have_coretext=true,, [#include <ApplicationServices/ApplicationServices.h>])
395
396	if $have_coretext; then
397		CORETEXT_CFLAGS=
398		CORETEXT_LIBS="-framework ApplicationServices"
399		AC_SUBST(CORETEXT_CFLAGS)
400		AC_SUBST(CORETEXT_LIBS)
401	else
402		# On iOS CoreText and CoreGraphics are stand-alone frameworks
403		if test "x$have_coretext" != "xtrue"; then
404			AC_CHECK_TYPE(CTFontRef, have_coretext=true,, [#include <CoreText/CoreText.h>])
405		fi
406
407		if $have_coretext; then
408			CORETEXT_CFLAGS=
409			CORETEXT_LIBS="-framework CoreText -framework CoreGraphics"
410			AC_SUBST(CORETEXT_CFLAGS)
411			AC_SUBST(CORETEXT_LIBS)
412		fi
413	fi
414fi
415if test "x$with_coretext" = "xyes" -a "x$have_coretext" != "xtrue"; then
416	AC_MSG_ERROR([CoreText support requested but libcoretext not found])
417fi
418if $have_coretext; then
419	AC_DEFINE(HAVE_CORETEXT, 1, [Have Core Text backend])
420fi
421AM_CONDITIONAL(HAVE_CORETEXT, $have_coretext)
422
423dnl ===========================================================================
424
425AC_CACHE_CHECK([for Intel atomic primitives], hb_cv_have_intel_atomic_primitives, [
426	hb_cv_have_intel_atomic_primitives=false
427	AC_TRY_LINK([
428		void memory_barrier (void) { __sync_synchronize (); }
429		int atomic_add (int *i) { return __sync_fetch_and_add (i, 1); }
430		int mutex_trylock (int *m) { return __sync_lock_test_and_set (m, 1); }
431		void mutex_unlock (int *m) { __sync_lock_release (m); }
432		], [], hb_cv_have_intel_atomic_primitives=true
433	)
434])
435if $hb_cv_have_intel_atomic_primitives; then
436	AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, [Have Intel __sync_* atomic primitives])
437fi
438
439dnl ===========================================================================
440
441AC_CACHE_CHECK([for Solaris atomic operations], hb_cv_have_solaris_atomic_ops, [
442	hb_cv_have_solaris_atomic_ops=false
443	AC_TRY_LINK([
444		#include <atomic.h>
445		/* This requires Solaris Studio 12.2 or newer: */
446		#include <mbarrier.h>
447		void memory_barrier (void) { __machine_rw_barrier (); }
448		int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i, 1); }
449		void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void *newval) { return atomic_cas_ptr (target, cmp, newval); }
450		], [], hb_cv_have_solaris_atomic_ops=true
451	)
452])
453if $hb_cv_have_solaris_atomic_ops; then
454	AC_DEFINE(HAVE_SOLARIS_ATOMIC_OPS, 1, [Have Solaris __machine_*_barrier and atomic_* operations])
455fi
456
457if test "$os_win32" = no && ! $have_pthread; then
458	AC_CHECK_HEADERS(sched.h)
459	AC_SEARCH_LIBS(sched_yield,rt,AC_DEFINE(HAVE_SCHED_YIELD, 1, [Have sched_yield]))
460fi
461
462dnl ===========================================================================
463
464AC_CONFIG_FILES([
465Makefile
466src/Makefile
467src/hb-version.h
468src/hb-ucdn/Makefile
469util/Makefile
470test/Makefile
471test/api/Makefile
472test/fuzzing/Makefile
473test/shaping/Makefile
474docs/Makefile
475docs/version.xml
476win32/Makefile
477win32/config.h.win32
478])
479
480AC_OUTPUT
481
482AC_MSG_NOTICE([
483
484Build configuration:
485
486Unicode callbacks (you want at least one):
487	Glib:			${have_glib}
488	ICU:			${have_icu}
489	UCDN:			${have_ucdn}
490
491Font callbacks (the more the better):
492	FreeType:		${have_freetype}
493
494Tools used for command-line utilities:
495	Cairo:			${have_cairo}
496	Fontconfig:		${have_fontconfig}
497
498Additional shapers (the more the better):
499	Graphite2:		${have_graphite2}
500
501Platform shapers (not normally needed):
502	CoreText:		${have_coretext}
503	Uniscribe:		${have_uniscribe}
504	DirectWrite:		${have_directwrite}
505
506Other features:
507	Documentation:		${have_gtk_doc}
508	GObject bindings:	${have_gobject}
509	Introspection:		${have_introspection}
510])
511