---
title: "Emakefile并行编译"
author: "litaocheng"
date: "2011-11-17T13:15:03Z"
tags: []
categories: ["编程语言"]
slug: "emakefile"
draft: false
lastmod: "2011-11-17T13:15:03Z"
id: 1264038
url: "https://erlangdisplay.iteye.com/blog/1264038"
---

项目代码越来越多，使用erlang编译也越来越慢。无论是Makefile还是Emakefile都力不从心。使用rebar编译速度会加快，但对原有项目改动太大。
通过对make.erl(otp/lib/tools/src/make.erl)进行修改，提供一个支持多进程编译的mmake.erl。其接口和make.erl相似，只是第一个参数为并发编译数，具体看下代码吧，非常简单。

对于项目中有编译次序要求时，比如必须首先编译自定义behaviour模块，随后编译其它模块，可以通过将Emakefile中内容分成多个{mod, opts}来达到目的。mmake实现中，对于同一个{mod, opts}内的模块会并行编译，而所有的{mod,opts}是顺序编译的。通过这个规则，我们就可以自定义顺序编译和并行编译。

比如，我们的项目首先要编译 gen_mod.erl，随后是mod_battle.erl,mod_team.erl模块：

```erlang

cat Emakefile
{"gen_mod.erl", [{i, "include}, {outdir, "ebin"}]}.
{["mod_battle.erl","mod_team.erl"], [{i, "include}, {outdir, "ebin"}]}.

```


代码地址:https://github.com/litaocheng/mmake