Index: configure.ac
===================================================================
--- configure.ac	(revision 2488)
+++ configure.ac	(working copy)
@@ -19,8 +19,6 @@
 
 case $host_os in
      mingw*)
-	   # if we don't have system regex, use SWORD's copy
-           AC_CHECK_LIB(regex, regexec,,target_mingw32="yes")
 	   # both lines necessary to convince gcc to build dll
 	   LIBS="$LIBS -no-undefined";
 	   export lt_cv_deplibs_check_method=pass_all;
@@ -66,6 +64,8 @@
 	AC_HELP_STRING([--with-curl],[build install manager support using libcurl (default=yes)]),,with_curl=yes)
 #AC_ARG_WITH(lucene,
 #	AC_HELP_STRING([--with-lucene],[include lucene support for searching (default=no)]),,with_lucene=no)
+AC_ARG_WITH([regex],
+	AS_HELP_STRING([--with-regex], [Compile using internal copy of regex]))
 
 
 # ---------------------------------------------------------------------
@@ -123,7 +123,18 @@
 	AM_CXXFLAGS="$AM_CXXFLAGS -DEXCLUDEZLIB"
 fi
 
+AS_IF([test "x$with_regex" = "xyes"],
+      [have_systemregex="no"],
+      [AC_SEARCH_LIBS(regexec, regex, [have_systemregex="yes"], [have_systemregex="no"])])
 
+AS_IF([test "x$have_systemregex" = "xyes"],
+      [AC_MSG_NOTICE([Using system regex.h])],
+      [AS_IF([test "x$with_regex" = "xno"],
+      	[AC_MSG_ERROR([System regex forced but not found])],
+	[AC_MSG_NOTICE([Using internal regex.h])])])
+
+AM_CONDITIONAL(SYSTEM_REGEX, test "$have_systemregex")
+
 # ---------------------------------------------------------------------
 # Find CppUnit
 # ---------------------------------------------------------------------
@@ -301,8 +312,8 @@
 AM_CONDITIONAL(HAVE_ICU, test x$with_icu = xyes)
 AM_CONDITIONAL(HAVE_ICUSWORD, test x$with_icusword = xyes)
 AM_CONDITIONAL(HAVE_VSNPRINTF, test x$have_vsnprintf = xyes)
+AM_CONDITIONAL(SYSTEM_REGEX, test x$have_systemregex = xyes)
 
-AM_CONDITIONAL(MINGW, test x$target_mingw32 = xyes)
 AM_CONDITIONAL(USELUCENE, test x$with_clucene = xyes)
 AM_CONDITIONAL(SHAREDLIB, test x$enable_shared = xyes)
 AM_CONDITIONAL(INSTCONF, test x$with_conf = xyes)
Index: examples/cmdline/Makefile.am
===================================================================
--- examples/cmdline/Makefile.am	(revision 2488)
+++ examples/cmdline/Makefile.am	(working copy)
@@ -1,5 +1,5 @@
 AUTOMAKE_OPTIONS = 1.6
-INCLUDES = -I $(top_srcdir)/include
+include $(top_srcdir)/include/Makefile.am
 LDADD = $(top_builddir)/lib/libsword.la
 
 noinst_PROGRAMS = lookup search threaded_search listoptions verserangeparse outplain outrender
Index: include/Makefile.am
===================================================================
--- include/Makefile.am	(revision 2488)
+++ include/Makefile.am	(working copy)
@@ -75,7 +75,8 @@
 pkginclude_HEADERS += $(swincludedir)/rawstr4.h
 pkginclude_HEADERS += $(swincludedir)/rawtext.h
 pkginclude_HEADERS += $(swincludedir)/rawverse.h
-if MINGW
+if SYSTEM_REGEX
+else
 pkginclude_HEADERS += $(swincludedir)/regex.h
 endif
 pkginclude_HEADERS += $(swincludedir)/roman.h
Index: lib/Makefile.am
===================================================================
--- lib/Makefile.am	(revision 2488)
+++ lib/Makefile.am	(working copy)
@@ -1,6 +1,5 @@
 AUTOMAKE_OPTIONS = 1.6
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(includedir) 
-AM_CPPFLAGS += -DUSE_AUTOTOOLS -DUNIX -Dunix -D__unix__
+AM_CPPFLAGS = -DUSE_AUTOTOOLS -DUNIX -Dunix -D__unix__
 
 # Global config directory
 globalconfdir := @sysconfdir@
Index: src/utilfuns/Makefile.am
===================================================================
--- src/utilfuns/Makefile.am	(revision 2488)
+++ src/utilfuns/Makefile.am	(working copy)
@@ -29,10 +29,10 @@
 libsword_la_SOURCES += $(UNTGZ) 
 libsword_la_SOURCES += $(ftpsrc)
 
-if MINGW
+if SYSTEM_REGEX
+SWREGEX =
+else
 SWREGEX = $(utilfunsdir)/regex.c
-else
-SWREGEX =
 endif
 libsword_la_SOURCES += $(SWREGEX)
 
Index: tests/cppunit/Makefile.am
===================================================================
--- tests/cppunit/Makefile.am	(revision 2488)
+++ tests/cppunit/Makefile.am	(working copy)
@@ -8,9 +8,10 @@
 endif
 check_PROGRAMS = $(TESTS)
 LibSword_SOURCES = main.cpp stringmgr_test.cpp swbuf_test.cpp url_test.cpp versekey_test.cpp 
-LibSword_CXXFLAGS = $(CPPUNIT_CFLAGS) -I$(top_srcdir)/include
+LibSword_CXXFLAGS = $(CPPUNIT_CFLAGS)
 LibSword_LDFLAGS = $(CPPUNIT_LIBS)
 
 swcppunitpdir = $(top_srcdir)/tests/cppunit
 
+include $(top_srcdir)/include/Makefile.am
 #all: check
Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 2488)
+++ tests/Makefile.am	(working copy)
@@ -1,5 +1,5 @@
 AUTOMAKE_OPTIONS = 1.6
-INCLUDES = -I $(top_srcdir)/include
+include $(top_srcdir)/include/Makefile.am
 LDADD = $(top_builddir)/lib/libsword.la
 
 SUBDIRS = cppunit
Index: utilities/Makefile.am
===================================================================
--- utilities/Makefile.am	(revision 2488)
+++ utilities/Makefile.am	(working copy)
@@ -1,6 +1,6 @@
 AUTOMAKE_OPTIONS = 1.6
 SUBDIRS = diatheke
-INCLUDES = -I $(top_srcdir)/include
+include $(top_srcdir)/include/Makefile.am
 LDADD = $(top_builddir)/lib/libsword.la
 noinst_PROGRAMS = cipherraw lexdump \
 stepdump step2vpl gbfidx modwrite addvs emptyvss \
