add . to list of include directories for all projects
[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 fprintf ( OUT, " /I \".\"" );
312 for ( i = 0; i < defines.size(); i++ )
313 {
314 fprintf ( OUT, " /D \"%s\"", defines[i].c_str() );
315 }
316 if ( lib || exe ) fprintf ( OUT, " /YX" );
317 fprintf ( OUT, " /FD" );
318 if ( debug )
319 {
320 fprintf ( OUT, " /GZ" );
321 if ( lib || exe ) fprintf ( OUT, " " );
322 }
323 fprintf ( OUT, " /c" );
324 fprintf ( OUT, "\r\n" );
325
326 vector<string> defines2;
327 defines2.push_back ( "WINVER=0x0501" );
328 defines2.push_back ( "_WIN32_WINNT=0x0501" );
329 defines2.push_back ( "_WIN32_IE=0x0600" );
330 defines2.push_back ( "WIN32" );
331 defines2.push_back ( "_WINDOWS" );
332 defines2.push_back ( "_MBCS" );
333 if ( debug )
334 {
335 defines2.push_back ( "_DEBUG" );
336 if(lib)
337 {
338 fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
339 defines2.push_back ( "_LIB" );
340 }
341 else
342 {
343 fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
344 defines2.push_back ( "_USRDLL" );
345 }
346 }
347 else
348 {
349 defines2.push_back ( "NDEBUG" );
350 if(lib)
351 {
352 fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
353 defines2.push_back ( "_LIB" );
354 }
355 else
356 {
357 fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
358 defines2.push_back ( "_USRDLL" );
359 }
360 }
361
362 std::vector<std::string> includes;
363 // TODO FIXME - wine hack?
364 if ( wine )
365 {
366 // TODO FIXME - wine hack?
367 //defines2.push_back ( string("_\U") + module.name + "\E_" );
368 // TODO FIXME - wine hack?
369 /*if ( module.name !~ /^(?:wine(?:build|test)|.*?_test)$/ )
370 defines2.push_back ( "__WINESRC__" );*/
371 if ( msvc_headers )
372 defines2.push_back ( "__WINE_USE_NATIVE_HEADERS" );
373 string output_dir2 = Replace(output_dir,"\\","\\\\");
374 defines2.push_back ( ssprintf("__WINETEST_OUTPUT_DIR=\\\"%s\\\"",output_dir.c_str()) );
375 defines2.push_back ( "__i386__" );
376 defines2.push_back ( "_X86_" );
377
378 // TODO FIXME - wine hacks?
379 /*if(module.name =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
380 push @includes, ".." );
381 }
382
383 if ( strstr ( module.name.c_str(), "_test" )
384 {
385 include.push_back ( msvc_wine_dir + "\\" + output_dir );
386 }
387
388 if (!msvc_headers || module.name == "winetest")
389 {
390 includes.push_back ( wine_include_dir );
391 }*/
392 }
393
394 if ( wine )
395 {
396 for ( i = 0; i < includes.size(); i++ );
397 {
398 const string& include = includes[i];
399 if ( strpbrk ( include.c_str(), "[\\\"]" ) )
400 {
401 fprintf ( OUT, " /I \"%s\"", include.c_str() );
402 }
403 else
404 {
405 fprintf ( OUT, " /I %s", include.c_str() );
406 }
407 }
408 }
409
410 fprintf ( OUT, " /I \".\"" );
411 for ( i = 0; i < defines2.size(); i++ )
412 {
413 const string& define = defines2[i];
414 if ( strpbrk ( define.c_str(), "[\\\"]" ) )
415 {
416 fprintf ( OUT, " /D \"%s\"", define.c_str() );
417 }
418 else
419 {
420 fprintf ( OUT, " /D %s", define.c_str() );
421 }
422 }
423 if ( wine ) fprintf ( OUT, " /D inline=__inline" );
424 if ( 0 && wine ) fprintf ( OUT, " /D \"__STDC__\"" );
425
426 fprintf ( OUT, lib ? " /YX" : " /FR" );
427 fprintf ( OUT, " /FD" );
428 if ( debug ) fprintf ( OUT, " /GZ" );
429 if ( debug && lib ) fprintf ( OUT, " " );
430 fprintf ( OUT, " /c" );
431 if ( !no_cpp ) fprintf ( OUT, " /TP" );
432 fprintf ( OUT, "\r\n" );
433
434 if ( debug )
435 {
436 if ( dll )
437 {
438 fprintf ( OUT, "# SUBTRACT CPP /X /YX\r\n" );
439 fprintf ( OUT, "# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" );
440 fprintf ( OUT, "# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n" );
441 }
442 fprintf ( OUT, "# ADD BASE RSC /l 0x41d /d \"_DEBUG\"\r\n" );
443 fprintf ( OUT, "# ADD RSC /l 0x41d" );
444 if ( wine )
445 {
446 for ( i = 0; i < includes.size(); i++ )
447 {
448 fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
449 }
450 }
451 fprintf ( OUT, " /d \"_DEBUG\"\r\n" );
452 }
453 else
454 {
455 if ( dll )
456 {
457 fprintf ( OUT, "# SUBTRACT CPP /YX\r\n" );
458 fprintf ( OUT, "# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" );
459 fprintf ( OUT, "# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n" );
460 }
461 fprintf ( OUT, "# ADD BASE RSC /l 0x41d /d \"NDEBUG\"\r\n" );
462 fprintf ( OUT, "# ADD RSC /l 0x41d" );
463 if ( wine )
464 {
465 for ( i = 0; i < includes.size(); i++ )
466 fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
467 }
468 fprintf ( OUT, "/d \"NDEBUG\"\r\n" );
469 }
470 fprintf ( OUT, "BSC32=bscmake.exe\r\n" );
471 fprintf ( OUT, "# ADD BASE BSC32 /nologo\r\n" );
472 fprintf ( OUT, "# ADD BSC32 /nologo\r\n" );
473
474 if ( exe || dll )
475 {
476 fprintf ( OUT, "LINK32=link.exe\r\n" );
477 fprintf ( OUT, "# ADD BASE LINK32 " );
478 vector<string> libraries;
479 libraries.push_back ( "kernel32.lib" );
480 libraries.push_back ( "user32.lib" );
481 libraries.push_back ( "gdi32.lib" );
482 libraries.push_back ( "winspool.lib" );
483 libraries.push_back ( "comdlg32.lib" );
484 libraries.push_back ( "advapi32.lib" );
485 libraries.push_back ( "shell32.lib" );
486 libraries.push_back ( "ole32.lib" );
487 libraries.push_back ( "oleaut32.lib" );
488 libraries.push_back ( "uuid.lib" );
489 libraries.push_back ( "odbc32.lib" );
490 libraries.push_back ( "odbccp32.lib" );
491 for ( i = 0; i < libraries.size(); i++ )
492 {
493 fprintf ( OUT, "%s ", libraries[i].c_str() );
494 }
495 fprintf ( OUT, " /nologo" );
496 if ( dll ) fprintf ( OUT, " /dll" );
497 if ( console ) fprintf ( OUT, " /subsystem:console" );
498 if ( debug ) fprintf ( OUT, " /debug" );
499 fprintf ( OUT, " /machine:I386" );
500 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
501 fprintf ( OUT, "\r\n" );
502
503 fprintf ( OUT, "# ADD LINK32" );
504 fprintf ( OUT, " /nologo" );
505 // TODO FIXME - do we need their kludge?
506 //if ( module.name == "ntdll" ) fprintf ( OUT, " libcmt.lib" ); // FIXME: Kludge
507 for ( i = 0; i < imports.size(); i++ )
508 {
509 const string& import = imports[i];
510 if ( import != "msvcrt" )
511 fprintf ( OUT, " %s.lib", import.c_str() );
512 }
513 if ( dll ) fprintf ( OUT, " /dll" );
514 if ( console ) fprintf ( OUT, " /subsystem:console" );
515 if ( debug ) fprintf ( OUT, " /debug" );
516 fprintf ( OUT, " /machine:I386" );
517 // TODO FIXME - do we need their kludge?
518 //if ( module.name == "ntdll" ) fprintf ( OUT, " /nodefaultlib" ); // FIXME: Kludge
519 if ( dll ) fprintf ( OUT, " /def:\"%s.def\"", module.name.c_str() );
520 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
521 fprintf ( OUT, "\r\n" );
522 }
523 else
524 {
525 fprintf ( OUT, "LIB32=link.exe -lib\r\n" );
526 fprintf ( OUT, "# ADD BASE LIB32 /nologo\r\n" );
527 fprintf ( OUT, "# ADD LIB32 /nologo\r\n" );
528 }
529
530 n++;
531 }
532
533 if ( cfgs.size() != 0 )
534 {
535 fprintf ( OUT, "\r\n" );
536 fprintf ( OUT, "!ENDIF \r\n" );
537 fprintf ( OUT, "\r\n" );
538 }
539 #if 0
540 if ( module.name == "winebuild" )
541 {
542 fprintf ( OUT, "# Begin Special Build Tool\r\n" );
543 fprintf ( OUT, "SOURCE=\"$(InputPath)\"\r\n" );
544 fprintf ( OUT, "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n" );
545 fprintf ( OUT, "PostBuild_Cmds=" );
546 fprintf ( OUT, "copy ..\\..\\library\\%s\\wine.dll $(OutDir)\t",
547 output_dir.c_str() );
548 fprintf ( OUT, "copy ..\\..\\unicode\\%s\\wine_unicode.dll $(OutDir)\r\n",
549 output_dir.c_str() );
550 fprintf ( OUT, "# End Special Build Tool\r\n" );
551 }
552 #endif
553 fprintf ( OUT, "# Begin Target\r\n" );
554 fprintf ( OUT, "\r\n" );
555 for ( i = 0; i < cfgs.size(); i++ )
556 {
557 fprintf ( OUT, "# Name \"%s\"\r\n", cfgs[i].c_str() );
558 }
559
560 fprintf ( OUT, "# Begin Group \"Source Files\"\r\n" );
561 fprintf ( OUT, "\r\n" );
562 fprintf ( OUT, "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n" );
563
564 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
565 {
566 string source_file = DosSeparator(source_files[isrcfile]);
567
568 if ( strncmp ( source_file.c_str(), ".\\", 2 ) )
569 {
570 source_file = string(".\\") + source_file;
571 }
572 #if 0
573 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
574 {
575 string basename = string ( source_file.c_str(), source_file.size() - 5 );
576
577 // TODO FIXME - not sure what this is doing? wine hack maybe?
578 //if ( basename !~ /\..{1,3}$/; ) basename += string(".dll");
579 string dbg_c_file = basename + ".dbg.c";
580
581 fprintf ( OUT, "# Begin Source File\r\n" );
582 fprintf ( OUT, "\r\n" );
583 fprintf ( OUT, "SOURCE=%s\r\n", dbg_c_file.c_str() );
584 fprintf ( OUT, "# End Source File\r\n" );
585 }
586 #endif
587 fprintf ( OUT, "# Begin Source File\r\n" );
588 fprintf ( OUT, "\r\n" );
589
590 fprintf ( OUT, "SOURCE=%s\r\n", source_file.c_str() );
591
592 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
593 {
594 #if 0
595 string basename = string ( source_file.c_str(), source_file.size() - 5 );
596
597 string spec_file = source_file;
598 string def_file = basename + ".def";
599
600 // TODO FIXME - not sure what this is doing? wine hack maybe?
601 //if ( basename !~ /\..{1,3}$/; ) basename += ".dll";
602 string dbg_file = basename + ".dbg";
603 string dbg_c_file = basename + ".dbg.c";
604
605 string srcdir = "."; // FIXME: Is this really always correct?
606
607 fprintf ( OUT, "# Begin Custom Build\r\n" );
608 fprintf ( OUT, "InputPath=%s\r\n", spec_file.c_str() );
609 fprintf ( OUT, "\r\n" );
610 fprintf ( OUT, "BuildCmds= \\\r\n" );
611 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe --def %s > %s \\\r\n",
612 output_dir.c_str(),
613 spec_file.c_str(),
614 def_file.c_str() );
615
616 if ( module.name == "ntdll" )
617 {
618 int n = 0;
619 for ( i = 0; i < c_srcs.size(); i++ )
620 {
621 const string& c_src = c_srcs[i];
622 if(n++ > 0)
623 {
624 fprintf ( OUT, "\techo %s >> %s \\\r\n", c_src.c_str(), dbg_file.c_str() );
625 }
626 else
627 {
628 fprintf ( OUT, "\techo %s > %s \\\r\n", c_src.c_str(), dbg_file.c_str() );
629 }
630 }
631 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
632 output_dir.c_str() );
633 fprintf ( OUT, " -o %s --debug -C%s %s \\\r\n",
634 dbg_c_file.c_str(),
635 srcdir.c_str(),
636 dbg_file.c_str() );
637 }
638 else
639 {
640 string sc_srcs;
641 for ( i = 0; i < c_srcs.size(); i++ )
642 {
643 const string& c_src = c_srcs[i];
644 if ( !strcmp ( &c_src[c_src.size()-2], ".c" ) )
645 {
646 if ( sc_srcs.size() )
647 sc_srcs += " ";
648 sc_srcs += c_src;
649 }
650 }
651
652 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
653 output_dir.c_str() );
654 fprintf ( OUT, " -o %s --debug -C%s %s \\\r\n",
655 dbg_c_file.c_str(),
656 srcdir.c_str(),
657 sc_srcs.c_str() );
658 }
659
660 fprintf ( OUT, "\t\r\n" );
661 fprintf ( OUT, "\r\n" );
662 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", def_file.c_str() );
663 fprintf ( OUT, " $(BuildCmds)\r\n" );
664 fprintf ( OUT, "\r\n" );
665 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", dbg_c_file.c_str() );
666 fprintf ( OUT, " $(BuildCmds)\r\n" );
667 fprintf ( OUT, "# End Custom Build\r\n" );
668 #endif
669 }
670 /*else if ( source_file =~ /([^\\]*?\.h)$/ )
671 {
672 my $h_file = $1;
673
674 foreach my $cfg (@cfgs) {
675 if($#cfgs == 0) {
676 # Nothing
677 } elsif($n == 0) {
678 fprintf ( OUT, "!IF \"$(CFG)\" == \"$cfg\"\r\n" );
679 fprintf ( OUT, "\r\n" );
680 } else {
681 fprintf ( OUT, "\r\n" );
682 fprintf ( OUT, "!ELSEIF \"$(CFG)\" == \"$cfg\"\r\n" );
683 fprintf ( OUT, "\r\n" );
684 }
685
686 $output_dir = $cfg;
687 $output_dir =~ s/^$project - //;
688 $output_dir =~ s/ /_/g;
689 $output_dir =~ s/C\+\+/Cxx/g;
690 if($output_prefix_dir) {
691 $output_dir = "$output_prefix_dir\\$output_dir" );
692 }
693
694 fprintf ( OUT, "# Begin Custom Build\r\n" );
695 fprintf ( OUT, "OutDir=%s\r\n", output_dir.c_str() );
696 fprintf ( OUT, "InputPath=%s\r\n", source_file.c_str() );
697 fprintf ( OUT, "\r\n" );
698 fprintf ( OUT, "\"$(OutDir)\\wine\\%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", h_file.c_str() );
699 fprintf ( OUT, "\tcopy \"$(InputPath)\" \"$(OutDir)\\wine\"\r\n" );
700 fprintf ( OUT, "\r\n" );
701 fprintf ( OUT, "# End Custom Build\r\n" );
702 }
703
704 if ( cfgs.size() != 0)
705 {
706 fprintf ( OUT, "\r\n" );
707 fprintf ( OUT, "!ENDIF \r\n" );
708 fprintf ( OUT, "\r\n" );
709 }
710 }*/
711
712 fprintf ( OUT, "# End Source File\r\n" );
713 }
714 fprintf ( OUT, "# End Group\r\n" );
715 fprintf ( OUT, "# Begin Group \"Header Files\"\r\n" );
716 fprintf ( OUT, "\r\n" );
717 fprintf ( OUT, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n" );
718 for ( i = 0; i < header_files.size(); i++ )
719 {
720 const string& header_file = header_files[i];
721 fprintf ( OUT, "# Begin Source File\r\n" );
722 fprintf ( OUT, "\r\n" );
723 fprintf ( OUT, "SOURCE=.\\%s\r\n", header_file.c_str() );
724 fprintf ( OUT, "# End Source File\r\n" );
725 }
726 fprintf ( OUT, "# End Group\r\n" );
727
728
729
730 fprintf ( OUT, "# Begin Group \"Resource Files\"\r\n" );
731 fprintf ( OUT, "\r\n" );
732 fprintf ( OUT, "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n" );
733 for ( i = 0; i < resource_files.size(); i++ )
734 {
735 const string& resource_file = resource_files[i];
736 fprintf ( OUT, "# Begin Source File\r\n" );
737 fprintf ( OUT, "\r\n" );
738 fprintf ( OUT, "SOURCE=.\\%s\r\n", resource_file.c_str() );
739 fprintf ( OUT, "# End Source File\r\n" );
740 }
741 fprintf ( OUT, "# End Group\r\n" );
742
743 fprintf ( OUT, "# End Target\r\n" );
744 fprintf ( OUT, "# End Project\r\n" );
745
746 fclose(OUT);
747 }
748
749 void
750 MSVCBackend::_generate_dsw_header ( FILE* OUT )
751 {
752 fprintf ( OUT, "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n" );
753 fprintf ( OUT, "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n" );
754 fprintf ( OUT, "\r\n" );
755 }
756
757 void
758 MSVCBackend::_generate_dsw_project (
759 FILE* OUT,
760 const Module& module,
761 std::string dsp_file,
762 const std::vector<Dependency*>& dependencies )
763 {
764 dsp_file = DosSeparator ( std::string(".\\") + dsp_file );
765
766 // TODO FIXME - must they be sorted?
767 //@dependencies = sort(@dependencies);
768
769 fprintf ( OUT, "###############################################################################\r\n" );
770 fprintf ( OUT, "\r\n" );
771 fprintf ( OUT, "Project: \"%s\"=%s - Package Owner=<4>\r\n", module.name.c_str(), dsp_file.c_str() );
772 fprintf ( OUT, "\r\n" );
773 fprintf ( OUT, "Package=<5>\r\n" );
774 fprintf ( OUT, "{{{\r\n" );
775 fprintf ( OUT, "}}}\r\n" );
776 fprintf ( OUT, "\r\n" );
777 fprintf ( OUT, "Package=<4>\r\n" );
778 fprintf ( OUT, "{{{\r\n" );
779 for ( size_t i = 0; i < dependencies.size(); i++ )
780 {
781 Dependency& dependency = *dependencies[i];
782 fprintf ( OUT, " Begin Project Dependency\r\n" );
783 fprintf ( OUT, " Project_Dep_Name %s\r\n", dependency.module.name.c_str() );
784 fprintf ( OUT, " End Project Dependency\r\n" );
785 }
786 fprintf ( OUT, "}}}\r\n" );
787 fprintf ( OUT, "\r\n" );
788 }
789
790 void
791 MSVCBackend::_generate_dsw_footer ( FILE* OUT )
792 {
793 fprintf ( OUT, "###############################################################################\r\n" );
794 fprintf ( OUT, "\r\n" );
795 fprintf ( OUT, "Global:\r\n" );
796 fprintf ( OUT, "\r\n" );
797 fprintf ( OUT, "Package=<5>\r\n" );
798 fprintf ( OUT, "{{{\r\n" );
799 fprintf ( OUT, "}}}\r\n" );
800 fprintf ( OUT, "\r\n" );
801 fprintf ( OUT, "Package=<3>\r\n" );
802 fprintf ( OUT, "{{{\r\n" );
803 fprintf ( OUT, "}}}\r\n" );
804 fprintf ( OUT, "\r\n" );
805 fprintf ( OUT, "###############################################################################\r\n" );
806 fprintf ( OUT, "\r\n" );
807 }
808
809 void
810 MSVCBackend::_generate_wine_dsw ( FILE* OUT )
811 {
812 _generate_dsw_header(OUT);
813 // TODO FIXME - is it necessary to sort them?
814 for ( size_t i = 0; i < ProjectNode.modules.size(); i++ )
815 {
816 Module& module = *ProjectNode.modules[i];
817
818 std::string dsp_file = DspFileName ( module );
819
820 // TODO FIXME - more wine hacks?
821 /*if ( module.name == "gdi32" )
822 {
823 for ( size_t idir = 0; idir < gdi32_dirs.size(); idir++ )
824 {
825 string dir2 = gdi32_dirs[idir];
826 $dir2 =~ s%^.*?/([^/]+)$%$1%;
827
828 dependencies.push_back ( Replace ( "gdi32_" + dir2, "/", "_" ) );
829 }
830 }*/
831
832 _generate_dsw_project ( OUT, module, dsp_file, module.dependencies );
833 }
834 _generate_dsw_footer ( OUT );
835 }