-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.go
89 lines (78 loc) · 2.02 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"os"
"github.com/DQNEO/babygo/internal/builder"
"github.com/DQNEO/babygo/lib/fmt"
"github.com/DQNEO/babygo/lib/mylib"
"github.com/DQNEO/babygo/lib/strconv"
)
const Version string = "0.4.1"
func showHelp() {
fmt.Printf("Usage:\n")
fmt.Printf(" version: show version\n")
fmt.Printf(" build -o <outfile> <pkgpath> e.g. build -o hello ./example/hello\n")
fmt.Printf(" compile -o <tmpbasename> <pkgpath> e.g. compile -o /tmp/os os\n")
fmt.Printf(" list -deps <pkgpath> e.g. list -deps ./t\n")
fmt.Printf(" link -o <outfile> <objfiles...>\n")
}
func showVersion() {
fmt.Printf("babygo version %s linux/amd64\n", Version)
}
func main() {
if len(os.Args) == 1 {
showHelp()
return
}
switch os.Args[1] {
case "version":
showVersion()
return
case "help":
showHelp()
return
case "panic": // What's this for ?? I can't remember ...
panicVersion := strconv.Itoa(mylib.Sum(1, 1))
panic("I am panic version " + panicVersion)
}
gopath := os.Getenv("GOPATH")
if gopath == "" {
panic("GOPATH is not set")
}
workdir := os.Getenv("WORKDIR")
if workdir == "" {
workdir = "/tmp/bbg-work/"
}
srcPath := gopath + "/src" // userland packages
bbgRootSrcPath := srcPath + "/github.com/DQNEO/babygo/src" // std packages
b := builder.Builder{
SrcPath: srcPath,
BbgRootSrcPath: bbgRootSrcPath,
}
switch os.Args[1] {
case "build":
args := os.Args[2:] // skip PROGRAM build
var verbose bool
if args[0] == "-x" {
verbose = true
args = args[1:]
}
outFilePath := args[1]
pkgPath := args[2]
b.Build(os.Args[0], workdir, outFilePath, pkgPath, verbose)
case "compile":
var verbose bool = true
outputBaseName := os.Args[3]
pkgPath := os.Args[4]
b.BuildOne(workdir, outputBaseName, pkgPath, verbose)
case "list":
pkgPath := os.Args[3]
b.ListDepth(workdir, pkgPath, os.Stdout)
case "link":
outFilePath := os.Args[3]
objFileNames := os.Args[4:]
b.Link(outFilePath, objFileNames, true)
default:
showHelp()
return
}
}