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 if ( configuration
.VSProjectVersion
== "6.00" )
58 filename_sln
+= ".dsw";
60 filename_sln
+= ".sln";
61 printf ( "Creating MSVC workspace: %s\n", filename_sln
.c_str() );
64 m_slnFile
= fopen ( filename_sln
.c_str(), "wb" );
68 printf ( "Could not create file '%s'.\n", filename_sln
.c_str() );
72 if ( configuration
.VSProjectVersion
== "6.00" )
73 _generate_wine_dsw ( m_slnFile
);
75 _generate_sln ( m_slnFile
);
81 void MSVCBackend::ProcessModules()
83 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
85 Module
&module
= *ProjectNode
.modules
[i
];
87 module
.guid
= _gen_guid();
89 if (configuration
.VSProjectVersion
== "6.00")
90 this->_generate_dsp ( module
);
92 this->_generate_vcproj ( module
);
95 /*for(size_t k = 0; k < module.non_if_data.files.size(); k++)
97 File &file = *module.non_if_data.files[k];
99 ProcessFile(file.name);
104 static bool FileExists(string
&filename
)
106 ifstream
file(filename
.c_str());
115 void MSVCBackend::ProcessFile(string
&filepath
)
117 // Remove the .\ at the start of the filenames
118 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
119 filepath
.erase(0, 2);
121 if(!FileExists(filepath
))
125 for(size_t i
= 0; i
< filepath
.length(); i
++)
127 if(filepath
[i
] == '\\')
131 // Remove the filename from the path
134 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
136 if(pos
!= string::npos
)
139 folder
.erase(pos
, folder
.length() - pos
);
143 fileUnit
.filename
= filepath
;
144 fileUnit
.folder
= folder
;
146 m_fileUnits
.push_back(fileUnit
);
154 bool MSVCBackend::CheckFolderAdded(string
&folder
)
156 for(size_t i
= 0; i
< m_folders
.size(); i
++)
158 if(m_folders
[i
] == folder
)
165 void MSVCBackend::AddFolders(string
&folder
)
167 // Check if this folder was already added. true if it was, false otherwise.
168 if(CheckFolderAdded(folder
))
171 m_folders
.push_back(folder
);
173 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
175 if(pos
== string::npos
)
178 folder
.erase(pos
, folder
.length() - pos
);
182 void MSVCBackend::OutputFolders()
185 m_devFile
<< "Folders=";
187 for(size_t i
= 0; i
< m_folders
.size(); i
++)
192 m_devFile
<< m_folders
[i
];
198 MSVCBackend::DspFileName ( const Module
& module
) const
201 ReplaceExtension ( module
.GetPath(), ".dsp" )
206 MSVCBackend::VcprojFileName ( const Module
& module
) const
209 ReplaceExtension ( module
.GetPath(), ".vcproj" )