Parse a Makefile into an abstract syntax tree
npm install parse-parser
const parseMakefile = require('parse-makefile');
const { ast } = parseMakefile(
`# Comment on VAR.
VAR = 23
# Comment on foo
foo: fizz\\ buzz bar
step 1 $@
step 2 $<`);
console.log(ast)
Output:
[ { variable: 'VAR', value: '23', comment: [ 'Comment on VAR.' ] },
{ target: 'foo',
deps: [ 'fizz\\ buzz', 'bar' ],
recipe: [ 'step 1 $@', 'step 2 $<' ],
comment: [ 'Comment on foo' ] } ]