Skip to content

Commit 02bad4b

Browse files
erikbrinkmanwtlangford
authored andcommitted
Add local oniguruma submodule
Configure should still allow use of prebuilt onigurumas (whether system-installed or in a special prefix). If these are not found, and configure was not called with `--without-oniguruma`, then use the vendored oniguruma module. If configure was called with `--without-oniguruma`, then we do not build regex functionality into jq.
1 parent 9b21790 commit 02bad4b

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "modules/oniguruma"]
2+
path = modules/oniguruma
3+
url = https://github.com/kkos/oniguruma.git

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ matrix:
1919
addons:
2020
apt:
2121
packages:
22-
- libonig-dev
2322
- valgrind
2423
- bison
24+
- automake
2525

2626
before_install:
2727
- echo "$TRAVIS_OS_NAME"
2828
- uname -s
2929
- brew update || true;
3030
brew install flex || true;
3131
brew install bison || true;
32-
brew install oniguruma || true;
3332
- rm src/{lexer,parser}.{c,h}
33+
- sed -i.bak '/^AM_INIT_AUTOMAKE(\[-Wno-portability 1\.14\])$/s/14/11/' modules/oniguruma/configure.ac
3434

3535
install:
3636
- bundle install --gemfile=docs/Gemfile
@@ -46,7 +46,7 @@ before_script:
4646
- echo PATH=$PATH
4747
- which bison
4848
- bison --version
49-
- autoreconf -i
49+
- autoreconf -if
5050
- ./configure YACC="$(which bison) -y" $COVERAGE
5151

5252
script:

Makefile.am

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ AM_YFLAGS = --warnings=all -d
4848
lib_LTLIBRARIES = libjq.la
4949
libjq_la_SOURCES = ${LIBJQ_SRC}
5050
libjq_la_LIBADD = -lm
51-
libjq_la_LDFLAGS = -export-symbols-regex '^j[qv]_' -version-info 1:4:0
51+
libjq_la_LDFLAGS = $(onig_LDFLAGS) -export-symbols-regex '^j[qv]_' -version-info 1:4:0
5252

5353
if WIN32
5454
libjq_la_LIBADD += -lshlwapi
@@ -133,6 +133,15 @@ jq.1: $(srcdir)/jq.1.prebuilt
133133
endif
134134

135135

136+
### Build oniguruma
137+
138+
if BUILD_ONIGURUMA
139+
libjq_la_LIBADD += modules/oniguruma/src/.libs/libonig.la
140+
SUBDIRS = modules/oniguruma
141+
endif
142+
143+
AM_CFLAGS += $(onig_CFLAGS)
144+
136145
### Packaging
137146

138147
docs/site.yml: configure.ac

configure.ac

+35-29
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,6 @@ if test "$USE_MAINTAINER_MODE" = yes; then
4444
fi
4545
fi
4646

47-
48-
##########################################################################
49-
# check for ONIGURUMA library
50-
##########################################################################
51-
52-
AC_ARG_WITH([oniguruma],
53-
[AS_HELP_STRING([--with-oniguruma=prefix],
54-
[try this for a non-standard install prefix of the oniguruma library])],
55-
[],
56-
[with_oniguruma=yes])
57-
58-
AS_IF([test "x$with_oniguruma" != xno], [
59-
AS_IF([test "x$with_oniguruma" != xyes], [
60-
CFLAGS="$CFLAGS -I${with_oniguruma}/include"
61-
LDFLAGS="$LDFLAGS -L${with_oniguruma}/lib"
62-
])
63-
# check for ONIGURUMA library
64-
have_oniguruma=0
65-
AC_CHECK_HEADER("oniguruma.h",
66-
AC_CHECK_LIB([onig],[onig_version],[LIBS="$LIBS -lonig"; have_oniguruma=1;]))
67-
# handle check results
68-
AS_IF([test $have_oniguruma = 1], [
69-
AC_DEFINE([HAVE_ONIGURUMA], 1, [Define to 1 if Oniguruma is installed])
70-
], [
71-
AC_MSG_NOTICE([Oniguruma was not found.])
72-
AC_MSG_NOTICE([Try setting the location using '--with-oniguruma=PREFIX'])
73-
])
74-
])
75-
7647
dnl Check for valgrind
7748
AC_CHECK_PROGS(valgrind_cmd, valgrind)
7849
if test "x$valgrind_cmd" = "x" ; then
@@ -254,6 +225,41 @@ AC_C_BIGENDIAN(
254225
AC_MSG_ERROR(universial endianess not supported)
255226
)
256227

