2 * Copyright (C) 2005 Trevor McCort
3 * Copyright (C) 2005 Casper S. Hornstrup
4 * Copyright (C) 2005 Steven Edwards
5 * Copyright (C) 2005 Royce Mitchell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #pragma warning ( disable : 4786 )
30 #include "../mingw/mingw.h"
34 static class MSVCFactory
: public Backend::Factory
38 MSVCFactory() : Factory("MSVC") {}
39 Backend
*operator() (Project
&project
,
40 Configuration
& configuration
)
42 return new MSVCBackend(project
, configuration
);
48 MSVCBackend::MSVCBackend(Project
&project
,
49 Configuration
& configuration
) : Backend(project
, configuration
)
54 void MSVCBackend::Process()
56 string
filename_sln ( ProjectNode
.name
);
57 string filename_rules
= "gccasm.rules";
59 if ( configuration
.VSProjectVersion
== "6.00" )
60 filename_sln
+= ".dsw";
62 filename_sln
+= ".sln";
64 m_rulesFile
= fopen ( filename_rules
.c_str(), "wb" );
67 _generate_rules_file ( m_rulesFile
);
69 fclose ( m_rulesFile
);
72 printf ( "Creating MSVC workspace: %s\n", filename_sln
.c_str() );
75 m_slnFile
= fopen ( filename_sln
.c_str(), "wb" );
79 printf ( "Could not create file '%s'.\n", filename_sln
.c_str() );
83 if ( configuration
.VSProjectVersion
== "6.00" )
84 _generate_wine_dsw ( m_slnFile
);
86 _generate_sln ( m_slnFile
);
92 void MSVCBackend::ProcessModules()
94 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
96 Module
&module
= *ProjectNode
.modules
[i
];
98 module
.guid
= _gen_guid();
100 if (configuration
.VSProjectVersion
== "6.00")
101 this->_generate_dsp ( module
);
103 this->_generate_vcproj ( module
);
106 /*for(size_t k = 0; k < module.non_if_data.files.size(); k++)
108 File &file = *module.non_if_data.files[k];
110 ProcessFile(file.name);
115 static bool FileExists(string
&filename
)
117 ifstream
file(filename
.c_str());
126 void MSVCBackend::ProcessFile(string
&filepath
)
128 // Remove the .\ at the start of the filenames
129 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
130 filepath
.erase(0, 2);
132 if(!FileExists(filepath
))
136 for(size_t i
= 0; i
< filepath
.length(); i
++)
138 if(filepath
[i
] == '\\')
142 // Remove the filename from the path
145 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
147 if(pos
!= string::npos
)
150 folder
.erase(pos
, folder
.length() - pos
);
154 fileUnit
.filename
= filepath
;
155 fileUnit
.folder
= folder
;
157 m_fileUnits
.push_back(fileUnit
);
165 bool MSVCBackend::CheckFolderAdded(string
&folder
)
167 for(size_t i
= 0; i
< m_folders
.size(); i
++)
169 if(m_folders
[i
] == folder
)
176 void MSVCBackend::AddFolders(string
&folder
)
178 // Check if this folder was already added. true if it was, false otherwise.
179 if(CheckFolderAdded(folder
))
182 m_folders
.push_back(folder
);
184 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
186 if(pos
== string::npos
)
189 folder
.erase(pos
, folder
.length() - pos
);
193 void MSVCBackend::OutputFolders()
196 m_devFile
<< "Folders=";
198 for(size_t i
= 0; i
< m_folders
.size(); i
++)
203 m_devFile
<< m_folders
[i
];
209 MSVCBackend::DspFileName ( const Module
& module
) const
212 ReplaceExtension ( module
.GetPath(), "_auto.dsp" )
217 MSVCBackend::VcprojFileName ( const Module
& module
) const
220 ReplaceExtension ( module
.GetPath(), "_auto.vcproj" )