added some verbosity
[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(), "w" );
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 module.name !~ /_test$/)
88 {
89 push @source_files, "$project.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 || module.name =~ /_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>\n", module.name.c_str() );
146 fprintf ( OUT, "# Microsoft Developer Studio Generated Build File, Format Version 6.00\n" );
147 fprintf ( OUT, "# ** DO NOT EDIT **\n" );
148 fprintf ( OUT, "\n" );
149
150 if ( lib )
151 {
152 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\n" );
153 }
154 else if ( dll )
155 {
156 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\n" );
157 }
158 else
159 {
160 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n" );
161 }
162 fprintf ( OUT, "\n" );
163
164 fprintf ( OUT, "CFG=$default_cfg\n" );
165 fprintf ( OUT, "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\n" );
166 fprintf ( OUT, "!MESSAGE use the Export Makefile command and run\n" );
167 fprintf ( OUT, "!MESSAGE \n" );
168 fprintf ( OUT, "!MESSAGE NMAKE /f \"%s.mak\".\n", module.name.c_str() );
169 fprintf ( OUT, "!MESSAGE \n" );
170 fprintf ( OUT, "!MESSAGE You can specify a configuration when running NMAKE\n" );
171 fprintf ( OUT, "!MESSAGE by defining the macro CFG on the command line. For example:\n" );
172 fprintf ( OUT, "!MESSAGE \n" );
173 fprintf ( OUT, "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s\"\n", module.name.c_str(), default_cfg.c_str() );
174 fprintf ( OUT, "!MESSAGE \n" );
175 fprintf ( OUT, "!MESSAGE Possible choices for configuration are:\n" );
176 fprintf ( OUT, "!MESSAGE \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\")\n", cfg.c_str() );
183 }
184 else if ( dll )
185 {
186 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Dynamic-Link Library\")\n", cfg.c_str() );
187 }
188 else
189 {
190 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Console Application\")\n", cfg.c_str() );
191 }
192 }
193 fprintf ( OUT, "!MESSAGE \n" );
194 fprintf ( OUT, "\n" );
195
196 fprintf ( OUT, "# Begin Project\n" );
197 fprintf ( OUT, "# PROP AllowPerConfigDependencies 0\n" );
198 fprintf ( OUT, "# PROP Scc_ProjName \"\"\n" );
199 fprintf ( OUT, "# PROP Scc_LocalPath \"\"\n" );
200 fprintf ( OUT, "CPP=cl.exe\n" );
201 if ( !lib && !exe ) fprintf ( OUT, "MTL=midl.exe\n" );
202 fprintf ( OUT, "RSC=rc.exe\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\"\n", cfg.c_str() );
215 fprintf ( OUT, "\n" );
216 }
217 else
218 {
219 fprintf ( OUT, "\n" );
220 fprintf ( OUT, "!ELSEIF \"$(CFG)\" == \"%s\"\n", cfg.c_str() );
221 fprintf ( OUT, "\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\n" );
229
230 if ( debug )
231 {
232 fprintf ( OUT, "# PROP BASE Use_Debug_Libraries 1\n" );
233 }
234 else
235 {
236 fprintf ( OUT, "# PROP BASE Use_Debug_Libraries 0\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\"\n", output_dir.c_str() );
247 fprintf ( OUT, "# PROP BASE Intermediate_Dir \"%s\"\n", output_dir.c_str() );
248
249 fprintf ( OUT, "# PROP BASE Target_Dir \"\"\n" );
250
251 fprintf ( OUT, "# PROP Use_MFC 0\n" );
252 if ( debug )
253 {
254 fprintf ( OUT, "# PROP Use_Debug_Libraries 1\n" );
255 }
256 else
257 {
258 fprintf ( OUT, "# PROP Use_Debug_Libraries 0\n" );
259 }
260 fprintf ( OUT, "# PROP Output_Dir \"%s\"\n", output_dir.c_str() );
261 fprintf ( OUT, "# PROP Intermediate_Dir \"%s\"\n", output_dir.c_str() );
262
263 if ( dll ) fprintf ( OUT, "# PROP Ignore_Export_Lib 0\n" );
264 fprintf ( OUT, "# PROP Target_Dir \"\"\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, "\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($project =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
377 push @includes, ".." );
378 }
379
380 if ($project =~ /_test$/) {
381 push @includes, "$msvc_wine_dir\\$output_dir" );
382 }
383
384 if (!$msvc_headers || $project eq "winetest") {
385 push @includes, $wine_include_dir;
386 }*/
387 }
388
389 if ( wine )
390 {
391 for ( i = 0; i < includes.size(); i++ );
392 {
393 const string& include = includes[i];
394 if ( strpbrk ( include.c_str(), "[\\\"]" ) )
395 {
396 fprintf ( OUT, " /I \"%s\"", include.c_str() );
397 }
398 else
399 {
400 fprintf ( OUT, " /I %s", include.c_str() );
401 }
402 }
403 }
404
405 for ( i = 0; i < defines2.size(); i++ )
406 {
407 const string& define = defines2[i];
408 if ( strpbrk ( define.c_str(), "[\\\"]" ) )
409 {
410 fprintf ( OUT, " /D \"%s\"", define.c_str() );
411 }
412 else
413 {
414 fprintf ( OUT, " /D %s", define.c_str() );
415 }
416 }
417 if ( wine ) fprintf ( OUT, " /D inline=__inline" );
418 //fprintf ( OUT, " /D \"__STDC__\"" if 0 && $wine;
419
420 fprintf ( OUT, lib ? " /YX" : " /FR" );
421 fprintf ( OUT, " /FD" );
422 if ( debug ) fprintf ( OUT, " /GZ" );
423 if ( debug && lib ) fprintf ( OUT, " " );
424 fprintf ( OUT, " /c" );
425 if ( !no_cpp ) fprintf ( OUT, " /TP" );
426 fprintf ( OUT, "\n" );
427
428 if ( debug )
429 {
430 if ( dll )
431 {
432 fprintf ( OUT, "# SUBTRACT CPP /X /YX\n" );
433 fprintf ( OUT, "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\n" );
434 fprintf ( OUT, "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\n" );
435 }
436 fprintf ( OUT, "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\n" );
437 fprintf ( OUT, "# ADD RSC /l 0x41d" );
438 if ( wine )
439 {
440 for ( i = 0; i < includes.size(); i++ )
441 {
442 fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
443 }
444 }
445 fprintf ( OUT, " /d \"_DEBUG\"\n" );
446 }
447 else
448 {
449 if ( dll )
450 {
451 fprintf ( OUT, "# SUBTRACT CPP /YX\n" );
452 fprintf ( OUT, "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\n" );
453 fprintf ( OUT, "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\n" );
454 }
455 fprintf ( OUT, "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\n" );
456 fprintf ( OUT, "# ADD RSC /l 0x41d" );
457 if ( wine )
458 {
459 for ( i = 0; i < includes.size(); i++ )
460 fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
461 }
462 fprintf ( OUT, "/d \"NDEBUG\"\n" );
463 }
464 fprintf ( OUT, "BSC32=bscmake.exe\n" );
465 fprintf ( OUT, "# ADD BASE BSC32 /nologo\n" );
466 fprintf ( OUT, "# ADD BSC32 /nologo\n" );
467
468 if ( exe || dll )
469 {
470 fprintf ( OUT, "LINK32=link.exe\n" );
471 fprintf ( OUT, "# ADD BASE LINK32 " );
472 vector<string> libraries;
473 libraries.push_back ( "kernel32.lib" );
474 libraries.push_back ( "user32.lib" );
475 libraries.push_back ( "gdi32.lib" );
476 libraries.push_back ( "winspool.lib" );
477 libraries.push_back ( "comdlg32.lib" );
478 libraries.push_back ( "advapi32.lib" );
479 libraries.push_back ( "shell32.lib" );
480 libraries.push_back ( "ole32.lib" );
481 libraries.push_back ( "oleaut32.lib" );
482 libraries.push_back ( "uuid.lib" );
483 libraries.push_back ( "odbc32.lib" );
484 libraries.push_back ( "odbccp32.lib" );
485 for ( i = 0; i < libraries.size(); i++ )
486 {
487 fprintf ( OUT, "%s ", libraries[i].c_str() );
488 }
489 fprintf ( OUT, " /nologo" );
490 if ( dll ) fprintf ( OUT, " /dll" );
491 if ( console ) fprintf ( OUT, " /subsystem:console" );
492 if ( debug ) fprintf ( OUT, " /debug" );
493 fprintf ( OUT, " /machine:I386" );
494 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
495 fprintf ( OUT, "\n" );
496
497 fprintf ( OUT, "# ADD LINK32" );
498 fprintf ( OUT, " /nologo" );
499 // TODO FIXME - do we need their kludge?
500 //fprintf ( OUT, " libcmt.lib" if $project =~ /^ntdll$/; # FIXME: Kludge
501 for ( i = 0; i < imports.size(); i++ )
502 {
503 const string& import = imports[i];
504 if ( import != "msvcrt" )
505 fprintf ( OUT, " %s.lib", import.c_str() );
506 }
507 if ( dll ) fprintf ( OUT, " /dll" );
508 if ( console ) fprintf ( OUT, " /subsystem:console" );
509 if ( debug ) fprintf ( OUT, " /debug" );
510 fprintf ( OUT, " /machine:I386" );
511 // TODO FIXME - do we need their kludge?
512 //fprintf ( OUT, " /nodefaultlib" if $project =~ /^ntdll$/; # FIXME: Kludge
513 if ( dll ) fprintf ( OUT, " /def:\"%s.def\"", module.name.c_str() );
514 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
515 fprintf ( OUT, "\n" );
516 }
517 else
518 {
519 fprintf ( OUT, "LIB32=link.exe -lib\n" );
520 fprintf ( OUT, "# ADD BASE LIB32 /nologo\n" );
521 fprintf ( OUT, "# ADD LIB32 /nologo\n" );
522 }
523
524 n++;
525 }
526
527 if ( cfgs.size() != 0 )
528 {
529 fprintf ( OUT, "\n" );
530 fprintf ( OUT, "!ENDIF \n" );
531 fprintf ( OUT, "\n" );
532 }
533
534 if ( module.name == "winebuild" )
535 {
536 fprintf ( OUT, "# Begin Special Build Tool\n" );
537 fprintf ( OUT, "SOURCE=\"$(InputPath)\"\n" );
538 fprintf ( OUT, "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\n" );
539 fprintf ( OUT, "PostBuild_Cmds=" );
540 fprintf ( OUT, "copy ..\\..\\library\\%s\\wine.dll $(OutDir)\t",
541 output_dir.c_str() );
542 fprintf ( OUT, "copy ..\\..\\unicode\\%s\\wine_unicode.dll $(OutDir)\n",
543 output_dir.c_str() );
544 fprintf ( OUT, "# End Special Build Tool\n" );
545 }
546 fprintf ( OUT, "# Begin Target\n" );
547 fprintf ( OUT, "\n" );
548 for ( i = 0; i < cfgs.size(); i++ )
549 {
550 fprintf ( OUT, "# Name \"%s\"\n", cfgs[i].c_str() );
551 }
552
553 fprintf ( OUT, "# Begin Group \"Source Files\"\n" );
554 fprintf ( OUT, "\n" );
555 fprintf ( OUT, "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\n" );
556
557 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
558 {
559 string source_file = DosSeparator(source_files[isrcfile]);
560
561 if ( strncmp ( source_file.c_str(), ".\\", 2 ) )
562 {
563 source_file = string(".\\") + source_file;
564 }
565
566 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
567 {
568 string basename = string ( source_file.c_str(), source_file.size() - 5 );
569
570 // TODO FIXME - not sure what this is doing? wine hack maybe?
571 //if ( $basename !~ /\..{1,3}$/; ) basename += string(".dll");
572 string dbg_c_file = basename + ".dbg.c";
573
574 fprintf ( OUT, "# Begin Source File\n" );
575 fprintf ( OUT, "\n" );
576 fprintf ( OUT, "SOURCE=%s\n", dbg_c_file.c_str() );
577 fprintf ( OUT, "# End Source File\n" );
578 }
579
580 fprintf ( OUT, "# Begin Source File\n" );
581 fprintf ( OUT, "\n" );
582
583 fprintf ( OUT, "SOURCE=%s\n", source_file.c_str() );
584
585 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
586 {
587 string basename = string ( source_file.c_str(), source_file.size() - 5 );
588
589 string spec_file = source_file;
590 string def_file = basename + ".def";
591
592 // TODO FIXME - not sure what this is doing? wine hack maybe?
593 //if ( $basename !~ /\..{1,3}$/; ) basename += ".dll";
594 string dbg_file = basename + ".dbg";
595 string dbg_c_file = basename + ".dbg.c";
596
597 string srcdir = "."; // FIXME: Is this really always correct?
598
599 fprintf ( OUT, "# Begin Custom Build\n" );
600 fprintf ( OUT, "InputPath=%s\n", spec_file.c_str() );
601 fprintf ( OUT, "\n" );
602 fprintf ( OUT, "BuildCmds= \\\n" );
603 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe --def %s > %s \\\n",
604 output_dir.c_str(),
605 spec_file.c_str(),
606 def_file.c_str() );
607
608 if ( module.name == "ntdll" )
609 {
610 int n = 0;
611 for ( i = 0; i < c_srcs.size(); i++ )
612 {
613 const string& c_src = c_srcs[i];
614 if(n++ > 0)
615 {
616 fprintf ( OUT, "\techo %s >> %s \\\n", c_src.c_str(), dbg_file.c_str() );
617 }
618 else
619 {
620 fprintf ( OUT, "\techo %s > %s \\\n", c_src.c_str(), dbg_file.c_str() );
621 }
622 }
623 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
624 output_dir.c_str() );
625 fprintf ( OUT, " -o %s --debug -C%s %s \\\n",
626 dbg_c_file.c_str(),
627 srcdir.c_str(),
628 dbg_file.c_str() );
629 }
630 else
631 {
632 string sc_srcs;
633 for ( i = 0; i < c_srcs.size(); i++ )
634 {
635 const string& c_src = c_srcs[i];
636 if ( !strcmp ( &c_src[c_src.size()-2], ".c" ) )
637 {
638 if ( sc_srcs.size() )
639 sc_srcs += " ";
640 sc_srcs += c_src;
641 }
642 }
643
644 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
645 output_dir.c_str() );
646 fprintf ( OUT, " -o %s --debug -C%s %s \\\n",
647 dbg_c_file.c_str(),
648 srcdir.c_str(),
649 sc_srcs.c_str() );
650 }
651
652 fprintf ( OUT, "\t\n" );
653 fprintf ( OUT, "\n" );
654 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n", def_file.c_str() );
655 fprintf ( OUT, " $(BuildCmds)\n" );
656 fprintf ( OUT, "\n" );
657 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n", dbg_c_file.c_str() );
658 fprintf ( OUT, " $(BuildCmds)\n" );
659 fprintf ( OUT, "# End Custom Build\n" );
660 }
661 /*else if ( source_file =~ /([^\\]*?\.h)$/ )
662 {
663 my $h_file = $1;
664
665 foreach my $cfg (@cfgs) {
666 if($#cfgs == 0) {
667 # Nothing
668 } elsif($n == 0) {
669 fprintf ( OUT, "!IF \"$(CFG)\" == \"$cfg\"\n" );
670 fprintf ( OUT, "\n" );
671 } else {
672 fprintf ( OUT, "\n" );
673 fprintf ( OUT, "!ELSEIF \"$(CFG)\" == \"$cfg\"\n" );
674 fprintf ( OUT, "\n" );
675 }
676
677 $output_dir = $cfg;
678 $output_dir =~ s/^$project - //;
679 $output_dir =~ s/ /_/g;
680 $output_dir =~ s/C\+\+/Cxx/g;
681 if($output_prefix_dir) {
682 $output_dir = "$output_prefix_dir\\$output_dir" );
683 }
684
685 fprintf ( OUT, "# Begin Custom Build\n" );
686 fprintf ( OUT, "OutDir=%s\n", output_dir.c_str() );
687 fprintf ( OUT, "InputPath=%s\n", source_file.c_str() );
688 fprintf ( OUT, "\n" );
689 fprintf ( OUT, "\"$(OutDir)\\wine\\%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n", h_file.c_str() );
690 fprintf ( OUT, "\tcopy \"$(InputPath)\" \"$(OutDir)\\wine\"\n" );
691 fprintf ( OUT, "\n" );
692 fprintf ( OUT, "# End Custom Build\n" );
693 }
694
695 if ( cfgs.size() != 0)
696 {
697 fprintf ( OUT, "\n" );
698 fprintf ( OUT, "!ENDIF \n" );
699 fprintf ( OUT, "\n" );
700 }
701 }*/
702
703 fprintf ( OUT, "# End Source File\n" );
704 }
705 fprintf ( OUT, "# End Group\n" );
706
707 fprintf ( OUT, "# Begin Group \"Header Files\"\n" );
708 fprintf ( OUT, "\n" );
709 fprintf ( OUT, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\n" );
710 for ( i = 0; i < header_files.size(); i++ )
711 {
712 const string& header_file = header_files[i];
713 fprintf ( OUT, "# Begin Source File\n" );
714 fprintf ( OUT, "\n" );
715 fprintf ( OUT, "SOURCE=.\\%s\n", header_file.c_str() );
716 fprintf ( OUT, "# End Source File\n" );
717 }
718 fprintf ( OUT, "# End Group\n" );
719
720
721
722 fprintf ( OUT, "# Begin Group \"Resource Files\"\n" );
723 fprintf ( OUT, "\n" );
724 fprintf ( OUT, "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\n" );
725 for ( i = 0; i < resource_files.size(); i++ )
726 {
727 const string& resource_file = resource_files[i];
728 fprintf ( OUT, "# Begin Source File\n" );
729 fprintf ( OUT, "\n" );
730 fprintf ( OUT, "SOURCE=.\\%s\n", resource_file.c_str() );
731 fprintf ( OUT, "# End Source File\n" );
732 }
733 fprintf ( OUT, "# End Group\n" );
734
735 fprintf ( OUT, "# End Target\n" );
736 fprintf ( OUT, "# End Project\n" );
737
738 fclose(OUT);
739 }
740
741 void
742 MSVCBackend::_generate_dsw_header ( FILE* OUT )
743 {
744 fprintf ( OUT, "Microsoft Developer Studio Workspace File, Format Version 6.00\n" );
745 fprintf ( OUT, "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\n" );
746 fprintf ( OUT, "\n" );
747 }
748
749 void
750 MSVCBackend::_generate_dsw_project (
751 FILE* OUT,
752 const Module& module,
753 std::string dsp_file,
754 const std::vector<Dependency*>& dependencies )
755 {
756 dsp_file = std::string(".\\") + dsp_file;
757 // TODO FIXME - what does next line do?
758 //$dsp_file =~ y%/%\\%;
759
760 // TODO FIXME - must they be sorted?
761 //@dependencies = sort(@dependencies);
762
763 fprintf ( OUT, "###############################################################################\n" );
764 fprintf ( OUT, "\n" );
765 fprintf ( OUT, "Project: \"%s\"=%s - Package Owner=<4>\n", module.name.c_str(), dsp_file.c_str() );
766 fprintf ( OUT, "\n" );
767 fprintf ( OUT, "Package=<5>\n" );
768 fprintf ( OUT, "{{{\n" );
769 fprintf ( OUT, "}}}\n" );
770 fprintf ( OUT, "\n" );
771 fprintf ( OUT, "Package=<4>\n" );
772 fprintf ( OUT, "{{{\n" );
773 for ( size_t i = 0; i < dependencies.size(); i++ )
774 {
775 Dependency& dependency = *dependencies[i];
776 fprintf ( OUT, " Begin Project Dependency\n" );
777 fprintf ( OUT, " Project_Dep_Name %s\n", dependency.module.name.c_str() );
778 fprintf ( OUT, " End Project Dependency\n" );
779 }
780 fprintf ( OUT, "}}}\n" );
781 fprintf ( OUT, "\n" );
782 }
783
784 void
785 MSVCBackend::_generate_dsw_footer ( FILE* OUT )
786 {
787 fprintf ( OUT, "###############################################################################\n" );
788 fprintf ( OUT, "\n" );
789 fprintf ( OUT, "Global:\n" );
790 fprintf ( OUT, "\n" );
791 fprintf ( OUT, "Package=<5>\n" );
792 fprintf ( OUT, "{{{\n" );
793 fprintf ( OUT, "}}}\n" );
794 fprintf ( OUT, "\n" );
795 fprintf ( OUT, "Package=<3>\n" );
796 fprintf ( OUT, "{{{\n" );
797 fprintf ( OUT, "}}}\n" );
798 fprintf ( OUT, "\n" );
799 fprintf ( OUT, "###############################################################################\n" );
800 fprintf ( OUT, "\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 //foreach my $module (sort(keys(%modules)))
810 {
811 Module& module = *ProjectNode.modules[i];
812
813 //my $project = module->{project};
814 std::string dsp_file = DspFileName ( module );
815
816 // TODO FIXME - more wine hacks?
817 /*if($project =~ /^gdi32$/) {
818 foreach my $dir (@gdi32_dirs) {
819 my $dir2 = $dir;
820 $dir2 =~ s%^.*?/([^/]+)$%$1%;
821
822 my $module = "gdi32_$dir2";
823 $module =~ s%/%_%g;
824 push @dependencies, $module;
825 }
826 }*/
827
828 _generate_dsw_project ( OUT, module, dsp_file, module.dependencies );
829 }
830 _generate_dsw_footer ( OUT );
831 }