Qt 5.6.3 is a bug-fix release. It maintains both forward and backward compatibility (source and binary) with previous Qt 5.6.x releases. For more details, refer to the online documentation included in this distribution. The documentation is also available online: http://doc.qt.io/qt-5/index.html The Qt version 5.6 series is binary compatible with the 5.5.x series. Applications compiled for 5.5 will continue to run with 5.6. Some of the changes listed in this file include issue tracking numbers corresponding to tasks in the Qt Bug Tracker: https://bugreports.qt.io/ Each of these identifiers can be entered in the bug tracker to obtain more information about a particular change. ***************************************************************************** * License Changes * ***************************************************************************** - Static libraries that are linked into executables (winmain and qopenglextensions) are now licensed under BSD _and_ commercial licenses. ****************************************************************************** * Important Behavior Changes * ****************************************************************************** - QPluginLoader: * [QTBUG-49061] QPluginLoader no longer performs the actual unloading of the plugin either on destruction or when unload() is called. This does not affect QLibrary and QLibrary::unload(). ****************************************************************************** * Library * ****************************************************************************** QtCore ------ - QDir: * [QTBUG-58390] Fixed the implementation of mkpath() to not attempt to mkdir directories that already exist, especially those in automount filesystems (like /home). - QHash / QMultiHash: * [QTBUG-60395] Fixed a bug that caused operator== not to return true if two containers had the elements with duplicate keys but in different order. - QLocale: * [QTBUG-59159] Fixed the parsing of day-of-week names that start with the name of another day. - QObject: * [QTBUG-59500] disconnectNotify() is now called when a connection is disconnected using its QMetaObject::Connection handle. * [QTBUG-52439] Fixed a bug that would cause applications compiled with the Intel compiler to fail to connect signals and slots. - QUrl: * [QTBUG-60364] Fixed a bug that caused certain domain names that look like Internationalized Domain Names to become corrupt in decoded forms of QUrl, notably toString() and toDisplayString(). * Updated the table of valid top level domains - QVarLengthArray: * Fixed a bug involving appending an item already in the container to the container again. * [QTBUG-57277] Fixed a crash when initializing the array with an empty std::initializer_list. QtSql ----- - MySql * Fixed the build of MySql plugin with MySql 5.0 * [QTBUG-53397] Fixed the parsing of tinyint(1) when used via prepared statements. - PostgreSQL: * [QTBUG-59524] Fixed datetime formats when the system locale doesn't use arabic numerals QtDBus ------ - QDBusServer * [QTBUG-55087] Fixed a bug causing certain messages that arrive soon after the client connects not to be processed. QtNetwork --------- - QNetworkInterface * Fixed the reporting of virtual interfaces on Linux. - QSslSocket * [QTBUG-43388][QTBUG-55170] Fixed a bug that caused the read buffer's max size not to be respected when using SecureTransport * [QTBUG-49554] Made sure that the QSslConfiguration is up-to-date when the QNetworkReply::encrypted() signal is emitted. QtGui ----- - Various fixes to our high DPI support. - CSS parser: * [QTBUG-53919] Fixed a crash while parsing malformed CSS. - PDF writer: * [QTBUG-56489] Monochrome images are now handled correctly. - QImage: * Fixed a crash when rendering to GrayScale8 images. * [QTBUG-56252] Fixed an illegal memory access when rotating images. * [QTBUG-59211] Improved rejection of corrupt images with invalid header info. - QMatrix4x4: * operator*=() now calculates the correct result even if the RHS and LHS are the same object. - QPainter * [QTBUG-14614] Fixed a read-after-free when using gradients. * [QTBUG-56969] Fixed painting artifacts for certain dashed lines. - Text: * [QTBUG-55222] Always return a correct list of fallback fonts * [QTBUG-55255][QTBUG-56714] Trailing whitespace are now properly taken into account when shaping lines * [QTBUG-53911] Fixed a crash that could happen if you were doing many different text layouts with different fonts and superscript or subscript alignment. * [QTBUG-56659] Fixed a regression where raster fonts on Windows were detected as smoothly scalable and thus rendering with said fonts in Qt Quick would break. * [QTBUG-51223] Fixed synthesized oblique for non-latin text on platforms using the basic font database, such as Android. * [QTBUG-56714] Fixed a bug where a no-break space would sometimes cause the first character of the containing line to not be displayed. * [QTBUG-48005] Fixed clipping errors and too small bounding rects for some right-to-left text. * [QTBUG-57241] Fixed a crash for very tall glyphs. * [QTBUG-55569] Fixed Myanmar rendering with some fonts. * [QTBUG-56659] Fixed the reporting of whether fonts are smoothly scalable on Windows. * [QTBUG-58364][QTBUG-42074][QTBUG-57003] Formatting characters are now accepted as valid input. QtWidgets --------- - Input: * [QTBUG-42074][QTBUG-57003] Characters in Private Use Area, as well as zero-width joiners and zero-width non-joiners are now accepted as input in QLineEdit and QTextEdit. - QDockWidget: * [QTBUG-7460][QTBUG-52354] Size of widgets no longer changed just because they are in a floating dock. * [QTBUG-58036] Dock widgets now have the correct parent after a drag. * [QTBUG-58049] Fixed clearing the dock indicator when not over a floating dock group window. - QMainWindow: * [QTBUG-56628] Fixed crash using takeCentralWidget when the central widget was not set. - QPixmapStyle: * Now handles progress bars with minimum != 0 correctly. - QPopup * [QTBUG-57292] Popups blocked by modal dialogs are now properly closed. - QTextEdit * [QTBUG-55758] Placeholder text is no longer shown while composing text. - QTooltip: * [QTBUG-55523] QTooltip is now properly hidden when a close event is received. * [QTBUG-55523] Tooltips no longer prevent closing of the app on lastWindowClosed() - QWidget: * [QTBUG-50589] Show and hide events are now properly sent to children on minimize/restore. * [QTBUG-53068] Fixed enter/leave events on popup menus. - Style sheets: * [QTBUG-55597] Now honors the font set on HeaderView section. ****************************************************************************** * Platform-specific Changes * ****************************************************************************** Android ------- - [QTBUG-44697] Removed old work-around which was causing OpenGL shader compilation to fail on updated Android emulators. Darwin ------ - [QTBUG-61034] QT_NO_EXCEPTIONS is now correctly set for Objective C++ source files. - [QTBUG-57165] Made QDir::tempPath() return the same directory as NSTemporaryDirectory, instead of a hardcoded "/tmp". - [QTBUG-55896] Fixed a bug that would cause QFileSystemWatcher to fail to watch certain paths containing non-ASCII characters. - [QTBUG-56124] Fixed a bug that would cause data corruption in QSettings when storing QStrings containing NULs, when storing to native format. - iOS specific: * Starting from iOS 10, Apple requires all apps that need access to photos to have the key 'NSPhotoLibraryUsageDescription' in the Info.plist. Therefore, to get the same support in Qt (when, e.g., using a file dialog), the Info.plist assigned to QMAKE_INFO_PLIST will need this key as well. * [QTBUG-49893] The shortcuts bar on iPad is now hidden when showing menus. - macOS specific: * Speech to text dictation now works for Qt text input. * Various bug fixes to menu bar handling. QNX --- - Qt can now handle more than 256 file descriptors open in the same process, up to a limit of 1000. WinRT ----- - Various fixes in our event and timer handling. X11 --- - [QTBUG-55942] Qt::WindowNoState event is no longer sent when hiding minimized windows. - [QTBUG-49645] Fixed keyboard modifier state for drops from external apps. - [QTBUG-48795] Fixed the keyboard state when processing key events. ****************************************************************************** * Compiler Specific Changes * ****************************************************************************** Visual Studio ------------- - Visual Studio 2017 is now supported. - [QTBUG-56594] PDB files are now properly generated even for static builds. ****************************************************************************** * Tools * ****************************************************************************** configure --------- - Fixed builds that explicitly asked for -sdk iphoneos. - [QTBUG-56388] Fixed the detection of the Microsoft compiler version when the CL environment variable was set or when the compiler was configured to another language (other than English). qmake ----- - [QTBUG-55505] Fixed an issue with iOS when the project path had a whitespace. - [QTBUG-56289] When cross-compiling on Windows to Unix targets, qmake no longer generates chmod calls. - [QTBUG-53905] Fixed qmake not to run moc twice on Objective C++ sources listed in the OBJECTIVE_SOURCES variable. - [QTBUG-56507] Fixed builds where a lex source refers to a file generated by yacc. - [QTBUG-57090][Darwin] Fixed the installation of asset catalog files. qdbusxml2cpp ------------ - [QTBUG-21577] Fixed the generation of signals when the direction argument was inverted from expected. '>163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the qmake application of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "unixmake.h"
#include "option.h"
#include "meta.h"
#include <qregexp.h>
#include <qbytearray.h>
#include <qfile.h>
#include <qdir.h>
#include <qdebug.h>
#include <time.h>

QT_BEGIN_NAMESPACE

UnixMakefileGenerator::UnixMakefileGenerator() : MakefileGenerator(), include_deps(false)
{

}

void
UnixMakefileGenerator::writePrlFile(QTextStream &t)
{
    MakefileGenerator::writePrlFile(t);
    // libtool support
    if(project->isActiveConfig("create_libtool") && project->first("TEMPLATE") == "lib") { //write .la
        writeLibtoolFile();
    }
    // pkg-config support
    if(project->isActiveConfig("create_pc") && project->first("TEMPLATE") == "lib")
        writePkgConfigFile();
}

bool
UnixMakefileGenerator::writeMakefile(QTextStream &t)
{

    writeHeader(t);
    if (writeDummyMakefile(t))
        return true;

    if (project->first("TEMPLATE") == "app" ||
        project->first("TEMPLATE") == "lib" ||
        project->first("TEMPLATE") == "aux") {
        if(Option::mkfile::do_stub_makefile && MakefileGenerator::writeStubMakefile(t))
            return true;
        writeMakeParts(t);
        return MakefileGenerator::writeMakefile(t);
    } else if (project->first("TEMPLATE") == "subdirs") {
        MakefileGenerator::writeSubDirs(t);
        return true;
    }
    return false;
}

void
UnixMakefileGenerator::writeDefaultVariables(QTextStream &t)
{
    MakefileGenerator::writeDefaultVariables(t);
    t << "TAR           = " << var("QMAKE_TAR") << endl;
    t << "COMPRESS      = " << var("QMAKE_GZIP") << endl;

    if (project->isEmpty("QMAKE_DISTNAME")) {
        ProString distname = project->first("QMAKE_ORIG_TARGET");
        if (!project->isActiveConfig("no_dist_version"))
            distname += project->first("VERSION");
        project->values("QMAKE_DISTNAME") = distname;
    }
    t << "DISTNAME      = " << fileVar("QMAKE_DISTNAME") << endl;

    if (project->isEmpty("QMAKE_DISTDIR"))
        project->values("QMAKE_DISTDIR") = project->first("QMAKE_DISTNAME");
    t << "DISTDIR = " << escapeFilePath(fileFixify(
            (project->isEmpty("OBJECTS_DIR") ? ProString(".tmp/") : project->first("OBJECTS_DIR")) + project->first("QMAKE_DISTDIR"),
            FileFixifyFromOutdir | FileFixifyAbsolute)) << endl;
}

