4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews/* Copyright (c) 2009 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * are met:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/build.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <stdlib.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <string.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/env.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/sanity.h"
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c/detail/text.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include "atf-c/error.h"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Auxiliary functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrewsappend_config_var(const char *var, const char *default_value, atf_list_t *argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_t words;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = atf_text_split(atf_env_get_with_default(var, default_value),
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews " ", &words);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_append_list(argv, &words);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntappend_arg1(const char *arg, atf_list_t *argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return atf_list_append(argv, strdup(arg), true);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntappend_arg2(const char *flag, const char *arg, atf_list_t *argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg1(flag, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (!atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg1(arg, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntappend_optargs(const char *const optargs[], atf_list_t *argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_no_error();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt while (*optargs != NULL && !atf_is_error(err)) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg1(strdup(*optargs), argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt optargs++;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntappend_src_out(const char *src, const char *obj, atf_list_t *argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg2("-o", obj, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg1("-c", argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg1(src, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntlist_to_array(const atf_list_t *l, char ***ap)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt char **a;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt a = (char **)malloc((atf_list_size(l) + 1) * sizeof(char *));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (a == NULL)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_no_memory_error();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt else {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt char **aiter;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_citer_t liter;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt aiter = a;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_for_each_c(liter, l) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *aiter = strdup((const char *)atf_list_citer_data(liter));
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt aiter++;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *aiter = NULL;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_no_error();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt *ap = a; /* Shut up warnings in the caller about uninitialized *ap. */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt/* ---------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * Free functions.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt * --------------------------------------------------------------------- */
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_build_c_o(const char *sfile,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *ofile,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *const optargs[],
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt char ***argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_t argv_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_list_init(&argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CC", ATF_BUILD_CC, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CFLAGS", ATF_BUILD_CFLAGS, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (optargs != NULL) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_optargs(optargs, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_src_out(sfile, ofile, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = list_to_array(&argv_list, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout_list:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_fini(&argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_build_cpp(const char *sfile,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *ofile,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *const optargs[],
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt char ***argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_t argv_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_list_init(&argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CPP", ATF_BUILD_CPP, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (optargs != NULL) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_optargs(optargs, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg2("-o", ofile, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_arg1(sfile, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = list_to_array(&argv_list, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout_list:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_fini(&argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_error_t
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntatf_build_cxx_o(const char *sfile,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *ofile,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const char *const optargs[],
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt char ***argv)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_error_t err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_t argv_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = atf_list_init(&argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CXX", ATF_BUILD_CXX, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CPPFLAGS", ATF_BUILD_CPPFLAGS,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews err = append_config_var("ATF_BUILD_CXXFLAGS", ATF_BUILD_CXXFLAGS,
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (optargs != NULL) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_optargs(optargs, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = append_src_out(sfile, ofile, &argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt err = list_to_array(&argv_list, argv);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (atf_is_error(err))
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt goto out_list;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout_list:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf_list_fini(&argv_list);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntout:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt return err;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}