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