Add new PEFIXUP tool and use it in the build system.
[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 {
1417 string target ( GetTargetMacro ( module ) );
1418 string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );
1419 string def_file = GetDefinitionFilename ();
1420
1421 fprintf ( fMakefile,
1422 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1423 target.c_str (),
1424 def_file.c_str (),
1425 dependencies.c_str (),
1426 target_folder.c_str () );
1427 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1428 string targetName ( module.GetTargetName () );
1429
1430 if ( module.IsDLL () )
1431 {
1432 string temp_exp = ros_temp + module.name + ".temp.exp";
1433 CLEAN_FILE ( temp_exp );
1434
1435 string killAt = module.mangledSymbols ? "" : "--kill-at";
1436 fprintf ( fMakefile,
1437 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1438 targetName.c_str (),
1439 def_file.c_str (),
1440 temp_exp.c_str (),
1441 killAt.c_str () );
1442
1443 fprintf ( fMakefile,
1444 "\t%s %s %s -o %s %s %s %s\n",
1445 linker.c_str (),
1446 linkerParameters.c_str (),
1447 temp_exp.c_str (),
1448 target.c_str (),
1449 objectsMacro.c_str (),
1450 libsMacro.c_str (),
1451 GetLinkerMacro ().c_str () );
1452
1453 fprintf ( fMakefile,
1454 "\t$(Q)$(PEFIXUP_TARGET) %s -exports\n",
1455 target.c_str () );
1456
1457 fprintf ( fMakefile,
1458 "\t-@${rm} %s 2>$(NUL)\n",
1459 temp_exp.c_str () );
1460 }
1461 else
1462 {
1463 fprintf ( fMakefile,
1464 "\t%s %s -o %s %s %s %s\n",
1465 linker.c_str (),
1466 linkerParameters.c_str (),
1467 target.c_str (),
1468 objectsMacro.c_str (),
1469 libsMacro.c_str (),
1470 GetLinkerMacro ().c_str () );
1471 }
1472
1473 GenerateBuildMapCode ();
1474 GenerateBuildNonSymbolStrippedCode ();
1475 GenerateRunRsymCode ();
1476 GenerateCleanObjectsAsYouGoCode ();
1477 }
1478
1479 void
1480 MingwModuleHandler::GeneratePhonyTarget() const
1481 {
1482 string targetMacro ( GetTargetMacro ( module ) );
1483 fprintf ( fMakefile,
1484 ".PHONY: %s\n\n",
1485 targetMacro.c_str ());
1486 fprintf ( fMakefile, "%s: | %s\n",
1487 targetMacro.c_str (),
1488 GetDirectory ( GetTargetFilename ( module, NULL ) ).c_str () );
1489 }
1490
1491 void
1492 MingwModuleHandler::GenerateObjectFileTargets (
1493 const IfableData& data,
1494 const string& cc,
1495 const string& cppc,
1496 const string& cflagsMacro,
1497 const string& nasmflagsMacro,
1498 const string& windresflagsMacro,
1499 const string& widlflagsMacro )
1500 {
1501 size_t i;
1502
1503 const vector<File*>& files = data.files;
1504 for ( i = 0; i < files.size (); i++ )
1505 {
1506 GenerateCommands ( *files[i],
1507 cc,
1508 cppc,
1509 cflagsMacro,
1510 nasmflagsMacro,
1511 windresflagsMacro,
1512 widlflagsMacro );
1513 fprintf ( fMakefile,
1514 "\n" );
1515 }
1516
1517 const vector<If*>& ifs = data.ifs;
1518 for ( i = 0; i < ifs.size(); i++ )
1519 {
1520 GenerateObjectFileTargets ( ifs[i]->data,
1521 cc,
1522 cppc,
1523 cflagsMacro,
1524 nasmflagsMacro,
1525 windresflagsMacro,
1526 widlflagsMacro );
1527 }
1528
1529 vector<File*> sourceFiles;
1530 GetModuleSpecificSourceFiles ( sourceFiles );
1531 for ( i = 0; i < sourceFiles.size (); i++ )
1532 {
1533 GenerateCommands ( *sourceFiles[i],
1534 cc,
1535 cppc,
1536 cflagsMacro,
1537 nasmflagsMacro,
1538 windresflagsMacro,
1539 widlflagsMacro );
1540 }
1541 CleanupFileVector ( sourceFiles );
1542 }
1543
1544 void
1545 MingwModuleHandler::GenerateObjectFileTargets (
1546 const string& cc,
1547 const string& cppc,
1548 const string& cflagsMacro,
1549 const string& nasmflagsMacro,
1550 const string& windresflagsMacro,
1551 const string& widlflagsMacro )
1552 {
1553 if ( module.pch && use_pch )
1554 {
1555 const string& baseHeaderFilename = module.pch->file.name;
1556 const string& pchFilename = GetPrecompiledHeaderFilename ();
1557 CLEAN_FILE(pchFilename);
1558 fprintf ( fMakefile,
1559 "%s: %s\n",
1560 pchFilename.c_str(),
1561 baseHeaderFilename.c_str() );
1562 fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
1563 fprintf ( fMakefile,
1564 "\t%s -o %s %s -g %s\n\n",
1565 module.cplusplus ? cppc.c_str() : cc.c_str(),
1566 pchFilename.c_str(),
1567 cflagsMacro.c_str(),
1568 baseHeaderFilename.c_str() );
1569 }
1570
1571 GenerateObjectFileTargets ( module.non_if_data,
1572 cc,
1573 cppc,
1574 cflagsMacro,
1575 nasmflagsMacro,
1576 windresflagsMacro,
1577 widlflagsMacro );
1578 fprintf ( fMakefile, "\n" );
1579 }
1580
1581 string
1582 MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
1583 const string& objs_macro ) const
1584 {
1585 string archiveFilename ( GetModuleArchiveFilename () );
1586
1587 fprintf ( fMakefile,
1588 "%s: %s | %s\n",
1589 archiveFilename.c_str (),
1590 objs_macro.c_str (),
1591 GetDirectory(archiveFilename).c_str() );
1592
1593 fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
1594
1595 fprintf ( fMakefile,
1596 "\t%s -rc $@ %s\n",
1597 ar.c_str (),
1598 objs_macro.c_str ());
1599
1600 GenerateCleanObjectsAsYouGoCode ();
1601
1602 fprintf ( fMakefile, "\n" );
1603
1604 return archiveFilename;
1605 }
1606
1607 string
1608 MingwModuleHandler::GetCFlagsMacro () const
1609 {
1610 return ssprintf ( "$(%s_CFLAGS)",
1611 module.name.c_str () );
1612 }
1613
1614 /*static*/ string
1615 MingwModuleHandler::GetObjectsMacro ( const Module& module )
1616 {
1617 return ssprintf ( "$(%s_OBJS)",
1618 module.name.c_str () );
1619 }
1620
1621 string
1622 MingwModuleHandler::GetLinkingDependenciesMacro () const
1623 {
1624 return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
1625 }
1626
1627 string
1628 MingwModuleHandler::GetLibsMacro () const
1629 {
1630 return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
1631 }
1632
1633 string
1634 MingwModuleHandler::GetLinkerMacro () const
1635 {
1636 return ssprintf ( "$(%s_LFLAGS)",
1637 module.name.c_str () );
1638 }
1639
1640 string
1641 MingwModuleHandler::GetModuleTargets ( const Module& module )
1642 {
1643 if ( ReferenceObjects ( module ) )
1644 return GetObjectsMacro ( module );
1645 else
1646 return GetTargetFilename ( module, NULL );
1647 }
1648
1649 void
1650 MingwModuleHandler::GenerateObjectMacro ()
1651 {
1652 objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
1653
1654 GenerateObjectMacros (
1655 "=",
1656 module.non_if_data,
1657 &module.linkerFlags );
1658
1659 // future references to the macro will be to get its values
1660 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
1661 }
1662
1663 void
1664 MingwModuleHandler::GenerateTargetMacro ()
1665 {
1666 fprintf ( fMakefile,
1667 "%s := %s\n",
1668 GetTargetMacro ( module, false ).c_str (),
1669 GetModuleTargets ( module ).c_str () );
1670 }
1671
1672 void
1673 MingwModuleHandler::GetRpcHeaderDependencies (
1674 vector<string>& dependencies ) const
1675 {
1676 for ( size_t i = 0; i < module.non_if_data.libraries.size (); i++ )
1677 {
1678 Library& library = *module.non_if_data.libraries[i];
1679 if ( library.importedModule->type == RpcServer ||
1680 library.importedModule->type == RpcClient )
1681 {
1682 for ( size_t j = 0; j < library.importedModule->non_if_data.files.size (); j++ )
1683 {
1684 File& file = *library.importedModule->non_if_data.files[j];
1685 string extension = GetExtension ( file.name );
1686 if ( extension == ".idl" || extension == ".IDL" )
1687 {
1688 string basename = GetBasename ( file.name );
1689 if ( library.importedModule->type == RpcServer )
1690 dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
1691 if ( library.importedModule->type == RpcClient )
1692 dependencies.push_back ( GetRpcClientHeaderFilename ( basename ) );
1693 }
1694 }
1695 }
1696 }
1697 }
1698
1699 void
1700 MingwModuleHandler::GenerateOtherMacros ()
1701 {
1702 cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
1703 nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
1704 windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
1705 widlflagsMacro = ssprintf ("%s_WIDLFLAGS", module.name.c_str ());
1706 linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
1707 libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
1708 linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
1709
1710 GenerateMacros (
1711 "=",
1712 module.non_if_data,
1713 &module.linkerFlags );
1714
1715 vector<string> s;
1716 if ( module.importLibrary )
1717 {
1718 const vector<File*>& files = module.non_if_data.files;
1719 for ( size_t i = 0; i < files.size (); i++ )
1720 {
1721 File& file = *files[i];
1722 string extension = GetExtension ( file.name );
1723 if ( extension == ".spec" || extension == ".SPEC" )
1724 GetSpecObjectDependencies ( s, file.name );
1725 }
1726 }
1727 if ( s.size () > 0 )
1728 {
1729 fprintf (
1730 fMakefile,
1731 "%s +=",
1732 linkDepsMacro.c_str() );
1733 for ( size_t i = 0; i < s.size(); i++ )
1734 fprintf ( fMakefile,
1735 " %s",
1736 s[i].c_str () );
1737 fprintf ( fMakefile, "\n" );
1738 }
1739
1740 string globalCflags = "-g";
1741 if ( backend->usePipe )
1742 globalCflags += " -pipe";
1743 if ( !module.enableWarnings )
1744 globalCflags += " -Werror";
1745
1746 fprintf (
1747 fMakefile,
1748 "%s += $(PROJECT_CFLAGS) %s\n",
1749 cflagsMacro.c_str (),
1750 globalCflags.c_str () );
1751
1752 fprintf (
1753 fMakefile,
1754 "%s += $(PROJECT_RCFLAGS)\n",
1755 windresflagsMacro.c_str () );
1756
1757 fprintf (
1758 fMakefile,
1759 "%s += $(PROJECT_WIDLFLAGS)\n",
1760 widlflagsMacro.c_str () );
1761
1762 fprintf (
1763 fMakefile,
1764 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1765 module.name.c_str () );
1766
1767 fprintf (
1768 fMakefile,
1769 "%s += $(%s)\n",
1770 linkDepsMacro.c_str (),
1771 libsMacro.c_str () );
1772
1773 string cflags = TypeSpecificCFlags();
1774 if ( cflags.size() > 0 )
1775 {
1776 fprintf ( fMakefile,
1777 "%s += %s\n\n",
1778 cflagsMacro.c_str (),
1779 cflags.c_str () );
1780 }
1781
1782 string nasmflags = TypeSpecificNasmFlags();
1783 if ( nasmflags.size () > 0 )
1784 {
1785 fprintf ( fMakefile,
1786 "%s += %s\n\n",
1787 nasmflagsMacro.c_str (),
1788 nasmflags.c_str () );
1789 }
1790
1791 string linkerflags = TypeSpecificLinkerFlags();
1792 if ( linkerflags.size() > 0 )
1793 {
1794 fprintf ( fMakefile,
1795 "%s += %s\n\n",
1796 linkerflagsMacro.c_str (),
1797 linkerflags.c_str () );
1798 }
1799
1800 fprintf ( fMakefile, "\n\n" );
1801
1802 // future references to the macros will be to get their values
1803 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
1804 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
1805 widlflagsMacro = ssprintf ("$(%s)", widlflagsMacro.c_str ());
1806 }
1807
1808 void
1809 MingwModuleHandler::GenerateRules ()
1810 {
1811 string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
1812 string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
1813 string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
1814
1815 if ( module.name != "zlib" ) /* Avoid make warning */
1816 {
1817 string proxyMakefile = PassThruCacheDirectory (
1818 NormalizeFilename ( module.GetBasePath () + SSEP + "makefile" ),
1819 backend->outputDirectory );
1820 CLEAN_FILE ( proxyMakefile );
1821 }
1822
1823 string targetMacro = GetTargetMacro ( module );
1824 CLEAN_FILE ( targetMacro );
1825
1826 // generate phony target for module name
1827 fprintf ( fMakefile, ".PHONY: %s\n",
1828 module.name.c_str () );
1829 string dependencies = GetTargetMacro ( module );
1830 if ( module.type == Test )
1831 dependencies += " $(REGTESTS_RUN_TARGET)";
1832 fprintf ( fMakefile, "%s: %s\n\n",
1833 module.name.c_str (),
1834 dependencies.c_str () );
1835 if ( module.type == Test )
1836 {
1837 fprintf ( fMakefile,
1838 "\t@%s\n",
1839 targetMacro.c_str ());
1840 }
1841
1842 if ( !ReferenceObjects ( module ) )
1843 {
1844 string ar_target ( GenerateArchiveTarget ( ar, objectsMacro ) );
1845 if ( targetMacro != ar_target )
1846 CLEAN_FILE ( ar_target );
1847 }
1848
1849 GenerateObjectFileTargets ( cc,
1850 cppc,
1851 cflagsMacro,
1852 nasmflagsMacro,
1853 windresflagsMacro,
1854 widlflagsMacro );
1855 }
1856
1857 void
1858 MingwModuleHandler::GetInvocationDependencies (
1859 const Module& module,
1860 string_list& dependencies )
1861 {
1862 for ( size_t i = 0; i < module.invocations.size (); i++ )
1863 {
1864 Invoke& invoke = *module.invocations[i];
1865 if ( invoke.invokeModule == &module )
1866 /* Protect against circular dependencies */
1867 continue;
1868 invoke.GetTargets ( dependencies );
1869 }
1870 }
1871
1872 void
1873 MingwModuleHandler::GenerateInvocations () const
1874 {
1875 if ( module.invocations.size () == 0 )
1876 return;
1877
1878 size_t iend = module.invocations.size ();
1879 for ( size_t i = 0; i < iend; i++ )
1880 {
1881 const Invoke& invoke = *module.invocations[i];
1882
1883 if ( invoke.invokeModule->type != BuildTool )
1884 {
1885 throw InvalidBuildFileException ( module.node.location,
1886 "Only modules of type buildtool can be invoked." );
1887 }
1888
1889 string invokeTarget = module.GetInvocationTarget ( i );
1890 string_list invoke_targets;
1891 assert ( invoke_targets.size() );
1892 invoke.GetTargets ( invoke_targets );
1893 fprintf ( fMakefile,
1894 ".PHONY: %s\n\n",
1895 invokeTarget.c_str () );
1896 fprintf ( fMakefile,
1897 "%s:",
1898 invokeTarget.c_str () );
1899 size_t j, jend = invoke_targets.size();
1900 for ( j = 0; j < jend; j++ )
1901 {
1902 fprintf ( fMakefile,
1903 " %s",
1904 invoke_targets[i].c_str () );
1905 }
1906 fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
1907 for ( j = 1; j < jend; j++ )
1908 fprintf ( fMakefile,
1909 " %s",
1910 invoke_targets[i].c_str () );
1911 fprintf ( fMakefile,
1912 ": %s\n",
1913 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str () );
1914 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1915 fprintf ( fMakefile,
1916 "\t%s %s\n\n",
1917 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str (),
1918 invoke.GetParameters ().c_str () );
1919 }
1920 }
1921
1922 string
1923 MingwModuleHandler::GetPreconditionDependenciesName () const
1924 {
1925 return module.name + "_precondition";
1926 }
1927
1928 void
1929 MingwModuleHandler::GetDefaultDependencies (
1930 string_list& dependencies ) const
1931 {
1932 /* Avoid circular dependency */
1933 if ( module.type != BuildTool
1934 && module.name != "zlib"
1935 && module.name != "hostzlib" )
1936
1937 dependencies.push_back ( "$(INIT)" );
1938 }
1939
1940 void
1941 MingwModuleHandler::GeneratePreconditionDependencies ()
1942 {
1943 string preconditionDependenciesName = GetPreconditionDependenciesName ();
1944 string_list sourceFilenames;
1945 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
1946 string_list dependencies;
1947 GetDefaultDependencies ( dependencies );
1948 GetModuleDependencies ( dependencies );
1949
1950 GetInvocationDependencies ( module, dependencies );
1951
1952 if ( dependencies.size() )
1953 {
1954 fprintf ( fMakefile,
1955 "%s =",
1956 preconditionDependenciesName.c_str () );
1957 for ( size_t i = 0; i < dependencies.size(); i++ )
1958 fprintf ( fMakefile,
1959 " %s",
1960 dependencies[i].c_str () );
1961 fprintf ( fMakefile, "\n\n" );
1962 }
1963
1964 for ( size_t i = 0; i < sourceFilenames.size(); i++ )
1965 {
1966 fprintf ( fMakefile,
1967 "%s: ${%s}\n",
1968 sourceFilenames[i].c_str(),
1969 preconditionDependenciesName.c_str ());
1970 }
1971 fprintf ( fMakefile, "\n" );
1972 }
1973
1974 bool
1975 MingwModuleHandler::IsWineModule () const
1976 {
1977 if ( module.importLibrary == NULL)
1978 return false;
1979
1980 size_t index = module.importLibrary->definition.rfind ( ".spec.def" );
1981 return ( index != string::npos );
1982 }
1983
1984 string
1985 MingwModuleHandler::GetDefinitionFilename () const
1986 {
1987 if ( module.importLibrary != NULL )
1988 {
1989 string defFilename = module.GetBasePath () + SSEP + module.importLibrary->definition;
1990 if ( IsWineModule () )
1991 return PassThruCacheDirectory ( NormalizeFilename ( defFilename ),
1992 backend->intermediateDirectory );
1993 else
1994 return defFilename;
1995 }
1996 else
1997 return "tools" SSEP "rbuild" SSEP "empty.def";
1998 }
1999
2000 void
2001 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2002 {
2003 if ( module.importLibrary != NULL )
2004 {
2005 string library_target (
2006 GetImportLibraryFilename ( module, &clean_files ) );
2007 string defFilename = GetDefinitionFilename ();
2008
2009 string_list deps;
2010 GetDefinitionDependencies ( deps );
2011
2012 fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
2013
2014 fprintf ( fMakefile, "%s: %s",
2015 library_target.c_str (),
2016 defFilename.c_str () );
2017
2018 size_t i, iend = deps.size();
2019 for ( i = 0; i < iend; i++ )
2020 fprintf ( fMakefile, " %s",
2021 deps[i].c_str () );
2022
2023 fprintf ( fMakefile, " | %s\n",
2024 GetDirectory ( GetImportLibraryFilename ( module, NULL ) ).c_str () );
2025
2026 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
2027
2028 string killAt = module.mangledSymbols ? "" : "--kill-at";
2029 fprintf ( fMakefile,
2030 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
2031 module.GetTargetName ().c_str (),
2032 defFilename.c_str (),
2033 library_target.c_str (),
2034 killAt.c_str () );
2035 }
2036 }
2037
2038 void
2039 MingwModuleHandler::GetSpecObjectDependencies (
2040 string_list& dependencies,
2041 const string& filename ) const
2042 {
2043 string basename = GetBasename ( filename );
2044 string defDependency = PassThruCacheDirectory (
2045 NormalizeFilename ( basename + ".spec.def" ),
2046 backend->intermediateDirectory );
2047 dependencies.push_back ( defDependency );
2048 string stubsDependency = PassThruCacheDirectory (
2049 NormalizeFilename ( basename + ".stubs.c" ),
2050 backend->intermediateDirectory );
2051 dependencies.push_back ( stubsDependency );
2052 }
2053
2054 void
2055 MingwModuleHandler::GetWidlObjectDependencies (
2056 string_list& dependencies,
2057 const string& filename ) const
2058 {
2059 string basename = GetBasename ( filename );
2060 string serverSourceDependency = PassThruCacheDirectory (
2061 NormalizeFilename ( basename + "_s.c" ),
2062 backend->intermediateDirectory );
2063 dependencies.push_back ( serverSourceDependency );
2064 dependencies.push_back ( GetRpcServerHeaderFilename ( basename ) );
2065 }
2066
2067 void
2068 MingwModuleHandler::GetDefinitionDependencies (
2069 string_list& dependencies ) const
2070 {
2071 string dkNkmLibNoFixup = "dk/nkm/lib";
2072 const vector<File*>& files = module.non_if_data.files;
2073 for ( size_t i = 0; i < files.size (); i++ )
2074 {
2075 File& file = *files[i];
2076 string extension = GetExtension ( file.name );
2077 if ( extension == ".spec" || extension == ".SPEC" )
2078 {
2079 GetSpecObjectDependencies ( dependencies, file.name );
2080 }
2081 if ( extension == ".idl" || extension == ".IDL" )
2082 {
2083 GetWidlObjectDependencies ( dependencies, file.name );
2084 }
2085 }
2086 }
2087
2088
2089 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
2090 : MingwModuleHandler ( module_ )
2091 {
2092 }
2093
2094 void
2095 MingwBuildToolModuleHandler::Process ()
2096 {
2097 GenerateBuildToolModuleTarget ();
2098 }
2099
2100 void
2101 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2102 {
2103 string targetMacro ( GetTargetMacro (module) );
2104 string objectsMacro = GetObjectsMacro ( module );
2105 string linkDepsMacro = GetLinkingDependenciesMacro ();
2106 string libsMacro = GetLibsMacro ();
2107
2108 GenerateRules ();
2109
2110 string linker;
2111 if ( module.cplusplus )
2112 linker = "${host_gpp}";
2113 else
2114 linker = "${host_gcc}";
2115
2116 fprintf ( fMakefile, "%s: %s %s | %s\n",
2117 targetMacro.c_str (),
2118 objectsMacro.c_str (),
2119 linkDepsMacro.c_str (),
2120 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2121 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2122 fprintf ( fMakefile,
2123 "\t%s %s -o $@ %s %s\n\n",
2124 linker.c_str (),
2125 GetLinkerMacro ().c_str (),
2126 objectsMacro.c_str (),
2127 libsMacro.c_str () );
2128 }
2129
2130
2131 MingwKernelModuleHandler::MingwKernelModuleHandler (
2132 const Module& module_ )
2133
2134 : MingwModuleHandler ( module_ )
2135 {
2136 }
2137
2138 void
2139 MingwKernelModuleHandler::Process ()
2140 {
2141 GenerateKernelModuleTarget ();
2142 }
2143
2144 void
2145 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2146 {
2147 string targetMacro ( GetTargetMacro ( module ) );
2148 string workingDirectory = GetWorkingDirectory ( );
2149 string objectsMacro = GetObjectsMacro ( module );
2150 string linkDepsMacro = GetLinkingDependenciesMacro ();
2151 string libsMacro = GetLibsMacro ();
2152
2153 GenerateImportLibraryTargetIfNeeded ();
2154
2155 if ( module.non_if_data.files.size () > 0 )
2156 {
2157 GenerateRules ();
2158
2159 string dependencies = linkDepsMacro + " " + objectsMacro;
2160
2161 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",
2162 module.GetBasePath ().c_str (),
2163 module.entrypoint.c_str (),
2164 module.baseaddress.c_str () );
2165 GenerateLinkerCommand ( dependencies,
2166 "${gcc}",
2167 linkerParameters,
2168 objectsMacro,
2169 libsMacro );
2170 }
2171 else
2172 {
2173 GeneratePhonyTarget();
2174 }
2175 }
2176
2177
2178 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2179 const Module& module_ )
2180
2181 : MingwModuleHandler ( module_ )
2182 {
2183 }
2184
2185 void
2186 MingwStaticLibraryModuleHandler::Process ()
2187 {
2188 GenerateStaticLibraryModuleTarget ();
2189 }
2190
2191 void
2192 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2193 {
2194 GenerateRules ();
2195 }
2196
2197
2198 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2199 const Module& module_ )
2200
2201 : MingwModuleHandler ( module_ )
2202 {
2203 }
2204
2205 void
2206 MingwObjectLibraryModuleHandler::Process ()
2207 {
2208 GenerateObjectLibraryModuleTarget ();
2209 }
2210
2211 void
2212 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2213 {
2214 GenerateRules ();
2215 }
2216
2217
2218 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2219 const Module& module_ )
2220
2221 : MingwModuleHandler ( module_ )
2222 {
2223 }
2224
2225 void
2226 MingwKernelModeDLLModuleHandler::Process ()
2227 {
2228 GenerateKernelModeDLLModuleTarget ();
2229 }
2230
2231 void
2232 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2233 {
2234 string targetMacro ( GetTargetMacro ( module ) );
2235 string workingDirectory = GetWorkingDirectory ( );
2236 string objectsMacro = GetObjectsMacro ( module );
2237 string linkDepsMacro = GetLinkingDependenciesMacro ();
2238 string libsMacro = GetLibsMacro ();
2239
2240 GenerateImportLibraryTargetIfNeeded ();
2241
2242 if ( module.non_if_data.files.size () > 0 )
2243 {
2244 GenerateRules ();
2245
2246 string dependencies = linkDepsMacro + " " + objectsMacro;
2247
2248 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2249 module.entrypoint.c_str (),
2250 module.baseaddress.c_str () );
2251 GenerateLinkerCommand ( dependencies,
2252 "${gcc}",
2253 linkerParameters,
2254 objectsMacro,
2255 libsMacro );
2256 }
2257 else
2258 {
2259 GeneratePhonyTarget();
2260 }
2261 }
2262
2263
2264 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2265 const Module& module_ )
2266
2267 : MingwModuleHandler ( module_ )
2268 {
2269 }
2270
2271 void
2272 MingwKernelModeDriverModuleHandler::Process ()
2273 {
2274 GenerateKernelModeDriverModuleTarget ();
2275 }
2276
2277
2278 void
2279 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2280 {
2281 string targetMacro ( GetTargetMacro (module) );
2282 string workingDirectory = GetWorkingDirectory ();
2283 string objectsMacro = GetObjectsMacro ( module );
2284 string linkDepsMacro = GetLinkingDependenciesMacro ();
2285 string libsMacro = GetLibsMacro ();
2286
2287 GenerateImportLibraryTargetIfNeeded ();
2288
2289 if ( module.non_if_data.files.size () > 0 )
2290 {
2291 GenerateRules ();
2292
2293 string dependencies = linkDepsMacro + " " + objectsMacro;
2294
2295 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2296 module.entrypoint.c_str (),
2297 module.baseaddress.c_str () );
2298 GenerateLinkerCommand ( dependencies,
2299 "${gcc}",
2300 linkerParameters,
2301 objectsMacro,
2302 libsMacro );
2303 }
2304 else
2305 {
2306 GeneratePhonyTarget();
2307 }
2308 }
2309
2310
2311 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2312 const Module& module_ )
2313
2314 : MingwModuleHandler ( module_ )
2315 {
2316 }
2317
2318 void
2319 MingwNativeDLLModuleHandler::Process ()
2320 {
2321 GenerateNativeDLLModuleTarget ();
2322 }
2323
2324 void
2325 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2326 {
2327 string targetMacro ( GetTargetMacro (module) );
2328 string workingDirectory = GetWorkingDirectory ( );
2329 string objectsMacro = GetObjectsMacro ( module );
2330 string linkDepsMacro = GetLinkingDependenciesMacro ();
2331 string libsMacro = GetLibsMacro ();
2332
2333 GenerateImportLibraryTargetIfNeeded ();
2334
2335 if ( module.non_if_data.files.size () > 0 )
2336 {
2337 GenerateRules ();
2338
2339 string dependencies = linkDepsMacro + " " + objectsMacro;
2340
2341 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2342 module.entrypoint.c_str (),
2343 module.baseaddress.c_str () );
2344 GenerateLinkerCommand ( dependencies,
2345 "${gcc}",
2346 linkerParameters,
2347 objectsMacro,
2348 libsMacro );
2349 }
2350 else
2351 {
2352 GeneratePhonyTarget();
2353 }
2354 }
2355
2356
2357 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2358 const Module& module_ )
2359
2360 : MingwModuleHandler ( module_ )
2361 {
2362 }
2363
2364 void
2365 MingwNativeCUIModuleHandler::Process ()
2366 {
2367 GenerateNativeCUIModuleTarget ();
2368 }
2369
2370 void
2371 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2372 {
2373 string targetMacro ( GetTargetMacro (module) );
2374 string workingDirectory = GetWorkingDirectory ( );
2375 string objectsMacro = GetObjectsMacro ( module );
2376 string linkDepsMacro = GetLinkingDependenciesMacro ();
2377 string libsMacro = GetLibsMacro ();
2378
2379 GenerateImportLibraryTargetIfNeeded ();
2380
2381 if ( module.non_if_data.files.size () > 0 )
2382 {
2383 GenerateRules ();
2384
2385 string dependencies = linkDepsMacro + " " + objectsMacro;
2386
2387 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2388 module.entrypoint.c_str (),
2389 module.baseaddress.c_str () );
2390 GenerateLinkerCommand ( dependencies,
2391 "${gcc}",
2392 linkerParameters,
2393 objectsMacro,
2394 libsMacro );
2395 }
2396 else
2397 {
2398 GeneratePhonyTarget();
2399 }
2400 }
2401
2402
2403 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2404 const Module& module_ )
2405
2406 : MingwModuleHandler ( module_ )
2407 {
2408 }
2409
2410 void
2411 MingwWin32DLLModuleHandler::Process ()
2412 {
2413 GenerateWin32DLLModuleTarget ();
2414 }
2415
2416 void
2417 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2418 {
2419 string targetMacro ( GetTargetMacro (module) );
2420 string workingDirectory = GetWorkingDirectory ( );
2421 string objectsMacro = GetObjectsMacro ( module );
2422 string linkDepsMacro = GetLinkingDependenciesMacro ();
2423 string libsMacro = GetLibsMacro ();
2424
2425 GenerateImportLibraryTargetIfNeeded ();
2426
2427 if ( module.non_if_data.files.size () > 0 )
2428 {
2429 GenerateRules ();
2430
2431 string dependencies = linkDepsMacro + " " + objectsMacro;
2432
2433 string linker;
2434 if ( module.cplusplus )
2435 linker = "${gpp}";
2436 else
2437 linker = "${gcc}";
2438
2439 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2440 module.entrypoint.c_str (),
2441 module.baseaddress.c_str () );
2442 GenerateLinkerCommand ( dependencies,
2443 linker,
2444 linkerParameters,
2445 objectsMacro,
2446 libsMacro );
2447 }
2448 else
2449 {
2450 GeneratePhonyTarget();
2451 }
2452 }
2453
2454
2455 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2456 const Module& module_ )
2457
2458 : MingwModuleHandler ( module_ )
2459 {
2460 }
2461
2462 void
2463 MingwWin32CUIModuleHandler::Process ()
2464 {
2465 GenerateWin32CUIModuleTarget ();
2466 }
2467
2468 void
2469 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2470 {
2471 string targetMacro ( GetTargetMacro (module) );
2472 string workingDirectory = GetWorkingDirectory ( );
2473 string objectsMacro = GetObjectsMacro ( module );
2474 string linkDepsMacro = GetLinkingDependenciesMacro ();
2475 string libsMacro = GetLibsMacro ();
2476
2477 GenerateImportLibraryTargetIfNeeded ();
2478
2479 if ( module.non_if_data.files.size () > 0 )
2480 {
2481 GenerateRules ();
2482
2483 string dependencies = linkDepsMacro + " " + objectsMacro;
2484
2485 string linker;
2486 if ( module.cplusplus )
2487 linker = "${gpp}";
2488 else
2489 linker = "${gcc}";
2490
2491 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2492 module.entrypoint.c_str (),
2493 module.baseaddress.c_str () );
2494 GenerateLinkerCommand ( dependencies,
2495 linker,
2496 linkerParameters,
2497 objectsMacro,
2498 libsMacro );
2499 }
2500 else
2501 {
2502 GeneratePhonyTarget();
2503 }
2504 }
2505
2506
2507 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2508 const Module& module_ )
2509
2510 : MingwModuleHandler ( module_ )
2511 {
2512 }
2513
2514 void
2515 MingwWin32GUIModuleHandler::Process ()
2516 {
2517 GenerateWin32GUIModuleTarget ();
2518 }
2519
2520 void
2521 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2522 {
2523 string targetMacro ( GetTargetMacro (module) );
2524 string workingDirectory = GetWorkingDirectory ( );
2525 string objectsMacro = GetObjectsMacro ( module );
2526 string linkDepsMacro = GetLinkingDependenciesMacro ();
2527 string libsMacro = GetLibsMacro ();
2528
2529 GenerateImportLibraryTargetIfNeeded ();
2530
2531 if ( module.non_if_data.files.size () > 0 )
2532 {
2533 GenerateRules ();
2534
2535 string dependencies = linkDepsMacro + " " + objectsMacro;
2536
2537 string linker;
2538 if ( module.cplusplus )
2539 linker = "${gpp}";
2540 else
2541 linker = "${gcc}";
2542
2543 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2544 module.entrypoint.c_str (),
2545 module.baseaddress.c_str () );
2546 GenerateLinkerCommand ( dependencies,
2547 linker,
2548 linkerParameters,
2549 objectsMacro,
2550 libsMacro );
2551 }
2552 else
2553 {
2554 GeneratePhonyTarget();
2555 }
2556 }
2557
2558
2559 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2560 const Module& module_ )
2561
2562 : MingwModuleHandler ( module_ )
2563 {
2564 }
2565
2566 void
2567 MingwBootLoaderModuleHandler::Process ()
2568 {
2569 GenerateBootLoaderModuleTarget ();
2570 }
2571
2572 void
2573 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2574 {
2575 string targetName ( module.GetTargetName () );
2576 string targetMacro ( GetTargetMacro (module) );
2577 string workingDirectory = GetWorkingDirectory ();
2578 string junk_tmp = ros_temp + module.name + ".junk.tmp";
2579 CLEAN_FILE ( junk_tmp );
2580 string objectsMacro = GetObjectsMacro ( module );
2581 string linkDepsMacro = GetLinkingDependenciesMacro ();
2582 string libsMacro = GetLibsMacro ();
2583
2584 GenerateRules ();
2585
2586 fprintf ( fMakefile, "%s: %s %s | %s\n",
2587 targetMacro.c_str (),
2588 objectsMacro.c_str (),
2589 linkDepsMacro.c_str (),
2590 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2591
2592 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2593
2594 fprintf ( fMakefile,
2595 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2596 GetLinkerMacro ().c_str (),
2597 junk_tmp.c_str (),
2598 objectsMacro.c_str (),
2599 linkDepsMacro.c_str () );
2600 fprintf ( fMakefile,
2601 "\t${objcopy} -O binary %s $@\n",
2602 junk_tmp.c_str () );
2603 fprintf ( fMakefile,
2604 "\t-@${rm} %s 2>$(NUL)\n",
2605 junk_tmp.c_str () );
2606 }
2607
2608
2609 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2610 const Module& module_ )
2611
2612 : MingwModuleHandler ( module_ )
2613 {
2614 }
2615
2616 void
2617 MingwBootSectorModuleHandler::Process ()
2618 {
2619 GenerateBootSectorModuleTarget ();
2620 }
2621
2622 void
2623 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2624 {
2625 string objectsMacro = GetObjectsMacro ( module );
2626
2627 GenerateRules ();
2628
2629 fprintf ( fMakefile, ".PHONY: %s\n\n",
2630 module.name.c_str ());
2631 fprintf ( fMakefile,
2632 "%s: %s\n",
2633 module.name.c_str (),
2634 objectsMacro.c_str () );
2635 }
2636
2637
2638 MingwIsoModuleHandler::MingwIsoModuleHandler (
2639 const Module& module_ )
2640
2641 : MingwModuleHandler ( module_ )
2642 {
2643 }
2644
2645 void
2646 MingwIsoModuleHandler::Process ()
2647 {
2648 GenerateIsoModuleTarget ();
2649 }
2650
2651 void
2652 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2653 const string& bootcdDirectory )
2654 {
2655 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2656 {
2657 const Module& m = *module.project.modules[i];
2658 if ( !m.enabled )
2659 continue;
2660 if ( m.bootstrap != NULL )
2661 {
2662 string sourceFilename = PassThruCacheDirectory (
2663 NormalizeFilename ( m.GetPath () ),
2664 backend->outputDirectory );
2665 string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
2666 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2667 NormalizeFilename ( targetFilenameNoFixup ),
2668 backend->outputDirectory );
2669 fprintf ( fMakefile,
2670 "\t$(ECHO_CP)\n" );
2671 fprintf ( fMakefile,
2672 "\t${cp} %s %s 1>$(NUL)\n",
2673 sourceFilename.c_str (),
2674 targetFilename.c_str () );
2675 }
2676 }
2677 }
2678
2679 void
2680 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2681 const string& bootcdDirectory )
2682 {
2683 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2684 {
2685 const CDFile& cdfile = *module.project.cdfiles[i];
2686 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2687 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2688 NormalizeFilename ( targetFilenameNoFixup ),
2689 backend->outputDirectory );
2690 fprintf ( fMakefile,
2691 "\t$(ECHO_CP)\n" );
2692 fprintf ( fMakefile,
2693 "\t${cp} %s %s 1>$(NUL)\n",
2694 cdfile.GetPath ().c_str (),
2695 targetFilename.c_str () );
2696 }
2697 }
2698
2699 string
2700 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
2701 {
2702 string directories;
2703 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2704 {
2705 const Module& m = *module.project.modules[i];
2706 if ( !m.enabled )
2707 continue;
2708 if ( m.bootstrap != NULL )
2709 {
2710 string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
2711 if ( directories.size () > 0 )
2712 directories += " ";
2713 directories += PassThruCacheDirectory (
2714 NormalizeFilename ( targetDirectory ),
2715 backend->outputDirectory );
2716 }
2717 }
2718 return directories;
2719 }
2720
2721 string
2722 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
2723 {
2724 string directories;
2725 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2726 {
2727 const CDFile& cdfile = *module.project.cdfiles[i];
2728 string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
2729 if ( directories.size () > 0 )
2730 directories += " ";
2731 directories += PassThruCacheDirectory (
2732 NormalizeFilename ( targetDirectory ),
2733 backend->outputDirectory );
2734 }
2735 return directories;
2736 }
2737
2738 string
2739 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
2740 {
2741 string directories = GetBootstrapCdDirectories ( bootcdDirectory );
2742 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
2743 return directories;
2744 }
2745
2746 void
2747 MingwIsoModuleHandler::GetBootstrapCdFiles (
2748 vector<string>& out ) const
2749 {
2750 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2751 {
2752 const Module& m = *module.project.modules[i];
2753 if ( !m.enabled )
2754 continue;
2755 if ( m.bootstrap != NULL )
2756 {
2757 string filename = PassThruCacheDirectory (
2758 NormalizeFilename ( m.GetPath () ),
2759 backend->outputDirectory );
2760 out.push_back ( filename );
2761 }
2762 }
2763 }
2764
2765 void
2766 MingwIsoModuleHandler::GetNonModuleCdFiles (
2767 vector<string>& out ) const
2768 {
2769 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2770 {
2771 const CDFile& cdfile = *module.project.cdfiles[i];
2772 out.push_back ( cdfile.GetPath () );
2773 }
2774 }
2775
2776 void
2777 MingwIsoModuleHandler::GetCdFiles (
2778 vector<string>& out ) const
2779 {
2780 GetBootstrapCdFiles ( out );
2781 GetNonModuleCdFiles ( out );
2782 }
2783
2784 void
2785 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2786 {
2787 string bootcdDirectory = "cd";
2788 string bootcd = PassThruCacheDirectory (
2789 NormalizeFilename ( bootcdDirectory + SSEP ),
2790 backend->outputDirectory );
2791 string isoboot = PassThruCacheDirectory (
2792 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2793 backend->outputDirectory );
2794 string bootcdReactosNoFixup = bootcdDirectory + SSEP "reactos";
2795 string bootcdReactos = PassThruCacheDirectory (
2796 NormalizeFilename ( bootcdReactosNoFixup + SSEP ),
2797 backend->outputDirectory );
2798 CLEAN_FILE ( bootcdReactos );
2799 string reactosInf = PassThruCacheDirectory (
2800 NormalizeFilename ( bootcdReactosNoFixup + SSEP "reactos.inf" ),
2801 backend->outputDirectory );
2802 string reactosDff = NormalizeFilename ( "bootdata" SSEP "packages" SSEP "reactos.dff" );
2803 string cdDirectories = GetCdDirectories ( bootcdDirectory );
2804 vector<string> vCdFiles;
2805 GetCdFiles ( vCdFiles );
2806 string cdFiles = v2s ( vCdFiles, 5 );
2807
2808 fprintf ( fMakefile, ".PHONY: %s\n\n",
2809 module.name.c_str ());
2810 fprintf ( fMakefile,
2811 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2812 module.name.c_str (),
2813 isoboot.c_str (),
2814 bootcdReactos.c_str (),
2815 cdDirectories.c_str (),
2816 cdFiles.c_str () );
2817 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2818 fprintf ( fMakefile,
2819 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2820 reactosDff.c_str (),
2821 bootcdReactos.c_str () );
2822 fprintf ( fMakefile,
2823 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2824 reactosDff.c_str (),
2825 reactosInf.c_str (),
2826 bootcdReactos.c_str ());
2827 fprintf ( fMakefile,
2828 "\t-@${rm} %s 2>$(NUL)\n",
2829 reactosInf.c_str () );
2830 OutputBootstrapfileCopyCommands ( bootcdDirectory );
2831 OutputCdfileCopyCommands ( bootcdDirectory );
2832 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2833 fprintf ( fMakefile,
2834 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2835 isoboot.c_str (),
2836 bootcd.c_str () );
2837 fprintf ( fMakefile,
2838 "\n" );
2839 }
2840
2841
2842 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2843 const Module& module_ )
2844
2845 : MingwModuleHandler ( module_ )
2846 {
2847 }
2848
2849 void
2850 MingwLiveIsoModuleHandler::Process ()
2851 {
2852 GenerateLiveIsoModuleTarget ();
2853 }
2854
2855 void
2856 MingwLiveIsoModuleHandler::CreateDirectory ( const string& directory )
2857 {
2858 string normalizedDirectory = MingwModuleHandler::PassThruCacheDirectory (
2859 NormalizeFilename ( directory ) + SSEP,
2860 backend->outputDirectory );
2861 }
2862
2863 void
2864 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string& sourceFilename,
2865 const string& targetFilename,
2866 const string& targetDirectory )
2867 {
2868 string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
2869 NormalizeFilename ( targetDirectory + SSEP + targetFilename ),
2870 backend->outputDirectory );
2871 fprintf ( fMakefile,
2872 "\t$(ECHO_CP)\n" );
2873 fprintf ( fMakefile,
2874 "\t${cp} %s %s 1>$(NUL)\n",
2875 sourceFilename.c_str (),
2876 normalizedTargetFilename.c_str () );
2877 }
2878
2879 void
2880 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string& livecdDirectory,
2881 string& reactosDirectory )
2882 {
2883 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2884 {
2885 const Module& m = *module.project.modules[i];
2886 if ( !m.enabled )
2887 continue;
2888 if ( m.installName.length () > 0 )
2889 {
2890 const Module& aliasedModule = backend->GetAliasedModuleOrModule ( m );
2891 string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
2892 NormalizeFilename ( aliasedModule.GetPath () ),
2893 backend->outputDirectory );
2894 OutputCopyCommand ( sourceFilename,
2895 m.installName,
2896 livecdDirectory + SSEP + reactosDirectory + SSEP + m.installBase );
2897 }
2898 }
2899 }
2900
2901 void
2902 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string& livecdDirectory,
2903 string& reactosDirectory )
2904 {
2905 for ( size_t i = 0; i < module.project.installfiles.size (); i++ )
2906 {
2907 const InstallFile& installfile = *module.project.installfiles[i];
2908 OutputCopyCommand ( installfile.GetPath (),
2909 installfile.newname,
2910 livecdDirectory + SSEP + reactosDirectory + SSEP + installfile.base );
2911 }
2912 }
2913
2914 void
2915 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string& livecdDirectory )
2916 {
2917 CreateDirectory ( livecdDirectory + SSEP "Profiles" );
2918 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users") ;
2919 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users" SSEP "Desktop" );
2920 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" );
2921 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "Desktop" );
2922 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "My Documents" );
2923
2924 string livecdIni = "bootdata" SSEP "livecd.ini";
2925 OutputCopyCommand ( livecdIni,
2926 "freeldr.ini",
2927 livecdDirectory );
2928 }
2929
2930 void
2931 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string& livecdDirectory )
2932 {
2933 string freeldr = PassThruCacheDirectory (
2934 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "freeldr" SSEP "freeldr.sys" ),
2935 backend->outputDirectory );
2936 CreateDirectory ( livecdDirectory + SSEP "loader" );
2937 OutputCopyCommand ( freeldr,
2938 "setupldr.sys",
2939 livecdDirectory + SSEP + "loader" );
2940 }
2941
2942 void
2943 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string& livecdDirectory )
2944 {
2945 string reactosSystem32ConfigDirectory =