-
Notifications
You must be signed in to change notification settings - Fork 47
/
option.go
163 lines (149 loc) · 3.64 KB
/
option.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main
import (
"runtime"
"strconv"
"github.com/cubicdaiya/nginx-build/builder"
)
type Options struct {
Values map[string]OptionValue
Bools map[string]OptionBool
Numbers map[string]OptionNumber
}
type OptionValue struct {
Desc string
Value *string
Default string
}
type OptionBool struct {
Desc string
Enabled *bool
// all options are false by default
//Default bool
}
type OptionNumber struct {
Desc string
Value *int
Default int
}
func makeNginxBuildOptions() Options {
var nginxBuildOptions Options
argsNumber := make(map[string]OptionNumber)
argsBool := make(map[string]OptionBool)
argsString := make(map[string]OptionValue)
argsNumber["j"] = OptionNumber{
Desc: "jobs to build nginx",
Default: runtime.NumCPU(),
}
argsBool["verbose"] = OptionBool{
Desc: "verbose mode",
}
argsBool["pcre"] = OptionBool{
Desc: "embedded PCRE staticlibrary",
}
argsBool["openssl"] = OptionBool{
Desc: "embedded OpenSSL staticlibrary",
}
argsBool["libressl"] = OptionBool{
Desc: "embedded LibreSSL staticlibrary",
}
argsBool["zlib"] = OptionBool{
Desc: "embedded zlib staticlibrary",
}
argsBool["clear"] = OptionBool{
Desc: "remove entries in working directory",
}
argsBool["version"] = OptionBool{
Desc: "print nginx-build version",
}
argsBool["versions"] = OptionBool{
Desc: "print nginx versions",
}
argsBool["openresty"] = OptionBool{
Desc: "download openresty instead of nginx",
}
argsBool["freenginx"] = OptionBool{
Desc: "download freenginx instead of nginx",
}
argsBool["configureonly"] = OptionBool{
Desc: "configure nginx only not building",
}
argsBool["idempotent"] = OptionBool{
Desc: "build nginx if already installed nginx version is different",
}
argsBool["help-all"] = OptionBool{
Desc: "print all flags",
}
argsString["v"] = OptionValue{
Desc: "nginx version",
Default: builder.NginxVersion,
}
argsString["c"] = OptionValue{
Desc: "configuration file for building nginx",
Default: "",
}
argsString["m"] = OptionValue{
Desc: "configuration file for 3rd party modules",
Default: "",
}
argsString["d"] = OptionValue{
Desc: "working directory",
Default: "",
}
argsString["pcreversion"] = OptionValue{
Desc: "PCRE version",
Default: builder.PcreVersion,
}
argsString["opensslversion"] = OptionValue{
Desc: "OpenSSL version",
Default: builder.OpenSSLVersion,
}
argsString["libresslversion"] = OptionValue{
Desc: "LibreSSL version",
Default: builder.LibreSSLVersion,
}
argsString["zlibversion"] = OptionValue{
Desc: "zlib version",
Default: builder.ZlibVersion,
}
argsString["openrestyversion"] = OptionValue{
Desc: "openresty version",
Default: builder.OpenRestyVersion,
}
argsString["freenginxversion"] = OptionValue{
Desc: "freenginx version",
Default: builder.FreenginxVersion,
}
argsString["patch"] = OptionValue{
Desc: "patch path for applying to nginx",
Default: "",
}
argsString["patch-opt"] = OptionValue{
Desc: "option for patch",
Default: "",
}
nginxBuildOptions.Bools = argsBool
nginxBuildOptions.Values = argsString
nginxBuildOptions.Numbers = argsNumber
return nginxBuildOptions
}
func isNginxBuildOption(k string) bool {
if _, ok := nginxBuildOptions.Bools[k]; ok {
return true
}
if _, ok := nginxBuildOptions.Values[k]; ok {
return true
}
if _, ok := nginxBuildOptions.Numbers[k]; ok {
return true
}
return false
}
func defaultStringValue(k string) string {
if _, ok := nginxBuildOptions.Values[k]; ok {
return nginxBuildOptions.Values[k].Default
}
if _, ok := nginxBuildOptions.Numbers[k]; ok {
return strconv.Itoa(nginxBuildOptions.Numbers[k].Default)
}
return ""
}