2 #############################################################################
4 ## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ## Contact: http://www.qt-project.org/
7 ## This file is part of the porting tools of the Qt Toolkit.
9 ## $QT_BEGIN_LICENSE:LGPL$
10 ## GNU Lesser General Public License Usage
11 ## This file may be used under the terms of the GNU Lesser General Public
12 ## License version 2.1 as published by the Free Software Foundation and
13 ## appearing in the file LICENSE.LGPL included in the packaging of this
14 ## file. Please review the following information to ensure the GNU Lesser
15 ## General Public License version 2.1 requirements will be met:
16 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ## In addition, as a special exception, Nokia gives you certain additional
19 ## rights. These rights are described in the Nokia Qt LGPL Exception
20 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ## GNU General Public License Usage
23 ## Alternatively, this file may be used under the terms of the GNU General
24 ## Public License version 3.0 as published by the Free Software Foundation
25 ## and appearing in the file LICENSE.GPL included in the packaging of this
26 ## file. Please review the following information to ensure the GNU General
27 ## Public License version 3.0 requirements will be met:
28 ## http://www.gnu.org/copyleft/gpl.html.
31 ## Alternatively, this file may be used in accordance with the terms and
32 ## conditions contained in a signed written agreement between you and Nokia.
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";