fixed vcproj files for modules which do not use pch
[reactos.git] / reactos / tools / rbuild / backend / msvc / vcprojmaker.cpp
1 /*
2 * Copyright (C) 2002 Patrik Stridvall
3 * Copyright (C) 2005 Royce Mitchell III
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #ifdef _MSC_VER
21 #pragma warning ( disable : 4786 )
22 #endif//_MSC_VER
23
24 #include <string>
25 #include <vector>
26
27 #include <stdio.h>
28
29 #include "msvc.h"
30
31 using std::string;
32 using std::vector;
33
34 #ifdef OUT
35 #undef OUT
36 #endif//OUT
37
38 void
39 MSVCBackend::_generate_vcproj ( const Module& module )
40 {
41 size_t i;
42 // TODO FIXME wine hack?
43 //const bool wine = false;
44
45 string vcproj_file = VcprojFileName(module);
46 printf ( "Creating MSVC.NET project: '%s'\n", vcproj_file.c_str() );
47 FILE* OUT = fopen ( vcproj_file.c_str(), "wb" );
48
49 vector<string> imports;
50 for ( i = 0; i < module.non_if_data.libraries.size(); i++ )
51 {
52 imports.push_back ( module.non_if_data.libraries[i]->name );
53 }
54
55 string module_type = GetExtension(module.GetTargetName());
56 bool lib = (module.type == ObjectLibrary) || (module_type == ".lib") || (module_type == ".a");
57 bool dll = (module_type == ".dll") || (module_type == ".cpl");
58 bool exe = (module_type == ".exe");
59 bool sys = (module_type == ".sys");
60 // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?
61
62 bool console = exe && (module.type == Win32CUI);
63
64 // TODO FIXME - not sure if the count here is right...
65 int parts = 0;
66 const char* p = strpbrk ( vcproj_file.c_str(), "/\\" );
67 while ( p )
68 {
69 ++parts;
70 p = strpbrk ( p+1, "/\\" );
71 }
72 string msvc_wine_dir = "..";
73 while ( --parts )
74 msvc_wine_dir += "\\..";
75
76 string wine_include_dir = msvc_wine_dir + "\\include";
77
78 //$progress_current++;
79 //$output->progress("$dsp_file (file $progress_current of $progress_max)");
80
81 // TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?
82 string vcproj_path = module.GetBasePath();
83 vector<string> c_srcs, source_files, resource_files, includes, libraries, defines;
84 vector<const IfableData*> ifs_list;
85 ifs_list.push_back ( &module.project.non_if_data );
86 ifs_list.push_back ( &module.non_if_data );
87
88 // this is a define in MinGW w32api, but not Microsoft's headers
89 defines.push_back ( "_CRT_SECURE_NO_DEPRECATE" );
90 defines.push_back ( "_CRT_NON_CONFORMING_SWPRINTFS" );
91 defines.push_back ( "STDCALL=__stdcall" );
92
93 while ( ifs_list.size() )
94 {
95 const IfableData& data = *ifs_list.back();
96 ifs_list.pop_back();
97 // TODO FIXME - refactor needed - we're discarding if conditions
98 for ( i = 0; i < data.ifs.size(); i++ )
99 ifs_list.push_back ( &data.ifs[i]->data );
100 const vector<File*>& files = data.files;
101 for ( i = 0; i < files.size(); i++ )
102 {
103 // TODO FIXME - do we want the full path of the file here?
104 string file = string(".") + &files[i]->name[vcproj_path.size()];
105
106 source_files.push_back ( file );
107 if ( !stricmp ( Right(file,2).c_str(), ".c" ) )
108 c_srcs.push_back ( file );
109 if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
110 resource_files.push_back ( file );
111 }
112 const vector<Include*>& incs = data.includes;
113 for ( i = 0; i < incs.size(); i++ )
114 {
115 // explicitly omit win32api directories
116 if ( !strncmp(incs[i]->directory.c_str(), "w32api", 6 ) )
117 continue;
118
119 // explicitly omit include/wine directories
120 if ( !strncmp(incs[i]->directory.c_str(), "include\\wine", 12 ) )
121 continue;
122
123 string path = Path::RelativeFromDirectory (
124 incs[i]->directory,
125 module.GetBasePath() );
126 includes.push_back ( path );
127 }
128 const vector<Library*>& libs = data.libraries;
129 for ( i = 0; i < libs.size(); i++ )
130 {
131 libraries.push_back ( libs[i]->name + ".lib" );
132 }
133 const vector<Define*>& defs = data.defines;
134 for ( i = 0; i < defs.size(); i++ )
135 {
136 if ( defs[i]->value[0] )
137 defines.push_back ( defs[i]->name + "=" + defs[i]->value );
138 else
139 defines.push_back ( defs[i]->name );
140 }
141 }
142
143 vector<string> header_files;
144
145 bool no_cpp = true;
146 bool no_msvc_headers = true;
147
148 std::vector<std::string> cfgs;
149
150 cfgs.push_back ( "Debug" );
151 cfgs.push_back ( "Release" );
152 cfgs.push_back ( "Speed" );
153
154 if (!no_cpp)
155 {
156 std::vector<std::string> _cfgs;
157 for ( i = 0; i < cfgs.size(); i++ )
158 {
159 _cfgs.push_back ( cfgs[i] + " C" );
160 _cfgs.push_back ( cfgs[i] + " C++" );
161 }
162 cfgs.resize(0);
163 cfgs = _cfgs;
164 }
165
166 if (!no_msvc_headers)
167 {
168 std::vector<std::string> _cfgs;
169 for ( i = 0; i < cfgs.size(); i++ )
170 {
171 _cfgs.push_back ( cfgs[i] + " MSVC Headers" );
172 _cfgs.push_back ( cfgs[i] + " Wine Headers" );
173 }
174 cfgs.resize(0);
175 cfgs = _cfgs;
176 }
177
178 string default_cfg = cfgs.back();
179 string include_string;
180
181 fprintf ( OUT, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );
182 fprintf ( OUT, "<VisualStudioProject\r\n" );
183 fprintf ( OUT, "\tProjectType=\"Visual C++\"\r\n" );
184
185 if (configuration.VSProjectVersion.empty())
186 configuration.VSProjectVersion = MS_VS_DEF_VERSION;
187
188 fprintf ( OUT, "\tVersion=\"%s\"\r\n", configuration.VSProjectVersion.c_str() );
189 fprintf ( OUT, "\tName=\"%s\"\r\n", module.name.c_str() );
190 fprintf ( OUT, "\tProjectGUID=\"%s\"\r\n", module.guid.c_str() );
191 fprintf ( OUT, "\tKeyword=\"Win32Proj\">\r\n" );
192
193 fprintf ( OUT, "\t<Platforms>\r\n" );
194 fprintf ( OUT, "\t\t<Platform\r\n" );
195 fprintf ( OUT, "\t\t\tName=\"Win32\"/>\r\n" );
196 fprintf ( OUT, "\t</Platforms>\r\n" );
197
198 fprintf ( OUT, "\t<ToolFiles>\r\n" );
199 fprintf ( OUT, "\t\t<ToolFile\r\n" );
200
201 string path = Path::RelativeFromDirectory ( ProjectNode.name, module.GetBasePath() );
202 path.erase(path.find(ProjectNode.name, 0), ProjectNode.name.size() + 1);
203
204 fprintf ( OUT, "\t\t\tRelativePath=\"%sgccasm.rules\"/>\r\n", path.c_str() );
205 fprintf ( OUT, "\t</ToolFiles>\r\n" );
206
207 int n = 0;
208
209 std::string output_dir;
210
211 fprintf ( OUT, "\t<Configurations>\r\n" );
212 for ( size_t icfg = 0; icfg < cfgs.size(); icfg++ )
213 {
214 std::string& cfg = cfgs[icfg];
215
216 bool debug = strstr ( cfg.c_str(), "Debug" );
217 bool speed = strstr ( cfg.c_str(), "Speed" );
218 bool release = (!debug && !speed );
219
220 //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
221
222 fprintf ( OUT, "\t\t<Configuration\r\n" );
223 fprintf ( OUT, "\t\t\tName=\"%s|Win32\"\r\n", cfg.c_str() );
224 fprintf ( OUT, "\t\t\tOutputDirectory=\"%s\"\r\n", cfg.c_str() );
225 fprintf ( OUT, "\t\t\tIntermediateDirectory=\"%s\"\r\n", cfg.c_str() );
226 fprintf ( OUT, "\t\t\tConfigurationType=\"%d\"\r\n", exe ? 1 : dll ? 2 : lib ? 4 : -1 );
227 fprintf ( OUT, "\t\t\tCharacterSet=\"2\">\r\n" );
228
229 fprintf ( OUT, "\t\t\t<Tool\r\n" );
230 fprintf ( OUT, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
231 fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", release ? 2 : 0 );
232
233 fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );
234 bool multiple_includes = false;
235 fprintf ( OUT, "./;" );
236 for ( i = 0; i < includes.size(); i++ )
237 {
238 const string& include = includes[i];
239 if ( strcmp ( include.c_str(), "." ) )
240 {
241 if ( multiple_includes )
242 fprintf ( OUT, ";" );
243
244 fprintf ( OUT, "%s", include.c_str() );
245 include_string += " /I " + include;
246 multiple_includes = true;
247 }
248 }
249 fprintf ( OUT, "\"\r\n " );
250
251 if ( debug )
252 {
253 defines.push_back ( "_DEBUG" );
254 }
255 else
256 {
257 defines.push_back ( "NDEBUG" );
258 }
259
260 if ( lib || exe )
261 {
262 defines.push_back ( "_LIB" );
263 }
264 else
265 {
266 defines.push_back ( "_WINDOWS" );
267 defines.push_back ( "_USRDLL" );
268 }
269
270 fprintf ( OUT, "\t\t\t\tPreprocessorDefinitions=\"" );
271 for ( i = 0; i < defines.size(); i++ )
272 {
273 if ( i > 0 )
274 fprintf ( OUT, ";" );
275
276 defines[i] = _replace_str(defines[i], "\"","&quot;");
277 fprintf ( OUT, "%s", defines[i].c_str() );
278 }
279 fprintf ( OUT, "\"\r\n" );
280
281 fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );
282 fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"%s\"\r\n", debug ? "3" : "0" );
283 fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
284 fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
285 fprintf ( OUT, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
286
287 if ( module.pch != NULL )
288 {
289 fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"2\"\r\n" );
290 string pch_path = Path::RelativeFromDirectory (
291 module.pch->file.name,
292 module.GetBasePath() );
293 fprintf ( OUT, "\t\t\t\tPrecompiledHeaderThrough=\"%s\"\r\n", pch_path.c_str() );
294 }
295 else
296 {
297 fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );
298 }
299
300 fprintf ( OUT, "\t\t\t\tWholeProgramOptimization=\"%s\"\r\n", release ? "TRUE" : "FALSE");
301 if ( release )
302 {
303 fprintf ( OUT, "\t\t\t\tFavorSizeOrSpeed=\"1\"\r\n" );
304 fprintf ( OUT, "\t\t\t\tStringPooling=\"true\"\r\n" );
305 }
306
307 fprintf ( OUT, "\t\t\t\tEnablePREfast=\"%s\"\r\n", debug ? "TRUE" : "FALSE");
308 fprintf ( OUT, "\t\t\t\tDisableSpecificWarnings=\"4201;4127\"\r\n" );
309 fprintf ( OUT, "\t\t\t\tWarningLevel=\"%s\"\r\n", release ? "0" : "4" );
310 fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"%s\"\r\n", release ? "FALSE" : "TRUE");
311 fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"%s\"/>\r\n", speed ? "0" : "4");
312
313 fprintf ( OUT, "\t\t\t<Tool\r\n" );
314 fprintf ( OUT, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
315
316 if ( lib )
317 {
318 fprintf ( OUT, "\t\t\t<Tool\r\n" );
319 fprintf ( OUT, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );
320 fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s.lib\"/>\r\n", module.name.c_str() );
321 }
322 else
323 {
324 fprintf ( OUT, "\t\t\t<Tool\r\n" );
325 fprintf ( OUT, "\t\t\t\tName=\"VCLinkerTool\"\r\n" );
326
327 fprintf ( OUT, "\t\t\t\tAdditionalDependencies=\"" );
328 for ( i = 0; i < libraries.size(); i++ )
329 {
330 if ( i > 0 )
331 fprintf ( OUT, " " );
332 fprintf ( OUT, "%s", libraries[i].c_str() );
333 }
334 fprintf ( OUT, "\"\r\n" );
335
336 fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module.name.c_str(), module_type.c_str() );
337 fprintf ( OUT, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug ? 2 : 1 );
338 fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );
339
340 if ( debug )
341 fprintf ( OUT, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module.name.c_str() );
342
343 if ( sys )
344 {
345 fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /DRIVER /ALIGN:0x20 /SUBSYSTEM:NATIVE /SECTION:INIT,D /NODEFAULTLIB /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );
346 fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
347 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DriverEntry" : module.entrypoint.c_str ());
348 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress == "" ? "0x10000" : module.baseaddress.c_str ());
349 }
350 else if ( exe )
351 {
352 if ( module.type == Kernel )
353 {
354 fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /SECTION:INIT,D /ALIGN:0x80\"\r\n" );
355 fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
356 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"KiSystemStartup\"\r\n" );
357 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress.c_str ());
358 }
359 else if ( module.type == NativeCUI )
360 {
361 fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /NODEFAULTLIB /ALIGN:0x20\"\r\n" );
362 fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
363 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"NtProcessStartup\"\r\n" );
364 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress.c_str ());
365 }
366 else if ( module.type == Win32CUI || module.type == Win32GUI )
367 {
368 fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );
369 }
370 }
371 else if ( dll )
372 {
373 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DllMain" : module.entrypoint.c_str ());
374 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress == "" ? "0x40000" : module.baseaddress.c_str ());
375 }
376 fprintf ( OUT, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );
377 }
378
379 fprintf ( OUT, "\t\t\t<Tool\r\n" );
380 fprintf ( OUT, "\t\t\t\tName=\"VCResourceCompilerTool\"\r\n" );
381 fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );
382 multiple_includes = false;
383 fprintf ( OUT, "./;" );
384 for ( i = 0; i < includes.size(); i++ )
385 {
386 const string& include = includes[i];
387 if ( strcmp ( include.c_str(), "." ) )
388 {
389 if ( multiple_includes )
390 fprintf ( OUT, ";" );
391 fprintf ( OUT, "%s", include.c_str() );
392 multiple_includes = true;
393 }
394 }
395 fprintf ( OUT, "\"/>\r\n " );
396
397 fprintf ( OUT, "\t\t\t<Tool\r\n" );
398 fprintf ( OUT, "\t\t\t\tName=\"VCMIDLTool\"/>\r\n" );
399 fprintf ( OUT, "\t\t\t<Tool\r\n" );
400 fprintf ( OUT, "\t\t\t\tName=\"VCPostBuildEventTool\"/>\r\n" );
401 fprintf ( OUT, "\t\t\t<Tool\r\n" );
402 fprintf ( OUT, "\t\t\t\tName=\"VCPreBuildEventTool\"/>\r\n" );
403 fprintf ( OUT, "\t\t\t<Tool\r\n" );
404 fprintf ( OUT, "\t\t\t\tName=\"VCPreLinkEventTool\"/>\r\n" );
405 fprintf ( OUT, "\t\t\t<Tool\r\n" );
406 fprintf ( OUT, "\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\r\n" );
407 fprintf ( OUT, "\t\t\t<Tool\r\n" );
408 fprintf ( OUT, "\t\t\t\tName=\"VCWebDeploymentTool\"/>\r\n" );
409 fprintf ( OUT, "\t\t</Configuration>\r\n" );
410
411 n++;
412 }
413 fprintf ( OUT, "\t</Configurations>\r\n" );
414
415 fprintf ( OUT, "\t<Files>\r\n" );
416
417 // Source files
418 fprintf ( OUT, "\t\t<Filter\r\n" );
419 fprintf ( OUT, "\t\t\tName=\"Source Files\"\r\n" );
420 fprintf ( OUT, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;S\">\r\n" );
421 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
422 {
423 string source_file = DosSeparator(source_files[isrcfile]);
424 fprintf ( OUT, "\t\t\t<File\r\n" );
425 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file.c_str() );
426
427 for ( size_t iconfig = 0; iconfig < cfgs.size(); iconfig++ )
428 {
429 std::string& config = cfgs[iconfig];
430
431 if (( isrcfile == 0 ) && ( module.pch != NULL ))
432 {
433 /* little hack to speed up PCH */
434 fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );
435 fprintf ( OUT, "\t\t\t\t\tName=\"" );
436 fprintf ( OUT, config.c_str() );
437 fprintf ( OUT, "|Win32\">\r\n" );
438 fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );
439 fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
440 fprintf ( OUT, "\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\r\n" );
441 fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );
442 }
443
444 if (configuration.VSProjectVersion < "8.00") {
445 if ((source_file.find(".idl") != string::npos) || ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's')))
446 {
447 fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );
448 fprintf ( OUT, "\t\t\t\t\tName=\"" );
449 fprintf ( OUT, config.c_str() );
450 fprintf ( OUT, "|Win32\">\r\n" );
451 fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );
452 if (source_file.find(".idl") != string::npos)
453 {
454 fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
455 fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );
456 }
457 else if ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's'))
458 {
459 fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
460 fprintf ( OUT, "\t\t\t\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; %s /D__ASM__ | as -o &quot;$(OutDir)\\(InputName).obj&quot;\"\r\n",include_string.c_str() );
461 fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );
462 }
463 fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );
464 }
465 }
466 }
467 fprintf ( OUT, "\t\t\t</File>\r\n" );
468 }
469 fprintf ( OUT, "\t\t</Filter>\r\n" );
470
471 // Header files
472 fprintf ( OUT, "\t\t<Filter\r\n" );
473 fprintf ( OUT, "\t\t\tName=\"Header Files\"\r\n" );
474 fprintf ( OUT, "\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\r\n" );
475 for ( i = 0; i < header_files.size(); i++ )
476 {
477 const string& header_file = header_files[i];
478 fprintf ( OUT, "\t\t\t<File\r\n" );
479 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", header_file.c_str() );
480 fprintf ( OUT, "\t\t\t</File>\r\n" );
481 }
482 fprintf ( OUT, "\t\t</Filter>\r\n" );
483
484 // Resource files
485 fprintf ( OUT, "\t\t<Filter\r\n" );
486 fprintf ( OUT, "\t\t\tName=\"Resource Files\"\r\n" );
487 fprintf ( OUT, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );
488 for ( i = 0; i < header_files.size(); i++ )
489 {
490 const string& resource_file = resource_files[i];
491 fprintf ( OUT, "\t\t\t<File\r\n" );
492 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", resource_file.c_str() );
493 fprintf ( OUT, "\t\t\t</File>\r\n" );
494 }
495 fprintf ( OUT, "\t\t</Filter>\r\n" );
496
497 fprintf ( OUT, "\t</Files>\r\n" );
498 fprintf ( OUT, "\t<Globals>\r\n" );
499 fprintf ( OUT, "\t</Globals>\r\n" );
500 fprintf ( OUT, "</VisualStudioProject>\r\n" );
501 fclose(OUT);
502 }
503
504 std::string
505 MSVCBackend::_replace_str(std::string string1, const std::string &find_str, const std::string &replace_str)
506 {
507 std::string::size_type pos = string1.find(find_str, 0);
508 int intLen = find_str.length();
509
510 while(std::string::npos != pos)
511 {
512 string1.replace(pos, intLen, replace_str);
513 pos = string1.find(find_str, intLen + pos);
514 }
515
516 return string1;
517 }
518
519 std::string
520 MSVCBackend::_get_solution_verion ( void ) {
521 string version;
522
523 if (configuration.VSProjectVersion.empty())
524 configuration.VSProjectVersion = MS_VS_DEF_VERSION;
525
526 if (configuration.VSProjectVersion == "7.00")
527 version = "7.00";
528
529 if (configuration.VSProjectVersion == "7.10")
530 version = "8.00";
531
532 if (configuration.VSProjectVersion == "8.00")
533 version = "9.00";
534
535 return version;
536 }
537
538
539 void
540 MSVCBackend::_generate_rules_file ( FILE* OUT )
541 {
542 fprintf ( OUT, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" );
543 fprintf ( OUT, "<VisualStudioToolFile\r\n" );
544 fprintf ( OUT, "\tName=\"GCC Assembler\"\r\n" );
545 fprintf ( OUT, "\tVersion=\"%s\"\r\n", _get_solution_verion().c_str() );
546 fprintf ( OUT, "\t>\r\n" );
547 fprintf ( OUT, "\t<Rules>\r\n" );
548 fprintf ( OUT, "\t\t<CustomBuildRule\r\n" );
549 fprintf ( OUT, "\t\t\tName=\"Assembler\"\r\n" );
550 fprintf ( OUT, "\t\t\tDisplayName=\"Assembler Files\"\r\n" );
551 fprintf ( OUT, "\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n" );
552 fprintf ( OUT, "\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"\r\n" );
553 fprintf ( OUT, "\t\t\tFileExtensions=\"*.S\"\r\n" );
554 fprintf ( OUT, "\t\t\tExecutionDescription=\"asm\"\r\n" );
555 fprintf ( OUT, "\t\t\t>\r\n" );
556 fprintf ( OUT, "\t\t\t<Properties>\r\n" );
557 fprintf ( OUT, "\t\t\t</Properties>\r\n" );
558 fprintf ( OUT, "\t\t</CustomBuildRule>\r\n" );
559 fprintf ( OUT, "\t</Rules>\r\n" );
560 fprintf ( OUT, "</VisualStudioToolFile>\r\n" );
561 }
562
563 void
564 MSVCBackend::_generate_sln_header ( FILE* OUT )
565 {
566 fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", _get_solution_verion().c_str() );
567 fprintf ( OUT, "# Visual Studio 2005\r\n" );
568 fprintf ( OUT, "\r\n" );
569 }
570
571
572 void
573 MSVCBackend::_generate_sln_project (
574 FILE* OUT,
575 const Module& module,
576 std::string vcproj_file,
577 std::string sln_guid,
578 std::string vcproj_guid,
579 const std::vector<Dependency*>& dependencies )
580 {
581 vcproj_file = DosSeparator ( std::string(".\\") + vcproj_file );
582
583 fprintf ( OUT, "Project(\"%s\") = \"%s\", \"%s\", \"%s\"\r\n", sln_guid.c_str() , module.name.c_str(), vcproj_file.c_str(), vcproj_guid.c_str() );
584
585 //FIXME: only omit ProjectDependencies in VS 2005 when there are no dependencies
586 //NOTE: VS 2002 do not use ProjectSection; it uses GlobalSection instead
587 if ((configuration.VSProjectVersion == "7.10") || (dependencies.size() > 0)) {
588 fprintf ( OUT, "\tProjectSection(ProjectDependencies) = postProject\r\n" );
589 for ( size_t i = 0; i < dependencies.size(); i++ )
590 {
591 Dependency& dependency = *dependencies[i];
592 fprintf ( OUT, "\t\t%s = %s\r\n", dependency.module.guid.c_str(), dependency.module.guid.c_str() );
593 }
594 fprintf ( OUT, "\tEndProjectSection\r\n" );
595 }
596
597 fprintf ( OUT, "EndProject\r\n" );
598 }
599
600
601 void
602 MSVCBackend::_generate_sln_footer ( FILE* OUT )
603 {
604 fprintf ( OUT, "Global\r\n" );
605 fprintf ( OUT, "\tGlobalSection(SolutionConfiguration) = preSolution\r\n" );
606 fprintf ( OUT, "\t\tDebug = Debug\r\n" );
607 fprintf ( OUT, "\t\tRelease = Release\r\n" );
608 fprintf ( OUT, "\tEndGlobalSection\r\n" );
609 fprintf ( OUT, "\tGlobalSection(ProjectConfiguration) = postSolution\r\n" );
610 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
611 {
612 Module& module = *ProjectNode.modules[i];
613 std::string guid = module.guid;
614 _generate_sln_configurations ( OUT, guid.c_str() );
615 }
616 fprintf ( OUT, "\tEndGlobalSection\r\n" );
617 fprintf ( OUT, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );
618 fprintf ( OUT, "\tEndGlobalSection\r\n" );
619 fprintf ( OUT, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );
620 fprintf ( OUT, "\tEndGlobalSection\r\n" );
621
622 if (configuration.VSProjectVersion == "7.00") {
623 fprintf ( OUT, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );
624 //FIXME: Add dependencies for VS 2002
625 fprintf ( OUT, "\tEndGlobalSection\r\n" );
626 }
627
628 if (configuration.VSProjectVersion == "8.00") {
629 fprintf ( OUT, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );
630 fprintf ( OUT, "\t\tHideSolutionNode = FALSE\r\n" );
631 fprintf ( OUT, "\tEndGlobalSection\r\n" );
632 }
633
634 fprintf ( OUT, "EndGlobal\r\n" );
635 fprintf ( OUT, "\r\n" );
636 }
637
638
639 void
640 MSVCBackend::_generate_sln_configurations ( FILE* OUT, std::string vcproj_guid )
641 {
642 fprintf ( OUT, "\t\t%s.Debug.ActiveCfg = Debug|Win32\r\n", vcproj_guid.c_str() );
643 fprintf ( OUT, "\t\t%s.Debug.Build.0 = Debug|Win32\r\n", vcproj_guid.c_str() );
644 fprintf ( OUT, "\t\t%s.Debug.Release.ActiveCfg = Release|Win32\r\n", vcproj_guid.c_str() );
645 fprintf ( OUT, "\t\t%s.Debug.Release.Build.0 = Release|Win32\r\n", vcproj_guid.c_str() );
646 }
647
648 void
649 MSVCBackend::_generate_sln ( FILE* OUT )
650 {
651 string sln_guid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
652 vector<string> guids;
653
654 _generate_sln_header(OUT);
655 // TODO FIXME - is it necessary to sort them?
656 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
657 {
658 Module& module = *ProjectNode.modules[i];
659
660 std::string vcproj_file = VcprojFileName ( module );
661 _generate_sln_project ( OUT, module, vcproj_file, sln_guid, module.guid, module.dependencies );
662 }
663 _generate_sln_footer ( OUT );
664 }
665