gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

227 lines
18KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>37.18. Extension Building Infrastructure</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="extend-extensions.html" title="37.17. Packaging Related Objects into an Extension" /><link rel="next" href="triggers.html" title="Chapter 38. Triggers" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">37.18. Extension Building Infrastructure</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="extend-extensions.html" title="37.17. Packaging Related Objects into an Extension">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="extend.html" title="Chapter 37. Extending SQL">Up</a></td><th width="60%" align="center">Chapter 37. Extending <acronym xmlns="http://www.w3.org/1999/xhtml" class="acronym">SQL</acronym></th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="triggers.html" title="Chapter 38. Triggers">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="EXTEND-PGXS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">37.18. Extension Building Infrastructure</h2></div></div></div><a id="id-1.8.3.21.2" class="indexterm"></a><p>
  3. If you are thinking about distributing your
  4. <span class="productname">PostgreSQL</span> extension modules, setting up a
  5. portable build system for them can be fairly difficult. Therefore
  6. the <span class="productname">PostgreSQL</span> installation provides a build
  7. infrastructure for extensions, called <acronym class="acronym">PGXS</acronym>, so
  8. that simple extension modules can be built simply against an
  9. already installed server. <acronym class="acronym">PGXS</acronym> is mainly intended
  10. for extensions that include C code, although it can be used for
  11. pure-SQL extensions too. Note that <acronym class="acronym">PGXS</acronym> is not
  12. intended to be a universal build system framework that can be used
  13. to build any software interfacing to <span class="productname">PostgreSQL</span>;
  14. it simply automates common build rules for simple server extension
  15. modules. For more complicated packages, you might need to write your
  16. own build system.
  17. </p><p>
  18. To use the <acronym class="acronym">PGXS</acronym> infrastructure for your extension,
  19. you must write a simple makefile.
  20. In the makefile, you need to set some variables
  21. and include the global <acronym class="acronym">PGXS</acronym> makefile.
  22. Here is an example that builds an extension module named
  23. <code class="literal">isbn_issn</code>, consisting of a shared library containing
  24. some C code, an extension control file, a SQL script, an include file
  25. (only needed if other modules might need to access the extension functions
  26. without going via SQL), and a documentation text file:
  27. </p><pre class="programlisting">
  28. MODULES = isbn_issn
  29. EXTENSION = isbn_issn
  30. DATA = isbn_issn--1.0.sql
  31. DOCS = README.isbn_issn
  32. HEADERS_isbn_issn = isbn_issn.h
  33. PG_CONFIG = pg_config
  34. PGXS := $(shell $(PG_CONFIG) --pgxs)
  35. include $(PGXS)
  36. </pre><p>
  37. The last three lines should always be the same. Earlier in the
  38. file, you assign variables or add custom
  39. <span class="application">make</span> rules.
  40. </p><p>
  41. Set one of these three variables to specify what is built:
  42. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="varname">MODULES</code></span></dt><dd><p>
  43. list of shared-library objects to be built from source files with same
  44. stem (do not include library suffixes in this list)
  45. </p></dd><dt><span class="term"><code class="varname">MODULE_big</code></span></dt><dd><p>
  46. a shared library to build from multiple source files
  47. (list object files in <code class="varname">OBJS</code>)
  48. </p></dd><dt><span class="term"><code class="varname">PROGRAM</code></span></dt><dd><p>
  49. an executable program to build
  50. (list object files in <code class="varname">OBJS</code>)
  51. </p></dd></dl></div><p>
  52. The following variables can also be set:
  53. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="varname">EXTENSION</code></span></dt><dd><p>
  54. extension name(s); for each name you must provide an
  55. <code class="literal"><em class="replaceable"><code>extension</code></em>.control</code> file,
  56. which will be installed into
  57. <code class="literal"><em class="replaceable"><code>prefix</code></em>/share/extension</code>
  58. </p></dd><dt><span class="term"><code class="varname">MODULEDIR</code></span></dt><dd><p>
  59. subdirectory of <code class="literal"><em class="replaceable"><code>prefix</code></em>/share</code>
  60. into which DATA and DOCS files should be installed
  61. (if not set, default is <code class="literal">extension</code> if
  62. <code class="varname">EXTENSION</code> is set,
  63. or <code class="literal">contrib</code> if not)
  64. </p></dd><dt><span class="term"><code class="varname">DATA</code></span></dt><dd><p>
  65. random files to install into <code class="literal"><em class="replaceable"><code>prefix</code></em>/share/$MODULEDIR</code>
  66. </p></dd><dt><span class="term"><code class="varname">DATA_built</code></span></dt><dd><p>
  67. random files to install into
  68. <code class="literal"><em class="replaceable"><code>prefix</code></em>/share/$MODULEDIR</code>,
  69. which need to be built first
  70. </p></dd><dt><span class="term"><code class="varname">DATA_TSEARCH</code></span></dt><dd><p>
  71. random files to install under
  72. <code class="literal"><em class="replaceable"><code>prefix</code></em>/share/tsearch_data</code>
  73. </p></dd><dt><span class="term"><code class="varname">DOCS</code></span></dt><dd><p>
  74. random files to install under
  75. <code class="literal"><em class="replaceable"><code>prefix</code></em>/doc/$MODULEDIR</code>
  76. </p></dd><dt><span class="term"><code class="varname">HEADERS</code><br /></span><span class="term"><code class="varname">HEADERS_built</code></span></dt><dd><p>
  77. Files to (optionally build and) install under
  78. <code class="literal"><em class="replaceable"><code>prefix</code></em>/include/server/$MODULEDIR/$MODULE_big</code>.
  79. </p><p>
  80. Unlike <code class="literal">DATA_built</code>, files in <code class="literal">HEADERS_built</code>
  81. are not removed by the <code class="literal">clean</code> target; if you want them removed,
  82. also add them to <code class="literal">EXTRA_CLEAN</code> or add your own rules to do it.
  83. </p></dd><dt><span class="term"><code class="varname">HEADERS_$MODULE</code><br /></span><span class="term"><code class="varname">HEADERS_built_$MODULE</code></span></dt><dd><p>
  84. Files to install (after building if specified) under
  85. <code class="literal"><em class="replaceable"><code>prefix</code></em>/include/server/$MODULEDIR/$MODULE</code>,
  86. where <code class="literal">$MODULE</code> must be a module name used
  87. in <code class="literal">MODULES</code> or <code class="literal">MODULE_big</code>.
  88. </p><p>
  89. Unlike <code class="literal">DATA_built</code>, files in <code class="literal">HEADERS_built_$MODULE</code>
  90. are not removed by the <code class="literal">clean</code> target; if you want them removed,
  91. also add them to <code class="literal">EXTRA_CLEAN</code> or add your own rules to do it.
  92. </p><p>
  93. It is legal to use both variables for the same module, or any
  94. combination, unless you have two module names in the
  95. <code class="literal">MODULES</code> list that differ only by the presence of a
  96. prefix <code class="literal">built_</code>, which would cause ambiguity. In
  97. that (hopefully unlikely) case, you should use only the
  98. <code class="literal">HEADERS_built_$MODULE</code> variables.
  99. </p></dd><dt><span class="term"><code class="varname">SCRIPTS</code></span></dt><dd><p>
  100. script files (not binaries) to install into
  101. <code class="literal"><em class="replaceable"><code>prefix</code></em>/bin</code>
  102. </p></dd><dt><span class="term"><code class="varname">SCRIPTS_built</code></span></dt><dd><p>
  103. script files (not binaries) to install into
  104. <code class="literal"><em class="replaceable"><code>prefix</code></em>/bin</code>,
  105. which need to be built first
  106. </p></dd><dt><span class="term"><code class="varname">REGRESS</code></span></dt><dd><p>
  107. list of regression test cases (without suffix), see below
  108. </p></dd><dt><span class="term"><code class="varname">REGRESS_OPTS</code></span></dt><dd><p>
  109. additional switches to pass to <span class="application">pg_regress</span>
  110. </p></dd><dt><span class="term"><code class="varname">ISOLATION</code></span></dt><dd><p>
  111. list of isolation test cases, see below for more details
  112. </p></dd><dt><span class="term"><code class="varname">ISOLATION_OPTS</code></span></dt><dd><p>
  113. additional switches to pass to
  114. <span class="application">pg_isolation_regress</span>
  115. </p></dd><dt><span class="term"><code class="varname">TAP_TESTS</code></span></dt><dd><p>
  116. switch defining if TAP tests need to be run, see below
  117. </p></dd><dt><span class="term"><code class="varname">NO_INSTALLCHECK</code></span></dt><dd><p>
  118. don't define an <code class="literal">installcheck</code> target, useful e.g. if tests require special configuration, or don't use <span class="application">pg_regress</span>
  119. </p></dd><dt><span class="term"><code class="varname">EXTRA_CLEAN</code></span></dt><dd><p>
  120. extra files to remove in <code class="literal">make clean</code>
  121. </p></dd><dt><span class="term"><code class="varname">PG_CPPFLAGS</code></span></dt><dd><p>
  122. will be prepended to <code class="varname">CPPFLAGS</code>
  123. </p></dd><dt><span class="term"><code class="varname">PG_CFLAGS</code></span></dt><dd><p>
  124. will be appended to <code class="varname">CFLAGS</code>
  125. </p></dd><dt><span class="term"><code class="varname">PG_CXXFLAGS</code></span></dt><dd><p>
  126. will be appended to <code class="varname">CXXFLAGS</code>
  127. </p></dd><dt><span class="term"><code class="varname">PG_LDFLAGS</code></span></dt><dd><p>
  128. will be prepended to <code class="varname">LDFLAGS</code>
  129. </p></dd><dt><span class="term"><code class="varname">PG_LIBS</code></span></dt><dd><p>
  130. will be added to <code class="varname">PROGRAM</code> link line
  131. </p></dd><dt><span class="term"><code class="varname">SHLIB_LINK</code></span></dt><dd><p>
  132. will be added to <code class="varname">MODULE_big</code> link line
  133. </p></dd><dt><span class="term"><code class="varname">PG_CONFIG</code></span></dt><dd><p>
  134. path to <span class="application">pg_config</span> program for the
  135. <span class="productname">PostgreSQL</span> installation to build against
  136. (typically just <code class="literal">pg_config</code> to use the first one in your
  137. <code class="varname">PATH</code>)
  138. </p></dd></dl></div><p>
  139. </p><p>
  140. Put this makefile as <code class="literal">Makefile</code> in the directory
  141. which holds your extension. Then you can do
  142. <code class="literal">make</code> to compile, and then <code class="literal">make
  143. install</code> to install your module. By default, the extension is
  144. compiled and installed for the
  145. <span class="productname">PostgreSQL</span> installation that
  146. corresponds to the first <code class="command">pg_config</code> program
  147. found in your <code class="varname">PATH</code>. You can use a different installation by
  148. setting <code class="varname">PG_CONFIG</code> to point to its
  149. <code class="command">pg_config</code> program, either within the makefile
  150. or on the <code class="literal">make</code> command line.
  151. </p><p>
  152. You can also run <code class="literal">make</code> in a directory outside the source
  153. tree of your extension, if you want to keep the build directory separate.
  154. This procedure is also called a
  155. <a id="id-1.8.3.21.7.2" class="indexterm"></a><em class="firstterm">VPATH</em>
  156. build. Here's how:
  157. </p><pre class="programlisting">
  158. mkdir build_dir
  159. cd build_dir
  160. make -f /path/to/extension/source/tree/Makefile
  161. make -f /path/to/extension/source/tree/Makefile install
  162. </pre><p>
  163. </p><p>
  164. Alternatively, you can set up a directory for a VPATH build in a similar
  165. way to how it is done for the core code. One way to do this is using the
  166. core script <code class="filename">config/prep_buildtree</code>. Once this has been done
  167. you can build by setting the <code class="literal">make</code> variable
  168. <code class="varname">VPATH</code> like this:
  169. </p><pre class="programlisting">
  170. make VPATH=/path/to/extension/source/tree
  171. make VPATH=/path/to/extension/source/tree install
  172. </pre><p>
  173. This procedure can work with a greater variety of directory layouts.
  174. </p><p>
  175. The scripts listed in the <code class="varname">REGRESS</code> variable are used for
  176. regression testing of your module, which can be invoked by <code class="literal">make
  177. installcheck</code> after doing <code class="literal">make install</code>. For this to
  178. work you must have a running <span class="productname">PostgreSQL</span> server.
  179. The script files listed in <code class="varname">REGRESS</code> must appear in a
  180. subdirectory named <code class="literal">sql/</code> in your extension's directory.
  181. These files must have extension <code class="literal">.sql</code>, which must not be
  182. included in the <code class="varname">REGRESS</code> list in the makefile. For each
  183. test there should also be a file containing the expected output in a
  184. subdirectory named <code class="literal">expected/</code>, with the same stem and
  185. extension <code class="literal">.out</code>. <code class="literal">make installcheck</code>
  186. executes each test script with <span class="application">psql</span>, and compares the
  187. resulting output to the matching expected file. Any differences will be
  188. written to the file <code class="literal">regression.diffs</code> in <code class="command">diff
  189. -c</code> format. Note that trying to run a test that is missing its
  190. expected file will be reported as <span class="quote">“<span class="quote">trouble</span>”</span>, so make sure you
  191. have all expected files.
  192. </p><p>
  193. The scripts listed in the <code class="varname">ISOLATION</code> variable are used
  194. for tests stressing behavior of concurrent session with your module, which
  195. can be invoked by <code class="literal">make installcheck</code> after doing
  196. <code class="literal">make install</code>. For this to work you must have a
  197. running <span class="productname">PostgreSQL</span> server. The script files
  198. listed in <code class="varname">ISOLATION</code> must appear in a subdirectory
  199. named <code class="literal">specs/</code> in your extension's directory. These files
  200. must have extension <code class="literal">.spec</code>, which must not be included
  201. in the <code class="varname">ISOLATION</code> list in the makefile. For each test
  202. there should also be a file containing the expected output in a
  203. subdirectory named <code class="literal">expected/</code>, with the same stem and
  204. extension <code class="literal">.out</code>. <code class="literal">make installcheck</code>
  205. executes each test script, and compares the resulting output to the
  206. matching expected file. Any differences will be written to the file
  207. <code class="literal">output_iso/regression.diffs</code> in
  208. <code class="command">diff -c</code> format. Note that trying to run a test that is
  209. missing its expected file will be reported as <span class="quote">“<span class="quote">trouble</span>”</span>, so
  210. make sure you have all expected files.
  211. </p><p>
  212. <code class="literal">TAP_TESTS</code> enables the use of TAP tests. Data from each
  213. run is present in a subdirectory named <code class="literal">tmp_check/</code>.
  214. See also <a class="xref" href="regress-tap.html" title="32.4. TAP Tests">Section 32.4</a> for more details.
  215. </p><div class="tip"><h3 class="title">Tip</h3><p>
  216. The easiest way to create the expected files is to create empty files,
  217. then do a test run (which will of course report differences). Inspect
  218. the actual result files found in the <code class="literal">results/</code>
  219. directory (for tests in <code class="literal">REGRESS</code>), or
  220. <code class="literal">output_iso/results/</code> directory (for tests in
  221. <code class="literal">ISOLATION</code>), then copy them to
  222. <code class="literal">expected/</code> if they match what you expect from the test.
  223. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="extend-extensions.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="extend.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="triggers.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">37.17. Packaging Related Objects into an Extension </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 38. Triggers</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1