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