.. 14-autoconf .. _label14: 14. 自動設定用の変数と関数 ================================== .. OMake standard library provides a number of functions and variables intended to help one write build specifications that need to be capable of autoconfiguring itself to adjust to different build environments. OMakeの標準ライブラリでは、異なったビルド環境下でのビルドを調整するための、自動設定用のコードを書くことを手助けする、数多くの関数や変数を提供しています。 .. _label14.1: 14.1 汎用的な自動設定関数 ---------------------------------- .. The following general-purpose functions can be used to discover the properties of your build environment in a fashion similar to the one used by GNU autoconf tool you may be familiar with. It is recommended that these function be used from an appropriate static. block (see Section 4.14 for more information). 以下にリストしてある汎用的な関数では、あなたの『ビルド環境(the properties of your build environment)』について調べることができます。これらの関数の中には、恐らくあなたがよく知っているであろうGNU autoconfツールによく似ているものも含まれています。また、これらの関数は適切な ``static.`` ブロックで使うことを推奨しています(詳細は ":ref:`label4.14`" を参照してください)。 .. In order to use the following general-purpose functions, you need to have the line included in your OMakefile or OMakeroot. 以下の汎用的な関数を使うためには、まずあなたの ``OMakeroot`` あるいは ``OMakefile`` ファイルに、以下の一行を追加してください。 :: open configure/Configure .. index:: single: ConfMsgChecking() single: ConfMsgResult() .. _label14.1.1: 14.1.1 ConfMsgChecking, ConfMsgResult ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: ConfMsgChecking() ... ConfMsgResult() .. The ConfMsgChecking function output message of the form --- Checking ... without any trailing newline. After the test advertized by ConfMsgChecking is performed, the ConfMsgResult function should be used to output the result. ``ConfMsgChecking`` 関数は ``--- Checking ...`` のような形のメッセージを *改行なしで* 出力します。 ``ConfMsgChecking`` が実行されて、後にテストが終わったときには、 ``ConfMsgResult`` 関数を使って結果を出力すべきです。 .. In certain cases users may want to redefine these function — for example, to use a different output formatting and/or to copy the messages to a log file. これらの関数を再定義したいという場合があるかもしれません。例えば、出力の形式を異なったものにしたいという場合や、メッセージをログファイルにコピーしたいというような場合です。 例:: static. = ConfMsgChecking(which foo to use) foo = ... ConfMsgResult($(foo)) .. index:: single: ConfMsgWarn() single: ConfMsgError() .. _label14.1.2: 14.1.2 ConfMsgWarn, ConfMsgError ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: ConfMsgWarn() ConfMsgError() .. Print a warning or an error message respectively. ConfMsgError would then abort OMake. 警告やエラーメッセージをそれぞれ表示します。 ``ConfMsgError`` はOMakeを中断させます。 .. index:: single: ConfMsgYesNo() single: ConfMsgFound() .. _label14.1.3: 14.1.3 ConfMsgYesNo, ConfMsgFound ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: flag = $(ConfMsgYesNo ) flag = $(ConfMsgFound ) .. The ConfMsgFound function expects to receive a boolean flag describing whether a test previously announced using the ConfMsgChecking function found what it was looking for. ConfMsgFound will output the appropriate result (“found” or “NOT found”) using the ConfMsgResult function and return its argument back. ``ConfMsgFound`` 関数を使う前にまず ``ConfMsgChecking`` 関数を用いて「コマンドが使用できるかどうか調べます」ということをユーザに伝えます。その後、その結果を真偽値で ``ConfMsgFound`` 関数に渡します。 ``ConfMsgFound`` は結果を適切な形("found"あるいは"NOT found")に直し、 ``ConfMsgResult`` 関数を使って出力します。また引数として渡された結果を、加工しないでそのまま返します。 .. The ConfMsgYesNo function is similar, outputting a simple (“yes” or “NO”). ``ConfMsgYesNo`` 関数は ``ConfMsgFound`` と似ていますが、出力がシンプルです("yes"あるいは"NO")。 .. index:: single: TryConpileC() single: TryLinkC() single: TryRunC() .. _label14.1.4: 14.1.4 TryCompileC, TryLinkC, TryRunC ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: success = $(TryCompileC ) success = $(TryLinkC ) success = $(TryRunC ) .. Given the text of a C program, the TryCompileC, TryLinkC, and TryRunC functions would try to compile / compile and link / compile, link, and run, the given program and return a boolean flag indicating whether the attempt was successful. Cプログラムの *コード* を引数として渡します。 ``TryCompileC`` , ``TryLinkC`` , ``TryRunC`` 関数は与えられた引数を『コンパイル/コンパイルとリンク/コンパイルとリンクと実行』できるかどうか試します。テストが成功した場合、この関数は真を返します。一方で、失敗した場合は偽を返します。 .. TryCompileC will use the CC, CFLAGS and INCLUDES variables to run the C compiler. TryLinkC and TryRunC will also use the LDFLAGS variable to run the C compiler and linker. However, the flags like /WX, -Werror and -warn-error will be not be passed to the compiler, even if they occur in CFLAGS. ``TryCompileC`` はCコンパイラを実行するときに ``CC`` , ``CFLAGS`` , ``INCLUDES`` 変数を使用します。 ``TryLinkC`` と ``TryRunC`` はそれに加えて ``LDFLAGS`` 変数を、Cコンパイラとリンカを実行するときに使用します。しかし、 ``/WX`` , ``-Werror`` , ``-warn-error`` のようなフラグは、たとえ ``CFLAGS`` 変数に含まれていたとしても、コンパイラに渡されることはありません。 .. These functions are silent and should normally be used with an appropriate ConfMsgChecking … ConfMsgResult. これらの関数は結果を表示しません。また、通常の場合は適切な ``ConfMsgChecking`` ~ ``ConfMsgResult`` 間で使用すべきです。 .. index:: single: RunCProg() .. _label14.1.5: 14.1.5 RunCProg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: output = $(RunCProg ) .. RunCProg is similar to the RunCProg function, except that it returns the output of the function (will return false if the program fails to compile or run). ``RunCProg`` 関数は ``TryRunC`` 関数と似ていますが、この関数はプログラムの出力を返します(プログラムのコンパイルや実行に失敗した場合は ``false`` が返されます)。 (訳注: 原文では "RunCProg is similar to the RunCProg function, ..." となっていましたが、恐らくこれはTryRunCの間違いではないかと思われます) .. index:: single: CheckCHeader() single: VerboseCheckCHeader() .. _label14.1.6: 14.1.6 CheckCHeader, VerboseCheckCHeader ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: success = $(CheckCHeader ) success = $(VerboseCheckCHeader ) .. Use the TryCompileC function to check whether your C compiler can locate and process the specified headers files. Will incude before including the header files. ``TryCompileC`` 関数を用いることで、あなたのCコンパイラが指定したヘッダファイルの位置をつきとめ、さらに処理できるかどうか調べることができます。 ``TryCompileC`` 関数はヘッダファイルをインクルードする前に ```` をインクルードします。 .. Both functions return a boolean value. The CheckCHeader function is silent; the VerboseCheckCHeader function will use the ConfMsgChecking and ConfMsgResult functions to describe the test and the outcome. 両方の関数は真偽値を返します。 ``CheckCHeader`` 関数は結果を表示しません。 ``VerboseCheckCHeader`` 関数はテストと結果を表示するのに ``ConfMsgChecking`` と ``ConfMsgResult`` 関数を使います。 例:: static. = NCURSES_H_AVAILABLE = $(VerboseCheckCHeader ncurses.h) .. index:: single: CheckCLib() single: VerboseCheckCLib() .. _label14.1.7: 14.1.7 CheckCLib, VerboseCheckCLib ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: success = $(CheckCLib , ) success = $(VerboseCheckCLib , ) .. Use the TryLinkC function to check whether your C compiler and linker can find the named functions when linking with the named libraries. Will pass the to the compiler using the -l flag. ``TryLinkC`` 関数を用いることで、与えられたライブラリのリンク時に、あなたのCコンパイラとリンカが、与えられた関数を見つけられるかどうか調べることができます。 ``TryLinkC`` 関数は ``-l`` フラグを使ってコンパイラに ```` を渡します。 .. Both functions return a boolean value. The CheckCLib function is silent; the VerboseCheckCHeader function will use the ConfMsgChecking and ConfMsgResult functions to describe the test and the outcome. 両方の関数は真偽値を返します。 ``CheckCLib`` 関数は結果を表示しません。 ``VerboseCheckCLib`` 関数はテストと結果を表示するのに ``ConfMsgChecking`` と ``ConfMsgResult`` 関数を使います。 例:: static. = NCURSES_LIB_AVAILABLE = $(VerboseCheckCLib ncurses, initscr setupterm tigetstr) .. index:: single: CheckProg() .. _label14.1.8: 14.1.8 CheckProg ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ :: success = $(CheckProg ) .. Checks whether the program exists in your path. Will use the ConfMsgChecking and ConfMsgResult functions to describe the test and the outcome. あなたのパス中に ```` が存在しているかどうかを調べます。この関数はテストと結果を表示するのに ``ConfMsgChecking`` と ``ConfMsgResult`` 関数を使います。 .. index:: single: AC_MSG_CHECKING single: AC_MSG_RESULT single: AC_MSG_WARN single: AC_MSG_ERROR single: AC_TRY_COMPILE single: AC_TRY_LINK single: AC_TRY_RUN .. _label14.2: 14.2 ``autoconf`` スクリプトをOMake用に翻訳する -------------------------------------------------- .. Some of the functions described above are very similar to the ones present in autoconf. Below is a brief translation table for such functions. 上の関数のいくつかは、 ``autoconf`` に存在しているものと非常に似ています。以下はそのような関数のための簡単な翻訳テーブルです。 .. AC_MSG_CHECKING is very similar to ConfMsgChecking function. AC_MSG_RESULT is very similar to ConfMsgResult function. AC_MSG_WARN is very similar to ConfMsgWarn function. AC_MSG_ERROR is very similar to ConfMsgError function. AC_TRY_COMPILE is somewhat similar to TryCompileC function, except the TryCompileC function returns a boolean value and only works for C. Similarly, AC_TRY_LINK is approximated by TryLinkC function, and AC_TRY_RUN is approximated by TryRunC function. * ``AC_MSG_CHECKING`` は ``ConfMsgChecking`` 関数と非常に似ています。 * ``AC_MSG_RESULT`` は ``ConfMsgResult`` 関数と非常に似ています。 * ``AC_MSG_WARN`` は ``ConfMsgWarn`` 関数と非常に似ています。 * ``AC_MSG_ERROR`` は ``COnfMsgError`` 関数と非常に似ています。 * ``AC_TRY_COMPILE`` は ``TryCompileC`` 関数をいくらか似ています。ただし、 ``TryCompileC`` 関数は真偽値を返し、 ``C`` 言語のみに機能するという点が異なります。 * ``AC_TRY_LINK`` は ``TryLinkC`` 関数と似ています。 * ``AC_TRY_RUN`` は ``TryRunC`` 関数と似ています。 .. _label14.3: 14.3 事前に用意された設定テスト ------------------------------------------ .. A number of configuration tests are already included in the standard library. In order to use them in your project, simply open (see Section 4.7) the corresponding build file in your OMakefile and the tests will run the first time OMake is executed. Note that it is not a problem to open these files from more than one place in your project — if you do that, the test will still run only once. OMakeでは数多くの設定テスト(configuration tests)が標準ライブラリに含まれています。あなたのプロジェクトでこれらを使うためには、単純に対象の ``OMakefile`` に、設定テストを記述したビルドファイルを『 ``open`` (詳細は ":ref:`label4.7`" を参照してください)』するだけです。そうすれば、OMakeを初めて実行した時点で設定テストが実行されます。これは、あなたのプロジェクト上で二回以上設定テストが ``open`` されるわけではない点に注意してください。たとえ二回以上呼び出したとしても、このテストは一回だけしか実行されません。 .. index:: single: NCURSES_AVAILABLE single: NCURSES_TERMH_IN_NCURSES single: NCURSES_CFLAGS single: NCURSES_CLIBS .. _label14.3.1: 14.3.1 NCursesライブラリの設定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. Add open configure/ncurses line to your OMakefile to get access to the following autoconfiguration variables. あなたの ``OMakefile`` に ``open configure/ncurses`` を加えることで、以下の自動設定変数を利用できます。 * **NCURSES_AVAILABLE** .. A boolean flag that would be set when both the curses.h header, the term.h header, and the ncurses library very found. ``curses.h`` , ``term.h`` ヘッダファイルと ``ncurses`` ライブラリが見つかった場合に真となる真偽値 * **NCURSES_TERMH_IN_NCURSES** .. A boolean flag that would be set when term.h has to be included as instead of . ``term.h`` が ```` の代わりに ```` としてインクルードされていた場合に真となる真偽値 * **NCURSES_CFLAGS** .. The CFLAGS to use when compiling ncurses code. Will include -DNCURSES and -DTERMH_IN_NCURSES, respectively when NCURSES_AVAILABLE and NCURSES_TERMH_IN_NCURSES are true. ncursesコードをコンパイルする際に用いる ``CFLAGS`` の値。 ``NCURSES_AVAILABLE`` と ``NCURSES_TERMH_IN_NCURSES`` がそれぞれ真である場合には ``-DNCURSES`` と ``-DTERMH_IN_NCURSES`` が含まれます。 * **NCURSES_CLIBS** .. The LDFLAGS to use when linking ncurses code. Will normally contain -lncurses when ncurses is found and remain empty otherwise. ncursesコードをリンクする際に用いる ``LDFLAGS`` の値。ncursesが見つかって、それ以外が空のままである場合には通常 ``-lncurses`` が含まれます。 .. index:: single: READLINE_AVAILABLE single: READLINE_GNU single: READLINE_CFLAGS single: READLINE_CLIBS .. _label14.3.2: 14.3.2 ReadLineライブラリの設定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. Add open configure/readline line to your OMakefile to get access to the following autoconfiguration variables. あなたの ``OMakefile`` に ``open configure/readline`` を加えることで、以下の自動設定変数を利用できます。 * **READLINE_AVAILABLE** .. A boolean flag that would be set when both the readline/readline.h header, the readline/history.h header, and the readline library very found. ``readline/readline.h`` , ``readline/history.h`` ヘッダと ``readline`` ライブラリが見つかった場合に真となる真偽値 * **READLINE_GNU** .. A boolean flag that would be set when the GNU version of the readline library is found (as opposed to the BSD one). readlineライブラリのGNUバージョン(BSDバージョンではなく)が見つかった場合に真となる真偽値 * **READLINE_CFLAGS** .. The CFLAGS to use when compiling readline code. Will include -DREADLINE_ENABLED and -DREADLINE_GNU, respectively when READLINE_AVAILABLE and READLINE_GNU are true. readlineコードをコンパイルする際に用いる ``CFLAGS`` の値。 ``READLINE_AVAILABLE`` と ``READLINE_GNU`` がそれぞれ真である場合には ``-DREADLINE_ENABLED`` と ``-DREADLINE_GNU`` が含まれます。 * **READLINE_CLIBS** .. The LDFLAGS to use when linking readline code. Will normally contain -lncurses -lreadline when readline is found and remain empty otherwise. readlineコードをリンクする際に用いる ``LDFLAGS`` の値。readlineが見つかって、それ以外が空である場合には通常 ``-lncurses -lreadline`` が含まれます。 .. index:: single: SNPRINTF_AVAILABLE .. _label14.3.3: 14.3.3 Snprintfの設定 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. Add open configure/snprintf line to your OMakefile to get access to the following autoconfiguration variables. あなたの ``OMakefile`` に ``open configure/snprintf`` を加えることで、以下の自動設定変数を利用できます。 * **SNPRINTF_AVAILABLE** .. A boolean flag telling whether the snprintf function is available in the standard C library. 標準Cライブラリでsnprintf関数が利用可能であるかどうかを示す真偽値