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