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