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"
40 #define IsStaticLibrary( module ) ( ( module.type == StaticLibrary ) || ( module.type == HostStaticLibrary ) )
42 static class CBFactory
: public Backend::Factory
46 CBFactory() : Factory("CB", "Code::Blocks") {}
47 Backend
*operator() (Project
&project
,
48 Configuration
& configuration
)
50 return new CBBackend(project
, configuration
);
56 CBBackend::CBBackend(Project
&project
,
57 Configuration
& configuration
) : Backend(project
, configuration
)
62 void CBBackend::Process()
65 while ( m_configurations
.size () > 0 )
67 const CBConfiguration
* cfg
= m_configurations
.back();
68 m_configurations
.pop_back();
72 m_configurations
.push_back ( new CBConfiguration( Debug
));
73 m_configurations
.push_back ( new CBConfiguration( Release
));
75 string
filename_wrkspace ( ProjectNode
.name
);
76 filename_wrkspace
+= "_auto.workspace";
78 printf ( "Creating Code::Blocks workspace: %s\n", filename_wrkspace
.c_str() );
81 m_wrkspaceFile
= fopen ( filename_wrkspace
.c_str(), "wb" );
83 if ( !m_wrkspaceFile
)
85 printf ( "Could not create file '%s'.\n", filename_wrkspace
.c_str() );
89 _generate_workspace ( m_wrkspaceFile
);
91 fclose ( m_wrkspaceFile
);
95 void CBBackend::ProcessModules()
97 for( std::map
<std::string
, Module
*>::const_iterator p
= ProjectNode
.modules
.begin(); p
!= ProjectNode
.modules
.end(); ++ p
)
99 Module
&module
= *p
->second
;
100 MingwAddImplicitLibraries( module
);
101 _generate_cbproj ( module
);
106 GetExtension ( const std::string
& filename
)
108 size_t index
= filename
.find_last_of ( '/' );
109 if (index
== string::npos
) index
= 0;
110 string tmp
= filename
.substr( index
, filename
.size() - index
);
111 size_t ext_index
= tmp
.find_last_of( '.' );
112 if (ext_index
!= string::npos
)
113 return filename
.substr ( index
+ ext_index
, filename
.size() );
117 static bool FileExists(string
&filename
)
119 ifstream
file(filename
.c_str());
128 void CBBackend::ProcessFile(string
&filepath
)
130 // Remove the .\ at the start of the filenames
131 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
132 filepath
.erase(0, 2);
134 if(!FileExists(filepath
))
138 for(size_t i
= 0; i
< filepath
.length(); i
++)
140 if(filepath
[i
] == '\\')
144 // Remove the filename from the path
147 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
149 if(pos
!= string::npos
)
152 folder
.erase(pos
, folder
.length() - pos
);
156 fileUnit
.filename
= filepath
;
157 fileUnit
.folder
= folder
;
159 m_fileUnits
.push_back(fileUnit
);
167 bool CBBackend::CheckFolderAdded(string
&folder
)
169 for(size_t i
= 0; i
< m_folders
.size(); i
++)
171 if(m_folders
[i
] == folder
)
178 void CBBackend::AddFolders(string
&folder
)
180 // Check if this folder was already added. true if it was, false otherwise.
181 if(CheckFolderAdded(folder
))
184 m_folders
.push_back(folder
);
186 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
188 if(pos
== string::npos
)
191 folder
.erase(pos
, folder
.length() - pos
);
195 void CBBackend::OutputFolders()
198 m_devFile
<< "Folders=";
200 for(size_t i
= 0; i
< m_folders
.size(); i
++)
205 m_devFile
<< m_folders
[i
];
211 CBBackend::CbpFileName ( const Module
& module
) const
214 ReplaceExtension ( module
.output
->relative_path
+ "\\" + module
.output
->name
, "_auto.cbp" )
219 CBBackend::LayoutFileName ( const Module
& module
) const
222 ReplaceExtension ( module
.output
->relative_path
+ "\\" + module
.output
->name
, "_auto.layout" )
227 CBBackend::DependFileName ( const Module
& module
) const
230 ReplaceExtension ( module
.output
->relative_path
+ "\\" + module
.output
->name
, "_auto.depend" )
235 CBBackend::_get_object_files ( const Module
& module
, vector
<string
>& out
) const
237 string basepath
= module
.output
->relative_path
;
239 string intenv
= Environment::GetIntermediatePath () + "\\" + basepath
+ "\\";
240 string outenv
= Environment::GetOutputPath () + "\\" + basepath
+ "\\";
244 if ( configuration
.UseConfigurationInPath
)
246 cfgs
.push_back ( intenv
+ "Debug" );
247 cfgs
.push_back ( intenv
+ "Release" );
248 cfgs
.push_back ( outenv
+ "Debug" );
249 cfgs
.push_back ( outenv
+ "Release" );
253 cfgs
.push_back ( intenv
);
254 cfgs
.push_back ( outenv
);
257 vector
<const IfableData
*> ifs_list
;
258 ifs_list
.push_back ( &module
.project
.non_if_data
);
259 ifs_list
.push_back ( &module
.non_if_data
);
260 while ( ifs_list
.size () )
262 const IfableData
& data
= *ifs_list
.back();
264 const vector
<File
*>& files
= data
.files
;
265 for ( i
= 0; i
< files
.size (); i
++ )
267 string file
= files
[i
]->file
.relative_path
+ sSep
+ files
[i
]->file
.name
;
268 string::size_type pos
= file
.find_last_of ("\\");
269 if ( pos
!= string::npos
)
270 file
.erase ( 0, pos
+1 );
271 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
272 file
= ReplaceExtension ( file
, ".res" );
274 file
= ReplaceExtension ( file
, ".obj" );
275 for ( size_t j
= 0; j
< cfgs
.size () / 2; j
++ )
276 out
.push_back ( cfgs
[j
] + "\\" + file
);
283 CBBackend::_clean_project_files ( void )
285 for( std::map
<std::string
, Module
*>::const_iterator p
= ProjectNode
.modules
.begin(); p
!= ProjectNode
.modules
.end(); ++ p
)
287 Module
& module
= *p
->second
;
289 printf("Cleaning project %s %s\n", module
.name
.c_str (), module
.output
->relative_path
.c_str () );
291 string basepath
= module
.output
->relative_path
;
292 remove ( CbpFileName ( module
).c_str () );
293 remove ( DependFileName ( module
).c_str () );
294 remove ( LayoutFileName ( module
).c_str () );
296 _get_object_files ( module
, out
);
297 for ( size_t j
= 0; j
< out
.size (); j
++)
299 //printf("Cleaning file %s\n", out[j].c_str () );
300 remove ( out
[j
].c_str () );
304 string filename_wrkspace
= ProjectNode
.name
+ ".workspace";
306 remove ( filename_wrkspace
.c_str () );
310 CBBackend::_generate_workspace ( FILE* OUT
)
312 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
313 fprintf ( OUT
, "<CodeBlocks_workspace_file>\r\n" );
314 fprintf ( OUT
, "\t<Workspace title=\"ReactOS\">\r\n" );
315 for( std::map
<std::string
, Module
*>::const_iterator p
= ProjectNode
.modules
.begin(); p
!= ProjectNode
.modules
.end(); ++ p
)
317 Module
& module
= *p
->second
;
319 if ((module
.type
!= Iso
) &&
320 (module
.type
!= LiveIso
) &&
321 (module
.type
!= IsoRegTest
) &&
322 (module
.type
!= LiveIsoRegTest
))
324 std::string Cbp_file
= CbpFileName ( module
);
325 fprintf ( OUT
, "\t\t<Project filename=\"%s\">\r\n", Cbp_file
.c_str());
328 vector
<const IfableData
*> ifs_list
;
329 ifs_list
.push_back ( &module
.project
.non_if_data
);
330 ifs_list
.push_back ( &module
.non_if_data
);
331 while ( ifs_list
.size() )
333 const IfableData
& data
= *ifs_list
.back();
335 const vector
<Library
*>& libs
= data
.libraries
;
336 for ( size_t j
= 0; j
< libs
.size(); j
++ )
337 fprintf ( OUT
, "\t\t\t<Depends filename=\"%s\\%s_auto.cbp\" />\r\n", libs
[j
]->importedModule
->output
->relative_path
.c_str(), libs
[j
]->name
.c_str() );
339 fprintf ( OUT
, "\t\t</Project>\r\n" );
342 fprintf ( OUT
, "\t</Workspace>\r\n" );
343 fprintf ( OUT
, "</CodeBlocks_workspace_file>\r\n" );
347 CBBackend::_generate_cbproj ( const Module
& module
)
352 string cbproj_file
= CbpFileName(module
);
355 string path_basedir
= module
.GetPathToBaseDir ();
356 string intenv
= Environment::GetIntermediatePath ();
357 string outenv
= Environment::GetOutputPath ();
358 string module_type
= GetExtension(*module
.output
);
359 string cbproj_path
= module
.output
->relative_path
;
362 string windres_defines
;
364 string project_linker_flags
= "-Wl,--enable-stdcall-fixup ";
365 project_linker_flags
+= GenerateProjectLinkerFlags();
367 bool lib
= (module
.type
== ObjectLibrary
) ||
368 (module
.type
== RpcClient
) ||
369 (module
.type
== RpcServer
) ||
370 (module
.type
== RpcProxy
) ||
371 (module_type
== ".lib") ||
372 (module_type
== ".a");
373 bool dll
= (module_type
== ".dll") || (module_type
== ".cpl");
374 bool exe
= (module_type
== ".exe") || (module_type
== ".scr");
375 bool sys
= (module_type
== ".sys");
377 vector
<string
> source_files
, resource_files
, includes
, libraries
, libpaths
;
378 vector
<string
> header_files
, common_defines
, compiler_flags
;
379 vector
<string
> vars
, values
;
381 /* do not create project files for these targets
382 use virtual targets instead */
394 compiler_flags
.push_back ( "-Wall" );
396 // Always force disabling of sibling calls optimisation for GCC
397 // (TODO: Move to version-specific once this bug is fixed in GCC)
398 compiler_flags
.push_back ( "-fno-optimize-sibling-calls" );
400 if ( module
.pch
!= NULL
)
402 string pch_path
= Path::RelativeFromDirectory (
403 module
.pch
->file
->name
,
404 module
.output
->relative_path
);
406 header_files
.push_back ( pch_path
);
409 if ( intenv
== "obj-i386" )
410 intdir
= path_basedir
+ "obj-i386"; /* append relative dir from project dir */
414 if ( outenv
== "output-i386" )
415 outdir
= path_basedir
+ "output-i386";
419 vector
<const IfableData
*> ifs_list
;
420 ifs_list
.push_back ( &module
.project
.non_if_data
);
421 ifs_list
.push_back ( &module
.non_if_data
);
422 while ( ifs_list
.size() )
424 const IfableData
& data
= *ifs_list
.back();
426 const vector
<File
*>& files
= data
.files
;
427 for ( i
= 0; i
< files
.size(); i
++ )
429 string fullpath
= files
[i
]->file
.relative_path
+ sSep
+ files
[i
]->file
.name
;
430 string file
= string(".") + &fullpath
[cbproj_path
.size()];
432 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
433 resource_files
.push_back ( file
);
435 source_files
.push_back ( file
);
437 const vector
<Include
*>& incs
= data
.includes
;
438 for ( i
= 0; i
< incs
.size(); i
++ )
440 string path
= Path::RelativeFromDirectory (
441 incs
[i
]->directory
->relative_path
,
442 module
.output
->relative_path
);
444 includes
.push_back ( path
);
445 widl_options
+= "-I" + path
+ " ";
447 const vector
<Library
*>& libs
= data
.libraries
;
448 for ( i
= 0; i
< libs
.size(); i
++ )
450 string libpath
= intdir
+ "\\" + libs
[i
]->importedModule
->output
->relative_path
;
451 libraries
.push_back ( libs
[i
]->name
);
452 libpaths
.push_back ( libpath
);
454 const vector
<CompilerFlag
*>& cflags
= data
.compilerFlags
;
455 for ( i
= 0; i
< cflags
.size(); i
++ )
457 compiler_flags
.push_back ( cflags
[i
]->flag
);
459 const vector
<Define
*>& defs
= data
.defines
;
460 for ( i
= 0; i
< defs
.size(); i
++ )
462 if ( defs
[i
]->value
[0] )
464 const string
& escaped
= _replace_str(defs
[i
]->value
, "\"",""");
465 common_defines
.push_back( defs
[i
]->name
+ "=" + escaped
);
466 windres_defines
+= "-D" + defs
[i
]->name
+ "=" + escaped
+ " ";
470 common_defines
.push_back( defs
[i
]->name
);
471 windres_defines
+= "-D" + defs
[i
]->name
+ " ";
474 /*const vector<Property*>& variables = data.properties;
475 for ( i = 0; i < variables.size(); i++ )
477 vars.push_back( variables[i]->name );
478 values.push_back( variables[i]->value );
480 for ( std::map
<std::string
, Property
*>::const_iterator p
= data
.properties
.begin(); p
!= data
.properties
.end(); ++ p
)
482 Property
& prop
= *p
->second
;
483 if ( strstr ( module
.baseaddress
.c_str(), prop
.name
.c_str() ) )
484 baseaddr
= prop
.value
;
488 if ( !module
.allowWarnings
)
489 compiler_flags
.push_back ( "-Werror" );
491 if ( IsStaticLibrary ( module
) && module
.isStartupLib
)
492 compiler_flags
.push_back ( "-Wno-main" );
495 FILE* OUT
= fopen ( cbproj_file
.c_str(), "wb" );
497 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
498 fprintf ( OUT
, "<CodeBlocks_project_file>\r\n" );
499 fprintf ( OUT
, "\t<FileVersion major=\"1\" minor=\"6\" />\r\n" );
500 fprintf ( OUT
, "\t<Project>\r\n" );
501 fprintf ( OUT
, "\t\t<Option title=\"%s\" />\r\n", module
.name
.c_str() );
502 fprintf ( OUT
, "\t\t<Option pch_mode=\"2\" />\r\n" );
503 fprintf ( OUT
, "\t\t<Option default_target=\"\" />\r\n" );
504 fprintf ( OUT
, "\t\t<Option compiler=\"gcc\" />\r\n" );
505 fprintf ( OUT
, "\t\t<Option extended_obj_names=\"1\" />\r\n" );
506 fprintf ( OUT
, "\t\t<Option virtualFolders=\"\" />\r\n" );
507 fprintf ( OUT
, "\t\t<Build>\r\n" );
509 bool console
= exe
&& (module
.type
== Win32CUI
);
511 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
513 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
514 fprintf ( OUT
, "\t\t\t<Target title=\"%s\">\r\n", cfg
.name
.c_str() );
516 if ( configuration
.UseConfigurationInPath
)
518 if ( IsStaticLibrary ( module
) ||module
.type
== ObjectLibrary
)
519 fprintf ( OUT
, "\t\t\t\t<Option output=\"%s\\%s%s\\%s%s\" prefix_auto=\"0\" extension_auto=\"0\" />\r\n", intdir
.c_str (), module
.output
->relative_path
.c_str (), cfg
.name
.c_str(), module
.name
.c_str(), module_type
.c_str());
521 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
.output
->relative_path
.c_str (), cfg
.name
.c_str(), module
.name
.c_str(), module_type
.c_str());
522 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s%s\" />\r\n", intdir
.c_str(), module
.output
->relative_path
.c_str (), cfg
.name
.c_str() );
526 if ( IsStaticLibrary ( module
) || module
.type
== ObjectLibrary
)
527 fprintf ( OUT
, "\t\t\t\t<Option output=\"%s\\%s\\%s%s\" prefix_auto=\"0\" extension_auto=\"0\" />\r\n", intdir
.c_str (), module
.output
->relative_path
.c_str (), module
.name
.c_str(), module_type
.c_str() );
529 fprintf ( OUT
, "\t\t\t\t<Option output=\"%s\\%s\\%s%s\" prefix_auto=\"0\" extension_auto=\"0\" />\r\n", outdir
.c_str (), module
.output
->relative_path
.c_str (), module
.name
.c_str(), module_type
.c_str() );
530 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s\" />\r\n", intdir
.c_str(), module
.output
->relative_path
.c_str () );
535 fprintf ( OUT
, "\t\t\t\t<Option type=\"2\" />\r\n" );
538 fprintf ( OUT
, "\t\t\t\t<Option type=\"3\" />\r\n" );
540 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
543 if ( module
.type
== Kernel
)
544 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
545 else if ( module
.type
== NativeCUI
)
546 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
547 else if ( module
.type
== Win32CUI
|| module
.type
== Win32GUI
|| module
.type
== Win32SCR
)
550 fprintf ( OUT
, "\t\t\t\t<Option type=\"1\" />\r\n" );
552 fprintf ( OUT
, "\t\t\t\t<Option type=\"0\" />\r\n" );
556 fprintf ( OUT
, "\t\t\t\t<Option compiler=\"gcc\" />\r\n" );
558 if ( module_type
== ".cpl" )
560 fprintf ( OUT
, "\t\t\t\t<Option parameters=\"shell32,Control_RunDLL "$exe_output",@\" />\r\n" );
561 fprintf ( OUT
, "\t\t\t\t<Option host_application=\"rundll32.exe\" />\r\n" );
563 fprintf ( OUT
, "\t\t\t\t<Compiler>\r\n" );
565 bool debug
= ( cfg
.optimization
== Debug
);
568 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-g\" />\r\n" );
571 for ( i
= 0; i
< compiler_flags
.size(); i
++ )
573 const string
& cflag
= compiler_flags
[i
];
574 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", cflag
.c_str() );
578 for ( i
= 0; i
< common_defines
.size(); i
++ )
580 const string
& define
= common_defines
[i
];
581 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-D%s\" />\r\n", define
.c_str() );
584 for ( i
= 0; i
< includes
.size(); i
++ )
586 const string
& include
= includes
[i
];
587 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
589 fprintf ( OUT
, "\t\t\t\t</Compiler>\r\n" );
592 fprintf ( OUT
, "\t\t\t\t<ResourceCompiler>\r\n" );
593 for ( i
= 0; i
< includes
.size(); i
++ )
595 const string
& include
= includes
[i
];
596 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
598 fprintf ( OUT
, "\t\t\t\t</ResourceCompiler>\r\n" );
600 fprintf ( OUT
, "\t\t\t\t<Linker>\r\n" );
601 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", project_linker_flags
.c_str() );
605 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 ());
606 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x10000" : baseaddr
.c_str () );
607 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--nostdlib\" />\r\n" );
611 if ( module
.type
== Kernel
)
613 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_KiSystemStartup\" />\r\n" );
614 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
616 else if ( module
.type
== NativeCUI
)
618 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_NtProcessStartup@4\" />\r\n" );
619 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
620 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--nostdlib\" />\r\n" );
624 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.cplusplus
? "-nostartfiles" : "-nostartfiles -Wl,--nostdlib" );
625 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"gcc\" />\r\n" );
630 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,%s%s\" />\r\n", "_", module
.GetEntryPoint(false).c_str () );
631 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x40000" : baseaddr
.c_str () );
633 if ( module
.type
== Win32DLL
)
634 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--shared\" />\r\n" );
635 else if ( module
.type
== NativeDLL
)
636 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--shared\" />\r\n" );
637 else if ( module
.type
== NativeDLL
)
638 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--shared\" />\r\n" );
640 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.cplusplus
? "-nostartfiles" : "-nostartfiles -Wl,--nostdlib" );
641 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"gcc\" />\r\n" );
644 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--file-alignment,0x1000\" />\r\n" );
645 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--section-alignment,0x1000\" />\r\n" );
648 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s.temp.exp\" />\r\n", module
.name
.c_str() );
651 for ( i
= 0; i
< libraries
.size(); i
++ )
653 const string
& lib
= libraries
[i
];
654 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"%s\" />\r\n", lib
.c_str() );
656 for ( i
= 0; i
< libpaths
.size(); i
++ )
658 const string
& lib
= libpaths
[i
];
659 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", lib
.c_str() );
661 fprintf ( OUT
, "\t\t\t\t</Linker>\r\n" );
663 fprintf ( OUT
, "\t\t\t\t<ExtraCommands>\r\n" );
666 if ( IsStaticLibrary ( module
) && module
.importLibrary
)
667 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"dlltool --dllname %s --def %s --output-lib $exe_output; %s -U\" />\r\n", module
.importLibrary
->dllname
.c_str (), module
.importLibrary
->definition
.c_str(), module
.mangledSymbols
? "" : "--kill-at" );
668 else if ( module
.importLibrary
!= NULL
)
669 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"dlltool --dllname %s --def %s --output-lib "$(TARGET_OBJECT_DIR)lib$(TARGET_OUTPUT_BASENAME).a" %s\" />\r\n", module
.GetTargetName ().c_str(), module
.importLibrary
->definition
.c_str(), module
.mangledSymbols
? "" : "--kill-at" );
673 for ( i
= 0; i
< resource_files
.size(); i
++ )
675 const string
& resource_file
= resource_files
[i
];
677 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del $(TARGET_OBJECT_DIR)\\%s.rci.tmp 2>NUL\" />\r\n", resource_file
.c_str() );
678 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del $(TARGET_OBJECT_DIR)\\%s.res.tmp 2>NUL\" />\r\n", resource_file
.c_str() );
680 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm $(TARGET_OBJECT_DIR)/%s.rci.tmp 2>/dev/null\" />\r\n", resource_file
.c_str() );
681 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm $(TARGET_OBJECT_DIR)/%s.res.tmp 2>/dev/null\" />\r\n", resource_file
.c_str() );
688 if (IsWineModule( module
))
689 fprintf ( OUT
, "\t\t\t\t\t<Add before=\"%s\\tools\\winebuild\\winebuild.exe -o %s --def -E %s.spec\" />\r\n", outdir
.c_str(), module
.importLibrary
->definition
.c_str(), module
.name
.c_str());
690 fprintf ( OUT
, "\t\t\t\t\t<Add before=\"dlltool --dllname %s --def %s --output-exp %s.temp.exp %s\" />\r\n", module
.GetTargetName ().c_str(), module
.importLibrary
->definition
.c_str(), module
.name
.c_str(), module
.mangledSymbols
? "" : "--kill-at" );
691 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"%s\\tools\\pefixup $exe_output -exports\" />\r\n", outdir
.c_str() );
693 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del %s.temp.exp 2>NUL\" />\r\n", module
.name
.c_str() );
695 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm %s.temp.exp 2>/dev/null\" />\r\n", module
.name
.c_str() );
697 fprintf ( OUT
, "\t\t\t\t\t<Mode after=\"always\" />\r\n" );
701 fprintf ( OUT
, "\t\t\t\t</ExtraCommands>\r\n" );
703 fprintf ( OUT
, "\t\t\t</Target>\r\n" );
708 fprintf ( OUT, "\t\t\t<Environment>\r\n" );
709 for ( i = 0; i < vars.size(); i++ )
711 const string& var = vars[i];
712 const string& value = values[i];
713 fprintf ( OUT, "\t\t\t\t<Variable name=\"%s\" value=\"%s\" />\r\n", var.c_str(), value.c_str() );
715 fprintf ( OUT, "\t\t\t</Environment>\r\n" ); */
717 fprintf ( OUT
, "\t\t</Build>\r\n" );
722 if ( module
.cplusplus
)
729 for ( i
= 0; i
< header_files
.size(); i
++ )
731 const string
& header_file
= header_files
[i
];
732 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", header_file
.c_str() );
733 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
734 fprintf ( OUT
, "\t\t\t<Option compile=\"0\" />\r\n" );
735 fprintf ( OUT
, "\t\t\t<Option link=\"0\" />\r\n" );
736 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
738 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
739 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
741 fprintf ( OUT
, "\t\t</Unit>\r\n" );
745 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
747 string source_file
= DosSeparator(source_files
[isrcfile
]);
748 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", source_file
.c_str() );
749 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
751 string extension
= GetExtension ( source_file
);
752 if ( extension
== ".s" || extension
== ".S" )
754 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
755 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
756 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" );
758 else if ( extension
== ".asm" || extension
== ".ASM" )
760 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
761 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
762 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"nasm -f win32 $file -o $link_objects\" />\r\n" );
764 else if ( extension
== ".idl" || extension
== ".IDL" )
766 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
767 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"%s\\tools\\widl\\widl.exe %s %s -h -H "$(TARGET_OUTPUT_DIR)$filetitle_c.h" -c -C "$(TARGET_OUTPUT_DIR)$filetitle_c.c" $file\\ngcc %s -c "$(TARGET_OUTPUT_DIR)$filetitle_c.c" -o "$(TARGET_OUTPUT_DIR)$file_c.o"\" />\r\n", outdir
.c_str(), widl_options
.c_str(), windres_defines
.c_str(), widl_options
.c_str() );
769 else if ( extension
== ".spec" || extension
== ".SPEC" )
771 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
772 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
773 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"%s\\tools\\winebuild\\winebuild.exe -o $file.stubs.c --pedll $file\\n$compiler -c $options $includes $file.stubs.c -o $(TARGET_OBJECT_DIR)\\$file.o\" />\r\n", outdir
.c_str() );
776 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
778 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
779 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
781 fprintf ( OUT
, "\t\t</Unit>\r\n" );
785 for ( i
= 0; i
< resource_files
.size(); i
++ )
787 const string
& resource_file
= resource_files
[i
];
788 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", resource_file
.c_str() );
789 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"WINDRES\" />\r\n" );
790 string extension
= GetExtension ( resource_file
);
791 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"gcc -xc -E -DRC_INVOKED $includes %s $file -o $(TARGET_OBJECT_DIR)\\$file.rci.tmp\\n%s\\tools\\wrc\\wrc.exe $includes %s $(TARGET_OBJECT_DIR)\\$file.rci.tmp $(TARGET_OBJECT_DIR)\\$file.res.tmp\\n$rescomp --output-format=coff $(TARGET_OBJECT_DIR)\\$file.res.tmp -o $resource_output\" />\r\n" , windres_defines
.c_str(), outdir
.c_str(), windres_defines
.c_str() );
792 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
794 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
795 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
797 fprintf ( OUT
, "\t\t</Unit>\r\n" );
800 fprintf ( OUT
, "\t\t<Extensions />\r\n" );
801 fprintf ( OUT
, "\t</Project>\r\n" );
802 fprintf ( OUT
, "</CodeBlocks_project_file>\r\n" );
808 CBConfiguration::CBConfiguration ( const OptimizationType optimization
, const std::string
&name
)
810 this->optimization
= optimization
;
815 if ( optimization
== Debug
)
816 this->name
= "Debug";
817 else if ( optimization
== Release
)
818 this->name
= "Release";
820 this->name
= "Unknown";
825 CBBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
827 std::string::size_type pos
= string1
.find(find_str
, 0);
828 int intLen
= find_str
.length();
830 while(std::string::npos
!= pos
)
832 string1
.replace(pos
, intLen
, replace_str
);
833 pos
= string1
.find(find_str
, intLen
+ pos
);
840 CBBackend::GenerateProjectLinkerFlags() const
843 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
845 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
846 if ( lflags
.length () > 0 )
848 lflags
+= linkerFlag
.flag
;
854 CBBackend::MingwAddImplicitLibraries( Module
&module
)
858 if ( !module
.isDefaultEntryPoint
)
861 if ( module
.IsDLL () )
863 //pLibrary = new Library ( module, "__mingw_dllmain" );
864 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
868 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
869 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
872 pLibrary
= new Library ( module
, "mingw_common" );
873 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
875 if ( module
.name
!= "msvcrt" )
877 // always link in msvcrt to get the basic routines
878 pLibrary
= new Library ( module
, "msvcrt" );
879 module
.non_if_data
.libraries
.push_back ( pLibrary
);
884 CBBackend::_lookup_property ( const Module
& module
, const std::string
& name
) const
886 std::map
<std::string
, Property
*>::const_iterator p
;
888 /* Check local values */
889 p
= module
.non_if_data
.properties
.find(name
);
891 if ( p
!= module
.non_if_data
.properties
.end() )
894 // TODO FIXME - should we check local if-ed properties?
895 p
= module
.project
.non_if_data
.properties
.find(name
);
897 if ( p
!= module
.project
.non_if_data
.properties
.end() )
900 // TODO FIXME - should we check global if-ed properties?
905 CBBackend::IsWineModule ( const Module
& module
) const
907 if ( module
.importLibrary
== NULL
)
910 size_t index
= module
.importLibrary
->source
->name
.rfind ( ".spec.def" );
911 return ( index
!= string::npos
);