228+
dnl Oniguruma
229+
AC_ARG_WITH([oniguruma],
230+
[AS_HELP_STRING([--with-oniguruma=prefix],
231+
[try this for a non-standard install prefix of the oniguruma library])], ,
232+
[with_oniguruma=yes])
233+
234+
build_oniguruma=no
235+
AS_IF([test "x$with_oniguruma" != xno], [
236+
save_CFLAGS="$CFLAGS"
237+
save_LDFLAGS="$LDFLAGS"
238+
AS_IF([test "x$with_oniguruma" != xyes], [
239+
onig_CFLAGS="-I${with_oniguruma}/include"
240+
onig_LDFLAGS="-L${with_oniguruma}/lib"
241+
CFLAGS="$CFLAGS $onig_CFLAGS"
242+
LDFLAGS="$LDFLAGS $onig_LDFLAGS"
243+
])
244+
# check for ONIGURUMA library
245+
AC_CHECK_HEADER("oniguruma.h",
246+
AC_CHECK_LIB([onig],[onig_version]))
247+
CFLAGS="$save_CFLAGS"
248+
LDFLAGS="$save_LDFLAGS"
249+
250+
# handle check results
251+
AS_IF([test "x$ac_cv_lib_onig_onig_version" != "xyes"], [
252+
onig_CFLAGS="-I${srcdir}/modules/oniguruma/src"
253+
onig_LDFLAGS=
254+
AC_CONFIG_SUBDIRS([modules/oniguruma])
255+
build_oniguruma=yes
256+
AC_MSG_NOTICE([Oniguruma was not found. Will use the packaged oniguruma.])
257+
])
258+
AC_SUBST(onig_CFLAGS)
259+
AC_SUBST(onig_LDFLAGS)
260+
])
261+
262+
AM_CONDITIONAL([BUILD_ONIGURUMA], [test "x$build_oniguruma" = xyes])
257263
AC_SUBST([BUNDLER], ["$bundle_cmd"])
258264

259265
AC_CONFIG_MACRO_DIR([config/m4])

modules/oniguruma

Submodule oniguruma added at 4ab96b4

src/builtin.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void *alloca (size_t);
2929
#include <ctype.h>
3030
#include <limits.h>
3131
#include <math.h>
32-
#ifdef HAVE_ONIGURUMA
32+
#ifdef HAVE_LIBONIG
3333
#include <oniguruma.h>
3434
#endif
3535
#include <string.h>
@@ -697,7 +697,7 @@ static jv f_group_by_impl(jq_state *jq, jv input, jv keys) {
697697
}
698698
}
699699

700-
#ifdef HAVE_ONIGURUMA
700+
#ifdef HAVE_LIBONIG
701701
static int f_match_name_iter(const UChar* name, const UChar *name_end, int ngroups,
702702
int *groups, regex_t *reg, void *arg) {
703703
jv captures = *(jv*)arg;
@@ -901,11 +901,11 @@ static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
901901
jv_free(regex);
902902
return result;
903903
}
904-
#else /* ! HAVE_ONIGURUMA */
904+
#else /* !HAVE_LIBONIG */
905905
static jv f_match(jq_state *jq, jv input, jv regex, jv modifiers, jv testmode) {
906906
return jv_invalid_with_msg(jv_string("jq was compiled without ONIGURUMA regex libary. match/test/sub and related functions are not available."));
907907
}
908-
#endif /* HAVE_ONIGURUMA */
908+
#endif /* HAVE_LIBONIG */
909909

910910
static jv minmax_by(jv values, jv keys, int is_min) {
911911
if (jv_get_kind(values) != JV_KIND_ARRAY)

0 commit comments

Comments
 (0)