(for Internet Explorer)
objdump -S executable
ソースと逆アセンブルを並べたものを表示する
関連
参考
ライブラリのシンボルを調べる
cross platform make
参考
Makefile や IDE のプロジェクト・ファイルを生成します。
設定ファイルは、CMakeLists.txt
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
ABC_INCLUDE_DIR (ADVANCED)
   used as include directory in directory /home/user1/work/Module
トラブルシューティング (variables NOTFOUND)
-D オプションを使って ABC_INCLUDE_DIR を設定してください。
(メモ) この環境変数は、エラーメッセージにあるように、 /home/user1/work/Module フォルダーにある
CMakeLists.txt ファイルの中で使われています。
cd  $SourcePath/../build
if [ -e "CMakeCache.txt" ]; then  rm  CMakeCache.txt  ;fi
                                 #// because cmake does not update this file.
cmake  [options] (source_path)
make  clean
make  VERBOSE=1
sudo make install
cmake  -D ABC_INCLUDE_DIR:PATH=/home/user1/include  source
サンプル:
クロス・コンパイルするときは、ツール・チェイン・ファイルを作成するか、それに相当する -D オプションを
指定してください。
参考
cmake が作る Makefile の構成
build/CMakeFiles/Makefile2
build/Makefile
build/Sub/ModuleA/CMakeFiles/ModuleA.dir/build.make
… 全体のメイン
… 全体のサブ
… モジュールのメイク
Sub/ModuleA は、ソース・フォルダーの構成に一致します。
ソース・フォルダーと同じ構成の build フォルダーを cmake が作ります。
書き方
指定した結果、正しく cmake 変数の値が設定されたかどうかは、CMakeCache.txt で確認できます。
上記リンク先には書いてありませんが、CMAKE_INSTALL_PREFIX の設定も必要です。
参考
Cross compiling is supported by CMake starting with version 2.6.0.
Cross compiling means that the software is built for a different system than the one which does the build.
This means

- CMake cannot autodetect the target system
- usually the executables don't run on the build host
- the build process has to use a different set of include files and libraries for building, i.e. not the native ones
クロス・コンパイルは、CMake のバージョン 2.6.0 からサポートされています。
クロス・コンパイルは、ビルドするシステムとは別のシステムで動くソフトウェアを作ります。
これは、次を意味します。

・CMake は、ターゲットシステムを自動的に検出することができません。
・通常、実行ファイルは、ビルドを行うホストの上で動きません。
・ビルドする処理において、インクルード・ファイルやライブラリ・ファイルは、異なるセット(いわゆるネイティブ
 ではないセット)を使わなければなりません。
