@kba/makefile-parser
v0.0.6
Published
Parse makefiles
Downloads
250
Readme
makefile-parser
Parse a Makefile into an abstract syntax tree
Installation
npm install -g @kba/makefile-parser
API
const parseMakefile = require('./makefile-parser')
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' ] } ]
CLI
Options:
--help Show help [boolean]
--version Show version number [boolean]
--dump Dump AST
--make-help Generate "make help" [count]
--indent [default: " "]
Without options, build a plain-text help
make help
- Install shinclude.
- Add the following before the first target of your
Makefile
:
# BEGIN-EVAL makefile-parser --make-help Makefile
# END-EVAL
- Document all variables and targets useful to be shown help for with a single line comment directly above the declaration:
# Spell to use. Default $(SPELL)
SPELL = xyzzy
# BEGIN-EVAL makefile-parser --make-help Makefile
# END-EVAL
# Casts the spell
cast:
do stuff
- Whenever you change the makefile, run
shinclude -c pound -i Makefile
which will result in
# Spell to use. Default $(SPELL)
SPELL = xyzzy
# BEGIN-EVAL makefile-parser --make-help Makefile
help:
@echo ""
@echo " Targets"
@echo ""
@echo " cast Casts the spell"
@echo ""
@echo " Variables"
@echo ""
@echo " SPELL Spell to use. Default $(SPELL)"
# END-EVAL
# Casts the spell
cast:
do stuff
- Users of the makefile can then run
make help
or just
make
to get basic information on the targets and variables of the Makefile.