1 |
Compiling PCRE on non-Unix systems
|
2 |
----------------------------------
|
3 |
|
4 |
This document contains the following sections:
|
5 |
|
6 |
General
|
7 |
Generic instructions for the PCRE C library
|
8 |
The C++ wrapper functions
|
9 |
Building for virtual Pascal
|
10 |
Stack size in Windows environments
|
11 |
Comments about Win32 builds
|
12 |
Building PCRE with CMake
|
13 |
Building under Windows with BCC5.5
|
14 |
Building PCRE on OpenVMS
|
15 |
|
16 |
|
17 |
GENERAL
|
18 |
|
19 |
I (Philip Hazel) have no experience of Windows or VMS sytems and how their
|
20 |
libraries work. The items in the PCRE distribution and Makefile that relate to
|
21 |
anything other than Unix-like systems are untested by me.
|
22 |
|
23 |
There are some other comments and files in the Contrib directory on the ftp
|
24 |
site that you may find useful. See
|
25 |
|
26 |
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib
|
27 |
|
28 |
If you want to compile PCRE for a non-Unix system (especially for a system that
|
29 |
does not support "configure" and "make" files), note that the basic PCRE
|
30 |
library consists entirely of code written in Standard C, and so should compile
|
31 |
successfully on any system that has a Standard C compiler and library. The C++
|
32 |
wrapper functions are a separate issue (see below).
|
33 |
|
34 |
The PCRE distribution includes support for CMake. This support is relatively
|
35 |
new, but has already been used successfully to build PCRE in multiple build
|
36 |
environments on Windows. There are some instructions in the section entitled
|
37 |
"Building PCRE with CMake" below.
|
38 |
|
39 |
|
40 |
GENERIC INSTRUCTIONS FOR THE PCRE C LIBRARY
|
41 |
|
42 |
The following are generic comments about building the PCRE C library "by hand".
|
43 |
|
44 |
(1) Copy or rename the file config.h.generic as config.h, and edit the macro
|
45 |
settings that it contains to whatever is appropriate for your environment.
|
46 |
In particular, if you want to force a specific value for newline, you can
|
47 |
define the NEWLINE macro. When you compile any of the PCRE modules, you
|
48 |
must specify -DHAVE_CONFIG_H to your compiler so that config.h is included
|
49 |
in the sources.
|
50 |
|
51 |
An alternative approach is not to edit config.h, but to use -D on the
|
52 |
compiler command line to make any changes that you need to the
|
53 |
configuration options. In this case -DHAVE_CONFIG_H must not be set.
|
54 |
|
55 |
NOTE: There have been occasions when the way in which certain parameters
|
56 |
in config.h are used has changed between releases. (In the configure/make
|
57 |
world, this is handled automatically.) When upgrading to a new release,
|
58 |
you are strongly advised to review config.h.generic before re-using what
|
59 |
you had previously.
|
60 |
|
61 |
(2) Copy or rename the file pcre.h.generic as pcre.h.
|
62 |
|
63 |
(3) EITHER:
|
64 |
Copy or rename file pcre_chartables.c.dist as pcre_chartables.c.
|
65 |
|
66 |
OR:
|
67 |
Compile dftables.c as a stand-alone program (using -DHAVE_CONFIG_H if
|
68 |
you have set up config.h), and then run it with the single argument
|
69 |
"pcre_chartables.c". This generates a set of standard character tables
|
70 |
and writes them to that file. The tables are generated using the default
|
71 |
C locale for your system. If you want to use a locale that is specified
|
72 |
by LC_xxx environment variables, add the -L option to the dftables
|
73 |
command. You must use this method if you are building on a system that
|
74 |
uses EBCDIC code.
|
75 |
|
76 |
The tables in pcre_chartables.c are defaults. The caller of PCRE can
|
77 |
specify alternative tables at run time.
|
78 |
|
79 |
(4) Ensure that you have the following header files:
|
80 |
|
81 |
pcre_internal.h
|
82 |
ucp.h
|
83 |
ucpinternal.h
|
84 |
ucptable.h
|
85 |
|
86 |
(5) Also ensure that you have the following file, which is #included as source
|
87 |
when building a debugging version of PCRE and is also used by pcretest.
|
88 |
|
89 |
pcre_printint.src
|
90 |
|
91 |
(6) Compile the following source files, setting -DHAVE_CONFIG_H as a compiler
|
92 |
option if you have set up config.h with your configuration, or else use
|
93 |
other -D settings to change the configuration as required.
|
94 |
|
95 |
pcre_chartables.c
|
96 |
pcre_compile.c
|
97 |
pcre_config.c
|
98 |
pcre_dfa_exec.c
|
99 |
pcre_exec.c
|
100 |
pcre_fullinfo.c
|
101 |
pcre_get.c
|
102 |
pcre_globals.c
|
103 |
pcre_info.c
|
104 |
pcre_maketables.c
|
105 |
pcre_newline.c
|
106 |
pcre_ord2utf8.c
|
107 |
pcre_refcount.c
|
108 |
pcre_study.c
|
109 |
pcre_tables.c
|
110 |
pcre_try_flipped.c
|
111 |
pcre_ucp_searchfuncs.c
|
112 |
pcre_valid_utf8.c
|
113 |
pcre_version.c
|
114 |
pcre_xclass.c
|
115 |
|
116 |
Make sure that you include -I. in the compiler command (or equivalent for
|
117 |
an unusual compiler) so that all included PCRE header files are first
|
118 |
sought in the current directory. Otherwise you run the risk of picking up
|
119 |
a previously-installed file from somewhere else.
|
120 |
|
121 |
(7) Now link all the compiled code into an object library in whichever form
|
122 |
your system keeps such libraries. This is the basic PCRE C library. If
|
123 |
your system has static and shared libraries, you may have to do this once
|
124 |
for each type.
|
125 |
|
126 |
(8) Similarly, compile pcreposix.c (remembering -DHAVE_CONFIG_H if necessary)
|
127 |
and link the result (on its own) as the pcreposix library.
|
128 |
|
129 |
(9) Compile the test program pcretest.c (again, don't forget -DHAVE_CONFIG_H).
|
130 |
This needs the functions in the pcre and pcreposix libraries when linking.
|
131 |
It also needs the pcre_printint.src source file, which it #includes.
|
132 |
|
133 |
(10) Run pcretest on the testinput files in the testdata directory, and check
|
134 |
that the output matches the corresponding testoutput files. Note that the
|
135 |
supplied files are in Unix format, with just LF characters as line
|
136 |
terminators. You may need to edit them to change this if your system uses
|
137 |
a different convention. If you are using Windows, you probably should use
|
138 |
the wintestinput3 file instead of testinput3 (and the corresponding output
|
139 |
file). This is a locale test; wintestinput3 sets the locale to "french"
|
140 |
rather than "fr_FR", and there some minor output differences.
|
141 |
|
142 |
(11) If you want to use the pcregrep command, compile and link pcregrep.c; it
|
143 |
uses only the basic PCRE library (it does not need the pcreposix library).
|
144 |
|
145 |
|
146 |
THE C++ WRAPPER FUNCTIONS
|
147 |
|
148 |
The PCRE distribution also contains some C++ wrapper functions and tests,
|
149 |
contributed by Google Inc. On a system that can use "configure" and "make",
|
150 |
the functions are automatically built into a library called pcrecpp. It should
|
151 |
be straightforward to compile the .cc files manually on other systems. The
|
152 |
files called xxx_unittest.cc are test programs for each of the corresponding
|
153 |
xxx.cc files.
|
154 |
|
155 |
|
156 |
BUILDING FOR VIRTUAL PASCAL
|
157 |
|
158 |
A script for building PCRE using Borland's C++ compiler for use with VPASCAL
|
159 |
was contributed by Alexander Tokarev. Stefan Weber updated the script and added
|
160 |
additional files. The following files in the distribution are for building PCRE
|
161 |
for use with VP/Borland: makevp_c.txt, makevp_l.txt, makevp.bat, pcregexp.pas.
|
162 |
|
163 |
|
164 |
STACK SIZE IN WINDOWS ENVIRONMENTS
|
165 |
|
166 |
The default processor stack size of 1Mb in some Windows environments is too
|
167 |
small for matching patterns that need much recursion. In particular, test 2 may
|
168 |
fail because of this. Normally, running out of stack causes a crash, but there
|
169 |
have been cases where the test program has just died silently. See your linker
|
170 |
documentation for how to increase stack size if you experience problems. The
|
171 |
Linux default of 8Mb is a reasonable choice for the stack, though even that can
|
172 |
be too small for some pattern/subject combinations.
|
173 |
|
174 |
PCRE has a compile configuration option to disable the use of stack for
|
175 |
recursion so that heap is used instead. However, pattern matching is
|
176 |
significantly slower when this is done. There is more about stack usage in the
|
177 |
"pcrestack" documentation.
|
178 |
|
179 |
|
180 |
COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE WITH CMAKE" below)
|
181 |
|
182 |
There are two ways of building PCRE using the "configure, make, make install"
|
183 |
paradigm on Windows systems: using MinGW or using Cygwin. These are not at all
|
184 |
the same thing; they are completely different from each other. There is also
|
185 |
some experimental, undocumented support for building using "cmake", which you
|
186 |
might like to try if you are familiar with "cmake". However, at the present
|
187 |
time, the "cmake" process builds only a static library (not a dll), and the
|
188 |
tests are not automatically run.
|
189 |
|
190 |
The MinGW home page (http://www.mingw.org/) says this:
|
191 |
|
192 |
MinGW: A collection of freely available and freely distributable Windows
|
193 |
specific header files and import libraries combined with GNU toolsets that
|
194 |
allow one to produce native Windows programs that do not rely on any
|
195 |
3rd-party C runtime DLLs.
|
196 |
|
197 |
The Cygwin home page (http://www.cygwin.com/) says this:
|
198 |
|
199 |
Cygwin is a Linux-like environment for Windows. It consists of two parts:
|
200 |
|
201 |
. A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing
|
202 |
substantial Linux API functionality
|
203 |
|
204 |
. A collection of tools which provide Linux look and feel.
|
205 |
|
206 |
The Cygwin DLL currently works with all recent, commercially released x86 32
|
207 |
bit and 64 bit versions of Windows, with the exception of Windows CE.
|
208 |
|
209 |
On both MinGW and Cygwin, PCRE should build correctly using:
|
210 |
|
211 |
./configure && make && make install
|
212 |
|
213 |
This should create two libraries called libpcre and libpcreposix, and, if you
|
214 |
have enabled building the C++ wrapper, a third one called libpcrecpp. These are
|
215 |
independent libraries: when you like with libpcreposix or libpcrecpp you must
|
216 |
also link with libpcre, which contains the basic functions. (Some earlier
|
217 |
releases of PCRE included the basic libpcre functions in libpcreposix. This no
|
218 |
longer happens.)
|
219 |
|
220 |
If you want to statically link your program against a non-dll .a file, you must
|
221 |
define PCRE_STATIC before including pcre.h, otherwise the pcre_malloc() and
|
222 |
pcre_free() exported functions will be declared __declspec(dllimport), with
|
223 |
unwanted results.
|
224 |
|
225 |
Using Cygwin's compiler generates libraries and executables that depend on
|
226 |
cygwin1.dll. If a library that is generated this way is distributed,
|
227 |
cygwin1.dll has to be distributed as well. Since cygwin1.dll is under the GPL
|
228 |
licence, this forces not only PCRE to be under the GPL, but also the entire
|
229 |
application. A distributor who wants to keep their own code proprietary must
|
230 |
purchase an appropriate Cygwin licence.
|
231 |
|
232 |
MinGW has no such restrictions. The MinGW compiler generates a library or
|
233 |
executable that can run standalone on Windows without any third party dll or
|
234 |
licensing issues.
|
235 |
|
236 |
But there is more complication:
|
237 |
|
238 |
If a Cygwin user uses the -mno-cygwin Cygwin gcc flag, what that really does is
|
239 |
to tell Cygwin's gcc to use the MinGW gcc. Cygwin's gcc is only acting as a
|
240 |
front end to MinGW's gcc (if you install Cygwin's gcc, you get both Cygwin's
|
241 |
gcc and MinGW's gcc). So, a user can:
|
242 |
|
243 |
. Build native binaries by using MinGW or by getting Cygwin and using
|
244 |
-mno-cygwin.
|
245 |
|
246 |
. Build binaries that depend on cygwin1.dll by using Cygwin with the normal
|
247 |
compiler flags.
|
248 |
|
249 |
The test files that are supplied with PCRE are in Unix format, with LF
|
250 |
characters as line terminators. It may be necessary to change the line
|
251 |
terminators in order to get some of the tests to work. We hope to improve
|
252 |
things in this area in future.
|
253 |
|
254 |
|
255 |
BUILDING PCRE WITH CMAKE
|
256 |
|
257 |
CMake is an alternative build facility that can be used instead of the
|
258 |
traditional Unix "configure". CMake version 2.4.7 supports Borland makefiles,
|
259 |
MinGW makefiles, MSYS makefiles, NMake makefiles, UNIX makefiles, Visual Studio
|
260 |
6, Visual Studio 7, Visual Studio 8, and Watcom W8. The following instructions
|
261 |
were contributed by a PCRE user.
|
262 |
|
263 |
1. Download CMake 2.4.7 or above from http://www.cmake.org/, install and ensure
|
264 |
that cmake\bin is on your path.
|
265 |
|
266 |
2. Unzip (retaining folder structure) the PCRE source tree into a source
|
267 |
directory such as C:\pcre.
|
268 |
|
269 |
3. Create a new, empty build directory: C:\pcre\build\
|
270 |
|
271 |
4. Run CMakeSetup from the Shell envirornment of your build tool, e.g., Msys
|
272 |
for Msys/MinGW or Visual Studio Command Prompt for VC/VC++
|
273 |
|
274 |
5. Enter C:\pcre\pcre-xx and C:\pcre\build for the source and build
|
275 |
directories, respectively
|
276 |
|
277 |
6. Hit the "Configure" button.
|
278 |
|
279 |
7. Select the particular IDE / build tool that you are using (Visual Studio,
|
280 |
MSYS makefiles, MinGW makefiles, etc.)
|
281 |
|
282 |
8. The GUI will then list several configuration options. This is where you can
|
283 |
enable UTF-8 support, etc.
|
284 |
|
285 |
9. Hit "Configure" again. The adjacent "OK" button should now be active.
|
286 |
|
287 |
10. Hit "OK".
|
288 |
|
289 |
11. The build directory should now contain a usable build system, be it a
|
290 |
solution file for Visual Studio, makefiles for MinGW, etc.
|
291 |
|
292 |
Testing with RunTest.bat
|
293 |
|
294 |
1. Copy RunTest.bat into the directory where pcretest.exe has been created.
|
295 |
|
296 |
2. Edit RunTest.bat and insert a line that indentifies the relative location of
|
297 |
the pcre source, e.g.:
|
298 |
|
299 |
set srcdir=..\pcre-7.4-RC3
|
300 |
|
301 |
3. Run RunTest.bat from a command shell environment. Test outputs will
|
302 |
automatically be compared to expected results, and discrepancies will
|
303 |
identified in the console output.
|
304 |
|
305 |
4. To test pcrecpp, run pcrecpp_unittest.exe, pcre_stringpiece_unittest.exe and
|
306 |
pcre_scanner_unittest.exe.
|
307 |
|
308 |
|
309 |
BUILDING UNDER WINDOWS WITH BCC5.5
|
310 |
|
311 |
Michael Roy sent these comments about building PCRE under Windows with BCC5.5:
|
312 |
|
313 |
Some of the core BCC libraries have a version of PCRE from 1998 built in,
|
314 |
which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a
|
315 |
version mismatch. I'm including an easy workaround below, if you'd like to
|
316 |
include it in the non-unix instructions:
|
317 |
|
318 |
When linking a project with BCC5.5, pcre.lib must be included before any of
|
319 |
the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command
|
320 |
line.
|
321 |
|
322 |
|
323 |
BUILDING PCRE ON OPENVMS
|
324 |
|
325 |
Dan Mooney sent the following comments about building PCRE on OpenVMS. They
|
326 |
relate to an older version of PCRE that used fewer source files, so the exact
|
327 |
commands will need changing. See the current list of source files above.
|
328 |
|
329 |
"It was quite easy to compile and link the library. I don't have a formal
|
330 |
make file but the attached file [reproduced below] contains the OpenVMS DCL
|
331 |
commands I used to build the library. I had to add #define
|
332 |
POSIX_MALLOC_THRESHOLD 10 to pcre.h since it was not defined anywhere.
|
333 |
|
334 |
The library was built on:
|
335 |
O/S: HP OpenVMS v7.3-1
|
336 |
Compiler: Compaq C v6.5-001-48BCD
|
337 |
Linker: vA13-01
|
338 |
|
339 |
The test results did not match 100% due to the issues you mention in your
|
340 |
documentation regarding isprint(), iscntrl(), isgraph() and ispunct(). I
|
341 |
modified some of the character tables temporarily and was able to get the
|
342 |
results to match. Tests using the fr locale did not match since I don't have
|
343 |
that locale loaded. The study size was always reported to be 3 less than the
|
344 |
value in the standard test output files."
|
345 |
|
346 |
=========================
|
347 |
$! This DCL procedure builds PCRE on OpenVMS
|
348 |
$!
|
349 |
$! I followed the instructions in the non-unix-use file in the distribution.
|
350 |
$!
|
351 |
$ COMPILE == "CC/LIST/NOMEMBER_ALIGNMENT/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES
|
352 |
$ COMPILE DFTABLES.C
|
353 |
$ LINK/EXE=DFTABLES.EXE DFTABLES.OBJ
|
354 |
$ RUN DFTABLES.EXE/OUTPUT=CHARTABLES.C
|
355 |
$ COMPILE MAKETABLES.C
|
356 |
$ COMPILE GET.C
|
357 |
$ COMPILE STUDY.C
|
358 |
$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
|
359 |
$! did not seem to be defined anywhere.
|
360 |
$! I edited pcre.h and added #DEFINE SUPPORT_UTF8 to enable UTF8 support.
|
361 |
$ COMPILE PCRE.C
|
362 |
$ LIB/CREATE PCRE MAKETABLES.OBJ, GET.OBJ, STUDY.OBJ, PCRE.OBJ
|
363 |
$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
|
364 |
$! did not seem to be defined anywhere.
|
365 |
$ COMPILE PCREPOSIX.C
|
366 |
$ LIB/CREATE PCREPOSIX PCREPOSIX.OBJ
|
367 |
$ COMPILE PCRETEST.C
|
368 |
$ LINK/EXE=PCRETEST.EXE PCRETEST.OBJ, PCRE/LIB, PCREPOSIX/LIB
|
369 |
$! C programs that want access to command line arguments must be
|
370 |
$! defined as a symbol
|
371 |
$ PCRETEST :== "$ SYS$ROADSUSERS:[DMOONEY.REGEXP]PCRETEST.EXE"
|
372 |
$! Arguments must be enclosed in quotes.
|
373 |
$ PCRETEST "-C"
|
374 |
$! Test results:
|
375 |
$!
|
376 |
$! The test results did not match 100%. The functions isprint(), iscntrl(),
|
377 |
$! isgraph() and ispunct() on OpenVMS must not produce the same results
|
378 |
$! as the system that built the test output files provided with the
|
379 |
$! distribution.
|
380 |
$!
|
381 |
$! The study size did not match and was always 3 less on OpenVMS.
|
382 |
$!
|
383 |
$! Locale could not be set to fr
|
384 |
$!
|
385 |
=========================
|
386 |
|
387 |
Last Updated: 21 September 2007
|
388 |
****
|