システムとツール・チェインの準備 - Setting up the system and toolchain
When cross compiling, CMake cannot guess the target system, so you have to preset some CMake variables,
e.g. using a toolchain file. The following variables have to be preset:
クロスコンパイルするとき、CMake はターゲットシステムを推測することができません。 なので、いくつかの
CMake 変数を提供しなければなりません。 たとえば、
しなければなりません。
this one is mandatory, it is the name of the target system, i.e. the same as CMAKE_SYSTEM_NAME
would have if CMake would run on the target system. Typical examples are "Linux" and "Windows".
This variable is used for constructing the file names of the platform files like Linux.cmake or
Windows-gcc.cmake. If your target is an embedded system without OS set CMAKE_SYSTEM_NAME
to "Generic". If CMAKE_SYSTEM_NAME is preset, the CMake variable CMAKE_CROSSCOMPILING
is automatically set to TRUE, so this can be used for testing in the CMake files.
これは、必須です。 ターゲット・システムの名前です。 言い換えれば、もし、CMake がターゲット・
システム上で動くのであれば、同じ CMAKE_SYSTEM_NAME を持っています。 典型的な例は、
Linux や Windows です。 この変数は、Linux.cmake や Windows-gcc.cmake のように、プラットフォーム
のファイル名を作成するときに使われます。 もし、ターゲットが OS なしの組み込みシステムであれば、
CMAKE_SYSTEM_NAME には、Generic を指定します。 CMAKE_SYSTEM_NAME が提供されると、
CMake 変数である CMAKE_CROSSCOMPILING は自動的に TRUE にセットされます。 これは、
CMake のファイルの中をテストするために使われます。
です。 次の変数を提供
Defining all the variables mentioned above using -DCMAKE_SYSTEM_NAME etc. would be quite tedious
and error prone. To make things easier, there is another cmake variable you can set:
-DCMAKE_SYSTEM_NAME のようにすべての変数を記述して定義していくことは、かなり退屈でエラーが
起こりがちです。 簡単にするために使える cmake 変数があります。
absolute or relative path to a cmake script which sets up all the toolchain related variables mentioned above
すべての関係するツール・チェイン(複数のプログラム)の変数をセットアップする cmake スクリプトへの
絶対パスまたは相対パス。
For instance for crosscompiling from Linux to Embedded Linux on PowerPC this file could look like this:
Linux から PowrePC 上の組み込み Linux へクロス・コンパイルするサンプルは、次のようになります。
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /opt/eldk-2007-01-19/usr/bin/ppc_74xx-gcc)
SET(CMAKE_CXX_COMPILER /opt/eldk-2007-01-19/usr/bin/ppc_74xx-g++)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /opt/eldk-2007-01-19/ppc_74xx /home/alex/eldk-ppc74xx-inst)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
If this file is named Toolchain-eldk-ppc74xx.cmake and is located in your home directory and you are
building in the subdirectory build then you can do:
このファイルの名前が Toolchain-eldk-ppc74xx.cmake で、あなたのホーム・ディレクトリに配置されて
いて、サブ・ディレクトリをビルドする場合は、次のようにできます。
~/src$ cd build
~/src/build$ cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-eldk-ppc74xx.cmake ..
...
You don't have to write a toolchain file for every piece of software you want to build, the toolchain files
are per target platform, i.e. if you are building several software packages all for the same target platform,
you have to write only one toolchain file and you can use this for all packages.
ツール・チェイン・ファイルを、ビルドしたいそれぞれのソフトウェア部品に対して書く必要はありません。
ツール・チェイン・ファイルは、ターゲット・プラットフォームごとに書くものです。 言い換えれば、
同じターゲット・プラットフォームで動く、それぞれのソフトウェア・パッケージをビルドするのであれば、
そのすべてのパッケージで使う1つのツール・チェイン・ファイルを書くだけです。
If your compiler is not able to build a simple program by default without special flags or files (e.g. linker
scripts or memory layout files), the toolchain file as shown above doesn't work. Then you have to force
the compiler:
コンパイラーが、特殊なフラグやファイル(たとえば、リンカーのスクリプトやメモリ・レイアウト・ファイル)を
使わなくても、簡単なプログラムをビルドできないなら、ツール・チェイン・ファイルは動きません。 そのときは、
コンパイラーを強制指定しなければなりません。
INCLUDE(CMakeForceCompiler)

# this one is important
SET(CMAKE_SYSTEM_NAME eCos)

