在windows开发环境下写bat脚本实现对erlang项目的并行编译处理

在windows开发环境下写bat脚本实现对erlang项目的并行编译:
1.项目结构:

这里写图片描述

config————>项目配置文件
ebin ————-> 编译文件路径
include———–> 引入文件
logs ————-> 日志文件
mmake———-> 并行编译所需的脚本
script ———–> 项目启动脚本
src ————–> 项目逻辑文件
MEmakefile —–>编译所需文件

3.编译脚本:mmake_all.bat(在script下)
并行编译所需文件:mmake.erl,mmake.beam(在mmake下),mmake.beam是mmake.erl编译后的文件

4.脚本代码:
mmake_all.bat

cd ../ebin
del *.beam
cd ../mmake
mkdir include
erlc -I include/ mmake.erl
cd ..
erl +P 1024000 -smp auto -pa mmake/ -s mmake all
pause

mmake.erl

%% 多进程编译
%% 解析Emakefile,根据获取{mods, options}列表,
%% 按照次序编译每项(解决编译顺序的问题)
%% 其中mods也可以包含多个模块,当大于1个时,
%% 可以启动多个process进行编译,从而提高编译速度.
-module(mmake).
-export([all/0,files/2, files/3]).
-compile(export_all).
-include_lib("kernel/include/file.hrl").

-define(MakeOpts,[noexec,load,netload,noload]).

all() ->
    all(30).
all(Worker) when is_integer(Worker) ->
    all(Worker, []).

all(Worker, Options) when is_integer(Worker) ->
    {MakeOpts, CompileOpts} = sort_options(Options,[],[]),
    case read_emakefile('MEmakefile', CompileOpts) of
        Files when is_list(Files) ->
            do_make_files(Worker, Files, MakeOpts),
            io:format("@@@@@@@@@@@@@@       finish compile   @@@@@@@@@@@@@@@@@~n");
        error ->
            error
    end,
    erlang:halt().

files(Worker, Fs) ->
    files(Worker, Fs, []).

files(Worker, Fs0, Options) ->
    Fs = [filename:rootname(F,".erl") || F <- Fs0],
    {MakeOpts,CompileOpts} = sort_options(Options,[],[]),
    case get_opts_from_emakefile(Fs,'MEmakefile',CompileOpts) of
        Files when is_list(Files) ->
            do_make_files(Worker, Files,MakeOpts);
        error -> error
    end.

do_make_files(Worker, Fs, Opts) ->
    %io:format("worker:~p~nfs:~p~nopts:~p~n", [Worker, Fs, Opts]),
    process(Fs, Worker, lists:member(noexec, Opts), load_opt(Opts)).

sort_options([H|T],Make,Comp) ->
    case lists:member(H,?MakeOpts) of
        true ->
            sort_options(T,[H|Make],Comp);
        false ->
            sort_options(T,Make,[H|Comp])
    end;
sort_options([],Make,Comp) ->
    {Make,lists:reverse(Comp)}.

%%% Reads the given Emakefile and returns a list of tuples: {Mods,Opts}
%%% Mods is a list of module names (strings)
%%% Opts is a list 
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值