2c64105e1bfb38288574e0e23548ef90e7f01418
[reactos.git] / reactos / tools / rbuild / backend / msvc / msvcmaker.cpp
1 #ifdef _MSC_VER
2 #pragma warning ( disable : 4786 )
3 #endif//_MSC_VER
4
5 #include <string>
6 #include <vector>
7
8 #include <stdio.h>
9
10 #include "msvc.h"
11
12 using std::string;
13 using std::vector;
14
15 void
16 MSVCBackend::_generate_dsp ( const Module& module )
17 {
18 size_t i;
19 // TODO FIXME wine hack?
20 const bool wine = false;
21
22 string dsp_file = DspFileName(module);
23 printf ( "Creating MSVC project: '%s'\n", dsp_file.c_str() );
24 FILE* OUT = fopen ( dsp_file.c_str(), "wb" );
25
26 vector<string> imports;
27 for ( i = 0; i < module.non_if_data.libraries.size(); i++ )
28 {
29 imports.push_back ( module.non_if_data.libraries[i]->name );
30 }
31
32 string module_type = Right(module.GetTargetName(),3);
33 bool lib = (module_type == "lib");
34 bool dll = (module_type == "dll");
35 bool exe = (module_type == "exe");
36 // TODO FIXME - need more checks here for 'sys' and possibly 'drv'?
37
38 bool console = exe; // FIXME: Not always correct
39
40 // TODO FIXME - not sure if the count here is right...
41 int parts = 0;
42 const char* p = strpbrk ( dsp_file.c_str(), "/\\" );
43 while ( p )
44 {
45 ++parts;
46 p = strpbrk ( p+1, "/\\" );
47 }
48 string msvc_wine_dir = "..";
49 while ( --parts )
50 msvc_wine_dir += "\\..";
51
52 string wine_include_dir = msvc_wine_dir + "\\include";
53
54 //$progress_current++;
55 //$output->progress("$dsp_file (file $progress_current of $progress_max)");
56
57 // TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?
58 string dsp_path = module.GetBasePath();
59 vector<string> c_srcs, source_files, resource_files;
60 vector<const IfableData*> ifs_list;
61 ifs_list.push_back ( &module.non_if_data );
62 while ( ifs_list.size() )
63 {
64 const IfableData& data = *ifs_list.back();
65 ifs_list.pop_back();
66 // TODO FIXME - refactor needed - we're discarding if conditions
67 for ( i = 0; i < data.ifs.size(); i++ )
68 ifs_list.push_back ( &data.ifs[i]->data );
69 const vector<File*>& files = data.files;
70 for ( i = 0; i < files.size(); i++ )
71 {
72 // TODO FIXME - do we want the full path of the file here?
73 string file = string(".") + &files[i]->name[dsp_path.size()];
74
75 source_files.push_back ( file );
76 if ( !stricmp ( Right(file,2).c_str(), ".c" ) )
77 c_srcs.push_back ( file );
78 if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
79 resource_files.push_back ( file );
80 }
81 }
82 // TODO FIXME - we don't include header files in our build system
83 //my @header_files = @{module->{header_files}};
84 vector<string> header_files;
85
86 // TODO FIXME - wine hack?
87 /*if (module.name !~ /^wine(?:_unicode|build|runtests|test)?$/ &&
88 module.name !~ /^(?:gdi32)_.+?$/ &&
89 Right ( module.name, 5 ) == "_test" )
90 {
91 source_files.push_back ( module.name + ".spec" );
92 @source_files = sort(@source_files);
93 }*/
94
95 bool no_cpp = true;
96 bool no_msvc_headers = true;
97 // TODO FIXME - wine hack?
98 /*if (module.name =~ /^wine(?:runtests|test)$/
99 || Right ( module.name, 5 ) == "_test" )
100 {
101 no_msvc_headers = false;
102 }*/
103
104 std::vector<std::string> cfgs;
105
106 cfgs.push_back ( module.name + " - Win32" );
107
108 if (!no_cpp)
109 {
110 std::vector<std::string> _cfgs;
111 for ( i = 0; i < cfgs.size(); i++ )
112 {
113 _cfgs.push_back ( cfgs[i] + " C" );
114 _cfgs.push_back ( cfgs[i] + " C++" );
115 }
116 cfgs.resize(0);
117 cfgs = _cfgs;
118 }
119
120 // TODO FIXME - wine hack?
121 /*if (!no_release)
122 {
123 std::vector<std::string> _cfgs;
124 for ( i = 0; i < cfgs.size(); i++ )
125 {
126 _cfgs.push_back ( cfgs[i] + " Debug" );
127 _cfgs.push_back ( cfgs[i] + " Release" );
128 }
129 cfgs.resize(0);
130 cfgs = _cfgs;
131 }*/
132
133 if (!no_msvc_headers)
134 {
135 std::vector<std::string> _cfgs;
136 for ( i = 0; i < cfgs.size(); i++ )
137 {
138 _cfgs.push_back ( cfgs[i] + " MSVC Headers" );
139 _cfgs.push_back ( cfgs[i] + " Wine Headers" );
140 }
141 cfgs.resize(0);
142 cfgs = _cfgs;
143 }
144
145 string default_cfg = cfgs.back();
146
147 fprintf ( OUT, "# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\r\n", module.name.c_str() );
148 fprintf ( OUT, "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n" );
149 fprintf ( OUT, "# ** DO NOT EDIT **\r\n" );
150 fprintf ( OUT, "\r\n" );
151
152 if ( lib )
153 {
154 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n" );
155 }
156 else if ( dll )
157 {
158 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n" );
159 }
160 else
161 {
162 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n" );
163 }
164 fprintf ( OUT, "\r\n" );
165
166 fprintf ( OUT, "CFG=%s\r\n", default_cfg.c_str() );
167 fprintf ( OUT, "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n" );
168 fprintf ( OUT, "!MESSAGE use the Export Makefile command and run\r\n" );
169 fprintf ( OUT, "!MESSAGE \r\n" );
170 fprintf ( OUT, "!MESSAGE NMAKE /f \"%s.mak\".\r\n", module.name.c_str() );
171 fprintf ( OUT, "!MESSAGE \r\n" );
172 fprintf ( OUT, "!MESSAGE You can specify a configuration when running NMAKE\r\n" );
173 fprintf ( OUT, "!MESSAGE by defining the macro CFG on the command line. For example:\r\n" );
174 fprintf ( OUT, "!MESSAGE \r\n" );
175 fprintf ( OUT, "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s\"\r\n", module.name.c_str(), default_cfg.c_str() );
176 fprintf ( OUT, "!MESSAGE \r\n" );
177 fprintf ( OUT, "!MESSAGE Possible choices for configuration are:\r\n" );
178 fprintf ( OUT, "!MESSAGE \r\n" );
179 for ( i = 0; i < cfgs.size(); i++ )
180 {
181 const string& cfg = cfgs[i];
182 if ( lib )
183 {
184 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Static Library\")\r\n", cfg.c_str() );
185 }
186 else if ( dll )
187 {
188 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n", cfg.c_str() );
189 }
190 else
191 {
192 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Console Application\")\r\n", cfg.c_str() );
193 }
194 }
195 fprintf ( OUT, "!MESSAGE \r\n" );
196 fprintf ( OUT, "\r\n" );
197
198 fprintf ( OUT, "# Begin Project\r\n" );
199 fprintf ( OUT, "# PROP AllowPerConfigDependencies 0\r\n" );
200 fprintf ( OUT, "# PROP Scc_ProjName \"\"\r\n" );
201 fprintf ( OUT, "# PROP Scc_LocalPath \"\"\r\n" );
202 fprintf ( OUT, "CPP=cl.exe\r\n" );
203 if ( !lib && !exe ) fprintf ( OUT, "MTL=midl.exe\r\n" );
204 fprintf ( OUT, "RSC=rc.exe\r\n" );
205
206 int n = 0;
207
208 std::string output_dir;
209 for ( size_t icfg = 0; icfg < cfgs.size(); icfg++ )
210 {
211 std::string& cfg = cfgs[icfg];
212 if ( icfg )
213 {
214 if ( n == 0 )
215 {
216 fprintf ( OUT, "!IF \"$(CFG)\" == \"%s\"\r\n", cfg.c_str() );
217 fprintf ( OUT, "\r\n" );
218 }
219 else
220 {
221 fprintf ( OUT, "\r\n" );
222 fprintf ( OUT, "!ELSEIF \"$(CFG)\" == \"%s\"\r\n", cfg.c_str() );
223 fprintf ( OUT, "\r\n" );
224 }
225 }
226
227 bool debug = !strstr ( cfg.c_str(), "Release" );
228 bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
229
230 fprintf ( OUT, "# PROP BASE Use_MFC 0\r\n" );
231
232 if ( debug )
233 {
234 fprintf ( OUT, "# PROP BASE Use_Debug_Libraries 1\r\n" );
235 }
236 else
237 {
238 fprintf ( OUT, "# PROP BASE Use_Debug_Libraries 0\r\n" );
239 }
240
241 output_dir = Replace(cfg,module.name + " - ","");
242 output_dir = Replace(output_dir," ","_");
243 output_dir = Replace(output_dir,"C++","Cxx");
244 // TODO FIXME - wine hack?
245 //if ( output_prefix_dir.size() )
246 // output_dir = output_prefix_dir + "\\" + output_dir;
247
248 fprintf ( OUT, "# PROP BASE Output_Dir \"%s\"\r\n", output_dir.c_str() );
249 fprintf ( OUT, "# PROP BASE Intermediate_Dir \"%s\"\r\n", output_dir.c_str() );
250
251 fprintf ( OUT, "# PROP BASE Target_Dir \"\"\r\n" );
252
253 fprintf ( OUT, "# PROP Use_MFC 0\r\n" );
254 if ( debug )
255 {
256 fprintf ( OUT, "# PROP Use_Debug_Libraries 1\r\n" );
257 }
258 else
259 {
260 fprintf ( OUT, "# PROP Use_Debug_Libraries 0\r\n" );
261 }
262 fprintf ( OUT, "# PROP Output_Dir \"%s\"\r\n", output_dir.c_str() );
263 fprintf ( OUT, "# PROP Intermediate_Dir \"%s\"\r\n", output_dir.c_str() );
264
265 if ( dll ) fprintf ( OUT, "# PROP Ignore_Export_Lib 0\r\n" );
266 fprintf ( OUT, "# PROP Target_Dir \"\"\r\n" );
267
268 vector<string> defines;
269 defines.push_back ( "WINVER=0x0501" );
270 defines.push_back ( "_WIN32_WINNT=0x0501" );
271 defines.push_back ( "_WIN32_IE=0x0600" );
272 defines.push_back ( "WIN32" );
273 defines.push_back ( "_WINDOWS" );
274 defines.push_back ( "WIN32" );
275 defines.push_back ( "_MBCS" );
276 if ( debug )
277 {
278 defines.push_back ( "_DEBUG" );
279 if ( lib || exe )
280 {
281 fprintf ( OUT, "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od" );
282 defines.push_back ( "_LIB" );
283 }
284 else
285 {
286 fprintf ( OUT, "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
287 defines.push_back ( "_WINDOWS" );
288 defines.push_back ( "_USRDLL" );
289 // TODO FIXME - wine hack?
290 //defines.push_back ( string("\U") + module.name + "\E_EXPORTS" );
291 }
292 }
293 else
294 {
295 defines.push_back ( "NDEBUG" );
296 if ( lib || exe )
297 {
298 fprintf ( OUT, "# ADD BASE CPP /nologo /W3 /GX /O2" );
299 defines.push_back ( "_LIB" );
300 }
301 else
302 {
303 fprintf ( OUT, "# ADD BASE CPP /nologo /MT /W3 /GX /O2" );
304 defines.push_back ( "_WINDOWS" );
305 defines.push_back ( "_USRDLL" );
306 // TODO FIXME - wine hack?
307 //defines.push_back ( string("\U") + module.name + "\E_EXPORTS" );
308 }
309 }
310
311 for ( i = 0; i < defines.size(); i++ )
312 {
313 fprintf ( OUT, " /D \"%s\"", defines[i].c_str() );
314 }
315 if ( lib || exe ) fprintf ( OUT, " /YX" );
316 fprintf ( OUT, " /FD" );
317 if ( debug )
318 {
319 fprintf ( OUT, " /GZ" );
320 if ( lib || exe ) fprintf ( OUT, " " );
321 }
322 fprintf ( OUT, " /c" );
323 fprintf ( OUT, "\r\n" );
324
325 vector<string> defines2;
326 defines2.push_back ( "WINVER=0x0501" );
327 defines2.push_back ( "_WIN32_WINNT=0x0501" );
328 defines2.push_back ( "_WIN32_IE=0x0600" );
329 defines2.push_back ( "WIN32" );
330 defines2.push_back ( "_WINDOWS" );
331 defines2.push_back ( "_MBCS" );
332 if ( debug )
333 {
334 defines2.push_back ( "_DEBUG" );
335 if(lib)
336 {
337 fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
338 defines2.push_back ( "_LIB" );
339 }
340 else
341 {
342 fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
343 defines2.push_back ( "_USRDLL" );
344 }
345 }
346 else
347 {
348 defines2.push_back ( "NDEBUG" );
349 if(lib)
350 {
351 fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
352 defines2.push_back ( "_LIB" );
353 }
354 else
355 {
356 fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
357 defines2.push_back ( "_USRDLL" );
358 }
359 }
360
361 std::vector<std::string> includes;
362 // TODO FIXME - wine hack?
363 if ( wine )
364 {
365 // TODO FIXME - wine hack?
366 //defines2.push_back ( string("_\U") + module.name + "\E_" );
367 // TODO FIXME - wine hack?
368 /*if ( module.name !~ /^(?:wine(?:build|test)|.*?_test)$/ )
369 defines2.push_back ( "__WINESRC__" );*/
370 if ( msvc_headers )
371 defines2.push_back ( "__WINE_USE_NATIVE_HEADERS" );
372 string output_dir2 = Replace(output_dir,"\\","\\\\");
373 defines2.push_back ( ssprintf("__WINETEST_OUTPUT_DIR=\\\"%s\\\"",output_dir.c_str()) );
374 defines2.push_back ( "__i386__" );
375 defines2.push_back ( "_X86_" );
376
377 // TODO FIXME - wine hacks?
378 /*if(module.name =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
379 push @includes, ".." );
380 }
381
382 if ( strstr ( module.name.c_str(), "_test" )
383 {
384 include.push_back ( msvc_wine_dir + "\\" + output_dir );
385 }
386
387 if (!msvc_headers || module.name == "winetest")
388 {
389 includes.push_back ( wine_include_dir );
390 }*/
391 }
392
393 if ( wine )
394 {
395 for ( i = 0; i < includes.size(); i++ );
396 {
397 const string& include = includes[i];
398 if ( strpbrk ( include.c_str(), "[\\\"]" ) )
399 {
400 fprintf ( OUT, " /I \"%s\"", include.c_str() );
401 }
402 else
403 {
404 fprintf ( OUT, " /I %s", include.c_str() );
405 }
406 }
407 }
408
409 for ( i = 0; i < defines2.size(); i++ )
410 {
411 const string& define = defines2[i];
412 if ( strpbrk ( define.c_str(), "[\\\"]" ) )
413 {
414 fprintf ( OUT, " /D \"%s\"", define.c_str() );
415 }
416 else
417 {
418 fprintf ( OUT, " /D %s", define.c_str() );
419 }
420 }
421 if ( wine ) fprintf ( OUT, " /D inline=__inline" );
422 if ( 0 && wine ) fprintf ( OUT, " /D \"__STDC__\"" );
423
424 fprintf ( OUT, lib ? " /YX" : " /FR" );
425 fprintf ( OUT, " /FD" );
426 if ( debug ) fprintf ( OUT, " /GZ" );
427 if ( debug && lib ) fprintf ( OUT, " " );
428 fprintf ( OUT, " /c" );
429 if ( !no_cpp ) fprintf ( OUT, " /TP" );
430 fprintf ( OUT, "\r\n" );
431
432 if ( debug )
433 {
434 if ( dll )
435 {
436 fprintf ( OUT, "# SUBTRACT CPP /X /YX\r\n" );
437 fprintf ( OUT, "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" );
438 fprintf ( OUT, "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" );
439 }
440 fprintf ( OUT, "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n" );
441 fprintf ( OUT, "# ADD RSC /l 0x41d" );
442 if ( wine )
443 {
444 for ( i = 0; i < includes.size(); i++ )
445 {
446 fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
447 }
448 }
449 fprintf ( OUT, " /d \"_DEBUG\"\r\n" );
450 }
451 else
452 {
453 if ( dll )
454 {
455 fprintf ( OUT, "# SUBTRACT CPP /YX\r\n" );
456 fprintf ( OUT, "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" );
457 fprintf ( OUT, "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" );
458 }
459 fprintf ( OUT, "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n" );
460 fprintf ( OUT, "# ADD RSC /l 0x41d" );
461 if ( wine )
462 {
463 for ( i = 0; i < includes.size(); i++ )
464 fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
465 }
466 fprintf ( OUT, "/d \"NDEBUG\"\r\n" );
467 }
468 fprintf ( OUT, "BSC32=bscmake.exe\r\n" );
469 fprintf ( OUT, "# ADD BASE BSC32 /nologo\r\n" );
470 fprintf ( OUT, "# ADD BSC32 /nologo\r\n" );
471
472 if ( exe || dll )
473 {
474 fprintf ( OUT, "LINK32=link.exe\r\n" );
475 fprintf ( OUT, "# ADD BASE LINK32 " );
476 vector<string> libraries;
477 libraries.push_back ( "kernel32.lib" );
478 libraries.push_back ( "user32.lib" );
479 libraries.push_back ( "gdi32.lib" );
480 libraries.push_back ( "winspool.lib" );
481 libraries.push_back ( "comdlg32.lib" );
482 libraries.push_back ( "advapi32.lib" );
483 libraries.push_back ( "shell32.lib" );
484 libraries.push_back ( "ole32.lib" );
485 libraries.push_back ( "oleaut32.lib" );
486 libraries.push_back ( "uuid.lib" );
487 libraries.push_back ( "odbc32.lib" );
488 libraries.push_back ( "odbccp32.lib" );
489 for ( i = 0; i < libraries.size(); i++ )
490 {
491 fprintf ( OUT, "%s ", libraries[i].c_str() );
492 }
493 fprintf ( OUT, " /nologo" );
494 if ( dll ) fprintf ( OUT, " /dll" );
495 if ( console ) fprintf ( OUT, " /subsystem:console" );
496 if ( debug ) fprintf ( OUT, " /debug" );
497 fprintf ( OUT, " /machine:I386" );
498 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
499 fprintf ( OUT, "\r\n" );
500
501 fprintf ( OUT, "# ADD LINK32" );
502 fprintf ( OUT, " /nologo" );
503 // TODO FIXME - do we need their kludge?
504 //if ( module.name == "ntdll" ) fprintf ( OUT, " libcmt.lib" ); // FIXME: Kludge
505 for ( i = 0; i < imports.size(); i++ )
506 {
507 const string& import = imports[i];
508 if ( import != "msvcrt" )
509 fprintf ( OUT, " %s.lib", import.c_str() );
510 }
511 if ( dll ) fprintf ( OUT, " /dll" );
512 if ( console ) fprintf ( OUT, " /subsystem:console" );
513 if ( debug ) fprintf ( OUT, " /debug" );
514 fprintf ( OUT, " /machine:I386" );
515 // TODO FIXME - do we need their kludge?
516 //if ( module.name == "ntdll" ) fprintf ( OUT, " /nodefaultlib" ); // FIXME: Kludge
517 if ( dll ) fprintf ( OUT, " /def:\"%s.def\"", module.name.c_str() );
518 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
519 fprintf ( OUT, "\r\n" );
520 }
521 else
522 {
523 fprintf ( OUT, "LIB32=link.exe -lib\r\n" );
524 fprintf ( OUT, "# ADD BASE LIB32 /nologo\r\n" );
525 fprintf ( OUT, "# ADD LIB32 /nologo\r\n" );
526 }
527
528 n++;
529 }
530
531 if ( cfgs.size() != 0 )
532 {
533 fprintf ( OUT, "\r\n" );
534 fprintf ( OUT, "!ENDIF \r\n" );
535 fprintf ( OUT, "\r\n" );
536 }
537
538 if ( module.name == "winebuild" )
539 {
540 fprintf ( OUT, "# Begin Special Build Tool\r\n" );
541 fprintf ( OUT, "SOURCE=\"$(InputPath)\"\r\n" );
542 fprintf ( OUT, "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n" );
543 fprintf ( OUT, "PostBuild_Cmds=" );
544 fprintf ( OUT, "copy ..\\..\\library\\%s\\wine.dll $(OutDir)\t",
545 output_dir.c_str() );
546 fprintf ( OUT, "copy ..\\..\\unicode\\%s\\wine_unicode.dll $(OutDir)\r\n",
547 output_dir.c_str() );
548 fprintf ( OUT, "# End Special Build Tool\r\n" );
549 }
550 fprintf ( OUT, "# Begin Target\r\n" );
551 fprintf ( OUT, "\r\n" );
552 for ( i = 0; i < cfgs.size(); i++ )
553 {
554 fprintf ( OUT, "# Name \"%s\"\r\n", cfgs[i].c_str() );
555 }
556
557 fprintf ( OUT, "# Begin Group \"Source Files\"\r\n" );
558 fprintf ( OUT, "\r\n" );
559 fprintf ( OUT, "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n" );
560
561 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
562 {
563 string source_file = DosSeparator(source_files[isrcfile]);
564
565 if ( strncmp ( source_file.c_str(), ".\\", 2 ) )
566 {
567 source_file = string(".\\") + source_file;
568 }
569
570 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
571 {
572 string basename = string ( source_file.c_str(), source_file.size() - 5 );
573
574 // TODO FIXME - not sure what this is doing? wine hack maybe?
575 //if ( basename !~ /\..{1,3}$/; ) basename += string(".dll");
576 string dbg_c_file = basename + ".dbg.c";
577
578 fprintf ( OUT, "# Begin Source File\r\n" );
579 fprintf ( OUT, "\r\n" );
580 fprintf ( OUT, "SOURCE=%s\r\n", dbg_c_file.c_str() );
581 fprintf ( OUT, "# End Source File\r\n" );
582 }
583
584 fprintf ( OUT, "# Begin Source File\r\n" );
585 fprintf ( OUT, "\r\n" );
586
587 fprintf ( OUT, "SOURCE=%s\r\n", source_file.c_str() );
588
589 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
590 {
591 string basename = string ( source_file.c_str(), source_file.size() - 5 );
592
593 string spec_file = source_file;
594 string def_file = basename + ".def";
595
596 // TODO FIXME - not sure what this is doing? wine hack maybe?
597 //if ( basename !~ /\..{1,3}$/; ) basename += ".dll";
598 string dbg_file = basename + ".dbg";
599 string dbg_c_file = basename + ".dbg.c";
600
601 string srcdir = "."; // FIXME: Is this really always correct?
602
603 fprintf ( OUT, "# Begin Custom Build\r\n" );
604 fprintf ( OUT, "InputPath=%s\r\n", spec_file.c_str() );
605 fprintf ( OUT, "\r\n" );
606 fprintf ( OUT, "BuildCmds= \\\r\n" );
607 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe --def %s > %s \\\r\n",
608 output_dir.c_str(),
609 spec_file.c_str(),
610 def_file.c_str() );
611
612 if ( module.name == "ntdll" )
613 {
614 int n = 0;
615 for ( i = 0; i < c_srcs.size(); i++ )
616 {
617 const string& c_src = c_srcs[i];
618 if(n++ > 0)
619 {
620 fprintf ( OUT, "\techo %s >> %s \\\r\n", c_src.c_str(), dbg_file.c_str() );
621 }
622 else
623 {
624 fprintf ( OUT, "\techo %s > %s \\\r\n", c_src.c_str(), dbg_file.c_str() );
625 }
626 }
627 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
628 output_dir.c_str() );
629 fprintf ( OUT, " -o %s --debug -C%s %s \\\r\n",
630 dbg_c_file.c_str(),
631 srcdir.c_str(),
632 dbg_file.c_str() );
633 }
634 else
635 {
636 string sc_srcs;
637 for ( i = 0; i < c_srcs.size(); i++ )
638 {
639 const string& c_src = c_srcs[i];
640 if ( !strcmp ( &c_src[c_src.size()-2], ".c" ) )
641 {
642 if ( sc_srcs.size() )
643 sc_srcs += " ";
644 sc_srcs += c_src;
645 }
646 }
647
648 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
649 output_dir.c_str() );
650 fprintf ( OUT, " -o %s --debug -C%s %s \\\r\n",
651 dbg_c_file.c_str(),
652 srcdir.c_str(),
653 sc_srcs.c_str() );
654 }
655
656 fprintf ( OUT, "\t\r\n" );
657 fprintf ( OUT, "\r\n" );
658 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", def_file.c_str() );
659 fprintf ( OUT, " $(BuildCmds)\r\n" );
660 fprintf ( OUT, "\r\n" );
661 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", dbg_c_file.c_str() );
662 fprintf ( OUT, " $(BuildCmds)\r\n" );
663 fprintf ( OUT, "# End Custom Build\r\n" );
664 }
665 /*else if ( source_file =~ /([^\\]*?\.h)$/ )
666 {
667 my $h_file = $1;
668
669 foreach my $cfg (@cfgs) {
670 if($#cfgs == 0) {
671 # Nothing
672 } elsif($n == 0) {
673 fprintf ( OUT, "!IF \"$(CFG)\" == \"$cfg\"\r\n" );
674 fprintf ( OUT, "\r\n" );
675 } else {
676 fprintf ( OUT, "\r\n" );
677 fprintf ( OUT, "!ELSEIF \"$(CFG)\" == \"$cfg\"\r\n" );
678 fprintf ( OUT, "\r\n" );
679 }
680
681 $output_dir = $cfg;
682 $output_dir =~ s/^$project - //;
683 $output_dir =~ s/ /_/g;
684 $output_dir =~ s/C\+\+/Cxx/g;
685 if($output_prefix_dir) {
686 $output_dir = "$output_prefix_dir\\$output_dir" );
687 }
688
689 fprintf ( OUT, "# Begin Custom Build\r\n" );
690 fprintf ( OUT, "OutDir=%s\r\n", output_dir.c_str() );
691 fprintf ( OUT, "InputPath=%s\r\n", source_file.c_str() );
692 fprintf ( OUT, "\r\n" );
693 fprintf ( OUT, "\"$(OutDir)\\wine\\%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", h_file.c_str() );
694 fprintf ( OUT, "\tcopy \"$(InputPath)\" \"$(OutDir)\\wine\"\r\n" );
695 fprintf ( OUT, "\r\n" );
696 fprintf ( OUT, "# End Custom Build\r\n" );
697 }
698
699 if ( cfgs.size() != 0)
700 {
701 fprintf ( OUT, "\r\n" );
702 fprintf ( OUT, "!ENDIF \r\n" );
703 fprintf ( OUT, "\r\n" );
704 }
705 }*/
706
707 fprintf ( OUT, "# End Source File\r\n" );
708 }
709 fprintf ( OUT, "# End Group\r\n" );
710
711 fprintf ( OUT, "# Begin Group \"Header Files\"\r\n" );
712 fprintf ( OUT, "\r\n" );
713 fprintf ( OUT, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n" );
714 for ( i = 0; i < header_files.size(); i++ )
715 {
716 const string& header_file = header_files[i];
717 fprintf ( OUT, "# Begin Source File\r\n" );
718 fprintf ( OUT, "\r\n" );
719 fprintf ( OUT, "SOURCE=.\\%s\r\n", header_file.c_str() );
720 fprintf ( OUT, "# End Source File\r\n" );
721 }
722 fprintf ( OUT, "# End Group\r\n" );
723
724
725
726 fprintf ( OUT, "# Begin Group \"Resource Files\"\r\n" );
727 fprintf ( OUT, "\r\n" );
728 fprintf ( OUT, "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n" );
729 for ( i = 0; i < resource_files.size(); i++ )
730 {
731 const string& resource_file = resource_files[i];
732 fprintf ( OUT, "# Begin Source File\r\n" );
733 fprintf ( OUT, "\r\n" );
734 fprintf ( OUT, "SOURCE=.\\%s\r\n", resource_file.c_str() );
735 fprintf ( OUT, "# End Source File\r\n" );
736 }
737 fprintf ( OUT, "# End Group\r\n" );
738
739 fprintf ( OUT, "# End Target\r\n" );
740 fprintf ( OUT, "# End Project\r\n" );
741
742 fclose(OUT);
743 }
744
745 void
746 MSVCBackend::_generate_dsw_header ( FILE* OUT )
747 {
748 fprintf ( OUT, "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n" );
749 fprintf ( OUT, "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n" );
750 fprintf ( OUT, "\r\n" );
751 }
752
753 void
754 MSVCBackend::_generate_dsw_project (
755 FILE* OUT,
756 const Module& module,
757 std::string dsp_file,
758 const std::vector<Dependency*>& dependencies )
759 {
760 dsp_file = DosSeparator ( std::string(".\\") + dsp_file );
761
762 // TODO FIXME - must they be sorted?
763 //@dependencies = sort(@dependencies);
764
765 fprintf ( OUT, "###############################################################################\r\n" );
766 fprintf ( OUT, "\r\n" );
767 fprintf ( OUT, "Project: \"%s\"=%s - Package Owner=<4>\r\n", module.name.c_str(), dsp_file.c_str() );
768 fprintf ( OUT, "\r\n" );
769 fprintf ( OUT, "Package=<5>\r\n" );
770 fprintf ( OUT, "{{{\r\n" );
771 fprintf ( OUT, "}}}\r\n" );
772 fprintf ( OUT, "\r\n" );
773 fprintf ( OUT, "Package=<4>\r\n" );
774 fprintf ( OUT, "{{{\r\n" );
775 for ( size_t i = 0; i < dependencies.size(); i++ )
776 {
777 Dependency& dependency = *dependencies[i];
778 fprintf ( OUT, " Begin Project Dependency\r\n" );
779 fprintf ( OUT, " Project_Dep_Name %s\r\n", dependency.module.name.c_str() );
780 fprintf ( OUT, " End Project Dependency\r\n" );
781 }
782 fprintf ( OUT, "}}}\r\n" );
783 fprintf ( OUT, "\r\n" );
784 }
785
786 void
787 MSVCBackend::_generate_dsw_footer ( FILE* OUT )
788 {
789 fprintf ( OUT, "###############################################################################\r\n" );
790 fprintf ( OUT, "\r\n" );
791 fprintf ( OUT, "Global:\r\n" );
792 fprintf ( OUT, "\r\n" );
793 fprintf ( OUT, "Package=<5>\r\n" );
794 fprintf ( OUT, "{{{\r\n" );
795 fprintf ( OUT, "}}}\r\n" );
796 fprintf ( OUT, "\r\n" );
797 fprintf ( OUT, "Package=<3>\r\n" );
798 fprintf ( OUT, "{{{\r\n" );
799 fprintf ( OUT, "}}}\r\n" );
800 fprintf ( OUT, "\r\n" );
801 fprintf ( OUT, "###############################################################################\r\n" );
802 fprintf ( OUT, "\r\n" );
803 }
804
805 void
806 MSVCBackend::_generate_wine_dsw ( FILE* OUT )
807 {
808 _generate_dsw_header(OUT);
809 // TODO FIXME - is it necessary to sort them?
810 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
811 {
812 Module& module = *ProjectNode.modules[i];
813
814 std::string dsp_file = DspFileName ( module );
815
816 // TODO FIXME - more wine hacks?
817 /*if ( module.name == "gdi32" )
818 {
819 for ( size_t idir = 0; idir < gdi32_dirs.size(); idir++ )
820 {
821 string dir2 = gdi32_dirs[idir];
822 $dir2 =~ s%^.*?/([^/]+)$%$1%;
823
824 dependencies.push_back ( Replace ( "gdi32_" + dir2, "/", "_" ) );
825 }
826 }*/
827
828 _generate_dsw_project ( OUT, module, dsp_file, module.dependencies );
829 }
830 _generate_dsw_footer ( OUT );
831 }