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