* Bring back rbuild build to be used until bug 6372 is fixed.
[reactos.git] / 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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.output);
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 vector<string> c_srcs, source_files, header_files, resource_files, includes, libraries;
86 StringSet common_defines;
87 vector<const IfableData*> ifs_list;
88 ifs_list.push_back ( &module.project.non_if_data );
89 ifs_list.push_back ( &module.non_if_data );
90
91 // this is a define in MinGW w32api, but not Microsoft's headers
92 common_defines.insert ( "STDCALL=__stdcall" );
93
94 while ( ifs_list.size() )
95 {
96 const IfableData& data = *ifs_list.back();
97 ifs_list.pop_back();
98 const vector<File*>& files = data.files;
99 for ( i = 0; i < files.size(); i++ )
100 {
101 if (files[i]->file.directory != SourceDirectory)
102 continue;
103
104 // We want the full path here for directory support later on
105 string path = Path::RelativeFromDirectory (
106 files[i]->file.relative_path,
107 module.output->relative_path );
108 string file = path + std::string("\\") + files[i]->file.name;
109
110 source_files.push_back ( file );
111 if ( !stricmp ( Right(file,2).c_str(), ".c" ) )
112 c_srcs.push_back ( file );
113 if ( !stricmp ( Right(file,2).c_str(), ".h" ) )
114 header_files.push_back ( file );
115 if ( !stricmp ( Right(file,3).c_str(), ".rc" ) )
116 resource_files.push_back ( file );
117 }
118 const vector<Include*>& incs = data.includes;
119 for ( i = 0; i < incs.size(); i++ )
120 {
121 string path = Path::RelativeFromDirectory (
122 incs[i]->directory->relative_path,
123 module.output->relative_path );
124 includes.push_back ( path );
125 }
126 const vector<Library*>& libs = data.libraries;
127 for ( i = 0; i < libs.size(); i++ )
128 {
129 libraries.push_back ( libs[i]->name + ".lib" );
130 }
131 const vector<Define*>& defs = data.defines;
132 for ( i = 0; i < defs.size(); i++ )
133 {
134 if ( defs[i]->value[0] )
135 common_defines.insert( defs[i]->name + "=" + defs[i]->value );
136 else
137 common_defines.insert( defs[i]->name );
138 }
139 }
140 // TODO FIXME - we don't include header files in our build system
141 //my @header_files = @{module->{header_files}};
142 //vector<string> header_files;
143
144 // TODO FIXME - wine hack?
145 /*if (module.name !~ /^wine(?:_unicode|build|runtests|test)?$/ &&
146 module.name !~ /^(?:gdi32)_.+?$/ &&
147 Right ( module.name, 5 ) == "_test" )
148 {
149 source_files.push_back ( module.name + ".spec" );
150 @source_files = sort(@source_files);
151 }*/
152
153 bool no_cpp = true;
154 bool no_msvc_headers = true;
155 // TODO FIXME - wine hack?
156 /*if (module.name =~ /^wine(?:runtests|test)$/
157 || Right ( module.name, 5 ) == "_test" )
158 {
159 no_msvc_headers = false;
160 }*/
161
162 std::vector<std::string> cfgs;
163
164 cfgs.push_back ( module.name + " - Win32" );
165
166 if (!no_cpp)
167 {
168 std::vector<std::string> _cfgs;
169 for ( i = 0; i < cfgs.size(); i++ )
170 {
171 _cfgs.push_back ( cfgs[i] + " C" );
172 _cfgs.push_back ( cfgs[i] + " C++" );
173 }
174 cfgs.resize(0);
175 cfgs = _cfgs;
176 }
177
178 // TODO FIXME - wine hack?
179 /*if (!no_release)
180 {
181 std::vector<std::string> _cfgs;
182 for ( i = 0; i < cfgs.size(); i++ )
183 {
184 _cfgs.push_back ( cfgs[i] + " Debug" );
185 _cfgs.push_back ( cfgs[i] + " Release" );
186 }
187 cfgs.resize(0);
188 cfgs = _cfgs;
189 }*/
190
191 if (!no_msvc_headers)
192 {
193 std::vector<std::string> _cfgs;
194 for ( i = 0; i < cfgs.size(); i++ )
195 {
196 _cfgs.push_back ( cfgs[i] + " MSVC Headers" );
197 _cfgs.push_back ( cfgs[i] + " Wine Headers" );
198 }
199 cfgs.resize(0);
200 cfgs = _cfgs;
201 }
202
203 string default_cfg = cfgs.back();
204
205 fprintf ( OUT, "# Microsoft Developer Studio Project File - Name=\"%s\" - Package Owner=<4>\r\n", module.name.c_str() );
206 fprintf ( OUT, "# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n" );
207 fprintf ( OUT, "# ** DO NOT EDIT **\r\n" );
208 fprintf ( OUT, "\r\n" );
209
210 if ( lib )
211 {
212 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\r\n" );
213 }
214 else if ( dll )
215 {
216 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Dynamic-Link Library\" 0x0102\r\n" );
217 }
218 else
219 {
220 fprintf ( OUT, "# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\r\n" );
221 }
222 fprintf ( OUT, "\r\n" );
223
224 fprintf ( OUT, "CFG=%s\r\n", default_cfg.c_str() );
225 fprintf ( OUT, "!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n" );
226 fprintf ( OUT, "!MESSAGE use the Export Makefile command and run\r\n" );
227 fprintf ( OUT, "!MESSAGE \r\n" );
228 fprintf ( OUT, "!MESSAGE NMAKE /f \"%s.mak\".\r\n", module.name.c_str() );
229 fprintf ( OUT, "!MESSAGE \r\n" );
230 fprintf ( OUT, "!MESSAGE You can specify a configuration when running NMAKE\r\n" );
231 fprintf ( OUT, "!MESSAGE by defining the macro CFG on the command line. For example:\r\n" );
232 fprintf ( OUT, "!MESSAGE \r\n" );
233 fprintf ( OUT, "!MESSAGE NMAKE /f \"%s.mak\" CFG=\"%s\"\r\n", module.name.c_str(), default_cfg.c_str() );
234 fprintf ( OUT, "!MESSAGE \r\n" );
235 fprintf ( OUT, "!MESSAGE Possible choices for configuration are:\r\n" );
236 fprintf ( OUT, "!MESSAGE \r\n" );
237 for ( i = 0; i < cfgs.size(); i++ )
238 {
239 const string& cfg = cfgs[i];
240 if ( lib )
241 {
242 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Static Library\")\r\n", cfg.c_str() );
243 }
244 else if ( dll )
245 {
246 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Dynamic-Link Library\")\r\n", cfg.c_str() );
247 }
248 else
249 {
250 fprintf ( OUT, "!MESSAGE \"%s\" (based on \"Win32 (x86) Console Application\")\r\n", cfg.c_str() );
251 }
252 }
253 fprintf ( OUT, "!MESSAGE \r\n" );
254 fprintf ( OUT, "\r\n" );
255
256 fprintf ( OUT, "# Begin Project\r\n" );
257 fprintf ( OUT, "# PROP AllowPerConfigDependencies 0\r\n" );
258 fprintf ( OUT, "# PROP Scc_ProjName \"\"\r\n" );
259 fprintf ( OUT, "# PROP Scc_LocalPath \"\"\r\n" );
260 fprintf ( OUT, "CPP=cl.exe\r\n" );
261 if ( !lib && !exe ) fprintf ( OUT, "MTL=midl.exe\r\n" );
262 fprintf ( OUT, "RSC=rc.exe\r\n" );
263
264 std::string output_dir;
265 for ( size_t icfg = 0; icfg < cfgs.size(); icfg++ )
266 {
267 std::string& cfg = cfgs[icfg];
268 if ( icfg == 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 bool debug = !strstr ( cfg.c_str(), "Release" );
281 bool msvc_headers = ( 0 != strstr ( cfg.c_str(), "MSVC Headers" ) );
282
283 fprintf ( OUT, "# PROP BASE Use_MFC 0\r\n" );
284
285 if ( debug )
286 {
287 fprintf ( OUT, "# PROP BASE Use_Debug_Libraries 1\r\n" );
288 }
289 else
290 {
291 fprintf ( OUT, "# PROP BASE Use_Debug_Libraries 0\r\n" );
292 }
293
294 output_dir = Replace(cfg,module.name + " - ","");
295 output_dir = Replace(output_dir," ","_");
296 output_dir = Replace(output_dir,"C++","Cxx");
297 // TODO FIXME - wine hack?
298 //if ( output_prefix_dir.size() )
299 // output_dir = output_prefix_dir + "\\" + output_dir;
300
301 fprintf ( OUT, "# PROP BASE Output_Dir \"%s\"\r\n", output_dir.c_str() );
302 fprintf ( OUT, "# PROP BASE Intermediate_Dir \"%s\"\r\n", output_dir.c_str() );
303
304 fprintf ( OUT, "# PROP BASE Target_Dir \"\"\r\n" );
305
306 fprintf ( OUT, "# PROP Use_MFC 0\r\n" );
307 if ( debug )
308 {
309 fprintf ( OUT, "# PROP Use_Debug_Libraries 1\r\n" );
310 }
311 else
312 {
313 fprintf ( OUT, "# PROP Use_Debug_Libraries 0\r\n" );
314 }
315 fprintf ( OUT, "# PROP Output_Dir \"%s\"\r\n", output_dir.c_str() );
316 fprintf ( OUT, "# PROP Intermediate_Dir \"%s\"\r\n", output_dir.c_str() );
317
318 if ( dll ) fprintf ( OUT, "# PROP Ignore_Export_Lib 0\r\n" );
319 fprintf ( OUT, "# PROP Target_Dir \"\"\r\n" );
320
321 StringSet defines = common_defines;
322
323 if ( debug )
324 {
325 defines.insert ( "_DEBUG" );
326 if ( lib || exe )
327 {
328 fprintf ( OUT, "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od" );
329 defines.insert ( "_LIB" );
330 }
331 else
332 {
333 fprintf ( OUT, "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
334 defines.insert ( "_WINDOWS" );
335 defines.insert ( "_USRDLL" );
336 // TODO FIXME - wine hack?
337 //defines.insert ( string("\U") + module.name + "\E_EXPORTS" );
338 }
339 }
340 else
341 {
342 defines.insert ( "NDEBUG" );
343 if ( lib || exe )
344 {
345 fprintf ( OUT, "# ADD BASE CPP /nologo /W3 /GX /O2" );
346 defines.insert ( "_LIB" );
347 }
348 else
349 {
350 fprintf ( OUT, "# ADD BASE CPP /nologo /MT /W3 /GX /O2" );
351 defines.insert ( "_WINDOWS" );
352 defines.insert ( "_USRDLL" );
353 // TODO FIXME - wine hack?
354 //defines.insert ( string("\U") + module.name + "\E_EXPORTS" );
355 }
356 }
357
358 for ( StringSet::const_iterator it1=defines.begin(); it1!=defines.end(); it1++ )
359 {
360 fprintf ( OUT, " /D \"%s\"", it1->c_str() );
361 }
362 if ( lib || exe ) fprintf ( OUT, " /YX" );
363 fprintf ( OUT, " /FD" );
364 if ( debug )
365 {
366 fprintf ( OUT, " /GZ" );
367 if ( lib || exe ) fprintf ( OUT, " " );
368 }
369 fprintf ( OUT, " /c" );
370 fprintf ( OUT, "\r\n" );
371
372 if ( debug )
373 {
374 defines.insert ( "_DEBUG" );
375 if(lib)
376 {
377 fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
378 defines.insert ( "_LIB" );
379 }
380 else
381 {
382 fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
383 defines.insert ( "_USRDLL" );
384 }
385 }
386 else
387 {
388 defines.insert ( "NDEBUG" );
389 if(lib)
390 {
391 fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
392 defines.insert ( "_LIB" );
393 }
394 else
395 {
396 fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
397 defines.insert ( "_USRDLL" );
398 }
399 }
400
401 // TODO FIXME - wine hack?
402 if ( wine )
403 {
404 // TODO FIXME - wine hack?
405 //defines.insert ( string("_\U") + module.name + "\E_" );
406 // TODO FIXME - wine hack?
407 /*if ( module.name !~ /^(?:wine(?:build|test)|.*?_test)$/ )
408 defines.insert ( "__WINESRC__" );*/
409 if ( msvc_headers )
410 defines.insert ( "__WINE_USE_NATIVE_HEADERS" );
411 string output_dir2 = Replace(output_dir,"\\","\\\\");
412 defines.insert ( ssprintf("__WINETEST_OUTPUT_DIR=\\\"%s\\\"",output_dir.c_str()) );
413 defines.insert ( "__i386__" );
414 defines.insert ( "_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 ( StringSet::const_iterator it2=defines.begin(); it2!=defines.end(); it2++ )
450 {
451 const string& define = *it2;
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 ( StringSet::const_iterator it3=defines.begin(); it3!=defines.end(); it3++ )
491 {
492 fprintf ( OUT, " /D \"%s\"", it3->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 ( StringSet::const_iterator it4=defines.begin(); it4!=defines.end(); it4++ )
513 {
514 fprintf ( OUT, " /D \"%s\"", it4->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 (( dll ) && ( module_type == ".cpl")) fprintf ( OUT, " /out:\"Win32\\%s%s\"", module.name.c_str(), module_type.c_str() );
559 if ( debug ) fprintf ( OUT, " /pdbtype:sept" );
560 fprintf ( OUT, "\r\n" );
561 }
562 else
563 {
564 fprintf ( OUT, "LIB32=link.exe -lib\r\n" );
565 fprintf ( OUT, "# ADD BASE LIB32 /nologo\r\n" );
566 fprintf ( OUT, "# ADD LIB32 /nologo\r\n" );
567 }
568 }
569
570 if ( cfgs.size() != 0 )
571 {
572 fprintf ( OUT, "\r\n" );
573 fprintf ( OUT, "!ENDIF \r\n" );
574 fprintf ( OUT, "\r\n" );
575 }
576 #if 0
577 if ( module.name == "winebuild" )
578 {
579 fprintf ( OUT, "# Begin Special Build Tool\r\n" );
580 fprintf ( OUT, "SOURCE=\"$(InputPath)\"\r\n" );
581 fprintf ( OUT, "PostBuild_Desc=Copying wine.dll and wine_unicode.dll ...\r\n" );
582 fprintf ( OUT, "PostBuild_Cmds=" );
583 fprintf ( OUT, "copy ..\\..\\library\\%s\\wine.dll $(OutDir)\t",
584 output_dir.c_str() );
585 fprintf ( OUT, "copy ..\\..\\unicode\\%s\\wine_unicode.dll $(OutDir)\r\n",
586 output_dir.c_str() );
587 fprintf ( OUT, "# End Special Build Tool\r\n" );
588 }
589 #endif
590 fprintf ( OUT, "# Begin Target\r\n" );
591 fprintf ( OUT, "\r\n" );
592 for ( i = 0; i < cfgs.size(); i++ )
593 {
594 fprintf ( OUT, "# Name \"%s\"\r\n", cfgs[i].c_str() );
595 }
596
597 fprintf ( OUT, "# Begin Group \"Source Files\"\r\n" );
598 fprintf ( OUT, "\r\n" );
599 fprintf ( OUT, "# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n" );
600
601 for ( size_t isrcfile = 0; isrcfile < source_files.size(); isrcfile++ )
602 {
603 string source_file = DosSeparator(source_files[isrcfile]);
604
605 if ( strncmp ( source_file.c_str(), ".\\", 2 ) )
606 {
607 source_file = string(".\\") + source_file;
608 }
609 #if 0
610 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
611 {
612 string basename = string ( source_file.c_str(), source_file.size() - 5 );
613
614 // TODO FIXME - not sure what this is doing? wine hack maybe?
615 //if ( basename !~ /\..{1,3}$/; ) basename += string(".dll");
616 string dbg_c_file = basename + ".dbg.c";
617
618 fprintf ( OUT, "# Begin Source File\r\n" );
619 fprintf ( OUT, "\r\n" );
620 fprintf ( OUT, "SOURCE=%s\r\n", dbg_c_file.c_str() );
621 fprintf ( OUT, "# End Source File\r\n" );
622 }
623 #endif
624 fprintf ( OUT, "# Begin Source File\r\n" );
625 fprintf ( OUT, "\r\n" );
626
627 fprintf ( OUT, "SOURCE=%s\r\n", source_file.c_str() );
628
629 if ( !strcmp ( &source_file[source_file.size()-5], ".spec" ) )
630 {
631 #if 0
632 string basename = string ( source_file.c_str(), source_file.size() - 5 );
633
634 string spec_file = source_file;
635 string def_file = basename + ".def";
636
637 // TODO FIXME - not sure what this is doing? wine hack maybe?
638 //if ( basename !~ /\..{1,3}$/; ) basename += ".dll";
639 string dbg_file = basename + ".dbg";
640 string dbg_c_file = basename + ".dbg.c";
641
642 string srcdir = "."; // FIXME: Is this really always correct?
643
644 fprintf ( OUT, "# Begin Custom Build\r\n" );
645 fprintf ( OUT, "InputPath=%s\r\n", spec_file.c_str() );
646 fprintf ( OUT, "\r\n" );
647 fprintf ( OUT, "BuildCmds= \\\r\n" );
648 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe --def %s > %s \\\r\n",
649 output_dir.c_str(),
650 spec_file.c_str(),
651 def_file.c_str() );
652
653 if ( module.name == "ntdll" )
654 {
655 int n = 0;
656 for ( i = 0; i < c_srcs.size(); i++ )
657 {
658 const string& c_src = c_srcs[i];
659 if(n++ > 0)
660 {
661 fprintf ( OUT, "\techo %s >> %s \\\r\n", c_src.c_str(), dbg_file.c_str() );
662 }
663 else
664 {
665 fprintf ( OUT, "\techo %s > %s \\\r\n", c_src.c_str(), dbg_file.c_str() );
666 }
667 }
668 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
669 output_dir.c_str() );
670 fprintf ( OUT, " -o %s --debug -C%s %s \\\r\n",
671 dbg_c_file.c_str(),
672 srcdir.c_str(),
673 dbg_file.c_str() );
674 }
675 else
676 {
677 string sc_srcs;
678 for ( i = 0; i < c_srcs.size(); i++ )
679 {
680 const string& c_src = c_srcs[i];
681 if ( !strcmp ( &c_src[c_src.size()-2], ".c" ) )
682 {
683 if ( sc_srcs.size() )
684 sc_srcs += " ";
685 sc_srcs += c_src;
686 }
687 }
688
689 fprintf ( OUT, "\t..\\..\\tools\\winebuild\\%s\\winebuild.exe",
690 output_dir.c_str() );
691 fprintf ( OUT, " -o %s --debug -C%s %s \\\r\n",
692 dbg_c_file.c_str(),
693 srcdir.c_str(),
694 sc_srcs.c_str() );
695 }
696
697 fprintf ( OUT, "\t\r\n" );
698 fprintf ( OUT, "\r\n" );
699 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", def_file.c_str() );
700 fprintf ( OUT, " $(BuildCmds)\r\n" );
701 fprintf ( OUT, "\r\n" );
702 fprintf ( OUT, "\"%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", dbg_c_file.c_str() );
703 fprintf ( OUT, " $(BuildCmds)\r\n" );
704 fprintf ( OUT, "# End Custom Build\r\n" );
705 #endif
706 }
707 /*else if ( source_file =~ /([^\\]*?\.h)$/ )
708 {
709 my $h_file = $1;
710
711 foreach my $cfg (@cfgs) {
712 if($#cfgs == 0) {
713 # Nothing
714 } elsif($n == 0) {
715 fprintf ( OUT, "!IF \"$(CFG)\" == \"$cfg\"\r\n" );
716 fprintf ( OUT, "\r\n" );
717 } else {
718 fprintf ( OUT, "\r\n" );
719 fprintf ( OUT, "!ELSEIF \"$(CFG)\" == \"$cfg\"\r\n" );
720 fprintf ( OUT, "\r\n" );
721 }
722
723 $output_dir = $cfg;
724 $output_dir =~ s/^$project - //;
725 $output_dir =~ s/ /_/g;
726 $output_dir =~ s/C\+\+/Cxx/g;
727 if($output_prefix_dir) {
728 $output_dir = "$output_prefix_dir\\$output_dir" );
729 }
730
731 fprintf ( OUT, "# Begin Custom Build\r\n" );
732 fprintf ( OUT, "OutDir=%s\r\n", output_dir.c_str() );
733 fprintf ( OUT, "InputPath=%s\r\n", source_file.c_str() );
734 fprintf ( OUT, "\r\n" );
735 fprintf ( OUT, "\"$(OutDir)\\wine\\%s\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\r\n", h_file.c_str() );
736 fprintf ( OUT, "\tcopy \"$(InputPath)\" \"$(OutDir)\\wine\"\r\n" );
737 fprintf ( OUT, "\r\n" );
738 fprintf ( OUT, "# End Custom Build\r\n" );
739 }
740
741 if ( cfgs.size() != 0)
742 {
743 fprintf ( OUT, "\r\n" );
744 fprintf ( OUT, "!ENDIF \r\n" );
745 fprintf ( OUT, "\r\n" );
746 }
747 }*/
748
749 fprintf ( OUT, "# End Source File\r\n" );
750 }
751 fprintf ( OUT, "# End Group\r\n" );
752 fprintf ( OUT, "# Begin Group \"Header Files\"\r\n" );
753 fprintf ( OUT, "\r\n" );
754 fprintf ( OUT, "# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n" );
755 for ( i = 0; i < header_files.size(); i++ )
756 {
757 const string& header_file = header_files[i];
758 fprintf ( OUT, "# Begin Source File\r\n" );
759 fprintf ( OUT, "\r\n" );
760 fprintf ( OUT, "SOURCE=.\\%s\r\n", header_file.c_str() );
761 fprintf ( OUT, "# End Source File\r\n" );
762 }
763 fprintf ( OUT, "# End Group\r\n" );
764
765
766
767 fprintf ( OUT, "# Begin Group \"Resource Files\"\r\n" );
768 fprintf ( OUT, "\r\n" );
769 fprintf ( OUT, "# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n" );
770 /* for ( i = 0; i < resource_files.size(); i++ )
771 {
772 const string& resource_file = resource_files[i];
773 fprintf ( OUT, "# Begin Source File\r\n" );
774 fprintf ( OUT, "\r\n" );
775 fprintf ( OUT, "SOURCE=.\\%s\r\n", resource_file.c_str() );
776 fprintf ( OUT, "# End Source File\r\n" );
777 }
778 */ fprintf ( OUT, "# End Group\r\n" );
779
780 fprintf ( OUT, "# End Target\r\n" );
781 fprintf ( OUT, "# End Project\r\n" );
782
783 fclose(OUT);
784 }
785
786 void
787 MSVCBackend::_generate_dsw_header ( FILE* OUT )
788 {
789 fprintf ( OUT, "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n" );
790 fprintf ( OUT, "# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n" );
791 fprintf ( OUT, "\r\n" );
792 }
793
794 void
795 MSVCBackend::_generate_dsw_project (
796 FILE* OUT,
797 const Module& module,
798 std::string dsp_file,
799 const std::vector<Dependency*>& dependencies )
800 {
801 dsp_file = DosSeparator ( std::string(".\\") + dsp_file );
802
803 // TODO FIXME - must they be sorted?
804 //@dependencies = sort(@dependencies);
805
806 fprintf ( OUT, "###############################################################################\r\n" );
807 fprintf ( OUT, "\r\n" );
808 fprintf ( OUT, "Project: \"%s\"=%s - Package Owner=<4>\r\n", module.name.c_str(), dsp_file.c_str() );
809 fprintf ( OUT, "\r\n" );
810 fprintf ( OUT, "Package=<5>\r\n" );
811 fprintf ( OUT, "{{{\r\n" );
812 fprintf ( OUT, "}}}\r\n" );
813 fprintf ( OUT, "\r\n" );
814 fprintf ( OUT, "Package=<4>\r\n" );
815 fprintf ( OUT, "{{{\r\n" );
816 for ( size_t i = 0; i < dependencies.size(); i++ )
817 {
818 Dependency& dependency = *dependencies[i];
819 fprintf ( OUT, " Begin Project Dependency\r\n" );
820 fprintf ( OUT, " Project_Dep_Name %s\r\n", dependency.module.name.c_str() );
821 fprintf ( OUT, " End Project Dependency\r\n" );
822 }
823 fprintf ( OUT, "}}}\r\n" );
824 fprintf ( OUT, "\r\n" );
825 }
826
827 void
828 MSVCBackend::_generate_dsw_footer ( FILE* OUT )
829 {
830 fprintf ( OUT, "###############################################################################\r\n" );
831 fprintf ( OUT, "\r\n" );
832 fprintf ( OUT, "Global:\r\n" );
833 fprintf ( OUT, "\r\n" );
834 fprintf ( OUT, "Package=<5>\r\n" );
835 fprintf ( OUT, "{{{\r\n" );
836 fprintf ( OUT, "}}}\r\n" );
837 fprintf ( OUT, "\r\n" );
838 fprintf ( OUT, "Package=<3>\r\n" );
839 fprintf ( OUT, "{{{\r\n" );
840 fprintf ( OUT, "}}}\r\n" );
841 fprintf ( OUT, "\r\n" );
842 fprintf ( OUT, "###############################################################################\r\n" );
843 fprintf ( OUT, "\r\n" );
844 }
845
846 void
847 MSVCBackend::_generate_wine_dsw ( FILE* OUT )
848 {
849 _generate_dsw_header(OUT);
850 // TODO FIXME - is it necessary to sort them?
851 for( std::map<std::string, Module*>::const_iterator p = ProjectNode.modules.begin(); p != ProjectNode.modules.end(); ++ p )
852 {
853 Module& module = *p->second;
854
855 std::string dsp_file = DspFileName ( module );
856
857 // TODO FIXME - more wine hacks?
858 /*if ( module.name == "gdi32" )
859 {
860 for ( size_t idir = 0; idir < gdi32_dirs.size(); idir++ )
861 {
862 string dir2 = gdi32_dirs[idir];
863 $dir2 =~ s%^.*?/([^/]+)$%$1%;
864
865 dependencies.push_back ( Replace ( "gdi32_" + dir2, "/", "_" ) );
866 }
867 }*/
868
869 _generate_dsw_project ( OUT, module, dsp_file, module.dependencies );
870 }
871 _generate_dsw_footer ( OUT );
872 }