1dnl configure.ac
2
3dnl Copyright (C) 2010, 2014-2015, 2018-2021 Free Software Foundation, Inc.
4dnl
5dnl This program is free software, licensed under the terms of the GNU
6dnl General Public License as published by the Free Software Foundation,
7dnl either version 3 of the License, or (at your option) any later version.
8dnl You should have received a copy of the GNU General Public License
9dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
10
11AC_PREREQ([2.61])
12AC_INIT([LibreDWG],
13        m4_esyscmd([build-aux/git-version-gen .tarball-version]),
14        [libredwg@gnu.org],,
15        [https://savannah.gnu.org/projects/libredwg/])
16AC_CONFIG_AUX_DIR([build-aux])
17dnl for older systems use this:
18dnl AM_INIT_AUTOMAKE([1.11.6 gnu no-define])
19dnl parallel-tests:
20dnl: error: using '$(srcdir)' in TESTS is currently broken: '$(srcdir)/libredwg.spec'
21dnl info-in-builddir might be an option for GH #211
22AM_INIT_AUTOMAKE([1.14 gnu no-define serial-tests dist-xz info-in-builddir])
23
24# Keep this in sync with what is passed in AC_INIT
25TARBALL_VERSION_FILE=".tarball-version"
26dnl Define these substitutions here to keep all version information in
27dnl one place. For information on how to properly maintain the library
28dnl version information, refer to the libtool manual, section "Updating
29dnl library version information":
30dnl http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
31AC_SUBST([LIBREDWG_SO_VERSION], [0:12:0])
32AC_SUBST([TARBALL_VERSION_FILE])
33
34AC_CONFIG_MACRO_DIR([m4])
35
36# Check if automake supports 'pretty' builds, if so enable them by default
37m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
38
39dnl create a config.h file (Automake will add -DHAVE_CONFIG_H)
40AM_CONFIG_HEADER([src/config.h])
41AC_MSG_CHECKING([git version])
42AC_MSG_RESULT($PACKAGE_VERSION)
43AC_MSG_CHECKING([so version-info])
44AC_MSG_RESULT($LIBREDWG_SO_VERSION)
45
46ISODATE=`date +%Y-%m-%d`
47AC_SUBST(ISODATE)
48
49AC_CANONICAL_HOST
50
51dnl Checks for programs
52PKG_PROG_PKG_CONFIG
53AC_PROG_CC
54AC_PROG_LN_S
55AC_PROG_MAKE_SET
56AC_PROG_INSTALL
57AC_PROG_LIBTOOL
58dnl AC_PROG_RANLIB: in LT_INIT
59LT_INIT
60AC_CHECK_PROGS([BASH], [bash])
61
62if test x$enable_shared = xyes; then
63   AC_DEFINE([ENABLE_SHARED],1,[Define to 1 if a shared library will be built])
64   LTEXEC="\${top_builddir}/libtool --mode=execute"
65fi
66AM_CONDITIONAL([ENABLE_SHARED], [test "x$enable_shared" = xyes])
67AC_SUBST(LTEXEC)
68
69AC_C_INLINE
70AC_C_RESTRICT
71
72dnl Checks for libraries
73AC_CHECK_LIB([ps],[PS_open_file],
74  libredwg_have_libps=yes,
75  libredwg_have_libps=no)
76
77dnl `pcre2-config --libs8`
78AC_CHECK_LIB([pcre2-8],[pcre2_config_8],
79  [libredwg_have_libpcre2=yes; PCRE2_LIBS=-lpcre2-8],
80  [if pkg-config --exists libpcre2; then
81    libredwg_have_libpcre2=yes;
82    PCRE2_CFLAGS=`pkg-config libpcre2 --cflags`
83    PCRE2_LIBS=`pkg-config libpcre2 --libs`
84  else
85    AC_MSG_WARN([libpcre2 for dwggrep not found])
86  fi])
87AC_CHECK_LIB([pcre2-16],[pcre2_config_16],
88  [libredwg_have_libpcre2_16=yes])
89if test yes = "$libredwg_have_libpcre2_16"; then
90  AC_DEFINE([HAVE_PCRE2_16],1,[Define to 1 if -lpcre2-16 is used also])
91  PCRE2_LIBS="$PCRE2_LIBS -lpcre2-16"
92fi
93AC_SUBST([PCRE2_CFLAGS])
94AC_SUBST([PCRE2_LIBS])
95
96dnl PKG_CHECK_MODULES([LIBXML2], [libxml-2.0], [],
97dnl    AC_MSG_ERROR([Install libxml-2.0 first]))
98AC_CHECK_LIB([xml2],[newXMLEntity],
99  [have_libxml2=yes;
100   XML2_LIBS=-lxml2;
101   AC_SUBST([XML2_CFLAGS])
102   AC_SUBST([XML2_LIBS])
103   ],
104  [if pkg-config --exists libpcre2; then
105    have_libxml2=yes;
106    XML2_CFLAGS=`pkg-config libxml-2.0 --cflags`
107    XML2_LIBS=`pkg-config libxml-2.0 --libs`
108  else
109    AC_MSG_WARN([libxml-2.0 for test/xmlsuite not found])
110  fi])
111AM_CONDITIONAL([HAVE_LIBXML2], [test x$have_libxml2 = xyes])
112
113dnl Checks for header files
114AC_HEADER_STDC
115dnl Avoid rpl_malloc when cross-compiling. we don't need malloc.h
116dnl We just want to know if it's needed
117ac_cv_func_malloc_0_nonnull=yes
118ac_cv_func_realloc_0_nonnull=yes
119AC_CHECK_HEADERS([stdlib.h string.h stddef.h unistd.h malloc.h wchar.h ctype.h \
120                  float.h limits.h \
121                  libgen.h getopt.h alloca.h valgrind/valgrind.h])
122AC_CHECK_HEADER_STDBOOL
123AX_INCLUDE_STRCASECMP
124
125# Don't bother testing for libps headers if libps is not available.
126if test yes = "$libredwg_have_libps" ; then
127  AC_CHECK_HEADERS([libps/pslib.h])
128fi
129AM_CONDITIONAL([HAVE_LIBPS],[test "x$libredwg_have_libps" = xyes &&
130                             test "x$ac_cv_header_libps_pslib_h" = xyes])
131
132if test yes = "$libredwg_have_libpcre2"; then
133  AC_CHECK_HEADERS([pcre2.h],[],[],[#define PCRE2_CODE_UNIT_WIDTH 8])
134else
135  AC_MSG_WARN([Couldn't find pcre2.h. No regex support in dwggrep])
136fi
137
138dnl Checks for typedefs, structures, and compiler characteristics
139AC_PROG_CC_C99
140case $CFLAGS in
141     *-fsanitize=undefined*)   ax_cv_have_aligned_access_required=yes  ;;
142     *-fsanitize=*,undefined*) ax_cv_have_aligned_access_required=yes  ;;
143esac
144case $CC in
145     *-fsanitize=undefined*)   ax_cv_have_aligned_access_required=yes  ;;
146     *-fsanitize=*,undefined*) ax_cv_have_aligned_access_required=yes  ;;
147esac
148AX_CHECK_ALIGNED_ACCESS_REQUIRED
149
150case $CC in
151     *-fsanitize=address*)     HAVE_ASAN=yes ;;
152     *-fsanitize=*,address*)   HAVE_ASAN=yes ;;
153esac
154case $CC in
155     *-fsanitize=leak*)        HAVE_ASAN=yes ;;
156     *-fsanitize=*,leak*)      HAVE_ASAN=yes ;;
157esac
158case $CFLAGS in
159     *-fsanitize=address*)     HAVE_ASAN=yes ;;
160     *-fsanitize=*,address*)   HAVE_ASAN=yes ;;
161esac
162case $CFLAGS in
163     *-fsanitize=leak*)        HAVE_ASAN=yes ;;
164     *-fsanitize=*,leak*)      HAVE_ASAN=yes ;;
165esac
166AC_SUBST(HAVE_ASAN)
167
168AC_TYPE_SIZE_T
169AC_TYPE_INT16_T
170AC_TYPE_UINT16_T
171AC_TYPE_INT32_T
172AC_TYPE_UINT32_T
173AC_TYPE_INT64_T
174AC_TYPE_UINT64_T
175AC_CHECK_SIZEOF([size_t])
176dnl AC_CHECK_TYPE([wchar_t],[],[],[[#include <wchar.h>]])
177if test x$ac_cv_header_wchar_h = xyes; then
178   AX_COMPILE_CHECK_SIZEOF([wchar_t], [#include <wchar.h>])
179fi
180dnl AX_GCC_BUILTIN(__builtin_offsetof)
181AC_DEFINE([_POSIX_C_SOURCE],[200809L],[Needed for strdup])
182AC_DEFINE([__XSI_VISIBLE],[700],[Needed for cygwin strdup])
183
184AX_IS_RELEASE([git-directory])
185dnl ability to override with a .git dir, to test release features
186AC_ARG_ENABLE([release],AS_HELP_STRING([--enable-release],[
187    Override IS_RELEASE with .git dir present (default: $ax_is_release).]),
188    [ax_is_release=yes
189    AC_MSG_RESULT(IS_RELEASE override with --enable-release)])
190if test x$ax_is_release = xyes; then
191   AC_DEFINE([IS_RELEASE],1,[Define to 1 if this is a release,
192   skipping unstable DWG features, unknown DWG versions and objects.])
193fi
194AM_CONDITIONAL([IS_RELEASE], [test x$ax_is_release = xyes])
195
196dnl Disable unwanted warnings here
197enable_Werror=no
198ax_enable_compile_warnings=yes
199dnl This is too intrusive for our DWG_TYPE_* switches
200ax_cv_check_cflags__Wswitch_enum=no
201if test x$enable_shared = xyes -a x$ac_compiler_gnu = xyes; then
202  AX_COMPILER_FLAGS([WARN_CFLAGS],[AM_LDFLAGS],[$ax_is_release],
203    [-fno-common -fvisibility=hidden -fno-semantic-interposition])
204else
205  AX_COMPILER_FLAGS([WARN_CFLAGS],[AM_LDFLAGS],[$ax_is_release],
206    [-fno-common -fvisibility=hidden])
207fi
208dnl if test x$ax_cv_check_cflags__Wunused_but_set_variable = xyes; then
209dnl   WARN_CFLAGS="$WARN_CFLAGS -Wno-unused-but-set-variable"
210dnl fi
211dnl if test x$ax_cv_check_cflags__Wunused_variable = xyes; then
212dnl   WARN_CFLAGS="$WARN_CFLAGS -Wno-unused-variable"
213dnl fi
214
215AC_CACHE_CHECK([for __attribute__((visibility("default")))],
216  ac_cv_attribute_visibility_default, [
217  ac_cv_attribute_visibility_default=no
218  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
219    [[ int __attribute__ ((visibility ("default"))) foo (void) { return 1; } ]], [])],
220    [ac_cv_attribute_visibility_default=yes])
221  ])
222if test x$ac_cv_attribute_visibility_default = xyes;
223then
224  AC_DEFINE(HAVE_ATTRIBUTE_VISIBILITY_DEFAULT, 1,
225    [Define if __attribute__((visibility("default"))) is supported.])
226fi
227dnl AX_GCC_FUNC_ATTRIBUTE(visibility)
228AX_GCC_FUNC_ATTRIBUTE(gnu_format)
229AX_GCC_FUNC_ATTRIBUTE(ms_format)
230AX_GCC_FUNC_ATTRIBUTE(format)
231AX_GCC_FUNC_ATTRIBUTE(malloc)
232AX_GCC_FUNC_ATTRIBUTE(returns_nonnull)
233AX_GCC_FUNC_ATTRIBUTE(noreturn)
234
235dnl until we can make a release, favor no -O2 optims.
236dnl it's fast enough and better for debugging.
237dnl if test x$ac_compiler_gnu = xyes; then
238dnl   CFLAGS="$CFLAGS -fno-omit-frame-pointer"
239dnl fi
240
241if test "x$ac_cv_prog_cc_c99" = "xno"; then
242   AC_MSG_WARN([This compiler ${CC} has no c99 support])
243else
244   AC_DEFINE([HAVE_C99], 1,
245        [Defined to 1 when the compiler supports c99, mostly (...) macros])
246   if test "x$ac_cv_prog_cc_c99" != "x"; then
247      AC_MSG_RESULT([added $ac_cv_prog_cc_c99 to CFLAGS])
248      CFLAGS="$CFLAGS $ac_cv_prog_cc_c99"
249   fi
250fi
251AC_SUBST(HAVE_C99)
252
253dnl Checks for library functions
254AC_FUNC_MALLOC
255AC_FUNC_REALLOC
256AC_FUNC_STAT
257AC_FUNC_ALLOCA
258dnl broken for cross-compiling
259dnl AC_FUNC_STRTOD
260AC_CHECK_FUNC([strtod],[],
261  AC_MSG_ERROR([C89 strtod not found. Ignore for now]))
262AC_CHECK_FUNC([strdup],[],
263  AC_MSG_ERROR([strdup not found. Check your _POSIX_C_SOURCE vs ANSI settings.]))
264AC_CHECK_FUNCS([getopt_long],[],
265  AC_MSG_WARN([getopt_long not found. programs will not accept long options.]))
266AC_CHECK_FUNCS([basename],[],
267  AC_MSG_WARN([basename not found. The default outfile will be unexpected.]))
268AC_CHECK_FUNCS([strcasestr],[],
269  AC_MSG_WARN([strcasestr not found. Using a slower workaround.]))
270AC_CHECK_FUNCS([scandir],[],
271  AC_MSG_WARN([BSD/POSIX scandir not found. No helper unit_testing_all.sh]))
272AC_CHECK_FUNCS([floor sqrt])
273AC_CHECK_LIB([m],[floor])
274AC_CHECK_LIB([m],[sqrt])
275AC_CHECK_FUNCS([sincos])
276AC_CHECK_FUNCS([memchr memmove strcasecmp strchr strstr strrchr strtol strtoul strtoull strnlen])
277AC_CHECK_FUNCS([memmem],[],
278  AC_MSG_WARN([memmem not found. Using a slower workaround.]))
279AC_CHECK_FUNCS([wcslen wcsnlen wcscpy wcscmp wcsstr])
280dnl try the secure extensions
281$as_echo '#define __STDC_WANT_LIB_EXT1__  1' >>confdefs.h
282AC_CHECK_FUNCS([sscanf_s],[],
283  AC_MSG_WARN([No secure sscanf_s found. dwgfuzz -add will produce false positives.]))
284dnl and undo it
285$GREP -v '__STDC_WANT_LIB_EXT1__' confdefs.h > confdefs.h.tmp
286mv confdefs.h.tmp confdefs.h
287
288dnl mingw-w64 7.0 bug with _FORTIFY_SOURCE, need -lssp
289case $host in
290 *-w64-mingw32)
291   case $CFLAGS in
292     *-fstack-protector*) ;;
293     *) CFLAGS="$CFLAGS -fstack-protector" ;;
294   esac
295   ;;
296esac
297dnl x86_64-mingw-w64-gcc-9.2 is seriously broken, and not just mingw-w64
298
299dnl --enable-debug sets DEBUG_CLASSES, will crash acad import
300AC_MSG_CHECKING([--enable-debug])
301AC_ARG_ENABLE([debug],AS_HELP_STRING([--enable-debug],[
302    Enable unstable DEBUG_CLASSES (default: no).]),
303  [if test x$ac_compiler_gnu = xyes; then
304    CFLAGS="`echo $CFLAGS|sed 's,-O2,,'` -fno-omit-frame-pointer"
305  fi
306  CFLAGS="$CFLAGS -DDEBUG_CLASSES"]
307  AC_MSG_RESULT([yes]),
308  AC_MSG_RESULT([no (default)]))
309AM_CONDITIONAL([ENABLE_DEBUG], [test x$enable_debug = xyes])
310
311AX_ADD_FORTIFY_SOURCE
312AX_RESTRICT
313
314dnl Feature: --disable-write
315AC_MSG_CHECKING([--disable-write])
316AC_ARG_ENABLE([write],AS_HELP_STRING([--disable-write],[
317    Disable write support (default: no).]),[],[enable_write=yes])
318AM_CONDITIONAL([USE_WRITE], [test x$enable_write != xno])
319AS_IF([test x$enable_write != xno],
320  [AC_DEFINE([USE_WRITE],1,[Undefine to disable write support.])
321   AC_SUBST(DISABLE_WRITE, 0)
322   AC_MSG_RESULT([no (default)])],
323  [AC_SUBST(DISABLE_WRITE, 1)
324   AC_MSG_RESULT([yes])])
325
326dnl Feature: --enable-trace
327AC_MSG_CHECKING([--enable-trace])
328AC_ARG_ENABLE([trace],AS_HELP_STRING([--enable-trace],[
329    Enable runtime tracing (default: no).  When enabled, the environment
330    variable LIBREDWG_TRACE is consulted on the first decode/encode attempt.
331    Its value is an integer: 0 (no output) through 9 (full verbosity).]),
332  AC_DEFINE([USE_TRACING],1,[Define to 1 to enable runtime tracing support.])
333  AC_MSG_RESULT([yes]),
334  AC_MSG_RESULT([no (default)]))
335
336AC_CHECK_FUNCS([setenv],[],
337  AS_IF([test x$enable_trace = xyes],
338    [AC_MSG_WARN([setenv not found. --enable-trace is limited with cmdline apps.
339      Only -v args are taken for verbosity not the LIBREDWG_TRACE env var.])],
340    [AC_MSG_RESULT([setenv not needed. no --enable-trace.])]
341    ))
342
343dnl --disable-dxf only useful for faster debug/test cycles
344AC_MSG_CHECKING([--disable-dxf])
345AC_ARG_ENABLE([dxf],AS_HELP_STRING([--disable-dxf],[
346    Disable DXF, JSON and other in/out modules (default: no).]),[],[enable_dxf=yes])
347AM_CONDITIONAL([DISABLE_DXF], [test x$enable_dxf = xno])
348AS_IF([test x$enable_dxf = xno],
349  AC_DEFINE([DISABLE_DXF],1,[Define to disable DXF, JSON and other in/out modules.])
350  AC_MSG_RESULT([yes]),
351  AC_MSG_RESULT([no (default)]))
352
353dnl --disable-json only useful for slim libraries (i.e. SolveSpace)
354AC_MSG_CHECKING([--disable-json])
355AC_ARG_ENABLE([json],AS_HELP_STRING([--disable-json],[
356    Disable JSON and GeoJSON in/out modules (default: no).]),[],[enable_json=yes])
357AM_CONDITIONAL([DISABLE_JSON], [test x$enable_json = xno])
358AS_IF([test x$enable_json = xno],
359  AC_DEFINE([DISABLE_JSON],1,[Define to disable JSON and GeoJSON in/out modules.])
360  AC_SUBST(DISABLE_JSON, 1)
361  AC_MSG_RESULT([yes]),
362  AC_MSG_RESULT([no (default)]))
363
364dnl --disable-bindings
365AC_MSG_CHECKING([--disable-bindings])
366AC_ARG_ENABLE([bindings],AS_HELP_STRING([--disable-bindings],[
367    Disable SWIG bindings (default: no).]),[],[enable_bindings=yes])
368AM_CONDITIONAL([DISABLE_BINDINGS], [test x$enable_bindings = xno])
369AS_IF([test x$enable_bindings = xno],
370  AC_DEFINE([DISABLE_BINDINGS],1,[Define to disable bindings.])
371  AC_MSG_RESULT([yes]),
372  AC_MSG_RESULT([no (default)]))
373
374AC_MSG_CHECKING([for --enable-gcov])
375AC_ARG_ENABLE(gcov,
376	AS_HELP_STRING([--enable-gcov],
377		       [turn on test coverage @<:@default=no@:>@]),
378	[case "${enableval}" in
379	yes) enable_gcov=true ; gcov=gcov ;;
380	no)  enable_gcov=false ;;
381	*)   enable_gcov=true ; gcov="${enableval}" ;;
382	esac], [enable_gcov=false ])
383if test "x$enable_gcov" = "xtrue" ; then
384	dnl if test "$GCC" = yes; then
385	dnl 	AC_MSG_ERROR([gcov only works if gcc is used])
386	dnl fi
387
388        dnl You might need the compiler-specific gcov: e.g. gcov-mp-6
389	GCOV="$gcov"
390	AC_MSG_RESULT([gcov=$gcov])
391	AC_SUBST(GCOV)
392
393	GCOV_CFLAGS="-fprofile-arcs -ftest-coverage"
394	AC_SUBST(GCOV_CFLAGS)
395
396	dnl libtool 1.5.22 and lower strip -fprofile-arcs from the flags
397	dnl passed to the linker, which is a bug; -fprofile-arcs implicitly
398	dnl links in -lgcov, so we do it explicitly here for the same effect
399	GCOV_LIBS=-lgcov
400	AC_SUBST(GCOV_LIBS)
401else
402	AC_MSG_RESULT([no (default)])
403fi
404AM_CONDITIONAL(ENABLE_GCOV, test "x$enable_gcov" = "xtrue")
405
406AC_CHECK_PROGS([GPERF], [gperf])
407if test -n "$GPERF"
408then
409    AC_MSG_CHECKING([GPERF version])
410    [GPERF_VERSION=`"$GPERF" --version | head -n1 2>&1 | sed 's,GNU gperf ,,'`]
411    case $GPERF_VERSION in
412      1.*) GPERF_VERSION=$((100+${GPERF_VERSION:2:1})) ;;
413      2.*) GPERF_VERSION=$((200+${GPERF_VERSION:2:1})) ;;
414      3.*) GPERF_VERSION=$((300+${GPERF_VERSION:2:1})) ;;
415      4.*) GPERF_VERSION=$((400+${GPERF_VERSION:2:1})) ;;
416    esac
417    AC_MSG_RESULT([$GPERF_VERSION])
418    AC_DEFINE_UNQUOTED([GPERF_VERSION],[$GPERF_VERSION],
419       [versions earlier than 301 will have no size_t])
420fi
421AC_SUBST(GPERF)
422AC_SUBST(GPERF_VERSION)
423AM_CONDITIONAL(HAVE_GPERF, test -n "$GPERF")
424
425AC_MSG_CHECKING([for latest clang-format])
426CLANG_FORMAT=
427for clangfmt in clang-format{-mp,}{-devel,-{8,7,6,5,4,3}{,.9,.8,.7,.6,.5,.4,.3,.2,.1,.0},}
428do
429    if which "$clangfmt" &>/dev/null; then
430        CLANG_FORMAT="$clangfmt"
431        break
432    fi
433done
434if test -z $CLANG_FORMAT; then
435    if which indent &>/dev/null; then
436        CLANG_FORMAT="indent"
437    else
438        CLANG_FORMAT=echo
439    fi
440fi
441AC_MSG_RESULT($CLANG_FORMAT)
442AC_SUBST(CLANG_FORMAT)
443
444dnl Check for mingw, cross and wine
445AM_CONDITIONAL([HAVE_MINGW], [test "x$host_os" = "xmingw32"])
446AM_CONDITIONAL([HAVE_MINGW_CROSS],
447        [test "x$host_os" = "xmingw32" -a "x$build_os" != "xmingw32"])
448if test "x$host_os" = "xmingw32" -a "x$build_os" != "xmingw32"; then
449   cross_compiling=yes
450   AC_CHECK_PROGS([WINE], [wine])
451   if test -z "$WINE"; then
452      AC_MSG_WARN([wine not found - cannot check cross-compiled executables])
453   else
454      AC_MSG_RESULT([wine found - test with make check-wine])
455      CFLAGS="$CFLAGS -D_WINE_MSVCRT"
456   fi
457fi
458AM_CONDITIONAL([HAVE_WINE], [test -n "$WINE"])
459
460dnl Optional SWIG + python bindings
461dnl Feature: --disable-python or --enable-python=python3.6
462AC_MSG_CHECKING([for --disable-python])
463AC_ARG_ENABLE(python,
464	AS_HELP_STRING([--disable-python],
465		       [Disable python bindings and tests @<:@default=check@:>@]),
466	[case "${enableval}" in
467	yes) enable_python=yes; AC_MSG_RESULT([enabled]) ;;
468	no)  enable_python=no; AC_MSG_RESULT([disabled]) ;;
469	*)   enable_python=yes; PYTHON="${enableval}"; AC_MSG_RESULT([enabled ($PYTHON)]) ;;
470	esac], [enable_python=check; AC_MSG_RESULT([check (default)]) ])
471
472if test x$cross_compiling = xno -a x$enable_bindings = xyes; then
473    AX_PKG_SWIG([1.3.17], [],
474      AC_MSG_WARN([SWIG is required for python bindings. disabled]))
475    if test -n "$SWIG" -a x$enable_python != xno; then
476      dnl ls -al /usr/bin/python* >&6
477      if test x$enable_python = xyes; then
478        dnl die on error
479        AM_PATH_PYTHON([2.7])
480      else
481        dnl skip on error
482        AM_PATH_PYTHON
483        PYTHON_NOVERSIONCHECK=1
484      fi
485      SWIG_PYTHON
486      AC_CHECK_PROGS([PATCH], [patch])
487    fi
488    dnl swig not required for perl, we ship swig_perl.c
489    dnl AX_SWIG_ENABLE_CXX
490    dnl SWIG_MULTI_MODULE_SUPPORT
491else
492    AC_MSG_WARN([disabled swig bindings])
493    if test x$enable_python != xno; then
494      if test x$enable_python = xyes; then
495        dnl die on error
496        AM_PATH_PYTHON([2.7])
497      else
498        dnl skip on error
499        AM_PATH_PYTHON
500        PYTHON_NOVERSIONCHECK=1
501      fi
502    fi
503fi
504
505if test x$enable_python != xno && test -n "$XML2_LIBS"; then
506  AC_MSG_CHECKING([for the libxml2 Python package])
507  ac_python_libxml2_result=`$PYTHON -c "import libxml2" 2>&1`
508  if test $? -eq 0; then
509    ac_have_python_libxml2=1
510    AC_MSG_RESULT([yes])
511  else
512    ac_have_python_libxml2=
513    AC_MSG_RESULT([no])
514    AC_MSG_WARN([disable test/xmlsuite.
515The import error was:
516$ac_python_libxml2_result])
517  fi
518fi
519AM_CONDITIONAL([HAVE_PYTHON_LIBXML2], [test x$ac_have_python_libxml2 = x1])
520
521if test -n "$PERL"; then
522  ac_cv_perl="$PERL"
523  AC_CACHE_VAL([ac_cv_perl],$PERL)
524else
525  ac_cv_perl=perl
526fi
527AC_PATH_PROG([PERL], [$ac_cv_perl])
528if test -n "$PERL"; then
529  AC_MSG_CHECKING([PERL version])
530  [PERL_VERSION=`"$PERL" -e'print $^V' 2>&1`]
531  AC_MSG_RESULT([$PERL_VERSION])
532  AM_RUN_LOG([$PERL -V:cc])
533
534  dnl --enable-perl-install=vendor. default: site
535  AS_IF([test x$enable_bindings = xyes],
536    [AC_MSG_CHECKING([for --with-perl-install=])
537     AC_ARG_WITH(perl-install,
538	AS_HELP_STRING([--with-perl-install=],
539          [Where to install the perl bindings, vendor,arch,yes,no or @<:@default=site@:>@]),
540	[case "${with_perl_install}" in
541	 vendor)   with_perl_install=vendor; AC_MSG_RESULT([vendor]) ;;
542	 yes|site) with_perl_install=site;   AC_MSG_RESULT([site]) ;;
543	 perl)     with_perl_install=perl;   AC_MSG_RESULT([perl]) ;;
544	 no)       with_perl_install=no;     AC_MSG_RESULT([no]) ;;
545	 *)        AC_MSG_RESULT([invalid ${with_perl_install}: vendor,site,yes,perl,no]) ;;
546	 esac],
547        [with_perl_install=site; AC_MSG_RESULT([site (default)]) ])
548    ]
549  )
550fi
551AC_SUBST([with_perl_install])
552
553AM_CONDITIONAL([HAVE_SWIG_PYTHON], [test -n "$SWIG" && test -n "$PYTHON_VERSION"])
554AM_CONDITIONAL([HAVE_PYTHON], [test x$enable_python != xno])
555AM_CONDITIONAL([HAVE_SWIG_PERL], [test -n "$SWIG" && test -n "$PERL_VERSION"])
556AM_CONDITIONAL([HAVE_PERL], [test -n "$PERL"])
557dnl only needed with python bindings
558AM_CONDITIONAL([HAVE_PATCH], [test -n "$PATCH"])
559dnl AC_MSG_WARN([srcdir: $srcdir ac_builddir: $ac_builddir builddir: $builddir])
560AM_CONDITIONAL([HAVE_INSRCDIR], [test x"$srcdir" = x"."])
561
562AC_CHECK_PROGS([PICAT], [picat])
563if test -n "$PICAT"; then
564  AC_MSG_CHECKING([PICAT version])
565  [picat_version=`"$PICAT" --version 2>&1 | grep 'Picat version' | cut -c15-`]
566  AC_MSG_RESULT([$picat_version])
567fi
568AM_CONDITIONAL([HAVE_PICAT], [test -n "$PICAT"])
569
570dnl GNU parallel, skip the old non-perl version from moreutils so far
571AC_CHECK_PROGS([PARALLEL], [parallel])
572logs_all=logs-all-serial.sh.in
573if test -n "$PARALLEL"; then
574  AC_MSG_CHECKING([PARALLEL version])
575  parallel_version=`"$PARALLEL" --version 2>&1 | head -n1 | cut -c14-`
576  case $parallel_version in
577    20* )   logs_all=logs-all-parallel.sh.in
578            ;;
579    *invalid* )
580            PARALLEL=
581            parallel_version="skip old moreutils version, need GNU parallel"
582            #TODO
583            #logs_all=logs-all-parallel-old.sh.in
584  esac
585  AC_MSG_RESULT([$parallel_version])
586fi
587AM_CONDITIONAL([HAVE_PARALLEL], [test -n "$PARALLEL"])
588
589dnl coreutils timeout
590AC_CHECK_PROGS([TIMEOUT], [timeout])
591if test -n "$TIMEOUT"; then
592  AC_MSG_CHECKING([TIMEOUT version])
593  [timeout_version=`"$TIMEOUT" --version 2>&1 | grep '^timeout ' | sed 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/g'`]
594  AC_MSG_RESULT([$timeout_version])
595  TIMEOUT_10="$TIMEOUT 10"
596  TIMEOUT_30="$TIMEOUT 30"
597fi
598AM_CONDITIONAL([HAVE_TIMEOUT], [test -n "$TIMEOUT"])
599AC_SUBST([TIMEOUT_10])
600AC_SUBST([TIMEOUT_30])
601
602dnl build-aux/missing catches an outdated /usr/bin/makeinfo 4.8 on darwin 10.11
603dnl the texi2any version >6 is needed for @indentedblock
604case $host_os in
605  darwin*)
606    if test -f /opt/local/bin/makeinfo ; then
607      MAKEINFO=/opt/local/bin/makeinfo
608    else
609      AC_CHECK_PROGS([MAKEINFO], [makeinfo])
610    fi
611    ;;
612  *) AC_CHECK_PROGS([MAKEINFO], [makeinfo])
613    ;;
614esac
615if test -n "$MAKEINFO"; then
616  AC_MSG_CHECKING([MAKEINFO version])
617  dnl either old makeinfo or new texi2any (preferred)
618  [makeinfo_version=`"$MAKEINFO" --version 2>&1 | $GREP 'texinfo' | cut -d' ' -f4`]
619  AC_SUBST([makeinfo_version])
620  AC_MSG_RESULT([$makeinfo_version])
621fi
622AM_CONDITIONAL([HAVE_MAKEINFO], [test -n "$MAKEINFO"])
623
624if test x$enable_debug = xyes; then
625   JSON_SED_NAN="\$SED -i -e's/ nan/ \"nan\"/g;'"
626else
627   JSON_SED_NAN="true"
628fi
629AC_SUBST([JSON_SED_NAN])
630
631AC_CHECK_PROGS([DOXYGEN], [doxygen])
632if test -n "$DOXYGEN"; then
633  AC_MSG_CHECKING([DOXYGEN version])
634  [doxygen_version=`"$DOXYGEN" --version 2>&1`]
635  AC_MSG_RESULT([$doxygen_version])
636fi
637AM_CONDITIONAL([HAVE_DOXYGEN], [test -n "$DOXYGEN"])
638
639AC_CHECK_PROGS([JQ], [jq])
640if test -n "$JQ"; then
641  AC_MSG_CHECKING([JQ version])
642  [jq_version=`"$JQ" --version 2>&1 | grep 'jq-' | cut -c4-`]
643  AC_MSG_RESULT([$jq_version])
644fi
645AM_CONDITIONAL([HAVE_JQ], [test -n "$JQ"])
646
647case $host_os in
648  darwin*)  DSYMUTIL=dsymutil ;;
649  mingw*)   DSYMUTIL=rem ;;
650  windows*) DSYMUTIL=rem ;;
651  *) DSYMUTIL='#' ;;
652esac
653AC_SUBST([DSYMUTIL])
654
655AC_CHECK_PROGS([SHELLCHECK], [shellcheck])
656AM_CONDITIONAL([HAVE_SHELLCHECK], [test -n "$SHELLCHECK"])
657AC_CHECK_PROGS([RPMLINT], [rpmlint])
658AM_CONDITIONAL([HAVE_RPMLINT], [test -n "$RPMLINT"])
659AC_CHECK_PROGS([GEOJSONHINT], [geojsonhint])
660if [ test -z "$GEOJSONHINT" ]; then
661  dnl fallback to npm i -g geojson-validation
662  AC_CHECK_PROGS([GJV], [gjv])
663  GEOJSONLINT="$GJV"
664else
665  GEOJSONLINT="$GEOJSONHINT"
666fi
667AC_SUBST([GEOJSONLINT])
668
669dnl SVG validation
670AC_CHECK_PROGS([JING], [jing])
671case $host_os in
672  mingw*)   RUN_JING=rem ;;
673  windows*) RUN_JING=rem ;;
674  *) RUN_JING=":" ;;
675esac
676
677dnl LaTeXML has a broken svg11-basic.rng
678dnl The zip from http://yupotan.sppd.ne.jp/relax-ng/svg11/ is correct.
679dnl Needs to be installed into /usr/local/share/relaxng/svg11/
680dnl See https://github.com/brucemiller/LaTeXML/issues/1237
681if test -n "$JING"
682then
683  AC_MSG_CHECKING([for a working relaxng svg11-basic.rng])
684  if test -e "/usr/local/share/relaxng/svg11/svg11-basic.rng"
685  then
686    try_jing="$JING /usr/local/share/relaxng/svg11/svg11-basic.rng"
687    AC_MSG_RESULT([$try_jing])
688  elif test -e "/usr/share/perl5/vendor_perl/LaTeXML/resources/RelaxNG/svg/svg11-basic.rng"
689  then
690    try_jing="$JING /usr/share/perl5/vendor_perl/LaTeXML/resources/RelaxNG/svg/svg11-basic.rng"
691    AC_MSG_RESULT([$try_jing])
692  else
693    LATEXPM=`$PERL -MLaTeXML -e'print $INC{"LaTeXML.pm"}'`
694    if test -e "$LATEXPM" -a -e "`dirname $LATEXPM`/LaTeXML/resources/RelaxNG/svg/svg11-basic.rng"
695    then
696      try_jing="$JING `dirname $LATEXPM`/LaTeXML/resources/RelaxNG/svg/svg11-basic.rng"
697      AC_MSG_RESULT([$try_jing])
698    else
699      AC_MSG_RESULT([none])
700      JING=
701    fi
702  fi
703  AC_MSG_CHECKING([whether the svg validator works (maybe broken LaTeXML)])
704  cat <<_ACEOF >try.svg
705<?xml version="1.0" encoding="UTF-8" standalone="no"?>
706<svg
707   xmlns:svg="http://www.w3.org/2000/svg"
708   xmlns="http://www.w3.org/2000/svg"
709   xmlns:xlink="http://www.w3.org/1999/xlink"
710   version="1.1" baseProfile="basic"
711   width="100%" height="100%"
712   viewBox="-2680430.068109 -1672547.179548 3540706.089899 2726367.694617">
713	<path id="dwg-object-45" d="M 2680800.926721,1053089.884765 L 2680880.107866,1053201.295796"
714	      style="fill:none;stroke:black;stroke-width:0.1px" />
715</svg>
716_ACEOF
717  if $try_jing try.svg
718  then
719    RUN_JING="$try_jing"
720    AC_MSG_RESULT([yes])
721  else
722    AC_MSG_RESULT([no])
723    AC_MSG_RESULT(m4_normalize([
724      Use the zip from http://yupotan.sppd.ne.jp/relax-ng/svg11/
725      and unpack it into /usr/local/share/relaxng/svg11/
726      ]))
727    JING=
728  fi
729  rm try.svg 2>/dev/null
730fi
731AC_SUBST([RUN_JING])
732AM_CONDITIONAL([HAVE_JING], [test -n "$JING"])
733
734dnl help2man only by the maintainer
735
736if test x$cross_compiling = xno; then
737  dnl check for valgrind
738  case $host_os in
739    darwin*)
740      enable_valgrind_helgrind=no
741      enable_valgrind_drd=no
742      ;;
743  esac
744  dnl passes only on some systems. --enable-valgrind-sgcheck
745  AX_VALGRIND_DFLT([sgcheck], [off])
746  AX_VALGRIND_CHECK()
747  if test -n "$VALGRIND"; then
748     if test -n "$VALGRIND"; then
749       AC_MSG_CHECKING([VALGRIND version])
750       [valgrind_version=`"$VALGRIND" --version 2>&1 | sed 's,valgrind-,,'`]
751       AC_MSG_RESULT([$valgrind_version])
752     fi
753     AC_MSG_CHECKING([for Valgrind suppressions])
754     case $host_os in
755       linux*)  VALGRIND_SUPPRESSIONS_FILE=valgrind-linux.supp ;;
756       darwin*) VALGRIND_SUPPRESSIONS_FILE=valgrind-darwin.supp ;;
757     esac
758     if test -n $VALGRIND_SUPPRESSIONS_FILE; then
759       VALGRIND_SUPPRESSIONS="--suppressions=\$(abs_top_srcdir)/\$(VALGRIND_SUPPRESSIONS_FILE)"
760       AC_MSG_RESULT([$VALGRIND_SUPPRESSIONS_FILE])
761     else
762       AC_MSG_RESULT([none])
763     fi
764   fi
765else
766  AC_MSG_WARN([disabled valgrind: cross-compiled])
767  enable_valgrind=no
768  AX_VALGRIND_CHECK()
769fi
770AC_SUBST(VALGRIND_SUPPRESSIONS)
771AC_SUBST(VALGRIND_SUPPRESSIONS_FILE)
772
773dnl Write it out
774AC_CONFIG_FILES([
775	Makefile
776	src/Makefile
777	doc/Makefile
778	programs/Makefile
779	examples/Makefile
780	bindings/Makefile
781	bindings/python/Makefile
782	test/Makefile
783	test/xmlsuite/Makefile
784	test/unit-testing/Makefile
785	libredwg.pc
786])
787
788AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
789AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/footer])])
790AM_COND_IF([HAVE_PERL], [AC_CONFIG_FILES([bindings/perl/Makefile.PL])])
791AC_CONFIG_FILES([programs/dwgfilter], [chmod +x programs/dwgfilter])
792AC_CONFIG_FILES([programs/alive.test], [chmod +x programs/alive.test])
793AC_CONFIG_FILES([programs/dxf.test], [chmod +x programs/dxf.test])
794AC_CONFIG_FILES([programs/json.test], [chmod +x programs/json.test])
795AC_CONFIG_FILES([programs/svg.test], [chmod +x programs/svg.test])
796AC_CONFIG_FILES([logs-all.sh:$logs_all], [chmod +x logs-all.sh])
797AC_CONFIG_FILES([log], [chmod +x log])
798AC_CONFIG_FILES([dwg], [chmod +x dwg])
799AC_CONFIG_FILES([dxf], [chmod +x dxf])
800AC_CONFIG_FILES([json], [chmod +x json])
801AC_CONFIG_FILES([svg], [chmod +x svg])
802AC_CONFIG_FILES([rw], [chmod +x rw])
803AC_CONFIG_FILES([dynapi_test_all.sh], [chmod +x dynapi_test_all.sh])
804if test "x$ac_cv_func_scandir" = xyes; then
805  AC_CONFIG_FILES([unit_testing_all.sh], [chmod +x unit_testing_all.sh])
806fi
807
808AC_OUTPUT
809
810dnl configure.ac ends here
811