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