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(), "w" );
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
;
101 // The MSVC build still needs the mingw backend.
104 printf ( "Done.\n" );
106 /*cout << "Don't expect the MSVC backend to work yet. "<< endl << endl;
108 if(get_key("yn","Would you like to configure for a Mingw build as well? (y/n)") == 'y')
110 exec = spawn_new(rbuild_mingw);
112 printf("\nError invoking rbuild\n");
116 void MSVCBackend::ProcessModules()
118 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
120 Module
&module
= *ProjectNode
.modules
[i
];
122 this->_generate_dsp ( module
);
124 /*for(size_t k = 0; k < module.non_if_data.files.size(); k++)
126 File &file = *module.non_if_data.files[k];
128 ProcessFile(file.name);
133 static bool FileExists(string
&filename
)
135 ifstream
file(filename
.c_str());
144 void MSVCBackend::ProcessFile(string
&filepath
)
146 // Remove the .\ at the start of the filenames
147 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
148 filepath
.erase(0, 2);
150 if(!FileExists(filepath
))
154 for(size_t i
= 0; i
< filepath
.length(); i
++)
156 if(filepath
[i
] == '\\')
160 // Remove the filename from the path
163 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
165 if(pos
!= string::npos
)
168 folder
.erase(pos
, folder
.length() - pos
);
172 fileUnit
.filename
= filepath
;
173 fileUnit
.folder
= folder
;
175 m_fileUnits
.push_back(fileUnit
);
183 bool MSVCBackend::CheckFolderAdded(string
&folder
)
185 for(size_t i
= 0; i
< m_folders
.size(); i
++)
187 if(m_folders
[i
] == folder
)
194 void MSVCBackend::AddFolders(string
&folder
)
196 // Check if this folder was already added. true if it was, false otherwise.
197 if(CheckFolderAdded(folder
))
200 m_folders
.push_back(folder
);
202 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
204 if(pos
== string::npos
)
207 folder
.erase(pos
, folder
.length() - pos
);
211 void MSVCBackend::OutputFolders()
214 m_devFile
<< "Folders=";
216 for(size_t i
= 0; i
< m_folders
.size(); i
++)
221 m_devFile
<< m_folders
[i
];
227 char get_key(char *valid
,char *prompt
)
232 if (prompt
) printf("%s ",prompt
);
234 while (ch
= getchar(), ch
== ' ' || ch
== '\t');
235 if (ch
== EOF
) exit(1);
236 if (!strchr(valid
,okay
= ch
)) okay
= 0;
237 while (ch
= getchar(), ch
!= '\n' && ch
!= EOF
);
238 if (ch
== EOF
) exit(1);
239 if (okay
) return okay
;
240 printf("Invalid input.\n");
244 bool spawn_new( const string
& cmd
)
246 string command
= ssprintf (
251 int exitcode
= system ( command
.c_str () );
252 return (exitcode
== 0);
256 MSVCBackend::DspFileName ( const Module
& module
) const
259 ReplaceExtension ( module
.GetPath(), ".dsp" )