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
);
105 GetExtension ( const std::string
& filename
)
107 size_t index
= filename
.find_last_of ( '/' );
108 if (index
== string::npos
) index
= 0;
109 string tmp
= filename
.substr( index
, filename
.size() - index
);
110 size_t ext_index
= tmp
.find_last_of( '.' );
111 if (ext_index
!= string::npos
)
112 return filename
.substr ( index
+ ext_index
, filename
.size() );
116 static bool FileExists(string
&filename
)
118 ifstream
file(filename
.c_str());
127 void CBBackend::ProcessFile(string
&filepath
)
129 // Remove the .\ at the start of the filenames
130 if ( filepath
[0] == '.' && strchr ( "/\\", filepath
[1] ) )
131 filepath
.erase(0, 2);
133 if(!FileExists(filepath
))
137 for(size_t i
= 0; i
< filepath
.length(); i
++)
139 if(filepath
[i
] == '\\')
143 // Remove the filename from the path
146 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
148 if(pos
!= string::npos
)
151 folder
.erase(pos
, folder
.length() - pos
);
155 fileUnit
.filename
= filepath
;
156 fileUnit
.folder
= folder
;
158 m_fileUnits
.push_back(fileUnit
);
166 bool CBBackend::CheckFolderAdded(string
&folder
)
168 for(size_t i
= 0; i
< m_folders
.size(); i
++)
170 if(m_folders
[i
] == folder
)
177 void CBBackend::AddFolders(string
&folder
)
179 // Check if this folder was already added. true if it was, false otherwise.
180 if(CheckFolderAdded(folder
))
183 m_folders
.push_back(folder
);
185 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
187 if(pos
== string::npos
)
190 folder
.erase(pos
, folder
.length() - pos
);
194 void CBBackend::OutputFolders()
197 m_devFile
<< "Folders=";
199 for(size_t i
= 0; i
< m_folders
.size(); i
++)
204 m_devFile
<< m_folders
[i
];
210 CBBackend::CbpFileName ( const Module
& module
) const
213 ReplaceExtension ( module
.output
->relative_path
+ "\\" + module
.output
->name
, "_auto.cbp" )
218 CBBackend::LayoutFileName ( const Module
& module
) const
221 ReplaceExtension ( module
.output
->relative_path
+ "\\" + module
.output
->name
, "_auto.layout" )
226 CBBackend::DependFileName ( const Module
& module
) const
229 ReplaceExtension ( module
.output
->relative_path
+ "\\" + module
.output
->name
, "_auto.depend" )
234 CBBackend::_get_object_files ( const Module
& module
, vector
<string
>& out
) const
236 string basepath
= module
.output
->relative_path
;
238 string intenv
= Environment::GetIntermediatePath () + "\\" + basepath
+ "\\";
239 string outenv
= Environment::GetOutputPath () + "\\" + basepath
+ "\\";
243 if ( configuration
.UseConfigurationInPath
)
245 cfgs
.push_back ( intenv
+ "Debug" );
246 cfgs
.push_back ( intenv
+ "Release" );
247 cfgs
.push_back ( outenv
+ "Debug" );
248 cfgs
.push_back ( outenv
+ "Release" );
252 cfgs
.push_back ( intenv
);
253 cfgs
.push_back ( outenv
);
256 vector
<const IfableData
*> ifs_list
;
257 ifs_list
.push_back ( &module
.project
.non_if_data
);
258 ifs_list
.push_back ( &module
.non_if_data
);
259 while ( ifs_list
.size () )
261 const IfableData
& data
= *ifs_list
.back();
263 const vector
<File
*>& files
= data
.files
;
264 for ( i
= 0; i
< files
.size (); i
++ )
266 string file
= files
[i
]->file
.relative_path
+ sSep
+ files
[i
]->file
.name
;
267 string::size_type pos
= file
.find_last_of ("\\");
268 if ( pos
!= string::npos
)
269 file
.erase ( 0, pos
+1 );
270 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
271 file
= ReplaceExtension ( file
, ".res" );
273 file
= ReplaceExtension ( file
, ".obj" );
274 for ( size_t j
= 0; j
< cfgs
.size () / 2; j
++ )
275 out
.push_back ( cfgs
[j
] + "\\" + file
);
282 CBBackend::_clean_project_files ( void )
284 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
286 Module
& module
= *ProjectNode
.modules
[i
];
288 printf("Cleaning project %s %s\n", module
.name
.c_str (), module
.output
->relative_path
.c_str () );
290 string basepath
= module
.output
->relative_path
;
291 remove ( CbpFileName ( module
).c_str () );
292 remove ( DependFileName ( module
).c_str () );
293 remove ( LayoutFileName ( module
).c_str () );
295 _get_object_files ( module
, out
);
296 for ( size_t j
= 0; j
< out
.size (); j
++)
298 //printf("Cleaning file %s\n", out[j].c_str () );
299 remove ( out
[j
].c_str () );
303 string filename_wrkspace
= ProjectNode
.name
+ ".workspace";
305 remove ( filename_wrkspace
.c_str () );
309 CBBackend::_generate_workspace ( FILE* OUT
)
311 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
312 fprintf ( OUT
, "<CodeBlocks_workspace_file>\r\n" );
313 fprintf ( OUT
, "\t<Workspace title=\"ReactOS\">\r\n" );
314 for ( size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++ )
316 Module
& module
= *ProjectNode
.modules
[i
];
318 if ((module
.type
!= Iso
) &&
319 (module
.type
!= LiveIso
) &&
320 (module
.type
!= IsoRegTest
) &&
321 (module
.type
!= LiveIsoRegTest
))
323 std::string Cbp_file
= CbpFileName ( module
);
324 fprintf ( OUT
, "\t\t<Project filename=\"%s\">\r\n", Cbp_file
.c_str());
327 vector
<const IfableData
*> ifs_list
;
328 ifs_list
.push_back ( &module
.project
.non_if_data
);
329 ifs_list
.push_back ( &module
.non_if_data
);
330 while ( ifs_list
.size() )
332 const IfableData
& data
= *ifs_list
.back();
334 const vector
<Library
*>& libs
= data
.libraries
;
335 for ( size_t j
= 0; j
< libs
.size(); j
++ )
336 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() );
338 fprintf ( OUT
, "\t\t</Project>\r\n" );
341 fprintf ( OUT
, "\t</Workspace>\r\n" );
342 fprintf ( OUT
, "</CodeBlocks_workspace_file>\r\n" );
346 CBBackend::_generate_cbproj ( const Module
& module
)
351 string cbproj_file
= CbpFileName(module
);
354 string path_basedir
= module
.GetPathToBaseDir ();
355 string intenv
= Environment::GetIntermediatePath ();
356 string outenv
= Environment::GetOutputPath ();
357 string module_type
= GetExtension(*module
.output
);
358 string cbproj_path
= module
.output
->relative_path
;
361 string windres_defines
;
363 string project_linker_flags
= "-Wl,--enable-stdcall-fixup ";
364 project_linker_flags
+= GenerateProjectLinkerFlags();
366 bool lib
= (module
.type
== ObjectLibrary
) || (module
.type
== RpcClient
) ||(module
.type
== RpcServer
) || (module_type
== ".lib") || (module_type
== ".a");
367 bool dll
= (module_type
== ".dll") || (module_type
== ".cpl");
368 bool exe
= (module_type
== ".exe") || (module_type
== ".scr");
369 bool sys
= (module_type
== ".sys");
371 vector
<string
> source_files
, resource_files
, includes
, libraries
, libpaths
;
372 vector
<string
> header_files
, common_defines
, compiler_flags
;
373 vector
<string
> vars
, values
;
375 /* do not create project files for these targets
376 use virtual targets instead */
388 compiler_flags
.push_back ( "-Wall" );
390 // Always force disabling of sibling calls optimisation for GCC
391 // (TODO: Move to version-specific once this bug is fixed in GCC)
392 compiler_flags
.push_back ( "-fno-optimize-sibling-calls" );
394 if ( module
.pch
!= NULL
)
396 string pch_path
= Path::RelativeFromDirectory (
397 module
.pch
->file
.name
,
398 module
.output
->relative_path
);
400 header_files
.push_back ( pch_path
);
403 if ( intenv
== "obj-i386" )
404 intdir
= path_basedir
+ "obj-i386"; /* append relative dir from project dir */
408 if ( outenv
== "output-i386" )
409 outdir
= path_basedir
+ "output-i386";
413 vector
<const IfableData
*> ifs_list
;
414 ifs_list
.push_back ( &module
.project
.non_if_data
);
415 ifs_list
.push_back ( &module
.non_if_data
);
416 while ( ifs_list
.size() )
418 const IfableData
& data
= *ifs_list
.back();
420 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
422 const Property
* property
= _lookup_property( module
, data
.ifs
[i
]->property
);
423 if ( property
!= NULL
)
425 if ( data
.ifs
[i
]->value
== property
->value
&& data
.ifs
[i
]->negated
== false ||
426 data
.ifs
[i
]->value
!= property
->value
&& data
.ifs
[i
]->negated
)
427 ifs_list
.push_back ( &data
.ifs
[i
]->data
);
430 const vector
<File
*>& files
= data
.files
;
431 for ( i
= 0; i
< files
.size(); i
++ )
433 string fullpath
= files
[i
]->file
.relative_path
+ sSep
+ files
[i
]->file
.name
;
434 string file
= string(".") + &fullpath
[cbproj_path
.size()];
436 if ( !stricmp ( Right(file
,3).c_str(), ".rc" ) )
437 resource_files
.push_back ( file
);
439 source_files
.push_back ( file
);
441 const vector
<Include
*>& incs
= data
.includes
;
442 for ( i
= 0; i
< incs
.size(); i
++ )
444 string path
= Path::RelativeFromDirectory (
445 incs
[i
]->directory
->relative_path
,
446 module
.output
->relative_path
);
448 includes
.push_back ( path
);
449 widl_options
+= "-I" + path
+ " ";
451 const vector
<Library
*>& libs
= data
.libraries
;
452 for ( i
= 0; i
< libs
.size(); i
++ )
454 string libpath
= intdir
+ "\\" + libs
[i
]->importedModule
->output
->relative_path
;
455 libraries
.push_back ( libs
[i
]->name
);
456 libpaths
.push_back ( libpath
);
458 const vector
<CompilerFlag
*>& cflags
= data
.compilerFlags
;
459 for ( i
= 0; i
< cflags
.size(); i
++ )
461 compiler_flags
.push_back ( cflags
[i
]->flag
);
463 const vector
<Define
*>& defs
= data
.defines
;
464 for ( i
= 0; i
< defs
.size(); i
++ )
466 if ( defs
[i
]->value
[0] )
468 const string
& escaped
= _replace_str(defs
[i
]->value
, "\"",""");
469 common_defines
.push_back( defs
[i
]->name
+ "=" + escaped
);
470 windres_defines
+= "-D" + defs
[i
]->name
+ "=" + escaped
+ " ";
474 common_defines
.push_back( defs
[i
]->name
);
475 windres_defines
+= "-D" + defs
[i
]->name
+ " ";
478 /*const vector<Property*>& variables = data.properties;
479 for ( i = 0; i < variables.size(); i++ )
481 vars.push_back( variables[i]->name );
482 values.push_back( variables[i]->value );
484 for ( i
= 0; i
< data
.properties
.size(); i
++ )
486 Property
& prop
= *data
.properties
[i
];
487 if ( strstr ( module
.baseaddress
.c_str(), prop
.name
.c_str() ) )
488 baseaddr
= prop
.value
;
492 if ( !module
.allowWarnings
)
493 compiler_flags
.push_back ( "-Werror" );
495 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
496 compiler_flags
.push_back ( "-Wno-main" );
499 FILE* OUT
= fopen ( cbproj_file
.c_str(), "wb" );
501 fprintf ( OUT
, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\r\n" );
502 fprintf ( OUT
, "<CodeBlocks_project_file>\r\n" );
503 fprintf ( OUT
, "\t<FileVersion major=\"1\" minor=\"6\" />\r\n" );
504 fprintf ( OUT
, "\t<Project>\r\n" );
505 fprintf ( OUT
, "\t\t<Option title=\"%s\" />\r\n", module
.name
.c_str() );
506 fprintf ( OUT
, "\t\t<Option pch_mode=\"2\" />\r\n" );
507 fprintf ( OUT
, "\t\t<Option default_target=\"\" />\r\n" );
508 fprintf ( OUT
, "\t\t<Option compiler=\"gcc\" />\r\n" );
509 fprintf ( OUT
, "\t\t<Option extended_obj_names=\"1\" />\r\n" );
510 fprintf ( OUT
, "\t\t<Option virtualFolders=\"\" />\r\n" );
511 fprintf ( OUT
, "\t\t<Build>\r\n" );
513 bool console
= exe
&& (module
.type
== Win32CUI
);
515 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
517 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
518 fprintf ( OUT
, "\t\t\t<Target title=\"%s\">\r\n", cfg
.name
.c_str() );
520 if ( configuration
.UseConfigurationInPath
)
522 if ( module
.type
== StaticLibrary
||module
.type
== ObjectLibrary
)
523 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());
525 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());
526 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() );
530 if ( module
.type
== StaticLibrary
|| module
.type
== ObjectLibrary
)
531 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() );
533 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() );
534 fprintf ( OUT
, "\t\t\t\t<Option object_output=\"%s\\%s\" />\r\n", intdir
.c_str(), module
.output
->relative_path
.c_str () );
539 fprintf ( OUT
, "\t\t\t\t<Option type=\"2\" />\r\n" );
542 fprintf ( OUT
, "\t\t\t\t<Option type=\"3\" />\r\n" );
544 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
547 if ( module
.type
== Kernel
)
548 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
549 else if ( module
.type
== NativeCUI
)
550 fprintf ( OUT
, "\t\t\t\t<Option type=\"5\" />\r\n" );
551 else if ( module
.type
== Win32CUI
|| module
.type
== Win32GUI
|| module
.type
== Win32SCR
)
554 fprintf ( OUT
, "\t\t\t\t<Option type=\"1\" />\r\n" );
556 fprintf ( OUT
, "\t\t\t\t<Option type=\"0\" />\r\n" );
560 fprintf ( OUT
, "\t\t\t\t<Option compiler=\"gcc\" />\r\n" );
562 if ( module_type
== ".cpl" )
564 fprintf ( OUT
, "\t\t\t\t<Option parameters=\"shell32,Control_RunDLL "$exe_output",@\" />\r\n" );
565 fprintf ( OUT
, "\t\t\t\t<Option host_application=\"rundll32.exe\" />\r\n" );
567 fprintf ( OUT
, "\t\t\t\t<Compiler>\r\n" );
569 bool debug
= ( cfg
.optimization
== Debug
);
572 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-g\" />\r\n" );
575 for ( i
= 0; i
< compiler_flags
.size(); i
++ )
577 const string
& cflag
= compiler_flags
[i
];
578 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", cflag
.c_str() );
582 for ( i
= 0; i
< common_defines
.size(); i
++ )
584 const string
& define
= common_defines
[i
];
585 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-D%s\" />\r\n", define
.c_str() );
588 for ( i
= 0; i
< includes
.size(); i
++ )
590 const string
& include
= includes
[i
];
591 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
593 fprintf ( OUT
, "\t\t\t\t</Compiler>\r\n" );
596 fprintf ( OUT
, "\t\t\t\t<ResourceCompiler>\r\n" );
597 for ( i
= 0; i
< includes
.size(); i
++ )
599 const string
& include
= includes
[i
];
600 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", include
.c_str() );
602 fprintf ( OUT
, "\t\t\t\t</ResourceCompiler>\r\n" );
604 fprintf ( OUT
, "\t\t\t\t<Linker>\r\n" );
605 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", project_linker_flags
.c_str() );
609 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 ());
610 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x10000" : baseaddr
.c_str () );
611 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--nostdlib\" />\r\n" );
615 if ( module
.type
== Kernel
)
617 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_KiSystemStartup\" />\r\n" );
618 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
620 else if ( module
.type
== NativeCUI
)
622 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,_NtProcessStartup@4\" />\r\n" );
623 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
.c_str () );
624 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--nostdlib\" />\r\n" );
628 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.cplusplus
? "-nostartfiles" : "-nostartfiles -Wl,--nostdlib" );
629 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"gcc\" />\r\n" );
634 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--entry,%s%s\" />\r\n", "_", module
.GetEntryPoint(false).c_str () );
635 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--image-base,%s\" />\r\n", baseaddr
== "" ? "0x40000" : baseaddr
.c_str () );
637 if ( module
.type
== Win32DLL
)
638 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--shared\" />\r\n" );
639 else if ( module
.type
== NativeDLL
)
640 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--shared\" />\r\n" );
641 else if ( module
.type
== NativeDLL
)
642 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-nostartfiles -Wl,--shared\" />\r\n" );
644 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s\" />\r\n", module
.cplusplus
? "-nostartfiles" : "-nostartfiles -Wl,--nostdlib" );
645 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"gcc\" />\r\n" );
648 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--file-alignment,0x1000\" />\r\n" );
649 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"-Wl,--section-alignment,0x1000\" />\r\n" );
652 fprintf ( OUT
, "\t\t\t\t\t<Add option=\"%s.temp.exp\" />\r\n", module
.name
.c_str() );
655 for ( i
= 0; i
< libraries
.size(); i
++ )
657 const string
& lib
= libraries
[i
];
658 fprintf ( OUT
, "\t\t\t\t\t<Add library=\"%s\" />\r\n", lib
.c_str() );
660 for ( i
= 0; i
< libpaths
.size(); i
++ )
662 const string
& lib
= libpaths
[i
];
663 fprintf ( OUT
, "\t\t\t\t\t<Add directory=\"%s\" />\r\n", lib
.c_str() );
665 fprintf ( OUT
, "\t\t\t\t</Linker>\r\n" );
667 fprintf ( OUT
, "\t\t\t\t<ExtraCommands>\r\n" );
670 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
671 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" );
672 else if ( module
.importLibrary
!= NULL
)
673 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" );
677 for ( i
= 0; i
< resource_files
.size(); i
++ )
679 const string
& resource_file
= resource_files
[i
];
681 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() );
682 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() );
684 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() );
685 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() );
692 if (IsWineModule( module
))
693 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());
694 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" );
695 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"%s\\tools\\pefixup $exe_output -exports\" />\r\n", outdir
.c_str() );
697 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"cmd /c del %s.temp.exp 2>NUL\" />\r\n", module
.name
.c_str() );
699 fprintf ( OUT
, "\t\t\t\t\t<Add after=\"rm %s.temp.exp 2>/dev/null\" />\r\n", module
.name
.c_str() );
701 fprintf ( OUT
, "\t\t\t\t\t<Mode after=\"always\" />\r\n" );
705 fprintf ( OUT
, "\t\t\t\t</ExtraCommands>\r\n" );
707 fprintf ( OUT
, "\t\t\t</Target>\r\n" );
712 fprintf ( OUT, "\t\t\t<Environment>\r\n" );
713 for ( i = 0; i < vars.size(); i++ )
715 const string& var = vars[i];
716 const string& value = values[i];
717 fprintf ( OUT, "\t\t\t\t<Variable name=\"%s\" value=\"%s\" />\r\n", var.c_str(), value.c_str() );
719 fprintf ( OUT, "\t\t\t</Environment>\r\n" ); */
721 fprintf ( OUT
, "\t\t</Build>\r\n" );
726 if ( module
.cplusplus
)
733 for ( i
= 0; i
< header_files
.size(); i
++ )
735 const string
& header_file
= header_files
[i
];
736 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", header_file
.c_str() );
737 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
738 fprintf ( OUT
, "\t\t\t<Option compile=\"0\" />\r\n" );
739 fprintf ( OUT
, "\t\t\t<Option link=\"0\" />\r\n" );
740 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
742 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
743 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
745 fprintf ( OUT
, "\t\t</Unit>\r\n" );
749 for ( size_t isrcfile
= 0; isrcfile
< source_files
.size(); isrcfile
++ )
751 string source_file
= DosSeparator(source_files
[isrcfile
]);
752 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", source_file
.c_str() );
753 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"%s\" />\r\n", CompilerVar
.c_str() );
755 string extension
= GetExtension ( source_file
);
756 if ( extension
== ".s" || extension
== ".S" )
758 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
759 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
760 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" );
762 else if ( extension
== ".asm" || extension
== ".ASM" )
764 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
765 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
766 fprintf ( OUT
, "\t\t\t<Option compiler=\"gcc\" use=\"1\" buildCommand=\"nasm -f win32 $file -o $link_objects\" />\r\n" );
768 else if ( extension
== ".idl" || extension
== ".IDL" )
770 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
771 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() );
773 else if ( extension
== ".spec" || extension
== ".SPEC" )
775 fprintf ( OUT
, "\t\t\t<Option compile=\"1\" />\r\n" );
776 fprintf ( OUT
, "\t\t\t<Option link=\"1\" />\r\n" );
777 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() );
780 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
782 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
783 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
785 fprintf ( OUT
, "\t\t</Unit>\r\n" );
789 for ( i
= 0; i
< resource_files
.size(); i
++ )
791 const string
& resource_file
= resource_files
[i
];
792 fprintf ( OUT
, "\t\t<Unit filename=\"%s\">\r\n", resource_file
.c_str() );
793 fprintf ( OUT
, "\t\t\t<Option compilerVar=\"WINDRES\" />\r\n" );
794 string extension
= GetExtension ( resource_file
);
795 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() );
796 for ( size_t icfg
= 0; icfg
< m_configurations
.size(); icfg
++ )
798 const CBConfiguration
& cfg
= *m_configurations
[icfg
];
799 fprintf ( OUT
, "\t\t\t<Option target=\"%s\" />\r\n" , cfg
.name
.c_str() );
801 fprintf ( OUT
, "\t\t</Unit>\r\n" );
804 fprintf ( OUT
, "\t\t<Extensions />\r\n" );
805 fprintf ( OUT
, "\t</Project>\r\n" );
806 fprintf ( OUT
, "</CodeBlocks_project_file>\r\n" );
812 CBConfiguration::CBConfiguration ( const OptimizationType optimization
, const std::string
&name
)
814 this->optimization
= optimization
;
819 if ( optimization
== Debug
)
820 this->name
= "Debug";
821 else if ( optimization
== Release
)
822 this->name
= "Release";
824 this->name
= "Unknown";
829 CBBackend::_replace_str(std::string string1
, const std::string
&find_str
, const std::string
&replace_str
)
831 std::string::size_type pos
= string1
.find(find_str
, 0);
832 int intLen
= find_str
.length();
834 while(std::string::npos
!= pos
)
836 string1
.replace(pos
, intLen
, replace_str
);
837 pos
= string1
.find(find_str
, intLen
+ pos
);
844 CBBackend::GenerateProjectLinkerFlags() const
847 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
849 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
850 if ( lflags
.length () > 0 )
852 lflags
+= linkerFlag
.flag
;
858 CBBackend::MingwAddImplicitLibraries( Module
&module
)
862 if ( !module
.isDefaultEntryPoint
)
865 if ( module
.IsDLL () )
867 //pLibrary = new Library ( module, "__mingw_dllmain" );
868 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
872 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
873 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
876 pLibrary
= new Library ( module
, "mingw_common" );
877 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
879 if ( module
.name
!= "msvcrt" )
881 // always link in msvcrt to get the basic routines
882 pLibrary
= new Library ( module
, "msvcrt" );
883 module
.non_if_data
.libraries
.push_back ( pLibrary
);
888 CBBackend::_lookup_property ( const Module
& module
, const std::string
& name
) const
890 /* Check local values */
891 for ( size_t i
= 0; i
< module
.non_if_data
.properties
.size(); i
++ )
893 const Property
& property
= *module
.non_if_data
.properties
[i
];
894 if ( property
.name
== name
)
897 // TODO FIXME - should we check local if-ed properties?
898 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size(); i
++ )
900 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
901 if ( property
.name
== name
)
904 // TODO FIXME - should we check global if-ed properties?
909 CBBackend::IsWineModule ( const Module
& module
) const
911 if ( module
.importLibrary
== NULL
)
914 size_t index
= module
.importLibrary
->source
->name
.rfind ( ".spec.def" );
915 return ( index
!= string::npos
);