void
UnixMakefileGenerator::writeSubTargets(QTextStream &t, QList<MakefileGenerator::SubTarget*> targets, int flags)
{
    MakefileGenerator::writeSubTargets(t, targets, flags);

    t << "dist: distdir FORCE" << endl;
    t << "\t(cd `dirname $(DISTDIR)` && $(TAR) $(DISTNAME).tar $(DISTNAME) && $(COMPRESS) $(DISTNAME).tar)"
         " && $(MOVE) `dirname $(DISTDIR)`/$(DISTNAME).tar.gz . && $(DEL_FILE) -r $(DISTDIR)";
    t << endl << endl;

    t << "distdir:";
    for (int target = 0; target < targets.size(); ++target) {
        SubTarget *subtarget = targets.at(target);
        t << " " << subtarget->target << "-distdir";
    }
    t << " FORCE\n\t"
      << mkdir_p_asstring("$(DISTDIR)", false) << "\n\t"
      << "$(COPY_FILE) --parents " << fileVar("DISTFILES") << " $(DISTDIR)" << Option::dir_sep << endl << endl;

    const QString abs_source_path = project->first("QMAKE_ABSOLUTE_SOURCE_PATH").toQString();
    for (int target = 0; target < targets.size(); ++target) {
        SubTarget *subtarget = targets.at(target);
        QString in_directory = subtarget->in_directory;
        if (!in_directory.isEmpty() && !in_directory.endsWith(Option::dir_sep))
            in_directory += Option::dir_sep;
        QString out_directory = subtarget->out_directory;
        if (!out_directory.isEmpty() && !out_directory.endsWith(Option::dir_sep))
            out_directory += Option::dir_sep;
        if (!abs_source_path.isEmpty() && out_directory.startsWith(abs_source_path))
            out_directory = Option::output_dir + out_directory.mid(abs_source_path.length());

        QString dist_directory = out_directory;
        if (dist_directory.endsWith(Option::dir_sep))
            dist_directory.chop(Option::dir_sep.length());
        if (!dist_directory.startsWith(Option::dir_sep))
            dist_directory.prepend(Option::dir_sep);

        QString out_directory_cdin = out_directory.isEmpty() ? "\n\t"
                                                             : "\n\tcd " + escapeFilePath(out_directory) + " && ";
        QString makefilein = " -e -f " + escapeFilePath(subtarget->makefile)
                + " distdir DISTDIR=$(DISTDIR)" + escapeFilePath(dist_directory);

        QString out = subtarget->makefile;
        QString in = escapeFilePath(fileFixify(in_directory + subtarget->profile, FileFixifyAbsolute));
        if (out.startsWith(in_directory))
            out.remove(0, in_directory.length());

        t << subtarget->target << "-distdir: FORCE";
        writeSubTargetCall(t, in_directory, in, out_directory, escapeFilePath(out),
                           out_directory_cdin, makefilein);
        t << endl;
    }
}

