4ddc2a117b6327d07052bf8468b9ec587a3e4751
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_dsw
= ProjectNode
.name
+ ".dsw";
57 string filename_sln
= ProjectNode
.name
+ ".sln";
59 printf ( "Creating MSVC workspace: %s\n", filename_dsw
.c_str() );
60 printf ( "Creating MSVC workspace: %s\n", filename_sln
.c_str() );
64 m_dswFile
= fopen ( filename_dsw
.c_str(), "wb" );
65 m_slnFile
= fopen ( filename_sln
.c_str(), "wb" );
69 printf ( "Could not create file '%s'.\n", filename_dsw
.c_str() );
72 _generate_wine_dsw ( m_dswFile
);
77 printf ( "Could not create file '%s'.\n", filename_sln
.c_str() );
80 _generate_sln ( m_slnFile
);
88 void MSVCBackend::ProcessModules()
90 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
92 Module
&module
= *ProjectNode
.modules
[i
];
94 module
.guid
= _gen_guid();
96 if (configuration
.VSProjectVersion
== "6.00")
97 this->_generate_dsp ( module
);
99 this->_generate_vcproj ( module
);
102 /*for(size_t k = 0; k < module.non_if_data.files.size(); k++)
104 File &file = *module.non_if_data.files[k];
106 ProcessFile(file.name);
111 static bool FileExists(string
&filename
)
113 ifstream
file(filename
.c_str());
122 void MSVCBackend::ProcessFile(string
&filepath
)
124 // Remove the .\ at the start of the filenames
125 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
126 filepath
.erase(0, 2);
128 if(!FileExists(filepath
))
132 for(size_t i
= 0; i
< filepath
.length(); i
++)
134 if(filepath
[i
] == '\\')
138 // Remove the filename from the path
141 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
143 if(pos
!= string::npos
)
146 folder
.erase(pos
, folder
.length() - pos
);
150 fileUnit
.filename
= filepath
;
151 fileUnit
.folder
= folder
;
153 m_fileUnits
.push_back(fileUnit
);
161 bool MSVCBackend::CheckFolderAdded(string
&folder
)
163 for(size_t i
= 0; i
< m_folders
.size(); i
++)
165 if(m_folders
[i
] == folder
)
172 void MSVCBackend::AddFolders(string
&folder
)
174 // Check if this folder was already added. true if it was, false otherwise.
175 if(CheckFolderAdded(folder
))
178 m_folders
.push_back(folder
);
180 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
182 if(pos
== string::npos
)
185 folder
.erase(pos
, folder
.length() - pos
);
189 void MSVCBackend::OutputFolders()
192 m_devFile
<< "Folders=";
194 for(size_t i
= 0; i
< m_folders
.size(); i
++)
199 m_devFile
<< m_folders
[i
];
205 MSVCBackend::DspFileName ( const Module
& module
) const
208 ReplaceExtension ( module
.GetPath(), ".dsp" )
213 MSVCBackend::VcprojFileName ( const Module
& module
) const
216 ReplaceExtension ( module
.GetPath(), ".vcproj" )