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.
32 #include "atf-c/build.h"
33 #include "atf-c/config.h"
34 #include "atf-c/error.h"
35 #include "atf-c/sanity.h"
36 #include "atf-c/text.h"
38 /* ---------------------------------------------------------------------
39 * Auxiliary functions.
40 * --------------------------------------------------------------------- */
44 append_config_var(const char *var
, atf_list_t
*argv
)
49 err
= atf_text_split(atf_config_get(var
), " ", &words
);
50 if (atf_is_error(err
))
53 atf_list_append_list(argv
, &words
);
61 append_arg1(const char *arg
, atf_list_t
*argv
)
63 return atf_list_append(argv
, strdup(arg
), true);
68 append_arg2(const char *flag
, const char *arg
, atf_list_t
*argv
)
72 err
= append_arg1(flag
, argv
);
73 if (!atf_is_error(err
))
74 err
= append_arg1(arg
, argv
);
81 append_optargs(const char *const optargs
[], atf_list_t
*argv
)
86 while (*optargs
!= NULL
&& !atf_is_error(err
)) {
87 err
= append_arg1(strdup(*optargs
), argv
);
96 append_src_out(const char *src
, const char *obj
, atf_list_t
*argv
)
100 err
= append_arg2("-o", obj
, argv
);
101 if (atf_is_error(err
))
104 err
= append_arg1("-c", argv
);
105 if (atf_is_error(err
))
108 err
= append_arg1(src
, argv
);
114 /* ---------------------------------------------------------------------
116 * --------------------------------------------------------------------- */
119 atf_build_c_o(const char *sfile
,
121 const char *const optargs
[],
126 err
= atf_list_init(argv
);
127 if (atf_is_error(err
))
130 err
= append_config_var("atf_build_cc", argv
);
131 if (atf_is_error(err
))
134 err
= append_config_var("atf_build_cppflags", argv
);
135 if (atf_is_error(err
))
138 err
= append_config_var("atf_build_cflags", argv
);
139 if (atf_is_error(err
))
142 if (optargs
!= NULL
) {
143 err
= append_optargs(optargs
, argv
);
144 if (atf_is_error(err
))
148 err
= append_src_out(sfile
, ofile
, argv
);
149 if (atf_is_error(err
))
152 INV(!atf_is_error(err
));
162 atf_build_cpp(const char *sfile
,
164 const char *const optargs
[],
169 err
= atf_list_init(argv
);
170 if (atf_is_error(err
))
173 err
= append_config_var("atf_build_cpp", argv
);
174 if (atf_is_error(err
))
177 err
= append_config_var("atf_build_cppflags", argv
);
178 if (atf_is_error(err
))
181 if (optargs
!= NULL
) {
182 err
= append_optargs(optargs
, argv
);
183 if (atf_is_error(err
))
187 err
= append_arg2("-o", ofile
, argv
);
188 if (atf_is_error(err
))
191 err
= append_arg1(sfile
, argv
);
192 if (atf_is_error(err
))
195 INV(!atf_is_error(err
));
205 atf_build_cxx_o(const char *sfile
,
207 const char *const optargs
[],
212 err
= atf_list_init(argv
);
213 if (atf_is_error(err
))
216 err
= append_config_var("atf_build_cxx", argv
);
217 if (atf_is_error(err
))
220 err
= append_config_var("atf_build_cppflags", argv
);
221 if (atf_is_error(err
))
224 err
= append_config_var("atf_build_cxxflags", argv
);
225 if (atf_is_error(err
))
228 if (optargs
!= NULL
) {
229 err
= append_optargs(optargs
, argv
);
230 if (atf_is_error(err
))
234 err
= append_src_out(sfile
, ofile
, argv
);
235 if (atf_is_error(err
))
238 INV(!atf_is_error(err
));