void MingwMakefileGenerator::writeMingwParts(QTextStream &t) { if (!project->isEmpty("QMAKE_SYMBIAN_SHLIB")) { t << "vpath %.dso " << project->values("QMAKE_LIBDIR").join(";") << endl; t << "vpath %.lib " << project->values("QMAKE_LIBDIR").join(";") << endl; t << "\n\n"; } writeStandardParts(t); if (!preCompHeaderOut.isEmpty()) { QString header = project->first("PRECOMPILED_HEADER"); QString cHeader = preCompHeaderOut + Option::dir_sep + "c"; t << escapeDependencyPath(cHeader) << ": " << escapeDependencyPath(header) << " " << escapeDependencyPaths(findDependencies(header)).join(" \\\n\t\t") << "\n\t" << mkdir_p_asstring(preCompHeaderOut) << "\n\t" << "$(CC) -x c-header -c $(CFLAGS) $(INCPATH) -o " << cHeader << " " << header << endl << endl; QString cppHeader = preCompHeaderOut + Option::dir_sep + "c++"; t << escapeDependencyPath(cppHeader) << ": " << escapeDependencyPath(header) << " " << escapeDependencyPaths(findDependencies(header)).join(" \\\n\t\t") << "\n\t" << mkdir_p_asstring(preCompHeaderOut) << "\n\t" << "$(CXX) -x c++-header -c $(CXXFLAGS) $(INCPATH) -o " << cppHeader << " " << header << endl << endl; } }
void tst_PluginDependencyGraph::linearDependencyTest() { auto graph = linearGraph(); QCOMPARE(graph.findDependencies("p1"), QVector<QString>{} << "p4" << "p3" << "p2"); QCOMPARE(graph.findDependents("p1"), QVector<QString>{}); QCOMPARE(graph.findDependencies("p2"), QVector<QString>{} << "p4" << "p3"); QCOMPARE(graph.findDependents("p2"), QVector<QString>{} << "p1"); QCOMPARE(graph.findDependencies("p3"), QVector<QString>{} << "p4"); QCOMPARE(graph.findDependents("p3"), QVector<QString>{} << "p1" << "p2"); QCOMPARE(graph.findDependencies("p4"), QVector<QString>{}); QCOMPARE(graph.findDependents("p4"), QVector<QString>{} << "p1" << "p2" << "p3"); }
void tst_PluginDependencyGraph::invalidDependencyTest() { auto graph = linearGraph(); QCOMPARE(graph.findDependencies("p8"), {}); QCOMPARE(graph.findDependents("p8"), {}); }
void MingwMakefileGenerator::writeMingwParts(QTextStream &t) { writeStandardParts(t); if (!preCompHeaderOut.isEmpty()) { QString header = project->first("PRECOMPILED_HEADER"); QString cHeader = preCompHeaderOut + Option::dir_sep + "c"; t << cHeader << ": " << header << " " << findDependencies(header).join(" \\\n\t\t") << "\n\t" << mkdir_p_asstring(preCompHeaderOut) << "\n\t" << "$(CC) -x c-header -c $(CFLAGS) $(INCPATH) -o " << cHeader << " " << header << endl << endl; QString cppHeader = preCompHeaderOut + Option::dir_sep + "c++"; t << cppHeader << ": " << header << " " << findDependencies(header).join(" \\\n\t\t") << "\n\t" << mkdir_p_asstring(preCompHeaderOut) << "\n\t" << "$(CXX) -x c++-header -c $(CXXFLAGS) $(INCPATH) -o " << cppHeader << " " << header << endl << endl; } }
void NmakeMakefileGenerator::writeNmakeParts(QTextStream &t) { writeStandardParts(t); // precompiled header if(usePCH) { QString precompRule = QString("-c -Yc -Fp%1 -Fo%2").arg(precompPch).arg(precompObj); t << precompObj << ": " << precompH << " " << findDependencies(precompH).join(" \\\n\t\t") << "\n\t" << "$(CXX) " + precompRule +" $(CXXFLAGS) $(INCPATH) -TP " << precompH << endl << endl; } }
void tst_PluginDependencyGraph::cycleDependencyTest() { auto graph = cycleGraph(); graph.addDependency("p1", "p2"); graph.addDependency("p2", "p3"); graph.addDependency("p2", "p4"); graph.addDependency("p3", "p5"); graph.addDependency("p4", "p5"); graph.addDependency("p5", "p2"); graph.addDependency("p5", "p6"); expect<PluginDependencyCycleException>([&]{ graph.findDependencies("p1"); }); QCOMPARE(graph.findDependents("p1"), QVector<QString>{}); expect<PluginDependencyCycleException>([&]{ graph.findDependencies("p2"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependents("p2"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependencies("p3"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependents("p3"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependencies("p4"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependents("p4"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependencies("p5"); }); expect<PluginDependencyCycleException>([&]{ graph.findDependents("p5"); }); QCOMPARE(graph.findDependencies("p6"), QVector<QString>{}); expect<PluginDependencyCycleException>([&]{ graph.findDependents("p6"); }); }
void tst_PluginDependencyGraph::treeDependencyTest() { auto graph = treeGraph(); auto p1Dependencies = graph.findDependencies("p1"); auto p1Dependents = graph.findDependents("p1"); auto p6Dependencies = graph.findDependencies("p6"); auto p6Dependents = graph.findDependents("p6"); QCOMPARE(p1Dependencies.size(), 5); QVERIFY(!contains(p1Dependencies, "p1")); QVERIFY(contains(p1Dependencies, "p2")); QVERIFY(contains(p1Dependencies, "p3")); QVERIFY(contains(p1Dependencies, "p4")); QVERIFY(contains(p1Dependencies, "p5")); QVERIFY(contains(p1Dependencies, "p6")); QVERIFY(precedes(p1Dependencies, "p6", "p5")); QVERIFY(precedes(p1Dependencies, "p5", "p4")); QVERIFY(precedes(p1Dependencies, "p5", "p3")); QVERIFY(precedes(p1Dependencies, "p4", "p2")); QVERIFY(precedes(p1Dependencies, "p3", "p2")); QCOMPARE(p1Dependents.size(), 0); QCOMPARE(p6Dependencies.size(), 0); QCOMPARE(p6Dependents.size(), 5); QVERIFY(contains(p6Dependents, "p1")); QVERIFY(contains(p6Dependents, "p2")); QVERIFY(contains(p6Dependents, "p3")); QVERIFY(contains(p6Dependents, "p4")); QVERIFY(contains(p6Dependents, "p5")); QVERIFY(!contains(p6Dependents, "p6")); QVERIFY(precedes(p6Dependents, "p1", "p2")); QVERIFY(precedes(p6Dependents, "p2", "p3")); QVERIFY(precedes(p6Dependents, "p2", "p4")); QVERIFY(precedes(p6Dependents, "p3", "p5")); QVERIFY(precedes(p6Dependents, "p4", "p5")); }
int main(int argc, char *argv[]) { time_t now; struct tm *t; char path[2048], cwd[2048], dirName[2048], parent[2048]; char *ext, *previous, *cp; int errors, c, j, i, levels, upLevel, incJava; errors = 0; program = mprGetBaseName(argv[0]); quiet = 0; while ((c = getopt(argc, argv, "?I:o:q")) != EOF) { switch(c) { case 'I': if (numIncludeDir >= MAX_INC) { fprintf(stderr, "Too many include directories\n"); exit(1); } includeDir[numIncludeDir++] = strdup(optarg); break; case 'q': quiet++; break; case '?': errors++; break; } } if (errors) { fprintf(stderr, "%s: usage: [-q] [-I includeDir] files...\n", program); exit(2); } includeDir[numIncludeDir++] = strdup("."); #if !WIN && !_WIN32 includeDir[numIncludeDir++] = strdup("/usr/include"); #endif openSignals(); if ((fp = fopen("make.dep", "w")) == 0) { fprintf(stderr, "Cant open make.dep\n"); exit(255); } now = time(0); t = localtime(&now); fprintf(fp, "#\n# make.dep -- Makefile dependencies. Generated by genDepend.\n#\n\n"); getcwd(cwd, sizeof(cwd)); mapDelimiters(cwd); fprintf(fp, "all: compile\n\n"); fprintf(fp, "BLD_TOP := "); strcpy(dirName, cwd); for (i = 0, levels = 0; *dirName; i++) { sprintf(path, "%s/build/make/make.rules", dirName); if (access(path, R_OK) == 0) { break; } mprGetDirName(parent, sizeof(parent), dirName); strcpy(dirName, parent); if (i > 0) { fprintf(fp, "/.."); } else { fprintf(fp, ".."); } levels++; } if (i == 0) { fprintf(fp, "."); } fprintf(fp, "\n"); /* * Extract a src path for Java. Go up N levels less one for the "java" * directory. */ strcpy(dirName, cwd); cp = &dirName[strlen(dirName) - 1]; for (upLevel = 1; upLevel < levels && cp > dirName; cp--) { if (*cp == '/') { upLevel++; } } if (levels > 1) { if (cp[0] != '\0' && cp[1] != '\0' && cp[2] != '\0') { cp += 2; } if (*cp == '\0') { cp = "."; } fprintf(fp, "SRC_PATH := %s\n\n", cp); } else { fprintf(fp, "SRC_PATH := .\n\n"); } fprintf(fp, "#\n# Read the build configuration settings and make" "variable definitions.\n#\n"); fprintf(fp, "include $(BLD_TOP)/buildConfig.make\n\n"); incJava = 0; for (i = optind; i < argc; i++) { if (strstr(argv[i], ".java") != 0 && strcmp(argv[i], "*.java") != 0) { incJava++; // fprintf(fp, "include $(BLD_TOP)/build/make/make.java\n"); break; } } if (incJava) { fprintf(fp, "HAS_JAVA = 1\n\n"); } fprintf(fp, "SRC ="); for (i = optind; i < argc; i++) { if (access(argv[i], R_OK) != 0) { continue; } strncpy(path, argv[i], sizeof(path)); fprintf(fp, " \\\n\t%s", mprGetBaseName(path)); } fprintf(fp, "\n\n"); fprintf(fp, "PROCESSED_SRC ="); for (i = optind; i < argc; i++) { if (access(argv[i], R_OK) != 0) { continue; } strncpy(path, argv[i], sizeof(path)); ext = mapExtension(path); if (strcmp(ext, ".java") == 0) { fprintf(fp, " \\\n\t$(BLD_OBJ_DIR)/src/$(SRC_PATH)/%s", mprGetBaseName(argv[i])); } } fprintf(fp, "\n\n"); fprintf(fp, "FILES ="); for (i = optind; i < argc; i++) { if (access(argv[i], R_OK) != 0) { continue; } strncpy(path, argv[i], sizeof(path)); ext = mapExtension(path); if (strcmp(ext, ".java") == 0) { fprintf(fp, " \\\n\t$(BLD_OBJ_DIR)/classes/$(SRC_PATH)/%s", mprGetBaseName(path)); } else { fprintf(fp, " \\\n\t$(BLD_OBJ_DIR)/%s", mprGetBaseName(path)); } } fprintf(fp, "\n"); for (i = optind; !finished && i < argc; i++) { if (*argv[i] == '*') { continue; } strcpy(path, argv[i]); ext = mapExtension(path); if (strcmp(ext, ".java") == 0) { fprintf(fp, "\n$(BLD_OBJ_DIR)/classes/$(SRC_PATH)/%s: ", mprGetBaseName(path)); } else { fprintf(fp, "\n$(BLD_OBJ_DIR)/%s: ", mprGetBaseName(path)); } numDependencies = 0; findDependencies(fp, argv[i]); qsort(dependencies, numDependencies, sizeof(char*), depSort); previous = ""; for (j = 0; j < numDependencies; j++) { if (strcmp(previous, dependencies[j]) != 0) { fprintf(fp, " \\\n\t%s", dependencies[j]); } previous = dependencies[j]; } for (j = 0; j < numDependencies; j++) { free(dependencies[j]); } fprintf(fp, "\n"); } fprintf(fp, "\n#\n# Read the Makefile rules\n#\n"); fprintf(fp, "include $(BLD_TOP)/build/make/make.rules\n\n"); fprintf(fp, "ifeq ($(BUILDING_CROSS),1)\n"); fprintf(fp, " include $(BLD_TOP)/build/make/make.os.$(BLD_HOST_OS)\n"); fprintf(fp, "else\n"); fprintf(fp, " include $(BLD_TOP)/build/make/make.os.$(BLD_BUILD_OS)\n"); fprintf(fp, "endif\n\n"); fclose(fp); return 0; }
static int findDependencies(FILE *fp, char *fname) { FILE *ifp; char path[2048], buf[8192], dirName[2048]; char *cp, *ep; int line, i, j; if ((ifp = fopen(fname, "r")) == 0) { if (!quiet) { fprintf(stderr, "Cant open %s\n", fname); } return -1; } for (line = 0; ! feof(ifp); line++) { if (fgets(buf, sizeof(buf), ifp) == 0) break; cp = buf; if (*cp++ != '#') { continue; } while (*cp == '\t' || *cp == ' ') { cp++; } if (*cp != 'i' || strncmp(cp, "include", 7)) { continue; } cp += 7; while (*cp == '\t' || *cp == ' ' || *cp == '\"') { cp++; } // // Skip system headers // if (*cp == '<') { continue; } ep = cp; while (isalnum((unsigned char) *ep) || *ep == '_' || *ep == '.' || *ep == '/' || *ep == '-') { ep++; } *ep = '\0'; strcpy(buf, cp); if (buf[0] == '/' || (buf[0] == '.' && buf[1] == '.')) { if (access(buf, R_OK) < 0) { if (!quiet) { fprintf(stderr, "Cant find include %s\n", buf); } continue; } } else { // // First search relative to the including file // mprGetDirName(dirName, sizeof(dirName), fname); if (*dirName) { sprintf(path, "%s/%s", dirName, buf); } else { strcpy(path, dirName); } if (access(path, R_OK) < 0) { for (j = 0; j < numIncludeDir; j++) { sprintf(path, "%s/%s", includeDir[j], buf); if (access(path, R_OK) == 0) { break; } } if (j == numIncludeDir) { if (!quiet) { fprintf(stderr, "Cant find include %s in %s at %d\n", buf, fname, line); } continue; } } } if (numDependencies >= MAX_DEPEND) { fprintf(stderr, "Too many dependencies\n"); } else { for (i = 0; i < numDependencies; i++) { if (strcmp(path, dependencies[i]) == 0) break; } if (i == numDependencies) { dependencies[numDependencies++] = strdup(path); findDependencies(fp, path); } } } fclose(ifp); return 0; }
void NmakeMakefileGenerator::writeNmakeParts(QTextStream &t) { t << "####### Compiler, tools and options" << endl << endl; t << "CC = " << var("QMAKE_CC") << endl; t << "CXX = " << var("QMAKE_CXX") << endl; t << "LEX = " << var("QMAKE_LEX") << endl; t << "YACC = " << var("QMAKE_YACC") << endl; t << "CFLAGS = " << var("QMAKE_CFLAGS") << " " << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " " << varGlue("DEFINES","-D"," -D","") << endl; t << "CXXFLAGS = " << var("QMAKE_CXXFLAGS") << " " << varGlue("PRL_EXPORT_DEFINES","-D"," -D","") << " " << varGlue("DEFINES","-D"," -D","") << endl; t << "LEXFLAGS =" << var("QMAKE_LEXFLAGS") << endl; t << "YACCFLAGS =" << var("QMAKE_YACCFLAGS") << endl; t << "INCPATH = "; QStringList &incs = project->variables()["INCLUDEPATH"]; for(QStringList::Iterator incit = incs.begin(); incit != incs.end(); ++incit) { QString inc = (*incit); if (inc.endsWith("\\")) inc.truncate(inc.length()-1); if (inc.startsWith("\"") && inc.endsWith("\"")) inc = inc.mid(1, inc.length() - 2); t << " -I\"" << inc << "\""; } t << " -I\"" << specdir() << "\"" << endl; if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) { t << "LINK = " << var("QMAKE_LINK") << endl; t << "LFLAGS = " << var("QMAKE_LFLAGS"); if ( !project->variables()["QMAKE_LIBDIR"].isEmpty() ) t << " " << varGlue("QMAKE_LIBDIR","/LIBPATH:\"","\" /LIBPATH:\"","\""); t << endl; t << "LIBS = "; QStringList &libs = project->variables()["QMAKE_LIBS"]; for(QStringList::Iterator libit = libs.begin(); libit != libs.end(); ++libit) { QString lib = (*libit); if (lib.endsWith("\\")) lib.truncate(lib.length()-1); t << " \"" << lib << "\""; } t << endl; } else { t << "LIB = " << var("QMAKE_LIB") << endl; } t << "MOC = " << (project->isEmpty("QMAKE_MOC") ? QString("moc") : Option::fixPathToTargetOS(var("QMAKE_MOC"), FALSE)) << endl; t << "UIC = " << (project->isEmpty("QMAKE_UIC") ? QString("uic") : Option::fixPathToTargetOS(var("QMAKE_UIC"), FALSE)) << endl; t << "QMAKE = " << (project->isEmpty("QMAKE_QMAKE") ? QString("qmake") : Option::fixPathToTargetOS(var("QMAKE_QMAKE"), FALSE)) << endl; t << "IDC = " << (project->isEmpty("QMAKE_IDC") ? QString("idc") : Option::fixPathToTargetOS(var("QMAKE_IDC"), FALSE)) << endl; t << "IDL = " << (project->isEmpty("QMAKE_IDL") ? QString("midl") : Option::fixPathToTargetOS(var("QMAKE_IDL"), FALSE)) << endl; t << "ZIP = " << var("QMAKE_ZIP") << endl; t << "COPY_FILE = " << var("QMAKE_COPY") << endl; t << "COPY_DIR = " << var("QMAKE_COPY") << endl; t << "DEL_FILE = " << var("QMAKE_DEL_FILE") << endl; t << "DEL_DIR = " << var("QMAKE_DEL_DIR") << endl; t << "MOVE = " << var("QMAKE_MOVE") << endl; t << "CHK_DIR_EXISTS = " << var("QMAKE_CHK_DIR_EXISTS") << endl; t << "MKDIR = " << var("QMAKE_MKDIR") << endl; t << "INSTALL_FILE= " << var("QMAKE_INSTALL_FILE") << endl; t << "INSTALL_DIR = " << var("QMAKE_INSTALL_DIR") << endl; t << endl; t << "####### Files" << endl << endl; t << "HEADERS = " << varList("HEADERS") << endl; t << "SOURCES = " << varList("SOURCES") << endl; t << "OBJECTS = " << varList("OBJECTS") << endl; t << "FORMS = " << varList("FORMS") << endl; t << "UICDECLS = " << varList("UICDECLS") << endl; t << "UICIMPLS = " << varList("UICIMPLS") << endl; t << "SRCMOC = " << varList("SRCMOC") << endl; t << "OBJMOC = " << varList("OBJMOC") << endl; QString extraCompilerDeps; if(!project->isEmpty("QMAKE_EXTRA_WIN_COMPILERS")) { t << "OBJCOMP = " << varList("OBJCOMP") << endl; extraCompilerDeps += " $(OBJCOMP) "; QStringList &comps = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"]; for(QStringList::Iterator compit = comps.begin(); compit != comps.end(); ++compit) { QStringList &vars = project->variables()[(*compit) + ".variables"]; for(QStringList::Iterator varit = vars.begin(); varit != vars.end(); ++varit) { QStringList vals = project->variables()[(*varit)]; if(!vals.isEmpty()) t << "QMAKE_COMP_" << (*varit) << " = " << valList(vals) << endl; } } } t << "DIST = " << varList("DISTFILES") << endl; t << "TARGET = "; if( !project->variables()[ "DESTDIR" ].isEmpty() ) t << varGlue("TARGET",project->first("DESTDIR"),"",project->first("TARGET_EXT")); else t << project->variables()[ "TARGET" ].first() << project->variables()[ "TARGET_EXT" ].first(); t << endl; t << endl; t << "####### Implicit rules" << endl << endl; t << ".SUFFIXES: .c"; QStringList::Iterator cppit; for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) t << " " << (*cppit); t << endl << endl; if(!project->isActiveConfig("no_batch")) { // Batchmode doesn't use the non implicit rules QMAKE_RUN_CXX & QMAKE_RUN_CC project->variables().remove("QMAKE_RUN_CXX"); project->variables().remove("QMAKE_RUN_CC"); QDict<void> source_directories; source_directories.insert(".", (void*)1); QString directories[] = { QString("MOC_DIR"), QString("UI_SOURCES_DIR"), QString("UI_DIR"), QString::null }; for(int y = 0; !directories[y].isNull(); y++) { QString dirTemp = project->first(directories[y]); if (dirTemp.endsWith("\\")) dirTemp.truncate(dirTemp.length()-1); if(!dirTemp.isEmpty()) source_directories.insert(dirTemp, (void*)1); } QString srcs[] = { QString("SOURCES"), QString("UICIMPLS"), QString("SRCMOC"), QString::null }; for(int x = 0; !srcs[x].isNull(); x++) { QStringList &l = project->variables()[srcs[x]]; for(QStringList::Iterator sit = l.begin(); sit != l.end(); ++sit) { QString sep = "\\"; if((*sit).find(sep) == -1) sep = "/"; QString dir = (*sit).section(sep, 0, -2); if(!dir.isEmpty() && !source_directories[dir]) source_directories.insert(dir, (void*)1); } } for(QDictIterator<void> it(source_directories); it.current(); ++it) { if(it.currentKey().isEmpty()) continue; for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) t << "{" << it.currentKey() << "}" << (*cppit) << "{" << var("OBJECTS_DIR") << "}" << Option::obj_ext << "::\n\t" << var("QMAKE_RUN_CXX_IMP_BATCH").replace( QRegExp( "\\$@" ), var("OBJECTS_DIR") ) << endl << "\t$<" << endl << "<<" << endl << endl; t << "{" << it.currentKey() << "}" << ".c{" << var("OBJECTS_DIR") << "}" << Option::obj_ext << "::\n\t" << var("QMAKE_RUN_CC_IMP_BATCH").replace( QRegExp( "\\$@" ), var("OBJECTS_DIR") ) << endl << "\t$<" << endl << "<<" << endl << endl; } } else { for(cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) t << (*cppit) << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CXX_IMP") << endl << endl; t << ".c" << Option::obj_ext << ":\n\t" << var("QMAKE_RUN_CC_IMP") << endl << endl; } t << "####### Build rules" << endl << endl; t << "all: " << fileFixify(Option::output.name()) << " " << varGlue("ALL_DEPS"," "," "," ") << "$(TARGET)" << endl << endl; t << "$(TARGET): " << var("PRE_TARGETDEPS") << " $(UICDECLS) $(OBJECTS) $(OBJMOC) " << extraCompilerDeps << var("POST_TARGETDEPS"); if(!project->variables()["QMAKE_APP_OR_DLL"].isEmpty()) { t << "\n\t" << "$(LINK) $(LFLAGS) /OUT:$(TARGET) @<< " << "\n\t " << "$(OBJECTS) $(OBJMOC) $(LIBS)"; } else { t << "\n\t" << "$(LIB) /OUT:$(TARGET) @<<" << "\n\t " << "$(OBJECTS) $(OBJMOC)"; } t << extraCompilerDeps; t << endl << "<<" << endl; if ( !project->variables()["QMAKE_POST_LINK"].isEmpty() ) t << "\t" << var( "QMAKE_POST_LINK" ) << endl; if(project->isActiveConfig("dll") && !project->variables()["DLLDESTDIR"].isEmpty()) { QStringList dlldirs = project->variables()["DLLDESTDIR"]; for ( QStringList::Iterator dlldir = dlldirs.begin(); dlldir != dlldirs.end(); ++dlldir ) { t << "\n\t" << "-$(COPY_FILE) \"$(TARGET)\" " << *dlldir; } } QString targetfilename = project->variables()["TARGET"].first(); if(project->isActiveConfig("activeqt")) { QString version = project->variables()["VERSION"].first(); if ( version.isEmpty() ) version = "1.0"; if ( project->isActiveConfig("dll")) { t << "\n\t" << ("-$(IDC) $(TARGET) /idl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version); t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb"); t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb"); t << "\n\t" << ("-$(IDC) $(TARGET) /regserver" ); } else { t << "\n\t" << ("-$(TARGET) -dumpidl " + var("OBJECTS_DIR") + targetfilename + ".idl -version " + version); t << "\n\t" << ("-$(IDL) /nologo " + var("OBJECTS_DIR") + targetfilename + ".idl /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb"); t << "\n\t" << ("-$(IDC) $(TARGET) /tlb " + var("OBJECTS_DIR") + targetfilename + ".tlb"); t << "\n\t" << "-$(TARGET) -regserver"; } } t << endl << endl; if(!project->variables()["RC_FILE"].isEmpty()) { t << var("RES_FILE") << ": " << var("RC_FILE") << "\n\t" << var("QMAKE_RC") << " " << var("RC_FILE") << endl << endl; } t << "mocables: $(SRCMOC)" << endl << "uicables: $(UICIMPLS) $(UICDECLS)" << endl << endl; writeMakeQmake(t); QStringList dist_files = Option::mkfile::project_files; if(!project->isEmpty("QMAKE_INTERNAL_INCLUDED_FILES")) dist_files += project->variables()["QMAKE_INTERNAL_INCLUDED_FILES"]; if(!project->isEmpty("TRANSLATIONS")) dist_files << var("TRANSLATIONS"); if(!project->isEmpty("FORMS")) { QStringList &forms = project->variables()["FORMS"]; for(QStringList::Iterator formit = forms.begin(); formit != forms.end(); ++formit) { QString ui_h = fileFixify((*formit) + Option::h_ext.first()); if(QFile::exists(ui_h) ) dist_files << ui_h; } } t << "dist:" << "\n\t" << "$(ZIP) " << var("QMAKE_ORIG_TARGET") << ".zip " << "$(SOURCES) $(HEADERS) $(DIST) $(FORMS) " << dist_files.join(" ") << " " << var("TRANSLATIONS") << " " << var("IMAGES") << endl << endl; t << "uiclean:" << varGlue("UICDECLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << varGlue("UICIMPLS" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << endl; t << "mocclean:" << varGlue("SRCMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << varGlue("OBJMOC" ,"\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << endl; t << "clean: uiclean mocclean" << varGlue("OBJECTS","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","") << varGlue("QMAKE_CLEAN","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","\n") << varGlue("CLEAN_FILES","\n\t-$(DEL_FILE) ","\n\t-$(DEL_FILE) ","\n"); if ( project->isActiveConfig("activeqt")) { t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".idl"); t << ("\n\t-$(DEL_FILE) " + var("OBJECTS_DIR") + targetfilename + ".tlb"); } if(!project->isEmpty("IMAGES")) t << varGlue("QMAKE_IMAGE_COLLECTION", "\n\t-$(DEL_FILE) ", "\n\t-$(DEL_FILE) ", ""); t << endl; // user defined targets QStringList::Iterator it; QStringList &qut = project->variables()["QMAKE_EXTRA_WIN_TARGETS"]; for(it = qut.begin(); it != qut.end(); ++it) { QString targ = var((*it) + ".target"), cmd = var((*it) + ".commands"), deps; if(targ.isEmpty()) targ = (*it); QStringList &deplist = project->variables()[(*it) + ".depends"]; for(QStringList::Iterator dep_it = deplist.begin(); dep_it != deplist.end(); ++dep_it) { QString dep = var((*dep_it) + ".target"); if(dep.isEmpty()) dep = (*dep_it); deps += " " + dep; } if(!project->variables()["QMAKE_NOFORCE"].isEmpty() && project->variables()[(*it) + ".CONFIG"].findIndex("phony") != -1) deps += QString(" ") + "FORCE"; t << "\n\n" << targ << ":" << deps << "\n\t" << cmd; } t << endl << endl; QStringList &quc = project->variables()["QMAKE_EXTRA_WIN_COMPILERS"]; for(it = quc.begin(); it != quc.end(); ++it) { QString tmp_out = project->variables()[(*it) + ".output"].first(); QString tmp_cmd = project->variables()[(*it) + ".commands"].join(" "); QString tmp_dep = project->variables()[(*it) + ".depends"].join(" "); QStringList &vars = project->variables()[(*it) + ".variables"]; if(tmp_out.isEmpty() || tmp_cmd.isEmpty()) continue; QStringList &tmp = project->variables()[(*it) + ".input"]; for(QStringList::Iterator it2 = tmp.begin(); it2 != tmp.end(); ++it2) { QStringList &inputs = project->variables()[(*it2)]; for(QStringList::Iterator input = inputs.begin(); input != inputs.end(); ++input) { QFileInfo fi(Option::fixPathToLocalOS((*input))); QString in = Option::fixPathToTargetOS((*input), FALSE), out = tmp_out, cmd = tmp_cmd, deps; out.replace("${QMAKE_FILE_BASE}", fi.baseName()); out.replace("${QMAKE_FILE_NAME}", fi.filePath()); cmd.replace("${QMAKE_FILE_BASE}", fi.baseName()); cmd.replace("${QMAKE_FILE_OUT}", out); cmd.replace("${QMAKE_FILE_NAME}", fi.filePath()); for(QStringList::Iterator it3 = vars.begin(); it3 != vars.end(); ++it3) cmd.replace("$(" + (*it3) + ")", "$(QMAKE_COMP_" + (*it3)+")"); if(!tmp_dep.isEmpty()) { char buff[256]; QString dep_cmd = tmp_dep; dep_cmd.replace("${QMAKE_FILE_NAME}", fi.filePath()); if(FILE *proc = QT_POPEN(dep_cmd.latin1(), "r")) { while(!feof(proc)) { int read_in = int(fread(buff, 1, 255, proc)); if(!read_in) break; int l = 0; for(int i = 0; i < read_in; i++) { if(buff[i] == '\n' || buff[i] == ' ') { deps += " " + QCString(buff+l, (i - l) + 1); l = i; } } } fclose(proc); } } t << out << ": " << in << deps << "\n\t" << cmd << endl << endl; } } } t << endl; if(project->variables()["QMAKE_NOFORCE"].isEmpty()) t << "FORCE:" << endl << endl; t << "distclean: clean" << "\n\t-$(DEL_FILE) $(TARGET)" << endl << endl; // precompiled header if(usePCH) { QString precompRule = QString("-c -Yc -Fp%1 -Fo%2").arg(precompPch).arg(precompObj); t << precompObj << ": " << precompH << " " << findDependencies(precompH).join(" \\\n\t\t") << "\n\t" << ("$(CXX) " + precompRule + " $(CXXFLAGS) $(INCPATH) -TP ") << precompH << endl << endl; } }
bool DspMakefileGenerator::writeDspParts(QTextStream &t) { QString dspfile; if ( !project->variables()["DSP_TEMPLATE"].isEmpty() ) { dspfile = project->first("DSP_TEMPLATE"); } else { dspfile = project->first("MSVCDSP_TEMPLATE"); } if (dspfile.startsWith("\"") && dspfile.endsWith("\"")) dspfile = dspfile.mid(1, dspfile.length() - 2); QString dspfile_loc = findTemplate(dspfile); QFile file(dspfile_loc); if(!file.open(IO_ReadOnly)) { fprintf(stderr, "Cannot open dsp file: %s\n", dspfile.latin1()); return FALSE; } QTextStream dsp(&file); QString platform = "Win32"; if ( !project->variables()["QMAKE_PLATFORM"].isEmpty() ) platform = varGlue("QMAKE_PLATFORM", "", " ", ""); // Setup PCH variables precompH = project->first("PRECOMPILED_HEADER"); QString namePCH = QFileInfo(precompH).fileName(); usePCH = !precompH.isEmpty() && project->isActiveConfig("precompile_header"); if (usePCH) { // Created files QString origTarget = project->first("QMAKE_ORIG_TARGET"); origTarget.replace(QRegExp("-"), "_"); precompObj = "\"$(IntDir)\\" + origTarget + Option::obj_ext + "\""; precompPch = "\"$(IntDir)\\" + origTarget + ".pch\""; // Add PRECOMPILED_HEADER to HEADERS if (!project->variables()["HEADERS"].contains(precompH)) project->variables()["HEADERS"] += precompH; // Add precompile compiler options project->variables()["PRECOMPILED_FLAGS_REL"] = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" "; project->variables()["PRECOMPILED_FLAGS_DEB"] = "/Yu\"" + namePCH + "\" /FI\"" + namePCH + "\" "; // Return to variable pool project->variables()["PRECOMPILED_OBJECT"] = precompObj; project->variables()["PRECOMPILED_PCH"] = precompPch; } int rep; QString line; while ( !dsp.eof() ) { line = dsp.readLine(); while((rep = line.find(QRegExp("\\$\\$[a-zA-Z0-9_-]*"))) != -1) { QString torep = line.mid(rep, line.find(QRegExp("[^\\$a-zA-Z0-9_-]"), rep) - rep); QString variable = torep.right(torep.length()-2); t << line.left(rep); //output the left side line = line.right(line.length() - (rep + torep.length())); //now past the variable if(variable == "MSVCDSP_SOURCES") { if(project->variables()["SOURCES"].isEmpty()) continue; QString mocpath = var( "QMAKE_MOC" ); mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " "; QStringList list = project->variables()["SOURCES"] + project->variables()["DEF_FILE"]; if(!project->isActiveConfig("flat")) list.sort(); QStringList::Iterator it; for( it = list.begin(); it != list.end(); ++it) { beginGroupForFile((*it), t); t << "# Begin Source File\n\nSOURCE=" << (*it) << endl; if (usePCH && (*it).endsWith(".c")) t << "# SUBTRACT CPP /FI\"" << namePCH << "\" /Yu\"" << namePCH << "\" /Fp" << endl; if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) { QString base = (*it); base.replace(QRegExp("\\..*$"), "").upper(); base.replace(QRegExp("[^a-zA-Z]"), "_"); QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) + "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\"" " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n" "\t" + mocpath + findMocSource((*it)) + " -o " + (*it) + "\n\n" "# End Custom Build\n\n"; t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build << "!ENDIF " << endl << endl; } t << "# End Source File" << endl; } endGroups(t); } else if(variable == "MSVCDSP_IMAGES") { if(project->variables()["IMAGES"].isEmpty()) continue; t << "# Begin Source File\n\nSOURCE=" << project->first("QMAKE_IMAGE_COLLECTION") << endl; t << "# End Source File" << endl; } else if(variable == "MSVCDSP_HEADERS") { if(project->variables()["HEADERS"].isEmpty()) continue; QStringList list = project->variables()["HEADERS"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { // beginGroupForFile((*it), t); t << "# Begin Source File\n\nSOURCE=" << (*it) << endl << endl; QString compilePCH; QStringList customDependencies; QString createMOC; QString buildCmdsR, buildCmdsD; QString buildCmds = "\nBuildCmds= \\\n"; // Create unique baseID QString base = (*it); { base.replace(QRegExp("\\..*$"), "").upper(); base.replace(QRegExp("[^a-zA-Z]"), "_"); } if (usePCH && precompH.endsWith(*it)) { QString basicBuildCmd = QString("\tcl.exe /TP /W3 /FD /c /D \"WIN32\" /Yc /Fp\"%1\" /Fo\"%2\" %3 %4 %5 %6 %7 %8 %9 /D \"") .arg(precompPch) .arg(precompObj) .arg(var("MSVCDSP_INCPATH")) .arg(var("MSVCDSP_DEFINES")) .arg(var("MSVCDSP_CXXFLAGS")); buildCmdsR = basicBuildCmd .arg("/D \"NDEBUG\"") .arg(var("QMAKE_CXXFLAGS_RELEASE")) .arg(var("MSVCDSP_MTDEF")) .arg(var("MSVCDSP_RELDEFS")); buildCmdsD = basicBuildCmd .arg("/D \"_DEBUG\" /Od") .arg(var("QMAKE_CXXFLAGS_DEBUG")) .arg(var("MSVCDSP_MTDEFD")) .arg(var("MSVCDSP_DEBUG_OPT")); if (project->first("TEMPLATE") == "vcapp") { // App buildCmdsR += var("MSVCDSP_WINCONDEF"); buildCmdsD += var("MSVCDSP_WINCONDEF"); } else if (project->isActiveConfig("dll")) { // Dll buildCmdsR += "_WINDOWS\" /D \"_USRDLL"; buildCmdsD += "_WINDOWS\" /D \"_USRDLL"; } else { // Lib buildCmdsR += "_LIB"; buildCmdsD += "_LIB"; } buildCmdsR += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n"; buildCmdsD += "\" /Fd\"$(IntDir)\\\\\" " + (*it) + " \\\n"; compilePCH = precompPch + " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n $(BuildCmds)\n\n"; QStringList &tmp = findDependencies(precompH); if(!tmp.isEmpty()) // Got Deps for PCH customDependencies += tmp; } if (project->isActiveConfig("moc") && !findMocDestination((*it)).isEmpty()) { QString mocpath = var( "QMAKE_MOC" ); mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " "; buildCmds += "\t" + mocpath + (*it) + " -o " + findMocDestination((*it)) + " \\\n"; createMOC = "\"" + findMocDestination((*it)) + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n $(BuildCmds)\n\n"; customDependencies += "\"$(QTDIR)\\bin\\moc.exe\""; } if (!createMOC.isEmpty() || !compilePCH.isEmpty()) { bool doMOC = !createMOC.isEmpty(); bool doPCH = !compilePCH.isEmpty(); QString build = "\n\n# Begin Custom Build - "+ QString(doMOC?"Moc'ing ":"") + QString((doMOC&&doPCH)?" and ":"") + QString(doPCH?"Creating PCH cpp from ":"") + (*it) + "...\nInputPath=.\\" + (*it) + "\n\n" + buildCmds + "%1\n" + createMOC + compilePCH + "# End Custom Build\n\n"; t << "USERDEP_" << base << "=" << valGlue(customDependencies, "\"", "\" \"", "\"") << endl << endl; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build.arg(buildCmdsR) << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build.arg(buildCmdsD) << "!ENDIF " << endl << endl; } t << "# End Source File" << endl; } // endGroups(t); } else if(variable == "MSVCDSP_FORMSOURCES" || variable == "MSVCDSP_FORMHEADERS") { if(project->variables()["FORMS"].isEmpty()) continue; QString uiSourcesDir; QString uiHeadersDir; if(!project->variables()["UI_DIR"].isEmpty()) { uiSourcesDir = project->first("UI_DIR"); uiHeadersDir = project->first("UI_DIR"); } else { if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() ) uiSourcesDir = project->first("UI_SOURCES_DIR"); else uiSourcesDir = ""; if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() ) uiHeadersDir = project->first("UI_HEADERS_DIR"); else uiHeadersDir = ""; } QStringList list = project->variables()["FORMS"]; if(!project->isActiveConfig("flat")) list.sort(); QString ext = variable == "MSVCDSP_FORMSOURCES" ? ".cpp" : ".h"; for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QString base = (*it); int dot = base.findRev("."); base.replace( dot, base.length() - dot, ext ); QString fname = base; int lbs = fname.findRev( "\\" ); QString fpath; if ( lbs != -1 ) fpath = fname.left( lbs + 1 ); fname = fname.right( fname.length() - lbs - 1 ); if ( ext == ".cpp" && !uiSourcesDir.isEmpty() ) fname.prepend(uiSourcesDir); else if ( ext == ".h" && !uiHeadersDir.isEmpty() ) fname.prepend(uiHeadersDir); else fname = base; // beginGroupForFile(fname, t); t << "# Begin Source File\n\nSOURCE=" << fname << "\n# End Source File" << endl; } // endGroups(t); } else if(variable == "MSVCDSP_TRANSLATIONS" ) { if(project->variables()["TRANSLATIONS"].isEmpty()) continue; t << "# Begin Group \"Translations\"\n"; t << "# Prop Default_Filter \"ts\"\n"; QStringList list = project->variables()["TRANSLATIONS"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QString sify = *it; sify.replace('/', '\\' ); QString base = (*it); base.replace(QRegExp("\\..*$"), "").upper(); base.replace(QRegExp("[^a-zA-Z]"), "_"); // beginGroupForFile(sify, t); t << "# Begin Source File\n\nSOURCE=" << sify << endl; t << "\n# End Source File" << endl; } // endGroups(t); t << "\n# End Group\n"; } else if (variable == "MSVCDSP_MOCSOURCES" && project->isActiveConfig("moc")) { if ( project->variables()["SRCMOC"].isEmpty()) continue; QString mocpath = var( "QMAKE_MOC" ); mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " "; QStringList list = project->variables()["SRCMOC"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { // beginGroupForFile((*it), t); t << "# Begin Source File\n\nSOURCE=" << (*it) << endl; if ( project->isActiveConfig("moc") && (*it).endsWith(Option::cpp_moc_ext)) { QString base = (*it); base.replace(QRegExp("\\..*$"), "").upper(); base.replace(QRegExp("[^a-zA-Z]"), "_"); QString build = "\n\n# Begin Custom Build - Moc'ing " + findMocSource((*it)) + "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + (*it) + "\"" " : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n" "\t" + mocpath + findMocSource((*it)) + " -o " + (*it) + "\n\n" "# End Custom Build\n\n"; t << "USERDEP_" << base << "=\".\\" << findMocSource((*it)) << "\" \"$(QTDIR)\\bin\\moc.exe\"" << endl << endl; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build << "!ENDIF " << endl << endl; } t << "# End Source File" << endl; } // endGroups(t); } else if(variable == "MSVCDSP_PICTURES") { if(project->variables()["IMAGES"].isEmpty()) continue; t << "# Begin Group \"Images\"\n" << "# Prop Default_Filter \"png jpeg bmp xpm\"\n"; QStringList list = project->variables()["IMAGES"]; if(!project->isActiveConfig("flat")) list.sort(); QStringList::Iterator it; // dump the image list to a file UIC can read. QFile f( "images.tmp" ); f.open( IO_WriteOnly ); QTextStream ts( &f ); for( it = list.begin(); it != list.end(); ++it ) ts << " " << *it; f.close(); // create an output step for images not more than once bool imagesBuildDone = FALSE; for( it = list.begin(); it != list.end(); ++it ) { // beginGroupForFile((*it), t); t << "# Begin Source File\n\nSOURCE=" << (*it) << endl; QString base = (*it); QString uicpath = var("QMAKE_UIC"); uicpath = uicpath.replace(QRegExp("\\..*$"), "") + " "; if ( !imagesBuildDone ) { imagesBuildDone = TRUE; QString build = "\n\n# Begin Custom Build - Creating image collection...\n" "InputPath=.\\" + base + "\n\n"; build += "\"" + project->first("QMAKE_IMAGE_COLLECTION") + "\" : $(SOURCE) \"$(INTDIR)\" \"$(OUTDIR)\"\n"; build += "\t" + uicpath + "-embed " + project->first("QMAKE_ORIG_TARGET") + " -f images.tmp -o " + project->first("QMAKE_IMAGE_COLLECTION") + "\n\n"; build.append("# End Custom Build\n\n"); t << "USERDEP_" << base << "="; QStringList::Iterator it2 = list.begin(); while ( it2 != list.end() ) { t << "\"" << (*it2) << "\""; it2++; if ( it2 != list.end() ) t << "\\\n"; } t << endl << endl; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - Win32 Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - Win32 Debug\"" << build << "!ENDIF \n\n" << endl; } t << "# End Source File" << endl; } // endGroups(t); t << "\n# End Group\n"; } else if(variable == "MSVCDSP_FORMS") { if(project->variables()["FORMS"].isEmpty()) continue; t << "# Begin Group \"Forms\"\n" << "# Prop Default_Filter \"ui\"\n"; QString uicpath = var("QMAKE_UIC"); uicpath = uicpath.replace(QRegExp("\\..*$"), "") + " "; QString mocpath = var( "QMAKE_MOC" ); mocpath = mocpath.replace( QRegExp( "\\..*$" ), "" ) + " "; QStringList list = project->variables()["FORMS"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QString base = (*it); // beginGroupForFile(base, t); t << "# Begin Source File\n\nSOURCE=" << base << endl; QString fname = base; fname.replace(".ui", ""); int lbs = fname.findRev( "\\" ); QString fpath; if ( lbs != -1 ) fpath = fname.left( lbs + 1 ); fname = fname.right( fname.length() - lbs - 1 ); QString mocFile; if(!project->variables()["MOC_DIR"].isEmpty()) mocFile = project->first("MOC_DIR"); else mocFile = fpath; QString uiSourcesDir; QString uiHeadersDir; if(!project->variables()["UI_DIR"].isEmpty()) { uiSourcesDir = project->first("UI_DIR"); uiHeadersDir = project->first("UI_DIR"); } else { if ( !project->variables()["UI_SOURCES_DIR"].isEmpty() ) uiSourcesDir = project->first("UI_SOURCES_DIR"); else uiSourcesDir = fpath; if ( !project->variables()["UI_HEADERS_DIR"].isEmpty() ) uiHeadersDir = project->first("UI_HEADERS_DIR"); else uiHeadersDir = fpath; } t << "USERDEP_" << base << "=\"$(QTDIR)\\bin\\moc.exe\" \"$(QTDIR)\\bin\\uic.exe\"" << endl << endl; QString build = "\n\n# Begin Custom Build - Uic'ing " + base + "...\n" "InputPath=.\\" + base + "\n\n" "BuildCmds= \\\n\t" + uicpath + base + " -o " + uiHeadersDir + fname + ".h \\\n" "\t" + uicpath + base + " -i " + fname + ".h -o " + uiSourcesDir + fname + ".cpp \\\n" "\t" + mocpath + " " + uiHeadersDir + fname + ".h -o " + mocFile + Option::h_moc_mod + fname + Option::h_moc_ext + " \\\n"; build.append("\n\"" + uiHeadersDir + fname + ".h\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n" "\t$(BuildCmds)\n\n" "\"" + uiSourcesDir + fname + ".cpp\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n" "\t$(BuildCmds)\n\n" "\"" + mocFile + Option::h_moc_mod + fname + Option::h_moc_ext + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n" "\t$(BuildCmds)\n\n"); build.append("# End Custom Build\n\n"); t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build << "!ENDIF \n\n" << "# End Source File" << endl; } // endGroups(t); t << "\n# End Group\n"; } else if(variable == "MSVCDSP_LEXSOURCES") { if(project->variables()["LEXSOURCES"].isEmpty()) continue; t << "# Begin Group \"Lexables\"\n" << "# Prop Default_Filter \"l\"\n"; QString lexpath = var("QMAKE_LEX") + varGlue("QMAKE_LEXFLAGS", " ", " ", "") + " "; QStringList list = project->variables()["LEXSOURCES"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QString fname = (*it); // beginGroupForFile(fname, t); t << "# Begin Source File\n\nSOURCE=" << fname << endl; fname.replace(".l", Option::lex_mod + Option::cpp_ext.first()); QString build = "\n\n# Begin Custom Build - Lex'ing " + (*it) + "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + fname + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n" "\t" + lexpath + (*it) + "\\\n" "\tdel " + fname + "\\\n" "\tcopy lex.yy.c " + fname + "\n\n" + "# End Custom Build\n\n"; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build << "!ENDIF \n\n" << build << "# End Source File" << endl; } // endGroups(t); t << "\n# End Group\n"; } else if(variable == "MSVCDSP_YACCSOURCES") { if(project->variables()["YACCSOURCES"].isEmpty()) continue; t << "# Begin Group \"Yaccables\"\n" << "# Prop Default_Filter \"y\"\n"; QString yaccpath = var("QMAKE_YACC") + varGlue("QMAKE_YACCFLAGS", " ", " ", "") + " "; QStringList list = project->variables()["YACCSOURCES"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { QString fname = (*it); // beginGroupForFile(fname, t); t << "# Begin Source File\n\nSOURCE=" << fname << endl; fname.replace(".y", Option::yacc_mod); QString build = "\n\n# Begin Custom Build - Yacc'ing " + (*it) + "...\n" "InputPath=.\\" + (*it) + "\n\n" "\"" + fname + Option::cpp_ext.first() + "\" : \"$(SOURCE)\" \"$(INTDIR)\" \"$(OUTDIR)\"" "\n" "\t" + yaccpath + (*it) + "\\\n" "\tdel " + fname + Option::h_ext.first() + "\\\n" "\tmove y.tab.h " + fname + Option::h_ext.first() + "\n\n" + "\tdel " + fname + Option::cpp_ext.first() + "\\\n" "\tmove y.tab.c " + fname + Option::cpp_ext.first() + "\n\n" + "# End Custom Build\n\n"; t << "!IF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Release\"" << build << "!ELSEIF \"$(CFG)\" == \"" << var("MSVCDSP_PROJECT") << " - " << platform << " Debug\"" << build << "!ENDIF \n\n" << "# End Source File" << endl; } // endGroups(t); t << "\n# End Group\n"; } else if( variable == "MSVCDSP_CONFIGMODE" ) { if( project->isActiveConfig( "debug" ) ) t << "Debug"; else t << "Release"; } else if( variable == "MSVCDSP_IDLSOURCES" ) { QStringList list = project->variables()["MSVCDSP_IDLSOURCES"]; if(!project->isActiveConfig("flat")) list.sort(); for(QStringList::Iterator it = list.begin(); it != list.end(); ++it) { t << "# Begin Source File" << endl << endl; t << "SOURCE=" << (*it) << endl; t << "# PROP Exclude_From_Build 1" << endl; t << "# End Source File" << endl << endl; } } else t << var(variable); } t << line << endl; } t << endl; file.close(); return TRUE; }
int main(int argc, char *argv[]) { char path[2048], cwd[2048], dirName[2048], parent[2048]; char *ext, *previous, *cp, *argp; int errors, j, i, levels, upLevel, incJava, nextArg; errors = 0; program = mprGetBaseName(argv[0]); quiet = 0; for (nextArg = 1; nextArg < argc; nextArg++) { argp = argv[nextArg]; if (*argp != '-') { break; } if (strncmp(argp, "-I", 2) == 0) { if (numIncludeDir >= MAX_INC) { fprintf(stderr, "Too many include directories\n"); exit(1); } includeDir[numIncludeDir++] = strdup(&argp[2]); } else if (strcmp(argp, "-q") == 0) { quiet++; } } if (errors) { fprintf(stderr, "%s: usage: [-q] [-I includeDir] files...\n", program); exit(2); } includeDir[numIncludeDir++] = strdup("."); #if !BLD_WIN_LIKE && !_WIN32 includeDir[numIncludeDir++] = strdup("/usr/include"); #endif openSignals(); if ((fp = fopen("make.newdep", "w")) == 0) { fprintf(stderr, "Cant open make.newdep\n"); exit(255); } fprintf(fp, "#\n# .makedep -- Makefile dependencies. Generated by edep.\n#\n\n"); if (getcwd(cwd, sizeof(cwd)) == 0) { fprintf(stderr, "Can't get working directory"); exit(255); } mapDelimiters(cwd); fprintf(fp, "all: compile\n\n"); fprintf(fp, "BLD_TOP := "); strcpy(dirName, cwd); for (i = 0, levels = 0; *dirName; i++) { sprintf(path, "%s/build/make/make.rules", dirName); if (access(path, R_OK) == 0) { break; } mprGetDirName(parent, sizeof(parent), dirName); strcpy(dirName, parent); if (i > 0) { fprintf(fp, "/.."); } else { fprintf(fp, ".."); } levels++; } if (i == 0) { fprintf(fp, "."); } fprintf(fp, "\n"); /* * Extract a src path for Java. Go up N levels less one for the "java" directory. */ strcpy(dirName, cwd); cp = &dirName[strlen(dirName) - 1]; for (upLevel = 1; upLevel < levels && cp > dirName; cp--) { if (*cp == '/') { upLevel++; } } if (levels > 1) { if (cp[0] != '\0' && cp[1] != '\0' && cp[2] != '\0') { cp += 2; } if (*cp == '\0') { cp = "."; } fprintf(fp, "SRC_PATH := %s\n\n", cp); } else { fprintf(fp, "SRC_PATH := .\n\n"); } fprintf(fp, "#\n# Read the build configuration settings and make variable definitions.\n#\n"); fprintf(fp, "include $(BLD_TOP)/buildConfig.make\n\n"); incJava = 0; for (i = nextArg; i < argc; i++) { if (strstr(argv[i], ".java") != 0 && strcmp(argv[i], "*.java") != 0) { incJava++; /* fprintf(fp, "include $(BLD_TOP)/build/make/make.java\n"); */ break; } } if (incJava) { fprintf(fp, "HAS_JAVA = 1\n\n"); } fprintf(fp, "SRC ="); for (i = nextArg; i < argc; i++) { if (access(argv[i], R_OK) != 0) { continue; } strncpy(path, argv[i], sizeof(path)); fprintf(fp, " \\\n\t%s", mprGetBaseName(path)); } fprintf(fp, "\n\n"); fprintf(fp, "PROCESSED_SRC ="); for (i = nextArg; i < argc; i++) { if (access(argv[i], R_OK) != 0) { continue; } strncpy(path, argv[i], sizeof(path)); ext = mapExtension(path); if (strcmp(ext, ".java") == 0) { fprintf(fp, " \\\n\t$(BLD_OBJ_DIR)/src/$(SRC_PATH)/%s", mprGetBaseName(argv[i])); } } fprintf(fp, "\n\n"); fprintf(fp, "OBJECTS ="); for (i = nextArg; i < argc; i++) { if (access(argv[i], R_OK) != 0) { continue; } strncpy(path, argv[i], sizeof(path)); ext = mapExtension(path); if (strcmp(ext, ".java") == 0) { fprintf(fp, " \\\n\t$(BLD_OBJ_DIR)/classes/$(SRC_PATH)/%s", mprGetBaseName(path)); } else { fprintf(fp, " \\\n\t$(BLD_OBJ_DIR)/%s", mprGetBaseName(path)); } } fprintf(fp, "\n"); for (i = nextArg; !finished && i < argc; i++) { if (*argv[i] == '*') { continue; } strcpy(path, argv[i]); ext = mapExtension(path); if (strcmp(ext, ".java") == 0) { fprintf(fp, "\n$(BLD_OBJ_DIR)/classes/$(SRC_PATH)/%s: ", mprGetBaseName(path)); } else { fprintf(fp, "\n$(BLD_OBJ_DIR)/%s: ", mprGetBaseName(path)); } numDependencies = 0; findDependencies(fp, argv[i]); qsort(dependencies, numDependencies, sizeof(char*), depSort); previous = ""; for (j = 0; j < numDependencies; j++) { if (strcmp(previous, dependencies[j]) != 0) { fprintf(fp, " \\\n\t%s", dependencies[j]); } previous = dependencies[j]; } for (j = 0; j < numDependencies; j++) { free(dependencies[j]); } fprintf(fp, "\n"); } fprintf(fp, "\n#\n# Read the Makefile rules\n#\n"); fprintf(fp, "include $(BLD_TOP)/build/make/make.rules\n\n"); fprintf(fp, "ifeq ($(BUILDING_CROSS),1)\n"); fprintf(fp, " include $(BLD_TOP)/build/make/make.$(BLD_HOST_OS)\n"); fprintf(fp, "else\n"); fprintf(fp, " include $(BLD_TOP)/build/make/make.$(BLD_BUILD_OS)\n"); fprintf(fp, "endif\n\n"); fclose(fp); unlink("make.dep"); unlink(".makedep"); if (rename("make.newdep", ".makedep") != 0) { fprintf(stderr, "Cant rename make.newdep to .makedep\n"); exit(255); } return 0; }
void ProjectGenerator::init() { if(init_flag) return; int file_count = 0; init_flag = TRUE; QMap<QString, QStringList> &v = project->variables(); QString templ = Option::user_template.isEmpty() ? QString("app") : Option::user_template; if(!Option::user_template_prefix.isEmpty()) templ.prepend(Option::user_template_prefix); v["TEMPLATE_ASSIGN"] += templ; //figure out target if(Option::output.name() == "-" || Option::output.name().isEmpty()) v["TARGET"] = QStringList("unknown"); //the scary stuff if(project->first("TEMPLATE_ASSIGN") != "subdirs") { QString builtin_regex = project_builtin_regx(); QStringList dirs = Option::projfile::project_dirs; if(Option::projfile::do_pwd) { if(!v["INCLUDEPATH"].contains(".")) v["INCLUDEPATH"] += "."; dirs.prepend(QDir::currentDirPath()); } for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { QString dir, regex; bool add_depend = FALSE; if(QFile::exists((*pd))) { QFileInfo fi((*pd)); if(fi.isDir()) { dir = (*pd); add_depend = TRUE; if(dir.right(1) != Option::dir_sep) dir += Option::dir_sep; if(Option::projfile::do_recursive) { QDir d(dir); d.setFilter(QDir::Dirs); for(int i = 0; i < (int)d.count(); i++) { if(d[i] != "." && d[i] != "..") dirs.append(dir + d[i] + QDir::separator() + builtin_regex); } } regex = builtin_regex; } else { QString file = (*pd); int s = file.findRev(Option::dir_sep); if(s != -1) dir = file.left(s+1); if(addFile(file)) { add_depend = TRUE; file_count++; } } } else { //regexp regex = (*pd); } if(!regex.isEmpty()) { int s = regex.findRev(Option::dir_sep); if(s != -1) { dir = regex.left(s+1); regex = regex.right(regex.length() - (s+1)); } if(Option::projfile::do_recursive) { QDir d(dir); d.setFilter(QDir::Dirs); for(int i = 0; i < (int)d.count(); i++) { if(d[i] != "." && d[i] != "..") dirs.append(dir + d[i] + QDir::separator() + regex); } } QDir d(dir, regex); for(int i = 0; i < (int)d.count(); i++) { QString file = dir + d[i]; if (addFile(file)) { add_depend = TRUE; file_count++; } } } if(add_depend && !dir.isEmpty() && !v["DEPENDPATH"].contains(dir)) { QFileInfo fi(dir); if(fi.absFilePath() != QDir::currentDirPath()) v["DEPENDPATH"] += fileFixify(dir); } } } if(!file_count) { //shall we try a subdir? QStringList dirs = Option::projfile::project_dirs; if(Option::projfile::do_pwd) dirs.prepend("."); const QString out_file = fileFixify(Option::output.name()); for(QStringList::Iterator pd = dirs.begin(); pd != dirs.end(); pd++) { if(QFile::exists((*pd))) { QString newdir = (*pd); QFileInfo fi(newdir); if(fi.isDir()) { newdir = fileFixify(newdir); QStringList &subdirs = v["SUBDIRS"]; if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && !subdirs.contains(newdir)) { subdirs.append(newdir); } else { QDir d(newdir, "*.pro"); d.setFilter(QDir::Files); for(int i = 0; i < (int)d.count(); i++) { QString nd = newdir; if(nd == ".") nd = ""; else if(!nd.isEmpty() && !nd.endsWith(QString(QChar(QDir::separator())))) nd += QDir::separator(); nd += d[i]; fileFixify(nd); if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd) && !out_file.endsWith(nd)) subdirs.append(nd); } } if(Option::projfile::do_recursive) { QDir d(newdir); d.setFilter(QDir::Dirs); for(int i = 0; i < (int)d.count(); i++) { QString nd = fileFixify(newdir + QDir::separator() + d[i]); if(d[i] != "." && d[i] != ".." && !dirs.contains(nd)) dirs.append(nd); } } } } else { //regexp QString regx = (*pd), dir; int s = regx.findRev(Option::dir_sep); if(s != -1) { dir = regx.left(s+1); regx = regx.right(regx.length() - (s+1)); } QDir d(dir, regx); d.setFilter(QDir::Dirs); QStringList &subdirs = v["SUBDIRS"]; for(int i = 0; i < (int)d.count(); i++) { QString newdir(dir + d[i]); QFileInfo fi(newdir); if(fi.fileName() != "." && fi.fileName() != "..") { newdir = fileFixify(newdir); if(QFile::exists(fi.filePath() + QDir::separator() + fi.fileName() + ".pro") && !subdirs.contains(newdir)) { subdirs.append(newdir); } else { QDir d(newdir, "*.pro"); d.setFilter(QDir::Files); for(int i = 0; i < (int)d.count(); i++) { QString nd = newdir + QDir::separator() + d[i]; fileFixify(nd); if(d[i] != "." && d[i] != ".." && !subdirs.contains(nd)) { if(newdir + d[i] != Option::output_dir + Option::output.name()) subdirs.append(nd); } } } if(Option::projfile::do_recursive && !dirs.contains(newdir)) dirs.append(newdir); } } } } v["TEMPLATE_ASSIGN"] = "subdirs"; return; } QPtrList<MakefileDependDir> deplist; deplist.setAutoDelete(TRUE); { QStringList &d = v["DEPENDPATH"]; for(QStringList::Iterator it = d.begin(); it != d.end(); ++it) { QString r = (*it), l = Option::fixPathToLocalOS((*it)); deplist.append(new MakefileDependDir(r, l)); } } QStringList &h = v["HEADERS"]; bool no_qt_files = TRUE; QString srcs[] = { "SOURCES", "YACCSOURCES", "LEXSOURCES", "INTERFACES", QString::null }; for(int i = 0; !srcs[i].isNull(); i++) { QStringList &l = v[srcs[i]]; for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) { if(generateDependencies(deplist, (*val_it), TRUE)) { QStringList &tmp = findDependencies((*val_it)); if(!tmp.isEmpty()) { for(QStringList::Iterator dep_it = tmp.begin(); dep_it != tmp.end(); ++dep_it) { QString file_dir = (*dep_it).section(Option::dir_sep, 0, -2), file_no_path = (*dep_it).section(Option::dir_sep, -1); if(!file_dir.isEmpty()) { for(MakefileDependDir *mdd = deplist.first(); mdd; mdd = deplist.next()) { if(mdd->local_dir == file_dir && !v["INCLUDEPATH"].contains(mdd->real_dir)) v["INCLUDEPATH"] += mdd->real_dir; } } if(no_qt_files && file_no_path.find(QRegExp("^q[a-z_0-9].h$")) != -1) no_qt_files = FALSE; QString h_ext; for(QStringList::Iterator hit = Option::h_ext.begin(); hit != Option::h_ext.end(); ++hit) { if((*dep_it).endsWith((*hit))) { h_ext = (*hit); break; } } if(!h_ext.isEmpty()) { if((*dep_it).left(1).lower() == "q") { QString qhdr = (*dep_it).lower(); if(file_no_path == "qthread.h") addConfig("thread"); } for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) { QString src((*dep_it).left((*dep_it).length() - h_ext.length()) + (*cppit)); if(QFile::exists(src)) { bool exists = FALSE; QStringList &srcl = v["SOURCES"]; for(QStringList::Iterator src_it = srcl.begin(); src_it != srcl.end(); ++src_it) { if((*src_it).lower() == src.lower()) { exists = TRUE; break; } } if(!exists) srcl.append(src); } } } else if((*dep_it).endsWith(Option::lex_ext) && file_no_path.startsWith(Option::lex_mod)) { addConfig("lex_included"); } if(!h.contains((*dep_it))) { if(generateMocList((*dep_it)) && !findMocDestination((*dep_it)).isEmpty()) h += (*dep_it); } } } } } } if(h.isEmpty()) addConfig("moc", FALSE); //if we find a file that matches an forms it needn't be included in the project QStringList &u = v["INTERFACES"]; QString no_ui[] = { "SOURCES", "HEADERS", QString::null }; { for(int i = 0; !no_ui[i].isNull(); i++) { QStringList &l = v[no_ui[i]]; for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ) { bool found = FALSE; for(QStringList::Iterator ui_it = u.begin(); ui_it != u.end(); ++ui_it) { QString s1 = (*val_it).right((*val_it).length() - ((*val_it).findRev(Option::dir_sep) + 1)); if(s1.findRev('.') != -1) s1 = s1.left(s1.findRev('.')) + Option::ui_ext; QString u1 = (*ui_it).right((*ui_it).length() - ((*ui_it).findRev(Option::dir_sep) + 1)); if(s1 == u1) { found = TRUE; break; } } if(!found && (*val_it).endsWith(Option::cpp_moc_ext)) found = TRUE; if(found) val_it = l.remove(val_it); else ++val_it; } } } }