added more correct linker flags (patch by brezenbak)
[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 ( "STDCALL=__stdcall" );
90
91 while ( ifs_list.size() )
92 {
93 const IfableData& data = *ifs_list.back();
94 ifs_list.pop_back();
95 // TODO FIXME - refactor needed - we're discarding if conditions
96 for ( i = 0; i < data.ifs.size(); i++ )
97 ifs_list.push_back ( &data.ifs[i]->data );
98 const vector<File*>& files = data.files;
99 for ( i = 0; i < files.size(); i++ )
100 {
101 // TODO FIXME - do we want the full path of the file here?
102 string file = string(".") + &files[i]->name[vcproj_path.size()];
103
104 source_files.push_back ( file );
105 if ( !stricmp ( Right(file,2).c_str(), ".c" ) )
106 c_srcs.push_back ( file );
107 if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
108 resource_files.push_back ( file );
109 }
110 const vector<Include*>& incs = data.includes;
111 for ( i = 0; i < incs.size(); i++ )
112 {
113 // explicitly omit win32api directories
114 if ( !strncmp(incs[i]->directory.c_str(), "w32api", 6 ) )
115 continue;
116
117 // explicitly omit include/wine directories
118 if ( !strncmp(incs[i]->directory.c_str(), "include\\wine", 12 ) )
119 continue;
120
121 string path = Path::RelativeFromDirectory (
122 incs[i]->directory,
123 module.GetBasePath() );
124 includes.push_back ( path );
125 }
126 const vector<Library*>& libs = data.libraries;
127 for ( i = 0; i < libs.size(); i++ )
128 {
129 libraries.push_back ( libs[i]->name + ".lib" );
130 }
131 const vector<Define*>& defs = data.defines;
132 for ( i = 0; i < defs.size(); i++ )
133 {
134 if ( defs[i]->value[0] )
135 defines.push_back ( defs[i]->name + "=" + defs[i]->value );
136 else
137 defines.push_back ( defs[i]->name );
138 }
139 }
140
141 vector<string> header_files;
142
143 bool no_cpp = true;
144 bool no_msvc_headers = true;
145
146 std::vector<std::string> cfgs;
147
148 cfgs.push_back ( "Debug" );
149 cfgs.push_back ( "Release" );
150 cfgs.push_back ( "Speed" );
151
152 if (!no_cpp)
153 {
154 std::vector<std::string> _cfgs;
155 for ( i = 0; i < cfgs.size(); i++ )
156 {
157 _cfgs.push_back ( cfgs[i] + " C" );
158 _cfgs.push_back ( cfgs[i] + " C++" );
159 }
160 cfgs.resize(0);
161 cfgs = _cfgs;
162 }
163
164 if (!no_msvc_headers)
165 {
166 std::vector<std::string> _cfgs;
167 for ( i = 0; i < cfgs.size(); i++ )
168 {
169 _cfgs.push_back ( cfgs[i] + " MSVC Headers" );
170 _cfgs.push_back ( cfgs[i] + " Wine Headers" );
171 }
172 cfgs.resize(0);
173 cfgs = _cfgs;
174 }
175
176 string default_cfg = cfgs.back();
177 string include_string;
178
179 fprintf ( OUT, "<?xml version=\"1.0\" encoding = \"Windows-1252\"?>\r\n" );
180 fprintf ( OUT, "<VisualStudioProject\r\n" );
181 fprintf ( OUT, "\tProjectType=\"Visual C++\"\r\n" );
182
183 if (configuration.VSProjectVersion.empty())
184 configuration.VSProjectVersion = MS_VS_DEF_VERSION;
185
186 fprintf ( OUT, "\tVersion=\"%s\"\r\n", configuration.VSProjectVersion.c_str() );
187 fprintf ( OUT, "\tName=\"%s\"\r\n", module.name.c_str() );
188 fprintf ( OUT, "\tProjectGUID=\"%s\"\r\n", module.guid.c_str() );
189 fprintf ( OUT, "\tKeyword=\"Win32Proj\">\r\n" );
190
191 fprintf ( OUT, "\t<Platforms>\r\n" );
192 fprintf ( OUT, "\t\t<Platform\r\n" );
193 fprintf ( OUT, "\t\t\tName=\"Win32\"/>\r\n" );
194 fprintf ( OUT, "\t</Platforms>\r\n" );
195
196 fprintf ( OUT, "\t<ToolFiles>\r\n" );
197 fprintf ( OUT, "\t\t<ToolFile\r\n" );
198
199 string path = Path::RelativeFromDirectory ( ProjectNode.name, module.GetBasePath() );
200 path.erase(path.find(ProjectNode.name, 0), ProjectNode.name.size() + 1);
201
202 fprintf ( OUT, "\t\t\tRelativePath=\"%sgccasm.rules\"/>\r\n", path.c_str() );
203 fprintf ( OUT, "\t</ToolFiles>\r\n" );
204
205 int n = 0;
206
207 std::string output_dir;
208
209 fprintf ( OUT, "\t<Configurations>\r\n" );
210 for ( size_t icfg = 0; icfg < cfgs.size(); icfg++ )
211 {
212 std::string& cfg = cfgs[icfg];
213
214 bool debug = !strstr ( cfg.c_str(), "Release" );
215 //bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
216
217 fprintf ( OUT, "\t\t<Configuration\r\n" );
218 fprintf ( OUT, "\t\t\tName=\"%s|Win32\"\r\n", cfg.c_str() );
219 fprintf ( OUT, "\t\t\tOutputDirectory=\"%s\"\r\n", cfg.c_str() );
220 fprintf ( OUT, "\t\t\tIntermediateDirectory=\"%s\"\r\n", cfg.c_str() );
221 fprintf ( OUT, "\t\t\tConfigurationType=\"%d\"\r\n", exe ? 1 : dll ? 2 : lib ? 4 : -1 );
222 fprintf ( OUT, "\t\t\tCharacterSet=\"2\">\r\n" );
223
224 fprintf ( OUT, "\t\t\t<Tool\r\n" );
225 fprintf ( OUT, "\t\t\t\tName=\"VCCLCompilerTool\"\r\n" );
226 fprintf ( OUT, "\t\t\t\tOptimization=\"%d\"\r\n", debug ? 0 : 2 );
227
228 fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );
229 bool multiple_includes = false;
230 fprintf ( OUT, "./;" );
231 for ( i = 0; i < includes.size(); i++ )
232 {
233 const string& include = includes[i];
234 if ( strcmp ( include.c_str(), "." ) )
235 {
236 if ( multiple_includes )
237 fprintf ( OUT, ";" );
238
239 fprintf ( OUT, "%s", include.c_str() );
240 include_string += " /I " + include;
241 multiple_includes = true;
242 }
243 }
244 fprintf ( OUT, "\"\r\n " );
245
246 if ( debug )
247 {
248 defines.push_back ( "_DEBUG" );
249 if ( lib || exe )
250 {
251 defines.push_back ( "_LIB" );
252 }
253 else
254 {
255 defines.push_back ( "_WINDOWS" );
256 defines.push_back ( "_USRDLL" );
257 }
258 }
259 else
260 {
261 defines.push_back ( "NDEBUG" );
262 if ( lib || exe )
263 {
264 defines.push_back ( "_LIB" );
265 }
266 else
267 {
268 defines.push_back ( "_WINDOWS" );
269 defines.push_back ( "_USRDLL" );
270 }
271 }
272
273 fprintf ( OUT, "\t\t\t\tPreprocessorDefinitions=\"" );
274 for ( i = 0; i < defines.size(); i++ )
275 {
276 if ( i > 0 )
277 fprintf ( OUT, ";" );
278
279 defines[i] = _replace_str(defines[i], "\"","&quot;");
280 fprintf ( OUT, "%s", defines[i].c_str() );
281 }
282 fprintf ( OUT, "\"\r\n" );
283
284 fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"TRUE\"\r\n" );
285 fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"3\"\r\n" );
286 fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
287 fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
288 fprintf ( OUT, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
289 fprintf ( OUT, "\t\t\t\tUsePrecompiledHeader=\"0\"\r\n" );
290 fprintf ( OUT, "\t\t\t\tWarningLevel=\"1\"\r\n" );
291 fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"TRUE\"\r\n" );
292 fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"4\"/>\r\n" );
293
294 fprintf ( OUT, "\t\t\t<Tool\r\n" );
295 fprintf ( OUT, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
296
297 if ( lib )
298 {
299 fprintf ( OUT, "\t\t\t<Tool\r\n" );
300 fprintf ( OUT, "\t\t\t\tName=\"VCLibrarianTool\"\r\n" );
301 fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s.lib\"/>\r\n", module.name.c_str() );
302 }
303 else
304 {
305 fprintf ( OUT, "\t\t\t<Tool\r\n" );
306 fprintf ( OUT, "\t\t\t\tName=\"VCLinkerTool\"\r\n" );
307
308 fprintf ( OUT, "\t\t\t\tAdditionalDependencies=\"" );
309 for ( i = 0; i < libraries.size(); i++ )
310 {
311 if ( i > 0 )
312 fprintf ( OUT, " " );
313 fprintf ( OUT, "%s", libraries[i].c_str() );
314 }
315 fprintf ( OUT, "\"\r\n" );
316
317 fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module.name.c_str(), module_type.c_str() );
318 fprintf ( OUT, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug ? 2 : 1 );
319 fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"TRUE\"\r\n" );
320
321 if ( debug )
322 fprintf ( OUT, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module.name.c_str() );
323
324 if ( sys )
325 {
326 fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /DRIVER /ALIGN:0x20 /subsystem:NATIVE /SECTION:INIT,D /FORCE:MULTIPLE /IGNORE:4001,4037,4039,4065,4070,4078,4087,4089,4096\"\r\n" );
327 fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
328 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DriverEntry" : module.entrypoint.c_str ());
329 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress == "" ? "0x10000" : module.baseaddress.c_str ());
330 }
331 else if ( exe )
332 {
333 if ( module.type == Kernel || module.type == NativeCUI)
334 {
335 fprintf ( OUT, "\t\t\t\tAdditionalOptions=\" /SUBSYSTEM:NATIVE /SECTION:INIT,D /ALIGN:4096 /FORCE:MULTIPLE\"\r\n" );
336 fprintf ( OUT, "\t\t\t\tIgnoreAllDefaultLibraries=\"TRUE\"\r\n" );
337 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint.c_str ());
338 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress.c_str ());
339 }
340 else if ( module.type == Win32CUI || module.type == Win32GUI )
341 {
342 fprintf ( OUT, "\t\t\t\tSubSystem=\"%d\"\r\n", console ? 1 : 2 );
343 }
344 }
345 else if ( dll)
346 {
347 fprintf ( OUT, "\t\t\t\tEntryPointSymbol=\"%s\"\r\n", module.entrypoint == "" ? "DllMain" : module.entrypoint.c_str ());
348 fprintf ( OUT, "\t\t\t\tBaseAddress=\"%s\"\r\n", module.baseaddress == "" ? "0x40000" : module.baseaddress.c_str ());
349 }
350 fprintf ( OUT, "\t\t\t\tTargetMachine=\"%d\"/>\r\n", 1 );
351 }
352
353 fprintf ( OUT, "\t\t\t<Tool\r\n" );
354 fprintf ( OUT, "\t\t\t\tName=\"VCResourceCompilerTool\"\r\n" );
355 fprintf ( OUT, "\t\t\t\tAdditionalIncludeDirectories=\"" );
356 multiple_includes = false;
357 fprintf ( OUT, "./;" );
358 for ( i = 0; i < includes.size(); i++ )
359 {
360 const string& include = includes[i];
361 if ( strcmp ( include.c_str(), "." ) )
362 {
363 if ( multiple_includes )
364 fprintf ( OUT, ";" );
365 fprintf ( OUT, "%s", include.c_str() );
366 multiple_includes = true;
367 }
368 }
369 fprintf ( OUT, "\"/>\r\n " );
370
371 fprintf ( OUT, "\t\t\t<Tool\r\n" );
372 fprintf ( OUT, "\t\t\t\tName=\"VCMIDLTool\"/>\r\n" );
373 fprintf ( OUT, "\t\t\t<Tool\r\n" );
374 fprintf ( OUT, "\t\t\t\tName=\"VCPostBuildEventTool\"/>\r\n" );
375 fprintf ( OUT, "\t\t\t<Tool\r\n" );
376 fprintf ( OUT, "\t\t\t\tName=\"VCPreBuildEventTool\"/>\r\n" );
377 fprintf ( OUT, "\t\t\t<Tool\r\n" );
378 fprintf ( OUT, "\t\t\t\tName=\"VCPreLinkEventTool\"/>\r\n" );
379 fprintf ( OUT, "\t\t\t<Tool\r\n" );
380 fprintf ( OUT, "\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\r\n" );
381 fprintf ( OUT, "\t\t\t<Tool\r\n" );
382 fprintf ( OUT, "\t\t\t\tName=\"VCWebDeploymentTool\"/>\r\n" );
383 fprintf ( OUT, "\t\t</Configuration>\r\n" );
384
385 n++;
386 }
387 fprintf ( OUT, "\t</Configurations>\r\n" );
388
389 fprintf ( OUT, "\t<Files>\r\n" );
390
391 // Source files
392 fprintf ( OUT, "\t\t<Filter\r\n" );
393 fprintf ( OUT, "\t\t\tName=\"Source Files\"\r\n" );
394 fprintf ( OUT, "\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;S\">\r\n" );
395 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
396 {
397 string source_file = DosSeparator(source_files[isrcfile]);
398 fprintf ( OUT, "\t\t\t<File\r\n" );
399 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", source_file.c_str() );
400
401 if (configuration.VSProjectVersion < "8.00") {
402 for ( size_t iconfig = 0; iconfig < cfgs.size(); iconfig++ )
403 {
404 std::string& config = cfgs[iconfig];
405
406 if ((source_file.find(".idl") != string::npos) || ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's')))
407 {
408 fprintf ( OUT, "\t\t\t\t<FileConfiguration\r\n" );
409 fprintf ( OUT, "\t\t\t\t\tName=\"" );
410 fprintf ( OUT, config.c_str() );
411 fprintf ( OUT, "|Win32\">\r\n" );
412 fprintf ( OUT, "\t\t\t\t\t<Tool\r\n" );
413 if (source_file.find(".idl") != string::npos)
414 {
415 fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
416 fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );
417 }
418 else if ((source_file.find(".asm") != string::npos || tolower(source_file.at(source_file.size() - 1)) == 's'))
419 {
420 fprintf ( OUT, "\t\t\t\t\t\tName=\"VCCustomBuildTool\"\r\n" );
421 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() );
422 fprintf ( OUT, "\t\t\t\t\t\tOutputs=\"$(OutDir)\\(InputName).obj\"/>\r\n" );
423 }
424 fprintf ( OUT, "\t\t\t\t</FileConfiguration>\r\n" );
425 }
426 }
427 }
428 fprintf ( OUT, "\t\t\t</File>\r\n" );
429 }
430 fprintf ( OUT, "\t\t</Filter>\r\n" );
431
432 // Header files
433 fprintf ( OUT, "\t\t<Filter\r\n" );
434 fprintf ( OUT, "\t\t\tName=\"Header Files\"\r\n" );
435 fprintf ( OUT, "\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\r\n" );
436 for ( i = 0; i < header_files.size(); i++ )
437 {
438 const string& header_file = header_files[i];
439 fprintf ( OUT, "\t\t\t<File\r\n" );
440 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", header_file.c_str() );
441 fprintf ( OUT, "\t\t\t</File>\r\n" );
442 }
443 fprintf ( OUT, "\t\t</Filter>\r\n" );
444
445 // Resource files
446 fprintf ( OUT, "\t\t<Filter\r\n" );
447 fprintf ( OUT, "\t\t\tName=\"Resource Files\"\r\n" );
448 fprintf ( OUT, "\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\r\n" );
449 for ( i = 0; i < header_files.size(); i++ )
450 {
451 const string& resource_file = resource_files[i];
452 fprintf ( OUT, "\t\t\t<File\r\n" );
453 fprintf ( OUT, "\t\t\t\tRelativePath=\"%s\">\r\n", resource_file.c_str() );
454 fprintf ( OUT, "\t\t\t</File>\r\n" );
455 }
456 fprintf ( OUT, "\t\t</Filter>\r\n" );
457
458 fprintf ( OUT, "\t</Files>\r\n" );
459 fprintf ( OUT, "\t<Globals>\r\n" );
460 fprintf ( OUT, "\t</Globals>\r\n" );
461 fprintf ( OUT, "</VisualStudioProject>\r\n" );
462 fclose(OUT);
463 }
464
465 std::string
466 MSVCBackend::_replace_str(std::string string1, const std::string &find_str, const std::string &replace_str)
467 {
468 std::string::size_type pos = string1.find(find_str, 0);
469 int intLen = find_str.length();
470
471 while(std::string::npos != pos)
472 {
473 string1.replace(pos, intLen, replace_str);
474 pos = string1.find(find_str, intLen + pos);
475 }
476
477 return string1;
478 }
479
480 std::string
481 MSVCBackend::_get_solution_verion ( void ) {
482 string version;
483
484 if (configuration.VSProjectVersion.empty())
485 configuration.VSProjectVersion = MS_VS_DEF_VERSION;
486
487 if (configuration.VSProjectVersion == "7.00")
488 version = "7.00";
489
490 if (configuration.VSProjectVersion == "7.10")
491 version = "8.00";
492
493 if (configuration.VSProjectVersion == "8.00")
494 version = "9.00";
495
496 return version;
497 }
498
499
500 void
501 MSVCBackend::_generate_rules_file ( FILE* OUT )
502 {
503 fprintf ( OUT, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" );
504 fprintf ( OUT, "<VisualStudioToolFile\r\n" );
505 fprintf ( OUT, "\tName=\"GCC Assembler\"\r\n" );
506 fprintf ( OUT, "\tVersion=\"%s\"\r\n", _get_solution_verion().c_str() );
507 fprintf ( OUT, "\t>\r\n" );
508 fprintf ( OUT, "\t<Rules>\r\n" );
509 fprintf ( OUT, "\t\t<CustomBuildRule\r\n" );
510 fprintf ( OUT, "\t\t\tName=\"Assembler\"\r\n" );
511 fprintf ( OUT, "\t\t\tDisplayName=\"Assembler Files\"\r\n" );
512 fprintf ( OUT, "\t\t\tCommandLine=\"cl /E &quot;$(InputPath)&quot; | as -o &quot;$(OutDir)\\$(InputName).obj&quot;\"\r\n" );
513 fprintf ( OUT, "\t\t\tOutputs=\"$(OutDir)\\$(InputName).obj\"\r\n" );
514 fprintf ( OUT, "\t\t\tFileExtensions=\"*.S\"\r\n" );
515 fprintf ( OUT, "\t\t\tExecutionDescription=\"asm\"\r\n" );
516 fprintf ( OUT, "\t\t\t>\r\n" );
517 fprintf ( OUT, "\t\t\t<Properties>\r\n" );
518 fprintf ( OUT, "\t\t\t</Properties>\r\n" );
519 fprintf ( OUT, "\t\t</CustomBuildRule>\r\n" );
520 fprintf ( OUT, "\t</Rules>\r\n" );
521 fprintf ( OUT, "</VisualStudioToolFile>\r\n" );
522 }
523
524 void
525 MSVCBackend::_generate_sln_header ( FILE* OUT )
526 {
527 fprintf ( OUT, "Microsoft Visual Studio Solution File, Format Version %s\r\n", _get_solution_verion().c_str() );
528 fprintf ( OUT, "# Visual Studio 2005\r\n" );
529 fprintf ( OUT, "\r\n" );
530 }
531
532
533 void
534 MSVCBackend::_generate_sln_project (
535 FILE* OUT,
536 const Module& module,
537 std::string vcproj_file,
538 std::string sln_guid,
539 std::string vcproj_guid,
540 const std::vector<Dependency*>& dependencies )
541 {
542 vcproj_file = DosSeparator ( std::string(".\\") + vcproj_file );
543
544 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() );
545
546 //FIXME: only omit ProjectDependencies in VS 2005 when there are no dependencies
547 //NOTE: VS 2002 do not use ProjectSection; it uses GlobalSection instead
548 if ((configuration.VSProjectVersion == "7.10") || (dependencies.size() > 0)) {
549 fprintf ( OUT, "\tProjectSection(ProjectDependencies) = postProject\r\n" );
550 for ( size_t i = 0; i < dependencies.size(); i++ )
551 {
552 Dependency& dependency = *dependencies[i];
553 fprintf ( OUT, "\t\t%s = %s\r\n", dependency.module.guid.c_str(), dependency.module.guid.c_str() );
554 }
555 fprintf ( OUT, "\tEndProjectSection\r\n" );
556 }
557
558 fprintf ( OUT, "EndProject\r\n" );
559 }
560
561
562 void
563 MSVCBackend::_generate_sln_footer ( FILE* OUT )
564 {
565 fprintf ( OUT, "Global\r\n" );
566 fprintf ( OUT, "\tGlobalSection(SolutionConfiguration) = preSolution\r\n" );
567 fprintf ( OUT, "\t\tDebug = Debug\r\n" );
568 fprintf ( OUT, "\t\tRelease = Release\r\n" );
569 fprintf ( OUT, "\tEndGlobalSection\r\n" );
570 fprintf ( OUT, "\tGlobalSection(ProjectConfiguration) = postSolution\r\n" );
571 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
572 {
573 Module& module = *ProjectNode.modules[i];
574 std::string guid = module.guid;
575 _generate_sln_configurations ( OUT, guid.c_str() );
576 }
577 fprintf ( OUT, "\tEndGlobalSection\r\n" );
578 fprintf ( OUT, "\tGlobalSection(ExtensibilityGlobals) = postSolution\r\n" );
579 fprintf ( OUT, "\tEndGlobalSection\r\n" );
580 fprintf ( OUT, "\tGlobalSection(ExtensibilityAddIns) = postSolution\r\n" );
581 fprintf ( OUT, "\tEndGlobalSection\r\n" );
582
583 if (configuration.VSProjectVersion == "7.00") {
584 fprintf ( OUT, "\tGlobalSection(ProjectDependencies) = postSolution\r\n" );
585 //FIXME: Add dependencies for VS 2002
586 fprintf ( OUT, "\tEndGlobalSection\r\n" );
587 }
588
589 if (configuration.VSProjectVersion == "8.00") {
590 fprintf ( OUT, "\tGlobalSection(SolutionProperties) = preSolution\r\n" );
591 fprintf ( OUT, "\t\tHideSolutionNode = FALSE\r\n" );
592 fprintf ( OUT, "\tEndGlobalSection\r\n" );
593 }
594
595 fprintf ( OUT, "EndGlobal\r\n" );
596 fprintf ( OUT, "\r\n" );
597 }
598
599
600 void
601 MSVCBackend::_generate_sln_configurations ( FILE* OUT, std::string vcproj_guid )
602 {
603 fprintf ( OUT, "\t\t%s.Debug.ActiveCfg = Debug|Win32\r\n", vcproj_guid.c_str() );
604 fprintf ( OUT, "\t\t%s.Debug.Build.0 = Debug|Win32\r\n", vcproj_guid.c_str() );
605 fprintf ( OUT, "\t\t%s.Debug.Release.ActiveCfg = Release|Win32\r\n", vcproj_guid.c_str() );
606 fprintf ( OUT, "\t\t%s.Debug.Release.Build.0 = Release|Win32\r\n", vcproj_guid.c_str() );
607 }
608
609 void
610 MSVCBackend::_generate_sln ( FILE* OUT )
611 {
612 string sln_guid = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}";
613 vector<string> guids;
614
615 _generate_sln_header(OUT);
616 // TODO FIXME - is it necessary to sort them?
617 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
618 {
619 Module& module = *ProjectNode.modules[i];
620
621 std::string vcproj_file = VcprojFileName ( module );
622 _generate_sln_project ( OUT, module, vcproj_file, sln_guid, module.guid, module.dependencies );
623 }
624 _generate_sln_footer ( OUT );
625 }
626