1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 //==========================================================================
29 // The implementation of build flags extraction from CDL data
31 //==========================================================================
32 //==========================================================================
33 //#####DESCRIPTIONBEGIN####
38 //####DESCRIPTIONEND####
39 //==========================================================================
44 static const std::string GLOBAL_FLAGS_PREFIX = "CYGBLD_GLOBAL_";
45 static const std::string ADD_FLAGS_SUFFIX = "_ADD";
46 static const std::string REMOVE_FLAGS_SUFFIX = "_REMOVE";
48 // convert a string of space-separated values into a list of strings
49 static void string_to_list (std::string input, std::list <std::string> & output) {
54 for (unsigned int n = 0; n < input.size (); n++) { // for each char in the string
55 if (isspace (input [n])) { // if char is a space
56 if (! space) { // if previous char not a space
57 output.push_back (item); // add item to output list
58 item.erase (); // clear item string
61 } else { // char is not a space
62 item += input [n]; // add char to item string
67 if (! space) { // if final char not a space
68 output.push_back (item); // add final item to output list
72 // convert a list of strings into a string of space-separated values
73 static std::string list_to_string (std::list <std::string> & input) {
76 for (std::list <std::string>::iterator item = input.begin (); item != input.end (); item++) { // for each item in the list
77 output += * item + " "; // add item to output string followed by a space
80 if (! output.empty ()) { // if the output string is not empty
81 output.resize (output.size () - 1); // remove the trailing space
87 // return the build flags of the specified category
88 std::string get_flags (const CdlConfiguration config, const CdlBuildInfo_Loadable * build_info, const std::string flag_category) {
89 std::list <std::string> flags_list;
91 CdlValuable global_flags = dynamic_cast <CdlValuable> (config->lookup (GLOBAL_FLAGS_PREFIX + flag_category));
92 if (global_flags) { // if there are global flags
93 string_to_list (global_flags->get_value (), flags_list);
96 if (build_info) { // if the caller requires flags specific to a particular loadable
97 // process flags to be removed
98 CdlValuable remove_flags = dynamic_cast <CdlValuable> (config->lookup (build_info->name + "_" + flag_category + REMOVE_FLAGS_SUFFIX));
99 if (remove_flags) { // if there are flags to be removed
100 std::list <std::string> remove_flags_list;
101 string_to_list (remove_flags->get_value (), remove_flags_list);
102 for (std::list <std::string>::iterator item = remove_flags_list.begin (); item != remove_flags_list.end (); item++) {
103 flags_list.remove (* item); // remove the flag from the list
107 // process flags to be added
108 CdlValuable add_flags = dynamic_cast <CdlValuable> (config->lookup (build_info->name + "_" + flag_category + ADD_FLAGS_SUFFIX));
109 if (add_flags) { // if there are flags to be added
110 std::list <std::string> add_flags_list;
111 string_to_list (add_flags->get_value (), add_flags_list);
112 flags_list.splice (flags_list.end (), add_flags_list); // splice the additional flags onto the end of the list
116 return list_to_string (flags_list);