| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: makefile.cpp 83 2006-04-15 15:29:11Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of MakefileGenerator class.
|
|---|
| 5 | **
|
|---|
| 6 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
|
|---|
| 7 | **
|
|---|
| 8 | ** This file is part of qmake.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file may be distributed under the terms of the Q Public License
|
|---|
| 11 | ** as defined by Trolltech AS of Norway and appearing in the file
|
|---|
| 12 | ** LICENSE.QPL included in the packaging of this file.
|
|---|
| 13 | **
|
|---|
| 14 | ** This file may be distributed and/or modified under the terms of the
|
|---|
| 15 | ** GNU General Public License version 2 as published by the Free Software
|
|---|
| 16 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 17 | ** packaging of this file.
|
|---|
| 18 | **
|
|---|
| 19 | ** Licensees holding valid Qt Enterprise Edition licenses may use this
|
|---|
| 20 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 21 | ** with the Software.
|
|---|
| 22 | **
|
|---|
| 23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
|---|
| 24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|---|
| 25 | **
|
|---|
| 26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
|---|
| 27 | ** information about Qt Commercial License Agreements.
|
|---|
| 28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
|---|
| 29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
|---|
| 30 | **
|
|---|
| 31 | ** Contact info@trolltech.com if any conditions of this licensing are
|
|---|
| 32 | ** not clear to you.
|
|---|
| 33 | **
|
|---|
| 34 | **********************************************************************/
|
|---|
| 35 |
|
|---|
| 36 | #include "makefile.h"
|
|---|
| 37 | #include "option.h"
|
|---|
| 38 | #include "meta.h"
|
|---|
| 39 | #include <qdir.h>
|
|---|
| 40 | #include <qfile.h>
|
|---|
| 41 | #include <qtextstream.h>
|
|---|
| 42 | #include <qregexp.h>
|
|---|
| 43 | #include <qdict.h>
|
|---|
| 44 | #if defined(Q_OS_UNIX)
|
|---|
| 45 | #include <unistd.h>
|
|---|
| 46 | #else
|
|---|
| 47 | #include <io.h>
|
|---|
| 48 | #endif
|
|---|
| 49 | #include <stdio.h>
|
|---|
| 50 | #include <stdlib.h>
|
|---|
| 51 | #include <time.h>
|
|---|
| 52 | #include <fcntl.h>
|
|---|
| 53 | #include <sys/types.h>
|
|---|
| 54 | #include <sys/stat.h>
|
|---|
| 55 |
|
|---|
| 56 | // Well, Windows doesn't have this, so here's the macro
|
|---|
| 57 | #ifndef S_ISDIR
|
|---|
| 58 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | QString mkdir_p_asstring(const QString &dir)
|
|---|
| 62 | {
|
|---|
| 63 | //@@TODO (dmik): OS/2 cannot create multiple subdirs in mkdir.
|
|---|
| 64 | //@@TODO (dmik): fix it here? (mkdir a\b\c = mkdir a;a\b;a\b\c)
|
|---|
| 65 | QString ret = "@$(CHK_DIR_EXISTS) \"" + dir + "\" ";
|
|---|
| 66 | if(Option::target_mode == Option::TARG_WIN_MODE ||
|
|---|
| 67 | Option::target_mode == Option::TARG_OS2_MODE
|
|---|
| 68 | )
|
|---|
| 69 | ret += "$(MKDIR)";
|
|---|
| 70 | else
|
|---|
| 71 | ret += "|| $(MKDIR)";
|
|---|
| 72 | ret += " \"" + dir + "\"";
|
|---|
| 73 | return ret;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | static bool createDir(const QString& fullPath)
|
|---|
| 77 | {
|
|---|
| 78 | if(QFile::exists(fullPath))
|
|---|
| 79 | return FALSE;
|
|---|
| 80 | QDir dirTmp;
|
|---|
| 81 | bool ret = TRUE;
|
|---|
| 82 | QString pathComponent, tmpPath;
|
|---|
| 83 | QStringList hierarchy = QStringList::split(QString(Option::dir_sep), fullPath, TRUE);
|
|---|
| 84 | for(QStringList::Iterator it = hierarchy.begin(); it != hierarchy.end(); ++it) {
|
|---|
| 85 | pathComponent = *it + QDir::separator();
|
|---|
| 86 | tmpPath += pathComponent;
|
|---|
| 87 | if(!dirTmp.mkdir(tmpPath)) {
|
|---|
| 88 | ret = FALSE;
|
|---|
| 89 | // break;
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 | return ret;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | MakefileGenerator::MakefileGenerator(QMakeProject *p) : init_opath_already(FALSE),
|
|---|
| 97 | init_already(FALSE), moc_aware(FALSE),
|
|---|
| 98 | no_io(FALSE), project(p)
|
|---|
| 99 | {
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | static char *gimme_buffer(off_t s)
|
|---|
| 103 | {
|
|---|
| 104 | static char *big_buffer = NULL;
|
|---|
| 105 | static int big_buffer_size = 0;
|
|---|
| 106 | if(!big_buffer || big_buffer_size < s)
|
|---|
| 107 | big_buffer = (char *)realloc(big_buffer, s);
|
|---|
| 108 | return big_buffer;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | bool
|
|---|
| 112 | MakefileGenerator::generateMocList(const QString &fn_target)
|
|---|
| 113 | {
|
|---|
| 114 | if(!findMocDestination(fn_target).isEmpty())
|
|---|
| 115 | return TRUE;
|
|---|
| 116 |
|
|---|
| 117 | QString fn_local = Option::fixPathToLocalOS(fileFixify(fn_target, QDir::currentDirPath(), Option::output_dir));
|
|---|
| 118 |
|
|---|
| 119 | int file = open(fn_local.latin1(), O_RDONLY);
|
|---|
| 120 | if(file == -1)
|
|---|
| 121 | return FALSE;
|
|---|
| 122 |
|
|---|
| 123 | struct stat fst;
|
|---|
| 124 | if(fstat(file, &fst) || S_ISDIR(fst.st_mode))
|
|---|
| 125 | return FALSE; //shouldn't happen
|
|---|
| 126 | char *big_buffer = gimme_buffer(fst.st_size);
|
|---|
| 127 |
|
|---|
| 128 | int total_size_read;
|
|---|
| 129 | for(int have_read = total_size_read = 0;
|
|---|
| 130 | (have_read = read(file, big_buffer + total_size_read,
|
|---|
| 131 | fst.st_size - total_size_read));
|
|---|
| 132 | total_size_read += have_read);
|
|---|
| 133 | close(file);
|
|---|
| 134 |
|
|---|
| 135 | bool ignore_qobject = FALSE;
|
|---|
| 136 | int line_count = 1;
|
|---|
| 137 | /* qmake ignore Q_OBJECT */
|
|---|
| 138 | #define COMP_LEN 8 //strlen("Q_OBJECT")
|
|---|
| 139 | #define OBJ_LEN 8 //strlen("Q_OBJECT")
|
|---|
| 140 | #define DIS_LEN 10 //strlen("Q_DISPATCH")
|
|---|
| 141 | int x;
|
|---|
| 142 | for(x = 0; x < (total_size_read-COMP_LEN); x++) {
|
|---|
| 143 | if(*(big_buffer + x) == '/') {
|
|---|
| 144 | x++;
|
|---|
| 145 | if(total_size_read >= x) {
|
|---|
| 146 | if(*(big_buffer + x) == '/') { //c++ style comment
|
|---|
| 147 | for( ;x < total_size_read && *(big_buffer + x) != '\n'; x++);
|
|---|
| 148 | line_count++;
|
|---|
| 149 | } else if(*(big_buffer + x) == '*') { //c style comment
|
|---|
| 150 | for( ;x < total_size_read; x++) {
|
|---|
| 151 | if(*(big_buffer + x) == 't' || *(big_buffer + x) == 'q') { //ignore
|
|---|
| 152 | if(total_size_read >= (x + 20)) {
|
|---|
| 153 | if(!strncmp(big_buffer + x + 1, "make ignore Q_OBJECT", 20)) {
|
|---|
| 154 | debug_msg(2, "Mocgen: %s:%d Found \"qmake ignore Q_OBJECT\"",
|
|---|
| 155 | fn_target.latin1(), line_count);
|
|---|
| 156 | x += 20;
|
|---|
| 157 | ignore_qobject = TRUE;
|
|---|
| 158 | }
|
|---|
| 159 | }
|
|---|
| 160 | } else if(*(big_buffer + x) == '*') {
|
|---|
| 161 | if(total_size_read >= (x+1) && *(big_buffer + (x+1)) == '/') {
|
|---|
| 162 | x += 2;
|
|---|
| 163 | break;
|
|---|
| 164 | }
|
|---|
| 165 | } else if(*(big_buffer + x) == '\n') {
|
|---|
| 166 | line_count++;
|
|---|
| 167 | }
|
|---|
| 168 | }
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 | #define SYMBOL_CHAR(x) ((x >= 'a' && x <= 'z') || (x >= 'A' && x <= 'Z') || \
|
|---|
| 173 | (x <= '0' && x >= '9') || x == '_')
|
|---|
| 174 |
|
|---|
| 175 | bool interesting = *(big_buffer+x) == 'Q' && (!strncmp(big_buffer+x, "Q_OBJECT", OBJ_LEN) ||
|
|---|
| 176 | !strncmp(big_buffer+x, "Q_DISPATCH", DIS_LEN));
|
|---|
| 177 | if(interesting) {
|
|---|
| 178 | int len = 0;
|
|---|
| 179 | if(!strncmp(big_buffer+x, "Q_OBJECT", OBJ_LEN)) {
|
|---|
| 180 | if(ignore_qobject) {
|
|---|
| 181 | debug_msg(2, "Mocgen: %s:%d Ignoring Q_OBJECT", fn_target.latin1(), line_count);
|
|---|
| 182 | interesting = FALSE;
|
|---|
| 183 | }
|
|---|
| 184 | len=OBJ_LEN;
|
|---|
| 185 | } else if(!strncmp(big_buffer+x, "Q_DISPATCH", DIS_LEN)) {
|
|---|
| 186 | len=DIS_LEN;
|
|---|
| 187 | }
|
|---|
| 188 | if(SYMBOL_CHAR(*(big_buffer+x+len)))
|
|---|
| 189 | interesting = FALSE;
|
|---|
| 190 | if(interesting) {
|
|---|
| 191 | *(big_buffer+x+len) = '\0';
|
|---|
| 192 | debug_msg(2, "Mocgen: %s:%d Found MOC symbol %s", fn_target.latin1(),
|
|---|
| 193 | line_count, big_buffer+x);
|
|---|
| 194 |
|
|---|
| 195 | int ext_pos = fn_target.findRev('.');
|
|---|
| 196 | int ext_len = fn_target.length() - ext_pos;
|
|---|
| 197 | int dir_pos = fn_target.findRev(Option::dir_sep, ext_pos);
|
|---|
| 198 | QString mocFile;
|
|---|
| 199 | if(!project->isEmpty("MOC_DIR"))
|
|---|
| 200 | mocFile = project->first("MOC_DIR");
|
|---|
| 201 | else if(dir_pos != -1)
|
|---|
| 202 | mocFile = fn_target.left(dir_pos+1);
|
|---|
| 203 |
|
|---|
| 204 | bool cpp_ext = FALSE;
|
|---|
| 205 | for(QStringList::Iterator cppit = Option::cpp_ext.begin();
|
|---|
| 206 | cppit != Option::cpp_ext.end(); ++cppit) {
|
|---|
| 207 | if((cpp_ext = (fn_target.right(ext_len) == (*cppit))))
|
|---|
| 208 | break;
|
|---|
| 209 | }
|
|---|
| 210 | if(cpp_ext) {
|
|---|
| 211 | mocFile += Option::cpp_moc_mod + fn_target.mid(dir_pos+1, ext_pos - dir_pos-1) + Option::cpp_moc_ext;
|
|---|
| 212 | project->variables()["_SRCMOC"].append(mocFile);
|
|---|
| 213 | } else if(project->variables()["HEADERS"].findIndex(fn_target) != -1) {
|
|---|
| 214 | for(QStringList::Iterator hit = Option::h_ext.begin();
|
|---|
| 215 | hit != Option::h_ext.end(); ++hit) {
|
|---|
| 216 | if((fn_target.right(ext_len) == (*hit))) {
|
|---|
| 217 | mocFile += Option::h_moc_mod + fn_target.mid(dir_pos+1, ext_pos - dir_pos-1) +
|
|---|
| 218 | Option::h_moc_ext;
|
|---|
| 219 | logicWarn(mocFile, "SOURCES");
|
|---|
| 220 | project->variables()["_HDRMOC"].append(mocFile);
|
|---|
| 221 | break;
|
|---|
| 222 | }
|
|---|
| 223 | }
|
|---|
| 224 | }
|
|---|
| 225 |
|
|---|
| 226 | if(!mocFile.isEmpty()) {
|
|---|
| 227 | mocFile = Option::fixPathToTargetOS(mocFile);
|
|---|
| 228 | mocablesToMOC[cleanFilePath(fn_target)] = mocFile;
|
|---|
| 229 | mocablesFromMOC[cleanFilePath(mocFile)] = fn_target;
|
|---|
| 230 | }
|
|---|
| 231 | break;
|
|---|
| 232 | }
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | while(x < total_size_read && SYMBOL_CHAR(*(big_buffer+x)))
|
|---|
| 236 | x++;
|
|---|
| 237 | if(*(big_buffer+x) == '\n')
|
|---|
| 238 | line_count++;
|
|---|
| 239 | }
|
|---|
| 240 | #undef OBJ_LEN
|
|---|
| 241 | #undef DIS_LEN
|
|---|
| 242 | return TRUE;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | bool
|
|---|
| 246 | MakefileGenerator::generateDependencies(QPtrList<MakefileDependDir> &dirs, const QString &f, bool recurse)
|
|---|
| 247 | {
|
|---|
| 248 | if(processedDependencies(f))
|
|---|
| 249 | return TRUE;
|
|---|
| 250 | setProcessedDependencies(f, TRUE);
|
|---|
| 251 |
|
|---|
| 252 | QStringList &fndeps = findDependencies(f);
|
|---|
| 253 | QString fn = fileFixify(f, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 254 | fn = Option::fixPathToLocalOS(fn, FALSE);
|
|---|
| 255 | QString fix_env_fn = Option::fixPathToLocalOS(fn);
|
|---|
| 256 | int file = open(fix_env_fn.latin1(), O_RDONLY);
|
|---|
| 257 | if(file == -1)
|
|---|
| 258 | return FALSE;
|
|---|
| 259 | struct stat fst;
|
|---|
| 260 | if(fstat(file, &fst) || S_ISDIR(fst.st_mode))
|
|---|
| 261 | return FALSE; //shouldn't happen
|
|---|
| 262 |
|
|---|
| 263 | QString fndir, fix_env_fndir;
|
|---|
| 264 | int dl = fn.findRev(Option::dir_sep);
|
|---|
| 265 | if(dl != -1)
|
|---|
| 266 | fndir = fn.left(dl+1);
|
|---|
| 267 | dl = fix_env_fn.findRev(Option::dir_sep);
|
|---|
| 268 | if(dl != -1)
|
|---|
| 269 | fix_env_fndir = fix_env_fn.left(dl + 1);
|
|---|
| 270 |
|
|---|
| 271 | int line_count = 1;
|
|---|
| 272 | char *big_buffer = gimme_buffer(fst.st_size);
|
|---|
| 273 |
|
|---|
| 274 | int total_size_read;
|
|---|
| 275 | for(int have_read = total_size_read = 0;
|
|---|
| 276 | (have_read = read(file, big_buffer + total_size_read,
|
|---|
| 277 | fst.st_size - total_size_read));
|
|---|
| 278 | total_size_read += have_read);
|
|---|
| 279 | close(file);
|
|---|
| 280 |
|
|---|
| 281 | bool ui_file = fn.endsWith(Option::ui_ext);
|
|---|
| 282 | for(int x = 0; x < total_size_read; x++) {
|
|---|
| 283 | QStringList *outdeps=&fndeps;
|
|---|
| 284 | QString inc;
|
|---|
| 285 | if(!ui_file) {
|
|---|
| 286 | if(*(big_buffer + x) == '/') {
|
|---|
| 287 | x++;
|
|---|
| 288 | if(total_size_read >= x) {
|
|---|
| 289 | if(*(big_buffer + x) == '/') { //c++ style comment
|
|---|
| 290 | for( ; x < total_size_read && *(big_buffer + x) != '\n'; x++);
|
|---|
| 291 | } else if(*(big_buffer + x) == '*') { //c style comment
|
|---|
| 292 | for( ; x < total_size_read; x++) {
|
|---|
| 293 | if(*(big_buffer + x) == '*') {
|
|---|
| 294 | if(total_size_read >= (x+1) && *(big_buffer + (x+1)) == '/') {
|
|---|
| 295 | x += 2;
|
|---|
| 296 | break;
|
|---|
| 297 | }
|
|---|
| 298 | } else if(*(big_buffer + x) == '\n') {
|
|---|
| 299 | line_count++;
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 | }
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 | if(*(big_buffer + x) == '#') {
|
|---|
| 306 | x++;
|
|---|
| 307 | while(x < total_size_read && //Skip spaces after hash
|
|---|
| 308 | (*(big_buffer+x) == ' ' || *(big_buffer+x) == '\t'))
|
|---|
| 309 | x++;
|
|---|
| 310 | if(total_size_read >= x + 8 && !strncmp(big_buffer + x, "include", 7) &&
|
|---|
| 311 | (*(big_buffer + x + 7) == ' ' || *(big_buffer + x + 7) == '\t' ||
|
|---|
| 312 | *(big_buffer + x + 7) == '<' || *(big_buffer + x + 7) == '"')) {
|
|---|
| 313 | for(x+=7; //skip spaces after keyword
|
|---|
| 314 | x < total_size_read && (*(big_buffer+x) == ' ' || *(big_buffer+x) == '\t');
|
|---|
| 315 | x++);
|
|---|
| 316 | char term = *(big_buffer + x);
|
|---|
| 317 | if(term == '"');
|
|---|
| 318 | else if(term == '<')
|
|---|
| 319 | term = '>';
|
|---|
| 320 | else
|
|---|
| 321 | continue; //wtf?
|
|---|
| 322 | x++;
|
|---|
| 323 |
|
|---|
| 324 | int inc_len;
|
|---|
| 325 | for(inc_len = 0; *(big_buffer + x + inc_len) != term &&
|
|---|
| 326 | *(big_buffer + x + inc_len) != '\n'; inc_len++);
|
|---|
| 327 | *(big_buffer + x + inc_len) = '\0';
|
|---|
| 328 | inc = big_buffer + x;
|
|---|
| 329 | } else if(total_size_read >= x + 14 && !strncmp(big_buffer + x, "qmake_warning ", 14)) {
|
|---|
| 330 | for(x+=14; //skip spaces after keyword
|
|---|
| 331 | x < total_size_read && (*(big_buffer+x) == ' ' || *(big_buffer+x) == '\t');
|
|---|
| 332 | x++);
|
|---|
| 333 | char term = '\n';
|
|---|
| 334 | if(*(big_buffer + x) == '"')
|
|---|
| 335 | term = '"';
|
|---|
| 336 | if(*(big_buffer + x) == '\'')
|
|---|
| 337 | term = '\'';
|
|---|
| 338 | if(term != '\n')
|
|---|
| 339 | x++;
|
|---|
| 340 |
|
|---|
| 341 | int msg_len;
|
|---|
| 342 | for(msg_len = 0; *(big_buffer + x + msg_len) != term &&
|
|---|
| 343 | *(big_buffer + x + msg_len) != '\n'; msg_len++);
|
|---|
| 344 | *(big_buffer + x + msg_len) = '\0';
|
|---|
| 345 | QString msg = big_buffer + x;
|
|---|
| 346 | debug_msg(0, "%s:%d qmake_warning -- %s", fix_env_fn.latin1(),
|
|---|
| 347 | line_count, msg.latin1());
|
|---|
| 348 | *(big_buffer + x + msg_len) = term; //put it back
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|
| 351 | } else if(ui_file) {
|
|---|
| 352 | // skip whitespaces
|
|---|
| 353 | while(x < total_size_read &&
|
|---|
| 354 | (*(big_buffer+x) == ' ' || *(big_buffer+x) == '\t'))
|
|---|
| 355 | x++;
|
|---|
| 356 | if(*(big_buffer + x) == '<') {
|
|---|
| 357 | x++;
|
|---|
| 358 | if(total_size_read >= x + 12 && !strncmp(big_buffer + x, "includehint", 11) &&
|
|---|
| 359 | (*(big_buffer + x + 11) == ' ' || *(big_buffer + x + 11) == '>')) {
|
|---|
| 360 | for(x += 12; *(big_buffer + x) != '>'; x++);
|
|---|
| 361 | int inc_len = 0;
|
|---|
| 362 | for(x += 1 ; *(big_buffer + x + inc_len) != '<'; inc_len++);
|
|---|
| 363 | *(big_buffer + x + inc_len) = '\0';
|
|---|
| 364 | inc = big_buffer + x;
|
|---|
| 365 | } else if(total_size_read >= x + 13 && !strncmp(big_buffer + x, "customwidget", 12) &&
|
|---|
| 366 | (*(big_buffer + x + 12) == ' ' || *(big_buffer + x + 12) == '>')) {
|
|---|
| 367 | for(x += 13; *(big_buffer + x) != '>'; x++); //skip up to >
|
|---|
| 368 | while(x < total_size_read) {
|
|---|
| 369 | for(x++; *(big_buffer + x) != '<'; x++); //skip up to <
|
|---|
| 370 | x++;
|
|---|
| 371 | if(total_size_read >= x + 7 && !strncmp(big_buffer+x, "header", 6) &&
|
|---|
| 372 | (*(big_buffer + x + 6) == ' ' || *(big_buffer + x + 6) == '>')) {
|
|---|
| 373 | for(x += 7; *(big_buffer + x) != '>'; x++); //skip up to >
|
|---|
| 374 | int inc_len = 0;
|
|---|
| 375 | for(x += 1 ; *(big_buffer + x + inc_len) != '<'; inc_len++);
|
|---|
| 376 | *(big_buffer + x + inc_len) = '\0';
|
|---|
| 377 | inc = big_buffer + x;
|
|---|
| 378 | break;
|
|---|
| 379 | } else if(total_size_read >= x + 14 && !strncmp(big_buffer+x, "/customwidget", 13) &&
|
|---|
| 380 | (*(big_buffer + x + 13) == ' ' || *(big_buffer + x + 13) == '>')) {
|
|---|
| 381 | x += 14;
|
|---|
| 382 | break;
|
|---|
| 383 | }
|
|---|
| 384 | }
|
|---|
| 385 | } else if(total_size_read >= x + 8 && !strncmp(big_buffer + x, "include", 7) &&
|
|---|
| 386 | (*(big_buffer + x + 7) == ' ' || *(big_buffer + x + 7) == '>')) {
|
|---|
| 387 | for(x += 8; *(big_buffer + x) != '>'; x++) {
|
|---|
| 388 | if(total_size_read >= x + 9 && *(big_buffer + x) == 'i' &&
|
|---|
| 389 | !strncmp(big_buffer + x, "impldecl", 8)) {
|
|---|
| 390 | for(x += 8; *(big_buffer + x) != '='; x++);
|
|---|
| 391 | if(*(big_buffer + x) != '=')
|
|---|
| 392 | continue;
|
|---|
| 393 | for(x++; *(big_buffer+x) == '\t' || *(big_buffer+x) == ' '; x++);
|
|---|
| 394 | char quote = 0;
|
|---|
| 395 | if(*(big_buffer+x) == '\'' || *(big_buffer+x) == '"') {
|
|---|
| 396 | quote = *(big_buffer + x);
|
|---|
| 397 | x++;
|
|---|
| 398 | }
|
|---|
| 399 | int val_len;
|
|---|
| 400 | for(val_len = 0; TRUE; val_len++) {
|
|---|
| 401 | if(quote) {
|
|---|
| 402 | if(*(big_buffer+x+val_len) == quote)
|
|---|
| 403 | break;
|
|---|
| 404 | } else if(*(big_buffer + x + val_len) == '>' ||
|
|---|
| 405 | *(big_buffer + x + val_len) == ' ') {
|
|---|
| 406 | break;
|
|---|
| 407 | }
|
|---|
| 408 | }
|
|---|
| 409 | char saved = *(big_buffer + x + val_len);
|
|---|
| 410 | *(big_buffer + x + val_len) = '\0';
|
|---|
| 411 | QString where = big_buffer + x;
|
|---|
| 412 | *(big_buffer + x + val_len) = saved;
|
|---|
| 413 | if(where == "in implementation") {
|
|---|
| 414 | QString cpp = fn.left(fn.length() - Option::ui_ext.length()) +
|
|---|
| 415 | Option::cpp_ext.first();
|
|---|
| 416 | outdeps = &findDependencies(cpp);
|
|---|
| 417 | }
|
|---|
| 418 | }
|
|---|
| 419 | }
|
|---|
| 420 | int inc_len = 0;
|
|---|
| 421 | for(x += 1 ; *(big_buffer + x + inc_len) != '<'; inc_len++);
|
|---|
| 422 | *(big_buffer + x + inc_len) = '\0';
|
|---|
| 423 | inc = big_buffer + x;
|
|---|
| 424 | }
|
|---|
| 425 | }
|
|---|
| 426 | }
|
|---|
| 427 |
|
|---|
| 428 | if(!inc.isEmpty()) {
|
|---|
| 429 | bool from_source_dir = TRUE;
|
|---|
| 430 | debug_msg(5, "%s:%d Found dependency to %s", fix_env_fn.latin1(),
|
|---|
| 431 | line_count, inc.latin1());
|
|---|
| 432 | if(!project->isEmpty("SKIP_DEPENDS")) {
|
|---|
| 433 | bool found = FALSE;
|
|---|
| 434 | QStringList &nodeplist = project->values("SKIP_DEPENDS");
|
|---|
| 435 | for(QStringList::Iterator it = nodeplist.begin();
|
|---|
| 436 | it != nodeplist.end(); ++it) {
|
|---|
| 437 | QRegExp regx((*it));
|
|---|
| 438 | if(regx.search(inc) != -1) {
|
|---|
| 439 | found = TRUE;
|
|---|
| 440 | break;
|
|---|
| 441 | }
|
|---|
| 442 | }
|
|---|
| 443 | if(found)
|
|---|
| 444 | continue;
|
|---|
| 445 | }
|
|---|
| 446 | QString fqn;
|
|---|
| 447 | if(project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH") &&
|
|---|
| 448 | !stat(fix_env_fndir + inc, &fst) && !S_ISDIR(fst.st_mode)) {
|
|---|
| 449 | fqn = fndir + inc;
|
|---|
| 450 | goto handle_fqn;
|
|---|
| 451 | } else {
|
|---|
| 452 | if((Option::target_mode == Option::TARG_MAC9_MODE && inc.find(':')) ||
|
|---|
| 453 | ((Option::target_mode == Option::TARG_WIN_MODE ||
|
|---|
| 454 | Option::target_mode == Option::TARG_OS2_MODE) && inc[1] != ':') ||
|
|---|
| 455 | ((Option::target_mode == Option::TARG_UNIX_MODE ||
|
|---|
| 456 | Option::target_mode == Option::TARG_QNX6_MODE ||
|
|---|
| 457 | Option::target_mode == Option::TARG_MACX_MODE) &&
|
|---|
| 458 | inc[0] != '/')) {
|
|---|
| 459 | for(MakefileDependDir *mdd = dirs.first(); mdd; mdd = dirs.next() ) {
|
|---|
| 460 | if(!stat(mdd->local_dir + QDir::separator() + inc, &fst) &&
|
|---|
| 461 | !S_ISDIR(fst.st_mode)) {
|
|---|
| 462 | fqn = mdd->real_dir + QDir::separator() + inc;
|
|---|
| 463 | goto handle_fqn;
|
|---|
| 464 | }
|
|---|
| 465 | }
|
|---|
| 466 | }
|
|---|
| 467 | }
|
|---|
| 468 | if(fqn.isEmpty() && Option::mkfile::do_dep_heuristics) {
|
|---|
| 469 | //these are some hacky heuristics it will try to do on an include
|
|---|
| 470 | //however these can be turned off at runtime, I'm not sure how
|
|---|
| 471 | //reliable these will be, most likely when problems arise turn it off
|
|---|
| 472 | //and see if they go away..
|
|---|
| 473 | if(depHeuristics.contains(inc)) {
|
|---|
| 474 | fqn = depHeuristics[inc];
|
|---|
| 475 | from_source_dir = FALSE;
|
|---|
| 476 | } else if(Option::mkfile::do_dep_heuristics) { //some heuristics..
|
|---|
| 477 | //is it a file from a .ui?
|
|---|
| 478 | QString inc_file = inc.section(Option::dir_sep, -1);
|
|---|
| 479 | int extn = inc_file.findRev('.');
|
|---|
| 480 | if(extn != -1 &&
|
|---|
| 481 | (inc_file.right(inc_file.length()-extn) == Option::cpp_ext.first() ||
|
|---|
| 482 | inc_file.right(inc_file.length()-extn) == Option::h_ext.first())) {
|
|---|
| 483 | QString uip = inc_file.left(extn) + Option::ui_ext;
|
|---|
| 484 | QStringList uil = project->variables()["FORMS"];
|
|---|
| 485 | for(QStringList::Iterator it = uil.begin(); it != uil.end(); ++it) {
|
|---|
| 486 | if((*it).section(Option::dir_sep, -1) == uip) {
|
|---|
| 487 | if(!project->isEmpty("UI_DIR"))
|
|---|
| 488 | fqn = project->first("UI_DIR");
|
|---|
| 489 | else if(!project->isEmpty("UI_HEADERS_DIR"))
|
|---|
| 490 | fqn = project->first("UI_HEADERS_DIR");
|
|---|
| 491 | else
|
|---|
| 492 | fqn = (*it).section(Option::dir_sep, 0, -2);
|
|---|
| 493 | if(!fqn.isEmpty() && !fqn.endsWith(Option::dir_sep))
|
|---|
| 494 | fqn += Option::dir_sep;
|
|---|
| 495 | fqn += inc_file;
|
|---|
| 496 | from_source_dir = FALSE; //uics go in the output_dir (so don't fix them)
|
|---|
| 497 | fqn = fileFixify(fqn, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 498 | goto cache_fqn;
|
|---|
| 499 | }
|
|---|
| 500 | }
|
|---|
| 501 | }
|
|---|
| 502 | if(project->isActiveConfig("lex_included")) { //is this the lex file?
|
|---|
| 503 | QString rhs = Option::lex_mod + Option::cpp_ext.first();
|
|---|
| 504 | if(inc.endsWith(rhs)) {
|
|---|
| 505 | QString lhs = inc.left(inc.length() - rhs.length()) + Option::lex_ext;
|
|---|
| 506 | QStringList ll = project->variables()["LEXSOURCES"];
|
|---|
| 507 | for(QStringList::Iterator it = ll.begin(); it != ll.end(); ++it) {
|
|---|
| 508 | QString s = (*it), d;
|
|---|
| 509 | int slsh = s.findRev(Option::dir_sep);
|
|---|
| 510 | if(slsh != -1) {
|
|---|
| 511 | d = s.left(slsh + 1);
|
|---|
| 512 | s = s.right(s.length() - slsh - 1);
|
|---|
| 513 | }
|
|---|
| 514 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
|
|---|
| 515 | d = project->first("QMAKE_ABSOLUTE_SOURCE_PATH");
|
|---|
| 516 | if(s == lhs) {
|
|---|
| 517 | fqn = d + inc;
|
|---|
| 518 | from_source_dir = FALSE; //uics go in the output_dir (so don't fix them)
|
|---|
| 519 | fqn = fileFixify(fqn, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 520 | goto cache_fqn;
|
|---|
| 521 | }
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 | }
|
|---|
| 525 | { //is it from a .y?
|
|---|
| 526 | QString rhs = Option::yacc_mod + Option::h_ext.first();
|
|---|
| 527 | if(inc.endsWith(rhs)) {
|
|---|
| 528 | QString lhs = inc.left(inc.length() - rhs.length()) + Option::yacc_ext;
|
|---|
| 529 | QStringList yl = project->variables()["YACCSOURCES"];
|
|---|
| 530 | for(QStringList::Iterator it = yl.begin(); it != yl.end(); ++it) {
|
|---|
| 531 | QString s = (*it), d;
|
|---|
| 532 | int slsh = s.findRev(Option::dir_sep);
|
|---|
| 533 | if(slsh != -1) {
|
|---|
| 534 | d = s.left(slsh + 1);
|
|---|
| 535 | s = s.right(s.length() - slsh - 1);
|
|---|
| 536 | }
|
|---|
| 537 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
|
|---|
| 538 | d = project->first("QMAKE_ABSOLUTE_SOURCE_PATH");
|
|---|
| 539 | if(s == lhs) {
|
|---|
| 540 | fqn = d + inc;
|
|---|
| 541 | from_source_dir = FALSE; //uics go in the output_dir (so don't fix them)
|
|---|
| 542 | fqn = fileFixify(fqn, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 543 | goto cache_fqn;
|
|---|
| 544 | }
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 | }
|
|---|
| 548 | if( mocAware() && //is it a moc file?
|
|---|
| 549 | ( inc.endsWith(Option::cpp_ext.first()) || inc.endsWith(Option::cpp_moc_ext) )
|
|---|
| 550 | || ( (Option::cpp_ext.first() != Option::h_moc_ext) && inc.endsWith(Option::h_moc_ext) )) {
|
|---|
| 551 | QString mocs[] = { QString("_HDRMOC"), QString("_SRCMOC"), QString::null };
|
|---|
| 552 | for(int moc = 0; !mocs[moc].isNull(); moc++) {
|
|---|
| 553 | QStringList &l = project->variables()[mocs[moc]];
|
|---|
| 554 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 555 | QString file = Option::fixPathToTargetOS((*it));
|
|---|
| 556 | if(file.section(Option::dir_sep, -(inc.contains('/')+1)) == inc) {
|
|---|
| 557 | fqn = (*it);
|
|---|
| 558 | if(mocs[moc] == "_HDRMOC") {
|
|---|
| 559 | //Since it is include, no need to link it in as well
|
|---|
| 560 | project->variables()["_SRCMOC"].append((*it));
|
|---|
| 561 | l.remove(it);
|
|---|
| 562 | } else if(!findMocSource(fqn).endsWith(fileFixify(fn))) {
|
|---|
| 563 | /* Not really a very good test, but this will at least avoid
|
|---|
| 564 | confusion if it really does happen (since tmake/qmake
|
|---|
| 565 | previously didn't even allow this the test is mostly accurate) */
|
|---|
| 566 | warn_msg(WarnLogic,
|
|---|
| 567 | "Found potential multiple MOC include %s (%s) in '%s'",
|
|---|
| 568 | inc.latin1(), fqn.latin1(), fix_env_fn.latin1());
|
|---|
| 569 | }
|
|---|
| 570 | from_source_dir = FALSE; //mocs go in the output_dir (so don't fix them)
|
|---|
| 571 | goto cache_fqn;
|
|---|
| 572 | }
|
|---|
| 573 | }
|
|---|
| 574 | }
|
|---|
| 575 | }
|
|---|
| 576 | fqn = findDependency(inc); //all else fails..
|
|---|
| 577 | cache_fqn:
|
|---|
| 578 | if(from_source_dir) {
|
|---|
| 579 | fqn = fileFixify(fqn);
|
|---|
| 580 | from_source_dir = FALSE;
|
|---|
| 581 | }
|
|---|
| 582 | depHeuristics.insert(inc, fqn);
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 | handle_fqn:
|
|---|
| 586 | if(fqn.isEmpty()) //I give up
|
|---|
| 587 | continue;
|
|---|
| 588 | fqn = Option::fixPathToTargetOS(fqn, FALSE);
|
|---|
| 589 | if(from_source_dir)
|
|---|
| 590 | fqn = fileFixify(fqn);
|
|---|
| 591 | debug_msg(4, "Resolved dependency of %s to %s", inc.latin1(), fqn.latin1());
|
|---|
| 592 | if(outdeps && outdeps->findIndex(fqn) == -1)
|
|---|
| 593 | outdeps->append(fqn);
|
|---|
| 594 | }
|
|---|
| 595 | //read past new line now..
|
|---|
| 596 | for( ; x < total_size_read && (*(big_buffer + x) != '\n'); x++);
|
|---|
| 597 | line_count++;
|
|---|
| 598 | }
|
|---|
| 599 |
|
|---|
| 600 | if(recurse) {
|
|---|
| 601 | for(QStringList::Iterator fnit = fndeps.begin(); fnit != fndeps.end(); ++fnit) {
|
|---|
| 602 | generateDependencies(dirs, (*fnit), recurse);
|
|---|
| 603 | QStringList &deplist = findDependencies((*fnit));
|
|---|
| 604 | for(QStringList::Iterator it = deplist.begin(); it != deplist.end(); ++it)
|
|---|
| 605 | if(fndeps.findIndex((*it)) == -1 && (*it) != fn)
|
|---|
| 606 | fndeps.append((*it));
|
|---|
| 607 | }
|
|---|
| 608 | }
|
|---|
| 609 | debug_msg(2, "Dependencies: %s -> %s", fn.latin1(), fndeps.join(" :: ").latin1());
|
|---|
| 610 | return TRUE;
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | void
|
|---|
| 614 | MakefileGenerator::initOutPaths()
|
|---|
| 615 | {
|
|---|
| 616 | if(init_opath_already)
|
|---|
| 617 | return;
|
|---|
| 618 | init_opath_already = TRUE;
|
|---|
| 619 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 620 | if(!v.contains("QMAKE_ABSOLUTE_SOURCE_PATH")) {
|
|---|
| 621 | if(Option::mkfile::do_cache && !Option::mkfile::cachefile.isEmpty() &&
|
|---|
| 622 | v.contains("QMAKE_ABSOLUTE_SOURCE_ROOT")) {
|
|---|
| 623 | QString root = v["QMAKE_ABSOLUTE_SOURCE_ROOT"].first();
|
|---|
| 624 | root = Option::fixPathToTargetOS( root );
|
|---|
| 625 | if(!root.isEmpty()) {
|
|---|
| 626 | QFileInfo fi(Option::mkfile::cachefile);
|
|---|
| 627 | if(!fi.convertToAbs()) {
|
|---|
| 628 | QString cache_r = fi.dirPath(), pwd = Option::output_dir;
|
|---|
| 629 | if ( pwd.startsWith(cache_r) && !pwd.startsWith(root) ) {
|
|---|
| 630 | pwd = Option::fixPathToTargetOS(root + pwd.mid(cache_r.length()));
|
|---|
| 631 | if(QFile::exists(pwd))
|
|---|
| 632 | v.insert("QMAKE_ABSOLUTE_SOURCE_PATH", pwd);
|
|---|
| 633 | }
|
|---|
| 634 | }
|
|---|
| 635 | }
|
|---|
| 636 | }
|
|---|
| 637 | }
|
|---|
| 638 | if(!v["QMAKE_ABSOLUTE_SOURCE_PATH"].isEmpty()) {
|
|---|
| 639 | QString &asp = v["QMAKE_ABSOLUTE_SOURCE_PATH"].first();
|
|---|
| 640 | asp = Option::fixPathToTargetOS( asp );
|
|---|
| 641 | if(asp.isEmpty() || asp == Option::output_dir) //if they're the same, why bother?
|
|---|
| 642 | v["QMAKE_ABSOLUTE_SOURCE_PATH"].clear();
|
|---|
| 643 | }
|
|---|
| 644 | QString currentDir = QDir::currentDirPath();
|
|---|
| 645 | QString dirs[] = { QString("OBJECTS_DIR"), QString("MOC_DIR"), QString("UI_HEADERS_DIR"),
|
|---|
| 646 | QString("UI_SOURCES_DIR"), QString("UI_DIR"), QString("DESTDIR"),
|
|---|
| 647 | QString("SUBLIBS_DIR"), QString("DLLDESTDIR"), QString::null };
|
|---|
| 648 | for(int x = 0; dirs[x] != QString::null; x++) {
|
|---|
| 649 | if ( !v[dirs[x]].isEmpty() ) {
|
|---|
| 650 | QString orig_path = v[dirs[x]].first();
|
|---|
| 651 | #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|---|
| 652 | // We don't want to add a separator for DLLDESTDIR on Windows
|
|---|
| 653 | if (!(dirs[x] == "DLLDESTDIR"))
|
|---|
| 654 | #endif
|
|---|
| 655 | {
|
|---|
| 656 | QString &path = v[dirs[x]].first();
|
|---|
| 657 | path = fileFixify(path, Option::output_dir, Option::output_dir);
|
|---|
| 658 | if(path.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 659 | path += Option::dir_sep;
|
|---|
| 660 | }
|
|---|
| 661 | if(noIO())
|
|---|
| 662 | continue;
|
|---|
| 663 |
|
|---|
| 664 | QString path = project->first(dirs[x]); //not to be changed any further
|
|---|
| 665 | path = Option::fixPathToTargetOS(fileFixify(path, QDir::currentDirPath(), Option::output_dir));
|
|---|
| 666 | debug_msg(3, "Fixed output_dir %s (%s) into %s (%s)", dirs[x].latin1(), orig_path.latin1(),
|
|---|
| 667 | v[dirs[x]].join("::").latin1(), path.latin1());
|
|---|
| 668 |
|
|---|
| 669 | QDir d;
|
|---|
| 670 | if(path.startsWith(Option::dir_sep)) {
|
|---|
| 671 | d.cd(Option::dir_sep);
|
|---|
| 672 | path = path.right(path.length() - 1);
|
|---|
| 673 | }
|
|---|
| 674 | #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|---|
| 675 | bool driveExists = TRUE;
|
|---|
| 676 | if ( !QDir::isRelativePath( path ) ) {
|
|---|
| 677 | if ( QFile::exists( path.left( 3 ) ) ) {
|
|---|
| 678 | d.cd( path.left( 3 ) );
|
|---|
| 679 | path = path.right( path.length() - 3 );
|
|---|
| 680 | } else {
|
|---|
| 681 | warn_msg(WarnLogic, "%s: Cannot access drive '%s' (%s)", dirs[x].latin1(),
|
|---|
| 682 | path.left( 3 ).latin1(), path.latin1() );
|
|---|
| 683 | driveExists = FALSE;
|
|---|
| 684 | }
|
|---|
| 685 | }
|
|---|
| 686 | if ( driveExists ) {
|
|---|
| 687 | #endif
|
|---|
| 688 | QStringList subs = QStringList::split(Option::dir_sep, path);
|
|---|
| 689 | for(QStringList::Iterator subit = subs.begin(); subit != subs.end(); ++subit) {
|
|---|
| 690 | if(!d.cd(*subit)) {
|
|---|
| 691 | d.mkdir((*subit));
|
|---|
| 692 | if ( d.exists( (*subit) ) )
|
|---|
| 693 | d.cd((*subit));
|
|---|
| 694 | else {
|
|---|
| 695 | warn_msg(WarnLogic, "%s: Cannot access directory '%s' (%s)", dirs[x].latin1(),
|
|---|
| 696 | (*subit).latin1(), path.latin1() );
|
|---|
| 697 | break;
|
|---|
| 698 | }
|
|---|
| 699 | }
|
|---|
| 700 | }
|
|---|
| 701 | #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|---|
| 702 | }
|
|---|
| 703 | #endif
|
|---|
| 704 | }
|
|---|
| 705 | }
|
|---|
| 706 | if ( !v["DESTDIR"].isEmpty() ) {
|
|---|
| 707 | QDir d(v["DESTDIR"].first());
|
|---|
| 708 | if(Option::fixPathToLocalOS(d.absPath()) == Option::fixPathToLocalOS(Option::output_dir))
|
|---|
| 709 | v.remove("DESTDIR");
|
|---|
| 710 | }
|
|---|
| 711 | QDir::current().cd( currentDir );
|
|---|
| 712 | }
|
|---|
| 713 |
|
|---|
| 714 | void
|
|---|
| 715 | MakefileGenerator::init()
|
|---|
| 716 | {
|
|---|
| 717 | initOutPaths();
|
|---|
| 718 | if(init_already)
|
|---|
| 719 | return;
|
|---|
| 720 | init_already = TRUE;
|
|---|
| 721 |
|
|---|
| 722 | QMap<QString, QStringList> &v = project->variables();
|
|---|
| 723 | QString paths[] = { QString("SOURCES"), QString("FORMS"), QString("YACCSOURCES"), QString("INCLUDEPATH"),
|
|---|
| 724 | QString("HEADERS"), QString("HEADERS_ORIG"), QString("LEXSOURCES"),
|
|---|
| 725 | QString("QMAKE_INTERNAL_INCLUDED_FILES"),
|
|---|
| 726 | QString("PRECOMPILED_HEADER"), QString::null };
|
|---|
| 727 | for(int y = 0; paths[y] != QString::null; y++) {
|
|---|
| 728 | QStringList &l = v[paths[y]];
|
|---|
| 729 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 730 | if ((*it).isEmpty())
|
|---|
| 731 | continue;
|
|---|
| 732 | if(QFile::exists((*it)))
|
|---|
| 733 | (*it) = fileFixify((*it));
|
|---|
| 734 | }
|
|---|
| 735 | }
|
|---|
| 736 |
|
|---|
| 737 | /* get deps and mocables */
|
|---|
| 738 | QDict<void> cache_found_files;
|
|---|
| 739 | QString cache_file(".qmake.internal.cache");
|
|---|
| 740 | if(!project->isEmpty("QMAKE_INTERNAL_CACHE_FILE"))
|
|---|
| 741 | cache_file = Option::fixPathToLocalOS(project->first("QMAKE_INTERNAL_CACHE_FILE"));
|
|---|
| 742 | if(cache_file.find(QDir::separator()) == -1) //guess they know what they are doing..
|
|---|
| 743 | cache_file.prepend(Option::output_dir + QDir::separator());
|
|---|
| 744 | if((Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT ||
|
|---|
| 745 | Option::mkfile::do_deps || Option::mkfile::do_mocs) && !noIO()) {
|
|---|
| 746 | QPtrList<MakefileDependDir> deplist;
|
|---|
| 747 | deplist.setAutoDelete(TRUE);
|
|---|
| 748 | if((Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT || Option::mkfile::do_deps) &&
|
|---|
| 749 | doDepends()) {
|
|---|
| 750 | QStringList incDirs = v["DEPENDPATH"] + v["QMAKE_ABSOLUTE_SOURCE_PATH"];
|
|---|
| 751 | if(project->isActiveConfig("depend_includepath"))
|
|---|
| 752 | incDirs += v["INCLUDEPATH"];
|
|---|
| 753 | for(QStringList::Iterator it = incDirs.begin(); it != incDirs.end(); ++it) {
|
|---|
| 754 | QString r = (*it), l = Option::fixPathToLocalOS((*it));
|
|---|
| 755 | deplist.append(new MakefileDependDir(r.replace("\"",""),
|
|---|
| 756 | l.replace("\"","")));
|
|---|
| 757 | }
|
|---|
| 758 | debug_msg(1, "Dependency Directories: %s", incDirs.join(" :: ").latin1());
|
|---|
| 759 | if(Option::output.name() != "-" && project->isActiveConfig("qmake_cache")) {
|
|---|
| 760 | QFile cachef(cache_file);
|
|---|
| 761 | if(cachef.open(IO_ReadOnly | IO_Translate)) {
|
|---|
| 762 | QFileInfo cachefi(cache_file);
|
|---|
| 763 | debug_msg(2, "Trying internal cache information: %s", cache_file.latin1());
|
|---|
| 764 | QTextStream cachet(&cachef);
|
|---|
| 765 | QString line, file;
|
|---|
| 766 | enum { CacheInfo, CacheDepend, CacheMoc } state = CacheInfo;
|
|---|
| 767 | while (!cachet.eof()) {
|
|---|
| 768 | line = cachet.readLine().stripWhiteSpace();
|
|---|
| 769 | int sep = line.find('=');
|
|---|
| 770 | if(line == "[depend]") {
|
|---|
| 771 | state = CacheDepend;
|
|---|
| 772 | } else if(line == "[mocable]") {
|
|---|
| 773 | state = CacheMoc;
|
|---|
| 774 | } else if(line == "[check]") {
|
|---|
| 775 | state = CacheInfo;
|
|---|
| 776 | } else if(!line.isEmpty() && sep != -1) {
|
|---|
| 777 | file = line.left(sep).stripWhiteSpace();
|
|---|
| 778 | line = line.right(line.length() - sep - 1).stripWhiteSpace();
|
|---|
| 779 | if(state == CacheInfo) {
|
|---|
| 780 | if(file == "QMAKE_CACHE_VERSION") {
|
|---|
| 781 | if(line != qmake_version())
|
|---|
| 782 | break;
|
|---|
| 783 | } else {
|
|---|
| 784 | const QStringList &l = project->variables()[file];
|
|---|
| 785 | if(!l.isEmpty() && !line.isEmpty() && l.join(" ") != line)
|
|---|
| 786 | break;
|
|---|
| 787 | }
|
|---|
| 788 | } else if(state == CacheDepend) {
|
|---|
| 789 | bool found = (bool)cache_found_files[file];
|
|---|
| 790 | QStringList files = QStringList::split(" ", line);
|
|---|
| 791 | if(!found) {
|
|---|
| 792 | QFileInfo fi(fileFixify(file, QDir::currentDirPath(), Option::output_dir));
|
|---|
| 793 | if(fi.exists() && fi.lastModified() < cachefi.lastModified()) {
|
|---|
| 794 | cache_found_files.insert(file, (void *)1);
|
|---|
| 795 | found = TRUE;
|
|---|
| 796 | }
|
|---|
| 797 | }
|
|---|
| 798 | if(found) {
|
|---|
| 799 | for(QStringList::Iterator dep_it = files.begin();
|
|---|
| 800 | dep_it != files.end(); ++dep_it) {
|
|---|
| 801 | if(!cache_found_files[(*dep_it)]) {
|
|---|
| 802 | QFileInfo fi(fileFixify((*dep_it), QDir::currentDirPath(), Option::output_dir));
|
|---|
| 803 | if(fi.exists() &&
|
|---|
| 804 | fi.lastModified() < cachefi.lastModified()) {
|
|---|
| 805 | cache_found_files.insert((*dep_it), (void *)1);
|
|---|
| 806 | } else {
|
|---|
| 807 | found = FALSE;
|
|---|
| 808 | break;
|
|---|
| 809 | }
|
|---|
| 810 | }
|
|---|
| 811 | }
|
|---|
| 812 | if(found) {
|
|---|
| 813 | debug_msg(2, "Dependencies (cached): %s -> %s", file.latin1(),
|
|---|
| 814 | files.join(" :: ").latin1());
|
|---|
| 815 | findDependencies(file) = files;
|
|---|
| 816 | setProcessedDependencies(file, TRUE);
|
|---|
| 817 | }
|
|---|
| 818 | }
|
|---|
| 819 | } else {
|
|---|
| 820 | void *found = cache_found_files[file];
|
|---|
| 821 | if(found != (void *)2) {
|
|---|
| 822 | if(found) {
|
|---|
| 823 | cache_found_files.replace(file, (void *)2);
|
|---|
| 824 | } else {
|
|---|
| 825 | QFileInfo fi(fileFixify(file, QDir::currentDirPath(), Option::output_dir));
|
|---|
| 826 | if(fi.exists() && fi.lastModified() < cachefi.lastModified()) {
|
|---|
| 827 | cache_found_files.insert(file, (void *)2);
|
|---|
| 828 | found = (void*)1;
|
|---|
| 829 | }
|
|---|
| 830 | }
|
|---|
| 831 | }
|
|---|
| 832 | if(found && line != "*qmake_ignore*") {
|
|---|
| 833 | int ext_len = file.length() - file.findRev('.');
|
|---|
| 834 | bool cpp_ext = FALSE;
|
|---|
| 835 | for(QStringList::Iterator cppit = Option::cpp_ext.begin();
|
|---|
| 836 | cppit != Option::cpp_ext.end(); ++cppit) {
|
|---|
| 837 | if((cpp_ext = (file.right(ext_len) == (*cppit))))
|
|---|
| 838 | break;
|
|---|
| 839 | }
|
|---|
| 840 | if(cpp_ext) {
|
|---|
| 841 | project->variables()["_SRCMOC"].append(line);
|
|---|
| 842 | } else if(project->variables()["HEADERS"].findIndex(file) != -1) {
|
|---|
| 843 | for(QStringList::Iterator hit = Option::h_ext.begin();
|
|---|
| 844 | hit != Option::h_ext.end(); ++hit) {
|
|---|
| 845 | if((file.right(ext_len) == (*hit))) {
|
|---|
| 846 | project->variables()["_HDRMOC"].append(line);
|
|---|
| 847 | break;
|
|---|
| 848 | }
|
|---|
| 849 | }
|
|---|
| 850 | }
|
|---|
| 851 | debug_msg(2, "Mocgen (cached): %s -> %s", file.latin1(),
|
|---|
| 852 | line.latin1());
|
|---|
| 853 | mocablesToMOC[file] = line;
|
|---|
| 854 | mocablesFromMOC[line] = file;
|
|---|
| 855 | }
|
|---|
| 856 | }
|
|---|
| 857 | }
|
|---|
| 858 | }
|
|---|
| 859 | cachef.close();
|
|---|
| 860 | }
|
|---|
| 861 | }
|
|---|
| 862 | }
|
|---|
| 863 | if(!noIO()) {
|
|---|
| 864 | QString sources[] = { QString("OBJECTS"), QString("LEXSOURCES"), QString("YACCSOURCES"),
|
|---|
| 865 | QString("HEADERS"), QString("SOURCES"), QString("FORMS"),
|
|---|
| 866 | QString("PRECOMPILED_HEADER"), QString::null };
|
|---|
| 867 | depHeuristics.clear();
|
|---|
| 868 | bool write_cache = FALSE, read_cache = QFile::exists(cache_file);
|
|---|
| 869 | int x;
|
|---|
| 870 | for(x = 0; sources[x] != QString::null; x++) {
|
|---|
| 871 | QStringList vpath, &l = v[sources[x]];
|
|---|
| 872 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 873 | if(!(*val_it).isEmpty()) {
|
|---|
| 874 | QString file = fileFixify((*val_it), QDir::currentDirPath(), Option::output_dir);
|
|---|
| 875 | if(!QFile::exists(file)) {
|
|---|
| 876 | bool found = FALSE;
|
|---|
| 877 | if(QDir::isRelativePath((*val_it))) {
|
|---|
| 878 | if(vpath.isEmpty())
|
|---|
| 879 | vpath = v["VPATH_" + sources[x]] + v["VPATH"] +
|
|---|
| 880 | v["QMAKE_ABSOLUTE_SOURCE_PATH"] + v["DEPENDPATH"];
|
|---|
| 881 |
|
|---|
| 882 | for(QStringList::Iterator vpath_it = vpath.begin();
|
|---|
| 883 | vpath_it != vpath.end(); ++vpath_it) {
|
|---|
| 884 | QString real_dir = Option::fixPathToLocalOS((*vpath_it));
|
|---|
| 885 | if(QFile::exists(real_dir + QDir::separator() + (*val_it))) {
|
|---|
| 886 | QString dir = (*vpath_it);
|
|---|
| 887 | if(dir.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 888 | dir += Option::dir_sep;
|
|---|
| 889 | (*val_it) = fileFixify(dir + (*val_it));
|
|---|
| 890 | found = TRUE;
|
|---|
| 891 | debug_msg(1, "Found file through vpath %s -> %s",
|
|---|
| 892 | file.latin1(), (*val_it).latin1());
|
|---|
| 893 | break;
|
|---|
| 894 | }
|
|---|
| 895 | }
|
|---|
| 896 | }
|
|---|
| 897 | if(!found) {
|
|---|
| 898 | QString dir, regex = (*val_it), real_dir;
|
|---|
| 899 | if(regex.findRev(Option::dir_sep) != -1) {
|
|---|
| 900 | dir = regex.left(regex.findRev(Option::dir_sep) + 1);
|
|---|
| 901 | real_dir = fileFixify(Option::fixPathToLocalOS(dir),
|
|---|
| 902 | QDir::currentDirPath(), Option::output_dir);
|
|---|
| 903 | regex = regex.right(regex.length() - dir.length());
|
|---|
| 904 | }
|
|---|
| 905 | if(real_dir.isEmpty() || QFile::exists(real_dir)) {
|
|---|
| 906 | QDir d(real_dir, regex);
|
|---|
| 907 | if(!d.count()) {
|
|---|
| 908 | debug_msg(1, "%s:%d Failure to find %s in vpath (%s)",
|
|---|
| 909 | __FILE__, __LINE__,
|
|---|
| 910 | (*val_it).latin1(), vpath.join("::").latin1());
|
|---|
| 911 | warn_msg(WarnLogic, "Failure to find: %s", (*val_it).latin1());
|
|---|
| 912 | continue;
|
|---|
| 913 | } else {
|
|---|
| 914 | for(int i = 0; i < (int)d.count(); i++) {
|
|---|
| 915 | QString file = fileFixify(dir + d[i]);
|
|---|
| 916 | if(i == (int)d.count() - 1)
|
|---|
| 917 | (*val_it) = file;
|
|---|
| 918 | else
|
|---|
| 919 | l.insert(val_it, file);
|
|---|
| 920 | }
|
|---|
| 921 | }
|
|---|
| 922 | } else {
|
|---|
| 923 | debug_msg(1, "%s:%d Cannot match %s%c%s, as %s does not exist.",
|
|---|
| 924 | __FILE__, __LINE__,
|
|---|
| 925 | real_dir.latin1(), QDir::separator(), regex.latin1(),
|
|---|
| 926 | real_dir.latin1());
|
|---|
| 927 | warn_msg(WarnLogic, "Failure to find: %s", (*val_it).latin1());
|
|---|
| 928 | }
|
|---|
| 929 | }
|
|---|
| 930 | }
|
|---|
| 931 | }
|
|---|
| 932 | }
|
|---|
| 933 | }
|
|---|
| 934 | for(x = 0; sources[x] != QString::null; x++) {
|
|---|
| 935 | QStringList &l = v[sources[x]];
|
|---|
| 936 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 937 | bool found_cache_moc = FALSE, found_cache_dep = FALSE;
|
|---|
| 938 | if(read_cache && Option::output.name() != "-" &&
|
|---|
| 939 | project->isActiveConfig("qmake_cache")) {
|
|---|
| 940 | if(processedDependencies((*val_it)))
|
|---|
| 941 | found_cache_dep = TRUE;
|
|---|
| 942 | if(cache_found_files[(*val_it)] == (void *)2)
|
|---|
| 943 | found_cache_moc = TRUE;
|
|---|
| 944 | if(!found_cache_moc || !found_cache_dep)
|
|---|
| 945 | write_cache = TRUE;
|
|---|
| 946 | }
|
|---|
| 947 | /* Do moc before dependency checking since some includes can come from
|
|---|
| 948 | moc_*.cpp files */
|
|---|
| 949 | if(found_cache_moc) {
|
|---|
| 950 | QString fixed_file(fileFixify((*val_it), QDir::currentDirPath(), Option::output_dir));
|
|---|
| 951 | QString moc = findMocDestination(fixed_file);
|
|---|
| 952 | if(!moc.isEmpty()) {
|
|---|
| 953 | for(QStringList::Iterator cppit = Option::cpp_ext.begin();
|
|---|
| 954 | cppit != Option::cpp_ext.end(); ++cppit) {
|
|---|
| 955 | if(fixed_file.endsWith((*cppit))) {
|
|---|
| 956 | QStringList &deps = findDependencies(fixed_file);
|
|---|
| 957 | if(!deps.contains(moc))
|
|---|
| 958 | deps.append(moc);
|
|---|
| 959 | break;
|
|---|
| 960 | }
|
|---|
| 961 | }
|
|---|
| 962 | }
|
|---|
| 963 | } else if(mocAware() && (sources[x] == "SOURCES" || sources[x] == "HEADERS") &&
|
|---|
| 964 | (Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT ||
|
|---|
| 965 | Option::mkfile::do_mocs)) {
|
|---|
| 966 | generateMocList((*val_it));
|
|---|
| 967 | }
|
|---|
| 968 | if(!found_cache_dep && sources[x] != "OBJECTS") {
|
|---|
| 969 | debug_msg(5, "Looking for dependencies for %s", (*val_it).latin1());
|
|---|
| 970 | generateDependencies(deplist, (*val_it), doDepends());
|
|---|
| 971 | }
|
|---|
| 972 | }
|
|---|
| 973 | }
|
|---|
| 974 | if(project->isActiveConfig("qmake_cache") && (write_cache || !read_cache)) {
|
|---|
| 975 | QFile cachef(cache_file);
|
|---|
| 976 | if(cachef.open(IO_WriteOnly | IO_Translate)) {
|
|---|
| 977 | debug_msg(2, "Writing internal cache information: %s", cache_file.latin1());
|
|---|
| 978 | QTextStream cachet(&cachef);
|
|---|
| 979 | cachet << "[check]" << "\n"
|
|---|
| 980 | << "QMAKE_CACHE_VERSION = " << qmake_version() << "\n"
|
|---|
| 981 | << "QMAKE_ABSOLUTE_SOURCE_PATH = " << var("QMAKE_ABSOLUTE_SOURCE_PATH") << "\n"
|
|---|
| 982 | << "MOC_DIR = " << var("MOC_DIR") << "\n"
|
|---|
| 983 | << "UI_DIR = " << var("UI_DIR") << "\n"
|
|---|
| 984 | << "UI_HEADERS_DIR = " << var("UI_HEADERS_DIR") << "\n"
|
|---|
| 985 | << "UI_SOURCES_DIR = " << var("UI_SOURCES_DIR") << "\n";
|
|---|
| 986 | cachet << "[depend]" << endl;
|
|---|
| 987 | for(QMap<QString, QStringList>::Iterator it = depends.begin();
|
|---|
| 988 | it != depends.end(); ++it)
|
|---|
| 989 | cachet << dependencyKey(it.key()) << " = " << it.data().join(" ") << endl;
|
|---|
| 990 | cachet << "[mocable]" << endl;
|
|---|
| 991 | QString mc, moc_sources[] = { QString("HEADERS"), QString("SOURCES"), QString::null };
|
|---|
| 992 | for(int x = 0; moc_sources[x] != QString::null; x++) {
|
|---|
| 993 | QStringList &l = v[moc_sources[x]];
|
|---|
| 994 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 995 | QString f = fileFixify((*val_it));
|
|---|
| 996 | if(!f.isEmpty()) {
|
|---|
| 997 | mc = mocablesToMOC[f];
|
|---|
| 998 | if(mc.isEmpty())
|
|---|
| 999 | mc = "*qmake_ignore*";
|
|---|
| 1000 | cachet << f << " = " << mc << endl;
|
|---|
| 1001 | }
|
|---|
| 1002 | }
|
|---|
| 1003 | }
|
|---|
| 1004 | cachef.close();
|
|---|
| 1005 | }
|
|---|
| 1006 | }
|
|---|
| 1007 | }
|
|---|
| 1008 | }
|
|---|
| 1009 | v["OBJECTS"] = createObjectList("SOURCES") + v["OBJECTS"]; // init variables
|
|---|
| 1010 |
|
|---|
| 1011 | //lex files
|
|---|
| 1012 | {
|
|---|
| 1013 | QStringList &impls = v["LEXIMPLS"];
|
|---|
| 1014 | QStringList &l = v["LEXSOURCES"];
|
|---|
| 1015 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1016 | QString dir;
|
|---|
| 1017 | QFileInfo fi((*it));
|
|---|
| 1018 | if(fi.dirPath() != ".")
|
|---|
| 1019 | dir = fi.dirPath() + Option::dir_sep;
|
|---|
| 1020 | dir = fileFixify(dir, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1021 | if(!dir.isEmpty() && dir.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 1022 | dir += Option::dir_sep;
|
|---|
| 1023 | QString impl = dir + fi.baseName(TRUE) + Option::lex_mod + Option::cpp_ext.first();
|
|---|
| 1024 | logicWarn(impl, "SOURCES");
|
|---|
| 1025 | logicWarn(impl, "SOURCES");
|
|---|
| 1026 | impls.append(impl);
|
|---|
| 1027 | if( ! project->isActiveConfig("lex_included")) {
|
|---|
| 1028 | v["SOURCES"].append(impl);
|
|---|
| 1029 | // attribute deps of lex file to impl file
|
|---|
| 1030 | QStringList &lexdeps = findDependencies((*it));
|
|---|
| 1031 | QStringList &impldeps = findDependencies(impl);
|
|---|
| 1032 | for(QStringList::ConstIterator d = lexdeps.begin(); d != lexdeps.end(); ++d) {
|
|---|
| 1033 | if(!impldeps.contains(*d))
|
|---|
| 1034 | impldeps.append(*d);
|
|---|
| 1035 | }
|
|---|
| 1036 | lexdeps.clear();
|
|---|
| 1037 | }
|
|---|
| 1038 | }
|
|---|
| 1039 | if( ! project->isActiveConfig("lex_included"))
|
|---|
| 1040 | v["OBJECTS"] += (v["LEXOBJECTS"] = createObjectList("LEXIMPLS"));
|
|---|
| 1041 | }
|
|---|
| 1042 | //yacc files
|
|---|
| 1043 | {
|
|---|
| 1044 | QStringList &decls = v["YACCCDECLS"], &impls = v["YACCIMPLS"];
|
|---|
| 1045 | QStringList &l = v["YACCSOURCES"];
|
|---|
| 1046 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1047 | QString dir;
|
|---|
| 1048 | QFileInfo fi((*it));
|
|---|
| 1049 | if(fi.dirPath() != ".")
|
|---|
| 1050 | dir = fi.dirPath() + Option::dir_sep;
|
|---|
| 1051 | dir = fileFixify(dir, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1052 | if(!dir.isEmpty() && dir.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 1053 | dir += Option::dir_sep;
|
|---|
| 1054 | QString impl = dir + fi.baseName(TRUE) + Option::yacc_mod + Option::cpp_ext.first();
|
|---|
| 1055 | logicWarn(impl, "SOURCES");
|
|---|
| 1056 | QString decl = dir + fi.baseName(TRUE) + Option::yacc_mod + Option::h_ext.first();
|
|---|
| 1057 | logicWarn(decl, "HEADERS");
|
|---|
| 1058 |
|
|---|
| 1059 | decls.append(decl);
|
|---|
| 1060 | impls.append(impl);
|
|---|
| 1061 | v["SOURCES"].append(impl);
|
|---|
| 1062 | QStringList &impldeps = findDependencies(impl);
|
|---|
| 1063 | impldeps.append(decl);
|
|---|
| 1064 | // attribute deps of yacc file to impl file
|
|---|
| 1065 | QStringList &yaccdeps = findDependencies((*it));
|
|---|
| 1066 | for(QStringList::ConstIterator d = yaccdeps.begin(); d != yaccdeps.end(); ++d) {
|
|---|
| 1067 | if(!impldeps.contains(*d))
|
|---|
| 1068 | impldeps.append(*d);
|
|---|
| 1069 | }
|
|---|
| 1070 | if( project->isActiveConfig("lex_included")) {
|
|---|
| 1071 | // is there a matching lex file ? Transfer its dependencies.
|
|---|
| 1072 | QString lexsrc = fi.baseName(TRUE) + Option::lex_ext;
|
|---|
| 1073 | if(fi.dirPath() != ".")
|
|---|
| 1074 | lexsrc.prepend(fi.dirPath() + Option::dir_sep);
|
|---|
| 1075 | if(v["LEXSOURCES"].findIndex(lexsrc) != -1) {
|
|---|
| 1076 | QString trg = dir + fi.baseName(TRUE) + Option::lex_mod + Option::cpp_ext.first();
|
|---|
| 1077 | impldeps.append(trg);
|
|---|
| 1078 | impldeps += findDependencies(lexsrc);
|
|---|
| 1079 | depends[lexsrc].clear();
|
|---|
| 1080 | }
|
|---|
| 1081 | }
|
|---|
| 1082 | yaccdeps.clear();
|
|---|
| 1083 | }
|
|---|
| 1084 | v["OBJECTS"] += (v["YACCOBJECTS"] = createObjectList("YACCIMPLS"));
|
|---|
| 1085 | }
|
|---|
| 1086 |
|
|---|
| 1087 | //UI files
|
|---|
| 1088 | {
|
|---|
| 1089 | QStringList &includepath = project->variables()["INCLUDEPATH"];
|
|---|
| 1090 | if(!project->isEmpty("UI_DIR"))
|
|---|
| 1091 | includepath.append(project->first("UI_DIR"));
|
|---|
| 1092 | else if(!project->isEmpty("UI_HEADERS_DIR"))
|
|---|
| 1093 | includepath.append(project->first("UI_HEADERS_DIR"));
|
|---|
| 1094 | QStringList &decls = v["UICDECLS"], &impls = v["UICIMPLS"];
|
|---|
| 1095 | QStringList &l = v["FORMS"];
|
|---|
| 1096 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1097 | QString impl, decl;
|
|---|
| 1098 | QFileInfo fi(Option::fixPathToLocalOS((*it)));
|
|---|
| 1099 | if ( !project->isEmpty("UI_DIR") ) {
|
|---|
| 1100 | impl = decl = project->first("UI_DIR");
|
|---|
| 1101 | QString d = fi.dirPath();
|
|---|
| 1102 | if( d == ".")
|
|---|
| 1103 | d = QDir::currentDirPath();
|
|---|
| 1104 | d = fileFixify(d, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1105 | if(!includepath.contains(d))
|
|---|
| 1106 | includepath.append(d);
|
|---|
| 1107 | } else {
|
|---|
| 1108 | if(decl.isEmpty() && !project->isEmpty("UI_HEADERS_DIR"))
|
|---|
| 1109 | decl = project->first("UI_HEADERS_DIR");
|
|---|
| 1110 | if(!decl.isEmpty() || (project->isEmpty("UI_HEADERS_DIR") &&
|
|---|
| 1111 | !project->isEmpty("UI_SOURCES_DIR")) ) {
|
|---|
| 1112 | QString d = fi.dirPath();
|
|---|
| 1113 | if( d == ".")
|
|---|
| 1114 | d = QDir::currentDirPath();
|
|---|
| 1115 | d = fileFixify(d, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1116 | if(includepath.contains(d))
|
|---|
| 1117 | includepath.append(d);
|
|---|
| 1118 | }
|
|---|
| 1119 | if(impl.isEmpty() && !project->isEmpty("UI_SOURCES_DIR"))
|
|---|
| 1120 | impl = project->first("UI_SOURCES_DIR");
|
|---|
| 1121 | if(fi.dirPath() != ".") {
|
|---|
| 1122 | if(impl.isEmpty())
|
|---|
| 1123 | impl = fi.dirPath() + Option::dir_sep;
|
|---|
| 1124 | if(decl.isEmpty())
|
|---|
| 1125 | decl = fi.dirPath() + Option::dir_sep;
|
|---|
| 1126 | }
|
|---|
| 1127 | }
|
|---|
| 1128 | impl = fileFixify(impl, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1129 | if(!impl.isEmpty() && !impl.endsWith(Option::dir_sep))
|
|---|
| 1130 | impl += Option::dir_sep;
|
|---|
| 1131 | impl += fi.baseName(TRUE) + Option::cpp_ext.first();
|
|---|
| 1132 | if(Option::output_dir != QDir::currentDirPath() &&
|
|---|
| 1133 | project->isEmpty("UI_DIR") && project->isEmpty("UI_HEADERS_DIR")) {
|
|---|
| 1134 | QString decl_fixed = fileFixify(decl, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1135 | if(!includepath.contains(decl_fixed))
|
|---|
| 1136 | includepath.append(decl_fixed);
|
|---|
| 1137 | if(!includepath.contains(decl))
|
|---|
| 1138 | project->variables()["INCLUDEPATH"].append(decl);
|
|---|
| 1139 | }
|
|---|
| 1140 | decl = fileFixify(decl, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1141 | if(!decl.isEmpty() && !decl.endsWith(Option::dir_sep))
|
|---|
| 1142 | decl += Option::dir_sep;
|
|---|
| 1143 | decl += fi.baseName(TRUE) + Option::h_ext.first();
|
|---|
| 1144 | logicWarn(impl, "SOURCES");
|
|---|
| 1145 | logicWarn(decl, "HEADERS");
|
|---|
| 1146 | decls.append(decl);
|
|---|
| 1147 | impls.append(impl);
|
|---|
| 1148 | findDependencies(impl).append(decl);
|
|---|
| 1149 |
|
|---|
| 1150 | QString mocable = Option::h_moc_mod + fi.baseName(TRUE) + Option::h_moc_ext;
|
|---|
| 1151 | if(!v["MOC_DIR"].isEmpty())
|
|---|
| 1152 | mocable.prepend(v["MOC_DIR"].first());
|
|---|
| 1153 | else if(fi.dirPath() != ".")
|
|---|
| 1154 | mocable.prepend(fi.dirPath() + Option::dir_sep);
|
|---|
| 1155 | logicWarn(mocable, "SOURCES");
|
|---|
| 1156 | mocablesToMOC[cleanFilePath(decl)] = mocable;
|
|---|
| 1157 | mocablesFromMOC[cleanFilePath(mocable)] = decl;
|
|---|
| 1158 | v["_UIMOC"].append(mocable);
|
|---|
| 1159 | }
|
|---|
| 1160 | v["OBJECTS"] += (v["UICOBJECTS"] = createObjectList("UICDECLS"));
|
|---|
| 1161 | }
|
|---|
| 1162 |
|
|---|
| 1163 | //Translation files
|
|---|
| 1164 | if(!project->isEmpty("TRANSLATIONS")) {
|
|---|
| 1165 | QStringList &trf = project->variables()["TRANSLATIONS"];
|
|---|
| 1166 | for(QStringList::Iterator it = trf.begin(); it != trf.end(); ++it) {
|
|---|
| 1167 | (*it) = Option::fixPathToLocalOS((*it));
|
|---|
| 1168 | }
|
|---|
| 1169 | }
|
|---|
| 1170 |
|
|---|
| 1171 | //Image files
|
|---|
| 1172 | if(!project->isEmpty("IMAGES")) {
|
|---|
| 1173 | if(project->isEmpty("QMAKE_IMAGE_COLLECTION"))
|
|---|
| 1174 | v["QMAKE_IMAGE_COLLECTION"].append("qmake_image_collection" + Option::cpp_ext.first());
|
|---|
| 1175 | QString imgfile = project->first("QMAKE_IMAGE_COLLECTION");
|
|---|
| 1176 | Option::fixPathToTargetOS(imgfile);
|
|---|
| 1177 | if(!project->isEmpty("UI_DIR") || !project->isEmpty("UI_SOURCES_DIR")) {
|
|---|
| 1178 | if(imgfile.find(Option::dir_sep) != -1)
|
|---|
| 1179 | imgfile = imgfile.right(imgfile.findRev(Option::dir_sep) + 1);
|
|---|
| 1180 | imgfile.prepend( (project->isEmpty("UI_DIR") ? project->first("UI_SOURCES_DIR") :
|
|---|
| 1181 | project->first("UI_DIR")) );
|
|---|
| 1182 | v["QMAKE_IMAGE_COLLECTION"] = QStringList(imgfile);
|
|---|
| 1183 | }
|
|---|
| 1184 | logicWarn(imgfile, "SOURCES");
|
|---|
| 1185 | if(!noIO()) {
|
|---|
| 1186 | QStringList &l = v["IMAGES"];
|
|---|
| 1187 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1188 | if(!QFile::exists((*it))) {
|
|---|
| 1189 | warn_msg(WarnLogic, "Failure to open: %s", (*it).latin1());
|
|---|
| 1190 | continue;
|
|---|
| 1191 | }
|
|---|
| 1192 | findDependencies(imgfile).append(fileFixify((*it)));
|
|---|
| 1193 | }
|
|---|
| 1194 | }
|
|---|
| 1195 | v["OBJECTS"] += (v["IMAGEOBJECTS"] = createObjectList("QMAKE_IMAGE_COLLECTION"));
|
|---|
| 1196 | }
|
|---|
| 1197 | if(Option::output_dir != QDir::currentDirPath())
|
|---|
| 1198 | project->variables()["INCLUDEPATH"].append(fileFixify(Option::output_dir, Option::output_dir,
|
|---|
| 1199 | Option::output_dir));
|
|---|
| 1200 |
|
|---|
| 1201 | //moc files
|
|---|
| 1202 | if ( mocAware() ) {
|
|---|
| 1203 | if(!project->isEmpty("MOC_DIR"))
|
|---|
| 1204 | project->variables()["INCLUDEPATH"].append(project->first("MOC_DIR"));
|
|---|
| 1205 | if ( Option::h_moc_ext == Option::cpp_ext.first() )
|
|---|
| 1206 | v["OBJMOC"] = createObjectList("_HDRMOC") + createObjectList("_UIMOC");
|
|---|
| 1207 |
|
|---|
| 1208 | QStringList &l = v["SRCMOC"];
|
|---|
| 1209 | l = v["_HDRMOC"] + v["_UIMOC"] + v["_SRCMOC"];
|
|---|
| 1210 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 1211 | if(!(*val_it).isEmpty())
|
|---|
| 1212 | (*val_it) = Option::fixPathToTargetOS((*val_it), FALSE);
|
|---|
| 1213 | }
|
|---|
| 1214 | }
|
|---|
| 1215 |
|
|---|
| 1216 | QString fixpaths[] = { QString("PRE_TARGETDEPS"), QString("POST_TARGETDEPS"), QString::null };
|
|---|
| 1217 | for(int path = 0; !fixpaths[path].isNull(); path++) {
|
|---|
| 1218 | QStringList &l = v[fixpaths[path]];
|
|---|
| 1219 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 1220 | if(!(*val_it).isEmpty())
|
|---|
| 1221 | (*val_it) = Option::fixPathToTargetOS((*val_it), FALSE);
|
|---|
| 1222 | }
|
|---|
| 1223 | }
|
|---|
| 1224 |
|
|---|
| 1225 | // Make sure the INCLUDEPATH doesn't contain any empty(/null) entries
|
|---|
| 1226 | QStringList &ipl = project->variables()["INCLUDEPATH"];
|
|---|
| 1227 | for(QStringList::Iterator ipl_it = ipl.begin(); ipl_it != ipl.end();) {
|
|---|
| 1228 | if ((*ipl_it).isEmpty())
|
|---|
| 1229 | ipl_it = ipl.remove(ipl_it);
|
|---|
| 1230 | else
|
|---|
| 1231 | ++ipl_it;
|
|---|
| 1232 | }
|
|---|
| 1233 | }
|
|---|
| 1234 |
|
|---|
| 1235 | bool
|
|---|
| 1236 | MakefileGenerator::processPrlFile(QString &file)
|
|---|
| 1237 | {
|
|---|
| 1238 | bool ret = FALSE, try_replace_file=FALSE;
|
|---|
| 1239 | QString meta_file, orig_file = file;
|
|---|
| 1240 | if(QMakeMetaInfo::libExists(file)) {
|
|---|
| 1241 | try_replace_file = TRUE;
|
|---|
| 1242 | meta_file = file;
|
|---|
| 1243 | file = "";
|
|---|
| 1244 | } else {
|
|---|
| 1245 | QString tmp = file;
|
|---|
| 1246 | int ext = tmp.findRev('.');
|
|---|
| 1247 | if(ext != -1)
|
|---|
| 1248 | tmp = tmp.left(ext);
|
|---|
| 1249 | meta_file = tmp;
|
|---|
| 1250 | }
|
|---|
| 1251 | meta_file = fileFixify(meta_file);
|
|---|
| 1252 | #if defined(Q_OS_OS2)
|
|---|
| 1253 | // As far as I understand, this code tries to load "qt-mt" prl if "qt" is
|
|---|
| 1254 | // specified, but not found, and vice versa. First of all, I don't get why
|
|---|
| 1255 | // we should do that (the user has specified he wants a particular single-
|
|---|
| 1256 | // threaded or multi-threadad version using the "thread" CONFIG keyword).
|
|---|
| 1257 | // And more over, the -mt suffix is no more used on OS/2.
|
|---|
| 1258 | #else
|
|---|
| 1259 | if(!QMakeMetaInfo::libExists(fileFixify(meta_file, QDir::currentDirPath(), Option::output_dir)) &&
|
|---|
| 1260 | project->isActiveConfig("qt")) {
|
|---|
| 1261 | QString stem = meta_file, dir, extn;
|
|---|
| 1262 | int slsh = stem.findRev('/'), hadlib = 0;
|
|---|
| 1263 | if(slsh != -1) {
|
|---|
| 1264 | dir = stem.left(slsh + 1);
|
|---|
| 1265 | stem = stem.right(stem.length() - slsh - 1);
|
|---|
| 1266 | }
|
|---|
| 1267 | if(stem.startsWith("lib")) {
|
|---|
| 1268 | hadlib = 1;
|
|---|
| 1269 | stem = stem.right(stem.length() - 3);
|
|---|
| 1270 | }
|
|---|
| 1271 | int dot = stem.find('.');
|
|---|
| 1272 | if(dot != -1) {
|
|---|
| 1273 | extn = stem.right(stem.length() - dot);
|
|---|
| 1274 | stem = stem.left(dot);
|
|---|
| 1275 | }
|
|---|
| 1276 | if(stem == "qt" || stem == "qte" || stem == "qte-mt" || stem == "qt-mt") {
|
|---|
| 1277 | if(stem.endsWith("-mt"))
|
|---|
| 1278 | stem = stem.left(stem.length() - 3); //lose the -mt
|
|---|
| 1279 | else
|
|---|
| 1280 | stem += "-mt"; //try the thread case
|
|---|
| 1281 | meta_file = dir;
|
|---|
| 1282 | if(hadlib)
|
|---|
| 1283 | meta_file += "lib";
|
|---|
| 1284 | meta_file += stem + extn;
|
|---|
| 1285 | try_replace_file = TRUE;
|
|---|
| 1286 | }
|
|---|
| 1287 | }
|
|---|
| 1288 | #endif
|
|---|
| 1289 | QString real_meta_file = Option::fixPathToLocalOS(meta_file);
|
|---|
| 1290 | if(project->variables()["QMAKE_PRL_INTERNAL_FILES"].findIndex(QMakeMetaInfo::findLib(meta_file)) != -1) {
|
|---|
| 1291 | ret = TRUE;
|
|---|
| 1292 | } else if(!meta_file.isEmpty()) {
|
|---|
| 1293 | QString f = fileFixify(real_meta_file, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1294 | if(QMakeMetaInfo::libExists(f)) {
|
|---|
| 1295 | QMakeMetaInfo libinfo;
|
|---|
| 1296 | debug_msg(1, "Processing PRL file: %s", real_meta_file.latin1());
|
|---|
| 1297 | if(!libinfo.readLib(f)) {
|
|---|
| 1298 | fprintf(stderr, "Error processing meta file: %s\n", real_meta_file.latin1());
|
|---|
| 1299 | } else if(project->isActiveConfig("no_read_prl_" + libinfo.type().lower())) {
|
|---|
| 1300 | debug_msg(2, "Ignored meta file %s [%s]", real_meta_file.latin1(), libinfo.type().latin1());
|
|---|
| 1301 | } else {
|
|---|
| 1302 | ret = TRUE;
|
|---|
| 1303 | QMap<QString, QStringList> &vars = libinfo.variables();
|
|---|
| 1304 | for( QMap<QString, QStringList>::Iterator it = vars.begin(); it != vars.end(); ++it)
|
|---|
| 1305 | processPrlVariable(it.key(), it.data());
|
|---|
| 1306 | if(try_replace_file && !libinfo.isEmpty("QMAKE_PRL_TARGET")) {
|
|---|
| 1307 | QString dir;
|
|---|
| 1308 | int slsh = real_meta_file.findRev(Option::dir_sep);
|
|---|
| 1309 | if(slsh != -1)
|
|---|
| 1310 | dir = real_meta_file.left(slsh+1);
|
|---|
| 1311 | file = libinfo.first("QMAKE_PRL_TARGET");
|
|---|
| 1312 | if(QDir::isRelativePath(file))
|
|---|
| 1313 | file.prepend(dir);
|
|---|
| 1314 | }
|
|---|
| 1315 | }
|
|---|
| 1316 | }
|
|---|
| 1317 | if(ret) {
|
|---|
| 1318 | QString mf = QMakeMetaInfo::findLib(meta_file);
|
|---|
| 1319 | project->variables()["QMAKE_PRL_INTERNAL_FILES"].append(mf);
|
|---|
| 1320 | project->variables()["QMAKE_INTERNAL_INCLUDED_FILES"].append(mf);
|
|---|
| 1321 | }
|
|---|
| 1322 | }
|
|---|
| 1323 | if(try_replace_file && file.isEmpty()) {
|
|---|
| 1324 | #if 0
|
|---|
| 1325 | warn_msg(WarnLogic, "Found prl [%s] file with no target [%s]!", meta_file.latin1(),
|
|---|
| 1326 | orig_file.latin1());
|
|---|
| 1327 | #endif
|
|---|
| 1328 | file = orig_file;
|
|---|
| 1329 | }
|
|---|
| 1330 | return ret;
|
|---|
| 1331 | }
|
|---|
| 1332 |
|
|---|
| 1333 | void
|
|---|
| 1334 | MakefileGenerator::processPrlVariable(const QString &var, const QStringList &l)
|
|---|
| 1335 | {
|
|---|
| 1336 | if(var == "QMAKE_PRL_LIBS") {
|
|---|
| 1337 | QString where = "QMAKE_LIBS";
|
|---|
| 1338 | if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
|
|---|
| 1339 | where = project->first("QMAKE_INTERNAL_PRL_LIBS");
|
|---|
| 1340 | QStringList &out = project->variables()[where];
|
|---|
| 1341 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1342 | if( out.findIndex((*it)) == -1)
|
|---|
| 1343 | out.append((*it));
|
|---|
| 1344 | }
|
|---|
| 1345 | } else if(var == "QMAKE_PRL_DEFINES") {
|
|---|
| 1346 | QStringList &out = project->variables()["DEFINES"];
|
|---|
| 1347 | for(QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1348 | if(out.findIndex((*it)) == -1 &&
|
|---|
| 1349 | project->variables()["PRL_EXPORT_DEFINES"].findIndex((*it)) == -1)
|
|---|
| 1350 | out.append((*it));
|
|---|
| 1351 | }
|
|---|
| 1352 | }
|
|---|
| 1353 | }
|
|---|
| 1354 |
|
|---|
| 1355 | void
|
|---|
| 1356 | MakefileGenerator::processPrlFiles()
|
|---|
| 1357 | {
|
|---|
| 1358 | QDict<void> processed;
|
|---|
| 1359 | for(bool ret = FALSE; TRUE; ret = FALSE) {
|
|---|
| 1360 | //read in any prl files included..
|
|---|
| 1361 | QStringList l_out;
|
|---|
| 1362 | QString where = "QMAKE_LIBS";
|
|---|
| 1363 | if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
|
|---|
| 1364 | where = project->first("QMAKE_INTERNAL_PRL_LIBS");
|
|---|
| 1365 | QStringList &l = project->variables()[where];
|
|---|
| 1366 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1367 | QString file = (*it);
|
|---|
| 1368 | if(!processed[file] && processPrlFile(file)) {
|
|---|
| 1369 | processed.insert(file, (void*)1);
|
|---|
| 1370 | ret = TRUE;
|
|---|
| 1371 | }
|
|---|
| 1372 | if(!file.isEmpty())
|
|---|
| 1373 | l_out.append(file);
|
|---|
| 1374 | }
|
|---|
| 1375 | if(ret)
|
|---|
| 1376 | l = l_out;
|
|---|
| 1377 | else
|
|---|
| 1378 | break;
|
|---|
| 1379 | }
|
|---|
| 1380 | }
|
|---|
| 1381 |
|
|---|
| 1382 | void
|
|---|
| 1383 | MakefileGenerator::writePrlFile(QTextStream &t)
|
|---|
| 1384 | {
|
|---|
| 1385 | QString target = project->first("TARGET");
|
|---|
| 1386 | int slsh = target.findRev(Option::dir_sep);
|
|---|
| 1387 | if(slsh != -1)
|
|---|
| 1388 | target = target.right(target.length() - slsh - 1);
|
|---|
| 1389 | QString bdir = Option::output_dir;
|
|---|
| 1390 | if(bdir.isEmpty())
|
|---|
| 1391 | bdir = QDir::currentDirPath();
|
|---|
| 1392 | t << "QMAKE_PRL_BUILD_DIR = " << bdir << endl;
|
|---|
| 1393 |
|
|---|
| 1394 | if(!project->projectFile().isEmpty() && project->projectFile() != "-")
|
|---|
| 1395 | t << "QMAKE_PRO_INPUT = " << project->projectFile().section('/', -1) << endl;
|
|---|
| 1396 |
|
|---|
| 1397 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
|
|---|
| 1398 | t << "QMAKE_PRL_SOURCE_DIR = " << project->first("QMAKE_ABSOLUTE_SOURCE_PATH") << endl;
|
|---|
| 1399 | t << "QMAKE_PRL_TARGET = " << target << endl;
|
|---|
| 1400 | if(!project->isEmpty("PRL_EXPORT_DEFINES"))
|
|---|
| 1401 | t << "QMAKE_PRL_DEFINES = " << project->variables()["PRL_EXPORT_DEFINES"].join(" ") << endl;
|
|---|
| 1402 | if(!project->isEmpty("PRL_EXPORT_CFLAGS"))
|
|---|
| 1403 | t << "QMAKE_PRL_CFLAGS = " << project->variables()["PRL_EXPORT_CFLAGS"].join(" ") << endl;
|
|---|
| 1404 | if(!project->isEmpty("PRL_EXPORT_CXXFLAGS"))
|
|---|
| 1405 | t << "QMAKE_PRL_CXXFLAGS = " << project->variables()["PRL_EXPORT_CXXFLAGS"].join(" ") << endl;
|
|---|
| 1406 | if(!project->isEmpty("CONFIG"))
|
|---|
| 1407 | t << "QMAKE_PRL_CONFIG = " << project->variables()["CONFIG"].join(" ") << endl;
|
|---|
| 1408 | if(!project->isEmpty("VERSION"))
|
|---|
| 1409 | t << "QMAKE_PRL_VERSION = " << project->first("VERSION") << endl;
|
|---|
| 1410 | if(project->isActiveConfig("staticlib") || project->isActiveConfig("explicitlib")) {
|
|---|
| 1411 | QStringList libs;
|
|---|
| 1412 | if(!project->isEmpty("QMAKE_INTERNAL_PRL_LIBS"))
|
|---|
| 1413 | libs = project->variables()["QMAKE_INTERNAL_PRL_LIBS"];
|
|---|
| 1414 | else
|
|---|
| 1415 | libs << "QMAKE_LIBS"; //obvious one
|
|---|
| 1416 | t << "QMAKE_PRL_LIBS = ";
|
|---|
| 1417 | for(QStringList::Iterator it = libs.begin(); it != libs.end(); ++it)
|
|---|
| 1418 | t << project->variables()[(*it)].join(" ") << " ";
|
|---|
| 1419 | t << endl;
|
|---|
| 1420 | }
|
|---|
| 1421 | }
|
|---|
| 1422 |
|
|---|
| 1423 | bool
|
|---|
| 1424 | MakefileGenerator::write()
|
|---|
| 1425 | {
|
|---|
| 1426 | usePlatformDir();
|
|---|
| 1427 | init();
|
|---|
| 1428 | findLibraries();
|
|---|
| 1429 | if((Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || //write prl
|
|---|
| 1430 | Option::qmake_mode == Option::QMAKE_GENERATE_PRL) &&
|
|---|
| 1431 | project->variables()["QMAKE_FAILED_REQUIREMENTS"].isEmpty() &&
|
|---|
| 1432 | project->isActiveConfig("create_prl") && project->first("TEMPLATE") == "lib" &&
|
|---|
| 1433 | !project->isActiveConfig("plugin")) {
|
|---|
| 1434 | QString prl = var("TARGET");
|
|---|
| 1435 | int slsh = prl.findRev(Option::dir_sep);
|
|---|
| 1436 | if(slsh != -1)
|
|---|
| 1437 | prl = prl.right(prl.length() - slsh);
|
|---|
| 1438 | int dot = prl.find('.');
|
|---|
| 1439 | if(dot != -1)
|
|---|
| 1440 | prl = prl.left(dot);
|
|---|
| 1441 | prl += Option::prl_ext;
|
|---|
| 1442 | if(!project->isEmpty("DESTDIR"))
|
|---|
| 1443 | prl.prepend(var("DESTDIR"));
|
|---|
| 1444 | QString local_prl = Option::fixPathToLocalOS(fileFixify(prl, QDir::currentDirPath(), Option::output_dir));
|
|---|
| 1445 | QFile ft(local_prl);
|
|---|
| 1446 | if(ft.open(IO_WriteOnly)) {
|
|---|
| 1447 | project->variables()["ALL_DEPS"].append(prl);
|
|---|
| 1448 | project->variables()["QMAKE_INTERNAL_PRL_FILE"].append(prl);
|
|---|
| 1449 | QTextStream t(&ft);
|
|---|
| 1450 | writePrlFile(t);
|
|---|
| 1451 | ft.close();
|
|---|
| 1452 | }
|
|---|
| 1453 | }
|
|---|
| 1454 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE &&
|
|---|
| 1455 | project->isActiveConfig("link_prl")) //load up prl's'
|
|---|
| 1456 | processPrlFiles();
|
|---|
| 1457 |
|
|---|
| 1458 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE || //write prl file
|
|---|
| 1459 | Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT) {
|
|---|
| 1460 | QTextStream t(&Option::output);
|
|---|
| 1461 | writeMakefile(t);
|
|---|
| 1462 | }
|
|---|
| 1463 | return TRUE;
|
|---|
| 1464 | }
|
|---|
| 1465 |
|
|---|
| 1466 | // Manipulate directories, so it's possible to build
|
|---|
| 1467 | // several cross-platform targets concurrently
|
|---|
| 1468 | void
|
|---|
| 1469 | MakefileGenerator::usePlatformDir()
|
|---|
| 1470 | {
|
|---|
| 1471 | QString pltDir(project->first("QMAKE_PLATFORM_DIR"));
|
|---|
| 1472 | if(pltDir.isEmpty())
|
|---|
| 1473 | return;
|
|---|
| 1474 | char sep = QDir::separator();
|
|---|
| 1475 | QString slashPltDir = sep + pltDir;
|
|---|
| 1476 |
|
|---|
| 1477 | QString filePath = project->first("DESTDIR");
|
|---|
| 1478 | project->variables()["DESTDIR"] = filePath
|
|---|
| 1479 | + (filePath.isEmpty() ? pltDir : slashPltDir);
|
|---|
| 1480 |
|
|---|
| 1481 | filePath = project->first("DLLDESTDIR");
|
|---|
| 1482 | project->variables()["DLLDESTDIR"] = filePath
|
|---|
| 1483 | + (filePath.isEmpty() ? pltDir : slashPltDir);
|
|---|
| 1484 |
|
|---|
| 1485 | filePath = project->first("OBJECTS_DIR");
|
|---|
| 1486 | project->variables()["OBJECTS_DIR"] = filePath
|
|---|
| 1487 | + (filePath.isEmpty() ? pltDir : slashPltDir);
|
|---|
| 1488 |
|
|---|
| 1489 | filePath = project->first("QMAKE_LIBDIR_QT");
|
|---|
| 1490 | project->variables()["QMAKE_LIBDIR_QT"] = filePath
|
|---|
| 1491 | + (filePath.isEmpty() ? pltDir : slashPltDir);
|
|---|
| 1492 |
|
|---|
| 1493 | filePath = project->first("QMAKE_LIBS_QT");
|
|---|
| 1494 | int fpi = filePath.findRev(sep);
|
|---|
| 1495 | if (fpi == -1)
|
|---|
| 1496 | project->variables()["QMAKE_LIBS_QT"].prepend(pltDir + sep);
|
|---|
| 1497 | else
|
|---|
| 1498 | project->variables()["QMAKE_LIBS_QT"] = filePath.left(fpi)
|
|---|
| 1499 | + slashPltDir
|
|---|
| 1500 | + filePath.mid(fpi);
|
|---|
| 1501 |
|
|---|
| 1502 | filePath = project->first("QMAKE_LIBS_QT_THREAD");
|
|---|
| 1503 | fpi = filePath.findRev(sep);
|
|---|
| 1504 | if (fpi == -1)
|
|---|
| 1505 | project->variables()["QMAKE_LIBS_QT_THREAD"].prepend(pltDir + sep);
|
|---|
| 1506 | else
|
|---|
| 1507 | project->variables()["QMAKE_LIBS_QT_THREAD"] = filePath.left(fpi)
|
|---|
| 1508 | + slashPltDir
|
|---|
| 1509 | + filePath.mid(fpi);
|
|---|
| 1510 |
|
|---|
| 1511 | filePath = project->first("QMAKE_LIBS_QT_ENTRY");
|
|---|
| 1512 | fpi = filePath.findRev(sep);
|
|---|
| 1513 | if (fpi == -1)
|
|---|
| 1514 | project->variables()["QMAKE_LIBS_QT_ENTRY"].prepend(pltDir + sep);
|
|---|
| 1515 | else
|
|---|
| 1516 | project->variables()["QMAKE_LIBS_QT_ENTRY"] = filePath.left(fpi)
|
|---|
| 1517 | + slashPltDir
|
|---|
| 1518 | + filePath.mid(fpi);
|
|---|
| 1519 | }
|
|---|
| 1520 |
|
|---|
| 1521 | void
|
|---|
| 1522 | MakefileGenerator::writeObj(QTextStream &t, const QString &obj, const QString &src)
|
|---|
| 1523 | {
|
|---|
| 1524 | QStringList &objl = project->variables()[obj];
|
|---|
| 1525 | QStringList &srcl = project->variables()[src];
|
|---|
| 1526 |
|
|---|
| 1527 | QStringList::Iterator oit = objl.begin();
|
|---|
| 1528 | QStringList::Iterator sit = srcl.begin();
|
|---|
| 1529 | QString stringSrc("$src");
|
|---|
| 1530 | QString stringObj("$obj");
|
|---|
| 1531 | for( ;sit != srcl.end() && oit != objl.end(); oit++, sit++) {
|
|---|
| 1532 | if((*sit).isEmpty())
|
|---|
| 1533 | continue;
|
|---|
| 1534 |
|
|---|
| 1535 | if(!doDepends()) {
|
|---|
| 1536 | QString sdep, odep = (*sit) + " ";
|
|---|
| 1537 | QStringList deps = findDependencies((*sit));
|
|---|
| 1538 | for(QStringList::Iterator dit = deps.begin(); dit != deps.end(); dit++) {
|
|---|
| 1539 | if((*dit).endsWith(Option::cpp_moc_ext))
|
|---|
| 1540 | odep += (*dit) + " ";
|
|---|
| 1541 | else
|
|---|
| 1542 | sdep += (*dit) + " ";
|
|---|
| 1543 | }
|
|---|
| 1544 | t << (*sit) << ": " << sdep << endl
|
|---|
| 1545 | << (*oit) << ": " << odep ;
|
|---|
| 1546 | } else {
|
|---|
| 1547 | t << (*oit) << ": " << (*sit) << " " << findDependencies((*sit)).join(" \\\n\t\t");
|
|---|
| 1548 | }
|
|---|
| 1549 |
|
|---|
| 1550 | QString comp, cimp;
|
|---|
| 1551 | for(QStringList::Iterator cppit = Option::cpp_ext.begin(); cppit != Option::cpp_ext.end(); ++cppit) {
|
|---|
| 1552 | if((*sit).endsWith((*cppit))) {
|
|---|
| 1553 | comp = "QMAKE_RUN_CXX";
|
|---|
| 1554 | cimp = "QMAKE_RUN_CXX_IMP";
|
|---|
| 1555 | break;
|
|---|
| 1556 | }
|
|---|
| 1557 | }
|
|---|
| 1558 | if(comp.isEmpty()) {
|
|---|
| 1559 | comp = "QMAKE_RUN_CC";
|
|---|
| 1560 | cimp = "QMAKE_RUN_CC_IMP";
|
|---|
| 1561 | }
|
|---|
| 1562 | bool use_implicit_rule = !project->isEmpty(cimp) && !project->isActiveConfig("compile_absolute_path");
|
|---|
| 1563 | if(use_implicit_rule) {
|
|---|
| 1564 | if(!project->isEmpty("OBJECTS_DIR")) {
|
|---|
| 1565 | use_implicit_rule = FALSE;
|
|---|
| 1566 | } else {
|
|---|
| 1567 | int dot = (*sit).findRev('.');
|
|---|
| 1568 | if(dot == -1 || ((*sit).left(dot) + Option::obj_ext != (*oit)))
|
|---|
| 1569 | use_implicit_rule = FALSE;
|
|---|
| 1570 | }
|
|---|
| 1571 | }
|
|---|
| 1572 | if (!use_implicit_rule && !project->isEmpty(comp)) {
|
|---|
| 1573 | QString p = var(comp), srcf(*sit);
|
|---|
| 1574 | if(project->isActiveConfig("compile_absolute_path") && QDir::isRelativePath(srcf))
|
|---|
| 1575 | srcf.prepend("$(PWD)" + Option::dir_sep);
|
|---|
| 1576 | p.replace(stringSrc, srcf);
|
|---|
| 1577 | p.replace(stringObj, (*oit));
|
|---|
| 1578 | t << "\n\t" << p;
|
|---|
| 1579 | }
|
|---|
| 1580 | t << endl << endl;
|
|---|
| 1581 | }
|
|---|
| 1582 | }
|
|---|
| 1583 |
|
|---|
| 1584 |
|
|---|
| 1585 | void
|
|---|
| 1586 | MakefileGenerator::writeUicSrc(QTextStream &t, const QString &ui)
|
|---|
| 1587 | {
|
|---|
| 1588 | QStringList &uil = project->variables()[ui];
|
|---|
| 1589 | for(QStringList::Iterator it = uil.begin(); it != uil.end(); it++) {
|
|---|
| 1590 | QString decl, impl;
|
|---|
| 1591 | {
|
|---|
| 1592 | QString tmp = (*it), impl_dir, decl_dir;
|
|---|
| 1593 | decl = tmp.replace(QRegExp("\\" + Option::ui_ext + "$"), Option::h_ext.first());
|
|---|
| 1594 | int dlen = decl.findRev(Option::dir_sep) + 1;
|
|---|
| 1595 | tmp = (*it);
|
|---|
| 1596 | impl = tmp.replace(QRegExp("\\" + Option::ui_ext + "$"), Option::cpp_ext.first());
|
|---|
| 1597 | int ilen = decl.findRev(Option::dir_sep) + 1;
|
|---|
| 1598 | if(!project->isEmpty("UI_DIR")) {
|
|---|
| 1599 | impl_dir = project->first("UI_DIR");
|
|---|
| 1600 | decl = project->first("UI_DIR") + decl.right(decl.length() - dlen);
|
|---|
| 1601 | impl = project->first("UI_DIR") + impl.right(impl.length() - ilen);
|
|---|
| 1602 | } else {
|
|---|
| 1603 | if(!project->isEmpty("UI_HEADERS_DIR")) {
|
|---|
| 1604 | decl_dir = project->first("UI_HEADERS_DIR");
|
|---|
| 1605 | decl = project->first("UI_HEADERS_DIR") + decl.right(decl.length() - dlen);
|
|---|
| 1606 | }
|
|---|
| 1607 | if(!project->isEmpty("UI_SOURCES_DIR")) {
|
|---|
| 1608 | impl_dir = project->first("UI_SOURCES_DIR");
|
|---|
| 1609 | impl = project->first("UI_SOURCES_DIR") + impl.right(impl.length() - ilen);
|
|---|
| 1610 | }
|
|---|
| 1611 | }
|
|---|
| 1612 | impl = fileFixify(impl, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1613 | decl = fileFixify(decl, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1614 | if(decl_dir.isEmpty())
|
|---|
| 1615 | decl_dir = decl.section(Option::dir_sep,0,-2);
|
|---|
| 1616 | if(impl_dir.isEmpty())
|
|---|
| 1617 | impl_dir = impl.section(Option::dir_sep,0,-2);
|
|---|
| 1618 | if (QDir::isRelativePath(impl_dir))
|
|---|
| 1619 | impl_dir.prepend(Option::output_dir + Option::dir_sep);
|
|---|
| 1620 | if (QDir::isRelativePath(decl_dir))
|
|---|
| 1621 | decl_dir.prepend(Option::output_dir + Option::dir_sep);
|
|---|
| 1622 | createDir(impl_dir);
|
|---|
| 1623 | createDir(decl_dir);
|
|---|
| 1624 | }
|
|---|
| 1625 | QStringList deps = findDependencies((*it));
|
|---|
| 1626 | deps.remove(decl); //avoid circular dependencies..
|
|---|
| 1627 | t << decl << ": " << (*it) << " " << deps.join(" \\\n\t\t") << "\n\t"
|
|---|
| 1628 | << "$(UIC) " << (*it) << " -o " << decl << endl << endl;
|
|---|
| 1629 |
|
|---|
| 1630 | QString mildDecl = decl;
|
|---|
| 1631 | int k = mildDecl.findRev(Option::dir_sep);
|
|---|
| 1632 | if ( k != -1 )
|
|---|
| 1633 | mildDecl = mildDecl.mid( k + 1 );
|
|---|
| 1634 | t << impl << ": " << decl << " " << (*it) << " " << deps.join(" \\\n\t\t") << "\n\t"
|
|---|
| 1635 | << "$(UIC)";
|
|---|
| 1636 | t << " " << (*it) << " -i " << mildDecl << " -o " << impl << endl << endl;
|
|---|
| 1637 | }
|
|---|
| 1638 | }
|
|---|
| 1639 |
|
|---|
| 1640 |
|
|---|
| 1641 | void
|
|---|
| 1642 | MakefileGenerator::writeMocObj(QTextStream &t, const QString &obj, const QString &src)
|
|---|
| 1643 | {
|
|---|
| 1644 | QStringList &objl = project->variables()[obj],
|
|---|
| 1645 | &srcl = project->variables()[src];
|
|---|
| 1646 | QStringList::Iterator oit = objl.begin(), sit = srcl.begin();
|
|---|
| 1647 | QString stringSrc("$src"), stringObj("$obj");
|
|---|
| 1648 | for( ;sit != srcl.end() && oit != objl.end(); oit++, sit++) {
|
|---|
| 1649 | QString hdr = findMocSource((*sit));
|
|---|
| 1650 | t << (*oit) << ": "
|
|---|
| 1651 | << (*sit) << " " << findDependencies((*sit)).join(" \\\n\t\t") << " "
|
|---|
| 1652 | << hdr << " " << findDependencies(hdr).join(" \\\n\t\t");
|
|---|
| 1653 | bool use_implicit_rule = !project->isEmpty("QMAKE_RUN_CXX_IMP") && !project->isActiveConfig("compile_absolute_path");
|
|---|
| 1654 | if(use_implicit_rule) {
|
|---|
| 1655 | if(!project->isEmpty("OBJECTS_DIR") || !project->isEmpty("MOC_DIR")) {
|
|---|
| 1656 | use_implicit_rule = FALSE;
|
|---|
| 1657 | } else {
|
|---|
| 1658 | int dot = (*sit).findRev('.');
|
|---|
| 1659 | if(dot == -1 || ((*sit).left(dot) + Option::obj_ext != (*oit)))
|
|---|
| 1660 | use_implicit_rule = FALSE;
|
|---|
| 1661 | }
|
|---|
| 1662 | }
|
|---|
| 1663 | if (!use_implicit_rule && !project->isEmpty("QMAKE_RUN_CXX")) {
|
|---|
| 1664 | QString p = var("QMAKE_RUN_CXX"), srcf(*sit);
|
|---|
| 1665 | if(project->isActiveConfig("compile_absolute_path") && QDir::isRelativePath(srcf))
|
|---|
| 1666 | srcf.prepend("$(PWD)" + Option::dir_sep);
|
|---|
| 1667 | p.replace(stringSrc, srcf);
|
|---|
| 1668 | p.replace(stringObj, (*oit));
|
|---|
| 1669 | t << "\n\t" << p;
|
|---|
| 1670 | }
|
|---|
| 1671 | t << endl << endl;
|
|---|
| 1672 | }
|
|---|
| 1673 | }
|
|---|
| 1674 |
|
|---|
| 1675 |
|
|---|
| 1676 | void
|
|---|
| 1677 | MakefileGenerator::writeMocSrc(QTextStream &t, const QString &src)
|
|---|
| 1678 | {
|
|---|
| 1679 | QStringList &l = project->variables()[src];
|
|---|
| 1680 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1681 | QString m = Option::fixPathToTargetOS(findMocDestination(*it));
|
|---|
| 1682 | if ( !m.isEmpty()) {
|
|---|
| 1683 | QString deps;
|
|---|
| 1684 | if(!project->isActiveConfig("no_mocdepend"))
|
|---|
| 1685 | deps += "$(MOC) ";
|
|---|
| 1686 | deps += (*it);
|
|---|
| 1687 | t << m << ": " << deps << "\n\t"
|
|---|
| 1688 | << "$(MOC)";
|
|---|
| 1689 | t << " " << (*it) << " -o " << m << endl << endl;
|
|---|
| 1690 | }
|
|---|
| 1691 | }
|
|---|
| 1692 | }
|
|---|
| 1693 |
|
|---|
| 1694 | void
|
|---|
| 1695 | MakefileGenerator::writeYaccSrc(QTextStream &t, const QString &src)
|
|---|
| 1696 | {
|
|---|
| 1697 | QStringList &l = project->variables()[src];
|
|---|
| 1698 | if(project->isActiveConfig("yacc_no_name_mangle") && l.count() > 1)
|
|---|
| 1699 | warn_msg(WarnLogic, "yacc_no_name_mangle specified, but multiple parsers expected."
|
|---|
| 1700 | "This can lead to link problems.\n");
|
|---|
| 1701 | QString default_out_h = "y.tab.h", default_out_c = "y.tab.c";
|
|---|
| 1702 | if(!project->isEmpty("QMAKE_YACC_HEADER"))
|
|---|
| 1703 | default_out_h = project->first("QMAKE_YACC_HEADER");
|
|---|
| 1704 | if(!project->isEmpty("QMAKE_YACC_SOURCE"))
|
|---|
| 1705 | default_out_c = project->first("QMAKE_YACC_SOURCE");
|
|---|
| 1706 | QString stringBase("$base");
|
|---|
| 1707 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1708 | QFileInfo fi((*it));
|
|---|
| 1709 | QString dir;
|
|---|
| 1710 | if(fi.dirPath() != ".")
|
|---|
| 1711 | dir = fi.dirPath() + Option::dir_sep;
|
|---|
| 1712 | dir = fileFixify(dir, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1713 | if(!dir.isEmpty() && dir.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 1714 | dir += Option::dir_sep;
|
|---|
| 1715 |
|
|---|
| 1716 | QString impl = dir + fi.baseName(TRUE) + Option::yacc_mod + Option::cpp_ext.first();
|
|---|
| 1717 | QString decl = dir + fi.baseName(TRUE) + Option::yacc_mod + Option::h_ext.first();
|
|---|
| 1718 |
|
|---|
| 1719 | QString yaccflags = "$(YACCFLAGS)", mangle = "y";
|
|---|
| 1720 | if(!project->isActiveConfig("yacc_no_name_mangle")) {
|
|---|
| 1721 | mangle = fi.baseName(TRUE);
|
|---|
| 1722 | if(!project->isEmpty("QMAKE_YACCFLAGS_MANGLE"))
|
|---|
| 1723 | yaccflags += " " + var("QMAKE_YACCFLAGS_MANGLE").replace(stringBase, mangle);
|
|---|
| 1724 | else
|
|---|
| 1725 | yaccflags += " -p " + mangle;
|
|---|
| 1726 | }
|
|---|
| 1727 | QString out_h = default_out_h, out_c = default_out_c;
|
|---|
| 1728 | if(!mangle.isEmpty()) {
|
|---|
| 1729 | out_h.replace(stringBase, mangle);
|
|---|
| 1730 | out_c.replace(stringBase, mangle);
|
|---|
| 1731 | }
|
|---|
| 1732 |
|
|---|
| 1733 | t << impl << ": " << (*it) << "\n\t"
|
|---|
| 1734 | << "$(YACC) " << yaccflags << " " << (*it) << "\n\t"
|
|---|
| 1735 | << "-$(DEL_FILE) " << impl << " " << decl << "\n\t"
|
|---|
| 1736 | << "-$(MOVE) " << out_h << " " << decl << "\n\t"
|
|---|
| 1737 | << "-$(MOVE) " << out_c << " " << impl << endl << endl;
|
|---|
| 1738 | t << decl << ": " << impl << endl << endl;
|
|---|
| 1739 | }
|
|---|
| 1740 | }
|
|---|
| 1741 |
|
|---|
| 1742 | void
|
|---|
| 1743 | MakefileGenerator::writeLexSrc(QTextStream &t, const QString &src)
|
|---|
| 1744 | {
|
|---|
| 1745 | QStringList &l = project->variables()[src];
|
|---|
| 1746 | if(project->isActiveConfig("yacc_no_name_mangle") && l.count() > 1)
|
|---|
| 1747 | warn_msg(WarnLogic, "yacc_no_name_mangle specified, but multiple parsers expected.\n"
|
|---|
| 1748 | "This can lead to link problems.\n");
|
|---|
| 1749 | QString default_out_c = "lex.$base.c";
|
|---|
| 1750 | if(!project->isEmpty("QMAKE_LEX_SOURCE"))
|
|---|
| 1751 | default_out_c = project->first("QMAKE_LEX_SOURCE");
|
|---|
| 1752 | QString stringBase("$base");
|
|---|
| 1753 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1754 | QFileInfo fi((*it));
|
|---|
| 1755 | QString dir;
|
|---|
| 1756 | if(fi.dirPath() != ".")
|
|---|
| 1757 | dir = fi.dirPath() + Option::dir_sep;
|
|---|
| 1758 | dir = fileFixify(dir, QDir::currentDirPath(), Option::output_dir);
|
|---|
| 1759 | if(!dir.isEmpty() && dir.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 1760 | dir += Option::dir_sep;
|
|---|
| 1761 | QString impl = dir + fi.baseName(TRUE) + Option::lex_mod + Option::cpp_ext.first();
|
|---|
| 1762 |
|
|---|
| 1763 | QString lexflags = "$(LEXFLAGS)", stub="yy";
|
|---|
| 1764 | if(!project->isActiveConfig("yacc_no_name_mangle")) {
|
|---|
| 1765 | stub = fi.baseName(TRUE);
|
|---|
| 1766 | lexflags += " -P" + stub;
|
|---|
| 1767 | }
|
|---|
| 1768 | QString out_c = default_out_c;
|
|---|
| 1769 | if(!stub.isEmpty())
|
|---|
| 1770 | out_c.replace(stringBase, stub);
|
|---|
| 1771 |
|
|---|
| 1772 | t << impl << ": " << (*it) << " " << findDependencies((*it)).join(" \\\n\t\t") << "\n\t"
|
|---|
| 1773 | << ( "$(LEX) " + lexflags + " " ) << (*it) << "\n\t"
|
|---|
| 1774 | << "-$(DEL_FILE) " << impl << " " << "\n\t"
|
|---|
| 1775 | << "-$(MOVE) " << out_c << " " << impl << endl << endl;
|
|---|
| 1776 | }
|
|---|
| 1777 | }
|
|---|
| 1778 |
|
|---|
| 1779 | void
|
|---|
| 1780 | MakefileGenerator::writeImageObj(QTextStream &t, const QString &obj)
|
|---|
| 1781 | {
|
|---|
| 1782 | QStringList &objl = project->variables()[obj];
|
|---|
| 1783 | QString stringSrc("$src");
|
|---|
| 1784 | QString stringObj("$obj");
|
|---|
| 1785 |
|
|---|
| 1786 | QString uidir;
|
|---|
| 1787 | for(QStringList::Iterator oit = objl.begin(); oit != objl.end(); oit++) {
|
|---|
| 1788 | QString src(project->first("QMAKE_IMAGE_COLLECTION"));
|
|---|
| 1789 | t << (*oit) << ": " << src;
|
|---|
| 1790 | bool use_implicit_rule = !project->isEmpty("QMAKE_RUN_CXX_IMP") && !project->isActiveConfig("compile_absolute_path");
|
|---|
| 1791 | if(use_implicit_rule) {
|
|---|
| 1792 | if(!project->isEmpty("OBJECTS_DIR") || !project->isEmpty("UI_DIR") || !project->isEmpty("UI_SOURCES_DIR")) {
|
|---|
| 1793 | use_implicit_rule = FALSE;
|
|---|
| 1794 | } else {
|
|---|
| 1795 | int dot = src.findRev('.');
|
|---|
| 1796 | if(dot == -1 || (src.left(dot) + Option::obj_ext != (*oit)))
|
|---|
| 1797 | use_implicit_rule = FALSE;
|
|---|
| 1798 | }
|
|---|
| 1799 | }
|
|---|
| 1800 | if(!use_implicit_rule && !project->isEmpty("QMAKE_RUN_CXX")) {
|
|---|
| 1801 | QString p = var("QMAKE_RUN_CXX"), srcf(src);
|
|---|
| 1802 | if(project->isActiveConfig("compile_absolute_path") && QDir::isRelativePath(srcf))
|
|---|
| 1803 | srcf.prepend("$(PWD)" + Option::dir_sep);
|
|---|
| 1804 | p.replace(stringSrc, srcf);
|
|---|
| 1805 | p.replace(stringObj, (*oit));
|
|---|
| 1806 | t << "\n\t" << p;
|
|---|
| 1807 | }
|
|---|
| 1808 | t << endl << endl;
|
|---|
| 1809 | }
|
|---|
| 1810 | }
|
|---|
| 1811 |
|
|---|
| 1812 |
|
|---|
| 1813 | void
|
|---|
| 1814 | MakefileGenerator::writeImageSrc(QTextStream &t, const QString &src)
|
|---|
| 1815 | {
|
|---|
| 1816 | QStringList &l = project->variables()[src];
|
|---|
| 1817 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1818 | QString gen = project->first("MAKEFILE_GENERATOR");
|
|---|
| 1819 | if ( gen == "MSVC" ) {
|
|---|
| 1820 | t << (*it) << ": " << findDependencies((*it)).join(" \\\n\t\t") << "\n\t"
|
|---|
| 1821 | << "$(UIC) -o " << (*it) << " -embed " << project->first("QMAKE_ORIG_TARGET")
|
|---|
| 1822 | << " -f <<\n" << findDependencies((*it)).join(" ") << "\n<<" << endl << endl;
|
|---|
| 1823 | } else if ( gen == "BMAKE" ) {
|
|---|
| 1824 | t << (*it) << ": " << findDependencies((*it)).join(" \\\n\t\t") << "\n\t"
|
|---|
| 1825 | << "$(UIC) " << " -embed " << project->first("QMAKE_ORIG_TARGET")
|
|---|
| 1826 | << " -f &&|\n" << findDependencies((*it)).join(" ") << "\n| -o " << (*it) << endl << endl;
|
|---|
| 1827 | } else {
|
|---|
| 1828 | t << (*it) << ": " << findDependencies((*it)).join(" \\\n\t\t") << "\n\t"
|
|---|
| 1829 | << "$(UIC) " << " -embed " << project->first("QMAKE_ORIG_TARGET")
|
|---|
| 1830 | << " " << findDependencies((*it)).join(" ") << " -o " << (*it) << endl << endl;
|
|---|
| 1831 | }
|
|---|
| 1832 | }
|
|---|
| 1833 | }
|
|---|
| 1834 |
|
|---|
| 1835 |
|
|---|
| 1836 | void
|
|---|
| 1837 | MakefileGenerator::writeInstalls(QTextStream &t, const QString &installs)
|
|---|
| 1838 | {
|
|---|
| 1839 | QString all_installs, all_uninstalls;
|
|---|
| 1840 | QStringList &l = project->variables()[installs];
|
|---|
| 1841 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 1842 | QString pvar = (*it) + ".path";
|
|---|
| 1843 | if(project->variables()[(*it) + ".CONFIG"].findIndex("no_path") == -1 &&
|
|---|
| 1844 | project->variables()[pvar].isEmpty()) {
|
|---|
| 1845 | warn_msg(WarnLogic, "%s is not defined: install target not created\n", pvar.latin1());
|
|---|
| 1846 | continue;
|
|---|
| 1847 | }
|
|---|
| 1848 |
|
|---|
| 1849 | bool do_default = TRUE;
|
|---|
| 1850 | const QString root = "$(INSTALL_ROOT)";
|
|---|
| 1851 | QString target, dst= fileFixify(project->variables()[pvar].first());
|
|---|
| 1852 | if(dst.right(1) != Option::dir_sep)
|
|---|
| 1853 | dst += Option::dir_sep;
|
|---|
| 1854 | QStringList tmp, uninst = project->variables()[(*it) + ".uninstall"];
|
|---|
| 1855 | //other
|
|---|
| 1856 | tmp = project->variables()[(*it) + ".extra"];
|
|---|
| 1857 | if(tmp.isEmpty())
|
|---|
| 1858 | tmp = project->variables()[(*it) + ".commands"]; //to allow compatible name
|
|---|
| 1859 | if(!tmp.isEmpty()) {
|
|---|
| 1860 | do_default = FALSE;
|
|---|
| 1861 | if(!target.isEmpty())
|
|---|
| 1862 | target += "\n\t";
|
|---|
| 1863 | target += tmp.join(" ");
|
|---|
| 1864 | }
|
|---|
| 1865 | //masks
|
|---|
| 1866 | tmp = project->variables()[(*it) + ".files"];
|
|---|
| 1867 | if(!tmp.isEmpty()) {
|
|---|
| 1868 | if(!target.isEmpty())
|
|---|
| 1869 | target += "\n";
|
|---|
| 1870 | do_default = FALSE;
|
|---|
| 1871 | for(QStringList::Iterator wild_it = tmp.begin(); wild_it != tmp.end(); ++wild_it) {
|
|---|
| 1872 | QString wild = Option::fixPathToLocalOS((*wild_it), FALSE), wild_var = fileFixify(wild);
|
|---|
| 1873 | QString dirstr = QDir::currentDirPath(), filestr = wild;
|
|---|
| 1874 | int slsh = filestr.findRev(Option::dir_sep);
|
|---|
| 1875 | if(slsh != -1) {
|
|---|
| 1876 | dirstr = filestr.left(slsh+1);
|
|---|
| 1877 | filestr = filestr.right(filestr.length() - slsh - 1);
|
|---|
| 1878 | }
|
|---|
| 1879 | if(dirstr.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 1880 | dirstr += Option::dir_sep;
|
|---|
| 1881 | if(QFile::exists(wild)) { //real file
|
|---|
| 1882 | QString file = wild;
|
|---|
| 1883 | QFileInfo fi(wild);
|
|---|
| 1884 | if(!target.isEmpty())
|
|---|
| 1885 | target += "\t";
|
|---|
| 1886 | QString cmd = QString(fi.isDir() ? "-$(INSTALL_DIR)" : "-$(INSTALL_FILE)") + " \"" +
|
|---|
| 1887 | Option::fixPathToTargetOS(fileFixify(wild, QString::null,
|
|---|
| 1888 | QString::null, FALSE, FALSE), FALSE) +
|
|---|
| 1889 | "\" \"" + root + dst + "\"\n";
|
|---|
| 1890 | target += cmd;
|
|---|
| 1891 | if(!project->isActiveConfig("debug") &&
|
|---|
| 1892 | !fi.isDir() && fi.isExecutable() && !project->isEmpty("QMAKE_STRIP"))
|
|---|
| 1893 | target += QString("\t-") + var("QMAKE_STRIP") + " \"" +
|
|---|
| 1894 | root + fileFixify(dst + filestr, QString::null, QString::null, FALSE, FALSE) +
|
|---|
| 1895 | "\"\n";
|
|---|
| 1896 | if(!uninst.isEmpty())
|
|---|
| 1897 | uninst.append("\n\t");
|
|---|
| 1898 | uninst.append(
|
|---|
| 1899 | #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|---|
| 1900 | QString("-$(DEL_FILE)")
|
|---|
| 1901 | #else
|
|---|
| 1902 | QString("-$(DEL_FILE) -r")
|
|---|
| 1903 | #endif
|
|---|
| 1904 | + " \"" + root + fileFixify(dst + filestr, QString::null, QString::null, FALSE, FALSE) + "\"");
|
|---|
| 1905 | continue;
|
|---|
| 1906 | }
|
|---|
| 1907 | fixEnvVariables(dirstr);
|
|---|
| 1908 | QDir dir(dirstr, filestr); //wild
|
|---|
| 1909 | for(uint x = 0; x < dir.count(); x++) {
|
|---|
| 1910 | QString file = dir[x];
|
|---|
| 1911 | if(file == "." || file == "..") //blah
|
|---|
| 1912 | continue;
|
|---|
| 1913 | if(!uninst.isEmpty())
|
|---|
| 1914 | uninst.append("\n\t");
|
|---|
| 1915 | uninst.append(
|
|---|
| 1916 | #if defined(Q_WS_WIN) || defined(Q_OS_OS2)
|
|---|
| 1917 | QString("-$(DEL_FILE)")
|
|---|
| 1918 | #else
|
|---|
| 1919 | QString("-$(DEL_FILE) -r")
|
|---|
| 1920 | #endif
|
|---|
| 1921 | + " \"" + root + fileFixify(dst + file, QString::null, QString::null, FALSE, FALSE) +
|
|---|
| 1922 | "\"");
|
|---|
| 1923 | QFileInfo fi(Option::fixPathToTargetOS(fileFixify(dirstr + file), TRUE));
|
|---|
| 1924 | if(!target.isEmpty())
|
|---|
| 1925 | target += "\t";
|
|---|
| 1926 | QString cmd = QString(fi.isDir() ? "-$(INSTALL_DIR)" : "-$(INSTALL_FILE)") + " \"" +
|
|---|
| 1927 | Option::fixPathToTargetOS(fileFixify(dirstr + file, QString::null,
|
|---|
| 1928 | QString::null, FALSE, FALSE), FALSE) +
|
|---|
| 1929 | "\" \"" + root + fileFixify(dst) + "\"\n";
|
|---|
| 1930 | target += cmd;
|
|---|
| 1931 | if(!project->isActiveConfig("debug") &&
|
|---|
| 1932 | !fi.isDir() && fi.isExecutable() && !project->isEmpty("QMAKE_STRIP"))
|
|---|
| 1933 | target += QString("\t-") + var("QMAKE_STRIP") + " \"" +
|
|---|
| 1934 | root + fileFixify(dst + file, QString::null, QString::null, FALSE, FALSE) +
|
|---|
| 1935 | "\"\n";
|
|---|
| 1936 | }
|
|---|
| 1937 | }
|
|---|
| 1938 | }
|
|---|
| 1939 | //default?
|
|---|
| 1940 | if(do_default) {
|
|---|
| 1941 | target = defaultInstall((*it));
|
|---|
| 1942 | uninst = project->variables()[(*it) + ".uninstall"];
|
|---|
| 1943 | }
|
|---|
| 1944 |
|
|---|
| 1945 | if(!target.isEmpty()) {
|
|---|
| 1946 | t << "install_" << (*it) << ": all ";
|
|---|
| 1947 | const QStringList &deps = project->variables()[(*it) + ".depends"];
|
|---|
| 1948 | if(!deps.isEmpty()) {
|
|---|
| 1949 | for(QStringList::ConstIterator dep_it = deps.begin(); dep_it != deps.end(); ++dep_it) {
|
|---|
| 1950 | QString targ = var((*dep_it) + ".target");
|
|---|
| 1951 | if(targ.isEmpty())
|
|---|
| 1952 | targ = (*dep_it);
|
|---|
| 1953 | t << targ;
|
|---|
| 1954 | }
|
|---|
| 1955 | }
|
|---|
| 1956 | t << "\n\t";
|
|---|
| 1957 | const QStringList &dirs = project->variables()[pvar];
|
|---|
| 1958 | for(QStringList::ConstIterator pit = dirs.begin(); pit != dirs.end(); ++pit) {
|
|---|
| 1959 | QString tmp_dst = fileFixify((*pit));
|
|---|
| 1960 | #ifndef Q_WS_WIN
|
|---|
| 1961 | if(tmp_dst.right(1) != Option::dir_sep)
|
|---|
| 1962 | tmp_dst += Option::dir_sep;
|
|---|
| 1963 | #endif
|
|---|
| 1964 | t << mkdir_p_asstring(root+tmp_dst) << "\n\t";
|
|---|
| 1965 | }
|
|---|
| 1966 | t << target << endl << endl;
|
|---|
| 1967 | if(!uninst.isEmpty()) {
|
|---|
| 1968 | t << "uninstall_" << (*it) << ": " << "\n\t"
|
|---|
| 1969 | << uninst.join("") << "\n\t"
|
|---|
| 1970 | << "-$(DEL_DIR) \"" << ( root + dst ) << "\"" << endl << endl;
|
|---|
| 1971 | }
|
|---|
| 1972 | t << endl;
|
|---|
| 1973 |
|
|---|
| 1974 | if(project->variables()[(*it) + ".CONFIG"].findIndex("no_default_install") == -1) {
|
|---|
| 1975 | all_installs += QString("install_") + (*it) + " ";
|
|---|
| 1976 | if(!uninst.isEmpty())
|
|---|
| 1977 | all_uninstalls += "uninstall_" + (*it) + " ";
|
|---|
| 1978 | }
|
|---|
| 1979 | } else {
|
|---|
| 1980 | debug_msg(1, "no definition for install %s: install target not created",(*it).latin1());
|
|---|
| 1981 | }
|
|---|
| 1982 | }
|
|---|
| 1983 | t << "install: " << all_installs << " " << var("INSTALLDEPS") << "\n\n";
|
|---|
| 1984 | t << "uninstall: " << all_uninstalls << " " << var("UNINSTALLDEPS") << "\n\n";
|
|---|
| 1985 | }
|
|---|
| 1986 |
|
|---|
| 1987 | QString
|
|---|
| 1988 | MakefileGenerator::var(const QString &var)
|
|---|
| 1989 | {
|
|---|
| 1990 | return val(project->variables()[var]);
|
|---|
| 1991 | }
|
|---|
| 1992 |
|
|---|
| 1993 | QString
|
|---|
| 1994 | MakefileGenerator::val(const QStringList &varList)
|
|---|
| 1995 | {
|
|---|
| 1996 | return valGlue(varList, "", " ", "");
|
|---|
| 1997 | }
|
|---|
| 1998 |
|
|---|
| 1999 | QString
|
|---|
| 2000 | MakefileGenerator::varGlue(const QString &var, const QString &before, const QString &glue, const QString &after)
|
|---|
| 2001 | {
|
|---|
| 2002 | return valGlue(project->variables()[var], before, glue, after);
|
|---|
| 2003 | }
|
|---|
| 2004 |
|
|---|
| 2005 | QString
|
|---|
| 2006 | MakefileGenerator::valGlue(const QStringList &varList, const QString &before, const QString &glue, const QString &after)
|
|---|
| 2007 | {
|
|---|
| 2008 | QString ret;
|
|---|
| 2009 | for(QStringList::ConstIterator it = varList.begin(); it != varList.end(); ++it) {
|
|---|
| 2010 | if(!(*it).isEmpty()) {
|
|---|
| 2011 | if(!ret.isEmpty())
|
|---|
| 2012 | ret += glue;
|
|---|
| 2013 | ret += (*it);
|
|---|
| 2014 | }
|
|---|
| 2015 | }
|
|---|
| 2016 | return ret.isEmpty() ? QString("") : before + ret + after;
|
|---|
| 2017 | }
|
|---|
| 2018 |
|
|---|
| 2019 |
|
|---|
| 2020 | QString
|
|---|
| 2021 | MakefileGenerator::varList(const QString &var)
|
|---|
| 2022 | {
|
|---|
| 2023 | return valList(project->variables()[var]);
|
|---|
| 2024 | }
|
|---|
| 2025 |
|
|---|
| 2026 | QString
|
|---|
| 2027 | MakefileGenerator::valList(const QStringList &varList)
|
|---|
| 2028 | {
|
|---|
| 2029 | return valGlue(varList, "", " \\\n\t\t", "");
|
|---|
| 2030 | }
|
|---|
| 2031 |
|
|---|
| 2032 |
|
|---|
| 2033 | QStringList
|
|---|
| 2034 | MakefileGenerator::createObjectList(const QString &var)
|
|---|
| 2035 | {
|
|---|
| 2036 | QStringList &l = project->variables()[var], ret;
|
|---|
| 2037 | QString objdir, dir;
|
|---|
| 2038 | if(!project->variables()["OBJECTS_DIR"].isEmpty())
|
|---|
| 2039 | objdir = project->first("OBJECTS_DIR");
|
|---|
| 2040 | for(QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
|
|---|
| 2041 | QFileInfo fi(Option::fixPathToLocalOS((*it)));
|
|---|
| 2042 | if(objdir.isEmpty() && project->isActiveConfig("object_with_source")) {
|
|---|
| 2043 | QString fName = Option::fixPathToTargetOS((*it), FALSE);
|
|---|
| 2044 | int dl = fName.findRev(Option::dir_sep);
|
|---|
| 2045 | if(dl != -1)
|
|---|
| 2046 | dir = fName.left(dl + 1);
|
|---|
| 2047 | } else {
|
|---|
| 2048 | dir = objdir;
|
|---|
| 2049 | }
|
|---|
| 2050 | ret.append(dir + fi.baseName(TRUE) + Option::obj_ext);
|
|---|
| 2051 | }
|
|---|
| 2052 | return ret;
|
|---|
| 2053 | }
|
|---|
| 2054 |
|
|---|
| 2055 | bool
|
|---|
| 2056 | MakefileGenerator::writeMakefile(QTextStream &t)
|
|---|
| 2057 | {
|
|---|
| 2058 | t << "####### Compile" << endl << endl;
|
|---|
| 2059 | writeObj(t, "OBJECTS", "SOURCES");
|
|---|
| 2060 | writeUicSrc(t, "FORMS");
|
|---|
| 2061 | writeObj(t, "UICOBJECTS", "UICIMPLS");
|
|---|
| 2062 | writeMocObj(t, "OBJMOC", "SRCMOC" );
|
|---|
| 2063 | writeMocSrc(t, "HEADERS");
|
|---|
| 2064 | writeMocSrc(t, "SOURCES");
|
|---|
| 2065 | writeMocSrc(t, "UICDECLS");
|
|---|
| 2066 | writeYaccSrc(t, "YACCSOURCES");
|
|---|
| 2067 | writeLexSrc(t, "LEXSOURCES");
|
|---|
| 2068 | writeImageObj(t, "IMAGEOBJECTS");
|
|---|
| 2069 | writeImageSrc(t, "QMAKE_IMAGE_COLLECTION");
|
|---|
| 2070 |
|
|---|
| 2071 | t << "####### Install" << endl << endl;
|
|---|
| 2072 | writeInstalls(t, "INSTALLS");
|
|---|
| 2073 | return TRUE;
|
|---|
| 2074 | }
|
|---|
| 2075 |
|
|---|
| 2076 | QString MakefileGenerator::buildArgs()
|
|---|
| 2077 | {
|
|---|
| 2078 | static QString ret;
|
|---|
| 2079 | if(ret.isEmpty()) {
|
|---|
| 2080 | //special variables
|
|---|
| 2081 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
|
|---|
| 2082 | ret += " QMAKE_ABSOLUTE_SOURCE_PATH=\"" + project->first("QMAKE_ABSOLUTE_SOURCE_PATH") + "\"";
|
|---|
| 2083 |
|
|---|
| 2084 | //warnings
|
|---|
| 2085 | else if(Option::warn_level == WarnNone)
|
|---|
| 2086 | ret += " -Wnone";
|
|---|
| 2087 | else if(Option::warn_level == WarnAll)
|
|---|
| 2088 | ret += " -Wall";
|
|---|
| 2089 | else if(Option::warn_level & WarnParser)
|
|---|
| 2090 | ret += " -Wparser";
|
|---|
| 2091 | //other options
|
|---|
| 2092 | if(!Option::user_template.isEmpty())
|
|---|
| 2093 | ret += " -t " + Option::user_template;
|
|---|
| 2094 | if(!Option::mkfile::do_cache)
|
|---|
| 2095 | ret += " -nocache";
|
|---|
| 2096 | if(!Option::mkfile::do_deps)
|
|---|
| 2097 | ret += " -nodepend";
|
|---|
| 2098 | if(!Option::mkfile::do_mocs)
|
|---|
| 2099 | ret += " -nomoc";
|
|---|
| 2100 | if(!Option::mkfile::do_dep_heuristics)
|
|---|
| 2101 | ret += " -nodependheuristics";
|
|---|
| 2102 | if(!Option::mkfile::qmakespec_commandline.isEmpty())
|
|---|
| 2103 | ret += " -spec " + Option::mkfile::qmakespec_commandline;
|
|---|
| 2104 |
|
|---|
| 2105 | //arguments
|
|---|
| 2106 | for(QStringList::Iterator it = Option::before_user_vars.begin();
|
|---|
| 2107 | it != Option::before_user_vars.end(); ++it) {
|
|---|
| 2108 | if((*it).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH")
|
|---|
| 2109 | ret += " \"" + (*it) + "\"";
|
|---|
| 2110 | }
|
|---|
| 2111 | if(Option::after_user_vars.count()) {
|
|---|
| 2112 | ret += " -after ";
|
|---|
| 2113 | for(QStringList::Iterator it = Option::after_user_vars.begin();
|
|---|
| 2114 | it != Option::after_user_vars.end(); ++it) {
|
|---|
| 2115 | if((*it).left(qstrlen("QMAKE_ABSOLUTE_SOURCE_PATH")) != "QMAKE_ABSOLUTE_SOURCE_PATH")
|
|---|
| 2116 | ret += " \"" + (*it) + "\"";
|
|---|
| 2117 | }
|
|---|
| 2118 | }
|
|---|
| 2119 | }
|
|---|
| 2120 | return ret;
|
|---|
| 2121 | }
|
|---|
| 2122 |
|
|---|
| 2123 | //could get stored argv, but then it would have more options than are
|
|---|
| 2124 | //probably necesary this will try to guess the bare minimum..
|
|---|
| 2125 | QString MakefileGenerator::build_args()
|
|---|
| 2126 | {
|
|---|
| 2127 | static QString ret;
|
|---|
| 2128 | if(ret.isEmpty()) {
|
|---|
| 2129 | ret = "$(QMAKE)";
|
|---|
| 2130 |
|
|---|
| 2131 | // general options and arguments
|
|---|
| 2132 | ret += buildArgs();
|
|---|
| 2133 |
|
|---|
| 2134 | //output
|
|---|
| 2135 | QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.name()));
|
|---|
| 2136 | if (!ofile.isEmpty() && ofile != project->first("QMAKE_MAKEFILE"))
|
|---|
| 2137 | ret += " -o " + ofile;
|
|---|
| 2138 |
|
|---|
| 2139 | //inputs
|
|---|
| 2140 | QStringList files = fileFixify(Option::mkfile::project_files);
|
|---|
| 2141 | ret += " " + files.join(" ");
|
|---|
| 2142 | }
|
|---|
| 2143 | return ret;
|
|---|
| 2144 | }
|
|---|
| 2145 |
|
|---|
| 2146 | bool
|
|---|
| 2147 | MakefileGenerator::writeHeader(QTextStream &t)
|
|---|
| 2148 | {
|
|---|
| 2149 | time_t foo = time(NULL);
|
|---|
| 2150 | t << "#############################################################################" << endl;
|
|---|
| 2151 | t << "# Makefile for building: " << var("TARGET") << endl;
|
|---|
| 2152 | t << "# Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: " << ctime(&foo);
|
|---|
| 2153 | t << "# Project: " << fileFixify(project->projectFile()) << endl;
|
|---|
| 2154 | t << "# Template: " << var("TEMPLATE") << endl;
|
|---|
| 2155 | t << "# Command: " << build_args() << endl;
|
|---|
| 2156 | t << "#############################################################################" << endl;
|
|---|
| 2157 | t << endl;
|
|---|
| 2158 | return TRUE;
|
|---|
| 2159 | }
|
|---|
| 2160 |
|
|---|
| 2161 |
|
|---|
| 2162 | //makes my life easier..
|
|---|
| 2163 | bool
|
|---|
| 2164 | MakefileGenerator::writeMakeQmake(QTextStream &t)
|
|---|
| 2165 | {
|
|---|
| 2166 | QString ofile = Option::fixPathToTargetOS(fileFixify(Option::output.name()));
|
|---|
| 2167 | if(project->isEmpty("QMAKE_FAILED_REQUIREMENTS") && !project->isActiveConfig("no_autoqmake") &&
|
|---|
| 2168 | !project->isEmpty("QMAKE_INTERNAL_PRL_FILE")) {
|
|---|
| 2169 | QStringList files = fileFixify(Option::mkfile::project_files);
|
|---|
| 2170 | t << project->first("QMAKE_INTERNAL_PRL_FILE") << ": " << "\n\t"
|
|---|
| 2171 | << "@$(QMAKE) -prl " << buildArgs() << " " << files.join(" ") << endl;
|
|---|
| 2172 | }
|
|---|
| 2173 |
|
|---|
| 2174 | QString pfile = project->projectFile();
|
|---|
| 2175 | if(pfile != "(stdin)") {
|
|---|
| 2176 | QString qmake = build_args();
|
|---|
| 2177 | if(!ofile.isEmpty() && !project->isActiveConfig("no_autoqmake")) {
|
|---|
| 2178 | t << ofile << ": " << fileFixify(pfile) << " ";
|
|---|
| 2179 | if(Option::mkfile::do_cache)
|
|---|
| 2180 | t << fileFixify(Option::mkfile::cachefile) << " ";
|
|---|
| 2181 | if(!specdir().isEmpty()) {
|
|---|
| 2182 | if (QFile::exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"qmake.conf")))
|
|---|
| 2183 | t << specdir() << Option::dir_sep << "qmake.conf" << " ";
|
|---|
| 2184 | else if (QFile::exists(Option::fixPathToLocalOS(specdir()+QDir::separator()+"tmake.conf")))
|
|---|
| 2185 | t << specdir() << Option::dir_sep << "tmake.conf" << " ";
|
|---|
| 2186 | }
|
|---|
| 2187 | t << project->variables()["QMAKE_INTERNAL_INCLUDED_FILES"].join(" \\\n\t\t") << "\n\t"
|
|---|
| 2188 | << qmake <<endl;
|
|---|
| 2189 | }
|
|---|
| 2190 | if(project->first("QMAKE_ORIG_TARGET") != "qmake") {
|
|---|
| 2191 | t << "qmake: " <<
|
|---|
| 2192 | project->variables()["QMAKE_INTERNAL_QMAKE_DEPS"].join(" \\\n\t\t") << "\n\t"
|
|---|
| 2193 | << "@" << qmake << endl << endl;
|
|---|
| 2194 | }
|
|---|
| 2195 | }
|
|---|
| 2196 | return TRUE;
|
|---|
| 2197 | }
|
|---|
| 2198 |
|
|---|
| 2199 | QStringList
|
|---|
| 2200 | MakefileGenerator::fileFixify(const QStringList& files, const QString &out_dir, const QString &in_dir,
|
|---|
| 2201 | bool force_fix, bool canon) const
|
|---|
| 2202 | {
|
|---|
| 2203 | if(files.isEmpty())
|
|---|
| 2204 | return files;
|
|---|
| 2205 | QStringList ret;
|
|---|
| 2206 | for(QStringList::ConstIterator it = files.begin(); it != files.end(); ++it) {
|
|---|
| 2207 | if(!(*it).isEmpty())
|
|---|
| 2208 | ret << fileFixify((*it), out_dir, in_dir, force_fix, canon);
|
|---|
| 2209 | }
|
|---|
| 2210 | return ret;
|
|---|
| 2211 | }
|
|---|
| 2212 |
|
|---|
| 2213 | QString
|
|---|
| 2214 | MakefileGenerator::fileFixify(const QString& file0, const QString &out_d,
|
|---|
| 2215 | const QString &in_d, bool force_fix, bool canon) const
|
|---|
| 2216 | {
|
|---|
| 2217 | if(file0.isEmpty())
|
|---|
| 2218 | return file0;
|
|---|
| 2219 | QString key = file0;
|
|---|
| 2220 | if(QDir::isRelativePath(file0))
|
|---|
| 2221 | key.prepend(QDir::currentDirPath() + "--");
|
|---|
| 2222 | if(!in_d.isEmpty() || !out_d.isEmpty() || force_fix || !canon)
|
|---|
| 2223 | key.prepend(in_d + "--" + out_d + "--" + QString::number((int)force_fix) + "--" +
|
|---|
| 2224 | QString::number((int)canon) + "-");
|
|---|
| 2225 | if(fileFixed.contains(key))
|
|---|
| 2226 | return fileFixed[key];
|
|---|
| 2227 |
|
|---|
| 2228 | QString file = file0;
|
|---|
| 2229 | int depth = 4;
|
|---|
| 2230 | if(Option::qmake_mode == Option::QMAKE_GENERATE_MAKEFILE ||
|
|---|
| 2231 | Option::qmake_mode == Option::QMAKE_GENERATE_PRL) {
|
|---|
| 2232 | if(project && !project->isEmpty("QMAKE_PROJECT_DEPTH"))
|
|---|
| 2233 | depth = project->first("QMAKE_PROJECT_DEPTH").toInt();
|
|---|
| 2234 | else if(Option::mkfile::cachefile_depth != -1)
|
|---|
| 2235 | depth = Option::mkfile::cachefile_depth;
|
|---|
| 2236 | }
|
|---|
| 2237 |
|
|---|
| 2238 | QChar quote;
|
|---|
| 2239 | if((file.startsWith("'") || file.startsWith("\"")) && file.startsWith(file.right(1))) {
|
|---|
| 2240 | quote = file.at(0);
|
|---|
| 2241 | file = file.mid(1, file.length() - 2);
|
|---|
| 2242 | }
|
|---|
| 2243 | QString orig_file = file;
|
|---|
| 2244 | if(!force_fix && project->isActiveConfig("no_fixpath")) {
|
|---|
| 2245 | if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH")) { //absoluteify it
|
|---|
| 2246 | QString qfile = Option::fixPathToLocalOS(file, TRUE, canon);
|
|---|
| 2247 | if(QDir::isRelativePath(file)) { //already absolute
|
|---|
| 2248 | QFileInfo fi(qfile);
|
|---|
| 2249 | if(!fi.convertToAbs()) //strange
|
|---|
| 2250 | file = fi.filePath();
|
|---|
| 2251 | }
|
|---|
| 2252 | }
|
|---|
| 2253 | } else { //fix it..
|
|---|
| 2254 | QString qfile(Option::fixPathToLocalOS(file, TRUE, canon)), in_dir(in_d), out_dir(out_d);
|
|---|
| 2255 | {
|
|---|
| 2256 | if(out_dir.isNull() || QDir::isRelativePath(out_dir))
|
|---|
| 2257 | out_dir.prepend(Option::output_dir + QDir::separator());
|
|---|
| 2258 | if(out_dir == ".")
|
|---|
| 2259 | out_dir = QDir::currentDirPath();
|
|---|
| 2260 | if(in_dir.isEmpty() || QDir::isRelativePath(in_dir))
|
|---|
| 2261 | in_dir.prepend(QDir::currentDirPath() + QDir::separator());
|
|---|
| 2262 | if(in_dir == ".")
|
|---|
| 2263 | in_dir = QDir::currentDirPath();
|
|---|
| 2264 |
|
|---|
| 2265 | if(!QDir::isRelativePath(in_dir) || !QDir::isRelativePath(out_dir)) {
|
|---|
| 2266 | QFileInfo in_fi(in_dir);
|
|---|
| 2267 | if(!in_fi.convertToAbs())
|
|---|
| 2268 | in_dir = in_fi.filePath();
|
|---|
| 2269 | QFileInfo out_fi(out_dir);
|
|---|
| 2270 | if(!out_fi.convertToAbs())
|
|---|
| 2271 | out_dir = out_fi.filePath();
|
|---|
| 2272 | }
|
|---|
| 2273 | QString in_canonical_dir = QDir(in_dir).canonicalPath(),
|
|---|
| 2274 | out_canonical_dir = QDir(out_dir).canonicalPath();
|
|---|
| 2275 | if(!in_canonical_dir.isEmpty())
|
|---|
| 2276 | in_dir = in_canonical_dir;
|
|---|
| 2277 | if(!out_canonical_dir.isEmpty())
|
|---|
| 2278 | out_dir = out_canonical_dir;
|
|---|
| 2279 | }
|
|---|
| 2280 | if(out_dir != in_dir || !QDir::isRelativePath(qfile)) {
|
|---|
| 2281 | if(QDir::isRelativePath(qfile)) {
|
|---|
| 2282 | if(file.left(Option::dir_sep.length()) != Option::dir_sep &&
|
|---|
| 2283 | in_dir.right(Option::dir_sep.length()) != Option::dir_sep)
|
|---|
| 2284 | file.prepend(Option::dir_sep);
|
|---|
| 2285 | file.prepend(in_dir);
|
|---|
| 2286 | }
|
|---|
| 2287 | file = Option::fixPathToTargetOS(file, FALSE, canon);
|
|---|
| 2288 | if(canon && QFile::exists(file) && file == Option::fixPathToTargetOS(file, TRUE, canon)) {
|
|---|
| 2289 | QString real_file = QDir(file).canonicalPath();
|
|---|
| 2290 | if(!real_file.isEmpty())
|
|---|
| 2291 | file = real_file;
|
|---|
| 2292 | }
|
|---|
| 2293 | QString match_dir = Option::fixPathToTargetOS(out_dir, FALSE, canon);
|
|---|
| 2294 | if(file == match_dir) {
|
|---|
| 2295 | file = "";
|
|---|
| 2296 | } else if(file.startsWith(match_dir) &&
|
|---|
| 2297 | file.mid(match_dir.length(), Option::dir_sep.length()) == Option::dir_sep) {
|
|---|
| 2298 | file = file.right(file.length() - (match_dir.length() + 1));
|
|---|
| 2299 | } else {
|
|---|
| 2300 | for(int i = 1; i <= depth; i++) {
|
|---|
| 2301 | int sl = match_dir.findRev(Option::dir_sep);
|
|---|
| 2302 | if(sl == -1)
|
|---|
| 2303 | break;
|
|---|
| 2304 | match_dir = match_dir.left(sl);
|
|---|
| 2305 | if(match_dir.isEmpty())
|
|---|
| 2306 | break;
|
|---|
| 2307 | if(file.startsWith(match_dir) &&
|
|---|
| 2308 | file.mid(match_dir.length(), Option::dir_sep.length()) == Option::dir_sep) {
|
|---|
| 2309 | //concat
|
|---|
| 2310 | int remlen = file.length() - (match_dir.length() + 1);
|
|---|
| 2311 | if (remlen < 0)
|
|---|
| 2312 | remlen = 0;
|
|---|
| 2313 | file = file.right(remlen);
|
|---|
| 2314 | //prepend
|
|---|
| 2315 | for(int o = 0; o < i; o++)
|
|---|
| 2316 | file.prepend(".." + Option::dir_sep);
|
|---|
| 2317 | }
|
|---|
| 2318 | }
|
|---|
| 2319 | }
|
|---|
| 2320 | }
|
|---|
| 2321 | }
|
|---|
| 2322 | file = Option::fixPathToTargetOS(file, FALSE, canon);
|
|---|
| 2323 | if(file.isEmpty())
|
|---|
| 2324 | file = ".";
|
|---|
| 2325 | if(!quote.isNull())
|
|---|
| 2326 | file = quote + file + quote;
|
|---|
| 2327 | debug_msg(3, "Fixed %s :: to :: %s (%d) [%s::%s]", orig_file.latin1(), file.latin1(), depth,
|
|---|
| 2328 | in_d.latin1(), out_d.latin1());
|
|---|
| 2329 | ((MakefileGenerator*)this)->fileFixed.insert(key, file);
|
|---|
| 2330 | return file;
|
|---|
| 2331 | }
|
|---|
| 2332 |
|
|---|
| 2333 | QString
|
|---|
| 2334 | MakefileGenerator::cleanFilePath(const QString &file) const
|
|---|
| 2335 | {
|
|---|
| 2336 | return fileFixify(Option::fixPathToTargetOS(file));
|
|---|
| 2337 | }
|
|---|
| 2338 |
|
|---|
| 2339 | void MakefileGenerator::logicWarn(const QString &f, const QString &w)
|
|---|
| 2340 | {
|
|---|
| 2341 | if(!(Option::warn_level & WarnLogic))
|
|---|
| 2342 | return;
|
|---|
| 2343 | QString file = f;
|
|---|
| 2344 | int slsh = f.findRev(Option::dir_sep);
|
|---|
| 2345 | if(slsh != -1)
|
|---|
| 2346 | file = file.right(file.length() - slsh - 1);
|
|---|
| 2347 | QStringList &l = project->variables()[w];
|
|---|
| 2348 | for(QStringList::Iterator val_it = l.begin(); val_it != l.end(); ++val_it) {
|
|---|
| 2349 | QString file2((*val_it));
|
|---|
| 2350 | slsh = file2.findRev(Option::dir_sep);
|
|---|
| 2351 | if(slsh != -1)
|
|---|
| 2352 | file2 = file2.right(file2.length() - slsh - 1);
|
|---|
| 2353 | if(file2 == file) {
|
|---|
| 2354 | warn_msg(WarnLogic, "Found potential symbol conflict of %s (%s) in %s",
|
|---|
| 2355 | file.latin1(), (*val_it).latin1(), w.latin1());
|
|---|
| 2356 | break;
|
|---|
| 2357 | }
|
|---|
| 2358 | }
|
|---|
| 2359 | }
|
|---|
| 2360 |
|
|---|
| 2361 | QString
|
|---|
| 2362 | MakefileGenerator::dependencyKey(const QString &file) const
|
|---|
| 2363 | {
|
|---|
| 2364 | QString key = file;
|
|---|
| 2365 | Option::fixPathToTargetOS(key);
|
|---|
| 2366 | if(key.find(Option::dir_sep))
|
|---|
| 2367 | key = key.right(key.length() - key.findRev(Option::dir_sep) - 1);
|
|---|
| 2368 | return key;
|
|---|
| 2369 | }
|
|---|
| 2370 |
|
|---|
| 2371 | void
|
|---|
| 2372 | MakefileGenerator::setProcessedDependencies(const QString &file, bool b)
|
|---|
| 2373 | {
|
|---|
| 2374 | depProcessed[dependencyKey(file)] = b;
|
|---|
| 2375 | }
|
|---|
| 2376 |
|
|---|
| 2377 | bool
|
|---|
| 2378 | MakefileGenerator::processedDependencies(const QString &file)
|
|---|
| 2379 | {
|
|---|
| 2380 | QString key = dependencyKey(file);
|
|---|
| 2381 | if(!depProcessed.contains(key))
|
|---|
| 2382 | return FALSE;
|
|---|
| 2383 | return depProcessed[key];
|
|---|
| 2384 | }
|
|---|
| 2385 |
|
|---|
| 2386 | QStringList
|
|---|
| 2387 | &MakefileGenerator::findDependencies(const QString &file)
|
|---|
| 2388 | {
|
|---|
| 2389 | return depends[dependencyKey(file)];
|
|---|
| 2390 | }
|
|---|
| 2391 |
|
|---|
| 2392 |
|
|---|
| 2393 | QString
|
|---|
| 2394 | MakefileGenerator::specdir()
|
|---|
| 2395 | {
|
|---|
| 2396 | if(!spec.isEmpty())
|
|---|
| 2397 | return spec;
|
|---|
| 2398 | spec = Option::mkfile::qmakespec;
|
|---|
| 2399 | #if 0
|
|---|
| 2400 | if(const char *d = getenv("QTDIR")) {
|
|---|
| 2401 | QString qdir = Option::fixPathToTargetOS(QString(d));
|
|---|
| 2402 | if(qdir.endsWith(QString(QChar(QDir::separator()))))
|
|---|
| 2403 | qdir.truncate(qdir.length()-1);
|
|---|
| 2404 | //fix path
|
|---|
| 2405 | QFileInfo fi(spec);
|
|---|
| 2406 | QString absSpec(fi.absFilePath());
|
|---|
| 2407 | absSpec = Option::fixPathToTargetOS(absSpec);
|
|---|
| 2408 | //replace what you can
|
|---|
| 2409 | if(absSpec.startsWith(qdir)) {
|
|---|
| 2410 | absSpec.replace(0, qdir.length(), "$(QTDIR)");
|
|---|
| 2411 | spec = absSpec;
|
|---|
| 2412 | }
|
|---|
| 2413 | }
|
|---|
| 2414 | #else
|
|---|
| 2415 | spec = Option::fixPathToTargetOS(spec);
|
|---|
| 2416 | #endif
|
|---|
| 2417 | return spec;
|
|---|
| 2418 | }
|
|---|
| 2419 |
|
|---|
| 2420 | bool
|
|---|
| 2421 | MakefileGenerator::openOutput(QFile &file) const
|
|---|
| 2422 | {
|
|---|
| 2423 | {
|
|---|
| 2424 | QString outdir;
|
|---|
| 2425 | if(!file.name().isEmpty()) {
|
|---|
| 2426 | if(QDir::isRelativePath(file.name()))
|
|---|
| 2427 | file.setName(Option::output_dir + file.name()); //pwd when qmake was run
|
|---|
| 2428 | QFileInfo fi(file);
|
|---|
| 2429 | if(fi.isDir())
|
|---|
| 2430 | outdir = file.name() + QDir::separator();
|
|---|
| 2431 | }
|
|---|
| 2432 | if(!outdir.isEmpty() || file.name().isEmpty()) {
|
|---|
| 2433 | QString fname = "Makefile";
|
|---|
| 2434 | if(!project->isEmpty("MAKEFILE"))
|
|---|
| 2435 | fname = project->first("MAKEFILE");
|
|---|
| 2436 | file.setName(outdir + fname);
|
|---|
| 2437 | }
|
|---|
| 2438 | }
|
|---|
| 2439 | if(QDir::isRelativePath(file.name()))
|
|---|
| 2440 | file.setName(Option::output_dir + file.name()); //pwd when qmake was run
|
|---|
| 2441 | if(project->isEmpty("QMAKE_MAKEFILE"))
|
|---|
| 2442 | project->variables()["QMAKE_MAKEFILE"].append(file.name());
|
|---|
| 2443 | int slsh = file.name().findRev(Option::dir_sep);
|
|---|
| 2444 | if(slsh != -1)
|
|---|
| 2445 | createDir(file.name().left(slsh));
|
|---|
| 2446 | if(file.open(IO_WriteOnly | IO_Translate)) {
|
|---|
| 2447 | QFileInfo fi(Option::output);
|
|---|
| 2448 | QString od = Option::fixPathToTargetOS((fi.isSymLink() ? fi.readLink() : fi.dirPath()) );
|
|---|
| 2449 | if(QDir::isRelativePath(od))
|
|---|
| 2450 | od.prepend(Option::output_dir);
|
|---|
| 2451 | Option::output_dir = od;
|
|---|
| 2452 | return TRUE;
|
|---|
| 2453 | }
|
|---|
| 2454 | return FALSE;
|
|---|
| 2455 | }
|
|---|
| 2456 |
|
|---|
| 2457 |
|
|---|
| 2458 |
|
|---|
| 2459 | //Factory thing
|
|---|
| 2460 | #include "unixmake.h"
|
|---|
| 2461 | #include "msvc_nmake.h"
|
|---|
| 2462 | #include "borland_bmake.h"
|
|---|
| 2463 | #include "mingw_make.h"
|
|---|
| 2464 | #include "gnumake.h"
|
|---|
| 2465 | #include "msvc_dsp.h"
|
|---|
| 2466 | #include "msvc_vcproj.h"
|
|---|
| 2467 | #include "metrowerks_xml.h"
|
|---|
| 2468 | #include "pbuilder_pbx.h"
|
|---|
| 2469 | #include "projectgenerator.h"
|
|---|
| 2470 |
|
|---|
| 2471 | MakefileGenerator *
|
|---|
| 2472 | MakefileGenerator::create(QMakeProject *proj)
|
|---|
| 2473 | {
|
|---|
| 2474 | if(Option::qmake_mode == Option::QMAKE_GENERATE_PROJECT)
|
|---|
| 2475 | return new ProjectGenerator(proj);
|
|---|
| 2476 |
|
|---|
| 2477 | MakefileGenerator *mkfile = NULL;
|
|---|
| 2478 | QString gen = proj->first("MAKEFILE_GENERATOR");
|
|---|
| 2479 | if(gen.isEmpty()) {
|
|---|
| 2480 | fprintf(stderr, "No generator specified in config file: %s\n",
|
|---|
| 2481 | proj->projectFile().latin1());
|
|---|
| 2482 | } else if(gen == "UNIX") {
|
|---|
| 2483 | mkfile = new UnixMakefileGenerator(proj);
|
|---|
| 2484 | } else if(gen == "MSVC") {
|
|---|
| 2485 | // Visual Studio =< v6.0
|
|---|
| 2486 | if(proj->first("TEMPLATE").find(QRegExp("^vc.*")) != -1)
|
|---|
| 2487 | mkfile = new DspMakefileGenerator(proj);
|
|---|
| 2488 | else
|
|---|
| 2489 | mkfile = new NmakeMakefileGenerator(proj);
|
|---|
| 2490 | } else if(gen == "MSVC.NET") {
|
|---|
| 2491 | // Visual Studio >= v7.0
|
|---|
| 2492 | if(proj->first("TEMPLATE").find(QRegExp("^vc.*")) != -1)
|
|---|
| 2493 | mkfile = new VcprojGenerator(proj);
|
|---|
| 2494 | else
|
|---|
| 2495 | mkfile = new NmakeMakefileGenerator(proj);
|
|---|
| 2496 | } else if(gen == "BMAKE") {
|
|---|
| 2497 | mkfile = new BorlandMakefileGenerator(proj);
|
|---|
| 2498 | } else if(gen == "MINGW") {
|
|---|
| 2499 | mkfile = new MingwMakefileGenerator(proj);
|
|---|
| 2500 | } else if(gen == "GNUMAKE") {
|
|---|
| 2501 | mkfile = new GNUMakefileGenerator(proj);
|
|---|
| 2502 | } else if(gen == "METROWERKS") {
|
|---|
| 2503 | mkfile = new MetrowerksMakefileGenerator(proj);
|
|---|
| 2504 | } else if(gen == "PROJECTBUILDER") {
|
|---|
| 2505 | mkfile = new ProjectBuilderMakefileGenerator(proj);
|
|---|
| 2506 | } else {
|
|---|
| 2507 | fprintf(stderr, "Unknown generator specified: %s\n", gen.latin1());
|
|---|
| 2508 | }
|
|---|
| 2509 | return mkfile;
|
|---|
| 2510 | }
|
|---|