2 ######################################################################
4 # Synchronizes Qt header files - internal development tool.
6 # Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 # Contact: Nokia Corporation (qt-info@nokia.com)
9 ######################################################################
11 # use packages -------------------------------------------------------
18 for (my $i = 0; $i < $#ARGV; $i++) {
19 if ($ARGV[$i] eq "-base-dir" && $i < $#ARGV - 1) {
20 $ENV{"QTDIR"} = $ARGV[$i + 1];
25 die "syncqt: QTDIR not defined" if ! $ENV{"QTDIR"}; # sanity check
29 my $basedir = $ENV{"QTDIR"};
31 my %modules = ( # path to module name map
32 "QtGui" => "$basedir/src/gui",
33 "QtOpenGL" => "$basedir/src/opengl",
34 "QtOpenVG" => "$basedir/src/openvg",
35 "QtCore" => "$basedir/src/corelib",
36 "QtXml" => "$basedir/src/xml",
37 "QtSql" => "$basedir/src/sql",
38 "QtNetwork" => "$basedir/src/network",
39 "QtSvg" => "$basedir/src/svg",
40 "QtTest" => "$basedir/src/testlib",
41 "QtDBus" => "$basedir/src/dbus",
43 my %moduleheaders = ( # restrict the module headers to those found in relative path
46 #$modules{"QtCore"} .= ";$basedir/mkspecs/" . $ENV{"MKSPEC"} if defined $ENV{"MKSPEC"};
48 # global variables (modified by options)
54 my $force_relative = 0;
55 my $check_includes = 0;
57 my $create_uic_class_map = 1;
58 my $create_private_headers = 1;
60 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
61 my $out_basedir = $basedir;
62 $out_basedir =~ s=\\=/=g;
63 my $quoted_basedir = "\Q$basedir";
65 # functions ----------------------------------------------------------
67 ######################################################################
71 # Purpose: Show the usage of the script.
73 ######################################################################
77 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
78 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
79 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
80 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
81 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
82 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
83 print " -quiet Only report problems, not activity (default: " . ($quiet ? "yes" : "no") . ")\n";
84 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR> Create headers for <NAME> with original headers in <HEADERDIR> relative to <PROFILEDIR> \n";
85 print " -help This help\n";
89 ######################################################################
93 # Purpose: Check if script runs on a Unix system or not. Cygwin
94 # systems are _not_ detected as Unix systems.
95 # Returns: 1 if a unix system, else 0.
96 ######################################################################
99 if ( $force_win != 0) {
101 } elsif ( -f "/bin/uname" ) {
103 (-f "\\bin\\uname") && ($r = 0);
104 } elsif ( -f "/usr/bin/uname" ) {
106 (-f "\\usr\\bin\\uname") && ($r = 0);
109 $_ = $Config{'osname'};
110 $r = 0 if( /(ms)|(cyg)win/i );
117 return 0 if($dir =~ /^\//);
118 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
122 ######################################################################
123 # Syntax: shouldMasterInclude(iheader)
124 # Params: iheader, string, filename to verify inclusion
126 # Purpose: Determines if header should be in the master include file.
127 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
128 # able to open, else 1.
129 ######################################################################
130 sub shouldMasterInclude {
132 return 0 if(basename($iheader) =~ /_/);
133 return 0 if(basename($iheader) =~ /qconfig/);
134 if(open(F, "<$iheader")) {
137 return 0 if(/^\#pragma qt_no_master_include$/);
146 ######################################################################
147 # Syntax: classNames(iheader)
148 # Params: iheader, string, filename to parse for classname "symlinks"
150 # Purpose: Scans through iheader to find all classnames that should be
151 # synced into library's include structure.
152 # Returns: List of all class names in a file.
153 ######################################################################
157 if(basename($iheader) eq "qglobal.h") {
158 push @ret, "QtGlobal";
159 } elsif(basename($iheader) eq "qendian.h") {
160 push @ret, "QtEndian";
161 } elsif(basename($iheader) eq "qconfig.h") {
162 push @ret, "QtConfig";
163 } elsif(basename($iheader) eq "qplugin.h") {
164 push @ret, "QtPlugin";
165 } elsif(basename($iheader) eq "qalgorithms.h") {
166 push @ret, "QtAlgorithms";
167 } elsif(basename($iheader) eq "qcontainerfwd.h") {
168 push @ret, "QtContainerFwd";
169 } elsif(basename($iheader) eq "qdebug.h") {
170 push @ret, "QtDebug";
171 } elsif(basename($iheader) eq "qevent.h") {
172 push @ret, "QtEvents";
173 } elsif(basename($iheader) eq "qnamespace.h") {
175 } elsif(basename($iheader) eq "qssl.h") {
177 } elsif(basename($iheader) eq "qtest.h") {
179 } elsif(basename($iheader) eq "qtconcurrentmap.h") {
180 push @ret, "QtConcurrentMap"
181 } elsif(basename($iheader) eq "qtconcurrentfilter.h") {
182 push @ret, "QtConcurrentFilter"
183 } elsif(basename($iheader) eq "qtconcurrentrun.h") {
184 push @ret, "QtConcurrentRun"
185 } elsif(basename($iheader) eq "qaudio.h") {
190 if(open(F, "<$iheader")) {
194 chop $line if ($line =~ /\r$/);
199 last unless($line =~ /\\$/);
202 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
203 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
207 $line =~ s,//.*$,,; #remove c++ comments
208 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
209 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
210 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
211 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
212 $parsable .= " " . $line;
218 my $last_definition = 0;
220 for(my $i = 0; $i < length($parsable); $i++) {
222 my $character = substr($parsable, $i, 1);
223 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
224 for($i+=2; $i < length($parsable); $i++) {
225 my $end = substr($parsable, $i, 2);
227 $last_definition = $i+2;
232 } elsif($character eq "{") {
234 my $block_start = $i + 1;
235 BLOCK: for($i+=1; $i < length($parsable); $i++) {
236 my $ignore = substr($parsable, $i, 1);
239 } elsif($ignore eq "}") {
241 unless($brace_depth) {
242 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
243 my $end = substr($parsable, $i2, 1);
244 if($end eq ";" || $end ne " ") {
245 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
246 $i = $i2 if($end eq ";");
247 $last_definition = $i + 1;
254 } elsif($character eq ";") {
255 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
256 $last_definition = $i + 1;
257 } elsif($character eq "}") {
258 # a naked } must be a namespace ending
259 # if it's not a namespace, it's eaten by the loop above
261 $last_definition = $i + 1;
264 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
265 && substr($parsable, $i+1, 1) eq "{") {
266 push @namespaces, $1;
268 # Eat the opening { so that the condensing loop above doesn't see it
270 $last_definition = $i + 1;
274 $definition =~ s=[\n\r]==g;
276 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
278 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
280 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
282 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
283 push @symbols, "Q" . $1 . "Iterator";
284 push @symbols, "QMutable" . $1 . "Iterator";
287 foreach my $symbol (@symbols) {
288 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
290 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
291 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
298 ######################################################################
299 # Syntax: syncHeader(header, iheader, copy, timestamp)
300 # Params: header, string, filename to create "symlink" for
301 # iheader, string, destination name of symlink
302 # copy, forces header to be a copy of iheader
303 # timestamp, the requested modification time if copying
305 # Purpose: Syncronizes header to iheader
306 # Returns: 1 if successful, else 0.
307 ######################################################################
309 my ($header, $iheader, $copy, $ts) = @_;
310 $iheader =~ s=\\=/=g;
312 return copyFile($iheader, $header) if($copy);
315 my $header_dir = dirname($header);
316 mkpath $header_dir, !$quiet;
319 my $iheader_out = fixPaths($iheader, $header_dir);
320 open HEADER, ">$header" || die "Could not open $header for writing!\n";
321 print HEADER "#include \"$iheader_out\"\n";
324 utime(time, $ts, $header) or die "$iheader, $header";
331 ######################################################################
332 # Syntax: fixPaths(file, dir)
333 # Params: file, string, filepath to be made relative to dir
334 # dir, string, dirpath for point of origin
336 # Purpose: file is made relative (if possible) of dir.
337 # Returns: String with the above applied conversion.
338 ######################################################################
340 my ($file, $dir) = @_;
341 $dir =~ s=^$quoted_basedir/=$out_basedir/= if(!($basedir eq $out_basedir));
347 $ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
348 my $file_dir = dirname($file);
349 if($file_dir eq ".") {
350 $file_dir = getcwd();
351 $file_dir =~ s=\\=/=g;
353 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
358 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
359 return basename($file) if($file_dir eq $dir);
363 for(my $i = 1; $i < length($file_dir); $i++) {
364 my $slash = index($file_dir, "/", $i);
365 last if($slash == -1);
366 my $tmp = substr($file_dir, 0, $slash);
367 last unless($dir =~ m,^\Q$tmp\E/,);
372 my $after = substr($dir, length($match_dir));
373 my $count = ($after =~ tr,/,,);
375 for(my $i = 0; $i < $count; $i++) {
378 $ret =~ s,^\Q$match_dir\E,$dots,;
384 ######################################################################
385 # Syntax: fileContents(filename)
386 # Params: filename, string, filename of file to return contents
388 # Purpose: Get the contents of a file.
389 # Returns: String with contents of the file, or empty string if file
391 # Warning: Dies if it does exist but script cannot get read access.
392 ######################################################################
395 my $filecontents = "";
397 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
403 return $filecontents;
406 ######################################################################
407 # Syntax: fileCompare(file1, file2)
408 # Params: file1, string, filename of first file
409 # file2, string, filename of second file
411 # Purpose: Determines if files are equal, and which one is newer.
412 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
413 # is newer, 1 if file2 is newer.
414 ######################################################################
416 my ($file1, $file2) = @_;
417 my $file1contents = fileContents($file1);
418 my $file2contents = fileContents($file2);
419 if (! -e $file1) { return 1; }
420 if (! -e $file2) { return -1; }
421 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
424 ######################################################################
425 # Syntax: copyFile(file, ifile)
426 # Params: file, string, filename to create duplicate for
427 # ifile, string, destination name of duplicate
429 # Purpose: Keeps files in sync so changes in the newer file will be
430 # written to the other.
431 # Returns: 1 if files were synced, else 0.
432 # Warning: Dies if script cannot get write access.
433 ######################################################################
436 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
437 # Bi-directional synchronization
438 open( I, "< " . $file ) || die "Could not open $file for reading";
443 if ( open(I, "< " . $ifile) ) {
446 $ifilecontents = <I>;
448 $copy = fileCompare($file, $ifile);
455 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
457 my $file_dir = dirname($file);
458 mkpath $file_dir, !$quiet unless(-e $file_dir);
459 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
462 print O $ifilecontents;
464 utime time, (stat($ifile))[9], $file;
466 } elsif ( $copy < 0 ) {
467 my $ifile_dir = dirname($ifile);
468 mkpath $ifile_dir, !$quiet unless(-e $ifile_dir);
469 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
472 print O $filecontents;
474 utime time, (stat($file))[9], $ifile;
481 ######################################################################
482 # Syntax: symlinkFile(file, ifile)
483 # Params: file, string, filename to create "symlink" for
484 # ifile, string, destination name of symlink
486 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
488 # Returns: 1 on success, else 0.
489 ######################################################################
492 my ($file,$ifile) = @_;
495 print "symlink created for $file " unless $quiet;
496 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
500 $t =~ s-^$quoted_basedir/--;
501 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
502 $file =~ s-^$quoted_basedir/-$p-;
503 print " ($file)\n" unless $quiet;
505 print "\n" unless $quiet;
506 return symlink($file, $ifile);
508 return copyFile($file, $ifile);
511 ######################################################################
512 # Syntax: findFiles(dir, match, descend)
513 # Params: dir, string, directory to search for name
514 # match, string, regular expression to match in dir
515 # descend, integer, 0 = non-recursive search
516 # 1 = recurse search into subdirectories
518 # Purpose: Finds files matching a regular expression.
519 # Returns: List of matching files.
522 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
523 # findFiles("/tmp","^#",0) - finds #* files in /tmp
524 ######################################################################
526 my ($dir,$match,$descend) = @_;
527 my ($file,$p,@files);
530 ($dir eq "") && ($dir = ".");
531 if ( opendir(D,$dir) ) {
535 ($dir =~ /\/$/) || ($dir .= "/");
537 foreach $file ( sort readdir(D) ) {
538 next if ( $file =~ /^\.\.?$/ );
540 ($file =~ /$match/) && (push @files, $p);
541 if ( $descend && -d $p && ! -l $p ) {
542 push @files, &findFiles($p,$match,$descend);
550 # --------------------------------------------------------------------
552 # --------------------------------------------------------------------
559 my $arg = shift @ARGV;
560 if ($arg eq "-h" || $arg eq "-help" || $arg eq "?") {
563 } elsif($arg eq "-copy") {
566 } elsif($arg eq "-o" || $arg eq "-outdir") {
569 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
570 $arg eq "-relative" || $arg eq "-check-includes") {
571 $var = substr($arg, 1);
573 } elsif($arg =~ /^-no-(.*)$/) {
576 #these are for commandline compat
577 } elsif($arg eq "-inc") {
580 } elsif($arg eq "-module") {
583 } elsif($arg eq "-separate-module") {
584 $var = "separate-module";
586 } elsif($arg eq "-show") {
589 } elsif($arg eq "-quiet") {
592 } elsif($arg eq "-base-dir") {
593 # skip, it's been dealt with at the top of the file
599 if(!$var || $var eq "show_help") {
600 print "Unknown option: $arg\n\n" if(!$var);
602 } elsif ($var eq "copy") {
608 } elsif ($var eq "showonly") {
614 } elsif ($var eq "quiet") {
620 } elsif ($var eq "check-includes") {
623 } elsif($check_includes) {
626 } elsif ($var eq "remove-stale") {
629 } elsif($remove_stale) {
632 } elsif ($var eq "windows") {
635 } elsif($force_win) {
638 } elsif ($var eq "relative") {
641 } elsif($force_relative) {
644 } elsif ($var eq "module") {
645 print "module :$val:\n" unless $quiet;
646 die "No such module: $val" unless(defined $modules{$val});
647 push @modules_to_sync, $val;
648 } elsif ($var eq "separate-module") {
649 my ($module, $prodir, $headerdir) = split(/:/, $val);
650 $modules{$module} = $prodir;
651 push @modules_to_sync, $module;
652 $moduleheaders{$module} = $headerdir;
653 $create_uic_class_map = 0;
654 $create_private_headers = 0;
655 } elsif ($var eq "output") {
657 if(checkRelative($outdir)) {
658 $out_basedir = getcwd();
660 $out_basedir .= "/" . $outdir;
662 $out_basedir = $outdir;
665 $out_basedir =~ s=\\=/=g;
668 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
670 $isunix = checkUnix; #cache checkUnix
673 mkpath "$out_basedir/include", !$quiet;
674 mkpath "$out_basedir/include/Qt", !$quiet;
676 my @ignore_headers = ();
677 my $class_lib_map_contents = "";
678 my @ignore_for_master_contents = ( "qt.h", "qpaintdevicedefs.h" );
679 my @ignore_for_include_check = ( "qatomic.h" );
680 my @ignore_for_qt_begin_header_check = ( "qiconset.h", "qconfig.h", "qconfig-dist.h", "qconfig-large.h", "qconfig-medium.h", "qconfig-minimal.h", "qconfig-small.h", "qfeatures.h", "qt_windows.h" );
681 my @ignore_for_qt_begin_namespace_check = ( "qconfig.h", "qconfig-dist.h", "qconfig-large.h", "qconfig-medium.h", "qconfig-minimal.h", "qconfig-small.h", "qfeatures.h", "qatomic_arch.h", "qatomic_windowsce.h", "qt_windows.h", "qatomic_macosx.h", "qatomic_arm.h", "qatomic_armv7.h" );
682 my @ignore_for_qt_module_check = ( "$modules{QtCore}/arch", "$modules{QtCore}/global", "$modules{QtSql}/drivers", "$modules{QtTest}", "$modules{QtDBus}" );
683 my %colliding_headers = ();
684 my %inject_headers = ( "$basedir/src/corelib/global" => ( "qconfig.h" ) ); # all from build dir
686 foreach my $lib (@modules_to_sync) {
688 my $dir = $modules{$lib};
689 my $pathtoheaders = "";
690 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
692 #information used after the syncing
693 my $pri_install_classes = "";
694 my $pri_install_files = "";
695 my $pri_install_pfiles = "";
697 my $libcapitals = $lib;
698 $libcapitals =~ y/a-z/A-Z/;
699 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
702 if(-e "$dir/" . basename($dir) . ".pro") {
703 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
704 while(my $line = <F>) {
706 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
707 foreach(split(/ /, $1)) {
708 $master_contents .= "#include <QtCore/QtCore>\n" if($_ eq "core");
709 $master_contents .= "#include <QtGui/QtGui>\n" if($_ eq "gui");
710 $master_contents .= "#include <QtNetwork/QtNetwork>\n" if($_ eq "network");
711 $master_contents .= "#include <QtSvg/QtSvg>\n" if($_ eq "svg");
712 $master_contents .= "#include <QtDeclarative/QtDeclarative>\n" if($_ eq "declarative");
713 $master_contents .= "#include <QtScript/QtScript>\n" if($_ eq "script");
714 $master_contents .= "#include <QtScriptTools/QtScriptTools>\n" if($_ eq "scripttools");
715 $master_contents .= "#include <Qt3Support/Qt3Support>\n" if($_ eq "qt3support");
716 $master_contents .= "#include <QtSql/QtSql>\n" if($_ eq "sql");
717 $master_contents .= "#include <QtXml/QtXml>\n" if($_ eq "xml");
718 $master_contents .= "#include <QtXmlPatterns/QtXmlPatterns>\n" if($_ eq "xmlpatterns");
719 $master_contents .= "#include <QtOpenGL/QtOpenGL>\n" if($_ eq "opengl");
720 $master_contents .= "#include <QtOpenVG/QtOpenVG>\n" if($_ eq "openvg");
728 #remove the old files
730 my @subdirs = ("$out_basedir/include/$lib");
731 foreach my $subdir (@subdirs) {
732 if (opendir DIR, $subdir) {
733 while(my $t = readdir(DIR)) {
734 my $file = "$subdir/$t";
736 push @subdirs, $file unless($t eq "." || $t eq "..");
739 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
740 foreach my $file (@files) {
742 if(open(F, "<$file")) {
743 while(my $line = <F>) {
745 if($line =~ /^\#include \"([^\"]*)\"$/) {
747 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
748 $remove_file = 1 unless(-e $include);
755 unlink $file if($remove_file);
767 foreach my $current_dir (split(/;/, $dir)) {
768 my $headers_dir = $current_dir;
769 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
771 my @subdirs = ($headers_dir);
772 foreach my $subdir (@subdirs) {
773 opendir DIR, $subdir or next;
774 while(my $t = readdir(DIR)) {
775 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
776 !($t eq "..") && !($t eq ".obj") &&
777 !($t eq ".moc") && !($t eq ".rcc") &&
778 !($t eq ".uic") && !($t eq "build"));
783 #calc files and "copy" them
784 foreach my $subdir (@subdirs) {
785 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
786 if (defined $inject_headers{$subdir}) {
787 foreach my $if ($inject_headers{$subdir}) {
788 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
789 push @headers, "*".$if;
792 foreach my $header (@headers) {
793 my $shadow = ($header =~ s/^\*//);
794 $header = 0 if($header =~ /^ui_.*.h/);
795 foreach (@ignore_headers) {
796 $header = 0 if($header eq $_);
799 my $header_copies = 0;
800 #figure out if it is a public header
801 my $public_header = $header;
802 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
805 foreach (@ignore_for_master_contents) {
806 $public_header = 0 if($header eq $_);
810 my $iheader = $subdir . "/" . $header;
811 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
812 my @classes = $public_header ? classNames($iheader) : ();
814 print "$header [$lib]\n";
816 print "SYMBOL: $_\n";
819 my $ts = (stat($iheader))[9];
820 #find out all the places it goes..
822 if ($public_header) {
823 @headers = ( "$out_basedir/include/$lib/$header" );
825 # write forwarding headers to include/Qt
826 if ($lib ne "phonon" && $subdir =~ /^$quoted_basedir\/src/) {
827 my $file_name = "$out_basedir/include/Qt/$header";
829 my $header_content = '';
830 if (exists $colliding_headers{$file_name}) {
833 $colliding_headers{$file_name} = 1;
834 my $warning_msg = 'Inclusion of header files from include/Qt is deprecated.';
835 $header_content = "#ifndef QT_NO_QT_INCLUDE_WARN\n" .
836 " #if defined(__GNUC__)\n" .
837 " #warning \"$warning_msg\"\n" .
838 " #elif defined(_MSC_VER)\n" .
839 " #pragma message(\"WARNING: $warning_msg\")\n" .
843 $header_content .= '#include "' . "../$lib/$header" . "\"\n";
844 open HEADERFILE, $file_op, $file_name or die "unable to open '$file_name' : $!\n";
845 print HEADERFILE $header_content;
849 foreach my $full_class (@classes) {
850 my $header_base = basename($header);
852 my $class = $full_class;
854 # if ($class =~ m/::/) {
857 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
858 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
860 # KDE-Compat headers for Phonon
861 if ($lib eq "phonon") {
862 $header_copies++ if (syncHeader("$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
865 } elsif ($create_private_headers) {
866 @headers = ( "$out_basedir/include/$lib/private/$header" );
868 foreach(@headers) { #sync them
869 $header_copies++ if(syncHeader($_, $iheader, $copy_headers && !$shadow, $ts));
873 #put it into the master file
874 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
876 #deal with the install directives
878 my $pri_install_iheader = fixPaths($iheader, $current_dir);
879 foreach my $class (@classes) {
882 # if ($class =~ m/::/) {
883 # $class =~ s,::,/,g;
885 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
887 $pri_install_classes .= $class_header
888 unless($pri_install_classes =~ $class_header);
890 $pri_install_files.= "$pri_install_iheader ";;
894 my $pri_install_iheader = fixPaths($iheader, $current_dir);
895 $pri_install_pfiles.= "$pri_install_iheader ";;
898 print "header created for $iheader ($header_copies)\n" if($header_copies > 0 && !$quiet);
904 # close the master include:
905 $master_contents .= "#endif\n";
909 push @master_includes, "$out_basedir/include/$lib/$lib";
910 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
911 foreach my $master_include (@master_includes) {
912 #generate the "master" include file
913 my @tmp = split(/;/,$modules{$lib});
914 $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
915 if($master_include && -e $master_include) {
916 open MASTERINCLUDE, "<$master_include";
918 binmode MASTERINCLUDE;
919 my $oldmaster = <MASTERINCLUDE>;
921 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
922 $master_include = 0 if($oldmaster eq $master_contents);
924 if($master_include && $master_contents) {
925 my $master_dir = dirname($master_include);
926 mkpath $master_dir, !$quiet;
927 print "header (master) created for $lib\n" unless $quiet;
928 open MASTERINCLUDE, ">$master_include";
929 print MASTERINCLUDE $master_contents;
934 #handle the headers.pri for each module
935 my $headers_pri_contents = "";
936 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
937 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
938 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
939 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
940 if(-e $headers_pri_file) {
941 open HEADERS_PRI_FILE, "<$headers_pri_file";
943 binmode HEADERS_PRI_FILE;
944 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
945 close HEADERS_PRI_FILE;
946 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
947 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
949 if($headers_pri_file && $master_contents) {
950 my $headers_pri_dir = dirname($headers_pri_file);
951 mkpath $headers_pri_dir, !$quiet;
952 print "headers.pri file created for $lib\n" unless $quiet;
953 open HEADERS_PRI_FILE, ">$headers_pri_file";
954 print HEADERS_PRI_FILE $headers_pri_contents;
955 close HEADERS_PRI_FILE;
959 unless($showonly || !$create_uic_class_map) {
960 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
961 if(-e $class_lib_map) {
962 open CLASS_LIB_MAP, "<$class_lib_map";
964 binmode CLASS_LIB_MAP;
965 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
967 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
968 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
971 my $class_lib_map_dir = dirname($class_lib_map);
972 mkpath $class_lib_map_dir, !$quiet;
973 open CLASS_LIB_MAP, ">$class_lib_map";
974 print CLASS_LIB_MAP $class_lib_map_contents;
979 if($check_includes) {
980 for my $lib (keys(%modules)) {
982 my @subdirs = ($modules{$lib});
983 foreach my $subdir (@subdirs) {
984 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
985 while(my $t = readdir(DIR)) {
986 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
987 !($t eq "..") && !($t eq ".obj") &&
988 !($t eq ".moc") && !($t eq ".rcc") &&
989 !($t eq ".uic") && !($t eq "build"));
994 foreach my $subdir (@subdirs) {
995 my $header_skip_qt_module_test = 0;
996 foreach(@ignore_for_qt_module_check) {
997 foreach (split(/;/, $_)) {
998 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1001 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1002 foreach my $header (@headers) {
1003 my $header_skip_qt_begin_header_test = 0;
1004 my $header_skip_qt_begin_namespace_test = 0;
1005 $header = 0 if($header =~ /^ui_.*.h/);
1006 foreach (@ignore_headers) {
1007 $header = 0 if($header eq $_);
1010 my $public_header = $header;
1011 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1014 foreach (@ignore_for_master_contents) {
1015 $public_header = 0 if($header eq $_);
1017 if($public_header) {
1018 foreach (@ignore_for_include_check) {
1019 $public_header = 0 if($header eq $_);
1021 foreach(@ignore_for_qt_begin_header_check) {
1022 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1024 foreach(@ignore_for_qt_begin_namespace_check) {
1025 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1030 my $iheader = $subdir . "/" . $header;
1031 if($public_header) {
1032 if(open(F, "<$iheader")) {
1033 my $qt_module_found = 0;
1034 my $qt_begin_header_found = 0;
1035 my $qt_end_header_found = 0;
1036 my $qt_begin_namespace_found = 0;
1037 my $qt_end_namespace_found = 0;
1039 while($line = <F>) {
1041 my $output_line = 1;
1042 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1044 } elsif($line =~ /^ *\# *include/) {
1045 my $include = $line;
1046 if($line =~ /<.*>/) {
1047 $include =~ s,.*<(.*)>.*,$1,;
1048 } elsif($line =~ /".*"/) {
1049 $include =~ s,.*"(.*)".*,$1,;
1054 for my $trylib (keys(%modules)) {
1055 if(-e "$out_basedir/include/$trylib/$include") {
1056 print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
1060 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1061 $qt_begin_header_found = 1;
1062 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1063 $qt_end_header_found = 1;
1064 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1065 $qt_begin_namespace_found = 1;
1066 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1067 $qt_end_namespace_found = 1;
1068 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1069 $qt_module_found = 1;
1072 if ($header_skip_qt_begin_header_test == 0) {
1073 if ($qt_begin_header_found == 0) {
1074 print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1077 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1078 print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1082 if ($header_skip_qt_begin_namespace_test == 0) {
1083 if ($qt_begin_namespace_found == 0) {
1084 print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1087 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1088 print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1092 if ($header_skip_qt_module_test == 0) {
1093 if ($qt_module_found == 0) {
1094 print "WARNING: $iheader does not include QT_MODULE\n";