xref: /freebsd/contrib/libxo/configure.ac (revision 273c26a3c3bea87a241d6879abd4f991db180bf0)
1#
2# $Id$
3#
4# See ./INSTALL for more info
5#
6
7#
8# Release numbering: even numbered dot releases are official ones, and
9# odd numbers are development ones.  The svn version of this file will
10# only (ONLY!) ever (EVER!) contain odd numbers, so I'll always know if
11# a particular user has the dist or svn release.
12#
13
14AC_PREREQ(2.2)
15AC_INIT([libxo], [0.6.3], [phil@juniper.net])
16AM_INIT_AUTOMAKE([-Wall -Werror foreign -Wno-portability])
17
18# Support silent build rules.  Requires at least automake-1.11.
19# Disable with "configure --disable-silent-rules" or "make V=1"
20m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
21
22AC_PROG_CC
23AM_PROG_AR
24AC_PROG_INSTALL
25AC_CONFIG_MACRO_DIR([m4])
26AC_PROG_LN_S
27
28# Must be after AC_PROG_AR
29LT_INIT([dlopen shared])
30
31AC_PATH_PROG(BASENAME, basename, /usr/bin/basename)
32AC_PATH_PROG(BISON, bison, /usr/bin/bison)
33AC_PATH_PROG(CAT, cat, /bin/cat)
34AC_PATH_PROG(CHMOD, chmod, /bin/chmod)
35AC_PATH_PROG(CP, cp, /bin/cp)
36AC_PATH_PROG(DIFF, diff, /usr/bin/diff)
37AC_PATH_PROG(MKDIR, mkdir, /bin/mkdir)
38AC_PATH_PROG(MV, mv, /bin/mv)
39AC_PATH_PROG(RM, rm, /bin/rm)
40AC_PATH_PROG(SED, sed, /bin/sed)
41
42AC_STDC_HEADERS
43
44# Checks for typedefs, structures, and compiler characteristics.
45AC_C_INLINE
46AC_TYPE_SIZE_T
47
48# Checks for library functions.
49AC_FUNC_ALLOCA
50AC_FUNC_MALLOC
51AC_FUNC_REALLOC
52AC_CHECK_FUNCS([bzero memmove strchr strcspn strerror strspn])
53AC_CHECK_FUNCS([sranddev srand strlcpy])
54AC_CHECK_FUNCS([fdopen getrusage])
55AC_CHECK_FUNCS([gettimeofday ctime])
56AC_CHECK_FUNCS([getpass])
57AC_CHECK_FUNCS([getprogname])
58AC_CHECK_FUNCS([sysctlbyname])
59AC_CHECK_FUNCS([flock])
60AC_CHECK_FUNCS([asprintf])
61AC_CHECK_FUNCS([__flbf])
62AC_CHECK_FUNCS([sysctlbyname])
63
64
65AC_CHECK_HEADERS([dlfcn.h])
66AC_CHECK_HEADERS([dlfcn.h])
67AC_CHECK_HEADERS([stdio_ext.h])
68AC_CHECK_HEADERS([tzfile.h])
69AC_CHECK_HEADERS([stdtime/tzfile.h])
70AC_CHECK_FUNCS([dlfunc])
71
72AC_CHECK_HEADERS([sys/time.h])
73AC_CHECK_HEADERS([ctype.h errno.h stdio.h stdlib.h])
74AC_CHECK_HEADERS([string.h sys/param.h unistd.h ])
75AC_CHECK_HEADERS([sys/sysctl.h])
76AC_CHECK_HEADERS([threads.h])
77AC_CHECK_HEADERS([monitor.h])
78
79dnl humanize_number(3) is a great function, but it's not standard.
80dnl Note Macosx has the function in libutil.a but doesn't ship the
81dnl header file, so I'll need to carry my own implementation.  See:
82dnl    https://devforums.apple.com/thread/271121
83AC_CHECK_HEADERS([libutil.h])
84AC_CHECK_LIB([util], [humanize_number],
85     [HAVE_HUMANIZE_NUMBER=$ac_cv_header_libutil_h],
86     [HAVE_HUMANIZE_NUMBER=no])
87
88AC_MSG_RESULT(humanize_number results: :${HAVE_HUMANIZE_NUMBER}:${ac_cv_header_libutil_h}:)
89
90if test "$HAVE_HUMANIZE_NUMBER" = "yes"; then
91    AC_DEFINE([HAVE_HUMANIZE_NUMBER], [1], [humanize_number(3)])
92fi
93
94AM_CONDITIONAL([HAVE_HUMANIZE_NUMBER], [test "$HAVE_HUMANIZE_NUMBER" = "yes"])
95
96AC_ARG_ENABLE([gettext],
97    [  --disable-gettext  Turn off support for gettext],
98    [GETTEXT_ENABLE=$enableval],
99    [GETTEXT_ENABLE=yes])
100
101dnl Looking for gettext(), assumably in libintl
102AC_ARG_WITH(gettext,
103        [  --with-gettext=[PFX]           Specify location of gettext installation],
104        [GETTEXT_PREFIX=$withval],
105	[GETTEXT_PREFIX=/usr],
106)
107
108HAVE_GETTEXT=no
109
110if test "$GETTEXT_ENABLE" != "no"; then
111
112  AC_MSG_CHECKING([gettext in ${GETTEXT_PREFIX}])
113
114  _save_cflags="$CFLAGS"
115  CFLAGS="$CFLAGS -I${GETTEXT_PREFIX}/include -L${GETTEXT_PREFIX}/lib -Werror -lintl"
116  AC_LINK_IFELSE([AC_LANG_SOURCE([[#include <libintl.h>]
117             [int main() {char *cp = dgettext(NULL, "xx"); return 0; }]])],
118             [HAVE_GETTEXT=yes],
119             [HAVE_GETTEXT=no])
120  CFLAGS="$_save_cflags"
121
122  AC_MSG_RESULT([$HAVE_GETTEXT])
123
124  if test "$HAVE_GETTEXT" != "yes"; then
125      GETTEXT_PREFIX=/opt/local
126      AC_MSG_CHECKING([gettext in ${GETTEXT_PREFIX}])
127
128      _save_cflags="$CFLAGS"
129      CFLAGS="$CFLAGS -I${GETTEXT_PREFIX}/include -L${GETTEXT_PREFIX}/lib -Werror -lintl"
130      AC_LINK_IFELSE([AC_LANG_SOURCE([[#include <libintl.h>]
131                 [int main() {char *cp = dgettext(NULL, "xx"); return 0; }]])],
132                 [HAVE_GETTEXT=yes],
133                 [HAVE_GETTEXT=no])
134      CFLAGS="$_save_cflags"
135
136      AC_MSG_RESULT([$HAVE_GETTEXT])
137  fi
138fi
139
140if test "$HAVE_GETTEXT" = "yes"; then
141    AC_DEFINE([HAVE_GETTEXT], [1], [gettext(3)])
142    GETTEXT_CFLAGS="-I${GETTEXT_PREFIX}/include"
143    GETTEXT_LIBS="-L${GETTEXT_PREFIX}/lib -lintl"
144else
145    GETTEXT_PREFIX=none
146    GETTEXT_CFLAGS=
147    GETTEXT_LIBS=
148fi
149AC_SUBST(GETTEXT_CFLAGS)
150AC_SUBST(GETTEXT_LIBS)
151
152GETTEXT_LIBDIR=${GETTEXT_PREFIX}/lib
153AC_SUBST(GETTEXT_LIBDIR)
154if test -x ${GETTEXT_PREFIX}/bin/msgfmt ; then
155    GETTEXT_BINDIR=${GETTEXT_PREFIX}/bin
156elif test -x ${GETTEXT_PREFIX}/local/bin/msgfmt ; then
157    GETTEXT_BINDIR=${GETTEXT_PREFIX}/local/bin
158else
159    AC_MSG_NOTICE("could not find msgfmt tool")
160    # Use a (bad) fall back value
161    GETTEXT_BINDIR=${GETTEXT_PREFIX}/bin
162fi
163AC_SUBST(GETTEXT_BINDIR)
164
165AM_CONDITIONAL([HAVE_GETTEXT], [test "$HAVE_GETTEXT" = "yes"])
166
167dnl Looking for how to do thread-local variables
168AC_ARG_WITH(threads,
169        [  --with-threads=[STYLE]           Specify style of thread-local support (none)],
170        [THREAD_LOCAL=$withval],
171	[THREAD_LOCAL=unknown],
172)
173
174AC_MSG_CHECKING([thread-locals are ${THREAD_LOCAL}])
175
176if test "$THREAD_LOCAL" = "unknown"; then
177     AC_LINK_IFELSE([AC_LANG_SOURCE([[]
178           [__thread int foo; int main() { foo++; return foo; }]])],
179           [THREAD_LOCAL=before],
180           [THREAD_LOCAL=unknown])
181
182    AC_MSG_RESULT([$THREAD_LOCAL])
183fi
184
185if test "$THREAD_LOCAL" = "unknown"; then
186    AC_LINK_IFELSE([AC_LANG_SOURCE([[]
187           [int __thread foo; int main() { foo++; return foo; }]])],
188           [THREAD_LOCAL=after],
189           [THREAD_LOCAL=unknown])
190    AC_MSG_RESULT([$THREAD_LOCAL])
191fi
192
193if test "$THREAD_LOCAL" = "unknown"; then
194    AC_LINK_IFELSE([AC_LANG_SOURCE([[]
195           [__declspec(int) foo; int main() { foo++; return foo; }]])],
196           [THREAD_LOCAL=declspec],
197           [THREAD_LOCAL=unknown])
198    AC_MSG_RESULT([$THREAD_LOCAL])
199fi
200
201if test "$THREAD_LOCAL" != "unknown"; then
202    AC_DEFINE_UNQUOTED([HAVE_THREAD_LOCAL],
203              THREAD_LOCAL_${THREAD_LOCAL}, [thread-local setting])
204fi
205
206dnl Looking for libcrypto....
207AC_CHECK_LIB([crypto], [MD5_Init])
208AM_CONDITIONAL([HAVE_LIBCRYPTO], [test "$HAVE_LIBCRYPTO" != "no"])
209
210AC_CHECK_MEMBER([struct sockaddr_un.sun_len],
211    [HAVE_SUN_LEN=yes ;
212        AC_DEFINE([HAVE_SUN_LEN], [1], [Have struct sockaddr_un.sun_len])],
213    [HAS_SUN_LEN=no], [[#include <sys/un.h>]])
214
215AC_CHECK_DECLS([__isthreaded], [], [], [#include <stdio.h>])
216HAVE_ISTHREADED=${ac_cv_have_decl___isthreaded}
217
218dnl
219dnl Some packages need to be checked against version numbers so we
220dnl define a function here for later use
221dnl
222AC_DEFUN([VERSION_TO_NUMBER],
223[`$1 | sed -e 's/lib.* //' | awk 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`])
224
225LIBSLAX_CONFIG_PREFIX=""
226LIBSLAX_SRC=""
227
228AC_ARG_WITH(libslax-prefix,
229        [  --with-libslax-prefix=[PFX]           Specify location of libslax config],
230        LIBSLAX_CONFIG_PREFIX=$withval
231)
232
233AC_MSG_CHECKING(for libslax)
234if test "x$LIBSLAX_CONFIG_PREFIX" != "x"
235then
236        SLAX_CONFIG=${LIBSLAX_CONFIG_PREFIX}/bin/slax-config
237else
238        SLAX_CONFIG=slax-config
239fi
240
241dnl
242dnl make sure slax-config is executable,
243dnl test version and init our variables
244dnl
245
246if ${SLAX_CONFIG} --libs > /dev/null 2>&1
247then
248	LIBSLAX_VERSION=`$SLAX_CONFIG --version`
249	SLAX_BINDIR="`$SLAX_CONFIG --bindir | head -1`"
250	SLAX_OXTRADOCDIR="`$SLAX_CONFIG --oxtradoc | head -1`"
251	AC_MSG_RESULT($LIBSLAX_VERSION found)
252	HAVE_OXTRADOC=yes
253else
254	LIBSLAX_VERSION=
255	SLAX_BINDIR=
256	SLAX_OXTRADOCDIR=
257	AC_MSG_RESULT([no])
258	HAVE_OXTRADOC=no
259fi
260AM_CONDITIONAL([HAVE_OXTRADOC], [test "$HAVE_OXTRADOC" != "no"])
261
262AC_SUBST(SLAX_BINDIR)
263AC_SUBST(SLAX_OXTRADOCDIR)
264
265AC_MSG_CHECKING([whether to build with warnings])
266AC_ARG_ENABLE([warnings],
267    [  --enable-warnings    Turn on compiler warnings],
268    [LIBXO_WARNINGS=$enableval],
269    [LIBXO_WARNINGS=no])
270AC_MSG_RESULT([$LIBXO_WARNINGS])
271AM_CONDITIONAL([LIBXO_WARNINGS_HIGH], [test "$LIBXO_WARNINGS" != "no"])
272
273AC_MSG_CHECKING([whether to build with debugging])
274AC_ARG_ENABLE([debug],
275    [  --enable-debug    Turn on debugging],
276    [LIBXO_DEBUG=yes; AC_DEFINE([LIBXO_DEBUG], [1], [Enable debugging])],
277    [LIBXO_DEBUG=no])
278AC_MSG_RESULT([$LIBXO_DEBUG])
279AM_CONDITIONAL([LIBXO_DEBUG], [test "$LIBXO_DEBUG" != "no"])
280
281AC_MSG_CHECKING([whether to build with text-only rendering])
282AC_ARG_ENABLE([text-only],
283    [  --enable-text-only    Turn on text-only rendering],
284    [LIBXO_TEXT_ONLY=yes; AC_DEFINE([LIBXO_TEXT_ONLY], [1], [Enable text-only rendering])],
285    [LIBXO_TEXT_ONLY=no])
286AC_MSG_RESULT([$LIBXO_TEXT_ONLY])
287AM_CONDITIONAL([LIBXO_TEXT_ONLY], [test "$LIBXO_TEXT_ONLY" != "no"])
288
289AC_MSG_CHECKING([whether to build with local wcwidth implementation])
290AC_ARG_ENABLE([wcwidth],
291    [  --disable-wcwidth        Disable local wcwidth implementation],
292    [LIBXO_WCWIDTH=$enableval],
293    [LIBXO_WCWIDTH=yes])
294AC_MSG_RESULT([$LIBXO_WCWIDTH])
295if test "${LIBXO_WCWIDTH}" != "no"; then
296  AC_DEFINE([LIBXO_WCWIDTH], [1], [Enable local wcwidth implementation])
297fi
298
299AC_MSG_CHECKING([retain hash bucket size])
300AC_ARG_WITH(retain-size,
301        [  --with-retain-size=[DIR]           Specify retain hash bucket size (in bits)],
302        [XO_RETAIN_SIZE=$withval],
303        [XO_RETAIN_SIZE=default]
304)
305
306AC_MSG_RESULT([$XO_RETAIN_SIZE])
307if test "${XO_RETAIN_SIZE}" != "default"; then
308  AC_DEFINE_UNQUOTED([XO_RETAIN_SIZE], ${XO_RETAIN_SIZE}, [Retain hash bucket size])
309fi
310
311AC_CHECK_LIB([m], [lrint])
312AM_CONDITIONAL([HAVE_LIBM], [test "$HAVE_LIBM" != "no"])
313
314AC_MSG_CHECKING([compiler for gcc])
315HAVE_GCC=no
316if test "${CC}" != ""; then
317    HAVE_GCC=`${CC} --version 2>&1 | grep GCC`
318    if test "${HAVE_GCC}" != ""; then
319        HAVE_GCC=yes
320    else
321        HAVE_GCC=no
322    fi
323fi
324AC_MSG_RESULT([$HAVE_GCC])
325AM_CONDITIONAL([HAVE_GCC], [test "$HAVE_GCC" = "yes"])
326
327AC_MSG_CHECKING([whether to build with printflike])
328AC_ARG_ENABLE([printflike],
329    [  --enable-printflike    Enable use of GCC __printflike attribute],
330    [HAVE_PRINTFLIKE=yes;
331           AC_DEFINE([HAVE_PRINTFLIKE], [1], [Support printflike])],
332    [HAVE_PRINTFLIKE=no])
333AC_MSG_RESULT([$HAVE_PRINTFLIKE])
334AM_CONDITIONAL([HAVE_PRINTFLIKE], [test "$HAVE_PRINTFLIKE" != ""])
335
336AC_MSG_CHECKING([whether to build with LIBXO_OPTIONS])
337AC_ARG_ENABLE([libxo-options],
338    [  --disable-libxo-options  Turn off support for LIBXO_OPTIONS],
339    [LIBXO_OPTS=$enableval],
340    [LIBXO_OPTS=yes])
341AC_MSG_RESULT([$LIBXO_OPTS])
342AM_CONDITIONAL([NO_LIBXO_OPTIONS], [test "$LIBXO_OPTS" != "yes"])
343
344case $host_os in
345     darwin*)
346        LIBTOOL=glibtool
347	XO_LIBEXT=dylib
348	;;
349     Linux*|linux*)
350        CFLAGS="-D_GNU_SOURCE $CFLAGS"
351	LDFLAGS=-ldl
352	XO_LIBEXT=so
353	;;
354     cygwin*|CYGWIN*)
355	LDFLAGS=-no-undefined
356	XO_LIBEXT=ddl
357	;;
358esac
359
360case $prefix in
361     NONE)
362	prefix=/usr/local
363	;;
364esac
365
366XO_LIBS=-lxo
367XO_SRCDIR=${srcdir}
368XO_LIBDIR=${libdir}
369XO_BINDIR=${bindir}
370XO_INCLUDEDIR=${includedir}
371XO_CFLAGS="${CFLAGS}"
372
373AC_SUBST(XO_LIBS)
374AC_SUBST(XO_SRCDIR)
375AC_SUBST(XO_LIBDIR)
376AC_SUBST(XO_BINDIR)
377AC_SUBST(XO_INCLUDEDIR)
378AC_SUBST(XO_LIBEXT)
379AC_SUBST(XO_CFLAGS)
380
381AC_ARG_WITH(encoder-dir,
382        [  --with-encoder-dir=[DIR]           Specify location of encoder libraries],
383        [XO_ENCODERDIR=$withval],
384        [XO_ENCODERDIR=$libdir/libxo/encoder]
385)
386AC_SUBST(XO_ENCODERDIR)
387
388AC_ARG_WITH(share-dir,
389        [  --with-share-dir=[DIR]           Specify location of shared files],
390        [XO_SHAREDIR=$withval],
391        [XO_SHAREDIR=$datarootdir/libxo]
392)
393XO_SHAREDIR=`echo $XO_SHAREDIR | sed "s;\\${prefix};$prefix;"`
394AC_SUBST(XO_SHAREDIR)
395
396dnl for the spec file
397RELDATE=`date +'%Y-%m-%d%n'`
398AC_SUBST(RELDATE)
399
400AC_MSG_RESULT(Using configure dir $ac_abs_confdir)
401
402if test -d $ac_abs_confdir/.git ; then
403  extra=`git branch | awk '/\*/ { print $2 }'`
404  if test "$extra" != "" -a "$extra" != "master"
405  then
406      LIBXO_VERSION_EXTRA="-git-$extra"
407  fi
408fi
409
410LIBXO_VERSION=$PACKAGE_VERSION
411LIBXO_VERSION_NUMBER=VERSION_TO_NUMBER(echo $PACKAGE_VERSION)
412AC_SUBST(LIBXO_VERSION)
413AC_SUBST(LIBXO_VERSION_NUMBER)
414AC_SUBST(LIBXO_VERSION_EXTRA)
415
416AC_DEFINE_UNQUOTED(LIBXO_VERSION, ["$LIBXO_VERSION"],
417    [Version number as dotted value])
418AC_DEFINE_UNQUOTED(LIBXO_VERSION_NUMBER, [$LIBXO_VERSION_NUMBER],
419    [Version number as a number])
420AC_DEFINE_UNQUOTED(LIBXO_VERSION_STRING, ["$LIBXO_VERSION_NUMBER"],
421    [Version number as string])
422AC_DEFINE_UNQUOTED(LIBXO_VERSION_EXTRA, ["$LIBXO_VERSION_EXTRA"],
423    [Version number extra information])
424
425AC_CONFIG_HEADERS([libxo/xo_config.h])
426AC_CONFIG_FILES([
427  Makefile
428  libxo-config
429  xohtml/xohtml.sh
430  libxo/Makefile
431  libxo/add.man
432  encoder/Makefile
433  encoder/cbor/Makefile
434  encoder/test/Makefile
435  xo/Makefile
436  xolint/Makefile
437  xohtml/Makefile
438  xopo/Makefile
439  packaging/libxo.pc
440  doc/Makefile
441  tests/Makefile
442  tests/core/Makefile
443  tests/gettext/Makefile
444  tests/xo/Makefile
445  packaging/libxo.spec
446  packaging/libxo.rb.base
447])
448AC_OUTPUT
449
450AC_MSG_NOTICE([summary of build options:
451
452  libxo version:    ${VERSION} ${LIBXO_VERSION_EXTRA}
453  host type:        ${host} / ${host_os}
454  install prefix:   ${prefix}
455  srcdir:           ${XO_SRCDIR}
456  libdir:           ${XO_LIBDIR}
457  bindir:           ${XO_BINDIR}
458  includedir:       ${XO_INCLUDEDIR}
459  share dir:        ${XO_SHAREDIR}
460  extensions dir:   ${XO_ENCODERDIR}
461  oxtradoc dir:     ${SLAX_OXTRADOCDIR}
462
463  compiler:         ${CC} (${HAVE_GCC:-no})
464  compiler flags:   ${CFLAGS}
465  library types:    Shared=${enable_shared}, Static=${enable_static}
466
467  warnings:         ${LIBXO_WARNINGS:-no}
468  debug:            ${LIBXO_DEBUG:-no}
469  printf-like:      ${HAVE_PRINTFLIKE:-no}
470  libxo-options:    ${LIBXO_OPTS:-no}
471  text-only:        ${LIBXO_TEXT_ONLY:-no}
472  gettext:          ${HAVE_GETTEXT:-no} (${GETTEXT_PREFIX})
473  isthreaded:       ${HAVE_ISTHREADED:-no}
474  thread-local:     ${THREAD_LOCAL:-no}
475  local wcwidth:    ${LIBXO_WCWIDTH:-no}
476  retain size:      ${XO_RETAIN_SIZE:-no}
477])
478