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.
28 static class DevCppFactory
: public Backend::Factory
32 DevCppFactory() : Factory("devcpp") {}
33 Backend
*operator() (Project
&project
)
35 return new DevCppBackend(project
);
41 DevCppBackend::DevCppBackend(Project
&project
) : Backend(project
)
46 void DevCppBackend::Process()
48 string filename
= ProjectNode
.name
+ ".dev";
50 cout
<< "Creating Dev-C++ project: " << filename
<< endl
;
54 m_devFile
.open(filename
.c_str());
56 if(!m_devFile
.is_open())
58 cout
<< "Could not open file." << endl
;
62 m_devFile
<< "[Project]" << endl
;
64 m_devFile
<< "FileName=" << filename
<< endl
65 << "Name=" << ProjectNode
.name
<< endl
66 << "UnitCount=" << m_unitCount
<< endl
69 << "ObjFiles=" << endl
70 << "Includes=" << endl
72 << "PrivateResource=" << endl
73 << "ResourceIncludes=" << endl
74 << "MakeIncludes=" << endl
75 << "Compiler=" << endl
76 << "CppCompiler=" << endl
80 << "ExeOutput=" << endl
81 << "ObjectOutput=" << endl
82 << "OverrideOutput=0" << endl
83 << "OverrideOutputName=" << endl
84 << "HostApplication=" << endl
85 << "CommandLine=" << endl
86 << "UseCustomMakefile=1" << endl
87 << "CustomMakefile=" << ProjectNode
.makefile
<< endl
88 << "IncludeVersionInto=0" << endl
89 << "SupportXPThemes=0" << endl
90 << "CompilerSet=0" << endl
92 << "CompilerSettings=0000000000000000000000" << endl
;
96 m_devFile
<< endl
<< endl
;
102 // Dev-C++ needs a makefile, so use the MinGW backend to create one.
104 cout
<< "Creating Makefile: " << ProjectNode
.makefile
<< endl
;
106 Backend
*backend
= Backend::Factory::Create("mingw", ProjectNode
);
110 cout
<< "Done." << endl
<< endl
;
112 cout
<< "You may want to disable Class browsing (see below) before you open this project in Dev-C++, as the "
113 << "parsing required for large projects can take quite awhile."
115 << "(Tools->Editor Options->Class browsing->Enable class browsing check box)"
119 void DevCppBackend::ProcessModules()
121 for(size_t i
= 0; i
< ProjectNode
.modules
.size(); i
++)
123 Module
&module
= *ProjectNode
.modules
[i
];
125 for(size_t k
= 0; k
< module
.files
.size(); k
++)
127 File
&file
= *module
.files
[k
];
129 ProcessFile(file
.name
);
134 bool FileExists(string
&filename
)
136 ifstream
file(filename
.c_str());
145 void DevCppBackend::ProcessFile(string
&filepath
)
147 // Remove the .\ at the start of the filenames
148 filepath
.erase(0, 2);
150 if(!FileExists(filepath
))
154 for(size_t i
= 0; i
< filepath
.length(); i
++)
156 if(filepath
[i
] == '\\')
160 // Remove the filename from the path
163 size_t pos
= filepath
.rfind(string("/"), filepath
.length() - 1);
165 if(pos
!= string::npos
)
168 folder
.erase(pos
, folder
.length() - pos
);
172 fileUnit
.filename
= filepath
;
173 fileUnit
.folder
= folder
;
175 m_fileUnits
.push_back(fileUnit
);
183 bool DevCppBackend::CheckFolderAdded(string
&folder
)
185 for(size_t i
= 0; i
< m_folders
.size(); i
++)
187 if(m_folders
[i
] == folder
)
194 void DevCppBackend::AddFolders(string
&folder
)
196 // Check if this folder was already added. true if it was, false otherwise.
197 if(CheckFolderAdded(folder
))
200 m_folders
.push_back(folder
);
202 size_t pos
= folder
.rfind(string("/"), folder
.length() - 1);
204 if(pos
== string::npos
)
207 folder
.erase(pos
, folder
.length() - pos
);
211 void DevCppBackend::OutputFolders()
213 m_devFile
<< "Folders=";
215 for(size_t i
= 0; i
< m_folders
.size(); i
++)
220 m_devFile
<< m_folders
[i
];
224 void DevCppBackend::OutputFileUnits()
226 for(size_t i
= 0; i
< m_fileUnits
.size(); i
++)
228 m_devFile
<< "[Unit" << i
+ 1 << "]" << endl
;
231 m_devFile
<< "FileName=" << m_fileUnits
[i
].filename
<< endl
;
232 m_devFile
<< "CompileCpp=1" << endl
;
233 m_devFile
<< "Folder=" << m_fileUnits
[i
].folder
<< endl
;
234 m_devFile
<< "Compile=1" << endl
;
235 m_devFile
<< "Link=1" << endl
;
236 m_devFile
<< "Priority=1000" << endl
;
237 m_devFile
<< "OverrideBuildCmd=0" << endl
;
238 m_devFile
<< "BuildCmd=" << endl
<< endl
;;