Compiling PCRE on non-Unix systems
----------------------------------

See below for comments on Cygwin or MinGW and OpenVMS usage. I (Philip Hazel)
have no knowledge of Windows or VMS sytems and how their libraries work. The
items in the PCRE Makefile that relate to anything other than Unix-like systems
have been contributed by PCRE users. There are some other comments and files in
the Contrib directory on the ftp site that you may find useful. See

  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib

If you want to compile PCRE for a non-Unix system (or perhaps, more strictly,
for a system that does not support "configure" and "make" files), note that
PCRE consists entirely of code written in Standard C, and so should compile
successfully on any system that has a Standard C compiler and library.


GENERIC INSTRUCTIONS FOR THE C LIBRARY

The following are generic comments about building PCRE. The interspersed
indented commands are suggestions from Mark Tetrode as to which commands you
might use on a Windows system to build a static library.

(1) Copy or rename the file config.in as config.h, and change the macros that
define HAVE_STRERROR and HAVE_MEMMOVE to define them as 1 rather than 0.
Unfortunately, because of the way Unix autoconf works, the default setting has
to be 0. You may also want to make changes to other macros in config.h. In
particular, if you want to force a specific value for newline, you can define
the NEWLINE macro. The default is to use '\n', thereby using whatever value
your compiler gives to '\n'.

  rem Mark Tetrode's commands
  copy config.in config.h
  rem Use write, because notepad cannot handle UNIX files. Change values.
  write config.h

(2) Copy or rename the file pcre.in as pcre.h, and change the macro definitions
for PCRE_MAJOR, PCRE_MINOR, and PCRE_DATE near its start to the values set in
configure.in.

  rem Mark Tetrode's commands
  copy pcre.in pcre.h
  rem Read values from configure.in
  write configure.in
  rem Change values
  write pcre.h

(3) Compile dftables.c as a stand-alone program, and then run it with
the single argument "pcre_chartables.c". This generates a set of standard
character tables and writes them to that file.

  rem Mark Tetrode's commands
  rem Compile & run
  cl -DSUPPORT_UTF8 -DSUPPORT_UCP dftables.c
  dftables.exe chartables.c

(4) Compile the following source files:

  pcre_chartables.c
  pcre_compile.c
  pcre_config.c
  pcre_dfa_exec.c
  pcre_exec.c
  pcre_fullinfo.c
  pcre_get.c
  pcre_globals.c
  pcre_info.c
  pcre_maketables.c
  pcre_ord2utf8.c
  pcre_printint.c
  pcre_refcount.c
  pcre_study.c
  pcre_tables.c
  pcre_try_flipped.c
  pcre_ucp_findchar.c
  pcre_valid_utf8.c
  pcre_version.c
  pcre_xclass.c

and link them all together into an object library in whichever form your system
keeps such libraries. This is the pcre C library. If your system has static and
shared libraries, you may have to do this once for each type.

  rem These comments are out-of-date, referring to a previous release which
  rem had fewer source files. Replace with the file names from above.
  rem Mark Tetrode's commands, for a static library
  rem Compile & lib
  cl -DSUPPORT_UTF8 -DSUPPORT_UCP -DPOSIX_MALLOC_THRESHOLD=10 /c maketables.c get.c study.c pcre.c
  lib /OUT:pcre.lib maketables.obj get.obj study.obj pcre.obj

(5) Similarly, compile pcreposix.c and link it (on its own) as the pcreposix
library.

  rem Mark Tetrode's commands, for a static library
  rem Compile & lib
  cl -DSUPPORT_UTF8 -DSUPPORT_UCP -DPOSIX_MALLOC_THRESHOLD=10 /c pcreposix.c
  lib /OUT:pcreposix.lib pcreposix.obj

(6) Compile the test program pcretest.c. This needs the functions in the
pcre and pcreposix libraries when linking.

  rem Mark Tetrode's commands
  rem compile & link
  cl /F0x400000 pcretest.c pcre.lib pcreposix.lib

(7) Run pcretest on the testinput files in the testdata directory, and check
that the output matches the corresponding testoutput files. You must use the
-i option when checking testinput2. Note that the supplied files are in Unix
format, with just LF characters as line terminators. You may need to edit them
to change this if your system uses a different convention.

  rem Mark Tetrode's commands
  pcretest testdata\testinput1 testdata\myoutput1
  windiff testdata\testoutput1 testdata\myoutput1
  pcretest -i testdata\testinput2 testdata\myoutput2
  windiff testdata\testoutput2 testdata\myoutput2
  pcretest testdata\testinput3 testdata\myoutput3
  windiff testdata\testoutput3 testdata\myoutput3
  pcretest testdata\testinput4 testdata\myoutput4
  windiff testdata\testoutput4 testdata\myoutput4
  pcretest testdata\testinput5 testdata\myoutput5
  windiff testdata\testoutput5 testdata\myoutput5
  pcretest testdata\testinput6 testdata\myoutput6
  windiff testdata\testoutput6 testdata\myoutput6

Note that there are now three more tests (7, 8, 9) that did not exist when Mark
wrote those comments. The test the new pcre_dfa_exec() function.


THE C++ WRAPPER FUNCTIONS

The PCRE distribution now contains some C++ wrapper functions and tests,
contributed by Google Inc. On a system that can use "configure" and "make",
the functions are automatically built into a library called pcrecpp. It should
be straightforward to compile the .cc files manually on other systems. The
files called xxx_unittest.cc are test programs for each of the corresponding
xxx.cc files.


FURTHER REMARKS

