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 if ((module
.type
!= Iso
) &&
307 (module
.type
!= LiveIso
) &&
308 (module
.type
!= IsoRegTest
) &&
309 (module
.type
!= LiveIsoRegTest
))
311 std::string Cbp_file
= CbpFileName ( module
);
312 fprintf ( OUT
, "\t\t<Project filename=\"%s\">\r\n", Cbp_file
.c_str());
315 vector
<const IfableData
*> ifs_list
;
316 ifs_list
.push_back ( &module
.project
.non_if_data
);
317 ifs_list
.push_back ( &module
.non_if_data
);
318 while ( ifs_list
.size() )
320 const IfableData
& data
= *ifs_list
.back();
322 const vector
<Library
*>& libs
= data
.libraries
;
323 for ( size_t j
= 0; j
< libs
.size(); j
++ )
324 fprintf ( OUT
, "\t\t\t<Depends filename=\"%s\\%s_auto.cbp\" />\r\n", libs
[j
]->importedModule
->GetBasePath().c_str(), libs
[j
]->name
.c_str() );
326 fprintf ( OUT
, "\t\t</Project>\r\n" );
329 fprintf ( OUT
, "\t</Workspace>\r\n" );
330 fprintf ( OUT
, "</CodeBlocks_workspace_file>\r\n" );
334 CBBackend::_generate_cbproj ( const Module
& module
)
339 string cbproj_file
= CbpFileName(module
);
342 string path_basedir
= module
.GetPathToBaseDir ();
343 string intenv
= Environment::GetIntermediatePath ();
344 string outenv
= Environment::GetOutputPath ();
345 string module_type
= GetExtension(module
.GetTargetName());
346 string cbproj_path
= module
.GetBasePath();
349 string windres_defines
;
351 string project_linker_flags
= "-Wl,--enable-stdcall-fixup ";
352 project_linker_flags
+= GenerateProjectLinkerFlags();
354 bool lib
= (module
.type
== ObjectLibrary
) || (module
.type
== RpcClient
) ||(module
.type
== RpcServer
) || (module_type
== ".lib") || (module_type
== ".a");
355 bool dll
= (module_type
== ".dll") || (module_type
== ".cpl");
356 bool exe
= (module_type
== ".exe") || (module_type
== ".scr");
357 bool sys
= (module_type
== ".sys");
359 vector
<string
> source_files
, resource_files
, includes
, libraries
, libpaths
;
360 vector
<string
> header_files
, common_defines
, compiler_flags
;
361 vector
<string
> vars
, values
;
363 /* do not create project files for these targets
364 use virtual targets instead */
376 compiler_flags
.push_back ( "-Wall" );
378 // Always force disabling of sibling calls optimisation for GCC
379 // (TODO: Move to version-specific once this bug is fixed in GCC)
380 compiler_flags
.push_back ( "-fno-optimize-sibling-calls" );
382 if ( module
.pch
!= NULL
)
384 string pch_path
= Path::RelativeFromDirectory (
385 module
.pch
->file
.name
,
386 module
.GetBasePath() );
388 header_files
.push_back ( pch_path
);
391 if ( intenv
== "obj-i386" )
392 intdir
= path_basedir
+ "obj-i386"; /* append relative dir from project dir */
396 if ( outenv
== "output-i386" )
397 outdir
= path_basedir
+ "output-i386";
401 vector
<const IfableData
*> ifs_list
;
402 ifs_list
.push_back ( &module
.project
.non_if_data
);
403 ifs_list
.push_back ( &module
.non_if_data
);
404 while ( ifs_list
.size() )
406 const IfableData
& data
= *ifs_list
.back();
408 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
410 const Property
* property
= _lookup_property( module
, data
.ifs
[i
]->property
);
411 if ( property
!= NULL
)
413 if ( data
.ifs
[i
]->value
== property
->value
&& data
.ifs
[i
]->negated
== false ||
414 data
.ifs
[i
]->value
!= property
->value
&& data
.ifs
[i
]->negated
)
415 ifs_list
.push_back ( &data
.ifs
[i
]->data
);
418 const vector
<File
*>& files
= data
.files
;
419 for ( i
= 0; i
< files
.size(); i
++ )
421 string file
= string(".") + &files
[i
]->name
[cbproj_path
.size()];
423 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
424 resource_files
.push_back ( file
);
426 source_files
.push_back ( file
);
428 const vector
<Include
*>& incs
= data
.includes
;
429 for ( i
= 0; i
< incs
.size(); i
++ )
431 string path
= Path::RelativeFromDirectory (
433 module
.GetBasePath() );
435 includes
.push_back ( path
);
436 widl_options
+= "-I" + path
+ " ";
438 const vector
<Library
*>& libs
= data
.libraries
;
439 for ( i
= 0; i
< libs
.size(); i
++ )
441 string libpath
= intdir
+ "\\" + libs
[i
]->importedModule
->GetBasePath();
442 libraries
.push_back ( libs
[i
]->name
);
443 libpaths
.push_back ( libpath
);
445 const vector
<CompilerFlag
*>& cflags
= data
.compilerFlags
;
446 for ( i
= 0; i
< cflags
.size(); i
++ )
448 compiler_flags
.push_back ( cflags
[i
]->flag
);
450 const vector
<Define
*>& defs
= data
.defines
;
451 for ( i
= 0; i
< defs
.size(); i
++ )
453 if ( defs
[i
]->value
[0] )
455 const string
& escaped
= _replace_str(defs
[i
]->value
, "\"",""");
456 common_defines
.push_back( defs
[i
]->name
+ "=" + escaped
);
457 windres_defines
+= "-D" + defs
[i
]->name
+ "=" + escaped
+ " ";
461 common_defines
.push_back( defs
[i
]->name
);
462 windres_defines
+= "-D" + defs
[i
]->name
+ " ";
465 /*const vector<Property*>& variables = data.properties;
466 for ( i = 0; i < variables.size(); i++ )
468 vars.push_back( variables[i]->name );
469 values.push_back( variables[i]->value );
471 for ( i
= 0; i
< data
.properties
.size(); i
++ )
473 Property
& prop
= *data
.properties
[i
];
474 if ( strstr ( module
.baseaddress
.c_str(), prop
.name
.c_str() ) )
475 baseaddr
= prop
.value
;
479 if ( !module
.allowWarnings
)
480 compiler_flags
.push_back ( "-Werror" );
482 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
483 compiler_flags
.push_back ( "-Wno-main" );
486 FILE* OUT
= fopen ( cbproj_file
.c_str(), "wb" );
488 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
489 fprintf ( OUT
, "<CodeBlocks_project_file>\r\n" );
490 fprintf ( OUT
, "\t<FileVersion major=\"1\" minor=\"6\" />\r\n" );
491 fprintf ( OUT
, "\t<Project>\r\n" );
492 fprintf ( OUT
, "\t\t<Option title=\"%s\" />\r\n", module
.name
.c_str() );
493 fprintf ( OUT
, "\t\t<Option pch_mode=\"2\" />\r\n" );
494 fprintf ( OUT
, "\t\t<Option default_target=\"\" />\r\n" );
495 fprintf ( OUT
, "\t\t<Option compiler=\"gcc\" />\r\n" );
496 fprintf ( OUT
, "\t\t<Option extended_obj_names=\"1\" />\r\n" );
497 fprintf ( OUT
, "\t\t<Option virtualFolders=\"\" />\r\n" );
498 fprintf ( OUT
, "\t\t<Build>\r\n" );
500 bool console
= exe
&& (module
.type
== Win32CUI
);
502 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
504 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
505 fprintf ( OUT
, "\t\t\t<Target title=\"%s\">\r\n", cfg
.name
.c_str() );
507 if ( configuration
.UseConfigurationInPath
)
509 if ( module
.type
== StaticLibrary
||module
.type
== ObjectLibrary
)
510 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
.GetBasePath ().c_str (), cfg
.name
.c_str(), module
.name
.c_str(), module_type
.c_str());
512 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());
513 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() );
517 if ( module
.type
== StaticLibrary
|| module
.type
== ObjectLibrary
)
518 fprintf ( OUT
, "\t\t\t\t<Option output=\"%s\\%s\\%s%s\" prefix_auto=\"0\" extension_auto=\"0\" />\r\n", intdir
.c_str (), module
.GetBasePath ().c_str (), module
.name
.c_str(), module_type
.c_str() );
520 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() );
521 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s\" />\r\n", intdir
.c_str(), module
.GetBasePath ().c_str () );
526 fprintf ( OUT
, "\t\t\t\t<Option type=\"2\" />\r\n" );
529 fprintf ( OUT
, "\t\t\t\t<Option type=\"3\" />\r\n" );
531 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
534 if ( module
.type
== Kernel
)
535 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
536 else if ( module
.type
== NativeCUI
)
537 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
538 else if ( module
.type
== Win32CUI
|| module
.type
== Win32GUI
|| module
.type
== Win32SCR
)
541 fprintf ( OUT
, "\t\t\t\t<Option type=\"1\" />\r\n" );
543 fprintf ( OUT
, "\t\t\t\t<Option type=\"0\" />\r\n" );
547 fprintf ( OUT
, "\t\t\t\t<Option compiler=\"gcc\" />\r\n" );
549 if ( module_type
== ".cpl" )
551 fprintf ( OUT
, "\t\t\t\t<Option parameters=\"shell32,Control_RunDLL "$exe_output",@\" />\r\n" );
552 fprintf ( OUT
, "\t\t\t\t<Option host_application=\"rundll32.exe\" />\r\n" );
554 fprintf ( OUT
, "\t\t\t\t<Compiler>\r\n" );
556 bool debug
= ( cfg
.optimization
== Debug
);
559 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-g\" />\r\n" );
562 for ( i
= 0; i
< compiler_flags
.size(); i
++ )
564 const string
& cflag
= compiler_flags
[i
];
565 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", cflag
.c_str() );
569 for ( i
= 0; i
< common_defines
.size(); i
++ )
571 const string
& define
= common_defines
[i
];
572 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-D%s\" />\r\n", define
.c_str() );
575 for ( i
= 0; i
< includes
.size(); i
++ )
577 const string
& include
= includes
[i
];
578 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
580 fprintf ( OUT
, "\t\t\t\t</Compiler>\r\n" );
583 fprintf ( OUT
, "\t\t\t\t<ResourceCompiler>\r\n" );
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</ResourceCompiler>\r\n" );
591 fprintf ( OUT
, "\t\t\t\t<Linker>\r\n" );
592 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", project_linker_flags
.c_str() );
596 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 ());
597 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x10000" : baseaddr
.c_str () );
598 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--nostdlib\" />\r\n" );
602 if ( module
.type
== Kernel
)
604 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_KiSystemStartup\" />\r\n" );
605 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
607 else if ( module
.type
== NativeCUI
)
609 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_NtProcessStartup@4\" />\r\n" );
610 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
611 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--nostdlib\" />\r\n" );
615 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.useHostStdlib
? "-nostartfiles" : "-nostartfiles -Wl,--nostdlib" );
616 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"gcc\" />\r\n" );
621 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,%s%s\" />\r\n", "_", module
.GetEntryPoint(false).c_str () );
622 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x40000" : baseaddr
.c_str () );
624 if ( module
.type
== Win32DLL
)
625 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--shared\" />\r\n" );
626 else if ( module
.type
== NativeDLL
)
627 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--shared\" />\r\n" );
628 else if ( module
.type
== NativeDLL
)
629 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--shared\" />\r\n" );
631 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.useHostStdlib
? "-nostartfiles" : "-nostartfiles -Wl,--nostdlib" );
632 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"gcc\" />\r\n" );
635 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--file-alignment,0x1000\" />\r\n" );
636 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--section-alignment,0x1000\" />\r\n" );
639 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s.temp.exp\" />\r\n", module
.name
.c_str() );
642 for ( i
= 0; i
< libraries
.size(); i
++ )
644 const string
& lib
= libraries
[i
];
645 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"%s\" />\r\n", lib
.c_str() );
647 for ( i
= 0; i
< libpaths
.size(); i
++ )
649 const string
& lib
= libpaths
[i
];
650 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", lib
.c_str() );
652 fprintf ( OUT
, "\t\t\t\t</Linker>\r\n" );
654 fprintf ( OUT
, "\t\t\t\t<ExtraCommands>\r\n" );
656 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
657 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" );
658 else if ( module
.importLibrary
!= NULL
)
659 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" );
662 for ( i
= 0; i
< resource_files
.size(); i
++ )
664 const string
& resource_file
= resource_files
[i
];
666 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() );
667 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() );
669 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() );
670 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() );
676 if (IsWineModule( module
))
677 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());
678 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" );
679 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"%s\\tools\\pefixup $exe_output -exports\" />\r\n", outdir
.c_str() );
681 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del %s.temp.exp 2>NUL\" />\r\n", module
.name
.c_str() );
683 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm %s.temp.exp 2>/dev/null\" />\r\n", module
.name
.c_str() );
685 fprintf ( OUT
, "\t\t\t\t\t<Mode after=\"always\" />\r\n" );
688 fprintf ( OUT
, "\t\t\t\t</ExtraCommands>\r\n" );
690 fprintf ( OUT
, "\t\t\t</Target>\r\n" );
695 fprintf ( OUT, "\t\t\t<Environment>\r\n" );
696 for ( i = 0; i < vars.size(); i++ )
698 const string& var = vars[i];
699 const string& value = values[i];
700 fprintf ( OUT, "\t\t\t\t<Variable name=\"%s\" value=\"%s\" />\r\n", var.c_str(), value.c_str() );
702 fprintf ( OUT, "\t\t\t</Environment>\r\n" ); */
704 fprintf ( OUT
, "\t\t</Build>\r\n" );
706 if ( module
.cplusplus
)
712 for ( i
= 0; i
< header_files
.size(); i
++ )
714 const string
& header_file
= header_files
[i
];
715 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", header_file
.c_str() );
716 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
717 fprintf ( OUT
, "\t\t\t<Option compile=\"0\" />\r\n" );
718 fprintf ( OUT
, "\t\t\t<Option link=\"0\" />\r\n" );
719 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
721 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
722 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
724 fprintf ( OUT
, "\t\t</Unit>\r\n" );
728 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
730 string source_file
= DosSeparator(source_files
[isrcfile
]);
731 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", source_file
.c_str() );
732 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
734 string extension
= GetExtension ( source_file
);
735 if ( extension
== ".s" || extension
== ".S" )
737 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
738 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
739 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" );
741 else if ( extension
== ".asm" || extension
== ".ASM" )
743 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
744 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
745 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"nasm -f win32 $file -o $link_objects\" />\r\n" );
747 else if ( extension
== ".idl" || extension
== ".IDL" )
749 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
750 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"%s\\tools\\widl\\widl.exe %s %s -h -H "$(TARGET_OUTPUT_DIR)\\$file_c.h" -c -C "$(TARGET_OUTPUT_DIR)\\$file_c.c" $file\\ngcc %s -c "$(TARGET_OUTPUT_DIR)\\$file_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() );
752 else if ( extension
== ".spec" || extension
== ".SPEC" )
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=\"%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() );
759 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
761 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
762 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
764 fprintf ( OUT
, "\t\t</Unit>\r\n" );
768 for ( i
= 0; i
< resource_files
.size(); i
++ )
770 const string
& resource_file
= resource_files
[i
];
771 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", resource_file
.c_str() );
772 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"WINDRES\" />\r\n" );
773 string extension
= GetExtension ( resource_file
);
774 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() );
775 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
777 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
778 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
780 fprintf ( OUT
, "\t\t</Unit>\r\n" );
783 fprintf ( OUT
, "\t\t<Extensions />\r\n" );
784 fprintf ( OUT
, "\t</Project>\r\n" );
785 fprintf ( OUT
, "</CodeBlocks_project_file>\r\n" );
791 CBConfiguration::CBConfiguration ( const OptimizationType optimization
, const std::string
&name
)
793 this->optimization
= optimization
;
798 if ( optimization
== Debug
)
799 this->name
= "Debug";
800 else if ( optimization
== Release
)
801 this->name
= "Release";
803 this->name
= "Unknown";
808 CBBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
810 std::string::size_type pos
= string1
.find(find_str
, 0);
811 int intLen
= find_str
.length();
813 while(std::string::npos
!= pos
)
815 string1
.replace(pos
, intLen
, replace_str
);
816 pos
= string1
.find(find_str
, intLen
+ pos
);
823 CBBackend::GenerateProjectLinkerFlags() const
826 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
828 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
829 if ( lflags
.length () > 0 )
831 lflags
+= linkerFlag
.flag
;
837 CBBackend::MingwAddImplicitLibraries( Module
&module
)
841 if ( !module
.isDefaultEntryPoint
)
844 if ( module
.IsDLL () )
846 //pLibrary = new Library ( module, "__mingw_dllmain" );
847 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
851 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
852 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
855 pLibrary
= new Library ( module
, "mingw_common" );
856 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
858 if ( module
.name
!= "msvcrt" )
860 // always link in msvcrt to get the basic routines
861 pLibrary
= new Library ( module
, "msvcrt" );
862 module
.non_if_data
.libraries
.push_back ( pLibrary
);
867 CBBackend::_lookup_property ( const Module
& module
, const std::string
& name
) const
869 /* Check local values */
870 for ( size_t i
= 0; i
< module
.non_if_data
.properties
.size(); i
++ )
872 const Property
& property
= *module
.non_if_data
.properties
[i
];
873 if ( property
.name
== name
)
876 // TODO FIXME - should we check local if-ed properties?
877 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size(); i
++ )
879 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
880 if ( property
.name
== name
)
883 // TODO FIXME - should we check global if-ed properties?
888 CBBackend::IsWineModule ( const Module
& module
) const
890 if ( module
.importLibrary
== NULL
)
893 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
894 return ( index
!= string::npos
);