# specify the cross compiler
CMAKE_FORCE_C_COMPILER(arm-elf-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(arm-elf-g++ GNU)

# where is the target environment
SET(CMAKE_FIND_ROOT_PATH  /home/alex/src/ecos/install )

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
This is done using the CMAKE_FORCE_XXX_COMPILER() macros. The second argument is the compiler id,
which is used by CMake to recognize the compiler.
これは、CMAKE_FORCE_XXX_COMPILER( ) マクロを使っています。 2つ目の引数は、CMake が認識できる
コンパイラーの ID です。
optional, version of your target system, not used very much.
オプションです。 あなたのターゲット・システムのバージョンです。 あまり使われません。
optional, processor (or hardware) of the target system. This variable is not used very much except for
one purpose, it is used to load a CMAKE_SYSTEM_NAME-compiler-CMAKE_SYSTEM_PROCESSOR.cmake
file, which can be used to modify settings like compiler flags etc. for the target. You probably only have
to set this one if you are using a cross compiler where every target hardware needs special build settings.
オプションです。 ターゲット・システムのプロセッサー(ハードウェア)です。 この変数は1つの目的以外には
あまり使われません。 それは、CMAKE_SYSTEM_NAME-compiler-CMAKE_SYSTEM_PROCESSOR.cmake
ファイルを読み込むことです。 コンパイラーのフラグなどの設定を修整するのに使われます。
おそらく、ターゲット・ハードウェアに特別なビルドの設定が必要なクロス・コンパイラーを使うときだけ、
必要になります。
Since CMake cannot guess the target system, it also cannot guess which compiler it should use, so you
have to preset this too:
CMake はターゲット・システムを推測できないので、適切なコンパイラーを推測することもできません。
よって、次の変数も提供しなければなりません。
the C compiler executable, may be the full path or just the filename. If it is specified with full path, then
this path will be prefered when searching the C++ compiler and the other tools (binutils, linker, etc.).
If this compiler is a gcc-cross compiler with a prefixed name (e.g. "arm-elf-gcc") CMake will detect this
and automatically find the corresponding C++ compiler (i.e. "arm-elf-c++"). The compiler can also be
preset via the CC environment variables.
C コンパイラーです。 これは、フルパスまたはファイル名です。 フルパスを指定した場合、C++ コンパイラー
や他のツール(binunits, linker など)を探すときに、優先的に探します。 もし、コンパイラーが arm-elf-gcc
のように接頭辞が付いた gcc のクロスコンパイラーだったら、CMake はこのことを検出し、自動的に対応
する C++ コンパイラー(例:arm-elf-c++)を見つけます。 また、コンパイラーは、CC 環境変数を参照して
プリセットします。
Most non-trivial projects will depend on external libraries or tools. CMake offers the FIND_PROGRAM(),
FIND_LIBRARY(), FIND_FILE(), FIND_PATH() and FIND_PACKAGE() commands for this purpose.
ほとんどの小さくないプロジェクトは、外部のライブラリやツールに依存しています。 CMake は、この目的
のために、FIND_PROGRAM(), FIND_LIBRARY(), FIND_FILE(), FIND_PATH(), FIND_PACKAGE() を提供して
います。
They search the file system in common places for files and return the results. FIND_PACKAGE() is a bit
different in that it actually doesn't search itself, but "only" executes FindXXX.cmake modules,
which usually call the FIND_PROGRAM(), FIND_LIBRARY(), FIND_FILE() and FIND_PATH() commands then.
これらは、共有する場所にあるファイルシステムの中からファイルを探して、結果を返します。
FIND_PACKAGE() は、少し違っていて、実際には探さない代わりに、FindXXX.cmake モジュールを実行
するところだけ違います。 FindXXX.cmake モジュールは、通常、FIND_PROGRAM(), FIND_LIBRARY(),
FIND_FILE(), FIND_PATH() コマンドを呼び出します。
When cross compiling e.g. for a target with an ARM processor getting /usr/lib/libjpeg.so as the result of
a FIND_PACKAGE(JPEG) wouldn't be much of a help, since this would be the JPEG library for the host
system, e.g. an x86 Linux box. So you need to tell CMake to search in other locations.
This can be done by setting the following variables:
たとえば、ARM プロセッサを持つターゲットをクロス・コンパイルするときは、FIND_PACKAGE(JPEG) の
結果として /usr/lib/libjpeg.so を取得しても、役に立たないしょう。 なぜなら、これは、x86 の
Linux box などの、ホスト・システムの JPEG ライブラリだからです。 よって、CMake が他の場所を探す
ように伝える必要があります。 次の変数を設定できます。
CMAKE_FIND_ROOT_PATH
this is a list of directories, each of the directories listed there will be prepended to each of the search
directories of every FIND_XXX() command.
これは、ディレクトリのリストです。 これらは、それぞれの FIND_XXX() コマンドが探すディレクトリの
リストの先頭に追加します。
So e.g. if your target environment is installed under /opt/eldk/ppc_74xx, set CMAKE_FIND_ROOT_PATH
to this directory. Then e.g. FIND_LIBRARY(BZ2_LIB bz2) will search in /opt/eldk/ppc_74xx/lib,
/opt/eldk/ppc_74xx/usr/lib, /lib, /usr/lib and so give /opt/eldk/ppc_74xx/usr/lib/libbz2.so as result.
たとえば、ターゲットの環境が、/opt/eldk/ppc_74xx の中にインストールされている場合、
CMAKE_FIND_ROOT_PATH に、このディレクトリを指定します。 すると、FIND_LIBRARY(BZ2_LIB bz2)
などは、/opt/eldk/ppc_74xx/lib, /opt/eldk/ppc_74xx/usr/lib, /lib, /usr/lib の順に探して、
/opt/eldk/ppc_74xx/usr/lib/libbz2.so を結果として返すでしょう。
By default CMAKE_FIND_ROOT_PATH is empty. If set, at first the directories prefixed with the directories
given in CMAKE_FIND_ROOT_PATH will be searched and after that the unprefixed versions of the search
directories will be searched.
CMAKE_FIND_ROOT_PATH のデフォルトは、空です。 最初は、CMAKE_FIND_ROOT_PATH に指定した
ディレクトリを前に付けたディレクトリを探すでしょう。 その後、 前に付けないディレクトリを探すでしょう。
This behaviour can be modified individually for every FIND_XXX() call with the
NO_CMAKE_FIND_ROOT_PATH, ONLY_CMAKE_FIND_ROOT_PATH and CMAKE_FIND_ROOT_PATH_BOTH
options or the default for all FIND_XXX() commands can be adjusted with the
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM, CMAKE_FIND_ROOT_PATH_MODE_LIBRARY and
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE variables.
この動きは、それぞれの FIND_XXX() の呼び出しに対して、NO_CMAKE_FIND_ROOT_PATH、
ONLY_CMAKE_FIND_ROOT_PATH、 CMAKE_FIND_ROOT_PATH_BOTH オプションや、
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM 変数、 CMAKE_FIND_ROOT_PATH_MODE_LIBRARY 変数、
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE 変数によって調整することができる、すべての FIND_XXX()
コマンドのデフォルトを個別に変更できます。
If you don't want to use only libraries that come with the toolchain but also build and use additional
libraries for your target platform, you should create an install directory for these packages,
e.g. $HOME/eldk-ppc_74xx-inst/ and add this to CMAKE_FIND_ROOT_PATH, so the FIND_XXX()
commands will search there too. If you then build packages for your target platform, they should be
installed into this directory.
もし、ツール・チェインによるライブラリだけ使いたくなく、ターゲット・プラットフォーム用の追加ライブラリ
を使いたい場合、それらのパッケージのインストール・ディレクトリ(たとえば、$HOME/eldk-ppc_74xx-inst/)
を作るべきであり、CMAKE_FIND_ROOT_PATH に、このディレクトリを追加するべきです。 すると、
FIND_XXX() コマンドは、それらの中も探します。 もし、ターゲット・プラットフォーム用のパッケージを
ビルドしたら、このディレクトリにインストールすべきです。
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM
This sets the default behaviour for the FIND_PROGRAM() command. It can be set to NEVER, ONLY
or BOTH (default).
これに、FIND_PROGRAM() コマンドのデフォルトの動きを指定します。 NEVER か ONLY か BOTH
(=デフォルト) を指定できます。
If set to NEVER, CMAKE_FIND_ROOT_PATH will not be used for FIND_PROGRAM() calls (except
where it is enabled explicitely).
NEVER を指定したら、FIND_PROGRAM() を呼び出したときに(そこで明示的に使うように指定
されない限り)、CMAKE_FIND_ROOT_PATH は使われません。
If set to ONLY, only the search directories with the prefixes coming from CMAKE_FIND_ROOT_PATH
will be used in FIND_PROGRAM().
ONLY を指定したら、FIND_PROGRAM() では、CMAKE_FIND_ROOT_PATH によって前に付けられた、
検索するディレクトリが使われます。
The default is BOTH, which means that at first the prefixed directories and after that the unprefixed
directories will be searched.
デフォルトは、BOTH です。 これは、前に付けられたディレクトリが先で、その後、前に付けない
ディレクトリを探します。
In most cases FIND_PROGRAM() is used to search for an executable which will then be executed
e.g. using EXECUTE_PROCESS() or ADD_CUSTOM_COMMAND(). So in most cases an executable
from the build host is required, so usually set CMAKE_FIND_ROOT_PATH_MODE_PROGRAM to NEVER.
FIND_PROGRAM() の、ほとんどのケースは、EXECUTE_PROCESS() や ADD_CUSTOM_COMMAND()
などを実行する、実行ファイルを探すことに使います。 ホストがビルドする実行ファイルのケースでは、
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM に NEVER. を指定します。
(cache)
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY
This is the same as above, but for the FIND_LIBRARY() command. In most cases this is used to find
a library which will then be used for linking, so a library for the target is required. So in the common
case, set it to ONLY.
これは、上記と同じですが、FIND_LIBRARY() コマンドであることが異なります。 ほとんどのケースで、
リンクするターゲット用のライブラリを見つけるために使われます。 共有するケースでは ONLY を
指定します。
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE
This is the same as above and used for both FIND_PATH() and FIND_FILE(). In many cases this is
used for finding include directories, so the target environment should be searched. So in the
common case, set it to ONLY.
これは、上記と同じですが、FIND_PATH() コマンドと FIND_FILE() コマンドであることが異なります。
多くのケースで、ターゲット用のインクルードするディレクトリを見つけるために使われます。
共有するケースでは ONLY を指定します。
You may have to adjust this behaviour for some of the FIND_PATH() or FIND_FILE() calls using
the NO_CMAKE_FIND_ROOT_PATH, ONLY_CMAKE_FIND_ROOT_PATH and
CMAKE_FIND_ROOT_PATH_BOTH options.
NO_CMAKE_FIND_ROOT_PATH、 ONLY_CMAKE_FIND_ROOT_PATH、CMAKE_FIND_ROOT_PATH_BOTH
オプションを使って、FIND_PATH() か FIND_FILE() を呼び出す動きを調整するべきです。
コマンド名は、大文字小文字を区別しないようです。
Load settings for an external project.
外部プロジェクトの設定をロードします。
find_package(<package> [version] [EXACT] [QUIET] [[REQUIRED|COMPONENTS] [components...]]
             [NO_POLICY_SCOPE])
Finds and loads settings from an external project. <package>_FOUND will be set to indicate whether
the package was found. When the package is found package-specific information is provided through
variables documented by the package itself.
外部プロジェクトから設定を見つけてロードします。 <package>_FOUND には、パッケージが見つかっ
たかどうかを示す値が設定されます。 パッケージが見つかったら、パッケージに関する情報が、
パッケージ自身によって文章化された変数を通して提供されます。
Link a target to given libraries.
指定したライブラリを、ターゲットとリンクします。
target_link_libraries(<target> [lib1 [lib2 [...]]] [debug|optimized|general] <lib>] ...)
Specify a list of libraries to be linked into the specified target. If any library name matches that of
a target in the current project a dependency will automatically be added in the build system to
make sure the library being linked is up-to-date before the target links.
指定したターゲットとリンクするライブラリのリストを記述してください。 もし、ライブラリ名が
現在のプロジェクトのターゲットとマッチしたら、依存するものは自動的に、リンクするライブラリを
確認するビルド・システムに追加され、ターゲットとリンクする前に、更新します。
Find the directory containing a file.
ファイルを含むディレクトリを見つけます。
find_path(<VAR> name1 [path1 path2 ...])
This is the short-hand signature for the command that is sufficient in many cases. It is the same
as find_path(<VAR> name1 [PATHS path1 path2 ...])
これは、多くのケースで十分なコマンドの速記形です。
find_path(<VAR> name1 [PATHS path1 path2 ...]) と同じです。
This command is used to find a directory containing the named file. A cache entry named by
<VAR> is created to store the result of this command. If the file in a directory is found the result
is stored in the variable and the search will not be repeated unless the variable is cleared.
find_path(<VAR>  name | NAMES name1 [name2 ...]  [HINTS path1 [path2 ... ENV var]]
          [PATHS path1 [path2 ... ENV var]]  [PATH_SUFFIXES suffix1 [suffix2 ...]]
          [DOC "cache documentation string"]  [NO_DEFAULT_PATH]  [NO_CMAKE_ENVIRONMENT_PATH]
          [NO_CMAKE_PATH]  [NO_SYSTEM_ENVIRONMENT_PATH]  [NO_CMAKE_SYSTEM_PATH]
          [CMAKE_FIND_ROOT_PATH_BOTH | ONLY_CMAKE_FIND_ROOT_PATH | NO_CMAKE_FIND_ROOT_PATH])
