| 1 |
Compiling PCRE on non-Unix systems
|
| 2 |
----------------------------------
|
| 3 |
|
| 4 |
I (Philip Hazel) have no knowledge of Windows or VMS sytems and how their
|
| 5 |
libraries work. The items in the PCRE distribution and Makefile that relate to
|
| 6 |
anything other than Unix-like systems have been contributed by PCRE users and
|
| 7 |
are untested by me.
|
| 8 |
|
| 9 |
There are some other comments and files in the Contrib directory on the ftp
|
| 10 |
site that you may find useful, although a lot of them are now out-of-date. See
|
| 11 |
|
| 12 |
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib
|
| 13 |
|
| 14 |
If you want to compile PCRE for a non-Unix system (or perhaps, more strictly,
|
| 15 |
for a system that does not support "configure" and "make" files), note that
|
| 16 |
the basic PCRE library consists entirely of code written in Standard C, and so
|
| 17 |
should compile successfully on any system that has a Standard C compiler and
|
| 18 |
library. The C++ wrapper functions are a separate issue (see below).
|
| 19 |
|
| 20 |
|
| 21 |
GENERIC INSTRUCTIONS FOR THE C LIBRARY
|
| 22 |
|
| 23 |
The following are generic comments about building the PCRE C library "by hand".
|
| 24 |
|
| 25 |
(1) Copy or rename the file config.h.generic as config.h, and edit the macro
|
| 26 |
settings that it contains to whatever is appropriate for your environment.
|
| 27 |
In particular, if you want to force a specific value for newline, you can
|
| 28 |
define the NEWLINE macro.
|
| 29 |
|
| 30 |
An alternative approach is not to edit config.h, but to use -D on the
|
| 31 |
compiler command line to make any changes that you need.
|
| 32 |
|
| 33 |
(2) Copy or rename the file pcre.h.generic to pcre.h.
|
| 34 |
|
| 35 |
(3) Compile dftables.c as a stand-alone program, and then run it with
|
| 36 |
the single argument "pcre_chartables.c". This generates a set of standard
|
| 37 |
character tables and writes them to that file.
|
| 38 |
|
| 39 |
(4) Compile the following source files:
|
| 40 |
|
| 41 |
pcre_chartables.c
|
| 42 |
pcre_compile.c
|
| 43 |
pcre_config.c
|
| 44 |
pcre_dfa_exec.c
|
| 45 |
pcre_exec.c
|
| 46 |
pcre_fullinfo.c
|
| 47 |
pcre_get.c
|
| 48 |
pcre_globals.c
|
| 49 |
pcre_info.c
|
| 50 |
pcre_maketables.c
|
| 51 |
pcre_newline.c
|
| 52 |
pcre_ord2utf8.c
|
| 53 |
pcre_refcount.c
|
| 54 |
pcre_study.c
|
| 55 |
pcre_tables.c
|
| 56 |
pcre_try_flipped.c
|
| 57 |
pcre_ucp_searchfuncs.c
|
| 58 |
pcre_valid_utf8.c
|
| 59 |
pcre_version.c
|
| 60 |
pcre_xclass.c
|
| 61 |
|
| 62 |
Now link them all together into an object library in whichever form your
|
| 63 |
system keeps such libraries. This is the basic PCRE C library. If your
|
| 64 |
system has static and shared libraries, you may have to do this once for
|
| 65 |
each type.
|
| 66 |
|
| 67 |
(5) Similarly, compile pcreposix.c and link it (on its own) as the pcreposix
|
| 68 |
library.
|
| 69 |
|
| 70 |
(6) Compile the test program pcretest.c. This needs the functions in the
|
| 71 |
pcre and pcreposix libraries when linking.
|
| 72 |
|
| 73 |
(7) Run pcretest on the testinput files in the testdata directory, and check
|
| 74 |
that the output matches the corresponding testoutput files. Note that the
|
| 75 |
supplied files are in Unix format, with just LF characters as line
|
| 76 |
terminators. You may need to edit them to change this if your system uses a
|
| 77 |
different convention.
|
| 78 |
|
| 79 |
(8) If you want to use the pcregrep command, compile and link pcregrep.c; it
|
| 80 |
uses only the basic PCRE library (it does not need the pcreposix library).
|
| 81 |
|
| 82 |
|
| 83 |
THE C++ WRAPPER FUNCTIONS
|
| 84 |
|
| 85 |
The PCRE distribution also contains some C++ wrapper functions and tests,
|
| 86 |
contributed by Google Inc. On a system that can use "configure" and "make",
|
| 87 |
the functions are automatically built into a library called pcrecpp. It should
|
| 88 |
be straightforward to compile the .cc files manually on other systems. The
|
| 89 |
files called xxx_unittest.cc are test programs for each of the corresponding
|
| 90 |
xxx.cc files.
|
| 91 |
|
| 92 |
|
| 93 |
BUILDING FOR VIRTUAL PASCAL
|
| 94 |
|
| 95 |
Stefan Weber contributed the following files in the distribution for building
|
| 96 |
PCRE for use with VP/Borland: !compile.txt, !linklib.txt, makevp.bat,
|
| 97 |
pcregexp.pas.
|
| 98 |
|
| 99 |
|
| 100 |
BUILDING UNDER WINDOWS WITH BCC5.5
|
| 101 |
|
| 102 |
Michael Roy sent these comments about building PCRE under Windows with BCC5.5:
|
| 103 |
|
| 104 |
Some of the core BCC libraries have a version of PCRE from 1998 built in,
|
| 105 |
which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a
|
| 106 |
version mismatch. I'm including an easy workaround below, if you'd like to
|
| 107 |
include it in the non-unix instructions:
|
| 108 |
|
| 109 |
When linking a project with BCC5.5, pcre.lib must be included before any of
|
| 110 |
the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command
|
| 111 |
line.
|
| 112 |
|
| 113 |
|
| 114 |
OUT-OF-DATE COMMENTS ABOUT WIN32 BUILDS
|
| 115 |
|
| 116 |
[These comments need looking at by someone who knows about Windows.]
|
| 117 |
|
| 118 |
Some help in building a Win32 DLL of PCRE in GnuWin32 environments was
|
| 119 |
contributed by Paul Sokolovsky. These environments are Mingw32
|
| 120 |
(http://www.xraylith.wisc.edu/~khan/software/gnu-win32/) and CygWin
|
| 121 |
(http://sourceware.cygnus.com/cygwin/). Paul comments:
|
| 122 |
|
| 123 |
For CygWin, set CFLAGS=-mno-cygwin, and do 'make dll'. You'll get
|
| 124 |
pcre.dll (containing pcreposix also), libpcre.dll.a, and dynamically
|
| 125 |
linked pgrep and pcretest. If you have /bin/sh, run RunTest (three
|
| 126 |
main test go ok, locale not supported).
|
| 127 |
|
| 128 |
Changes to do MinGW with autoconf 2.50 were supplied by Fred Cox
|
| 129 |
<sailorFred@yahoo.com>, who comments as follows:
|
| 130 |
|
| 131 |
If you are using the PCRE DLL, the normal Unix style configure && make &&
|
| 132 |
make check && make install should just work[*]. If you want to statically
|
| 133 |
link against the .a file, you must define PCRE_STATIC before including
|
| 134 |
pcre.h, otherwise the pcre_malloc and pcre_free exported functions will be
|
| 135 |
declared __declspec(dllimport), with hilarious results. See the configure.in
|
| 136 |
and pcretest.c for how it is done for the static test.
|
| 137 |
|
| 138 |
Also, there will only be a libpcre.la, not a libpcreposix.la, as you
|
| 139 |
would expect from the Unix version. The single DLL includes the pcreposix
|
| 140 |
interface.
|
| 141 |
|
| 142 |
[*] But note that the supplied test files are in Unix format, with just LF
|
| 143 |
characters as line terminators. You will have to edit them to change to CR LF
|
| 144 |
terminators.
|
| 145 |
|
| 146 |
A script for building PCRE using Borland's C++ compiler for use with VPASCAL
|
| 147 |
was contributed by Alexander Tokarev. It is called makevp.bat.
|
| 148 |
|
| 149 |
These are some further comments about Win32 builds from Mark Evans. They
|
| 150 |
were contributed before Fred Cox's changes were made, so it is possible that
|
| 151 |
they may no longer be relevant.
|
| 152 |
|
| 153 |
"The documentation for Win32 builds is a bit shy. Under MSVC6 I
|
| 154 |
followed their instructions to the letter, but there were still
|
| 155 |
some things missing.
|
| 156 |
|
| 157 |
(1) Must #define STATIC for entire project if linking statically.
|
| 158 |
(I see no reason to use DLLs for code this compact.) This of
|
| 159 |
course is a project setting in MSVC under Preprocessor.
|
| 160 |
|
| 161 |
(2) Missing some #ifdefs relating to the function pointers
|
| 162 |
pcre_malloc and pcre_free. See my solution below. (The stubs
|
| 163 |
may not be mandatory but they made me feel better.)"
|
| 164 |
|
| 165 |
=========================
|
| 166 |
#ifdef _WIN32
|
| 167 |
#include <malloc.h>
|
| 168 |
|
| 169 |
void* malloc_stub(size_t N)
|
| 170 |
{ return malloc(N); }
|
| 171 |
void free_stub(void* p)
|
| 172 |
{ free(p); }
|
| 173 |
void *(*pcre_malloc)(size_t) = &malloc_stub;
|
| 174 |
void (*pcre_free)(void *) = &free_stub;
|
| 175 |
|
| 176 |
#else
|
| 177 |
|
| 178 |
void *(*pcre_malloc)(size_t) = malloc;
|
| 179 |
void (*pcre_free)(void *) = free;
|
| 180 |
|
| 181 |
#endif
|
| 182 |
=========================
|
| 183 |
|
| 184 |
|
| 185 |
BUILDING PCRE ON OPENVMS
|
| 186 |
|
| 187 |
Dan Mooney sent the following comments about building PCRE on OpenVMS. They
|
| 188 |
relate to an older version of PCRE that used fewer source files, so the exact
|
| 189 |
commands will need changing. See the current list of source files above.
|
| 190 |
|
| 191 |
"It was quite easy to compile and link the library. I don't have a formal
|
| 192 |
make file but the attached file [reproduced below] contains the OpenVMS DCL
|
| 193 |
commands I used to build the library. I had to add #define
|
| 194 |
POSIX_MALLOC_THRESHOLD 10 to pcre.h since it was not defined anywhere.
|
| 195 |
|
| 196 |
The library was built on:
|
| 197 |
O/S: HP OpenVMS v7.3-1
|
| 198 |
Compiler: Compaq C v6.5-001-48BCD
|
| 199 |
Linker: vA13-01
|
| 200 |
|
| 201 |
The test results did not match 100% due to the issues you mention in your
|
| 202 |
documentation regarding isprint(), iscntrl(), isgraph() and ispunct(). I
|
| 203 |
modified some of the character tables temporarily and was able to get the
|
| 204 |
results to match. Tests using the fr locale did not match since I don't have
|
| 205 |
that locale loaded. The study size was always reported to be 3 less than the
|
| 206 |
value in the standard test output files."
|
| 207 |
|
| 208 |
=========================
|
| 209 |
$! This DCL procedure builds PCRE on OpenVMS
|
| 210 |
$!
|
| 211 |
$! I followed the instructions in the non-unix-use file in the distribution.
|
| 212 |
$!
|
| 213 |
$ COMPILE == "CC/LIST/NOMEMBER_ALIGNMENT/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES
|
| 214 |
$ COMPILE DFTABLES.C
|
| 215 |
$ LINK/EXE=DFTABLES.EXE DFTABLES.OBJ
|
| 216 |
$ RUN DFTABLES.EXE/OUTPUT=CHARTABLES.C
|
| 217 |
$ COMPILE MAKETABLES.C
|
| 218 |
$ COMPILE GET.C
|
| 219 |
$ COMPILE STUDY.C
|
| 220 |
$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
|
| 221 |
$! did not seem to be defined anywhere.
|
| 222 |
$! I edited pcre.h and added #DEFINE SUPPORT_UTF8 to enable UTF8 support.
|
| 223 |
$ COMPILE PCRE.C
|
| 224 |
$ LIB/CREATE PCRE MAKETABLES.OBJ, GET.OBJ, STUDY.OBJ, PCRE.OBJ
|
| 225 |
$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
|
| 226 |
$! did not seem to be defined anywhere.
|
| 227 |
$ COMPILE PCREPOSIX.C
|
| 228 |
$ LIB/CREATE PCREPOSIX PCREPOSIX.OBJ
|
| 229 |
$ COMPILE PCRETEST.C
|
| 230 |
$ LINK/EXE=PCRETEST.EXE PCRETEST.OBJ, PCRE/LIB, PCREPOSIX/LIB
|
| 231 |
$! C programs that want access to command line arguments must be
|
| 232 |
$! defined as a symbol
|
| 233 |
$ PCRETEST :== "$ SYS$ROADSUSERS:[DMOONEY.REGEXP]PCRETEST.EXE"
|
| 234 |
$! Arguments must be enclosed in quotes.
|
| 235 |
$ PCRETEST "-C"
|
| 236 |
$! Test results:
|
| 237 |
$!
|
| 238 |
$! The test results did not match 100%. The functions isprint(), iscntrl(),
|
| 239 |
$! isgraph() and ispunct() on OpenVMS must not produce the same results
|
| 240 |
$! as the system that built the test output files provided with the
|
| 241 |
$! distribution.
|
| 242 |
$!
|
| 243 |
$! The study size did not match and was always 3 less on OpenVMS.
|
| 244 |
$!
|
| 245 |
$! Locale could not be set to fr
|
| 246 |
$!
|
| 247 |
=========================
|
| 248 |
|
| 249 |
****
|