バージョンごとのドキュメント一覧

38.18. 拡張構築基盤 #

<title>Extension Building Infrastructure</title>

If you are thinking about distributing your <productname>PostgreSQL</productname> extension modules, setting up a portable build system for them can be fairly difficult. Therefore the <productname>PostgreSQL</productname> installation provides a build infrastructure for extensions, called <acronym>PGXS</acronym>, so that simple extension modules can be built simply against an already installed server. <acronym>PGXS</acronym> is mainly intended for extensions that include C code, although it can be used for pure-SQL extensions too. Note that <acronym>PGXS</acronym> is not intended to be a universal build system framework that can be used to build any software interfacing to <productname>PostgreSQL</productname>; it simply automates common build rules for simple server extension modules. For more complicated packages, you might need to write your own build system. PostgreSQL拡張モジュールの配布を考えているのであれば、移植可能な構築システムを準備することはかなり難しいものになるかもしれません。 このためPostgreSQLインストレーションは単純な拡張モジュールをすでにインストールされているサーバに対して簡単に構築できるように、PGXSと呼ばれる拡張向けの構築基盤を提供します。 PGXSは主にCコードを含む拡張を意図していますが、SQLのみからなる拡張でも使用できます。 PGXSPostgreSQLと相互に作用する任意のソフトウェアを構築するために使用できるような万能な構築システムを意図したものではないことに注意してください。 これは単に、単純なサーバ拡張用の一般的な構築規則を自動化するものです。 より複雑なパッケージでは、独自の構築システムを作成する必要があるかもしれません。

To use the <acronym>PGXS</acronym> infrastructure for your extension, you must write a simple makefile. In the makefile, you need to set some variables and include the global <acronym>PGXS</acronym> makefile. Here is an example that builds an extension module named <literal>isbn_issn</literal>, consisting of a shared library containing some C code, an extension control file, an SQL script, an include file (only needed if other modules might need to access the extension functions without going via SQL), and a documentation text file: 独自の拡張でPGXS基盤を使用するためには、簡単なmakefileを作成する必要があります。 このmakefileの中で、いくつか変数を設定し、大域的なPGXSmakefileをインクルードする必要があります。 以下にisbn_issnという名称の拡張モジュールを構築する例を示します。 このモジュールはいくつかのCコードを含む共有ライブラリ、拡張の制御ファイル、SQLスクリプト、インクルードファイル(他のモジュールが拡張の関数にSQLを経由せずにアクセスする必要があるかもしれない場合にのみ必要です)、ドキュメントテキストファイルから構成されます。

MODULES = isbn_issn
EXTENSION = isbn_issn
DATA = isbn_issn--1.0.sql
DOCS = README.isbn_issn
HEADERS_isbn_issn = isbn_issn.h

PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

The last three lines should always be the same. Earlier in the file, you assign variables or add custom <application>make</application> rules. 最後の3行は常に同じです。 ファイルのこの前に変数の設定と独自のmakeルールを記載してください。

Set one of these three variables to specify what is built: 以下の3個の変数の1つを構築対象に指定してください。

MODULES #

list of shared-library objects to be built from source files with same stem (do not include library suffixes in this list) 同じ家系のソースファイルから構築される共有ライブラリのリストです。 (このリストにはライブラリ接頭辞を含めないでください。)

MODULE_big #

a shared library to build from multiple source files (list object files in <varname>OBJS</varname>) 複数のソースファイルから構築される共有ライブラリです。 (OBJSにオブジェクトファイルを列挙します。)

PROGRAM #

an executable program to build (list object files in <varname>OBJS</varname>) 構築する実行プログラムです。 (OBJSにオブジェクトファイルを列挙します。)

The following variables can also be set: 以下の変数も設定できます。

EXTENSION #

extension name(s); for each name you must provide an <literal><replaceable>extension</replaceable>.control</literal> file, which will be installed into <literal><replaceable>prefix</replaceable>/share/extension</literal> 拡張の名前です。 各名前に対して、prefix/share/extensionにインストールされるextension.controlを提供しなければなりません。

MODULEDIR #

subdirectory of <literal><replaceable>prefix</replaceable>/share</literal> into which DATA and DOCS files should be installed (if not set, default is <literal>extension</literal> if <varname>EXTENSION</varname> is set, or <literal>contrib</literal> if not) DATAおよびDOCSファイルのインストール先となるはずのprefix/shareサブディレクトリです。 (設定がない場合、デフォルトはEXTENSIONが設定されている場合はextensionに、設定されていない場合はcontribになります。)

