source: trunk/qmake/generators/win32/mingw_make.cpp

Last change on this file was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 30.7 KB
Line 
1/****************************************************************************
2** $Id: mingw_make.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of MingwMakefileGenerator class.
5**
6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
7**
8** This file is part of qmake.
9**
10** This file may be distributed under the terms of the Q Public License
11** as defined by Trolltech AS of Norway and appearing in the file
12** LICENSE.QPL included in the packaging of this file.
13**
14** This file may be distributed and/or modified under the terms of the
15** GNU General Public License version 2 as published by the Free Software
16** Foundation and appearing in the file LICENSE.GPL included in the
17** packaging of this file.
18**
19** Licensees holding valid Qt Enterprise Edition licenses may use this
20** file in accordance with the Qt Commercial License Agreement provided
21** with the Software.
22**
23** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
24** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
25**
26** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
27** information about Qt Commercial License Agreements.
28** See http://www.trolltech.com/qpl/ for QPL licensing information.
29** See http://www.trolltech.com/gpl/ for GPL licensing information.
30**
31** Contact info@trolltech.com if any conditions of this licensing are
32** not clear to you.
33**
34**********************************************************************/
35
36#include "mingw_make.h"
37#include "option.h"
38#include <qregexp.h>
39#include <qdir.h>
40#include <stdlib.h>
41#include <time.h>
42
43
44MingwMakefileGenerator::MingwMakefileGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE)
45{
46 Option::obj_ext = ".o";
47}
48
49bool
50MingwMakefileGenerator::findLibraries() // todo - pascal
51{
52 return TRUE;
53}
54
55bool
56MingwMakefileGenerator::writeMakefile(QTextStream &t)
57{
58 writeHeader(t);
59 if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
60 t << "all clean:" << "\n\t"
61 << "@echo \"Some of the required modules ("
62 << var("QMAKE_FAILED_REQUIREMENTS") << ") are not available.\"" << "\n\t"
63 << "@echo \"Skipped.\"" << endl << endl;
64 writeMakeQmake(t);
65 return TRUE;
66 }
67
68 if(project->first("TEMPLATE") == "app" ||
69 project->first("TEMPLATE") == "lib") {
70 writeMingwParts(t);
71 return MakefileGenerator::writeMakefile(t);
72 }
73 else if(project->first("TEMPLATE") == "subdirs") {
74 writeSubDirs(t);
75 return TRUE;
76 }
77 return FALSE;
78 }
79
80void createLdObjectScriptFile(const QString & fileName, QStringList & objList)
81{
82 QString filePath = Option::output_dir + QDir::separator() + fileName;
83 QFile file(filePath);
84 if (file.open(IO_WriteOnly | IO_Translate )) {
85 QTextStream t(&file);
86 t << "INPUT(" << endl;
87 for (QStringList::Iterator it = objList.begin(); it != objList.end(); ++it ) {
88 t << *it << endl;
89 }
90 t << ");" << endl;
91 file.close();
92 }
93}
94
95void
96MingwMakefileGenerator::writeMingwParts(QTextStream &t)
97{
98 t << "####### Compiler, tools and options" << endl << endl;
99 t << "CC = " << var("QMAKE_CC") << endl;
100 t << "CXX = " << var("QMAKE_CXX") << endl;
101 t << "LEX = " << var("QMAKE_LEX") << endl;
102 t << "YACC = " << var("QMAKE_YACC") << endl;
103 t << "CFLAGS = " << var("QMAKE_CFLAGS") << " "
104 << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " "
105 << varGlue("DEFINES","-D"," -D","") << endl;
106 t << "CXXFLAGS = " << var("QMAKE_CXXFLAGS") << " "
107 << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " "
108 << varGlue("DEFINES","-D"," -D","") << endl;
109 t << "LEXFLAGS =" << var("QMAKE_LEXFLAGS") << endl;
110 t << "YACCFLAGS =" << var("QMAKE_YACCFLAGS") << endl;
111
112 t << "INCPATH = ";
113 QStringList &incs = project->variables()["INCLUDEPATH"];
114 for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
115 QString inc = (*incit);
116 inc.replace(QRegExp("\\\\$"), "\\\\");
117 inc.replace(QRegExp("\""), "");
118 t << " -I" << "\"" << inc << "\"";
119 }
120 t << " -I" << "\"" << specdir() << "\"" << endl;
121 if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) {
122 t << "LINK = " << var("QMAKE_LINK") << endl;
123 t << "LFLAGS = " << var("QMAKE_LFLAGS") << endl;
124 t << "LIBS = ";
125 if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() )
126 t << varGlue("QMAKE_LIBDIR","-L\"","\" -L\"","\"") << " ";
127 t << var("QMAKE_LIBS").replace(QRegExp("(\\slib|^lib)")," -l") << endl;
128 }
129 else {
130 t << "LIB = " << var("QMAKE_LIB") << endl;
131 }
132 t << "MOC = " << (project->isEmpty("QMAKE_MOC") ? QString("moc") :
133 Option::fixPathToTargetOS(var("QMAKE_MOC"), FALSE)) << endl;
134 t << "UIC = " << (project->isEmpty("QMAKE_UIC") ? QString("uic") :
135 Option::fixPathToTargetOS(var("QMAKE_UIC"), FALSE)) << endl;
136 t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") :
137 Option::fixPathToTargetOS(var("QMAKE_QMAKE"), FALSE)) << endl;
138 t << "IDC = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
139 Option::fixPathToTargetOS(var("QMAKE_IDC"), FALSE)) << endl;
140 t << "IDL = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
141 Option::fixPathToTargetOS(var("QMAKE_IDL"), FALSE)) << endl;
142 t << "ZIP = " << var("QMAKE_ZIP") << endl;
143 t << "DEF_FILE = " << varList("DEF_FILE") << endl;
144 t << "COPY_FILE = " << var("QMAKE_COPY") << endl;
145 t << "COPY_DIR = " << var("QMAKE_COPY") << endl;
146 t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl;
147 t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl;
148 t << "MOVE = " << var("QMAKE_MOVE") << endl;
149 t << "CHK_DIR_EXISTS = " << var("QMAKE_CHK_DIR_EXISTS") << endl;
150 t << "MKDIR = " << var("QMAKE_MKDIR") << endl;
151 t << endl;
152
153 t << "####### Output directory" << endl << endl;
154 if (! project->variables()["OBJECTS_DIR"].isEmpty())
155 t << "OBJECTS_DIR = " << var("OBJECTS_DIR").replace(QRegExp("\\\\$"),"") << endl;
156 else
157 t << "OBJECTS_DIR = . " << endl;
158 if (! project->variables()["MOC_DIR"].isEmpty())
159 t << "MOC_DIR = " << var("MOC_DIR").replace(QRegExp("\\\\$"),"") << endl;
160 else
161 t << "MOC_DIR = . " << endl;
162 t << endl;
163
164 t << "####### Files" << endl << endl;
165 t << "HEADERS = " << varList("HEADERS") << endl;
166 t << "SOURCES = " << varList("SOURCES") << endl;
167 QString objectsLinkLine;
168 if (!project->variables()["QMAKE_APP_OR_DLL"].isEmpty() &&
169 project->variables()["OBJECTS"].count() > var("QMAKE_LINK_OBJECT_MAX").toUInt()) {
170 createLdObjectScriptFile(var("QMAKE_LINK_OBJECT_SCRIPT"), project->variables()["OBJECTS"]);
171 objectsLinkLine = var("QMAKE_LINK_OBJECT_SCRIPT");
172 } else {
173 objectsLinkLine = "$(OBJECTS)";
174 }
175 t << "OBJECTS = " << varList("OBJECTS") << endl;
176 t << "FORMS = " << varList("FORMS") << endl;
177 t << "UICDECLS = " << varList("UICDECLS") << endl;
178 t << "UICIMPLS = " << varList("UICIMPLS") << endl;
179 t << "SRCMOC = " << varList("SRCMOC") << endl;
180 QString objmocLinkLine;
181 if (!project->variables()["QMAKE_APP_OR_DLL"].isEmpty() &&
182 project->variables()["OBJMOC"].count() > var("QMAKE_LINK_OBJECT_MAX").toUInt()) {
183 createLdObjectScriptFile(var("QMAKE_LINK_OBJMOC_SCRIPT"), project->variables()["OBJMOC"]);
184 objmocLinkLine = var("QMAKE_LINK_OBJMOC_SCRIPT");
185 } else {
186 objmocLinkLine = "$(OBJMOC)";
187 }
188 t << "OBJMOC = " << varList("OBJMOC") << endl;
189 QString extraCompilerDeps;
190 if(!project->isEmpty("QMAKE_EXTRA_WIN_COMPILERS")) {
191 t << "OBJCOMP = " << varList("OBJCOMP") << endl;
192 extraCompilerDeps += " $(OBJCOMP) ";
193
194 QStringList &comps = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
195 for(QStringList::Iterator compit = comps.begin(); compit != comps.end(); ++compit) {
196 QStringList &vars = project->variables()[(*compit) + ".variables"];
197 for(QStringList::Iterator varit = vars.begin(); varit != vars.end(); ++varit) {
198 QStringList vals = project->variables()[(*varit)];
199 if(!vals.isEmpty())
200 t << "QMAKE_COMP_" << (*varit) << " = " << valList(vals) << endl;
201 }
202 }
203 }
204
205 t << "DIST = " << varList("DISTFILES") << endl;
206 t << "TARGET = ";
207 if( !project->variables()[ "DESTDIR" ].isEmpty() )
208 t << varGlue("TARGET",project->first("DESTDIR"),"",project->first("TARGET_EXT"));
209 else
210 t << project->variables()[ "TARGET" ].first() << project->variables()[ "TARGET_EXT" ].first();
211 t << endl;
212 t << endl;
213
214 t << "####### Implicit rules" << endl << endl;
215 t << ".SUFFIXES: .cpp .cxx .cc .C .c" << endl << endl;
216 t << ".cpp.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
217 t << ".cxx.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
218 t << ".cc.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
219 t << ".C.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
220 t << ".c.o:\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
221
222 t << "####### Build rules" << endl << endl;
223 t << "all: " << "$(OBJECTS_DIR) " << "$(MOC_DIR) " << varGlue("ALL_DEPS",""," "," ") << "$(TARGET)" << endl << endl;
224 t << "$(TARGET): " << var("PRE_TARGETDEPS") << " $(UICDECLS) $(OBJECTS) $(OBJMOC) "
225 << extraCompilerDeps << var("POST_TARGETDEPS");
226 if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) {
227 t << "\n\t" << "$(LINK) $(LFLAGS) -o $(TARGET) " << objectsLinkLine << " " << objmocLinkLine << " $(LIBS)";
228 } else {
229 t << "\n\t" << "$(LIB) $(TARGET) " << objectsLinkLine << " " << objmocLinkLine;
230 }
231 t << extraCompilerDeps;
232 if(project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty()) {
233 QStringList dlldirs = project->variables()["DLLDESTDIR"];
234 for ( QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) {
235 t << "\n\t" << "$(COPY_FILE) $(TARGET) " << *dlldir;
236 }
237 }
238 QString targetfilename = project->variables()["TARGET"].first();
239 if(project->isActiveConfig("activeqt")) {
240 QString version = project->variables()["VERSION"].first();
241 if ( version.isEmpty() )
242 version = "1.0";
243
244 if ( project->isActiveConfig("dll")) {
245 t << "\n\t" << ("-$(IDC) $(TARGET) /idl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version);
246 t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
247 t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
248 t << "\n\t" << ("-$(IDC) $(TARGET) /regserver" );
249 } else {
250 t << "\n\t" << ("-$(TARGET) -dumpidl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version);
251 t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
252 t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
253 t << "\n\t" << "-$(TARGET) -regserver";
254 }
255 }
256 t << endl << endl;
257
258 if(!project->variables()["RC_FILE"].isEmpty()) {
259 t << var("RES_FILE") << ": " << var("RC_FILE") << "\n\t"
260 << var("QMAKE_RC") << " -i " << var("RC_FILE") << " -o " << var("RC_FILE").replace(QRegExp("\\.rc"),".o") << " --include-dir=" << QFileInfo(var("RC_FILE")).dirPath() << endl << endl;
261 }
262 project->variables()["RES_FILE"].first().replace(QRegExp("\\.rc"),".o");
263
264 t << "mocables: $(SRCMOC)" << endl << endl;
265
266 t << "$(OBJECTS_DIR):" << "\n\t"
267 << "@if not exist $(OBJECTS_DIR) $(MKDIR) $(OBJECTS_DIR)" << endl << endl;
268
269 t << "$(MOC_DIR):" << "\n\t"
270 << "@if not exist $(MOC_DIR) $(MKDIR) $(MOC_DIR)" << endl << endl;
271
272 writeMakeQmake(t);
273
274 t << "dist:" << "\n\t"
275 << "$(ZIP) " << var("PROJECT") << ".zip "
276 << var("PROJECT") << ".pro $(SOURCES) $(HEADERS) $(DIST) $(FORMS)" << endl << endl;
277
278 t << "clean:"
279 << varGlue("OBJECTS","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","").replace(QRegExp("\\.obj"),".o")
280 << varGlue("SRCMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
281 << varGlue("OBJMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","").replace(QRegExp("\\.obj"),".o")
282 << varGlue("UICDECLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
283 << varGlue("UICIMPLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
284 << "\n\t-$(DEL_FILE) $(TARGET)"
285 << varGlue("QMAKE_CLEAN","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
286 << varGlue("CLEAN_FILES","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","");
287 if ( project->isActiveConfig("activeqt")) {
288 t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".idl");
289 t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".tlb");
290 }
291 if(!project->isEmpty("IMAGES"))
292 t << varGlue("QMAKE_IMAGE_COLLECTION", "\n\t-$(DEL_FILE) ", "\n\t-$(DEL_FILE) ", "");
293
294 // user defined targets
295 QStringList::Iterator it;
296 QStringList &qut = project->variables()["QMAKE_EXTRA_WIN_TARGETS"];
297
298 for(it = qut.begin(); it != qut.end(); ++it) {
299 QString targ = var((*it) + ".target"),
300 cmd = var((*it) + ".commands"), deps;
301 if(targ.isEmpty())
302 targ = (*it);
303 QStringList &deplist = project->variables()[(*it) + ".depends"];
304 for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) {
305 QString dep = var((*dep_it) + ".target");
306 if(dep.isEmpty())
307 dep = (*dep_it);
308 deps += " " + dep;
309 }
310 t << "\n\n" << targ << ":" << deps << "\n\t"
311 << cmd;
312 }
313
314 t << endl << endl;
315
316 QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
317 for(it = quc.begin(); it != quc.end(); ++it) {
318 QString tmp_out = project->variables()[(*it) + ".output"].first();
319 QString tmp_cmd = project->variables()[(*it) + ".commands"].join(" ");
320 QString tmp_dep = project->variables()[(*it) + ".depends"].join(" ");
321 QStringList &vars = project->variables()[(*it) + ".variables"];
322 if(tmp_out.isEmpty() || tmp_cmd.isEmpty())
323 continue;
324 QStringList &tmp = project->variables()[(*it) + ".input"];
325 for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
326 QStringList &inputs = project->variables()[(*it2)];
327 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
328 QFileInfo fi(Option::fixPathToLocalOS((*input)));
329 QString in = Option::fixPathToTargetOS((*input), FALSE),
330 out = tmp_out, cmd = tmp_cmd, deps;
331 out.replace("${QMAKE_FILE_BASE}", fi.baseName());
332 out.replace("${QMAKE_FILE_NAME}", fi.fileName());
333 cmd.replace("${QMAKE_FILE_BASE}", fi.baseName());
334 cmd.replace("${QMAKE_FILE_OUT}", out);
335 cmd.replace("${QMAKE_FILE_NAME}", fi.fileName());
336 for(QStringList::Iterator it3 = vars.begin(); it3 != vars.end(); ++it3)
337 cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")");
338 if(!tmp_dep.isEmpty()) {
339 char buff[256];
340 QString dep_cmd = tmp_dep;
341 dep_cmd.replace("${QMAKE_FILE_NAME}", fi.fileName());
342 if(FILE *proc = QT_POPEN(dep_cmd.latin1(), "r")) {
343 while(!feof(proc)) {
344 int read_in = fread(buff, 1, 255, proc);
345 if(!read_in)
346 break;
347 int l = 0;
348 for(int i = 0; i < read_in; i++) {
349 if(buff[i] == '\n' || buff[i] == ' ') {
350 deps += " " + QCString(buff+l, (i - l) + 1);
351 l = i;
352 }
353 }
354 }
355 fclose(proc);
356 }
357 }
358 t << out << ": " << in << deps << "\n\t"
359 << cmd << endl << endl;
360 }
361 }
362 }
363 t << endl;
364}
365
366
367void
368MingwMakefileGenerator::init()
369{
370 if(init_flag)
371 return;
372 init_flag = TRUE;
373
374 /* this should probably not be here, but I'm using it to wrap the .t files */
375 if(project->first("TEMPLATE") == "app")
376 project->variables()["QMAKE_APP_FLAG"].append("1");
377 else if(project->first("TEMPLATE") == "lib")
378 project->variables()["QMAKE_LIB_FLAG"].append("1");
379 else if(project->first("TEMPLATE") == "subdirs") {
380 MakefileGenerator::init();
381 if(project->variables()["MAKEFILE"].isEmpty())
382 project->variables()["MAKEFILE"].append("Makefile");
383 if(project->variables()["QMAKE"].isEmpty())
384 project->variables()["QMAKE"].append("qmake");
385 return;
386 }
387
388 bool is_qt = (project->first("TARGET") == "qt"QTDLL_POSTFIX || project->first("TARGET") == "qt-mt"QTDLL_POSTFIX);
389 project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
390
391 // LIBS defined in Profile comes first for gcc
392 project->variables()["QMAKE_LIBS"] += project->variables()["LIBS"];
393
394 QString targetfilename = project->variables()["TARGET"].first();
395 QStringList &configs = project->variables()["CONFIG"];
396
397 if (project->isActiveConfig("qt") && project->isActiveConfig("shared"))
398 project->variables()["DEFINES"].append("QT_DLL");
399
400 if (project->isActiveConfig("qt_dll"))
401 if (configs.findIndex("qt") == -1)
402 configs.append("qt");
403
404 if ( project->isActiveConfig("qt") ) {
405 if ( project->isActiveConfig( "plugin" ) ) {
406 project->variables()["CONFIG"].append("dll");
407 if(project->isActiveConfig("qt"))
408 project->variables()["DEFINES"].append("QT_PLUGIN");
409 }
410 if ( (project->variables()["DEFINES"].findIndex("QT_NODLL") == -1) &&
411 ((project->variables()["DEFINES"].findIndex("QT_MAKEDLL") != -1 ||
412 project->variables()["DEFINES"].findIndex("QT_DLL") != -1) ||
413 (getenv("QT_DLL") && !getenv("QT_NODLL"))) ) {
414 project->variables()["QMAKE_QT_DLL"].append("1");
415 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() )
416 project->variables()["CONFIG"].append("dll");
417 }
418 if ( project->isActiveConfig("thread") )
419 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_THREAD_SUPPORT");
420 if ( project->isActiveConfig("accessibility" ) )
421 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_ACCESSIBILITY_SUPPORT");
422 if ( project->isActiveConfig("tablet") )
423 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_TABLET_SUPPORT");
424 }
425
426 if ( project->isActiveConfig("dll") || !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
427 project->variables()["CONFIG"].remove("staticlib");
428 project->variables()["QMAKE_APP_OR_DLL"].append("1");
429 } else {
430 project->variables()["CONFIG"].append("staticlib");
431 }
432
433 if ( project->isActiveConfig("warn_off") ) {
434 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_WARN_OFF"];
435 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_WARN_OFF"];
436 } else if ( project->isActiveConfig("warn_on") ) {
437 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_WARN_ON"];
438 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_WARN_ON"];
439 }
440
441 if ( project->isActiveConfig("debug") ) {
442 if ( project->isActiveConfig("thread") ) {
443 // use the DLL RT even here
444 if ( project->variables()["DEFINES"].contains("QT_DLL") ) {
445 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DLLDBG"];
446 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DLLDBG"];
447 } else {
448 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DBG"];
449 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DBG"];
450 }
451 }
452 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_DEBUG"];
453 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_DEBUG"];
454 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_DEBUG"];
455 } else {
456 if ( project->isActiveConfig("thread") ) {
457 if ( project->variables()["DEFINES"].contains("QT_DLL") ) {
458 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DLL"];
459 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DLL"];
460 } else {
461 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT"];
462 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT"];
463 }
464 }
465 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RELEASE"];
466 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RELEASE"];
467 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_RELEASE"];
468 }
469
470 if ( !project->variables()["QMAKE_INCDIR"].isEmpty())
471 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR"];
472
473 if ( project->isActiveConfig("qt") || project->isActiveConfig("opengl") )
474 project->variables()["CONFIG"].append("windows");
475
476 if ( project->isActiveConfig("qt") ) {
477 project->variables()["CONFIG"].append("moc");
478 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QT"];
479 project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
480 if ( !project->isActiveConfig("debug") )
481 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_NO_DEBUG");
482 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
483 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty()) {
484 project->variables()["DEFINES"].append("QT_MAKEDLL");
485 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_QT_DLL"];
486 }
487 } else {
488
489 if(project->isActiveConfig("thread"))
490 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
491 else
492 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
493 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
494 int hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt");
495 if ( hver == -1 )
496 hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt-mt");
497 if(hver != -1) {
498 QString ver;
499 ver.sprintf("libqt-%s" QTDLL_POSTFIX "%d.a", (project->isActiveConfig("thread") ? "-mt" : ""), hver);
500 QStringList &libs = project->variables()["QMAKE_LIBS"];
501// @@@HGTODO maybe we must change the replace regexp if we understand what's going on
502 for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit)
503 (*libit).replace(QRegExp("qt(-mt)?\\.lib"), ver);
504 }
505 }
506 if ( project->isActiveConfig( "activeqt" ) ) {
507 project->variables().remove("QMAKE_LIBS_QT_ENTRY");
508 project->variables()["QMAKE_LIBS_QT_ENTRY"] = "-lqaxserver";
509 if ( project->isActiveConfig( "dll" ) ) {
510 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_ENTRY"];
511 }
512 }
513 if ( !project->isActiveConfig("dll") && !project->isActiveConfig("plugin") ) {
514 project->variables()["QMAKE_LIBS"] +=project->variables()["QMAKE_LIBS_QT_ENTRY"];
515 }
516
517 // QMAKE_LIBS_QT_ENTRY should be first on the link line as it needs qt
518 project->variables()["QMAKE_LIBS"].remove(project->variables()["QMAKE_LIBS_QT_ENTRY"].first());
519 project->variables()["QMAKE_LIBS"].prepend(project->variables()["QMAKE_LIBS_QT_ENTRY"].first());
520
521 }
522 }
523
524 if ( project->isActiveConfig("opengl") ) {
525 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
526 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
527 }
528
529 if ( project->isActiveConfig("dll") ) {
530 project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE_DLL"];
531 project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE_DLL"];
532 project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE_DLL"];
533 project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS_DLL"];
534 if ( !project->variables()["QMAKE_LIB_FLAG"].isEmpty()) {
535 project->variables()["TARGET_EXT"].append(
536 QStringList::split('.',project->first("VERSION")).join("") + ".dll");
537 } else {
538 project->variables()["TARGET_EXT"].append(".dll");
539 }
540 } else {
541 project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE"];
542 project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE"];
543 project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE"];
544 project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS"];
545 if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty()) {
546 project->variables()["TARGET_EXT"].append(".exe");
547 } else {
548 project->variables()["TARGET_EXT"].append(".a");
549 project->variables()["QMAKE_LFLAGS"].append("-static");
550 if(project->variables()["TARGET"].first().left(3) != "lib")
551 project->variables()["TARGET"].first().prepend("lib");
552 }
553 }
554
555 if ( project->isActiveConfig("windows") ) {
556 if ( project->isActiveConfig("console") ) {
557 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
558 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
559 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
560 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
561 } else {
562 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"];
563 }
564 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
565 } else {
566 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
567 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
568 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
569 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
570 }
571
572 if ( project->isActiveConfig("exceptions") ) {
573 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_ON"];
574 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_ON"];
575 } else {
576 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_OFF"];
577 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_OFF"];
578 }
579
580 if ( project->isActiveConfig("rtti") ) {
581 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_ON"];
582 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_ON"];
583 } else {
584 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_OFF"];
585 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_OFF"];
586 }
587
588 if ( project->isActiveConfig("moc") )
589 setMocAware(TRUE);
590
591 // add -L libs to libdir
592 QStringList &libs = project->variables()["QMAKE_LIBS"];
593 for ( QStringList::Iterator libit = libs.begin(); libit != libs.end(); ) {
594 if ( (*libit).startsWith( "-L" ) ) {
595 project->variables()["QMAKE_LIBDIR"] += (*libit).mid(2);
596 libit = libs.remove( libit );
597 } else {
598 ++libit;
599 }
600 }
601
602 project->variables()["QMAKE_FILETAGS"] += QStringList::split(' ',
603 "HEADERS SOURCES DEF_FILE RC_FILE TARGET QMAKE_LIBS DESTDIR DLLDESTDIR INCLUDEPATH");
604 QStringList &l = project->variables()["QMAKE_FILETAGS"];
605 QStringList::Iterator it;
606 for(it = l.begin(); it != l.end(); ++it) {
607 QStringList &gdmf = project->variables()[(*it)];
608 for(QStringList::Iterator inner = gdmf.begin(); inner != gdmf.end(); ++inner)
609 (*inner) = Option::fixPathToTargetOS((*inner), FALSE);
610 }
611
612 if ( project->isActiveConfig("dll") ) {
613 QString destDir = "";
614 if (!project->first("DESTDIR").isEmpty())
615 destDir = project->first("DESTDIR") + "\\";
616 project->variables()["QMAKE_LFLAGS"].append(QString("-Wl,--out-implib,") +
617 destDir + "lib" + project->first("TARGET") + ".a");
618 }
619
620 if ( !project->variables()["DEF_FILE"].isEmpty() )
621 project->variables()["QMAKE_LFLAGS"].append(QString("-Wl,") + project->first("DEF_FILE"));
622// if(!project->isActiveConfig("incremental"))
623// project->variables()["QMAKE_LFLAGS"].append(QString("/incremental:no"));
624
625#if 0
626 if ( !project->variables()["VERSION"].isEmpty() ) {
627 QString version = project->variables()["VERSION"][0];
628 int firstDot = version.find( "." );
629 QString major = version.left( firstDot );
630 QString minor = version.right( version.length() - firstDot - 1 );
631 minor.replace( ".", "" );
632 project->variables()["QMAKE_LFLAGS"].append( "/VERSION:" + major + "." + minor );
633 }
634#endif
635
636 if ( !project->variables()["RC_FILE"].isEmpty()) {
637 if ( !project->variables()["RES_FILE"].isEmpty()) {
638 fprintf(stderr, "Both .rc and .res file specified.\n");
639 fprintf(stderr, "Please specify one of them, not both.");
640 exit(666);
641 }
642 project->variables()["RES_FILE"] = project->variables()["RC_FILE"];
643 project->variables()["RES_FILE"].first().replace(".rc",".o");
644 project->variables()["POST_TARGETDEPS"] += project->variables()["RES_FILE"];
645 project->variables()["CLEAN_FILES"] += project->variables()["RES_FILE"];
646 }
647
648 if ( !project->variables()["RES_FILE"].isEmpty())
649 project->variables()["QMAKE_LIBS"] += project->variables()["RES_FILE"];
650
651 MakefileGenerator::init();
652
653 if ( !project->variables()["VERSION"].isEmpty()) {
654 QStringList l = QStringList::split('.', project->first("VERSION"));
655 project->variables()["VER_MAJ"].append(l[0]);
656 project->variables()["VER_MIN"].append(l[1]);
657 }
658
659 if(project->isActiveConfig("dll")) {
660 project->variables()["QMAKE_CLEAN"].append(project->first("DESTDIR") +"lib" + project->first("TARGET") + ".a");
661 }
662
663 QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
664 for(it = quc.begin(); it != quc.end(); ++it) {
665 QString tmp_out = project->variables()[(*it) + ".output"].first();
666 if(tmp_out.isEmpty())
667 continue;
668 QStringList &tmp = project->variables()[(*it) + ".input"];
669 for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
670 QStringList &inputs = project->variables()[(*it2)];
671 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
672 QFileInfo fi(Option::fixPathToLocalOS((*input)));
673 QString in = Option::fixPathToTargetOS((*input), FALSE),
674 out = tmp_out;
675 out.replace("${QMAKE_FILE_BASE}", fi.baseName());
676 out.replace("${QMAKE_FILE_NAME}", fi.fileName());
677 if(project->variables()[(*it) + ".CONFIG"].findIndex("no_link") == -1)
678 project->variables()["OBJCOMP"] += out;
679 }
680 }
681 }
682}
683
684void
685MingwMakefileGenerator::writeSubDirs(QTextStream &t)
686{
687 QString qs ;
688 QTextStream ts (&qs, IO_WriteOnly) ;
689 Win32MakefileGenerator::writeSubDirs( ts ) ;
690 QRegExp rx("(\\n\\tcd [^\\n\\t]+)(\\n\\t.+)\\n\\t@cd ..") ;
691 rx.setMinimal(TRUE);
692 int pos = 0 ;
693 while ( -1 != (pos = rx.search( qs, pos)))
694 {
695 QString qsMatch = rx.cap(2);
696 qsMatch.replace("\n\t"," && \\\n\t");
697 qs.replace(pos+rx.cap(1).length(), rx.cap(2).length(), qsMatch );
698 pos += (rx.cap(1).length()+qsMatch.length());
699 }
700 t << qs ;
701}
Note: See TracBrowser for help on using the repository browser.