2 * Copyright (C) 2006 Christoph von Wittich
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.
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.
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.
19 #pragma warning ( disable : 4786 )
29 #include "codeblocks.h"
30 #include "../mingw/mingw.h"
41 static class CBFactory
: public Backend::Factory
45 CBFactory() : Factory("CB", "Code::Blocks") {}
46 Backend
*operator() (Project
&project
,
47 Configuration
& configuration
)
49 return new CBBackend(project
, configuration
);
55 CBBackend::CBBackend(Project
&project
,
56 Configuration
& configuration
) : Backend(project
, configuration
)
61 void CBBackend::Process()
64 while ( m_configurations
.size () > 0 )
66 const CBConfiguration
* cfg
= m_configurations
.back();
67 m_configurations
.pop_back();
71 m_configurations
.push_back ( new CBConfiguration( Debug
));
72 m_configurations
.push_back ( new CBConfiguration( Release
));
74 string
filename_wrkspace ( ProjectNode
.name
);
75 filename_wrkspace
+= "_auto.workspace";
77 printf ( "Creating Code::Blocks workspace: %s\n", filename_wrkspace
.c_str() );
80 m_wrkspaceFile
= fopen ( filename_wrkspace
.c_str(), "wb" );
82 if ( !m_wrkspaceFile
)
84 printf ( "Could not create file '%s'.\n", filename_wrkspace
.c_str() );
88 _generate_workspace ( m_wrkspaceFile
);
90 fclose ( m_wrkspaceFile
);
94 void CBBackend::ProcessModules()
96 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
98 Module
&module
= *ProjectNode
.modules
[i
];
99 MingwAddImplicitLibraries( module
);
100 _generate_cbproj ( module
);
104 static bool FileExists(string
&filename
)
106 ifstream
file(filename
.c_str());
115 void CBBackend::ProcessFile(string
&filepath
)
117 // Remove the .\ at the start of the filenames
118 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
119 filepath
.erase(0, 2);
121 if(!FileExists(filepath
))
125 for(size_t i
= 0; i
< filepath
.length(); i
++)
127 if(filepath
[i
] == '\\')
131 // Remove the filename from the path
134 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
136 if(pos
!= string::npos
)
139 folder
.erase(pos
, folder
.length() - pos
);
143 fileUnit
.filename
= filepath
;
144 fileUnit
.folder
= folder
;
146 m_fileUnits
.push_back(fileUnit
);
154 bool CBBackend::CheckFolderAdded(string
&folder
)
156 for(size_t i
= 0; i
< m_folders
.size(); i
++)
158 if(m_folders
[i
] == folder
)
165 void CBBackend::AddFolders(string
&folder
)
167 // Check if this folder was already added. true if it was, false otherwise.
168 if(CheckFolderAdded(folder
))
171 m_folders
.push_back(folder
);
173 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
175 if(pos
== string::npos
)
178 folder
.erase(pos
, folder
.length() - pos
);
182 void CBBackend::OutputFolders()
185 m_devFile
<< "Folders=";
187 for(size_t i
= 0; i
< m_folders
.size(); i
++)
192 m_devFile
<< m_folders
[i
];
198 CBBackend::CbpFileName ( const Module
& module
) const
201 ReplaceExtension ( module
.GetPath(), + "_auto.cbp" )
206 CBBackend::LayoutFileName ( const Module
& module
) const
209 ReplaceExtension ( module
.GetPath(), + "_auto.layout" )
214 CBBackend::DependFileName ( const Module
& module
) const
217 ReplaceExtension ( module
.GetPath(), + "_auto.depend" )
222 CBBackend::_get_object_files ( const Module
& module
, vector
<string
>& out
) const
224 string basepath
= module
.GetBasePath ();
226 string intenv
= Environment::GetIntermediatePath () + "\\" + basepath
+ "\\";
227 string outenv
= Environment::GetOutputPath () + "\\" + basepath
+ "\\";
231 if ( configuration
.UseConfigurationInPath
)
233 cfgs
.push_back ( intenv
+ "Debug" );
234 cfgs
.push_back ( intenv
+ "Release" );
235 cfgs
.push_back ( outenv
+ "Debug" );
236 cfgs
.push_back ( outenv
+ "Release" );
240 cfgs
.push_back ( intenv
);
241 cfgs
.push_back ( outenv
);
244 vector
<const IfableData
*> ifs_list
;
245 ifs_list
.push_back ( &module
.project
.non_if_data
);
246 ifs_list
.push_back ( &module
.non_if_data
);
247 while ( ifs_list
.size () )
249 const IfableData
& data
= *ifs_list
.back();
251 const vector
<File
*>& files
= data
.files
;
252 for ( i
= 0; i
< files
.size (); i
++ )
254 string file
= files
[i
]->name
;
255 string::size_type pos
= file
.find_last_of ("\\");
256 if ( pos
!= string::npos
)
257 file
.erase ( 0, pos
+1 );
258 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
259 file
= ReplaceExtension ( file
, ".res" );
261 file
= ReplaceExtension ( file
, ".obj" );
262 for ( size_t j
= 0; j
< cfgs
.size () / 2; j
++ )
263 out
.push_back ( cfgs
[j
] + "\\" + file
);
270 CBBackend::_clean_project_files ( void )
272 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
274 Module
& module
= *ProjectNode
.modules
[i
];
276 printf("Cleaning project %s %s\n", module
.name
.c_str (), module
.GetBasePath ().c_str () );
278 string basepath
= module
.GetBasePath ();
279 remove ( CbpFileName ( module
).c_str () );
280 remove ( DependFileName ( module
).c_str () );
281 remove ( LayoutFileName ( module
).c_str () );
283 _get_object_files ( module
, out
);
284 for ( size_t j
= 0; j
< out
.size (); j
++)
286 //printf("Cleaning file %s\n", out[j].c_str () );
287 remove ( out
[j
].c_str () );
291 string filename_wrkspace
= ProjectNode
.name
+ ".workspace";
293 remove ( filename_wrkspace
.c_str () );
297 CBBackend::_generate_workspace ( FILE* OUT
)
299 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
300 fprintf ( OUT
, "<CodeBlocks_workspace_file>\r\n" );
301 fprintf ( OUT
, "\t<Workspace title=\"ReactOS\">\r\n" );
302 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
304 Module
& module
= *ProjectNode
.modules
[i
];
306 std::string Cbp_file
= CbpFileName ( module
);
307 fprintf ( OUT
, "\t\t<Project filename=\"%s\">\r\n", Cbp_file
.c_str());
310 vector
<const IfableData
*> ifs_list
;
311 ifs_list
.push_back ( &module
.project
.non_if_data
);
312 ifs_list
.push_back ( &module
.non_if_data
);
313 while ( ifs_list
.size() )
315 const IfableData
& data
= *ifs_list
.back();
317 const vector
<Library
*>& libs
= data
.libraries
;
318 for ( size_t j
= 0; j
< libs
.size(); j
++ )
319 fprintf ( OUT
, "\t\t\t<Depends filename=\"%s\\%s_auto.cbp\" />\r\n", libs
[j
]->importedModule
->GetBasePath().c_str(), libs
[j
]->name
.c_str() );
321 fprintf ( OUT
, "\t\t</Project>\r\n" );
324 fprintf ( OUT
, "\t</Workspace>\r\n" );
325 fprintf ( OUT
, "</CodeBlocks_workspace_file>\r\n" );
329 CBBackend::_generate_cbproj ( const Module
& module
)
334 string cbproj_file
= CbpFileName(module
);
337 string path_basedir
= module
.GetPathToBaseDir ();
338 string intenv
= Environment::GetIntermediatePath ();
339 string outenv
= Environment::GetOutputPath ();
340 string module_type
= GetExtension(module
.GetTargetName());
341 string cbproj_path
= module
.GetBasePath();
344 string project_linker_flags
= "-Wl,--enable-stdcall-fixup ";
345 project_linker_flags
+= GenerateProjectLinkerFlags();
347 bool lib
= (module
.type
== ObjectLibrary
) || (module
.type
== RpcClient
) ||(module
.type
== RpcServer
) || (module_type
== ".lib") || (module_type
== ".a");
348 bool dll
= (module_type
== ".dll") || (module_type
== ".cpl");
349 bool exe
= (module_type
== ".exe") || (module_type
== ".scr");
350 bool sys
= (module_type
== ".sys");
352 vector
<string
> source_files
, resource_files
, includes
, libraries
, libpaths
;
353 vector
<string
> header_files
, common_defines
, compiler_flags
;
354 vector
<string
> vars
, values
;
356 compiler_flags
.push_back ( "-Wall" );
358 // Always force disabling of sibling calls optimisation for GCC
359 // (TODO: Move to version-specific once this bug is fixed in GCC)
360 compiler_flags
.push_back ( "-fno-optimize-sibling-calls" );
362 if ( module
.pch
!= NULL
)
364 string pch_path
= Path::RelativeFromDirectory (
365 module
.pch
->file
.name
,
366 module
.GetBasePath() );
368 header_files
.push_back ( pch_path
);
371 if ( intenv
== "obj-i386" )
372 intdir
= path_basedir
+ "obj-i386"; /* append relative dir from project dir */
376 if ( outenv
== "output-i386" )
377 outdir
= path_basedir
+ "output-i386";
381 vector
<const IfableData
*> ifs_list
;
382 ifs_list
.push_back ( &module
.project
.non_if_data
);
383 ifs_list
.push_back ( &module
.non_if_data
);
384 while ( ifs_list
.size() )
386 const IfableData
& data
= *ifs_list
.back();
388 const vector
<File
*>& files
= data
.files
;
389 for ( i
= 0; i
< files
.size(); i
++ )
391 string file
= string(".") + &files
[i
]->name
[cbproj_path
.size()];
393 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
394 resource_files
.push_back ( file
);
396 source_files
.push_back ( file
);
398 const vector
<Include
*>& incs
= data
.includes
;
399 for ( i
= 0; i
< incs
.size(); i
++ )
401 string path
= Path::RelativeFromDirectory (
403 module
.GetBasePath() );
405 includes
.push_back ( path
);
407 const vector
<Library
*>& libs
= data
.libraries
;
408 for ( i
= 0; i
< libs
.size(); i
++ )
410 string libpath
= outdir
+ "\\" + libs
[i
]->importedModule
->GetBasePath() + "\\" + libs
[i
]->name
;
411 libraries
.push_back ( libs
[i
]->name
);
412 libpaths
.push_back ( libpath
);
414 const vector
<CompilerFlag
*>& cflags
= data
.compilerFlags
;
415 for ( i
= 0; i
< cflags
.size(); i
++ )
417 compiler_flags
.push_back ( cflags
[i
]->flag
);
419 const vector
<Define
*>& defs
= data
.defines
;
420 for ( i
= 0; i
< defs
.size(); i
++ )
422 if ( defs
[i
]->value
[0] )
424 const string
& escaped
= _replace_str(defs
[i
]->value
, "\"",""");
425 common_defines
.push_back( defs
[i
]->name
+ "=" + escaped
);
429 common_defines
.push_back( defs
[i
]->name
);
432 /*const vector<Property*>& variables = data.properties;
433 for ( i = 0; i < variables.size(); i++ )
435 vars.push_back( variables[i]->name );
436 values.push_back( variables[i]->value );
438 for ( i
= 0; i
< data
.properties
.size(); i
++ )
440 Property
& prop
= *data
.properties
[i
];
441 if ( strstr ( module
.baseaddress
.c_str(), prop
.name
.c_str() ) )
442 baseaddr
= prop
.value
;
446 if ( !module
.allowWarnings
)
447 compiler_flags
.push_back ( "-Werror" );
449 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
450 compiler_flags
.push_back ( "-Wno-main" );
453 FILE* OUT
= fopen ( cbproj_file
.c_str(), "wb" );
455 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
456 fprintf ( OUT
, "<CodeBlocks_project_file>\r\n" );
457 fprintf ( OUT
, "\t<FileVersion major=\"1\" minor=\"5\" />\r\n" );
458 fprintf ( OUT
, "\t<Project>\r\n" );
459 fprintf ( OUT
, "\t\t<Option title=\"%s\" />\r\n", module
.name
.c_str() );
460 fprintf ( OUT
, "\t\t<Option pch_mode=\"2\" />\r\n" );
461 fprintf ( OUT
, "\t\t<Option default_target=\"\" />\r\n" );
462 fprintf ( OUT
, "\t\t<Option compiler=\"gcc\" />\r\n" );
463 fprintf ( OUT
, "\t\t<Option virtualFolders=\"\" />\r\n" );
464 fprintf ( OUT
, "\t\t<Build>\r\n" );
466 bool console
= exe
&& (module
.type
== Win32CUI
);
468 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
470 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
471 fprintf ( OUT
, "\t\t\t<Target title=\"%s\">\r\n", cfg
.name
.c_str() );
473 if ( configuration
.UseConfigurationInPath
)
475 fprintf ( OUT
, "\t\t\t\t<Option output=\"%s\\%s%s\\%s%s\" prefix_auto=\"0\" extension_auto=\"0\" />\r\n", outdir
.c_str (), module
.GetBasePath ().c_str (), cfg
.name
.c_str(), module
.name
.c_str(), module_type
.c_str());
476 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s%s\" />\r\n", intdir
.c_str(), module
.GetBasePath ().c_str (), cfg
.name
.c_str() );
480 fprintf ( OUT
, "\t\t\t\t<Option output=\"%s\\%s\\%s%s\" prefix_auto=\"0\" extension_auto=\"0\" />\r\n", outdir
.c_str (), module
.GetBasePath ().c_str (), module
.name
.c_str(), module_type
.c_str() );
481 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s\" />\r\n", intdir
.c_str(), module
.GetBasePath ().c_str () );
485 fprintf ( OUT
, "\t\t\t\t<Option type=\"2\" />\r\n" );
487 fprintf ( OUT
, "\t\t\t\t<Option type=\"3\" />\r\n" );
489 fprintf ( OUT
, "\t\t\t\t<Option type=\"4\" />\r\n" );
492 if ( module
.type
== Kernel
)
493 fprintf ( OUT
, "\t\t\t\t<Option type=\"4\" />\r\n" );
494 else if ( module
.type
== NativeCUI
)
495 fprintf ( OUT
, "\t\t\t\t<Option type=\"4\" />\r\n" );
496 else if ( module
.type
== Win32CUI
|| module
.type
== Win32GUI
|| module
.type
== Win32SCR
)
499 fprintf ( OUT
, "\t\t\t\t<Option type=\"1\" />\r\n" );
501 fprintf ( OUT
, "\t\t\t\t<Option type=\"0\" />\r\n" );
505 fprintf ( OUT
, "\t\t\t\t<Option compiler=\"gcc\" />\r\n" );
506 if ( module_type
== ".cpl" )
508 if ( configuration
.UseConfigurationInPath
)
509 fprintf ( OUT
, "\t\t\t\t<Option parameters=\"shell32,Control_RunDLL "%s\\%s%s\\%s%s",@\" />\r\n", outdir
.c_str (), module
.GetBasePath ().c_str (), cfg
.name
.c_str(), module
.name
.c_str(), module_type
.c_str() );
511 fprintf ( OUT
, "\t\t\t\t<Option parameters=\"shell32,Control_RunDLL "%s\\%s\\%s%s",@\" />\r\n", outdir
.c_str (), module
.GetBasePath ().c_str (), module
.name
.c_str(), module_type
.c_str() );
513 fprintf ( OUT
, "\t\t\t\t<Option host_application=\"rundll32.exe\" />\r\n" );
515 fprintf ( OUT
, "\t\t\t\t<Compiler>\r\n" );
517 bool debug
= ( cfg
.optimization
== Debug
);
520 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-g\" />\r\n" );
523 for ( i
= 0; i
< compiler_flags
.size(); i
++ )
525 const string
& cflag
= compiler_flags
[i
];
526 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", cflag
.c_str() );
530 for ( i
= 0; i
< common_defines
.size(); i
++ )
532 const string
& define
= common_defines
[i
];
533 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-D%s\" />\r\n", define
.c_str() );
536 for ( i
= 0; i
< includes
.size(); i
++ )
538 const string
& include
= includes
[i
];
539 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
541 fprintf ( OUT
, "\t\t\t\t</Compiler>\r\n" );
544 fprintf ( OUT
, "\t\t\t\t<ResourceCompiler>\r\n" );
545 for ( i
= 0; i
< includes
.size(); i
++ )
547 const string
& include
= includes
[i
];
548 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
550 fprintf ( OUT
, "\t\t\t\t</ResourceCompiler>\r\n" );
552 fprintf ( OUT
, "\t\t\t\t<Linker>\r\n" );
553 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", project_linker_flags
.c_str() );
557 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,%s%s\" />\r\n", "_", module
.GetEntryPoint(false) == "" ? "DriverEntry@8" : module
.GetEntryPoint(false).c_str ());
558 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x10000" : baseaddr
.c_str () );
559 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -nostdlib\" />\r\n" );
563 if ( module
.type
== Kernel
)
565 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_KiSystemStartup\" />\r\n" );
566 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
568 else if ( module
.type
== NativeCUI
)
570 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_NtProcessStartup@4\" />\r\n" );
571 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
572 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -nostdlib\" />\r\n" );
576 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc" );
581 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,%s%s\" />\r\n", "_", module
.GetEntryPoint(false).c_str () );
582 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x40000" : baseaddr
.c_str () );
583 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc" );
586 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--file-alignment,0x1000\" />\r\n" );
587 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--section-alignment,0x1000\" />\r\n" );
590 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s.temp.exp\" />\r\n", module
.name
.c_str() );
593 for ( i
= 0; i
< libraries
.size(); i
++ )
595 const string
& lib
= libraries
[i
];
596 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"%s\" />\r\n", lib
.c_str() );
598 for ( i
= 0; i
< libpaths
.size(); i
++ )
600 const string
& lib
= libpaths
[i
];
601 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", lib
.c_str() );
603 fprintf ( OUT
, "\t\t\t\t</Linker>\r\n" );
607 fprintf ( OUT
, "\t\t\t\t<ExtraCommands>\r\n" );
608 fprintf ( OUT
, "\t\t\t\t\t<Add before=\"dlltool --dllname %s%s --def %s --output-exp %s.temp.exp --kill-at\" />\r\n", module
.name
.c_str(), module_type
.c_str(), module
.importLibrary
->definition
.c_str(), module
.name
.c_str() );
610 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del %s.temp.exp 2>NUL\" />\r\n", module
.name
.c_str() );
612 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm %s.temp.exp 2>/dev/null\" />\r\n", module
.name
.c_str() );
614 fprintf ( OUT
, "\t\t\t\t\t<Mode after=\"always\" />\r\n" );
616 fprintf ( OUT
, "\t\t\t\t</ExtraCommands>\r\n" );
619 fprintf ( OUT
, "\t\t\t</Target>\r\n" );
624 fprintf ( OUT, "\t\t\t<Environment>\r\n" );
625 for ( i = 0; i < vars.size(); i++ )
627 const string& var = vars[i];
628 const string& value = values[i];
629 fprintf ( OUT, "\t\t\t\t<Variable name=\"%s\" value=\"%s\" />\r\n", var.c_str(), value.c_str() );
631 fprintf ( OUT, "\t\t\t</Environment>\r\n" ); */
633 fprintf ( OUT
, "\t\t</Build>\r\n" );
635 if ( module
.cplusplus
)
641 for ( i
= 0; i
< header_files
.size(); i
++ )
643 const string
& header_file
= header_files
[i
];
644 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", header_file
.c_str() );
645 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
646 fprintf ( OUT
, "\t\t\t<Option compile=\"0\" />\r\n" );
647 fprintf ( OUT
, "\t\t\t<Option link=\"0\" />\r\n" );
648 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
650 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
651 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
653 fprintf ( OUT
, "\t\t</Unit>\r\n" );
657 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
659 string source_file
= DosSeparator(source_files
[isrcfile
]);
660 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", source_file
.c_str() );
661 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
662 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
664 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
665 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
667 fprintf ( OUT
, "\t\t</Unit>\r\n" );
671 for ( i
= 0; i
< resource_files
.size(); i
++ )
673 const string
& resource_file
= resource_files
[i
];
674 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", resource_file
.c_str() );
675 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"WINDRES\" />\r\n" );
676 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
678 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
679 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
681 fprintf ( OUT
, "\t\t</Unit>\r\n" );
684 fprintf ( OUT
, "\t\t<Extensions />\r\n" );
685 fprintf ( OUT
, "\t</Project>\r\n" );
686 fprintf ( OUT
, "</CodeBlocks_project_file>\r\n" );
692 CBConfiguration::CBConfiguration ( const OptimizationType optimization
, const std::string
&name
)
694 this->optimization
= optimization
;
699 if ( optimization
== Debug
)
700 this->name
= "Debug";
701 else if ( optimization
== Release
)
702 this->name
= "Release";
704 this->name
= "Unknown";
709 CBBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
711 std::string::size_type pos
= string1
.find(find_str
, 0);
712 int intLen
= find_str
.length();
714 while(std::string::npos
!= pos
)
716 string1
.replace(pos
, intLen
, replace_str
);
717 pos
= string1
.find(find_str
, intLen
+ pos
);
724 CBBackend::GenerateProjectLinkerFlags() const
727 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
729 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
730 if ( lflags
.length () > 0 )
732 lflags
+= linkerFlag
.flag
;
738 CBBackend::MingwAddImplicitLibraries( Module
&module
)
742 if ( !module
.isDefaultEntryPoint
)
745 if ( module
.IsDLL () )
747 //pLibrary = new Library ( module, "__mingw_dllmain" );
748 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
752 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
753 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
756 pLibrary
= new Library ( module
, "mingw_common" );
757 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
759 if ( module
.name
!= "msvcrt" )
761 // always link in msvcrt to get the basic routines
762 pLibrary
= new Library ( module
, "msvcrt" );
763 module
.non_if_data
.libraries
.push_back ( pLibrary
);