版权声明:@潘广宇博客, https://blog.csdn.net/panguangyuu/article/details/89070733
通过 makefile 可以自动化一部分工作,比如编译 .erl 文件
一、在 /root/workspace/erlang/test 中新建两个 .erl 文件,分别是 test.erl ,test2.erl
% test.erl
-module(test).
-export([hello/0]).
hello() -> io:format("hello, world~n").
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% test2.erl
-module(test2).
-export([hello2/0]).
hello2() -> io:format("hello2, world~n").
二、创建 makefile
.SUFFIXES: .erl .beam
.erl.beam:
erlc -W $<
ERL = erl -boot start_clean
### 模块的定义,如有 test.erl test2.erl 则写 test test2
MODS = test test2
all:compile
${ERL} -pa '/root/workspace/erlang/test' -s test hello -s test2 hello2
### 当输入 make 时,默认是 make all , 会自动执行上面的语句,会同时编译并执行 test:hello() test2.hello()
compile: ${MODS:%=%.beam}
test:compile
${ERL} -pa '/root/workspace/erlang/test' -s test hello
### 当输入 make test 时, 会自动执行上面的语句,会同时编译并执行 test:hello()
test2:compile
${ERL} -pa '/root/workspace/erlang/test' -s test2 hello2
### 当输入 make test2 时, 会自动执行上面的语句,会同时编译并执行 test2:hello2()
clean:
rm -rf *.beam erl_crash.dump
### 移除已编译的对象代码和 erl_crash.dump 文件
三、测试
make % 会编译执行两个模块
make test % 只会编译执行 hello 模块
make test2 % 只会编译执行 hello2 模块