github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
19 KiB

  1. Building PCRE2 without using autotools
  2. --------------------------------------
  3. This document contains the following sections:
  4. General
  5. Generic instructions for the PCRE2 C libraries
  6. Stack size in Windows environments
  7. Linking programs in Windows environments
  8. Calling conventions in Windows environments
  9. Comments about Win32 builds
  10. Building PCRE2 on Windows with CMake
  11. Building PCRE2 on Windows with Visual Studio
  12. Testing with RunTest.bat
  13. Building PCRE2 on native z/OS and z/VM
  14. Building PCRE2 under VMS
  15. GENERAL
  16. The source of the PCRE2 libraries consists entirely of code written in Standard
  17. C, and so should compile successfully on any system that has a Standard C
  18. compiler and library.
  19. The PCRE2 distribution includes a "configure" file for use by the
  20. configure/make (autotools) build system, as found in many Unix-like
  21. environments. The README file contains information about the options for
  22. "configure".
  23. There is also support for CMake, which some users prefer, especially in Windows
  24. environments, though it can also be run in Unix-like environments. See the
  25. section entitled "Building PCRE2 on Windows with CMake" below.
  26. Versions of src/config.h and src/pcre2.h are distributed in the PCRE2 tarballs
  27. under the names src/config.h.generic and src/pcre2.h.generic. These are
  28. provided for those who build PCRE2 without using "configure" or CMake. If you
  29. use "configure" or CMake, the .generic versions are not used.
  30. GENERIC INSTRUCTIONS FOR THE PCRE2 C LIBRARIES
  31. There are three possible PCRE2 libraries, each handling data with a specific
  32. code unit width: 8, 16, or 32 bits. You can build any combination of them. The
  33. following are generic instructions for building a PCRE2 C library "by hand". If
  34. you are going to use CMake, this section does not apply to you; you can skip
  35. ahead to the CMake section. Note that the settings concerned with 8-bit,
  36. 16-bit, and 32-bit code units relate to the type of data string that PCRE2
  37. processes. They are NOT referring to the underlying operating system bit width.
  38. You do not have to do anything special to compile in a 64-bit environment, for
  39. example.
  40. (1) Copy or rename the file src/config.h.generic as src/config.h, and edit the
  41. macro settings that it contains to whatever is appropriate for your
  42. environment. In particular, you can alter the definition of the NEWLINE
  43. macro to specify what character(s) you want to be interpreted as line
  44. terminators by default. You need to #define at least one of
  45. SUPPORT_PCRE2_8, SUPPORT_PCRE2_16, or SUPPORT_PCRE2_32, depending on which
  46. libraries you are going to build. You must set all that apply.
  47. When you subsequently compile any of the PCRE2 modules, you must specify
  48. -DHAVE_CONFIG_H to your compiler so that src/config.h is included in the
  49. sources.
  50. An alternative approach is not to edit src/config.h, but to use -D on the
  51. compiler command line to make any changes that you need to the
  52. configuration options. In this case -DHAVE_CONFIG_H must not be set.
  53. NOTE: There have been occasions when the way in which certain parameters
  54. in src/config.h are used has changed between releases. (In the
  55. configure/make world, this is handled automatically.) When upgrading to a
  56. new release, you are strongly advised to review src/config.h.generic
  57. before re-using what you had previously.
  58. Note also that the src/config.h.generic file is created from a config.h
  59. that was generated by Autotools, which automatically includes settings of
  60. a number of macros that are not actually used by PCRE2 (for example,
  61. HAVE_DLFCN_H).
  62. (2) Copy or rename the file src/pcre2.h.generic as src/pcre2.h.
  63. (3) EITHER:
  64. Copy or rename file src/pcre2_chartables.c.dist as
  65. src/pcre2_chartables.c.
  66. OR:
  67. Compile src/pcre2_dftables.c as a stand-alone program (using
  68. -DHAVE_CONFIG_H if you have set up src/config.h), and then run it with
  69. the single argument "src/pcre2_chartables.c". This generates a set of
  70. standard character tables and writes them to that file. The tables are
  71. generated using the default C locale for your system. If you want to use
  72. a locale that is specified by LC_xxx environment variables, add the -L
  73. option to the pcre2_dftables command. You must use this method if you
  74. are building on a system that uses EBCDIC code.
  75. The tables in src/pcre2_chartables.c are defaults. The caller of PCRE2 can
  76. specify alternative tables at run time.
  77. (4) For a library that supports 8-bit code units in the character strings that
  78. it processes, compile the following source files from the src directory,
  79. setting -DPCRE2_CODE_UNIT_WIDTH=8 as a compiler option. Also set
  80. -DHAVE_CONFIG_H if you have set up src/config.h with your configuration,
  81. or else use other -D settings to change the configuration as required.
  82. pcre2_auto_possess.c
  83. pcre2_chkdint.c
  84. pcre2_chartables.c
  85. pcre2_compile.c
  86. pcre2_config.c
  87. pcre2_context.c
  88. pcre2_convert.c
  89. pcre2_dfa_match.c
  90. pcre2_error.c
  91. pcre2_extuni.c
  92. pcre2_find_bracket.c
  93. pcre2_jit_compile.c
  94. pcre2_maketables.c
  95. pcre2_match.c
  96. pcre2_match_data.c
  97. pcre2_newline.c
  98. pcre2_ord2utf.c
  99. pcre2_pattern_info.c
  100. pcre2_script_run.c
  101. pcre2_serialize.c
  102. pcre2_string_utils.c
  103. pcre2_study.c
  104. pcre2_substitute.c
  105. pcre2_substring.c
  106. pcre2_tables.c
  107. pcre2_ucd.c
  108. pcre2_valid_utf.c
  109. pcre2_xclass.c
  110. Make sure that you include -I. in the compiler command (or equivalent for
  111. an unusual compiler) so that all included PCRE2 header files are first
  112. sought in the src directory under the current directory. Otherwise you run
  113. the risk of picking up a previously-installed file from somewhere else.
  114. Note that you must compile pcre2_jit_compile.c, even if you have not
  115. defined SUPPORT_JIT in src/config.h, because when JIT support is not
  116. configured, dummy functions are compiled. When JIT support IS configured,
  117. pcre2_jit_compile.c #includes other files from the sljit subdirectory,
  118. all of whose names begin with "sljit". It also #includes
  119. src/pcre2_jit_match.c and src/pcre2_jit_misc.c, so you should not compile
  120. those yourself.
  121. Note also that the pcre2_fuzzsupport.c file contains special code that is
  122. useful to those who want to run fuzzing tests on the PCRE2 library. Unless
  123. you are doing that, you can ignore it.
  124. (5) Now link all the compiled code into an object library in whichever form
  125. your system keeps such libraries. This is the PCRE2 C 8-bit library,
  126. typically called something like libpcre2-8. If your system has static and
  127. shared libraries, you may have to do this once for each type.
  128. (6) If you want to build a library that supports 16-bit or 32-bit code units,
  129. set 16 or 32 as the value of -DPCRE2_CODE_UNIT_WIDTH when obeying step 4
  130. above. If you want to build more than one PCRE2 library, repeat steps 4
  131. and 5 as necessary.
  132. (7) If you want to build the POSIX wrapper functions (which apply only to the
  133. 8-bit library), ensure that you have the src/pcre2posix.h file and then
  134. compile src/pcre2posix.c. Link the result (on its own) as the pcre2posix
  135. library. If targeting a DLL in Windows, make sure to include
  136. -DPCRE2POSIX_SHARED with your compiler flags.
  137. (8) The pcre2test program can be linked with any combination of the 8-bit,
  138. 16-bit and 32-bit libraries (depending on what you specfied in
  139. src/config.h) . Compile src/pcre2test.c; don't forget -DHAVE_CONFIG_H if
  140. necessary, but do NOT define PCRE2_CODE_UNIT_WIDTH. Then link with the
  141. appropriate library/ies. If you compiled an 8-bit library, pcre2test also
  142. needs the pcre2posix wrapper library.
  143. (9) Run pcre2test on the testinput files in the testdata directory, and check
  144. that the output matches the corresponding testoutput files. There are
  145. comments about what each test does in the section entitled "Testing PCRE2"
  146. in the README file. If you compiled more than one of the 8-bit, 16-bit and
  147. 32-bit libraries, you need to run pcre2test with the -16 option to do
  148. 16-bit tests and with the -32 option to do 32-bit tests.
  149. Some tests are relevant only when certain build-time options are selected.
  150. For example, test 4 is for Unicode support, and will not run if you have
  151. built PCRE2 without it. See the comments at the start of each testinput
  152. file. If you have a suitable Unix-like shell, the RunTest script will run
  153. the appropriate tests for you. The command "RunTest list" will output a
  154. list of all the tests.
  155. Note that the supplied files are in Unix format, with just LF characters
  156. as line terminators. You may need to edit them to change this if your
  157. system uses a different convention.
  158. (10) If you have built PCRE2 with SUPPORT_JIT, the JIT features can be tested
  159. by running pcre2test with the -jit option. This is done automatically by
  160. the RunTest script. You might also like to build and run the freestanding
  161. JIT test program, src/pcre2_jit_test.c.
  162. (11) The pcre2test program tests the POSIX wrapper library, but there is also a
  163. freestanding test program in src/pcre2posix_test.c. It must be linked with
  164. both the pcre2posix library and the 8-bit PCRE2 library.
  165. (12) If you want to use the pcre2grep command, compile and link
  166. src/pcre2grep.c; it uses only the 8-bit PCRE2 library (it does not need
  167. the pcre2posix library). If you have built the PCRE2 library with JIT
  168. support by defining SUPPORT_JIT in src/config.h, you can also define
  169. SUPPORT_PCRE2GREP_JIT, which causes pcre2grep to make use of JIT (unless
  170. it is run with --no-jit). If you define SUPPORT_PCRE2GREP_JIT without
  171. defining SUPPORT_JIT, pcre2grep does not try to make use of JIT.
  172. STACK SIZE IN WINDOWS ENVIRONMENTS
  173. Prior to release 10.30 the default system stack size of 1MiB in some Windows
  174. environments caused issues with some tests. This should no longer be the case
  175. for 10.30 and later releases.
  176. LINKING PROGRAMS IN WINDOWS ENVIRONMENTS
  177. If you want to statically link a program against a PCRE2 library in the form of
  178. a non-dll .a file, you must define PCRE2_STATIC before including src/pcre2.h.
  179. CALLING CONVENTIONS IN WINDOWS ENVIRONMENTS
  180. It is possible to compile programs to use different calling conventions using
  181. MSVC. Search the web for "calling conventions" for more information. To make it
  182. easier to change the calling convention for the exported functions in a
  183. PCRE2 library, the macro PCRE2_CALL_CONVENTION is present in all the external
  184. definitions. It can be set externally when compiling (e.g. in CFLAGS). If it is
  185. not set, it defaults to empty; the default calling convention is then used
  186. (which is what is wanted most of the time).
  187. COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE2 ON WINDOWS WITH CMAKE")
  188. There are two ways of building PCRE2 using the "configure, make, make install"
  189. paradigm on Windows systems: using MinGW or using Cygwin. These are not at all
  190. the same thing; they are completely different from each other. There is also
  191. support for building using CMake, which some users find a more straightforward
  192. way of building PCRE2 under Windows.
  193. The MinGW home page (http://www.mingw.org/) says this:
  194. MinGW: A collection of freely available and freely distributable Windows
  195. specific header files and import libraries combined with GNU toolsets that
  196. allow one to produce native Windows programs that do not rely on any
  197. 3rd-party C runtime DLLs.
  198. The Cygwin home page (http://www.cygwin.com/) says this:
  199. Cygwin is a Linux-like environment for Windows. It consists of two parts:
  200. . A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing
  201. substantial Linux API functionality
  202. . A collection of tools which provide Linux look and feel.
  203. On both MinGW and Cygwin, PCRE2 should build correctly using:
  204. ./configure && make && make install
  205. This should create two libraries called libpcre2-8 and libpcre2-posix. These
  206. are independent libraries: when you link with libpcre2-posix you must also link
  207. with libpcre2-8, which contains the basic functions.
  208. Using Cygwin's compiler generates libraries and executables that depend on
  209. cygwin1.dll. If a library that is generated this way is distributed,
  210. cygwin1.dll has to be distributed as well. Since cygwin1.dll is under the GPL
  211. licence, this forces not only PCRE2 to be under the GPL, but also the entire
  212. application. A distributor who wants to keep their own code proprietary must
  213. purchase an appropriate Cygwin licence.
  214. MinGW has no such restrictions. The MinGW compiler generates a library or
  215. executable that can run standalone on Windows without any third party dll or
  216. licensing issues.
  217. But there is more complication:
  218. If a Cygwin user uses the -mno-cygwin Cygwin gcc flag, what that really does is
  219. to tell Cygwin's gcc to use the MinGW gcc. Cygwin's gcc is only acting as a
  220. front end to MinGW's gcc (if you install Cygwin's gcc, you get both Cygwin's
  221. gcc and MinGW's gcc). So, a user can:
  222. . Build native binaries by using MinGW or by getting Cygwin and using
  223. -mno-cygwin.
  224. . Build binaries that depend on cygwin1.dll by using Cygwin with the normal
  225. compiler flags.
  226. The test files that are supplied with PCRE2 are in UNIX format, with LF
  227. characters as line terminators. Unless your PCRE2 library uses a default
  228. newline option that includes LF as a valid newline, it may be necessary to
  229. change the line terminators in the test files to get some of the tests to work.
  230. BUILDING PCRE2 ON WINDOWS WITH CMAKE
  231. CMake is an alternative configuration facility that can be used instead of
  232. "configure". CMake creates project files (make files, solution files, etc.)
  233. tailored to numerous development environments, including Visual Studio,
  234. Borland, Msys, MinGW, NMake, and Unix. If possible, use short paths with no
  235. spaces in the names for your CMake installation and your PCRE2 source and build
  236. directories.
  237. The following instructions were contributed by a PCRE1 user, but they should
  238. also work for PCRE2. If they are not followed exactly, errors may occur. In the
  239. event that errors do occur, it is recommended that you delete the CMake cache
  240. before attempting to repeat the CMake build process. In the CMake GUI, the
  241. cache can be deleted by selecting "File > Delete Cache".
  242. 1. Install the latest CMake version available from http://www.cmake.org/, and
  243. ensure that cmake\bin is on your path.
  244. 2. Unzip (retaining folder structure) the PCRE2 source tree into a source
  245. directory such as C:\pcre2. You should ensure your local date and time
  246. is not earlier than the file dates in your source dir if the release is
  247. very new.
  248. 3. Create a new, empty build directory, preferably a subdirectory of the
  249. source dir. For example, C:\pcre2\pcre2-xx\build.
  250. 4. Run cmake-gui from the Shell environment of your build tool, for example,
  251. Msys for Msys/MinGW or Visual Studio Command Prompt for VC/VC++. Do not try
  252. to start Cmake from the Windows Start menu, as this can lead to errors.
  253. 5. Enter C:\pcre2\pcre2-xx and C:\pcre2\pcre2-xx\build for the source and
  254. build directories, respectively.
  255. 6. Hit the "Configure" button.
  256. 7. Select the particular IDE / build tool that you are using (Visual
  257. Studio, MSYS makefiles, MinGW makefiles, etc.)
  258. 8. The GUI will then list several configuration options. This is where
  259. you can disable Unicode support or select other PCRE2 optional features.
  260. 9. Hit "Configure" again. The adjacent "Generate" button should now be
  261. active.
  262. 10. Hit "Generate".
  263. 11. The build directory should now contain a usable build system, be it a
  264. solution file for Visual Studio, makefiles for MinGW, etc. Exit from
  265. cmake-gui and use the generated build system with your compiler or IDE.
  266. E.g., for MinGW you can run "make", or for Visual Studio, open the PCRE2
  267. solution, select the desired configuration (Debug, or Release, etc.) and
  268. build the ALL_BUILD project.
  269. 12. If during configuration with cmake-gui you've elected to build the test
  270. programs, you can execute them by building the test project. E.g., for
  271. MinGW: "make test"; for Visual Studio build the RUN_TESTS project. The
  272. most recent build configuration is targeted by the tests. A summary of
  273. test results is presented. Complete test output is subsequently
  274. available for review in Testing\Temporary under your build dir.
  275. BUILDING PCRE2 ON WINDOWS WITH VISUAL STUDIO
  276. The code currently cannot be compiled without an inttypes.h header, which is
  277. available only with Visual Studio 2013 or newer. However, this portable and
  278. permissively-licensed implementation of the stdint.h header could be used as an
  279. alternative:
  280. http://www.azillionmonkeys.com/qed/pstdint.h
  281. Just rename it and drop it into the top level of the build tree.
  282. TESTING WITH RUNTEST.BAT
  283. If configured with CMake, building the test project ("make test" or building
  284. ALL_TESTS in Visual Studio) creates (and runs) pcre2_test.bat (and depending
  285. on your configuration options, possibly other test programs) in the build
  286. directory. The pcre2_test.bat script runs RunTest.bat with correct source and
  287. exe paths.
  288. For manual testing with RunTest.bat, provided the build dir is a subdirectory
  289. of the source directory: Open command shell window. Chdir to the location
  290. of your pcre2test.exe and pcre2grep.exe programs. Call RunTest.bat with
  291. "..\RunTest.Bat" or "..\..\RunTest.bat" as appropriate.
  292. To run only a particular test with RunTest.Bat provide a test number argument.
  293. Otherwise:
  294. 1. Copy RunTest.bat into the directory where pcre2test.exe and pcre2grep.exe
  295. have been created.
  296. 2. Edit RunTest.bat to identify the full or relative location of
  297. the pcre2 source (wherein which the testdata folder resides), e.g.:
  298. set srcdir=C:\pcre2\pcre2-10.00
  299. 3. In a Windows command environment, chdir to the location of your bat and
  300. exe programs.
  301. 4. Run RunTest.bat. Test outputs will automatically be compared to expected
  302. results, and discrepancies will be identified in the console output.
  303. To independently test the just-in-time compiler, run pcre2_jit_test.exe.
  304. BUILDING PCRE2 ON NATIVE Z/OS AND Z/VM
  305. z/OS and z/VM are operating systems for mainframe computers, produced by IBM.
  306. The character code used is EBCDIC, not ASCII or Unicode. In z/OS, UNIX APIs and
  307. applications can be supported through UNIX System Services, and in such an
  308. environment it should be possible to build PCRE2 in the same way as in other
  309. systems, with the EBCDIC related configuration settings, but it is not known if
  310. anybody has tried this.
  311. In native z/OS (without UNIX System Services) and in z/VM, special ports are
  312. required. For details, please see file 939 on this web site:
  313. http://www.cbttape.org
  314. Everything in that location, source and executable, is in EBCDIC and native
  315. z/OS file formats. The port provides an API for LE languages such as COBOL and
  316. for the z/OS and z/VM versions of the Rexx languages.
  317. BUILDING PCRE2 UNDER VMS
  318. Alexey Chuphin has contributed some auxiliary files for building PCRE2 under
  319. OpenVMS. They are in the "vms" directory in the distribution tarball. Please
  320. read the file called vms/openvms_readme.txt. The pcre2test and pcre2grep
  321. programs contain some VMS-specific code.
  322. ===========================
  323. Last Updated: 16 April 2024
  324. ===========================