forked from gnormal/gnorm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmage.go
73 lines (62 loc) · 1.9 KB
/
mage.go
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
//+build mage
// This is the "magefile" for gnorm. To install mage, run go get github.com/magefile/mage.
// To build gnorm, just mage build.
package main
import (
"log"
"github.com/magefile/mage/mg"
)
// Runs go install for gnorm. This generates the embedded docs and the version
// info into the binary.
func Build() error {
mg.Deps(installHugo, installStatik)
if err := genSite(); err != nil {
return err
}
defer cleanup()
ldf, err := flags()
if err != nil {
return err
}
log.Print("running go install")
// use -tags make so we can have different behavior for when we know we've built with mage.
return run("go", "install", "-tags", "make", "--ldflags="+ldf, "gnorm.org/gnorm")
}
// Generates binaries for all supported versions. Currently that means a
// combination of windows, linux, and OSX in 32 bit and 64 bit formats. The
// files will be dumped in the local directory with names according to their
// supported platform.
func All() error {
mg.Deps(installHugo, installStatik)
if err := genSite(); err != nil {
return err
}
defer cleanup()
ldf, err := flags()
if err != nil {
return err
}
for _, OS := range []string{"windows", "darwin", "linux"} {
for _, ARCH := range []string{"amd64", "386"} {
log.Printf("running go build for GOOS=%s GOARCH=%s", OS, ARCH)
env := []string{"GOOS=" + OS, "GOARCH=" + ARCH}
if err := runWith(env, "go", "build", "-tags", "make", "-o", "gnorm_"+OS+"_"+ARCH, "--ldflags="+ldf); err != nil {
return err
}
}
}
return err
}
func installHugo() error {
log.Print("downloading hugo")
return run("go", "get", "github.com/gohugoio/hugo")
}
func installStatik() error {
log.Print("downloading statik")
return run("go", "get", "github.com/rakyll/statik")
}
// Removes generated cruft. This target shouldn't ever be necessary, since the
// cleanup should happen automatically, but it's here just in case.
func Clean() error {
return cleanup()
}