/vendor/pcre/NON-UNIX-USE

http://github.com/feyeleanor/RubyGoLightly · #! · 441 lines · 330 code · 111 blank · 0 comment · 0 complexity · 68cf69c503fcbabc1300537fbea6a807 MD5 · raw file

  1. Compiling PCRE on non-Unix systems
  2. ----------------------------------
  3. This document contains the following sections:
  4. General
  5. Generic instructions for the PCRE C library
  6. The C++ wrapper functions
  7. Building for virtual Pascal
  8. Stack size in Windows environments
  9. Linking programs in Windows environments
  10. Comments about Win32 builds
  11. Building PCRE on Windows with CMake
  12. Use of relative paths with CMake on Windows
  13. Testing with runtest.bat
  14. Building under Windows with BCC5.5
  15. Building PCRE on OpenVMS
  16. GENERAL
  17. I (Philip Hazel) have no experience of Windows or VMS sytems and how their
  18. libraries work. The items in the PCRE distribution and Makefile that relate to
  19. anything other than Unix-like systems are untested by me.
  20. There are some other comments and files in the Contrib directory on the ftp
  21. site that you may find useful. See
  22. ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Contrib
  23. If you want to compile PCRE for a non-Unix system (especially for a system that
  24. does not support "configure" and "make" files), note that the basic PCRE
  25. library consists entirely of code written in Standard C, and so should compile
  26. successfully on any system that has a Standard C compiler and library. The C++
  27. wrapper functions are a separate issue (see below).
  28. The PCRE distribution includes a "configure" file for use by the Configure/Make
  29. build system, as found in many Unix-like environments. There is also support
  30. support for CMake, which some users prefer, in particular in Windows
  31. environments. There are some instructions for CMake under Windows in the
  32. section entitled "Building PCRE with CMake" below. CMake can also be used to
  33. build PCRE in Unix-like systems.
  34. GENERIC INSTRUCTIONS FOR THE PCRE C LIBRARY
  35. The following are generic comments about building the PCRE C library "by hand".
  36. (1) Copy or rename the file config.h.generic as config.h, and edit the macro
  37. settings that it contains to whatever is appropriate for your environment.
  38. In particular, if you want to force a specific value for newline, you can
  39. define the NEWLINE macro. When you compile any of the PCRE modules, you
  40. must specify -DHAVE_CONFIG_H to your compiler so that config.h is included
  41. in the sources.
  42. An alternative approach is not to edit config.h, but to use -D on the
  43. compiler command line to make any changes that you need to the
  44. configuration options. In this case -DHAVE_CONFIG_H must not be set.
  45. NOTE: There have been occasions when the way in which certain parameters
  46. in config.h are used has changed between releases. (In the configure/make
  47. world, this is handled automatically.) When upgrading to a new release,
  48. you are strongly advised to review config.h.generic before re-using what
  49. you had previously.
  50. (2) Copy or rename the file pcre.h.generic as pcre.h.
  51. (3) EITHER:
  52. Copy or rename file pcre_chartables.c.dist as pcre_chartables.c.
  53. OR:
  54. Compile dftables.c as a stand-alone program (using -DHAVE_CONFIG_H if
  55. you have set up config.h), and then run it with the single argument
  56. "pcre_chartables.c". This generates a set of standard character tables
  57. and writes them to that file. The tables are generated using the default
  58. C locale for your system. If you want to use a locale that is specified
  59. by LC_xxx environment variables, add the -L option to the dftables
  60. command. You must use this method if you are building on a system that
  61. uses EBCDIC code.
  62. The tables in pcre_chartables.c are defaults. The caller of PCRE can
  63. specify alternative tables at run time.
  64. (4) Ensure that you have the following header files:
  65. pcre_internal.h
  66. ucp.h
  67. (5) Also ensure that you have the following file, which is #included as source
  68. when building a debugging version of PCRE, and is also used by pcretest.
  69. pcre_printint.src
  70. (6) Compile the following source files, setting -DHAVE_CONFIG_H as a compiler
  71. option if you have set up config.h with your configuration, or else use
  72. other -D settings to change the configuration as required.
  73. pcre_chartables.c
  74. pcre_compile.c
  75. pcre_config.c
  76. pcre_dfa_exec.c
  77. pcre_exec.c
  78. pcre_fullinfo.c
  79. pcre_get.c
  80. pcre_globals.c
  81. pcre_info.c
  82. pcre_maketables.c
  83. pcre_newline.c
  84. pcre_ord2utf8.c
  85. pcre_refcount.c
  86. pcre_study.c
  87. pcre_tables.c
  88. pcre_try_flipped.c
  89. pcre_ucd.c
  90. pcre_valid_utf8.c
  91. pcre_version.c
  92. pcre_xclass.c
  93. Make sure that you include -I. in the compiler command (or equivalent for
  94. an unusual compiler) so that all included PCRE header files are first
  95. sought in the current directory. Otherwise you run the risk of picking up
  96. a previously-installed file from somewhere else.
  97. (7) Now link all the compiled code into an object library in whichever form
  98. your system keeps such libraries. This is the basic PCRE C library. If
  99. your system has static and shared libraries, you may have to do this once
  100. for each type.
  101. (8) Similarly, compile pcreposix.c (remembering -DHAVE_CONFIG_H if necessary)
  102. and link the result (on its own) as the pcreposix library.
  103. (9) Compile the test program pcretest.c (again, don't forget -DHAVE_CONFIG_H).
  104. This needs the functions in the pcre and pcreposix libraries when linking.
  105. It also needs the pcre_printint.src source file, which it #includes.
  106. (10) Run pcretest on the testinput files in the testdata directory, and check
  107. that the output matches the corresponding testoutput files. Note that the
  108. supplied files are in Unix format, with just LF characters as line
  109. terminators. You may need to edit them to change this if your system uses
  110. a different convention. If you are using Windows, you probably should use
  111. the wintestinput3 file instead of testinput3 (and the corresponding output
  112. file). This is a locale test; wintestinput3 sets the locale to "french"
  113. rather than "fr_FR", and there some minor output differences.
  114. (11) If you want to use the pcregrep command, compile and link pcregrep.c; it
  115. uses only the basic PCRE library (it does not need the pcreposix library).
  116. THE C++ WRAPPER FUNCTIONS
  117. The PCRE distribution also contains some C++ wrapper functions and tests,
  118. contributed by Google Inc. On a system that can use "configure" and "make",
  119. the functions are automatically built into a library called pcrecpp. It should
  120. be straightforward to compile the .cc files manually on other systems. The
  121. files called xxx_unittest.cc are test programs for each of the corresponding
  122. xxx.cc files.
  123. BUILDING FOR VIRTUAL PASCAL
  124. A script for building PCRE using Borland's C++ compiler for use with VPASCAL
  125. was contributed by Alexander Tokarev. Stefan Weber updated the script and added
  126. additional files. The following files in the distribution are for building PCRE
  127. for use with VP/Borland: makevp_c.txt, makevp_l.txt, makevp.bat, pcregexp.pas.
  128. STACK SIZE IN WINDOWS ENVIRONMENTS
  129. The default processor stack size of 1Mb in some Windows environments is too
  130. small for matching patterns that need much recursion. In particular, test 2 may
  131. fail because of this. Normally, running out of stack causes a crash, but there
  132. have been cases where the test program has just died silently. See your linker
  133. documentation for how to increase stack size if you experience problems. The
  134. Linux default of 8Mb is a reasonable choice for the stack, though even that can
  135. be too small for some pattern/subject combinations.
  136. PCRE has a compile configuration option to disable the use of stack for
  137. recursion so that heap is used instead. However, pattern matching is
  138. significantly slower when this is done. There is more about stack usage in the
  139. "pcrestack" documentation.
  140. LINKING PROGRAMS IN WINDOWS ENVIRONMENTS
  141. If you want to statically link a program against a PCRE library in the form of
  142. a non-dll .a file, you must define PCRE_STATIC before including pcre.h,
  143. otherwise the pcre_malloc() and pcre_free() exported functions will be declared
  144. __declspec(dllimport), with unwanted results.
  145. CALLING CONVENTIONS IN WINDOWS ENVIRONMENTS
  146. It is possible to compile programs to use different calling conventions using
  147. MSVC. Search the web for "calling conventions" for more information. To make it
  148. easier to change the calling convention for the exported functions in the
  149. PCRE library, the macro PCRE_CALL_CONVENTION is present in all the external
  150. definitions. It can be set externally when compiling (e.g. in CFLAGS). If it is
  151. not set, it defaults to empty; the default calling convention is then used
  152. (which is what is wanted most of the time).
  153. COMMENTS ABOUT WIN32 BUILDS (see also "BUILDING PCRE WITH CMAKE" below)
  154. There are two ways of building PCRE using the "configure, make, make install"
  155. paradigm on Windows systems: using MinGW or using Cygwin. These are not at all
  156. the same thing; they are completely different from each other. There is also
  157. support for building using CMake, which some users find a more straightforward
  158. way of building PCRE under Windows. However, the tests are not run
  159. automatically when CMake is used.
  160. The MinGW home page (http://www.mingw.org/) says this:
  161. MinGW: A collection of freely available and freely distributable Windows
  162. specific header files and import libraries combined with GNU toolsets that
  163. allow one to produce native Windows programs that do not rely on any
  164. 3rd-party C runtime DLLs.
  165. The Cygwin home page (http://www.cygwin.com/) says this:
  166. Cygwin is a Linux-like environment for Windows. It consists of two parts:
  167. . A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing
  168. substantial Linux API functionality
  169. . A collection of tools which provide Linux look and feel.
  170. The Cygwin DLL currently works with all recent, commercially released x86 32
  171. bit and 64 bit versions of Windows, with the exception of Windows CE.
  172. On both MinGW and Cygwin, PCRE should build correctly using:
  173. ./configure && make && make install
  174. This should create two libraries called libpcre and libpcreposix, and, if you
  175. have enabled building the C++ wrapper, a third one called libpcrecpp. These are
  176. independent libraries: when you like with libpcreposix or libpcrecpp you must
  177. also link with libpcre, which contains the basic functions. (Some earlier
  178. releases of PCRE included the basic libpcre functions in libpcreposix. This no
  179. longer happens.)
  180. A user submitted a special-purpose patch that makes it easy to create
  181. "pcre.dll" under mingw32 using the "msys" environment. It provides "pcre.dll"
  182. as a special target. If you use this target, no other files are built, and in
  183. particular, the pcretest and pcregrep programs are not built. An example of how
  184. this might be used is:
  185. ./configure --enable-utf --disable-cpp CFLAGS="-03 -s"; make pcre.dll
  186. Using Cygwin's compiler generates libraries and executables that depend on
  187. cygwin1.dll. If a library that is generated this way is distributed,
  188. cygwin1.dll has to be distributed as well. Since cygwin1.dll is under the GPL
  189. licence, this forces not only PCRE to be under the GPL, but also the entire
  190. application. A distributor who wants to keep their own code proprietary must
  191. purchase an appropriate Cygwin licence.
  192. MinGW has no such restrictions. The MinGW compiler generates a library or
  193. executable that can run standalone on Windows without any third party dll or
  194. licensing issues.
  195. But there is more complication:
  196. If a Cygwin user uses the -mno-cygwin Cygwin gcc flag, what that really does is
  197. to tell Cygwin's gcc to use the MinGW gcc. Cygwin's gcc is only acting as a
  198. front end to MinGW's gcc (if you install Cygwin's gcc, you get both Cygwin's
  199. gcc and MinGW's gcc). So, a user can:
  200. . Build native binaries by using MinGW or by getting Cygwin and using
  201. -mno-cygwin.
  202. . Build binaries that depend on cygwin1.dll by using Cygwin with the normal
  203. compiler flags.
  204. The test files that are supplied with PCRE are in Unix format, with LF
  205. characters as line terminators. It may be necessary to change the line
  206. terminators in order to get some of the tests to work. We hope to improve
  207. things in this area in future.
  208. BUILDING PCRE ON WINDOWS WITH CMAKE
  209. CMake is an alternative build facility that can be used instead of the
  210. traditional Unix "configure". CMake version 2.4.7 supports Borland makefiles,
  211. MinGW makefiles, MSYS makefiles, NMake makefiles, UNIX makefiles, Visual Studio
  212. 6, Visual Studio 7, Visual Studio 8, and Watcom W8. The following instructions
  213. were contributed by a PCRE user.
  214. 1. Download CMake 2.4.7 or above from http://www.cmake.org/, install and ensure
  215. that cmake\bin is on your path.
  216. 2. Unzip (retaining folder structure) the PCRE source tree into a source
  217. directory such as C:\pcre.
  218. 3. Create a new, empty build directory: C:\pcre\build\
  219. 4. Run CMakeSetup from the Shell envirornment of your build tool, e.g., Msys
  220. for Msys/MinGW or Visual Studio Command Prompt for VC/VC++
  221. 5. Enter C:\pcre\pcre-xx and C:\pcre\build for the source and build
  222. directories, respectively
  223. 6. Hit the "Configure" button.
  224. 7. Select the particular IDE / build tool that you are using (Visual Studio,
  225. MSYS makefiles, MinGW makefiles, etc.)
  226. 8. The GUI will then list several configuration options. This is where you can
  227. enable UTF-8 support, etc.
  228. 9. Hit "Configure" again. The adjacent "OK" button should now be active.
  229. 10. Hit "OK".
  230. 11. The build directory should now contain a usable build system, be it a
  231. solution file for Visual Studio, makefiles for MinGW, etc.
  232. USE OF RELATIVE PATHS WITH CMAKE ON WINDOWS
  233. A PCRE user comments as follows:
  234. I thought that others may want to know the current state of
  235. CMAKE_USE_RELATIVE_PATHS support on Windows.
  236. Here it is:
  237. -- AdditionalIncludeDirectories is only partially modified (only the
  238. first path - see below)
  239. -- Only some of the contained file paths are modified - shown below for
  240. pcre.vcproj
  241. -- It properly modifies
  242. I am sure CMake people can fix that if they want to. Until then one will
  243. need to replace existing absolute paths in project files with relative
  244. paths manually (e.g. from VS) - relative to project file location. I did
  245. just that before being told to try CMAKE_USE_RELATIVE_PATHS. Not a big
  246. deal.
  247. AdditionalIncludeDirectories="E:\builds\pcre\build;E:\builds\pcre\pcre-7.5;"
  248. AdditionalIncludeDirectories=".;E:\builds\pcre\pcre-7.5;"
  249. RelativePath="pcre.h">
  250. RelativePath="pcre_chartables.c">
  251. RelativePath="pcre_chartables.c.rule">
  252. TESTING WITH RUNTEST.BAT
  253. 1. Copy RunTest.bat into the directory where pcretest.exe has been created.
  254. 2. Edit RunTest.bat and insert a line that indentifies the relative location of
  255. the pcre source, e.g.:
  256. set srcdir=..\pcre-7.4-RC3
  257. 3. Run RunTest.bat from a command shell environment. Test outputs will
  258. automatically be compared to expected results, and discrepancies will
  259. identified in the console output.
  260. 4. To test pcrecpp, run pcrecpp_unittest.exe, pcre_stringpiece_unittest.exe and
  261. pcre_scanner_unittest.exe.
  262. BUILDING UNDER WINDOWS WITH BCC5.5
  263. Michael Roy sent these comments about building PCRE under Windows with BCC5.5:
  264. Some of the core BCC libraries have a version of PCRE from 1998 built in,
  265. which can lead to pcre_exec() giving an erroneous PCRE_ERROR_NULL from a
  266. version mismatch. I'm including an easy workaround below, if you'd like to
  267. include it in the non-unix instructions:
  268. When linking a project with BCC5.5, pcre.lib must be included before any of
  269. the libraries cw32.lib, cw32i.lib, cw32mt.lib, and cw32mti.lib on the command
  270. line.
  271. BUILDING PCRE ON OPENVMS
  272. Dan Mooney sent the following comments about building PCRE on OpenVMS. They
  273. relate to an older version of PCRE that used fewer source files, so the exact
  274. commands will need changing. See the current list of source files above.
  275. "It was quite easy to compile and link the library. I don't have a formal
  276. make file but the attached file [reproduced below] contains the OpenVMS DCL
  277. commands I used to build the library. I had to add #define
  278. POSIX_MALLOC_THRESHOLD 10 to pcre.h since it was not defined anywhere.
  279. The library was built on:
  280. O/S: HP OpenVMS v7.3-1
  281. Compiler: Compaq C v6.5-001-48BCD
  282. Linker: vA13-01
  283. The test results did not match 100% due to the issues you mention in your
  284. documentation regarding isprint(), iscntrl(), isgraph() and ispunct(). I
  285. modified some of the character tables temporarily and was able to get the
  286. results to match. Tests using the fr locale did not match since I don't have
  287. that locale loaded. The study size was always reported to be 3 less than the
  288. value in the standard test output files."
  289. =========================
  290. $! This DCL procedure builds PCRE on OpenVMS
  291. $!
  292. $! I followed the instructions in the non-unix-use file in the distribution.
  293. $!
  294. $ COMPILE == "CC/LIST/NOMEMBER_ALIGNMENT/PREFIX_LIBRARY_ENTRIES=ALL_ENTRIES
  295. $ COMPILE DFTABLES.C
  296. $ LINK/EXE=DFTABLES.EXE DFTABLES.OBJ
  297. $ RUN DFTABLES.EXE/OUTPUT=CHARTABLES.C
  298. $ COMPILE MAKETABLES.C
  299. $ COMPILE GET.C
  300. $ COMPILE STUDY.C
  301. $! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
  302. $! did not seem to be defined anywhere.
  303. $! I edited pcre.h and added #DEFINE SUPPORT_UTF8 to enable UTF8 support.
  304. $ COMPILE PCRE.C
  305. $ LIB/CREATE PCRE MAKETABLES.OBJ, GET.OBJ, STUDY.OBJ, PCRE.OBJ
  306. $! I had to set POSIX_MALLOC_THRESHOLD to 10 in PCRE.H since the symbol
  307. $! did not seem to be defined anywhere.
  308. $ COMPILE PCREPOSIX.C
  309. $ LIB/CREATE PCREPOSIX PCREPOSIX.OBJ
  310. $ COMPILE PCRETEST.C
  311. $ LINK/EXE=PCRETEST.EXE PCRETEST.OBJ, PCRE/LIB, PCREPOSIX/LIB
  312. $! C programs that want access to command line arguments must be
  313. $! defined as a symbol
  314. $ PCRETEST :== "$ SYS$ROADSUSERS:[DMOONEY.REGEXP]PCRETEST.EXE"
  315. $! Arguments must be enclosed in quotes.
  316. $ PCRETEST "-C"
  317. $! Test results:
  318. $!
  319. $! The test results did not match 100%. The functions isprint(), iscntrl(),
  320. $! isgraph() and ispunct() on OpenVMS must not produce the same results
  321. $! as the system that built the test output files provided with the
  322. $! distribution.
  323. $!
  324. $! The study size did not match and was always 3 less on OpenVMS.
  325. $!
  326. $! Locale could not be set to fr
  327. $!
  328. =========================
  329. Last Updated: 05 September 2008
  330. ****