天天看點

2015-1-11 【erlang】Emakefile的{d,Macro} {d,Macro,Value}的小了解

先來段抄的,來自 http://blog.sina.com.cn/s/blog_96b8a15401012ezu.html

Erlang有個類似Makefile的檔案Emakefile負責編譯erl程式,

格式是

Erlang代碼

  1. {Modules, Options}.

其中Modules是一個atom,或者是一個atom的清單。

這些atom

可以是一個子產品名,如file1;

可以是别的目錄中的子產品名,如../foo/file3;

也可以是通過通配符比對的一系列子產品名,如file*;

還可以是上述atom的清單,如['file*', '../foo/file3', 'File4']。

Options是compiler指令的配置參數,具體參數可以 檢視文檔

一個Emakefile的例子

Erlang代碼

  1. {'src/*',
  2. [debug_info,
  3. {i,"include"},
  4. {outdir,"ebin"}
  5. ]}.

shell指令

Shell代碼

  1. erl -make

将尋找目前目錄下的Emakefile檔案,然後根據檔案内容build,例如上述例子将目前src目錄中的所有子產品進行編譯,程式中-include 或者 -include_dir指定的相關檔案将在include目錄中查找,編譯好的beam檔案輸出到ebin目錄下。

make時将檢視輸出目錄下有沒有相關的編譯檔案,如果沒有則進行編譯;

如果有則檢查檔案時間,比較後決定是否要進一步編譯;

如果是最新修改的源檔案,則進行編譯。

ps:

在erl shell中輸入指令

Erlang shell代碼

  1. make :all().

有同樣的功效。如果加上load參數,

Erlang shell代碼

  1. make:all([load]).

1.然後學習一些源碼時,發現某個Emakefile中的Options清單中出現了{d,Macro}, {d,Macro,Value}的使用 問題來源:

2015-1-11 【erlang】Emakefile的{d,Macro} {d,Macro,Value}的小了解

檢視compiler-4.8.2 文檔關于Options的參數說明,如下: {d,Macro}

{d,Macro,Value}

Defines a macro Macro to have the value Value. Macro is of type atom, and Value can be any term. The

default Value is true. 翻譯: 選項{d,Macro}或者{d,Macro,Value}  定義一個名為Macro的宏,對應的值為Value. Macro呢,是一個原子類型,然後呢,Value,可以為任何erlang中的項式。Value的預設值為true(那麼,上面中的 {d,Macro}等價于{d,Macro,true} ) 那麼 總結下就是, 1.在Emakefile的{Modules, Options} 的Options的清單中,出現{d,Debug}等價與 {debug,Debug,true},即定義了一個全局的宏,等價于-define Debug true。然後全部源碼都可以用Debug這個宏了 2.erlang中如何使用Emakefile,需要查閱compiler-4.8.2(自己目前在用R15B版本) 中的compile:file/1,2以及查閱 tools-2.6.8中關于erl的-make選項的相關内容  3.有待補充

繼續閱讀