static QString rfc1034Identifier(const QString &str)
{
    QString s = str;
    for (QChar &ch : s) {
        const char c = ch.toLatin1();

        const bool okChar = (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z')
                || (c >= 'a' && c <= 'z') || c == '-' || c == '.';
        if (!okChar)
            ch = QChar::fromLatin1('-');
    }
    return s;
}

void
UnixMakefileGenerator::writeMakeParts(QTextStream &t)
{
    bool do_incremental = (project->isActiveConfig("incremental") &&
                           !project->values("QMAKE_INCREMENTAL").isEmpty() &&
                           (!project->values("QMAKE_APP_FLAG").isEmpty() ||
                            (!project->isActiveConfig("staticlib")))),
         src_incremental=false;

    ProStringList &bundledFiles = project->values("QMAKE_BUNDLED_FILES");

    writeExportedVariables(t);

    t << "####### Compiler, tools and options\n\n";
    t << "CC            = " << var("QMAKE_CC") << endl;
    t << "CXX           = " << var("QMAKE_CXX") << endl;
    t << "DEFINES       = "
      << varGlue("PRL_EXPORT_DEFINES","-D"," -D"," ")
      << varGlue("DEFINES","-D"," -D","") << endl;
    t << "CFLAGS        = " << var("QMAKE_CFLAGS") << " $(DEFINES)\n";
    t << "CXXFLAGS      = " << var("QMAKE_CXXFLAGS") << " $(DEFINES)\n";
    t << "INCPATH       =";
    {
        QString isystem = var("QMAKE_CFLAGS_ISYSTEM");
        const ProStringList &incs = project->values("INCLUDEPATH");
        for(int i = 0; i < incs.size(); ++i) {
            const ProString &inc = incs.at(i);
            if (inc.isEmpty())
                continue;

            if (!isystem.isEmpty() && isSystemInclude(inc.toQString()))
                t << ' ' << isystem << ' ';
            else
                t << " -I";
            t << escapeFilePath(inc);
        }
    }
    if(!project->isEmpty("QMAKE_FRAMEWORKPATH_FLAGS"))
       t << " " << var("QMAKE_FRAMEWORKPATH_FLAGS");
    t << endl;

    writeDefaultVariables(t);

    if(!project->isActiveConfig("staticlib")) {
        t << "LINK          = " << var("QMAKE_LINK") << endl;
        t << "LFLAGS        = " << var("QMAKE_LFLAGS") << endl;
        t << "LIBS          = $(SUBLIBS) " << fixLibFlags("LIBS").join(' ') << ' '
                                           << fixLibFlags("LIBS_PRIVATE").join(' ') << ' '
                                           << fixLibFlags("QMAKE_LIBS").join(' ') << ' '
                                           << fixLibFlags("QMAKE_LIBS_PRIVATE").join(' ') << endl;
    }

    t << "AR            = " << var("QMAKE_AR") << endl;
    t << "RANLIB        = " << var("QMAKE_RANLIB") << endl;
    t << "SED           = " << var("QMAKE_STREAM_EDITOR") << endl;
    t << "STRIP         = " << var("QMAKE_STRIP") << endl;

    t << endl;

    t << "####### Output directory\n\n";
    // This is used in commands by some .prf files.
    if (! project->values("OBJECTS_DIR").isEmpty())
        t << "OBJECTS_DIR   = " << fileVar("OBJECTS_DIR") << endl;
    else
        t << "OBJECTS_DIR   = ./\n";
    t << endl;

    /* files */
    t << "####### Files\n\n";
    // This is used by the dist target.
    t << "SOURCES       = " << fileVarList("SOURCES") << ' ' << fileVarList("GENERATED_SOURCES") << endl;
    if(do_incremental) {
        const ProStringList &objs = project->values("OBJECTS");
        const ProStringList &incrs = project->values("QMAKE_INCREMENTAL");
        ProStringList incrs_out;
        t << "OBJECTS       = ";
        for (ProStringList::ConstIterator objit = objs.begin(); objit != objs.end(); ++objit) {
            bool increment = false;
            for (ProStringList::ConstIterator incrit = incrs.begin(); incrit != incrs.end(); ++incrit) {
                if ((*objit).toQString().indexOf(QRegExp((*incrit).toQString(), Qt::CaseSensitive,
                                                 QRegExp::Wildcard)) != -1) {
                    increment = true;
                    incrs_out.append((*objit));
                    break;
                }
            }
            if(!increment)
                t << "\\\n\t\t" << (*objit);
        }
        if(incrs_out.count() == objs.count()) { //we just switched places, no real incrementals to be done!
            t << escapeFilePaths(incrs_out).join(QString(" \\\n\t\t")) << endl;
        } else if(!incrs_out.count()) {
            t << endl;
        } else {
            src_incremental = true;
            t << endl;
            t << "INCREMENTAL_OBJECTS = "
              << escapeFilePaths(incrs_out).join(QString(" \\\n\t\t")) << endl;
        }
    } else {
        // Used all over the place in both deps and commands.
        t << "OBJECTS       = " << valList(escapeDependencyPaths(project->values("OBJECTS"))) << endl;
    }
    if(do_incremental && !src_incremental)
        do_incremental = false;
    t << "DIST          = " << valList(fileFixify(project->values("DISTFILES").toQStringList())) << " "
                            << fileVarList("HEADERS") << ' ' << fileVarList("SOURCES") << endl;
    t << "QMAKE_TARGET  = " << fileVar("QMAKE_ORIG_TARGET") << endl;
    QString destd = fileVar("DESTDIR");
    // When building on non-MSys MinGW, the path ends with a backslash, which
    // GNU make will interpret that as a line continuation. Doubling the backslash
    // avoids the problem, at the cost of the variable containing *both* backslashes.
    if (destd.endsWith('\\'))
        destd += '\\';
    t << "DESTDIR       = " << destd << endl;
    t << "TARGET        = " << fileVar("TARGET") << endl;
    if(project->isActiveConfig("plugin")) {
        t << "TARGETD       = " << fileVar("TARGET") << endl;
    } else if(!project->isActiveConfig("staticlib") && project->values("QMAKE_APP_FLAG").isEmpty()) {
        t << "TARGETA       = " << fileVar("TARGETA") << endl;
        if(!project->isEmpty("QMAKE_BUNDLE")) {
            t << "TARGETD       = " << fileVar("TARGET_x.y") << endl;
            t << "TARGET0       = " << fileVar("TARGET_") << endl;
        } else if (!project->isActiveConfig("unversioned_libname")) {
            t << "TARGET0       = " << fileVar("TARGET_") << endl;
            if (project->isEmpty("QMAKE_HPUX_SHLIB")) {
                t << "TARGETD       = " << fileVar("TARGET_x.y.z") << endl;
                t << "TARGET1       = " << fileVar("TARGET_x") << endl;
                t << "TARGET2       = " << fileVar("TARGET_x.y") << endl;
            } else {
                t << "TARGETD       = " << fileVar("TARGET_x") << endl;
            }
        }
    }
    writeExtraCompilerVariables(t);
    writeExtraVariables(t);
    t << endl;

    // blasted includes
    const ProStringList &qeui = project->values("QMAKE_EXTRA_INCLUDES");
    ProStringList::ConstIterator it;
    for(it = qeui.begin(); it != qeui.end(); ++it)
        t << "include " << escapeDependencyPath(*it) << endl;

    /* rules */
    t << "first:" << (!project->isActiveConfig("no_default_goal_deps") ? " all" : "") << "\n";

    if(include_deps) {
        if (project->isActiveConfig("gcc_MD_depends")) {
            ProStringList objects = project->values("OBJECTS");
            for (ProStringList::Iterator it = objects.begin(); it != objects.end(); ++it) {
                QString d_file = (*it).toQString().replace(QRegExp(Option::obj_ext + "$"), ".d");
                t << "-include " << escapeDependencyPath(d_file) << endl;
                project->values("QMAKE_DISTCLEAN") << d_file;
            }
        } else {
            QString cmd=var("QMAKE_CFLAGS_DEPS") + " ";
            cmd += varGlue("DEFINES","-D"," -D","") + varGlue("PRL_EXPORT_DEFINES"," -D"," -D","");
            if(!project->isEmpty("QMAKE_ABSOLUTE_SOURCE_PATH"))
                cmd += " -I" + fileVar("QMAKE_ABSOLUTE_SOURCE_PATH") + ' ';
            cmd += " $(INCPATH) " + fileVarGlue("DEPENDPATH", "-I", " -I", "");
            ProString odir;
            if(!project->values("OBJECTS_DIR").isEmpty())
                odir = project->first("OBJECTS_DIR");
            QString odird = escapeDependencyPath(odir.toQString());

            QString pwd = escapeFilePath(fileFixify(qmake_getpwd()));

            t << "###### Dependencies\n\n";
            t << odird << ".deps/%.d: " << pwd << "/%.cpp\n\t";
            if(project->isActiveConfig("echo_depend_creation"))
                t << "@echo Creating depend for $<\n\t";
            t << mkdir_p_asstring("$(@D)", false) << "\n\t"
              << "@$(CXX) " << cmd << " $< | sed \"s,^\\($(*F).o\\):," << odir << "\\1:,g\" >$@\n\n";

            t << odird << ".deps/%.d: " << pwd << "/%.c\n\t";
            if(project->isActiveConfig("echo_depend_creation"))
                t << "@echo Creating depend for $<\n\t";
            t << mkdir_p_asstring("$(@D)", false) << "\n\t"
              << "@$(CC) " << cmd << " $< | sed \"s,^\\($(*F).o\\):," << odir << "\\1:,g\" >$@\n\n";

            static const char * const src[] = { "SOURCES", "GENERATED_SOURCES", nullptr };
            for (int x = 0; src[x]; x++) {
                const ProStringList &l = project->values(src[x]);
                for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it) {
                    if(!(*it).isEmpty()) {
                        QString d_file;
                        for(QStringList::Iterator cit = Option::c_ext.begin();
                            cit != Option::c_ext.end(); ++cit) {
                            if((*it).endsWith((*cit))) {
                                d_file = (*it).left((*it).length() - (*cit).length()).toQString();
                                break;
                            }
                        }
                        if(d_file.isEmpty()) {
                            for(QStringList::Iterator cppit = Option::cpp_ext.begin();
                                cppit != Option::cpp_ext.end(); ++cppit) {
                                if((*it).endsWith((*cppit))) {
                                    d_file = (*it).left((*it).length() - (*cppit).length()).toQString();
                                    break;
                                }
                            }
                        }

                        if(!d_file.isEmpty()) {
                            d_file = odir + ".deps/" + fileFixify(d_file, FileFixifyBackwards) + ".d";
                            QString d_file_d = escapeDependencyPath(d_file);
                            QStringList deps = findDependencies((*it).toQString()).filter(QRegExp(
                                        "((^|/)" + Option::h_moc_mod + "|" + Option::cpp_moc_ext + "$)"));
                            if(!deps.isEmpty())
                                t << d_file_d << ": " << finalizeDependencyPaths(deps).join(' ') << endl;
                            t << "-include " << d_file_d << endl;
                            project->values("QMAKE_DISTCLEAN") += d_file;
                        }
                    }
                }
            }
        }
    }

    t << "####### Build rules\n\n";
    if(!project->values("SUBLIBS").isEmpty()) {
        ProString libdir = "tmp/";
        if(!project->isEmpty("SUBLIBS_DIR"))
            libdir = project->first("SUBLIBS_DIR");
        t << "SUBLIBS       = ";
        const ProStringList &l = project->values("SUBLIBS");
        for (ProStringList::ConstIterator it = l.begin(); it != l.end(); ++it)
            t << escapeFilePath(libdir + project->first("QMAKE_PREFIX_STATICLIB") + (*it) + '.'
                                + project->first("QMAKE_EXTENSION_STATICLIB")) << ' ';
        t << endl << endl;
    }
    QString target_deps;
    if ((project->isActiveConfig("depend_prl") || project->isActiveConfig("fast_depend_prl"))
        && !project->isEmpty("QMAKE_PRL_INTERNAL_FILES")) {
        const ProStringList &l = project->values("QMAKE_PRL_INTERNAL_FILES");
        ProStringList::ConstIterator it;
        for(it = l.begin(); it != l.end(); ++it) {
            QMakeMetaInfo libinfo;
            if (libinfo.readLib((*it).toQString()) && !libinfo.isEmpty("QMAKE_PRL_BUILD_DIR")) {
                ProString dir;
                int slsh = (*it).lastIndexOf(Option::dir_sep);
                if(slsh != -1)
                    dir = (*it).left(slsh + 1);
                QString targ = dir + libinfo.first("QMAKE_PRL_TARGET");
                QString targ_d = escapeDependencyPath(targ);
                target_deps += ' ' + targ_d;
                t << targ_d;
                if (project->isActiveConfig("fast_depend_prl"))
                    t << ":\n\t@echo \"Creating '";
                else
                    t << ": FORCE\n\t@echo \"Creating/updating '";
                t << targ << "'\"\n\t"
                  << "(cd " << escapeFilePath(libinfo.first("QMAKE_PRL_BUILD_DIR")) << ';'
                  << "$(MAKE))\n";
            }
        }
    }
    QString deps = escapeDependencyPath(fileFixify(Option::output.fileName()));
    QString allDeps;
    if (!project->values("QMAKE_APP_FLAG").isEmpty() || project->first("TEMPLATE") == "aux") {
        QString destdir = project->first("DESTDIR").toQString();
        if(!project->isEmpty("QMAKE_BUNDLE")) {
            QString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION").toQString();
            if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/"))
                bundle_loc.prepend("/");
            if(!bundle_loc.endsWith("/"))
                bundle_loc += "/";
            destdir += project->first("QMAKE_BUNDLE") + bundle_loc;
        }
        if(do_incremental) {
            //incremental target
            QString incr_target = var("TARGET") + "_incremental";
            if(incr_target.indexOf(Option::dir_sep) != -1)
                incr_target = incr_target.right(incr_target.length() -
                                                (incr_target.lastIndexOf(Option::dir_sep) + 1));
            QString incr_deps, incr_objs;
            if(project->first("QMAKE_INCREMENTAL_STYLE") == "ld") {
                QString incr_target_dir = var("OBJECTS_DIR") + incr_target + Option::obj_ext;
                QString incr_target_dir_d = escapeDependencyPath(incr_target_dir);
                QString incr_target_dir_f = escapeFilePath(incr_target_dir);
                //actual target
                t << incr_target_dir_d << ": $(OBJECTS)\n\t"
                  << "ld -r  -o " << incr_target_dir_f << " $(OBJECTS)\n";
                //communicated below
                deps.prepend(incr_target_dir_d + ' ');
                incr_deps = "$(INCREMENTAL_OBJECTS)";
                if(!incr_objs.isEmpty())
                    incr_objs += " ";
                incr_objs += incr_target_dir_f;
            } else {
                //actual target
                QString incr_target_dir = var("DESTDIR") + "lib" + incr_target + "." +
                                          project->first("QMAKE_EXTENSION_SHLIB");
                QString incr_target_dir_d = escapeDependencyPath(incr_target_dir);
                QString incr_target_dir_f = escapeFilePath(incr_target_dir);
                QString incr_lflags = var("QMAKE_LFLAGS_SHLIB") + " ";
                if(project->isActiveConfig("debug"))
                    incr_lflags += var("QMAKE_LFLAGS_DEBUG");
                else if (project->isActiveConfig("debug_info"))
                    incr_lflags += var("QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO");
                else
                    incr_lflags += var("QMAKE_LFLAGS_RELEASE");
                t << incr_target_dir_d << ": $(INCREMENTAL_OBJECTS)\n\t";
                if(!destdir.isEmpty())
                    t << "\n\t" << mkdir_p_asstring(destdir) << "\n\t";
                t << "$(LINK) " << incr_lflags << " -o "<< incr_target_dir_f <<
                    " $(INCREMENTAL_OBJECTS)\n";
                //communicated below
                if(!destdir.isEmpty()) {
                    if(!incr_objs.isEmpty())
                        incr_objs += " ";
                    incr_objs += "-L" + escapeFilePath(destdir);
                } else {
                    if(!incr_objs.isEmpty())
                        incr_objs += " ";
                    incr_objs += "-L" + escapeFilePath(qmake_getpwd());
                }
                if(!incr_objs.isEmpty())
                    incr_objs += " ";
                incr_objs += " -l" + escapeFilePath(incr_target);
                deps.prepend(incr_target_dir_d + ' ');
                incr_deps = "$(OBJECTS)";
            }

            //real target
            t << var("TARGET") << ": " << depVar("PRE_TARGETDEPS") << ' ' << incr_deps << ' ' << target_deps
              << ' ' << depVar("POST_TARGETDEPS") << "\n\t";
            if(!destdir.isEmpty())
                t << "\n\t" << mkdir_p_asstring(destdir) << "\n\t";
            if(!project->isEmpty("QMAKE_PRE_LINK"))
                t << var("QMAKE_PRE_LINK") << "\n\t";
            t << "$(LINK) $(LFLAGS) " << var("QMAKE_LINK_O_FLAG") << "$(TARGET) " << incr_deps << " " << incr_objs << " $(OBJCOMP) $(LIBS)";
            if(!project->isEmpty("QMAKE_POST_LINK"))
                t << "\n\t" << var("QMAKE_POST_LINK");
            t << endl << endl;
        } else {
            t << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) "
              << target_deps << ' ' << depVar("POST_TARGETDEPS") << "\n\t";
            if (project->first("TEMPLATE") != "aux") {
                if (!destdir.isEmpty())
                    t << mkdir_p_asstring(destdir) << "\n\t";
                if (!project->isEmpty("QMAKE_PRE_LINK"))
                    t << var("QMAKE_PRE_LINK") << "\n\t";
                t << "$(LINK) $(LFLAGS) " << var("QMAKE_LINK_O_FLAG") << "$(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)";
                if (!project->isEmpty("QMAKE_POST_LINK"))
                    t << "\n\t" << var("QMAKE_POST_LINK");
            }
            t << endl << endl;
        }
        allDeps = ' ' + depVar("TARGET");
    } else if(!project->isActiveConfig("staticlib")) {
        QString destdir_r = project->first("DESTDIR").toQString(), incr_deps;
        if(!project->isEmpty("QMAKE_BUNDLE")) {
            QString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION").toQString();
            if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/"))
                bundle_loc.prepend("/");
            if(!bundle_loc.endsWith("/"))
                bundle_loc += "/";
            destdir_r += project->first("QMAKE_BUNDLE") + bundle_loc;
        }
        QString destdir_d = escapeDependencyPath(destdir_r);
        QString destdir = escapeFilePath(destdir_r);

        if(do_incremental) {
            ProString s_ext = project->first("QMAKE_EXTENSION_SHLIB");
            QString incr_target = var("QMAKE_ORIG_TARGET").replace(
                QRegExp("\\." + s_ext), "").replace(QRegExp("^lib"), "") + "_incremental";
            if(incr_target.indexOf(Option::dir_sep) != -1)
                incr_target = incr_target.right(incr_target.length() -
                                                (incr_target.lastIndexOf(Option::dir_sep) + 1));

            if(project->first("QMAKE_INCREMENTAL_STYLE") == "ld") {
                QString incr_target_dir = var("OBJECTS_DIR") + incr_target + Option::obj_ext;
                QString incr_target_dir_d = escapeDependencyPath(incr_target_dir);
                QString incr_target_dir_f = escapeFilePath(incr_target_dir);
                //actual target
                const QString link_deps = "$(OBJECTS) ";
                t << incr_target_dir_d << ": " << link_deps << "\n\t"
                  << "ld -r  -o " << incr_target_dir_f << ' ' << link_deps << endl;
                //communicated below
                ProStringList &cmd = project->values("QMAKE_LINK_SHLIB_CMD");
                cmd[0] = cmd.at(0).toQString().replace(QLatin1String("$(OBJECTS) "), QLatin1String("$(INCREMENTAL_OBJECTS)")); //ick
                cmd.append(incr_target_dir_f);
                deps.prepend(incr_target_dir_d + ' ');
                incr_deps = "$(INCREMENTAL_OBJECTS)";
            } else {
                //actual target
                QString incr_target_dir = destdir_r + "lib" + incr_target + '.' + s_ext;
                QString incr_target_dir_d = escapeDependencyPath(incr_target_dir);
                QString incr_target_dir_f = escapeFilePath(incr_target_dir);
                QString incr_lflags = var("QMAKE_LFLAGS_SHLIB") + " ";
                if(!project->isEmpty("QMAKE_LFLAGS_INCREMENTAL"))
                    incr_lflags += var("QMAKE_LFLAGS_INCREMENTAL") + " ";
                if(project->isActiveConfig("debug"))
                    incr_lflags += var("QMAKE_LFLAGS_DEBUG");
                else if (project->isActiveConfig("debug_info"))
                    incr_lflags += var("QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO");
                else
                    incr_lflags += var("QMAKE_LFLAGS_RELEASE");
                t << incr_target_dir_d << ": $(INCREMENTAL_OBJECTS)\n\t";
                if(!destdir.isEmpty())
                    t << mkdir_p_asstring(destdir, false) << "\n\t";
                t << "$(LINK) " << incr_lflags << ' ' << var("QMAKE_LINK_O_FLAG") << incr_target_dir_f <<
                    " $(INCREMENTAL_OBJECTS)\n";
                //communicated below
                ProStringList &cmd = project->values("QMAKE_LINK_SHLIB_CMD");
                if(!destdir.isEmpty())
                    cmd.append(" -L" + destdir);
                cmd.append(" -l" + escapeFilePath(incr_target));
                deps.prepend(incr_target_dir_d + ' ');
                incr_deps = "$(OBJECTS)";
            }

            //real target
            t << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS") << ' '
              << incr_deps << " $(SUBLIBS) " << target_deps << ' ' << depVar("POST_TARGETDEPS");
        } else {
            t << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS")
              << " $(OBJECTS) $(SUBLIBS) $(OBJCOMP) " << target_deps
              << ' ' << depVar("POST_TARGETDEPS");
        }
        allDeps = ' ' + destdir_d + depVar("TARGET");
        if(!destdir.isEmpty())
            t << "\n\t" << mkdir_p_asstring(destdir, false);
        if(!project->isEmpty("QMAKE_PRE_LINK"))
            t << "\n\t" << var("QMAKE_PRE_LINK");

        if (project->isActiveConfig("plugin")) {
            t << "\n\t"
              << "-$(DEL_FILE) $(TARGET)\n\t"
              << var("QMAKE_LINK_SHLIB_CMD");
            if(!destdir.isEmpty())
                t << "\n\t"
                  << "-$(MOVE) $(TARGET) " << destdir << "$(TARGET)";
            if(!project->isEmpty("QMAKE_POST_LINK"))
                t << "\n\t" << var("QMAKE_POST_LINK");
            t << endl << endl;
        } else if(!project->isEmpty("QMAKE_BUNDLE")) {
            bundledFiles << destdir_r + var("TARGET");
            t << "\n\t"
              << "-$(DEL_FILE) $(TARGET) $(TARGET0) $(DESTDIR)$(TARGET0)\n\t"
              << var("QMAKE_LINK_SHLIB_CMD") << "\n\t"
              << mkdir_p_asstring("\"`dirname $(DESTDIR)$(TARGETD)`\"", false) << "\n\t"
              << "-$(MOVE) $(TARGET) $(DESTDIR)$(TARGETD)\n\t"
              << mkdir_p_asstring("\"`dirname $(DESTDIR)$(TARGET0)`\"", false) << "\n\t";
            if (!project->isActiveConfig("shallow_bundle"))
                t << varGlue("QMAKE_LN_SHLIB", "-", " ",
                             " Versions/Current/$(TARGET) $(DESTDIR)$(TARGET0)") << "\n\t";
            if(!project->isEmpty("QMAKE_POST_LINK"))
                t << "\n\t" << var("QMAKE_POST_LINK");
            t << endl << endl;
        } else if(project->isEmpty("QMAKE_HPUX_SHLIB")) {
            t << "\n\t";

            if (!project->isActiveConfig("unversioned_libname"))
                t << "-$(DEL_FILE) $(TARGET) $(TARGET0) $(TARGET1) $(TARGET2)";
            else
                t << "-$(DEL_FILE) $(TARGET)";

            t << "\n\t" << var("QMAKE_LINK_SHLIB_CMD");

            if (!project->isActiveConfig("unversioned_libname")) {
                t << "\n\t"
                  << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET0)") << "\n\t"
                  << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET1)") << "\n\t"
                  << varGlue("QMAKE_LN_SHLIB","-"," "," $(TARGET) $(TARGET2)");
            }
            if (!destdir.isEmpty()) {
                t << "\n\t"
                  << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t"
                  << "-$(MOVE) $(TARGET) " << destdir << "$(TARGET)";

                if (!project->isActiveConfig("unversioned_libname")) {
                    t << "\n\t"
                      << "-$(DEL_FILE) " << destdir << "$(TARGET0)\n\t"
                      << "-$(DEL_FILE) " << destdir << "$(TARGET1)\n\t"
                      << "-$(DEL_FILE) " << destdir << "$(TARGET2)\n\t"
                      << "-$(MOVE) $(TARGET0) " << destdir << "$(TARGET0)\n\t"
                      << "-$(MOVE) $(TARGET1) " << destdir << "$(TARGET1)\n\t"
                      << "-$(MOVE) $(TARGET2) " << destdir << "$(TARGET2)";
                }
            }
            if(!project->isEmpty("QMAKE_POST_LINK"))
                t << "\n\t" << var("QMAKE_POST_LINK");
            t << endl << endl;
        } else {
            t << "\n\t"
              << "-$(DEL_FILE) $(TARGET) $(TARGET0)\n\t"
              << var("QMAKE_LINK_SHLIB_CMD") << "\n\t";
            t << varGlue("QMAKE_LN_SHLIB",""," "," $(TARGET) $(TARGET0)");
            if(!destdir.isEmpty())
                t  << "\n\t"
                   << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t"
                   << "-$(DEL_FILE) " << destdir << "$(TARGET0)\n\t"
                   << "-$(MOVE) $(TARGET) " << destdir << "$(TARGET)\n\t"
                   << "-$(MOVE) $(TARGET0) " << destdir << "$(TARGET0)\n\t";
            if(!project->isEmpty("QMAKE_POST_LINK"))
                t << "\n\t" << var("QMAKE_POST_LINK");
            t << endl << endl;
        }
        t << endl << endl;

        if (! project->isActiveConfig("plugin")) {
            t << "staticlib: " << depVar("TARGETA") << "\n\n";
            t << depVar("TARGETA") << ": " << depVar("PRE_TARGETDEPS") << " $(OBJECTS) $(OBJCOMP)";
            if(do_incremental)
                t << " $(INCREMENTAL_OBJECTS)";
            t << ' ' << depVar("POST_TARGETDEPS") << "\n\t";
            if (!project->isEmpty("QMAKE_PRE_LINK"))
                t << var("QMAKE_PRE_LINK") << "\n\t";
            t << "-$(DEL_FILE) $(TARGETA) \n\t"
              << var("QMAKE_AR_CMD");
            if(do_incremental)
                t << " $(INCREMENTAL_OBJECTS)";
            if (!project->isEmpty("QMAKE_POST_LINK"))
                t << "\n\t" << var("QMAKE_POST_LINK");
            if(!project->isEmpty("QMAKE_RANLIB"))
                t << "\n\t$(RANLIB) $(TARGETA)";
            t << endl << endl;
        }
    } else {
        QString destdir_r = project->first("DESTDIR").toQString();
        QString destdir_d = escapeDependencyPath(destdir_r);
        QString destdir = escapeFilePath(destdir_r);
        allDeps = ' ' + destdir_d + depVar("TARGET");
        t << "staticlib: " << destdir_d << "$(TARGET)\n\n"
          << destdir_d << depVar("TARGET") << ": " << depVar("PRE_TARGETDEPS")
          << " $(OBJECTS) $(OBJCOMP) " << depVar("POST_TARGETDEPS") << "\n\t";
        if (!destdir.isEmpty())
            t << mkdir_p_asstring(destdir, false) << "\n\t";
        if (!project->isEmpty("QMAKE_PRE_LINK"))
            t << var("QMAKE_PRE_LINK") << "\n\t";
        t << "-$(DEL_FILE) " << destdir << "$(TARGET)\n\t"
          << var("QMAKE_AR_CMD") << "\n";
        if (!project->isEmpty("QMAKE_POST_LINK"))
            t << "\t" << var("QMAKE_POST_LINK") << "\n";
        if (!project->isEmpty("QMAKE_RANLIB"))
            t << "\t$(RANLIB) " << destdir << "$(TARGET)\n";
        t << endl << endl;
    }

    writeMakeQmake(t);
    if(project->isEmpty("QMAKE_FAILED_REQUIREMENTS") && !project->isActiveConfig("no_autoqmake")) {
        QStringList meta_files;
        if (project->isActiveConfig("create_libtool") && project->first("TEMPLATE") == "lib") { //libtool
            meta_files += libtoolFileName();
        }
        if(project->isActiveConfig("create_pc") && project->first("TEMPLATE") == "lib") { //pkg-config
            meta_files += pkgConfigFileName();
        }
        if(!meta_files.isEmpty())
            t << escapeDependencyPaths(meta_files).join(" ") << ": \n\t"
              << "@$(QMAKE) -prl " << escapeFilePath(project->projectFile()) << ' ' << buildArgs(true) << endl;
    }

    if (!project->isEmpty("QMAKE_BUNDLE")) {
        QHash<QString, QString> symlinks;
        ProStringList &alldeps = project->values("ALL_DEPS");
        QString bundle_dir = project->first("DESTDIR") + project->first("QMAKE_BUNDLE") + "/";
        if (!project->first("QMAKE_PKGINFO").isEmpty()) {
            ProString pkginfo = project->first("QMAKE_PKGINFO");
            ProString pkginfo_f = escapeFilePath(pkginfo);
            ProString pkginfo_d = escapeDependencyPath(pkginfo);
            bundledFiles << pkginfo;
            alldeps << pkginfo;
            QString destdir = bundle_dir + "Contents";
            t << pkginfo_d << ": \n\t";
            if (!destdir.isEmpty())
                t << mkdir_p_asstring(destdir) << "\n\t";
            t << "@$(DEL_FILE) " << pkginfo_f << "\n\t"
              << "@echo \"APPL"
              << (project->isEmpty("QMAKE_PKGINFO_TYPEINFO")
                  ? QString::fromLatin1("????") : project->first("QMAKE_PKGINFO_TYPEINFO").left(4))
              << "\" > " << pkginfo_f << endl;
        }
        if (!project->first("QMAKE_BUNDLE_RESOURCE_FILE").isEmpty()) {
            ProString resources = project->first("QMAKE_BUNDLE_RESOURCE_FILE");
            ProString resources_f = escapeFilePath(resources);
            ProString resources_d = escapeDependencyPath(resources);
            bundledFiles << resources;
            alldeps << resources;
            QString destdir = bundle_dir + "Contents/Resources";
            t << resources_d << ": \n\t";
            t << mkdir_p_asstring(destdir) << "\n\t";
            t << "@touch " << resources_f << "\n\t\n";
        }
        //copy the plist
        while (!project->isActiveConfig("no_plist")) {  // 'while' just to be able to 'break'
            QString info_plist = project->first("QMAKE_INFO_PLIST").toQString();
            if (info_plist.isEmpty()) {
                info_plist = escapeFilePath(specdir() + QDir::separator() + "Info.plist." + project->first("TEMPLATE"));
            } else if (!exists(Option::normalizePath(info_plist))) {
                warn_msg(WarnLogic, "Could not resolve Info.plist: '%s'. Check if QMAKE_INFO_PLIST points to a valid file.",
                         info_plist.toLatin1().constData());
                break;
            } else {
                info_plist = escapeFilePath(fileFixify(info_plist));
            }
            bool isFramework = project->first("TEMPLATE") == "lib"
                && !project->isActiveConfig("plugin")
                && project->isActiveConfig("lib_bundle");
            bool isShallowBundle = project->isActiveConfig("shallow_bundle");
            QString info_plist_out = bundle_dir +
                (!isShallowBundle
                    ? (isFramework
                        ? ("Versions/" + project->first("QMAKE_FRAMEWORK_VERSION") + "/Resources/")
                        : "Contents/")
                    : QString())
                + "Info.plist";
            bundledFiles << info_plist_out;
            alldeps << info_plist_out;
            QString destdir = info_plist_out.section(Option::dir_sep, 0, -2);
            t << escapeDependencyPath(info_plist_out) << ": \n\t";
            info_plist_out = escapeFilePath(info_plist_out);
            if (!destdir.isEmpty())
                t << mkdir_p_asstring(destdir) << "\n\t";
            ProStringList commonSedArgs;
            if (!project->values("VERSION").isEmpty()) {
                const ProString shortVersion =
                    project->first("VER_MAJ") + "." +
                    project->first("VER_MIN");
                commonSedArgs << "-e \"s,@SHORT_VERSION@," << shortVersion << ",g\" ";
                commonSedArgs << "-e \"s,\\$${QMAKE_SHORT_VERSION}," << shortVersion << ",g\" ";
                const ProString fullVersion =
                    project->first("VER_MAJ") + "." +
                    project->first("VER_MIN") + "." +
                    project->first("VER_PAT");
                commonSedArgs << "-e \"s,@FULL_VERSION@," << fullVersion << ",g\" ";
                commonSedArgs << "-e \"s,\\$${QMAKE_FULL_VERSION}," << fullVersion << ",g\" ";
            }
            const ProString typeInfo = project->isEmpty("QMAKE_PKGINFO_TYPEINFO")
                ? QString::fromLatin1("????")
                : project->first("QMAKE_PKGINFO_TYPEINFO").left(4);
            commonSedArgs << "-e \"s,@TYPEINFO@," << typeInfo << ",g\" ";
            commonSedArgs << "-e \"s,\\$${QMAKE_PKGINFO_TYPEINFO}," << typeInfo << ",g\" ";

            QString bundlePrefix = project->first("QMAKE_TARGET_BUNDLE_PREFIX").toQString();
            if (bundlePrefix.isEmpty())
                bundlePrefix = "com.yourcompany";
            if (bundlePrefix.endsWith("."))
                bundlePrefix.chop(1);
            QString bundleIdentifier =  bundlePrefix + "." + var("QMAKE_BUNDLE");
            if (bundleIdentifier.endsWith(".app"))
                bundleIdentifier.chop(4);
            if (bundleIdentifier.endsWith(".framework"))
                bundleIdentifier.chop(10);
            // replace invalid bundle id characters
            bundleIdentifier = rfc1034Identifier(bundleIdentifier);
            commonSedArgs << "-e \"s,@BUNDLEIDENTIFIER@," << bundleIdentifier << ",g\" ";
            commonSedArgs << "-e \"s,\\$${PRODUCT_BUNDLE_IDENTIFIER}," << bundleIdentifier << ",g\" ";

            commonSedArgs << "-e \"s,\\$${MACOSX_DEPLOYMENT_TARGET},"
                          << project->first("QMAKE_MACOSX_DEPLOYMENT_TARGET").toQString() << ",g\" ";
            commonSedArgs << "-e \"s,\\$${IPHONEOS_DEPLOYMENT_TARGET},"
                          << project->first("QMAKE_IPHONEOS_DEPLOYMENT_TARGET").toQString() << ",g\" ";
            commonSedArgs << "-e \"s,\\$${TVOS_DEPLOYMENT_TARGET},"
                          << project->first("QMAKE_TVOS_DEPLOYMENT_TARGET").toQString() << ",g\" ";
            commonSedArgs << "-e \"s,\\$${WATCHOS_DEPLOYMENT_TARGET},"
                          << project->first("QMAKE_WATCHOS_DEPLOYMENT_TARGET").toQString() << ",g\" ";

            if (!isFramework) {
                ProString app_bundle_name = var("QMAKE_APPLICATION_BUNDLE_NAME");
                if (app_bundle_name.isEmpty())
                    app_bundle_name = var("QMAKE_ORIG_TARGET");

                ProString plugin_bundle_name = var("QMAKE_PLUGIN_BUNDLE_NAME");
                if (plugin_bundle_name.isEmpty())
                    plugin_bundle_name = var("QMAKE_ORIG_TARGET");

                QString icon = fileFixify(var("ICON"));
                t << "@$(DEL_FILE) " << info_plist_out << "\n\t"
                  << "@sed ";
                for (const ProString &arg : qAsConst(commonSedArgs))
                    t << arg;
                const QString iconName = icon.section(Option::dir_sep, -1);
                t << "-e \"s,@ICON@," << iconName << ",g\" "
                  << "-e \"s,\\$${ASSETCATALOG_COMPILER_APPICON_NAME}," << iconName << ",g\" "
                  << "-e \"s,@EXECUTABLE@," << app_bundle_name << ",g\" "
                  << "-e \"s,@LIBRARY@," << plugin_bundle_name << ",g\" "
                  << "-e \"s,\\$${EXECUTABLE_NAME}," << (app_bundle_name.isEmpty() ? app_bundle_name : plugin_bundle_name) << ",g\" "
                  << "-e \"s,@TYPEINFO@,"<< typeInfo << ",g\" "
                  << "-e \"s,\\$${QMAKE_PKGINFO_TYPEINFO},"<< typeInfo << ",g\" "
                  << "" << info_plist << " >" << info_plist_out << endl;
                //copy the icon
                if (!project->isEmpty("ICON")) {
                    QString dir = bundle_dir + "Contents/Resources/";
                    const QString icon_path = dir + icon.section(Option::dir_sep, -1);
                    QString icon_path_f = escapeFilePath(icon_path);
                    bundledFiles << icon_path;
                    alldeps << icon_path;
                    t << escapeDependencyPath(icon_path) << ": " << escapeDependencyPath(icon) << "\n\t"
                      << mkdir_p_asstring(dir) << "\n\t"
                      << "@$(DEL_FILE) " << icon_path_f << "\n\t"
                      << "@$(COPY_FILE) " << escapeFilePath(icon) << ' ' << icon_path_f << endl;
                }
            } else {
                ProString lib_bundle_name = var("QMAKE_FRAMEWORK_BUNDLE_NAME");
                if (lib_bundle_name.isEmpty())
                    lib_bundle_name = var("QMAKE_ORIG_TARGET");

                if (!isShallowBundle)
                    symlinks[bundle_dir + "Resources"] = "Versions/Current/Resources";
                t << "@$(DEL_FILE) " << info_plist_out << "\n\t"
                  << "@sed ";
                for (const ProString &arg : qAsConst(commonSedArgs))
                    t << arg;
                t << "-e \"s,@LIBRARY@," << lib_bundle_name << ",g\" "
                  << "-e \"s,\\$${EXECUTABLE_NAME}," << lib_bundle_name << ",g\" "
                  << "-e \"s,@TYPEINFO@," << typeInfo << ",g\" "
                  << "-e \"s,\\$${QMAKE_PKGINFO_TYPEINFO}," << typeInfo << ",g\" "
                  << "" << info_plist << " >" << info_plist_out << endl;
            }
            break;
        } // project->isActiveConfig("no_plist")
        //copy other data
        if(!project->isEmpty("QMAKE_BUNDLE_DATA")) {
            const ProStringList &bundle_data = project->values("QMAKE_BUNDLE_DATA");
            for(int i = 0; i < bundle_data.count(); i++) {
                const ProStringList &files = project->values(ProKey(bundle_data[i] + ".files"));
                QString path = bundle_dir;
                const ProKey pkey(bundle_data[i] + ".path");
                if (!project->isActiveConfig("shallow_bundle")) {
                    const ProKey vkey(bundle_data[i] + ".version");
                    if (!project->isEmpty(vkey)) {
                        QString version = project->first(vkey) + "/" +
                                          project->first("QMAKE_FRAMEWORK_VERSION") + "/";
                        ProString name = project->first(pkey);
                        int pos = name.indexOf('/');
                        if (pos > 0)
                            name = name.mid(0, pos);
                        symlinks[Option::fixPathToTargetOS(path + name)] =
                                project->first(vkey) + "/Current/" + name;
                        path += version;
                    }
                }
                path += project->first(pkey).toQString();
                path = Option::fixPathToTargetOS(path);
                for(int file = 0; file < files.count(); file++) {
                    QString fn = files.at(file).toQString();
                    QString src = fileFixify(fn, FileFixifyAbsolute);
                    if (!QFile::exists(src))
                        src = fileFixify(fn, FileFixifyFromOutdir);
                    else
                        src = fileFixify(fn);
                    QString dst = path + Option::dir_sep + fileInfo(fn).fileName();
                    bundledFiles << dst;
                    alldeps << dst;
                    t << escapeDependencyPath(dst) << ": " << escapeDependencyPath(src) << "\n\t"
                      << mkdir_p_asstring(path) << "\n\t";
                    src = escapeFilePath(src);
                    dst = escapeFilePath(dst);
                    QFileInfo fi(fileInfo(fn));
                    if(fi.isDir())
                        t << "@$(DEL_FILE) -r " << dst << "\n\t"
                          << "@$(COPY_DIR) " << src << " " << dst << endl;
                    else
                        t << "@$(DEL_FILE) " << dst << "\n\t"
                          << "@$(COPY_FILE) " << src << " " << dst << endl;
                }
            }
        }
        if (!symlinks.isEmpty()) {
            QString bundle_dir_f = escapeFilePath(bundle_dir);
            QHash<QString, QString>::ConstIterator symIt = symlinks.constBegin(),
                                                   symEnd = symlinks.constEnd();
            for (; symIt != symEnd; ++symIt) {
                bundledFiles << symIt.key();
                alldeps << symIt.key();
                t << escapeDependencyPath(symIt.key()) << ":\n\t"
                  << mkdir_p_asstring(bundle_dir) << "\n\t"
                  << "@$(SYMLINK) " << escapeFilePath(symIt.value()) << ' ' << bundle_dir_f << endl;
            }

            if (!project->isActiveConfig("shallow_bundle")) {
                QString currentLink = bundle_dir + "Versions/Current";
                QString currentLink_f = escapeDependencyPath(currentLink);
                bundledFiles << currentLink;
                alldeps << currentLink;
                t << currentLink_f << ": $(MAKEFILE)\n\t"
                  << mkdir_p_asstring(bundle_dir + "Versions") << "\n\t"
                  << "@-$(DEL_FILE) " << currentLink_f << "\n\t"
                  << "@$(SYMLINK) " << project->first("QMAKE_FRAMEWORK_VERSION")
                             << ' ' << currentLink_f << endl;
            }
        }
    }

    t << endl << "all: " << deps
      << valGlue(escapeDependencyPaths(project->values("ALL_DEPS")), " \\\n\t\t", " \\\n\t\t", "")
      << allDeps << endl << endl;

    t << "dist: distdir FORCE\n\t";
    t << "(cd `dirname $(DISTDIR)` && $(TAR) $(DISTNAME).tar $(DISTNAME) && $(COMPRESS) $(DISTNAME).tar)"
         " && $(MOVE) `dirname $(DISTDIR)`" << Option::dir_sep << "$(DISTNAME).tar.gz ."
         " && $(DEL_FILE) -r $(DISTDIR)";
    t << endl << endl;

    t << "distdir: FORCE\n\t"
      << mkdir_p_asstring("$(DISTDIR)", false) << "\n\t"
      << "$(COPY_FILE) --parents $(DIST) $(DISTDIR)" << Option::dir_sep << endl;
    if(!project->isEmpty("QMAKE_EXTRA_COMPILERS")) {
        const ProStringList &quc = project->values("QMAKE_EXTRA_COMPILERS");
        for (ProStringList::ConstIterator it = quc.begin(); it != quc.end(); ++it) {
            const ProStringList &var = project->values(ProKey(*it + ".input"));
            for (ProStringList::ConstIterator var_it = var.begin(); var_it != var.end(); ++var_it) {
                const ProStringList &val = project->values((*var_it).toKey());
                if(val.isEmpty())
                    continue;
                t << "\t$(COPY_FILE) --parents " << escapeFilePaths(val).join(' ')
                                                 << " $(DISTDIR)" << Option::dir_sep << endl;
            }
        }
    }
    if(!project->isEmpty("TRANSLATIONS"))
        t << "\t$(COPY_FILE) --parents " << fileVar("TRANSLATIONS") << " $(DISTDIR)" << Option::dir_sep << endl;
    t << endl << endl;

    QString clean_targets = " compiler_clean " + depVar("CLEAN_DEPS");
    if(do_incremental) {
        t << "incrclean:\n";
        if(src_incremental)
            t << "\t-$(DEL_FILE) $(INCREMENTAL_OBJECTS)\n";
        t << endl;
    }

    t << "clean:" << clean_targets << "\n\t";
    if(!project->isEmpty("OBJECTS")) {
        t << "-$(DEL_FILE) $(OBJECTS)\n\t";
    }
    if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
        ProStringList precomp_files;
        ProString precomph_out_dir;

        if(!project->isEmpty("PRECOMPILED_DIR"))
            precomph_out_dir = project->first("PRECOMPILED_DIR");
        precomph_out_dir += project->first("QMAKE_ORIG_TARGET");
        if (!project->isActiveConfig("clang_pch_style"))
            precomph_out_dir += project->first("QMAKE_PCH_OUTPUT_EXT");

        if (project->isActiveConfig("icc_pch_style")) {
            // icc style
            ProString pchBaseName = project->first("QMAKE_ORIG_TARGET");
            ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS");
            if (pchArchs.isEmpty())
                pchArchs << ProString(); // normal single-arch PCH
            for (const ProString &arch : qAsConst(pchArchs)) {
                ProString pchOutput;
                if (!project->isEmpty("PRECOMPILED_DIR"))
                    pchOutput = project->first("PRECOMPILED_DIR");
                pchOutput += pchBaseName + project->first("QMAKE_PCH_OUTPUT_EXT");
                if (!arch.isEmpty())
                    pchOutput = ProString(pchOutput.toQString().replace(
                        QStringLiteral("${QMAKE_PCH_ARCH}"), arch.toQString()));

                ProString sourceFile = pchOutput + Option::cpp_ext.first();
                ProString objectFile = createObjectList(ProStringList(sourceFile)).first();
                precomp_files << precomph_out_dir << sourceFile << objectFile;
            }
        } else {
            // gcc style (including clang_pch_style)
            precomph_out_dir += Option::dir_sep;

            ProString header_prefix = project->first("QMAKE_PRECOMP_PREFIX");
            ProString header_suffix = project->isActiveConfig("clang_pch_style")
                               ? project->first("QMAKE_PCH_OUTPUT_EXT") : "";

            for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
                if (project->isEmpty(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE")))
                    continue;
                ProString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler));
                if (language.isEmpty())
                    continue;

                ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS");
                if (pchArchs.isEmpty())
                    pchArchs << ProString(); // normal single-arch PCH
                for (const ProString &arch : qAsConst(pchArchs)) {
                    auto suffix = header_suffix.toQString();
                    if (!arch.isEmpty())
                        suffix.replace(QStringLiteral("${QMAKE_PCH_ARCH}"), arch.toQString());
                    precomp_files += precomph_out_dir + header_prefix + language + suffix;
                }
            }
        }
        t << "-$(DEL_FILE) " << escapeFilePaths(precomp_files).join(' ') << "\n\t";
    }
    if(src_incremental)
        t << "-$(DEL_FILE) $(INCREMENTAL_OBJECTS)\n\t";
    t << fileVarGlue("QMAKE_CLEAN","-$(DEL_FILE) "," ","\n\t")
      << "-$(DEL_FILE) *~ core *.core\n"
      << fileVarGlue("CLEAN_FILES","\t-$(DEL_FILE) "," ","") << endl << endl;

    ProString destdir = project->first("DESTDIR");
    if (!destdir.isEmpty() && !destdir.endsWith(Option::dir_sep))
        destdir += Option::dir_sep;
    t << "distclean: clean " << depVar("DISTCLEAN_DEPS") << '\n';
    if(!project->isEmpty("QMAKE_BUNDLE")) {
        QString bundlePath = escapeFilePath(destdir + project->first("QMAKE_BUNDLE"));
        t << "\t-$(DEL_FILE) -r " << bundlePath << endl;
    } else if (project->isActiveConfig("staticlib") || project->isActiveConfig("plugin")) {
        t << "\t-$(DEL_FILE) " << escapeFilePath(destdir) << "$(TARGET) \n";
    } else if (project->values("QMAKE_APP_FLAG").isEmpty()) {
        destdir = escapeFilePath(destdir);
        t << "\t-$(DEL_FILE) " << destdir << "$(TARGET) \n";
        if (!project->isActiveConfig("unversioned_libname")) {
            t << "\t-$(DEL_FILE) " << destdir << "$(TARGET0) " << destdir << "$(TARGET1) "
              << destdir << "$(TARGET2) $(TARGETA)\n";
        } else {
            t << "\t-$(DEL_FILE) $(TARGETA)\n";
        }
    } else {
        t << "\t-$(DEL_FILE) $(TARGET) \n";
    }
    t << fileVarGlue("QMAKE_DISTCLEAN","\t-$(DEL_FILE) "," ","\n");
    {
        QString ofile = fileFixify(Option::output.fileName());
        if(!ofile.isEmpty())
            t << "\t-$(DEL_FILE) " << escapeFilePath(ofile) << endl;
    }
    t << endl << endl;

    t << "####### Sub-libraries\n\n";
    if (!project->values("SUBLIBS").isEmpty()) {
        ProString libdir = "tmp/";
        if (!project->isEmpty("SUBLIBS_DIR"))
            libdir = project->first("SUBLIBS_DIR");
        const ProStringList &l = project->values("SUBLIBS");
        for (it = l.begin(); it != l.end(); ++it)
            t << escapeDependencyPath(libdir + project->first("QMAKE_PREFIX_STATICLIB") + (*it) + '.'
                                      + project->first("QMAKE_EXTENSION_STATICLIB")) << ":\n\t"
              << var(ProKey("MAKELIB" + *it)) << endl << endl;
    }

    if(doPrecompiledHeaders() && !project->isEmpty("PRECOMPILED_HEADER")) {
        QString pchInput = project->first("PRECOMPILED_HEADER").toQString();
        t << "###### Precompiled headers\n";
        for (const ProString &compiler : project->values("QMAKE_BUILTIN_COMPILERS")) {
            QString pchOutputDir;
            QString pchFlags = var(ProKey("QMAKE_" + compiler + "FLAGS_PRECOMPILE"));
            if(pchFlags.isEmpty())
                continue;

            QString cflags;
            if (compiler == "C" || compiler == "OBJC")
                cflags += " $(CFLAGS)";
            else
                cflags += " $(CXXFLAGS)";

            ProStringList pchArchs = project->values("QMAKE_PCH_ARCHS");
            if (pchArchs.isEmpty())
                pchArchs << ProString(); // normal single-arch PCH
            ProString pchBaseName = project->first("QMAKE_ORIG_TARGET");
            ProString pchOutput;
            if(!project->isEmpty("PRECOMPILED_DIR"))
                pchOutput = project->first("PRECOMPILED_DIR");
            pchOutput += pchBaseName;
            if (!project->isActiveConfig("clang_pch_style"))
                pchOutput += project->first("QMAKE_PCH_OUTPUT_EXT");

            if (!project->isActiveConfig("icc_pch_style")) {
                // gcc style (including clang_pch_style)
                ProString header_prefix = project->first("QMAKE_PRECOMP_PREFIX");
                ProString header_suffix = project->isActiveConfig("clang_pch_style")
                                  ? project->first("QMAKE_PCH_OUTPUT_EXT") : "";
                pchOutput += Option::dir_sep;
                pchOutputDir = pchOutput.toQString();

                QString language = project->first(ProKey("QMAKE_LANGUAGE_" + compiler)).toQString();
                if (language.isEmpty())
                    continue;

                pchOutput += header_prefix + language + header_suffix;
            }
            pchFlags.replace(QLatin1String("${QMAKE_PCH_INPUT}"), escapeFilePath(pchInput))
                    .replace(QLatin1String("${QMAKE_PCH_OUTPUT_BASE}"), escapeFilePath(pchBaseName.toQString()));
            for (const ProString &arch : qAsConst(pchArchs)) {
                auto pchArchOutput = pchOutput.toQString();
                if (!arch.isEmpty())
                    pchArchOutput.replace(QStringLiteral("${QMAKE_PCH_ARCH}"), arch.toQString());

                const auto pchFilePath_d = escapeDependencyPath(pchArchOutput);
                if (!arch.isEmpty()) {
                    t << pchFilePath_d << ": " << "EXPORT_ARCH_ARGS = -arch " << arch << "\n\n";
                    t << pchFilePath_d << ": "
                      << "EXPORT_QMAKE_XARCH_CFLAGS = $(EXPORT_QMAKE_XARCH_CFLAGS_" << arch << ")" << "\n\n";
                    t << pchFilePath_d << ": "
                      << "EXPORT_QMAKE_XARCH_LFLAGS = $(EXPORT_QMAKE_XARCH_LFLAGS_" << arch << ")" << "\n\n";
                }
                t << pchFilePath_d << ": " << escapeDependencyPath(pchInput) << ' '
                  << finalizeDependencyPaths(findDependencies(pchInput)).join(" \\\n\t\t");
                if (project->isActiveConfig("icc_pch_style")) {
                    QString sourceFile = pchArchOutput + Option::cpp_ext.first();
                    QString sourceFile_f = escapeFilePath(sourceFile);
                    QString objectFile = createObjectList(ProStringList(sourceFile)).first().toQString();

                    pchFlags.replace(QLatin1String("${QMAKE_PCH_TEMP_SOURCE}"), sourceFile_f)
                            .replace(QLatin1String("${QMAKE_PCH_TEMP_OBJECT}"), escapeFilePath(objectFile));

                    t << "\n\techo \"// Automatically generated, do not modify\" > " << sourceFile_f
                      << "\n\trm -f " << escapeFilePath(pchArchOutput);
                } else {
                    t << "\n\t" << mkdir_p_asstring(pchOutputDir);
                }

                auto pchArchFlags = pchFlags;
                pchArchFlags.replace(QLatin1String("${QMAKE_PCH_OUTPUT}"), escapeFilePath(pchArchOutput));

                QString compilerExecutable;
                if (compiler == "C" || compiler == "OBJC")
                    compilerExecutable = "$(CC)";
                else
                    compilerExecutable = "$(CXX)";

                // compile command
                t << "\n\t" << compilerExecutable << cflags << " $(INCPATH) " << pchArchFlags << endl << endl;
            }
        }
    }

    writeExtraTargets(t);
    writeExtraCompilerTargets(t);
}

