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