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