summaryrefslogtreecommitdiff
path: root/src/cmd/gobuild/makefile.go
blob: 2c71917630437cfb55adcbb33dd99675fd519090 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright 2009 The Go Authors.  All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package gobuild

import (
	"fmt";
	"gobuild";
	"io";
	"path";
	"template";
)

var makefileTemplate =
	"# DO NOT EDIT.  Automatically generated by gobuild.\n"
	"{Args|args} >Makefile\n"
	"\n"
	"D={.section Dir}/{@}{.end}\n"
	"\n"
	"include $(GOROOT)/src/Make.$(GOARCH)\n"
	"AR=gopack\n"
	"\n"
	"default: packages\n"
	"\n"
	"clean:\n"
	"	rm -rf *.[$(OS)] *.a [$(OS)].out {ObjDir}\n"
	"\n"
	"test: packages\n"
	"	gotest\n"
	"\n"
	"coverage: packages\n"
	"	gotest\n"
	"	6cov -g `pwd` | grep -v '_test\\.go:'\n"
	"\n"
	"%.$O: %.go\n"
	"	$(GC) -I{ObjDir} $*.go\n"
	"\n"
	"%.$O: %.c\n"
	"	$(CC) $*.c\n"
	"\n"
	"%.$O: %.s\n"
	"	$(AS) $*.s\n"
	"\n"
	"{.repeated section Phases}\n"
	"O{Phase}=\\\n"
	"{.repeated section ArCmds}\n"
	"{.repeated section Files}\n"
	"	{Name|basename}.$O\\\n"
	"{.end}\n"
	"{.end}\n"
	"\n"
	"{.end}\n"
	"\n"
	"phases:{.repeated section Phases} a{Phase}{.end}\n"
	"{.repeated section Packages}\n"
	"{ObjDir}$D/{Name}.a: phases\n"
	"{.end}\n"
	"\n"
	"{.repeated section Phases}\n"
	"a{Phase}: $(O{Phase})\n"
	"{.repeated section ArCmds}\n"
	"	$(AR) grc {ObjDir}$D/{.section Pkg}{Name}.a{.end}{.repeated section Files} {Name|basename}.$O{.end}\n"
	"{.end}\n"
	"	rm -f $(O{Phase})\n"
	"\n"
	"{.end}\n"
	"\n"
	"newpkg: clean\n"
	"	mkdir -p {ObjDir}$D\n"
	"{.repeated section Packages}\n"
	"	$(AR) grc {ObjDir}$D/{Name}.a\n"
	"{.end}\n"
	"\n"
	"$(O1): newpkg\n"
	"{.repeated section Phases}\n"
	"$(O{Phase|+1}): a{Phase}\n"
	"{.end}\n"
	"\n"
	"nuke: clean\n"
	"	rm -f{.repeated section Packages} $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/{Name}.a{.end}\n"
	"\n"
	"packages:{.repeated section Packages} {ObjDir}$D/{Name}.a{.end}\n"
	"\n"
	"install: packages\n"
	"	test -d $(GOROOT)/pkg && mkdir -p $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D\n"
	"{.repeated section Packages}\n"
	"	cp {ObjDir}$D/{Name}.a $(GOROOT)/pkg/$(GOOS)_$(GOARCH)$D/{Name}.a\n"
	"{.end}\n"

func argsFmt(w io.Writer, x interface{}, format string) {
	args := x.([]string);
	fmt.Fprint(w, "#");
	for i, a := range args {
		fmt.Fprint(w, " ", ShellString(a));
	}
}

func basenameFmt(w io.Writer, x interface{}, format string) {
	t := fmt.Sprint(x);
	t = t[0:len(t)-len(path.Ext(t))];
	fmt.Fprint(w, MakeString(t));
}

func plus1Fmt(w io.Writer, x interface{}, format string) {
	fmt.Fprint(w, x.(int) + 1);
}

func makeFmt(w io.Writer, x interface{}, format string) {
	fmt.Fprint(w, MakeString(fmt.Sprint(x)));
}

var makefileMap = template.FormatterMap {
	"": makeFmt,
	"+1": plus1Fmt,
	"args": argsFmt,
	"basename": basenameFmt,
}