1Building PCRE without using autotools 2------------------------------------- 3 4This 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 Linking programs in Windows environments 12 Comments about Win32 builds 13 Building PCRE on Windows with CMake 14 Use of relative paths with CMake on Windows 15 Testing with RunTest.bat 16 Building under Windows with BCC5.5 17 Building PCRE on OpenVMS 18 Building PCRE on Stratus OpenVOS 19 20 21GENERAL 22 23I (Philip Hazel) have no experience of Windows or VMS sytems and how their 24libraries work. The items in the PCRE distribution and Makefile that relate to 25anything other than Linux systems are untested by me. 26 27There are some other comments and files (including some documentation in CHM 28format) in the Contrib directory on the FTP site: 29 30 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib 31 32The basic PCRE library consists entirely of code written in Standard C, and so 33should compile successfully on any system that has a Standard C compiler and 34library. The C++ wrapper functions are a separate issue (see below). 35 36The PCRE distribution includes a "configure" file for use by the configure/make 37(autotools) build system, as found in many Unix-like environments. The README 38file contains information about the options for "configure". 39 40There is also support for CMake, which some users prefer, especially in Windows 41environments, though it can also be run in Unix-like environments. See the 42section entitled "Building PCRE on Windows with CMake" below. 43 44Versions of config.h and pcre.h are distributed in the PCRE tarballs under the 45names config.h.generic and pcre.h.generic. These are provided for those who 46build PCRE without using "configure" or CMake. If you use "configure" or CMake, 47the .generic versions are not used. 48 49 50GENERIC INSTRUCTIONS FOR THE PCRE C LIBRARY 51 52The following are generic instructions for building the PCRE C library "by 53hand": 54 55 (1) Copy or rename the file config.h.generic as config.h, and edit the macro 56 settings that it contains to whatever is appropriate for your environment. 57 In particular, if you want to force a specific value for newline, you can 58 define the NEWLINE macro. When you compile any of the PCRE modules, you 59 must specify -DHAVE_CONFIG_H to your compiler so that config.h is included 60 in the sources. 61 62 An alternative approach is not to edit config.h, but to use -D on the 63 compiler command line to make any changes that you need to the 64 configuration options. In this case -DHAVE_CONFIG_H must not be set. 65 66 NOTE: There have been occasions when the way in which certain parameters 67 in config.h are used has changed between releases. (In the configure/make 68 world, this is handled automatically.) When upgrading to a new release, 69 you are strongly advised to review config.h.generic before re-using what 70 you had previously. 71 72 (2) Copy or rename the file pcre.h.generic as pcre.h. 73 74 (3) EITHER: 75 Copy or rename file pcre_chartables.c.dist as pcre_chartables.c. 76 77 OR: 78 Compile dftables.c as a stand-alone program (using -DHAVE_CONFIG_H if 79 you have set up config.h), and then run it with the single argument 80 "pcre_chartables.c". This generates a set of standard character tables 81 and writes them to that file. The tables are generated using the default 82 C locale for your system. If you want to use a locale that is specified 83 by LC_xxx environment variables, add the -L option to the dftables 84 command. You must use this method if you are building on a system that 85 uses EBCDIC code. 86 87 The tables in pcre_chartables.c are defaults. The caller of PCRE can 88 specify alternative tables at run time. 89 90 (4) Ensure that you have the following header files: 91 92 pcre_internal.h 93 ucp.h 94 95 (5) For an 8-bit library, compile the following source files, setting 96 -DHAVE_CONFIG_H as a compiler option if you have set up config.h with your 97 configuration, or else use other -D settings to change the configuration 98 as required. 99 100 pcre_byte_order.c 101 pcre_chartables.c 102 pcre_compile.c 103 pcre_config.c 104 pcre_dfa_exec.c 105 pcre_exec.c 106 pcre_fullinfo.c 107 pcre_get.c 108 pcre_globals.c 109 pcre_maketables.c 110 pcre_newline.c 111 pcre_ord2utf8.c 112 pcre_refcount.c 113 pcre_string_utils.c 114 pcre_study.c 115 pcre_tables.c 116 pcre_ucd.c 117 pcre_valid_utf8.c 118 pcre_version.c 119 pcre_xclass.c 120 121 Make sure that you include -I. in the compiler command (or equivalent for 122 an unusual compiler) so that all included PCRE header files are first 123 sought in the current directory. Otherwise you run the risk of picking up 124 a previously-installed file from somewhere else. 125 126 (6) If you have defined SUPPORT_JIT in config.h, you must also compile 127 128 pcre_jit_compile.c 129 130 This file #includes sources from the sljit subdirectory, where there 131 should be 16 files, all of whose names begin with "sljit". 132 133 (7) Now link all the compiled code into an object library in whichever form 134 your system keeps such libraries. This is the basic PCRE C 8-bit library. 135 If your system has static and shared libraries, you may have to do this 136 once for each type. 137 138 (8) If you want to build a 16-bit library (as well as, or instead of the 8-bit 139 library) repeat steps 5-7 with the following files: 140 141 pcre16_byte_order.c 142 pcre16_chartables.c 143 pcre16_compile.c 144 pcre16_config.c 145 pcre16_dfa_exec.c 146 pcre16_exec.c 147 pcre16_fullinfo.c 148 pcre16_get.c 149 pcre16_globals.c 150 pcre16_jit_compile.c (if SUPPORT_JIT is defined) 151 pcre16_maketables.c 152 pcre16_newline.c 153 pcre16_ord2utf16.c 154 pcre16_refcount.c 155 pcre16_string_utils.c 156 pcre16_study.c 157 pcre16_tables.c 158 pcre16_ucd.c 159 pcre16_utf16_utils.c 160 pcre16_valid_utf16.c 161 pcre16_version.c 162 pcre16_xclass.c 163 164 (9) If you want to build the POSIX wrapper functions (which apply only to the 165 8-bit library), ensure that you have the pcreposix.h file and then compile 166 pcreposix.c (remembering -DHAVE_CONFIG_H if necessary). Link the result 167 (on its own) as the pcreposix library. 168 169(10) The pcretest program can be linked with either or both of the 8-bit and 170 16-bit libraries (depending on what you selected in config.h). Compile 171 pcretest.c and pcre_printint.c (again, don't forget -DHAVE_CONFIG_H) and 172 link them together with the appropriate library/ies. If you compiled an 173 8-bit library, pcretest also needs the pcreposix wrapper library unless 174 you compiled it with -DNOPOSIX. 175 176(11) Run pcretest on the testinput files in the testdata directory, and check 177 that the output matches the corresponding testoutput files. There are 178 comments about what each test does in the section entitled "Testing PCRE" 179 in the README file. If you compiled both an 8-bit and a 16-bit library, 180 you need to run pcretest with the -16 option to do 16-bit tests. 181 182 Some tests are relevant only when certain build-time options are selected. 183 For example, test 4 is for UTF-8 or UTF-16 support, and will not run if 184 you have built PCRE without it. See the comments at the start of each 185 testinput file. If you have a suitable Unix-like shell, the RunTest script 186 will run the appropriate tests for you. 187 188 Note that the supplied files are in Unix format, with just LF characters 189 as line terminators. You may need to edit them to change this if your 190 system uses a different convention. If you are using Windows, you probably 191 should use the wintestinput3 file instead of testinput3 (and the 192 corresponding output file). This is a locale test; wintestinput3 sets the 193 locale to "french" rather than "fr_FR", and there some minor output 194 differences. 195 196(12) If you have built PCRE with SUPPORT_JIT, the JIT features will be tested 197 by the testdata files. However, you might also like to build and run 198 the JIT test program, pcre_jit_test.c. 199 200(13) If you want to use the pcregrep command, compile and link pcregrep.c; it 201 uses only the basic 8-bit PCRE library (it does not need the pcreposix 202 library). 203 204 205THE C++ WRAPPER FUNCTIONS 206 207The PCRE distribution also contains some C++ wrapper functions and tests, 208applicable to the 8-bit library, which were contributed by Google Inc. On a 209system that can use "configure" and "make", the functions are automatically 210built into a library called pcrecpp. It should be straightforward to compile 211the .cc files manually on other systems. The files called xxx_unittest.cc are 212test programs for each of the corresponding xxx.cc files. 213 214 215BUILDING FOR VIRTUAL PASCAL 216 217A script for building PCRE using Borland's C++ compiler for use with VPASCAL 218was contributed by Alexander Tokarev. Stefan Weber updated the script and added 219additional files. The following files in the distribution are for building PCRE 220for use with VP/Borland: makevp_c.txt, makevp_l.txt, makevp.bat, pcregexp.pas. 221 222 223STACK SIZE IN WINDOWS ENVIRONMENTS 224 225The default processor stack size of 1Mb in some Windows environments is too 226small for matching patterns that need much recursion. In particular, test 2 may 227fail because of this. Normally, running out of stack causes a crash, but there 228have been cases where the test program has just died silently. See your linker 229documentation for how to increase stack size if you experience problems. The 230Linux default of 8Mb is a reasonable choice for the stack, though even that can 231be too small for some pattern/subject combinations. 232 233PCRE has a compile configuration option to disable the use of stack for 234recursion so that heap is used instead. However, pattern matching is 235significantly slower when this is done. There is more about stack usage in the 236"pcrestack" documentation. 237 238 239LINKING PROGRAMS IN WINDOWS ENVIRONMENTS 240 241If you want to statically link a program against a PCRE library in the form of 242a non-dll .a file, you must define PCRE_STATIC before including pcre.h or 243pcrecpp.h, otherwise the pcre_malloc() and pcre_free() exported functions will 244be declared __declspec(dllimport), with unwanted results. 245 246 247CALLING CONVENTIONS IN WINDOWS ENVIRONMENTS 248 249It is possible to compile programs to use different calling conventions using 250MSVC. Search the web for "calling conventions" for more information. To make it 251easier to change the calling convention for the exported functions in the 252PCRE library, the macro PCRE_CALL_CONVENTION is present in all the external 253definitions. It can be set externally when compiling (e.g. in CFLAGS). If it is 254not set, it defaults to empty; the default calling convention is then used 255(which is what is wanted most of the time). 256 257 258COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE ON WINDOWS WITH CMAKE") 259 260There are two ways of building PCRE using the "configure, make, make install" 261paradigm on Windows systems: using MinGW or using Cygwin. These are not at all 262the same thing; they are completely different from each other. There is also 263support for building using CMake, which some users find a more straightforward 264way of building PCRE under Windows. 265 266The MinGW home page (http://www.mingw.org/) says this: 267 268 MinGW: A collection of freely available and freely distributable Windows 269 specific header files and import libraries combined with GNU toolsets that 270 allow one to produce native Windows programs that do not rely on any 271 3rd-party C runtime DLLs. 272 273The Cygwin home page (http://www.cygwin.com/) says this: 274 275 Cygwin is a Linux-like environment for Windows. It consists of two parts: 276 277 . A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing 278 substantial Linux API functionality 279 280 . A collection of tools which provide Linux look and feel. 281 282 The Cygwin DLL currently works with all recent, commercially released x86 32 283 bit and 64 bit versions of Windows, with the exception of Windows CE. 284 285On both MinGW and Cygwin, PCRE should build correctly using: 286 287 ./configure && make && make install 288 289This should create two libraries called libpcre and libpcreposix, and, if you 290have enabled building the C++ wrapper, a third one called libpcrecpp. These are 291independent libraries: when you link with libpcreposix or libpcrecpp you must 292also link with libpcre, which contains the basic functions. (Some earlier 293releases of PCRE included the basic libpcre functions in libpcreposix. This no 294longer happens.) 295 296A user submitted a special-purpose patch that makes it easy to create 297"pcre.dll" under mingw32 using the "msys" environment. It provides "pcre.dll" 298as a special target. If you use this target, no other files are built, and in 299particular, the pcretest and pcregrep programs are not built. An example of how 300this might be used is: 301 302 ./configure --enable-utf --disable-cpp CFLAGS="-03 -s"; make pcre.dll 303 304Using Cygwin's compiler generates libraries and executables that depend on 305cygwin1.dll. If a library that is generated this way is distributed, 306cygwin1.dll has to be distributed as well. Since cygwin1.dll is under the GPL 307licence, this forces not only PCRE to be under the GPL, but also the entire 308application. A distributor who wants to keep their own code proprietary must 309purchase an appropriate Cygwin licence. 310 311MinGW has no such restrictions. The MinGW compiler generates a library or 312executable that can run standalone on Windows without any third party dll or 313licensing issues. 314 315But there is more complication: 316 317If a Cygwin user uses the -mno-cygwin Cygwin gcc flag, what that really does is 318to tell Cygwin's gcc to use the MinGW gcc. Cygwin's gcc is only acting as a 319front end to MinGW's gcc (if you install Cygwin's gcc, you get both Cygwin's 320gcc and MinGW's gcc). So, a user can: 321 322. Build native binaries by using MinGW or by getting Cygwin and using 323 -mno-cygwin. 324 325. Build binaries that depend on cygwin1.dll by using Cygwin with the normal 326 compiler flags. 327 328The test files that are supplied with PCRE are in UNIX format, with LF 329characters as line terminators. Unless your PCRE library uses a default newline 330option that includes LF as a valid newline, it may be necessary to change the 331line terminators in the test files to get some of the tests to work. 332 333 334BUILDING PCRE ON WINDOWS WITH CMAKE 335 336CMake is an alternative configuration facility that can be used instead of 337"configure". CMake creates project files (make files, solution files, etc.) 338tailored to numerous development environments, including Visual Studio, 339Borland, Msys, MinGW, NMake, and Unix. If possible, use short paths with no 340spaces in the names for your CMake installation and your PCRE source and build 341directories. 342 343The following instructions were contributed by a PCRE user. 344 3451. Install the latest CMake version available from http://www.cmake.org/, and 346 ensure that cmake\bin is on your path. 347 3482. Unzip (retaining folder structure) the PCRE source tree into a source 349 directory such as C:\pcre. You should ensure your local date and time 350 is not earlier than the file dates in your source dir if the release is 351 very new. 352 3533. Create a new, empty build directory, preferably a subdirectory of the 354 source dir. For example, C:\pcre\pcre-xx\build. 355 3564. Run cmake-gui from the Shell envirornment of your build tool, for example, 357 Msys for Msys/MinGW or Visual Studio Command Prompt for VC/VC++. 358 3595. Enter C:\pcre\pcre-xx and C:\pcre\pcre-xx\build for the source and build 360 directories, respectively. 361 3626. Hit the "Configure" button. 363 3647. Select the particular IDE / build tool that you are using (Visual 365 Studio, MSYS makefiles, MinGW makefiles, etc.) 366 3678. The GUI will then list several configuration options. This is where 368 you can enable UTF-8 support or other PCRE optional features. 369 3709. Hit "Configure" again. The adjacent "Generate" button should now be 371 active. 372 37310. Hit "Generate". 374 37511. The build directory should now contain a usable build system, be it a 376 solution file for Visual Studio, makefiles for MinGW, etc. Exit from 377 cmake-gui and use the generated build system with your compiler or IDE. 378 E.g., for MinGW you can run "make", or for Visual Studio, open the PCRE 379 solution, select the desired configuration (Debug, or Release, etc.) and 380 build the ALL_BUILD project. 381 38212. If during configuration with cmake-gui you've elected to build the test 383 programs, you can execute them by building the test project. E.g., for 384 MinGW: "make test"; for Visual Studio build the RUN_TESTS project. The 385 most recent build configuration is targeted by the tests. A summary of 386 test results is presented. Complete test output is subsequently 387 available for review in Testing\Temporary under your build dir. 388 389 390USE OF RELATIVE PATHS WITH CMAKE ON WINDOWS 391 392A PCRE user comments as follows: 393 394I thought that others may want to know the current state of 395CMAKE_USE_RELATIVE_PATHS support on Windows. 396 397Here it is: 398-- AdditionalIncludeDirectories is only partially modified (only the 399first path - see below) 400-- Only some of the contained file paths are modified - shown below for 401pcre.vcproj 402-- It properly modifies 403 404I am sure CMake people can fix that if they want to. Until then one will 405need to replace existing absolute paths in project files with relative 406paths manually (e.g. from VS) - relative to project file location. I did 407just that before being told to try CMAKE_USE_RELATIVE_PATHS. Not a big 408deal. 409 410AdditionalIncludeDirectories="E:\builds\pcre\build;E:\builds\pcre\pcre-7.5;" 411AdditionalIncludeDirectories=".;E:\builds\pcre\pcre-7.5;" 412 413RelativePath="pcre.h"> 414RelativePath="pcre_chartables.c"> 415RelativePath="pcre_chartables.c.rule"> 416 417 418TESTING WITH RUNTEST.BAT 419 420If configured with CMake, building the test project ("make test" or building 421ALL_TESTS in Visual Studio) creates (and runs) pcre_test.bat (and depending 422on your configuration options, possibly other test programs) in the build 423directory. Pcre_test.bat runs RunTest.Bat with correct source and exe paths. 424 425For manual testing with RunTest.bat, provided the build dir is a subdirectory 426of the source directory: Open command shell window. Chdir to the location 427of your pcretest.exe and pcregrep.exe programs. Call RunTest.bat with 428"..\RunTest.Bat" or "..\..\RunTest.bat" as appropriate. 429 430To run only a particular test with RunTest.Bat provide a test number argument. 431 432Otherwise: 433 4341. Copy RunTest.bat into the directory where pcretest.exe and pcregrep.exe 435 have been created. 436 4372. Edit RunTest.bat to indentify the full or relative location of 438 the pcre source (wherein which the testdata folder resides), e.g.: 439 440 set srcdir=C:\pcre\pcre-8.20 441 4423. In a Windows command environment, chdir to the location of your bat and 443 exe programs. 444 4454. Run RunTest.bat. Test outputs will automatically be compared to expected 446 results, and discrepancies will be identified in the console output. 447 448To independently test the just-in-time compiler, run pcre_jit_test.exe. 449To test pcrecpp, run pcrecpp_unittest.exe, pcre_stringpiece_unittest.exe and 450pcre_scanner_unittest.exe. 451 452 453BUILDING UNDER WINDOWS WITH BCC5.5 454 455Michael Roy sent these comments about building PCRE under Windows with BCC5.5: 456 457 Some of the core BCC libraries have a version of PCRE from 1998 built in, 458 which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a 459 version mismatch. I'm including an easy workaround below, if you'd like to 460 include it in the non-unix instructions: 461 462 When linking a project with BCC5.5, pcre.lib must be included before any of 463 the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command 464 line. 465 466 467BUILDING UNDER WINDOWS CE WITH VISUAL STUDIO 200x 468 469Vincent Richomme sent a zip archive of files to help with this process. They 470can be found in the file "pcre-vsbuild.zip" in the Contrib directory of the FTP 471site. 472 473 474BUILDING PCRE ON OPENVMS 475 476Dan Mooney sent the following comments about building PCRE on OpenVMS. They 477relate to an older version of PCRE that used fewer source files, so the exact 478commands will need changing. See the current list of source files above. 479 480"It was quite easy to compile and link the library. I don't have a formal 481make file but the attached file [reproduced below] contains the OpenVMS DCL 482commands I used to build the library. I had to add #define 483POSIX_MALLOC_THRESHOLD 10 to pcre.h since it was not defined anywhere. 484 485The library was built on: 486O/S: HP OpenVMS v7.3-1 487Compiler: Compaq C v6.5-001-48BCD 488Linker: vA13-01 489 490The test results did not match 100% due to the issues you mention in your 491documentation regarding isprint(), iscntrl(), isgraph() and ispunct(). I 492modified some of the character tables temporarily and was able to get the 493results to match. Tests using the fr locale did not match since I don't have 494that locale loaded. The study size was always reported to be 3 less than the 495value in the standard test output files." 496 497========================= 498$! This DCL procedure builds PCRE on OpenVMS 499$! 500$! I followed the instructions in the non-unix-use file in the distribution. 501$! 502$ COMPILE == "CC/LIST/NOMEMBER_ALIGNMENT/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES 503$ COMPILE DFTABLES.C 504$ LINK/EXE=DFTABLES.EXE DFTABLES.OBJ 505$ RUN DFTABLES.EXE/OUTPUT=CHARTABLES.C 506$ COMPILE MAKETABLES.C 507$ COMPILE GET.C 508$ COMPILE STUDY.C 509$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol 510$! did not seem to be defined anywhere. 511$! I edited pcre.h and added #DEFINE SUPPORT_UTF8 to enable UTF8 support. 512$ COMPILE PCRE.C 513$ LIB/CREATE PCRE MAKETABLES.OBJ, GET.OBJ, STUDY.OBJ, PCRE.OBJ 514$! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol 515$! did not seem to be defined anywhere. 516$ COMPILE PCREPOSIX.C 517$ LIB/CREATE PCREPOSIX PCREPOSIX.OBJ 518$ COMPILE PCRETEST.C 519$ LINK/EXE=PCRETEST.EXE PCRETEST.OBJ, PCRE/LIB, PCREPOSIX/LIB 520$! C programs that want access to command line arguments must be 521$! defined as a symbol 522$ PCRETEST :== "$ SYS$ROADSUSERS:[DMOONEY.REGEXP]PCRETEST.EXE" 523$! Arguments must be enclosed in quotes. 524$ PCRETEST "-C" 525$! Test results: 526$! 527$! The test results did not match 100%. The functions isprint(), iscntrl(), 528$! isgraph() and ispunct() on OpenVMS must not produce the same results 529$! as the system that built the test output files provided with the 530$! distribution. 531$! 532$! The study size did not match and was always 3 less on OpenVMS. 533$! 534$! Locale could not be set to fr 535$! 536========================= 537 538 539BUILDING PCRE ON STRATUS OPENVOS 540 541These notes on the port of PCRE to VOS (lightly edited) were supplied by 542Ashutosh Warikoo, whose email address has the local part awarikoo and the 543domain nse.co.in. The port was for version 7.9 in August 2009. 544 5451. Building PCRE 546 547I built pcre on OpenVOS Release 17.0.1at using GNU Tools 3.4a without any 548problems. I used the following packages to build PCRE: 549 550 ftp://ftp.stratus.com/pub/vos/posix/ga/posix.save.evf.gz 551 552Please read and follow the instructions that come with these packages. To start 553the build of pcre, from the root of the package type: 554 555 ./build.sh 556 5572. Installing PCRE 558 559Once you have successfully built PCRE, login to the SysAdmin group, switch to 560the root user, and type 561 562 [ !create_dir (master_disk)>usr --if needed ] 563 [ !create_dir (master_disk)>usr>local --if needed ] 564 !gmake install 565 566This installs PCRE and its man pages into /usr/local. You can add 567(master_disk)>usr>local>bin to your command search paths, or if you are in 568BASH, add /usr/local/bin to the PATH environment variable. 569 5704. Restrictions 571 572This port requires readline library optionally. However during the build I 573faced some yet unexplored errors while linking with readline. As it was an 574optional component I chose to disable it. 575 5765. Known Problems 577 578I ran the test suite, but you will have to be your own judge of whether this 579command, and this port, suits your purposes. If you find any problems that 580appear to be related to the port itself, please let me know. Please see the 581build.log file in the root of the package also. 582 583 584========================== 585Last Updated: 18 June 2012 586