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 "QtXmlPatterns" => "$basedir/src/xmlpatterns",
38 "QtSql" => "$basedir/src/sql",
39 "QtNetwork" => "$basedir/src/network",
40 "QtSvg" => "$basedir/src/svg",
41 "QtDeclarative" => "$basedir/src/declarative",
42 "QtScript" => "$basedir/src/script",
43 "QtScriptTools" => "$basedir/src/scripttools",
44 "Qt3Support" => "$basedir/src/qt3support",
45 "ActiveQt" => "$basedir/src/activeqt",
46 "QtTest" => "$basedir/src/testlib",
47 "QtHelp" => "$basedir/tools/assistant/lib",
48 "QtDesigner" => "$basedir/tools/designer/src/lib",
49 "QtUiTools" => "$basedir/tools/designer/src/uitools",
50 "QtDBus" => "$basedir/src/dbus",
51 "QtWebKit" => "$basedir/src/3rdparty/webkit/Source/WebKit/qt",
52 "phonon" => "$basedir/src/phonon",
53 "QtMultimedia" => "$basedir/src/multimedia",
54 "QtMeeGoGraphicsSystemHelper" => "$basedir/tools/qmeegographicssystemhelper",
56 my %moduleheaders = ( # restrict the module headers to those found in relative path
58 "phonon" => "../3rdparty/phonon/phonon",
61 #$modules{"QtCore"} .= ";$basedir/mkspecs/" . $ENV{"MKSPEC"} if defined $ENV{"MKSPEC"};
63 # global variables (modified by options)
69 my $force_relative = 0;
70 my $check_includes = 0;
72 my $create_uic_class_map = 1;
73 my $create_private_headers = 1;
75 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
76 my $out_basedir = $basedir;
77 $out_basedir =~ s=\\=/=g;
78 my $quoted_basedir = "\Q$basedir";
80 # functions ----------------------------------------------------------
82 ######################################################################
86 # Purpose: Show the usage of the script.
88 ######################################################################
92 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
93 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
94 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
95 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
96 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
97 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
98 print " -quiet Only report problems, not activity (default: " . ($quiet ? "yes" : "no") . ")\n";
99 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR> Create headers for <NAME> with original headers in <HEADERDIR> relative to <PROFILEDIR> \n";
100 print " -help This help\n";
104 ######################################################################
105 # Syntax: checkUnix()
108 # Purpose: Check if script runs on a Unix system or not. Cygwin
109 # systems are _not_ detected as Unix systems.
110 # Returns: 1 if a unix system, else 0.
111 ######################################################################
114 if ( $force_win != 0) {
116 } elsif ( -f "/bin/uname" ) {
118 (-f "\\bin\\uname") && ($r = 0);
119 } elsif ( -f "/usr/bin/uname" ) {
121 (-f "\\usr\\bin\\uname") && ($r = 0);
124 $_ = $Config{'osname'};
125 $r = 0 if( /(ms)|(cyg)win/i );
132 return 0 if($dir =~ /^\//);
133 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
137 ######################################################################
138 # Syntax: shouldMasterInclude(iheader)
139 # Params: iheader, string, filename to verify inclusion
141 # Purpose: Determines if header should be in the master include file.
142 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
143 # able to open, else 1.
144 ######################################################################
145 sub shouldMasterInclude {
147 return 0 if(basename($iheader) =~ /_/);
148 return 0 if(basename($iheader) =~ /qconfig/);
149 if(open(F, "<$iheader")) {
152 return 0 if(/^\#pragma qt_no_master_include$/);
161 ######################################################################
162 # Syntax: classNames(iheader)
163 # Params: iheader, string, filename to parse for classname "symlinks"
165 # Purpose: Scans through iheader to find all classnames that should be
166 # synced into library's include structure.
167 # Returns: List of all class names in a file.
168 ######################################################################
172 if(basename($iheader) eq "qglobal.h") {
173 push @ret, "QtGlobal";
174 } elsif(basename($iheader) eq "qendian.h") {
175 push @ret, "QtEndian";
176 } elsif(basename($iheader) eq "qconfig.h") {
177 push @ret, "QtConfig";
178 } elsif(basename($iheader) eq "qplugin.h") {
179 push @ret, "QtPlugin";
180 } elsif(basename($iheader) eq "qalgorithms.h") {
181 push @ret, "QtAlgorithms";
182 } elsif(basename($iheader) eq "qcontainerfwd.h") {
183 push @ret, "QtContainerFwd";
184 } elsif(basename($iheader) eq "qdebug.h") {
185 push @ret, "QtDebug";
186 } elsif(basename($iheader) eq "qevent.h") {
187 push @ret, "QtEvents";
188 } elsif(basename($iheader) eq "qnamespace.h") {
190 } elsif(basename($iheader) eq "qssl.h") {
192 } elsif(basename($iheader) eq "qtest.h") {
194 } elsif(basename($iheader) eq "qtconcurrentmap.h") {
195 push @ret, "QtConcurrentMap"
196 } elsif(basename($iheader) eq "qtconcurrentfilter.h") {
197 push @ret, "QtConcurrentFilter"
198 } elsif(basename($iheader) eq "qtconcurrentrun.h") {
199 push @ret, "QtConcurrentRun"
200 } elsif(basename($iheader) eq "qaudio.h") {
205 if(open(F, "<$iheader")) {
209 chop $line if ($line =~ /\r$/);
214 last unless($line =~ /\\$/);
217 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
218 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
222 $line =~ s,//.*$,,; #remove c++ comments
223 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
224 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
225 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
226 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
227 $parsable .= " " . $line;
233 my $last_definition = 0;
235 for(my $i = 0; $i < length($parsable); $i++) {
237 my $character = substr($parsable, $i, 1);
238 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
239 for($i+=2; $i < length($parsable); $i++) {
240 my $end = substr($parsable, $i, 2);
242 $last_definition = $i+2;
247 } elsif($character eq "{") {
249 my $block_start = $i + 1;
250 BLOCK: for($i+=1; $i < length($parsable); $i++) {
251 my $ignore = substr($parsable, $i, 1);
254 } elsif($ignore eq "}") {
256 unless($brace_depth) {
257 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
258 my $end = substr($parsable, $i2, 1);
259 if($end eq ";" || $end ne " ") {
260 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
261 $i = $i2 if($end eq ";");
262 $last_definition = $i + 1;
269 } elsif($character eq ";") {
270 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
271 $last_definition = $i + 1;
272 } elsif($character eq "}") {
273 # a naked } must be a namespace ending
274 # if it's not a namespace, it's eaten by the loop above
276 $last_definition = $i + 1;
279 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
280 && substr($parsable, $i+1, 1) eq "{") {
281 push @namespaces, $1;
283 # Eat the opening { so that the condensing loop above doesn't see it
285 $last_definition = $i + 1;
289 $definition =~ s=[\n\r]==g;
291 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
293 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
295 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
297 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
298 push @symbols, "Q" . $1 . "Iterator";
299 push @symbols, "QMutable" . $1 . "Iterator";
302 foreach my $symbol (@symbols) {
303 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
305 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
306 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
313 ######################################################################
314 # Syntax: syncHeader(header, iheader, copy, timestamp)
315 # Params: header, string, filename to create "symlink" for
316 # iheader, string, destination name of symlink
317 # copy, forces header to be a copy of iheader
318 # timestamp, the requested modification time if copying
320 # Purpose: Syncronizes header to iheader
321 # Returns: 1 if successful, else 0.
322 ######################################################################
324 my ($header, $iheader, $copy, $ts) = @_;
325 $iheader =~ s=\\=/=g;
327 return copyFile($iheader, $header) if($copy);
330 my $header_dir = dirname($header);
331 mkpath $header_dir, !$quiet;
334 my $iheader_out = fixPaths($iheader, $header_dir);
335 open HEADER, ">$header" || die "Could not open $header for writing!\n";
336 print HEADER "#include \"$iheader_out\"\n";
339 utime(time, $ts, $header) or die "$iheader, $header";
346 ######################################################################
347 # Syntax: fixPaths(file, dir)
348 # Params: file, string, filepath to be made relative to dir
349 # dir, string, dirpath for point of origin
351 # Purpose: file is made relative (if possible) of dir.
352 # Returns: String with the above applied conversion.
353 ######################################################################
355 my ($file, $dir) = @_;
356 $dir =~ s=^$quoted_basedir/=$out_basedir/= if(!($basedir eq $out_basedir));
362 $ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
363 my $file_dir = dirname($file);
364 if($file_dir eq ".") {
365 $file_dir = getcwd();
366 $file_dir =~ s=\\=/=g;
368 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
373 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
374 return basename($file) if($file_dir eq $dir);
378 for(my $i = 1; $i < length($file_dir); $i++) {
379 my $slash = index($file_dir, "/", $i);
380 last if($slash == -1);
381 my $tmp = substr($file_dir, 0, $slash);
382 last unless($dir =~ m,^\Q$tmp\E/,);
387 my $after = substr($dir, length($match_dir));
388 my $count = ($after =~ tr,/,,);
390 for(my $i = 0; $i < $count; $i++) {
393 $ret =~ s,^\Q$match_dir\E,$dots,;
399 ######################################################################
400 # Syntax: fileContents(filename)
401 # Params: filename, string, filename of file to return contents
403 # Purpose: Get the contents of a file.
404 # Returns: String with contents of the file, or empty string if file
406 # Warning: Dies if it does exist but script cannot get read access.
407 ######################################################################
410 my $filecontents = "";
412 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
418 return $filecontents;
421 ######################################################################
422 # Syntax: fileCompare(file1, file2)
423 # Params: file1, string, filename of first file
424 # file2, string, filename of second file
426 # Purpose: Determines if files are equal, and which one is newer.
427 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
428 # is newer, 1 if file2 is newer.
429 ######################################################################
431 my ($file1, $file2) = @_;
432 my $file1contents = fileContents($file1);
433 my $file2contents = fileContents($file2);
434 if (! -e $file1) { return 1; }
435 if (! -e $file2) { return -1; }
436 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
439 ######################################################################
440 # Syntax: copyFile(file, ifile)
441 # Params: file, string, filename to create duplicate for
442 # ifile, string, destination name of duplicate
444 # Purpose: Keeps files in sync so changes in the newer file will be
445 # written to the other.
446 # Returns: 1 if files were synced, else 0.
447 # Warning: Dies if script cannot get write access.
448 ######################################################################
451 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
452 # Bi-directional synchronization
453 open( I, "< " . $file ) || die "Could not open $file for reading";
458 if ( open(I, "< " . $ifile) ) {
461 $ifilecontents = <I>;
463 $copy = fileCompare($file, $ifile);
470 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
472 my $file_dir = dirname($file);
473 mkpath $file_dir, !$quiet unless(-e $file_dir);
474 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
477 print O $ifilecontents;
479 utime time, (stat($ifile))[9], $file;
481 } elsif ( $copy < 0 ) {
482 my $ifile_dir = dirname($ifile);
483 mkpath $ifile_dir, !$quiet unless(-e $ifile_dir);
484 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
487 print O $filecontents;
489 utime time, (stat($file))[9], $ifile;
496 ######################################################################
497 # Syntax: symlinkFile(file, ifile)
498 # Params: file, string, filename to create "symlink" for
499 # ifile, string, destination name of symlink
501 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
503 # Returns: 1 on success, else 0.
504 ######################################################################
507 my ($file,$ifile) = @_;
510 print "symlink created for $file " unless $quiet;
511 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
515 $t =~ s-^$quoted_basedir/--;
516 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
517 $file =~ s-^$quoted_basedir/-$p-;
518 print " ($file)\n" unless $quiet;
520 print "\n" unless $quiet;
521 return symlink($file, $ifile);
523 return copyFile($file, $ifile);
526 ######################################################################
527 # Syntax: findFiles(dir, match, descend)
528 # Params: dir, string, directory to search for name
529 # match, string, regular expression to match in dir
530 # descend, integer, 0 = non-recursive search
531 # 1 = recurse search into subdirectories
533 # Purpose: Finds files matching a regular expression.
534 # Returns: List of matching files.
537 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
538 # findFiles("/tmp","^#",0) - finds #* files in /tmp
539 ######################################################################
541 my ($dir,$match,$descend) = @_;
542 my ($file,$p,@files);
545 ($dir eq "") && ($dir = ".");
546 if ( opendir(D,$dir) ) {
550 ($dir =~ /\/$/) || ($dir .= "/");
552 foreach $file ( sort readdir(D) ) {
553 next if ( $file =~ /^\.\.?$/ );
555 ($file =~ /$match/) && (push @files, $p);
556 if ( $descend && -d $p && ! -l $p ) {
557 push @files, &findFiles($p,$match,$descend);
565 # --------------------------------------------------------------------
567 # --------------------------------------------------------------------
574 my $arg = shift @ARGV;
575 if ($arg eq "-h" || $arg eq "-help" || $arg eq "?") {
578 } elsif($arg eq "-copy") {
581 } elsif($arg eq "-o" || $arg eq "-outdir") {
584 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
585 $arg eq "-relative" || $arg eq "-check-includes") {
586 $var = substr($arg, 1);
588 } elsif($arg =~ /^-no-(.*)$/) {
591 #these are for commandline compat
592 } elsif($arg eq "-inc") {
595 } elsif($arg eq "-module") {
598 } elsif($arg eq "-separate-module") {
599 $var = "separate-module";
601 } elsif($arg eq "-show") {
604 } elsif($arg eq "-quiet") {
607 } elsif($arg eq "-base-dir") {
608 # skip, it's been dealt with at the top of the file
614 if(!$var || $var eq "show_help") {
615 print "Unknown option: $arg\n\n" if(!$var);
617 } elsif ($var eq "copy") {
623 } elsif ($var eq "showonly") {
629 } elsif ($var eq "quiet") {
635 } elsif ($var eq "check-includes") {
638 } elsif($check_includes) {
641 } elsif ($var eq "remove-stale") {
644 } elsif($remove_stale) {
647 } elsif ($var eq "windows") {
650 } elsif($force_win) {
653 } elsif ($var eq "relative") {
656 } elsif($force_relative) {
659 } elsif ($var eq "module") {
660 print "module :$val:\n" unless $quiet;
661 die "No such module: $val" unless(defined $modules{$val});
662 push @modules_to_sync, $val;
663 } elsif ($var eq "separate-module") {
664 my $dirsep = ($force_win ? ";" : ":");
665 my ($module, $prodir, $headerdir) = split($dirsep, $val);
666 $modules{$module} = $prodir;
667 push @modules_to_sync, $module;
668 $moduleheaders{$module} = $headerdir;
669 $create_uic_class_map = 0;
670 $create_private_headers = 0;
671 } elsif ($var eq "output") {
673 if(checkRelative($outdir)) {
674 $out_basedir = getcwd();
676 $out_basedir .= "/" . $outdir;
678 $out_basedir = $outdir;
681 $out_basedir =~ s=\\=/=g;
684 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
686 $isunix = checkUnix; #cache checkUnix
689 mkpath "$out_basedir/include", !$quiet;
690 mkpath "$out_basedir/include/Qt", !$quiet;
692 my @ignore_headers = ();
693 my $class_lib_map_contents = "";
694 my @ignore_for_master_contents = ( "qt.h", "qpaintdevicedefs.h" );
695 my @ignore_for_include_check = ( "qatomic.h" );
696 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" );
697 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" );
698 my @ignore_for_qt_module_check = ( "$modules{QtCore}/arch", "$modules{QtCore}/global", "$modules{QtSql}/drivers", "$modules{QtTest}", "$modules{QtDesigner}", "$modules{QtUiTools}", "$modules{QtDBus}", "$modules{phonon}" );
699 my %colliding_headers = ();
700 my %inject_headers = ( "$basedir/src/corelib/global" => ( "qconfig.h" ) ); # all from build dir
702 foreach my $lib (@modules_to_sync) {
704 my $dir = $modules{$lib};
705 my $pathtoheaders = "";
706 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
708 #information used after the syncing
709 my $pri_install_classes = "";
710 my $pri_install_files = "";
711 my $pri_install_pfiles = "";
713 my $libcapitals = $lib;
714 $libcapitals =~ y/a-z/A-Z/;
715 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
718 my $pro_file = "$dir/" . basename($dir) . ".pro";
719 if(!open(F, "<$pro_file")) {
720 #the pro file doesn't exist let's try to find one
723 foreach my $file (readdir(DIR))
725 if ( $file =~ /\.pro$/i) {
726 die "There are multiple pro files for $lib module, which one should I use? \n" if ($pro_file ne "");
727 $pro_file = "$dir/" . $file;
731 if ($pro_file eq "") {
732 die "I couldn't find a pro file for $lib module \n";
736 if(open(F, "<$pro_file")) {
737 while(my $line = <F>) {
739 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
740 foreach(split(/ /, $1)) {
741 $master_contents .= "#include <QtCore/QtCore>\n" if($_ eq "core");
742 $master_contents .= "#include <QtGui/QtGui>\n" if($_ eq "gui");
743 $master_contents .= "#include <QtNetwork/QtNetwork>\n" if($_ eq "network");
744 $master_contents .= "#include <QtSvg/QtSvg>\n" if($_ eq "svg");
745 $master_contents .= "#include <QtDeclarative/QtDeclarative>\n" if($_ eq "declarative");
746 $master_contents .= "#include <QtScript/QtScript>\n" if($_ eq "script");
747 $master_contents .= "#include <QtScriptTools/QtScriptTools>\n" if($_ eq "scripttools");
748 $master_contents .= "#include <Qt3Support/Qt3Support>\n" if($_ eq "qt3support");
749 $master_contents .= "#include <QtSql/QtSql>\n" if($_ eq "sql");
750 $master_contents .= "#include <QtXml/QtXml>\n" if($_ eq "xml");
751 $master_contents .= "#include <QtXmlPatterns/QtXmlPatterns>\n" if($_ eq "xmlpatterns");
752 $master_contents .= "#include <QtOpenGL/QtOpenGL>\n" if($_ eq "opengl");
753 $master_contents .= "#include <QtOpenVG/QtOpenVG>\n" if($_ eq "openvg");
761 #remove the old files
763 my @subdirs = ("$out_basedir/include/$lib");
764 foreach my $subdir (@subdirs) {
765 if (opendir DIR, $subdir) {
766 while(my $t = readdir(DIR)) {
767 my $file = "$subdir/$t";
769 push @subdirs, $file unless($t eq "." || $t eq "..");
772 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
773 foreach my $file (@files) {
775 if(open(F, "<$file")) {
776 while(my $line = <F>) {
778 if($line =~ /^\#include \"([^\"]*)\"$/) {
780 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
781 $remove_file = 1 unless(-e $include);
788 unlink $file if($remove_file);
800 foreach my $current_dir (split(/;/, $dir)) {
801 my $headers_dir = $current_dir;
802 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
804 my @subdirs = ($headers_dir);
805 foreach my $subdir (@subdirs) {
806 opendir DIR, $subdir or next;
807 while(my $t = readdir(DIR)) {
808 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
809 !($t eq "..") && !($t eq ".obj") &&
810 !($t eq ".moc") && !($t eq ".rcc") &&
811 !($t eq ".uic") && !($t eq "build"));
816 #calc files and "copy" them
817 foreach my $subdir (@subdirs) {
818 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
819 if (defined $inject_headers{$subdir}) {
820 foreach my $if ($inject_headers{$subdir}) {
821 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
822 push @headers, "*".$if;
825 foreach my $header (@headers) {
826 my $shadow = ($header =~ s/^\*//);
827 $header = 0 if($header =~ /^ui_.*.h/);
828 foreach (@ignore_headers) {
829 $header = 0 if($header eq $_);
832 my $header_copies = 0;
833 #figure out if it is a public header
834 my $public_header = $header;
835 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
838 foreach (@ignore_for_master_contents) {
839 $public_header = 0 if($header eq $_);
843 my $iheader = $subdir . "/" . $header;
844 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
845 my @classes = $public_header ? classNames($iheader) : ();
847 print "$header [$lib]\n";
849 print "SYMBOL: $_\n";
852 my $ts = (stat($iheader))[9];
853 #find out all the places it goes..
855 if ($public_header) {
856 @headers = ( "$out_basedir/include/$lib/$header" );
858 # write forwarding headers to include/Qt
859 if ($lib ne "phonon" && $subdir =~ /^$quoted_basedir\/src/) {
860 my $file_name = "$out_basedir/include/Qt/$header";
862 my $header_content = '';
863 if (exists $colliding_headers{$file_name}) {
866 $colliding_headers{$file_name} = 1;
867 my $warning_msg = 'Inclusion of header files from include/Qt is deprecated.';
868 $header_content = "#ifndef QT_NO_QT_INCLUDE_WARN\n" .
869 " #if defined(__GNUC__)\n" .
870 " #warning \"$warning_msg\"\n" .
871 " #elif defined(_MSC_VER)\n" .
872 " #pragma message(\"WARNING: $warning_msg\")\n" .
876 $header_content .= '#include "' . "../$lib/$header" . "\"\n";
877 open HEADERFILE, $file_op, $file_name or die "unable to open '$file_name' : $!\n";
878 print HEADERFILE $header_content;
882 foreach my $full_class (@classes) {
883 my $header_base = basename($header);
885 my $class = $full_class;
887 # if ($class =~ m/::/) {
890 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
891 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
893 # KDE-Compat headers for Phonon
894 if ($lib eq "phonon") {
895 $header_copies++ if (syncHeader("$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
898 } elsif ($create_private_headers) {
899 @headers = ( "$out_basedir/include/$lib/private/$header" );
901 foreach(@headers) { #sync them
902 $header_copies++ if(syncHeader($_, $iheader, $copy_headers && !$shadow, $ts));
906 #put it into the master file
907 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
909 #deal with the install directives
911 my $pri_install_iheader = fixPaths($iheader, $current_dir);
912 foreach my $class (@classes) {
915 # if ($class =~ m/::/) {
916 # $class =~ s,::,/,g;
918 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
920 $pri_install_classes .= $class_header
921 unless($pri_install_classes =~ $class_header);
923 $pri_install_files.= "$pri_install_iheader ";;
927 my $pri_install_iheader = fixPaths($iheader, $current_dir);
928 $pri_install_pfiles.= "$pri_install_iheader ";;
931 print "header created for $iheader ($header_copies)\n" if($header_copies > 0 && !$quiet);
937 # close the master include:
938 $master_contents .= "#endif\n";
942 push @master_includes, "$out_basedir/include/$lib/$lib";
943 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
944 foreach my $master_include (@master_includes) {
945 #generate the "master" include file
946 my @tmp = split(/;/,$modules{$lib});
947 $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
948 if($master_include && -e $master_include) {
949 open MASTERINCLUDE, "<$master_include";
951 binmode MASTERINCLUDE;
952 my $oldmaster = <MASTERINCLUDE>;
954 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
955 $master_include = 0 if($oldmaster eq $master_contents);
957 if($master_include && $master_contents) {
958 my $master_dir = dirname($master_include);
959 mkpath $master_dir, !$quiet;
960 print "header (master) created for $lib\n" unless $quiet;
961 open MASTERINCLUDE, ">$master_include";
962 print MASTERINCLUDE $master_contents;
967 #handle the headers.pri for each module
968 my $headers_pri_contents = "";
969 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
970 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
971 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
972 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
973 if(-e $headers_pri_file) {
974 open HEADERS_PRI_FILE, "<$headers_pri_file";
976 binmode HEADERS_PRI_FILE;
977 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
978 close HEADERS_PRI_FILE;
979 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
980 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
982 if($headers_pri_file && $master_contents) {
983 my $headers_pri_dir = dirname($headers_pri_file);
984 mkpath $headers_pri_dir, !$quiet;
985 print "headers.pri file created for $lib\n" unless $quiet;
986 open HEADERS_PRI_FILE, ">$headers_pri_file";
987 print HEADERS_PRI_FILE $headers_pri_contents;
988 close HEADERS_PRI_FILE;
992 unless($showonly || !$create_uic_class_map) {
993 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
994 if(-e $class_lib_map) {
995 open CLASS_LIB_MAP, "<$class_lib_map";
997 binmode CLASS_LIB_MAP;
998 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1000 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1001 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1003 if($class_lib_map) {
1004 my $class_lib_map_dir = dirname($class_lib_map);
1005 mkpath $class_lib_map_dir, !$quiet;
1006 open CLASS_LIB_MAP, ">$class_lib_map";
1007 print CLASS_LIB_MAP $class_lib_map_contents;
1008 close CLASS_LIB_MAP;
1012 if($check_includes) {
1013 for my $lib (keys(%modules)) {
1015 my @subdirs = ($modules{$lib});
1016 foreach my $subdir (@subdirs) {
1017 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
1018 while(my $t = readdir(DIR)) {
1019 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
1020 !($t eq "..") && !($t eq ".obj") &&
1021 !($t eq ".moc") && !($t eq ".rcc") &&
1022 !($t eq ".uic") && !($t eq "build"));
1027 foreach my $subdir (@subdirs) {
1028 my $header_skip_qt_module_test = 0;
1029 foreach(@ignore_for_qt_module_check) {
1030 foreach (split(/;/, $_)) {
1031 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1034 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1035 foreach my $header (@headers) {
1036 my $header_skip_qt_begin_header_test = 0;
1037 my $header_skip_qt_begin_namespace_test = 0;
1038 $header = 0 if($header =~ /^ui_.*.h/);
1039 foreach (@ignore_headers) {
1040 $header = 0 if($header eq $_);
1043 my $public_header = $header;
1044 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1047 foreach (@ignore_for_master_contents) {
1048 $public_header = 0 if($header eq $_);
1050 if($public_header) {
1051 foreach (@ignore_for_include_check) {
1052 $public_header = 0 if($header eq $_);
1054 foreach(@ignore_for_qt_begin_header_check) {
1055 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1057 foreach(@ignore_for_qt_begin_namespace_check) {
1058 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1063 my $iheader = $subdir . "/" . $header;
1064 if($public_header) {
1065 if(open(F, "<$iheader")) {
1066 my $qt_module_found = 0;
1067 my $qt_begin_header_found = 0;
1068 my $qt_end_header_found = 0;
1069 my $qt_begin_namespace_found = 0;
1070 my $qt_end_namespace_found = 0;
1072 while($line = <F>) {
1074 my $output_line = 1;
1075 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1077 } elsif($line =~ /^ *\# *include/) {
1078 my $include = $line;
1079 if($line =~ /<.*>/) {
1080 $include =~ s,.*<(.*)>.*,$1,;
1081 } elsif($line =~ /".*"/) {
1082 $include =~ s,.*"(.*)".*,$1,;
1087 for my $trylib (keys(%modules)) {
1088 if(-e "$out_basedir/include/$trylib/$include") {
1089 print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
1093 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1094 $qt_begin_header_found = 1;
1095 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1096 $qt_end_header_found = 1;
1097 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1098 $qt_begin_namespace_found = 1;
1099 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1100 $qt_end_namespace_found = 1;
1101 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1102 $qt_module_found = 1;
1105 if ($header_skip_qt_begin_header_test == 0) {
1106 if ($qt_begin_header_found == 0) {
1107 print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1110 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1111 print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1115 if ($header_skip_qt_begin_namespace_test == 0) {
1116 if ($qt_begin_namespace_found == 0) {
1117 print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1120 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1121 print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1125 if ($header_skip_qt_module_test == 0) {
1126 if ($qt_module_found == 0) {
1127 print "WARNING: $iheader does not include QT_MODULE\n";