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