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 build configuration 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 #############################################################################
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);
91 our @qpa_headers = ();
93 # global variables (modified by options)
97 my $verbose_level = 1;
100 my $force_relative = 0;
101 my $check_includes = 0;
102 my $copy_headers = 0;
103 my $create_uic_class_map = 0;
104 my $create_private_headers = 1;
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 " -minimal Do not create CamelCase headers (default: " . ($minimal ? "yes" : "no") . ")\n";
130 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
131 print " -qtdir <PATH> Set the path to QtBase (detected: " . (defined $qtbasedir ? $qtbasedir : "-none-") . ")\n";
132 print " -quiet Only report problems, not activity (same as -verbose 0)\n";
133 print " -v, -verbose <level> Sets the verbosity level (max. 4) (default: $verbose_level)\n";
134 print " The short form increases the level by +1\n";
135 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
136 print " Create headers for <NAME> with original headers in\n";
137 print " <HEADERDIR> relative to <PROFILEDIR> \n";
138 print " -private Force copy private headers (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
139 print " -help This help\n";
143 ######################################################################
144 # Syntax: checkUnix()
147 # Purpose: Check if script runs on a Unix system or not. Cygwin
148 # systems are _not_ detected as Unix systems.
149 # Returns: 1 if a unix system, else 0.
150 ######################################################################
153 if ( $force_win != 0) {
155 } elsif ( -f "/bin/uname" ) {
157 (-f "\\bin\\uname") && ($r = 0);
158 } elsif ( -f "/usr/bin/uname" ) {
160 (-f "\\usr\\bin\\uname") && ($r = 0);
163 $_ = $Config{'osname'};
164 $r = 0 if( /(ms)|(cyg)win/i );
171 return 0 if($dir =~ /^\//);
172 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
176 ######################################################################
177 # Syntax: classNames(iheader)
178 # Params: iheader, string, filename to parse for classname "symlinks"
180 # Purpose: Scans through iheader to find all classnames that should be
181 # synced into library's include structure.
182 # Returns: List of all class names in a file.
183 ######################################################################
188 my $classname = $classnames{basename($iheader)};
189 push @ret, $classname if ($classname);
192 if(open(F, "<$iheader")) {
196 chop $line if ($line =~ /\r$/);
201 last unless($line =~ /\\$/);
204 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
205 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
209 $line =~ s,//.*$,,; #remove c++ comments
210 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
211 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
212 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE(_[A-Z]+)*[\r\n]*$/); #qt macro
213 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
214 $parsable .= " " . $line;
220 my $last_definition = 0;
222 for(my $i = 0; $i < length($parsable); $i++) {
224 my $character = substr($parsable, $i, 1);
225 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
226 for($i+=2; $i < length($parsable); $i++) {
227 my $end = substr($parsable, $i, 2);
229 $last_definition = $i+2;
234 } elsif($character eq "{") {
236 my $block_start = $i + 1;
237 BLOCK: for($i+=1; $i < length($parsable); $i++) {
238 my $ignore = substr($parsable, $i, 1);
241 } elsif($ignore eq "}") {
243 unless($brace_depth) {
244 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
245 my $end = substr($parsable, $i2, 1);
246 if($end eq ";" || $end ne " ") {
247 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
248 $i = $i2 if($end eq ";");
249 $last_definition = $i + 1;
256 } elsif($character eq ";") {
257 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
258 $last_definition = $i + 1;
259 } elsif($character eq "}") {
260 # a naked } must be a namespace ending
261 # if it's not a namespace, it's eaten by the loop above
263 $last_definition = $i + 1;
266 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
267 && substr($parsable, $i+1, 1) eq "{") {
268 push @namespaces, $1;
270 # Eat the opening { so that the condensing loop above doesn't see it
272 $last_definition = $i + 1;
276 $definition =~ s=[\n\r]==g;
278 my $post_kw = qr/Q_DECL_FINAL|final|sealed/; # add here macros and keywords that go after the class-name of a class definition
279 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
281 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
283 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?((?!$post_kw)[^<\s]+) ?(<[^>]*> ?)?\s*(?:$post_kw)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/o) {
285 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
286 push @symbols, "Q" . $1 . "Iterator";
287 push @symbols, "QMutable" . $1 . "Iterator";
290 our $publicclassregexp;
291 foreach my $symbol (@symbols) {
292 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
294 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
295 || $symbol =~ /^Phonon::/) { # or in the Phonon namespace
297 } elsif (defined($publicclassregexp)) {
298 push @ret, $symbol if ($symbol =~ $publicclassregexp);
307 my ($dir, $lib, $be_verbose) = @_;
310 $dir = "<outbase>" . substr($dir, length($out_basedir)) if ($be_verbose < 3);
311 print "$lib: mkpath $dir\n" if ($be_verbose > 1);
315 ######################################################################
316 # Syntax: syncHeader(header, iheader, copy, timestamp)
317 # Params: header, string, filename to create "symlink" for
318 # iheader, string, destination name of symlink
319 # copy, forces header to be a copy of iheader
320 # timestamp, the requested modification time if copying
322 # Purpose: Syncronizes header to iheader
323 # Returns: 1 if successful, else 0.
324 ######################################################################
326 my ($lib, $header, $iheader, $copy, $ts) = @_;
327 normalizePath(\$iheader);
328 normalizePath(\$header);
329 return copyFile($lib, $iheader, $header) if($copy);
332 my $header_dir = dirname($header);
333 make_path($header_dir, $lib, $verbose_level);
336 my $iheader_out = fixPaths($iheader, $header_dir);
337 open(HEADER, ">$header") || die "Could not open $header for writing: $!\n";
338 print HEADER "#include \"$iheader_out\"\n";
341 utime(time, $ts, $header) or die "$iheader, $header";
348 ######################################################################
349 # Syntax: fixPaths(file, dir)
350 # Params: file, string, filepath to be made relative to dir
351 # dir, string, dirpath for point of origin
353 # Purpose: file is made relative (if possible) of dir.
354 # Returns: String with the above applied conversion.
355 ######################################################################
359 normalizePath(\$file);
360 while ($file =~ s,/[^/]+/\.\./,/,) {}
365 my ($file, $dir) = @_;
367 my $out = File::Spec->abs2rel(cleanupPath($file), cleanupPath($dir));
372 ######################################################################
373 # Syntax: fileContents(filename)
374 # Params: filename, string, filename of file to return contents
376 # Purpose: Get the contents of a file.
377 # Returns: String with contents of the file, or empty string if file
379 # Warning: Dies if it does exist but script cannot get read access.
380 ######################################################################
383 my $filecontents = "";
385 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
391 return $filecontents;
394 ######################################################################
395 # Syntax: fileCompare(file1, file2)
396 # Params: file1, string, filename of first file
397 # file2, string, filename of second file
399 # Purpose: Determines if files are equal, and which one is newer.
400 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
401 # is newer, 1 if file2 is newer.
402 ######################################################################
404 my ($file1, $file2) = @_;
405 my $file1contents = fileContents($file1);
406 my $file2contents = fileContents($file2);
407 if (! -e $file1) { return 1; }
408 if (! -e $file2) { return -1; }
409 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
412 ######################################################################
413 # Syntax: copyFile(file, ifile)
414 # Params: file, string, filename to create duplicate for
415 # ifile, string, destination name of duplicate
417 # Purpose: Keeps files in sync so changes in the newer file will be
418 # written to the other.
419 # Returns: 1 if files were synced, else 0.
420 # Warning: Dies if script cannot get write access.
421 ######################################################################
424 my ($lib, $file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
425 # Bi-directional synchronization
426 open( I, "< " . $file ) || die "Could not open $file for reading";
431 if ( open(I, "< " . $ifile) ) {
434 $ifilecontents = <I>;
436 $copy = fileCompare($file, $ifile);
443 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
445 my $file_dir = dirname($file);
446 make_path($file_dir, $lib, $verbose_level);
447 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
450 print O $ifilecontents;
452 utime time, (stat($ifile))[9], $file;
454 } elsif ( $copy < 0 ) {
455 my $ifile_dir = dirname($ifile);
456 make_path($ifile_dir, $lib, $verbose_level);
457 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
460 print O $filecontents;
462 utime time, (stat($file))[9], $ifile;
469 ######################################################################
470 # Syntax: symlinkFile(file, ifile)
471 # Params: file, string, filename to create "symlink" for
472 # ifile, string, destination name of symlink
474 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
476 # Returns: 1 on success, else 0.
477 ######################################################################
480 my ($lib, $file, $ifile) = @_;
483 print "$lib: symlink created for $file " if ($verbose_level);
484 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
488 $t =~ s-^$quoted_basedir/--;
489 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
490 $file =~ s-^$quoted_basedir/-$p-;
491 print " ($file)\n" if($verbose_level);
493 print "\n" if($verbose_level);
494 return symlink($file, $ifile);
496 return copyFile($lib, $file, $ifile);
499 ######################################################################
500 # Syntax: findFiles(dir, match, descend)
501 # Params: dir, string, directory to search for name
502 # match, string, regular expression to match in dir
503 # descend, integer, 0 = non-recursive search
504 # 1 = recurse search into subdirectories
506 # Purpose: Finds files matching a regular expression.
507 # Returns: List of matching files.
510 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
511 # findFiles("/tmp","^#",0) - finds #* files in /tmp
512 ######################################################################
514 my ($dir,$match,$descend) = @_;
515 my ($file,$p,@files);
517 normalizePath(\$dir);
518 ($dir eq "") && ($dir = ".");
519 if ( opendir(D,$dir) ) {
523 ($dir =~ /\/$/) || ($dir .= "/");
525 foreach $file ( sort readdir(D) ) {
526 next if ( $file =~ /^\.\.?$/ );
528 ($file =~ /$match/) && (push @files, $p);
529 if ( $descend && -d $p && ! -l $p ) {
530 push @files, &findFiles($p,$match,$descend);
540 foreach my $subdir (@subdirs) {
541 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
542 foreach my $t (sort readdir(DIR)) {
543 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
544 !($t eq "..") && !($t eq ".obj") &&
545 !($t eq ".moc") && !($t eq ".rcc") &&
546 !($t eq ".uic") && !($t eq "build") &&
554 ######################################################################
555 # Syntax: loadSyncProfile()
557 # Purpose: Locates the sync.profile.
558 # Returns: Hashmap of module name -> directory.
559 ######################################################################
560 sub loadSyncProfile {
561 my ($srcbase, $outbase) = @_;
562 if ($verbose_level) {
563 print("<srcbase> = $$srcbase \n");
564 print("<outbase> = $$outbase \n");
567 my $syncprofile = "$$srcbase/sync.profile";
569 unless ($result = do "$syncprofile") {
570 die "syncqt couldn't parse $syncprofile: $@" if $@;
571 die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
578 $$arg =~ s,^\Q$basedir\E,<srcbase>,;
579 $$arg =~ s,^\Q$out_basedir\E,<outbase>,;
584 while ($arg =~ s,[^/]+/\.\.(/|$),,) {}
588 sub locateSyncProfile
590 my ($directory) = @_;
591 $directory = abs_path($directory);
593 my $file = $directory."/sync.profile";
594 return $file if (-e $file);
595 my $odir = $directory;
596 $directory = dirname($directory);
597 return undef if ($directory eq $odir);
604 foreach my $qpa_header (@qpa_headers) {
605 return 1 if ($header =~ $qpa_header);
610 # check if this is an in-source build, and if so use that as the basedir too
611 $basedir = locateSyncProfile($out_basedir);
613 $basedir = dirname($basedir) ;
614 normalizePath(\$basedir);
615 $quoted_basedir = "\Q$basedir";
618 # --------------------------------------------------------------------
620 # --------------------------------------------------------------------
627 my $arg = shift @ARGV;
628 if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
631 } elsif($arg eq "-copy") {
634 } elsif($arg eq "-o" || $arg eq "-outdir") {
637 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
638 $arg eq "-relative" || $arg eq "-check-includes") {
639 $var = substr($arg, 1);
641 } elsif($arg =~ /^-no-(.*)$/) {
644 #these are for commandline compat
645 } elsif($arg eq "-inc") {
648 } elsif($arg eq "-module") {
651 } elsif($arg eq "-separate-module") {
652 $var = "separate-module";
654 } elsif($arg eq "-show") {
657 } elsif($arg eq "-quiet") {
660 } elsif($arg eq "-v") {
663 } elsif($arg eq "-verbose") {
666 } elsif($arg eq "-minimal") {
669 } elsif($arg eq "-private") {
670 $var = "create_private_headers";
672 } elsif($arg eq "-qtdir") {
675 } elsif($arg =~/^-/) {
676 print "Unknown option: $arg\n\n" if(!$var);
679 $basedir = locateSyncProfile($arg);
680 die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
681 $basedir = dirname($basedir);
682 normalizePath(\$basedir);
683 $quoted_basedir = "\Q$basedir";
688 if(!$var || $var eq "show_help") {
689 print "Unknown option: $arg\n\n" if(!$var);
691 } elsif ($var eq "copy") {
697 } elsif ($var eq "showonly") {
703 } elsif ($var eq "verbose") {
706 } elsif($val eq "no" && $verbose_level) {
709 $verbose_level = int($val);
711 } elsif ($var eq "check-includes") {
714 } elsif($check_includes) {
717 } elsif ($var eq "remove-stale") {
720 } elsif($remove_stale) {
723 } elsif ($var eq "windows") {
726 } elsif($force_win) {
729 } elsif ($var eq "relative") {
732 } elsif($force_relative) {
735 } elsif ($var eq "minimal") {
741 } elsif ($var eq "module") {
742 push @modules_to_sync, $val;
743 } elsif ($var eq "separate-module") {
744 my ($module, $prodir, $headerdir) = split(/:/, $val);
745 $modules{$module} = $prodir;
746 push @modules_to_sync, $module;
747 $moduleheaders{$module} = $headerdir;
748 $create_uic_class_map = 0;
749 } elsif ($var eq "qtdir") {
752 normalizePath(\$qtbasedir);
754 die "The -qtdir option requires an argument";
756 } elsif ($var eq "output") {
758 if(checkRelative($outdir)) {
759 $out_basedir = getcwd();
761 $out_basedir .= "/" . $outdir;
763 $out_basedir = $outdir;
765 normalizePath(\$out_basedir);
769 die "Cannot automatically detect/use provided path to QtBase's build directory!\n" .
770 "QTDIR detected/provided: " . (defined $qtbasedir ? $qtbasedir : "-none-") . "\n" .
771 "Please use the -qtdir option to provide the correct path.\nsyncqt failed"
772 if (!$qtbasedir || !-d "$qtbasedir/mkspecs");
774 # if we have no $basedir we cannot be sure which sources you want, so die
775 die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
777 my $class_lib_map_contents = "";
778 our @ignore_headers = ();
779 our @ignore_for_master_contents = ();
780 our @ignore_for_include_check = ();
781 our @ignore_for_qt_begin_header_check = ();
782 our @ignore_for_qt_begin_namespace_check = ();
783 our @ignore_for_qt_module_check = ();
784 our %inject_headers = ();
786 # load the module's sync.profile here, before we can
787 loadSyncProfile(\$basedir, \$out_basedir);
789 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
791 my %allmoduleheadersprivate = map { $_ => 1 } @allmoduleheadersprivate;
793 $isunix = checkUnix; #cache checkUnix
795 my $qt_version = fileContents($qtbasedir."/mkspecs/qconfig.pri");
796 if (length($qt_version)) {
797 $qt_version =~ s,.*^QT_VERSION\h*=\h*(\S+).*,$1,sm;
799 $qt_version = fileContents($basedir."/src/corelib/global/qglobal.h");
800 $qt_version =~ s,.*^#\h*define\h+QT_VERSION_STR\h+"([^"]+)".*,$1,sm;
802 foreach my $lib (@modules_to_sync) {
803 die "No such module: $lib" unless(defined $modules{$lib});
806 my $dir = $modules{$lib};
809 $project =~ s,/([^/]+)$,/$1/$1.pro,;
810 my $module_version = fileContents($project);
811 $module_version = $qt_version unless ($module_version =~ s,.*^VERSION\h*=\h*(\S+).*,$1,sm);
813 # Backwards compatibility for modules with checked in .pri files.
814 if (defined $modulepris{$lib} and -e "$modulepris{$lib}") {
815 my $content = fileContents($modulepris{$lib});
816 my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
818 # We only pick the first one, since each module need a separate .pri file
819 $module_version = $version_rows[0];
820 chomp $module_version;
821 $module_version =~ s/^\s*QT\..*\.VERSION\s*=\s*([^#]+).*$/$1/;
822 $module_version =~ s/\s+$//;
826 my $pathtoheaders = "";
827 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
829 my $allheadersprivate = 0;
830 $allheadersprivate = 1 if $allmoduleheadersprivate{$lib};
832 #information used after the syncing
833 my $pri_install_classes = "";
834 my $pri_install_files = "";
835 my $pri_install_pfiles = "";
836 my $pri_install_qpafiles = "";
838 #remove the old files
841 for my $p (keys %inject_headers) {
842 next unless ($p =~ /^\Q$dir\E(\/|$)/);
844 $sp =~ s,^\Q$basedir\E/,$out_basedir/,;
845 for my $n (@{$inject_headers{$p}}) {
846 $injections{$sp."/".$n} = 1;
849 my @subdirs = ("$out_basedir/include/$lib");
850 foreach my $subdir (@subdirs) {
851 if (opendir DIR, $subdir) {
852 foreach my $t (sort { $b cmp $a } readdir(DIR)) {
853 my $file = "$subdir/$t";
855 push @subdirs, $file unless($t eq "." || $t eq "..");
858 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
859 foreach my $file (@files) {
861 if(open(F, "<$file")) {
862 while(my $line = <F>) {
864 if($line =~ /^\#include \"([^\"]*)\"$/) {
866 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
867 $remove_file = 1 unless(-e $include or defined $injections{cleanPath($include)});
874 unlink $file if($remove_file);
886 foreach my $current_dir (split(/;/, $dir)) {
887 my @headers_paths = split(/;/, $pathtoheaders);
888 if (@headers_paths) {
889 @headers_paths = map { "$current_dir/$_" } @headers_paths;
891 push @headers_paths, $current_dir;
894 foreach my $headers_dir (@headers_paths) {
896 my @subdirs = listSubdirs($headers_dir);
898 #calc files and "copy" them
899 foreach my $subdir (@subdirs) {
900 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
901 if (defined $inject_headers{$subdir}) {
902 foreach my $if (@{$inject_headers{$subdir}}) {
903 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
904 push @headers, "*".$if;
907 my $header_dirname = "";
908 foreach my $header (@headers) {
909 my $shadow = ($header =~ s/^\*//);
910 $header = 0 if($header =~ /^ui_.*.h/);
911 foreach (@ignore_headers) {
912 $header = 0 if($header eq $_);
915 my $header_copies = 0;
916 #figure out if it is a public header
917 my $public_header = $header;
919 if(isQpaHeader($public_header)) {
922 } elsif($allheadersprivate || $public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
925 foreach (@ignore_for_master_contents) {
926 $public_header = 0 if($header eq $_);
930 my $iheader = $subdir . "/" . $header;
931 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
932 my @classes = $public_header && !$minimal ? classNames($iheader) : ();
934 print "$header [$lib]\n";
936 print "SYMBOL: $_\n";
939 my $ts = (stat($iheader))[9];
940 #find out all the places it goes..
942 if ($public_header) {
943 @headers = ( "$out_basedir/include/$lib/$header" );
944 foreach my $full_class (@classes) {
945 my $header_base = basename($header);
947 my $class = $full_class;
949 # if ($class =~ m/::/) {
953 if (defined $explicitheaders{$lib}{$class}) {
954 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$explicitheaders{$lib}{$class}", 0, $ts));
956 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
957 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
960 # KDE-Compat headers for Phonon
961 if ($lib eq "phonon") {
962 $header_copies++ if (syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
966 if ($explicitheaders{$lib}{basename($header)}) {
967 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$explicitheaders{$lib}{basename($header)}", "$out_basedir/include/$lib/$header", 0, $ts));
970 } elsif ($create_private_headers && !$qpa_header) {
971 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
972 } elsif ($create_private_headers) {
973 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/qpa/$header" );
976 foreach(@headers) { #sync them
977 $header_copies++ if(syncHeader($lib, $_, $iheader, $copy_headers && !$shadow, $ts));
981 #deal with the install directives
983 my $pri_install_iheader = fixPaths($iheader, $current_dir);
984 foreach my $class (@classes) {
987 # if ($class =~ m/::/) {
988 # $class =~ s,::,/,g;
990 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
992 $pri_install_classes .= $class_header
993 unless($pri_install_classes =~ $class_header);
995 if ($explicitheaders{$lib}{basename($iheader)}) {
996 my $compat_header = fixPaths("$out_basedir/include/$lib/$explicitheaders{$lib}{basename($iheader)}", $current_dir) . " ";
997 $pri_install_files .= $compat_header unless($pri_install_files =~ $compat_header);
999 $pri_install_files.= "$pri_install_iheader ";;
1002 elsif ($qpa_header) {
1003 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1004 $pri_install_qpafiles.= "$pri_install_iheader ";;
1007 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1008 $pri_install_pfiles.= "$pri_install_iheader ";;
1012 if ($verbose_level && $header_copies) {
1013 my $new_header_dirname = dirname($iheader);
1014 basePrettify(\$new_header_dirname) if ($new_header_dirname && $verbose_level < 2);
1015 my $header_base = basename($iheader);
1016 if ($verbose_level < 3) {
1017 my $line_prefix = ",";
1018 if ($new_header_dirname ne $header_dirname) {
1019 $line_prefix = "$lib: created fwd-include header(s) for $new_header_dirname/ {";
1020 $line_prefix = " }\n".$line_prefix if ($header_dirname);
1021 $header_dirname = $new_header_dirname;
1025 print "$line_prefix $header_base ($header_copies)";
1026 } else { # $verbose_level >= 3
1027 basePrettify(\$iheader) if ($verbose_level == 3);
1028 print "$lib: created $header_copies fwd-include headers for $iheader\n";
1033 print " }\n" if ($header_dirname && $verbose_level > 0 && $verbose_level < 3);
1038 unless ($showonly || $minimal) {
1039 # create deprecated headers
1041 while (my ($header, $include) = each %{$deprecatedheaders{$lib}}) {
1042 my $public_header = 0;
1043 $public_header = 1 unless ($allheadersprivate || ($header =~ /_p\.h$/));
1044 next unless ($public_header || $create_private_headers);
1046 my $header_path = "$out_basedir/include/$lib/";
1047 unless ($public_header) {
1048 $header_path .= "$module_version/$lib/private/";
1050 $header_path .= "$header";
1052 unless (-e $header_path) {
1053 my $guard = "DEPRECATED_HEADER_" . $lib . "_" . $header;
1054 $guard =~ s/([^a-zA-Z0-9_])/_/g;
1056 my $header_dir = dirname($header_path);
1057 make_path($header_dir, $lib, $verbose_level);
1059 open(HEADER, ">$header_path") || die "Could not open $header_path for writing: $!\n";
1060 print HEADER "#ifndef $guard\n";
1061 print HEADER "#define $guard\n";
1062 my $warning = "Header <$lib/";
1063 $warning .= "private/" unless ($public_header);
1064 $warning .= "$header> is deprecated. Please include <$include> instead.";
1065 print HEADER "#if defined(__GNUC__)\n";
1066 print HEADER "# warning $warning\n";
1067 print HEADER "#elif defined(_MSC_VER)\n";
1068 print HEADER "# pragma message (\"$warning\")\n";
1069 print HEADER "#endif\n";
1070 print HEADER "#include <$include>\n";
1071 if ($public_header) {
1072 print HEADER "#if 0\n";
1073 print HEADER "#pragma qt_no_master_include\n";
1074 print HEADER "#endif\n";
1076 print HEADER "#endif\n";
1079 if ($verbose_level < 3) {
1080 my $line_prefix = ",";
1081 $line_prefix = "$lib: created deprecated header(s) {" if ($first);
1082 print "$line_prefix $header";
1084 print "$lib: created deprecated header $header => $include\n";
1089 my $addendum = fixPaths($header_path, $dir) . " ";
1090 if ($public_header) {
1091 $pri_install_files .= $addendum;
1093 $pri_install_pfiles .= $addendum;
1096 if ($verbose_level < 3) {
1097 print " }\n" unless ($first);
1100 # module version header
1101 my $vheader = "$out_basedir/include/$lib/".lc($lib)."version.h";
1102 my $VHeader = "$out_basedir/include/$lib/${lib}Version";
1103 syncHeader($lib, $VHeader, $vheader, 0);
1104 $pri_install_files .= fixPaths($vheader, $dir) . " ";
1105 $pri_install_classes .= fixPaths($VHeader, $dir) . " ";
1107 # KDE-Compat master header for Phonon
1108 if ($lib eq "phonon") {
1109 syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/Phonon", "$out_basedir/include/phonon/phonon", 0);
1112 #handle the headers.pri for each module
1113 my $headers_pri_contents = "";
1114 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1115 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1116 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1117 $headers_pri_contents .= "SYNCQT.QPA_HEADER_FILES = $pri_install_qpafiles\n";
1118 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1119 if(-e $headers_pri_file) {
1120 open HEADERS_PRI_FILE, "<$headers_pri_file";
1122 binmode HEADERS_PRI_FILE;
1123 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1124 close HEADERS_PRI_FILE;
1125 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1126 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1128 if($headers_pri_file) {
1129 my $headers_pri_dir = dirname($headers_pri_file);
1130 make_path($headers_pri_dir, $lib, $verbose_level);
1131 open HEADERS_PRI_FILE, ">$headers_pri_file";
1132 print HEADERS_PRI_FILE $headers_pri_contents;
1133 close HEADERS_PRI_FILE;
1134 print "$lib: created headers.pri file\n" if($verbose_level);
1138 unless($showonly || !$create_uic_class_map) {
1139 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1140 if(-e $class_lib_map) {
1141 open CLASS_LIB_MAP, "<$class_lib_map";
1143 binmode CLASS_LIB_MAP;
1144 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1145 close CLASS_LIB_MAP;
1146 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1147 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1149 if($class_lib_map) {
1150 my $class_lib_map_dir = dirname($class_lib_map);
1151 make_path($class_lib_map_dir, "<outdir>", $verbose_level);
1152 open CLASS_LIB_MAP, ">$class_lib_map";
1153 print CLASS_LIB_MAP $class_lib_map_contents;
1154 close CLASS_LIB_MAP;
1158 if($check_includes) {
1159 for my $lib (keys(%modules)) {
1161 my @subdirs = listSubdirs($modules{$lib});
1163 foreach my $subdir (@subdirs) {
1164 my $header_skip_qt_module_test = 0;
1165 foreach(@ignore_for_qt_module_check) {
1166 foreach (split(/;/, $_)) {
1167 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1170 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1171 foreach my $header (@headers) {
1172 my $header_skip_qt_begin_header_test = 0;
1173 my $header_skip_qt_begin_namespace_test = 0;
1174 $header = 0 if($header =~ /^ui_.*.h/);
1175 foreach (@ignore_headers) {
1176 $header = 0 if($header eq $_);
1179 my $public_header = $header;
1180 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1182 } elsif (isQpaHeader($public_header)) {
1185 foreach (@ignore_for_master_contents) {
1186 $public_header = 0 if($header eq $_);
1188 if($public_header) {
1189 foreach (@ignore_for_include_check) {
1190 $public_header = 0 if($header eq $_);
1192 foreach(@ignore_for_qt_begin_header_check) {
1193 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1195 foreach(@ignore_for_qt_begin_namespace_check) {
1196 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1201 my $iheader = $subdir . "/" . $header;
1202 if($public_header) {
1203 if(open(F, "<$iheader")) {
1204 my $qt_begin_header_found = 0;
1205 my $qt_end_header_found = 0;
1206 my $qt_begin_namespace_found = 0;
1207 my $qt_end_namespace_found = 0;
1209 while($line = <F>) {
1211 my $output_line = 1;
1212 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1214 } elsif($line =~ /^ *\# *include/) {
1215 my $include = $line;
1216 if($line =~ /<.*>/) {
1217 $include =~ s,.*<(.*)>.*,$1,;
1218 } elsif($line =~ /".*"/) {
1219 $include =~ s,.*"(.*)".*,$1,;
1224 for my $trylib (keys(%modules)) {
1225 if(-e "$out_basedir/include/$trylib/$include") {
1226 print "$lib: WARNING: $iheader includes $include when it should include $trylib/$include\n";
1230 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1231 $qt_begin_header_found = 1;
1232 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1233 $qt_end_header_found = 1;
1234 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1235 $qt_begin_namespace_found = 1;
1236 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1237 $qt_end_namespace_found = 1;
1240 if ($header_skip_qt_begin_header_test == 0) {
1241 if ($qt_begin_header_found == 0) {
1242 print "$lib: WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1245 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1246 print "$lib: WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1250 if ($header_skip_qt_begin_namespace_test == 0) {
1251 if ($qt_begin_namespace_found == 0) {
1252 print "$lib: WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1255 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1256 print "$lib: WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";