makefile

package module
v0.0.0-...-a9aa488 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 6 Imported by: 4

README

go-makefile GoDoc Build Status

A go package for generating Makefiles

Example

See example/self.go for an example. To try this first run go run self.go. This will generate self.mk. Now you can run make and the generated makefile will compile self.go and use it to re-generate the makefile.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Dep1 = RawText("$<")

Dep1 is the first dep of the current rule

View Source
var Target = RawText("$@")

Target is the target of the current rule

Functions

This section is empty.

Types

type Builder

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

Builder is a tool to build a Makefile in memory

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new Makefile Builder

func (*Builder) AddRaw

func (b *Builder) AddRaw(str string) *Builder

AddRaw adds a raw string to a Makefile this method does not handle newlines - please add a newline before the text

func (*Builder) AppendPhony

func (b *Builder) AppendPhony() *Builder

AppendPhony appends a .PHONY rule using all of the phony rules that have been appended previously

func (*Builder) AppendVar

func (b *Builder) AppendVar(mv MakeVar, val Text) *Builder

AppendVar appends a value to a variable

func (*Builder) BlankLine

func (b *Builder) BlankLine() *Builder

BlankLine adds a blank line to a Makefile

func (*Builder) Comment

func (b *Builder) Comment() *Comment

Comment returns a new Comment

func (*Builder) NewRule

func (b *Builder) NewRule(target Text) *Rule

NewRule creates a new Rule and adds it to the Makefile

func (*Builder) SectionBuilder

func (b *Builder) SectionBuilder() *Builder

SectionBuilder returns another Builder which will be substituted in

func (*Builder) SetVar

func (b *Builder) SetVar(mv MakeVar, val Text) *Builder

SetVar sets a variable to a single value

func (*Builder) SetVarSlice

func (b *Builder) SetVarSlice(mv MakeVar, vals []Text) *Builder

SetVarSlice sets a MakeVar to a slice of values

func (*Builder) WriteTo

func (b *Builder) WriteTo(w io.Writer) (int64, error)

WriteTo writes the Makefile to an io.Writer

type Command

type Command struct {
	Base    Text //base is the program to invoke (e.g. gcc)
	Args    []Text
	Env     map[ShellVar]Text
	NoPrint bool
}

Command is a command in a rule/shell substitution

func NewCmd

func NewCmd(base Text) *Command

NewCmd returns a command using base as the Base and args as arguments

func (*Command) AddArg

func (c *Command) AddArg(arg Text) *Command

AddArg adds an arg to a command

func (*Command) AddArgSlice

func (c *Command) AddArgSlice(args []Text) *Command

AddArgSlice adds a slice of arguments to a command

func (*Command) SetEnv

func (c *Command) SetEnv(v ShellVar, val Text) *Command

SetEnv sets an environment variable for the Command

func (*Command) SetNoPrint

func (c *Command) SetNoPrint() *Command

SetNoPrint sets the NoPrint to true on a command

func (*Command) String

func (c *Command) String() string

String returns the command as a string NOTE: may panic

func (*Command) Sub

func (c *Command) Sub() ShellSub

Sub returns a shell substitution (Text) which substitutes in this command

type Comment

type Comment []string

Comment is a comment in a Makefile

func (*Comment) Line

func (c *Comment) Line(ln string) *Comment

Line adds a line to the comment

type ErrEmpty

type ErrEmpty struct {
	SrcType string
}

ErrEmpty is an error returned when something is empty

func (ErrEmpty) Error

func (err ErrEmpty) Error() string

type ErrIllegalRune

type ErrIllegalRune struct {
	Rune      rune   //the illegal rune
	SrcString string //the string it was found in
	SrcType   string //the type of the source string (MakeVar, etc.)
	Context   string //the subtype of error (e.g. "initial")
}

ErrIllegalRune is an error type returned indicating that a rune is not allowed

func (ErrIllegalRune) Error

func (err ErrIllegalRune) Error() string

type ExtPattern

type ExtPattern string

ExtPattern is a simple Makefile pattern which matches an extension NOTE: no leading . TODO: error checking E.g. makefile.ExtPattern("go") -> %.go

func (ExtPattern) Convert

func (ep ExtPattern) Convert() string

