| Building PCRE2 without using autotools | |
| ====================================== | |
| This document contains the following sections: | |
| General | |
| Generic instructions for the PCRE2 C libraries | |
| Stack size in Windows environments | |
| Linking programs in Windows environments | |
| Calling conventions in Windows environments | |
| Comments about Win32 builds | |
| Building PCRE2 on Windows with CMake | |
| Building PCRE2 on Windows with Visual Studio | |
| Testing with Python | |
| Building PCRE2 on z/OS and z/VM | |
| Building PCRE2 under VMS | |
| General | |
| ------- | |
| The source of the PCRE2 libraries 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 PCRE2 distribution includes a "configure" file for use by the | |
| configure/make (autotools) build system, as found in many Unix-like | |
| environments. The README file contains information about the options for | |
| "configure". | |
| There is also support for CMake, which some users prefer, especially in Windows | |
| environments, though it can also be run in Unix-like environments. See the | |
| section entitled "Building PCRE2 on Windows with CMake" below. | |
| Versions of src/config.h and src/pcre2.h are distributed in the PCRE2 tarballs | |
| under the names src/config.h.generic and src/pcre2.h.generic. These are | |
| provided for those who build PCRE2 without using "configure" or CMake. If you | |
| use "configure" or CMake, the .generic versions are not used. | |
| Generic instructions for the PCRE2 C libraries | |
| ---------------------------------------------- | |
| There are three possible PCRE2 libraries, each handling data with a specific | |
| code unit width: 8, 16, or 32 bits. You can build any combination of them. The | |
| following are generic instructions for building a PCRE2 C library "by hand". If | |
| you are going to use CMake, this section does not apply to you; you can skip | |
| ahead to the CMake section. Note that the settings concerned with 8-bit, | |
| 16-bit, and 32-bit code units relate to the type of data string that PCRE2 | |
| processes. They are NOT referring to the underlying operating system bit width. | |
| You do not have to do anything special to compile in a 64-bit environment, for | |
| example. | |
| (1) Copy or rename the file src/config.h.generic as src/config.h, and edit the | |
| macro settings that it contains to whatever is appropriate for your | |
| environment. In particular, you can alter the definition of the NEWLINE | |
| macro to specify what character(s) you want to be interpreted as line | |
| terminators by default. You need to #define at least one of | |
| SUPPORT_PCRE2_8, SUPPORT_PCRE2_16, or SUPPORT_PCRE2_32, depending on which | |
| libraries you are going to build. You must set all that apply. | |
| When you subsequently compile any of the PCRE2 modules, you must specify | |
| -DHAVE_CONFIG_H to your compiler so that src/config.h is included in the | |
| sources. | |
| An alternative approach is not to edit src/config.h, but to use -D on the | |
| compiler command line to make any changes that you need to the | |
| configuration options. In this case -DHAVE_CONFIG_H must not be set. | |
| NOTE: There have been occasions when the way in which certain parameters | |
| in src/config.h are used has changed between releases. (In the | |
| configure/make world, this is handled automatically.) When upgrading to a | |
| new release, you are strongly advised to review src/config.h.generic | |
| before re-using what you had previously. | |
| Note also that the src/config.h.generic file is created from a config.h | |
| that was generated by Autotools, which automatically includes settings of | |
| a number of macros that are not actually used by PCRE2 (for example, | |
| HAVE_DLFCN_H). | |
| (2) Copy or rename the file src/pcre2.h.generic as src/pcre2.h. | |
| (3) EITHER: | |
| Copy or rename file src/pcre2_chartables.c.dist as | |
| src/pcre2_chartables.c. | |
| OR: | |
| Compile src/pcre2_dftables.c as a stand-alone program (using | |
| -DHAVE_CONFIG_H if you have set up src/config.h), and then run it with | |
| the single argument "src/pcre2_chartables.c". This generates a set of | |
| standard character tables and writes them to that file. The tables are | |
| generated using the default C locale for your system. If you want to use | |
| a locale that is specified by LC_xxx environment variables, add the -L | |
| option to the pcre2_dftables command. You must use this method if you | |
| are building on a system that uses EBCDIC code. | |
| The tables in src/pcre2_chartables.c are defaults. The caller of PCRE2 can | |
| specify alternative tables at run time. | |
| (4) For a library that supports 8-bit code units in the character strings that | |
| it processes, compile the following source files from the src directory, | |
| setting -DPCRE2_CODE_UNIT_WIDTH=8 as a compiler option. Also set | |
| -DHAVE_CONFIG_H if you have set up src/config.h with your configuration, | |
| or else use other -D settings to change the configuration as required. | |
| pcre2_auto_possess.c | |
| pcre2_chkdint.c | |
| pcre2_chartables.c | |
| pcre2_compile.c | |
| pcre2_compile_cgroup.c | |
| pcre2_compile_class.c | |
| pcre2_config.c | |
| pcre2_context.c | |
| pcre2_convert.c | |
| pcre2_dfa_match.c | |
| pcre2_error.c | |
| pcre2_extuni.c | |
| pcre2_find_bracket.c | |
| pcre2_jit_compile.c | |
| pcre2_maketables.c | |
| pcre2_match.c | |
| pcre2_match_data.c | |
| pcre2_match_next.c | |
| pcre2_newline.c | |
| pcre2_ord2utf.c | |
| pcre2_pattern_info.c | |
| pcre2_script_run.c | |
| pcre2_serialize.c | |
| pcre2_string_utils.c | |
| pcre2_study.c | |
| pcre2_substitute.c | |
| pcre2_substring.c | |
| pcre2_tables.c | |
| pcre2_ucd.c | |
| pcre2_valid_utf.c | |
| pcre2_xclass.c | |
| Make sure that you include -I. in the compiler command (or equivalent for | |
| an unusual compiler) so that all included PCRE2 header files are first | |
| sought in the src directory under the current directory. Otherwise you run | |
| the risk of picking up a previously-installed file from somewhere else. | |
| Note that you must compile pcre2_jit_compile.c, even if you have not | |
| defined SUPPORT_JIT in src/config.h, because when JIT support is not | |
| configured, dummy functions are compiled. When JIT support IS configured, | |
| pcre2_jit_compile.c #includes other files from the sljit dependency, | |
| all of whose names begin with "sljit". | |
| Note also that the pcre2_fuzzsupport.c file contains special code that is | |
| useful to those who want to run fuzzing tests on the PCRE2 library. Unless | |
| you are doing that, you can ignore it. | |
| (5) Now link all the compiled code into an object library in whichever form | |
| your system keeps such libraries. This is the PCRE2 C 8-bit library, | |
| typically called something like libpcre2-8. If your system has static and | |
| shared libraries, you may have to do this once for each type. | |
| (6) If you want to build a library that supports 16-bit or 32-bit code units, | |
| set 16 or 32 as the value of -DPCRE2_CODE_UNIT_WIDTH when obeying step 4 | |
| above. If you want to build more than one PCRE2 library, repeat steps 4 | |
| and 5 as necessary. | |
| (7) If you want to build the POSIX wrapper functions (which apply only to the | |
| 8-bit library), ensure that you have the src/pcre2posix.h file and then | |
| compile src/pcre2posix.c. Link the result (on its own) as the pcre2posix | |
| library. If targeting a DLL in Windows, make sure to include | |
| -DPCRE2POSIX_SHARED with your compiler flags. | |
| (8) The pcre2test program can be linked with any combination of the 8-bit, | |
| 16-bit and 32-bit libraries (depending on what you specfied in | |
| src/config.h) . Compile src/pcre2test.c; don't forget -DHAVE_CONFIG_H if | |
| necessary, but do NOT define PCRE2_CODE_UNIT_WIDTH. Then link with the | |
| appropriate library/ies. If you compiled an 8-bit library, pcre2test also | |
| needs the pcre2posix wrapper library when linking. | |
| (9) Run pcre2test on the testinput files in the testdata directory, and check | |
| that the output matches the corresponding testoutput files. There are | |
| comments about what each test does in the section entitled "Testing PCRE2" | |
| in the README file. If you compiled more than one of the 8-bit, 16-bit and | |
| 32-bit libraries, you need to run pcre2test with the -16 option to do | |
| 16-bit tests and with the -32 option to do 32-bit tests. | |
| Some tests are relevant only when certain build-time options are selected. | |
| For example, test 4 is for Unicode support, and will not run if you have | |
| built PCRE2 without it. See the comments at the start of each testinput | |
| file. The Python script RunTest.py will run the appropriate tests on | |
| Unix-like systems and Windows. A Unix shell version is also available | |
| as RunTest. The command "python3 RunTest.py list" (or "RunTest list" for | |
| the shell version) will output a list of all the tests. | |
| Note that the supplied files are in Unix format, with just LF characters | |
| as line terminators. | |
| (10) If you have built PCRE2 with SUPPORT_JIT, the JIT features can be tested | |
| by running pcre2test with the -jit option. This is done automatically by | |
| RunTest.py and RunTest. You might also like to build and run the | |
| freestanding JIT test program, src/pcre2_jit_test.c. | |
| (11) The pcre2test program tests the POSIX wrapper library, but there is also a | |
| freestanding test program in src/pcre2posix_test.c. It must be linked with | |
| both the pcre2posix library and the 8-bit PCRE2 library. | |
| (12) If you want to use the pcre2grep command, compile and link | |
| src/pcre2grep.c; it uses only the 8-bit PCRE2 library (it does not need | |
| the pcre2posix library). If you have built the PCRE2 library with JIT | |
| support by defining SUPPORT_JIT in src/config.h, you can also define | |
| SUPPORT_PCRE2GREP_JIT, which causes pcre2grep to make use of JIT (unless | |
| it is run with --no-jit). If you define SUPPORT_PCRE2GREP_JIT without | |
| defining SUPPORT_JIT, pcre2grep does not try to make use of JIT. | |
| Stack size in Windows environments | |
| ---------------------------------- | |
| Prior to release 10.30 the default system stack size of 1MiB in some Windows | |
| environments caused issues with some tests. This should no longer be the case | |
| for 10.30 and later releases. | |
| Linking programs in Windows environments | |
| ---------------------------------------- | |
| If you want to statically link a program against a PCRE2 library in the form of | |
| a non-dll .a file, you must define PCRE2_STATIC before including src/pcre2.h. | |
| Calling conventions in Windows environments | |
| ------------------------------------------- | |
| It is possible to compile programs to use different calling conventions using | |
| MSVC. Search the web for "calling conventions" for more information. To make it | |
| easier to change the calling convention for the exported functions in a | |
| PCRE2 library, the macro PCRE2_CALL_CONVENTION is present in all the external | |
| definitions. It can be set externally when compiling (e.g. in CFLAGS). If it is | |
| not set, it defaults to empty; the default calling convention is then used | |
| (which is what is wanted most of the time). | |
| Comments about Win32 builds (see also "Building PCRE2 on Windows with CMake") | |
| --------------------------- | |
| There are two ways of building PCRE2 using the "configure, make, make install" | |
| paradigm on Windows systems: using MinGW or using Cygwin. These are not at all | |
| the same thing; they are completely different from each other. There is also | |
| support for building using CMake, which some users find a more straightforward | |
| way of building PCRE2 under Windows. | |
| The MinGW home page (http://www.mingw.org/) says this: | |
| MinGW: A collection of freely available and freely distributable Windows | |
| specific header files and import libraries combined with GNU toolsets that | |
| allow one to produce native Windows programs that do not rely on any | |
| 3rd-party C runtime DLLs. | |
| The Cygwin home page (http://www.cygwin.com/) says this: | |
| Cygwin is a Linux-like environment for Windows. It consists of two parts: | |
| . A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing | |
| substantial Linux API functionality | |
| . A collection of tools which provide Linux look and feel. | |
| On both MinGW and Cygwin, PCRE2 should build correctly using: | |
| ./configure && make && make install | |
| This should create two libraries called libpcre2-8 and libpcre2-posix. These | |
| are independent libraries: when you link with libpcre2-posix you must also link | |
| with libpcre2-8, which contains the basic functions. | |
| Using Cygwin's compiler generates libraries and executables that depend on | |
| cygwin1.dll. If a library that is generated this way is distributed, | |
| cygwin1.dll has to be distributed as well. Since cygwin1.dll is under the GPL | |
| licence, this forces not only PCRE2 to be under the GPL, but also the entire | |
| application. A distributor who wants to keep their own code proprietary must | |
| purchase an appropriate Cygwin licence. | |
| MinGW has no such restrictions. The MinGW compiler generates a library or | |
| executable that can run standalone on Windows without any third party dll or | |
| licensing issues. | |
| But there is more complication: | |
| If a Cygwin user uses the -mno-cygwin Cygwin gcc flag, what that really does is | |
| to tell Cygwin's gcc to use the MinGW gcc. Cygwin's gcc is only acting as a | |
| front end to MinGW's gcc (if you install Cygwin's gcc, you get both Cygwin's | |
| gcc and MinGW's gcc). So, a user can: | |
| . Build native binaries by using MinGW or by getting Cygwin and using | |
| -mno-cygwin. | |
| . Build binaries that depend on cygwin1.dll by using Cygwin with the normal | |
| compiler flags. | |
| The test files that are supplied with PCRE2 are in UNIX format, with LF | |
| characters as line terminators. Unless your PCRE2 library uses a default | |
| newline option that includes LF as a valid newline, it may be necessary to | |
| change the line terminators in the test files to get some of the tests to work. | |
| Building PCRE2 on Windows with CMake | |
| ------------------------------------ | |
| CMake is an alternative configuration facility that can be used instead of | |
| "configure". CMake creates project files (make files, solution files, etc.) | |
| tailored to numerous development environments, including Visual Studio, | |
| Borland, Msys, MinGW, NMake, and Unix. If possible, use short paths with no | |
| spaces in the names for your CMake installation and your PCRE2 source and build | |
| directories. | |
| If you are using CMake and encounter errors, deleting the CMake cache and | |
| restarting from a fresh build may fix the error. In the CMake GUI, the cache can | |
| be deleted by selecting "File > Delete Cache"; or the folder "CMakeCache" can | |
| be deleted. | |
| 1. Install the latest CMake version available from http://www.cmake.org/, and | |
| ensure that cmake\bin is on your path. | |
| 2. Unzip (retaining folder structure) the PCRE2 source tree into a source | |
| directory such as C:\pcre2. You should ensure your local date and time | |
| is not earlier than the file dates in your source dir if the release is | |
| very new. | |
| 3. Create a new, empty build directory, preferably a subdirectory of the | |
| source dir. For example, C:\pcre2\pcre2-xx\build. | |
| 4. Run CMake. | |
| - Using the CLI, simply run `cmake ..` inside the `build/` directory. You can | |
| use the `ccmake` ncurses GUI to select and configure PCRE2 features. | |
| - Using the CMake GUI: | |
| a) Run cmake-gui from the Shell environment of your build tool, for | |
| example, Msys for Msys/MinGW or Visual Studio Command Prompt for | |
| VC/VC++. | |
| b) Enter C:\pcre2\pcre2-xx and C:\pcre2\pcre2-xx\build for the source and | |
| build directories, respectively. | |
| c) Press the "Configure" button. | |
| d) Select the particular IDE / build tool that you are using (Visual | |
| Studio, MSYS makefiles, MinGW makefiles, etc.) | |
| e) The GUI will then list several configuration options. This is where | |
| you can disable Unicode support or select other PCRE2 optional features. | |
| f) Press "Configure" again. The adjacent "Generate" button should now be | |
| active. | |
| g) Press "Generate". | |
| 5. The build directory should now contain a usable build system, be it a | |
| solution file for Visual Studio, makefiles for MinGW, etc. Exit from | |
| cmake-gui and use the generated build system with your compiler or IDE. | |
| E.g., for MinGW you can run "make", or for Visual Studio, open the PCRE2 | |
| solution, select the desired configuration (Debug, or Release, etc.) and | |
| build the ALL_BUILD project. | |
| Regardless of build system used, `cmake --build .` will build it. | |
| 6. If during configuration with cmake-gui you've elected to build the test | |
| programs, you can execute them by building the test project. E.g., for | |
| MinGW: "make test"; for Visual Studio build the RUN_TESTS project. The | |
| most recent build configuration is targeted by the tests. A summary of | |
| test results is presented. Complete test output is subsequently | |
| available for review in Testing\Temporary under your build dir. | |
| Regardless of build system used, `ctest` will run the tests. | |
| Testing with Python | |
| ------------------- | |
| The autotools build uses `make check` to run the test suites using the `RunTest` | |
| and `RunGrepTest` shell (bash) scripts. The test suite is also available for | |
| non-Unix platforms using the equivalent `RunTest.py` and `RunGrepTest.py` Python | |
| scripts instead. | |
| These Python scripts can be used with any build system, and should work on | |
| supported PCRE2 platforms. | |
| The autotools build only uses the shell scripts. | |
| The CMake build tests for a Python 3 installation, and defaults to registering | |
| the Python scripts with CTest. If Python 3 is not found, CMake registers the | |
| shell scripts on Unix, or fails otherwise. | |
| On Windows, the requirement for a Python installation to run the test suite can | |
| be avoided by passing `-DPCRE2_BUILD_TESTS=OFF`, although releasing untested | |
| builds is not recommended. | |
| After building, run CTest in the usual way, specifying the configuration for a | |
| multi-configuration generator. For example: | |
| cmake --build build --config Release | |
| ctest --test-dir build -C Release --output-on-failure | |
| The scripts can also be run directly from the build directory. If the source | |
| and executable paths cannot be inferred from that directory, pass them | |
| explicitly. For example: | |
| python3 ../RunTest.py --srcdir .. --pcre2test ./Release/pcre2test.exe | |
| python3 ../RunGrepTest.py --srcdir .. ^ | |
| --pcre2test ./Release/pcre2test.exe ^ | |
| --pcre2grep ./Release/pcre2grep.exe | |
| The runner scripts (shell and Python) support out-of-tree builds by accepting | |
| commandline arguments specifying the location of the srcdir (the directory | |
| containing the `testdata/` directory); of `pcre2test[.exe]`; and for | |
| `RunGrepTest` and `RunGrepTest.py`, `pcre2grep[.exe]`. Alternatively, | |
| environment variables can be used to pass the paths; and if none are provided | |
| the working directory is used. | |
| Building PCRE2 on z/OS and z/VM | |
| ------------------------------- | |
| z/OS and z/VM are operating systems for mainframe computers, produced by IBM. | |
| The character code used is EBCDIC, not ASCII or Unicode. In z/OS, UNIX APIs and | |
| applications can be supported through UNIX System Services. | |
| The PCRE2 codebase compiles and runs with native EBCDIC support on modern z/OS | |
| systems, using the pre-installed tools (/bin/sh, ./configure, and the XLC or | |
| IBM-Clang compilers). PCRE2 supports z/OS using both Autoconf (./configure) and | |
| CMake (which IBM distributes via "zopen install cmake"). | |
| Note that as of the time of writing, IBM's port of CMake to z/OS has only | |
| partial support for EBCDIC. It is recommended to build PCRE2 using the | |
| ./configure script, if you require an EBCDIC build. | |
| Any EBCDIC codepage should work (PCRE2 does not assume or require IBM-1047), or | |
| PCRE2 can compiled for ASCII/Latin-1/Unicode. | |
| After unpacking the PCRE2 tarball, you must subsequently tag the files as ASCII | |
| in order for the z/OS shell and compiler to interpret them correctly: | |
| chtag -R -tc ISO8859-1 <directory> | |
| Some unusual features on the IBM platform are: | |
| - The _ALL_SOURCE macro must be provided. Unlike on Linux or macOS, even quite | |
| standard POSIX APIs are not made visible by default. PCRE2's Autoconf and | |
| CMake system both provide this for you. | |
| - The `cc`, `c89`, and even `c99` compilers provided by IBM do not default to | |
| the same argument ordering as other Unix platforms. | |
| - The XLC compiler requires `-qhaltonmsg=CCN3296`, otherwise it will treat any | |
| preprocessor #include errors as a warning rather than an error. Needless to | |
| say this default wrecks Autoconf and CMake's feature-detection tests. | |
| PCRE2's build system is aware of this. | |
| - The test suite (in the testdata/ directory) is entirely in ASCII/UTF-8. | |
| When running the tests, you must ensure that the EBCDIC-native build of | |
| pcre2test receives an EBCDIC version of these files. The easiest way to | |
| achieve this is via filesystem tagging (chtag). Alternatively, you could | |
| manually re-encode the testdata files as EBCDIC, and tag them as EBCDIC. | |
| (Latin-1 and EBCDIC are one-to-one convertible encodings, a simple | |
| byte-by-byte permutation of the 256 values.) | |
| In native z/OS (without UNIX System Services) and in z/VM, a user has provided a | |
| special port of PCRE2. For details, please see file 939 on this web site: | |
| http://www.cbttape.org | |
| The user-provided port also provides an API for LE languages such as COBOL and | |
| for the z/OS and z/VM versions of the Rexx languages. | |
| Building PCRE2 under VMS | |
| ------------------------ | |
| Alexey Chuphin has contributed some auxiliary files for building PCRE2 under | |
| OpenVMS. They are in the "vms" directory in the distribution tarball. Please | |
| read the file called vms/openvms_readme.txt. The pcre2test and pcre2grep | |
| programs contain some VMS-specific code. | |
| This has not been tested for some time. The PCRE2 maintainers would be grateful | |
| to learn whether it still works (or if anyone still uses it). | |
| ============================= | |
| Last updated: 17 October 2025 | |
| ============================= | |