source: trunk/qmake/generators/os2/gnumake.cpp

Last change on this file was 201, checked in by rudi, 14 years ago

Allow to use the Watcom linker WL.EXE bundled with "newer" GCCs. Also increased library page size and set CPU instuction set and optimisation.

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