1 /* $NetBSD: build.c,v 1.1.1.3 2014/12/10 03:34:48 christos Exp $ */
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2009 The NetBSD Foundation, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "atf-c/build.h"
36 #include "atf-c/config.h"
37 #include "atf-c/error.h"
39 #include "detail/sanity.h"
40 #include "detail/text.h"
42 /* ---------------------------------------------------------------------
43 * Auxiliary functions.
44 * --------------------------------------------------------------------- */
48 append_config_var(const char *var
, atf_list_t
*argv
)
53 err
= atf_text_split(atf_config_get(var
), " ", &words
);
54 if (atf_is_error(err
))
57 atf_list_append_list(argv
, &words
);
65 append_arg1(const char *arg
, atf_list_t
*argv
)
67 return atf_list_append(argv
, strdup(arg
), true);
72 append_arg2(const char *flag
, const char *arg
, atf_list_t
*argv
)
76 err
= append_arg1(flag
, argv
);
77 if (!atf_is_error(err
))
78 err
= append_arg1(arg
, argv
);
85 append_optargs(const char *const optargs
[], atf_list_t
*argv
)
90 while (*optargs
!= NULL
&& !atf_is_error(err
)) {
91 err
= append_arg1(strdup(*optargs
), argv
);
100 append_src_out(const char *src
, const char *obj
, atf_list_t
*argv
)
104 err
= append_arg2("-o", obj
, argv
);
105 if (atf_is_error(err
))
108 err
= append_arg1("-c", argv
);
109 if (atf_is_error(err
))
112 err
= append_arg1(src
, argv
);
120 list_to_array(const atf_list_t
*l
, char ***ap
)
125 a
= (char **)malloc((atf_list_size(l
) + 1) * sizeof(char *));
127 err
= atf_no_memory_error();
130 atf_list_citer_t liter
;
133 atf_list_for_each_c(liter
, l
) {
134 *aiter
= strdup((const char *)atf_list_citer_data(liter
));
139 err
= atf_no_error();
141 *ap
= a
; /* Shut up warnings in the caller about uninitialized *ap. */
146 /* ---------------------------------------------------------------------
148 * --------------------------------------------------------------------- */
151 atf_build_c_o(const char *sfile
,
153 const char *const optargs
[],
157 atf_list_t argv_list
;
159 err
= atf_list_init(&argv_list
);
160 if (atf_is_error(err
))
163 err
= append_config_var("atf_build_cc", &argv_list
);
164 if (atf_is_error(err
))
167 err
= append_config_var("atf_build_cppflags", &argv_list
);
168 if (atf_is_error(err
))
171 err
= append_config_var("atf_build_cflags", &argv_list
);
172 if (atf_is_error(err
))
175 if (optargs
!= NULL
) {
176 err
= append_optargs(optargs
, &argv_list
);
177 if (atf_is_error(err
))
181 err
= append_src_out(sfile
, ofile
, &argv_list
);
182 if (atf_is_error(err
))
185 err
= list_to_array(&argv_list
, argv
);
186 if (atf_is_error(err
))
190 atf_list_fini(&argv_list
);
196 atf_build_cpp(const char *sfile
,
198 const char *const optargs
[],
202 atf_list_t argv_list
;
204 err
= atf_list_init(&argv_list
);
205 if (atf_is_error(err
))
208 err
= append_config_var("atf_build_cpp", &argv_list
);
209 if (atf_is_error(err
))
212 err
= append_config_var("atf_build_cppflags", &argv_list
);
213 if (atf_is_error(err
))
216 if (optargs
!= NULL
) {
217 err
= append_optargs(optargs
, &argv_list
);
218 if (atf_is_error(err
))
222 err
= append_arg2("-o", ofile
, &argv_list
);
223 if (atf_is_error(err
))
226 err
= append_arg1(sfile
, &argv_list
);
227 if (atf_is_error(err
))
230 err
= list_to_array(&argv_list
, argv
);
231 if (atf_is_error(err
))
235 atf_list_fini(&argv_list
);
241 atf_build_cxx_o(const char *sfile
,
243 const char *const optargs
[],
247 atf_list_t argv_list
;
249 err
= atf_list_init(&argv_list
);
250 if (atf_is_error(err
))
253 err
= append_config_var("atf_build_cxx", &argv_list
);
254 if (atf_is_error(err
))
257 err
= append_config_var("atf_build_cppflags", &argv_list
);
258 if (atf_is_error(err
))
261 err
= append_config_var("atf_build_cxxflags", &argv_list
);
262 if (atf_is_error(err
))
265 if (optargs
!= NULL
) {
266 err
= append_optargs(optargs
, &argv_list
);
267 if (atf_is_error(err
))
271 err
= append_src_out(sfile
, ofile
, &argv_list
);
272 if (atf_is_error(err
))
275 err
= list_to_array(&argv_list
, argv
);
276 if (atf_is_error(err
))
280 atf_list_fini(&argv_list
);