Andrew L. Moore
2017-10-17 11:11:07 UTC
Hi,
First of all, thank you for providing GNU gnulib,
I’m using the steps below to conditionally include gnulib regex
if either requested (i.e., by `configure —with-included-regex’)
or a system regex isn't found. The strategy is to hide
lib/regex.h until configure requests it. If there’s a better
way, I’d be interested to know and apologize if this
has been covered previously.
In configure.ac:
...
AC_MSG_CHECKING([whether included regex is requested])
AC_ARG_WITH([included-regex],
[AS_HELP_STRING([--with-included-regex],
[use GNU gnulib regex library included here])],[],
[with_included_regex=check])
AC_MSG_RESULT([$with_included_regex])
AS_IF([test ."$with_included_regex" != .'yes'],
[AC_CHECK_FUNCS([regcomp],[with_included_regex=no],
[AC_MSG_WARN([System regex not found, falling back to included version])
with_included_regex=yes])])
AM_CONDITIONAL([LIBADD_REGEX], [test ."$with_included_regex" = .'yes'])
AM_COND_IF([LIBADD_REGEX],
[AC_DEFINE([HAVE_REG_SYNTAX_T], [1],
[Define to 1 if regex.h defines `reg_syntax_t'.])],
[AC_CHECK_TYPES([reg_syntax_t],
[AC_DEFINE([HAVE_REG_SYNTAX_T], [1],
[Define to 1 if regex.h defines `reg_syntax_t'.])],[],
[[#include <sys/types.h>
#include <regex.h>]])])
gl_INIT
AM_CONDITIONAL([LDADD_LIBGNU],
[test ."$with_included_regex" = .'yes' || \
test ."$ac_cv_func_getopt_long_only" = .’yes’ || \
...])
…
Then lib/regex.h is renamed to lib/regex.h.in, and in lib/Makefile.am:
...
## begin gnulib module regex
if LIBADD_REGEX
BUILT_SOURCES += regex.h
DISTCLEANFILES += regex.h
AM_CPPFLAGS += -DRE_ENABLE_I18N=1 -D__USE_GNU=1
regex.h: regex.h.in
$(LN_S) $(top_srcdir)/lib/$@.in $@
endif LIBADD_REGEX
EXTRA_DIST = … regex.h.in …
…
Finally in src/Makefile.am:
...
if LDADD_LIBGNU
my_prog_LDADD += ../lib/libgnu.a
endif LDADD_LIBGNU
if LIBADD_REGEX
AM_CPPFLAGS += -DRE_ENABLE_I18N=1 -D__USE_GNU=1
endif
…
This appears to work well on GNU/Linux, BSD and Darwin,
with the caveat that before switching to an alternative regex,
it’s necessary to run `make distclean’.
-AM
First of all, thank you for providing GNU gnulib,
I’m using the steps below to conditionally include gnulib regex
if either requested (i.e., by `configure —with-included-regex’)
or a system regex isn't found. The strategy is to hide
lib/regex.h until configure requests it. If there’s a better
way, I’d be interested to know and apologize if this
has been covered previously.
In configure.ac:
...
AC_MSG_CHECKING([whether included regex is requested])
AC_ARG_WITH([included-regex],
[AS_HELP_STRING([--with-included-regex],
[use GNU gnulib regex library included here])],[],
[with_included_regex=check])
AC_MSG_RESULT([$with_included_regex])
AS_IF([test ."$with_included_regex" != .'yes'],
[AC_CHECK_FUNCS([regcomp],[with_included_regex=no],
[AC_MSG_WARN([System regex not found, falling back to included version])
with_included_regex=yes])])
AM_CONDITIONAL([LIBADD_REGEX], [test ."$with_included_regex" = .'yes'])
AM_COND_IF([LIBADD_REGEX],
[AC_DEFINE([HAVE_REG_SYNTAX_T], [1],
[Define to 1 if regex.h defines `reg_syntax_t'.])],
[AC_CHECK_TYPES([reg_syntax_t],
[AC_DEFINE([HAVE_REG_SYNTAX_T], [1],
[Define to 1 if regex.h defines `reg_syntax_t'.])],[],
[[#include <sys/types.h>
#include <regex.h>]])])
gl_INIT
AM_CONDITIONAL([LDADD_LIBGNU],
[test ."$with_included_regex" = .'yes' || \
test ."$ac_cv_func_getopt_long_only" = .’yes’ || \
...])
…
Then lib/regex.h is renamed to lib/regex.h.in, and in lib/Makefile.am:
...
## begin gnulib module regex
if LIBADD_REGEX
BUILT_SOURCES += regex.h
DISTCLEANFILES += regex.h
AM_CPPFLAGS += -DRE_ENABLE_I18N=1 -D__USE_GNU=1
regex.h: regex.h.in
$(LN_S) $(top_srcdir)/lib/$@.in $@
endif LIBADD_REGEX
EXTRA_DIST = … regex.h.in …
…
Finally in src/Makefile.am:
...
if LDADD_LIBGNU
my_prog_LDADD += ../lib/libgnu.a
endif LDADD_LIBGNU
if LIBADD_REGEX
AM_CPPFLAGS += -DRE_ENABLE_I18N=1 -D__USE_GNU=1
endif
…
This appears to work well on GNU/Linux, BSD and Darwin,
with the caveat that before switching to an alternative regex,
it’s necessary to run `make distclean’.
-AM