f20601376f7e557c7146d241b477fac1650be8b1
[reactos.git] / reactos / tools / rbuild / backend / mingw / mingw.cpp
1
2 #include "../../pch.h"
3
4 #include "mingw.h"
5
6 using std::string;
7 using std::vector;
8
9 static class MingwFactory : public Backend::Factory
10 {
11 public:
12 MingwFactory() : Factory ( "mingw" ) {}
13 Backend* operator() ( Project& project )
14 {
15 return new MingwBackend ( project );
16 }
17 } factory;
18
19
20 MingwBackend::MingwBackend ( Project& project )
21 : Backend ( project )
22 {
23 }
24
25 void
26 MingwBackend::Process ()
27 {
28 CreateMakefile ();
29 GenerateHeader ();
30 GenerateGlobalVariables ();
31 GenerateAllTarget ();
32 for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
33 {
34 Module& module = *ProjectNode.modules[i];
35 ProcessModule ( module );
36 }
37 CloseMakefile ();
38 }
39
40 void
41 MingwBackend::CreateMakefile ()
42 {
43 fMakefile = fopen ( ProjectNode.makefile.c_str (), "w" );
44 if ( !fMakefile )
45 throw AccessDeniedException ( ProjectNode.makefile );
46 }
47
48 void
49 MingwBackend::CloseMakefile ()
50 {
51 if (fMakefile)
52 fclose ( fMakefile );
53 }
54
55 void
56 MingwBackend::GenerateHeader ()
57 {
58 fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
59 }
60
61 void
62 MingwBackend::GenerateGlobalVariables ()
63 {
64 fprintf ( fMakefile, "rm = del /y\n" );
65 fprintf ( fMakefile, "gcc = gcc\n" );
66 fprintf ( fMakefile, "ld = ld\n" );
67 fprintf ( fMakefile, "ar = ar\n" );
68 fprintf ( fMakefile, "dlltool = dlltool\n" );
69 fprintf ( fMakefile, "\n" );
70 }
71
72 void
73 MingwBackend::GenerateAllTarget ()
74 {
75 fprintf ( fMakefile, "all:" );
76 for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
77 {
78 Module& module = *ProjectNode.modules[i];
79 fprintf ( fMakefile,
80 " %s",
81 module.GetPath ().c_str () );
82 }
83 fprintf ( fMakefile, "\n\t\n\n" );
84 }
85
86 void
87 MingwBackend::ProcessModule ( Module& module )
88 {
89 MingwModuleHandlerList moduleHandlers;
90 GetModuleHandlers ( moduleHandlers );
91 for (size_t i = 0; i < moduleHandlers.size (); i++)
92 {
93 MingwModuleHandler& moduleHandler = *moduleHandlers[i];
94 if (moduleHandler.CanHandleModule ( module ) )
95 {
96 moduleHandler.Process ( module );
97 return;
98 }
99 }
100 }
101
102 void
103 MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers ) const
104 {
105 moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) );
106 moduleHandlers.push_back ( new MingwStaticLibraryModuleHandler ( fMakefile ) );
107 }