2 #############################################################################
4 ## Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
8 ## This file is part of the porting tools of the Qt Toolkit.
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## 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('QtWidgets', $qtdir);
144 findQtHeaders('QtPrintSupport', $qtdir);
146 if (-d $qtdir . '/include/QtQuick1') {
147 findQtHeaders('QtQuick1', $qtdir);
148 } elsif (-d $qtdir . '/../qtdeclarative' ) {
149 # This is the case if QTDIR points to a source tree instead of an installed Qt
150 findQtHeaders('QtQuick1', $qtdir . '/../qtdeclarative');
152 print "Warning - cannot find QtQuick1 headers\n";
156 $headerSubst{'QtGui'} = 'QtWidgets/QtWidgets';
158 find({ wanted => \&fixHeaders, no_chdir => 1}, $cwd);
160 print 'Done. ', ($dry_run ? 'Checked' : 'Modified'), ' ', $fixedFileCount, ' of ', $fileCount, " file(s).\n";