Convert formats the ExtPattern as a Makefile pattern

type FilePath

type FilePath string

FilePath is a file path which can be used as Text

func (FilePath) CheckValid

func (fp FilePath) CheckValid() error

CheckValid does a validity check of a FilePath currently allows alphanumeric and "_ -.\/" runes

func (FilePath) Convert

func (fp FilePath) Convert() string

Convert converts a FilePath to a string suitable for a Makefile currently replaces ' ' -> '\ ' and '\' -> '\\'

type Join

type Join struct {
	Sep string
	Txt []Text
}

Join is a piece of text formed by joining other pieces of text

func (Join) Convert

func (j Join) Convert() string

Convert returns the joined text

type MakeVar

type MakeVar string

MakeVar is a type which can be used as a Makefile variable

func (MakeVar) CheckValid

func (mv MakeVar) CheckValid() error

CheckValid does a very strict validity check of a MakeVar

func (MakeVar) Sub

func (mv MakeVar) Sub() MakeVarSubstitution

Sub substitutes a MakeVar

type MakeVarSubstitution

type MakeVarSubstitution struct {
	Variable MakeVar
}

MakeVarSubstitution is a Text type which substitutes for a Makefile variable

func (MakeVarSubstitution) Convert

func (v MakeVarSubstitution) Convert() string

Convert returns the MakeVarSubstitution formatted as a Makefile variable substitution

type RawText

type RawText string

RawText is a Text type which converts to the unmodified string

func (RawText) Convert

func (raw RawText) Convert() string

Convert returns the unmodified string

type Rule

type Rule struct {
	Name    Text
	Deps    []Text
	Command []*Command
	Attr    RuleAttributes
}

Rule is a Makefile rule

func (*Rule) AddCmd

func (r *Rule) AddCmd(c *Command) *Rule

AddCmd adds an existing Command to a rule

func (*Rule) AddDep

func (r *Rule) AddDep(dep Text) *Rule

AddDep adds a dependency to the Rule

func (*Rule) NewCmd

func (r *Rule) NewCmd(base string) *Command

NewCmd creates a new Command and adds it to the rule

func (*Rule) OneShell

func (r *Rule) OneShell() *Rule

OneShell configures a Rule to be built with one shell

func (*Rule) Phony

func (r *Rule) Phony() *Rule

Phony configures a Rule to be phony

func (*Rule) Print

func (r *Rule) Print(txt Text) *Rule

Print prunts a piece of Text

func (*Rule) SetShell

func (r *Rule) SetShell(sh Text) *Rule

SetShell configures a Rule to use the specified shell

type RuleAttributes

type RuleAttributes struct {
	OneShell bool //goes in front of rule as .ONESHELL:
	Phony    bool
	Shell    Text //shell to use, goes in deps as SHELL:=path
}

RuleAttributes is a struct containing the attributes of a Rule

type ShellSub

type ShellSub struct {
	Cmd *Command
}

ShellSub substitutes the output of a command

func (ShellSub) Convert

func (ss ShellSub) Convert() string

Convert formats the ShellSub as a shell substitution

type ShellVar

type ShellVar string

ShellVar is a type which can be used as a shell variable in a Makefile

func (ShellVar) CheckValid

func (sv ShellVar) CheckValid() error

CheckValid does a validity check of a ShellVar based on http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap08.html allows lowercase because all modern systems should have lowercase

func (ShellVar) Sub

func (sv ShellVar) Sub() ShellVarSubstitution

Sub substitutes a ShellVar

type ShellVarSubstitution

type ShellVarSubstitution struct {
	Variable ShellVar
}

ShellVarSubstitution is a Text type which substitutes for a shell variable

func (ShellVarSubstitution) Convert

func (v ShellVarSubstitution) Convert() string

Convert returns the ShellVarSubstitution formatted as a shell variable substitution

type Text

type Text interface {
	Convert() string //return a string, panic to pass error
}

Text is an interface for a text value in a Makefile

func JoinText

func JoinText(sep string, txt ...Text) Text

JoinText returns a Join formed by joining the txt values by the sep seperator

Directories

Path Synopsis
This example uses a generated makefile to compile itself
This example uses a generated makefile to compile itself

Jump to

Keyboard shortcuts

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