Compiling PCRE on non-Unix systems ---------------------------------- I (Philip Hazel) have no knowledge of Windows or VMS sytems and how their libraries work. The items in the PCRE distribution and Makefile that relate to anything other than Unix-like systems are untested by me. There are some other comments and files in the Contrib directory on the ftp site that you may find useful, although a lot of them are now out-of-date. 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 the basic PCRE library consists entirely of code written in Standard C, and so should compile successfully on any system that has a Standard C compiler and library. The C++ wrapper functions are a separate issue (see below). GENERIC INSTRUCTIONS FOR THE C LIBRARY The following are generic comments about building the PCRE C library "by hand". (1) Copy or rename the file config.h.generic as config.h, and edit the macro settings that it contains to whatever is appropriate for your environment. In particular, if you want to force a specific value for newline, you can define the NEWLINE macro. An alternative approach is not to edit config.h, but to use -D on the compiler command line to make any changes that you need. (2) Copy or rename the file pcre.h.generic as 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. (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_newline.c pcre_ord2utf8.c pcre_refcount.c pcre_study.c pcre_tables.c pcre_try_flipped.c pcre_ucp_searchfuncs.c pcre_valid_utf8.c pcre_version.c pcre_xclass.c Now link them all together into an object library in whichever form your system keeps such libraries. This is the basic PCRE C library. If your system has static and shared libraries, you may have to do this once for each type. (5) Similarly, compile pcreposix.c and link it (on its own) as the pcreposix library. (6) Compile the test program pcretest.c. This needs the functions in the pcre and pcreposix libraries when linking. (7) Run pcretest on the testinput files in the testdata directory, and check that the output matches the corresponding testoutput files. 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. (8) If you want to use the pcregrep command, compile and link pcregrep.c; it uses only the basic PCRE library (it does not need the pcreposix library). THE C++ WRAPPER FUNCTIONS The PCRE distribution also 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. BUILDING FOR VIRTUAL PASCAL Stefan Weber contributed the following files in the distribution for building PCRE for use with VP/Borland: !compile.txt, !linklib.txt, makevp.bat, pcregexp.pas. BUILDING UNDER WINDOWS WITH BCC5.5 Michael Roy sent these comments about building PCRE under Windows with BCC5.5: Some of the core BCC libraries have a version of PCRE from 1998 built in, which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a version mismatch. I'm including an easy workaround below, if you'd like to include it in the non-unix instructions: When linking a project with BCC5.5, pcre.lib must be included before any of the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command line. OUT-OF-DATE COMMENTS ABOUT WIN32 BUILDS [These comments need looking at by someone who knows about Windows.] 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 , 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 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 $! ========================= ****