光棍节???????
:-)
学习erlang开发时,在某个Makefile中发现,在使用erl时使用 -make 选项,于是查找手册学习之,顺带了解了Emakefile
1.困惑的出现 erl -make
2.erts-5.9.3.1手册上关于erl的-make选项的解释
3.原来是等于调用了make模块all()函数,tools-2.6.8 手册中关于make的文档如下
makeErlang module
The module make provides a set of functions similar to the UNIX type Make functions. (类似与Unix下的Make功能)
Exports
all() -> up_to_date | error
all(Options) -> up_to_date | error
Types:
Options = [Option]
Option = noexec | load | netload | <compiler option>
This function first looks in the current working directory for a file named Emakefile (see below) specifying the set
of modules to compile and the compile options to use. If no such file is found, the set of modules to compile defaults
to all modules in the current working directory.
翻译:
这个函数首先会在当前工作目录下查找一个名为 Emakefile 文件(下面有介绍),该文件是用来指定模块的编译选项的。如果找不到这个文件,则编译当前目录下的所有模块。
• there is no object file, or
• the source file has been modified since it was last compiled, or,
• an include file has been modified since the source file was last compiled.
翻译:
在遍历所有模块时,如果某个模块满足下面的条件之一,则会被重新编译:
1.该模块没有目标文件,或者
2.该模块的源代码自从上次编译后已经有所改动,又或者
3.该模块的源代码自从上次编译后,它所包含的头文件有所改动
As a side effect, the function prints the name of each module it tries to compile. If compilation fails for a module, the
make procedure stops and error is returned.
Options is a list of make- and compiler options. The following make options exist:
• noexec
No execution mode. Just prints the name of each module that needs to be compiled.
• load
Load mode. Loads all recompiled modules.
• netload
Net load mode. Loads all recompiled modules an all known nodes.
翻译:
编译模块时,会把每个模块的名称打印到终端上。如果一个模块在编译时发生了错误,编译过程会终止并返回错误信息。
参数 Options 是一个列表类型的参数,选项值有如下:
1.noexec:不执行模式,只打印需要编译的模块的名字,不做任何其他操作2.load:加载模式,加载所有编译过的模块
3.netload:网络加载模式,把编译好的模块加载到所有已知的节点上
All items in Options that are not make options are assumed to be compiler options and are passed as-is to
compile:file/2. Options defaults to [] .
files(ModFiles) -> up_to_date | error
files(ModFiles, Options) -> up_to_date | error
Types:
ModFiles = [Module | File]
Module = atom()
File = string()
Options = [Option]
Option = noexec | load | netload | <compiler option>
files/1,2 does exactly the same thing as all/0,1 but for the specified ModFiles, which is a list of module
or file names. The file extension .erl may be omitted.
The Emakefile (if it exists) in the current directory is searched for compiler options for each module. If a given
module does not exist in Emakefile or if Emakefile does not exist, the module is still compiled.
翻译:
选项若不是make的选项,则会被认为是compiler的选项,将会被原样传给compile:file/2函数
参数 Options 的默认值是 []。
compile:
files/1,2和make:
all/0,1并非是完全一样的,但是对于指定的ModFiles(模块列表或文件列表),功能确实一样的。
在写ModFiles参数是,后缀 .erl可以忽略。
在当前目录下的Emakefile(如果存在的话),会被编译器搜索。如果一个在Emakefile中没有被指定编译选项,或者Emakefile根本就不存在,模块还是会照旧被编译下去。
(这么说,Emakefile只是用来指定每个模块的编译的方式,可能有些模块比较特别,需要指出不同的编译选项来,后来看了下面的Emakefile的介绍,应该是这么理解的)
Emakefile
make:all/0,1 and make:files/1,2 looks in the current working directory for a file named Emakefile. If
it exists, Emakefile should contain elements like this:
make:all/0,1 and make:files/1,2 looks in the current working directory for a file named Emakefile. If
it exists, Emakefile should contain elements like this:
Modules.
{Modules,Options}.
Modules is an atom or a list of atoms. It can be
• a module name, e.g. file1
• a module name in another directory, e.g. ../foo/file3
• a set of modules specified with a wildcards, e.g. 'file*'
• a wildcard indicating all modules in current directory, i.e. '*'
• a list of any of the above, e.g. ['file*','../foo/file3','File4']
{Modules,Options}.
Modules is an atom or a list of atoms. It can be
• a module name, e.g. file1
• a module name in another directory, e.g. ../foo/file3
• a set of modules specified with a wildcards, e.g. 'file*'
• a wildcard indicating all modules in current directory, i.e. '*'
• a list of any of the above, e.g. ['file*','../foo/file3','File4']
翻译:
make:all/0,1 和 make:files/1,2在当前工作目录下寻找一个名为Emakefile的文件。
如果存在,Emakefile这个文件应该包含如下元素
Modules.
{Modules,Options}.
Modules是一个原子或者是一个包含原子的列表。它可以是
1.一个模块的名字,比如 file1
2.一个在其他目录下的模块的名字,比如 ../foo/file3
3.用了通配符的一系列的模块的名字,比如 'file*'
4.简单的一个通配符,就是‘*’,指明了在当前目录下的所有模块
5.包含了上述4种情况的列表,比如 ['file*','../foo/file3','File4']
Options is a list of compiler options.Emakefile is read from top to bottom. If a module matches more than one entry, the first match is valid. For example,
the following Emakefile means that file1 shall be compiled with the options [debug_info,{i,"../
foo"}] , while all other files in the current directory shall be compiled with only the debug_info flag.
{'file1',[debug_info,{i,"../foo"}]}.
{'*',[debug_info]}
翻译:
Options 是编译器的选项的列表
Emakefile会被从头至尾的检查一遍(应该是被make:all/0,1 and make:files/1,2吧)。如果(当前工作目录下的)某个模块名字能够(与Emakefile中项目)匹配多项,则第一个匹配的有效。请看这个例子:
{'file1',[debug_info,{i,"../foo"}]}.
{'*',[debug_info]}
{'*',[debug_info]}
file1被编译的时候,使用的编译选项应该是 [debug_info,{i,"../foo"}]
而在当前工作目录下的其他文件,则都只用到编译选项 debug_info