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 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
390 const Property
* property
= _lookup_property( module
, data
.ifs
[i
]->property
);
391 if ( property
!= NULL
)
393 if ( data
.ifs
[i
]->value
== property
->value
&& data
.ifs
[i
]->negated
== false ||
394 data
.ifs
[i
]->value
!= property
->value
&& data
.ifs
[i
]->negated
)
395 ifs_list
.push_back ( &data
.ifs
[i
]->data
);
398 const vector
<File
*>& files
= data
.files
;
399 for ( i
= 0; i
< files
.size(); i
++ )
401 string file
= string(".") + &files
[i
]->name
[cbproj_path
.size()];
403 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
404 resource_files
.push_back ( file
);
406 source_files
.push_back ( file
);
408 const vector
<Include
*>& incs
= data
.includes
;
409 for ( i
= 0; i
< incs
.size(); i
++ )
411 string path
= Path::RelativeFromDirectory (
413 module
.GetBasePath() );
415 includes
.push_back ( path
);
417 const vector
<Library
*>& libs
= data
.libraries
;
418 for ( i
= 0; i
< libs
.size(); i
++ )
420 string libpath
= outdir
+ "\\" + libs
[i
]->importedModule
->GetBasePath();
421 libraries
.push_back ( libs
[i
]->name
);
422 libpaths
.push_back ( libpath
);
424 const vector
<CompilerFlag
*>& cflags
= data
.compilerFlags
;
425 for ( i
= 0; i
< cflags
.size(); i
++ )
427 compiler_flags
.push_back ( cflags
[i
]->flag
);
429 const vector
<Define
*>& defs
= data
.defines
;
430 for ( i
= 0; i
< defs
.size(); i
++ )
432 if ( defs
[i
]->value
[0] )
434 const string
& escaped
= _replace_str(defs
[i
]->value
, "\"",""");
435 common_defines
.push_back( defs
[i
]->name
+ "=" + escaped
);
439 common_defines
.push_back( defs
[i
]->name
);
442 /*const vector<Property*>& variables = data.properties;
443 for ( i = 0; i < variables.size(); i++ )
445 vars.push_back( variables[i]->name );
446 values.push_back( variables[i]->value );
448 for ( i
= 0; i
< data
.properties
.size(); i
++ )
450 Property
& prop
= *data
.properties
[i
];
451 if ( strstr ( module
.baseaddress
.c_str(), prop
.name
.c_str() ) )
452 baseaddr
= prop
.value
;
456 if ( !module
.allowWarnings
)
457 compiler_flags
.push_back ( "-Werror" );
459 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
460 compiler_flags
.push_back ( "-Wno-main" );
463 FILE* OUT
= fopen ( cbproj_file
.c_str(), "wb" );
465 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
466 fprintf ( OUT
, "<CodeBlocks_project_file>\r\n" );
467 fprintf ( OUT
, "\t<FileVersion major=\"1\" minor=\"5\" />\r\n" );
468 fprintf ( OUT
, "\t<Project>\r\n" );
469 fprintf ( OUT
, "\t\t<Option title=\"%s\" />\r\n", module
.name
.c_str() );
470 fprintf ( OUT
, "\t\t<Option pch_mode=\"2\" />\r\n" );
471 fprintf ( OUT
, "\t\t<Option default_target=\"\" />\r\n" );
472 fprintf ( OUT
, "\t\t<Option compiler=\"gcc\" />\r\n" );
473 fprintf ( OUT
, "\t\t<Option virtualFolders=\"\" />\r\n" );
474 fprintf ( OUT
, "\t\t<Build>\r\n" );
476 bool console
= exe
&& (module
.type
== Win32CUI
);
478 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
480 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
481 fprintf ( OUT
, "\t\t\t<Target title=\"%s\">\r\n", cfg
.name
.c_str() );
483 if ( configuration
.UseConfigurationInPath
)
485 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());
486 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() );
490 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() );
491 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s\" />\r\n", intdir
.c_str(), module
.GetBasePath ().c_str () );
495 fprintf ( OUT
, "\t\t\t\t<Option type=\"2\" />\r\n" );
497 fprintf ( OUT
, "\t\t\t\t<Option type=\"3\" />\r\n" );
499 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
502 if ( module
.type
== Kernel
)
503 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
504 else if ( module
.type
== NativeCUI
)
505 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
506 else if ( module
.type
== Win32CUI
|| module
.type
== Win32GUI
|| module
.type
== Win32SCR
)
509 fprintf ( OUT
, "\t\t\t\t<Option type=\"1\" />\r\n" );
511 fprintf ( OUT
, "\t\t\t\t<Option type=\"0\" />\r\n" );
515 fprintf ( OUT
, "\t\t\t\t<Option compiler=\"gcc\" />\r\n" );
516 if ( module_type
== ".cpl" )
518 fprintf ( OUT
, "\t\t\t\t<Option parameters=\"shell32,Control_RunDLL "$exe_output",@\" />\r\n" );
519 fprintf ( OUT
, "\t\t\t\t<Option host_application=\"rundll32.exe\" />\r\n" );
521 fprintf ( OUT
, "\t\t\t\t<Compiler>\r\n" );
523 bool debug
= ( cfg
.optimization
== Debug
);
526 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-g\" />\r\n" );
529 for ( i
= 0; i
< compiler_flags
.size(); i
++ )
531 const string
& cflag
= compiler_flags
[i
];
532 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", cflag
.c_str() );
536 for ( i
= 0; i
< common_defines
.size(); i
++ )
538 const string
& define
= common_defines
[i
];
539 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-D%s\" />\r\n", define
.c_str() );
542 for ( i
= 0; i
< includes
.size(); i
++ )
544 const string
& include
= includes
[i
];
545 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
547 fprintf ( OUT
, "\t\t\t\t</Compiler>\r\n" );
550 fprintf ( OUT
, "\t\t\t\t<ResourceCompiler>\r\n" );
551 for ( i
= 0; i
< includes
.size(); i
++ )
553 const string
& include
= includes
[i
];
554 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
556 fprintf ( OUT
, "\t\t\t\t</ResourceCompiler>\r\n" );
558 fprintf ( OUT
, "\t\t\t\t<Linker>\r\n" );
559 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", project_linker_flags
.c_str() );
563 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 ());
564 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x10000" : baseaddr
.c_str () );
565 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -nostdlib\" />\r\n" );
569 if ( module
.type
== Kernel
)
571 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_KiSystemStartup\" />\r\n" );
572 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
574 else if ( module
.type
== NativeCUI
)
576 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_NtProcessStartup@4\" />\r\n" );
577 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
578 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -nostdlib\" />\r\n" );
582 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc" );
587 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,%s%s\" />\r\n", "_", module
.GetEntryPoint(false).c_str () );
588 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x40000" : baseaddr
.c_str () );
589 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc" );
592 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--file-alignment,0x1000\" />\r\n" );
593 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--section-alignment,0x1000\" />\r\n" );
596 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s.temp.exp\" />\r\n", module
.name
.c_str() );
599 for ( i
= 0; i
< libraries
.size(); i
++ )
601 const string
& lib
= libraries
[i
];
602 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"%s\" />\r\n", lib
.c_str() );
604 for ( i
= 0; i
< libpaths
.size(); i
++ )
606 const string
& lib
= libpaths
[i
];
607 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", lib
.c_str() );
609 fprintf ( OUT
, "\t\t\t\t</Linker>\r\n" );
611 fprintf ( OUT
, "\t\t\t\t<ExtraCommands>\r\n" );
613 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
614 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"dlltool --dllname %s --def %s --output-lib "$(TARGET_OUTPUT_DIR)lib$(TARGET_OUTPUT_BASENAME).a" %s -U\" />\r\n", module
.importLibrary
->dllname
.c_str (), module
.importLibrary
->definition
.c_str(), module
.mangledSymbols
? "" : "--kill-at" );
619 fprintf ( OUT
, "\t\t\t\t\t<Add before=\"dlltool --dllname %s --def %s --output-exp %s.temp.exp %s\" />\r\n", module
.importLibrary
->dllname
.c_str (), module
.importLibrary
->definition
.c_str(), module
.name
.c_str(), module
.mangledSymbols
? "" : "--kill-at" );
621 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del %s.temp.exp 2>NUL\" />\r\n", module
.name
.c_str() );
623 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm %s.temp.exp 2>/dev/null\" />\r\n", module
.name
.c_str() );
625 fprintf ( OUT
, "\t\t\t\t\t<Mode after=\"always\" />\r\n" );
628 fprintf ( OUT
, "\t\t\t\t</ExtraCommands>\r\n" );
630 fprintf ( OUT
, "\t\t\t</Target>\r\n" );
635 fprintf ( OUT, "\t\t\t<Environment>\r\n" );
636 for ( i = 0; i < vars.size(); i++ )
638 const string& var = vars[i];
639 const string& value = values[i];
640 fprintf ( OUT, "\t\t\t\t<Variable name=\"%s\" value=\"%s\" />\r\n", var.c_str(), value.c_str() );
642 fprintf ( OUT, "\t\t\t</Environment>\r\n" ); */
644 fprintf ( OUT
, "\t\t</Build>\r\n" );
646 if ( module
.cplusplus
)
652 for ( i
= 0; i
< header_files
.size(); i
++ )
654 const string
& header_file
= header_files
[i
];
655 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", header_file
.c_str() );
656 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
657 fprintf ( OUT
, "\t\t\t<Option compile=\"0\" />\r\n" );
658 fprintf ( OUT
, "\t\t\t<Option link=\"0\" />\r\n" );
659 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
661 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
662 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
664 fprintf ( OUT
, "\t\t</Unit>\r\n" );
668 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
670 string source_file
= DosSeparator(source_files
[isrcfile
]);
671 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", source_file
.c_str() );
672 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
674 string extension
= GetExtension ( source_file
);
675 if ( extension
== ".s" || extension
== ".S" )
676 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"gcc -x assembler-with-cpp -c $file -o $link_objects $includes -D__ASM__ $options\" />\r\n" );
677 if ( extension
== ".asm" || extension
== ".ASM" )
678 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"nasm -f win32 $file -o $link_objects\" />\r\n" );
680 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
682 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
683 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
685 fprintf ( OUT
, "\t\t</Unit>\r\n" );
689 for ( i
= 0; i
< resource_files
.size(); i
++ )
691 const string
& resource_file
= resource_files
[i
];
692 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", resource_file
.c_str() );
693 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"WINDRES\" />\r\n" );
694 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
696 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
697 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
699 fprintf ( OUT
, "\t\t</Unit>\r\n" );
702 fprintf ( OUT
, "\t\t<Extensions />\r\n" );
703 fprintf ( OUT
, "\t</Project>\r\n" );
704 fprintf ( OUT
, "</CodeBlocks_project_file>\r\n" );
710 CBConfiguration::CBConfiguration ( const OptimizationType optimization
, const std::string
&name
)
712 this->optimization
= optimization
;
717 if ( optimization
== Debug
)
718 this->name
= "Debug";
719 else if ( optimization
== Release
)
720 this->name
= "Release";
722 this->name
= "Unknown";
727 CBBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
729 std::string::size_type pos
= string1
.find(find_str
, 0);
730 int intLen
= find_str
.length();
732 while(std::string::npos
!= pos
)
734 string1
.replace(pos
, intLen
, replace_str
);
735 pos
= string1
.find(find_str
, intLen
+ pos
);
742 CBBackend::GenerateProjectLinkerFlags() const
745 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
747 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
748 if ( lflags
.length () > 0 )
750 lflags
+= linkerFlag
.flag
;
756 CBBackend::MingwAddImplicitLibraries( Module
&module
)
760 if ( !module
.isDefaultEntryPoint
)
763 if ( module
.IsDLL () )
765 //pLibrary = new Library ( module, "__mingw_dllmain" );
766 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
770 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
771 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
774 pLibrary
= new Library ( module
, "mingw_common" );
775 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
777 if ( module
.name
!= "msvcrt" )
779 // always link in msvcrt to get the basic routines
780 pLibrary
= new Library ( module
, "msvcrt" );
781 module
.non_if_data
.libraries
.push_back ( pLibrary
);
786 CBBackend::_lookup_property ( const Module
& module
, const std::string
& name
) const
788 /* Check local values */
789 for ( size_t i
= 0; i
< module
.non_if_data
.properties
.size(); i
++ )
791 const Property
& property
= *module
.non_if_data
.properties
[i
];
792 if ( property
.name
== name
)
795 // TODO FIXME - should we check local if-ed properties?
796 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size(); i
++ )
798 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
799 if ( property
.name
== name
)
802 // TODO FIXME - should we check global if-ed properties?