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