From 4c95dd86a79900094356e8634d7211fd32abf896 Mon Sep 17 00:00:00 2001 From: Hema Seetharamaiah Date: Sun, 26 Apr 2009 16:43:01 +0530 Subject: [PATCH 1/5] Add --without-tre option elinks-lite in Debian does not depend on any libraries (except gnutls). Including this option will allow elinks-lite to be built without libtre dependency. --- configure.in | 82 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/configure.in b/configure.in index 81f39ec2..47910a30 100644 --- a/configure.in +++ b/configure.in @@ -926,42 +926,56 @@ fi # Check for TRE library # =================================================================== -AC_MSG_CHECKING([[for TRE in pkg-config]]) -if pkg-config tre; then - TRE_CFLAGS=`pkg-config --cflags tre` - TRE_LIBS=`pkg-config --libs tre` - AC_MSG_RESULT([[yes]]) -else - # - # "libtre-dev: /usr/lib/pkgconfig/tre.pc missing" - # so we look for the library even if pkg-config doesn't know about it. - TRE_CFLAGS= - TRE_LIBS=-ltre - AC_MSG_RESULT([[no, but let's try defaults]]) -fi +disable_tre="" +AC_ARG_WITH(tre, [ --without-tre disable TRE regex search support], + [if test "$with_tre" = no; then disable_tre=yes; fi]) + +AC_MSG_CHECKING([for TRE]) -AC_MSG_CHECKING([[for TRE header and library]]) EL_SAVE_FLAGS -CFLAGS="$TRE_CFLAGS $CFLAGS" -LIBS="$TRE_LIBS $LIBS" -AC_TRY_LINK([#include ], - [regex_t re; - regmatch_t match[1]; - regwcomp(&re, L"zap", REG_ICASE); - regwexec(&re, L"ELIZAPROGRAM", 1, match, 0);], - [AC_MSG_RESULT([[yes]]) - AC_DEFINE([HAVE_TRE_REGEX_H], [1], - [Define to 1 if you have the header file.]) - # TRE_CFLAGS will be used only where needed. - # TRE_LIBS will be kept in LIBS and used everywhere. - EL_RESTORE_FLAGS - LIBS="$TRE_LIBS $LIBS"], - [AC_MSG_RESULT([[no]]) - TRE_CFLAGS= - TRE_LIBS= - EL_RESTORE_FLAGS]) -AC_SUBST(TRE_CFLAGS) -AC_SUBST(TRE_LIBS) +cf_result="no" + +if test "$disable_tre" = yes; then + cf_result="not used" +else + AC_MSG_CHECKING([[for TRE in pkg-config]]) + if pkg-config tre; then + TRE_CFLAGS=`pkg-config --cflags tre` + TRE_LIBS=`pkg-config --libs tre` + AC_MSG_RESULT([[yes]]) + else + # + # "libtre-dev: /usr/lib/pkgconfig/tre.pc missing" + # so we look for the library even if pkg-config doesn't know about it. + TRE_CFLAGS= + TRE_LIBS=-ltre + AC_MSG_RESULT([[no, but let's try defaults]]) + fi + + AC_MSG_CHECKING([[for TRE header and library]]) + EL_SAVE_FLAGS + CFLAGS="$TRE_CFLAGS $CFLAGS" + LIBS="$TRE_LIBS $LIBS" + AC_TRY_LINK([#include ], + [regex_t re; + regmatch_t match[1]; + regwcomp(&re, L"zap", REG_ICASE); + regwexec(&re, L"ELIZAPROGRAM", 1, match, 0);], + [AC_MSG_RESULT([[yes]]) + AC_DEFINE([HAVE_TRE_REGEX_H], [1], + [Define to 1 if you have the header file.]) + # TRE_CFLAGS will be used only where needed. + # TRE_LIBS will be kept in LIBS and used everywhere. + EL_RESTORE_FLAGS + LIBS="$TRE_LIBS $LIBS"], + [AC_MSG_RESULT([[no]]) + TRE_CFLAGS= + TRE_LIBS= + EL_RESTORE_FLAGS]) + AC_SUBST(TRE_CFLAGS) + AC_SUBST(TRE_LIBS) +fi +AC_MSG_RESULT($cf_result) AC_CHECK_SIZEOF([wchar_t], [4], [[#include ]]) From 4850a136fe182d3cac7dcc86d3cd60652ac8fd76 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 21 May 2009 13:55:25 +0300 Subject: [PATCH 2/5] Add Hema Seetharamaiah to AUTHORS The licence grants are in these messages posted to elinks-dev: Subject: Re: Patch to make libtre dependency optional. Date: Tue, 28 Apr 2009 20:16:25 +0530 Message-ID: <49F716C1.40004@treap.net> Subject: Re: Patch to make libtre dependency optional. Date: Thu, 21 May 2009 09:06:15 +0530 (IST) Message-ID: <1126.122.167.155.194.1242876975.squirrel@www.treap.net> --- AUTHORS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AUTHORS b/AUTHORS index 6569ebc7..6c4a3982 100644 --- a/AUTHORS +++ b/AUTHORS @@ -214,6 +214,10 @@ Gianluca Montecchi Harold L Hunt II Build system minor fixes +Hema Seetharamaiah + Licenses the change under GPLv2-or-later and the modified BSD and X11 license, and permits linking with OpenSSL and with code licensed under LGPL. + Add configure --without-tre option + Hugo Haas Minor random hacking debian/watch file From 07c90ea43896464f3fa3f2be39fed4ce60c86b24 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 21 May 2009 14:57:54 +0300 Subject: [PATCH 3/5] --without-tre: Don't nest AC_MSG_CHECKING...AC_MSG_RESULT The previous version could display its progress like this: checking for TRE... checking for TRE in pkg-config... yes checking for TRE header and library... yes no Omit the outer "checking for TRE..." and "no" (which was untrue anyway), unless --without-tre causes the inner checks to be skipped. --- configure.in | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/configure.in b/configure.in index 47910a30..d3815e08 100644 --- a/configure.in +++ b/configure.in @@ -926,17 +926,10 @@ fi # Check for TRE library # =================================================================== -disable_tre="" -AC_ARG_WITH(tre, [ --without-tre disable TRE regex search support], - [if test "$with_tre" = no; then disable_tre=yes; fi]) - -AC_MSG_CHECKING([for TRE]) - -EL_SAVE_FLAGS -cf_result="no" - -if test "$disable_tre" = yes; then - cf_result="not used" +AC_ARG_WITH([[tre]], [[ --without-tre disable TRE regex search support]]) +if test "$with_tre" = no; then + AC_MSG_CHECKING([[for TRE]]) + AC_MSG_RESULT([[disabled]]) else AC_MSG_CHECKING([[for TRE in pkg-config]]) if pkg-config tre; then @@ -975,7 +968,6 @@ else AC_SUBST(TRE_CFLAGS) AC_SUBST(TRE_LIBS) fi -AC_MSG_RESULT($cf_result) AC_CHECK_SIZEOF([wchar_t], [4], [[#include ]]) From 0c756fc3e84edb207d37b85019a6e2defb7afaa0 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 21 May 2009 17:22:12 +0300 Subject: [PATCH 4/5] TRE: Check for 32-bit wchar_t at configure time This check used to be in src/elinks.h. Move it to configure.in so that (1) the result can be logged and (2) ELinks won't even link with TRE if wchar_t prevents its use. Also, rename HAVE_TRE_REGEX_H to CONFIG_TRE, to reflect that it is not always defined if the header exists. --- configure.in | 85 ++++++++++++++++++++++++++++++++++------ src/config/options.inc | 2 +- src/elinks.h | 24 ------------ src/intl/charsets.h | 1 + src/viewer/text/search.c | 22 +++++------ 5 files changed, 85 insertions(+), 49 deletions(-) diff --git a/configure.in b/configure.in index d3815e08..46cbb9ad 100644 --- a/configure.in +++ b/configure.in @@ -925,11 +925,20 @@ fi # =================================================================== # Check for TRE library # =================================================================== +# +# This section only checks that --without-tre is not given and the +# library seems to work, and sets TRE_CFLAGS, TRE_LIBS, and +# tre_log. It does not define CONFIG_TRE, and always resets +# LIBS and CFLAGS back to their original values. +# +# After any --enable-utf-8 and --disable-utf-8 options have been +# handled, a separate section decides whether to actually use TRE. AC_ARG_WITH([[tre]], [[ --without-tre disable TRE regex search support]]) if test "$with_tre" = no; then AC_MSG_CHECKING([[for TRE]]) AC_MSG_RESULT([[disabled]]) + tre_log="no (explicitly disabled)" else AC_MSG_CHECKING([[for TRE in pkg-config]]) if pkg-config tre; then @@ -955,22 +964,12 @@ else regwcomp(&re, L"zap", REG_ICASE); regwexec(&re, L"ELIZAPROGRAM", 1, match, 0);], [AC_MSG_RESULT([[yes]]) - AC_DEFINE([HAVE_TRE_REGEX_H], [1], - [Define to 1 if you have the header file.]) - # TRE_CFLAGS will be used only where needed. - # TRE_LIBS will be kept in LIBS and used everywhere. - EL_RESTORE_FLAGS - LIBS="$TRE_LIBS $LIBS"], + tre_log="available"], [AC_MSG_RESULT([[no]]) - TRE_CFLAGS= - TRE_LIBS= - EL_RESTORE_FLAGS]) - AC_SUBST(TRE_CFLAGS) - AC_SUBST(TRE_LIBS) + tre_log="no (TRE not found)"]) + EL_RESTORE_FLAGS fi -AC_CHECK_SIZEOF([wchar_t], [4], [[#include ]]) - # =================================================================== # Check for Ruby, optional even if installed. # =================================================================== @@ -1385,6 +1384,66 @@ AC_ARG_ENABLE(weehoofooboomookerchoo, [AC_MSG_ERROR(Are you strange, or what?)]) +# =================================================================== +# Decide whether to use TRE +# =================================================================== +# +# This must be done after the CONFIG_UTF8 check above. +# The first part of the TRE check is separate, to get +# the configure --help output in a sensible order. + +if test "$tre_log" = "available"; then + if test "$CONFIG_UTF8" = "yes"; then + # When CONFIG_UTF8 and CONFIG_TRE are both defined, + # src/viewer/text/search.c makes a string of + # unicode_val_T and gives it to regwexec(), which + # expects a string of wchar_t. If the unicode_val_T + # and wchar_t types are too different, this won't + # work, so try to detect that and disable regexp + # operations entirely in that case. + # + # Currently, this code only compares the sizes of the + # types. src/intl/charsets.h defines unicode_val_T as + # uint32_t, so we check whether wchar_t has exactly 32 + # bits. But don't use AC_CHECK_SIZEOF for this, because + # there doesn't seem to be a documented way to get the + # result of that for use in the configure script. + # + # C99 says the implementation can define + # __STDC_ISO_10646__ if wchar_t values match ISO 10646 + # (or Unicode) numbers in all locales. Do not check + # that macro here, because it is too restrictive: it + # should be enough for ELinks if the values match in + # the locales where ELinks is actually run. + AC_MSG_CHECKING([[whether wchar_t is exactly 32-bit]]) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +int dummy[(sizeof(wchar_t) * CHAR_BIT == 32) ? 1 : -1];]], [])], + [AC_MSG_RESULT([[yes]]) + tre_log="TRE"], + [AC_MSG_RESULT([[no]]) + tre_log="no (unsuitable wchar_t)"]) + else + # If UTF-8 is not used, then wchar_t doesn't matter. + tre_log="TRE" + fi +fi + +if test "$tre_log" = "TRE"; then + AC_DEFINE([CONFIG_TRE], [1], + [Define as 1 to use the TRE library for regular expression searching. This requires the header file. If you define CONFIG_UTF8 too, then wchar_t must be exactly 32-bit so that it matches unicode_val_T.]) + # TRE_CFLAGS will be used only where needed. + LIBS="$LIBS $TRE_LIBS" +else + TRE_LIBS= + TRE_CFLAGS= +fi +AC_SUBST(TRE_CFLAGS) +AC_SUBST(TRE_LIBS) +EL_LOG_CONFIG([[CONFIG_TRE]], [[Regexp searching]], [[$tre_log]]) + + # =================================================================== # Further LDFLAGS tweaks # =================================================================== diff --git a/src/config/options.inc b/src/config/options.inc index b9c6a7f2..163f7b94 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -407,7 +407,7 @@ static struct option_info config_options_info[] = { N_("Whether the search should match the document text while " "maintaining case sensitivity.")), -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE INIT_OPT_INT("document.browse.search", N_("Regular expressions"), "regex", 0, 0, 2, 0, N_("Enable searching with regular expressions:\n" diff --git a/src/elinks.h b/src/elinks.h index 0e164a1b..6cdcffb0 100644 --- a/src/elinks.h +++ b/src/elinks.h @@ -29,30 +29,6 @@ #define DEBUG_MEMLEAK #endif - -/* When CONFIG_UTF8 is defined, src/viewer/text/search.c makes a string - * of unicode_val_T and gives it to regwexec(), which expects a string - * of wchar_t. If the unicode_val_T and wchar_t types are too different, - * this won't work, so try to detect that and disable regexp operations - * entirely in that case. - * - * Currently, this code only compares the sizes of the types. Because - * unicode_val_T is defined as uint32_t and POSIX says bytes are 8-bit, - * sizeof(unicode_val_T) is 4 and the following compares SIZEOF_WCHAR_T - * to that. - * - * C99 says the implementation can define __STDC_ISO_10646__ if wchar_t - * values match ISO 10646 (or Unicode) numbers in all locales. Do not - * check that macro here, because it is too restrictive: it should be - * enough for ELinks if the values match in the locales where ELinks is - * actually run. */ - -#ifdef CONFIG_UTF8 -#if SIZEOF_WCHAR_T != 4 -#undef HAVE_TRE_REGEX_H -#endif -#endif - /* This maybe overrides some of the standard high-level functions, to ensure * the expected behaviour. These overrides are not system specific. */ #include "osdep/stub.h" diff --git a/src/intl/charsets.h b/src/intl/charsets.h index 32a676fe..7baf3cf3 100644 --- a/src/intl/charsets.h +++ b/src/intl/charsets.h @@ -1,6 +1,7 @@ #ifndef EL__INTL_CHARSETS_H #define EL__INTL_CHARSETS_H +/* The TRE check in configure.in assumes unicode_val_T is uint32_t. */ typedef uint32_t unicode_val_T; /* U+0020 SPACE. Normally the same as ' ' or L' ' but perhaps ELinks diff --git a/src/viewer/text/search.c b/src/viewer/text/search.c index 83656dce..0cb673ae 100644 --- a/src/viewer/text/search.c +++ b/src/viewer/text/search.c @@ -18,7 +18,7 @@ #include /* FreeBSD needs this before regex.h */ #include #include -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE #include #endif @@ -270,7 +270,7 @@ get_range(struct document *document, int y, int height, int l, return 0; } -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE /** Returns a string @c doc that is a copy of the text in the search * nodes from @a s1 to (@a s1 + @a doclen - 1) with the space at the * end of each line converted to a new-line character (LF). */ @@ -465,7 +465,7 @@ is_in_range_regex(struct document *document, int y, int height, return common_ctx.found; } -#endif /* HAVE_TRE_REGEX_H */ +#endif /* CONFIG_TRE */ static UCHAR * memacpy_u(unsigned char *text, int textlen, int utf8) @@ -602,7 +602,7 @@ is_in_range(struct document *document, int y, int height, if (get_range(document, y, height, textlen, &s1, &s2)) return 0; -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE if (get_opt_int("document.browse.search.regex")) return is_in_range_regex(document, y, height, text, textlen, min, max, s1, s2, utf8); @@ -681,7 +681,7 @@ srch_failed: *pl = len; } -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE struct get_searched_regex_context { int xoffset; int yoffset; @@ -749,7 +749,7 @@ get_searched_regex(struct document_view *doc_view, struct point **pt, int *pl, *pt = ctx.points; *pl = ctx.len; } -#endif /* HAVE_TRE_REGEX_H */ +#endif /* CONFIG_TRE */ static void get_searched(struct document_view *doc_view, struct point **pt, int *pl, int utf8) @@ -773,7 +773,7 @@ get_searched(struct document_view *doc_view, struct point **pt, int *pl, int utf return; } -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE if (get_opt_int("document.browse.search.regex")) get_searched_regex(doc_view, pt, pl, l, s1, s2, utf8); else @@ -1594,7 +1594,7 @@ search_typeahead(struct session *ses, struct document_view *doc_view, * a nice cleanup target ;-). --pasky */ enum search_option { -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE SEARCH_OPT_REGEX, #endif SEARCH_OPT_CASE, @@ -1602,7 +1602,7 @@ enum search_option { }; static struct option_resolver resolvers[] = { -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE { SEARCH_OPT_REGEX, "regex" }, #endif { SEARCH_OPT_CASE, "case" }, @@ -1669,7 +1669,7 @@ search_dlg_do(struct terminal *term, struct memory_list *ml, hop->values, SEARCH_OPTIONS); hop->data = data; -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE #define SEARCH_WIDGETS_COUNT 8 #else #define SEARCH_WIDGETS_COUNT 5 @@ -1693,7 +1693,7 @@ search_dlg_do(struct terminal *term, struct memory_list *ml, field = get_dialog_offset(dlg, SEARCH_WIDGETS_COUNT); add_dlg_field(dlg, text, 0, 0, NULL, MAX_STR_LEN, field, history); -#ifdef HAVE_TRE_REGEX_H +#ifdef CONFIG_TRE add_dlg_radio(dlg, _("Normal search", term), 1, 0, &hop->values[SEARCH_OPT_REGEX].number); add_dlg_radio(dlg, _("Regexp search", term), 1, 1, &hop->values[SEARCH_OPT_REGEX].number); add_dlg_radio(dlg, _("Extended regexp search", term), 1, 2, &hop->values[SEARCH_OPT_REGEX].number); From ec4bca9cb3d52c055f72b4c0932abe493c29be91 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Thu, 21 May 2009 19:48:35 +0300 Subject: [PATCH 5/5] NEWS: mention configure --without-tre --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 03f86e73..7a7ecc5e 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ includes the changes listed under ``ELinks 0.11.6.GIT now'' below. * critical bug 1071: Fix crash in get_dom_node_child. * Debian build bug 526349: Include asciidoc.py from AsciiDoc 7.1.2, to remove all dependencies on the installed version. +* build enhancement: Recognize ``configure --without-tre''. ELinks 0.12pre3: ----------------