* Nasm support
[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 MingwModuleHandler::SetMakefile ( fMakefile );
47 }
48
49 void
50 MingwBackend::CloseMakefile ()
51 {
52 if (fMakefile)
53 fclose ( fMakefile );
54 }
55
56 void
57 MingwBackend::GenerateHeader ()
58 {
59 fprintf ( fMakefile, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
60 }
61
62 void
63 MingwBackend::GenerateGlobalVariables ()
64 {
65 fprintf ( fMakefile, "host_gcc = gcc\n" );
66 fprintf ( fMakefile, "host_ar = ar\n" );
67 fprintf ( fMakefile, "host_ld = ld\n" );
68 fprintf ( fMakefile, "rm = del /f /q\n" );
69 fprintf ( fMakefile, "gcc = gcc\n" );
70 fprintf ( fMakefile, "ld = ld\n" );
71 fprintf ( fMakefile, "ar = ar\n" );
72 fprintf ( fMakefile, "dlltool = dlltool\n" );
73 fprintf ( fMakefile, "\n" );
74 }
75
76 void
77 MingwBackend::GenerateAllTarget ()
78 {
79 fprintf ( fMakefile, "all:" );
80 for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )
81 {
82 Module& module = *ProjectNode.modules[i];
83 fprintf ( fMakefile,
84 " %s",
85 FixupTargetFilename( module.GetPath () ).c_str () );
86 }
87 fprintf ( fMakefile, "\n\t\n\n" );
88 }
89
90 void
91 MingwBackend::ProcessModule ( Module& module )
92 {
93 MingwModuleHandler* h = MingwModuleHandler::LookupHandler (
94 module.node.location,
95 module.type );
96 h->Process ( module );
97 }
98
99 string
100 FixupTargetFilename ( const string& targetFilename )
101 {
102 return string("$(ROS_INTERMEDIATE)") + targetFilename;
103 }