erlang erl文件编译的三种脚本

方案1:命令行

#!/bin/sh

#file name: erl.sh
#author: stars
#time:2015.06.05
#eg: ./erl.sh hello.erl start 2

#full name for erl name.
erlFileName=$1
#the function in erl file.
func=$2
# params
params=$3

erlFileSize=`expr length "$erlFileName"`
subSize=`expr $erlFileSize - 4`
erlFileBaseName=`expr substr "$erlFileName" 1 $subSize`

erlc $erlFileName
erl -noshell -s $erlFileBaseName $func $params -s init stop

 

方案2:escript

#!/usr/bin/env escript

main(_) -> io:format("Hello World\n").

 

方案3:makefile

#makefile for erl
#author: stars
#time: 2015.06.05

.SUFFIXES: .erl .beam
    
ERL         = erl -noshell

ERL_DIR     = .
BEAM_DIR    = .
MODULES     = $(patsubst $(ERL_DIR)/%.erl, $(BEAM_DIR)/%.beam, $(wildcard $(ERL_DIR)/*.erl))

all: compile
    $(ERL) -s hello start -s init stop

compile: $(MODULES)

%.beam: %.erl
    erlc -W $<

.PHONY: clean
clean:
    rm -rf $(MODULES) *.dump

 

posted on 2015-06-05 16:16  霏霏暮雨  阅读(2769)  评论(0编辑  收藏  举报

导航