1AC_PREREQ([2.64])
2AC_INIT([HarfBuzz],
3        [0.9.33],
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-pax 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_version_major + 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
148if test "x$with_glib" = "xyes" -o "x$with_glib" = "xauto"; then
149	PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, have_glib=true, :)
150fi
151if test "x$with_glib" = "xyes" -a "x$have_glib" != "xtrue"; then
152	AC_MSG_ERROR([glib support requested but glib-2.0 not found])
153fi
154if $have_glib; then
155	AC_DEFINE(HAVE_GLIB, 1, [Have glib2 library])
156fi
157AM_CONDITIONAL(HAVE_GLIB, $have_glib)
158
159dnl ===========================================================================
160
161AC_ARG_WITH(gobject,
162	[AS_HELP_STRING([--with-gobject=@<:@yes/no/auto@:>@],
163			[Use gobject @<:@default=auto@:>@])],,
164	[with_gobject=no])
165have_gobject=false
166if test "x$with_gobject" = "xyes" -o "x$with_gobject" = "xauto"; then
167	PKG_CHECK_MODULES(GOBJECT, gobject-2.0 glib-2.0, have_gobject=true, :)
168fi
169if test "x$with_gobject" = "xyes" -a "x$have_gobject" != "xtrue"; then
170	AC_MSG_ERROR([gobject support requested but gobject-2.0 / glib-2.0 not found])
171fi
172if $have_gobject; then
173	AC_DEFINE(HAVE_GOBJECT, 1, [Have gobject2 library])
174	GLIB_MKENUMS=`$PKG_CONFIG --variable=glib_mkenums glib-2.0`
175	AC_SUBST(GLIB_MKENUMS)
176fi
177AM_CONDITIONAL(HAVE_GOBJECT, $have_gobject)
178
179dnl ===========================================================================
180
181
182dnl ===========================================================================
183# Gobject-Introspection
184have_introspection=false
185m4_ifdef([GOBJECT_INTROSPECTION_CHECK], [
186	if $have_gobject; then
187		GOBJECT_INTROSPECTION_CHECK([1.34.0])
188		if test "x$found_introspection" = xyes; then
189			have_introspection=true
190		fi
191	else
192		AM_CONDITIONAL([HAVE_INTROSPECTION], false)
193	fi
194], [
195	AM_CONDITIONAL([HAVE_INTROSPECTION], false)
196])
197
198dnl ===========================================================================
199
200have_ucdn=true
201if $have_glib; then
202	have_ucdn=false
203fi
204if $have_ucdn; then
205	AC_DEFINE(HAVE_UCDN, 1, [Have UCDN Unicode functions])
206fi
207AM_CONDITIONAL(HAVE_UCDN, $have_ucdn)
208
209dnl ==========================================================================
210
211AC_ARG_WITH(cairo,
212	[AS_HELP_STRING([--with-cairo=@<:@yes/no/auto@:>@],
213			[Use cairo @<:@default=auto@:>@])],,
214	[with_cairo=auto])
215have_cairo=false
216if test "x$with_cairo" = "xyes" -o "x$with_cairo" = "xauto"; then
217	PKG_CHECK_MODULES(CAIRO, cairo >= 1.8.0, have_cairo=true, :)
218fi
219if test "x$with_cairo" = "xyes" -a "x$have_cairo" != "xtrue"; then
220	AC_MSG_ERROR([cairo support requested but not found])
221fi
222if $have_cairo; then
223	AC_DEFINE(HAVE_CAIRO, 1, [Have cairo graphics library])
224fi
225AM_CONDITIONAL(HAVE_CAIRO, $have_cairo)
226
227have_cairo_ft=false
228if $have_cairo; then
229	PKG_CHECK_MODULES(CAIRO_FT, cairo-ft, have_cairo_ft=true, :)
230fi
231if $have_cairo_ft; then
232	AC_DEFINE(HAVE_CAIRO_FT, 1, [Have cairo-ft support in cairo graphics library])
233fi
234AM_CONDITIONAL(HAVE_CAIRO_FT, $have_cairo_ft)
235
236dnl ==========================================================================
237
238AC_ARG_WITH(icu,
239	[AS_HELP_STRING([--with-icu=@<:@yes/no/auto@:>@],
240			[Use ICU @<:@default=auto@:>@])],,
241	[with_icu=auto])
242have_icu=false
243if test "x$with_icu" = "xyes" -o "x$with_icu" = "xauto"; then
244	PKG_CHECK_MODULES(ICU, icu-uc, have_icu=true, :)
245
246	dnl Fallback to icu-config if ICU pkg-config files could not be found
247	if test "$have_icu" != "true"; then
248		AC_CHECK_TOOL(ICU_CONFIG, icu-config, no)
249		AC_MSG_CHECKING([for ICU by using icu-config fallback])
250		if test "$ICU_CONFIG" != "no" && "$ICU_CONFIG" --version >/dev/null; then
251			have_icu=true
252			# We don't use --cflags as this gives us a lot of things that we don't
253			# necessarily want, like debugging and optimization flags
254			# See man (1) icu-config for more info.
255			ICU_CFLAGS=`$ICU_CONFIG --cppflags`
256			ICU_LIBS=`$ICU_CONFIG --ldflags-searchpath --ldflags-libsonly`
257			AC_SUBST(ICU_CFLAGS)
258			AC_SUBST(ICU_LIBS)
259			AC_MSG_RESULT([yes])
260		else
261			AC_MSG_RESULT([no])
262		fi
263	fi
264fi
265if test "x$with_icu" = "xyes" -a "x$have_icu" != "xtrue"; then
266	AC_MSG_ERROR([icu support requested but icu-uc not found])
267fi
268if $have_icu; then
269	CXXFLAGS="$CXXFLAGS `$PKG_CONFIG --variable=CXXFLAGS icu-uc`"
270	AC_DEFINE(HAVE_ICU, 1, [Have ICU library])
271fi
272AM_CONDITIONAL(HAVE_ICU, $have_icu)
273
274dnl ==========================================================================
275
276AC_ARG_WITH(graphite2,
277	[AS_HELP_STRING([--with-graphite2=@<:@yes/no/auto@:>@],
278			[Use the graphite2 library @<:@default=no@:>@])],,
279	[with_graphite2=no])
280have_graphite2=false
281if test "x$with_graphite2" = "xyes" -o "x$with_graphite2" = "xauto"; then
282	PKG_CHECK_MODULES(GRAPHITE2, graphite2, have_graphite2=true, :)
283fi
284if test "x$with_graphite2" = "xyes" -a "x$have_graphite2" != "xtrue"; then
285	AC_MSG_ERROR([graphite2 support requested but libgraphite2 not found])
286fi
287if $have_graphite2; then
288    AC_DEFINE(HAVE_GRAPHITE2, 1, [Have Graphite2 library])
289fi
290AM_CONDITIONAL(HAVE_GRAPHITE2, $have_graphite2)
291
292dnl ==========================================================================
293
294AC_ARG_WITH(freetype,
295	[AS_HELP_STRING([--with-freetype=@<:@yes/no/auto@:>@],
296			[Use the FreeType library @<:@default=auto@:>@])],,
297	[with_freetype=auto])
298have_freetype=false
299if test "x$with_freetype" = "xyes" -o "x$with_freetype" = "xauto"; then
300	PKG_CHECK_MODULES(FREETYPE, freetype2 >= 2.3.8, have_freetype=true, :)
301fi
302if test "x$with_freetype" = "xyes" -a "x$have_freetype" != "xtrue"; then
303	AC_MSG_ERROR([FreeType support requested but libfreetype2 not found])
304fi
305if $have_freetype; then
306	AC_DEFINE(HAVE_FREETYPE, 1, [Have FreeType 2 library])
307	_save_libs="$LIBS"
308	_save_cflags="$CFLAGS"
309	LIBS="$LIBS $FREETYPE_LIBS"
310	CFLAGS="$CFLAGS $FREETYPE_CFLAGS"
311	AC_CHECK_FUNCS(FT_Face_GetCharVariantIndex)
312	LIBS="$_save_libs"
313	CFLAGS="$_save_cflags"
314fi
315AM_CONDITIONAL(HAVE_FREETYPE, $have_freetype)
316
317dnl ===========================================================================
318
319AC_ARG_WITH(uniscribe,
320	[AS_HELP_STRING([--with-uniscribe=@<:@yes/no/auto@:>@],
321			[Use the Uniscribe library @<:@default=no@:>@])],,
322	[with_uniscribe=no])
323have_uniscribe=false
324if test "x$with_uniscribe" = "xyes" -o "x$with_uniscribe" = "xauto"; then
325	AC_CHECK_HEADERS(usp10.h windows.h, have_uniscribe=true)
326fi
327if test "x$with_uniscribe" = "xyes" -a "x$have_uniscribe" != "xtrue"; then
328	AC_MSG_ERROR([uniscribe support requested but not found])
329fi
330if $have_uniscribe; then
331	UNISCRIBE_CFLAGS=
332	UNISCRIBE_LIBS="-lusp10 -lgdi32 -lrpcrt4"
333	AC_SUBST(UNISCRIBE_CFLAGS)
334	AC_SUBST(UNISCRIBE_LIBS)
335	AC_DEFINE(HAVE_UNISCRIBE, 1, [Have Uniscribe library])
336fi
337AM_CONDITIONAL(HAVE_UNISCRIBE, $have_uniscribe)
338
339dnl ===========================================================================
340
341AC_ARG_WITH(coretext,
342	[AS_HELP_STRING([--with-coretext=@<:@yes/no/auto@:>@],
343			[Use CoreText @<:@default=no@:>@])],,
344	[with_coretext=no])
345have_coretext=false
346if test "x$with_coretext" = "xyes" -o "x$with_coretext" = "xauto"; then
347	AC_CHECK_TYPE(CTFontRef, have_coretext=true,, [#include <ApplicationServices/ApplicationServices.h>])
348
349	if $have_coretext; then
350		CORETEXT_CFLAGS=
351		CORETEXT_LIBS="-framework ApplicationServices"
352		AC_SUBST(CORETEXT_CFLAGS)
353		AC_SUBST(CORETEXT_LIBS)
354	else
355		# On iOS CoreText and CoreGraphics are stand-alone frameworks
356		if test "x$have_coretext" != "xtrue"; then
357			AC_CHECK_TYPE(CTFontRef, have_coretext=true,, [#include <CoreText/CoreText.h>])
358		fi
359
360		if $have_coretext; then
361			CORETEXT_CFLAGS=
362			CORETEXT_LIBS="-framework CoreText -framework CoreGraphics"
363			AC_SUBST(CORETEXT_CFLAGS)
364			AC_SUBST(CORETEXT_LIBS)
365		fi
366	fi
367fi
368if test "x$with_coretext" = "xyes" -a "x$have_coretext" != "xtrue"; then
369	AC_MSG_ERROR([CoreText support requested but libcoretext not found])
370fi
371if $have_coretext; then
372	AC_DEFINE(HAVE_CORETEXT, 1, [Have Core Text backend])
373fi
374AM_CONDITIONAL(HAVE_CORETEXT, $have_coretext)
375
376dnl ===========================================================================
377
378AC_CACHE_CHECK([for Intel atomic primitives], hb_cv_have_intel_atomic_primitives, [
379	hb_cv_have_intel_atomic_primitives=false
380	AC_TRY_LINK([
381		void memory_barrier (void) { __sync_synchronize (); }
382		int atomic_add (int *i) { return __sync_fetch_and_add (i, 1); }
383		int mutex_trylock (int *m) { return __sync_lock_test_and_set (m, 1); }
384		void mutex_unlock (int *m) { __sync_lock_release (m); }
385		], [], hb_cv_have_intel_atomic_primitives=true
386	)
387])
388if $hb_cv_have_intel_atomic_primitives; then
389	AC_DEFINE(HAVE_INTEL_ATOMIC_PRIMITIVES, 1, [Have Intel __sync_* atomic primitives])
390fi
391
392dnl ===========================================================================
393
394AC_CACHE_CHECK([for Solaris atomic operations], hb_cv_have_solaris_atomic_ops, [
395	hb_cv_have_solaris_atomic_ops=false
396	AC_TRY_LINK([
397		#include <atomic.h>
398		/* This requires Solaris Studio 12.2 or newer: */
399		#include <mbarrier.h>
400		void memory_barrier (void) { __machine_rw_barrier (); }
401		int atomic_add (volatile unsigned *i) { return atomic_add_int_nv (i, 1); }
402		void *atomic_ptr_cmpxchg (volatile void **target, void *cmp, void *newval) { return atomic_cas_ptr (target, cmp, newval); }
403		], [], hb_cv_have_solaris_atomic_ops=true
404	)
405])
406if $hb_cv_have_solaris_atomic_ops; then
407	AC_DEFINE(HAVE_SOLARIS_ATOMIC_OPS, 1, [Have Solaris __machine_*_barrier and atomic_* operations])
408fi
409
410if test "$os_win32" = no && ! $have_pthread; then
411	AC_CHECK_HEADERS(sched.h)
412	AC_SEARCH_LIBS(sched_yield,rt,AC_DEFINE(HAVE_SCHED_YIELD, 1, [Have sched_yield]))
413fi
414
415dnl ===========================================================================
416
417AC_CONFIG_FILES([
418Makefile
419src/Makefile
420src/hb-version.h
421src/hb-ucdn/Makefile
422util/Makefile
423test/Makefile
424test/api/Makefile
425test/shaping/Makefile
426docs/Makefile
427docs/reference/Makefile
428docs/reference/version.xml
429])
430
431AC_OUTPUT
432
433AC_MSG_NOTICE([
434
435Build configuration:
436
437Unicode callbacks (you want at least one):
438	Glib:			${have_glib}
439	ICU:			${have_icu}
440	UCDN:			${have_ucdn}
441
442Font callbacks (the more the better):
443	FreeType:		${have_freetype}
444
445Tools used for command-line utilities:
446	Cairo:			${have_cairo}
447
448Additional shapers (the more the better):
449	Graphite2:		${have_graphite2}
450
451Platform shapers (not normally needed):
452	CoreText:		${have_coretext}
453	Uniscribe:		${have_uniscribe}
454
455Other features:
456	Documentation:		${have_gtk_doc}
457	GObject bindings:	${have_gobject}
458	Introspection:		${have_introspection}
459])
460