@kba/makefile-parser

0.0.6 • Public • Published

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

  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.

/@kba/makefile-parser/

    Package Sidebar

    Install

    npm i @kba/makefile-parser

    Weekly Downloads

    308

    Version

    0.0.6

    License

    0.0.1

    Unpacked Size

    9.64 kB

    Total Files

    8

    Last publish

    Collaborators

    • kba