7b0a5fe2b60da3b2131d789f152c9f6a69fc98f5
2 * Copyright (C) 2005 Trevor McCort
3 * Copyright (C) 2005 Casper S. Hornstrup
4 * Copyright (C) 2005 Steven Edwards
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #pragma warning ( disable : 4786 )
29 #include "../mingw/mingw.h"
33 char get_key(char *valid
,char *prompt
); //FIXME
34 bool spawn_new(const string
& cmd
); //FIXME
37 static class MSVCFactory
: public Backend::Factory
41 MSVCFactory() : Factory("MSVC") {}
42 Backend
*operator() (Project
&project
,
43 Configuration
& configuration
)
45 return new MSVCBackend(project
, configuration
);
51 MSVCBackend::MSVCBackend(Project
&project
,
52 Configuration
& configuration
) : Backend(project
, configuration
)
57 void MSVCBackend::Process()
60 //const char rbuild_mingw[] = "output-i386\\tools\\rbuild\\rbuild.exe mingw";
62 string filename
= ProjectNode
.name
+ ".dsw";
64 printf ( "Creating MSVC workspace: %s\n", filename
.c_str() );
68 m_dswFile
= fopen ( filename
.c_str(), "wb" );
72 printf ( "Could not create file '%s'.\n", filename
.c_str() );
75 _generate_wine_dsw ( m_dswFile
);
77 m_devFile
<< "Microsoft Visual Studio Solution File, Format Version 9.00" << endl
;
78 m_devFile
<< "# Visual C++ Express 2005" << endl
;
80 m_devFile
<< "# FIXME Project listings here" << endl
;
81 m_devFile
<< "EndProject" << endl
;
82 m_devFile
<< "Global" << endl
;
83 m_devFile
<< " GlobalSection(SolutionConfigurationPlatforms) = preSolution" << endl
;
84 m_devFile
<< " Debug|Win32 = Debug|Win32" << endl
;
85 m_devFile
<< " Release|Win32 = Release|Win32" << endl
;
86 m_devFile
<< " EndGlobalSection" << endl
;
87 m_devFile
<< " GlobalSection(ProjectConfigurationPlatforms) = postSolution" << endl
;
88 m_devFile
<< " #FIXME Project Listings Here" << endl
;
89 m_devFile
<< " EndGlobalSection" << endl
;
90 m_devFile
<< " GlobalSection(SolutionProperties) = preSolution" << endl
;
91 m_devFile
<< " HideSolutionNode = FALSE" << endl
;
92 m_devFile
<< " EndGlobalSection" << endl
;
93 m_devFile
<< "EndGlobal" << endl
;
95 m_devFile
<< endl
<< endl
;
99 // The MSVC build still needs the mingw backend.
102 printf ( "Done.\n" );
104 /*cout << "Don't expect the MSVC backend to work yet. "<< endl << endl;
106 if(get_key("yn","Would you like to configure for a Mingw build as well? (y/n)") == 'y')
108 exec = spawn_new(rbuild_mingw);
110 printf("\nError invoking rbuild\n");
114 void MSVCBackend::ProcessModules()
116 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
118 Module
&module
= *ProjectNode
.modules
[i
];
120 this->_generate_dsp ( module
);
123 /*for(size_t k = 0; k < module.non_if_data.files.size(); k++)
125 File &file = *module.non_if_data.files[k];
127 ProcessFile(file.name);
132 static bool FileExists(string
&filename
)
134 ifstream
file(filename
.c_str());
143 void MSVCBackend::ProcessFile(string
&filepath
)
145 // Remove the .\ at the start of the filenames
146 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
147 filepath
.erase(0, 2);
149 if(!FileExists(filepath
))
153 for(size_t i
= 0; i
< filepath
.length(); i
++)
155 if(filepath
[i
] == '\\')
159 // Remove the filename from the path
162 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
164 if(pos
!= string::npos
)
167 folder
.erase(pos
, folder
.length() - pos
);
171 fileUnit
.filename
= filepath
;
172 fileUnit
.folder
= folder
;
174 m_fileUnits
.push_back(fileUnit
);
182 bool MSVCBackend::CheckFolderAdded(string
&folder
)
184 for(size_t i
= 0; i
< m_folders
.size(); i
++)
186 if(m_folders
[i
] == folder
)
193 void MSVCBackend::AddFolders(string
&folder
)
195 // Check if this folder was already added. true if it was, false otherwise.
196 if(CheckFolderAdded(folder
))
199 m_folders
.push_back(folder
);
201 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
203 if(pos
== string::npos
)
206 folder
.erase(pos
, folder
.length() - pos
);
210 void MSVCBackend::OutputFolders()
213 m_devFile
<< "Folders=";
215 for(size_t i
= 0; i
< m_folders
.size(); i
++)
220 m_devFile
<< m_folders
[i
];
226 char get_key(char *valid
,char *prompt
)
231 if (prompt
) printf("%s ",prompt
);
233 while (ch
= getchar(), ch
== ' ' || ch
== '\t');
234 if (ch
== EOF
) exit(1);
235 if (!strchr(valid
,okay
= ch
)) okay
= 0;
236 while (ch
= getchar(), ch
!= '\n' && ch
!= EOF
);
237 if (ch
== EOF
) exit(1);
238 if (okay
) return okay
;
239 printf("Invalid input.\n");
243 bool spawn_new( const string
& cmd
)
245 string command
= ssprintf (
250 int exitcode
= system ( command
.c_str () );
251 return (exitcode
== 0);
255 MSVCBackend::DspFileName ( const Module
& module
) const
258 ReplaceExtension ( module
.GetPath(), ".dsp" )