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, 258 [ Define to a field in the regex_t struct where TRE should store a 259 pointer to the internal tre_tnfa_t structure ]) 260else 261 AC_DEFINE(TRE_REGEX_T_FIELD, value) 262fi 263 264AC_CHECK_FUNCS([isascii isblank]) 265 266AC_CHECK_HEADERS([getopt.h]) 267AC_CHECK_FUNCS([getopt_long],, 268 [ # FreeBSD has a "gnugetopt" library. 269 AC_CHECK_LIB([gnugetopt], [getopt_long], 270 [ AC_DEFINE([HAVE_GETOPT_LONG]) ]) ]) 271 272dnl Check whether wide character support should be enabled. 273AC_ARG_ENABLE(wchar, 274 AC_HELP_STRING( 275 [--disable-wchar], 276 [disable the wide character (wchar_t) support @<:@default=detect@:>@]), 277 [ tre_enable_wchar="$enableval" ], 278 [ tre_enable_wchar="detect" ]) 279 280dnl Check whether libutf8 location has been given. 281AC_ARG_WITH(libutf8, 282 AC_HELP_STRING( 283 [--with-libutf8@<:@=DIR@:>@], 284 [search for libutf8 from DIR/include and DIR/lib]) 285AC_HELP_STRING( 286 [--without-libutf8], 287 [do not use libutf8 @<:@default=use if needed@:>@]), 288 [ if test "$with_val" = "no"; then 289 tre_libutf8="no" 290 else 291 tre_libutf8="yes" 292 tre_libutf8_dirs="$with_libutf8" 293 tre_libutf8_libs="-lutf8" 294 fi ], 295 [ tre_libutf8="detect" 296 tre_libutf8_dirs="none /usr /usr/local" 297 tre_libutf8_libs="none -lutf8" ]) 298 299 300if test "$tre_enable_wchar" != "no"; then 301 302 dnl Wide character support is requested. Check if we need libutf8. 303 old_libs="$LIBS" 304 old_ldflags="$LDFLAGS" 305 old_cppflags="$CPPFLAGS" 306 if test "$tre_libutf8" != "no"; then 307 AC_MSG_CHECKING([for libutf8]) 308 found="no" 309 dnl Go through directories in $tre_libutf8_dirs for CPPFLAGS and LDFLAGS. 310 for try_dir in $tre_libutf8_dirs; do 311 if test "$try_dir" = "none"; then 312 LDFLAGS="$old_ldflags" 313 CPPFLAGS="$old_cppflags" 314 else 315 LDFLAGS="$old_ldflags -L$try_dir/lib" 316 CPPFLAGS="$old_cppflags -I$try_dir/include" 317 fi 318 dnl Go through libs in $tre_libutf8_libs. 319 for try_lib in $tre_libutf8_libs; do 320 if test "$try_lib" = "none"; then 321 LIBS="$old_libs" 322 else 323 LIBS="$try_lib $old_libs" 324 fi 325 dnl Check if mbrtowc or utf8_mbrtowc is available with the current 326 dnl CPPFLAGS, LDFLAGS, and LIBS. 327 AC_LINK_IFELSE([AC_LANG_CALL([],[mbrtowc])],[found="yes"]) 328 if test "$found" = "yes"; then 329 break; 330 fi 331 AC_LINK_IFELSE([AC_LANG_CALL([],[utf8_mbrtowc])],[found="yes"]) 332 if test "$found" = "yes"; then 333 break; 334 fi 335 done 336 if test "$found" = "yes"; then 337 break; 338 fi 339 done 340 341 dnl Report results. 342 if test "$found" = "yes"; then 343 if test "$LIBS" = "$old_libs"; then 344 AC_MSG_RESULT([not needed]) 345 tre_libutf8="no" 346 else 347 AC_MSG_RESULT([using from $try_dir/{lib,include}]) 348 tre_libutf8="yes" 349 fi 350 else 351 LIBS="$old_libs" 352 LDFLAGS="$old_ldflags" 353 CPPFLAGS="$old_cppflags" 354 if test "$tre_libutf8" = "detect"; then 355 AC_MSG_RESULT([no]) 356 tre_libutf8="no" 357 else 358 # Fail if libutf8 was requested but was not found. 359 AC_MSG_ERROR([not found]) 360 fi 361 fi 362 fi 363 364 if test "$tre_libutf8" = "yes"; then 365 dnl We do need libutf8, use the libutf8 headers. 366 tre_wchar="yes" 367 AC_CHECK_HEADERS([libutf8.h]) 368 else 369 dnl Use the POSIX headers. 370 AC_CHECK_HEADERS([wchar.h wctype.h]) 371 fi 372 373else 374 tre_wchar_reason="disabled with --disable-wchar" 375 tre_wchar="no ($tre_wchar_reason)" 376fi 377 378 379tre_includes=" 380#ifdef HAVE_WCHAR_H 381#include <wchar.h> 382#endif /* HAVE_WCHAR_H */ 383#ifdef HAVE_WCTYPE_H 384#include <wctype.h> 385#endif /* HAVE_WCTYPE_H */ 386#ifdef HAVE_LIBUTF8_H 387#include <libutf8.h> 388#endif /* HAVE_LIBUTF8_H */ 389" 390 391if test "$tre_enable_wchar" != "no"; then 392 dnl We need wchar_t and WCHAR_MAX 393 AC_CHECK_TYPES([wchar_t], 394 [ tre_wchar="yes" 395 AX_DECL_WCHAR_MAX ], 396 [ tre_wchar_reason="wchar_t type not found" 397 tre_wchar="no ($tre_wchar_reason)" ], 398 [ $tre_includes ]) 399 400 if test "$tre_wchar" = "yes"; then 401 dnl We need wint_t 402 AC_CHECK_TYPES([wint_t],, 403 [ tre_wchar_reason="wint_t type not found" 404 tre_wchar="no ($tre_wchar_reason)" ], 405 [ $tre_includes ]) 406 fi 407 408 if test "$tre_wchar" = "yes"; then 409 dnl We may need mbstate_t 410 AC_CHECK_TYPES([mbstate_t],,,[ $tre_includes ]) 411 fi 412 413 if test "$tre_wchar" = "yes"; then 414 dnl We need either wcsrtombs (preferred) or wcstombs 415 found="no" 416 AX_CHECK_FUNCS_COMP([wcsrtombs wcstombs],[found="yes"; break],, 417 [$tre_includes]) 418 if test "$found" = "no"; then 419 tre_wchar_reason="no wcsrtombs or wcstombs found" 420 tre_wchar="no ($tre_wchar_reason)" 421 fi 422 fi 423 424 if test "$tre_wchar" = "yes"; then 425 dnl We need all these 426 AX_CHECK_FUNCS_COMP([iswlower iswupper towlower towupper wcschr \ 427 wcscpy wcslen wcsncpy], 428 [ tre_wchar="yes" ], 429 [ tre_wchar_reason="$ac_func not found" 430 tre_wchar="no ($tre_wchar_reason)" 431 break ], 432 [ $tre_includes ]) 433 fi 434fi 435 436case $host in 437 *-mingw*) 438 dnl wcsrtombs and wcstombs don't seem to work at all on MinGW. 439 if test "$tre_libutf8" != "yes"; then 440 tre_wchar_reason="Not supported on MinGW" 441 tre_wchar="no ($tre_wchar_reason)" 442 fi 443 ;; 444esac 445 446# Fail if wide character support was specifically requested but is 447# not supported on this system. 448if test "$tre_enable_wchar" = "yes"; then 449 if test "$tre_wchar" != "yes"; then 450 AC_MSG_ERROR([Cannot enable wide character support: $tre_wchar_reason]) 451 fi 452fi 453 454if test "$tre_wchar" = "yes"; then 455 AC_DEFINE(TRE_WCHAR, 1, 456 [ Define to enable wide character (wchar_t) support. ]) 457 458 dnl We make use of these if they exist. 459 AX_CHECK_FUNCS_COMP([wctype iswctype],,,[$tre_includes]) 460 AX_CHECK_FUNCS_COMP([iswascii iswblank],,,[$tre_includes]) 461fi 462 463dnl Check for multibyte character set support 464AC_ARG_ENABLE(multibyte, 465 AC_HELP_STRING( 466 [--disable-multibyte], 467 [disable multibyte character set support @<:@default=detect@:>@]), 468 [ tre_enable_multibyte="$enableval" ], 469 [ tre_enable_multibyte="detect" ]) 470 471dnl Wide character support is required for multibyte character set support 472if test "$tre_wchar" != "yes"; then 473 if test "$tre_enable_multibyte" = "yes"; then 474 AC_MSG_ERROR([Cannot enable multibyte character support because wide \ 475character support is not enabled ($tre_wchar_reason)]) 476 fi 477fi 478 479if test "$tre_enable_multibyte" != "no"; then 480 if test "$tre_wchar" != "yes"; then 481 tre_multibyte="no (requires wide character support)" 482 else 483 found="no" 484 dnl We need either mbrtowc (preferred) or mbtowc 485 AX_CHECK_FUNCS_COMP([mbrtowc mbtowc],[found="yes"; break],,[$tre_includes]) 486 if test "$found" = "no"; then 487 tre_mbs_reason="no mbrtowc or mbtowc found" 488 tre_multibyte="no ($tre_mbs_reason)" 489 else 490 tre_multibyte="yes" 491 fi 492 fi 493else 494 tre_multibyte="no (disabled with --disable-multibyte)" 495fi 496 497# Fail if multibyte character set support was specifically requested but 498# is not supported on this system. 499if test "$tre_enable_multibyte" = "yes"; then 500 if test "$tre_multibyte" != "yes"; then 501 AC_MSG_ERROR([Cannot enable multibyte character set support: \ 502$tre_mbs_reason]) 503 fi 504fi 505 506if test "$tre_multibyte" = "yes"; then 507 AM_CONDITIONAL(TRE_MULTIBYTE, true) 508 AC_DEFINE(TRE_MULTIBYTE, 1, 509 [ Define to enable multibyte character set support. ]) 510else 511 AM_CONDITIONAL(TRE_MULTIBYTE, false) 512fi 513 514AC_SYS_LARGEFILE 515 516AM_GNU_GETTEXT([external]) 517AC_LIBTOOL_TAGS([]) 518AC_LIBTOOL_WIN32_DLL 519AM_DISABLE_STATIC 520AC_PROG_LIBTOOL 521 522dnl Output files 523AC_CONFIG_HEADERS([config.h lib/tre-config.h]) 524AC_CONFIG_FILES([ 525Makefile 526doc/Makefile 527doc/agrep.1 528lib/Makefile 529m4/Makefile 530po/Makefile.in 531src/Makefile 532tests/Makefile 533tests/agrep/Makefile 534tre.pc 535tre.spec 536utils/Makefile 537]) 538AC_OUTPUT 539 540 541dnl Print configuration summary 542 543cat <<EOF 544 545 546Configuration summary 547===================== 548 549TRE is now configured as follows: 550 551* Compilation environment 552 553 CC = $CC 554 CFLAGS = $CFLAGS 555 CPP = $CPP 556 CPPFLAGS = $CPPFLAGS 557 LD = $LD 558 LDFLAGS = $LDFLAGS 559 LIBS = $LIBS 560 Use alloca(): $tre_use_alloca 561 562* TRE options 563 564 Development-time debugging: $tre_debug 565 System regex ABI compatibility: $tre_system_abi 566 Wide character (wchar_t) support: $tre_wchar 567 Multibyte character set support: $tre_multibyte 568 Approximate matching support: $tre_approx 569 Build and install agrep: $tre_agrep 570 571EOF 572