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 "project.h"
00037 #include "property.h"
00038 #include "option.h"
00039 #include "makefile.h"
00040 #include <qnamespace.h>
00041 #include <qregexp.h>
00042 #include <qdir.h>
00043 #include <stdio.h>
00044 #include <stdlib.h>
00045 #include <ctype.h>
00046 #include <fcntl.h>
00047 #include <sys/types.h>
00048 #include <sys/stat.h>
00049
00050
00051 #undef main
00052 #ifdef Q_OS_MAC
00053
00054 bool qt_resolve_symlinks = FALSE;
00055 #endif
00056
00057 int main(int argc, char **argv)
00058 {
00059
00060 if(!Option::parseCommandLine(argc, argv))
00061 return 666;
00062
00063 QDir sunworkshop42workaround = QDir::current();
00064 QString oldpwd = sunworkshop42workaround.currentDirPath();
00065 #ifdef Q_WS_WIN
00066 if(!(oldpwd.length() == 3 && oldpwd[0].isLetter() && oldpwd.endsWith(":/") ) )
00067 #endif
00068 {
00069 if(oldpwd.right(1) != QString(QChar(QDir::separator())))
00070 oldpwd += QDir::separator();
00071 }
00072 Option::output_dir = oldpwd;
00073
00074 if(Option::output.name() != "-") {
00075 QFileInfo fi(Option::output);
00076 QString dir;
00077 if(fi.isDir()) {
00078 dir = fi.filePath();
00079 } else {
00080 QString tmp_dir = fi.dirPath();
00081 if(!tmp_dir.isEmpty() && QFile::exists(tmp_dir))
00082 dir = tmp_dir;
00083 }
00084 if(!dir.isNull() && dir != ".")
00085 Option::output_dir = dir;
00086 if(QDir::isRelativePath(Option::output_dir))
00087 Option::output_dir.prepend(oldpwd);
00088 }
00089
00090 QMakeProperty prop;
00091 if(Option::qmake_mode == Option::QMAKE_QUERY_PROPERTY || Option::qmake_mode == Option::QMAKE_SET_PROPERTY)
00092 return prop.exec() ? 0 : 101;
00093
00094 QMakeProject proj(&prop);
00095 int exit_val = 0;
00096 QStringList files;
00097 if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
00098 files << "(*hack*)";
00099 else
00100 files = Option::mkfile::project_files;
00101 for(QStringList::Iterator pfile = files.begin(); pfile != files.end(); pfile++) {
00102 if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
00103 Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
00104 QString fn = Option::fixPathToLocalOS((*pfile));
00105
00106
00107 debug_msg(1, "Resetting dir to: %s", oldpwd.latin1());
00108 QDir::setCurrent(oldpwd);
00109 int di = fn.findRev(Option::dir_sep);
00110 if(di != -1) {
00111 debug_msg(1, "Changing dir to: %s", fn.left(di).latin1());
00112 if(!QDir::setCurrent(fn.left(di)))
00113 fprintf(stderr, "Cannot find directory: %s\n", fn.left(di).latin1());
00114 fn = fn.right(fn.length() - di - 1);
00115 }
00116
00117
00118 if(!proj.read(fn, oldpwd)) {
00119 fprintf(stderr, "Error processing project file: %s\n",
00120 fn == "-" ? "(stdin)" : (*pfile).latin1());
00121 exit_val = 2;
00122 continue;
00123 }
00124 if(Option::mkfile::do_preprocess)
00125 continue;
00126
00127
00128 if(!Option::postProcessProject(&proj)) {
00129 fprintf(stderr, "Error post-processing project file: %s",
00130 fn == "-" ? "(stdin)" : (*pfile).latin1());
00131 exit_val = 8;
00132 continue;
00133 }
00134 }
00135
00136 bool using_stdout = FALSE;
00137 MakefileGenerator *mkfile = MakefileGenerator::create(&proj);
00138 if(mkfile && (Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
00139 Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)) {
00140
00141 if(!(Option::output.state() & IO_Open)) {
00142 if(Option::output.name() == "-") {
00143 Option::output.setName("");
00144 Option::output_dir = QDir::currentDirPath();
00145 Option::output.open(IO_WriteOnly | IO_Translate, stdout);
00146 using_stdout = TRUE;
00147 } else {
00148 if(Option::output.name().isEmpty() && Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE)
00149 Option::output.setName(proj.first("QMAKE_MAKEFILE"));
00150 Option::output_dir = oldpwd;
00151 if(!mkfile->openOutput(Option::output)) {
00152 fprintf(stderr, "Failure to open file: %s\n",
00153 Option::output.name().isEmpty() ? "(stdout)" : Option::output.name().latin1());
00154 return 5;
00155 }
00156 }
00157 }
00158 } else {
00159 using_stdout = TRUE;
00160 }
00161 if(mkfile && !mkfile->write()) {
00162 if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
00163 fprintf(stderr, "Unable to generate project file.\n");
00164 else
00165 fprintf(stderr, "Unable to generate makefile for: %s\n", (*pfile).latin1());
00166 if(!using_stdout)
00167 QFile::remove(Option::output.name());
00168 exit_val = 6;
00169 }
00170 delete mkfile;
00171 mkfile = NULL;
00172
00173
00174 if(Option::debug_level) {
00175 QMap<QString, QStringList> &vars = proj.variables();
00176 for(QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it) {
00177 if(!it.key().startsWith(".") && !it.data().isEmpty())
00178 debug_msg(1, "%s === %s", it.key().latin1(), it.data().join(" :: ").latin1());
00179 }
00180 }
00181 }
00182 return exit_val;
00183 }