2 #############################################################################
4 ## Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
5 ## Contact: http://www.qt-project.org/legal
7 ## This file is part of the porting tools of the Qt Toolkit.
9 ## $QT_BEGIN_LICENSE:LGPL$
10 ## Commercial License Usage
11 ## Licensees holding valid commercial Qt licenses may use this file in
12 ## accordance with the commercial license agreement provided with the
13 ## Software or, alternatively, in accordance with the terms contained in
14 ## a written agreement between you and Digia. For licensing terms and
15 ## conditions see http://qt.digia.com/licensing. For further information
16 ## use the contact form at http://qt.digia.com/contact-us.
18 ## GNU Lesser General Public License Usage
19 ## Alternatively, this file may be used under the terms of the GNU Lesser
20 ## General Public License version 2.1 as published by the Free Software
21 ## Foundation and appearing in the file LICENSE.LGPL included in the
22 ## packaging of this file. Please review the following information to
23 ## ensure the GNU Lesser General Public License version 2.1 requirements
24 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
26 ## In addition, as a special exception, Digia gives you certain additional
27 ## rights. These rights are described in the Digia Qt LGPL Exception
28 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
30 ## GNU General Public License Usage
31 ## Alternatively, this file may be used under the terms of the GNU
32 ## General Public License version 3.0 as published by the Free Software
33 ## Foundation and appearing in the file LICENSE.GPL included in the
34 ## packaging of this file. Please review the following information to
35 ## ensure the GNU General Public License version 3.0 requirements will be
36 ## met: http://www.gnu.org/copyleft/gpl.html.
41 #############################################################################
55 my $fixedFileCount = 0;
58 my $qtdir = $ENV{'QTDIR'};
61 This script replaces all Qt 4 style includes with Qt 5 includes.
66 --dry-run : Do not replace anything, just print what would be replaced
67 --strip-modules : Strip the module headers for writing portable code
69 --qtdir <directory> : Point to Qt 5's qtbase directory
72 if (!GetOptions('dry-run' => \$dry_run, 'help' => \$help,
73 'strip-modules' => \$stripModule, 'verbose' => \$verbose, 'qtdir:s' => \$qtdir)
84 my $fileName = $File::Find::name;
85 my $relFileName = File::Spec->abs2rel($fileName, $cwd);
87 # only check sources, also ignore symbolic links and directories
88 return unless -f $fileName && $fileName =~ /(\.h|\.cpp|\/C|\.cc|\.CC)$/;
90 my $inFile = new IO::File('<' . $fileName) or die ('Unable to open ' . $fileName . ': ' . $!);
95 while (my $line = <$inFile>) {
96 if ($line =~ /^#(\s*)include(\s*)<.*?\/(.*?)>(.*)/) {
97 my $newHeader = $headerSubst{$3};
99 $line = '#' . $1 . 'include' . $2 . '<' . $newHeader . '>' . $4 . "\n";
100 push(@affectedClasses, $3);
102 } elsif ($line =~ /^#(\s*)include(\s*)<QtGui>(.*)/) {
103 $line = '#' . $1 . 'include' . $2 . '<QtWidgets>' . $3 . "\n";
104 push(@affectedClasses, 'QtGui');
106 push(@outLines, $line);
110 if (scalar(@affectedClasses)) {
112 print $relFileName, ': ', join(', ', @affectedClasses), "\n" if ($verbose || $dry_run);
114 my $outFile = new IO::File('>' . $fileName) or die ('Unable to open ' . $fileName . ': ' . $!);
115 map { print $outFile $_; } @outLines;
119 print $relFileName, ": no modification.\n" if ($verbose || $dry_run);
125 my ($dirName,$baseDir) = @_;
129 opendir(DIR, $baseDir . '/include/' . $dirName) || die ('Unable to open ' .$baseDir . '/include/' . $dirName . ': ' . $!);
130 my @headers = readdir(DIR);
133 foreach my $header (@headers) {
134 next if (-d ($baseDir . '/include/' . $dirName . '/' . $header) || $header =~ /\.pri$/);
135 $headerSubst{$header} = $stripModule ? $header : ($dirName . '/' . $header);
141 die "This script requires the QTDIR environment variable pointing to Qt 5\n" unless $qtdir;
143 findQtHeaders('QtCore', $qtdir);
144 findQtHeaders('QtConcurrent', $qtdir);
145 findQtHeaders('QtWidgets', $qtdir);
146 findQtHeaders('QtPrintSupport', $qtdir);
148 if (-d $qtdir . '/include/QtQuick1') {
149 findQtHeaders('QtQuick1', $qtdir);
150 } elsif (-d $qtdir . '/../qtdeclarative' ) {
151 # This is the case if QTDIR points to a source tree instead of an installed Qt
152 findQtHeaders('QtQuick1', $qtdir . '/../qtdeclarative');
154 print "Warning - cannot find QtQuick1 headers\n";
157 # Support porting from "Qt 4.99" QtDeclarative to QtQuick (QQuickItem et al)
158 if (-d $qtdir . '/include/QtQuick') {
159 findQtHeaders('QtQuick', $qtdir);
160 } elsif (-d $qtdir . '/../qtdeclarative' ) {
161 # This is the case if QTDIR points to a source tree instead of an installed Qt
162 findQtHeaders('QtQuick', $qtdir . '/../qtdeclarative');
166 $headerSubst{'QtGui'} = 'QtWidgets/QtWidgets';
168 find({ wanted => \&fixHeaders, no_chdir => 1}, $cwd);
170 print 'Done. ', ($dry_run ? 'Checked' : 'Modified'), ' ', $fixedFileCount, ' of ', $fileCount, " file(s).\n";