-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathConfig.zu
203 lines (174 loc) · 6.48 KB
/
Config.zu
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# The Zimbu compiler written in Zimbu
#
# Config class.
#
# Copyright 2009 Bram Moolenaar All Rights Reserved.
# Licensed under the Apache License, Version 2.0. See the LICENSE file or
# obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0
#
#
# Figures out properties of the compiler and libraries.
# What is defined here may change when the C compiler command arguments
# change. What will not change is handled by zimbuConfig.zu.
#
# TODO: Move some checks to zimbuConfig.zu ?
#
IMPORT.PROTO "zimbuConfig.proto" # Defines the Zimbu.Config class.
MODULE Config @items=public # TODO: restrict visibility
string int64name # C type name for 64 bit int
string int32name # C type name for 32 bit int
string int16name # C type name for 32 bit int
string nat64name # C type name for 64 bit unsigned
string nat32name # C type name for 32 bit unsigned
string nat16name # C type name for 16 bit unsigned
string floatName # C type name for 64 bit float
string float32name # C type name for 32 bit float
string intPtrName # C type name for int that can hold a pointer
string printIntFormat
string printNatFormat
string scanfHexFormat
int intSize # C sizeof(int)
bool isMingw # using MingW compiler. Note: consider OR'ing with the
# portable flag.
list<string> %libArgs = NEW() # extra compiler arguments
string exeSuffix # suffix used for an executable
string exePrefix # prefix used for an executable without an
# absolute path on Unix: "./"
string mallocArg # extra compiler argument for tcmalloc
string threadArg # extra compiler argument for threads
string socketArg # extra compiler argument for sockets
string mathArg # extra compiler argument for floating point
string libPath # path to "lib" directory
string pluginPath # path to the "plugin" directory
string zudirName = "ZUDIR"
bool haveResolve # whether IO.resolve() is available
bool haveFork # whether fork() is available
bool haveSigaction # whether sigaction() is available
bool gcWithThreads # whether GC can be used with multi-threading
ARG.Bool quick = NEW("q", "quick", FALSE,
"Quick execution, disable backtrace")
bool noBacktrace = quick.get()
# don't generate code for stack backtrace
ARG.String compiler = NEW(NIL, "cc", "cc", "C compiler to use")
.setArgName("compiler")
ARG.String ccarg = NEW(NIL, "ccarg", "-g",
"C compiler arguments (before other arguments)")
ARG.String ccendarg = NEW(NIL, "ccendarg", "",
"C compiler arguments (after other arguments)")
ARG.Bool portableFlag = NEW(NIL, "portable", FALSE,
"Produce portable C code, not using threads")
bool portable = portableFlag.get()
# The configuration read from the zimbuConfig.out file.
Zimbu.Config zimbuConfig @public
FUNC run() status
>>>
%intSize% = sizeof(int);
<<<
# Set the libPath relative to the compiler executable.
# "zimbu" -> root == ""
# "./zimbu" -> root == ""
# "/usr/bin/zimbu/zimbu" -> root == "/usr/bin/zimbu/"
int tail = IO.tailIndex(ARG.exeName)
string root
IF tail <= 0
root = ""
ELSE
root = ARG.exeName.slice(0, tail - 1)
# Normalize the directory name (upper/lower case, backslashes).
root = IO.fullPath(root)
# Make sure it ends in a slash.
IF !root.endsWith("/") && !root.endsWith("\\")
root = root .. "/"
}
}
IF root.startsWith("./")
root = root.slice(2)
ELSE
# Remove the path if it equals the current directory. This is for when
# building Zimu itself. Make sure the path separator is excluded.
string curdir = IO.fullPath(IO.getdir())
IF root.startsWith(curdir)
IF root[curdir.Size()] == '/'
root = root.slice(curdir.Size() + 1)
ELSE
root = root.slice(curdir.Size())
}
}
}
libPath = root .. "lib"
pluginPath = root .. "plugin"
string configName = ARG.getExeDir() .. "/zimbuConfig.out"
IO.File reader = IO.fileReader(configName)
IF reader == NIL
IO.print("Cannot open " .. configName)
EXIT 5
}
zimbuConfig = Zimbu.Config.createFromText(reader)
reader.close()
mallocArg = zimbuConfig.getMallocArg()
threadArg = zimbuConfig.getThreadArg()
socketArg = zimbuConfig.getSocketArg()
mathArg = zimbuConfig.getMathArg()
haveResolve = zimbuConfig.getHaveResolve()
haveFork = zimbuConfig.getHaveFork()
haveSigaction = zimbuConfig.getHaveSigaction()
gcWithThreads = zimbuConfig.getGcWithThreads()
exeSuffix = ""
exePrefix = zimbuConfig.getExePrefix()
int64name = zimbuConfig.getInt64Name()
int32name = zimbuConfig.getInt32Name()
int16name = zimbuConfig.getInt16Name()
nat64name = zimbuConfig.getNat64Name()
nat32name = zimbuConfig.getNat32Name()
nat16name = zimbuConfig.getNat16Name()
floatName = zimbuConfig.getFloatName()
float32name = zimbuConfig.getFloat32Name()
intPtrName = zimbuConfig.getIntPtrName()
printIntFormat = zimbuConfig.getPrintIntFormat()
printNatFormat = zimbuConfig.getPrintNatFormat()
scanfHexFormat = zimbuConfig.getScanfHexFormat()
isMingw = zimbuConfig.getIsMingw()
# Invoke the listeners.
FOR l IN listeners
l()
}
listeners = NIL # free the memory
RETURN OK
}
list<proc<>> listeners = NEW()
# Add |listener| to be called after the config was read.
PROC addListener(proc<> listener)
listeners.add(listener)
}
# call when using threads
PROC addThreadLib()
%libArgs.add(threadArg)
}
# call when using sockets
PROC addSocketLib()
IF socketArg != NIL
%libArgs.add(socketArg)
}
}
# call when using floating point operations
PROC addMathLib()
IF mathArg != NIL
%libArgs.add(mathArg)
}
}
FUNC compilerCmd(string srcName, string binName) string
string cmd = compiler.value() .. " " .. ccarg.value()
.. " -o \"" .. binName .. "\" "
.. "\"" .. srcName .. "\" "
.. ccendarg.value()
RETURN cmd
}
FUNC extraCompilerArgs() string
string ret = ""
FOR lib IN %libArgs
ret ..= " " .. lib
}
RETURN ret
}
}