-
Notifications
You must be signed in to change notification settings - Fork 5
/
Configure.om
276 lines (231 loc) · 8.46 KB
/
Configure.om
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
# It is recommended that these function be used from an appropriate static. block
open build/Common
ConfMsgChecking(msg) =
print($"--- Checking $(msg)... ")
ConfMsgResult(msg) =
println($"($(msg))")
value $(msg)
ConfMsgWarn(msg) =
msg[] = $(split $(nl), $(msg))
print($(concat $(EMPTY), $(add-wrapper $'--- *** ', $(nl), $(msg))))
ConfMsgError(msg) =
msg[] = $(split $(nl), $(msg))
eprintln($"""*** ERROR: $(concat '$(nl)--- ', $(msg))""")
exit(1)
# flag = $(ConfMsgYesNo <bool expr>)
# flag = $(ConfMsgFound <bool expr>)
# The ConfMsgFound function expects to receive a boolean flag describing whether a test
# previously announced using the ConfMsgChecking found what it
# was looking for. ConfMsgFound will output the appropriate result (``found'' or ``NOT found'')
# using the ConfMsgResult and return its argument back.
# The ConfMsgYesNo function is similar, outputting a simple (``yes'' or ``NO'').
ConfMsgYesNo(found) =
ConfMsgResult($(if $(found), yes, NO))
return $(found)
ConfMsgFound(found) =
ConfMsgResult($(if $(found), found, NOT found))
return $(found)
# TryCompileC{TryRunC}
# success = $(TryCompileC <prog_text>)
# success = $(TryLinkC <prog_text>)
# success = $(TryRunC <prog_text>)
#
# Given the text of a C program, the TryCompileC, TryLinkC, and TryRunC
# functions would try to compile / compile and link / compile, link, and run, the given program and return a boolean flag
# indicating whether the attempt was successful.
#
# TryCompileC will use the CC, CFLAGS and INCLUDES variables
# to run the C compiler. TryLinkC and TryRunC will also use the LDFLAGS
# to run the C compiler and linker. However, the flags like \verb+/WX+, \verb+-Werror+ and \verb+-warn-error+
# will be not be passed to the compiler, even if they occur in CFLAGS.
#
# These functions are silent and should normally be used with an appropriate
# ConfMsgChecking $\ldots$ ConfMsgResult.
# doc
ConfCleanCFLAGS(cflags) =
value $(filter-out /WX -Werror --warn-error, $(cflags))
TryCompilingC(command, command_suffix, ext, prog, extra) =
# The command line
private.tmp_c = $(file $(tmpfile omake, .c))
private.tmp = $(file $(replacesuffixes .c, $"$(EMPTY)", $(tmp_c)))
export command
if $(and $(not $(equal $(CCOUT), $(LDOUT))), $(equal $(ext), $(EXE)))
command[] += $(CCOUT)$(file $(tmp)$(EXT_OBJ)) $(LDOUT)$(file $(tmp)$(ext))
else
command[] += $(CCOUT)$(file $(tmp)$(ext))
command[] += $(file $(tmp_c)) $(command_suffix)
# The program
program = $"""/* Configuration file; you can remove this. */
/* Command line: $(command) */
$(prog)
"""
# Compile it
fprint($(tmp_c), $(program))
protected.result = $(shell-success-null $(command))
export result
if $(result)
switch $(extra)
case Runs
result = $(shell-success-null $(file $(tmp)$(EXE)))
case Output
result =
try
value $(shell $(file $(tmp)$(EXE)))
default
value $(not true)
# Remove temporaries
rm -f $(tmp_c) $(tmp)$(EXT_OBJ) $(tmp)$(EXE)
return $(result)
TryCompileC(prog) =
return $(TryCompilingC $(CC) $(ConfCleanCFLAGS $(CFLAGS)) $(PREFIXED_INCLUDES) -c, $(EMPTY), $(EXT_OBJ), $(prog), None)
TryLinkC(prog) =
return $(TryCompilingC $(CC) $(ConfCleanCFLAGS $(CFLAGS)) $(PREFIXED_INCLUDES), $(LDFLAGS), $(EXE), $(prog), None)
TryRunC(prog) =
return $(TryCompilingC $(CC) $(ConfCleanCFLAGS $(CFLAGS)) $(PREFIXED_INCLUDES), $(LDFLAGS), $(EXE), $(prog), Runs)
# RunCProg
# output = $(RunCProg <prog>)
#
# RunCProg is similar to the RunCProg, except that it
# returns the output of the function (will return false if the program fails to compile
# or run).
RunCProg(prog) =
return $(TryCompilingC $(CC) $(ConfCleanCFLAGS $(CFLAGS)) $(PREFIXED_INCLUDES), $(LDFLAGS), $(EXE), $(prog), Output)
#
# Check whether a header file exists.
# We call the C compiler.
#
# doc
# CheckCHeader
# verbatim
# success = $(CheckCHeader <files>)
# success = $(VerboseCheckCHeader <files>)
# verbatim
#
# Use the TryCompileC to check whether your C compiler can locate
# and process the specified headers files.
# Will incude \verb+<stdio.h>+ before including the header files.
#
# Both functions return a boolean value. The CheckCHeader function is silent; the
# VerboseCheckCHeader function will use the ConfMsgChecking and
# ConfMsgResult functions to describe the test and the outcome.
#
# Example:
# verbatim
# static. =
# NCURSES_H_AVAILABLE = $(VerboseCheckCHeader ncurses.h)
# verbatim
# doc
#
public.CheckCHeader(files) =
return $(TryCompileC $"""
#ifdef __cplusplus
extern "C"
#endif
#pragma warning( disable : 4100 )
#include <stdio.h>
$(add-wrapper $(nl)$'#include <', >, $(files))
int main(int argc, char **argv) {
return 0;
}
""")
public.VerboseCheckCHeader(files) =
ConfMsgChecking(for $(files))
return $(ConfMsgFound $(CheckCHeader $(files)))
#
# Check whether the libraries have the given functions
#
# doc
# CheckCLib
# verbatim
# success = $(CheckCLib <libs>, <functions>)
# success = $(VerboseCheckCLib <libs>, <functions>)
# verbatim
#
# Use the TryLinkC to check whether your C compiler and linker can
# find the named functions when linking with the named libraries. Will pass the \verb+<libs>+ to
# the compiler using the \verb+-l+ flag.
#
# Both functions return a boolean value. The CheckCLib function is silent; the
# VerboseCheckCHeader function will use the ConfMsgChecking and
# ConfMsgResult functions to describe the test and the outcome.
#
# Example:
# verbatim
# static. =
# NCURSES_LIB_AVAILABLE = $(VerboseCheckCLib ncurses, initscr setupterm tigetstr)
# verbatim
# doc
#
public.CheckCLib(libs, funs) =
CFLAGS += $(addprefix -l, $(libs))
return $(TryLinkC $"""
#ifdef __cplusplus
extern "C"
#endif
#pragma warning( disable : 4100 )
/* Override any gcc2 internal prototype to avoid an error. */
$(add-wrapper $(nl)extern char , $'();', $(funs))
int main(int argc, char **argv) {
/* Usage */
$(add-wrapper $(nl) , $'();', $(funs))
return 0;
}
""")
public.VerboseCheckCLib(libs, funs) =
msg1 = $(if $(funs), $"""function$(if $(gt $(length $(funs)), 1), s) $(concat $", ", $(funs))""")
msg2 = $(if $(libs), $"""librar$(if $(gt $(length $(libs)), 1), ies, y) $(concat $", ", $(libs))""")
ConfMsgChecking($"""for $(msg1)$(if $(not $(or $(not $(funs)), $(not $(libs)))), $' in ')$(msg2)""")
return $(ConfMsgFound $(CheckCLib $(libs), $(funs)))
#
# Backwards compatibility
#
# XXX: Once we decide how we are going to provide the multi-language support,
# we should either update these or have them produce an "obsolete" warning.
#
public.CheckLib = $(CheckCLib)
public.VerboseCheckLib = $(VerboseCheckCLib)
public.CheckHeader = $(CheckCHeader)
public.VerboseCheckHeader = $(VerboseCheckCHeader)
#
# Check whether a program exists in the PATH
#
# doc
# CheckProg
# \verb+success = $(CheckProg <prog>)+
#
# Checks whether the program \verb+<prog>+ exists in your path. Will use the
# ConfMsgChecking and
# ConfMsgResult functions to describe the test and the outcome.
#
#
public.CheckProg(prog) =
ConfMsgChecking(for $(prog))
WHERE = $(where $(prog))
if $(WHERE)
ConfMsgResult(found $(nth 0, $(WHERE)))
return true
else
ConfMsgResult(FAILED - no $(prog) found)
return false
#
# \section{Translating autoconf scripts}
# Some of the functions described above are very similar to the ones present in autoconf.
# Below is a brief translation table for such functions.
# description
# \itemidx{AC\_MSG\_CHECKING} is very similar to ConfMsgChecking.
# \itemidx{AC\_MSG\_RESULT} is very similar to ConfMsgResult.
# \itemidx{AC\_MSG\_WARN} is very similar to ConfMsgWarn.
# \itemidx{AC\_MSG\_ERROR} is very similar to ConfMsgError.
# \itemidx{AC\_TRY\_COMPILE} is somewhat similar to TryCompileC,
# except the TryCompileC returns a boolean value and only works for C. Similarly,
# \itemidx{AC\_TRY\_LINK} is approximated by TryLinkC, and
# \itemidx{AC\_TRY\_RUN} is approximated by TryRunC.
# description
#
# \section{Predefined configuration tests}
# A number of configuration tests are already included in the standard library.
# In order to use them in your project, simply open (see Section~\ref{section:include}) the
# corresponding build file in your OMakefile and the tests will run the first time \OMake{}
# is executed. Note that it is not a problem to open these files from more than one place in
# your project --- if you do that, the test will still run only once.
#