このコマンドは、指定した名前のファイルを含むディレクトリを見つけます。 <VAR> という名前の
キャッシュ・エントリーは、このコマンドの結果を代入して作られます。
もし、ディレクトリの中にファイルが見つかれば、変数の中に代入し、変数がクリアされない限り、
検索を繰り返しません。
The name of the file in a directory that is searched for is specified by the names listed after
the NAMES argument. Additional search locations can be specified after the PATHS argument.
検索するディレクトリの中のファイル名は、NAME 引数の後に並べます。
追加して検索する場所は、PATHS 引数の後に記述できます。
If NO_DEFAULT_PATH is not specified, the search process is as follows:
NO_DEFAULT_PATH を指定しなかった場合、検索する手順は次のようになります。
1. Search paths specified in cmake-specific cache variables. These are intended to be used on
the command line with a -DVAR=value. This can be skipped if NO_CMAKE_PATH is passed.
1. cmake-specific キャッシュ変数に指定されたパスを探します。 これらは、コマンドラインの
-DVAR=value に使われることを意図します。 これは、 NO_CMAKE_PATH をパスしたら、
スキップできます。
2. 同、環境変数。
訳注)name1 は、ファイル名、path1 は、ディレクトリ名です。
Linux の場合、name には、libXXX.so の XXX の部分を指定するようです。
変数に代入される値は、ライブラリ・ファイルのパスです。 ライブラリが入ったフォルダーではありません。
This command is used to find a library. A cache entry named by <VAR> is created to store the
result of this command. If the library is found the result is stored in the variable and the search
will not be repeated unless the variable is cleared.
このコマンドは、ライブラリを見つけます。 <VAR> という名前のキャッシュ・エントリーは、この
コマンドの結果を代入して作られます。 ライブラリが見つかったら、変数に結果を代入し、
変数がクリアされない限り、繰り返しません。
CMAKE_BUILD_TYPE
Debug, Release, RelWithDebInfo, MinSizeRel のいずれか。
ビルドするコンフィギュレーションを指定します。
cmake  -D CMAKE_BUILD_TYPE="Debug" ...
make のようなもの。
参考
ダウンロード
m4 は、マクロ・プロセッサです。 define などのディレクティブを使って、シンボルの置換を行います。
多くの場合、シンボルがコードに置き換えられ、簡易的なコードジェネレーターとして使われます。

