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 $mkspecsdir = dirname(dirname($0));
87 normalizePath(\$mkspecsdir) if (defined $mkspecsdir);
89 # will be defined based on the modules sync.profile
90 our (%modules, %moduleheaders, @allmoduleheadersprivate, %classnames, %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 " -mkspecsdir <PATH> Set the path to the mkspecs (detected: " . (defined $mkspecsdir ? $mkspecsdir : "-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 "-mkspecsdir") {
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 "mkspecsdir") {
752 normalizePath(\$mkspecsdir);
754 die "The -mkspecsdir 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 $mkspecsdir ? $mkspecsdir : "-none-") . "\n" .
771 "Please use the -mkspecsdir option to provide the correct path.\nsyncqt failed"
772 if (!$mkspecsdir || !-d $mkspecsdir);
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($mkspecsdir."/qconfig.pri");
796 if (length($qt_version)) {
797 $qt_version =~ s,.*^QT_VERSION[ \t]*=[ \t]*(\S+).*,$1,sm;
799 $qt_version = fileContents($basedir."/src/corelib/global/qglobal.h");
800 $qt_version =~ s,.*^#[ \t]*define[ \t]+QT_VERSION_STR[ \t]+"([^"]+)".*,$1,sm;
802 foreach my $lib (@modules_to_sync) {
803 die "No such module: $lib" unless(defined $modules{$lib});
806 my @dirs = split(/;/, $modules{$lib});
810 $project =~ s,/([^/]+)$,/$1/$1.pro,;
811 my $module_version = fileContents($project);
812 $module_version = $qt_version unless ($module_version =~ s,.*^VERSION[ \t]*=[ \t]*(\S+).*,$1,sm);
814 my $pathtoheaders = "";
815 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
817 my $allheadersprivate = 0;
818 $allheadersprivate = 1 if $allmoduleheadersprivate{$lib};
820 #information used after the syncing
821 my $pri_install_classes = "";
822 my $pri_install_files = "";
823 my $pri_install_pfiles = "";
824 my $pri_install_qpafiles = "";
826 #remove the old files
829 for my $p (keys %inject_headers) {
830 next unless ($p =~ /^\Q$dir\E(\/|$)/);
832 $sp =~ s,^\Q$basedir\E/,$out_basedir/,;
833 for my $n (@{$inject_headers{$p}}) {
834 $injections{$sp."/".$n} = 1;
837 my @subdirs = ("$out_basedir/include/$lib");
838 foreach my $subdir (@subdirs) {
839 if (opendir DIR, $subdir) {
840 foreach my $t (sort { $b cmp $a } readdir(DIR)) {
841 my $file = "$subdir/$t";
843 push @subdirs, $file unless($t eq "." || $t eq "..");
846 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
847 foreach my $file (@files) {
849 if(open(F, "<$file")) {
850 while(my $line = <F>) {
852 if($line =~ /^\#include \"([^\"]*)\"$/) {
854 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
855 $remove_file = 1 unless(-e $include or defined $injections{cleanPath($include)});
862 unlink $file if($remove_file);
874 foreach my $current_dir (@dirs) {
876 ($current_dir =~ s/^\^//) and $thisprivate = 1;
877 my @headers_paths = split(/;/, $pathtoheaders);
878 if (@headers_paths) {
879 @headers_paths = map { "$current_dir/$_" } @headers_paths;
881 push @headers_paths, $current_dir;
884 foreach my $headers_dir (@headers_paths) {
886 my @subdirs = listSubdirs($headers_dir);
888 #calc files and "copy" them
889 foreach my $subdir (@subdirs) {
890 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
891 if (defined $inject_headers{$subdir}) {
892 foreach my $if (@{$inject_headers{$subdir}}) {
893 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
894 push @headers, "*".$if;
897 my $header_dirname = "";
898 foreach my $header (@headers) {
899 my $shadow = ($header =~ s/^\*//);
900 $header = 0 if($header =~ /^ui_.*.h/);
901 foreach (@ignore_headers) {
902 $header = 0 if($header eq $_);
905 my $header_copies = 0;
906 #figure out if it is a public header
907 my $public_header = $header;
909 if(isQpaHeader($public_header)) {
912 } elsif($allheadersprivate || $thisprivate || $public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
915 foreach (@ignore_for_master_contents) {
916 $public_header = 0 if($header eq $_);
920 my $iheader = $subdir . "/" . $header;
921 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
922 my @classes = $public_header && !$minimal ? classNames($iheader) : ();
924 print "$header [$lib]\n";
926 print "SYMBOL: $_\n";
929 my $ts = (stat($iheader))[9];
930 #find out all the places it goes..
932 if ($public_header) {
933 @headers = ( "$out_basedir/include/$lib/$header" );
934 foreach my $full_class (@classes) {
935 my $header_base = basename($header);
937 my $class = $full_class;
939 # if ($class =~ m/::/) {
943 if (defined $explicitheaders{$lib}{$class}) {
944 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$explicitheaders{$lib}{$class}", 0, $ts));
946 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
947 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
950 # KDE-Compat headers for Phonon
951 if ($lib eq "phonon") {
952 $header_copies++ if (syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
956 if ($explicitheaders{$lib}{basename($header)}) {
957 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$explicitheaders{$lib}{basename($header)}", "$out_basedir/include/$lib/$header", 0, $ts));
960 } elsif ($create_private_headers && !$qpa_header) {
961 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
962 } elsif ($create_private_headers) {
963 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/qpa/$header" );
966 foreach(@headers) { #sync them
967 $header_copies++ if(syncHeader($lib, $_, $iheader, $copy_headers && !$shadow, $ts));
971 #deal with the install directives
973 my $pri_install_iheader = fixPaths($iheader, $current_dir);
974 foreach my $class (@classes) {
977 # if ($class =~ m/::/) {
978 # $class =~ s,::,/,g;
980 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
982 $pri_install_classes .= $class_header
983 unless($pri_install_classes =~ $class_header);
985 if ($explicitheaders{$lib}{basename($iheader)}) {
986 my $compat_header = fixPaths("$out_basedir/include/$lib/$explicitheaders{$lib}{basename($iheader)}", $current_dir) . " ";
987 $pri_install_files .= $compat_header unless($pri_install_files =~ $compat_header);
989 $pri_install_files.= "$pri_install_iheader ";;
992 elsif ($qpa_header) {
993 my $pri_install_iheader = fixPaths($iheader, $current_dir);
994 $pri_install_qpafiles.= "$pri_install_iheader ";;
997 my $pri_install_iheader = fixPaths($iheader, $current_dir);
998 $pri_install_pfiles.= "$pri_install_iheader ";;
1002 if ($verbose_level && $header_copies) {
1003 my $new_header_dirname = dirname($iheader);
1004 basePrettify(\$new_header_dirname) if ($new_header_dirname && $verbose_level < 2);
1005 my $header_base = basename($iheader);
1006 if ($verbose_level < 3) {
1007 my $line_prefix = ",";
1008 if ($new_header_dirname ne $header_dirname) {
1009 $line_prefix = "$lib: created fwd-include header(s) for $new_header_dirname/ {";
1010 $line_prefix = " }\n".$line_prefix if ($header_dirname);
1011 $header_dirname = $new_header_dirname;
1015 print "$line_prefix $header_base ($header_copies)";
1016 } else { # $verbose_level >= 3
1017 basePrettify(\$iheader) if ($verbose_level == 3);
1018 print "$lib: created $header_copies fwd-include headers for $iheader\n";
1023 print " }\n" if ($header_dirname && $verbose_level > 0 && $verbose_level < 3);
1028 unless ($showonly || $minimal) {
1029 # create deprecated headers
1031 while (my ($header, $include) = each %{$deprecatedheaders{$lib}}) {
1032 my $public_header = 0;
1033 $public_header = 1 unless ($allheadersprivate || ($header =~ /_p\.h$/));
1034 next unless ($public_header || $create_private_headers);
1036 my $header_path = "$out_basedir/include/$lib/";
1037 unless ($public_header) {
1038 $header_path .= "$module_version/$lib/private/";
1040 $header_path .= "$header";
1042 unless (-e $header_path) {
1043 my $guard = "DEPRECATED_HEADER_" . $lib . "_" . $header;
1044 $guard =~ s/([^a-zA-Z0-9_])/_/g;
1046 my $header_dir = dirname($header_path);
1047 make_path($header_dir, $lib, $verbose_level);
1049 open(HEADER, ">$header_path") || die "Could not open $header_path for writing: $!\n";
1050 print HEADER "#ifndef $guard\n";
1051 print HEADER "#define $guard\n";
1052 my $warning = "Header <$lib/";
1053 $warning .= "private/" unless ($public_header);
1054 $warning .= "$header> is deprecated. Please include <$include> instead.";
1055 print HEADER "#if defined(__GNUC__)\n";
1056 print HEADER "# warning $warning\n";
1057 print HEADER "#elif defined(_MSC_VER)\n";
1058 print HEADER "# pragma message (\"$warning\")\n";
1059 print HEADER "#endif\n";
1060 print HEADER "#include <$include>\n";
1061 if ($public_header) {
1062 print HEADER "#if 0\n";
1063 print HEADER "#pragma qt_no_master_include\n";
1064 print HEADER "#endif\n";
1066 print HEADER "#endif\n";
1069 if ($verbose_level < 3) {
1070 my $line_prefix = ",";
1071 $line_prefix = "$lib: created deprecated header(s) {" if ($first);
1072 print "$line_prefix $header";
1074 print "$lib: created deprecated header $header => $include\n";
1079 my $addendum = fixPaths($header_path, $dir) . " ";
1080 if ($public_header) {
1081 $pri_install_files .= $addendum;
1083 $pri_install_pfiles .= $addendum;
1086 if ($verbose_level < 3) {
1087 print " }\n" unless ($first);
1090 # module version header
1091 my $vheader = "$out_basedir/include/$lib/".lc($lib)."version.h";
1092 my $VHeader = "$out_basedir/include/$lib/${lib}Version";
1093 syncHeader($lib, $VHeader, $vheader, 0);
1094 $pri_install_files .= fixPaths($vheader, $dir) . " ";
1095 $pri_install_classes .= fixPaths($VHeader, $dir) . " ";
1097 # KDE-Compat master header for Phonon
1098 if ($lib eq "phonon") {
1099 syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/Phonon", "$out_basedir/include/phonon/phonon", 0);
1102 #handle the headers.pri for each module
1103 my $headers_pri_contents = "";
1104 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1105 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1106 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1107 $headers_pri_contents .= "SYNCQT.QPA_HEADER_FILES = $pri_install_qpafiles\n";
1108 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1109 if(-e $headers_pri_file) {
1110 open HEADERS_PRI_FILE, "<$headers_pri_file";
1112 binmode HEADERS_PRI_FILE;
1113 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1114 close HEADERS_PRI_FILE;
1115 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1116 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1118 if($headers_pri_file) {
1119 my $headers_pri_dir = dirname($headers_pri_file);
1120 make_path($headers_pri_dir, $lib, $verbose_level);
1121 open HEADERS_PRI_FILE, ">$headers_pri_file";
1122 print HEADERS_PRI_FILE $headers_pri_contents;
1123 close HEADERS_PRI_FILE;
1124 print "$lib: created headers.pri file\n" if($verbose_level);
1128 unless($showonly || !$create_uic_class_map) {
1129 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1130 if(-e $class_lib_map) {
1131 open CLASS_LIB_MAP, "<$class_lib_map";
1133 binmode CLASS_LIB_MAP;
1134 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1135 close CLASS_LIB_MAP;
1136 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1137 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1139 if($class_lib_map) {
1140 my $class_lib_map_dir = dirname($class_lib_map);
1141 make_path($class_lib_map_dir, "<outdir>", $verbose_level);
1142 open CLASS_LIB_MAP, ">$class_lib_map";
1143 print CLASS_LIB_MAP $class_lib_map_contents;
1144 close CLASS_LIB_MAP;
1148 if($check_includes) {
1149 for my $lib (keys(%modules)) {
1151 my @subdirs = listSubdirs(map { s/^\^//; $_ } split(/;/, $modules{$lib}));
1153 foreach my $subdir (@subdirs) {
1154 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1155 foreach my $header (@headers) {
1156 my $header_skip_qt_begin_header_test = 0;
1157 my $header_skip_qt_begin_namespace_test = 0;
1158 $header = 0 if($header =~ /^ui_.*.h/);
1159 foreach (@ignore_headers) {
1160 $header = 0 if($header eq $_);
1163 my $public_header = $header;
1164 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1166 } elsif (isQpaHeader($public_header)) {
1169 foreach (@ignore_for_master_contents) {
1170 $public_header = 0 if($header eq $_);
1172 if($public_header) {
1173 foreach (@ignore_for_include_check) {
1174 $public_header = 0 if($header eq $_);
1176 foreach(@ignore_for_qt_begin_header_check) {
1177 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1179 foreach(@ignore_for_qt_begin_namespace_check) {
1180 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1185 my $iheader = $subdir . "/" . $header;
1186 if($public_header) {
1187 if(open(F, "<$iheader")) {
1188 my $qt_begin_header_found = 0;
1189 my $qt_end_header_found = 0;
1190 my $qt_begin_namespace_found = 0;
1191 my $qt_end_namespace_found = 0;
1193 my $stop_processing = 0;
1194 while($line = <F>) {
1196 my $output_line = 1;
1197 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1198 $stop_processing = 1;
1200 } elsif($line =~ /^ *\# *include/) {
1201 my $include = $line;
1202 if($line =~ /<.*>/) {
1203 $include =~ s,.*<(.*)>.*,$1,;
1204 } elsif($line =~ /".*"/) {
1205 $include =~ s,.*"(.*)".*,$1,;
1210 for my $trylib (keys(%modules)) {
1211 if(-e "$out_basedir/include/$trylib/$include") {
1212 print "$lib: WARNING: $iheader includes $include when it should include $trylib/$include\n";
1216 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1217 $qt_begin_header_found = 1;
1218 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1219 $qt_end_header_found = 1;
1220 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1221 $qt_begin_namespace_found = 1;
1222 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1223 $qt_end_namespace_found = 1;
1226 if ($header_skip_qt_begin_header_test == 0 and $stop_processing == 0) {
1227 if ($qt_begin_header_found == 0) {
1228 print "$lib: WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1231 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1232 print "$lib: WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1236 if ($header_skip_qt_begin_namespace_test == 0 and $stop_processing == 0) {
1237 if ($qt_begin_namespace_found == 0) {
1238 print "$lib: WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1241 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1242 print "$lib: WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";