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

main.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** 
00003 **
00004 ** ???
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 "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 // for Borland, main is defined to qMain which breaks qmake
00051 #undef main
00052 #ifdef Q_OS_MAC
00053 // for qurl
00054 bool qt_resolve_symlinks = FALSE;
00055 #endif
00056 
00057 int main(int argc, char **argv)
00058 {
00059     /* parse command line */
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; //for now this is the output dir
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*)"; //we don't even use files, but we do the for() body once
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             //setup pwd properly
00107             debug_msg(1, "Resetting dir to: %s", oldpwd.latin1());
00108             QDir::setCurrent(oldpwd); //reset the old pwd
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             /* read project.. */
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) //no need to create makefile
00125                 continue;
00126             
00127             /* let Option post-process */
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); //figure out generator
00138         if(mkfile && (Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
00139                       Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)) {
00140             //open output
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; //kind of..
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         /* debugging */
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 }

Generated on Sat Nov 5 16:15:25 2005 for OPIE by  doxygen 1.4.2