2 * Copyright (C) 2005 Trevor McCort
3 * Copyright (C) 2005 Casper S. Hornstrup
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #pragma warning ( disable : 4786 )
31 static class DevCppFactory
: public Backend::Factory
35 DevCppFactory() : Factory("devcpp", "Dev C++") {}
36 Backend
*operator() (Project
&project
,
37 Configuration
& configuration
)
39 return new DevCppBackend(project
, configuration
);
45 DevCppBackend::DevCppBackend(Project
&project
,
46 Configuration
& configuration
) : Backend(project
, configuration
)
51 void DevCppBackend::Process()
53 string filename
= ProjectNode
.name
+ ".dev";
55 cout
<< "Creating Dev-C++ project: " << filename
<< endl
;
59 m_devFile
.open(filename
.c_str());
61 if(!m_devFile
.is_open())
63 cout
<< "Could not open file." << endl
;
67 m_devFile
<< "[Project]" << endl
;
69 m_devFile
<< "FileName=" << filename
<< endl
70 << "Name=" << ProjectNode
.name
<< endl
71 << "UnitCount=" << m_unitCount
<< endl
74 << "ObjFiles=" << endl
75 << "Includes=" << endl
77 << "PrivateResource=" << endl
78 << "ResourceIncludes=" << endl
79 << "MakeIncludes=" << endl
80 << "Compiler=" << endl
81 << "CppCompiler=" << endl
85 << "ExeOutput=" << endl
86 << "ObjectOutput=" << endl
87 << "OverrideOutput=0" << endl
88 << "OverrideOutputName=" << endl
89 << "HostApplication=" << endl
90 << "CommandLine=" << endl
91 << "UseCustomMakefile=1" << endl
92 << "CustomMakefile=" << ProjectNode
.makefile
<< endl
93 << "IncludeVersionInto=0" << endl
94 << "SupportXPThemes=0" << endl
95 << "CompilerSet=0" << endl
97 << "CompilerSettings=0000000000000000000000" << endl
;
101 m_devFile
<< endl
<< endl
;
107 // Dev-C++ needs a makefile, so use the MinGW backend to create one.
109 cout
<< "Creating Makefile: " << ProjectNode
.makefile
<< endl
;
111 Backend
*backend
= Backend::Factory::Create("mingw",
117 cout
<< "Done." << endl
<< endl
;
119 cout
<< "You may want to disable Class browsing (see below) before you open this project in Dev-C++, as the "
120 << "parsing required for large projects can take quite awhile."
122 << "(Tools->Editor Options->Class browsing->Enable class browsing check box)"
126 void DevCppBackend::ProcessModules()
128 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
130 Module
&module
= *ProjectNode
.modules
[i
];
132 for(size_t k
= 0; k
< module
.non_if_data
.files
.size(); k
++)
134 File
&file
= *module
.non_if_data
.files
[k
];
136 ProcessFile(file
.name
);
141 bool FileExists(string
&filename
)
143 ifstream
file(filename
.c_str());
152 void DevCppBackend::ProcessFile(string
&filepath
)
154 // Remove the .\ at the start of the filenames
155 if ((filepath
[0] == '.') && (filepath
[1] == '\\')) filepath
.erase(0, 2);
157 if(!FileExists(filepath
))
162 for(size_t i
= 0; i
< filepath
.length(); i
++)
164 if(filepath
[i
] == '/')
169 // Remove the filename from the path
172 size_t pos
= filepath
.rfind(string("\\"), filepath
.length() - 1);
174 if(pos
!= string::npos
)
177 folder
.erase(pos
, folder
.length() - pos
);
181 fileUnit
.filename
= filepath
;
182 fileUnit
.folder
= folder
;
184 m_fileUnits
.push_back(fileUnit
);
192 bool DevCppBackend::CheckFolderAdded(string
&folder
)
194 for(size_t i
= 0; i
< m_folders
.size(); i
++)
196 if(m_folders
[i
] == folder
)
203 void DevCppBackend::AddFolders(string
&folder
)
205 // Check if this folder was already added. true if it was, false otherwise.
206 if(CheckFolderAdded(folder
))
209 m_folders
.push_back(folder
);
211 size_t pos
= folder
.rfind(string("\\"), folder
.length() - 1);
213 if(pos
== string::npos
)
216 folder
.erase(pos
, folder
.length() - pos
);
220 void DevCppBackend::OutputFolders()
222 m_devFile
<< "Folders=";
224 for(size_t i
= 0; i
< m_folders
.size(); i
++)
229 m_devFile
<< m_folders
[i
];
233 void DevCppBackend::OutputFileUnits()
235 for(size_t i
= 0; i
< m_fileUnits
.size(); i
++)
237 m_devFile
<< "[Unit" << i
+ 1 << "]" << endl
;
240 m_devFile
<< "FileName=" << m_fileUnits
[i
].filename
<< endl
;
241 m_devFile
<< "CompileCpp=1" << endl
;
242 m_devFile
<< "Folder=" << m_fileUnits
[i
].folder
<< endl
;
243 m_devFile
<< "Compile=1" << endl
;
244 m_devFile
<< "Link=1" << endl
;
245 m_devFile
<< "Priority=1000" << endl
;
246 m_devFile
<< "OverrideBuildCmd=0" << endl
;
247 m_devFile
<< "BuildCmd=" << endl
<< endl
;;