If you have a system without "configure" but where you can use a Makefile, edit
Makefile.in to create Makefile, substituting suitable values for the variables
at the head of the file.

Some help in building a Win32 DLL of PCRE in GnuWin32 environments was
contributed by Paul Sokolovsky. These environments are Mingw32
(http://www.xraylith.wisc.edu/~khan/software/gnu-win32/) and CygWin
(http://sourceware.cygnus.com/cygwin/). Paul comments:

  For CygWin, set CFLAGS=-mno-cygwin, and do 'make dll'. You'll get
  pcre.dll (containing pcreposix also), libpcre.dll.a, and dynamically
  linked pgrep and pcretest. If you have /bin/sh, run RunTest (three
  main test go ok, locale not supported).

Changes to do MinGW with autoconf 2.50 were supplied by Fred Cox
<sailorFred@yahoo.com>, who comments as follows:

  If you are using the PCRE DLL, the normal Unix style configure && make &&
  make check && make install should just work[*]. If you want to statically
  link against the .a file, you must define PCRE_STATIC before including
  pcre.h, otherwise the pcre_malloc and pcre_free exported functions will be
  declared __declspec(dllimport), with hilarious results.  See the configure.in
  and pcretest.c for how it is done for the static test.

  Also, there will only be a libpcre.la, not a libpcreposix.la, as you
  would expect from the Unix version. The single DLL includes the pcreposix
  interface.

[*] But note that the supplied test files are in Unix format, with just LF
characters as line terminators. You will have to edit them to change to CR LF
terminators.

A script for building PCRE using Borland's C++ compiler for use with VPASCAL
was contributed by Alexander Tokarev. It is called makevp.bat.

These are some further comments about Win32 builds from Mark Evans. They
were contributed before Fred Cox's changes were made, so it is possible that
they may no longer be relevant.

"The documentation for Win32 builds is a bit shy.  Under MSVC6 I
followed their instructions to the letter, but there were still
some things missing.

(1) Must #define STATIC for entire project if linking statically.
    (I see no reason to use DLLs for code this compact.)  This of
    course is a project setting in MSVC under Preprocessor.

(2) Missing some #ifdefs relating to the function pointers
    pcre_malloc and pcre_free.  See my solution below.  (The stubs
    may not be mandatory but they made me feel better.)"

=========================
#ifdef _WIN32
#include <malloc.h>

void* malloc_stub(size_t N)
{ return malloc(N); }
void free_stub(void* p)
{ free(p); }
void *(*pcre_malloc)(size_t) = &malloc_stub;
void  (*pcre_free)(void *) = &free_stub;

#else

void *(*pcre_malloc)(size_t) = malloc;
void  (*pcre_free)(void *) = free;

#endif
=========================


BUILDING PCRE ON OPENVMS

Dan Mooney sent the following comments about building PCRE on OpenVMS. They
relate to an older version of PCRE that used fewer source files, so the exact
commands will need changing. See the current list of source files above.

"It was quite easy to compile and link the library. I don't have a formal
make file but the attached file [reproduced below] contains the OpenVMS DCL
commands I used to build the library. I had to add #define
POSIX_MALLOC_THRESHOLD 10 to pcre.h since it was not defined anywhere.

The library was built on:
O/S: HP OpenVMS v7.3-1
Compiler: Compaq C v6.5-001-48BCD
Linker: vA13-01

The test results did not match 100% due to the issues you mention in your
documentation regarding isprint(), iscntrl(), isgraph() and ispunct(). I
modified some of the character tables temporarily and was able to get the
results to match. Tests using the fr locale did not match since I don't have
that locale loaded. The study size was always reported to be 3 less than the
value in the standard test output files."

=========================
$! This DCL procedure builds PCRE on OpenVMS
$!
$! I followed the instructions in the non-unix-use file in the distribution.
$!
$ COMPILE == "CC/LIST/NOMEMBER_ALIGNMENT/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES
$ COMPILE DFTABLES.C
$ LINK/EXE=DFTABLES.EXE DFTABLES.OBJ
$ RUN DFTABLES.EXE/OUTPUT=CHARTABLES.C
$ COMPILE MAKETABLES.C
$ COMPILE GET.C
$ COMPILE STUDY.C
$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
$! did not seem to be defined anywhere.
$! I edited pcre.h and added #DEFINE SUPPORT_UTF8 to enable UTF8 support.
$ COMPILE PCRE.C
$ LIB/CREATE PCRE MAKETABLES.OBJ, GET.OBJ, STUDY.OBJ, PCRE.OBJ
$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
$! did not seem to be defined anywhere.
$ COMPILE PCREPOSIX.C
$ LIB/CREATE PCREPOSIX PCREPOSIX.OBJ
$ COMPILE PCRETEST.C
$ LINK/EXE=PCRETEST.EXE PCRETEST.OBJ, PCRE/LIB, PCREPOSIX/LIB
$! C programs that want access to command line arguments must be
$! defined as a symbol
$ PCRETEST :== "$ SYS$ROADSUSERS:[DMOONEY.REGEXP]PCRETEST.EXE"
$! Arguments must be enclosed in quotes.
$ PCRETEST "-C"
$! Test results:
$!
$!   The test results did not match 100%. The functions isprint(), iscntrl(),
$!   isgraph() and ispunct() on OpenVMS must not produce the same results
$!   as the system that built the test output files provided with the
$!   distribution.
$!
$!   The study size did not match and was always 3 less on OpenVMS.
$!
$!   Locale could not be set to fr
$!
=========================

****