DATA #

random files to install into <literal><replaceable>prefix</replaceable>/share/$MODULEDIR</literal> prefix/share/$MODULEDIRにインストールされる様々なファイルです。

DATA_built #

random files to install into <literal><replaceable>prefix</replaceable>/share/$MODULEDIR</literal>, which need to be built first prefix/share/$MODULEDIRにインストールされる、最初に構築しなければならない様々なファイルです。

DATA_TSEARCH #

random files to install under <literal><replaceable>prefix</replaceable>/share/tsearch_data</literal> prefix/share/tsearch_data以下にインストールされる様々なファイルです。

DOCS #

random files to install under <literal><replaceable>prefix</replaceable>/doc/$MODULEDIR</literal> prefix/doc/$MODULEDIR以下にインストールされる様々なファイルです。

HEADERS
HEADERS_built #

Files to (optionally build and) install under <literal><replaceable>prefix</replaceable>/include/server/$MODULEDIR/$MODULE_big</literal>. (必要に応じてビルドして)prefix/include/server/$MODULEDIR/$MODULE_big以下にインストールをするファイル。

Unlike <literal>DATA_built</literal>, files in <literal>HEADERS_built</literal> are not removed by the <literal>clean</literal> target; if you want them removed, also add them to <literal>EXTRA_CLEAN</literal> or add your own rules to do it. DATA_builtと違って、HEADERS_builtのファイルはcleanターゲットによって削除されません。削除したい場合には、それらをEXTRA_CLEANにも加えるか、削除を行う独自のルールを追加してください。

HEADERS_$MODULE
HEADERS_built_$MODULE #

Files to install (after building if specified) under <literal><replaceable>prefix</replaceable>/include/server/$MODULEDIR/$MODULE</literal>, where <literal>$MODULE</literal> must be a module name used in <literal>MODULES</literal> or <literal>MODULE_big</literal>. (指定されていたならビルド後に)prefix/include/server/$MODULEDIR/$MODULEの下にインストールするファイル。ここでの$MODULEMODULESMODULE_bigで使われているモジュール名でなければなりません。

Unlike <literal>DATA_built</literal>, files in <literal>HEADERS_built_$MODULE</literal> are not removed by the <literal>clean</literal> target; if you want them removed, also add them to <literal>EXTRA_CLEAN</literal> or add your own rules to do it. DATA_builtと違って、HEADERS_built_$MODULEのファイルはcleanターゲットによって削除されません。削除したい場合には、これらをEXTRA_CLEANにも加えるか、削除を行う独自のルールを追加してください。

It is legal to use both variables for the same module, or any combination, unless you have two module names in the <literal>MODULES</literal> list that differ only by the presence of a prefix <literal>built_</literal>, which would cause ambiguity. In that (hopefully unlikely) case, you should use only the <literal>HEADERS_built_$MODULE</literal> variables. 同じモジュールあるいは任意の組み合わせに対して両方の変数を使うことは正当ですが、MODULESリストにプレフィックスbuilt_の有無しか異ならない二つのモジュール名を書く場合を除きます。これは両義解釈をひき起こすでしょう。 このような(おそらくありそうにない)場合、HEADERS_built_$MODULE変数だけを使うべきです。

SCRIPTS #

script files (not binaries) to install into <literal><replaceable>prefix</replaceable>/bin</literal> prefix/binにインストールされるスクリプトファイルです(バイナリファイルではありません)。

SCRIPTS_built #

script files (not binaries) to install into <literal><replaceable>prefix</replaceable>/bin</literal>, which need to be built first prefix/binにインストールされる、最初に構築しなければならないスクリプトファイルです(バイナリファイルではありません)。

REGRESS #

list of regression test cases (without suffix), see below リグレッションテストケース(接尾辞がない)のリストです。 後述します。

REGRESS_OPTS #

additional switches to pass to <application>pg_regress</application> pg_regressに渡す追加オプションです。

ISOLATION #

list of isolation test cases, see below for more details 分離性試験のリストです。 詳細は後述します。

ISOLATION_OPTS #

additional switches to pass to <application>pg_isolation_regress</application> pg_isolation_regressに渡す追加オプションです。

TAP_TESTS #

switch defining if TAP tests need to be run, see below TAPテストを実行する必要があるかどうかを定義するオプションです。 後述します。

NO_INSTALL #

