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