void UnixMakefileGenerator::init2()
{
    if(project->isEmpty("QMAKE_FRAMEWORK_VERSION"))
        project->values("QMAKE_FRAMEWORK_VERSION").append(project->first("VER_MAJ"));

    if (project->first("TEMPLATE") == "aux") {
        // nothing
    } else if (!project->values("QMAKE_APP_FLAG").isEmpty()) {
        if(!project->isEmpty("QMAKE_BUNDLE")) {
            ProString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION");
            if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/"))
                bundle_loc.prepend("/");
            if(!bundle_loc.endsWith("/"))
                bundle_loc += "/";
            project->values("TARGET").first().prepend(project->first("QMAKE_BUNDLE") + bundle_loc);
        }
        if(!project->isEmpty("TARGET"))
            project->values("TARGET").first().prepend(project->first("DESTDIR"));
    } else if (project->isActiveConfig("staticlib")) {
        project->values("PRL_TARGET") =
            project->values("TARGET").first().prepend(project->first("QMAKE_PREFIX_STATICLIB"));
        project->values("TARGET").first() += "." + project->first("QMAKE_EXTENSION_STATICLIB");
        if(project->values("QMAKE_AR_CMD").isEmpty())
            project->values("QMAKE_AR_CMD").append("$(AR) $(DESTDIR)$(TARGET) $(OBJECTS)");
    } else {
        project->values("TARGETA").append(project->first("DESTDIR") + project->first("QMAKE_PREFIX_STATICLIB")
                + project->first("TARGET") + "." + project->first("QMAKE_EXTENSION_STATICLIB"));

        ProStringList &ar_cmd = project->values("QMAKE_AR_CMD");
        if (!ar_cmd.isEmpty())
            ar_cmd[0] = ar_cmd.at(0).toQString().replace(QLatin1String("(TARGET)"), QLatin1String("(TARGETA)"));
        else
            ar_cmd.append("$(AR) $(TARGETA) $(OBJECTS)");
        if (!project->isEmpty("QMAKE_BUNDLE")) {
            project->values("PRL_TARGET").prepend(
                    project->first("QMAKE_BUNDLE") + Option::dir_sep + project->first("TARGET"));
            ProString bundle_loc = project->first("QMAKE_BUNDLE_LOCATION");
            if(!bundle_loc.isEmpty() && !bundle_loc.startsWith("/"))
                bundle_loc.prepend("/");
            if(!bundle_loc.endsWith("/"))
                bundle_loc += "/";
            const QString target = project->first("QMAKE_BUNDLE") +
                                        bundle_loc + project->first("TARGET");
            project->values("TARGET_").append(target);
            if (!project->isActiveConfig("shallow_bundle")) {
                project->values("TARGET_x.y").append(project->first("QMAKE_BUNDLE") +
                                                          "/Versions/" +
                                                          project->first("QMAKE_FRAMEWORK_VERSION") +
                                                          bundle_loc + project->first("TARGET"));
            } else {
                project->values("TARGET_x.y").append(target);
            }
        } else if(project->isActiveConfig("plugin")) {
            QString prefix;
            if(!project->isActiveConfig("no_plugin_name_prefix"))
                prefix = "lib";
            project->values("PRL_TARGET").prepend(prefix + project->first("TARGET"));
            project->values("TARGET_x.y.z").append(prefix +
                                                        project->first("TARGET") + "." +
                                                        project->first("QMAKE_EXTENSION_PLUGIN"));
            if(project->isActiveConfig("lib_version_first"))
                project->values("TARGET_x").append(prefix + project->first("TARGET") + "." +
                                                        project->first("VER_MAJ") + "." +
                                                        project->first("QMAKE_EXTENSION_PLUGIN"));
            else
                project->values("TARGET_x").append(prefix + project->first("TARGET") + "." +
                                                        project->first("QMAKE_EXTENSION_PLUGIN") +
                                                        "." + project->first("VER_MAJ"));
            project->values("TARGET") = project->values("TARGET_x.y.z");
        } else if (!project->isEmpty("QMAKE_HPUX_SHLIB")) {
            project->values("PRL_TARGET").prepend("lib" + project->first("TARGET"));
            project->values("TARGET_").append("lib" + project->first("TARGET") + ".sl");
            if(project->isActiveConfig("lib_version_first"))
                project->values("TARGET_x").append("lib" + project->first("VER_MAJ") + "." +
                                                        project->first("TARGET"));
            else
                project->values("TARGET_x").append("lib" + project->first("TARGET") + "." +
                                                        project->first("VER_MAJ"));
            project->values("TARGET") = project->values("TARGET_x");
        } else if (!project->isEmpty("QMAKE_AIX_SHLIB")) {
            project->values("PRL_TARGET").prepend("lib" + project->first("TARGET"));
            project->values("TARGET_").append(project->first("QMAKE_PREFIX_STATICLIB") + project->first("TARGET")
                    + "." + project->first("QMAKE_EXTENSION_STATICLIB"));
            if(project->isActiveConfig("lib_version_first")) {
                project->values("TARGET_x").append("lib" + project->first("TARGET") + "." +
                                                        project->first("VER_MAJ") + "." +
                                                        project->first("QMAKE_EXTENSION_SHLIB"));
                project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." +
                                                          project->first("VER_MAJ") +
                                                          "." + project->first("VER_MIN") + "." +
                                                          project->first("QMAKE_EXTENSION_SHLIB"));
                project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + "." +
                                                            project->first("VER_MAJ") + "." +
                                                            project->first("VER_MIN") + "." +
                                                            project->first("VER_PAT") + "." +
                                                            project->first("QMAKE_EXTENSION_SHLIB"));
            } else {
                project->values("TARGET_x").append("lib" + project->first("TARGET") + "." +
                                                        project->first("QMAKE_EXTENSION_SHLIB") +
                                                        "." + project->first("VER_MAJ"));
                project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." +
                                                          project->first("QMAKE_EXTENSION_SHLIB") +
                                                          "." + project->first("VER_MAJ") +
                                                          "." + project->first("VER_MIN"));
                project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + "." +
                                                            project->first("QMAKE_EXTENSION_SHLIB") + "." +
                                                            project->first("VER_MAJ") + "." +
                                                            project->first("VER_MIN") + "." +
                                                            project->first("VER_PAT"));
            }
            project->values("TARGET") = project->values("TARGET_x.y.z");
        } else {
            project->values("PRL_TARGET").prepend("lib" + project->first("TARGET"));
            project->values("TARGET_").append("lib" + project->first("TARGET") + "." +
                                                   project->first("QMAKE_EXTENSION_SHLIB"));
            if(project->isActiveConfig("lib_version_first")) {
                project->values("TARGET_x").append("lib" + project->first("TARGET") + "." +
                                                        project->first("VER_MAJ") + "." +
                                                        project->first("QMAKE_EXTENSION_SHLIB"));
                project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." +
                                                          project->first("VER_MAJ") +
                                                          "." + project->first("VER_MIN") + "." +
                                                          project->first("QMAKE_EXTENSION_SHLIB"));
                project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") + "." +
                                                            project->first("VER_MAJ") + "." +
                                                            project->first("VER_MIN") +  "." +
                                                            project->first("VER_PAT") + "." +
                                                            project->first("QMAKE_EXTENSION_SHLIB"));
            } else {
                project->values("TARGET_x").append("lib" + project->first("TARGET") + "." +
                                                        project->first("QMAKE_EXTENSION_SHLIB") +
                                                        "." + project->first("VER_MAJ"));
                project->values("TARGET_x.y").append("lib" + project->first("TARGET") + "." +
                                                      project->first("QMAKE_EXTENSION_SHLIB")
                                                      + "." + project->first("VER_MAJ") +
                                                      "." + project->first("VER_MIN"));
                project->values("TARGET_x.y.z").append("lib" + project->first("TARGET") +
                                                            "." +
                                                            project->first(
                                                                "QMAKE_EXTENSION_SHLIB") + "." +
                                                            project->first("VER_MAJ") + "." +
                                                            project->first("VER_MIN") +  "." +
                                                            project->first("VER_PAT"));
            }
            if (project->isActiveConfig("unversioned_libname"))
                project->values("TARGET") = project->values("TARGET_");
            else
                project->values("TARGET") = project->values("TARGET_x.y.z");
        }
        if (!project->values("QMAKE_LFLAGS_SONAME").isEmpty()) {
            ProString soname;
            if(project->isActiveConfig("plugin")) {
                if(!project->values("TARGET").isEmpty())
                    soname += project->first("TARGET");
            } else if(!project->isEmpty("QMAKE_BUNDLE")) {
                soname += project->first("TARGET_x.y");
            } else if(project->isActiveConfig("unversioned_soname")) {
                soname = "lib" + project->first("QMAKE_ORIG_TARGET")
                    + "." + project->first("QMAKE_EXTENSION_SHLIB");
            } else if(!project->values("TARGET_x").isEmpty()) {
                soname += project->first("TARGET_x");
            }
            if(!soname.isEmpty()) {
                if(project->isActiveConfig("absolute_library_soname") &&
                   project->values("INSTALLS").indexOf("target") != -1 &&
                   !project->isEmpty("target.path")) {
                    QString instpath = Option::fixPathToTargetOS(project->first("target.path").toQString());
                    if(!instpath.endsWith(Option::dir_sep))
                        instpath += Option::dir_sep;
                    soname.prepend(instpath);
                } else if (!project->isEmpty("QMAKE_SONAME_PREFIX")) {
                    QString sonameprefix = project->first("QMAKE_SONAME_PREFIX").toQString();
                    if (!sonameprefix.startsWith('@'))
                        sonameprefix = Option::fixPathToTargetOS(sonameprefix, false);
                    if (!sonameprefix.endsWith(Option::dir_sep))
                        sonameprefix += Option::dir_sep;
                    soname.prepend(sonameprefix);
                }
                project->values("QMAKE_LFLAGS_SONAME").first() += escapeFilePath(soname);
            }
        }
        if (project->values("QMAKE_LINK_SHLIB_CMD").isEmpty())
            project->values("QMAKE_LINK_SHLIB_CMD").append(
                "$(LINK) $(LFLAGS) " + project->first("QMAKE_LINK_O_FLAG") + "$(TARGET) $(OBJECTS) $(LIBS) $(OBJCOMP)");
    }
    if (!project->values("QMAKE_APP_FLAG").isEmpty() || project->first("TEMPLATE") == "aux") {
        project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_APP");
        project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_APP");
        project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_APP");
    } else if (project->isActiveConfig("dll")) {
        if(!project->isActiveConfig("plugin") || !project->isActiveConfig("plugin_no_share_shlib_cflags")) {
            project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_SHLIB");
            project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_SHLIB");
        }
        if (project->isActiveConfig("plugin")) {
            project->values("QMAKE_CFLAGS") += project->values("QMAKE_CFLAGS_PLUGIN");
            project->values("QMAKE_CXXFLAGS") += project->values("QMAKE_CXXFLAGS_PLUGIN");
            project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_PLUGIN");
            if (project->isActiveConfig("plugin_with_soname"))
                project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SONAME");
        } else {
            project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SHLIB");
            if(!project->isEmpty("QMAKE_LFLAGS_COMPAT_VERSION")) {
                if(project->isEmpty("COMPAT_VERSION"))
                    project->values("QMAKE_LFLAGS") += QString(project->first("QMAKE_LFLAGS_COMPAT_VERSION") +
                                                                    project->first("VER_MAJ") + "." +
                                                                    project->first("VER_MIN"));
                else
                    project->values("QMAKE_LFLAGS") += QString(project->first("QMAKE_LFLAGS_COMPAT_VERSION") +
                                                                    project->first("COMPATIBILITY_VERSION"));
            }
            if(!project->isEmpty("QMAKE_LFLAGS_VERSION")) {
                project->values("QMAKE_LFLAGS") += QString(project->first("QMAKE_LFLAGS_VERSION") +
                                                                project->first("VER_MAJ") + "." +
                                                                project->first("VER_MIN") + "." +
                                                                project->first("VER_PAT"));
            }
            project->values("QMAKE_LFLAGS") += project->values("QMAKE_LFLAGS_SONAME");
        }
    }

    if (include_deps && project->isActiveConfig("gcc_MD_depends")) {
        // use -MMD if we know about -isystem too
        ProString MD_flag(project->values("QMAKE_CFLAGS_ISYSTEM").isEmpty() ? "-MD" : "-MMD");
        project->values("QMAKE_CFLAGS") += MD_flag;
        project->values("QMAKE_CXXFLAGS") += MD_flag;
    }
}

