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