make_msvcX_install_[config] patch by Brezenbak
[reactos.git] / reactos / tools / rbuild / compilationunit.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
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.
8 *
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.
13 *
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.
17 */
18 #include "pch.h"
19 #include <assert.h>
20
21 #include "rbuild.h"
22
23 using std::string;
24 using std::vector;
25
26 CompilationUnit::CompilationUnit ( File* file )
27 : project(NULL),
28 module(NULL),
29 node(NULL)
30 {
31 name = file->name;
32 files.push_back ( file );
33 }
34
35 CompilationUnit::CompilationUnit ( const Project* project,
36 const Module* module,
37 const XMLElement* node )
38 : project(project),
39 module(module),
40 node(node)
41 {
42 const XMLAttribute* att = node->GetAttribute ( "name", true );
43 assert(att);
44 name = module->GetBasePath () + cSep + att->value;
45 }
46
47 CompilationUnit::~CompilationUnit ()
48 {
49 size_t i;
50 for ( i = 0; i < files.size (); i++ )
51 delete files[i];
52 }
53
54 void
55 CompilationUnit::ProcessXML ()
56 {
57 size_t i;
58 for ( i = 0; i < files.size (); i++ )
59 files[i]->ProcessXML ();
60 }
61
62 bool
63 CompilationUnit::IsGeneratedFile () const
64 {
65 if ( files.size () != 1 )
66 return false;
67 File* file = files[0];
68 string extension = GetExtension ( file->name );
69 return ( extension == ".spec" || extension == ".SPEC" );
70 }
71
72 bool
73 CompilationUnit::HasFileWithExtension ( const std::string& extension ) const
74 {
75 size_t i;
76 for ( i = 0; i < files.size (); i++ )
77 {
78 File& file = *files[i];
79 string fileExtension = GetExtension ( file.name );
80 if ( !stricmp ( fileExtension.c_str (), extension.c_str () ) )
81 return true;
82 }
83 return false;
84 }
85
86 bool
87 CompilationUnit::IsFirstFile () const
88 {
89 if ( files.size () == 0 || files.size () > 1 )
90 return false;
91 File* file = files[0];
92 return file->first;
93 }
94
95 FileLocation*
96 CompilationUnit::GetFilename ( Directory* intermediateDirectory ) const
97 {
98 if ( files.size () == 0 || files.size () > 1 )
99 return new FileLocation ( intermediateDirectory, name );
100 File* file = files[0];
101 return new FileLocation ( NULL, file->name );
102 }
103
104 std::string
105 CompilationUnit::GetSwitches () const
106 {
107 if ( files.size () == 0 || files.size () > 1 )
108 return "";
109 File* file = files[0];
110 return file->switches;
111 }