create only the project files specified on cmdline
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #include "../../pch.h"
19 #include <assert.h>
20
21 #include "../../rbuild.h"
22 #include "mingw.h"
23 #include "modulehandler.h"
24
25 using std::string;
26 using std::vector;
27
28 #define CLEAN_FILE(f) clean_files.push_back ( f );
29
30 static string ros_temp = "$(TEMPORARY)";
31 MingwBackend*
32 MingwModuleHandler::backend = NULL;
33 FILE*
34 MingwModuleHandler::fMakefile = NULL;
35 bool
36 MingwModuleHandler::use_pch = false;
37
38 string
39 PrefixFilename (
40 const string& filename,
41 const string& prefix )
42 {
43 if ( !prefix.length() )
44 return filename;
45 string out;
46 const char* pfilename = filename.c_str();
47 const char* p1 = strrchr ( pfilename, '/' );
48 const char* p2 = strrchr ( pfilename, '\\' );
49 if ( p1 || p2 )
50 {
51 if ( p2 > p1 )
52 p1 = p2;
53 out += string(pfilename,p1-pfilename) + CSEP;
54 pfilename = p1 + 1;
55 }
56 out += prefix + pfilename;
57 return out;
58 }
59
60 string
61 GetTargetMacro ( const Module& module, bool with_dollar )
62 {
63 string s ( module.name );
64 strupr ( &s[0] );
65 s += "_TARGET";
66 if ( with_dollar )
67 return ssprintf ( "$(%s)", s.c_str() );
68 return s;
69 }
70
71 MingwModuleHandler::MingwModuleHandler (
72 const Module& module_ )
73
74 : module(module_)
75 {
76 }
77
78 MingwModuleHandler::~MingwModuleHandler()
79 {
80 }
81
82 /*static*/ void
83 MingwModuleHandler::SetBackend ( MingwBackend* backend_ )
84 {
85 backend = backend_;
86 }
87
88 /*static*/ void
89 MingwModuleHandler::SetMakefile ( FILE* f )
90 {
91 fMakefile = f;
92 }
93
94 /*static*/ void
95 MingwModuleHandler::SetUsePch ( bool b )
96 {
97 use_pch = b;
98 }
99
100 /* static*/ string
101 MingwModuleHandler::RemoveVariables ( string path)
102 {
103 size_t i = path.find ( '$' );
104 if ( i != string::npos )
105 {
106 size_t j = path.find ( ')', i );
107 if ( j != string::npos )
108 {
109 if ( j + 2 < path.length () && path[j + 1] == CSEP )
110 return path.substr ( j + 2);
111 else
112 return path.substr ( j + 1);
113 }
114 }
115 return path;
116 }
117
118 /*static*/ string
119 MingwModuleHandler::PassThruCacheDirectory (
120 const string &file,
121 Directory* directoryTree )
122 {
123 string directory ( GetDirectory ( RemoveVariables ( file ) ) );
124 string generatedFilesDirectory = backend->AddDirectoryTarget ( directory,
125 directoryTree );
126 if ( directory.find ( generatedFilesDirectory ) != string::npos )
127 /* This path already includes the generated files directory variable */
128 return file;
129 else
130 {
131 if ( file == "" )
132 return generatedFilesDirectory;
133 return generatedFilesDirectory + SSEP + file;
134 }
135 }
136
137 /*static*/ Directory*
138 MingwModuleHandler::GetTargetDirectoryTree (
139 const Module& module )
140 {
141 if ( module.type == StaticLibrary )
142 return backend->intermediateDirectory;
143 return backend->outputDirectory;
144 }
145
146 /*static*/ string
147 MingwModuleHandler::GetTargetFilename (
148 const Module& module,
149 string_list* pclean_files )
150 {
151 string target = PassThruCacheDirectory (
152 NormalizeFilename ( module.GetPath () ),
153 GetTargetDirectoryTree ( module ) );
154 if ( pclean_files )
155 {
156 string_list& clean_files = *pclean_files;
157 CLEAN_FILE ( target );
158 }
159 return target;
160 }
161
162 /*static*/ string
163 MingwModuleHandler::GetImportLibraryFilename (
164 const Module& module,
165 string_list* pclean_files )
166 {
167 string target = PassThruCacheDirectory (
168 NormalizeFilename ( module.GetDependencyPath () ),
169 backend->intermediateDirectory );
170 if ( pclean_files )
171 {
172 string_list& clean_files = *pclean_files;
173 CLEAN_FILE ( target );
174 }
175 return target;
176 }
177
178 /*static*/ MingwModuleHandler*
179 MingwModuleHandler::InstanciateHandler (
180 const Module& module,
181 MingwBackend* backend )
182 {
183 MingwModuleHandler* handler;
184 switch ( module.type )
185 {
186 case BuildTool:
187 handler = new MingwBuildToolModuleHandler ( module );
188 break;
189 case StaticLibrary:
190 handler = new MingwStaticLibraryModuleHandler ( module );
191 break;
192 case ObjectLibrary:
193 handler = new MingwObjectLibraryModuleHandler ( module );
194 break;
195 case Kernel:
196 handler = new MingwKernelModuleHandler ( module );
197 break;
198 case NativeCUI:
199 handler = new MingwNativeCUIModuleHandler ( module );
200 break;
201 case Win32CUI:
202 handler = new MingwWin32CUIModuleHandler ( module );
203 break;
204 case Win32GUI:
205 handler = new MingwWin32GUIModuleHandler ( module );
206 break;
207 case KernelModeDLL:
208 handler = new MingwKernelModeDLLModuleHandler ( module );
209 break;
210 case NativeDLL:
211 handler = new MingwNativeDLLModuleHandler ( module );
212 break;
213 case Win32DLL:
214 handler = new MingwWin32DLLModuleHandler ( module );
215 break;
216 case KernelModeDriver:
217 handler = new MingwKernelModeDriverModuleHandler ( module );
218 break;
219 case BootLoader:
220 handler = new MingwBootLoaderModuleHandler ( module );
221 break;
222 case BootSector:
223 handler = new MingwBootSectorModuleHandler ( module );
224 break;
225 case Iso:
226 handler = new MingwIsoModuleHandler ( module );
227 break;
228 case LiveIso:
229 handler = new MingwLiveIsoModuleHandler ( module );
230 break;
231 case Test:
232 handler = new MingwTestModuleHandler ( module );
233 break;
234 case RpcServer:
235 handler = new MingwRpcServerModuleHandler ( module );
236 break;
237 case RpcClient:
238 handler = new MingwRpcClientModuleHandler ( module );
239 break;
240 case Alias:
241 handler = new MingwAliasModuleHandler ( module );
242 break;
243 default:
244 throw UnknownModuleTypeException (
245 module.node.location,
246 module.type );
247 break;
248 }
249 return handler;
250 }
251
252 string
253 MingwModuleHandler::GetWorkingDirectory () const
254 {
255 return ".";
256 }
257
258 string
259 MingwModuleHandler::GetBasename ( const string& filename ) const
260 {
261 size_t index = filename.find_last_of ( '.' );
262 if ( index != string::npos )
263 return filename.substr ( 0, index );
264 return "";
265 }
266
267 string
268 MingwModuleHandler::GetActualSourceFilename (
269 const string& filename ) const
270 {
271 string extension = GetExtension ( filename );
272 if ( extension == ".spec" || extension == ".SPEC" )
273 {
274 string basename = GetBasename ( filename );
275 return PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ),
276 backend->intermediateDirectory );
277 }
278 else if ( extension == ".idl" || extension == ".IDL" )
279 {
280 string basename = GetBasename ( filename );
281 string newname;
282 if ( module.type == RpcServer )
283 newname = basename + "_s.c";
284 else
285 newname = basename + "_c.c";
286 return PassThruCacheDirectory ( NormalizeFilename ( newname ),
287 backend->intermediateDirectory );
288 }
289 else
290 return filename;
291 }
292
293 string
294 MingwModuleHandler::GetExtraDependencies (
295 const string& filename ) const
296 {
297 string extension = GetExtension ( filename );
298 if ( extension == ".idl" || extension == ".IDL" )
299 {
300 string basename = GetBasename ( filename );
301 return GetRpcServerHeaderFilename ( basename ) + " " + GetRpcClientHeaderFilename ( basename );
302 }
303 else
304 return "";
305 }
306
307 string
308 MingwModuleHandler::GetModuleArchiveFilename () const
309 {
310 if ( module.type == StaticLibrary )
311 return GetTargetFilename ( module, NULL );
312 return PassThruCacheDirectory ( ReplaceExtension (
313 NormalizeFilename ( module.GetPath () ),
314 ".temp.a" ),
315 backend->intermediateDirectory );
316 }
317
318 bool
319 MingwModuleHandler::IsGeneratedFile ( const File& file ) const
320 {
321 string extension = GetExtension ( file.name );
322 return ( extension == ".spec" || extension == ".SPEC" );
323 }
324
325 /*static*/ bool
326 MingwModuleHandler::ReferenceObjects (
327 const Module& module )
328 {
329 if ( module.type == ObjectLibrary )
330 return true;
331 if ( module.type == RpcServer )
332 return true;
333 if ( module.type == RpcClient )
334 return true;
335 return false;
336 }
337
338 string
339 MingwModuleHandler::GetImportLibraryDependency (
340 const Module& importedModule )
341 {
342 string dep;
343 if ( ReferenceObjects ( importedModule ) )
344 dep = GetTargetMacro ( importedModule );
345 else
346 dep = GetImportLibraryFilename ( importedModule, NULL );
347 return dep;
348 }
349
350 void
351 MingwModuleHandler::GetTargets ( const Module& dependencyModule,
352 string_list& targets )
353 {
354 if ( dependencyModule.invocations.size () > 0 )
355 {
356 for ( size_t i = 0; i < dependencyModule.invocations.size (); i++ )
357 {
358 Invoke& invoke = *dependencyModule.invocations[i];
359 invoke.GetTargets ( targets );
360 }
361 }
362 else
363 targets.push_back ( GetImportLibraryDependency ( dependencyModule ) );
364 }
365
366 void
367 MingwModuleHandler::GetModuleDependencies (
368 string_list& dependencies )
369 {
370 size_t iend = module.dependencies.size ();
371
372 if ( iend == 0 )
373 return;
374
375 for ( size_t i = 0; i < iend; i++ )
376 {
377 const Dependency& dependency = *module.dependencies[i];
378 const Module& dependencyModule = *dependency.dependencyModule;
379 GetTargets ( dependencyModule,
380 dependencies );
381 }
382 GetDefinitionDependencies ( dependencies );
383 }
384
385 void
386 MingwModuleHandler::GetSourceFilenames ( string_list& list,
387 bool includeGeneratedFiles ) const
388 {
389 size_t i;
390
391 const vector<File*>& files = module.non_if_data.files;
392 for ( i = 0; i < files.size (); i++ )
393 {
394 if ( includeGeneratedFiles || !files[i]->IsGeneratedFile () )
395 {
396 list.push_back (
397 GetActualSourceFilename ( files[i]->name ) );
398 }
399 }
400 // intentionally make a copy so that we can append more work in
401 // the middle of processing without having to go recursive
402 vector<If*> v = module.non_if_data.ifs;
403 for ( i = 0; i < v.size (); i++ )
404 {
405 size_t j;
406 If& rIf = *v[i];
407 // check for sub-ifs to add to list
408 const vector<If*>& ifs = rIf.data.ifs;
409 for ( j = 0; j < ifs.size (); j++ )
410 v.push_back ( ifs[j] );
411 const vector<File*>& files = rIf.data.files;
412 for ( j = 0; j < files.size (); j++ )
413 {
414 File& file = *files[j];
415 if ( includeGeneratedFiles || !file.IsGeneratedFile () )
416 {
417 list.push_back (
418 GetActualSourceFilename ( file.name ) );
419 }
420 }
421 }
422 }
423
424 void
425 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
426 string_list& list ) const
427 {
428 GetSourceFilenames ( list, false );
429 }
430
431 string
432 MingwModuleHandler::GetObjectFilename (
433 const string& sourceFilename,
434 string_list* pclean_files ) const
435 {
436 Directory* directoryTree;
437
438 string newExtension;
439 string extension = GetExtension ( sourceFilename );
440 if ( extension == ".rc" || extension == ".RC" )
441 newExtension = ".coff";
442 else if ( extension == ".spec" || extension == ".SPEC" )
443 newExtension = ".stubs.o";
444 else if ( extension == ".idl" || extension == ".IDL" )
445 {
446 if ( module.type == RpcServer )
447 newExtension = "_s.o";
448 else
449 newExtension = "_c.o";
450 }
451 else
452 newExtension = ".o";
453
454 if ( module.type == BootSector )
455 directoryTree = backend->outputDirectory;
456 else
457 directoryTree = backend->intermediateDirectory;
458
459 string obj_file = PassThruCacheDirectory (
460 NormalizeFilename ( ReplaceExtension (
461 RemoveVariables ( sourceFilename ),
462 newExtension ) ),
463 directoryTree );
464 if ( pclean_files )
465 {
466 string_list& clean_files = *pclean_files;
467 CLEAN_FILE ( obj_file );
468 }
469 return obj_file;
470 }
471
472 string
473 MingwModuleHandler::GetModuleCleanTarget ( const Module& module ) const
474 {
475 return module.name + "_clean";
476 }
477
478 void
479 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector<string>& moduleNames ) const
480 {
481 for ( size_t i = 0; i < module.non_if_data.libraries.size (); i++ )
482 {
483 Library& library = *module.non_if_data.libraries[i];
484 if ( library.importedModule->type == ObjectLibrary )
485 moduleNames.push_back ( GetModuleCleanTarget ( *library.importedModule ) );
486 }
487 }
488
489 void
490 MingwModuleHandler::GenerateCleanTarget () const
491 {
492 if ( module.type == Alias )
493 return;
494
495 fprintf ( fMakefile,
496 ".PHONY: %s_clean\n",
497 module.name.c_str() );
498 vector<string> referencedModuleNames;
499 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames );
500 fprintf ( fMakefile,
501 "%s: %s\n\t-@${rm}",
502 GetModuleCleanTarget ( module ).c_str(),
503 v2s ( referencedModuleNames, 10 ).c_str () );
504 for ( size_t i = 0; i < clean_files.size(); i++ )
505 {
506 if ( 9==((i+1)%10) )
507 fprintf ( fMakefile, " 2>$(NUL)\n\t-@${rm}" );
508 fprintf ( fMakefile, " %s", clean_files[i].c_str() );
509 }
510 fprintf ( fMakefile, " 2>$(NUL)\n" );
511 fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
512 }
513
514 void
515 MingwModuleHandler::GenerateInstallTarget () const
516 {
517 if ( module.installName.length () == 0 )
518 return;
519 fprintf ( fMakefile, ".PHONY: %s_install\n", module.name.c_str() );
520 string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
521 NormalizeFilename ( module.installBase + SSEP + module.installName ),
522 backend->installDirectory );
523 fprintf ( fMakefile,
524 "%s_install: %s\n",
525 module.name.c_str (),
526 normalizedTargetFilename.c_str() );
527 }
528
529 void
530 MingwModuleHandler::GenerateDependsTarget () const
531 {
532 fprintf ( fMakefile,
533 ".PHONY: %s_depends\n",
534 module.name.c_str() );
535 fprintf ( fMakefile,
536 "%s_depends: $(RBUILD_TARGET)\n",
537 module.name.c_str () );
538 fprintf ( fMakefile,
539 "\t$(ECHO_RBUILD)\n" );
540 fprintf ( fMakefile,
541 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
542 module.name.c_str () );
543 }
544
545 string
546 MingwModuleHandler::GetObjectFilenames ()
547 {
548 const vector<File*>& files = module.non_if_data.files;
549 if ( files.size () == 0 )
550 return "";
551
552 string objectFilenames ( "" );
553 for ( size_t i = 0; i < files.size (); i++ )
554 {
555 if ( objectFilenames.size () > 0 )
556 objectFilenames += " ";
557 objectFilenames +=
558 GetObjectFilename ( files[i]->name, NULL );
559 }
560 return objectFilenames;
561 }
562
563 /* static */ string
564 MingwModuleHandler::GenerateGccDefineParametersFromVector (
565 const vector<Define*>& defines )
566 {
567 string parameters;
568 for ( size_t i = 0; i < defines.size (); i++ )
569 {
570 Define& define = *defines[i];
571 if (parameters.length () > 0)
572 parameters += " ";
573 parameters += "-D";
574 parameters += define.name;
575 if (define.value.length () > 0)
576 {
577 parameters += "=";
578 parameters += define.value;
579 }
580 }
581 return parameters;
582 }
583
584 string
585 MingwModuleHandler::GenerateGccDefineParameters () const
586 {
587 string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );
588 string s = GenerateGccDefineParametersFromVector ( module.non_if_data.defines );
589 if ( s.length () > 0 )
590 {
591 parameters += " ";
592 parameters += s;
593 }
594 return parameters;
595 }
596
597 string
598 MingwModuleHandler::ConcatenatePaths (
599 const string& path1,
600 const string& path2 ) const
601 {
602 if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
603 return path2;
604 if ( path1[path1.length ()] == CSEP )
605 return path1 + path2;
606 else
607 return path1 + CSEP + path2;
608 }
609
610 /* static */ string
611 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes )
612 {
613 string parameters;
614 for ( size_t i = 0; i < includes.size (); i++ )
615 {
616 Include& include = *includes[i];
617 if ( parameters.length () > 0 )
618 parameters += " ";
619 parameters += "-I" + include.directory;
620 }
621 return parameters;
622 }
623
624 string
625 MingwModuleHandler::GenerateGccIncludeParameters () const
626 {
627 string parameters = GenerateGccIncludeParametersFromVector ( module.non_if_data.includes );
628 string s = GenerateGccIncludeParametersFromVector ( module.project.non_if_data.includes );
629 if ( s.length () > 0 )
630 {
631 parameters += " ";
632 parameters += s;
633 }
634 return parameters;
635 }
636
637 string
638 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const
639 {
640 string parameters;
641 for ( size_t i = 0; i < compilerFlags.size (); i++ )
642 {
643 CompilerFlag& compilerFlag = *compilerFlags[i];
644 if ( parameters.length () > 0 )
645 parameters += " ";
646 parameters += compilerFlag.flag;
647 }
648 return parameters;
649 }
650
651 string
652 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const
653 {
654 string parameters;
655 for ( size_t i = 0; i < linkerFlags.size (); i++ )
656 {
657 LinkerFlag& linkerFlag = *linkerFlags[i];
658 if ( parameters.length () > 0 )
659 parameters += " ";
660 parameters += linkerFlag.flag;
661 }
662 return parameters;
663 }
664
665 string
666 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
667 const vector<Library*>& libraries )
668 {
669 string dependencies ( "" );
670 int wrap_count = 0;
671 for ( size_t i = 0; i < libraries.size (); i++ )
672 {
673 if ( wrap_count++ == 5 )
674 dependencies += " \\\n\t\t", wrap_count = 0;
675 else if ( dependencies.size () > 0 )
676 dependencies += " ";
677 dependencies += GetImportLibraryDependency ( *libraries[i]->importedModule );
678 }
679 return dependencies;
680 }
681
682 string
683 MingwModuleHandler::GenerateLinkerParameters () const
684 {
685 return GenerateLinkerParametersFromVector ( module.linkerFlags );
686 }
687
688 void
689 MingwModuleHandler::GenerateMacro (
690 const char* assignmentOperation,
691 const string& macro,
692 const IfableData& data )
693 {
694 size_t i;
695 bool generateAssignment;
696
697 generateAssignment = (use_pch && module.pch != NULL ) || data.includes.size () > 0 || data.defines.size () > 0 || data.compilerFlags.size () > 0;
698 if ( generateAssignment )
699 {
700 fprintf ( fMakefile,
701 "%s %s",
702 macro.c_str(),
703 assignmentOperation );
704 }
705
706 if ( use_pch && module.pch != NULL )
707 {
708 fprintf ( fMakefile,
709 " -I%s",
710 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
711 }
712
713 string compilerParameters = GenerateCompilerParametersFromVector ( data.compilerFlags );
714 if ( compilerParameters.size () > 0 )
715 {
716 fprintf (
717 fMakefile,
718 " %s",
719 compilerParameters.c_str () );
720 }
721
722 for ( i = 0; i < data.includes.size(); i++ )
723 {
724 const Include& include = *data.includes[i];
725 string includeDirectory;
726 if ( include.baseModule != NULL &&
727 ( include.baseModule->type == RpcServer ||
728 include.baseModule->type == RpcClient ) )
729 includeDirectory = PassThruCacheDirectory ( NormalizeFilename ( include.directory ),
730 backend->intermediateDirectory );
731 else
732 includeDirectory = include.directory;
733 fprintf (
734 fMakefile,
735 " -I%s",
736 includeDirectory.c_str() );
737 }
738 for ( i = 0; i < data.defines.size(); i++ )
739 {
740 Define& d = *data.defines[i];
741 fprintf (
742 fMakefile,
743 " -D%s",
744 d.name.c_str() );
745 if ( d.value.size() )
746 fprintf (
747 fMakefile,
748 "=%s",
749 d.value.c_str() );
750 }
751 if ( generateAssignment )
752 {
753 fprintf ( fMakefile, "\n" );
754 }
755 }
756
757 void
758 MingwModuleHandler::GenerateMacros (
759 const char* assignmentOperation,
760 const IfableData& data,
761 const vector<LinkerFlag*>* linkerFlags )
762 {
763 size_t i;
764
765 GenerateMacro ( assignmentOperation,
766 cflagsMacro,
767 data );
768 GenerateMacro ( assignmentOperation,
769 windresflagsMacro,
770 data );
771
772 if ( linkerFlags != NULL )
773 {
774 string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
775 if ( linkerParameters.size () > 0 )
776 {
777 fprintf (
778 fMakefile,
779 "%s %s %s\n",
780 linkerflagsMacro.c_str (),
781 assignmentOperation,
782 linkerParameters.c_str() );
783 }
784 }
785
786 if ( data.libraries.size () > 0 )
787 {
788 string deps = GenerateImportLibraryDependenciesFromVector ( data.libraries );
789 if ( deps.size () > 0 )
790 {
791 fprintf (
792 fMakefile,
793 "%s %s %s\n",
794 libsMacro.c_str(),
795 assignmentOperation,
796 deps.c_str() );
797 }
798 }
799
800 const vector<If*>& ifs = data.ifs;
801 for ( i = 0; i < ifs.size(); i++ )
802 {
803 If& rIf = *ifs[i];
804 if ( rIf.data.defines.size()
805 || rIf.data.includes.size()
806 || rIf.data.libraries.size()
807 || rIf.data.files.size()
808 || rIf.data.compilerFlags.size()
809 || rIf.data.ifs.size() )
810 {
811 fprintf (
812 fMakefile,
813 "%s (\"$(%s)\",\"%s\")\n",
814 rIf.negated ? "ifneq" : "ifeq",
815 rIf.property.c_str(),
816 rIf.value.c_str() );
817 GenerateMacros (
818 "+=",
819 rIf.data,
820 NULL );
821 fprintf (
822 fMakefile,
823 "endif\n\n" );
824 }
825 }
826 }
827
828 void
829 MingwModuleHandler::CleanupFileVector ( vector<File*>& sourceFiles )
830 {
831 for (size_t i = 0; i < sourceFiles.size (); i++)
832 delete sourceFiles[i];
833 }
834
835 void
836 MingwModuleHandler::GetModuleSpecificSourceFiles ( vector<File*>& sourceFiles )
837 {
838 }
839
840 void
841 MingwModuleHandler::GenerateObjectMacros (
842 const char* assignmentOperation,
843 const IfableData& data,
844 const vector<LinkerFlag*>* linkerFlags )
845 {
846 size_t i;
847
848 const vector<File*>& files = data.files;
849 if ( files.size () > 0 )
850 {
851 for ( i = 0; i < files.size (); i++ )
852 {
853 File& file = *files[i];
854 if ( file.first )
855 {
856 fprintf ( fMakefile,
857 "%s := %s $(%s)\n",
858 objectsMacro.c_str(),
859 GetObjectFilename (
860 file.name, NULL ).c_str (),
861 objectsMacro.c_str() );
862 }
863 }
864 fprintf (
865 fMakefile,
866 "%s %s",
867 objectsMacro.c_str (),
868 assignmentOperation );
869 for ( i = 0; i < files.size(); i++ )
870 {
871 File& file = *files[i];
872 if ( !file.first )
873 {
874 fprintf (
875 fMakefile,
876 "%s%s",
877 ( i%10 == 9 ? " \\\n\t" : " " ),
878 GetObjectFilename (
879 file.name, NULL ).c_str () );
880 }
881 }
882 fprintf ( fMakefile, "\n" );
883 }
884
885 const vector<If*>& ifs = data.ifs;
886 for ( i = 0; i < ifs.size(); i++ )
887 {
888 If& rIf = *ifs[i];
889 if ( rIf.data.defines.size()
890 || rIf.data.includes.size()
891 || rIf.data.libraries.size()
892 || rIf.data.files.size()
893 || rIf.data.compilerFlags.size()
894 || rIf.data.ifs.size() )
895 {
896 fprintf (
897 fMakefile,
898 "%s (\"$(%s)\",\"%s\")\n",
899 rIf.negated ? "ifneq" : "ifeq",
900 rIf.property.c_str(),
901 rIf.value.c_str() );
902 GenerateObjectMacros (
903 "+=",
904 rIf.data,
905 NULL );
906 fprintf (
907 fMakefile,
908 "endif\n\n" );
909 }
910 }
911
912 vector<File*> sourceFiles;
913 GetModuleSpecificSourceFiles ( sourceFiles );
914 for ( i = 0; i < sourceFiles.size (); i++ )
915 {
916 fprintf (
917 fMakefile,
918 "%s += %s\n",
919 objectsMacro.c_str(),
920 GetObjectFilename (
921 sourceFiles[i]->name, NULL ).c_str () );
922 }
923 CleanupFileVector ( sourceFiles );
924 }
925
926 string
927 MingwModuleHandler::GetPrecompiledHeaderFilename () const
928 {
929 const string& basePchFilename = module.pch->file.name + ".gch";
930 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename ),
931 backend->intermediateDirectory );
932 }
933
934 void
935 MingwModuleHandler::GenerateGccCommand (
936 const string& sourceFilename,
937 const string& extraDependencies,
938 const string& cc,
939 const string& cflagsMacro )
940 {
941 string dependencies = sourceFilename;
942 if ( extraDependencies != "" )
943 dependencies += " " + extraDependencies;
944 if ( module.pch && use_pch )
945 dependencies += " " + GetPrecompiledHeaderFilename ();
946
947 /* WIDL generated headers may be used */
948 vector<string> rpcDependencies;
949 GetRpcHeaderDependencies ( rpcDependencies );
950 dependencies += " " + v2s ( rpcDependencies, 5 );
951 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
952
953 string objectFilename = GetObjectFilename (
954 sourceFilename, &clean_files );
955 fprintf ( fMakefile,
956 "%s: %s | %s\n",
957 objectFilename.c_str (),
958 dependencies.c_str (),
959 GetDirectory ( objectFilename ).c_str () );
960 fprintf ( fMakefile, "\t$(ECHO_CC)\n" );
961 fprintf ( fMakefile,
962 "\t%s -c $< -o $@ %s\n",
963 cc.c_str (),
964 cflagsMacro.c_str () );
965 }
966
967 void
968 MingwModuleHandler::GenerateGccAssemblerCommand (
969 const string& sourceFilename,
970 const string& cc,
971 const string& cflagsMacro )
972 {
973 string dependencies = sourceFilename;
974 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
975 string objectFilename = GetObjectFilename (
976 sourceFilename, &clean_files );
977 fprintf ( fMakefile,
978 "%s: %s | %s\n",
979 objectFilename.c_str (),
980 dependencies.c_str (),
981 GetDirectory ( objectFilename ).c_str () );
982 fprintf ( fMakefile, "\t$(ECHO_GAS)\n" );
983 fprintf ( fMakefile,
984 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
985 cc.c_str (),
986 cflagsMacro.c_str () );
987 }
988
989 void
990 MingwModuleHandler::GenerateNasmCommand (
991 const string& sourceFilename,
992 const string& nasmflagsMacro )
993 {
994 string dependencies = sourceFilename;
995 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
996 string objectFilename = GetObjectFilename (
997 sourceFilename, &clean_files );
998 fprintf ( fMakefile,
999 "%s: %s | %s\n",
1000 objectFilename.c_str (),
1001 dependencies.c_str (),
1002 GetDirectory ( objectFilename ).c_str () );
1003 fprintf ( fMakefile, "\t$(ECHO_NASM)\n" );
1004 fprintf ( fMakefile,
1005 "\t%s -f win32 $< -o $@ %s\n",
1006 "$(Q)${nasm}",
1007 nasmflagsMacro.c_str () );
1008 }
1009
1010 void
1011 MingwModuleHandler::GenerateWindresCommand (
1012 const string& sourceFilename,
1013 const string& windresflagsMacro )
1014 {
1015 string dependencies = sourceFilename;
1016 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
1017 string objectFilename =
1018 GetObjectFilename ( sourceFilename, &clean_files );
1019 string sourceFilenamePart = ReplaceExtension ( GetFilename ( sourceFilename ), "" );
1020 string rciFilename = ros_temp + module.name + "." + sourceFilenamePart + ".rci.tmp";
1021 string resFilename = ros_temp + module.name + "." + sourceFilenamePart + ".res.tmp";
1022 if ( module.useWRC )
1023 {
1024 fprintf ( fMakefile,
1025 "%s: %s $(WRC_TARGET) | %s\n",
1026 objectFilename.c_str (),
1027 dependencies.c_str (),
1028 GetDirectory ( objectFilename ).c_str () );
1029 fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
1030 fprintf ( fMakefile,
1031 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1032 windresflagsMacro.c_str (),
1033 sourceFilename.c_str (),
1034 rciFilename.c_str () );
1035 fprintf ( fMakefile,
1036 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1037 windresflagsMacro.c_str (),
1038 rciFilename.c_str (),
1039 resFilename.c_str () );
1040 fprintf ( fMakefile,
1041 "\t-@${rm} %s 2>$(NUL)\n",
1042 rciFilename.c_str () );
1043 fprintf ( fMakefile,
1044 "\t${windres} %s -o $@\n",
1045 resFilename.c_str () );
1046 fprintf ( fMakefile,
1047 "\t-@${rm} %s 2>$(NUL)\n",
1048 resFilename.c_str () );
1049 }
1050 else
1051 {
1052 fprintf ( fMakefile,
1053 "%s: %s $(WRC_TARGET) | %s\n",
1054 objectFilename.c_str (),
1055 dependencies.c_str (),
1056 GetDirectory ( objectFilename ).c_str () );
1057 fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
1058 fprintf ( fMakefile,
1059 "\t${windres} $(%s) %s -o $@\n",
1060 windresflagsMacro.c_str (),
1061 sourceFilename.c_str () );
1062 }
1063 }
1064
1065 void
1066 MingwModuleHandler::GenerateWinebuildCommands (
1067 const string& sourceFilename )
1068 {
1069 string dependencies = sourceFilename;
1070 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
1071
1072 string basename = GetBasename ( sourceFilename );
1073 string def_file = PassThruCacheDirectory (
1074 basename + ".spec.def",
1075 backend->intermediateDirectory );
1076 CLEAN_FILE(def_file);
1077
1078 string stub_file = PassThruCacheDirectory (
1079 basename + ".stubs.c",
1080 backend->intermediateDirectory );
1081 CLEAN_FILE(stub_file)
1082
1083 fprintf ( fMakefile,
1084 "%s: %s $(WINEBUILD_TARGET)\n",
1085 def_file.c_str (),
1086 dependencies.c_str () );
1087 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
1088 fprintf ( fMakefile,
1089 "\t%s -o %s --def -E %s\n",
1090 "$(Q)$(WINEBUILD_TARGET)",
1091 def_file.c_str (),
1092 sourceFilename.c_str () );
1093 fprintf ( fMakefile,
1094 "%s: %s $(WINEBUILD_TARGET)\n",
1095 stub_file.c_str (),
1096 sourceFilename.c_str () );
1097 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
1098 fprintf ( fMakefile,
1099 "\t%s -o %s --pedll %s\n",
1100 "$(Q)$(WINEBUILD_TARGET)",
1101 stub_file.c_str (),
1102 sourceFilename.c_str () );
1103 }
1104
1105 string
1106 MingwModuleHandler::GetWidlFlags ( const File& file )
1107 {
1108 return file.switches;
1109 }
1110
1111 string
1112 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename ) const
1113 {
1114 return PassThruCacheDirectory ( basename + "_s.h",
1115 backend->intermediateDirectory );
1116 }
1117
1118 void
1119 MingwModuleHandler::GenerateWidlCommandsServer (
1120 const File& file,
1121 const string& widlflagsMacro )
1122 {
1123 string dependencies = file.name;
1124 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
1125
1126 string basename = GetBasename ( file.name );
1127
1128 string generatedHeaderFilename = GetRpcServerHeaderFilename ( basename );
1129 CLEAN_FILE(generatedHeaderFilename);
1130
1131 string generatedServerFilename = PassThruCacheDirectory (
1132 basename + "_s.c",
1133 backend->intermediateDirectory );
1134 CLEAN_FILE(generatedServerFilename);
1135
1136 fprintf ( fMakefile,
1137 "%s %s: %s $(WIDL_TARGET) | %s\n",
1138 generatedServerFilename.c_str (),
1139 generatedHeaderFilename.c_str (),
1140 dependencies.c_str (),
1141 GetDirectory ( generatedServerFilename ).c_str () );
1142 fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
1143 fprintf ( fMakefile,
1144 "\t%s %s %s -h -H %s -s -S %s %s\n",
1145 "$(Q)$(WIDL_TARGET)",
1146 GetWidlFlags ( file ).c_str (),
1147 widlflagsMacro.c_str (),
1148 generatedHeaderFilename.c_str (),
1149 generatedServerFilename.c_str (),
1150 file.name.c_str () );
1151 }
1152
1153 string
1154 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename ) const
1155 {
1156 return PassThruCacheDirectory ( basename + "_c.h",
1157 backend->intermediateDirectory );
1158 }
1159
1160 void
1161 MingwModuleHandler::GenerateWidlCommandsClient (
1162 const File& file,
1163 const string& widlflagsMacro )
1164 {
1165 string dependencies = file.name;
1166 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
1167
1168 string basename = GetBasename ( file.name );
1169
1170 string generatedHeaderFilename = GetRpcClientHeaderFilename ( basename );
1171 CLEAN_FILE(generatedHeaderFilename);
1172
1173 string generatedClientFilename = PassThruCacheDirectory (
1174 basename + "_c.c",
1175 backend->intermediateDirectory );
1176 CLEAN_FILE(generatedClientFilename);
1177
1178 fprintf ( fMakefile,
1179 "%s %s: %s $(WIDL_TARGET) | %s\n",
1180 generatedClientFilename.c_str (),
1181 generatedHeaderFilename.c_str (),
1182 dependencies.c_str (),
1183 GetDirectory ( generatedClientFilename ).c_str () );
1184 fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
1185 fprintf ( fMakefile,
1186 "\t%s %s %s -h -H %s -c -C %s %s\n",
1187 "$(Q)$(WIDL_TARGET)",
1188 GetWidlFlags ( file ).c_str (),
1189 widlflagsMacro.c_str (),
1190 generatedHeaderFilename.c_str (),
1191 generatedClientFilename.c_str (),
1192 file.name.c_str () );
1193 }
1194
1195 void
1196 MingwModuleHandler::GenerateWidlCommands (
1197 const File& file,
1198 const string& widlflagsMacro )
1199 {
1200 if ( module.type == RpcServer )
1201 GenerateWidlCommandsServer ( file,
1202 widlflagsMacro );
1203 else
1204 GenerateWidlCommandsClient ( file,
1205 widlflagsMacro );
1206 }
1207
1208 void
1209 MingwModuleHandler::GenerateCommands (
1210 const File& file,
1211 const string& cc,
1212 const string& cppc,
1213 const string& cflagsMacro,
1214 const string& nasmflagsMacro,
1215 const string& windresflagsMacro,
1216 const string& widlflagsMacro )
1217 {
1218 string extension = GetExtension ( file.name );
1219 if ( extension == ".c" || extension == ".C" )
1220 {
1221 GenerateGccCommand ( file.name,
1222 "",
1223 cc,
1224 cflagsMacro );
1225 return;
1226 }
1227 else if ( extension == ".cc" || extension == ".CC" ||
1228 extension == ".cpp" || extension == ".CPP" ||
1229 extension == ".cxx" || extension == ".CXX" )
1230 {
1231 GenerateGccCommand ( file.name,
1232 "",
1233 cppc,
1234 cflagsMacro );
1235 return;
1236 }
1237 else if ( extension == ".s" || extension == ".S" )
1238 {
1239 GenerateGccAssemblerCommand ( file.name,
1240 cc,
1241 cflagsMacro );
1242 return;
1243 }
1244 else if ( extension == ".asm" || extension == ".ASM" )
1245 {
1246 GenerateNasmCommand ( file.name,
1247 nasmflagsMacro );
1248 return;
1249 }
1250 else if ( extension == ".rc" || extension == ".RC" )
1251 {
1252 GenerateWindresCommand ( file.name,
1253 windresflagsMacro );
1254 return;
1255 }
1256 else if ( extension == ".spec" || extension == ".SPEC" )
1257 {
1258 GenerateWinebuildCommands ( file.name );
1259 GenerateGccCommand ( GetActualSourceFilename ( file.name ),
1260 "",
1261 cc,
1262 cflagsMacro );
1263 return;
1264 }
1265 else if ( extension == ".idl" || extension == ".IDL" )
1266 {
1267 GenerateWidlCommands ( file,
1268 widlflagsMacro );
1269 GenerateGccCommand ( GetActualSourceFilename ( file.name ),
1270 GetExtraDependencies ( file.name ),
1271 cc,
1272 cflagsMacro );
1273 return;
1274 }
1275
1276 throw InvalidOperationException ( __FILE__,
1277 __LINE__,
1278 "Unsupported filename extension '%s' in file '%s'",
1279 extension.c_str (),
1280 file.name.c_str () );
1281 }
1282
1283 void
1284 MingwModuleHandler::GenerateBuildMapCode ()
1285 {
1286 fprintf ( fMakefile,
1287 "ifeq ($(ROS_BUILDMAP),full)\n" );
1288
1289 string mapFilename = PassThruCacheDirectory (
1290 GetBasename ( module.GetPath () ) + ".map",
1291 backend->outputDirectory );
1292 CLEAN_FILE ( mapFilename );
1293
1294 fprintf ( fMakefile,
1295 "\t$(ECHO_OBJDUMP)\n" );
1296 fprintf ( fMakefile,
1297 "\t$(Q)${objdump} -d -S $@ > %s\n",
1298 mapFilename.c_str () );
1299
1300 fprintf ( fMakefile,
1301 "else\n" );
1302 fprintf ( fMakefile,
1303 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1304
1305 fprintf ( fMakefile,
1306 "\t$(ECHO_NM)\n" );
1307 fprintf ( fMakefile,
1308 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
1309 mapFilename.c_str () );
1310
1311 fprintf ( fMakefile,
1312 "endif\n" );
1313
1314 fprintf ( fMakefile,
1315 "endif\n" );
1316 }
1317
1318 void
1319 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1320 {
1321 fprintf ( fMakefile,
1322 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1323
1324 string filename = module.GetPath ();
1325 string outputFilename = PassThruCacheDirectory (
1326 filename,
1327 backend->outputDirectory );
1328 string nostripFilename = PassThruCacheDirectory (
1329 GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ),
1330 backend->outputDirectory );
1331 CLEAN_FILE ( nostripFilename );
1332
1333 fprintf ( fMakefile,
1334 "\t$(ECHO_CP)\n" );
1335 fprintf ( fMakefile,
1336 "\t${cp} %s %s 1>$(NUL)\n",
1337 outputFilename.c_str (),
1338 nostripFilename.c_str () );
1339
1340 fprintf ( fMakefile,
1341 "endif\n" );
1342 }
1343
1344 void
1345 MergeStringVector ( const vector<string>& input,
1346 vector<string>& output )
1347 {
1348 int wrap_at = 25;
1349 string s;
1350 int wrap_count = -1;
1351 for ( size_t i = 0; i < input.size (); i++ )
1352 {
1353 if ( input[i].size () == 0 )
1354 continue;
1355 if ( wrap_count++ == wrap_at )
1356 {
1357 output.push_back ( s );
1358 s = "";
1359 wrap_count = 0;
1360 }
1361 else if ( s.size () > 0)
1362 s += " ";
1363 s += input[i];
1364 }
1365 if ( s.length () > 0 )
1366 output.push_back ( s );
1367 }
1368
1369 void
1370 MingwModuleHandler::GetObjectsVector ( const IfableData& data,
1371 vector<string>& objectFiles ) const
1372 {
1373 for ( size_t i = 0; i < data.files.size (); i++ )
1374 {
1375 File& file = *data.files[i];
1376 objectFiles.push_back ( GetObjectFilename ( file.name, NULL ) );
1377 }
1378 }
1379
1380 void
1381 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1382 {
1383 if ( backend->configuration.CleanAsYouGo )
1384 {
1385 vector<string> objectFiles;
1386 GetObjectsVector ( module.non_if_data,
1387 objectFiles );
1388 vector<string> lines;
1389 MergeStringVector ( objectFiles,
1390 lines );
1391 for ( size_t i = 0; i < lines.size (); i++ )
1392 {
1393 fprintf ( fMakefile,
1394 "\t-@${rm} %s 2>$(NUL)\n",
1395 lines[i].c_str () );
1396 }
1397 }
1398 }
1399
1400 void
1401 MingwModuleHandler::GenerateRunRsymCode () const
1402 {
1403 fprintf ( fMakefile,
1404 "\t$(ECHO_RSYM)\n" );
1405 fprintf ( fMakefile,
1406 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1407 }
1408
1409 void
1410 MingwModuleHandler::GenerateLinkerCommand (
1411 const string& dependencies,
1412 const string& linker,
1413 const string& linkerParameters,
1414 const string& objectsMacro,
1415 const string& libsMacro,
1416 const string& pefixupParameters )
1417 {
1418 string target ( GetTargetMacro ( module ) );
1419 string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );
1420 string def_file = GetDefinitionFilename ();
1421
1422 fprintf ( fMakefile,
1423 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1424 target.c_str (),
1425 def_file.c_str (),
1426 dependencies.c_str (),
1427 target_folder.c_str () );
1428 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1429 string targetName ( module.GetTargetName () );
1430
1431 if ( module.IsDLL () )
1432 {
1433 string temp_exp = ros_temp + module.name + ".temp.exp";
1434 CLEAN_FILE ( temp_exp );
1435
1436 string killAt = module.mangledSymbols ? "" : "--kill-at";
1437 fprintf ( fMakefile,
1438 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1439 targetName.c_str (),
1440 def_file.c_str (),
1441 temp_exp.c_str (),
1442 killAt.c_str () );
1443
1444 fprintf ( fMakefile,
1445 "\t%s %s %s -o %s %s %s %s\n",
1446 linker.c_str (),
1447 linkerParameters.c_str (),
1448 temp_exp.c_str (),
1449 target.c_str (),
1450 objectsMacro.c_str (),
1451 libsMacro.c_str (),
1452 GetLinkerMacro ().c_str () );
1453
1454 fprintf ( fMakefile,
1455 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1456 target.c_str (),
1457 pefixupParameters.c_str() );
1458
1459 fprintf ( fMakefile,
1460 "\t-@${rm} %s 2>$(NUL)\n",
1461 temp_exp.c_str () );
1462 }
1463 else
1464 {
1465 fprintf ( fMakefile,
1466 "\t%s %s -o %s %s %s %s\n",
1467 linker.c_str (),
1468 linkerParameters.c_str (),
1469 target.c_str (),
1470 objectsMacro.c_str (),
1471 libsMacro.c_str (),
1472 GetLinkerMacro ().c_str () );
1473
1474 if ( pefixupParameters.length() != 0 )
1475 {
1476 fprintf ( fMakefile,
1477 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1478 target.c_str (),
1479 pefixupParameters.c_str() );
1480 }
1481 }
1482
1483 GenerateBuildMapCode ();
1484 GenerateBuildNonSymbolStrippedCode ();
1485 GenerateRunRsymCode ();
1486 GenerateCleanObjectsAsYouGoCode ();
1487 }
1488
1489 void
1490 MingwModuleHandler::GeneratePhonyTarget() const
1491 {
1492 string targetMacro ( GetTargetMacro ( module ) );
1493 fprintf ( fMakefile,
1494 ".PHONY: %s\n\n",
1495 targetMacro.c_str ());
1496 fprintf ( fMakefile, "%s: | %s\n",
1497 targetMacro.c_str (),
1498 GetDirectory ( GetTargetFilename ( module, NULL ) ).c_str () );
1499 }
1500
1501 void
1502 MingwModuleHandler::GenerateObjectFileTargets (
1503 const IfableData& data,
1504 const string& cc,
1505 const string& cppc,
1506 const string& cflagsMacro,
1507 const string& nasmflagsMacro,
1508 const string& windresflagsMacro,
1509 const string& widlflagsMacro )
1510 {
1511 size_t i;
1512
1513 const vector<File*>& files = data.files;
1514 for ( i = 0; i < files.size (); i++ )
1515 {
1516 GenerateCommands ( *files[i],
1517 cc,
1518 cppc,
1519 cflagsMacro,
1520 nasmflagsMacro,
1521 windresflagsMacro,
1522 widlflagsMacro );
1523 fprintf ( fMakefile,
1524 "\n" );
1525 }
1526
1527 const vector<If*>& ifs = data.ifs;
1528 for ( i = 0; i < ifs.size(); i++ )
1529 {
1530 GenerateObjectFileTargets ( ifs[i]->data,
1531 cc,
1532 cppc,
1533 cflagsMacro,
1534 nasmflagsMacro,
1535 windresflagsMacro,
1536 widlflagsMacro );
1537 }
1538
1539 vector<File*> sourceFiles;
1540 GetModuleSpecificSourceFiles ( sourceFiles );
1541 for ( i = 0; i < sourceFiles.size (); i++ )
1542 {
1543 GenerateCommands ( *sourceFiles[i],
1544 cc,
1545 cppc,
1546 cflagsMacro,
1547 nasmflagsMacro,
1548 windresflagsMacro,
1549 widlflagsMacro );
1550 }
1551 CleanupFileVector ( sourceFiles );
1552 }
1553
1554 void
1555 MingwModuleHandler::GenerateObjectFileTargets (
1556 const string& cc,
1557 const string& cppc,
1558 const string& cflagsMacro,
1559 const string& nasmflagsMacro,
1560 const string& windresflagsMacro,
1561 const string& widlflagsMacro )
1562 {
1563 if ( module.pch && use_pch )
1564 {
1565 const string& baseHeaderFilename = module.pch->file.name;
1566 const string& pchFilename = GetPrecompiledHeaderFilename ();
1567 CLEAN_FILE(pchFilename);
1568 fprintf ( fMakefile,
1569 "%s: %s\n",
1570 pchFilename.c_str(),
1571 baseHeaderFilename.c_str() );
1572 fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
1573 fprintf ( fMakefile,
1574 "\t%s -o %s %s -g %s\n\n",
1575 module.cplusplus ? cppc.c_str() : cc.c_str(),
1576 pchFilename.c_str(),
1577 cflagsMacro.c_str(),
1578 baseHeaderFilename.c_str() );
1579 }
1580
1581 GenerateObjectFileTargets ( module.non_if_data,
1582 cc,
1583 cppc,
1584 cflagsMacro,
1585 nasmflagsMacro,
1586 windresflagsMacro,
1587 widlflagsMacro );
1588 fprintf ( fMakefile, "\n" );
1589 }
1590
1591 string
1592 MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
1593 const string& objs_macro ) const
1594 {
1595 string archiveFilename ( GetModuleArchiveFilename () );
1596
1597 fprintf ( fMakefile,
1598 "%s: %s | %s\n",
1599 archiveFilename.c_str (),
1600 objs_macro.c_str (),
1601 GetDirectory(archiveFilename).c_str() );
1602
1603 fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
1604
1605 fprintf ( fMakefile,
1606 "\t%s -rc $@ %s\n",
1607 ar.c_str (),
1608 objs_macro.c_str ());
1609
1610 GenerateCleanObjectsAsYouGoCode ();
1611
1612 fprintf ( fMakefile, "\n" );
1613
1614 return archiveFilename;
1615 }
1616
1617 string
1618 MingwModuleHandler::GetCFlagsMacro () const
1619 {
1620 return ssprintf ( "$(%s_CFLAGS)",
1621 module.name.c_str () );
1622 }
1623
1624 /*static*/ string
1625 MingwModuleHandler::GetObjectsMacro ( const Module& module )
1626 {
1627 return ssprintf ( "$(%s_OBJS)",
1628 module.name.c_str () );
1629 }
1630
1631 string
1632 MingwModuleHandler::GetLinkingDependenciesMacro () const
1633 {
1634 return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
1635 }
1636
1637 string
1638 MingwModuleHandler::GetLibsMacro () const
1639 {
1640 return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
1641 }
1642
1643 string
1644 MingwModuleHandler::GetLinkerMacro () const
1645 {
1646 return ssprintf ( "$(%s_LFLAGS)",
1647 module.name.c_str () );
1648 }
1649
1650 string
1651 MingwModuleHandler::GetModuleTargets ( const Module& module )
1652 {
1653 if ( ReferenceObjects ( module ) )
1654 return GetObjectsMacro ( module );
1655 else
1656 return GetTargetFilename ( module, NULL );
1657 }
1658
1659 void
1660 MingwModuleHandler::GenerateObjectMacro ()
1661 {
1662 objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
1663
1664 GenerateObjectMacros (
1665 "=",
1666 module.non_if_data,
1667 &module.linkerFlags );
1668
1669 // future references to the macro will be to get its values
1670 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
1671 }
1672
1673 void
1674 MingwModuleHandler::GenerateTargetMacro ()
1675 {
1676 fprintf ( fMakefile,
1677 "%s := %s\n",
1678 GetTargetMacro ( module, false ).c_str (),
1679 GetModuleTargets ( module ).c_str () );
1680 }
1681
1682 void
1683 MingwModuleHandler::GetRpcHeaderDependencies (
1684 vector<string>& dependencies ) const
1685 {
1686 for ( size_t i = 0; i < module.non_if_data.libraries.size (); i++ )
1687 {
1688 Library& library = *module.non_if_data.libraries[i];
1689 if ( library.importedModule->type == RpcServer ||
1690 library.importedModule->type == RpcClient )
1691 {
1692 for ( size_t j = 0; j < library.importedModule->non_if_data.files.size (); j++ )
1693 {
1694 File& file = *library.importedModule->non_if_data.files[j];
1695 string extension = GetExtension ( file.name );
1696 if ( extension == ".idl" || extension == ".IDL" )
1697 {
1698 string basename = GetBasename ( file.name );
1699 if ( library.importedModule->type == RpcServer )
1700 dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
1701 if ( library.importedModule->type == RpcClient )
1702 dependencies.push_back ( GetRpcClientHeaderFilename ( basename ) );
1703 }
1704 }
1705 }
1706 }
1707 }
1708
1709 void
1710 MingwModuleHandler::GenerateOtherMacros ()
1711 {
1712 cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
1713 nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
1714 windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
1715 widlflagsMacro = ssprintf ("%s_WIDLFLAGS", module.name.c_str ());
1716 linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
1717 libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
1718 linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
1719
1720 GenerateMacros (
1721 "=",
1722 module.non_if_data,
1723 &module.linkerFlags );
1724
1725 vector<string> s;
1726 if ( module.importLibrary )
1727 {
1728 const vector<File*>& files = module.non_if_data.files;
1729 for ( size_t i = 0; i < files.size (); i++ )
1730 {
1731 File& file = *files[i];
1732 string extension = GetExtension ( file.name );
1733 if ( extension == ".spec" || extension == ".SPEC" )
1734 GetSpecObjectDependencies ( s, file.name );
1735 }
1736 }
1737 if ( s.size () > 0 )
1738 {
1739 fprintf (
1740 fMakefile,
1741 "%s +=",
1742 linkDepsMacro.c_str() );
1743 for ( size_t i = 0; i < s.size(); i++ )
1744 fprintf ( fMakefile,
1745 " %s",
1746 s[i].c_str () );
1747 fprintf ( fMakefile, "\n" );
1748 }
1749
1750 string globalCflags = "-g";
1751 if ( backend->usePipe )
1752 globalCflags += " -pipe";
1753 if ( !module.allowWarnings )
1754 globalCflags += " -Werror";
1755
1756 fprintf (
1757 fMakefile,
1758 "%s += $(PROJECT_CFLAGS) %s\n",
1759 cflagsMacro.c_str (),
1760 globalCflags.c_str () );
1761
1762 fprintf (
1763 fMakefile,
1764 "%s += $(PROJECT_RCFLAGS)\n",
1765 windresflagsMacro.c_str () );
1766
1767 fprintf (
1768 fMakefile,
1769 "%s += $(PROJECT_WIDLFLAGS)\n",
1770 widlflagsMacro.c_str () );
1771
1772 fprintf (
1773 fMakefile,
1774 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1775 module.name.c_str () );
1776
1777 fprintf (
1778 fMakefile,
1779 "%s += $(%s)\n",
1780 linkDepsMacro.c_str (),
1781 libsMacro.c_str () );
1782
1783 string cflags = TypeSpecificCFlags();
1784 if ( cflags.size() > 0 )
1785 {
1786 fprintf ( fMakefile,
1787 "%s += %s\n\n",
1788 cflagsMacro.c_str (),
1789 cflags.c_str () );
1790 }
1791
1792 string nasmflags = TypeSpecificNasmFlags();
1793 if ( nasmflags.size () > 0 )
1794 {
1795 fprintf ( fMakefile,
1796 "%s += %s\n\n",
1797 nasmflagsMacro.c_str (),
1798 nasmflags.c_str () );
1799 }
1800
1801 string linkerflags = TypeSpecificLinkerFlags();
1802 if ( linkerflags.size() > 0 )
1803 {
1804 fprintf ( fMakefile,
1805 "%s += %s\n\n",
1806 linkerflagsMacro.c_str (),
1807 linkerflags.c_str () );
1808 }
1809
1810 fprintf ( fMakefile, "\n\n" );
1811
1812 // future references to the macros will be to get their values
1813 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
1814 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
1815 widlflagsMacro = ssprintf ("$(%s)", widlflagsMacro.c_str ());
1816 }
1817
1818 void
1819 MingwModuleHandler::GenerateRules ()
1820 {
1821 string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
1822 string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
1823 string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
1824
1825 if ( module.name != "zlib" ) /* Avoid make warning */
1826 {
1827 string proxyMakefile = PassThruCacheDirectory (
1828 NormalizeFilename ( module.GetBasePath () + SSEP + "makefile" ),
1829 backend->outputDirectory );
1830 CLEAN_FILE ( proxyMakefile );
1831 }
1832
1833 string targetMacro = GetTargetMacro ( module );
1834 CLEAN_FILE ( targetMacro );
1835
1836 // generate phony target for module name
1837 fprintf ( fMakefile, ".PHONY: %s\n",
1838 module.name.c_str () );
1839 string dependencies = GetTargetMacro ( module );
1840 if ( module.type == Test )
1841 dependencies += " $(REGTESTS_RUN_TARGET)";
1842 fprintf ( fMakefile, "%s: %s\n\n",
1843 module.name.c_str (),
1844 dependencies.c_str () );
1845 if ( module.type == Test )
1846 {
1847 fprintf ( fMakefile,
1848 "\t@%s\n",
1849 targetMacro.c_str ());
1850 }
1851
1852 if ( !ReferenceObjects ( module ) )
1853 {
1854 string ar_target ( GenerateArchiveTarget ( ar, objectsMacro ) );
1855 if ( targetMacro != ar_target )
1856 CLEAN_FILE ( ar_target );
1857 }
1858
1859 GenerateObjectFileTargets ( cc,
1860 cppc,
1861 cflagsMacro,
1862 nasmflagsMacro,
1863 windresflagsMacro,
1864 widlflagsMacro );
1865 }
1866
1867 void
1868 MingwModuleHandler::GetInvocationDependencies (
1869 const Module& module,
1870 string_list& dependencies )
1871 {
1872 for ( size_t i = 0; i < module.invocations.size (); i++ )
1873 {
1874 Invoke& invoke = *module.invocations[i];
1875 if ( invoke.invokeModule == &module )
1876 /* Protect against circular dependencies */
1877 continue;
1878 invoke.GetTargets ( dependencies );
1879 }
1880 }
1881
1882 void
1883 MingwModuleHandler::GenerateInvocations () const
1884 {
1885 if ( module.invocations.size () == 0 )
1886 return;
1887
1888 size_t iend = module.invocations.size ();
1889 for ( size_t i = 0; i < iend; i++ )
1890 {
1891 const Invoke& invoke = *module.invocations[i];
1892
1893 if ( invoke.invokeModule->type != BuildTool )
1894 {
1895 throw InvalidBuildFileException ( module.node.location,
1896 "Only modules of type buildtool can be invoked." );
1897 }
1898
1899 string invokeTarget = module.GetInvocationTarget ( i );
1900 string_list invoke_targets;
1901 assert ( invoke_targets.size() );
1902 invoke.GetTargets ( invoke_targets );
1903 fprintf ( fMakefile,
1904 ".PHONY: %s\n\n",
1905 invokeTarget.c_str () );
1906 fprintf ( fMakefile,
1907 "%s:",
1908 invokeTarget.c_str () );
1909 size_t j, jend = invoke_targets.size();
1910 for ( j = 0; j < jend; j++ )
1911 {
1912 fprintf ( fMakefile,
1913 " %s",
1914 invoke_targets[i].c_str () );
1915 }
1916 fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
1917 for ( j = 1; j < jend; j++ )
1918 fprintf ( fMakefile,
1919 " %s",
1920 invoke_targets[i].c_str () );
1921 fprintf ( fMakefile,
1922 ": %s\n",
1923 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str () );
1924 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1925 fprintf ( fMakefile,
1926 "\t%s %s\n\n",
1927 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str (),
1928 invoke.GetParameters ().c_str () );
1929 }
1930 }
1931
1932 string
1933 MingwModuleHandler::GetPreconditionDependenciesName () const
1934 {
1935 return module.name + "_precondition";
1936 }
1937
1938 void
1939 MingwModuleHandler::GetDefaultDependencies (
1940 string_list& dependencies ) const
1941 {
1942 /* Avoid circular dependency */
1943 if ( module.type != BuildTool
1944 && module.name != "zlib"
1945 && module.name != "hostzlib" )
1946
1947 dependencies.push_back ( "$(INIT)" );
1948 }
1949
1950 void
1951 MingwModuleHandler::GeneratePreconditionDependencies ()
1952 {
1953 string preconditionDependenciesName = GetPreconditionDependenciesName ();
1954 string_list sourceFilenames;
1955 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
1956 string_list dependencies;
1957 GetDefaultDependencies ( dependencies );
1958 GetModuleDependencies ( dependencies );
1959
1960 GetInvocationDependencies ( module, dependencies );
1961
1962 if ( dependencies.size() )
1963 {
1964 fprintf ( fMakefile,
1965 "%s =",
1966 preconditionDependenciesName.c_str () );
1967 for ( size_t i = 0; i < dependencies.size(); i++ )
1968 fprintf ( fMakefile,
1969 " %s",
1970 dependencies[i].c_str () );
1971 fprintf ( fMakefile, "\n\n" );
1972 }
1973
1974 for ( size_t i = 0; i < sourceFilenames.size(); i++ )
1975 {
1976 fprintf ( fMakefile,
1977 "%s: ${%s}\n",
1978 sourceFilenames[i].c_str(),
1979 preconditionDependenciesName.c_str ());
1980 }
1981 fprintf ( fMakefile, "\n" );
1982 }
1983
1984 bool
1985 MingwModuleHandler::IsWineModule () const
1986 {
1987 if ( module.importLibrary == NULL)
1988 return false;
1989
1990 size_t index = module.importLibrary->definition.rfind ( ".spec.def" );
1991 return ( index != string::npos );
1992 }
1993
1994 string
1995 MingwModuleHandler::GetDefinitionFilename () const
1996 {
1997 if ( module.importLibrary != NULL )
1998 {
1999 string defFilename = module.GetBasePath () + SSEP + module.importLibrary->definition;
2000 if ( IsWineModule () )
2001 return PassThruCacheDirectory ( NormalizeFilename ( defFilename ),
2002 backend->intermediateDirectory );
2003 else
2004 return defFilename;
2005 }
2006 else
2007 return "tools" SSEP "rbuild" SSEP "empty.def";
2008 }
2009
2010 void
2011 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2012 {
2013 if ( module.importLibrary != NULL )
2014 {
2015 string library_target (
2016 GetImportLibraryFilename ( module, &clean_files ) );
2017 string defFilename = GetDefinitionFilename ();
2018
2019 string_list deps;
2020 GetDefinitionDependencies ( deps );
2021
2022 fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
2023
2024 fprintf ( fMakefile, "%s: %s",
2025 library_target.c_str (),
2026 defFilename.c_str () );
2027
2028 size_t i, iend = deps.size();
2029 for ( i = 0; i < iend; i++ )
2030 fprintf ( fMakefile, " %s",
2031 deps[i].c_str () );
2032
2033 fprintf ( fMakefile, " | %s\n",
2034 GetDirectory ( GetImportLibraryFilename ( module, NULL ) ).c_str () );
2035
2036 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
2037
2038 string killAt = module.mangledSymbols ? "" : "--kill-at";
2039 fprintf ( fMakefile,
2040 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
2041 module.GetTargetName ().c_str (),
2042 defFilename.c_str (),
2043 library_target.c_str (),
2044 killAt.c_str () );
2045 }
2046 }
2047
2048 void
2049 MingwModuleHandler::GetSpecObjectDependencies (
2050 string_list& dependencies,
2051 const string& filename ) const
2052 {
2053 string basename = GetBasename ( filename );
2054 string defDependency = PassThruCacheDirectory (
2055 NormalizeFilename ( basename + ".spec.def" ),
2056 backend->intermediateDirectory );
2057 dependencies.push_back ( defDependency );
2058 string stubsDependency = PassThruCacheDirectory (
2059 NormalizeFilename ( basename + ".stubs.c" ),
2060 backend->intermediateDirectory );
2061 dependencies.push_back ( stubsDependency );
2062 }
2063
2064 void
2065 MingwModuleHandler::GetWidlObjectDependencies (
2066 string_list& dependencies,
2067 const string& filename ) const
2068 {
2069 string basename = GetBasename ( filename );
2070 string serverSourceDependency = PassThruCacheDirectory (
2071 NormalizeFilename ( basename + "_s.c" ),
2072 backend->intermediateDirectory );
2073 dependencies.push_back ( serverSourceDependency );
2074 dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
2075 }
2076
2077 void
2078 MingwModuleHandler::GetDefinitionDependencies (
2079 string_list& dependencies ) const
2080 {
2081 string dkNkmLibNoFixup = "dk/nkm/lib";
2082 const vector<File*>& files = module.non_if_data.files;
2083 for ( size_t i = 0; i < files.size (); i++ )
2084 {
2085 File& file = *files[i];
2086 string extension = GetExtension ( file.name );
2087 if ( extension == ".spec" || extension == ".SPEC" )
2088 {
2089 GetSpecObjectDependencies ( dependencies, file.name );
2090 }
2091 if ( extension == ".idl" || extension == ".IDL" )
2092 {
2093 GetWidlObjectDependencies ( dependencies, file.name );
2094 }
2095 }
2096 }
2097
2098
2099 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
2100 : MingwModuleHandler ( module_ )
2101 {
2102 }
2103
2104 void
2105 MingwBuildToolModuleHandler::Process ()
2106 {
2107 GenerateBuildToolModuleTarget ();
2108 }
2109
2110 void
2111 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2112 {
2113 string targetMacro ( GetTargetMacro (module) );
2114 string objectsMacro = GetObjectsMacro ( module );
2115 string linkDepsMacro = GetLinkingDependenciesMacro ();
2116 string libsMacro = GetLibsMacro ();
2117
2118 GenerateRules ();
2119
2120 string linker;
2121 if ( module.cplusplus )
2122 linker = "${host_gpp}";
2123 else
2124 linker = "${host_gcc}";
2125
2126 fprintf ( fMakefile, "%s: %s %s | %s\n",
2127 targetMacro.c_str (),
2128 objectsMacro.c_str (),
2129 linkDepsMacro.c_str (),
2130 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2131 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2132 fprintf ( fMakefile,
2133 "\t%s %s -o $@ %s %s\n\n",
2134 linker.c_str (),
2135 GetLinkerMacro ().c_str (),
2136 objectsMacro.c_str (),
2137 libsMacro.c_str () );
2138 }
2139
2140
2141 MingwKernelModuleHandler::MingwKernelModuleHandler (
2142 const Module& module_ )
2143
2144 : MingwModuleHandler ( module_ )
2145 {
2146 }
2147
2148 void
2149 MingwKernelModuleHandler::Process ()
2150 {
2151 GenerateKernelModuleTarget ();
2152 }
2153
2154 void
2155 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2156 {
2157 string targetMacro ( GetTargetMacro ( module ) );
2158 string workingDirectory = GetWorkingDirectory ( );
2159 string objectsMacro = GetObjectsMacro ( module );
2160 string linkDepsMacro = GetLinkingDependenciesMacro ();
2161 string libsMacro = GetLibsMacro ();
2162
2163 GenerateImportLibraryTargetIfNeeded ();
2164
2165 if ( module.non_if_data.files.size () > 0 )
2166 {
2167 GenerateRules ();
2168
2169 string dependencies = linkDepsMacro + " " + objectsMacro;
2170
2171 string linkerParameters = ssprintf ( "-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2172 module.GetBasePath ().c_str (),
2173 module.entrypoint.c_str (),
2174 module.baseaddress.c_str () );
2175 GenerateLinkerCommand ( dependencies,
2176 "${gcc}",
2177 linkerParameters,
2178 objectsMacro,
2179 libsMacro,
2180 "-sections" );
2181 }
2182 else
2183 {
2184 GeneratePhonyTarget();
2185 }
2186 }
2187
2188
2189 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2190 const Module& module_ )
2191
2192 : MingwModuleHandler ( module_ )
2193 {
2194 }
2195
2196 void
2197 MingwStaticLibraryModuleHandler::Process ()
2198 {
2199 GenerateStaticLibraryModuleTarget ();
2200 }
2201
2202 void
2203 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2204 {
2205 GenerateRules ();
2206 }
2207
2208
2209 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2210 const Module& module_ )
2211
2212 : MingwModuleHandler ( module_ )
2213 {
2214 }
2215
2216 void
2217 MingwObjectLibraryModuleHandler::Process ()
2218 {
2219 GenerateObjectLibraryModuleTarget ();
2220 }
2221
2222 void
2223 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2224 {
2225 GenerateRules ();
2226 }
2227
2228
2229 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2230 const Module& module_ )
2231
2232 : MingwModuleHandler ( module_ )
2233 {
2234 }
2235
2236 void
2237 MingwKernelModeDLLModuleHandler::Process ()
2238 {
2239 GenerateKernelModeDLLModuleTarget ();
2240 }
2241
2242 void
2243 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2244 {
2245 string targetMacro ( GetTargetMacro ( module ) );
2246 string workingDirectory = GetWorkingDirectory ( );
2247 string objectsMacro = GetObjectsMacro ( module );
2248 string linkDepsMacro = GetLinkingDependenciesMacro ();
2249 string libsMacro = GetLibsMacro ();
2250
2251 GenerateImportLibraryTargetIfNeeded ();
2252
2253 if ( module.non_if_data.files.size () > 0 )
2254 {
2255 GenerateRules ();
2256
2257 string dependencies = linkDepsMacro + " " + objectsMacro;
2258
2259 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2260 module.entrypoint.c_str (),
2261 module.baseaddress.c_str () );
2262 GenerateLinkerCommand ( dependencies,
2263 "${gcc}",
2264 linkerParameters,
2265 objectsMacro,
2266 libsMacro,
2267 "-sections" );
2268 }
2269 else
2270 {
2271 GeneratePhonyTarget();
2272 }
2273 }
2274
2275
2276 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2277 const Module& module_ )
2278
2279 : MingwModuleHandler ( module_ )
2280 {
2281 }
2282
2283 void
2284 MingwKernelModeDriverModuleHandler::Process ()
2285 {
2286 GenerateKernelModeDriverModuleTarget ();
2287 }
2288
2289
2290 void
2291 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2292 {
2293 string targetMacro ( GetTargetMacro (module) );
2294 string workingDirectory = GetWorkingDirectory ();
2295 string objectsMacro = GetObjectsMacro ( module );
2296 string linkDepsMacro = GetLinkingDependenciesMacro ();
2297 string libsMacro = GetLibsMacro ();
2298
2299 GenerateImportLibraryTargetIfNeeded ();
2300
2301 if ( module.non_if_data.files.size () > 0 )
2302 {
2303 GenerateRules ();
2304
2305 string dependencies = linkDepsMacro + " " + objectsMacro;
2306
2307 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2308 module.entrypoint.c_str (),
2309 module.baseaddress.c_str () );
2310 GenerateLinkerCommand ( dependencies,
2311 "${gcc}",
2312 linkerParameters,
2313 objectsMacro,
2314 libsMacro,
2315 "-sections" );
2316 }
2317 else
2318 {
2319 GeneratePhonyTarget();
2320 }
2321 }
2322
2323
2324 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2325 const Module& module_ )
2326
2327 : MingwModuleHandler ( module_ )
2328 {
2329 }
2330
2331 void
2332 MingwNativeDLLModuleHandler::Process ()
2333 {
2334 GenerateNativeDLLModuleTarget ();
2335 }
2336
2337 void
2338 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2339 {
2340 string targetMacro ( GetTargetMacro (module) );
2341 string workingDirectory = GetWorkingDirectory ( );
2342 string objectsMacro = GetObjectsMacro ( module );
2343 string linkDepsMacro = GetLinkingDependenciesMacro ();
2344 string libsMacro = GetLibsMacro ();
2345
2346 GenerateImportLibraryTargetIfNeeded ();
2347
2348 if ( module.non_if_data.files.size () > 0 )
2349 {
2350 GenerateRules ();
2351
2352 string dependencies = linkDepsMacro + " " + objectsMacro;
2353
2354 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2355 module.entrypoint.c_str (),
2356 module.baseaddress.c_str () );
2357 GenerateLinkerCommand ( dependencies,
2358 "${gcc}",
2359 linkerParameters,
2360 objectsMacro,
2361 libsMacro,
2362 "" );
2363 }
2364 else
2365 {
2366 GeneratePhonyTarget();
2367 }
2368 }
2369
2370
2371 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2372 const Module& module_ )
2373
2374 : MingwModuleHandler ( module_ )
2375 {
2376 }
2377
2378 void
2379 MingwNativeCUIModuleHandler::Process ()
2380 {
2381 GenerateNativeCUIModuleTarget ();
2382 }
2383
2384 void
2385 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2386 {
2387 string targetMacro ( GetTargetMacro (module) );
2388 string workingDirectory = GetWorkingDirectory ( );
2389 string objectsMacro = GetObjectsMacro ( module );
2390 string linkDepsMacro = GetLinkingDependenciesMacro ();
2391 string libsMacro = GetLibsMacro ();
2392
2393 GenerateImportLibraryTargetIfNeeded ();
2394
2395 if ( module.non_if_data.files.size () > 0 )
2396 {
2397 GenerateRules ();
2398
2399 string dependencies = linkDepsMacro + " " + objectsMacro;
2400
2401 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2402 module.entrypoint.c_str (),
2403 module.baseaddress.c_str () );
2404 GenerateLinkerCommand ( dependencies,
2405 "${gcc}",
2406 linkerParameters,
2407 objectsMacro,
2408 libsMacro,
2409 "" );
2410 }
2411 else
2412 {
2413 GeneratePhonyTarget();
2414 }
2415 }
2416
2417
2418 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2419 const Module& module_ )
2420
2421 : MingwModuleHandler ( module_ )
2422 {
2423 }
2424
2425 void
2426 MingwWin32DLLModuleHandler::Process ()
2427 {
2428 GenerateWin32DLLModuleTarget ();
2429 }
2430
2431 void
2432 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2433 {
2434 string targetMacro ( GetTargetMacro (module) );
2435 string workingDirectory = GetWorkingDirectory ( );
2436 string objectsMacro = GetObjectsMacro ( module );
2437 string linkDepsMacro = GetLinkingDependenciesMacro ();
2438 string libsMacro = GetLibsMacro ();
2439
2440 GenerateImportLibraryTargetIfNeeded ();
2441
2442 if ( module.non_if_data.files.size () > 0 )
2443 {
2444 GenerateRules ();
2445
2446 string dependencies = linkDepsMacro + " " + objectsMacro;
2447
2448 string linker;
2449 if ( module.cplusplus )
2450 linker = "${gpp}";
2451 else
2452 linker = "${gcc}";
2453
2454 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2455 module.entrypoint.c_str (),
2456 module.baseaddress.c_str () );
2457 GenerateLinkerCommand ( dependencies,
2458 linker,
2459 linkerParameters,
2460 objectsMacro,
2461 libsMacro,
2462 "" );
2463 }
2464 else
2465 {
2466 GeneratePhonyTarget();
2467 }
2468 }
2469
2470
2471 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2472 const Module& module_ )
2473
2474 : MingwModuleHandler ( module_ )
2475 {
2476 }
2477
2478 void
2479 MingwWin32CUIModuleHandler::Process ()
2480 {
2481 GenerateWin32CUIModuleTarget ();
2482 }
2483
2484 void
2485 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2486 {
2487 string targetMacro ( GetTargetMacro (module) );
2488 string workingDirectory = GetWorkingDirectory ( );
2489 string objectsMacro = GetObjectsMacro ( module );
2490 string linkDepsMacro = GetLinkingDependenciesMacro ();
2491 string libsMacro = GetLibsMacro ();
2492
2493 GenerateImportLibraryTargetIfNeeded ();
2494
2495 if ( module.non_if_data.files.size () > 0 )
2496 {
2497 GenerateRules ();
2498
2499 string dependencies = linkDepsMacro + " " + objectsMacro;
2500
2501 string linker;
2502 if ( module.cplusplus )
2503 linker = "${gpp}";
2504 else
2505 linker = "${gcc}";
2506
2507 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2508 module.entrypoint.c_str (),
2509 module.baseaddress.c_str () );
2510 GenerateLinkerCommand ( dependencies,
2511 linker,
2512 linkerParameters,
2513 objectsMacro,
2514 libsMacro,
2515 "" );
2516 }
2517 else
2518 {
2519 GeneratePhonyTarget();
2520 }
2521 }
2522
2523
2524 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2525 const Module& module_ )
2526
2527 : MingwModuleHandler ( module_ )
2528 {
2529 }
2530
2531 void
2532 MingwWin32GUIModuleHandler::Process ()
2533 {
2534 GenerateWin32GUIModuleTarget ();
2535 }
2536
2537 void
2538 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2539 {
2540 string targetMacro ( GetTargetMacro (module) );
2541 string workingDirectory = GetWorkingDirectory ( );
2542 string objectsMacro = GetObjectsMacro ( module );
2543 string linkDepsMacro = GetLinkingDependenciesMacro ();
2544 string libsMacro = GetLibsMacro ();
2545
2546 GenerateImportLibraryTargetIfNeeded ();
2547
2548 if ( module.non_if_data.files.size () > 0 )
2549 {
2550 GenerateRules ();
2551
2552 string dependencies = linkDepsMacro + " " + objectsMacro;
2553
2554 string linker;
2555 if ( module.cplusplus )
2556 linker = "${gpp}";
2557 else
2558 linker = "${gcc}";
2559
2560 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2561 module.entrypoint.c_str (),
2562 module.baseaddress.c_str () );
2563 GenerateLinkerCommand ( dependencies,
2564 linker,
2565 linkerParameters,
2566 objectsMacro,
2567 libsMacro,
2568 "" );
2569 }
2570 else
2571 {
2572 GeneratePhonyTarget();
2573 }
2574 }
2575
2576
2577 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2578 const Module& module_ )
2579
2580 : MingwModuleHandler ( module_ )
2581 {
2582 }
2583
2584 void
2585 MingwBootLoaderModuleHandler::Process ()
2586 {
2587 GenerateBootLoaderModuleTarget ();
2588 }
2589
2590 void
2591 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2592 {
2593 string targetName ( module.GetTargetName () );
2594 string targetMacro ( GetTargetMacro (module) );
2595 string workingDirectory = GetWorkingDirectory ();
2596 string junk_tmp = ros_temp + module.name + ".junk.tmp";
2597 CLEAN_FILE ( junk_tmp );
2598 string objectsMacro = GetObjectsMacro ( module );
2599 string linkDepsMacro = GetLinkingDependenciesMacro ();
2600 string libsMacro = GetLibsMacro ();
2601
2602 GenerateRules ();
2603
2604 fprintf ( fMakefile, "%s: %s %s | %s\n",
2605 targetMacro.c_str (),
2606 objectsMacro.c_str (),
2607 linkDepsMacro.c_str (),
2608 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2609
2610 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2611
2612 fprintf ( fMakefile,
2613 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2614 GetLinkerMacro ().c_str (),
2615 junk_tmp.c_str (),
2616 objectsMacro.c_str (),
2617 linkDepsMacro.c_str () );
2618 fprintf ( fMakefile,
2619 "\t${objcopy} -O binary %s $@\n",
2620 junk_tmp.c_str () );
2621 fprintf ( fMakefile,
2622 "\t-@${rm} %s 2>$(NUL)\n",
2623 junk_tmp.c_str () );
2624 }
2625
2626
2627 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2628 const Module& module_ )
2629
2630 : MingwModuleHandler ( module_ )
2631 {
2632 }
2633
2634 void
2635 MingwBootSectorModuleHandler::Process ()
2636 {
2637 GenerateBootSectorModuleTarget ();
2638 }
2639
2640 void
2641 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2642 {
2643 string objectsMacro = GetObjectsMacro ( module );
2644
2645 GenerateRules ();
2646
2647 fprintf ( fMakefile, ".PHONY: %s\n\n",
2648 module.name.c_str ());
2649 fprintf ( fMakefile,
2650 "%s: %s\n",
2651 module.name.c_str (),
2652 objectsMacro.c_str () );
2653 }
2654
2655
2656 MingwIsoModuleHandler::MingwIsoModuleHandler (
2657 const Module& module_ )
2658
2659 : MingwModuleHandler ( module_ )
2660 {
2661 }
2662
2663 void
2664 MingwIsoModuleHandler::Process ()
2665 {
2666 GenerateIsoModuleTarget ();
2667 }
2668
2669 void
2670 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2671 const string& bootcdDirectory )
2672 {
2673 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2674 {
2675 const Module& m = *module.project.modules[i];
2676 if ( !m.enabled )
2677 continue;
2678 if ( m.bootstrap != NULL )
2679 {
2680 string sourceFilename = PassThruCacheDirectory (
2681 NormalizeFilename ( m.GetPath () ),
2682 backend->outputDirectory );
2683 string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
2684 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2685 NormalizeFilename ( targetFilenameNoFixup ),
2686 backend->outputDirectory );
2687 fprintf ( fMakefile,
2688 "\t$(ECHO_CP)\n" );
2689 fprintf ( fMakefile,
2690 "\t${cp} %s %s 1>$(NUL)\n",
2691 sourceFilename.c_str (),
2692 targetFilename.c_str () );
2693 }
2694 }
2695 }
2696
2697 void
2698 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2699 const string& bootcdDirectory )
2700 {
2701 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2702 {
2703 const CDFile& cdfile = *module.project.cdfiles[i];
2704 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2705 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2706 NormalizeFilename ( targetFilenameNoFixup ),
2707 backend->outputDirectory );
2708 fprintf ( fMakefile,
2709 "\t$(ECHO_CP)\n" );
2710 fprintf ( fMakefile,
2711 "\t${cp} %s %s 1>$(NUL)\n",
2712 cdfile.GetPath ().c_str (),
2713 targetFilename.c_str () );
2714 }
2715 }
2716
2717 string
2718 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
2719 {
2720 string directories;
2721 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2722 {
2723 const Module& m = *module.project.modules[i];
2724 if ( !m.enabled )
2725 continue;
2726 if ( m.bootstrap != NULL )
2727 {
2728 string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
2729 if ( directories.size () > 0 )
2730 directories += " ";
2731 directories += PassThruCacheDirectory (
2732 NormalizeFilename ( targetDirectory ),
2733 backend->outputDirectory );
2734 }
2735 }
2736 return directories;
2737 }
2738
2739 string
2740 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
2741 {
2742 string directories;
2743 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2744 {
2745 const CDFile& cdfile = *module.project.cdfiles[i];
2746 string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
2747 if ( directories.size () > 0 )
2748 directories += " ";
2749 directories += PassThruCacheDirectory (
2750 NormalizeFilename ( targetDirectory ),
2751 backend->outputDirectory );
2752 }
2753 return directories;
2754 }
2755
2756 string
2757 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
2758 {
2759 string directories = GetBootstrapCdDirectories ( bootcdDirectory );
2760 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
2761 return directories;
2762 }
2763
2764 void
2765 MingwIsoModuleHandler::GetBootstrapCdFiles (
2766 vector<string>& out ) const
2767 {
2768 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2769 {
2770 const Module& m = *module.project.modules[i];
2771 if ( !m.enabled )
2772 continue;
2773 if ( m.bootstrap != NULL )
2774 {
2775 string filename = PassThruCacheDirectory (
2776 NormalizeFilename ( m.GetPath () ),
2777 backend->outputDirectory );
2778 out.push_back ( filename );
2779 }
2780 }
2781 }
2782
2783 void
2784 MingwIsoModuleHandler::GetNonModuleCdFiles (
2785 vector<string>& out ) const
2786 {
2787 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2788 {
2789 const CDFile& cdfile = *module.project.cdfiles[i];
2790 out.push_back ( cdfile.GetPath () );
2791 }
2792 }
2793
2794 void
2795 MingwIsoModuleHandler::GetCdFiles (
2796 vector<string>& out ) const
2797 {
2798 GetBootstrapCdFiles ( out );
2799 GetNonModuleCdFiles ( out );
2800 }
2801
2802 void
2803 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2804 {
2805 string bootcdDirectory = "cd";
2806 string bootcd = PassThruCacheDirectory (
2807 NormalizeFilename ( bootcdDirectory + SSEP ),
2808 backend->outputDirectory );
2809 string isoboot = PassThruCacheDirectory (
2810 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2811 backend->outputDirectory );
2812 string bootcdReactosNoFixup = bootcdDirectory + SSEP "reactos";
2813 string bootcdReactos = PassThruCacheDirectory (
2814 NormalizeFilename ( bootcdReactosNoFixup + SSEP ),
2815 backend->outputDirectory );
2816 CLEAN_FILE ( bootcdReactos );
2817 string reactosInf = PassThruCacheDirectory (
2818 NormalizeFilename ( bootcdReactosNoFixup + SSEP "reactos.inf" ),
2819 backend->outputDirectory );
2820 string reactosDff = NormalizeFilename ( "bootdata" SSEP "packages" SSEP "reactos.dff" );
2821 string cdDirectories = GetCdDirectories ( bootcdDirectory );
2822 vector<string> vCdFiles;
2823 GetCdFiles ( vCdFiles );
2824 string cdFiles = v2s ( vCdFiles, 5 );
2825
2826 fprintf ( fMakefile, ".PHONY: %s\n\n",
2827 module.name.c_str ());
2828 fprintf ( fMakefile,
2829 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2830 module.name.c_str (),
2831 isoboot.c_str (),
2832 bootcdReactos.c_str (),
2833 cdDirectories.c_str (),
2834 cdFiles.c_str () );
2835 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2836 fprintf ( fMakefile,
2837 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2838 reactosDff.c_str (),
2839 bootcdReactos.c_str () );
2840 fprintf ( fMakefile,
2841 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2842 reactosDff.c_str (),
2843 reactosInf.c_str (),
2844 bootcdReactos.c_str ());
2845 fprintf ( fMakefile,
2846 "\t-@${rm} %s 2>$(NUL)\n",
2847 reactosInf.c_str () );
2848 OutputBootstrapfileCopyCommands ( bootcdDirectory );
2849 OutputCdfileCopyCommands ( bootcdDirectory );
2850 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2851 fprintf ( fMakefile,
2852 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2853 isoboot.c_str (),
2854 bootcd.c_str () );
2855 fprintf ( fMakefile,
2856 "\n" );
2857 }
2858
2859
2860 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2861 const Module& module_ )
2862
2863 : MingwModuleHandler ( module_ )
2864 {
2865 }
2866
2867 void
2868 MingwLiveIsoModuleHandler::Process ()
2869 {
2870 GenerateLiveIsoModuleTarget ();
2871 }
2872
2873 void
2874 MingwLiveIsoModuleHandler::CreateDirectory ( const string& directory )
2875 {
2876 string normalizedDirectory = MingwModuleHandler::PassThruCacheDirectory (
2877 NormalizeFilename ( directory ) + SSEP,
2878 backend->outputDirectory );
2879 }
2880
2881 void
2882 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string& sourceFilename,
2883 const string& targetFilename,
2884 const string& targetDirectory )
2885 {
2886 string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
2887 NormalizeFilename ( targetDirectory + SSEP + targetFilename ),
2888 backend->outputDirectory );
2889 fprintf ( fMakefile,
2890 "\t$(ECHO_CP)\n" );
2891 fprintf ( fMakefile,
2892 "\t${cp} %s %s 1>$(NUL)\n",
2893 sourceFilename.c_str (),
2894 normalizedTargetFilename.c_str () );
2895 }
2896
2897 void
2898 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string& livecdDirectory,
2899 string& reactosDirectory )
2900 {
2901 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2902 {
2903 const Module& m = *module.project.modules[i];
2904 if ( !m.enabled )
2905 continue;
2906 if ( m.installName.length () > 0 )
2907 {
2908 const Module& aliasedModule = backend->GetAliasedModuleOrModule ( m );
2909 string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
2910 NormalizeFilename ( aliasedModule.GetPath () ),
2911 backend->outputDirectory );
2912 OutputCopyCommand ( sourceFilename,
2913 m.installName,
2914 livecdDirectory + SSEP + reactosDirectory + SSEP + m.installBase );
2915 }
2916 }
2917 }
2918
2919 void
2920 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string& livecdDirectory,
2921 string& reactosDirectory )
2922 {
2923 for ( size_t i = 0; i < module.project.installfiles.size (); i++ )
2924 {
2925 const InstallFile& installfile = *module.project.installfiles[i];
2926 OutputCopyCommand ( installfile.GetPath (),
2927 installfile.newname,
2928 livecdDirectory + SSEP + reactosDirectory + SSEP + installfile.base );
2929 }
2930 }
2931
2932 void
2933 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string& livecdDirectory )
2934 {
2935 CreateDirectory ( livecdDirectory + SSEP "Profiles" );
2936 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users") ;
2937 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users" SSEP "Desktop" );
2938 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" );
2939 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "Desktop" );
2940 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "My Documents" );
2941
2942 string livecdIni = "bootdata" SSEP "livecd.ini";
2943 OutputCopyCommand ( livecdIni,
2944 "freeldr.ini",
2945 livecdDirectory );
2946 }
2947
2948 void
2949 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string& livecdDirectory )
2950 {
2951 string freeldr = PassThruCacheDirectory (
2952 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "freeldr" SSEP "freeldr.sys" ),
2953 backend->outputDirectory );
2954 CreateDirectory ( livecdDirectory + SSEP "loader" );
2955 OutputCopyCommand ( freeldr,
2956 "setupldr.sys",
2957 livecdDirectory + SSEP + "loader" );
2958 }
2959
2960 void
2961 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string& livecdDirectory )
2962 {
2963 string reactosSystem32ConfigDirectory = NormalizeFilename (
2964 MingwModuleHandler::PassThruCacheDirectory (
2965 livecdDirectory + SSEP "reactos" SSEP "system32" SSEP "config" SSEP,
2966 backend->outputDirectory ) );
2967 fprintf ( fMakefile,
2968 "\t$(ECHO_MKHIVE)\n" );
2969 fprintf ( fMakefile,
2970 "\t$(MKHIVE_TARGET) bootdata %s bootdata" SSEP "livecd.inf bootdata" SSEP "hiveinst.inf\n",
2971 reactosSystem32ConfigDirectory.c_str () );
2972 }
2973
2974 void
2975 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
2976 {
2977 string livecdDirectory = "livecd";
2978 string livecd = PassThruCacheDirectory (
2979 NormalizeFilename ( livecdDirectory + SSEP ),
2980 backend->outputDirectory );
2981 string isoboot = PassThruCacheDirectory (
2982 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2983 backend->outputDirectory );
2984 string reactosDirectory = "reactos";
2985 string livecdReactosNoFixup = livecdDirectory + SSEP + reactosDirectory;
2986 string livecdReactos = NormalizeFilename ( PassThruCacheDirectory (
2987 NormalizeFilename ( livecdReactosNoFixup + SSEP ),
2988 backend->outputDirectory ) );
2989 CLEAN_FILE ( livecdReactos );
2990
2991 fprintf ( fMakefile, ".PHONY: %s\n\n",
2992 module.name.c_str ());
2993 fprintf ( fMakefile,
2994 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
2995 module.name.c_str (),
2996 isoboot.c_str (),
2997 livecdReactos.c_str () );
2998 OutputModuleCopyCommands ( livecdDirectory,
2999 reactosDirectory );
3000 OutputNonModuleCopyCommands ( livecdDirectory,
3001 reactosDirectory );
3002 OutputProfilesDirectoryCommands ( livecdDirectory );
3003 OutputLoaderCommands ( livecdDirectory );
3004 OutputRegistryCommands ( livecdDirectory );
3005 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
3006 fprintf ( fMakefile,
3007 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
3008 isoboot.c_str (),
3009 livecd.c_str () );
3010 fprintf ( fMakefile,
3011 "\n" );
3012 }
3013
3014
3015 MingwTestModuleHandler::MingwTestModuleHandler (
3016 const Module& module_ )
3017
3018 : MingwModuleHandler ( module_ )
3019 {
3020 }
3021
3022 void
3023 MingwTestModuleHandler::Process ()
3024 {
3025 GenerateTestModuleTarget ();
3026 }
3027
3028 void
3029 MingwTestModuleHandler::GetModuleSpecificSourceFiles ( vector<File*>& sourceFiles )
3030 {
3031 string basePath = "$(INTERMEDIATE)" SSEP + module.GetBasePath ();
3032 sourceFiles.push_back ( new File ( basePath + SSEP "_hooks.c", false, "", false ) );
3033 sourceFiles.push_back ( new File ( basePath + SSEP "_stubs.S", false, "", false ) );
3034 sourceFiles.push_back ( new File ( basePath + SSEP "_startup.c", false, "", false ) );
3035 }
3036
3037 void
3038 MingwTestModuleHandler::GenerateTestModuleTarget ()
3039 {
3040 string targetMacro ( GetTargetMacro ( module ) );
3041 string workingDirectory = GetWorkingDirectory ( );
3042 string objectsMacro = GetObjectsMacro ( module );
3043 string linkDepsMacro = GetLinkingDependenciesMacro ();
3044 string libsMacro = GetLibsMacro ();
3045
3046 GenerateImportLibraryTargetIfNeeded ();
3047
3048 if ( module.non_if_data.files.size () > 0 )
3049 {
3050 GenerateRules ();
3051
3052 string dependencies = linkDepsMacro + " " + objectsMacro;
3053
3054 string linker;
3055 if ( module.cplusplus )
3056 linker = "${gpp}";
3057 else
3058 linker = "${gcc}";
3059
3060 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3061 module.entrypoint.c_str (),
3062 module.baseaddress.c_str () );
3063 GenerateLinkerCommand ( dependencies,
3064 linker,
3065 linkerParameters,
3066 objectsMacro,
3067 libsMacro,
3068 "" );
3069 }
3070 else
3071 {
3072 GeneratePhonyTarget();
3073 }
3074 }
3075
3076
3077 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3078 const Module& module_ )
3079
3080 : MingwModuleHandler ( module_ )
3081 {
3082 }
3083
3084 void
3085 MingwRpcServerModuleHandler::Process ()
3086 {
3087 GenerateRules ();
3088 }
3089
3090
3091 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3092 const Module& module_ )
3093
3094 : MingwModuleHandler ( module_ )
3095 {
3096 }
3097
3098 void
3099 MingwRpcClientModuleHandler::Process ()
3100 {
3101 GenerateRules ();
3102 }
3103
3104
3105 MingwAliasModuleHandler::MingwAliasModuleHandler (
3106 const Module& module_ )
3107
3108 : MingwModuleHandler ( module_ )
3109 {
3110 }
3111
3112 void
3113 MingwAliasModuleHandler::Process ()
3114 {
3115 }