Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

msvc_dsp.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** 
00003 **
00004 ** Implementation of DspMakefileGenerator class.
00005 **
00006 ** Copyright (C) 1992-2003 Trolltech AS.  All rights reserved.
00007 **
00008 ** This file is part of qmake.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech AS of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** Licensees holding valid Qt Enterprise Edition licenses may use this
00020 ** file in accordance with the Qt Commercial License Agreement provided
00021 ** with the Software.
00022 **
00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 **
00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00027 **   information about Qt Commercial License Agreements.
00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00030 **
00031 ** Contact info@trolltech.com if any conditions of this licensing are
00032 ** not clear to you.
00033 **
00034 **********************************************************************/
00035 
00036 #include "msvc_dsp.h"
00037 #include "option.h"
00038 #include <qdir.h>
00039 #include <qregexp.h>
00040 #include <stdlib.h>
00041 #include <time.h>
00042 
00043 DspMakefileGenerator::DspMakefileGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE)
00044 {
00045 
00046 }
00047 
00048 bool
00049 DspMakefileGenerator::writeMakefile(QTextStream &t)
00050 {
00051     if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
00052         /* for now just dump, I need to generated an empty dsp or something.. */
00053         fprintf(stderr, "Project file not generated because all requirements not met:\n\t%s\n",
00054                 var("QMAKE_FAILED_REQUIREMENTS").latin1());
00055         return TRUE;
00056     }
00057 
00058     if(project->first("TEMPLATE") == "vcapp" ||
00059        project->first("TEMPLATE") == "vclib") {
00060         return writeDspParts(t);
00061     }
00062     else if(project->first("TEMPLATE") == "subdirs") {
00063         writeHeader(t);
00064         writeSubDirs(t);
00065         return TRUE;
00066     }
00067     return FALSE;
00068 }
00069 
00070 bool
00071 DspMakefileGenerator::writeDspParts(QTextStream &t)
00072 {
00073     QString dspfile;
00074     if ( !project->variables()["DSP_TEMPLATE"].isEmpty() ) {
00075         dspfile = project->first("DSP_TEMPLATE");
00076     } else {
00077         dspfile = project->first("MSVCDSP_TEMPLATE");
00078     }
00079     if (dspfile.startsWith("\"") && dspfile.endsWith("\""))
00080         dspfile = dspfile.mid(1, dspfile.length() - 2);
00081     QString dspfile_loc = findTemplate(dspfile);
00082 
00083     QFile file(dspfile_loc);
00084     if(!file.open(IO_ReadOnly)) {
00085         fprintf(stderr, "Cannot open dsp file: %s\n", dspfile.latin1());
00086         return FALSE;
00087     }
00088     QTextStream dsp(&file);
00089 
00090     QString platform = "Win32";
00091     if ( !project->variables()["QMAKE_PLATFORM"].isEmpty() )
00092         platform = varGlue("QMAKE_PLATFORM", "", " ", "");
00093 
00094     // Setup PCH variables
00095     precompH = project->first("PRECOMPILED_HEADER");
00096     QString namePCH = QFileInfo(precompH).fileName();
00097     usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
00098     if (usePCH) {
00099         // Created files
00100         QString origTarget = project->first("QMAKE_ORIG_TARGET");
00101         origTarget.replace(QRegExp("-"), "_");
00102         precompObj = "\"$(IntDir)\\" + origTarget + Option::obj_ext + "\"";
00103         precompPch = "\"$(IntDir)\\" + origTarget + ".pch\"";
00104         // Add PRECOMPILED_HEADER to HEADERS
00105         if (!project->variables()["HEADERS"].contains(precompH))
00106             project->variables()["HEADERS"] += precompH;
00107         // Add precompile compiler options
00108         project->variables()["PRECOMPILED_FLAGS_REL"]  = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" ";
00109         project->variables()["PRECOMPILED_FLAGS_DEB"]  = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" ";
00110         // Return to variable pool
00111         project->variables()["PRECOMPILED_OBJECT"] = precompObj;
00112         project->variables()["PRECOMPILED_PCH"]    = precompPch;
00113     }
00114     int rep;
00115     QString line;
00116     while ( !dsp.eof() ) {
00117         line = dsp.readLine();
00118         while((rep = line.find(QRegExp("\\$\\$[a-zA-Z0-9_-]*"))) != -1) {
00119             QString torep = line.mid(rep, line.find(QRegExp("[^\\$a-zA-Z0-9_-]"), rep) - rep);
00120             QString variable = torep.right(torep.length()-2);
00121 
00122             t << line.left(rep); //output the left side
00123             line = line.right(line.length() - (rep + torep.length())); //now past the variable
00124             if(variable == "MSVCDSP_SOURCES") {
00125                 if(project->variables()["SOURCES"].isEmpty())
00126                     continue;
00127 
00128                 QString mocpath = var( "QMAKE_MOC" );
00129                 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
00130 
00131                 QStringList list = project->variables()["SOURCES"] + project->variables()["DEF_FILE"];
00132                 if(!project->isActiveConfig("flat"))
00133                     list.sort();
00134                 QStringList::Iterator it;
00135                 for( it = list.begin(); it != list.end(); ++it) {
00136                     beginGroupForFile((*it), t);
00137                     t << "# Begin Source File\n\nSOURCE=" << (*it) << endl;
00138                     if (usePCH && (*it).endsWith(".c"))
00139                         t << "# SUBTRACT CPP /FI\"" << namePCH << "\" /Yu\"" << namePCH << "\" /Fp" << endl;
00140                     if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) {
00141                         QString base = (*it);
00142                         base.replace(QRegExp("\\..*$"), "").upper();
00143                         base.replace(QRegExp("[^a-zA-Z]"), "_");
00144 
00145                         QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) +
00146                                         "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\""
00147                                         " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n"
00148                                         "\t" + mocpath + findMocSource((*it)) + " -o " +
00149                                         (*it) + "\n\n" "# End Custom Build\n\n";
00150 
00151                         t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl;
00152 
00153                         t << "!IF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
00154                           << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\""
00155                           << build << "!ENDIF " << endl << endl;
00156                     }
00157                     t << "# End Source File" << endl;
00158                 }
00159                 endGroups(t);
00160             } else if(variable == "MSVCDSP_IMAGES") {
00161                 if(project->variables()["IMAGES"].isEmpty())
00162                     continue;
00163                 t << "# Begin Source File\n\nSOURCE=" << project->first("QMAKE_IMAGE_COLLECTION") << endl;
00164                 t << "# End Source File" << endl;
00165             } else if(variable == "MSVCDSP_HEADERS") {
00166                 if(project->variables()["HEADERS"].isEmpty())
00167                     continue;
00168 
00169                 QStringList list = project->variables()["HEADERS"];
00170                 if(!project->isActiveConfig("flat"))
00171                     list.sort();
00172                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00173 //                  beginGroupForFile((*it), t);
00174                     t << "# Begin Source File\n\nSOURCE=" << (*it) << endl << endl;
00175                     QString compilePCH;
00176                     QStringList customDependencies;
00177                     QString createMOC;
00178                     QString buildCmdsR, buildCmdsD;
00179                     QString buildCmds = "\nBuildCmds= \\\n";
00180                     // Create unique baseID
00181                     QString base = (*it);
00182                     {
00183                         base.replace(QRegExp("\\..*$"), "").upper();
00184                         base.replace(QRegExp("[^a-zA-Z]"), "_");
00185                     }
00186                     if (usePCH && precompH.endsWith(*it)) {
00187                         QString basicBuildCmd = QString("\tcl.exe /TP /W3 /FD /c /D \"WIN32\" /Yc /Fp\"%1\" /Fo\"%2\" %3 %4 %5 %6 %7 %8 %9 /D \"")
00188                                                         .arg(precompPch)
00189                                                         .arg(precompObj)
00190                                                         .arg(var("MSVCDSP_INCPATH"))
00191                                                         .arg(var("MSVCDSP_DEFINES"))
00192                                                         .arg(var("MSVCDSP_CXXFLAGS"));
00193                         buildCmdsR = basicBuildCmd
00194                                             .arg("/D \"NDEBUG\"")
00195                                             .arg(var("QMAKE_CXXFLAGS_RELEASE"))
00196                                             .arg(var("MSVCDSP_MTDEF"))
00197                                             .arg(var("MSVCDSP_RELDEFS"));
00198                         buildCmdsD = basicBuildCmd
00199                                             .arg("/D \"_DEBUG\" /Od")
00200                                             .arg(var("QMAKE_CXXFLAGS_DEBUG"))
00201                                             .arg(var("MSVCDSP_MTDEFD"))
00202                                             .arg(var("MSVCDSP_DEBUG_OPT"));
00203                         if (project->first("TEMPLATE") == "vcapp") {    // App
00204                             buildCmdsR += var("MSVCDSP_WINCONDEF");
00205                             buildCmdsD += var("MSVCDSP_WINCONDEF");
00206                         } else if (project->isActiveConfig("dll")) {    // Dll
00207                             buildCmdsR += "_WINDOWS\" /D \"_USRDLL";
00208                             buildCmdsD += "_WINDOWS\" /D \"_USRDLL";
00209                         } else {                                        // Lib
00210                             buildCmdsR += "_LIB";
00211                             buildCmdsD += "_LIB";
00212                         }
00213                         buildCmdsR += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n";
00214                         buildCmdsD += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n";
00215 
00216                         compilePCH = precompPch + " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n   $(BuildCmds)\n\n";
00217 
00218                         QStringList &tmp = findDependencies(precompH);
00219                         if(!tmp.isEmpty()) // Got Deps for PCH
00220                             customDependencies += tmp;
00221                     }
00222                     if (project->isActiveConfig("moc") && !findMocDestination((*it)).isEmpty()) {
00223                         QString mocpath = var( "QMAKE_MOC" );
00224                         mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
00225                         buildCmds += "\t" + mocpath + (*it)  + " -o " + findMocDestination((*it)) + " \\\n";
00226                         createMOC  = "\"" + findMocDestination((*it)) + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n   $(BuildCmds)\n\n";
00227                         customDependencies += "\"$(QTDIR)\\bin\\moc.exe\"";
00228                     }
00229                     if (!createMOC.isEmpty() || !compilePCH.isEmpty()) {
00230                         bool doMOC = !createMOC.isEmpty();
00231                         bool doPCH = !compilePCH.isEmpty();
00232                         QString build = "\n\n# Begin Custom Build - "+ 
00233                                         QString(doMOC?"Moc'ing ":"") +
00234                                         QString((doMOC&&doPCH)?" and ":"") +
00235                                         QString(doPCH?"Creating PCH cpp from ":"") +
00236                                         (*it) + "...\nInputPath=.\\" + (*it) + "\n\n" +
00237                                         buildCmds + "%1\n" +
00238                                         createMOC + 
00239                                         compilePCH +
00240                                         "# End Custom Build\n\n";
00241 
00242                         t << "USERDEP_" << base << "=" << valGlue(customDependencies, "\"", "\" \"", "\"") << endl << endl;
00243                         t << "!IF  \"$(CFG)\" == \""     << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build.arg(buildCmdsR)
00244                           << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\""   << build.arg(buildCmdsD)
00245                           << "!ENDIF " << endl << endl;
00246                     }
00247                     t << "# End Source File" << endl;
00248                 }
00249 //              endGroups(t);
00250             } else if(variable == "MSVCDSP_FORMSOURCES" || variable == "MSVCDSP_FORMHEADERS") {
00251                 if(project->variables()["FORMS"].isEmpty())
00252                     continue;
00253 
00254                 QString uiSourcesDir;
00255                 QString uiHeadersDir;
00256                 if(!project->variables()["UI_DIR"].isEmpty()) {
00257                     uiSourcesDir = project->first("UI_DIR");
00258                     uiHeadersDir = project->first("UI_DIR");
00259                 } else {
00260                     if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() )
00261                         uiSourcesDir = project->first("UI_SOURCES_DIR");
00262                     else
00263                         uiSourcesDir = "";
00264                     if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() )
00265                         uiHeadersDir = project->first("UI_HEADERS_DIR");
00266                     else
00267                         uiHeadersDir = "";
00268                 }
00269 
00270                 QStringList list = project->variables()["FORMS"];
00271                 if(!project->isActiveConfig("flat"))
00272                     list.sort();
00273                 QString ext = variable == "MSVCDSP_FORMSOURCES" ? ".cpp" : ".h";
00274                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00275                     QString base = (*it);
00276                     int dot = base.findRev(".");
00277                     base.replace( dot, base.length() - dot, ext );
00278                     QString fname = base;
00279 
00280                     int lbs = fname.findRev( "\\" );
00281                     QString fpath;
00282                     if ( lbs != -1 )
00283                         fpath = fname.left( lbs + 1 );
00284                     fname = fname.right( fname.length() - lbs - 1 );
00285 
00286                     if ( ext == ".cpp" && !uiSourcesDir.isEmpty() )
00287                         fname.prepend(uiSourcesDir);
00288                     else if ( ext == ".h" && !uiHeadersDir.isEmpty() )
00289                         fname.prepend(uiHeadersDir);
00290                     else
00291                         fname = base;
00292 //                  beginGroupForFile(fname, t);
00293                     t << "# Begin Source File\n\nSOURCE=" << fname
00294                       << "\n# End Source File" << endl;
00295                 }
00296 //              endGroups(t);
00297             } else if(variable == "MSVCDSP_TRANSLATIONS" ) {
00298                 if(project->variables()["TRANSLATIONS"].isEmpty())
00299                     continue;
00300 
00301                 t << "# Begin Group \"Translations\"\n";
00302                 t << "# Prop Default_Filter \"ts\"\n";
00303 
00304                 QStringList list = project->variables()["TRANSLATIONS"];
00305                 if(!project->isActiveConfig("flat"))
00306                     list.sort();
00307                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00308                     QString sify = *it;
00309                     sify.replace('/', '\\' );
00310                     QString base = (*it);
00311                     base.replace(QRegExp("\\..*$"), "").upper();
00312                     base.replace(QRegExp("[^a-zA-Z]"), "_");
00313 
00314 //                  beginGroupForFile(sify, t);
00315                     t << "# Begin Source File\n\nSOURCE=" << sify << endl;
00316                     t << "\n# End Source File" << endl;
00317                 }
00318 //              endGroups(t);
00319                 t << "\n# End Group\n";
00320             } else if (variable == "MSVCDSP_MOCSOURCES" && project->isActiveConfig("moc")) {
00321                 if ( project->variables()["SRCMOC"].isEmpty())
00322                     continue;
00323 
00324                 QString mocpath = var( "QMAKE_MOC" );
00325                 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
00326 
00327                 QStringList list = project->variables()["SRCMOC"];
00328                 if(!project->isActiveConfig("flat"))
00329                     list.sort();
00330                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00331 //                  beginGroupForFile((*it), t);
00332                     t << "# Begin Source File\n\nSOURCE=" << (*it) << endl;
00333                     if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) {
00334                         QString base = (*it);
00335                         base.replace(QRegExp("\\..*$"), "").upper();
00336                         base.replace(QRegExp("[^a-zA-Z]"), "_");
00337 
00338                         QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) +
00339                                         "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\""
00340                                         " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n"
00341                                         "\t" + mocpath + findMocSource((*it)) + " -o " +
00342                                         (*it) + "\n\n" "# End Custom Build\n\n";
00343 
00344                         t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl;
00345 
00346                         t << "!IF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
00347                           << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\""
00348                           << build << "!ENDIF " << endl << endl;
00349                     }
00350                     t << "# End Source File" << endl;
00351                 }
00352 //              endGroups(t);
00353             } else if(variable == "MSVCDSP_PICTURES") {
00354                 if(project->variables()["IMAGES"].isEmpty())
00355                     continue;
00356 
00357                 t << "# Begin Group \"Images\"\n"
00358                   << "# Prop Default_Filter \"png jpeg bmp xpm\"\n";
00359 
00360                 QStringList list = project->variables()["IMAGES"];
00361                 if(!project->isActiveConfig("flat"))
00362                     list.sort();
00363                 QStringList::Iterator it;
00364 
00365                 // dump the image list to a file UIC can read.
00366                 QFile f( "images.tmp" );
00367                 f.open( IO_WriteOnly );
00368                 QTextStream ts( &f );
00369                 for( it = list.begin(); it != list.end(); ++it )
00370                     ts << " " << *it;
00371                 f.close();
00372 
00373                 // create an output step for images not more than once
00374                 bool imagesBuildDone = FALSE;
00375                 for( it = list.begin(); it != list.end(); ++it ) {
00376 //                  beginGroupForFile((*it), t);
00377                     t << "# Begin Source File\n\nSOURCE=" << (*it) << endl;
00378 
00379                     QString base = (*it);
00380                     QString uicpath = var("QMAKE_UIC");
00381                     uicpath = uicpath.replace(QRegExp("\\..*$"), "") + " ";
00382 
00383                     if ( !imagesBuildDone ) {
00384                         imagesBuildDone = TRUE;
00385                         QString build = "\n\n# Begin Custom Build - Creating image collection...\n"
00386                             "InputPath=.\\" + base + "\n\n";
00387 
00388                         build += "\"" + project->first("QMAKE_IMAGE_COLLECTION") + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n";
00389                         build += "\t" + uicpath + "-embed " + project->first("QMAKE_ORIG_TARGET") + " -f images.tmp -o "
00390                                       + project->first("QMAKE_IMAGE_COLLECTION") + "\n\n";
00391                         build.append("# End Custom Build\n\n");
00392 
00393                         t << "USERDEP_" << base << "=";
00394                         QStringList::Iterator it2 = list.begin();
00395                         while ( it2 != list.end() ) {
00396                             t << "\"" << (*it2) << "\"";
00397                             it2++;
00398                             if ( it2 != list.end() )
00399                                 t << "\\\n";
00400                         }
00401                         t << endl << endl;
00402 
00403                         t << "!IF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - Win32 Release\"" << build
00404                           << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - Win32 Debug\"" << build
00405                           << "!ENDIF \n\n" << endl;
00406                     }
00407 
00408                     t << "# End Source File" << endl;
00409                 }
00410 //              endGroups(t);
00411                 t << "\n# End Group\n";
00412             } else if(variable == "MSVCDSP_FORMS") {
00413                 if(project->variables()["FORMS"].isEmpty())
00414                     continue;
00415 
00416                 t << "# Begin Group \"Forms\"\n"
00417                   << "# Prop Default_Filter \"ui\"\n";
00418 
00419                 QString uicpath = var("QMAKE_UIC");
00420                 uicpath = uicpath.replace(QRegExp("\\..*$"), "") + " ";
00421                 QString mocpath = var( "QMAKE_MOC" );
00422                 mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " ";
00423 
00424                 QStringList list = project->variables()["FORMS"];
00425                 if(!project->isActiveConfig("flat"))
00426                     list.sort();
00427                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00428                     QString base = (*it);
00429 //                  beginGroupForFile(base, t);
00430                     t <<  "# Begin Source File\n\nSOURCE=" << base << endl;
00431 
00432                     QString fname = base;
00433                     fname.replace(".ui", "");
00434                     int lbs = fname.findRev( "\\" );
00435                     QString fpath;
00436                     if ( lbs != -1 )
00437                         fpath = fname.left( lbs + 1 );
00438                     fname = fname.right( fname.length() - lbs - 1 );
00439 
00440                     QString mocFile;
00441                     if(!project->variables()["MOC_DIR"].isEmpty())
00442                         mocFile = project->first("MOC_DIR");
00443                     else
00444                         mocFile = fpath;
00445 
00446                     QString uiSourcesDir;
00447                     QString uiHeadersDir;
00448                     if(!project->variables()["UI_DIR"].isEmpty()) {
00449                         uiSourcesDir = project->first("UI_DIR");
00450                         uiHeadersDir = project->first("UI_DIR");
00451                     } else {
00452                         if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() )
00453                             uiSourcesDir = project->first("UI_SOURCES_DIR");
00454                         else
00455                             uiSourcesDir = fpath;
00456                         if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() )
00457                             uiHeadersDir = project->first("UI_HEADERS_DIR");
00458                         else
00459                             uiHeadersDir = fpath;
00460                     }
00461 
00462                     t << "USERDEP_" << base << "=\"$(QTDIR)\\bin\\moc.exe\" \"$(QTDIR)\\bin\\uic.exe\"" << endl << endl;
00463 
00464                     QString build = "\n\n# Begin Custom Build - Uic'ing " + base + "...\n"
00465                         "InputPath=.\\" + base + "\n\n" "BuildCmds= \\\n\t" + uicpath + base +
00466                                     " -o " + uiHeadersDir + fname + ".h \\\n" "\t" + uicpath  + base +
00467                                     " -i " + fname + ".h -o " + uiSourcesDir + fname + ".cpp \\\n"
00468                                     "\t" + mocpath + " " + uiHeadersDir +
00469                                     fname + ".h -o " + mocFile + Option::h_moc_mod + fname + Option::h_moc_ext + " \\\n";
00470 
00471                     build.append("\n\"" + uiHeadersDir + fname + ".h\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\""  "\n"
00472                                  "\t$(BuildCmds)\n\n"
00473                                  "\"" + uiSourcesDir + fname + ".cpp\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
00474                                  "\t$(BuildCmds)\n\n"
00475                                  "\"" + mocFile + Option::h_moc_mod + fname + Option::h_moc_ext + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
00476                                  "\t$(BuildCmds)\n\n");
00477 
00478                     build.append("# End Custom Build\n\n");
00479 
00480                     t << "!IF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
00481                       << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build
00482                       << "!ENDIF \n\n" << "# End Source File" << endl;
00483                 }
00484 //              endGroups(t);
00485                 t << "\n# End Group\n";
00486             } else if(variable == "MSVCDSP_LEXSOURCES") {
00487                 if(project->variables()["LEXSOURCES"].isEmpty())
00488                     continue;
00489 
00490                 t << "# Begin Group \"Lexables\"\n"
00491                   << "# Prop Default_Filter \"l\"\n";
00492 
00493                 QString lexpath = var("QMAKE_LEX") + varGlue("QMAKE_LEXFLAGS", " ", " ", "") + " ";
00494 
00495                 QStringList list = project->variables()["LEXSOURCES"];
00496                 if(!project->isActiveConfig("flat"))
00497                     list.sort();
00498                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00499                     QString fname = (*it);
00500 //                  beginGroupForFile(fname, t);
00501                     t <<  "# Begin Source File\n\nSOURCE=" << fname << endl;
00502                     fname.replace(".l", Option::lex_mod + Option::cpp_ext.first());
00503 
00504                     QString build = "\n\n# Begin Custom Build - Lex'ing " + (*it) + "...\n"
00505                         "InputPath=.\\" + (*it) + "\n\n"
00506                                     "\"" + fname + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
00507                                     "\t" + lexpath + (*it) + "\\\n"
00508                                     "\tdel " + fname + "\\\n"
00509                                     "\tcopy lex.yy.c " + fname + "\n\n" +
00510                                     "# End Custom Build\n\n";
00511                     t << "!IF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
00512                       << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build
00513                       << "!ENDIF \n\n" << build
00514 
00515                       << "# End Source File" << endl;
00516                 }
00517 //              endGroups(t);
00518                 t << "\n# End Group\n";
00519             } else if(variable == "MSVCDSP_YACCSOURCES") {
00520                 if(project->variables()["YACCSOURCES"].isEmpty())
00521                     continue;
00522 
00523                 t << "# Begin Group \"Yaccables\"\n"
00524                   << "# Prop Default_Filter \"y\"\n";
00525 
00526                 QString yaccpath = var("QMAKE_YACC") + varGlue("QMAKE_YACCFLAGS", " ", " ", "") + " ";
00527 
00528                 QStringList list = project->variables()["YACCSOURCES"];
00529                 if(!project->isActiveConfig("flat"))
00530                     list.sort();
00531                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00532                     QString fname = (*it);
00533 //                  beginGroupForFile(fname, t);
00534                     t <<  "# Begin Source File\n\nSOURCE=" << fname << endl;
00535                     fname.replace(".y", Option::yacc_mod);
00536 
00537                     QString build = "\n\n# Begin Custom Build - Yacc'ing " + (*it) + "...\n"
00538                         "InputPath=.\\" + (*it) + "\n\n"
00539                                     "\"" + fname + Option::cpp_ext.first() + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n"
00540                                     "\t" + yaccpath + (*it) + "\\\n"
00541                                     "\tdel " + fname + Option::h_ext.first() + "\\\n"
00542                                     "\tmove y.tab.h " + fname + Option::h_ext.first() + "\n\n" +
00543                                     "\tdel " + fname + Option::cpp_ext.first() + "\\\n"
00544                                     "\tmove y.tab.c " + fname + Option::cpp_ext.first() + "\n\n" +
00545                                     "# End Custom Build\n\n";
00546 
00547                     t << "!IF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build
00548                       << "!ELSEIF  \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build
00549                       << "!ENDIF \n\n"
00550                       << "# End Source File" << endl;
00551                 }
00552 //              endGroups(t);
00553                 t << "\n# End Group\n";
00554             } else if( variable == "MSVCDSP_CONFIGMODE" ) {
00555                 if( project->isActiveConfig( "debug" ) )
00556                     t << "Debug";
00557                 else
00558                     t << "Release";
00559             } else if( variable == "MSVCDSP_IDLSOURCES" ) {
00560                 QStringList list = project->variables()["MSVCDSP_IDLSOURCES"];
00561                 if(!project->isActiveConfig("flat"))
00562                     list.sort();
00563                 for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00564                     t << "# Begin Source File" << endl << endl;
00565                     t << "SOURCE=" << (*it) << endl;
00566                     t << "# PROP Exclude_From_Build 1" << endl;
00567                     t << "# End Source File" << endl << endl;
00568                 }
00569             }
00570             else
00571                 t << var(variable);
00572         }
00573         t << line << endl;
00574     }
00575     t << endl;
00576     file.close();
00577     return TRUE;
00578 }
00579 
00580 
00581 
00582 void
00583 DspMakefileGenerator::init()
00584 {
00585     if(init_flag)
00586         return;
00587     QStringList::Iterator it;
00588     init_flag = TRUE;
00589 
00590     const bool thread = project->isActiveConfig("thread");
00591 
00592     if ( project->isActiveConfig("stl") ) {
00593         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_ON"];
00594         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_ON"];
00595     } else {
00596         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_OFF"];
00597         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_OFF"];
00598     }
00599     if ( project->isActiveConfig("exceptions") ) {
00600         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_ON"];
00601         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_ON"];
00602     } else {
00603         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_OFF"];
00604         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_OFF"];
00605     }
00606     if ( project->isActiveConfig("rtti") ) {
00607         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_ON"];
00608         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_ON"];
00609     } else {
00610         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_OFF"];
00611         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_OFF"];
00612     }
00613 
00614     
00615     /* this should probably not be here, but I'm using it to wrap the .t files */
00616     if(project->first("TEMPLATE") == "vcapp" )
00617         project->variables()["QMAKE_APP_FLAG"].append("1");
00618     else if(project->first("TEMPLATE") == "vclib")
00619         project->variables()["QMAKE_LIB_FLAG"].append("1");
00620     if ( project->variables()["QMAKESPEC"].isEmpty() )
00621         project->variables()["QMAKESPEC"].append( getenv("QMAKESPEC") );
00622 
00623     bool is_qt = (project->first("TARGET") == "qt"QTDLL_POSTFIX || project->first("TARGET") == "qt-mt"QTDLL_POSTFIX);
00624     project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
00625 
00626     QStringList &configs = project->variables()["CONFIG"];
00627     if (project->isActiveConfig("shared"))
00628         project->variables()["DEFINES"].append("QT_DLL");
00629     if (project->isActiveConfig("qt_dll"))
00630         if(configs.findIndex("qt") == -1) configs.append("qt");
00631     if ( project->isActiveConfig("qtopia") ) {
00632         if(configs.findIndex("qtopialib") == -1)
00633             configs.append("qtopialib");
00634         if(configs.findIndex("qtopiainc") == -1)
00635             configs.append("qtopiainc");
00636     }
00637     if ( project->isActiveConfig("qt") ) {
00638         if ( project->isActiveConfig( "plugin" ) ) {
00639             project->variables()["CONFIG"].append("dll");
00640             project->variables()["DEFINES"].append("QT_PLUGIN");
00641         }
00642         if ( (project->variables()["DEFINES"].findIndex("QT_NODLL") == -1) &&
00643              ((project->variables()["DEFINES"].findIndex("QT_MAKEDLL") != -1 ||
00644                project->variables()["DEFINES"].findIndex("QT_DLL") != -1) ||
00645               (getenv("QT_DLL") && !getenv("QT_NODLL"))) ) {
00646             project->variables()["QMAKE_QT_DLL"].append("1");
00647             if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() )
00648                 project->variables()["CONFIG"].append("dll");
00649         }
00650     }
00651     if ( project->isActiveConfig("dll") || !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
00652         project->variables()["CONFIG"].remove("staticlib");
00653         project->variables()["QMAKE_APP_OR_DLL"].append("1");
00654     } else {
00655         project->variables()["CONFIG"].append("staticlib");
00656     }
00657 
00658     if ( project->isActiveConfig("qt") || project->isActiveConfig("opengl") ) {
00659         project->variables()["CONFIG"].append("windows");
00660     }
00661     if ( !project->variables()["VERSION"].isEmpty() ) {
00662         QString version = project->variables()["VERSION"][0];
00663         int firstDot = version.find( "." );
00664         QString major = version.left( firstDot );
00665         QString minor = version.right( version.length() - firstDot - 1 );
00666         minor.replace( ".", "" );
00667         project->variables()["MSVCDSP_VERSION"].append( "/VERSION:" + major + "." + minor );
00668     }
00669 
00670     if ( project->isActiveConfig("qtopiainc") )
00671         project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QTOPIA"];
00672     if ( project->isActiveConfig("qtopialib") ) {
00673         if(!project->isEmpty("QMAKE_LIBDIR_QTOPIA"))
00674             project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QTOPIA"];
00675         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QTOPIA"];
00676     }
00677 
00678     if ( project->isActiveConfig("qt") ) {
00679         project->variables()["CONFIG"].append("moc");
00680         project->variables()["INCLUDEPATH"] +=  project->variables()["QMAKE_INCDIR_QT"];
00681         project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
00682 
00683         if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
00684             if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
00685                 project->variables()["DEFINES"].append("QT_MAKEDLL");
00686                 project->variables()["QMAKE_LFLAGS"].append("/base:\"0x39D00000\"");
00687             }
00688         } else {
00689             if( thread )
00690                 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
00691             else
00692                 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
00693             if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
00694                 int hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt");
00695                 if ( hver == -1 )
00696                     hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt-mt");
00697                 if(hver != -1) {
00698                     QString ver;
00699                     ver.sprintf("qt%s" QTDLL_POSTFIX "%d.lib", (thread ? "-mt" : ""), hver);
00700                     QStringList &libs = project->variables()["QMAKE_LIBS"];
00701                     for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit)
00702                         (*libit).replace(QRegExp("qt(-mt)?\\.lib"), ver);
00703                 }
00704             }
00705             if ( project->isActiveConfig( "activeqt" ) ) {
00706                 project->variables().remove("QMAKE_LIBS_QT_ENTRY");
00707                 project->variables()["QMAKE_LIBS_QT_ENTRY"] = "qaxserver.lib";
00708                 if ( project->isActiveConfig( "dll" ) )
00709                     project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_ENTRY"];
00710             }
00711             if ( !project->isActiveConfig("dll") && !project->isActiveConfig("plugin") ) {
00712                 project->variables()["QMAKE_LIBS"] +=project->variables()["QMAKE_LIBS_QT_ENTRY"];
00713             }
00714         }
00715     }
00716 
00717     if ( project->isActiveConfig("debug") ) {
00718         if ( !project->first("OBJECTS_DIR").isEmpty() )
00719             project->variables()["MSVCDSP_OBJECTSDIRDEB"] = project->first("OBJECTS_DIR");
00720         else
00721             project->variables()["MSVCDSP_OBJECTSDIRDEB"] = "Debug";
00722         project->variables()["MSVCDSP_OBJECTSDIRREL"] = "Release";
00723         if ( !project->first("DESTDIR").isEmpty() )
00724             project->variables()["MSVCDSP_TARGETDIRDEB"] = project->first("DESTDIR");
00725         else
00726             project->variables()["MSVCDSP_TARGETDIRDEB"] = "Debug";
00727         project->variables()["MSVCDSP_TARGETDIRREL"] = "Release";
00728     } else {
00729         if ( !project->first("OBJECTS_DIR").isEmpty() )
00730             project->variables()["MSVCDSP_OBJECTSDIRREL"] = project->first("OBJECTS_DIR");
00731         else
00732             project->variables()["MSVCDSP_OBJECTSDIRREL"] = "Release";
00733         project->variables()["MSVCDSP_OBJECTSDIRDEB"] = "Debug";
00734         if ( !project->first("DESTDIR").isEmpty() )
00735             project->variables()["MSVCDSP_TARGETDIRREL"] = project->first("DESTDIR");
00736         else
00737             project->variables()["MSVCDSP_TARGETDIRREL"] = "Release";
00738         project->variables()["MSVCDSP_TARGETDIRDEB"] = "Debug";
00739     }
00740 
00741     if ( project->isActiveConfig("opengl") ) {
00742         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
00743         project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
00744     }
00745     if ( thread ) {
00746         if(project->isActiveConfig("qt"))
00747             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_THREAD_SUPPORT" );
00748         if ( project->isActiveConfig("dll") || project->first("TARGET") == "qtmain"
00749              || !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
00750             project->variables()["MSVCDSP_MTDEFD"] += project->variables()["QMAKE_CXXFLAGS_MT_DLLDBG"];
00751             project->variables()["MSVCDSP_MTDEF"] += project->variables()["QMAKE_CXXFLAGS_MT_DLL"];
00752         } else {
00753             // YES we want to use the DLL even in a static build
00754             project->variables()["MSVCDSP_MTDEFD"] += project->variables()["QMAKE_CXXFLAGS_MT_DBG"];
00755             project->variables()["MSVCDSP_MTDEF"] += project->variables()["QMAKE_CXXFLAGS_MT"];
00756         }
00757         if ( !project->variables()["DEFINES"].contains("QT_DLL") && is_qt
00758              && project->first("TARGET") != "qtmain" )
00759             project->variables()["QMAKE_LFLAGS"].append("/NODEFAULTLIB:\"libc\"");
00760     }
00761 
00762     if(project->isActiveConfig("qt")) {
00763         if ( project->isActiveConfig("accessibility" ) )
00764             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_ACCESSIBILITY_SUPPORT");
00765         if ( project->isActiveConfig("tablet") )
00766             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_TABLET_SUPPORT");
00767     }
00768     if ( project->isActiveConfig("dll") ) {
00769         project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE_DLL"];
00770         project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE_DLL"];
00771         project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE_DLL"];
00772         project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS_DLL"];
00773         if ( !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
00774             QString ver_xyz(project->first("VERSION"));
00775             ver_xyz.replace(".", "");
00776             project->variables()["TARGET_EXT"].append(ver_xyz + ".dll");
00777         } else {
00778             project->variables()["TARGET_EXT"].append(".dll");
00779         }
00780     } else {
00781         project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE"];
00782         project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE"];
00783         project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE"];
00784         project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS"];
00785         if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty() )
00786             project->variables()["TARGET_EXT"].append(".exe");
00787         else
00788             project->variables()["TARGET_EXT"].append(".lib");
00789     }
00790 
00791     if ( project->isActiveConfig("windows") ) {
00792         if ( project->isActiveConfig("console") ) {
00793             project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
00794             project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
00795             project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
00796             project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
00797         } else {
00798             project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"];
00799         }
00800         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
00801     } else {
00802         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
00803         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
00804         project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
00805         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
00806     }
00807 
00808     project->variables()["MSVCDSP_VER"] = "6.00";
00809     project->variables()["MSVCDSP_DEBUG_OPT"] = "/GZ /ZI";
00810 
00811     if(!project->isActiveConfig("incremental")) {
00812         project->variables()["QMAKE_LFLAGS"].append(QString("/incremental:no"));
00813         if ( is_qt )
00814             project->variables()["MSVCDSP_DEBUG_OPT"] = "/GZ /Zi";
00815     }
00816 
00817     QString msvcdsp_project;
00818     if ( project->variables()["TARGET"].count() )
00819         msvcdsp_project = project->variables()["TARGET"].first();
00820 
00821     QString targetfilename = project->variables()["TARGET"].first();
00822     project->variables()["TARGET"].first() += project->first("TARGET_EXT");
00823     if ( project->isActiveConfig("moc") )
00824         setMocAware(TRUE);
00825 
00826     project->variables()["QMAKE_LIBS"] += project->variables()["LIBS"];
00827     project->variables()["QMAKE_FILETAGS"] += QStringList::split(' ',
00828                                                                  "HEADERS SOURCES DEF_FILE RC_FILE TARGET QMAKE_LIBS DESTDIR DLLDESTDIR INCLUDEPATH");
00829     QStringList &l = project->variables()["QMAKE_FILETAGS"];
00830     for(it = l.begin(); it != l.end(); ++it) {
00831         QStringList &gdmf = project->variables()[(*it)];
00832         for(QStringList::Iterator inner = gdmf.begin(); inner != gdmf.end(); ++inner)
00833             (*inner) = Option::fixPathToTargetOS((*inner), FALSE);
00834     }
00835 
00836     MakefileGenerator::init();
00837     if ( msvcdsp_project.isEmpty() )
00838         msvcdsp_project = Option::output.name();
00839 
00840     msvcdsp_project = msvcdsp_project.right( msvcdsp_project.length() - msvcdsp_project.findRev( "\\" ) - 1 );
00841     msvcdsp_project = msvcdsp_project.left( msvcdsp_project.findRev( "." ) );
00842     msvcdsp_project.replace("-", "");
00843 
00844     project->variables()["MSVCDSP_PROJECT"].append(msvcdsp_project);
00845     QStringList &proj = project->variables()["MSVCDSP_PROJECT"];
00846 
00847     for(it = proj.begin(); it != proj.end(); ++it)
00848         (*it).replace(QRegExp("\\.[a-zA-Z0-9_]*$"), "");
00849 
00850     if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
00851         project->variables()["MSVCDSP_TEMPLATE"].append("win32app" + project->first( "DSP_EXTENSION" ) );
00852         if ( project->isActiveConfig("console") ) {
00853             project->variables()["MSVCDSP_CONSOLE"].append("Console");
00854             project->variables()["MSVCDSP_WINCONDEF"].append("_CONSOLE");
00855             project->variables()["MSVCDSP_DSPTYPE"].append("0x0103");
00856         } else {
00857             project->variables()["MSVCDSP_CONSOLE"].clear();
00858             project->variables()["MSVCDSP_WINCONDEF"].append("_WINDOWS");
00859             project->variables()["MSVCDSP_DSPTYPE"].append("0x0101");
00860         }
00861     } else {
00862         if ( project->isActiveConfig("dll") ) {
00863             project->variables()["MSVCDSP_TEMPLATE"].append("win32dll" + project->first( "DSP_EXTENSION" ) );
00864         } else {
00865             project->variables()["MSVCDSP_TEMPLATE"].append("win32lib" + project->first( "DSP_EXTENSION" ) );
00866         }
00867     }
00868 
00869     project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
00870  
00871     processPrlFiles();
00872 
00873      // Update -lname to name.lib,
00874     QStringList &libs2 = project->variables()["QMAKE_LIBS"];
00875     for ( QStringList::Iterator libit2 = libs2.begin(); libit2 != libs2.end(); ++libit2 ) {
00876         if (  (*libit2).startsWith( "-l" ) ) {
00877             (*libit2) = (*libit2).mid( 2 ) + ".lib";
00878         } else if ( (*libit2).startsWith( "-L" ) ) {
00879             project->variables()["QMAKE_LIBDIR"] += (*libit2).mid(2);
00880             libit2 = libs2.remove( libit2 );
00881         }
00882     }
00883     
00884     project->variables()["MSVCDSP_LFLAGS" ] += project->variables()["QMAKE_LFLAGS"];
00885     if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() )
00886         project->variables()["MSVCDSP_LFLAGS" ].append(varGlue("QMAKE_LIBDIR","/LIBPATH:\"","\" /LIBPATH:\"","\""));
00887     project->variables()["MSVCDSP_CXXFLAGS" ] += project->variables()["QMAKE_CXXFLAGS"];
00888     project->variables()["MSVCDSP_DEFINES"].append(varGlue("DEFINES","/D ","" " /D ",""));
00889     project->variables()["MSVCDSP_DEFINES"].append(varGlue("PRL_EXPORT_DEFINES","/D ","" " /D ",""));
00890 
00891     if (!project->variables()["RES_FILE"].isEmpty())
00892         project->variables()["QMAKE_LIBS"] += project->variables()["RES_FILE"];
00893 
00894     QStringList &libs = project->variables()["QMAKE_LIBS"];
00895     for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit) {
00896         QString lib = (*libit);
00897         lib.replace(QRegExp("\""), "");
00898         project->variables()["MSVCDSP_LIBS"].append(" \"" + lib + "\"");
00899     }
00900 
00901     QStringList &incs = project->variables()["INCLUDEPATH"];
00902     for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
00903         QString inc = (*incit);
00904         inc.replace("\"", "");
00905         if(inc.endsWith("\\")) // Remove trailing \'s from paths
00906             inc.truncate(inc.length()-1);
00907         project->variables()["MSVCDSP_INCPATH"].append("/I \"" + inc + "\"");
00908     }
00909 
00910     project->variables()["MSVCDSP_INCPATH"].append("/I \"" + specdir() + "\"");
00911     if ( project->isActiveConfig("qt") ) {
00912         project->variables()["MSVCDSP_RELDEFS"].append("/D \"QT_NO_DEBUG\"");
00913     } else {
00914         project->variables()["MSVCDSP_RELDEFS"].clear();
00915     }
00916 
00917     QString dest;
00918     QString postLinkStep;
00919     QString copyDllStep;
00920     QString activeQtStepPreCopyDll;
00921     QString activeQtStepPostCopyDll;
00922     QString activeQtStepPreCopyDllDebug;
00923     QString activeQtStepPostCopyDllDebug;
00924     QString activeQtStepPreCopyDllRelease;
00925     QString activeQtStepPostCopyDllRelease;
00926 
00927     if ( !project->variables()["QMAKE_POST_LINK"].isEmpty() )
00928         postLinkStep += var("QMAKE_POST_LINK");
00929 
00930     if ( !project->variables()["DESTDIR"].isEmpty() ) {
00931         project->variables()["TARGET"].first().prepend(project->first("DESTDIR"));
00932         Option::fixPathToTargetOS(project->first("TARGET"));
00933         dest = project->first("TARGET");
00934         if ( project->first("TARGET").startsWith("$(QTDIR)") )
00935             dest.replace( "$(QTDIR)", getenv("QTDIR") );
00936         project->variables()["MSVCDSP_TARGET"].append(
00937             QString("/out:\"") + dest + "\"");
00938         if ( project->isActiveConfig("dll") ) {
00939             QString imp = dest;
00940             imp.replace(".dll", ".lib");
00941             project->variables()["MSVCDSP_TARGET"].append(QString(" /implib:\"") + imp + "\"");
00942         }
00943     }
00944     if ( project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty() ) {
00945         QStringList dlldirs = project->variables()["DLLDESTDIR"];
00946         if ( dlldirs.count() )
00947             copyDllStep += "\t";
00948         for ( QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) {
00949             copyDllStep += "copy \"$(TargetPath)\" \"" + *dlldir + "\"\t";
00950         }
00951     }
00952 
00953     if ( project->isActiveConfig("activeqt") ) {
00954         QString idl = project->variables()["QMAKE_IDL"].first();
00955         QString idc = project->variables()["QMAKE_IDC"].first();
00956         QString version = project->variables()["VERSION"].first();
00957         if ( version.isEmpty() )
00958             version = "1.0";
00959         project->variables()["MSVCDSP_IDLSOURCES"].append( var("OBJECTS_DIR") + targetfilename + ".idl" );
00960         if ( project->isActiveConfig( "dll" ) ) {
00961             activeQtStepPreCopyDll += 
00962                              "\t" + idc + " %1 -idl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version +
00963                              "\t" + idl + " /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb" +
00964                              "\t" + idc + " %2 /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb";
00965             activeQtStepPostCopyDll +=
00966                              "\t" + idc + " %1 /regserver\n";
00967 
00968             QString executable = project->variables()["MSVCDSP_TARGETDIRREL"].first() + "\\" + targetfilename + ".dll";
00969             activeQtStepPreCopyDllRelease = activeQtStepPreCopyDll.arg(executable).arg(executable);
00970             activeQtStepPostCopyDllRelease = activeQtStepPostCopyDll.arg(executable);
00971 
00972             executable = project->variables()["MSVCDSP_TARGETDIRDEB"].first() + "\\" + targetfilename + ".dll";
00973             activeQtStepPreCopyDllDebug = activeQtStepPreCopyDll.arg(executable).arg(executable);
00974             activeQtStepPostCopyDllDebug = activeQtStepPostCopyDll.arg(executable);
00975         } else {
00976             activeQtStepPreCopyDll += 
00977                              "\t%1 -dumpidl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version +
00978                              "\t" + idl + " /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb" +
00979                              "\t" + idc + " %2 /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb";
00980             activeQtStepPostCopyDll +=
00981                              "\t%1 -regserver\n";
00982             QString executable = project->variables()["MSVCDSP_TARGETDIRREL"].first() + "\\" + targetfilename + ".exe";
00983             activeQtStepPreCopyDllRelease = activeQtStepPreCopyDll.arg(executable).arg(executable);
00984             activeQtStepPostCopyDllRelease = activeQtStepPostCopyDll.arg(executable);
00985 
00986             executable = project->variables()["MSVCDSP_TARGETDIRDEB"].first() + "\\" + targetfilename + ".exe";
00987             activeQtStepPreCopyDllDebug = activeQtStepPreCopyDll.arg(executable).arg(executable);
00988             activeQtStepPostCopyDllDebug = activeQtStepPostCopyDll.arg(executable);
00989         }
00990 
00991     }
00992 
00993     
00994     if ( !postLinkStep.isEmpty() || !copyDllStep.isEmpty() || !activeQtStepPreCopyDllDebug.isEmpty() || !activeQtStepPreCopyDllRelease.isEmpty() ) {
00995         project->variables()["MSVCDSP_POST_LINK_DBG"].append(
00996             "# Begin Special Build Tool\n"
00997             "SOURCE=$(InputPath)\n"
00998             "PostBuild_Desc=Post Build Step\n"
00999             "PostBuild_Cmds=" + postLinkStep + activeQtStepPreCopyDllDebug + copyDllStep + activeQtStepPostCopyDllDebug + "\n"
01000             "# End Special Build Tool\n" );
01001         project->variables()["MSVCDSP_POST_LINK_REL"].append(
01002             "# Begin Special Build Tool\n"
01003             "SOURCE=$(InputPath)\n"
01004             "PostBuild_Desc=Post Build Step\n"
01005             "PostBuild_Cmds=" + postLinkStep + activeQtStepPreCopyDllRelease + copyDllStep + activeQtStepPostCopyDllRelease + "\n"
01006             "# End Special Build Tool\n" );
01007     }
01008 
01009     if ( !project->variables()["SOURCES"].isEmpty() || !project->variables()["RC_FILE"].isEmpty() ) {
01010         project->variables()["SOURCES"] += project->variables()["RC_FILE"];
01011     }
01012     QStringList &list = project->variables()["FORMS"];
01013     for( it = list.begin(); it != list.end(); ++it ) {
01014         if ( QFile::exists( *it + ".h" ) )
01015             project->variables()["SOURCES"].append( *it + ".h" );
01016     }
01017     project->variables()["QMAKE_INTERNAL_PRL_LIBS"] << "MSVCDSP_LIBS"; 
01018 }
01019 
01020 
01021 QString
01022 DspMakefileGenerator::findTemplate(const QString &file)
01023 {
01024     QString ret;
01025     if(!QFile::exists((ret = file)) &&
01026        !QFile::exists((ret = QString(Option::mkfile::qmakespec + "/" + file))) &&
01027        !QFile::exists((ret = QString(getenv("QTDIR")) + "/mkspecs/win32-msvc/" + file)) &&
01028        !QFile::exists((ret = (QString(getenv("HOME")) + "/.tmake/" + file))))
01029         return "";
01030     return ret;
01031 }
01032 
01033 
01034 void
01035 DspMakefileGenerator::processPrlVariable(const QString &var, const QStringList &l)
01036 {
01037     if(var == "QMAKE_PRL_DEFINES") {
01038         QStringList &out = project->variables()["MSVCDSP_DEFINES"];
01039         for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
01040             if(out.findIndex((*it)) == -1)
01041                 out.append((" /D \"" + *it + "\""));
01042         }
01043     } else {
01044         MakefileGenerator::processPrlVariable(var, l);
01045     }
01046 }
01047 
01048 
01049 void
01050 DspMakefileGenerator::beginGroupForFile(QString file, QTextStream &t,
01051                                         const QString& filter)
01052 {
01053     if(project->isActiveConfig("flat"))
01054         return;
01055     fileFixify(file, QDir::currentDirPath(), QDir::currentDirPath(), TRUE);
01056     file = file.section(Option::dir_sep, 0, -2);
01057     if(file.right(Option::dir_sep.length()) != Option::dir_sep)
01058         file += Option::dir_sep;
01059     if(file == currentGroup)
01060         return;
01061 
01062     if(file.isEmpty() || !QDir::isRelativePath(file)) {
01063         endGroups(t);
01064         return;
01065     }
01066     
01067     QString tempFile = file;
01068     if(tempFile.startsWith(currentGroup))
01069         tempFile = tempFile.mid(currentGroup.length());
01070     int dirSep = currentGroup.findRev( Option::dir_sep );
01071 
01072     while( !tempFile.startsWith( currentGroup ) && dirSep != -1 ) {
01073         currentGroup.truncate( dirSep );
01074         dirSep = currentGroup.findRev( Option::dir_sep );
01075         if ( !tempFile.startsWith( currentGroup ) && dirSep != -1 )
01076             t << "\n# End Group\n";
01077     }
01078     if ( !file.startsWith( currentGroup ) ) {
01079         t << "\n# End Group\n";
01080         currentGroup = "";
01081     }
01082 
01083     QStringList dirs = QStringList::split(Option::dir_sep, file.right( file.length() - currentGroup.length() ) );
01084     for(QStringList::Iterator dir_it = dirs.begin(); dir_it != dirs.end(); ++dir_it) {
01085         t << "# Begin Group \"" << (*dir_it) << "\"\n"
01086             << "# Prop Default_Filter \"" << filter << "\"\n";
01087     }
01088     currentGroup = file;
01089 }
01090 
01091 
01092 void
01093 DspMakefileGenerator::endGroups(QTextStream &t)
01094 {
01095     if(project->isActiveConfig("flat"))
01096         return;
01097     else if(currentGroup.isEmpty())
01098         return;
01099 
01100     QStringList dirs = QStringList::split(Option::dir_sep, currentGroup);
01101     for(QStringList::Iterator dir_it = dirs.end(); dir_it != dirs.begin(); --dir_it) {
01102         t << "\n# End Group\n";
01103     }
01104     currentGroup = "";
01105 }
01106 
01107 bool
01108 DspMakefileGenerator::openOutput(QFile &file) const
01109 {
01110     QString outdir;
01111     if(!file.name().isEmpty()) {
01112         if(QDir::isRelativePath(file.name()))
01113             file.setName(Option::output_dir + file.name()); //pwd when qmake was run
01114         QFileInfo fi(file);
01115         if(fi.isDir())
01116             outdir = file.name() + QDir::separator();
01117     }
01118     if(!outdir.isEmpty() || file.name().isEmpty())
01119         file.setName(outdir + project->first("TARGET") + project->first("DSP_EXTENSION"));
01120     if(QDir::isRelativePath(file.name())) {
01121         QString ofile;
01122         ofile = file.name();
01123         int slashfind = ofile.findRev('\\');
01124         if (slashfind == -1) {
01125             ofile = ofile.replace(QRegExp("-"), "_");
01126         } else {
01127             int hypenfind = ofile.find('-', slashfind);
01128             while (hypenfind != -1 && slashfind < hypenfind) {
01129                 ofile = ofile.replace(hypenfind, 1, "_");
01130                 hypenfind = ofile.find('-', hypenfind + 1);
01131             }
01132         }
01133         file.setName(Option::fixPathToLocalOS(QDir::currentDirPath() + Option::dir_sep + ofile));
01134     }
01135     return Win32MakefileGenerator::openOutput(file);
01136 }

Generated on Sat Nov 5 16:18:21 2005 for OPIE by  doxygen 1.4.2