Chapter 27. gcc のデフォルト値の最適化

Note: Contributed by Brian Gallew

Brian Gallewによる御提供

Configuring gcc to use certain flags by default is a simple matter of editing the /usr/local/lib/gcc-lib/platform/version/specs file.

gcc において,ある特定のフラグをデフォルトで使うための設定としては, 単に/usr/local/lib/gcc-lib/プラットフォーム/バージョン/specs ファイルを編集するだけです. The format of this file pretty simple. The file is broken into sections, each of which is three lines long. The first line is "*section_name:" (e.g. "*asm:"). The second line is a list of flags, and the third line is blank. このファイルのフォーマットはかなりシンプルです.ファイルはいくつかの セクションに別れており,各セクションは 3 行ずつあります.最初の行は "*セクション名:" (たとえば "*asm:")です. 2番目の行はフラグのリストで,3番目の行は空白です.

The easiest change to make is to append the desired default flags to the list in the appropriate section. As an example, let's suppose that I have linux running on a '486 with gcc 2.7.2 installed in the default location. In the file /usr/local/lib/gcc-lib/i486-linux/2.7.2/specs, 13 lines down I find the following section:

メイクするために一番簡単な変更は,指定したいデフォルトのフラグを 適切なセクションのリストに追加することです.例を挙げると,私は デフォルトの位置に gcc 2.7.2 がインストールされた '486 で動いている linux を持っている としましょう.ファイル /usr/local/lib/gcc-lib/i486-linux/2.7.2/specs の 13 行目に以下のセクションがあります:

- ----------SECTION----------
*cc1:


- ----------SECTION----------
As you can see, there aren't any default flags. If I always wanted compiles of C code to use "-m486 -fomit-frame-pointer", I would change it to look like: これでわかるように,何もデフォルトのフラグが設定されていませんね. もし私が C のコードをコンパイルする際に,常に "-m486 -fomit-frame-pointer" を使いたいとすると,ここを以下のように 変更すればいいことになります:
- ----------SECTION----------
*cc1:
- -m486 -fomit-frame-pointer

- ----------SECTION----------
If I wanted to be able to generate 386 code for another, older linux box lying around, I'd have to make it look like this: もし私が,そのへんにころがっているもう 1 つの古い linux box 用に 386 のコードを生成したいとすれば,このようにします.
- ----------SECTION----------
*cc1:
%{!m386:-m486} -fomit-frame-pointer

- ----------SECTION----------
This will always omit frame pointers, any will build 486-optimized code unless -m386 is specified on the command line. これをやっておくと,コマンドラインで -m386 が指定されない限り, 常にフレームポインタ(frame pointers)を省略し,486 で最適化された コードを吐くようになります.

You can actually do quite a lot of customization with the specs file. Always remember, however, that these changes are global, and affect all users of the system.

実際に,specs ファイルでは非常に多くのカスタマイズをすることができます. しかしながら,これらの変更はグローバルであり,システム内のすべての ユーザに影響を及ぼすことを忘れないでください.