4 # Copyright The SCons Foundation
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be included
15 # in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
18 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
19 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 Verify creation of a config.h file from a Configure context.
34 test
= TestSCons
.TestSCons(match
= TestSCons
.match_exact
)
36 lib
= test
.Configure_lib
37 LIB
= "LIB" + lib
.upper()
39 test
.write('SConstruct', """\
40 DefaultEnvironment(tools=[])
43 env.AppendENVPath('PATH', os.environ['PATH'])
44 conf = Configure(env, config_h = 'config.h')
45 r1 = conf.CheckFunc('printf', header='#include <stdio.h>', funcargs='""')
46 r2 = conf.CheckFunc('noFunctionCall')
47 r3 = conf.CheckFunc('memmove')
48 r4 = conf.CheckType('int')
49 r5 = conf.CheckType('noType')
51 m1 = conf.CheckMember('struct timespec.tv_sec', '#include <time.h>')
52 m2 = conf.CheckMember('struct timespec.tv_nanosec', '#include <time.h>')
54 r6 = conf.CheckCHeader('stdio.h', '<>')
55 r7 = conf.CheckCHeader('hopefullynoc-header.h')
56 r8 = conf.CheckCXXHeader('vector', '<>')
57 r9 = conf.CheckCXXHeader('hopefullynocxx-header.h')
59 conf = Configure(env, config_h = 'config.h')
60 r10 = conf.CheckLib('%(lib)s', 'sin')
61 r11 = conf.CheckLib('hopefullynolib', 'sin')
62 r12 = conf.CheckLibWithHeader('%(lib)s', 'math.h', 'c')
63 r13 = conf.CheckLibWithHeader('%(lib)s', 'hopefullynoheader2.h', 'c')
64 r14 = conf.CheckLibWithHeader('hopefullynolib2', 'math.h', 'c')
68 expected_read_str
= """\
69 Checking for C function printf()... yes
70 Checking for C function noFunctionCall()... no
71 Checking for C function memmove()... yes
72 Checking for C type int... yes
73 Checking for C type noType... no
74 Checking for C member struct timespec.tv_sec... yes
75 Checking for C member struct timespec.tv_nanosec... no
76 Checking for C header file stdio.h... yes
77 Checking for C header file hopefullynoc-header.h... no
78 Checking for C++ header file vector... yes
79 Checking for C++ header file hopefullynocxx-header.h... no
80 Checking for sin() in C library %(lib)s... yes
81 Checking for sin() in C library hopefullynolib... no
82 Checking for C library %(lib)s... yes
83 Checking for C library %(lib)s... no
84 Checking for C library hopefullynolib2... no
87 expected_build_str
= """\
88 scons: Configure: creating config.h
91 expected_stdout
= test
.wrap_stdout(build_str
=expected_build_str
,
92 read_str
=expected_read_str
)
94 expected_config_h
= ("""\
99 /* Define to 1 if the system has the function `printf'. */
100 #define HAVE_PRINTF 1
102 /* Define to 1 if the system has the function `noFunctionCall'. */
103 /* #undef HAVE_NOFUNCTIONCALL */
105 /* Define to 1 if the system has the function `memmove'. */
106 #define HAVE_MEMMOVE 1
108 /* Define to 1 if the system has the type `int'. */
111 /* Define to 1 if the system has the type `noType'. */
112 /* #undef HAVE_NOTYPE */
114 /* Define to 1 if the system has the member `struct timespec.tv_sec`. */
115 #define HAVE_STRUCT_TIMESPEC_TV_SEC 1
117 /* Define to 1 if the system has the member `struct timespec.tv_nanosec`. */
118 /* #undef HAVE_STRUCT_TIMESPEC_TV_NANOSEC */
120 /* Define to 1 if you have the <stdio.h> header file. */
121 #define HAVE_STDIO_H 1
123 /* Define to 1 if you have the <hopefullynoc-header.h> header file. */
124 /* #undef HAVE_HOPEFULLYNOC_HEADER_H */
126 /* Define to 1 if you have the <vector> header file. */
127 #define HAVE_VECTOR 1
129 /* Define to 1 if you have the <hopefullynocxx-header.h> header file. */
130 /* #undef HAVE_HOPEFULLYNOCXX_HEADER_H */
132 /* Define to 1 if you have the `%(lib)s' library. */
133 #define HAVE_%(LIB)s 1
135 /* Define to 1 if you have the `hopefullynolib' library. */
136 /* #undef HAVE_LIBHOPEFULLYNOLIB */
138 /* Define to 1 if you have the `%(lib)s' library. */
139 #define HAVE_%(LIB)s 1
141 /* Define to 1 if you have the `%(lib)s' library. */
142 /* #undef HAVE_%(LIB)s */
144 /* Define to 1 if you have the `hopefullynolib2' library. */
145 /* #undef HAVE_LIBHOPEFULLYNOLIB2 */
147 #endif /* CONFIG_H_SEEN */
150 test
.run(stdout
=expected_stdout
)
152 config_h
= test
.read(test
.workpath('config.h'), mode
='r')
153 if expected_config_h
!= config_h
:
154 print("Unexpected config.h")
156 print("---------------------------------------------------------")
157 print(repr(expected_config_h
))
158 print("---------------------------------------------------------")
160 print("---------------------------------------------------------")
161 print(repr(config_h
))
162 print("---------------------------------------------------------")
164 print("---------------------------------------------------------")
166 print("---------------------------------------------------------")
169 expected_read_str
= re
.sub(r
'\b((yes)|(no))\b',
172 expected_build_str
= "scons: `.' is up to date.\n"
173 expected_stdout
= test
.wrap_stdout(build_str
=expected_build_str
,
174 read_str
=expected_read_str
)
175 #expected_stdout = expected_stdout.replace("\n", os.linesep)
177 test
.run(stdout
=expected_stdout
)
179 config_h
= test
.read(test
.workpath('config.h'),mode
='r')
180 if expected_config_h
!= config_h
:
181 print("Unexpected config.h")
183 print("---------------------------------------------------------")
184 print(repr(expected_config_h
))
185 print("---------------------------------------------------------")
187 print("---------------------------------------------------------")
188 print(repr(config_h
))
189 print("---------------------------------------------------------")
191 print("---------------------------------------------------------")
193 print("---------------------------------------------------------")
200 # indent-tabs-mode:nil
202 # vim: set expandtab tabstop=4 shiftwidth=4: