From dd3e666c5114f81c9518e9f5ba14959ced079ab6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Date: Mon, 14 Dec 2009 23:04:00 +0100 Subject: Add dependencies Makefile generation to erlc(1) and compile(3) This is useful when a project is built with Makefiles and erlc(1) instead of EMakefiles. Tracking dependencies by hand is error-prone and it becomes painful when using external application headers like EUnit's one. A dependencies Makefile will look like this: module.beam: module.erl \ /usr/local/lib/erlang/lib/eunit-2.1.4/include/eunit.hrl \ header.hrl When included in the main Makefile, 'module' will be recompiled only when needed. GCC offers the same feature and new erlc(1) options are compatible with it. More informations at: http://wiki.github.com/dumbbell/otp/dependencies-makefile --- erts/doc/src/erlc.xml | 44 ++++++++++++++++++++++ erts/etc/common/erlc.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) (limited to 'erts') diff --git a/erts/doc/src/erlc.xml b/erts/doc/src/erlc.xml index 1e8960c22c..7e689c418e 100644 --- a/erts/doc/src/erlc.xml +++ b/erts/doc/src/erlc.xml @@ -141,6 +141,50 @@ for compiling native code, which needs to be compiled with the same run-time system that it should be run on.

+ -M + +

Produces a Makefile rule to track headers dependencies. The + rule is sent to stdout. No object file is produced. +

+
+ -MF Makefile + +

Like the option above, except that the + Makefile is written to Makefile. No object + file is produced. +

+
+ -MD + +

Same as .Pbeam]]>. +

+
+ -MT Target + +

In conjunction with or + , change the name of the rule emitted + to Target. +

+
+ -MQ Target + +

Like the option above, except that + characters special to make(1) are quoted. +

+
+ -MP + +

In conjunction with or + , add a phony target for each dependency. +

+
+ -MG + +

In conjunction with or + , consider missing headers as generated + files and add them to the dependencies. +

+
--

Signals that no more options will follow. diff --git a/erts/etc/common/erlc.c b/erts/etc/common/erlc.c index cd137435d1..b76a2caf91 100644 --- a/erts/etc/common/erlc.c +++ b/erts/etc/common/erlc.c @@ -28,6 +28,7 @@ #include /* FIXE ME config_win32.h? */ #define HAVE_STRERROR 1 +#define snprintf _snprintf #endif #include @@ -260,6 +261,95 @@ main(int argc, char** argv) case 'I': PUSH2("@i", process_opt(&argc, &argv, 0)); break; + case 'M': + { + char *buf, *key, *val; + size_t buf_len; + + if (argv[1][2] == '\0') { /* -M */ + /* Push the following options: + * o 'makedep' + * o {makedep_output, standard_io} + */ + buf = strsave("makedep"); + PUSH2("@option", buf); + + key = "makedep_output"; + val = "standard_io"; + buf_len = 1 + strlen(key) + 1 + strlen(val) + 1 + 1; + buf = emalloc(buf_len); + snprintf(buf, buf_len, "{%s,%s}", key, val); + PUSH2("@option", buf); + } else if (argv[1][3] == '\0') { + switch(argv[1][2]) { + case 'D': /* -MD */ + /* Push the following options: + * o 'makedep' + */ + buf = strsave("makedep"); + PUSH2("@option", buf); + break; + case 'F': /* -MF */ + /* Push the following options: + * o 'makedep' + * o {makedep_output, } + */ + buf = strsave("makedep"); + PUSH2("@option", buf); + + key = "makedep_output"; + val = process_opt(&argc, &argv, 1); + buf_len = 1 + strlen(key) + 2 + strlen(val) + 2 + 1; + buf = emalloc(buf_len); + snprintf(buf, buf_len, "{%s,\"%s\"}", key, val); + PUSH2("@option", buf); + break; + case 'T': /* -MT */ + /* Push the following options: + * o {makedep_target, } + */ + key = "makedep_target"; + val = process_opt(&argc, &argv, 1); + buf_len = 1 + strlen(key) + 2 + strlen(val) + 2 + 1; + buf = emalloc(buf_len); + snprintf(buf, buf_len, "{%s,\"%s\"}", key, val); + PUSH2("@option", buf); + break; + case 'Q': /* -MQ */ + /* Push the following options: + * o {makedep_target, } + * o makedep_quote_target + */ + key = "makedep_target"; + val = process_opt(&argc, &argv, 1); + buf_len = 1 + strlen(key) + 2 + strlen(val) + 2 + 1; + buf = emalloc(buf_len); + snprintf(buf, buf_len, "{%s,\"%s\"}", key, val); + PUSH2("@option", buf); + + buf = strsave("makedep_quote_target"); + PUSH2("@option", buf); + break; + case 'G': /* -MG */ + /* Push the following options: + * o makedep_add_missing + */ + buf = strsave("makedep_add_missing"); + PUSH2("@option", buf); + break; + case 'P': /* -MP */ + /* Push the following options: + * o makedep_phony + */ + buf = strsave("makedep_add_missing"); + PUSH2("@option", buf); + break; + default: + goto error; + } + } + } + break; case 'o': PUSH2("@outdir", process_opt(&argc, &argv, 0)); break; @@ -561,6 +651,15 @@ usage(void) {"-hybrid", "compile using hybrid-heap emulator"}, {"-help", "shows this help text"}, {"-I path", "where to search for include files"}, + {"-M", "generate a rule for make(1) describing the dependencies"}, + {"-MF file", "write the dependencies to 'file'"}, + {"-MT target", "change the target of the rule emitted by dependency " + "generation"}, + {"-MQ target", "same as -MT but quote characters special to make(1)"}, + {"-MG", "consider missing headers as generated files and add them to " + "the dependencies"}, + {"-MP", "add a phony target for each dependency"}, + {"-MD", "same as -M -MT file (with default 'file')"}, {"-o name", "name output directory or file"}, {"-pa path", "add path to the front of Erlang's code path"}, {"-pz path", "add path to the end of Erlang's code path"}, -- cgit v1.2.3