00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "mingw_make.h"
00037 #include "option.h"
00038 #include <qregexp.h>
00039 #include <qdir.h>
00040 #include <stdlib.h>
00041 #include <time.h>
00042
00043
00044 MingwMakefileGenerator::MingwMakefileGenerator(QMakeProject *p) : Win32MakefileGenerator(p), init_flag(FALSE)
00045 {
00046 Option::obj_ext = ".o";
00047 }
00048
00049 bool
00050 MingwMakefileGenerator::findLibraries()
00051 {
00052 return TRUE;
00053 }
00054
00055 bool
00056 MingwMakefileGenerator::writeMakefile(QTextStream &t)
00057 {
00058 writeHeader(t);
00059 if(!project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty()) {
00060 t << "all clean:" << "\n\t"
00061 << "@echo \"Some of the required modules ("
00062 << var("QMAKE_FAILED_REQUIREMENTS") << ") are not available.\"" << "\n\t"
00063 << "@echo \"Skipped.\"" << endl << endl;
00064 writeMakeQmake(t);
00065 return TRUE;
00066 }
00067
00068 if(project->first("TEMPLATE") == "app" ||
00069 project->first("TEMPLATE") == "lib") {
00070 writeMingwParts(t);
00071 return MakefileGenerator::writeMakefile(t);
00072 }
00073 else if(project->first("TEMPLATE") == "subdirs") {
00074 writeSubDirs(t);
00075 return TRUE;
00076 }
00077 return FALSE;
00078 }
00079
00080 void createLdObjectScriptFile(const QString & fileName, QStringList & objList)
00081 {
00082 QString filePath = Option::output_dir + QDir::separator() + fileName;
00083 QFile file(filePath);
00084 if (file.open(IO_WriteOnly | IO_Translate )) {
00085 QTextStream t(&file);
00086 t << "INPUT(" << endl;
00087 for (QStringList::Iterator it = objList.begin(); it != objList.end(); ++it ) {
00088 t << *it << endl;
00089 }
00090 t << ");" << endl;
00091 file.close();
00092 }
00093 }
00094
00095 void
00096 MingwMakefileGenerator::writeMingwParts(QTextStream &t)
00097 {
00098 t << "####### Compiler, tools and options" << endl << endl;
00099 t << "CC = " << var("QMAKE_CC") << endl;
00100 t << "CXX = " << var("QMAKE_CXX") << endl;
00101 t << "LEX = " << var("QMAKE_LEX") << endl;
00102 t << "YACC = " << var("QMAKE_YACC") << endl;
00103 t << "CFLAGS = " << var("QMAKE_CFLAGS") << " "
00104 << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " "
00105 << varGlue("DEFINES","-D"," -D","") << endl;
00106 t << "CXXFLAGS = " << var("QMAKE_CXXFLAGS") << " "
00107 << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " "
00108 << varGlue("DEFINES","-D"," -D","") << endl;
00109 t << "LEXFLAGS =" << var("QMAKE_LEXFLAGS") << endl;
00110 t << "YACCFLAGS =" << var("QMAKE_YACCFLAGS") << endl;
00111
00112 t << "INCPATH = ";
00113 QStringList &incs = project->variables()["INCLUDEPATH"];
00114 for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) {
00115 QString inc = (*incit);
00116 inc.replace(QRegExp("\\\\$"), "\\\\");
00117 inc.replace(QRegExp("\""), "");
00118 t << " -I" << "\"" << inc << "\"";
00119 }
00120 t << " -I" << "\"" << specdir() << "\"" << endl;
00121 if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) {
00122 t << "LINK = " << var("QMAKE_LINK") << endl;
00123 t << "LFLAGS = " << var("QMAKE_LFLAGS") << endl;
00124 t << "LIBS = ";
00125 if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() )
00126 t << varGlue("QMAKE_LIBDIR","-L\"","\" -L\"","\"") << " ";
00127 t << var("QMAKE_LIBS").replace(QRegExp("(\\slib|^lib)")," -l") << endl;
00128 }
00129 else {
00130 t << "LIB = " << var("QMAKE_LIB") << endl;
00131 }
00132 t << "MOC = " << (project->isEmpty("QMAKE_MOC") ? QString("moc") :
00133 Option::fixPathToTargetOS(var("QMAKE_MOC"), FALSE)) << endl;
00134 t << "UIC = " << (project->isEmpty("QMAKE_UIC") ? QString("uic") :
00135 Option::fixPathToTargetOS(var("QMAKE_UIC"), FALSE)) << endl;
00136 t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") :
00137 Option::fixPathToTargetOS(var("QMAKE_QMAKE"), FALSE)) << endl;
00138 t << "IDC = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") :
00139 Option::fixPathToTargetOS(var("QMAKE_IDC"), FALSE)) << endl;
00140 t << "IDL = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") :
00141 Option::fixPathToTargetOS(var("QMAKE_IDL"), FALSE)) << endl;
00142 t << "ZIP = " << var("QMAKE_ZIP") << endl;
00143 t << "DEF_FILE = " << varList("DEF_FILE") << endl;
00144 t << "COPY_FILE = " << var("QMAKE_COPY") << endl;
00145 t << "COPY_DIR = " << var("QMAKE_COPY") << endl;
00146 t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl;
00147 t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl;
00148 t << "MOVE = " << var("QMAKE_MOVE") << endl;
00149 t << "CHK_DIR_EXISTS = " << var("QMAKE_CHK_DIR_EXISTS") << endl;
00150 t << "MKDIR = " << var("QMAKE_MKDIR") << endl;
00151 t << "INSTALL_FILE= " << var("QMAKE_INSTALL_FILE") << endl;
00152 t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl;
00153 t << endl;
00154
00155 t << "####### Output directory" << endl << endl;
00156 if (! project->variables()["OBJECTS_DIR"].isEmpty())
00157 t << "OBJECTS_DIR = " << var("OBJECTS_DIR").replace(QRegExp("\\\\$"),"") << endl;
00158 else
00159 t << "OBJECTS_DIR = . " << endl;
00160 if (! project->variables()["MOC_DIR"].isEmpty())
00161 t << "MOC_DIR = " << var("MOC_DIR").replace(QRegExp("\\\\$"),"") << endl;
00162 else
00163 t << "MOC_DIR = . " << endl;
00164 t << endl;
00165
00166 t << "####### Files" << endl << endl;
00167 t << "HEADERS = " << varList("HEADERS") << endl;
00168 t << "SOURCES = " << varList("SOURCES") << endl;
00169 QString objectsLinkLine;
00170 if (!project->variables()["QMAKE_APP_OR_DLL"].isEmpty() &&
00171 project->variables()["OBJECTS"].count() > var("QMAKE_LINK_OBJECT_MAX").toUInt()) {
00172 createLdObjectScriptFile(var("QMAKE_LINK_OBJECT_SCRIPT"), project->variables()["OBJECTS"]);
00173 objectsLinkLine = var("QMAKE_LINK_OBJECT_SCRIPT");
00174 } else {
00175 objectsLinkLine = "$(OBJECTS)";
00176 }
00177 t << "OBJECTS = " << varList("OBJECTS") << endl;
00178 t << "FORMS = " << varList("FORMS") << endl;
00179 t << "UICDECLS = " << varList("UICDECLS") << endl;
00180 t << "UICIMPLS = " << varList("UICIMPLS") << endl;
00181 t << "SRCMOC = " << varList("SRCMOC") << endl;
00182 QString objmocLinkLine;
00183 if (!project->variables()["QMAKE_APP_OR_DLL"].isEmpty() &&
00184 project->variables()["OBJMOC"].count() > var("QMAKE_LINK_OBJECT_MAX").toUInt()) {
00185 createLdObjectScriptFile(var("QMAKE_LINK_OBJMOC_SCRIPT"), project->variables()["OBJMOC"]);
00186 objmocLinkLine = var("QMAKE_LINK_OBJMOC_SCRIPT");
00187 } else {
00188 objmocLinkLine = "$(OBJMOC)";
00189 }
00190 t << "OBJMOC = " << varList("OBJMOC") << endl;
00191 QString extraCompilerDeps;
00192 if(!project->isEmpty("QMAKE_EXTRA_WIN_COMPILERS")) {
00193 t << "OBJCOMP = " << varList("OBJCOMP") << endl;
00194 extraCompilerDeps += " $(OBJCOMP) ";
00195
00196 QStringList &comps = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
00197 for(QStringList::Iterator compit = comps.begin(); compit != comps.end(); ++compit) {
00198 QStringList &vars = project->variables()[(*compit) + ".variables"];
00199 for(QStringList::Iterator varit = vars.begin(); varit != vars.end(); ++varit) {
00200 QStringList vals = project->variables()[(*varit)];
00201 if(!vals.isEmpty())
00202 t << "QMAKE_COMP_" << (*varit) << " = " << valList(vals) << endl;
00203 }
00204 }
00205 }
00206
00207 t << "DIST = " << varList("DISTFILES") << endl;
00208 t << "TARGET = ";
00209 if( !project->variables()[ "DESTDIR" ].isEmpty() )
00210 t << varGlue("TARGET",project->first("DESTDIR"),"",project->first("TARGET_EXT"));
00211 else
00212 t << project->variables()[ "TARGET" ].first() << project->variables()[ "TARGET_EXT" ].first();
00213 t << endl;
00214 t << endl;
00215
00216 t << "####### Implicit rules" << endl << endl;
00217 t << ".SUFFIXES: .cpp .cxx .cc .C .c" << endl << endl;
00218 t << ".cpp.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
00219 t << ".cxx.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
00220 t << ".cc.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
00221 t << ".C.o:\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl;
00222 t << ".c.o:\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl;
00223
00224 t << "####### Build rules" << endl << endl;
00225 t << "all: " << "$(OBJECTS_DIR) " << "$(MOC_DIR) " << varGlue("ALL_DEPS",""," "," ") << "$(TARGET)" << endl << endl;
00226 t << "$(TARGET): " << var("PRE_TARGETDEPS") << " $(UICDECLS) $(OBJECTS) $(OBJMOC) "
00227 << extraCompilerDeps << var("POST_TARGETDEPS");
00228 if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) {
00229 t << "\n\t" << "$(LINK) $(LFLAGS) -o $(TARGET) " << objectsLinkLine << " " << objmocLinkLine << " $(LIBS)";
00230 } else {
00231 t << "\n\t" << "$(LIB) $(TARGET) " << objectsLinkLine << " " << objmocLinkLine;
00232 }
00233 t << extraCompilerDeps;
00234 if(project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty()) {
00235 QStringList dlldirs = project->variables()["DLLDESTDIR"];
00236 for ( QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) {
00237 t << "\n\t" << "$(COPY_FILE) \"$(TARGET)\" " << *dlldir;
00238 }
00239 }
00240 QString targetfilename = project->variables()["TARGET"].first();
00241 if(project->isActiveConfig("activeqt")) {
00242 QString version = project->variables()["VERSION"].first();
00243 if ( version.isEmpty() )
00244 version = "1.0";
00245
00246 if ( project->isActiveConfig("dll")) {
00247 t << "\n\t" << ("-$(IDC) $(TARGET) /idl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version);
00248 t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00249 t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00250 t << "\n\t" << ("-$(IDC) $(TARGET) /regserver" );
00251 } else {
00252 t << "\n\t" << ("-$(TARGET) -dumpidl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version);
00253 t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00254 t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00255 t << "\n\t" << "-$(TARGET) -regserver";
00256 }
00257 }
00258 t << endl << endl;
00259
00260 if(!project->variables()["RC_FILE"].isEmpty()) {
00261 t << var("RES_FILE") << ": " << var("RC_FILE") << "\n\t"
00262 << var("QMAKE_RC") << " -i " << var("RC_FILE") << " -o " << var("RC_FILE").replace(QRegExp("\\.rc"),".o") << " --include-dir=" << QFileInfo(var("RC_FILE")).dirPath() << endl << endl;
00263 }
00264 project->variables()["RES_FILE"].first().replace(QRegExp("\\.rc"),".o");
00265
00266 t << "mocables: $(SRCMOC)" << endl << endl;
00267
00268 t << "$(OBJECTS_DIR):" << "\n\t"
00269 << "@if not exist $(OBJECTS_DIR) $(MKDIR) $(OBJECTS_DIR)" << endl << endl;
00270
00271 t << "$(MOC_DIR):" << "\n\t"
00272 << "@if not exist $(MOC_DIR) $(MKDIR) $(MOC_DIR)" << endl << endl;
00273
00274 writeMakeQmake(t);
00275
00276 t << "dist:" << "\n\t"
00277 << "$(ZIP) " << var("PROJECT") << ".zip "
00278 << var("PROJECT") << ".pro $(SOURCES) $(HEADERS) $(DIST) $(FORMS)" << endl << endl;
00279
00280 t << "clean:"
00281 << varGlue("OBJECTS","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","").replace(QRegExp("\\.obj"),".o")
00282 << varGlue("SRCMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00283 << varGlue("OBJMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","").replace(QRegExp("\\.obj"),".o")
00284 << varGlue("UICDECLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00285 << varGlue("UICIMPLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00286 << "\n\t-$(DEL_FILE) $(TARGET)"
00287 << varGlue("QMAKE_CLEAN","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","")
00288 << varGlue("CLEAN_FILES","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","");
00289 if ( project->isActiveConfig("activeqt")) {
00290 t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".idl");
00291 t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".tlb");
00292 }
00293 if(!project->isEmpty("IMAGES"))
00294 t << varGlue("QMAKE_IMAGE_COLLECTION", "\n\t-$(DEL_FILE) ", "\n\t-$(DEL_FILE) ", "");
00295
00296
00297 QStringList::Iterator it;
00298 QStringList &qut = project->variables()["QMAKE_EXTRA_WIN_TARGETS"];
00299
00300 for(it = qut.begin(); it != qut.end(); ++it) {
00301 QString targ = var((*it) + ".target"),
00302 cmd = var((*it) + ".commands"), deps;
00303 if(targ.isEmpty())
00304 targ = (*it);
00305 QStringList &deplist = project->variables()[(*it) + ".depends"];
00306 for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) {
00307 QString dep = var((*dep_it) + ".target");
00308 if(dep.isEmpty())
00309 dep = (*dep_it);
00310 deps += " " + dep;
00311 }
00312 t << "\n\n" << targ << ":" << deps << "\n\t"
00313 << cmd;
00314 }
00315
00316 t << endl << endl;
00317
00318 QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
00319 for(it = quc.begin(); it != quc.end(); ++it) {
00320 QString tmp_out = project->variables()[(*it) + ".output"].first();
00321 QString tmp_cmd = project->variables()[(*it) + ".commands"].join(" ");
00322 QString tmp_dep = project->variables()[(*it) + ".depends"].join(" ");
00323 QStringList &vars = project->variables()[(*it) + ".variables"];
00324 if(tmp_out.isEmpty() || tmp_cmd.isEmpty())
00325 continue;
00326 QStringList &tmp = project->variables()[(*it) + ".input"];
00327 for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
00328 QStringList &inputs = project->variables()[(*it2)];
00329 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
00330 QFileInfo fi(Option::fixPathToLocalOS((*input)));
00331 QString in = Option::fixPathToTargetOS((*input), FALSE),
00332 out = tmp_out, cmd = tmp_cmd, deps;
00333 out.replace("${QMAKE_FILE_BASE}", fi.baseName());
00334 out.replace("${QMAKE_FILE_NAME}", fi.fileName());
00335 cmd.replace("${QMAKE_FILE_BASE}", fi.baseName());
00336 cmd.replace("${QMAKE_FILE_OUT}", out);
00337 cmd.replace("${QMAKE_FILE_NAME}", fi.fileName());
00338 for(QStringList::Iterator it3 = vars.begin(); it3 != vars.end(); ++it3)
00339 cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")");
00340 if(!tmp_dep.isEmpty()) {
00341 char buff[256];
00342 QString dep_cmd = tmp_dep;
00343 dep_cmd.replace("${QMAKE_FILE_NAME}", fi.fileName());
00344 if(FILE *proc = QT_POPEN(dep_cmd.latin1(), "r")) {
00345 while(!feof(proc)) {
00346 int read_in = int(fread(buff, 1, 255, proc));
00347 if(!read_in)
00348 break;
00349 int l = 0;
00350 for(int i = 0; i < read_in; i++) {
00351 if(buff[i] == '\n' || buff[i] == ' ') {
00352 deps += " " + QCString(buff+l, (i - l) + 1);
00353 l = i;
00354 }
00355 }
00356 }
00357 fclose(proc);
00358 }
00359 }
00360 t << out << ": " << in << deps << "\n\t"
00361 << cmd << endl << endl;
00362 }
00363 }
00364 }
00365 t << endl;
00366 }
00367
00368
00369 void
00370 MingwMakefileGenerator::init()
00371 {
00372 if(init_flag)
00373 return;
00374 init_flag = TRUE;
00375
00376
00377 if(project->first("TEMPLATE") == "app")
00378 project->variables()["QMAKE_APP_FLAG"].append("1");
00379 else if(project->first("TEMPLATE") == "lib")
00380 project->variables()["QMAKE_LIB_FLAG"].append("1");
00381 else if(project->first("TEMPLATE") == "subdirs") {
00382 MakefileGenerator::init();
00383 if(project->variables()["MAKEFILE"].isEmpty())
00384 project->variables()["MAKEFILE"].append("Makefile");
00385 if(project->variables()["QMAKE"].isEmpty())
00386 project->variables()["QMAKE"].append("qmake");
00387 return;
00388 }
00389
00390 if(project->isEmpty("QMAKE_INSTALL_FILE"))
00391 project->variables()["QMAKE_INSTALL_FILE"].append("$(COPY_FILE)");
00392 if(project->isEmpty("QMAKE_INSTALL_DIR"))
00393 project->variables()["QMAKE_INSTALL_DIR"].append("$(COPY_DIR)");
00394
00395 bool is_qt = (project->first("TARGET") == "qt"QTDLL_POSTFIX || project->first("TARGET") == "qt-mt"QTDLL_POSTFIX);
00396 project->variables()["QMAKE_ORIG_TARGET"] = project->variables()["TARGET"];
00397
00398
00399 project->variables()["QMAKE_LIBS"] += project->variables()["LIBS"];
00400
00401 QString targetfilename = project->variables()["TARGET"].first();
00402 QStringList &configs = project->variables()["CONFIG"];
00403
00404 if (project->isActiveConfig("qt") && project->isActiveConfig("shared"))
00405 project->variables()["DEFINES"].append("QT_DLL");
00406
00407 if (project->isActiveConfig("qt_dll"))
00408 if (configs.findIndex("qt") == -1)
00409 configs.append("qt");
00410
00411 if ( project->isActiveConfig("qt") ) {
00412 if ( project->isActiveConfig( "plugin" ) ) {
00413 project->variables()["CONFIG"].append("dll");
00414 if(project->isActiveConfig("qt"))
00415 project->variables()["DEFINES"].append("QT_PLUGIN");
00416 }
00417 if ( (project->variables()["DEFINES"].findIndex("QT_NODLL") == -1) &&
00418 ((project->variables()["DEFINES"].findIndex("QT_MAKEDLL") != -1 ||
00419 project->variables()["DEFINES"].findIndex("QT_DLL") != -1) ||
00420 (getenv("QT_DLL") && !getenv("QT_NODLL"))) ) {
00421 project->variables()["QMAKE_QT_DLL"].append("1");
00422 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() )
00423 project->variables()["CONFIG"].append("dll");
00424 }
00425 if ( project->isActiveConfig("thread") )
00426 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_THREAD_SUPPORT");
00427 if ( project->isActiveConfig("accessibility" ) )
00428 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_ACCESSIBILITY_SUPPORT");
00429 if ( project->isActiveConfig("tablet") )
00430 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_TABLET_SUPPORT");
00431 }
00432
00433 if ( project->isActiveConfig("dll") || !project->variables()["QMAKE_APP_FLAG"].isEmpty() ) {
00434 project->variables()["CONFIG"].remove("staticlib");
00435 project->variables()["QMAKE_APP_OR_DLL"].append("1");
00436 } else {
00437 project->variables()["CONFIG"].append("staticlib");
00438 }
00439
00440 if ( project->isActiveConfig("warn_off") ) {
00441 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_WARN_OFF"];
00442 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_WARN_OFF"];
00443 } else if ( project->isActiveConfig("warn_on") ) {
00444 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_WARN_ON"];
00445 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_WARN_ON"];
00446 }
00447
00448 if ( project->isActiveConfig("debug") ) {
00449 if ( project->isActiveConfig("thread") ) {
00450
00451 if ( project->variables()["DEFINES"].contains("QT_DLL") ) {
00452 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DLLDBG"];
00453 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DLLDBG"];
00454 } else {
00455 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DBG"];
00456 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DBG"];
00457 }
00458 }
00459 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_DEBUG"];
00460 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_DEBUG"];
00461 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_DEBUG"];
00462 } else {
00463 if ( project->isActiveConfig("thread") ) {
00464 if ( project->variables()["DEFINES"].contains("QT_DLL") ) {
00465 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT_DLL"];
00466 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT_DLL"];
00467 } else {
00468 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_MT"];
00469 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_MT"];
00470 }
00471 }
00472 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RELEASE"];
00473 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RELEASE"];
00474 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_RELEASE"];
00475 }
00476
00477 if ( !project->variables()["QMAKE_INCDIR"].isEmpty())
00478 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR"];
00479
00480 if ( project->isActiveConfig("qt") || project->isActiveConfig("opengl") )
00481 project->variables()["CONFIG"].append("windows");
00482
00483 if ( project->isActiveConfig("qt") ) {
00484 project->variables()["CONFIG"].append("moc");
00485 project->variables()["INCLUDEPATH"] += project->variables()["QMAKE_INCDIR_QT"];
00486 project->variables()["QMAKE_LIBDIR"] += project->variables()["QMAKE_LIBDIR_QT"];
00487 if ( !project->isActiveConfig("debug") )
00488 project->variables()[is_qt ? "PRL_EXPORT_DEFINES" : "DEFINES"].append("QT_NO_DEBUG");
00489 if ( is_qt && !project->variables()["QMAKE_LIB_FLAG"].isEmpty() ) {
00490 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty()) {
00491 project->variables()["DEFINES"].append("QT_MAKEDLL");
00492 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_QT_DLL"];
00493 }
00494 } else {
00495
00496 if(project->isActiveConfig("thread"))
00497 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_THREAD"];
00498 else
00499 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT"];
00500 if ( !project->variables()["QMAKE_QT_DLL"].isEmpty() ) {
00501 int hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt");
00502 if ( hver == -1 )
00503 hver = findHighestVersion(project->first("QMAKE_LIBDIR_QT"), "qt-mt");
00504 if(hver != -1) {
00505 QString ver;
00506 ver.sprintf("libqt-%s" QTDLL_POSTFIX "%d.a", (project->isActiveConfig("thread") ? "-mt" : ""), hver);
00507 QStringList &libs = project->variables()["QMAKE_LIBS"];
00508
00509 for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit)
00510 (*libit).replace(QRegExp("qt(-mt)?\\.lib"), ver);
00511 }
00512 }
00513 if ( project->isActiveConfig( "activeqt" ) ) {
00514 project->variables().remove("QMAKE_LIBS_QT_ENTRY");
00515 project->variables()["QMAKE_LIBS_QT_ENTRY"] = "-lqaxserver";
00516 if ( project->isActiveConfig( "dll" ) ) {
00517 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_QT_ENTRY"];
00518 }
00519 }
00520 if ( !project->isActiveConfig("dll") && !project->isActiveConfig("plugin") ) {
00521 project->variables()["QMAKE_LIBS"] +=project->variables()["QMAKE_LIBS_QT_ENTRY"];
00522 }
00523
00524
00525 project->variables()["QMAKE_LIBS"].remove(project->variables()["QMAKE_LIBS_QT_ENTRY"].first());
00526 project->variables()["QMAKE_LIBS"].prepend(project->variables()["QMAKE_LIBS_QT_ENTRY"].first());
00527
00528 }
00529 }
00530
00531 if ( project->isActiveConfig("opengl") ) {
00532 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_OPENGL"];
00533 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_OPENGL"];
00534 }
00535
00536 if ( project->isActiveConfig("dll") ) {
00537 project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE_DLL"];
00538 project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE_DLL"];
00539 project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE_DLL"];
00540 project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS_DLL"];
00541 if ( !project->variables()["QMAKE_LIB_FLAG"].isEmpty()) {
00542 project->variables()["TARGET_EXT"].append(
00543 QStringList::split('.',project->first("VERSION")).join("") + ".dll");
00544 } else {
00545 project->variables()["TARGET_EXT"].append(".dll");
00546 }
00547 } else {
00548 project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CFLAGS_CONSOLE"];
00549 project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_CXXFLAGS_CONSOLE"];
00550 project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"] = project->variables()["QMAKE_LFLAGS_CONSOLE"];
00551 project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"] = project->variables()["QMAKE_LFLAGS_WINDOWS"];
00552 if ( !project->variables()["QMAKE_APP_FLAG"].isEmpty()) {
00553 project->variables()["TARGET_EXT"].append(".exe");
00554 } else {
00555 project->variables()["TARGET_EXT"].append(".a");
00556 project->variables()["QMAKE_LFLAGS"].append("-static");
00557 if(project->variables()["TARGET"].first().left(3) != "lib")
00558 project->variables()["TARGET"].first().prepend("lib");
00559 }
00560 }
00561
00562 if ( project->isActiveConfig("windows") ) {
00563 if ( project->isActiveConfig("console") ) {
00564 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
00565 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
00566 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
00567 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
00568 } else {
00569 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_WINDOWS_ANY"];
00570 }
00571 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_WINDOWS"];
00572 } else {
00573 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_CONSOLE_ANY"];
00574 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_CONSOLE_ANY"];
00575 project->variables()["QMAKE_LFLAGS"] += project->variables()["QMAKE_LFLAGS_CONSOLE_ANY"];
00576 project->variables()["QMAKE_LIBS"] += project->variables()["QMAKE_LIBS_CONSOLE"];
00577 }
00578
00579 if ( project->isActiveConfig("exceptions") ) {
00580 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_ON"];
00581 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_ON"];
00582 } else {
00583 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_EXCEPTIONS_OFF"];
00584 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_EXCEPTIONS_OFF"];
00585 }
00586
00587 if ( project->isActiveConfig("rtti") ) {
00588 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_ON"];
00589 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_ON"];
00590 } else {
00591 project->variables()["QMAKE_CFLAGS"] += project->variables()["QMAKE_CFLAGS_RTTI_OFF"];
00592 project->variables()["QMAKE_CXXFLAGS"] += project->variables()["QMAKE_CXXFLAGS_RTTI_OFF"];
00593 }
00594
00595 if ( project->isActiveConfig("moc") )
00596 setMocAware(TRUE);
00597
00598
00599 QStringList &libs = project->variables()["QMAKE_LIBS"];
00600 for ( QStringList::Iterator libit = libs.begin(); libit != libs.end(); ) {
00601 if ( (*libit).startsWith( "-L" ) ) {
00602 project->variables()["QMAKE_LIBDIR"] += (*libit).mid(2);
00603 libit = libs.remove( libit );
00604 } else {
00605 ++libit;
00606 }
00607 }
00608
00609 project->variables()["QMAKE_FILETAGS"] += QStringList::split(' ',
00610 "HEADERS SOURCES DEF_FILE RC_FILE TARGET QMAKE_LIBS DESTDIR DLLDESTDIR INCLUDEPATH");
00611 QStringList &l = project->variables()["QMAKE_FILETAGS"];
00612 QStringList::Iterator it;
00613 for(it = l.begin(); it != l.end(); ++it) {
00614 QStringList &gdmf = project->variables()[(*it)];
00615 for(QStringList::Iterator inner = gdmf.begin(); inner != gdmf.end(); ++inner)
00616 (*inner) = Option::fixPathToTargetOS((*inner), FALSE);
00617 }
00618
00619 if ( project->isActiveConfig("dll") ) {
00620 QString destDir = "";
00621 if (!project->first("DESTDIR").isEmpty())
00622 destDir = project->first("DESTDIR") + Option::dir_sep;
00623 project->variables()["QMAKE_LFLAGS"].append(QString("-Wl,--out-implib,") +
00624 destDir + "lib" + project->first("TARGET") + ".a");
00625 }
00626
00627 if ( !project->variables()["DEF_FILE"].isEmpty() )
00628 project->variables()["QMAKE_LFLAGS"].append(QString("-Wl,") + project->first("DEF_FILE"));
00629
00630
00631
00632 #if 0
00633 if ( !project->variables()["VERSION"].isEmpty() ) {
00634 QString version = project->variables()["VERSION"][0];
00635 int firstDot = version.find( "." );
00636 QString major = version.left( firstDot );
00637 QString minor = version.right( version.length() - firstDot - 1 );
00638 minor.replace( ".", "" );
00639 project->variables()["QMAKE_LFLAGS"].append( "/VERSION:" + major + "." + minor );
00640 }
00641 #endif
00642
00643 if ( !project->variables()["RC_FILE"].isEmpty()) {
00644 if ( !project->variables()["RES_FILE"].isEmpty()) {
00645 fprintf(stderr, "Both .rc and .res file specified.\n");
00646 fprintf(stderr, "Please specify one of them, not both.");
00647 exit(666);
00648 }
00649 project->variables()["RES_FILE"] = project->variables()["RC_FILE"];
00650 project->variables()["RES_FILE"].first().replace(".rc",".o");
00651 project->variables()["POST_TARGETDEPS"] += project->variables()["RES_FILE"];
00652 project->variables()["CLEAN_FILES"] += project->variables()["RES_FILE"];
00653 }
00654
00655 if ( !project->variables()["RES_FILE"].isEmpty())
00656 project->variables()["QMAKE_LIBS"] += project->variables()["RES_FILE"];
00657
00658 MakefileGenerator::init();
00659
00660 if ( !project->variables()["VERSION"].isEmpty()) {
00661 QStringList l = QStringList::split('.', project->first("VERSION"));
00662 project->variables()["VER_MAJ"].append(l[0]);
00663 project->variables()["VER_MIN"].append(l[1]);
00664 }
00665
00666 if(project->isActiveConfig("dll")) {
00667 project->variables()["QMAKE_CLEAN"].append(project->first("DESTDIR") +"lib" + project->first("TARGET") + ".a");
00668 }
00669
00670 QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"];
00671 for(it = quc.begin(); it != quc.end(); ++it) {
00672 QString tmp_out = project->variables()[(*it) + ".output"].first();
00673 if(tmp_out.isEmpty())
00674 continue;
00675 QStringList &tmp = project->variables()[(*it) + ".input"];
00676 for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) {
00677 QStringList &inputs = project->variables()[(*it2)];
00678 for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) {
00679 QFileInfo fi(Option::fixPathToLocalOS((*input)));
00680 QString in = Option::fixPathToTargetOS((*input), FALSE),
00681 out = tmp_out;
00682 out.replace("${QMAKE_FILE_BASE}", fi.baseName());
00683 out.replace("${QMAKE_FILE_NAME}", fi.fileName());
00684 if(project->variables()[(*it) + ".CONFIG"].findIndex("no_link") == -1)
00685 project->variables()["OBJCOMP"] += out;
00686 }
00687 }
00688 }
00689 }
00690
00691 void
00692 MingwMakefileGenerator::writeSubDirs(QTextStream &t)
00693 {
00694 QString qs ;
00695 QTextStream ts (&qs, IO_WriteOnly) ;
00696 Win32MakefileGenerator::writeSubDirs( ts ) ;
00697 QRegExp rx("(\\n\\tcd [^\\n\\t]+)(\\n\\t.+)\\n\\t@cd ..") ;
00698 rx.setMinimal(TRUE);
00699 int pos = 0 ;
00700 while ( -1 != (pos = rx.search( qs, pos)))
00701 {
00702 QString qsMatch = rx.cap(2);
00703 qsMatch.replace("\n\t"," && \\\n\t");
00704 qs.replace(pos+rx.cap(1).length(), rx.cap(2).length(), qsMatch );
00705 pos += (rx.cap(1).length()+qsMatch.length());
00706 }
00707 t << qs ;
00708 }