Parse libraries.
[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 #ifdef WIN32
10 #define EXEPOSTFIX ".exe"
11 #define SEP "\\"
12 string FixSep ( const string& s )
13 {
14 string s2(s);
15 char* p = strchr ( &s2[0], '/' );
16 while ( p )
17 {
18 *p++ = '\\';
19 p = strchr ( p, '/' );
20 }
21 return s2;
22 }
23 #else
24 #define EXEPOSTFIX
25 #define SEP "/"
26 string FixSep ( const string& s )
27 {
28 string s2(s);
29 char* p = strchr ( &s2[0], '\\' );
30 while ( p )
31 {
32 *p++ = '/';
33 p = strchr ( p, '\\' );
34 }
35 return s2;
36 }
37 #endif
38
39 MingwBackend::MingwBackend ( Project& project )
40 : Backend ( project )
41 {
42 }
43
44 void MingwBackend::Process ()
45 {
46 CreateMakefile ();
47 GenerateHeader ();
48 GenerateAllTarget ();
49 for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
50 {
51 Module& module = *ProjectNode.modules[i];
52 ProcessModule ( module );
53 }
54 CloseMakefile ();
55 }
56
57 void MingwBackend::CreateMakefile ()
58 {
59 fMakefile = fopen ( ProjectNode.makefile.c_str (), "w" );
60 if ( !fMakefile )
61 throw AccessDeniedException ( ProjectNode.makefile );
62 }
63
64 void MingwBackend::CloseMakefile ()
65 {
66 if (fMakefile)
67 fclose ( fMakefile );
68 }
69
70 void MingwBackend::GenerateHeader ()
71 {
72 fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
73 }
74
75 void MingwBackend::GenerateAllTarget ()
76 {
77 fprintf ( fMakefile, "all: " );
78 for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
79 {
80 Module& module = *ProjectNode.modules[i];
81 fprintf ( fMakefile,
82 " %s" SEP "%s" EXEPOSTFIX,
83 FixSep(module.path).c_str (),
84 module.name.c_str () );
85 }
86 fprintf ( fMakefile, "\n\n" );
87 }
88
89 void MingwBackend::ProcessModule ( Module& module )
90 {
91 MingwModuleHandlerList moduleHandlers;
92 GetModuleHandlers ( moduleHandlers );
93 for (size_t i = 0; i < moduleHandlers.size (); i++)
94 {
95 MingwModuleHandler& moduleHandler = *moduleHandlers[i];
96 if (moduleHandler.CanHandleModule ( module ) )
97 {
98 moduleHandler.Process ( module );
99 return;
100 }
101 }
102 }
103
104 void MingwBackend::GetModuleHandlers ( MingwModuleHandlerList& moduleHandlers )
105 {
106 moduleHandlers.push_back ( new MingwKernelModuleHandler ( fMakefile ) );
107 }