npm.io
0.0.6 • Published 5 years agoCLI

@kba/makefile-parser

Licence
0.0.1
Version
0.0.6
Deps
1
Size
9 kB
Vulns
0
Weekly
0
Stars
23

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 __CODE_BLOCK_1__lt;`)
console.log(ast)

Output:

[ { variable: 'VAR', value: '23', comment: [ 'Comment on VAR.' ] },
  { target: 'foo',
    deps: [ 'fizz\\ buzz', 'bar' ],
    recipe: [ 'step 1 $@', 'step 2 __CODE_BLOCK_2__lt;' ],
    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

  1. Install shinclude.
  2. Add the following before the first target of your Makefile:
# BEGIN-EVAL makefile-parser --make-help Makefile
# END-EVAL
  1. 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
  1. 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
  1. Users of the makefile can then run
make help

or just

make

to get basic information on the targets and variables of the Makefile.