mde/jake — pull request #180 by xiejw (2013-03-30 23:11:30+00:00)
Title: New Feature of Implicit/Suffix Rules

Hi, thanks for merging my yesterday's pull request so quick.

Here, I would like to add a new feature: Implicit/Suffix Rules. It should be very useful.

Consider the following example. The final output file `main` depends on `main.o` and `util.o`, which are generated by the corresponding source files `main.c` and `util.c`. In this situation, it is convenient to provide a _Rule_, which helps us generate the `.o` obj from the source `.c` for each case automatically, especially when `main` depends on several `.o` files which can be generated by the same way.

As you can review the File Changes, I did minimum modifications to your original code. The current strategy is following (in descending priority):

1. If the task for the specific file exists, use this task.
2. If not, check _Rule_ first. If there is a _Rule_ to generate this file, use it.
3. If no corresponding _rule_, check whether it is a static file.
4. If all fail, throw error.

The _Rule_ task
* supports prerequisites (optional),
* tests the timestamps of the obj and src files (using the FileTask),
* and supports chain rule, i.e, the src of the obj may still need to be generated by another rule.

Meanwhile, I also add description to each rule. If you are interested, you may output the them via `Jake -T`.

The Jakefile I tested is given here:

util = require('util');

desc('Default');
task('default', ['main'], function (params) {} );

desc('Compile the file.');
file('main', ['main.o', 'util.o'], function (params) {
params = params || '';
jake.exec(['gcc -o main *.o' + params], function () {
complete();
}, {printStdout: true});
}, { async : true });

desc('Compile the the source file to .o.');
rule('.o', '.c', ['util.h'], function(obj, src) {
var cmd = util.format('gcc -o %s -c %s', obj, src);
console.log(cmd);
jake.exec([cmd], function () {
complete();
}, {printStdout: true});
}, { async : true });