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 build configuration 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 #############################################################################
44 # Synchronizes Qt header files - internal development tool.
47 # use packages -------------------------------------------------------
56 use English qw(-no_match_vars );
58 my $normalizePath_fixDrive = ($^O eq "msys" ? 1 : 0);
60 ######################################################################
61 # Syntax: normalizePath(\$path)
62 # Params: Reference to a path that's going to be normalized.
64 # Purpose: Converts the path into a form that can be used as include
65 # path from C++ sources and qmake's .pro files.
66 # Only relevant on Windows.
68 ######################################################################
72 if ($normalizePath_fixDrive && $$s =~ m,^/([a-zA-Z])/(.*),) {
73 $$s = lc($1) . ":/$2";
77 # set output basedir to be where ever syncqt is run from
78 our $out_basedir = getcwd();
79 normalizePath(\$out_basedir);
83 # Make sure we use Windows line endings for chomp and friends on Windows.
84 $INPUT_RECORD_SEPARATOR = "\r\n" if ($^O eq "msys");
86 my $qtbasedir = dirname(dirname($0));
87 normalizePath(\$qtbasedir) if (defined $qtbasedir);
89 # will be defined based on the modules sync.profile
90 our (%modules, %moduleheaders, @allmoduleheadersprivate, %classnames, %modulepris, %explicitheaders, %deprecatedheaders);
92 # global variables (modified by options)
96 my $verbose_level = 1;
99 my $force_relative = 0;
100 my $check_includes = 0;
101 my $copy_headers = 0;
102 my $create_uic_class_map = 0;
103 my $create_private_headers = 1;
105 my $developer_build = 0;
106 my @modules_to_sync ;
107 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
110 # functions ----------------------------------------------------------
112 ######################################################################
113 # Syntax: showUsage()
116 # Purpose: Show the usage of the script.
118 ######################################################################
122 print " <module directory> Specifies which module to sync header files for (required for shadow builds!)\n\n";
124 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
125 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
126 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
127 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
128 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
129 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
130 print " -qtdir <PATH> Set the path to QtBase (detected: " . (defined $qtbasedir ? $qtbasedir : "-none-") . ")\n";
131 print " -quiet Only report problems, not activity (same as -verbose 0)\n";
132 print " -v, -verbose <level> Sets the verbosity level (max. 4) (default: $verbose_level)\n";
133 print " The short form increases the level by +1\n";
134 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
135 print " Create headers for <NAME> with original headers in\n";
136 print " <HEADERDIR> relative to <PROFILEDIR> \n";
137 print " -private Force copy private headers (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
138 print " -module-fwd <PATH> Create fwd includes for module pri files in the given\n";
139 print " path (default: none)\n";
140 print " -developer-build Point libraries and binaries to a common directory for\n";
141 print " easy development\n";
142 print " -help This help\n";
146 ######################################################################
147 # Syntax: checkUnix()
150 # Purpose: Check if script runs on a Unix system or not. Cygwin
151 # systems are _not_ detected as Unix systems.
152 # Returns: 1 if a unix system, else 0.
153 ######################################################################
156 if ( $force_win != 0) {
158 } elsif ( -f "/bin/uname" ) {
160 (-f "\\bin\\uname") && ($r = 0);
161 } elsif ( -f "/usr/bin/uname" ) {
163 (-f "\\usr\\bin\\uname") && ($r = 0);
166 $_ = $Config{'osname'};
167 $r = 0 if( /(ms)|(cyg)win/i );
174 return 0 if($dir =~ /^\//);
175 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
179 ######################################################################
180 # Syntax: classNames(iheader)
181 # Params: iheader, string, filename to parse for classname "symlinks"
183 # Purpose: Scans through iheader to find all classnames that should be
184 # synced into library's include structure.
185 # Returns: List of all class names in a file.
186 ######################################################################
191 my $classname = $classnames{basename($iheader)};
192 push @ret, $classname if ($classname);
195 if(open(F, "<$iheader")) {
199 chop $line if ($line =~ /\r$/);
204 last unless($line =~ /\\$/);
207 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
208 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
212 $line =~ s,//.*$,,; #remove c++ comments
213 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
214 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
215 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE(_[A-Z]+)*[\r\n]*$/); #qt macro
216 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
217 $parsable .= " " . $line;
223 my $last_definition = 0;
225 for(my $i = 0; $i < length($parsable); $i++) {
227 my $character = substr($parsable, $i, 1);
228 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
229 for($i+=2; $i < length($parsable); $i++) {
230 my $end = substr($parsable, $i, 2);
232 $last_definition = $i+2;
237 } elsif($character eq "{") {
239 my $block_start = $i + 1;
240 BLOCK: for($i+=1; $i < length($parsable); $i++) {
241 my $ignore = substr($parsable, $i, 1);
244 } elsif($ignore eq "}") {
246 unless($brace_depth) {
247 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
248 my $end = substr($parsable, $i2, 1);
249 if($end eq ";" || $end ne " ") {
250 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
251 $i = $i2 if($end eq ";");
252 $last_definition = $i + 1;
259 } elsif($character eq ";") {
260 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
261 $last_definition = $i + 1;
262 } elsif($character eq "}") {
263 # a naked } must be a namespace ending
264 # if it's not a namespace, it's eaten by the loop above
266 $last_definition = $i + 1;
269 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
270 && substr($parsable, $i+1, 1) eq "{") {
271 push @namespaces, $1;
273 # Eat the opening { so that the condensing loop above doesn't see it
275 $last_definition = $i + 1;
279 $definition =~ s=[\n\r]==g;
281 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
283 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
285 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
287 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
288 push @symbols, "Q" . $1 . "Iterator";
289 push @symbols, "QMutable" . $1 . "Iterator";
292 our $publicclassregexp;
293 foreach my $symbol (@symbols) {
294 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
296 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
297 || $symbol =~ /^Phonon::/) { # or in the Phonon namespace
299 } elsif (defined($publicclassregexp)) {
300 push @ret, $symbol if ($symbol =~ $publicclassregexp);
309 my ($dir, $lib, $be_verbose) = @_;
312 $dir = "<outbase>" . substr($dir, length($out_basedir)) if ($be_verbose < 3);
313 print "$lib: mkpath $dir\n" if ($be_verbose > 1);
317 ######################################################################
318 # Syntax: syncHeader(header, iheader, copy, timestamp)
319 # Params: header, string, filename to create "symlink" for
320 # iheader, string, destination name of symlink
321 # copy, forces header to be a copy of iheader
322 # timestamp, the requested modification time if copying
324 # Purpose: Syncronizes header to iheader
325 # Returns: 1 if successful, else 0.
326 ######################################################################
328 my ($lib, $header, $iheader, $copy, $ts) = @_;
329 normalizePath(\$iheader);
330 normalizePath(\$header);
331 return copyFile($lib, $iheader, $header) if($copy);
334 my $header_dir = dirname($header);
335 make_path($header_dir, $lib, $verbose_level);
338 my $iheader_out = fixPaths($iheader, $header_dir);
339 open(HEADER, ">$header") || die "Could not open $header for writing: $!\n";
340 print HEADER "#include \"$iheader_out\"\n";
343 utime(time, $ts, $header) or die "$iheader, $header";
350 ######################################################################
351 # Syntax: fixPaths(file, dir)
352 # Params: file, string, filepath to be made relative to dir
353 # dir, string, dirpath for point of origin
355 # Purpose: file is made relative (if possible) of dir.
356 # Returns: String with the above applied conversion.
357 ######################################################################
361 normalizePath(\$file);
362 while ($file =~ s,/[^/]+/\.\./,/,) {}
367 my ($file, $dir) = @_;
369 my $out = File::Spec->abs2rel(cleanupPath($file), cleanupPath($dir));
374 ######################################################################
375 # Syntax: fileContents(filename)
376 # Params: filename, string, filename of file to return contents
378 # Purpose: Get the contents of a file.
379 # Returns: String with contents of the file, or empty string if file
381 # Warning: Dies if it does exist but script cannot get read access.
382 ######################################################################
385 my $filecontents = "";
387 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
393 return $filecontents;
396 ######################################################################
397 # Syntax: fileCompare(file1, file2)
398 # Params: file1, string, filename of first file
399 # file2, string, filename of second file
401 # Purpose: Determines if files are equal, and which one is newer.
402 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
403 # is newer, 1 if file2 is newer.
404 ######################################################################
406 my ($file1, $file2) = @_;
407 my $file1contents = fileContents($file1);
408 my $file2contents = fileContents($file2);
409 if (! -e $file1) { return 1; }
410 if (! -e $file2) { return -1; }
411 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
414 ######################################################################
415 # Syntax: copyFile(file, ifile)
416 # Params: file, string, filename to create duplicate for
417 # ifile, string, destination name of duplicate
419 # Purpose: Keeps files in sync so changes in the newer file will be
420 # written to the other.
421 # Returns: 1 if files were synced, else 0.
422 # Warning: Dies if script cannot get write access.
423 ######################################################################
426 my ($lib, $file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
427 # Bi-directional synchronization
428 open( I, "< " . $file ) || die "Could not open $file for reading";
433 if ( open(I, "< " . $ifile) ) {
436 $ifilecontents = <I>;
438 $copy = fileCompare($file, $ifile);
445 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
447 my $file_dir = dirname($file);
448 make_path($file_dir, $lib, $verbose_level);
449 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
452 print O $ifilecontents;
454 utime time, (stat($ifile))[9], $file;
456 } elsif ( $copy < 0 ) {
457 my $ifile_dir = dirname($ifile);
458 make_path($ifile_dir, $lib, $verbose_level);
459 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
462 print O $filecontents;
464 utime time, (stat($file))[9], $ifile;
471 ######################################################################
472 # Syntax: symlinkFile(file, ifile)
473 # Params: file, string, filename to create "symlink" for
474 # ifile, string, destination name of symlink
476 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
478 # Returns: 1 on success, else 0.
479 ######################################################################
482 my ($lib, $file, $ifile) = @_;
485 print "$lib: symlink created for $file " if ($verbose_level);
486 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
490 $t =~ s-^$quoted_basedir/--;
491 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
492 $file =~ s-^$quoted_basedir/-$p-;
493 print " ($file)\n" if($verbose_level);
495 print "\n" if($verbose_level);
496 return symlink($file, $ifile);
498 return copyFile($lib, $file, $ifile);
501 ######################################################################
502 # Syntax: findFiles(dir, match, descend)
503 # Params: dir, string, directory to search for name
504 # match, string, regular expression to match in dir
505 # descend, integer, 0 = non-recursive search
506 # 1 = recurse search into subdirectories
508 # Purpose: Finds files matching a regular expression.
509 # Returns: List of matching files.
512 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
513 # findFiles("/tmp","^#",0) - finds #* files in /tmp
514 ######################################################################
516 my ($dir,$match,$descend) = @_;
517 my ($file,$p,@files);
519 normalizePath(\$dir);
520 ($dir eq "") && ($dir = ".");
521 if ( opendir(D,$dir) ) {
525 ($dir =~ /\/$/) || ($dir .= "/");
527 foreach $file ( sort readdir(D) ) {
528 next if ( $file =~ /^\.\.?$/ );
530 ($file =~ /$match/) && (push @files, $p);
531 if ( $descend && -d $p && ! -l $p ) {
532 push @files, &findFiles($p,$match,$descend);
540 ######################################################################
541 # Syntax: loadSyncProfile()
543 # Purpose: Locates the sync.profile.
544 # Returns: Hashmap of module name -> directory.
545 ######################################################################
546 sub loadSyncProfile {
547 my ($srcbase, $outbase) = @_;
548 if ($verbose_level) {
549 print("<srcbase> = $$srcbase \n");
550 print("<outbase> = $$outbase \n");
553 my $syncprofile = "$$srcbase/sync.profile";
555 unless ($result = do "$syncprofile") {
556 die "syncqt couldn't parse $syncprofile: $@" if $@;
557 die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
564 $$arg =~ s,^\Q$basedir\E,<srcbase>,;
565 $$arg =~ s,^\Q$out_basedir\E,<outbase>,;
570 while ($arg =~ s,[^/]+/\.\.(/|$),,) {}
574 sub locateSyncProfile
576 my ($directory) = @_;
577 $directory = abs_path($directory);
579 my $file = $directory."/sync.profile";
580 return $file if (-e $file);
581 my $odir = $directory;
582 $directory = dirname($directory);
583 return undef if ($directory eq $odir);
587 # check if this is an in-source build, and if so use that as the basedir too
588 $basedir = locateSyncProfile($out_basedir);
590 $basedir = dirname($basedir) ;
591 normalizePath(\$basedir);
592 $quoted_basedir = "\Q$basedir";
595 # --------------------------------------------------------------------
597 # --------------------------------------------------------------------
604 my $arg = shift @ARGV;
605 if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
608 } elsif($arg eq "-copy") {
611 } elsif($arg eq "-o" || $arg eq "-outdir") {
614 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
615 $arg eq "-relative" || $arg eq "-check-includes") {
616 $var = substr($arg, 1);
618 } elsif($arg eq "-module-fwd") {
621 } elsif($arg eq "-developer-build") {
622 $var = "developer_build";
624 } elsif($arg =~ /^-no-(.*)$/) {
627 #these are for commandline compat
628 } elsif($arg eq "-inc") {
631 } elsif($arg eq "-module") {
634 } elsif($arg eq "-separate-module") {
635 $var = "separate-module";
637 } elsif($arg eq "-show") {
640 } elsif($arg eq "-quiet") {
643 } elsif($arg eq "-v") {
646 } elsif($arg eq "-verbose") {
649 } elsif($arg eq "-private") {
650 $var = "create_private_headers";
652 } elsif($arg eq "-qtdir") {
655 } elsif($arg =~/^-/) {
656 print "Unknown option: $arg\n\n" if(!$var);
659 $basedir = locateSyncProfile($arg);
660 die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
661 $basedir = dirname($basedir);
662 normalizePath(\$basedir);
663 $quoted_basedir = "\Q$basedir";
668 if(!$var || $var eq "show_help") {
669 print "Unknown option: $arg\n\n" if(!$var);
671 } elsif ($var eq "copy") {
677 } elsif ($var eq "showonly") {
683 } elsif ($var eq "verbose") {
686 } elsif($val eq "no" && $verbose_level) {
689 $verbose_level = int($val);
691 } elsif ($var eq "check-includes") {
694 } elsif($check_includes) {
697 } elsif ($var eq "remove-stale") {
700 } elsif($remove_stale) {
703 } elsif ($var eq "windows") {
706 } elsif($force_win) {
709 } elsif ($var eq "relative") {
712 } elsif($force_relative) {
715 } elsif ($var eq "module") {
716 print "module :$val:\n" if($verbose_level);
717 die "No such module: $val" unless(defined $modules{$val});
718 push @modules_to_sync, $val;
719 } elsif ($var eq "separate-module") {
720 my ($module, $prodir, $headerdir) = split(/:/, $val);
721 $modules{$module} = $prodir;
722 push @modules_to_sync, $module;
723 $moduleheaders{$module} = $headerdir;
724 $create_uic_class_map = 0;
725 } elsif ($var eq "qtdir") {
728 normalizePath(\$qtbasedir);
730 die "The -qtdir option requires an argument";
732 } elsif ($var eq "module_fwd") {
734 } elsif ($var eq "developer_build") {
735 $developer_build = 1;
736 } elsif ($var eq "output") {
738 if(checkRelative($outdir)) {
739 $out_basedir = getcwd();
741 $out_basedir .= "/" . $outdir;
743 $out_basedir = $outdir;
745 normalizePath(\$out_basedir);
749 die "Cannot automatically detect/use provided path to QtBase's build directory!\n" .
750 "QTDIR detected/provided: " . (defined $qtbasedir ? $qtbasedir : "-none-") . "\n" .
751 "Please use the -qtdir option to provide the correct path.\nsyncqt failed"
752 if (!$qtbasedir || !-d "$qtbasedir/mkspecs");
754 # if we have no $basedir we cannot be sure which sources you want, so die
755 die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
757 my $class_lib_map_contents = "";
758 our @ignore_headers = ();
759 our @ignore_for_master_contents = ();
760 our @ignore_for_include_check = ();
761 our @ignore_for_qt_begin_header_check = ();
762 our @ignore_for_qt_begin_namespace_check = ();
763 our @ignore_for_qt_module_check = ();
764 our %inject_headers = ();
766 # load the module's sync.profile here, before we can
767 loadSyncProfile(\$basedir, \$out_basedir);
769 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
771 my %allmoduleheadersprivate = map { $_ => 1 } @allmoduleheadersprivate;
773 $isunix = checkUnix; #cache checkUnix
775 my $qt_version = fileContents($qtbasedir."/mkspecs/qconfig.pri");
776 if (length($qt_version)) {
777 $qt_version =~ s,.*^QT_VERSION\h*=\h*(\S+).*,$1,sm;
779 $qt_version = fileContents($basedir."/src/corelib/global/qglobal.h");
780 $qt_version =~ s,.*^#\h*define\h+QT_VERSION_STR\h+"([^"]+)".*,$1,sm;
782 foreach my $lib (@modules_to_sync) {
784 my $dir = $modules{$lib};
787 $project =~ s,/([^/]+)$,/$1/$1.pro,;
788 my $module_version = fileContents($project);
789 $module_version = $qt_version unless ($module_version =~ s,.*^VERSION\h*=\h*(\S+).*,$1,sm);
791 # Backwards compatibility for modules with checked in .pri files.
792 if (defined $modulepris{$lib} and -e "$modulepris{$lib}") {
793 my $content = fileContents($modulepris{$lib});
794 my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
796 # We only pick the first one, since each module need a separate .pri file
797 $module_version = $version_rows[0];
798 chomp $module_version;
799 $module_version =~ s/^\s*QT\..*\.VERSION\s*=\s*([^#]+).*$/$1/;
800 $module_version =~ s/\s+$//;
804 my $pathtoheaders = "";
805 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
807 my $allheadersprivate = 0;
808 $allheadersprivate = 1 if $allmoduleheadersprivate{$lib};
810 #information used after the syncing
811 my $pri_install_classes = "";
812 my $pri_install_files = "";
813 my $pri_install_pfiles = "";
814 my $pri_install_qpafiles = "";
816 push @{$inject_headers{$dir}}, lc($lib)."version.h";
817 $classnames{lc($lib)."version.h"} = $lib."Version";
819 #remove the old files
822 for my $p (keys %inject_headers) {
823 next unless ($p =~ /^\Q$dir\E(\/|$)/);
825 $sp =~ s,^\Q$basedir\E/,$out_basedir/,;
826 for my $n (@{$inject_headers{$p}}) {
827 $injections{$sp."/".$n} = 1;
830 my @subdirs = ("$out_basedir/include/$lib");
831 foreach my $subdir (@subdirs) {
832 if (opendir DIR, $subdir) {
833 foreach my $t (sort readdir(DIR)) {
834 my $file = "$subdir/$t";
836 push @subdirs, $file unless($t eq "." || $t eq "..");
839 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
840 foreach my $file (@files) {
842 if(open(F, "<$file")) {
843 while(my $line = <F>) {
845 if($line =~ /^\#include \"([^\"]*)\"$/) {
847 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
848 $remove_file = 1 unless(-e $include or defined $injections{cleanPath($include)});
855 unlink $file if($remove_file);
867 foreach my $current_dir (split(/;/, $dir)) {
868 my @headers_paths = split(/;/, $pathtoheaders);
869 if (@headers_paths) {
870 @headers_paths = map { "$current_dir/$_" } @headers_paths;
872 push @headers_paths, $current_dir;
875 foreach my $headers_dir (@headers_paths) {
877 my @subdirs = ($headers_dir);
878 foreach my $subdir (@subdirs) {
879 if ($subdir =~ /\/doc$/) {
882 opendir DIR, $subdir or next;
883 foreach my $t (sort readdir(DIR)) {
884 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
885 !($t eq "..") && !($t eq ".obj") &&
886 !($t eq ".moc") && !($t eq ".rcc") &&
887 !($t eq ".uic") && !($t eq "build"));
892 #calc files and "copy" them
893 foreach my $subdir (@subdirs) {
894 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
895 if (defined $inject_headers{$subdir}) {
896 foreach my $if (@{$inject_headers{$subdir}}) {
897 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
898 push @headers, "*".$if;
901 my $header_dirname = "";
902 foreach my $header (@headers) {
903 my $shadow = ($header =~ s/^\*//);
904 $header = 0 if($header =~ /^ui_.*.h/);
905 foreach (@ignore_headers) {
906 $header = 0 if($header eq $_);
909 my $header_copies = 0;
910 #figure out if it is a public header
911 my $public_header = $header;
913 if($public_header =~ /^qplatform/) {
916 } elsif($allheadersprivate || $public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
919 foreach (@ignore_for_master_contents) {
920 $public_header = 0 if($header eq $_);
924 my $iheader = $subdir . "/" . $header;
925 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
926 my @classes = $public_header ? classNames($iheader) : ();
928 print "$header [$lib]\n";
930 print "SYMBOL: $_\n";
933 my $ts = (stat($iheader))[9];
934 #find out all the places it goes..
936 if ($public_header) {
937 @headers = ( "$out_basedir/include/$lib/$header" );
938 foreach my $full_class (@classes) {
939 my $header_base = basename($header);
941 my $class = $full_class;
943 # if ($class =~ m/::/) {
947 if (defined $explicitheaders{$lib}{$class}) {
948 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$explicitheaders{$lib}{$class}", 0, $ts));
950 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
951 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
954 # KDE-Compat headers for Phonon
955 if ($lib eq "phonon") {
956 $header_copies++ if (syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
960 if ($explicitheaders{$lib}{basename($header)}) {
961 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$explicitheaders{$lib}{basename($header)}", "$out_basedir/include/$lib/$header", 0, $ts));
964 } elsif ($create_private_headers && !$qpa_header) {
965 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
966 } elsif ($create_private_headers) {
967 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/qpa/$header" );
970 foreach(@headers) { #sync them
971 $header_copies++ if(syncHeader($lib, $_, $iheader, $copy_headers && !$shadow, $ts));
975 #deal with the install directives
977 my $pri_install_iheader = fixPaths($iheader, $current_dir);
978 foreach my $class (@classes) {
981 # if ($class =~ m/::/) {
982 # $class =~ s,::,/,g;
984 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
986 $pri_install_classes .= $class_header
987 unless($pri_install_classes =~ $class_header);
989 if ($explicitheaders{$lib}{basename($iheader)}) {
990 my $compat_header = fixPaths("$out_basedir/include/$lib/$explicitheaders{$lib}{basename($iheader)}", $current_dir) . " ";
991 $pri_install_files .= $compat_header unless($pri_install_files =~ $compat_header);
993 $pri_install_files.= "$pri_install_iheader ";;
996 elsif ($qpa_header) {
997 my $pri_install_iheader = fixPaths($iheader, $current_dir);
998 $pri_install_qpafiles.= "$pri_install_iheader ";;
1001 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1002 $pri_install_pfiles.= "$pri_install_iheader ";;
1006 if ($verbose_level && $header_copies) {
1007 my $new_header_dirname = dirname($iheader);
1008 basePrettify(\$new_header_dirname) if ($new_header_dirname && $verbose_level < 2);
1009 my $header_base = basename($iheader);
1010 if ($verbose_level < 3) {
1011 my $line_prefix = ",";
1012 if ($new_header_dirname ne $header_dirname) {
1013 $line_prefix = "$lib: created fwd-include header(s) for $new_header_dirname/ {";
1014 $line_prefix = " }\n".$line_prefix if ($header_dirname);
1015 $header_dirname = $new_header_dirname;
1019 print "$line_prefix $header_base ($header_copies)";
1020 } else { # $verbose_level >= 3
1021 basePrettify(\$iheader) if ($verbose_level == 3);
1022 print "$lib: created $header_copies fwd-include headers for $iheader\n";
1027 print " }\n" if ($header_dirname && $verbose_level > 0 && $verbose_level < 3);
1033 # create deprecated headers
1035 while (my ($header, $include) = each %{$deprecatedheaders{$lib}}) {
1036 my $public_header = 0;
1037 $public_header = 1 unless ($allheadersprivate || ($header =~ /_p\.h$/));
1038 next unless ($public_header || $create_private_headers);
1040 my $header_path = "$out_basedir/include/$lib/";
1041 unless ($public_header) {
1042 $header_path .= "$module_version/$lib/private/";
1044 $header_path .= "$header";
1046 unless (-e $header_path) {
1047 my $guard = "DEPRECATED_HEADER_" . $lib . "_" . $header;
1048 $guard =~ s/([^a-zA-Z0-9_])/_/g;
1050 my $header_dir = dirname($header_path);
1051 make_path($header_dir, $lib, $verbose_level);
1053 open(HEADER, ">$header_path") || die "Could not open $header_path for writing: $!\n";
1054 print HEADER "#ifndef $guard\n";
1055 print HEADER "#define $guard\n";
1056 my $warning = "Header <$lib/";
1057 $warning .= "private/" unless ($public_header);
1058 $warning .= "$header> is deprecated. Please include <$include> instead.";
1059 print HEADER "#if defined(__GNUC__)\n";
1060 print HEADER "# warning $warning\n";
1061 print HEADER "#elif defined(_MSC_VER)\n";
1062 print HEADER "# pragma message (\"$warning\")\n";
1063 print HEADER "#endif\n";
1064 print HEADER "#include <$include>\n";
1065 if ($public_header) {
1066 print HEADER "#if 0\n";
1067 print HEADER "#pragma qt_no_master_include\n";
1068 print HEADER "#endif\n";
1070 print HEADER "#endif\n";
1073 if ($verbose_level < 3) {
1074 my $line_prefix = ",";
1075 $line_prefix = "$lib: created deprecated header(s) {" if ($first);
1076 print "$line_prefix $header";
1078 print "$lib: created deprecated header $header => $include\n";
1083 my $addendum = fixPaths($header_path, $dir) . " ";
1084 if ($public_header) {
1085 $pri_install_files .= $addendum;
1087 $pri_install_pfiles .= $addendum;
1090 if ($verbose_level < 3) {
1091 print " }\n" unless ($first);
1094 # KDE-Compat master header for Phonon
1095 if ($lib eq "phonon") {
1096 syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/Phonon", "$out_basedir/include/phonon/phonon", 0);
1099 #handle the headers.pri for each module
1100 my $headers_pri_contents = "";
1101 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1102 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1103 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1104 $headers_pri_contents .= "SYNCQT.QPA_HEADER_FILES = $pri_install_qpafiles\n";
1105 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1106 if(-e $headers_pri_file) {
1107 open HEADERS_PRI_FILE, "<$headers_pri_file";
1109 binmode HEADERS_PRI_FILE;
1110 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1111 close HEADERS_PRI_FILE;
1112 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1113 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1115 if($headers_pri_file) {
1116 my $headers_pri_dir = dirname($headers_pri_file);
1117 make_path($headers_pri_dir, $lib, $verbose_level);
1118 open HEADERS_PRI_FILE, ">$headers_pri_file";
1119 print HEADERS_PRI_FILE $headers_pri_contents;
1120 close HEADERS_PRI_FILE;
1121 print "$lib: created headers.pri file\n" if($verbose_level);
1124 # create forwarding module pri in qtbase/mkspecs/modules
1126 my $modulepri = $modulepris{$lib};
1127 if (defined $modulepri and -e $modulepri) {
1128 my $modulepriname = basename($modulepri);
1129 make_path($module_fwd, $lib, $verbose_level);
1130 my $moduleprifwd = "$module_fwd/$modulepriname";
1131 my $mod_base = $basedir;
1132 my $mod_component_base = $developer_build ? $qtbasedir : $out_basedir;
1133 open MODULE_PRI_FILE, ">$moduleprifwd" or die("Could not open $moduleprifwd for writing");
1134 print MODULE_PRI_FILE "QT_MODULE_BASE = $mod_base\n";
1135 print MODULE_PRI_FILE "QT_MODULE_BIN_BASE = $mod_component_base/bin\n";
1136 print MODULE_PRI_FILE "QT_MODULE_INCLUDE_BASE = $out_basedir/include\n";
1137 print MODULE_PRI_FILE "QT_MODULE_IMPORT_BASE = $mod_component_base/imports\n";
1138 print MODULE_PRI_FILE "QT_MODULE_LIB_BASE = $mod_component_base/lib\n";
1139 print MODULE_PRI_FILE "QT_MODULE_PLUGIN_BASE = $mod_component_base/plugins\n";
1140 print MODULE_PRI_FILE "include($modulepri)\n";
1141 close MODULE_PRI_FILE;
1142 utime(time, (stat($modulepri))[9], $moduleprifwd);
1143 } elsif ($modulepri) {
1144 print "$lib: WARNING: Module\'s pri file '$modulepri' not found.\n$lib: Skipped creating forwarding pri.\n";
1149 unless($showonly || !$create_uic_class_map) {
1150 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1151 if(-e $class_lib_map) {
1152 open CLASS_LIB_MAP, "<$class_lib_map";
1154 binmode CLASS_LIB_MAP;
1155 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1156 close CLASS_LIB_MAP;
1157 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1158 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1160 if($class_lib_map) {
1161 my $class_lib_map_dir = dirname($class_lib_map);
1162 make_path($class_lib_map_dir, "<outdir>", $verbose_level);
1163 open CLASS_LIB_MAP, ">$class_lib_map";
1164 print CLASS_LIB_MAP $class_lib_map_contents;
1165 close CLASS_LIB_MAP;
1169 if($check_includes) {
1170 for my $lib (keys(%modules)) {
1172 my @subdirs = ($modules{$lib});
1173 foreach my $subdir (@subdirs) {
1174 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
1175 foreach my $t (sort readdir(DIR)) {
1176 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
1177 !($t eq "..") && !($t eq ".obj") &&
1178 !($t eq ".moc") && !($t eq ".rcc") &&
1179 !($t eq ".uic") && !($t eq "build"));
1184 foreach my $subdir (@subdirs) {
1185 my $header_skip_qt_module_test = 0;
1186 foreach(@ignore_for_qt_module_check) {
1187 foreach (split(/;/, $_)) {
1188 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1191 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1192 foreach my $header (@headers) {
1193 my $header_skip_qt_begin_header_test = 0;
1194 my $header_skip_qt_begin_namespace_test = 0;
1195 $header = 0 if($header =~ /^ui_.*.h/);
1196 foreach (@ignore_headers) {
1197 $header = 0 if($header eq $_);
1200 my $public_header = $header;
1201 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1203 } elsif ($public_header =~ /^qplatform/) {
1206 foreach (@ignore_for_master_contents) {
1207 $public_header = 0 if($header eq $_);
1209 if($public_header) {
1210 foreach (@ignore_for_include_check) {
1211 $public_header = 0 if($header eq $_);
1213 foreach(@ignore_for_qt_begin_header_check) {
1214 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1216 foreach(@ignore_for_qt_begin_namespace_check) {
1217 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1222 my $iheader = $subdir . "/" . $header;
1223 if($public_header) {
1224 if(open(F, "<$iheader")) {
1225 my $qt_begin_header_found = 0;
1226 my $qt_end_header_found = 0;
1227 my $qt_begin_namespace_found = 0;
1228 my $qt_end_namespace_found = 0;
1230 while($line = <F>) {
1232 my $output_line = 1;
1233 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1235 } elsif($line =~ /^ *\# *include/) {
1236 my $include = $line;
1237 if($line =~ /<.*>/) {
1238 $include =~ s,.*<(.*)>.*,$1,;
1239 } elsif($line =~ /".*"/) {
1240 $include =~ s,.*"(.*)".*,$1,;
1245 for my $trylib (keys(%modules)) {
1246 if(-e "$out_basedir/include/$trylib/$include") {
1247 print "$lib: WARNING: $iheader includes $include when it should include $trylib/$include\n";
1251 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1252 $qt_begin_header_found = 1;
1253 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1254 $qt_end_header_found = 1;
1255 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1256 $qt_begin_namespace_found = 1;
1257 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1258 $qt_end_namespace_found = 1;
1261 if ($header_skip_qt_begin_header_test == 0) {
1262 if ($qt_begin_header_found == 0) {
1263 print "$lib: WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1266 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1267 print "$lib: WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1271 if ($header_skip_qt_begin_namespace_test == 0) {
1272 if ($qt_begin_namespace_found == 0) {
1273 print "$lib: WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1276 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1277 print "$lib: WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";