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