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