# @kba/makefile-parser

> Parse makefiles

Latest version **0.0.6** (published 2021-07-01) · 0.0.1 license · 0 weekly downloads

## Install

```sh
npm install @kba/makefile-parser
pnpm add @kba/makefile-parser
yarn add @kba/makefile-parser
bun add @kba/makefile-parser
```

Provides the command `makefile-parser`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2021-07-01 |
| First published | 2017-10-07 |
| Weekly downloads | 0 |
| License | 0.0.1 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | kba |
| Maintainers | kba |

## Links

- npm: https://www.npmjs.com/package/@kba/makefile-parser
- Repository: https://github.com/kba/makefile-parser
- Homepage: https://github.com/kba/makefile-parser#readme
- Issues: https://github.com/kba/makefile-parser/issues
- npm.io page: https://npm.io/package/@kba/makefile-parser

## Dependencies (1)

- [yargs](https://npm.io/package/yargs.md) ^17.0.1

## Recent versions

- 0.0.6 (latest) — 2021-07-01
- 0.0.5 — 2021-06-25
- 0.0.3 — 2017-10-07
- 0.0.2 — 2017-10-07
- 0.0.1 — 2017-10-07

## README

# makefile-parser

> Parse a Makefile into an abstract syntax tree

<!-- BEGIN-MARKDOWN-TOC -->
* [Installation](#installation)
* [API](#api)
* [CLI](#cli)
* [`make help`](#make-help)

<!-- END-MARKDOWN-TOC -->

## Installation

```sh
npm install -g @kba/makefile-parser
```

## API

```js
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:

```js
[ { variable: 'VAR', value: '23', comment: [ 'Comment on VAR.' ] },
  { target: 'foo',
    deps: [ 'fizz\\ buzz', 'bar' ],
    recipe: [ 'step 1 $@', 'step 2 $<' ],
    comment: [ 'Comment on foo' ] } ]
```

## CLI

```sh
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](https://github.com/kba/shinclude).
2. Add the following before the first target of your `Makefile`:

```make
# BEGIN-EVAL makefile-parser --make-help Makefile
# END-EVAL
```

3. Document all variables and targets useful to be shown help for with a single line comment directly above the declaration:

```make
# Spell to use. Default $(SPELL)
SPELL = xyzzy

# BEGIN-EVAL makefile-parser --make-help Makefile
# END-EVAL

# Casts the spell
cast:
	do stuff
```

4. Whenever you change the makefile, run

```
shinclude -c pound -i Makefile
```

which will result in

```make
# 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
```

5. Users of the makefile can then run

```sh
make help
```

or just

```sh
make
```

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

---
_Source: https://npm.io/package/@kba/makefile-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