don't define an <literal>install</literal> target, useful for test modules that don't need their build products to be installed installターゲットを定義しません。 構築物をインストールする必要のないテストモジュールに有用です。

NO_INSTALLCHECK #

don't define an <literal>installcheck</literal> target, useful e.g., if tests require special configuration, or don't use <application>pg_regress</application> installcheckターゲットを定義しません。 テストの際に特殊な設定が必要、あるいはpg_regressを使用しない場合などに有用です。

EXTRA_CLEAN #

extra files to remove in <literal>make clean</literal> make cleanで削除される追加ファイルです。

PG_CPPFLAGS #

will be prepended to <varname>CPPFLAGS</varname> CPPFLAGSの先頭に加えられます。

PG_CFLAGS #

will be appended to <varname>CFLAGS</varname> CFLAGSに加えられます。

PG_CXXFLAGS #

will be appended to <varname>CXXFLAGS</varname> CXXFLAGSに加えられます。

PG_LDFLAGS #

will be prepended to <varname>LDFLAGS</varname> LDFLAGSの先頭に加えられます。

PG_LIBS #

will be added to <varname>PROGRAM</varname> link line PROGRAMのリンク行に追加されます。

will be added to <varname>MODULE_big</varname> link line MODULE_bigリンク行に追加されます。

PG_CONFIG #

path to <application>pg_config</application> program for the <productname>PostgreSQL</productname> installation to build against (typically just <literal>pg_config</literal> to use the first one in your <varname>PATH</varname>) 構築対象のPostgreSQLインストレーション用のpg_configプログラムへのパスです。 (通常はPATH内の最初に見つかるpg_configが単純に使用されます)

Put this makefile as <literal>Makefile</literal> in the directory which holds your extension. Then you can do <literal>make</literal> to compile, and then <literal>make install</literal> to install your module. By default, the extension is compiled and installed for the <productname>PostgreSQL</productname> installation that corresponds to the first <command>pg_config</command> program found in your <varname>PATH</varname>. You can use a different installation by setting <varname>PG_CONFIG</varname> to point to its <command>pg_config</command> program, either within the makefile or on the <literal>make</literal> command line. このmakefileをMakefileとして拡張を保管するディレクトリ内に保管してください。 その後コンパイルするためにmakeを、モジュールをインストールするためにmake installを行うことができます。 デフォルトでは、PATHの中で最初に見つかるpg_configプログラムが対応するPostgreSQLインストレーション用に拡張はコンパイルされ、インストールされます。 makefileまたはmakeのコマンドラインのいずれかでPG_CONFIGを別のpg_configプログラムを指し示すように設定することで、別のインストレーションを使用できます。

You can also run <literal>make</literal> in a directory outside the source tree of your extension, if you want to keep the build directory separate. This procedure is also called a <indexterm><primary>VPATH</primary></indexterm><firstterm>VPATH</firstterm> build. Here's how: 構築ディレクトリを別にしておきたいのであれば、拡張のソースツリーの外のディレクトリでmakeを実行することもできます。 この方法はVPATH構築とも呼ばれます。 以下にやり方を示します。

mkdir build_dir
cd build_dir
make -f /path/to/extension/source/tree/Makefile
make -f /path/to/extension/source/tree/Makefile install

Alternatively, you can set up a directory for a VPATH build in a similar way to how it is done for the core code. One way to do this is using the core script <filename>config/prep_buildtree</filename>. Once this has been done you can build by setting the <literal>make</literal> variable <varname>VPATH</varname> like this: あるいは、コアコードと同様な方法でVPATH構築用のディレクトリを設定できます。 そのようにする1つの方法は、コアスクリプトconfig/prep_buildtreeを使うことです。 一度そうすれば、make変数VPATHを以下のように設定することで、構築できます。

make VPATH=/path/to/extension/source/tree
make VPATH=/path/to/extension/source/tree install

This procedure can work with a greater variety of directory layouts. この方法はより様々なディレクトリのレイアウトで機能します。

