• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2009 The RE2 Authors.  All Rights Reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file.
4
5# To build against ICU for full Unicode properties support,
6# uncomment the next two lines:
7# CCICU=$(shell pkg-config icu-uc --cflags) -DRE2_USE_ICU
8# LDICU=$(shell pkg-config icu-uc --libs)
9
10# To build against PCRE for testing or benchmarking,
11# uncomment the next two lines:
12# CCPCRE=-I/usr/local/include -DUSEPCRE
13# LDPCRE=-L/usr/local/lib -lpcre
14
15CXX?=g++
16# can override
17CXXFLAGS?=-O3 -g
18LDFLAGS?=
19# required
20RE2_CXXFLAGS?=-std=c++11 -pthread -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -I. $(CCICU) $(CCPCRE)
21RE2_LDFLAGS?=-pthread $(LDICU) $(LDPCRE)
22AR?=ar
23ARFLAGS?=rsc
24NM?=nm
25NMFLAGS?=-p
26
27# Variables mandated by GNU, the arbiter of all good taste on the internet.
28# http://www.gnu.org/prep/standards/standards.html
29prefix=/usr/local
30exec_prefix=$(prefix)
31includedir=$(prefix)/include
32libdir=$(exec_prefix)/lib
33INSTALL=install
34INSTALL_DATA=$(INSTALL) -m 644
35
36# Work around the weirdness of sed(1) on Darwin. :/
37ifeq ($(shell uname),Darwin)
38SED_INPLACE=sed -i ''
39else ifeq ($(shell uname),SunOS)
40SED_INPLACE=sed -i
41else
42SED_INPLACE=sed -i
43endif
44
45# ABI version
46# http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html
47SONAME=0
48
49# To rebuild the Tables generated by Perl and Python scripts (requires Internet
50# access for Unicode data), uncomment the following line:
51# REBUILD_TABLES=1
52
53# The SunOS linker does not support wildcards. :(
54ifeq ($(shell uname),Darwin)
55SOEXT=dylib
56SOEXTVER=$(SONAME).$(SOEXT)
57SOEXTVER00=$(SONAME).0.0.$(SOEXT)
58MAKE_SHARED_LIBRARY=$(CXX) -dynamiclib -Wl,-install_name,$(libdir)/libre2.$(SOEXTVER),-exported_symbols_list,libre2.symbols.darwin $(RE2_LDFLAGS) $(LDFLAGS)
59else ifeq ($(shell uname),SunOS)
60SOEXT=so
61SOEXTVER=$(SOEXT).$(SONAME)
62SOEXTVER00=$(SOEXT).$(SONAME).0.0
63MAKE_SHARED_LIBRARY=$(CXX) -shared -Wl,-soname,libre2.$(SOEXTVER) $(RE2_LDFLAGS) $(LDFLAGS)
64else
65SOEXT=so
66SOEXTVER=$(SOEXT).$(SONAME)
67SOEXTVER00=$(SOEXT).$(SONAME).0.0
68MAKE_SHARED_LIBRARY=$(CXX) -shared -Wl,-soname,libre2.$(SOEXTVER),--version-script,libre2.symbols $(RE2_LDFLAGS) $(LDFLAGS)
69endif
70
71all: obj/libre2.a obj/so/libre2.$(SOEXT)
72
73INSTALL_HFILES=\
74	re2/filtered_re2.h\
75	re2/re2.h\
76	re2/set.h\
77	re2/stringpiece.h\
78
79HFILES=\
80	util/benchmark.h\
81	util/flags.h\
82	util/logging.h\
83	util/malloc_counter.h\
84	util/mix.h\
85	util/mutex.h\
86	util/pcre.h\
87	util/strutil.h\
88	util/test.h\
89	util/utf.h\
90	util/util.h\
91	re2/bitmap256.h\
92	re2/filtered_re2.h\
93	re2/pod_array.h\
94	re2/prefilter.h\
95	re2/prefilter_tree.h\
96	re2/prog.h\
97	re2/re2.h\
98	re2/regexp.h\
99	re2/set.h\
100	re2/sparse_array.h\
101	re2/sparse_set.h\
102	re2/stringpiece.h\
103	re2/testing/exhaustive_tester.h\
104	re2/testing/regexp_generator.h\
105	re2/testing/string_generator.h\
106	re2/testing/tester.h\
107	re2/unicode_casefold.h\
108	re2/unicode_groups.h\
109	re2/walker-inl.h\
110
111OFILES=\
112	obj/util/rune.o\
113	obj/util/strutil.o\
114	obj/re2/bitstate.o\
115	obj/re2/compile.o\
116	obj/re2/dfa.o\
117	obj/re2/filtered_re2.o\
118	obj/re2/mimics_pcre.o\
119	obj/re2/nfa.o\
120	obj/re2/onepass.o\
121	obj/re2/parse.o\
122	obj/re2/perl_groups.o\
123	obj/re2/prefilter.o\
124	obj/re2/prefilter_tree.o\
125	obj/re2/prog.o\
126	obj/re2/re2.o\
127	obj/re2/regexp.o\
128	obj/re2/set.o\
129	obj/re2/simplify.o\
130	obj/re2/stringpiece.o\
131	obj/re2/tostring.o\
132	obj/re2/unicode_casefold.o\
133	obj/re2/unicode_groups.o\
134
135TESTOFILES=\
136	obj/util/pcre.o\
137	obj/re2/testing/backtrack.o\
138	obj/re2/testing/dump.o\
139	obj/re2/testing/exhaustive_tester.o\
140	obj/re2/testing/null_walker.o\
141	obj/re2/testing/regexp_generator.o\
142	obj/re2/testing/string_generator.o\
143	obj/re2/testing/tester.o\
144
145TESTS=\
146	obj/test/charclass_test\
147	obj/test/compile_test\
148	obj/test/filtered_re2_test\
149	obj/test/mimics_pcre_test\
150	obj/test/parse_test\
151	obj/test/possible_match_test\
152	obj/test/re2_test\
153	obj/test/re2_arg_test\
154	obj/test/regexp_test\
155	obj/test/required_prefix_test\
156	obj/test/search_test\
157	obj/test/set_test\
158	obj/test/simplify_test\
159	obj/test/string_generator_test\
160
161BIGTESTS=\
162	obj/test/dfa_test\
163	obj/test/exhaustive1_test\
164	obj/test/exhaustive2_test\
165	obj/test/exhaustive3_test\
166	obj/test/exhaustive_test\
167	obj/test/random_test\
168
169SOFILES=$(patsubst obj/%,obj/so/%,$(OFILES))
170# We use TESTOFILES for testing the shared lib, only it is built differently.
171STESTS=$(patsubst obj/%,obj/so/%,$(TESTS))
172SBIGTESTS=$(patsubst obj/%,obj/so/%,$(BIGTESTS))
173
174DOFILES=$(patsubst obj/%,obj/dbg/%,$(OFILES))
175DTESTOFILES=$(patsubst obj/%,obj/dbg/%,$(TESTOFILES))
176DTESTS=$(patsubst obj/%,obj/dbg/%,$(TESTS))
177DBIGTESTS=$(patsubst obj/%,obj/dbg/%,$(BIGTESTS))
178
179obj/%.o: %.cc $(HFILES)
180	@mkdir -p $$(dirname $@)
181	$(CXX) -c -o $@ $(CPPFLAGS) $(RE2_CXXFLAGS) $(CXXFLAGS) -DNDEBUG $*.cc
182
183obj/dbg/%.o: %.cc $(HFILES)
184	@mkdir -p $$(dirname $@)
185	$(CXX) -c -o $@ $(CPPFLAGS) $(RE2_CXXFLAGS) $(CXXFLAGS) $*.cc
186
187obj/so/%.o: %.cc $(HFILES)
188	@mkdir -p $$(dirname $@)
189	$(CXX) -c -o $@ -fPIC $(CPPFLAGS) $(RE2_CXXFLAGS) $(CXXFLAGS) -DNDEBUG $*.cc
190
191obj/libre2.a: $(OFILES)
192	@mkdir -p obj
193	$(AR) $(ARFLAGS) obj/libre2.a $(OFILES)
194
195obj/dbg/libre2.a: $(DOFILES)
196	@mkdir -p obj/dbg
197	$(AR) $(ARFLAGS) obj/dbg/libre2.a $(DOFILES)
198
199obj/so/libre2.$(SOEXT): $(SOFILES)
200	@mkdir -p obj/so
201	$(MAKE_SHARED_LIBRARY) -o obj/so/libre2.$(SOEXTVER) $(SOFILES)
202	ln -sf libre2.$(SOEXTVER) $@
203
204obj/dbg/test/%: obj/dbg/libre2.a obj/dbg/re2/testing/%.o $(DTESTOFILES) obj/dbg/util/test.o
205	@mkdir -p obj/dbg/test
206	$(CXX) -o $@ obj/dbg/re2/testing/$*.o $(DTESTOFILES) obj/dbg/util/test.o obj/dbg/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
207
208obj/test/%: obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/test.o
209	@mkdir -p obj/test
210	$(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
211
212# Test the shared lib, falling back to the static lib for private symbols
213obj/so/test/%: obj/so/libre2.$(SOEXT) obj/libre2.a obj/re2/testing/%.o $(TESTOFILES) obj/util/test.o
214	@mkdir -p obj/so/test
215	$(CXX) -o $@ obj/re2/testing/$*.o $(TESTOFILES) obj/util/test.o -Lobj/so -lre2 obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
216
217# Filter out dump.o because testing::TempDir() isn't available for it.
218obj/test/regexp_benchmark: obj/libre2.a obj/re2/testing/regexp_benchmark.o $(TESTOFILES) obj/util/benchmark.o
219	@mkdir -p obj/test
220	$(CXX) -o $@ obj/re2/testing/regexp_benchmark.o $(filter-out obj/re2/testing/dump.o, $(TESTOFILES)) obj/util/benchmark.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
221
222# re2_fuzzer is a target for fuzzers like libFuzzer and AFL. This fake fuzzing
223# is simply a way to check that the target builds and then to run it against a
224# fixed set of inputs. To perform real fuzzing, refer to the documentation for
225# libFuzzer (llvm.org/docs/LibFuzzer.html) and AFL (lcamtuf.coredump.cx/afl/).
226obj/test/re2_fuzzer: obj/libre2.a obj/re2/fuzzing/re2_fuzzer.o obj/util/fuzz.o
227	@mkdir -p obj/test
228	$(CXX) -o $@ obj/re2/fuzzing/re2_fuzzer.o obj/util/fuzz.o obj/libre2.a $(RE2_LDFLAGS) $(LDFLAGS)
229
230ifdef REBUILD_TABLES
231re2/perl_groups.cc: re2/make_perl_groups.pl
232	perl $< > $@
233
234re2/unicode_%.cc: re2/make_unicode_%.py
235	python $< > $@
236
237.PRECIOUS: re2/perl_groups.cc re2/unicode_casefold.cc re2/unicode_groups.cc
238endif
239
240distclean: clean
241	rm -f re2/perl_groups.cc re2/unicode_casefold.cc re2/unicode_groups.cc
242
243clean:
244	rm -rf obj
245	rm -f re2/*.pyc
246
247testofiles: $(TESTOFILES)
248
249test: $(DTESTS) $(TESTS) $(STESTS) debug-test static-test shared-test
250
251debug-test: $(DTESTS)
252	@./runtests $(DTESTS)
253
254static-test: $(TESTS)
255	@./runtests $(TESTS)
256
257shared-test: $(STESTS)
258	@./runtests -shared-library-path obj/so $(STESTS)
259
260debug-bigtest: $(DTESTS) $(DBIGTESTS)
261	@./runtests $(DTESTS) $(DBIGTESTS)
262
263static-bigtest: $(TESTS) $(BIGTESTS)
264	@./runtests $(TESTS) $(BIGTESTS)
265
266shared-bigtest: $(STESTS) $(SBIGTESTS)
267	@./runtests -shared-library-path obj/so $(STESTS) $(SBIGTESTS)
268
269benchmark: obj/test/regexp_benchmark
270
271fuzz: obj/test/re2_fuzzer
272
273install: obj/libre2.a obj/so/libre2.$(SOEXT)
274	mkdir -p $(DESTDIR)$(includedir)/re2 $(DESTDIR)$(libdir)/pkgconfig
275	$(INSTALL_DATA) $(INSTALL_HFILES) $(DESTDIR)$(includedir)/re2
276	$(INSTALL) obj/libre2.a $(DESTDIR)$(libdir)/libre2.a
277	$(INSTALL) obj/so/libre2.$(SOEXT) $(DESTDIR)$(libdir)/libre2.$(SOEXTVER00)
278	ln -sf libre2.$(SOEXTVER00) $(DESTDIR)$(libdir)/libre2.$(SOEXTVER)
279	ln -sf libre2.$(SOEXTVER00) $(DESTDIR)$(libdir)/libre2.$(SOEXT)
280	$(INSTALL_DATA) re2.pc $(DESTDIR)$(libdir)/pkgconfig/re2.pc
281	$(SED_INPLACE) -e "s#@includedir@#$(includedir)#" $(DESTDIR)$(libdir)/pkgconfig/re2.pc
282	$(SED_INPLACE) -e "s#@libdir@#$(libdir)#" $(DESTDIR)$(libdir)/pkgconfig/re2.pc
283
284testinstall: static-testinstall shared-testinstall
285	@echo
286	@echo Install tests passed.
287	@echo
288
289static-testinstall: CXXFLAGS:=-std=c++11 -pthread -I$(DESTDIR)$(includedir) $(CXXFLAGS)
290static-testinstall: LDFLAGS:=-pthread -L$(DESTDIR)$(libdir) -l:libre2.a $(LDICU) $(LDFLAGS)
291static-testinstall:
292	@mkdir -p obj
293	@cp testinstall.cc obj
294ifeq ($(shell uname),Darwin)
295	@echo Skipping test for libre2.a on Darwin.
296else ifeq ($(shell uname),SunOS)
297	@echo Skipping test for libre2.a on SunOS.
298else
299	(cd obj && $(CXX) testinstall.cc -o testinstall $(CXXFLAGS) $(LDFLAGS))
300	obj/testinstall
301endif
302
303shared-testinstall: CXXFLAGS:=-std=c++11 -pthread -I$(DESTDIR)$(includedir) $(CXXFLAGS)
304shared-testinstall: LDFLAGS:=-pthread -L$(DESTDIR)$(libdir) -lre2 $(LDICU) $(LDFLAGS)
305shared-testinstall:
306	@mkdir -p obj
307	@cp testinstall.cc obj
308	(cd obj && $(CXX) testinstall.cc -o testinstall $(CXXFLAGS) $(LDFLAGS))
309ifeq ($(shell uname),Darwin)
310	DYLD_LIBRARY_PATH="$(DESTDIR)$(libdir):$(DYLD_LIBRARY_PATH)" obj/testinstall
311else
312	LD_LIBRARY_PATH="$(DESTDIR)$(libdir):$(LD_LIBRARY_PATH)" obj/testinstall
313endif
314
315benchlog: obj/test/regexp_benchmark
316	(echo '==BENCHMARK==' `hostname` `date`; \
317	  (uname -a; $(CXX) --version; git rev-parse --short HEAD; file obj/test/regexp_benchmark) | sed 's/^/# /'; \
318	  echo; \
319	  ./obj/test/regexp_benchmark 'PCRE|RE2') | tee -a benchlog.$$(hostname | sed 's/\..*//')
320
321# Keep gmake from deleting intermediate files it creates.
322# This makes repeated builds faster and preserves debug info on OS X.
323
324.PRECIOUS: obj/%.o obj/dbg/%.o obj/so/%.o obj/libre2.a \
325	obj/dbg/libre2.a obj/so/libre2.a \
326	obj/test/% obj/so/test/% obj/dbg/test/%
327
328log:
329	$(MAKE) clean
330	$(MAKE) CXXFLAGS="$(CXXFLAGS) -DLOGGING=1" \
331		$(filter obj/test/exhaustive%_test,$(BIGTESTS))
332	echo '#' RE2 exhaustive tests built by make log >re2-exhaustive.txt
333	echo '#' $$(date) >>re2-exhaustive.txt
334	obj/test/exhaustive_test |grep -v '^PASS$$' >>re2-exhaustive.txt
335	obj/test/exhaustive1_test |grep -v '^PASS$$' >>re2-exhaustive.txt
336	obj/test/exhaustive2_test |grep -v '^PASS$$' >>re2-exhaustive.txt
337	obj/test/exhaustive3_test |grep -v '^PASS$$' >>re2-exhaustive.txt
338
339	$(MAKE) CXXFLAGS="$(CXXFLAGS) -DLOGGING=1" obj/test/search_test
340	echo '#' RE2 basic search tests built by make $@ >re2-search.txt
341	echo '#' $$(date) >>re2-search.txt
342	obj/test/search_test |grep -v '^PASS$$' >>re2-search.txt
343
344x: x.cc obj/libre2.a
345	g++ -I. -o x x.cc obj/libre2.a
346