たとえば、autoconf は、configure.in や Makefile.in という名前の m4 ファイルを configure スクリプトと
Makefile に変換します。 autoconf が定義している m4 の define ディレクティブについては、autoconf
の仕様を確認してください。
参考
define(`MAIN_CODE',`int  main() { return  sub(); }')
define(`SUB_CODE', `int  sub() { return  0; }')

MAIN_CODE
SUB_CODE
$ m4 sample1.m4


int  main() { return  sub(); }
int  sub() { return  0; }
sample1.m4
… 置き換える define ディレクティブ
クォーテーションの記号が開始と終了で
異なることに注意
シェルから m4 を実行したときの出力
日本語や UTF-8 文字コードは使えません。
関連
→ XSL
MAIN_CODE
主なディレクティブの一覧
置き換えられるのは、define で定義されたシンボルです。 つまり、英文字から始まる単語は
置き換えられる可能性があり、数字は置き換わりません。

.m4 ファイルに書かれたものの、ほとんどがシンボルになっていることもあります。
それぞれのシンボルが、ある程度の規模を持った、ソース・コードに変換されることもあります。
m4 コマンドの -D オプションを使って、置換後の内容を切り替えることが多いでしょう。
SUB_CODE
define(`SYMBOL',`Line1
Line2')
aaa SYMBOL bbb

aaa Line1
Line2 bbb
define ディレクティブによって、複数行に置換するときは、` から ' の間に改行を含めます。
m4 sample.m4 を実行したときの出力
sample.m4
[ 親: m4 ]
Line1
Line2
sample.m4
m4 sample.m4 を実行したときの出力

VAR is "1"
define(`VAR',1)
ifdef(`VAR',
  ``VAR' is "VAR"',
  `VAR is not defined')
VAR is not defined
m4 sample.m4 を実行したときの出力
sample.m4
ifdef(`VAR',
  ``VAR' is "VAR"',
  `VAR is not defined')
m4 -DVAR=2 sample.m4 を実行したときの出力
2
m4 を起動したときのパラメーターに、-D オプションを付けると、define されます。
sample.m4
VAR
ifdef( `シンボル',  `真のとき',  `偽のとき' )
ifelse( 左辺,  右辺,  `左辺と右辺が等しいとき'  [, `等しくないとき'] )
置換(展開)するシンボルは、` ' で囲まないでください。
等しくないときの引数を省略したとき、等しくなかったら、空文字になります。
sample.m4
VAR is "1"
m4 -DVAR=1 sample.m4 を実行したときの出力
ifelse(VAR,1,
  ``VAR' is "1"',
  ``VAR' is not "1"')
m4 -DVAR=2 sample.m4 を実行したときの出力
VAR is not "1"
VAR is not "1"
m4 sample.m4 を実行したときの出力
ifelse( 左辺,  右辺A,  `左辺と右辺Aが等しいとき',
               右辺B,  `左辺と右辺Bが等しいとき',  [, `等しくないとき'] )
シンボルは ` ' で囲んでください。
上記は3分岐の書式ですが、同様に4分岐以上もできます。
サンプル
サンプル