The scripts listed in the <varname>REGRESS</varname> variable are used for regression testing of your module, which can be invoked by <literal>make installcheck</literal> after doing <literal>make install</literal>. For this to work you must have a running <productname>PostgreSQL</productname> server. The script files listed in <varname>REGRESS</varname> must appear in a subdirectory named <literal>sql/</literal> in your extension's directory. These files must have extension <literal>.sql</literal>, which must not be included in the <varname>REGRESS</varname> list in the makefile. For each test there should also be a file containing the expected output in a subdirectory named <literal>expected/</literal>, with the same stem and extension <literal>.out</literal>. <literal>make installcheck</literal> executes each test script with <application>psql</application>, and compares the resulting output to the matching expected file. Any differences will be written to the file <literal>regression.diffs</literal> in <command>diff -c</command> format. Note that trying to run a test that is missing its expected file will be reported as <quote>trouble</quote>, so make sure you have all expected files. REGRESS変数に列挙されたスクリプトは、make installを実行した後でmake installcheckによって呼び出すことができる、作成したモジュールのリグレッションテストで使用されます。 これが動作するためには、PostgreSQLサーバが実行していなければなりません。 REGRESS変数に列挙されたスクリプトは、拡張のディレクトリ内のsql/という名前のサブディレクトリ内に存在しなければなりません。 これらのファイルは.sqlという拡張子を持たなければなりません。 この拡張子はmakefile内のREGRESSリストには含まれません。 また試験ごとにexpected/という名前のサブディレクトリ内に想定出力を内容として含む、同じステムに.out拡張子を付けた名前のファイルがなければなりません。 make installcheckpsqlを用いて各試験スクリプトを実行し、結果出力が想定ファイルに一致するかどうか比較します。 何らかの差異はdiff -c書式でregression.diffsに書き出されます。 想定ファイルがない試験を実行しようとすると問題として報告されます。 このためすべての想定ファイルがあることを確認してください。

The scripts listed in the <varname>ISOLATION</varname> variable are used for tests stressing behavior of concurrent session with your module, which can be invoked by <literal>make installcheck</literal> after doing <literal>make install</literal>. For this to work you must have a running <productname>PostgreSQL</productname> server. The script files listed in <varname>ISOLATION</varname> must appear in a subdirectory named <literal>specs/</literal> in your extension's directory. These files must have extension <literal>.spec</literal>, which must not be included in the <varname>ISOLATION</varname> list in the makefile. For each test there should also be a file containing the expected output in a subdirectory named <literal>expected/</literal>, with the same stem and extension <literal>.out</literal>. <literal>make installcheck</literal> executes each test script, and compares the resulting output to the matching expected file. Any differences will be written to the file <literal>output_iso/regression.diffs</literal> in <command>diff -c</command> format. Note that trying to run a test that is missing its expected file will be reported as <quote>trouble</quote>, so make sure you have all expected files. ISOLATION変数に列挙されたスクリプトは、make installを実行した後でmake installcheckによって呼び出すことができるモジュールでの同時実行中のセッションの振舞いの負荷テストで使用されます。 これが動作するためには、PostgreSQLサーバが実行していなければなりません。 ISOLATION変数に列挙されたスクリプトは、拡張のディレクトリ内のspecs/という名前のサブディレクトリ内に存在しなければなりません。 これらのファイルは.specという拡張子を持たなければなりません。 この拡張子はmakefile内のISOLATIONリストには含まれません。 また試験ごとにexpected/という名前のサブディレクトリ内に想定出力を内容として含む、同じステムに.out拡張子を付けた名前のファイルがなければなりません。 make installcheckは各試験スクリプトを実行し、結果出力が想定ファイルに一致するかどうか比較します。 何らかの差異はdiff -c書式でoutput_iso/regression.diffsに書き出されます。 想定ファイルがない試験を実行しようとすると問題として報告されます。 このためすべての想定ファイルがあることを確認してください。

<literal>TAP_TESTS</literal> enables the use of TAP tests. Data from each run is present in a subdirectory named <literal>tmp_check/</literal>. See also <xref linkend="regress-tap"/> for more details. TAP_TESTSはTAPテストの指定を有効にします。 各試験の実行によるデータはtmp_check/という名前のサブディレクトリに含まれます。 詳細は33.4を参照してください。

ヒント

The easiest way to create the expected files is to create empty files, then do a test run (which will of course report differences). Inspect the actual result files found in the <literal>results/</literal> directory (for tests in <literal>REGRESS</literal>), or <literal>output_iso/results/</literal> directory (for tests in <literal>ISOLATION</literal>), then copy them to <literal>expected/</literal> if they match what you expect from the test. 想定ファイルを作成する最も簡単な方法は、空のファイルを作成し、試験を実行する(当然差異が報告されます)ことです。 (REGRESSの試験による)results/ディレクトリまたは(ISOLATIONの試験による)output_iso/results/ディレクトリ内で見つかる実際の結果ファイルを確認し、テストの想定結果と合致するのであれば、expected/にコピーしてください。