source: trunk/qmake/generators/win32/msvc_dsp.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: 46.5 KB
Line 
1/****************************************************************************
2** $Id: msvc_dsp.cpp 2 2005-11-16 15:49:26Z dmik $
3**
4** Implementation of DspMakefileGenerator 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 "msvc_dsp.h"
37#include "option.h"
38#include <qdir.h>
39#include <qregexp.h>
40#include <stdlib.h>
41#include <time.h>
42
43DspMakefileGenerator::DspMakefileGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE)
44{
45
46}
47
48bool
49DspMakefileGenerator::writeMakefile(QTextStream &t)
50{
51 if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
52 /* for now just dump, I need to generated an empty dsp or something.. */
53 fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
54 var("QMAKE_FAILED_REQUIREMENTS").latin1());
55 return TRUE;
56 }
57
58 if(project->first("TEMPLATE") == "vcapp" ||
59 project->first("TEMPLATE") == "vclib") {
60 return writeDspParts(t);
61 }
62 else if(project->first("TEMPLATE") == "subdirs") {
63 writeHeader(t);
64 writeSubDirs(t);
65 return TRUE;
66 }
67 return FALSE;
68}
69
70bool
71DspMakefileGenerator::writeDspParts(QTextStream &t)
72{
73 QString dspfile;
74 if ( !project->variables()["DSP_TEMPLATE"].isEmpty() ) {
75 dspfile = project->first("DSP_TEMPLATE");
76 } else {
77 dspfile = project->first("MSVCDSP_TEMPLATE");
78 }
79 QString dspfile_loc = findTemplate(dspfile);
80
81 QFile file(dspfile_loc);
82 if(!file.open(IO_ReadOnly)) {
83 fprintf(stderr, "Cannot open dsp file: %s\n", dspfile.latin1());
84 return FALSE;
85 }
86 QTextStream dsp(&file);
87
88 QString platform = "Win32";
89 if ( !project->variables()["QMAKE_PLATFORM"].isEmpty() )
90 platform = varGlue("QMAKE_PLATFORM", "", " ", "");
91
92 // Setup PCH variables
93 precompH = project->first("PRECOMPILED_HEADER");
94 QString namePCH = QFileInfo(precompH).fileName();
95 usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
96 if (usePCH) {
97 // Created files
98 QString origTarget = project->first("QMAKE_ORIG_TARGET");
99 origTarget.replace(QRegExp("-"), "_");
100 precompObj = "\"$(IntDir)\\" + origTarget + Option::obj_ext + "\"";
101 precompPch = "\"$(IntDir)\\" + origTarget + ".pch\"";
102 // Add PRECOMPILED_HEADER to HEADERS
103 if (!project->variables()["HEADERS"].contains(precompH))
104 project->variables()["HEADERS"] += precompH;
105 // Add precompile compiler options
106 project->variables()["PRECOMPILED_FLAGS_REL"] = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" ";
107 project->variables()["PRECOMPILED_FLAGS_DEB"] = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" ";
108 // Return to variable pool
109 project->variables()["PRECOMPILED_OBJECT"] = precompObj;
110 project->variables()["PRECOMPILED_PCH"] = precompPch;
111 }
112 int rep;
113 QString line;
114 while ( !dsp.eof() ) {
115 line = dsp.readLine();
116 while((rep = line.find(QRegExp("\\$\\$[a-zA-Z0-9_-]*"))) != -1) {
117 QString torep = line.mid(rep, line.find(QRegExp("[^\\$a-zA-Z0-9_-]"), rep) - rep);
118 QString variable = torep.right(torep.length()-2);
119
120 t << line.left(rep); //output the left side
121 line = line.right(line.length() - (rep + torep.length())); //now past the variable
122 if(variable == "MSVCDSP_SOURCES") {
123 if(project->variables()["SOURCES"].isEmpty())
124 continue;
125
126 QString mocpath = var( "QMAKE_MOC" );
127 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
128
129 QStringList list = project->variables()["SOURCES"] + project->variables()["DEF_FILE"];
130 if(!project->isActiveConfig("flat"))
131 list.sort();
132 QStringList::Iterator it;
133 for( it = list.begin(); it != list.end(); ++it) {
134 beginGroupForFile((*it), t);
135 t << "# Begin Source File\n\nSOURCE=" << (*it) << endl;
136 if (usePCH && (*it).endsWith(".c"))
137 t << "# SUBTRACT CPP /FI\"" << namePCH << "\" /Yu\"" << namePCH << "\" /Fp" << endl;
138 if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) {
139 QString base = (*it);
140 base.replace(QRegExp("\\..*$"), "").upper();
141 base.replace(QRegExp("[^a-zA-Z]"), "_");
142
143 QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) +
144 "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\""
145 " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n"
146 "\t" + mocpath + findMocSource((*it)) + " -o " +
147 (*it) + "\n\n" "# End Custom Build\n\n";
148
149 t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl;
150
151 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
152 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\""
153 << build << "!ENDIF " << endl << endl;
154 }
155 t << "# End Source File" << endl;
156 }
157 endGroups(t);
158 } else if(variable == "MSVCDSP_IMAGES") {
159 if(project->variables()["IMAGES"].isEmpty())
160 continue;
161 t << "# Begin Source File\n\nSOURCE=" << project->first("QMAKE_IMAGE_COLLECTION") << endl;
162 t << "# End Source File" << endl;
163 } else if(variable == "MSVCDSP_HEADERS") {
164 if(project->variables()["HEADERS"].isEmpty())
165 continue;
166
167 QStringList list = project->variables()["HEADERS"];
168 if(!project->isActiveConfig("flat"))
169 list.sort();
170 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
171// beginGroupForFile((*it), t);
172 t << "# Begin Source File\n\nSOURCE=" << (*it) << endl << endl;
173 QString compilePCH;
174 QStringList customDependencies;
175 QString createMOC;
176 QString buildCmdsR, buildCmdsD;
177 QString buildCmds = "\nBuildCmds= \\\n";
178 // Create unique baseID
179 QString base = (*it);
180 {
181 base.replace(QRegExp("\\..*$"), "").upper();
182 base.replace(QRegExp("[^a-zA-Z]"), "_");
183 }
184 if (usePCH && precompH.endsWith(*it)) {
185 QString basicBuildCmd = QString("\tcl.exe /TP /W3 /FD /c /D \"WIN32\" /Yc /Fp\"%1\" /Fo\"%2\" %3 %4 %5 %6 %7 %8 %9 /D \"")
186 .arg(precompPch)
187 .arg(precompObj)
188 .arg(var("MSVCDSP_INCPATH"))
189 .arg(var("MSVCDSP_DEFINES"))
190 .arg(var("MSVCDSP_CXXFLAGS"));
191 buildCmdsR = basicBuildCmd
192 .arg("/D \"NDEBUG\"")
193 .arg(var("QMAKE_CXXFLAGS_RELEASE"))
194 .arg(var("MSVCDSP_MTDEF"))
195 .arg(var("MSVCDSP_RELDEFS"));
196 buildCmdsD = basicBuildCmd
197 .arg("/D \"_DEBUG\" /Od")
198 .arg(var("QMAKE_CXXFLAGS_DEBUG"))
199 .arg(var("MSVCDSP_MTDEFD"))
200 .arg(var("MSVCDSP_DEBUG_OPT"));
201 if (project->first("TEMPLATE") == "vcapp") { // App
202 buildCmdsR += var("MSVCDSP_WINCONDEF");
203 buildCmdsD += var("MSVCDSP_WINCONDEF");
204 } else if (project->isActiveConfig("dll")) { // Dll
205 buildCmdsR += "_WINDOWS\" /D \"_USRDLL";
206 buildCmdsD += "_WINDOWS\" /D \"_USRDLL";
207 } else { // Lib
208 buildCmdsR += "_LIB";
209 buildCmdsD += "_LIB";
210 }
211 buildCmdsR += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n";
212 buildCmdsD += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n";
213
214 compilePCH = precompPch + " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n $(BuildCmds)\n\n";
215
216 QStringList &tmp = findDependencies(precompH);
217 if(!tmp.isEmpty()) // Got Deps for PCH
218 customDependencies += tmp;
219 }
220 if (project->isActiveConfig("moc") && !findMocDestination((*it)).isEmpty()) {
221 QString mocpath = var( "QMAKE_MOC" );
222 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
223 buildCmds += "\t" + mocpath + (*it) + " -o " + findMocDestination((*it)) + " \\\n";
224 createMOC = "\"" + findMocDestination((*it)) + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n $(BuildCmds)\n\n";
225 customDependencies += "\"$(QTDIR)\\bin\\moc.exe\"";
226 }
227 if (!createMOC.isEmpty() || !compilePCH.isEmpty()) {
228 bool doMOC = !createMOC.isEmpty();
229 bool doPCH = !compilePCH.isEmpty();
230 QString build = "\n\n# Begin Custom Build - "+
231 QString(doMOC?"Moc'ing ":"") +
232 QString((doMOC&&doPCH)?" and ":"") +
233 QString(doPCH?"Creating PCH cpp from ":"") +
234 (*it) + "...\nInputPath=.\\" + (*it) + "\n\n" +
235 buildCmds + "%1\n" +
236 createMOC +
237 compilePCH +
238 "# End Custom Build\n\n";
239
240 t << "USERDEP_" << base << "=" << valGlue(customDependencies, "\"", "\" \"", "\"") << endl << endl;
241 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build.arg(buildCmdsR)
242 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build.arg(buildCmdsD)
243 << "!ENDIF " << endl << endl;
244 }
245 t << "# End Source File" << endl;
246 }
247// endGroups(t);
248 } else if(variable == "MSVCDSP_FORMSOURCES" || variable == "MSVCDSP_FORMHEADERS") {
249 if(project->variables()["FORMS"].isEmpty())
250 continue;
251
252 QString uiSourcesDir;
253 QString uiHeadersDir;
254 if(!project->variables()["UI_DIR"].isEmpty()) {
255 uiSourcesDir = project->first("UI_DIR");
256 uiHeadersDir = project->first("UI_DIR");
257 } else {
258 if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() )
259 uiSourcesDir = project->first("UI_SOURCES_DIR");
260 else
261 uiSourcesDir = "";
262 if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() )
263 uiHeadersDir = project->first("UI_HEADERS_DIR");
264 else
265 uiHeadersDir = "";
266 }
267
268 QStringList list = project->variables()["FORMS"];
269 if(!project->isActiveConfig("flat"))
270 list.sort();
271 QString ext = variable == "MSVCDSP_FORMSOURCES" ? ".cpp" : ".h";
272 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
273 QString base = (*it);
274 int dot = base.findRev(".");
275 base.replace( dot, base.length() - dot, ext );
276 QString fname = base;
277
278 int lbs = fname.findRev( "\\" );
279 QString fpath;
280 if ( lbs != -1 )
281 fpath = fname.left( lbs + 1 );
282 fname = fname.right( fname.length() - lbs - 1 );
283
284 if ( ext == ".cpp" && !uiSourcesDir.isEmpty() )
285 fname.prepend(uiSourcesDir);
286 else if ( ext == ".h" && !uiHeadersDir.isEmpty() )
287 fname.prepend(uiHeadersDir);
288 else
289 fname = base;
290// beginGroupForFile(fname, t);
291 t << "# Begin Source File\n\nSOURCE=" << fname
292 << "\n# End Source File" << endl;
293 }
294// endGroups(t);
295 } else if(variable == "MSVCDSP_TRANSLATIONS" ) {
296 if(project->variables()["TRANSLATIONS"].isEmpty())
297 continue;
298
299 t << "# Begin Group \"Translations\"\n";
300 t << "# Prop Default_Filter \"ts\"\n";
301
302 QStringList list = project->variables()["TRANSLATIONS"];
303 if(!project->isActiveConfig("flat"))
304 list.sort();
305 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
306 QString sify = *it;
307 sify.replace('/', '\\' );
308 QString base = (*it);
309 base.replace(QRegExp("\\..*$"), "").upper();
310 base.replace(QRegExp("[^a-zA-Z]"), "_");
311
312// beginGroupForFile(sify, t);
313 t << "# Begin Source File\n\nSOURCE=" << sify << endl;
314 t << "\n# End Source File" << endl;
315 }
316// endGroups(t);
317 t << "\n# End Group\n";
318 } else if (variable == "MSVCDSP_MOCSOURCES" && project->isActiveConfig("moc")) {
319 if ( project->variables()["SRCMOC"].isEmpty())
320 continue;
321
322 QString mocpath = var( "QMAKE_MOC" );
323 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
324
325 QStringList list = project->variables()["SRCMOC"];
326 if(!project->isActiveConfig("flat"))
327 list.sort();
328 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
329// beginGroupForFile((*it), t);
330 t << "# Begin Source File\n\nSOURCE=" << (*it) << endl;
331 if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) {
332 QString base = (*it);
333 base.replace(QRegExp("\\..*$"), "").upper();
334 base.replace(QRegExp("[^a-zA-Z]"), "_");
335
336 QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) +
337 "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\""
338 " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n"
339 "\t" + mocpath + findMocSource((*it)) + " -o " +
340 (*it) + "\n\n" "# End Custom Build\n\n";
341
342 t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl;
343
344 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
345 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\""
346 << build << "!ENDIF " << endl << endl;
347 }
348 t << "# End Source File" << endl;
349 }
350// endGroups(t);
351 } else if(variable == "MSVCDSP_PICTURES") {
352 if(project->variables()["IMAGES"].isEmpty())
353 continue;
354
355 t << "# Begin Group \"Images\"\n"
356 << "# Prop Default_Filter \"png jpeg bmp xpm\"\n";
357
358 QStringList list = project->variables()["IMAGES"];
359 if(!project->isActiveConfig("flat"))
360 list.sort();
361 QStringList::Iterator it;
362
363 // dump the image list to a file UIC can read.
364 QFile f( "images.tmp" );
365 f.open( IO_WriteOnly );
366 QTextStream ts( &f );
367 for( it = list.begin(); it != list.end(); ++it )
368 ts << " " << *it;
369 f.close();
370
371 // create an output step for images not more than once
372 bool imagesBuildDone = FALSE;
373 for( it = list.begin(); it != list.end(); ++it ) {
374// beginGroupForFile((*it), t);
375 t << "# Begin Source File\n\nSOURCE=" << (*it) << endl;
376
377 QString base = (*it);
378 QString uicpath = var("QMAKE_UIC");
379 uicpath = uicpath.replace(QRegExp("\\..*$"), "") + " ";
380
381 if ( !imagesBuildDone ) {
382 imagesBuildDone = TRUE;
383 QString build = "\n\n# Begin Custom Build - Creating image collection...\n"
384 "InputPath=.\\" + base + "\n\n";
385
386 build += "\"" + project->first("QMAKE_IMAGE_COLLECTION") + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n";
387 build += "\t" + uicpath + "-embed " + project->first("QMAKE_ORIG_TARGET") + " -f images.tmp -o "
388 + project->first("QMAKE_IMAGE_COLLECTION") + "\n\n";
389 build.append("# End Custom Build\n\n");
390
391 t << "USERDEP_" << base << "=";
392 QStringList::Iterator it2 = list.begin();
393 while ( it2 != list.end() ) {
394 t << "\"" << (*it2) << "\"";
395 it2++;
396 if ( it2 != list.end() )
397 t << "\\\n";
398 }
399 t << endl << endl;
400
401 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - Win32 Release\"" << build
402 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - Win32 Debug\"" << build
403 << "!ENDIF \n\n" << endl;
404 }
405
406 t << "# End Source File" << endl;
407 }
408// endGroups(t);
409 t << "\n# End Group\n";
410 } else if(variable == "MSVCDSP_FORMS") {
411 if(project->variables()["FORMS"].isEmpty())
412 continue;
413
414 t << "# Begin Group \"Forms\"\n"
415 << "# Prop Default_Filter \"ui\"\n";
416
417 QString uicpath = var("QMAKE_UIC");
418 uicpath = uicpath.replace(QRegExp("\\..*$"), "") + " ";
419 QString mocpath = var( "QMAKE_MOC" );
420 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
421
422 QStringList list = project->variables()["FORMS"];
423 if(!project->isActiveConfig("flat"))
424 list.sort();
425 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
426 QString base = (*it);
427// beginGroupForFile(base, t);
428 t << "# Begin Source File\n\nSOURCE=" << base << endl;
429
430 QString fname = base;
431 fname.replace(".ui", "");
432 int lbs = fname.findRev( "\\" );
433 QString fpath;
434 if ( lbs != -1 )
435 fpath = fname.left( lbs + 1 );
436 fname = fname.right( fname.length() - lbs - 1 );
437
438 QString mocFile;
439 if(!project->variables()["MOC_DIR"].isEmpty())
440 mocFile = project->first("MOC_DIR");
441 else
442 mocFile = fpath;
443
444 QString uiSourcesDir;
445 QString uiHeadersDir;
446 if(!project->variables()["UI_DIR"].isEmpty()) {
447 uiSourcesDir = project->first("UI_DIR");
448 uiHeadersDir = project->first("UI_DIR");
449 } else {
450 if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() )
451 uiSourcesDir = project->first("UI_SOURCES_DIR");
452 else
453 uiSourcesDir = fpath;
454 if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() )
455 uiHeadersDir = project->first("UI_HEADERS_DIR");
456 else
457 uiHeadersDir = fpath;
458 }
459
460 t << "USERDEP_" << base << "=\"$(QTDIR)\\bin\\moc.exe\" \"$(QTDIR)\\bin\\uic.exe\"" << endl << endl;
461
462 QString build = "\n\n# Begin Custom Build - Uic'ing " + base + "...\n"
463 "InputPath=.\\" + base + "\n\n" "BuildCmds= \\\n\t" + uicpath + base +
464 " -o " + uiHeadersDir + fname + ".h \\\n" "\t" + uicpath + base +
465 " -i " + fname + ".h -o " + uiSourcesDir + fname + ".cpp \\\n"
466 "\t" + mocpath + " " + uiHeadersDir +
467 fname + ".h -o " + mocFile + Option::h_moc_mod + fname + Option::h_moc_ext + " \\\n";
468
469 build.append("\n\"" + uiHeadersDir + fname + ".h\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
470 "\t$(BuildCmds)\n\n"
471 "\"" + uiSourcesDir + fname + ".cpp\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
472 "\t$(BuildCmds)\n\n"
473 "\"" + mocFile + Option::h_moc_mod + fname + Option::h_moc_ext + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
474 "\t$(BuildCmds)\n\n");
475
476 build.append("# End Custom Build\n\n");
477
478 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
479 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build
480 << "!ENDIF \n\n" << "# End Source File" << endl;
481 }
482// endGroups(t);
483 t << "\n# End Group\n";
484 } else if(variable == "MSVCDSP_LEXSOURCES") {
485 if(project->variables()["LEXSOURCES"].isEmpty())
486 continue;
487
488 t << "# Begin Group \"Lexables\"\n"
489 << "# Prop Default_Filter \"l\"\n";
490
491 QString lexpath = var("QMAKE_LEX") + varGlue("QMAKE_LEXFLAGS", " ", " ", "") + " ";
492
493 QStringList list = project->variables()["LEXSOURCES"];
494 if(!project->isActiveConfig("flat"))
495 list.sort();
496 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
497 QString fname = (*it);
498// beginGroupForFile(fname, t);
499 t << "# Begin Source File\n\nSOURCE=" << fname << endl;
500 fname.replace(".l", Option::lex_mod + Option::cpp_ext.first());
501
502 QString build = "\n\n# Begin Custom Build - Lex'ing " + (*it) + "...\n"
503 "InputPath=.\\" + (*it) + "\n\n"
504 "\"" + fname + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
505 "\t" + lexpath + (*it) + "\\\n"
506 "\tdel " + fname + "\\\n"
507 "\tcopy lex.yy.c " + fname + "\n\n" +
508 "# End Custom Build\n\n";
509 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
510 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build
511 << "!ENDIF \n\n" << build
512
513 << "# End Source File" << endl;
514 }
515// endGroups(t);
516 t << "\n# End Group\n";
517 } else if(variable == "MSVCDSP_YACCSOURCES") {
518 if(project->variables()["YACCSOURCES"].isEmpty())
519 continue;
520
521 t << "# Begin Group \"Yaccables\"\n"
522 << "# Prop Default_Filter \"y\"\n";
523
524 QString yaccpath = var("QMAKE_YACC") + varGlue("QMAKE_YACCFLAGS", " ", " ", "") + " ";
525
526 QStringList list = project->variables()["YACCSOURCES"];
527 if(!project->isActiveConfig("flat"))
528 list.sort();
529 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
530 QString fname = (*it);
531// beginGroupForFile(fname, t);
532 t << "# Begin Source File\n\nSOURCE=" << fname << endl;
533 fname.replace(".y", Option::yacc_mod);
534
535 QString build = "\n\n# Begin Custom Build - Yacc'ing " + (*it) + "...\n"
536 "InputPath=.\\" + (*it) + "\n\n"
537 "\"" + fname + Option::cpp_ext.first() + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
538 "\t" + yaccpath + (*it) + "\\\n"
539 "\tdel " + fname + Option::h_ext.first() + "\\\n"
540 "\tmove y.tab.h " + fname + Option::h_ext.first() + "\n\n" +
541 "\tdel " + fname + Option::cpp_ext.first() + "\\\n"
542 "\tmove y.tab.c " + fname + Option::cpp_ext.first() + "\n\n" +
543 "# End Custom Build\n\n";
544
545 t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
546 << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build
547 << "!ENDIF \n\n"
548 << "# End Source File" << endl;
549 }
550// endGroups(t);
551 t << "\n# End Group\n";
552 } else if( variable == "MSVCDSP_CONFIGMODE" ) {
553 if( project->isActiveConfig( "debug" ) )
554 t << "Debug";
555 else
556 t << "Release";
557 } else if( variable == "MSVCDSP_IDLSOURCES" ) {
558 QStringList list = project->variables()["MSVCDSP_IDLSOURCES"];
559 if(!project->isActiveConfig("flat"))
560 list.sort();
561 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
562 t << "# Begin Source File" << endl << endl;
563 t << "SOURCE=" << (*it) << endl;
564 t << "# PROP Exclude_From_Build 1" << endl;
565 t << "# End Source File" << endl << endl;
566 }
567 }
568 else
569 t << var(variable);
570 }
571 t << line << endl;
572 }
573 t << endl;
574 file.close();
575 return TRUE;
576}
577
578
579
580void
581DspMakefileGenerator::init()
582{
583 if(init_flag)
584 return;
585 QStringList::Iterator it;
586 init_flag = TRUE;
587
588 const bool thread = project->isActiveConfig("thread");
589
590 if ( project->isActiveConfig("stl") ) {
591 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_ON"];
592 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_ON"];
593 } else {
594 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_OFF"];
595 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_OFF"];
596 }
597 if ( project->isActiveConfig("exceptions") ) {
598 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_ON"];
599 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_ON"];
600 } else {
601 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_OFF"];
602 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_OFF"];
603 }
604 if ( project->isActiveConfig("rtti") ) {
605 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_ON"];
606 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_ON"];
607 } else {
608 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_OFF"];
609 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_OFF"];
610 }
611
612
613 /* this should probably not be here, but I'm using it to wrap the .t files */
614 if(project->first("TEMPLATE") == "vcapp" )
615 project->variables()["QMAKE_APP_FLAG"].append("1");
616 else if(project->first("TEMPLATE") == "vclib")
617 project->variables()["QMAKE_LIB_FLAG"].append("1");
618 if ( project->variables()["QMAKESPEC"].isEmpty() )
619 project->variables()["QMAKESPEC"].append( getenv("QMAKESPEC") );
620
621 bool is_qt = (project->first("TARGET") == "qt"QTDLL_POSTFIX || project->first("TARGET") == "qt-mt"QTDLL_POSTFIX);
622 project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
623
624 QStringList &configs = project->variables()["CONFIG"];
625 if (project->isActiveConfig("shared"))
626 project->variables()["DEFINES"].append("QT_DLL");
627 if (project->isActiveConfig("qt_dll"))
628 if(configs.findIndex("qt") == -1) configs.append("qt");
629 if ( project->isActiveConfig("qtopia") ) {
630 if(configs.findIndex("qtopialib") == -1)
631 configs.append("qtopialib");
632 if(configs.findIndex("qtopiainc") == -1)
633 configs.append("qtopiainc");
634 }
635 if ( project->isActiveConfig("qt") ) {
636 if ( project->isActiveConfig( "plugin" ) ) {
637 project->variables()["CONFIG"].append("dll");
638 project->variables()["DEFINES"].append("QT_PLUGIN");
639 }
640 if ( (project->variables()["DEFINES"].findIndex("QT_NODLL") == -1) &&
641 ((project->variables()["DEFINES"].findIndex("QT_MAKEDLL") != -1 ||
642 project->variables()["DEFINES"].findIndex("QT_DLL") != -1) ||
643 (getenv("QT_DLL") && !getenv("QT_NODLL"))) ) {
644 project->variables()["QMAKE_QT_DLL"].append("1");
645 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() )
646 project->variables()["CONFIG"].append("dll");
647 }
648 }
649 if ( project->isActiveConfig("dll") || !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
650 project->variables()["CONFIG"].remove("staticlib");
651 project->variables()["QMAKE_APP_OR_DLL"].append("1");
652 } else {
653 project->variables()["CONFIG"].append("staticlib");
654 }
655
656 if ( project->isActiveConfig("qt") || project->isActiveConfig("opengl") ) {
657 project->variables()["CONFIG"].append("windows");
658 }
659 if ( !project->variables()["VERSION"].isEmpty() ) {
660 QString version = project->variables()["VERSION"][0];
661 int firstDot = version.find( "." );
662 QString major = version.left( firstDot );
663 QString minor = version.right( version.length() - firstDot - 1 );
664 minor.replace( ".", "" );
665 project->variables()["MSVCDSP_VERSION"].append( "/VERSION:" + major + "." + minor );
666 }
667
668 if ( project->isActiveConfig("qtopiainc") )
669 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QTOPIA"];
670 if ( project->isActiveConfig("qtopialib") ) {
671 if(!project->isEmpty("QMAKE_LIBDIR_QTOPIA"))
672 project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QTOPIA"];
673 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QTOPIA"];
674 }
675
676 if ( project->isActiveConfig("qt") ) {
677 project->variables()["CONFIG"].append("moc");
678 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QT"];
679 project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
680
681 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
682 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
683 project->variables()["DEFINES"].append("QT_MAKEDLL");
684 project->variables()["QMAKE_LFLAGS"].append("/base:\"0x39D00000\"");
685 }
686 } else {
687 if( thread )
688 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
689 else
690 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
691 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
692 int hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt");
693 if ( hver == -1 )
694 hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt-mt");
695 if(hver != -1) {
696 QString ver;
697 ver.sprintf("qt%s" QTDLL_POSTFIX "%d.lib", (thread ? "-mt" : ""), hver);
698 QStringList &libs = project->variables()["QMAKE_LIBS"];
699 for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit)
700 (*libit).replace(QRegExp("qt(-mt)?\\.lib"), ver);
701 }
702 }
703 if ( project->isActiveConfig( "activeqt" ) ) {
704 project->variables().remove("QMAKE_LIBS_QT_ENTRY");
705 project->variables()["QMAKE_LIBS_QT_ENTRY"] = "qaxserver.lib";
706 if ( project->isActiveConfig( "dll" ) )
707 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_ENTRY"];
708 }
709 if ( !project->isActiveConfig("dll") && !project->isActiveConfig("plugin") ) {
710 project->variables()["QMAKE_LIBS"] +=project->variables()["QMAKE_LIBS_QT_ENTRY"];
711 }
712 }
713 }
714
715 if ( project->isActiveConfig("debug") ) {
716 if ( !project->first("OBJECTS_DIR").isEmpty() )
717 project->variables()["MSVCDSP_OBJECTSDIRDEB"] = project->first("OBJECTS_DIR");
718 else
719 project->variables()["MSVCDSP_OBJECTSDIRDEB"] = "Debug";
720 project->variables()["MSVCDSP_OBJECTSDIRREL"] = "Release";
721 if ( !project->first("DESTDIR").isEmpty() )
722 project->variables()["MSVCDSP_TARGETDIRDEB"] = project->first("DESTDIR");
723 else
724 project->variables()["MSVCDSP_TARGETDIRDEB"] = "Debug";
725 project->variables()["MSVCDSP_TARGETDIRREL"] = "Release";
726 } else {
727 if ( !project->first("OBJECTS_DIR").isEmpty() )
728 project->variables()["MSVCDSP_OBJECTSDIRREL"] = project->first("OBJECTS_DIR");
729 else
730 project->variables()["MSVCDSP_OBJECTSDIRREL"] = "Release";
731 project->variables()["MSVCDSP_OBJECTSDIRDEB"] = "Debug";
732 if ( !project->first("DESTDIR").isEmpty() )
733 project->variables()["MSVCDSP_TARGETDIRREL"] = project->first("DESTDIR");
734 else
735 project->variables()["MSVCDSP_TARGETDIRREL"] = "Release";
736 project->variables()["MSVCDSP_TARGETDIRDEB"] = "Debug";
737 }
738
739 if ( project->isActiveConfig("opengl") ) {
740 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
741 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
742 }
743 if ( thread ) {
744 if(project->isActiveConfig("qt"))
745 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_THREAD_SUPPORT" );
746 if ( project->isActiveConfig("dll") || project->first("TARGET") == "qtmain"
747 || !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
748 project->variables()["MSVCDSP_MTDEFD"] += project->variables()["QMAKE_CXXFLAGS_MT_DLLDBG"];
749 project->variables()["MSVCDSP_MTDEF"] += project->variables()["QMAKE_CXXFLAGS_MT_DLL"];
750 } else {
751 // YES we want to use the DLL even in a static build
752 project->variables()["MSVCDSP_MTDEFD"] += project->variables()["QMAKE_CXXFLAGS_MT_DBG"];
753 project->variables()["MSVCDSP_MTDEF"] += project->variables()["QMAKE_CXXFLAGS_MT"];
754 }
755 if ( !project->variables()["DEFINES"].contains("QT_DLL") && is_qt
756 && project->first("TARGET") != "qtmain" )
757 project->variables()["QMAKE_LFLAGS"].append("/NODEFAULTLIB:\"libc\"");
758 }
759
760 if(project->isActiveConfig("qt")) {
761 if ( project->isActiveConfig("accessibility" ) )
762 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_ACCESSIBILITY_SUPPORT");
763 if ( project->isActiveConfig("tablet") )
764 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_TABLET_SUPPORT");
765 }
766 if ( project->isActiveConfig("dll") ) {
767 project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE_DLL"];
768 project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE_DLL"];
769 project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE_DLL"];
770 project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS_DLL"];
771 if ( !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
772 QString ver_xyz(project->first("VERSION"));
773 ver_xyz.replace(".", "");
774 project->variables()["TARGET_EXT"].append(ver_xyz + ".dll");
775 } else {
776 project->variables()["TARGET_EXT"].append(".dll");
777 }
778 } else {
779 project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE"];
780 project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE"];
781 project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE"];
782 project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS"];
783 if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty() )
784 project->variables()["TARGET_EXT"].append(".exe");
785 else
786 project->variables()["TARGET_EXT"].append(".lib");
787 }
788
789 if ( project->isActiveConfig("windows") ) {
790 if ( project->isActiveConfig("console") ) {
791 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
792 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
793 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
794 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
795 } else {
796 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"];
797 }
798 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
799 } else {
800 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
801 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
802 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
803 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
804 }
805
806 project->variables()["MSVCDSP_VER"] = "6.00";
807 project->variables()["MSVCDSP_DEBUG_OPT"] = "/GZ /ZI";
808
809 if(!project->isActiveConfig("incremental")) {
810 project->variables()["QMAKE_LFLAGS"].append(QString("/incremental:no"));
811 if ( is_qt )
812 project->variables()["MSVCDSP_DEBUG_OPT"] = "/GZ /Zi";
813 }
814
815 QString msvcdsp_project;
816 if ( project->variables()["TARGET"].count() )
817 msvcdsp_project = project->variables()["TARGET"].first();
818
819 QString targetfilename = project->variables()["TARGET"].first();
820 project->variables()["TARGET"].first() += project->first("TARGET_EXT");
821 if ( project->isActiveConfig("moc") )
822 setMocAware(TRUE);
823
824 project->variables()["QMAKE_LIBS"] += project->variables()["LIBS"];
825 project->variables()["QMAKE_FILETAGS"] += QStringList::split(' ',
826 "HEADERS SOURCES DEF_FILE RC_FILE TARGET QMAKE_LIBS DESTDIR DLLDESTDIR INCLUDEPATH");
827 QStringList &l = project->variables()["QMAKE_FILETAGS"];
828 for(it = l.begin(); it != l.end(); ++it) {
829 QStringList &gdmf = project->variables()[(*it)];
830 for(QStringList::Iterator inner = gdmf.begin(); inner != gdmf.end(); ++inner)
831 (*inner) = Option::fixPathToTargetOS((*inner), FALSE);
832 }
833
834 MakefileGenerator::init();
835 if ( msvcdsp_project.isEmpty() )
836 msvcdsp_project = Option::output.name();
837
838 msvcdsp_project = msvcdsp_project.right( msvcdsp_project.length() - msvcdsp_project.findRev( "\\" ) - 1 );
839 msvcdsp_project = msvcdsp_project.left( msvcdsp_project.findRev( "." ) );
840 msvcdsp_project.replace("-", "");
841
842 project->variables()["MSVCDSP_PROJECT"].append(msvcdsp_project);
843 QStringList &proj = project->variables()["MSVCDSP_PROJECT"];
844
845 for(it = proj.begin(); it != proj.end(); ++it)
846 (*it).replace(QRegExp("\\.[a-zA-Z0-9_]*$"), "");
847
848 if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
849 project->variables()["MSVCDSP_TEMPLATE"].append("win32app" + project->first( "DSP_EXTENSION" ) );
850 if ( project->isActiveConfig("console") ) {
851 project->variables()["MSVCDSP_CONSOLE"].append("Console");
852 project->variables()["MSVCDSP_WINCONDEF"].append("_CONSOLE");
853 project->variables()["MSVCDSP_DSPTYPE"].append("0x0103");
854 } else {
855 project->variables()["MSVCDSP_CONSOLE"].clear();
856 project->variables()["MSVCDSP_WINCONDEF"].append("_WINDOWS");
857 project->variables()["MSVCDSP_DSPTYPE"].append("0x0101");
858 }
859 } else {
860 if ( project->isActiveConfig("dll") ) {
861 project->variables()["MSVCDSP_TEMPLATE"].append("win32dll" + project->first( "DSP_EXTENSION" ) );
862 } else {
863 project->variables()["MSVCDSP_TEMPLATE"].append("win32lib" + project->first( "DSP_EXTENSION" ) );
864 }
865 }
866
867 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
868
869 processPrlFiles();
870
871 // Update -lname to name.lib,
872 QStringList &libs2 = project->variables()["QMAKE_LIBS"];
873 for ( QStringList::Iterator libit2 = libs2.begin(); libit2 != libs2.end(); ++libit2 ) {
874 if ( (*libit2).startsWith( "-l" ) ) {
875 (*libit2) = (*libit2).mid( 2 ) + ".lib";
876 } else if ( (*libit2).startsWith( "-L" ) ) {
877 project->variables()["QMAKE_LIBDIR"] += (*libit2).mid(2);
878 libit2 = libs2.remove( libit2 );
879 }
880 }
881
882 project->variables()["MSVCDSP_LFLAGS" ] += project->variables()["QMAKE_LFLAGS"];
883 if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() )
884 project->variables()["MSVCDSP_LFLAGS" ].append(varGlue("QMAKE_LIBDIR","/LIBPATH:\"","\" /LIBPATH:\"","\""));
885 project->variables()["MSVCDSP_CXXFLAGS" ] += project->variables()["QMAKE_CXXFLAGS"];
886 project->variables()["MSVCDSP_DEFINES"].append(varGlue("DEFINES","/D ","" " /D ",""));
887 project->variables()["MSVCDSP_DEFINES"].append(varGlue("PRL_EXPORT_DEFINES","/D ","" " /D ",""));
888
889
890
891 QStringList &libs = project->variables()["QMAKE_LIBS"];
892 for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit) {
893 QString lib = (*libit);
894 lib.replace(QRegExp("\""), "");
895 project->variables()["MSVCDSP_LIBS"].append(" \"" + lib + "\"");
896 }
897
898 QStringList &incs = project->variables()["INCLUDEPATH"];
899 for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
900 QString inc = (*incit);
901 inc.replace("\"", "");
902 if(inc.endsWith("\\")) // Remove trailing \'s from paths
903 inc.truncate(inc.length()-1);
904 project->variables()["MSVCDSP_INCPATH"].append("/I \"" + inc + "\"");
905 }
906
907 project->variables()["MSVCDSP_INCPATH"].append("/I \"" + specdir() + "\"");
908 if ( project->isActiveConfig("qt") ) {
909 project->variables()["MSVCDSP_RELDEFS"].append("/D \"QT_NO_DEBUG\"");
910 } else {
911 project->variables()["MSVCDSP_RELDEFS"].clear();
912 }
913
914 QString dest;
915 QString postLinkStep;
916 QString copyDllStep;
917 QString activeQtStepPreCopyDll;
918 QString activeQtStepPostCopyDll;
919 QString activeQtStepPreCopyDllDebug;
920 QString activeQtStepPostCopyDllDebug;
921 QString activeQtStepPreCopyDllRelease;
922 QString activeQtStepPostCopyDllRelease;
923
924 if ( !project->variables()["QMAKE_POST_LINK"].isEmpty() )
925 postLinkStep += var("QMAKE_POST_LINK");
926
927 if ( !project->variables()["DESTDIR"].isEmpty() ) {
928 project->variables()["TARGET"].first().prepend(project->first("DESTDIR"));
929 Option::fixPathToTargetOS(project->first("TARGET"));
930 dest = project->first("TARGET");
931 if ( project->first("TARGET").startsWith("$(QTDIR)") )
932 dest.replace( "$(QTDIR)", getenv("QTDIR") );
933 project->variables()["MSVCDSP_TARGET"].append(
934 QString("/out:\"") + dest + "\"");
935 if ( project->isActiveConfig("dll") ) {
936 QString imp = dest;
937 imp.replace(".dll", ".lib");
938 project->variables()["MSVCDSP_TARGET"].append(QString(" /implib:\"") + imp + "\"");
939 }
940 }
941 if ( project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty() ) {
942 QStringList dlldirs = project->variables()["DLLDESTDIR"];
943 if ( dlldirs.count() )
944 copyDllStep += "\t";
945 for ( QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) {
946 copyDllStep += "copy \"$(TargetPath)\" \"" + *dlldir + "\"\t";
947 }
948 }
949
950 if ( project->isActiveConfig("activeqt") ) {
951 QString idl = project->variables()["QMAKE_IDL"].first();
952 QString idc = project->variables()["QMAKE_IDC"].first();
953 QString version = project->variables()["VERSION"].first();
954 if ( version.isEmpty() )
955 version = "1.0";
956 project->variables()["MSVCDSP_IDLSOURCES"].append( var("OBJECTS_DIR") + targetfilename + ".idl" );
957 if ( project->isActiveConfig( "dll" ) ) {
958 activeQtStepPreCopyDll +=
959 "\t" + idc + " %1 -idl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version +
960 "\t" + idl + " /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb" +
961 "\t" + idc + " %2 /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb";
962 activeQtStepPostCopyDll +=
963 "\t" + idc + " %1 /regserver\n";
964
965 QString executable = project->variables()["MSVCDSP_TARGETDIRREL"].first() + "\\" + targetfilename + ".dll";
966 activeQtStepPreCopyDllRelease = activeQtStepPreCopyDll.arg(executable).arg(executable);
967 activeQtStepPostCopyDllRelease = activeQtStepPostCopyDll.arg(executable);
968
969 executable = project->variables()["MSVCDSP_TARGETDIRDEB"].first() + "\\" + targetfilename + ".dll";
970 activeQtStepPreCopyDllDebug = activeQtStepPreCopyDll.arg(executable).arg(executable);
971 activeQtStepPostCopyDllDebug = activeQtStepPostCopyDll.arg(executable);
972 } else {
973 activeQtStepPreCopyDll +=
974 "\t%1 -dumpidl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version +
975 "\t" + idl + " /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb" +
976 "\t" + idc + " %2 /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb";
977 activeQtStepPostCopyDll +=
978 "\t%1 -regserver\n";
979 QString executable = project->variables()["MSVCDSP_TARGETDIRREL"].first() + "\\" + targetfilename + ".exe";
980 activeQtStepPreCopyDllRelease = activeQtStepPreCopyDll.arg(executable).arg(executable);
981 activeQtStepPostCopyDllRelease = activeQtStepPostCopyDll.arg(executable);
982
983 executable = project->variables()["MSVCDSP_TARGETDIRDEB"].first() + "\\" + targetfilename + ".exe";
984 activeQtStepPreCopyDllDebug = activeQtStepPreCopyDll.arg(executable).arg(executable);
985 activeQtStepPostCopyDllDebug = activeQtStepPostCopyDll.arg(executable);
986 }
987
988 }
989
990
991 if ( !postLinkStep.isEmpty() || !copyDllStep.isEmpty() || !activeQtStepPreCopyDllDebug.isEmpty() || !activeQtStepPreCopyDllRelease.isEmpty() ) {
992 project->variables()["MSVCDSP_POST_LINK_DBG"].append(
993 "# Begin Special Build Tool\n"
994 "SOURCE=$(InputPath)\n"
995 "PostBuild_Desc=Post Build Step\n"
996 "PostBuild_Cmds=" + postLinkStep + activeQtStepPreCopyDllDebug + copyDllStep + activeQtStepPostCopyDllDebug + "\n"
997 "# End Special Build Tool\n" );
998 project->variables()["MSVCDSP_POST_LINK_REL"].append(
999 "# Begin Special Build Tool\n"
1000 "SOURCE=$(InputPath)\n"
1001 "PostBuild_Desc=Post Build Step\n"
1002 "PostBuild_Cmds=" + postLinkStep + activeQtStepPreCopyDllRelease + copyDllStep + activeQtStepPostCopyDllRelease + "\n"
1003 "# End Special Build Tool\n" );
1004 }
1005
1006 if ( !project->variables()["SOURCES"].isEmpty() || !project->variables()["RC_FILE"].isEmpty() ) {
1007 project->variables()["SOURCES"] += project->variables()["RC_FILE"];
1008 }
1009 QStringList &list = project->variables()["FORMS"];
1010 for( it = list.begin(); it != list.end(); ++it ) {
1011 if ( QFile::exists( *it + ".h" ) )
1012 project->variables()["SOURCES"].append( *it + ".h" );
1013 }
1014 project->variables()["QMAKE_INTERNAL_PRL_LIBS"] << "MSVCDSP_LIBS";
1015}
1016
1017
1018QString
1019DspMakefileGenerator::findTemplate(const QString &file)
1020{
1021 QString ret;
1022 if(!QFile::exists((ret = file)) &&
1023 !QFile::exists((ret = QString(Option::mkfile::qmakespec + "/" + file))) &&
1024 !QFile::exists((ret = QString(getenv("QTDIR")) + "/mkspecs/win32-msvc/" + file)) &&
1025 !QFile::exists((ret = (QString(getenv("HOME")) + "/.tmake/" + file))))
1026 return "";
1027 return ret;
1028}
1029
1030
1031void
1032DspMakefileGenerator::processPrlVariable(const QString &var, const QStringList &l)
1033{
1034 if(var == "QMAKE_PRL_DEFINES") {
1035 QStringList &out = project->variables()["MSVCDSP_DEFINES"];
1036 for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
1037 if(out.findIndex((*it)) == -1)
1038 out.append((" /D \"" + *it + "\""));
1039 }
1040 } else {
1041 MakefileGenerator::processPrlVariable(var, l);
1042 }
1043}
1044
1045
1046void
1047DspMakefileGenerator::beginGroupForFile(QString file, QTextStream &t,
1048 const QString& filter)
1049{
1050 if(project->isActiveConfig("flat"))
1051 return;
1052 fileFixify(file, QDir::currentDirPath(), QDir::currentDirPath(), TRUE);
1053 file = file.section(Option::dir_sep, 0, -2);
1054 if(file.right(Option::dir_sep.length()) != Option::dir_sep)
1055 file += Option::dir_sep;
1056 if(file == currentGroup)
1057 return;
1058
1059 if(file.isEmpty() || !QDir::isRelativePath(file)) {
1060 endGroups(t);
1061 return;
1062 }
1063
1064 QString tempFile = file;
1065 if(tempFile.startsWith(currentGroup))
1066 tempFile = tempFile.mid(currentGroup.length());
1067 int dirSep = currentGroup.findRev( Option::dir_sep );
1068
1069 while( !tempFile.startsWith( currentGroup ) && dirSep != -1 ) {
1070 currentGroup.truncate( dirSep );
1071 dirSep = currentGroup.findRev( Option::dir_sep );
1072 if ( !tempFile.startsWith( currentGroup ) && dirSep != -1 )
1073 t << "\n# End Group\n";
1074 }
1075 if ( !file.startsWith( currentGroup ) ) {
1076 t << "\n# End Group\n";
1077 currentGroup = "";
1078 }
1079
1080 QStringList dirs = QStringList::split(Option::dir_sep, file.right( file.length() - currentGroup.length() ) );
1081 for(QStringList::Iterator dir_it = dirs.begin(); dir_it != dirs.end(); ++dir_it) {
1082 t << "# Begin Group \"" << (*dir_it) << "\"\n"
1083 << "# Prop Default_Filter \"" << filter << "\"\n";
1084 }
1085 currentGroup = file;
1086}
1087
1088
1089void
1090DspMakefileGenerator::endGroups(QTextStream &t)
1091{
1092 if(project->isActiveConfig("flat"))
1093 return;
1094 else if(currentGroup.isEmpty())
1095 return;
1096
1097 QStringList dirs = QStringList::split(Option::dir_sep, currentGroup);
1098 for(QStringList::Iterator dir_it = dirs.end(); dir_it != dirs.begin(); --dir_it) {
1099 t << "\n# End Group\n";
1100 }
1101 currentGroup = "";
1102}
1103
1104bool
1105DspMakefileGenerator::openOutput(QFile &file) const
1106{
1107 QString outdir;
1108 if(!file.name().isEmpty()) {
1109 if(QDir::isRelativePath(file.name()))
1110 file.setName(Option::output_dir + file.name()); //pwd when qmake was run
1111 QFileInfo fi(file);
1112 if(fi.isDir())
1113 outdir = file.name() + QDir::separator();
1114 }
1115 if(!outdir.isEmpty() || file.name().isEmpty())
1116 file.setName(outdir + project->first("TARGET") + project->first("DSP_EXTENSION"));
1117 if(QDir::isRelativePath(file.name())) {
1118 QString ofile;
1119 ofile = file.name();
1120 int slashfind = ofile.findRev('\\');
1121 if (slashfind == -1) {
1122 ofile = ofile.replace(QRegExp("-"), "_");
1123 } else {
1124 int hypenfind = ofile.find('-', slashfind);
1125 while (hypenfind != -1 && slashfind < hypenfind) {
1126 ofile = ofile.replace(hypenfind, 1, "_");
1127 hypenfind = ofile.find('-', hypenfind + 1);
1128 }
1129 }
1130 file.setName(Option::fixPathToLocalOS(QDir::currentDirPath() + Option::dir_sep + ofile));
1131 }
1132 return Win32MakefileGenerator::openOutput(file);
1133}
Note: See TracBrowser for help on using the repository browser.