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