2 * Copyright (C) 2007 Christoph von Wittich
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #pragma warning ( disable : 4786 )
30 #include "dependencymap.h"
31 #include "../mingw/mingw.h"
43 static class DepMapFactory
: public Backend::Factory
47 DepMapFactory() : Factory("DepMap", "Dependency Map") {}
48 Backend
*operator() (Project
&project
,
49 Configuration
& configuration
)
51 return new DepMapBackend(project
, configuration
);
57 DepMapBackend::DepMapBackend(Project
&project
,
58 Configuration
& configuration
) : Backend(project
, configuration
)
63 void DepMapBackend::Process()
65 string
filename_depmap ( "dependencymap.xml" );
66 printf ( "Creating dependecy map: %s\n", filename_depmap
.c_str() );
68 m_DepMapFile
= fopen ( filename_depmap
.c_str(), "wb" );
72 printf ( "Could not create file '%s'.\n", filename_depmap
.c_str() );
76 _generate_depmap ( m_DepMapFile
);
78 fclose ( m_DepMapFile
);
83 DepMapBackend::_clean_project_files ( void )
85 remove ( "dependencymap.xml" );
90 DepMapBackend::_generate_depmap ( FILE* OUT
)
92 /* add dependencies */
94 typedef map
<string
, module_data
*> ModuleMap
;
97 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
99 Module
& module
= *ProjectNode
.modules
[i
];
100 if ((module
.type
!= Iso
) &&
101 (module
.type
!= LiveIso
) &&
102 (module
.type
!= IsoRegTest
) &&
103 (module
.type
!= LiveIsoRegTest
))
105 vector
<const IfableData
*> ifs_list
;
106 ifs_list
.push_back ( &module
.project
.non_if_data
);
107 ifs_list
.push_back ( &module
.non_if_data
);
109 module_data
* current_data
;
110 ModuleMap::iterator mod_it
= module_map
.find ( module
.name
);
111 if (mod_it
!= module_map
.end ())
113 current_data
= mod_it
->second
;
117 current_data
= new module_data();
120 module_map
.insert (std::make_pair
<string
, module_data
*>(module
.name
, current_data
));
123 while ( ifs_list
.size() )
125 const IfableData
& data
= *ifs_list
.back();
127 const vector
<Library
*>& libs
= data
.libraries
;
128 for ( size_t j
= 0; j
< libs
.size(); j
++ )
130 ModuleMap::iterator it
= module_map
.find ( libs
[j
]->name
);
132 if ( it
!= module_map
.end ())
134 module_data
* data
= it
->second
;
135 data
->references
.push_back ( module
.name
);
139 module_data
* data
= new module_data();
142 data
->references
.push_back ( module
.name
);
144 module_map
.insert ( std::make_pair
<string
, module_data
*>( libs
[j
]->name
, data
) );
146 current_data
->libraries
.push_back ( libs
[j
]->name
);
152 fprintf ( m_DepMapFile
, "<?xml version=\"1.0\" encoding=\"iso-8859-1\" ?>\r\n" );
153 fprintf ( m_DepMapFile
, "<?xml-stylesheet type=\"text/xsl\" href=\"depmap.xsl\"?>\r\n" );
154 fprintf ( m_DepMapFile
, "<components>\r\n" );
156 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
158 Module
& module
= *ProjectNode
.modules
[i
];
160 ModuleMap::iterator it
= module_map
.find ( module
.name
);
161 if ( it
!= module_map
.end () )
163 module_data
* data
= it
->second
;
167 fprintf ( m_DepMapFile
, "\t<component>\r\n" );
168 fprintf ( m_DepMapFile
, "\t\t<name>%s</name>\r\n", module
.name
.c_str () );
169 fprintf ( m_DepMapFile
, "\t\t<base>%s</base>\r\n", module
.GetBasePath ().c_str () );
170 fprintf ( m_DepMapFile
, "\t\t<ref_count>%u</ref_count>\r\n", (unsigned int)data
->references
.size () );
171 fprintf ( m_DepMapFile
, "\t\t<lib_count>%u</lib_count>\r\n", (unsigned int)data
->libraries
.size () );
173 if ( data
->references
.size () )
175 fprintf ( m_DepMapFile
, "\t<references>\r\n" );
176 for ( size_t j
= 0; j
< data
->references
.size (); j
++ )
178 fprintf ( m_DepMapFile
, "\t\t<reference name =\"%s\" />\r\n", data
->references
[j
].c_str () );
180 fprintf ( m_DepMapFile
, "\t</references>\r\n" );
183 if ( data
->libraries
.size () )
185 fprintf ( m_DepMapFile
, "\t<libraries>\r\n" );
186 for ( size_t j
= 0; j
< data
->libraries
.size (); j
++ )
188 fprintf ( m_DepMapFile
, "\t\t<library name =\"%s\" />\r\n", data
->libraries
[j
].c_str () );
190 fprintf ( m_DepMapFile
, "\t</libraries>\r\n" );
193 fprintf ( m_DepMapFile
, "\t</component>\r\n" );
197 fprintf ( m_DepMapFile
, "</components>" );
201 DepMapConfiguration::DepMapConfiguration ( const std::string
&name
)
203 /* nothing to do here */