9780ebeb327073a677f202855e73ce3f2f4816a0
10 static class MingwFactory
: public Backend::Factory
13 MingwFactory() : Factory ( "mingw" ) {}
14 Backend
* operator() ( Project
& project
)
16 return new MingwBackend ( project
);
21 MingwBackend::MingwBackend ( Project
& project
)
27 MingwBackend::Process ()
33 GenerateGlobalVariables ();
35 GenerateInitTarget ();
36 GenerateXmlBuildFilesMacro();
37 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
39 Module
& module
= *ProjectNode
.modules
[i
];
40 ProcessModule ( module
);
42 CheckAutomaticDependencies ();
47 MingwBackend::CreateMakefile ()
49 fMakefile
= fopen ( ProjectNode
.makefile
.c_str (), "w" );
51 throw AccessDeniedException ( ProjectNode
.makefile
);
52 MingwModuleHandler::SetMakefile ( fMakefile
);
56 MingwBackend::CloseMakefile () const
63 MingwBackend::GenerateHeader () const
65 fprintf ( fMakefile
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
69 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
70 const vector
<Include
*>& includes
,
71 const vector
<Define
*>& defines
) const
78 assignmentOperation
);
79 for ( i
= 0; i
< includes
.size(); i
++ )
84 includes
[i
]->directory
.c_str() );
87 for ( i
= 0; i
< defines
.size(); i
++ )
89 Define
& d
= *defines
[i
];
100 fprintf ( fMakefile
, "\n" );
104 MingwBackend::GenerateGlobalCFlagsAndProperties (
105 const char* assignmentOperation
,
106 const vector
<Property
*>& properties
,
107 const vector
<Include
*>& includes
,
108 const vector
<Define
*>& defines
,
109 const vector
<If
*>& ifs
) const
113 for ( i
= 0; i
< properties
.size(); i
++ )
115 Property
& prop
= *properties
[i
];
116 fprintf ( fMakefile
, "%s := %s\n",
118 prop
.value
.c_str() );
121 if ( includes
.size() || defines
.size() )
123 GenerateProjectCFlagsMacro ( assignmentOperation
,
128 for ( i
= 0; i
< ifs
.size(); i
++ )
131 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.ifs
.size() )
135 "ifeq (\"$(%s)\",\"%s\")\n",
136 rIf
.property
.c_str(),
138 GenerateGlobalCFlagsAndProperties (
152 MingwBackend::GenerateProjectLFLAGS () const
155 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
157 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
158 if ( lflags
.length () > 0 )
160 lflags
+= linkerFlag
.flag
;
166 MingwBackend::GenerateGlobalVariables () const
168 fprintf ( fMakefile
, "mkdir = $(Q)tools" SSEP
"rmkdir" EXEPOSTFIX
"\n" );
169 fprintf ( fMakefile
, "winebuild = $(Q)tools" SSEP
"winebuild" SSEP
"winebuild" EXEPOSTFIX
"\n" );
170 fprintf ( fMakefile
, "bin2res = $(Q)tools" SSEP
"bin2res" SSEP
"bin2res" EXEPOSTFIX
"\n" );
171 fprintf ( fMakefile
, "cabman = $(Q)tools" SSEP
"cabman" SSEP
"cabman" EXEPOSTFIX
"\n" );
172 fprintf ( fMakefile
, "cdmake = $(Q)tools" SSEP
"cdmake" SSEP
"cdmake" EXEPOSTFIX
"\n" );
173 fprintf ( fMakefile
, "rsym = $(Q)tools" SSEP
"rsym" EXEPOSTFIX
"\n" );
174 fprintf ( fMakefile
, "wrc = $(Q)tools" SSEP
"wrc" SSEP
"wrc" EXEPOSTFIX
"\n" );
175 fprintf ( fMakefile
, "\n" );
176 GenerateGlobalCFlagsAndProperties (
178 ProjectNode
.properties
,
179 ProjectNode
.includes
,
182 fprintf ( fMakefile
, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );
183 fprintf ( fMakefile
, "PROJECT_LFLAGS = %s\n",
184 GenerateProjectLFLAGS ().c_str () );
185 fprintf ( fMakefile
, "\n" );
189 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
191 if ( module
.type
== ObjectLibrary
)
193 if ( module
.type
== BootSector
)
195 if ( module
.type
== Iso
)
201 MingwBackend::GenerateAllTarget () const
203 fprintf ( fMakefile
, "all:" );
205 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
207 Module
& module
= *ProjectNode
.modules
[i
];
208 if ( IncludeInAllTarget ( module
) )
210 if ( wrap_count
++ == 5 )
211 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
214 FixupTargetFilename ( module
.GetPath () ).c_str () );
217 fprintf ( fMakefile
, "\n\t\n\n" );
221 MingwBackend::GetBuildToolDependencies () const
224 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
226 Module
& module
= *ProjectNode
.modules
[i
];
227 if ( module
.type
== BuildTool
)
229 if ( dependencies
.length () > 0 )
231 dependencies
+= module
.GetDependencyPath ();
238 MingwBackend::GenerateInitTarget () const
243 " $(ROS_INTERMEDIATE)." SSEP
"tools" );
246 GetBuildToolDependencies ().c_str () );
249 "include" SSEP
"reactos" SSEP
"buildno.h" );
254 "$(ROS_INTERMEDIATE)." SSEP
"tools:\n" );
256 "ifneq ($(ROS_INTERMEDIATE),)\n" );
258 "\t${nmkdir} $(ROS_INTERMEDIATE)\n" );
262 "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP
"tools\n" );
268 MingwBackend::GenerateXmlBuildFilesMacro() const
271 "XMLBUILDFILES = %s \\\n",
272 ProjectNode
.GetProjectFilename ().c_str () );
273 string xmlbuildFilenames
;
274 int numberOfExistingFiles
= 0;
275 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
277 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
278 if ( !xmlbuildfile
.fileExists
)
280 numberOfExistingFiles
++;
281 if ( xmlbuildFilenames
.length () > 0 )
282 xmlbuildFilenames
+= " ";
283 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
284 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
288 xmlbuildFilenames
.c_str ());
289 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
298 xmlbuildFilenames
.c_str () );
300 xmlbuildFilenames
.resize ( 0 );
302 numberOfExistingFiles
++;
309 MingwBackend::CheckAutomaticDependencies ()
311 AutomaticDependency
automaticDependency ( ProjectNode
);
312 automaticDependency
.Process ();
313 automaticDependency
.CheckAutomaticDependencies ();
317 MingwBackend::ProcessModule ( Module
& module
) const
319 MingwModuleHandler
* h
= MingwModuleHandler::LookupHandler (
320 module
.node
.location
,
322 MingwModuleHandler::string_list clean_files
;
323 h
->Process ( module
, clean_files
);
324 h
->GenerateCleanTarget ( module
, clean_files
);
325 h
->GenerateDirectoryTargets ();
329 FixupTargetFilename ( const string
& targetFilename
)
331 return string("$(ROS_INTERMEDIATE)") + NormalizeFilename ( targetFilename
);
335 MingwBackend::DetectPCHSupport()
337 string path
= "tools" SSEP
"rbuild" SSEP
"backend" SSEP
"mingw" SSEP
"pch_detection.h";
338 system ( ssprintf("gcc -c %s", path
.c_str()).c_str() );
341 FILE* f
= fopen ( path
.c_str(), "rb" );
346 unlink ( path
.c_str() );
351 // TODO FIXME - eventually check for ROS_USE_PCH env var and
352 // allow that to override use_pch if true