Created
March 21, 2014 02:19
-
-
Save AdamMagaluk/9678229 to your computer and use it in GitHub Desktop.
Sample Dependancy Runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var path = require('path'); | |
var cfiles = ['file_a.c','file_b.c']; | |
task() | |
.env({gcc : '/usr/bin/gcc',cflags : '-Wall '}) | |
.add('somelib.a',cfiles,compileLib) | |
.each(cfiles,compileFile) | |
.done(function(err){ | |
}) | |
function toO(f){ | |
return path.basename(f,path.extname(f)) + '.o'; | |
} | |
function exec(cmd,callback){ | |
// execute cmd string on OS when done run callback; | |
} | |
function compileLib(next){ | |
// this.deps => ['file_a.c','file_b.c'] | |
// this.name = 'somelib.a' | |
// this.env = {gcc : '/usr/bin/gcc',cflags : '-Wall '} | |
var cmd = [this.env.gcc,this.env.cflags,'-o',this.name].concat(this.deps.map(toO).join(' ')).join(' '); | |
// cmd => /usr/bin/gcc -Wall -o somelib.a file_a.o file_b.o | |
exec(cmd,next); | |
} | |
function compileFile(next){ | |
// this.deps => []; | |
// this.name = 'file_a.c' | |
var cmd = [this.env.gcc,this.env.cflags,'-o', toO(this.name),this.name ]; | |
// cmd => /usr/bin/gcc -Wall -o file_a.o this.name | |
exec(cmd,next); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment