2 * Automated Testing Framework (atf)
4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "atf-c/build.h"
34 #include "atf-c/config.h"
35 #include "atf-c/error.h"
37 #include "detail/sanity.h"
38 #include "detail/text.h"
40 /* ---------------------------------------------------------------------
41 * Auxiliary functions.
42 * --------------------------------------------------------------------- */
46 append_config_var(const char *var
, atf_list_t
*argv
)
51 err
= atf_text_split(atf_config_get(var
), " ", &words
);
52 if (atf_is_error(err
))
55 atf_list_append_list(argv
, &words
);
63 append_arg1(const char *arg
, atf_list_t
*argv
)
65 return atf_list_append(argv
, strdup(arg
), true);
70 append_arg2(const char *flag
, const char *arg
, atf_list_t
*argv
)
74 err
= append_arg1(flag
, argv
);
75 if (!atf_is_error(err
))
76 err
= append_arg1(arg
, argv
);
83 append_optargs(const char *const optargs
[], atf_list_t
*argv
)
88 while (*optargs
!= NULL
&& !atf_is_error(err
)) {
89 err
= append_arg1(strdup(*optargs
), argv
);
98 append_src_out(const char *src
, const char *obj
, atf_list_t
*argv
)
102 err
= append_arg2("-o", obj
, argv
);
103 if (atf_is_error(err
))
106 err
= append_arg1("-c", argv
);
107 if (atf_is_error(err
))
110 err
= append_arg1(src
, argv
);
118 list_to_array(const atf_list_t
*l
, char ***ap
)
123 a
= (char **)malloc((atf_list_size(l
) + 1) * sizeof(char *));
125 err
= atf_no_memory_error();
128 atf_list_citer_t liter
;
131 atf_list_for_each_c(liter
, l
) {
132 *aiter
= strdup((const char *)atf_list_citer_data(liter
));
137 err
= atf_no_error();
139 *ap
= a
; /* Shut up warnings in the caller about uninitialized *ap. */
144 /* ---------------------------------------------------------------------
146 * --------------------------------------------------------------------- */
149 atf_build_c_o(const char *sfile
,
151 const char *const optargs
[],
155 atf_list_t argv_list
;
157 err
= atf_list_init(&argv_list
);
158 if (atf_is_error(err
))
161 err
= append_config_var("atf_build_cc", &argv_list
);
162 if (atf_is_error(err
))
165 err
= append_config_var("atf_build_cppflags", &argv_list
);
166 if (atf_is_error(err
))
169 err
= append_config_var("atf_build_cflags", &argv_list
);
170 if (atf_is_error(err
))
173 if (optargs
!= NULL
) {
174 err
= append_optargs(optargs
, &argv_list
);
175 if (atf_is_error(err
))
179 err
= append_src_out(sfile
, ofile
, &argv_list
);
180 if (atf_is_error(err
))
183 err
= list_to_array(&argv_list
, argv
);
184 if (atf_is_error(err
))
188 atf_list_fini(&argv_list
);
194 atf_build_cpp(const char *sfile
,
196 const char *const optargs
[],
200 atf_list_t argv_list
;
202 err
= atf_list_init(&argv_list
);
203 if (atf_is_error(err
))
206 err
= append_config_var("atf_build_cpp", &argv_list
);
207 if (atf_is_error(err
))
210 err
= append_config_var("atf_build_cppflags", &argv_list
);
211 if (atf_is_error(err
))
214 if (optargs
!= NULL
) {
215 err
= append_optargs(optargs
, &argv_list
);
216 if (atf_is_error(err
))
220 err
= append_arg2("-o", ofile
, &argv_list
);
221 if (atf_is_error(err
))
224 err
= append_arg1(sfile
, &argv_list
);
225 if (atf_is_error(err
))
228 err
= list_to_array(&argv_list
, argv
);
229 if (atf_is_error(err
))
233 atf_list_fini(&argv_list
);
239 atf_build_cxx_o(const char *sfile
,
241 const char *const optargs
[],
245 atf_list_t argv_list
;
247 err
= atf_list_init(&argv_list
);
248 if (atf_is_error(err
))
251 err
= append_config_var("atf_build_cxx", &argv_list
);
252 if (atf_is_error(err
))
255 err
= append_config_var("atf_build_cppflags", &argv_list
);
256 if (atf_is_error(err
))
259 err
= append_config_var("atf_build_cxxflags", &argv_list
);
260 if (atf_is_error(err
))
263 if (optargs
!= NULL
) {
264 err
= append_optargs(optargs
, &argv_list
);
265 if (atf_is_error(err
))
269 err
= append_src_out(sfile
, ofile
, &argv_list
);
270 if (atf_is_error(err
))
273 err
= list_to_array(&argv_list
, argv
);
274 if (atf_is_error(err
))
278 atf_list_fini(&argv_list
);