3 * Copyright (C) 2005 Trevor McCort
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #pragma warning ( disable : 4786 )
32 static class DevCppFactory
: public Backend::Factory
36 DevCppFactory() : Factory("devcpp") {}
37 Backend
*operator() (Project
&project
, bool verbose
)
39 return new DevCppBackend(project
, verbose
);
45 DevCppBackend::DevCppBackend(Project
&project
, bool verbose
) : Backend(project
, verbose
)
50 void DevCppBackend::Process()
52 string filename
= ProjectNode
.name
+ ".dev";
54 cout
<< "Creating Dev-C++ project: " << filename
<< endl
;
58 m_devFile
.open(filename
.c_str());
60 if(!m_devFile
.is_open())
62 cout
<< "Could not open file." << endl
;
66 m_devFile
<< "[Project]" << endl
;
68 m_devFile
<< "FileName=" << filename
<< endl
69 << "Name=" << ProjectNode
.name
<< endl
70 << "UnitCount=" << m_unitCount
<< endl
73 << "ObjFiles=" << endl
74 << "Includes=" << endl
76 << "PrivateResource=" << endl
77 << "ResourceIncludes=" << endl
78 << "MakeIncludes=" << endl
79 << "Compiler=" << endl
80 << "CppCompiler=" << endl
84 << "ExeOutput=" << endl
85 << "ObjectOutput=" << endl
86 << "OverrideOutput=0" << endl
87 << "OverrideOutputName=" << endl
88 << "HostApplication=" << endl
89 << "CommandLine=" << endl
90 << "UseCustomMakefile=1" << endl
91 << "CustomMakefile=" << ProjectNode
.makefile
<< endl
92 << "IncludeVersionInto=0" << endl
93 << "SupportXPThemes=0" << endl
94 << "CompilerSet=0" << endl
96 << "CompilerSettings=0000000000000000000000" << endl
;
100 m_devFile
<< endl
<< endl
;
106 // Dev-C++ needs a makefile, so use the MinGW backend to create one.
108 cout
<< "Creating Makefile: " << ProjectNode
.makefile
<< endl
;
110 Backend
*backend
= Backend::Factory::Create("mingw", ProjectNode
, verbose
);
114 cout
<< "Done." << endl
<< endl
;
116 cout
<< "You may want to disable Class browsing (see below) before you open this project in Dev-C++, as the "
117 << "parsing required for large projects can take quite awhile."
119 << "(Tools->Editor Options->Class browsing->Enable class browsing check box)"
123 void DevCppBackend::ProcessModules()
125 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
127 Module
&module
= *ProjectNode
.modules
[i
];
129 for(size_t k
= 0; k
< module
.non_if_data
.files
.size(); k
++)
131 File
&file
= *module
.non_if_data
.files
[k
];
133 ProcessFile(file
.name
);
138 bool FileExists(string
&filename
)
140 ifstream
file(filename
.c_str());
149 void DevCppBackend::ProcessFile(string
&filepath
)
151 // Remove the .\ at the start of the filenames
152 filepath
.erase(0, 2);
154 if(!FileExists(filepath
))
158 for(size_t i
= 0; i
< filepath
.length(); i
++)
160 if(filepath
[i
] == '\\')
164 // Remove the filename from the path
167 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
169 if(pos
!= string::npos
)
172 folder
.erase(pos
, folder
.length() - pos
);
176 fileUnit
.filename
= filepath
;
177 fileUnit
.folder
= folder
;
179 m_fileUnits
.push_back(fileUnit
);
187 bool DevCppBackend::CheckFolderAdded(string
&folder
)
189 for(size_t i
= 0; i
< m_folders
.size(); i
++)
191 if(m_folders
[i
] == folder
)
198 void DevCppBackend::AddFolders(string
&folder
)
200 // Check if this folder was already added. true if it was, false otherwise.
201 if(CheckFolderAdded(folder
))
204 m_folders
.push_back(folder
);
206 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
208 if(pos
== string::npos
)
211 folder
.erase(pos
, folder
.length() - pos
);
215 void DevCppBackend::OutputFolders()
217 m_devFile
<< "Folders=";
219 for(size_t i
= 0; i
< m_folders
.size(); i
++)
224 m_devFile
<< m_folders
[i
];
228 void DevCppBackend::OutputFileUnits()
230 for(size_t i
= 0; i
< m_fileUnits
.size(); i
++)
232 m_devFile
<< "[Unit" << i
+ 1 << "]" << endl
;
235 m_devFile
<< "FileName=" << m_fileUnits
[i
].filename
<< endl
;
236 m_devFile
<< "CompileCpp=1" << endl
;
237 m_devFile
<< "Folder=" << m_fileUnits
[i
].folder
<< endl
;
238 m_devFile
<< "Compile=1" << endl
;
239 m_devFile
<< "Link=1" << endl
;
240 m_devFile
<< "Priority=1000" << endl
;
241 m_devFile
<< "OverrideBuildCmd=0" << endl
;
242 m_devFile
<< "BuildCmd=" << endl
<< endl
;;