Erlang(八)makefile编译自动化

运行程序的不同方式

1、在Erlang shell里编译和执行

2、在命令行提示符界面里编译和执行

erlc hello.erl
erl -noshell -s hello start -s init stop

3、作为Escript运行

#!/user/bin/env escript
main(Args) -> 
    io:format("hello world~n").

带命令行参数的程序

makefile编译自动化,执行make

# leave these lines alone
.SUFFIXES: .erl .beam .yrl
.erl.beam:
     erlc -W $<
.yrl.erl:
     erlc -W $<
ERL = erl -boot start_clean
# Here's a list of the erlang modules you want compiling
# If the modules don't fit onto one line add a \ character
# to the end of the line and continue on the next line
# Edit the lines below
MODS = module1 module2 \
       module3 ... special1 ...\
       ...
       moduleN
# The first target in any makefile is the default target.
# If you just type "make" then "make all" is assumed (because
#   "all" is the first target in this makefile)
all: compile
compile: ${MODS:%=%.beam} subdirs    
## special compilation requirements are added here
special1.beam: special1.erl   
    ${ERL} -Dflag1 -W0 special1.erl
## run an application from the makefile
application1: compile
    ${ERL} -pa Dir1  -s application1 start Arg1 Arg2
# the subdirs target compiles any code in
# sub-directories
subdirs:
    cd dir1; $(MAKE)
    cd dir2; $(MAKE)
    ...
# remove all the code
clean:    
    rm -rf *.beam erl_crash.dump
    cd dir1; $(MAKE) clean
    cd dir2; $(MAKE) clean  
erlang9