mp
@kba/makefile-parser
npm i @kba/makefile-parser
mp

@kba/makefile-parser

Parser and documentation generator for Makefiles

by Konstantin Baierer

0.0.6 (see all)TypeScript:Not Found
npm i @kba/makefile-parser
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

  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.

Downloads/wk

290

GitHub Stars

17

LAST COMMIT

1yr ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

3

OPEN PRs

5
VersionTagPublished
0.0.6
latest
1yr ago
No alternatives found
No tutorials found
Add a tutorial
No dependencies found

Rate & Review

100
No reviews found
Be the first to rate