OSDN Git Service

autoconf, configureの索引を追加. 自動設定->autoconfと分かりやすく.
[omake-japanese/omake_trans.git] / quickstart.rst
1 .. 2-quickstart
2
3 .. _label2:
4
5 2. OMakeクイックスタートガイド
6 ==================================
7
8 .. _label2.1:
9
10 2.1 概要
11 ----------------------------------
12 .. omake is designed for building projects that might have source files in several directories. Projects are normally specified using an OMakefile in each of the project directories, and an OMakeroot file in the root directory of the project. The OMakeroot file specifies general build rules, and the OMakefiles specify the build parameters specific to each of the subdirectories. When omake runs, it walks the configuration tree, evaluating rules from all of the OMakefiles. The project is then built from the entire collection of build rules.
13
14 OMakeは複数のディレクトリにまたがって存在するソースファイルをビルドするために製作されたツールです。OMakeを使用したプロジェクトは通常、 ``OMakefile`` を各々のプロジェクトディレクトリに置き、 ``OMakeroot`` をプロジェクトのルートディレクトリに置きます。 ``OMakeroot`` には一般的なビルドルールを指定し、 ``OMakefiles`` にはそれぞれのサブディレクトリに固有のビルドパラメータを指定します。いったんOMakeを起動すると、OMakeはまず設定ファイルのあるディレクトリをスキャンし、すべての ``OMakefile`` を評価します。そしてプロジェクトは全体のビルドルールの集合としてビルドされます。
15
16 .. index::
17    single: .SCANNER
18 .. _label2.1.1:
19
20 2.1.1 自動的な依存関係の解析
21 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22 .. Dependency analysis has always been problematic with the make(1) program. omake addresses this by adding the .SCANNER target, which specifies a command to produce dependencies. For example, the following rule
23
24 従来のmake(1)プログラムでは以前から依存関係の解析が問題となっていました。OMakeではこの問題を、依存関係を生成するコマンドを指定した ``.SCANNER`` ターゲットを追加することで解決しました。たとえば、以下のルール ::
25
26     .SCANNER: %.o: %.c
27         $(CC) $(INCLUDE) -MM $<
28
29 .. is the standard way to generate dependencies for .c files. omake will automatically run the scanner when it needs to determine dependencies for a file.
30
31 は ``.c`` ファイルの依存関係を生成する常套手段です。OMakeはソースファイルの依存関係を知る必要がある時点で、自動的にソースファイルをスキャンし、依存関係を特定します。
32
33 .. index::
34    single: MD5
35    single: .omakedb
36 .. _label2.1.2:
37
38 2.1.2 ファイル内容から依存関係を解析
39 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40 .. Dependency analysis in omake uses MD5 digests to determine whether files have changed. After each run, omake stores the dependency information in a file called .omakedb in the project root directory. When a rule is considered for execution, the command is not executed if the target, dependencies, and command sequence are unchanged since the last run of omake. As an optimization, omake does not recompute the digest for a file that has an unchanged modification time, size, and inode number.
41
42 どのファイルの依存関係が変更されたかを知るために、OMakeではMD5による要約を用いてチェックを行います。各々のディレクトリでOMakeが実行された後に、 OMakeは依存関係の情報をプロジェクトルートディレクトリの ``.omakedb`` ファイルに保存します。いったんOMakeが依存関係のルールファイルを保存したのであれば、OMakeが最後に実行された時点で、ターゲット、依存関係、ソースコードに関して変更がない場合、ビルドは実行されません。また最適化としてOMakeはMD5の再計算を、修正日時、サイズ、ノード番号に変更のないファイルに関しては実行しません。
43
44 .. index::
45    single: make
46    single: .PHONY
47    single: .SUBDIRS
48    single: .SUFFIXES
49 .. _label2.2:
50
51 2.2 既にmakeに慣れている人向けの注意事項
52 ------------------------------------------
53 .. For users already familiar with the make(1) command, here is a list of differences to keep in mind when using omake.
54
55 既にmakeコマンドに慣れているユーザがomakeを使う際には、以下のmakeとomakeの違いを列挙したリストについて留意しておきましょう。
56
57 ..  * In omake, you are much less likely to define build rules of your own. The system provides many standard functions (like StaticCLibrary and CProgram), described in Chapter 13, to specify these builds more simply.
58     * Implicit rules using .SUFFIXES and the .suf1.suf2: are not supported. You should use wildcard patterns instead %.suf2: %.suf1.
59     * Scoping is significant: you should define variables and .PHONY targets (see Section 8.10) before they are used.
60     * Subdirectories are incorporated into a project using the .SUBDIRS: target (see Section 8.8). 
61
62 * omakeを用いると、あなたがビルドルールを自力で定義するよりもはるかに省力化できます。このシステムは多くのビルドイン関数を提供しています( ``StaticCLibrary`` や ``CProgram`` など)。第13章(:ref:`label13`)で説明した事項を用いると、これらのビルドはより簡単になります。
63 * ``.SUFFIXES`` や ``.suf1.suf2:`` などを用いた暗黙のルール(implicit rule)はサポートされていません。その代わりにあなたはワイルドカード ``%.suf2: %.suf1`` を用いるべきです。
64 * スコーピングは重要です。あなたは変数や ``.PHONY`` ターゲットを、使用する前に定義すべきです。(詳細は ":ref:`label8.10`" を参照してください。)
65 * サブディレクトリをプロジェクトに組み入れる際には、 ``.SUBDIRS:`` ターゲットを用います。(詳細は ":ref:`label8.8`" を参照してください。)
66
67 .. index::
68    single: CProgram()
69    single: OMakefile
70    single: OMakeroot
71    single: EXE
72    single: CC
73    single: CFLAGS
74    single: .DEFAULT
75 .. _label2.3:
76
77 2.3 小さなCプログラムのビルド
78 --------------------------------
79 .. To start a new project, the easiest method is to change directories to the project root and use the command omake --install to install default OMakefiles.
80
81 新しいプロジェクトを作る際にもっとも簡単な方法は、カレントディレクトリをプロジェクトのルートディレクトリに変え、 ``omake --install`` とコマンドを入力してデフォルトの ``OMakefile`` と ``OMakeroot`` をインストールすることです。 ::
82
83     $ cd ~/newproject
84     $ omake --install
85     *** omake: creating OMakeroot
86     *** omake: creating OMakefile
87     *** omake: project files OMakefile and OMakeroot have been installed
88     *** omake: you should edit these files before continuing
89
90 .. The default OMakefile contains sections for building C and OCaml programs. For now, we'll build a simple C project.
91
92 デフォルトの ``OMakefile`` はCとOCamlのプログラムをビルドするためのセクションを含んでいます。さて、それではOMakeを用いて簡単なCプロジェクトをビルドしてみましょう。
93
94 .. Suppose we have a C file called hello_code.c containing the following code:
95
96 私たちは ``hello_code.c`` というCファイルを持っており、そのコードは以下であったとします。 ::
97
98     #include <stdio.h>
99
100     int main(int argc, char **argv)
101     {
102         printf("Hello world\n");
103         return 0;
104     }
105
106 .. To build the program a program hello from this file, we can use the CProgram function. The OMakefile contains just one line that specifies that the program hello is to be built from the source code in the hello_code.c file (note that file suffixes are not passed to these functions).
107
108 このファイルから ``hello`` というプログラムをビルドする場合、 ``CProgram`` という関数を使うことができます。 ``OMakefile`` に ``hello_code.c`` のソースコードから ``hello`` プログラムをビルドすることを指定するため、以下の一行を加えます(ファイルの拡張子はこれらの関数に渡していないことに注意してください)。 ::
109
110     CProgram(hello, hello_code)
111
112 .. Now we can run omake to build the project. Note that the first time we run omake, it both scans the hello_code.c file for dependencies, and compiles it using the cc compiler. The status line printed at the end indicates how many files were scanned, how many were built, and how many MD5 digests were computed.
113
114 これで私たちはこのプロジェクトをビルドするために、OMakeを実行することができます。最初に私たちがOMakeを実行した時点で、OMakeは依存関係の解析に ``hello_code.c`` を解析し、 ``cc`` コンパイラを用いてコンパイルします。一番最後の行にはどれだけ多くのファイルが解析されて、どれだけ多くビルドされて、そしてどれだけ多くのMD5が計算されたのかが表示されます。 ::
115
116     $ omake hello
117     *** omake: reading OMakefiles
118     *** omake: finished reading OMakefiles (0.0 sec)
119     - scan . hello_code.o
120     + cc -I. -MM hello_code.c
121     - build . hello_code.o
122     + cc -I. -c -o hello_code.o hello_code.c
123     - build . hello
124     + cc -o hello hello_code.o
125     *** omake: done (0.5 sec, 1/6 scans, 2/6 rules, 5/22 digests)
126     $ omake
127     *** omake: reading OMakefiles
128     *** omake: finished reading OMakefiles (0.1 sec)
129     *** omake: done (0.1 sec, 0/4 scans, 0/4 rules, 0/9 digests)
130
131 .. If we want to change the compile options, we can redefine the CC and CFLAGS variables before the CProgram line. In this example, we will use the gcc compiler with the -g option. In addition, we will specify a .DEFAULT target to be built by default. The EXE variable is defined to be .exe on Win32 systems; it is empty otherwise.
132
133 私たちがコンパイルオプションを変更したいと思った場合、 ``CProgram`` と書いてある行の前に ``CC`` と ``CFLAGS`` 変数を再定義することで可能となります。たとえば、現在私たちは ``-g`` オプションで ``gcc`` コンパイラを用いたいとします。加えて、デフォルトでビルドするために ``.DEFAULT`` ターゲットを指定したい、さらにWin32システムで ``.exe`` と定義された ``EXE`` 変数を用いたいとします。これらの要望は以下のコードで実現できます。 ::
134
135     CC = gcc
136     CFLAGS += -g
137     CProgram(hello, hello_code)
138     .DEFAULT: hello$(EXE)
139
140 .. Here is the corresponding run for omake.
141
142 以下はomakeを実行させた場合の全体のコンソールです。 ::
143
144     $ omake
145     *** omake: reading OMakefiles
146     *** omake: finished reading OMakefiles (0.0 sec)
147     - scan . hello_code.o
148     + gcc -g -I. -MM hello_code.c
149     - build . hello_code.o
150     + gcc -g -I. -c -o hello_code.o hello_code.c
151     - build . hello
152     + gcc -g -o hello hello_code.o
153     *** omake: done (0.4 sec, 1/7 scans, 2/7 rules, 3/22 digests)
154
155 .. We can, of course, include multiple files in the program. Suppose we write a new file hello_helper.c. We would include this in the project as follows.
156
157 もちろん、プログラム中に複数のファイルをインクルードすることもできます。 ``hello_helper.c`` という新しいファイルを追加したとしましょう。以下のように ``OMakefile`` を変更することで対応できます。 ::
158
159     CC = gcc
160     CFLAGS += -g
161     CProgram(hello, hello_code hello_helper)
162     .DEFAULT: hello$(EXE)
163
164 .. index::
165    single: StaticCLibrary()
166 .. _label2.4:
167
168 2.4  巨大なプロジェクト
169 -------------------------
170 .. As the project grows it is likely that we will want to build libraries of code. Libraries can be built using the StaticCLibrary function. Here is an example of an OMakefile with two libraries.
171
172 プロジェクトが成長するにつれて、コードからライブラリをビルドしたいと思うかもしれません。ライブラリは ``StaticCLibrary`` 関数を用いることでビルドすることができます。以下は二つのライブラリをビルドする際の ``OMakefile`` のサンプルです。 ::
173
174     CC = gcc
175     CFLAGS += -g
176
177     FOO_FILES = foo_a foo_b
178     BAR_FILES = bar_a bar_b bar_c
179
180     StaticCLibrary(libfoo, $(FOO_FILES))
181     StaticCLibrary(libbar, $(BAR_FILES))
182
183     # helloプログラムは両方のライブラリを用いてリンクされます
184     LIBS = libfoo libbar
185     CProgram(hello, hello_code hello_helper)
186
187     .DEFAULT: hello$(EXE)
188
189 .. index::
190    single: INCLUDES
191    single: section
192    single: export
193    single: StaticCLibraryInstall()
194    single: if
195 .. _label2.5:
196
197 2.5  サブディレクトリ
198 --------------------------
199 .. As the project grows even further, it is a good idea to split it into several directories. Suppose we place the libfoo and libbar into subdirectories.
200
201 プロジェクトがさらに成長していく時点で、いくつかのディレクトリにコードファイルを分割することは良いアイデアです。現在私たちは ``libfoo`` と ``libbar`` をサブディレクトリに置いてあるものとしましょう。
202
203 .. In each subdirectory, we define an OMakefile for that directory. For example, here is an example OMakefile for the foo subdirectory.
204
205 まず、 ``OMakefile`` を各々のサブディレクトリ内に置きます。例えば、以下は ``foo/`` サブディレクトリ内の ``OMakefile`` のサンプルです。 ::
206
207     INCLUDES += .. ../bar
208
209     FOO_FILES = foo_a foo_b
210     StaticCLibrary(libfoo, $(FOO_FILES))
211
212 .. Note the the INCLUDES variable is defined to include the other directories in the project.
213
214 ``INCLUDES`` 変数はプロジェクトの他のディレクトリをインクルードするために定義されています。
215
216 .. Now, the next step is to link the subdirectories into the main project. The project OMakefile should be modified to include a .SUBDIRS: target.
217
218 さて、次のステップはメインプロジェクトの中にサブディレクトリをリンクさせます。プロジェクトの ``OMakefile`` を ``.SUBDIRS`` プロジェクトを含めるように修正します。 ::
219
220     # プロジェクトの設定
221     CC = gcc
222     CFLAGS += -g
223
224     # サブディレクトリ
225     .SUBDIRS: foo bar
226
227     # ライブラリはサブディレクトリの中に存在します
228     LIBS = foo/libfoo bar/libbar
229
230     CProgram(hello, hello_code hello_helper)
231
232     .DEFAULT: hello$(EXE)
233
234 .. Note that the variables CC and CFLAGS are defined before the .SUBDIRS target. These variables remain defined in the subdirectories, so that libfoo and libbar use gcc -g.
235
236 変数 ``CC`` と ``CFLAGS`` は ``.SUBDIRS`` ターゲットの *前に* 定義されてあることに注目してください。これらの変数はサブディレクトリでも保持されていますので、 ``libfoo`` と ``libbar`` では ``gcc -g`` が使われます。
237
238 .. If the two directories are to be configured differently, we have two choices. The OMakefile in each subdirectory can be modified with its configuration (this is how it would normally be done). Alternatively, we can also place the change in the root OMakefile.
239
240 二つのディレクトリに異なる設定を用いる必要がある場合、二つの方法があります。一つ目は各々のサブディレクトリの ``OMakefile`` にそれぞれの設定を書く方法です(普通はこのようにして問題を解決します)。二つ目は、ルートの ``OMakefile`` を以下のコードに書き換える方法です。 ::
241
242     # 通常のプロジェクト設定
243     CC = gcc
244     CFLAGS += -g
245
246     # libfooは通常の設定を用います
247     .SUBDIRS: foo
248
249     # libbarは加えて最適化を行います
250     CFLAGS += -O3
251     .SUBDIRS: bar
252
253     # メインプログラム
254     LIBS = foo/libfoo bar/libbar
255     CProgram(hello, hello_code hello_helper)
256
257     .DEFAULT: hello$(EXE)
258
259 .. Note that the way we have specified it, the CFLAGS variable also contains the -O3 option for the CProgram, and hello_code.c and hello_helper.c file will both be compiled with the -O3 option. If we want to make the change truly local to libbar, we can put the bar subdirectory in its own scope using the section form.
260
261 ``CFLAGS`` 変数にさらに ``-O3`` オプションを加えることで、 ``hello_code.c`` と ``hello_helper.c`` の両方は ``-O3`` オプションでコンパイルされます。
262 ``libbar`` のみにオプションを変更させたい場合、 ``section`` 文を使用することで ``bar/`` サブディレクトリ内のみに変更を適用することができます。 ::
263
264     # 通常のプロジェクト設定
265     CC = gcc
266     CFLAGS += -g
267
268     # libfooは通常の設定を用います
269     .SUBDIRS: foo
270
271     # libbarは加えて最適化を行います
272     section
273         CFLAGS += -O3
274         .SUBDIRS: bar
275
276     # メインプログラムでは最適化を使用しません
277     LIBS = foo/libfoo bar/libbar
278     CProgram(hello, hello_code hello_helper)
279
280     .DEFAULT: hello$(EXE)
281
282 .. Later, suppose we decide to port this project to Win32, and we discover that we need different compiler flags and an additional library.
283
284 後で、私たちがこのプロジェクトをWin32に移し、そして異なるコンパイラフラグや追加ライブラリが必要になることがわかったとしましょう。 ::
285
286     # 通常のプロジェクト設定
287     if $(equal $(OSTYPE), Win32)
288         CC = cl /nologo
289         CFLAGS += /DWIN32 /MT
290         export
291     else
292         CC = gcc
293         CFLAGS += -g
294         export
295
296     # libfooは通常の設定を用います
297     .SUBDIRS: foo
298
299     # libbarは加えて最適化を行います
300     section
301         CFLAGS += $(if $(equal $(OSTYPE), Win32), $(EMPTY), -O3)
302         .SUBDIRS: bar
303
304     # 通常のライブラリ
305     LIBS = foo/libfoo bar/libbar
306
307     # Win32上のみlibwin32を必要とします
308     if $(equal $(OSTYPE), Win32)
309        LIBS += win32/libwin32
310
311        .SUBDIRS: win32
312        export
313
314     # メインプログラムでは最適化を使用しません
315     CProgram(hello, hello_code hello_helper)
316
317     .DEFAULT: hello$(EXE)
318
319 .. Note the use of the export directives to export the variable definitions from the if-statements. Variables in omake are scoped—variables in nested blocks (blocks with greater indentation), are not normally defined in outer blocks. The export directive specifies that the variable definitions in the nested blocks should be exported to their parent block.
320
321 ``export`` によって ``if`` 文の中にある変数が外部にエクスポートされます。 *OMakeでの変数はスコープ化* されており、ネストされたブロック内の変数は通常、外部のブロックから使用することはできません。 ``export`` はネストされたブロック内の変数を、親のブロックに移す命令です。
322
323 .. note::
324   訳注: 今回の例では ``$(OSTYPE)`` 変数を用いて場合分けを行っていますが、 ``$(CC)`` 変数に関しては省略することができます。なぜなら、 ``Unix`` 上では ``$(CC)`` は ``gcc`` , ``Win32`` 上では ``cl /nologo`` が自動的に束縛されるからです。
325   
326   大抵の場合において、このような設定変数は異なるプラットフォーム上においても正常に動作するよう設計されています(詳細は ":ref:`label13.5.2`" を参照してください)。もちろん、その他になにか追加オプションを指定したい場合には、このような場合分けが有効となるでしょう。
327
328 .. Finally, for this example, we decide to copy all libraries into a common lib directory. We first define a directory variable, and replace occurrences of the lib string with the variable.
329
330 最後に、私たちはすべてのライブラリを共通の ``lib/`` ディレクトリにコピーしたいものとします。私たちはまずはじめにディレクトリの変数を定め、そして ``lib`` の文字列を変数で置き換えます。 ::
331
332     # 共用のlibディレクトリ
333     LIB = $(dir lib)
334
335     # phonyターゲットはライブラリのみビルドを行います
336     .PHONY: makelibs
337
338     # 通常のプロジェクト設定
339     if $(equal $(OSTYPE), Win32)
340         CC = cl /nologo
341         CFLAGS += /DWIN32 /MT
342         export
343     else
344         CC = gcc
345         CFLAGS += -g
346         export
347
348     # libfooは通常の設定を用います
349     .SUBDIRS: foo
350
351     # libbarは加えて最適化を行います
352     section
353         CFLAGS += $(if $(equal $(OSTYPE), Win32), $(EMPTY), -O3)
354         .SUBDIRS: bar
355
356     # 通常のライブラリ
357     LIBS = $(LIB)/libfoo $(LIB)/libbar
358
359     # Win32上のみlibwin32を必要とします
360     if $(equal $(OSTYPE), Win32)
361        LIBS += $(LIB)/libwin32
362
363        .SUBDIRS: win32
364        export
365
366     # メインプログラムでは最適化を使用しません
367     CProgram(hello, hello_code hello_helper)
368
369     .DEFAULT: hello$(EXE)
370
371 .. In each subdirectory, we modify the OMakefiles in the library directories to install them into the $(LIB) directory. Here is the relevant change to foo/OMakefile.
372
373 ``$(LIB)`` ディレクトリの中にライブラリをインストールするため、ライブラリディレクトリ内の ``OMakefile`` を修正します。以下は新しく変更された ``foo/OMakefile`` です。 ::
374
375     INCLUDES += .. ../bar
376
377     FOO_FILES = foo_a foo_b
378     StaticCLibraryInstall(makelib, $(LIB), libfoo, $(FOO_FILES))
379
380 .. Directory (and file names) evaluate to relative pathnames. Within the foo directory, the $(LIB) variable evaluates to ../lib.
381
382 ディレクトリ(そしてファイル名)は現在のパス名で評価されます。 ``foo/`` ディレクトリ内では、 ``$(LIB)`` 変数は ``../lib`` として評価されます。
383
384 .. As another example, instead of defining the INCLUDES variable separately in each subdirectory, we can define it in the toplevel as follows.
385
386 各々のサブディレクトリ内で ``INCLUDES`` 変数を個別に定義する代わりに、以下のようにトップレベルで定義することもできます。 ::
387
388     INCLUDES = $(ROOT) $(dir foo bar win32)
389
390 .. In the foo directory, the INCLUDES variable will evaluate to the string .. . ../bar ../win32. In the bar directory, it would be .. ../foo . ../win32. In the root directory it would be . foo bar win32.
391
392 ``foo/`` ディレクトリ内において ``INCLUDES`` 変数は文字列 ``.. . ../bar`` として評価されます。また ``bar/`` ディレクトリ内において、 ``INCLUDES`` 変数は文字列 ``.. ../foo . ../win32`` として評価されます。ルートディレクトリでは、 ``INCLUDES`` 変数は文字列 ``. foo bar win32`` として評価されます。
393
394 .. note::
395   訳注: 今までの議論の中で「 *Win32プラットフォーム上でディレクトリのセパレータに/(スラッシュ)を指定していいのだろうか?\\(バックスラッシュ)を使わないといけないのでは?* 」と疑問に思った方も多いと思います。実は、この点に関しては心配いりません。omakeはたとえWin32上で ``/`` を使っていたとしても、実際の評価ではー非常に奇妙に思われるかもしれませんがー ``\`` が用いられるのです。同様に、セパレータに ``\`` を用いたとしてもUnixプラットフォーム上では ``/`` と変換されます。
396   
397   このように、ディレクトリのセパレータは ``/`` , ``\`` どちらを使っても、異なるプラットフォーム上で正常に動作します。ただし、 ``\`` はエスケープ文字として使用されることが多いため、思わぬ誤動作を引き起こすことがあるかもしれません。大抵の場合、ディレクトリのセパレータは ``/`` を使うことをおすすめします(詳細は ":ref:`label10.4`" を参照してください)。
398   
399 .. _label2.6:
400
401 2.6  その他の考慮事項
402 --------------------------
403 .. omake also handles recursive subdirectories. For example, suppose the foo directory itself contains several subdirectories. The foo/OMakefile would then contain its own .SUBDIRS target, and each of its subdirectories would contain its own OMakefile.
404
405 OMakeはまたリソースのあるサブディレクトリも扱うことができます。例えば、先ほどの ``foo/`` ディレクトリの中に、さらにいくつかのサブディレクトリを保持しているような場合を考えてみましょう。 ``foo/OMakefile`` は ``foo/`` ディレクトリ自身の ``.SUBDIRS`` ターゲットを保持しており、また各々のサブディレクトリもまたサブディレクトリ自身の ``OMakefile`` を保持しています。
406
407 .. index::
408    single: OCaml
409 .. _label2.7:
410
411 2.7 OCamlプログラムのビルド
412 ----------------------------
413 .. By default, omake is also configured with functions for building OCaml programs. The functions for OCaml program use the OCaml prefix. For example, suppose we reconstruct the previous example in OCaml, and we have a file called hello_code.ml that contains the following code.
414
415 通常、OMakeはOCamlのプログラムをビルドするための関数群も持っています。OCamlプログラムのための関数群は接頭語として ``OCaml`` がつきます。例えば、前回のサンプルをOCamlで置き換えて、 ``hello_code.ml`` という以下のコードを含んだファイルを持っている場合を考えましょう。 ::
416
417    open Printf
418
419    let () = printf "Hello world\n"
420
421 .. An example OMakefile for this simple project would contain the following.
422
423 この簡単なプロジェクトのOMakefileのサンプルは以下になります。 ::
424
425     # バイトコードコンパイラを使用
426     BYTE_ENABLED = true
427     NATIVE_ENABLED = false
428     OCAMLCFLAGS += -g
429
430     # プログラムをビルド
431     OCamlProgram(hello, hello_code)
432     .DEFAULT: hello.run
433
434 .. Next, suppose the we have two library subdirectories: the foo subdirectory is written in C, the bar directory is written in OCaml, and we need to use the standard OCaml Unix module.
435
436 次に、二つのライブラリのサブディレクトリを持っている場合を考えましょう。 ``foo/`` ディレクトリはCで書かれており、 ``bar/`` ディレクトリはOCamlで書かれています。そして私たちは標準的なOCamlのUNIXモジュールを使用したいといった場合です。 ::
437
438     # 通常のプロジェクト設定
439     if $(equal $(OSTYPE), Win32)
440         CC = cl /nologo
441         CFLAGS += /DWIN32 /MT
442         export
443     else
444         CC = gcc
445         CFLAGS += -g
446         export
447
448     # バイトコードコンパイラを使用
449     BYTE_ENABLED = true
450     NATIVE_ENABLED = false
451     OCAMLCFLAGS += -g
452
453     # ライブラリのサブディレクトリ
454     INCLUDES += $(dir foo bar)
455     OCAMLINCLUDES += $(dir foo bar)
456     .SUBDIRS: foo bar
457
458     # Cライブラリ
459     LIBS = foo/libfoo
460
461     # OCamlライブラリ
462     OCAML_LIBS = bar/libbar
463
464     # Unixモジュールも用います
465     OCAML_OTHER_LIBS = unix
466
467     # メインプログラム
468     OCamlProgram(hello, hello_code hello_helper)
469
470     .DEFAULT: hello
471
472 .. The foo/OMakefile would be configured as a C library.
473
474 ``foo/OMakefile`` はCライブラリとして設定します。 ::
475
476     FOO_FILES = foo_a foo_b
477     StaticCLibrary(libfoo, $(FOO_FILES))
478
479 .. The bar/OMakefile would build an ML library.
480
481 また、 ``bar/OMakefile`` はMLライブラリとして設定します。 ::
482
483    BAR_FILES = bar_a bar_b bar_c
484    OCamlLibrary(libbar, $(BAR_FILES))
485
486 .. index::
487    single: OMakefile
488    single: OMakeroot
489 .. _label2.8:
490
491 2.8  OMakefileとOMakeroot
492 ------------------------------------
493 .. OMake uses the OMakefile and OMakeroot files for configuring a project. The syntax of these files is the same, but their role is slightly different. For one thing, every project must have exactly one OMakeroot file in the project root directory. This file serves to identify the project root, and it contains code that sets up the project. In contrast, a multi-directory project will often have an OMakefile in each of the project subdirectories, specifying how to build the files in that subdirectory.
494
495 プロジェクトを設定する際、OMakeは ``OMakefile`` と ``OMakeroot`` の2つのファイルを使用します。これらのファイルの構文は同じですが、役割は全く異なります。さらに付け加えると、すべてのプロジェクトは ``OMakeroot`` ファイルをプロジェクトのルートディレクトリに必ず置かなければなりません。このファイルはこのディレクトリがプロジェクトのルートディレクトリであることを決め、さらにプロジェクトをセットアップするためのコードを含んでいます。対照的に、複数のディレクトリが存在するプロジェクトは、どのようにサブディレクトリ内のファイルをビルドするのかを設定した ``OMakefile`` を、各々のプロジェクトのサブディレクトリに置くことになります。
496
497 .. Normally, the OMakeroot file is boilerplate. The following listing is a typical example.
498
499 通常、 ``OMakeroot`` ファイルはほとんど変更する必要のない決まり文句です。以下のリストは ``OMakeroot`` ファイルの一部です。 ::
500
501     include $(STDLIB)/build/Common
502     include $(STDLIB)/build/C
503     include $(STDLIB)/build/OCaml
504     include $(STDLIB)/build/LaTeX
505
506     # コマンドライン変数を再定義
507     DefineCommandVars(.)
508
509     # 現在のディレクトリをプロジェクトの一部として設定
510     .SUBDIRS: .
511
512 .. The include lines include the standard configuration files needed for the project. The $(STDLIB) represents the omake library directory. The only required configuration file is Common. The others are optional; for example, the $(STDLIB)/build/OCaml file is needed only when the project contains programs written in OCaml.
513
514 ``include`` が書かれている行では、プロジェクトに必要な、標準的な設定ファイルをインクルードしています。 ``$(STDLIB)`` 変数はOMakeライブラリのディレクトリを表します。OCamlが動作するために必須となる設定ファイルは ``Common`` だけで、その他の設定ファイルはなくても構いません。 ``$(STDLIB)/build/OCaml`` ファイルはプロジェクトがOCamlで書かれたプログラムを含んでいる場合のみ必要となります。
515
516 .. The DefineCommandVars function defines any variables specified on the command line (as arguments of the form VAR=<value>). The .SUBDIRS line specifies that the current directory is part of the project (so the OMakefile should be read).
517
518 ``DefineCommandVars`` 関数は( ``VAR=<value>`` のような形で)コマンドライン上から指定された、いくつかの変数を定義します。 ``.SUBDIRS`` が書かれている行では現在のディレクトリがプロジェクトの一部であることを指定しています(よって同ディレクトリの ``OMakefile`` が読み込まれます)。
519
520 .. Normally, the OMakeroot file should be small and project-independent. Any project-specific configuration should be placed in the OMakefiles of the project.
521
522 通常、 ``OMakeroot`` ファイルはサイズが小さく、かつプロジェクトから独立しています。プロジェクト固有の設定はすべてプロジェクト上の ``OMakefile`` に設定すべきです。
523
524 .. index::
525    single: vmount()
526    single: 仮想的なマウント
527 .. _label2.9:
528
529 2.9 複数のバージョンのサポート
530 -----------------------------------
531 .. OMake version 0.9.6 introduced preliminary support for multiple, simultaneous versions of a project. Versioning uses the vmount(dir1, dir2) function, which defines a “virtual mount” of directory dir1 over directory dir2. A “virtual mount” is like a transparent mount in Unix, where the files from dir1 appear in the dir2 namespace, but new files are created in dir2. More precisely, the filename dir2/foo refers to: a) the file dir1/foo if it exists, or b) dir2/foo otherwise.
532
533 OMake バージョン 0.9.6では、複数の同じバージョンのプロジェクトや、予備として用いる複数のプロジェクトに関するサポートを導入しました。 ``vmount(dir1, dir2)`` 関数を用いることで、 ``dir1/`` ディレクトリを ``dir2/`` ディレクトリに『仮想的にマウント』することができます。『仮想的なマウント』はUnixにて、 ``dir1/`` ディレクトリ内のファイルを ``dir2/`` ディレクトリにマウントするが、新しいファイルは ``dir2/`` ディレクトリに作られるようなものです。さらに具体的には、ファイル ``dir2/foo`` は、 ``dir1/foo`` が存在している場合は ``dir1/foo`` に置き換わりますが、存在していない場合は ``dir2/foo`` が用いられます。
534
535 .. The vmount function makes it easy to specify multiple versions of a project. Suppose we have a project where the source files are in the directory src/, and we want to compile two versions, one with debugging support and one optimized. We create two directories, debug and opt, and mount the src directory over them.
536
537 ``vmount`` 関数によってプロジェクト内の複数のバージョンをビルドすることが容易になりました。 ``src/`` ディレクトリ内にいくつかのソースファイルが入っており、これをデバッグサポートがついているバージョンと、最適化されたバージョンの2つにコンパイルする場合を考えてみましょう。まず ``debug/`` と ``opt/`` の2つのディレクトリを作成して、 ``src/`` ディレクトリをこれらのディレクトリにマウントします。 ::
538
539     section
540         CFLAGS += -g
541         vmount(-l, src, debug)
542         .SUBDIRS: debug
543
544     section
545         CFLAGS += -O3
546         vmount(-l, src, opt)
547         .SUBDIRS: opt
548
549 .. Here, we are using section blocks to define the scope of the vmount—you may not need them in your project.
550
551 ここで、 ``vmount`` 関数を必要としていないプロジェクトに適用させないために、私たちは ``section`` ブロックを用いて ``vmount`` のスコープ範囲を定義しました。
552
553 .. The -l option is optional. It specifies that files form the src directory should be linked into the target directories (or copied, if the system is Win32). The links are added as files are referenced. If no options are given, then files are not copied or linked, but filenames are translated to refer directly to the src/ files.
554
555 ``-l`` オプションはなくても構いません。それを指定することで ``src/`` ディレクトリのファイルは、ターゲットとなるディレクトリにリンクされます(システムがWin32の場合、ファイルはコピーされます)。ファイルが関連付けられるようにファイルへのリンクが追加されます。何もオプションが与えられていない場合、ファイル名は直接 ``src/`` ディレクトリのファイル名に変換されます。
556
557 .. Now, when a file is referenced in the debug directory, it is linked from the src directory if it exists. For example, when the file debug/OMakefile is read, the src/OMakefile is linked into the debug/ directory.
558
559 ``debug/`` ディレクトリ内のファイルが参照された時点で、もし ``src/`` ディレクトリにそのファイルが存在するならば、 ``debug/`` ディレクトリのファイルは ``src/`` のファイルにリンクされます。例えば、 ``debug/OMakefile`` が参照された場合、 ``src/OMakefile`` が ``debug/OMakefile`` としてリンクされます。
560
561 .. The vmount model is fairly transparent. The OMakefiles can be written as if referring to files in the src/ directory—they need not be aware of mounting. However, there are a few points to keep in mind.
562
563 ``vmount`` 関数の動作はだいぶ透過的です。あなたは ``OMakefile`` をまるで ``src/`` ディレクトリ内のファイルが関連付けられているかのように書くことができ、マウントについて気にする必要はありません。しかしながら、以下に示すいくつかの注意点を頭に入れておきましょう。
564
565 .. _label2.10:
566
567 2.10  注意点
568 --------------------
569 .. When using the vmount function for versioning, it wise to keep the source files distinct from the compiled versions. For example, suppose the source directory contained a file src/foo.o. When mounted, the foo.o file will be the same in all versions, which is probably not what you want. It is better to keep the src/ directory pristine, containing no compiled code.
570
571 バージョン管理の目的で ``vmount`` 関数を用いた場合、コンパイルされたファイルをソースファイルから分離することをお勧めします。例えば、ソースディレクトリに ``src/foo.o`` ファイルが含まれている場合を考えましょう。もし ``src/foo.o`` がマウントされてしまったとすると、 ``foo.o`` ファイルはすべてのバージョンにおいて共通のファイルになってしまい、おそらくあなたが求めていた動作とは違うものになるでしょう。 ``src/`` ディレクトリにはソースコード以外何もない状態にして、コンパイルされたコードは含めないようにしましょう。
572
573 .. When using the vmount -l option, files are linked into the version directory only if they are referenced in the project. Functions that examine the filesystem (like $(ls ...)) may produce unexpected results. 
574
575 ``vmount -l`` オプションを使用したときは、ソースファイルがプロジェクトから参照された場合のみ、バージョンディレクトリ内にリンクされます。ファイルシステムを用いる関数( ``$(ls ...)`` など)はあなたが期待していない動作を引き起こすことになります。