make

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2025 License: MIT Imports: 9 Imported by: 0

README

Go Make

Makefile parsing and utilities in Go

Usage

Reading

The make.Parser is the primary way to read Makefiles.

f := os.Open("Makefile")
p := make.NewParser(f, nil)

m, err := p.ParseFile()

fmt.Println(m.Rules)

The more primitive make.Scanner and make.ScanTokens used by make.Parser can be used individually.

Using make.ScanTokens with a bufio.Scanner

f := os.Open("Makefile")
s := bufio.NewScanner(f)
s.Split(make.ScanTokens)

for s.Scan() {
  s.Bytes() // The current token byte slice i.e. []byte(":=")
  s.Text() // The current token as a string i.e. ":="
}

Using make.Scanner

f := os.Open("Makefile")
s := make.NewScanner(f, nil)

for pos, tok, lit := s.Scan(); tok != token.EOF {
  fmt.Println(pos) // The position of tok
  fmt.Println(tok) // The current token.Token i.e. token.SIMPLE_ASSIGN
  fmt.Println(lit) // Literal tokens as a string i.e. "identifier"
}

if err := s.Err(); err != nil {
  fmt.Println(err)
}

Documentation

Index

Constants

View Source
const (
	DefineDirective      = "define"
	EndefDirective       = "endef"
	UndefineDirective    = "undefine"
	IfdefDirective       = "ifdef"
	IfndefDirective      = "ifndef"
	IfeqDirective        = "ifeq"
	IfneqDirective       = "ifneq"
	ElseDirective        = "else"
	EndifDirective       = "endif"
	IncludeDirective     = "include"
	DashIncludeDirective = "-include"
	SincludeDirective    = "sinclude"
	OverrideDirective    = "override"
	ExportDirective      = "export"
	UnexportDirective    = "unexport"
	PrivateDirective     = "private"
	VpathDirective       = "vpath"
)
View Source
const (
	SubstFunction      = "subst"
	PatsubstFunction   = "patsubst"
	StripFunction      = "strip"
	FindstringFunction = "findstring"
	FilterFunction     = "filter"
	FilterOutFunction  = "filter-out"
	SortFunction       = "sort"
	WordFunction       = "word"
	WordsFunction      = "words"
	WordlistFunction   = "wordlist"
	FirstwordFunction  = "firstword"
	LastwordFunction   = "lastword"
	DirFunction        = "dir"
	NotdirFunction     = "notdir"
	SuffixFunction     = "suffix"
	BasenameFunction   = "basename"
	AddsuffixFunction  = "addsuffix"
	AddprefixFunction  = "addprefix"
	JoinFunction       = "join"
	WildcardFunction   = "wildcard"
	RealpathFunction   = "realpath"
	AbspathFunction    = "abspath"
	ErrorFunction      = "error"
	WarningFunction    = "warning"
	ShellFunction      = "shell"
	OriginFunction     = "origin"
	FlavorFunction     = "flavor"
	LetFunction        = "let"
	ForeachFunction    = "foreach"
	IfFunction         = "if"
	OrFunction         = "or"
	AndFunction        = "and"
	IntcmpFunction     = "intcmp"
	CallFunction       = "call"
	EvalFunction       = "eval"
	FileFunction       = "file"
	ValueFunction      = "value"
)
View Source
const (
	MakefilesVariable    = "MAKEFILES"
	VpathVariable        = "VPATH"
	ShellVariable        = "SHELL"
	MakeshellVariable    = "MAKESHELL"
	MakeVariable         = "MAKE"
	MakeVersionVariable  = "MAKE_VERSION"
	MakeHostVariable     = "MAKE_HOST"
	MakelevelVariable    = "MAKELEVEL"
	MakeflagsVariable    = "MAKEFLAGS"
	GnumakeflagsVariable = "GNUMAKEFLAGS"
	MakecmdgoalsVariable = "MAKECMDGOALS"
	CurdirVariable       = "CURDIR"
	SuffixesVariable     = "SUFFIXES"
	LibpatternsVariable  = ".LIBPATTERNS"
)
View Source
const (
	PhonyTarget              = ".PHONY"
	SuffixesTarget           = ".SUFFIXES"
	DefaultTarget            = ".DEFAULT"
	PreciousTarget           = ".PRECIOUS"
	IntermediateTarget       = ".INTERMEDIATE"
	NotintermediateTarget    = ".NOTINTERMEDIATE"
	SecondaryTarget          = ".SECONDARY"
	SecondexpansionTarget    = ".SECONDEXPANSION"
	DeleteOnErrorTarget      = ".DELETE_ON_ERROR"
	IgnoreTarget             = ".IGNORE"
	LowResolutionTimeTarget  = ".LOW_RESOLUTION_TIME"
	SilentTarget             = ".SILENT"
	ExportAllVariablesTarget = ".EXPORT_ALL_VARIABLES"
	NotparallelTarget        = ".NOTPARALLEL"
	OneshellTarget           = ".ONESHELL"
	PosixTarget              = ".POSIX"
)

Variables

Functions

func ScanTokens

func ScanTokens(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanTokens is a bufio.SplitFunc for a bufio.Scanner that scans for tokens supported by the make syntax.

Types

type Makefile

type Makefile struct {
	Rules []Rule
}

type Parser added in v0.2.0

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser added in v0.2.0

func NewParser(r io.Reader, file *token.File) *Parser

func (*Parser) ParseFile added in v0.2.0

func (p *Parser) ParseFile() (*ast.File, error)

type PreReq

type PreReq string

type Recipe

type Recipe string

type Rule

type Rule struct {
	Target  []string
	PreReqs []string
	Recipe  []string
}

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(r io.Reader, file *token.File) *Scanner

func (Scanner) Err

func (s Scanner) Err() error

func (Scanner) Position added in v0.2.0

func (s Scanner) Position(pos token.Pos) token.Position

func (*Scanner) Scan

func (s *Scanner) Scan() (pos token.Pos, tok token.Token, lit string)

type Target

type Target string

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func NewWriter

func NewWriter(w io.Writer) *Writer

func (*Writer) WriteLine

func (w *Writer) WriteLine() (n int, err error)

func (*Writer) WriteMakefile

func (w *Writer) WriteMakefile(m Makefile) (n int, err error)

func (*Writer) WritePreReq

func (w *Writer) WritePreReq(p string) (n int, err error)

func (*Writer) WritePreReqs

func (w *Writer) WritePreReqs(ps []string) (n int, err error)

func (*Writer) WriteRecipe

func (w *Writer) WriteRecipe(r string) (n int, err error)

func (*Writer) WriteRecipes

func (w *Writer) WriteRecipes(rs []string) (n int, err error)

func (*Writer) WriteRule

func (w *Writer) WriteRule(r Rule) (n int, err error)

func (*Writer) WriteTarget

func (w *Writer) WriteTarget(t string) (n int, err error)

func (*Writer) WriteTargets

func (w *Writer) WriteTargets(ts []string) (n int, err error)

Directories

Path Synopsis
internal
Package token defines constants representing the lexical tokens of a Makefile.
Package token defines constants representing the lexical tokens of a Makefile.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL