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

msvc_nmake.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** 
00003 **
00004 ** Implementation of NmakeMakefileGenerator 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_nmake.h"
00037 #include "option.h"
00038 #include <qregexp.h>
00039 #include <qdict.h>
00040 #include <qdir.h>
00041 #include <stdlib.h>
00042 #include <time.h>
00043 
00044 NmakeMakefileGenerator::NmakeMakefileGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE)
00045 {
00046 
00047 }
00048 
00049 bool
00050 NmakeMakefileGenerator::writeMakefile(QTextStream &t)
00051 {
00052     writeHeader(t);
00053     if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
00054         { //write the extra unix targets..
00055             QStringList &qut = project->variables()["QMAKE_EXTRA_WIN_TARGETS"];
00056             for(QStringList::ConstIterator it = qut.begin(); it != qut.end(); ++it)
00057                 t << *it << " ";
00058         }
00059         t << "all clean:" << "\n\t"
00060           << "@echo \"Some of the required modules ("
00061           << var("QMAKE_FAILED_REQUIREMENTS") << ") are not available.\"" << "\n\t"
00062           << "@echo \"Skipped.\"" << endl << endl;
00063         writeMakeQmake(t);
00064         return TRUE;
00065     }
00066 
00067     if(project->first("TEMPLATE") == "app" ||
00068        project->first("TEMPLATE") == "lib") {
00069         writeNmakeParts(t);
00070         return MakefileGenerator::writeMakefile(t);
00071     }
00072     else if(project->first("TEMPLATE") == "subdirs") {
00073         writeSubDirs(t);
00074         return TRUE;
00075     }
00076     return FALSE;
00077 }
00078 
00079 QStringList
00080 &NmakeMakefileGenerator::findDependencies(const QString &file)
00081 {
00082     QStringList &aList = MakefileGenerator::findDependencies(file);
00083     // Note: The QMAKE_IMAGE_COLLECTION file have all images
00084     // as dependency, so don't add precompiled header then
00085     if (file == project->first("QMAKE_IMAGE_COLLECTION"))
00086         return aList;
00087     for(QStringList::Iterator it = Option::cpp_ext.begin(); it != Option::cpp_ext.end(); ++it) {
00088         if(file.endsWith(*it)) {
00089             if(!aList.contains(precompH))
00090                 aList += precompH;
00091             break;
00092         }
00093     }
00094     return aList;
00095 }
00096 
00097 void
00098 NmakeMakefileGenerator::writeNmakeParts(QTextStream &t)
00099 {
00100     t << "####### Compiler, tools and options" << endl << endl;
00101     t << "CC            =       " << var("QMAKE_CC") << endl;
00102     t << "CXX           =       " << var("QMAKE_CXX") << endl;
00103     t << "LEX           = " << var("QMAKE_LEX") << endl;
00104     t << "YACC          = " << var("QMAKE_YACC") << endl;
00105     t << "CFLAGS        =       " << var("QMAKE_CFLAGS") << " "
00106       << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " "
00107       <<  varGlue("DEFINES","-D"," -D","") << endl;
00108     t << "CXXFLAGS      =       " << var("QMAKE_CXXFLAGS") << " "
00109       << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " "
00110       << varGlue("DEFINES","-D"," -D","") << endl;
00111     t << "LEXFLAGS      =" << var("QMAKE_LEXFLAGS") << endl;
00112     t << "YACCFLAGS     =" << var("QMAKE_YACCFLAGS") << endl;
00113 
00114     t << "INCPATH       =       ";
00115     QStringList &incs = project->variables()["INCLUDEPATH"];
00116     for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
00117         QString inc = (*incit);
00118         if (inc.endsWith("\\"))
00119             inc.truncate(inc.length()-1);
00120         t << " -I\"" << inc << "\"";
00121     }
00122     t << " -I\"" << specdir() << "\""
00123       << endl;
00124     if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) {
00125         t << "LINK      =       " << var("QMAKE_LINK") << endl;
00126         t << "LFLAGS    =       " << var("QMAKE_LFLAGS");
00127         if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() )
00128           t << " " << varGlue("QMAKE_LIBDIR","/LIBPATH:\"","\" /LIBPATH:\"","\"");
00129         t << endl;
00130         t << "LIBS      =       ";
00131         QStringList &libs = project->variables()["QMAKE_LIBS"];
00132         for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit) {
00133             QString lib = (*libit);
00134             if (lib.endsWith("\\"))
00135                 lib.truncate(lib.length()-1);
00136             t << " \"" << lib << "\"";
00137         }
00138         t << endl;
00139     }
00140     else {
00141         t << "LIB       =       " << var("QMAKE_LIB") << endl;
00142     }
00143     t << "MOC           =       " << (project->isEmpty("QMAKE_MOC") ? QString("moc") :
00144                               Option::fixPathToTargetOS(var("QMAKE_MOC"), FALSE)) << endl;
00145     t << "UIC           =       " << (project->isEmpty("QMAKE_UIC") ? QString("uic") :
00146                               Option::fixPathToTargetOS(var("QMAKE_UIC"), FALSE)) << endl;
00147     t << "QMAKE         =       " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") :
00148                               Option::fixPathToTargetOS(var("QMAKE_QMAKE"), FALSE)) << endl;
00149     t << "IDC           =       " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
00150                               Option::fixPathToTargetOS(var("QMAKE_IDC"), FALSE)) << endl;
00151     t << "IDL           =       " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
00152                               Option::fixPathToTargetOS(var("QMAKE_IDL"), FALSE)) << endl;
00153     t << "ZIP           =       " << var("QMAKE_ZIP") << endl;
00154     t << "COPY_FILE     =       " << var("QMAKE_COPY") << endl;
00155     t << "COPY_DIR      =       " << var("QMAKE_COPY") << endl;
00156     t << "DEL_FILE      =       " << var("QMAKE_DEL_FILE") << endl;
00157     t << "DEL_DIR       =       " << var("QMAKE_DEL_DIR") << endl;
00158     t << "MOVE          =       " << var("QMAKE_MOVE") << endl;
00159     t << "CHK_DIR_EXISTS =      " << var("QMAKE_CHK_DIR_EXISTS") << endl;
00160     t << "MKDIR         =       " << var("QMAKE_MKDIR") << endl;
00161     t << "INSTALL_FILE= " << var("QMAKE_INSTALL_FILE") << endl;
00162     t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl;
00163     t << endl;
00164 
00165     t << "####### Files" << endl << endl;
00166     t << "HEADERS =     " << varList("HEADERS") << endl;
00167     t << "SOURCES =     " << varList("SOURCES") << endl;
00168     t << "OBJECTS =     " << varList("OBJECTS") << endl;
00169     t << "FORMS =       " << varList("FORMS") << endl;
00170     t << "UICDECLS =    " << varList("UICDECLS") << endl;
00171     t << "UICIMPLS =    " << varList("UICIMPLS") << endl;
00172     t << "SRCMOC        =       " << varList("SRCMOC") << endl;
00173     t << "OBJMOC        =       " << varList("OBJMOC") << endl;
00174 
00175     QString extraCompilerDeps;
00176     if(!project->isEmpty("QMAKE_EXTRA_WIN_COMPILERS")) {
00177         t << "OBJCOMP = " << varList("OBJCOMP") << endl;
00178         extraCompilerDeps += " $(OBJCOMP) ";
00179 
00180         QStringList &comps = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
00181         for(QStringList::Iterator compit = comps.begin(); compit != comps.end(); ++compit) {
00182             QStringList &vars = project->variables()[(*compit) + ".variables"];
00183             for(QStringList::Iterator varit = vars.begin(); varit != vars.end(); ++varit) {
00184                 QStringList vals = project->variables()[(*varit)];
00185                 if(!vals.isEmpty())
00186                     t << "QMAKE_COMP_" << (*varit) << " = " << valList(vals) << endl;
00187             }
00188         }
00189     }
00190 
00191     t << "DIST  =       " << varList("DISTFILES") << endl;
00192     t << "TARGET        =       ";
00193     if( !project->variables()[ "DESTDIR" ].isEmpty() )
00194         t << varGlue("TARGET",project->first("DESTDIR"),"",project->first("TARGET_EXT"));
00195     else
00196         t << project->variables()[ "TARGET" ].first() << project->variables()[ "TARGET_EXT" ].first();
00197     t << endl;
00198     t << endl;
00199 
00200     t << "####### Implicit rules" << endl << endl;
00201     t << ".SUFFIXES: .c";
00202     QStringList::Iterator cppit;
00203     for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
00204         t << " " << (*cppit);
00205     t << endl << endl;
00206 
00207     if(!project->isActiveConfig("no_batch")) {
00208         // Batchmode doesn't use the non implicit rules QMAKE_RUN_CXX & QMAKE_RUN_CC
00209         project->variables().remove("QMAKE_RUN_CXX");
00210         project->variables().remove("QMAKE_RUN_CC");
00211 
00212         QDict<void> source_directories;
00213         source_directories.insert(".", (void*)1);
00214         QString directories[] = { QString("MOC_DIR"), QString("UI_SOURCES_DIR"), QString("UI_DIR"), QString::null };
00215         for(int y = 0; !directories[y].isNull(); y++) {
00216             QString dirTemp = project->first(directories[y]);
00217             if (dirTemp.endsWith("\\"))
00218                 dirTemp.truncate(dirTemp.length()-1);
00219             if(!dirTemp.isEmpty())
00220                 source_directories.insert(dirTemp, (void*)1);
00221         }
00222         QString srcs[] = { QString("SOURCES"), QString("UICIMPLS"), QString("SRCMOC"), QString::null };
00223         for(int x = 0; !srcs[x].isNull(); x++) {
00224             QStringList &l = project->variables()[srcs[x]];
00225             for(QStringList::Iterator sit = l.begin(); sit != l.end(); ++sit) {
00226                 QString sep = "\\";
00227                 if((*sit).find(sep) == -1)
00228                     sep = "/";
00229                 QString dir = (*sit).section(sep, 0, -2);
00230                 if(!dir.isEmpty() && !source_directories[dir])
00231                     source_directories.insert(dir, (void*)1);
00232             }
00233         }
00234 
00235         for(QDictIterator<void> it(source_directories); it.current(); ++it) {
00236             if(it.currentKey().isEmpty())
00237                 continue;
00238             for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
00239                 t << "{" << it.currentKey() << "}" << (*cppit) << "{" << var("OBJECTS_DIR") << "}" << Option::obj_ext << "::\n\t"
00240                   << var("QMAKE_RUN_CXX_IMP_BATCH").replace( QRegExp( "\\$@" ), var("OBJECTS_DIR") ) << endl << "\t$<" << endl << "<<" << endl << endl;
00241             t << "{" << it.currentKey() << "}" << ".c{" << var("OBJECTS_DIR") << "}" << Option::obj_ext << "::\n\t"
00242               << var("QMAKE_RUN_CC_IMP_BATCH").replace( QRegExp( "\\$@" ), var("OBJECTS_DIR") ) << endl << "\t$<" << endl << "<<" << endl << endl;
00243         }
00244     } else {
00245         for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit)
00246             t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
00247         t << ".c" << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
00248     }
00249 
00250     t << "####### Build rules" << endl << endl;
00251     t << "all: " << fileFixify(Option::output.name()) << " " << varGlue("ALL_DEPS"," "," "," ") << "$(TARGET)" << endl << endl;
00252     t << "$(TARGET): " << var("PRE_TARGETDEPS") << " $(UICDECLS) $(OBJECTS) $(OBJMOC) "
00253       << extraCompilerDeps << var("POST_TARGETDEPS");
00254     if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) {
00255         t << "\n\t" << "$(LINK) $(LFLAGS) /OUT:$(TARGET) @<< " << "\n\t  "
00256           << "$(OBJECTS) $(OBJMOC) $(LIBS)";
00257     } else {
00258         t << "\n\t" << "$(LIB) /OUT:$(TARGET) @<<" << "\n\t  "
00259           << "$(OBJECTS) $(OBJMOC)";
00260     }
00261     t << extraCompilerDeps;
00262     t << endl << "<<" << endl;
00263     if ( !project->variables()["QMAKE_POST_LINK"].isEmpty() )
00264         t << "\t" << var( "QMAKE_POST_LINK" ) << endl;
00265     if(project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty()) {
00266         QStringList dlldirs = project->variables()["DLLDESTDIR"];
00267         for ( QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) {
00268             t << "\n\t" << "-$(COPY_FILE) \"$(TARGET)\" " << *dlldir;
00269         }
00270     }
00271     QString targetfilename = project->variables()["TARGET"].first();
00272     if(project->isActiveConfig("activeqt")) {
00273         QString version = project->variables()["VERSION"].first();
00274         if ( version.isEmpty() )
00275             version = "1.0";
00276 
00277         if ( project->isActiveConfig("dll")) {
00278             t << "\n\t" << ("-$(IDC) $(TARGET) /idl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version);
00279             t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00280             t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00281             t << "\n\t" << ("-$(IDC) $(TARGET) /regserver" );
00282         } else {
00283             t << "\n\t" << ("-$(TARGET) -dumpidl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version);
00284             t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00285             t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00286             t << "\n\t" << "-$(TARGET) -regserver";
00287         }
00288     }
00289     t << endl << endl;
00290 
00291     if(!project->variables()["RC_FILE"].isEmpty()) {
00292         t << var("RES_FILE") << ": " << var("RC_FILE") << "\n\t"
00293           << var("QMAKE_RC") << " " << var("RC_FILE") << endl << endl;
00294     }
00295 
00296     t << "mocables: $(SRCMOC)" << endl
00297       << "uicables: $(UICIMPLS) $(UICDECLS)" << endl << endl;
00298 
00299     writeMakeQmake(t);
00300 
00301     QStringList dist_files = Option::mkfile::project_files;
00302     if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES"))
00303         dist_files += project->variables()["QMAKE_INTERNAL_INCLUDED_FILES"];
00304     if(!project->isEmpty("TRANSLATIONS"))
00305         dist_files << var("TRANSLATIONS");
00306     if(!project->isEmpty("FORMS")) {
00307         QStringList &forms = project->variables()["FORMS"];
00308         for(QStringList::Iterator formit = forms.begin(); formit != forms.end(); ++formit) {
00309             QString ui_h = fileFixify((*formit) + Option::h_ext.first());
00310             if(QFile::exists(ui_h) )
00311                 dist_files << ui_h;
00312         }
00313     }
00314     t << "dist:" << "\n\t"
00315       << "$(ZIP) " << var("QMAKE_ORIG_TARGET") << ".zip " << "$(SOURCES) $(HEADERS) $(DIST) $(FORMS) "
00316       << dist_files.join(" ") << " " << var("TRANSLATIONS") << " " << var("IMAGES") << endl << endl;
00317 
00318     t << "uiclean:"
00319       << varGlue("UICDECLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00320       << varGlue("UICIMPLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << endl;
00321 
00322     t << "mocclean:"
00323       << varGlue("SRCMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00324       << varGlue("OBJMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << endl;
00325 
00326     t << "clean: uiclean mocclean"
00327       << varGlue("OBJECTS","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00328       << varGlue("QMAKE_CLEAN","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","\n")
00329       << varGlue("CLEAN_FILES","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","\n");
00330     if ( project->isActiveConfig("activeqt")) {
00331         t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".idl");
00332         t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00333     }
00334     if(!project->isEmpty("IMAGES"))
00335         t << varGlue("QMAKE_IMAGE_COLLECTION", "\n\t-$(DEL_FILE) ", "\n\t-$(DEL_FILE) ", "");
00336     t << endl;
00337 
00338     // user defined targets
00339 
00340     QStringList::Iterator it;
00341     QStringList &qut = project->variables()["QMAKE_EXTRA_WIN_TARGETS"];
00342     for(it = qut.begin(); it != qut.end(); ++it) {
00343         QString targ = var((*it) + ".target"),
00344                  cmd = var((*it) + ".commands"), deps;
00345         if(targ.isEmpty())
00346             targ = (*it);
00347         QStringList &deplist = project->variables()[(*it) + ".depends"];
00348         for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) {
00349             QString dep = var((*dep_it) + ".target");
00350             if(dep.isEmpty())
00351                 dep = (*dep_it);
00352             deps += " " + dep;
00353         }
00354         if(!project->variables()["QMAKE_NOFORCE"].isEmpty() &&
00355            project->variables()[(*it) + ".CONFIG"].findIndex("phony") != -1)
00356             deps += QString(" ") + "FORCE";
00357         t << "\n\n" << targ << ":" << deps << "\n\t"
00358           << cmd;
00359     }
00360     t << endl << endl;
00361 
00362     QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
00363     for(it = quc.begin(); it != quc.end(); ++it) {
00364         QString tmp_out = project->variables()[(*it) + ".output"].first();
00365         QString tmp_cmd = project->variables()[(*it) + ".commands"].join(" ");
00366         QString tmp_dep = project->variables()[(*it) + ".depends"].join(" ");
00367         QStringList &vars = project->variables()[(*it) + ".variables"];
00368         if(tmp_out.isEmpty() || tmp_cmd.isEmpty())
00369             continue;
00370         QStringList &tmp = project->variables()[(*it) + ".input"];
00371         for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
00372             QStringList &inputs = project->variables()[(*it2)];
00373             for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
00374                 QFileInfo fi(Option::fixPathToLocalOS((*input)));
00375                 QString in = Option::fixPathToTargetOS((*input), FALSE),
00376                        out = tmp_out, cmd = tmp_cmd, deps;
00377                 out.replace("${QMAKE_FILE_BASE}", fi.baseName());
00378                 out.replace("${QMAKE_FILE_NAME}", fi.fileName());
00379                 cmd.replace("${QMAKE_FILE_BASE}", fi.baseName());
00380                 cmd.replace("${QMAKE_FILE_OUT}", out);
00381                 cmd.replace("${QMAKE_FILE_NAME}", fi.fileName());
00382                 for(QStringList::Iterator it3 = vars.begin(); it3 != vars.end(); ++it3)
00383                     cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")");
00384                 if(!tmp_dep.isEmpty()) {
00385                     char buff[256];
00386                     QString dep_cmd = tmp_dep;
00387                     dep_cmd.replace("${QMAKE_FILE_NAME}", fi.fileName());
00388                     if(FILE *proc = QT_POPEN(dep_cmd.latin1(), "r")) {
00389                         while(!feof(proc)) {
00390                             int read_in = int(fread(buff, 1, 255, proc));
00391                             if(!read_in)
00392                                 break;
00393                             int l = 0;
00394                             for(int i = 0; i < read_in; i++) {
00395                                 if(buff[i] == '\n' || buff[i] == ' ') {
00396                                     deps += " " + QCString(buff+l, (i - l) + 1);
00397                                     l = i;
00398                                 }
00399                             }
00400                         }
00401                         fclose(proc);
00402                     }
00403                 }
00404                 t << out << ": " << in << deps << "\n\t"
00405                   << cmd << endl << endl;
00406             }
00407         }
00408     }
00409     t << endl;
00410 
00411     if(project->variables()["QMAKE_NOFORCE"].isEmpty())
00412         t << "FORCE:" << endl << endl;
00413 
00414     t << "distclean: clean"
00415       << "\n\t-$(DEL_FILE) $(TARGET)"
00416       << endl << endl;
00417 
00418     // precompiled header
00419     if(usePCH) {
00420         QString precompRule = QString("-c -Yc -Fp%1 -Fo%2").arg(precompPch).arg(precompObj);
00421         t << precompObj << ": " << precompH << " " << findDependencies(precompH).join(" \\\n\t\t")
00422           << "\n\t" << "$(CXX) " + precompRule +" $(CXXFLAGS) $(INCPATH) -TP " << precompH << endl << endl;
00423     }
00424 }
00425 
00426 QString
00427 NmakeMakefileGenerator::var(const QString &value)
00428 {
00429     if (usePCH) {
00430         if ((value == "QMAKE_RUN_CXX_IMP_BATCH"
00431             || value == "QMAKE_RUN_CXX_IMP"
00432             || value == "QMAKE_RUN_CXX")) {
00433             QFileInfo precompHInfo(precompH);
00434             QString precompRule = QString("-c -FI%1 -Yu%2 -Fp%3")
00435                 .arg(precompHInfo.fileName())
00436                 .arg(precompHInfo.fileName())
00437                 .arg(precompPch);
00438             QString p = MakefileGenerator::var(value);
00439             p.replace("-c", precompRule);
00440             // Cannot use -Gm with -FI & -Yu, as this gives an
00441             // internal compiler error, on the newer compilers
00442             p.remove("-Gm");
00443             return p;
00444         } else if (value == "QMAKE_CXXFLAGS") {
00445             // Remove internal compiler error option
00446             return MakefileGenerator::var(value).remove("-Gm");
00447         }
00448     }
00449 
00450     // Normal val
00451     return MakefileGenerator::var(value);
00452 }
00453 
00454 void
00455 NmakeMakefileGenerator::init()
00456 {
00457     if(init_flag)
00458         return;
00459     init_flag = TRUE;
00460 
00461     /* this should probably not be here, but I'm using it to wrap the .t files */
00462     if(project->first("TEMPLATE") == "app")
00463         project->variables()["QMAKE_APP_FLAG"].append("1");
00464     else if(project->first("TEMPLATE") == "lib")
00465         project->variables()["QMAKE_LIB_FLAG"].append("1");
00466     else if(project->first("TEMPLATE") == "subdirs") {
00467         MakefileGenerator::init();
00468         if(project->variables()["MAKEFILE"].isEmpty())
00469             project->variables()["MAKEFILE"].append("Makefile");
00470         if(project->variables()["QMAKE"].isEmpty())
00471             project->variables()["QMAKE"].append("qmake");
00472         return;
00473     }
00474 
00475     if(project->isEmpty("QMAKE_INSTALL_FILE"))
00476         project->variables()["QMAKE_INSTALL_FILE"].append("$(COPY_FILE)");
00477     if(project->isEmpty("QMAKE_INSTALL_DIR"))
00478         project->variables()["QMAKE_INSTALL_DIR"].append("$(COPY_DIR)");
00479 
00480     bool is_qt = (project->first("TARGET") == "qt"QTDLL_POSTFIX || project->first("TARGET") == "qt-mt"QTDLL_POSTFIX);
00481     project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
00482 
00483     QString targetfilename = project->variables()["TARGET"].first();
00484     QStringList &configs = project->variables()["CONFIG"];
00485     if (project->isActiveConfig("qt") && project->isActiveConfig("shared"))
00486         project->variables()["DEFINES"].append("QT_DLL");
00487     if (project->isActiveConfig("qt_dll"))
00488         if(configs.findIndex("qt") == -1) configs.append("qt");
00489     if ( project->isActiveConfig("qtopia") ) {
00490         if(configs.findIndex("qtopialib") == -1)
00491             configs.append("qtopialib");
00492         if(configs.findIndex("qtopiainc") == -1)
00493             configs.append("qtopiainc");
00494     }
00495     if ( project->isActiveConfig("qt") ) {
00496         if ( project->isActiveConfig( "plugin" ) ) {
00497             project->variables()["CONFIG"].append("dll");
00498             if(project->isActiveConfig("qt"))
00499                 project->variables()["DEFINES"].append("QT_PLUGIN");
00500         }
00501         if ( (project->variables()["DEFINES"].findIndex("QT_NODLL") == -1) &&
00502          ((project->variables()["DEFINES"].findIndex("QT_MAKEDLL") != -1 ||
00503            project->variables()["DEFINES"].findIndex("QT_DLL") != -1) ||
00504           (getenv("QT_DLL") && !getenv("QT_NODLL"))) ) {
00505             project->variables()["QMAKE_QT_DLL"].append("1");
00506             if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() )
00507                 project->variables()["CONFIG"].append("dll");
00508         }
00509         if ( project->isActiveConfig("thread") )
00510             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_THREAD_SUPPORT");
00511         if ( project->isActiveConfig("accessibility" ) )
00512             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_ACCESSIBILITY_SUPPORT");
00513         if ( project->isActiveConfig("tablet") )
00514             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_TABLET_SUPPORT");
00515     }
00516     if ( project->isActiveConfig("dll") || !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
00517         project->variables()["CONFIG"].remove("staticlib");
00518         project->variables()["QMAKE_APP_OR_DLL"].append("1");
00519     } else {
00520         project->variables()["CONFIG"].append("staticlib");
00521     }
00522     if ( project->isActiveConfig("warn_off") ) {
00523         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_WARN_OFF"];
00524         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_WARN_OFF"];
00525     } else if ( project->isActiveConfig("warn_on") ) {
00526         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_WARN_ON"];
00527         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_WARN_ON"];
00528     }
00529     if ( project->isActiveConfig("debug") ) {
00530         if ( project->isActiveConfig("thread") ) {
00531             // use the DLL RT even here
00532             if ( project->variables()["DEFINES"].contains("QT_DLL") ) {
00533                 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DLLDBG"];
00534                 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DLLDBG"];
00535             } else {
00536                 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DBG"];
00537                 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DBG"];
00538             }
00539         }
00540         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_DEBUG"];
00541         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_DEBUG"];
00542         project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_DEBUG"];
00543     } else {
00544         if ( project->isActiveConfig("thread") ) {
00545             if ( project->variables()["DEFINES"].contains("QT_DLL") ) {
00546                 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DLL"];
00547                 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DLL"];
00548             } else {
00549                 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT"];
00550                 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT"];
00551             }
00552         }
00553         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RELEASE"];
00554         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RELEASE"];
00555         project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_RELEASE"];
00556     }
00557     if ( project->isActiveConfig("thread") && !project->variables()["DEFINES"].contains("QT_DLL")
00558         && !is_qt && project->first("TARGET") != "qtmain") {
00559         project->variables()["QMAKE_LFLAGS"].append("/NODEFAULTLIB:\"libc\"");
00560     }
00561 
00562     if ( !project->variables()["QMAKE_INCDIR"].isEmpty())
00563         project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR"];
00564     if ( project->isActiveConfig("qt") || project->isActiveConfig("opengl") )
00565         project->variables()["CONFIG"].append("windows");
00566     if ( project->isActiveConfig("qtopiainc") )
00567         project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QTOPIA"];
00568     if ( project->isActiveConfig("qtopialib") ) {
00569         if(!project->isEmpty("QMAKE_LIBDIR_QTOPIA"))
00570             project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QTOPIA"];
00571         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QTOPIA"];
00572     }
00573     if ( project->isActiveConfig("qt") ) {
00574         project->variables()["CONFIG"].append("moc");
00575         project->variables()["INCLUDEPATH"] +=  project->variables()["QMAKE_INCDIR_QT"];
00576         project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
00577         if ( !project->isActiveConfig("debug") )
00578             project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_NO_DEBUG");
00579         if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
00580             if ( !project->variables()["QMAKE_QT_DLL"].isEmpty()) {
00581                 project->variables()["DEFINES"].append("QT_MAKEDLL");
00582                 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_QT_DLL"];
00583             }
00584         } else {
00585             if(project->isActiveConfig("thread"))
00586                 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
00587             else
00588                 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
00589             if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
00590                 int hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt");
00591                 if ( hver == -1 )
00592                     hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt-mt");
00593                 if(hver != -1) {
00594                     QString ver;
00595                     ver.sprintf("qt%s" QTDLL_POSTFIX "%d.lib", (project->isActiveConfig("thread") ? "-mt" : ""), hver);
00596                     QStringList &libs = project->variables()["QMAKE_LIBS"];
00597                     for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit)
00598                         (*libit).replace(QRegExp("qt(-mt)?\\.lib"), ver);
00599                 }
00600             }
00601             if ( project->isActiveConfig( "activeqt" ) ) {
00602                 project->variables().remove("QMAKE_LIBS_QT_ENTRY");
00603                 project->variables()["QMAKE_LIBS_QT_ENTRY"] = "qaxserver.lib";
00604                 if ( project->isActiveConfig( "dll" ) )
00605                     project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_ENTRY"];
00606             }
00607             if ( !project->isActiveConfig("dll") && !project->isActiveConfig("plugin") ) {
00608                 project->variables()["QMAKE_LIBS"] +=project->variables()["QMAKE_LIBS_QT_ENTRY"];
00609             }
00610         }
00611     }
00612     if ( project->isActiveConfig("opengl") ) {
00613         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
00614         project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
00615     }
00616     if ( project->isActiveConfig("dll") ) {
00617         project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE_DLL"];
00618         project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE_DLL"];
00619         project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE_DLL"];
00620         project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS_DLL"];
00621         if ( !project->variables()["QMAKE_LIB_FLAG"].isEmpty()) {
00622             project->variables()["TARGET_EXT"].append(
00623                 QStringList::split('.',project->first("VERSION")).join("") + ".dll");
00624         } else {
00625             project->variables()["TARGET_EXT"].append(".dll");
00626         }
00627     } else {
00628         project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE"];
00629         project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE"];
00630         project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE"];
00631         project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS"];
00632         if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty()) {
00633             project->variables()["TARGET_EXT"].append(".exe");
00634         } else {
00635             project->variables()["TARGET_EXT"].append(".lib");
00636         }
00637     }
00638     if ( project->isActiveConfig("windows") ) {
00639         if ( project->isActiveConfig("console") ) {
00640             project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
00641             project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
00642             project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
00643             project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
00644         } else {
00645             project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"];
00646         }
00647         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
00648     } else {
00649         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
00650         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
00651         project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
00652         project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
00653     }
00654     if ( project->isActiveConfig("stl") ) {
00655         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_ON"];
00656         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_ON"];
00657     } else {
00658         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_STL_OFF"];
00659         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_STL_OFF"];
00660     }
00661     if ( project->isActiveConfig("exceptions") ) {
00662         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_ON"];
00663         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_ON"];
00664     } else {
00665         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_OFF"];
00666         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_OFF"];
00667     }
00668     if ( project->isActiveConfig("rtti") ) {
00669         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_ON"];
00670         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_ON"];
00671     } else {
00672         project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_OFF"];
00673         project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_OFF"];
00674     }
00675 
00676 
00677     if ( project->isActiveConfig("moc") )
00678         setMocAware(TRUE);
00679     project->variables()["QMAKE_LIBS"] += project->variables()["LIBS"];
00680 
00681     QStringList &libList = project->variables()["QMAKE_LIBS"];
00682     for( QStringList::Iterator stIt = libList.begin(); stIt != libList.end(); ) {
00683         QString s = *stIt;
00684         if( s.startsWith( "-l" ) ) {
00685             stIt = libList.remove( stIt );
00686             stIt = libList.insert( stIt, s.mid( 2 ) + ".lib" );
00687         } else if( s.startsWith( "-L" ) ) {
00688             stIt = libList.remove( stIt );
00689             project->variables()["QMAKE_LIBDIR"].append(QDir::convertSeparators(s.mid( 2 )));
00690         } else {
00691             stIt++;
00692         }
00693     }
00694 
00695     project->variables()["QMAKE_FILETAGS"] += QStringList::split(' ',
00696         "HEADERS SOURCES DEF_FILE RC_FILE TARGET QMAKE_LIBS DESTDIR DLLDESTDIR INCLUDEPATH");
00697     QStringList &l = project->variables()["QMAKE_FILETAGS"];
00698     QStringList::Iterator it;
00699     for(it = l.begin(); it != l.end(); ++it) {
00700         QStringList &gdmf = project->variables()[(*it)];
00701         for(QStringList::Iterator inner = gdmf.begin(); inner != gdmf.end(); ++inner)
00702             (*inner) = Option::fixPathToTargetOS((*inner), FALSE);
00703     }
00704 
00705     if ( !project->variables()["DEF_FILE"].isEmpty() )
00706         project->variables()["QMAKE_LFLAGS"].append(QString("/DEF:") + project->first("DEF_FILE"));
00707     if(!project->isActiveConfig("incremental"))
00708         project->variables()["QMAKE_LFLAGS"].append(QString("/incremental:no"));
00709 
00710     if ( !project->variables()["VERSION"].isEmpty() ) {
00711         QString version = project->variables()["VERSION"][0];
00712         int firstDot = version.find( "." );
00713         QString major = version.left( firstDot );
00714         QString minor = version.right( version.length() - firstDot - 1 );
00715         minor.replace( ".", "" );
00716         project->variables()["QMAKE_LFLAGS"].append( "/VERSION:" + major + "." + minor );
00717     }
00718     if ( !project->variables()["RC_FILE"].isEmpty()) {
00719         if ( !project->variables()["RES_FILE"].isEmpty()) {
00720             fprintf(stderr, "Both .rc and .res file specified.\n");
00721             fprintf(stderr, "Please specify one of them, not both.");
00722             exit(666);
00723         }
00724         project->variables()["RES_FILE"] = project->variables()["RC_FILE"];
00725         project->variables()["RES_FILE"].first().replace(".rc",".res");
00726         project->variables()["POST_TARGETDEPS"] += project->variables()["RES_FILE"];
00727         project->variables()["CLEAN_FILES"] += project->variables()["RES_FILE"];
00728     }
00729     if ( !project->variables()["RES_FILE"].isEmpty())
00730         project->variables()["QMAKE_LIBS"] += project->variables()["RES_FILE"];
00731 
00732     // Base class init!
00733     MakefileGenerator::init();
00734 
00735     // Setup PCH variables
00736     precompH = project->first("PRECOMPILED_HEADER");
00737     usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header");
00738     if (usePCH) {
00739         // Created files
00740         precompObj = var("OBJECTS_DIR") + project->first("TARGET") + "_pch" + Option::obj_ext;
00741         precompPch = var("OBJECTS_DIR") + project->first("TARGET") + "_pch.pch";
00742         // Add linking of precompObj (required for whole precompiled classes)
00743         project->variables()["OBJECTS"]           += precompObj;
00744         // Add pch file to cleanup
00745         project->variables()["QMAKE_CLEAN"]       += precompPch;
00746         // Return to variable pool
00747         project->variables()["PRECOMPILED_OBJECT"] = precompObj;
00748         project->variables()["PRECOMPILED_PCH"]    = precompPch;
00749     }
00750 
00751     if ( !project->variables()["VERSION"].isEmpty()) {
00752         QStringList l = QStringList::split('.', project->first("VERSION"));
00753         project->variables()["VER_MAJ"].append(l[0]);
00754         project->variables()["VER_MIN"].append(l[1]);
00755     }
00756 
00757     QString version = QStringList::split('.', project->first("VERSION")).join("");
00758     if(project->isActiveConfig("dll")) {
00759         project->variables()["QMAKE_CLEAN"].append(project->first("DESTDIR") + project->first("TARGET") + version + ".exp");
00760     }
00761     if(project->isActiveConfig("debug")) {
00762         project->variables()["QMAKE_CLEAN"].append(project->first("DESTDIR") + project->first("TARGET") + version + ".pdb");
00763         project->variables()["QMAKE_CLEAN"].append(project->first("DESTDIR") + project->first("TARGET") + version + ".ilk");
00764         project->variables()["QMAKE_CLEAN"].append("vc*.pdb");
00765         project->variables()["QMAKE_CLEAN"].append("vc*.idb");
00766     }
00767 
00768     QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
00769     for(it = quc.begin(); it != quc.end(); ++it) {
00770         QString tmp_out = project->variables()[(*it) + ".output"].first();
00771         if(tmp_out.isEmpty())
00772             continue;
00773         QStringList &tmp = project->variables()[(*it) + ".input"];
00774         for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
00775             QStringList &inputs = project->variables()[(*it2)];
00776             for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
00777                 QFileInfo fi(Option::fixPathToLocalOS((*input)));
00778                 QString in = Option::fixPathToTargetOS((*input), FALSE),
00779                        out = tmp_out;
00780                 out.replace("${QMAKE_FILE_BASE}", fi.baseName());
00781                 out.replace("${QMAKE_FILE_NAME}", fi.fileName());
00782                 if(project->variables()[(*it) + ".CONFIG"].findIndex("no_link") == -1)
00783                     project->variables()["OBJCOMP"] += out;
00784             }
00785         }
00786     }
00787 }

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