-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
142 lines (127 loc) · 3.97 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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2013 The GoGL2 Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.mkd file.
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
func generateGoPackages(specsDir string, f []Feature, d *Documentation) {
ps, err := ParseSpecFile(filepath.Join(specsDir, openGLSpecFile), f)
if err != nil {
fmt.Println("Error while parsing OpenGL specification:", err)
}
err = ps.GeneratePackages(d)
if err != nil {
fmt.Println("Error while generating OpenGL packages:", err)
}
/*ps, err = ParseSpecFile(filepath.Join(specsDir, wglSpecFile))
if err != nil {
fmt.Println("Error while parsing WGL specification:", err)
}
err = ps.GeneratePackages(d)
if err != nil {
fmt.Println("Error while generating WGL packages:", err)
}
ps, err = ParseSpecFile(filepath.Join(specsDir, glxSpecFile))
if err != nil {
fmt.Println("Error while parsing GLX specification:", err)
}
err = ps.GeneratePackages(d)
if err != nil {
fmt.Println("Error while generating GLX packages:", err)
}
ps, err = ParseSpecFile(filepath.Join(specsDir, eglSpecFile))
if err != nil {
fmt.Println("Error while parsing EGL specification:", err)
}
err = ps.GeneratePackages(d)
if err != nil {
fmt.Println("Error while generating EGL packages:", err)
}*/
}
func downloadSpec(name string, args []string) {
fs := flag.NewFlagSet(name, flag.ExitOnError)
src := fs.String("src", "khronos", "Source URL or 'khronos'.")
odir := fs.String("odir", "glspecs", "Output directory for spec files.")
fs.Parse(args)
fmt.Println("Downloading specs ...")
if *src == "khronos" {
*src = khronosRegistryBaseURL
}
err := downloadAllSpecs(*src, *odir)
if err != nil {
fmt.Println("Error while downloading docs:", err)
}
}
func downloadDoc(name string, args []string) {
fs := flag.NewFlagSet(name, flag.ExitOnError)
src := fs.String("src", "khronos", "Source URL or 'khronos'.")
odir := fs.String("odir", "gldocs", "Output directory for doc files.")
ver := fs.Int("ver", -1, "Doc version: 2, 3, 4")
fs.Parse(args)
if *ver < 2 || *ver > 4 {
fmt.Println("Invalid doc version:", *ver)
return
}
fmt.Println("Downloading docs ...")
if *src == "khronos" {
*src = khronosDocBaseURL
}
err := DownloadDocs(*src, fmt.Sprintf("man%d", *ver), *odir)
if err != nil {
fmt.Println("Error while downloading docs:", err)
}
}
func generatePackages(name string, args []string) {
fs := flag.NewFlagSet(name, flag.ExitOnError)
sdir := fs.String("sdir", "glspecs", "OpenGL spec directory.")
ddir := fs.String("ddir", "gldocs", "Documentation directory (currently not used).")
feat := fs.String("f", "", "Spec features and version seperated by '|'. e.g. : -f=gl:2.1|gles1:1.0")
fs.Parse(args)
df, err := ParseAllDocs(*ddir)
if err != nil {
fmt.Println("Error while parsing docs:", err)
return
}
f, err := ParseFeatureList(*feat)
if err != nil {
fmt.Println("Error while parsing feature arguments:", err)
return
}
fmt.Println("Generate Bindings ...")
generateGoPackages(*sdir, f, df)
}
func printUsage(name string) {
fmt.Printf("Usage: %s command [arguments]\n", name)
fmt.Println("Commands:")
fmt.Println(" pullspec Download spec files.")
fmt.Println(" pulldoc Download documentation files.")
fmt.Println(" generate Generate bindings.")
fmt.Printf("Type %s <command> -help for a detailed command description.\n", name)
}
func main() {
fmt.Println("GoGL2 - OpenGL binding generator for the Go programming language (http://golang.org).")
fmt.Println("Copyright (c) 2013 by Christoph Schunk. All rights reserved. See LICENSE.mkd for more information.")
name := os.Args[0]
args := os.Args[1:]
if len(args) < 1 {
printUsage(name)
os.Exit(-1)
}
command := args[0]
switch command {
case "pullspec":
downloadSpec("pullspec", args[1:])
case "pulldoc":
downloadDoc("pulldoc", args[1:])
case "generate":
generatePackages("generate", args[1:])
default:
fmt.Printf("Unknown command: '%s'\n", command)
printUsage(name)
os.Exit(-1)
}
}