configure.ac revision 1.2
1dnl Process this file with autoconf to produce a configure script. 2AC_INIT(TRE, 0.8.0, [tre-general@lists.laurikari.net]) 3AC_CONFIG_SRCDIR([lib/regcomp.c]) 4AC_CONFIG_AUX_DIR(utils) 5AC_CANONICAL_TARGET 6AM_INIT_AUTOMAKE(1.9.0) 7AC_PREREQ(2.59) 8AM_GNU_GETTEXT_VERSION(0.17) 9 10dnl Checks for programs. 11AC_PROG_CC 12AC_PROG_CPP 13AC_PROG_INSTALL 14AM_PROG_CC_C_O 15 16tre_version_1=`echo $PACKAGE_VERSION | cut -d . -f 1` 17tre_version_2=`echo $PACKAGE_VERSION | cut -d . -f 2` 18tre_version_3=`echo $PACKAGE_VERSION | cut -d . -f 3` 19tre_version=$tre_version_1.$tre_version_2.$tre_version_3 20AC_DEFINE_UNQUOTED(TRE_VERSION, "$tre_version", [ TRE version string. ]) 21AC_DEFINE_UNQUOTED(TRE_VERSION_1, $tre_version_1, [ TRE version level 1. ]) 22AC_DEFINE_UNQUOTED(TRE_VERSION_2, $tre_version_2, [ TRE version level 2. ]) 23AC_DEFINE_UNQUOTED(TRE_VERSION_3, $tre_version_3, [ TRE version level 3. ]) 24AC_SUBST(TRE_VERSION, $tre_version) 25 26dnl Options 27AC_ARG_ENABLE(profile, 28 AC_HELP_STRING([--enable-profile], 29 [enable profiling with gprof @<:@default=disabled@:>@]), 30 [ tre_profile="$enableval" ], 31 [ tre_profile="no" ]) 32 33AC_ARG_ENABLE(debug, 34 AC_HELP_STRING( 35 [--enable-debug], 36 [enable development-time debugging @<:@default=disabled@:>@]), 37 [ tre_debug="$enableval" ], 38 [ tre_debug="no" ]) 39if test "$tre_debug" = "yes"; then 40 AM_CONDITIONAL(TRE_DEBUG, true) 41 AC_DEFINE(TRE_DEBUG, 1, 42 [ Define if you want TRE to print debug messages to stdout. ]) 43else 44 AM_CONDITIONAL(TRE_DEBUG, false) 45 AC_DEFINE(NDEBUG, 1, [ Define if you want to disable debug assertions. ]) 46fi 47 48if test "$tre_profile" = "yes"; then 49 CFLAGS="$CFLAGS -pg" 50 AM_CONDITIONAL(TRE_PROFILE, true) 51else 52 AM_CONDITIONAL(TRE_PROFILE, false) 53fi 54 55AC_ARG_ENABLE(warnings, 56 AC_HELP_STRING( 57 [--disable-warnings], 58 [disable C compiler warning messages @<:@default=enabled@:>@]), 59 [ tre_cc_warnings="$enableval" ], 60 [ tre_cc_warnings="yes" ]) 61if test "$tre_cc_warnings" = "yes"; then 62 VL_PROG_CC_WARNINGS() 63fi 64 65AC_ARG_ENABLE(approx, 66 AC_HELP_STRING( 67 [--disable-approx], 68 [disable the approximate matching functionality @<:@default=enabled@:>@]), 69 [ tre_approx="$enableval" ], 70 [ tre_approx="yes" ]) 71if test "$tre_approx" = "yes"; then 72 AC_DEFINE(TRE_APPROX, 1, 73 [ Define if you want to enable approximate matching functionality. ]) 74 AM_CONDITIONAL(TRE_APPROX, true) 75else 76 AM_CONDITIONAL(TRE_APPROX, false) 77fi 78 79if test "$tre_approx" = "yes"; then 80 AC_ARG_ENABLE(agrep, 81 AC_HELP_STRING([--disable-agrep], 82 [Do not build and install the agrep tool @<:@default=install@:>@]), 83 [ tre_agrep="$enableval" ], 84 [ tre_agrep="yes" ]) 85else 86 tre_agrep="no (requires approximate matching)" 87fi 88 89if test "$tre_agrep" = "yes"; then 90 AM_CONDITIONAL(TRE_AGREP, true) 91else 92 AM_CONDITIONAL(TRE_AGREP, false) 93fi 94 95 96dnl Checks for compiler characteristics. 97AC_C_CONST 98AC_C_INLINE 99 100dnl Checks for headers, functions, types, and macros 101AC_DEFINE(_GNU_SOURCE, 1, [ Define to enable GNU extensions in glibc ]) 102AC_HEADER_STDC 103 104AC_ARG_WITH(alloca, 105 AC_HELP_STRING( 106 [--without-alloca], 107 [don't use alloca @<:@default=use@:>@]), 108 [ tre_use_alloca="$withval" ], 109 [ tre_use_alloca="yes" ]) 110if test "$tre_use_alloca" = "yes"; then 111 ALLOCA="" 112 AC_FUNC_ALLOCA 113 if test -z "$ALLOCA"; then 114 # alloca() works. 115 AC_DEFINE(TRE_USE_ALLOCA, 1, 116 [ Define if you want TRE to use alloca() instead of malloc() when 117 allocating memory needed for regexec operations. ]) 118 fi 119fi 120 121AC_ARG_ENABLE(system-abi, 122 AC_HELP_STRING( 123 [--enable-system-abi], 124 [try to make TRE compatible with the system \ 125regex ABI @<:@default=disabled@:>@]), 126 [ tre_system_abi="$enableval" ], 127 [ tre_system_abi="no" ]) 128 129# If we are building a version compatible with the system ABI, we need to 130# find an absolute path to the system regex.h (so it can be included from 131# TRE regex.h using `#include "/path/to/regex.h"'). Then we need to 132# find a field in the system defined regex_t struct where a pointer to 133# the compiled regex object can be stored. 134 135if test "$tre_system_abi" = "yes"; then 136 # Check that there is a system regex.h to begin with. We may need 137 # to include sys/types.h before regex.h, so check for that first. 138 AC_CHECK_HEADERS([sys/types.h]) 139 AC_CHECK_HEADERS([regex.h], [], 140 [ tre_system_abi="no (regex.h not found)" ], 141 [#if HAVE_SYS_TYPES_H 142#include <sys/types.h> 143#endif 144]) 145fi 146 147if test "$tre_system_abi" = "yes"; then 148 # Find out where system regex.h is. This is done by running the C 149 # preprocessor and grepping its output, hopefully getting a full 150 # path to regex.h. 151 AC_MSG_CHECKING([path to system regex.h]) 152 echo '#include <regex.h>' > conftest.c 153 tre_system_regex_h=`$CPP conftest.c \ 154 | grep '^#[a-z]* [0-9]* "\(.*regex.h\)"' \ 155 | head -1 \ 156 | sed 's/^#[a-z]* [0-9]* \"\(.*\)\".*/\1/'` 157 rm -f conftest.c 158 if test -n "$tre_system_regex_h" && test -f "$tre_system_regex_h"; then 159 AC_MSG_RESULT($tre_system_regex_h) 160 else 161 AC_MSG_RESULT(unknown) 162 tre_system_abi="no (could determine path to systeg regex.h)" 163 fi 164fi 165 166if test "$tre_system_abi" = "yes"; then 167 # Find a field in the system regex_t struct where we can store a pointer. 168 # This is done by trying several names that are known to work on different 169 # systems. 170 AC_MSG_CHECKING([for a usable field for a pointer in regex_t]) 171 tre_regex_t_field="" 172 for field in buffer re_comp __re_comp __reg_expression \ 173 re_g "re_pad@<:@0@:>@"; do 174 if test -z "$tre_regex_t_field"; then 175 AC_COMPILE_IFELSE( 176 [ AC_LANG_PROGRAM([ 177#include <sys/types.h> 178#include <regex.h> 179 ], 180 [ 181 regex_t foo; 182 void *bar = foo.$field; 183 foo.$field = bar; 184 ])], 185 [ AC_MSG_RESULT($field) 186 tre_regex_t_field="$field" ]) 187 fi 188 done 189 if test -z "$tre_regex_t_field"; then 190 AC_MSG_RESULT(no) 191 tre_system_abi="no (unknown regex_t contents, report to \ 192$PACKAGE_BUGREPORT)" 193 fi 194fi 195 196if test "$tre_system_abi" = "yes"; then 197 # So far, so good. Now check if we can redefine the system regex 198 # functions. For example, the system headers may define the 199 # standard functions as static wrapper functions (like on IRIX) 200 # which prevents redefining them later. 201 202 # IRIX has some macro magic which we need to turn off. 203 AC_DEFINE(_REGCOMP_INTERNAL, 1, [ Define on IRIX ]) 204 AC_MSG_CHECKING([if POSIX regex functions can be redefined]) 205 AC_COMPILE_IFELSE( 206 [ AC_LANG_PROGRAM([ 207#include <sys/types.h> 208#include <regex.h> 209 210int 211regcomp(regex_t *preg, const char *regex, int cflags) 212{ 213 return 0; 214} 215void 216regfree(regex_t *preg) 217{ 218 return; 219} 220int 221regexec(const regex_t *preg, const char *str, 222 size_t nmatch, regmatch_t pmatch@<:@@:>@, int eflags) 223{ 224 return 0; 225} 226size_t 227regerror(int errcode, const regex_t *preg, char *errbuf, 228 size_t errbuf_size) 229{ 230 return 0; 231} 232 ])], 233 [ AC_MSG_RESULT(yes) 234 tre_system_abi="yes" ], 235 [ AC_MSG_RESULT(no) 236 tre_system_abi="no (unable to redefine system functions)" ]) 237fi 238 239if test "$tre_system_abi" = "yes"; then 240 # Great, everything seems to be OK for ABI compatibility. Just check 241 # some additional types that may or may not be defined, and set up 242 # variables to enable ABI compatibility in regex.h. 243 244 AC_CHECK_TYPES([reg_errcode_t],,,[ 245#ifdef HAVE_SYS_TYPES_H 246#include <sys/types.h> 247#endif /* HAVE_SYS_TYPES_H */ 248#ifdef HAVE_REGEX_H 249#include <regex.h> 250#endif /* HAVE_REGEX_H */ 251 ]) 252 253 AC_DEFINE(TRE_USE_SYSTEM_REGEX_H, 1, 254 [ Define to include the system regex.h from TRE regex.h ]) 255 AC_DEFINE_UNQUOTED(TRE_SYSTEM_REGEX_H_PATH, "$tre_system_regex_h", 256 [ Define to the absolute path to the system regex.h ]) 257 AC_DEFINE_UNQUOTED(TRE_REGEX_T_FIELD, $tre_regex_t_field) 258else 259 AC_DEFINE(TRE_REGEX_T_FIELD, value) 260fi 261 262AH_VERBATIM(TRE_REGEX_T_FIELD, 263[/* Define to a field in the regex_t struct where TRE should store a pointer to 264 the internal tre_tnfa_t structure */ 265#ifndef TRE_REGEX_T_FIELD 266#undef TRE_REGEX_T_FIELD 267#endif]) 268 269AC_CHECK_FUNCS([isascii isblank]) 270 271AC_CHECK_HEADERS([getopt.h]) 272AC_CHECK_FUNCS([getopt_long],, 273 [ # FreeBSD has a "gnugetopt" library. 274 AC_CHECK_LIB([gnugetopt], [getopt_long], 275 [ AC_DEFINE([HAVE_GETOPT_LONG]) ]) ]) 276 277dnl Check whether wide character support should be enabled. 278AC_ARG_ENABLE(wchar, 279 AC_HELP_STRING( 280 [--disable-wchar], 281 [disable the wide character (wchar_t) support @<:@default=detect@:>@]), 282 [ tre_enable_wchar="$enableval" ], 283 [ tre_enable_wchar="detect" ]) 284 285dnl Check whether libutf8 location has been given. 286AC_ARG_WITH(libutf8, 287 AC_HELP_STRING( 288 [--with-libutf8@<:@=DIR@:>@], 289 [search for libutf8 from DIR/include and DIR/lib]) 290AC_HELP_STRING( 291 [--without-libutf8], 292 [do not use libutf8 @<:@default=use if needed@:>@]), 293 [ if test "$with_val" = "no"; then 294 tre_libutf8="no" 295 else 296 tre_libutf8="yes" 297 tre_libutf8_dirs="$with_libutf8" 298 tre_libutf8_libs="-lutf8" 299 fi ], 300 [ tre_libutf8="detect" 301 tre_libutf8_dirs="none /usr /usr/local" 302 tre_libutf8_libs="none -lutf8" ]) 303 304 305if test "$tre_enable_wchar" != "no"; then 306 307 dnl Wide character support is requested. Check if we need libutf8. 308 old_libs="$LIBS" 309 old_ldflags="$LDFLAGS" 310 old_cppflags="$CPPFLAGS" 311 if test "$tre_libutf8" != "no"; then 312 AC_MSG_CHECKING([for libutf8]) 313 found="no" 314 dnl Go through directories in $tre_libutf8_dirs for CPPFLAGS and LDFLAGS. 315 for try_dir in $tre_libutf8_dirs; do 316 if test "$try_dir" = "none"; then 317 LDFLAGS="$old_ldflags" 318 CPPFLAGS="$old_cppflags" 319 else 320 LDFLAGS="$old_ldflags -L$try_dir/lib" 321 CPPFLAGS="$old_cppflags -I$try_dir/include" 322 fi 323 dnl Go through libs in $tre_libutf8_libs. 324 for try_lib in $tre_libutf8_libs; do 325 if test "$try_lib" = "none"; then 326 LIBS="$old_libs" 327 else 328 LIBS="$try_lib $old_libs" 329 fi 330 dnl Check if mbrtowc or utf8_mbrtowc is available with the current 331 dnl CPPFLAGS, LDFLAGS, and LIBS. 332 AC_LINK_IFELSE([AC_LANG_CALL([],[mbrtowc])],[found="yes"]) 333 if test "$found" = "yes"; then 334 break; 335 fi 336 AC_LINK_IFELSE([AC_LANG_CALL([],[utf8_mbrtowc])],[found="yes"]) 337 if test "$found" = "yes"; then 338 break; 339 fi 340 done 341 if test "$found" = "yes"; then 342 break; 343 fi 344 done 345 346 dnl Report results. 347 if test "$found" = "yes"; then 348 if test "$LIBS" = "$old_libs"; then 349 AC_MSG_RESULT([not needed]) 350 tre_libutf8="no" 351 else 352 AC_MSG_RESULT([using from $try_dir/{lib,include}]) 353 tre_libutf8="yes" 354 fi 355 else 356 LIBS="$old_libs" 357 LDFLAGS="$old_ldflags" 358 CPPFLAGS="$old_cppflags" 359 if test "$tre_libutf8" = "detect"; then 360 AC_MSG_RESULT([no]) 361 tre_libutf8="no" 362 else 363 # Fail if libutf8 was requested but was not found. 364 AC_MSG_ERROR([not found]) 365 fi 366 fi 367 fi 368 369 if test "$tre_libutf8" = "yes"; then 370 dnl We do need libutf8, use the libutf8 headers. 371 tre_wchar="yes" 372 AC_CHECK_HEADERS([libutf8.h]) 373 else 374 dnl Use the POSIX headers. 375 AC_CHECK_HEADERS([wchar.h wctype.h]) 376 fi 377 378else 379 tre_wchar_reason="disabled with --disable-wchar" 380 tre_wchar="no ($tre_wchar_reason)" 381fi 382 383 384tre_includes=" 385#ifdef HAVE_WCHAR_H 386#include <wchar.h> 387#endif /* HAVE_WCHAR_H */ 388#ifdef HAVE_WCTYPE_H 389#include <wctype.h> 390#endif /* HAVE_WCTYPE_H */ 391#ifdef HAVE_LIBUTF8_H 392#include <libutf8.h> 393#endif /* HAVE_LIBUTF8_H */ 394" 395 396if test "$tre_enable_wchar" != "no"; then 397 dnl We need wchar_t and WCHAR_MAX 398 AC_CHECK_TYPES([wchar_t], 399 [ tre_wchar="yes" 400 AX_DECL_WCHAR_MAX ], 401 [ tre_wchar_reason="wchar_t type not found" 402 tre_wchar="no ($tre_wchar_reason)" ], 403 [ $tre_includes ]) 404 405 if test "$tre_wchar" = "yes"; then 406 dnl We need wint_t 407 AC_CHECK_TYPES([wint_t],, 408 [ tre_wchar_reason="wint_t type not found" 409 tre_wchar="no ($tre_wchar_reason)" ], 410 [ $tre_includes ]) 411 fi 412 413 if test "$tre_wchar" = "yes"; then 414 dnl We may need mbstate_t 415 AC_CHECK_TYPES([mbstate_t],,,[ $tre_includes ]) 416 fi 417 418 if test "$tre_wchar" = "yes"; then 419 dnl We need either wcsrtombs (preferred) or wcstombs 420 found="no" 421 AX_CHECK_FUNCS_COMP([wcsrtombs wcstombs],[found="yes"; break],, 422 [$tre_includes]) 423 if test "$found" = "no"; then 424 tre_wchar_reason="no wcsrtombs or wcstombs found" 425 tre_wchar="no ($tre_wchar_reason)" 426 fi 427 fi 428 429 if test "$tre_wchar" = "yes"; then 430 dnl We need all these 431 AX_CHECK_FUNCS_COMP([iswlower iswupper towlower towupper wcschr \ 432 wcscpy wcslen wcsncpy], 433 [ tre_wchar="yes" ], 434 [ tre_wchar_reason="$ac_func not found" 435 tre_wchar="no ($tre_wchar_reason)" 436 break ], 437 [ $tre_includes ]) 438 fi 439fi 440 441case $host in 442 *-mingw*) 443 dnl wcsrtombs and wcstombs don't seem to work at all on MinGW. 444 if test "$tre_libutf8" != "yes"; then 445 tre_wchar_reason="Not supported on MinGW" 446 tre_wchar="no ($tre_wchar_reason)" 447 fi 448 ;; 449esac 450 451# Fail if wide character support was specifically requested but is 452# not supported on this system. 453if test "$tre_enable_wchar" = "yes"; then 454 if test "$tre_wchar" != "yes"; then 455 AC_MSG_ERROR([Cannot enable wide character support: $tre_wchar_reason]) 456 fi 457fi 458 459if test "$tre_wchar" = "yes"; then 460 AC_DEFINE(TRE_WCHAR, 1, 461 [ Define to enable wide character (wchar_t) support. ]) 462 463 dnl We make use of these if they exist. 464 AX_CHECK_FUNCS_COMP([wctype iswctype],,,[$tre_includes]) 465 AX_CHECK_FUNCS_COMP([iswascii iswblank],,,[$tre_includes]) 466fi 467 468dnl Check for multibyte character set support 469AC_ARG_ENABLE(multibyte, 470 AC_HELP_STRING( 471 [--disable-multibyte], 472 [disable multibyte character set support @<:@default=detect@:>@]), 473 [ tre_enable_multibyte="$enableval" ], 474 [ tre_enable_multibyte="detect" ]) 475 476dnl Wide character support is required for multibyte character set support 477if test "$tre_wchar" != "yes"; then 478 if test "$tre_enable_multibyte" = "yes"; then 479 AC_MSG_ERROR([Cannot enable multibyte character support because wide \ 480character support is not enabled ($tre_wchar_reason)]) 481 fi 482fi 483 484if test "$tre_enable_multibyte" != "no"; then 485 if test "$tre_wchar" != "yes"; then 486 tre_multibyte="no (requires wide character support)" 487 else 488 found="no" 489 dnl We need either mbrtowc (preferred) or mbtowc 490 AX_CHECK_FUNCS_COMP([mbrtowc mbtowc],[found="yes"; break],,[$tre_includes]) 491 if test "$found" = "no"; then 492 tre_mbs_reason="no mbrtowc or mbtowc found" 493 tre_multibyte="no ($tre_mbs_reason)" 494 else 495 tre_multibyte="yes" 496 fi 497 fi 498else 499 tre_multibyte="no (disabled with --disable-multibyte)" 500fi 501 502# Fail if multibyte character set support was specifically requested but 503# is not supported on this system. 504if test "$tre_enable_multibyte" = "yes"; then 505 if test "$tre_multibyte" != "yes"; then 506 AC_MSG_ERROR([Cannot enable multibyte character set support: \ 507$tre_mbs_reason]) 508 fi 509fi 510 511if test "$tre_multibyte" = "yes"; then 512 AM_CONDITIONAL(TRE_MULTIBYTE, true) 513 AC_DEFINE(TRE_MULTIBYTE, 1, 514 [ Define to enable multibyte character set support. ]) 515else 516 AM_CONDITIONAL(TRE_MULTIBYTE, false) 517fi 518 519AC_SYS_LARGEFILE 520 521AM_GNU_GETTEXT([external]) 522AC_LIBTOOL_TAGS([]) 523AC_LIBTOOL_WIN32_DLL 524AM_DISABLE_STATIC 525AC_PROG_LIBTOOL 526 527dnl Output files 528AC_CONFIG_HEADERS([config.h lib/tre-config.h]) 529AC_CONFIG_FILES([ 530Makefile 531doc/Makefile 532doc/agrep.1 533lib/Makefile 534m4/Makefile 535po/Makefile.in 536src/Makefile 537tests/Makefile 538tests/agrep/Makefile 539tre.pc 540tre.spec 541utils/Makefile 542]) 543AC_OUTPUT 544 545 546dnl Print configuration summary 547 548cat <<EOF 549 550 551Configuration summary 552===================== 553 554TRE is now configured as follows: 555 556* Compilation environment 557 558 CC = $CC 559 CFLAGS = $CFLAGS 560 CPP = $CPP 561 CPPFLAGS = $CPPFLAGS 562 LD = $LD 563 LDFLAGS = $LDFLAGS 564 LIBS = $LIBS 565 Use alloca(): $tre_use_alloca 566 567* TRE options 568 569 Development-time debugging: $tre_debug 570 System regex ABI compatibility: $tre_system_abi 571 Wide character (wchar_t) support: $tre_wchar 572 Multibyte character set support: $tre_multibyte 573 Approximate matching support: $tre_approx 574 Build and install agrep: $tre_agrep 575 576EOF 577