i would like to use re2 from Python (preferrably Python 3.1) and was
excited to see files like ``make_unicode_groups.py`` in the distro.
those however were not deployed on my machine.
how can i use re2 from Python?
If you want to incorporate it into the main distribution, go ahead.
If not, that's fine too.
The following changes to Makefile allowed me to get as far as
importing this module
diff -r deb45325aab9 Makefile
--- a/Makefile Fri Mar 12 09:52:38 2010 -0800
+++ b/Makefile Tue Mar 16 22:22:33 2010 +0000
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
-all: obj/libre2.a
+all: obj/libre2.so obj/libre2.a
# to build against PCRE for testing or benchmarking,
# uncomment the next two lines
@@ -10,11 +10,14 @@
# LDPCRE=-L/usr/local/lib -lpcre
CC=g++
-CFLAGS=-c -Wall -Wno-sign-compare -O3 -g -I. $(CCPCRE)
+CFLAGS=-c -fPIC -Wall -Wno-sign-compare -O3 -g -I. $(CCPCRE)
AR=ar
ARFLAGS=rsc
NM=nm
NMFLAGS=-p
+LD=gcc
+LDFLAGS=-shared -o
+PREFIX=/usr/local
HFILES=\
util/arena.h\
@@ -114,6 +117,9 @@
@mkdir -p obj
$(AR) $(ARFLAGS) obj/libre2.a $(OFILES)
+obj/libre2.so: $(OFILES)
+ $(LD) $(LDFLAGS) obj/libre2.so $(OFILES)
+
obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/
test.o
@mkdir -p obj/test
$(CC) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o obj/
libre2.a -lpthread $(LDPCRE)
@@ -132,17 +138,20 @@
benchmark: obj/test/regexp_benchmark
-install: obj/libre2.a
- mkdir -p /usr/local/include/re2
- install -m 444 re2/re2.h /usr/local/include/re2/re2.h
- install -m 444 re2/stringpiece.h /usr/local/include/re2/
stringpiece.h
- install -m 444 re2/variadic_function.h /usr/local/include/re2/
variadic_function.h
- install -m 555 obj/libre2.a /usr/local/lib/libre2.a
+install: obj/libre2.a obj/libre2.so
+ mkdir -p $(PREFIX)/include/re2
+ mkdir -p $(PREFIX)/lib
+ install -m 444 re2/re2.h $(PREFIX)/include/re2/re2.h
+ install -m 444 re2/stringpiece.h $(PREFIX)/include/re2/stringpiece.h
+ install -m 444 re2/variadic_function.h $(PREFIX)/include/re2/
variadic_function.h
+ install -m 555 obj/libre2.a $(PREFIX)/lib/libre2.a
+ install -m 555 obj/libre2.so $(PREFIX)/lib/libre2.so
+ ldconfig
testinstall:
@mkdir -p obj
cp testinstall.cc obj
- (cd obj && g++ -I/usr/local/include testinstall.cc -lre2 -lpthread -
o testinstall)
+ (cd obj && g++ -I$(PREFIX)/include testinstall.cc -lre2 -lpthread -o
testinstall)
obj/testinstall
benchlog: obj/test/regexp_benchmark
I plan to, thanks for putting it together.
You might also want to pass the RE2::Quiet option
to the constructor, to silence the log prints like
re2/re2.cc:153: Error parsing '(foo': missing ): (foo
Russ
Good call. Done in latest master. It might be worth documenting that
the constructor doesn't keep a reference to the options. I had to
check the source to confirm that it was okay to use a temporary.