QString
UnixMakefileGenerator::libtoolFileName(bool fixify)
{
    QString ret = var("TARGET");
    int slsh = ret.lastIndexOf(Option::dir_sep);
    if(slsh != -1)
        ret = ret.right(ret.length() - slsh - 1);
    int dot = ret.indexOf('.');
    if(dot != -1)
        ret = ret.left(dot);
    ret += Option::libtool_ext;
    if(!project->isEmpty("QMAKE_LIBTOOL_DESTDIR"))
        ret.prepend(project->first("QMAKE_LIBTOOL_DESTDIR") + Option::dir_sep);
    if(fixify) {
        if(QDir::isRelativePath(ret) && !project->isEmpty("DESTDIR"))
            ret.prepend(project->first("DESTDIR").toQString());
        ret = fileFixify(ret, FileFixifyBackwards);
    }
    return ret;
}

void
UnixMakefileGenerator::writeLibtoolFile()
{
    QString fname = libtoolFileName(), lname = fname;
    mkdir(fileInfo(fname).path());
    int slsh = lname.lastIndexOf(Option::dir_sep);
    if(slsh != -1)
        lname = lname.right(lname.length() - slsh - 1);
    QFile ft(fname);
    if(!ft.open(QIODevice::WriteOnly))
        return;
    QString ffname(fileFixify(fname));
    project->values("ALL_DEPS").append(ffname);
    project->values("QMAKE_DISTCLEAN").append(ffname);

    QTextStream t(&ft);
    t << "# " << lname << " - a libtool library file\n";
    t << "# Generated by qmake/libtool (" QMAKE_VERSION_STR ") (Qt "
      << QT_VERSION_STR << ")";
    t << "\n";

    t << "# The name that we can dlopen(3).\n"
      << "dlname='" << fileVar(project->isActiveConfig("plugin") ? "TARGET" : "TARGET_x")
      << "'\n\n";

    t << "# Names of this library.\n";
    t << "library_names='";
    if(project->isActiveConfig("plugin")) {
        t << fileVar("TARGET");
    } else {
        if (project->isEmpty("QMAKE_HPUX_SHLIB"))
            t << fileVar("TARGET_x.y.z") << ' ';
        t << fileVar("TARGET_x") << ' ' << fileVar("TARGET_");
    }
    t << "'\n\n";

    t << "# The name of the static archive.\n"
      << "old_library='" << escapeFilePath(lname.left(lname.length()-Option::libtool_ext.length()))
                         << ".a'\n\n";

    t << "# Libraries that this one depends upon.\n";
    ProStringList libs;
    libs << "LIBS" << "QMAKE_LIBS";
    t << "dependency_libs='";
    for (ProStringList::ConstIterator it = libs.cbegin(); it != libs.cend(); ++it)
        t << fixLibFlags((*it).toKey()).join(' ') << ' ';
    t << "'\n\n";

    t << "# Version information for " << lname << "\n";
    int maj = project->first("VER_MAJ").toInt();
    int min = project->first("VER_MIN").toInt();
    int pat = project->first("VER_PAT").toInt();
    t << "current=" << (10*maj + min) << "\n" // best I can think of
      << "age=0\n"
      << "revision=" << pat << "\n\n";

    t << "# Is this an already installed library.\n"
        "installed=yes\n\n"; // ###

    t << "# Files to dlopen/dlpreopen.\n"
        "dlopen=''\n"
        "dlpreopen=''\n\n";

    ProString install_dir = project->first("QMAKE_LIBTOOL_LIBDIR");
    if(install_dir.isEmpty())
        install_dir = project->first("target.path");
    if(install_dir.isEmpty())
        install_dir = project->first("DESTDIR");
    t << "# Directory that this library needs to be installed in:\n"
        "libdir='" << Option::fixPathToTargetOS(install_dir.toQString(), false) << "'\n";
}

QT_END_NAMESPACE