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