Fix regression introduced in c08e708037d33271825ce6a6a1ac640e96b70c36
[qt-netbsd.git] / bin / syncqt
bloba14a82dc192c764505610f5d3a811484c949ef9f
1 #!/usr/bin/perl -w
2 ######################################################################
4 # Synchronizes Qt header files - internal development tool.
6 # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
7 # Contact: Nokia Corporation (qt-info@nokia.com)
9 ######################################################################
11 # use packages -------------------------------------------------------
12 use File::Basename;
13 use File::Path;
14 use Cwd;
15 use Config;
16 use strict;
18 die "syncqt: QTDIR not defined" if ! $ENV{"QTDIR"}; # sanity check
20 # global variables
21 my $isunix = 0;
22 my $basedir = $ENV{"QTDIR"};
23 $basedir =~ s=\\=/=g;
24 my %modules = ( # path to module name map
25 "QtGui" => "$basedir/src/gui",
26 "QtOpenGL" => "$basedir/src/opengl",
27 "QtOpenVG" => "$basedir/src/openvg",
28 "QtCore" => "$basedir/src/corelib",
29 "QtXml" => "$basedir/src/xml",
30 "QtXmlPatterns" => "$basedir/src/xmlpatterns",
31 "QtSql" => "$basedir/src/sql",
32 "QtNetwork" => "$basedir/src/network",
33 "QtSvg" => "$basedir/src/svg",
34 "QtDeclarative" => "$basedir/src/declarative",
35 "QtScript" => "$basedir/src/script",
36 "QtScriptTools" => "$basedir/src/scripttools",
37 "Qt3Support" => "$basedir/src/qt3support",
38 "ActiveQt" => "$basedir/src/activeqt/container;$basedir/src/activeqt/control;$basedir/src/activeqt/shared",
39 "QtTest" => "$basedir/src/testlib",
40 "QtAssistant" => "$basedir/tools/assistant/compat/lib",
41 "QtHelp" => "$basedir/tools/assistant/lib",
42 "QtDesigner" => "$basedir/tools/designer/src/lib",
43 "QtUiTools" => "$basedir/tools/designer/src/uitools",
44 "QtDBus" => "$basedir/src/dbus",
45 "QtWebKit" => "$basedir/src/3rdparty/webkit/WebCore",
46 "phonon" => "$basedir/src/phonon",
47 "QtMultimedia" => "$basedir/src/multimedia",
49 my %moduleheaders = ( # restrict the module headers to those found in relative path
50 "QtWebKit" => "../WebKit/qt/Api",
51 "phonon" => "../3rdparty/phonon/phonon",
54 #$modules{"QtCore"} .= ";$basedir/mkspecs/" . $ENV{"MKSPEC"} if defined $ENV{"MKSPEC"};
56 # global variables (modified by options)
57 my $module = 0;
58 my $showonly = 0;
59 my $remove_stale = 1;
60 my $force_win = 0;
61 my $force_relative = 0;
62 my $check_includes = 0;
63 my $copy_headers = 0;
64 my @modules_to_sync ;
65 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
66 my $out_basedir = $basedir;
67 $out_basedir =~ s=\\=/=g;
69 # functions ----------------------------------------------------------
71 ######################################################################
72 # Syntax: showUsage()
73 # Params: -none-
75 # Purpose: Show the usage of the script.
76 # Returns: -none-
77 ######################################################################
78 sub showUsage
80 print "$0 usage:\n";
81 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
82 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
83 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
84 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
85 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
86 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
87 print " -help This help\n";
88 exit 0;
91 ######################################################################
92 # Syntax: checkUnix()
93 # Params: -none-
95 # Purpose: Check if script runs on a Unix system or not. Cygwin
96 # systems are _not_ detected as Unix systems.
97 # Returns: 1 if a unix system, else 0.
98 ######################################################################
99 sub checkUnix {
100 my ($r) = 0;
101 if ( $force_win != 0) {
102 return 0;
103 } elsif ( -f "/bin/uname" ) {
104 $r = 1;
105 (-f "\\bin\\uname") && ($r = 0);
106 } elsif ( -f "/usr/bin/uname" ) {
107 $r = 1;
108 (-f "\\usr\\bin\\uname") && ($r = 0);
110 if($r) {
111 $_ = $Config{'osname'};
112 $r = 0 if( /(ms)|(cyg)win/i );
114 return $r;
117 sub checkRelative {
118 my ($dir) = @_;
119 return 0 if($dir =~ /^\//);
120 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
121 return 1;
124 ######################################################################
125 # Syntax: shouldMasterInclude(iheader)
126 # Params: iheader, string, filename to verify inclusion
128 # Purpose: Determines if header should be in the master include file.
129 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
130 # able to open, else 1.
131 ######################################################################
132 sub shouldMasterInclude {
133 my ($iheader) = @_;
134 return 0 if(basename($iheader) =~ /_/);
135 return 0 if(basename($iheader) =~ /qconfig/);
136 if(open(F, "<$iheader")) {
137 while(<F>) {
138 chomp;
139 return 0 if(/^\#pragma qt_no_master_include$/);
141 close(F);
142 } else {
143 return 0;
145 return 1;
148 ######################################################################
149 # Syntax: classNames(iheader)
150 # Params: iheader, string, filename to parse for classname "symlinks"
152 # Purpose: Scans through iheader to find all classnames that should be
153 # synced into library's include structure.
154 # Returns: List of all class names in a file.
155 ######################################################################
156 sub classNames {
157 my @ret;
158 my ($iheader) = @_;
159 if(basename($iheader) eq "qglobal.h") {
160 push @ret, "QtGlobal";
161 } elsif(basename($iheader) eq "qendian.h") {
162 push @ret, "QtEndian";
163 } elsif(basename($iheader) eq "qconfig.h") {
164 push @ret, "QtConfig";
165 } elsif(basename($iheader) eq "qplugin.h") {
166 push @ret, "QtPlugin";
167 } elsif(basename($iheader) eq "qalgorithms.h") {
168 push @ret, "QtAlgorithms";
169 } elsif(basename($iheader) eq "qcontainerfwd.h") {
170 push @ret, "QtContainerFwd";
171 } elsif(basename($iheader) eq "qdebug.h") {
172 push @ret, "QtDebug";
173 } elsif(basename($iheader) eq "qevent.h") {
174 push @ret, "QtEvents";
175 } elsif(basename($iheader) eq "qnamespace.h") {
176 push @ret, "Qt"
177 } elsif(basename($iheader) eq "qssl.h") {
178 push @ret, "QSsl";
179 } elsif(basename($iheader) eq "qtest.h") {
180 push @ret, "QTest"
181 } elsif(basename($iheader) eq "qtconcurrentmap.h") {
182 push @ret, "QtConcurrentMap"
183 } elsif(basename($iheader) eq "qtconcurrentfilter.h") {
184 push @ret, "QtConcurrentFilter"
185 } elsif(basename($iheader) eq "qtconcurrentrun.h") {
186 push @ret, "QtConcurrentRun"
189 my $parsable = "";
190 if(open(F, "<$iheader")) {
191 while(<F>) {
192 my $line = $_;
193 chomp $line;
194 chop $line if ($line =~ /\r$/);
195 if($line =~ /^\#/) {
196 if($line =~ /\\$/) {
197 while($line = <F>) {
198 chomp $line;
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]*$/);
204 $line = 0;
206 if($line) {
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;
215 close(F);
218 my $last_definition = 0;
219 my @namespaces;
220 for(my $i = 0; $i < length($parsable); $i++) {
221 my $definition = 0;
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);
226 if($end eq "*/") {
227 $last_definition = $i+2;
228 $i++;
229 last;
232 } elsif($character eq "{") {
233 my $brace_depth = 1;
234 my $block_start = $i + 1;
235 BLOCK: for($i+=1; $i < length($parsable); $i++) {
236 my $ignore = substr($parsable, $i, 1);
237 if($ignore eq "{") {
238 $brace_depth++;
239 } elsif($ignore eq "}") {
240 $brace_depth--;
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;
248 last BLOCK;
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
260 pop @namespaces;
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
269 $i++;
270 $last_definition = $i + 1;
273 if($definition) {
274 $definition =~ s=[\n\r]==g;
275 my @symbols;
276 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
277 push @symbols, $1;
278 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
279 push @symbols, $2;
280 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
281 push @symbols, $4;
282 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
283 push @symbols, "Q" . $1 . "Iterator";
284 push @symbols, "QMutable" . $1 . "Iterator";
287 foreach (@symbols) {
288 my $symbol = $_;
289 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
290 push @ret, $symbol
291 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
292 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
296 return @ret;
299 ######################################################################
300 # Syntax: syncHeader(header, iheader, copy)
301 # Params: header, string, filename to create "symlink" for
302 # iheader, string, destination name of symlink
303 # copy, forces header to be a copy of iheader
305 # Purpose: Syncronizes header to iheader
306 # Returns: 1 if successful, else 0.
307 ######################################################################
308 sub syncHeader {
309 my ($header, $iheader, $copy) = @_;
310 $iheader =~ s=\\=/=g;
311 $header =~ s=\\=/=g;
312 return copyFile($iheader, $header) if($copy);
314 unless(-e "$header") {
315 my $header_dir = dirname($header);
316 mkpath $header_dir, 0777;
318 #write it
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";
322 close HEADER;
323 return 1;
325 return 0;
328 ######################################################################
329 # Syntax: fixPaths(file, dir)
330 # Params: file, string, filepath to be made relative to dir
331 # dir, string, dirpath for point of origin
333 # Purpose: file is made relative (if possible) of dir.
334 # Returns: String with the above applied conversion.
335 ######################################################################
336 sub fixPaths {
337 my ($file, $dir) = @_;
338 $dir =~ s=^$basedir/=$out_basedir/= if(!($basedir eq $out_basedir));
339 $file =~ s=\\=/=g;
340 $file =~ s/\+/\\+/g;
341 $dir =~ s=\\=/=g;
342 $dir =~ s/\+/\\+/g;
344 #setup
345 my $ret = $file;
346 my $file_dir = dirname($file);
347 if($file_dir eq ".") {
348 $file_dir = getcwd();
349 $file_dir =~ s=\\=/=g;
351 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:,g;
352 if($dir eq ".") {
353 $dir = getcwd();
354 $dir =~ s=\\=/=g;
356 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
357 return basename($file) if("$file_dir" eq "$dir");
359 #guts
360 my $match_dir = 0;
361 for(my $i = 1; $i < length($file_dir); $i++) {
362 my $slash = index($file_dir, "/", $i);
363 last if($slash == -1);
364 my $tmp = substr($file_dir, 0, $slash);
365 last unless($dir =~ m,^$tmp/,);
366 $match_dir = $tmp;
367 $i = $slash;
369 if($match_dir) {
370 my $after = substr($dir, length($match_dir));
371 my $count = ($after =~ tr,/,,);
372 my $dots = "";
373 for(my $i = 0; $i < $count; $i++) {
374 $dots .= "../";
376 $ret =~ s,^$match_dir,$dots,;
378 $ret =~ s,/+,/,g;
379 return $ret;
382 ######################################################################
383 # Syntax: fileContents(filename)
384 # Params: filename, string, filename of file to return contents
386 # Purpose: Get the contents of a file.
387 # Returns: String with contents of the file, or empty string if file
388 # doens't exist.
389 # Warning: Dies if it does exist but script cannot get read access.
390 ######################################################################
391 sub fileContents {
392 my ($filename) = @_;
393 my $filecontents = "";
394 if (-e $filename) {
395 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
396 local $/;
397 binmode I;
398 $filecontents = <I>;
399 close I;
401 return $filecontents;
404 ######################################################################
405 # Syntax: fileCompare(file1, file2)
406 # Params: file1, string, filename of first file
407 # file2, string, filename of second file
409 # Purpose: Determines if files are equal, and which one is newer.
410 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
411 # is newer, 1 if file2 is newer.
412 ######################################################################
413 sub fileCompare {
414 my ($file1, $file2) = @_;
415 my $file1contents = fileContents($file1);
416 my $file2contents = fileContents($file2);
417 if (! -e $file1) { return 1; }
418 if (! -e $file2) { return -1; }
419 return $file1contents ne $file2contents ? (stat("$file2"))[9] <=> (stat("$file1"))[9] : 0;
422 ######################################################################
423 # Syntax: copyFile(file, ifile)
424 # Params: file, string, filename to create duplicate for
425 # ifile, string, destination name of duplicate
427 # Purpose: Keeps files in sync so changes in the newer file will be
428 # written to the other.
429 # Returns: 1 if files were synced, else 0.
430 # Warning: Dies if script cannot get write access.
431 ######################################################################
432 sub copyFile
434 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
435 # Bi-directional synchronization
436 open( I, "< " . $file ) || die "Could not open $file for reading";
437 local $/;
438 binmode I;
439 $filecontents = <I>;
440 close I;
441 if ( open(I, "< " . $ifile) ) {
442 local $/;
443 binmode I;
444 $ifilecontents = <I>;
445 close I;
446 $copy = fileCompare($file, $ifile);
447 $knowdiff = 0,
448 } else {
449 $copy = -1;
450 $knowdiff = 1;
453 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
454 if ( $copy > 0 ) {
455 my $file_dir = dirname($file);
456 mkpath $file_dir, 0777 unless(-e "$file_dir");
457 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
458 local $/;
459 binmode O;
460 print O $ifilecontents;
461 close O;
462 return 1;
463 } elsif ( $copy < 0 ) {
464 my $ifile_dir = dirname($ifile);
465 mkpath $ifile_dir, 0777 unless(-e "$ifile_dir");
466 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
467 local $/;
468 binmode O;
469 print O $filecontents;
470 close O;
471 return 1;
474 return 0;
477 ######################################################################
478 # Syntax: symlinkFile(file, ifile)
479 # Params: file, string, filename to create "symlink" for
480 # ifile, string, destination name of symlink
482 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
483 # support symlink).
484 # Returns: 1 on success, else 0.
485 ######################################################################
486 sub symlinkFile
488 my ($file,$ifile) = @_;
490 if ($isunix) {
491 print "symlink created for $file ";
492 if ( $force_relative && ($ifile =~ /^$basedir/)) {
493 my $t = getcwd();
494 my $c = -1;
495 my $p = "../";
496 $t =~ s-^$basedir/--;
497 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
498 $file =~ s-^$basedir/-$p-;
499 print " ($file)\n";
501 print "\n";
502 return symlink($file, $ifile);
504 return copyFile($file, $ifile);
507 ######################################################################
508 # Syntax: findFiles(dir, match, descend)
509 # Params: dir, string, directory to search for name
510 # match, string, regular expression to match in dir
511 # descend, integer, 0 = non-recursive search
512 # 1 = recurse search into subdirectories
514 # Purpose: Finds files matching a regular expression.
515 # Returns: List of matching files.
517 # Examples:
518 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
519 # findFiles("/tmp","^#",0) - finds #* files in /tmp
520 ######################################################################
521 sub findFiles {
522 my ($dir,$match,$descend) = @_;
523 my ($file,$p,@files);
524 local(*D);
525 $dir =~ s=\\=/=g;
526 ($dir eq "") && ($dir = ".");
527 if ( opendir(D,$dir) ) {
528 if ( $dir eq "." ) {
529 $dir = "";
530 } else {
531 ($dir =~ /\/$/) || ($dir .= "/");
533 foreach $file ( sort readdir(D) ) {
534 next if ( $file =~ /^\.\.?$/ );
535 $p = $file;
536 ($file =~ /$match/) && (push @files, $p);
537 if ( $descend && -d $p && ! -l $p ) {
538 push @files, &findFiles($p,$match,$descend);
541 closedir(D);
543 return @files;
546 # --------------------------------------------------------------------
547 # "main" function
548 # --------------------------------------------------------------------
550 while ( @ARGV ) {
551 my $var = 0;
552 my $val = 0;
554 #parse
555 my $arg = shift @ARGV;
556 if ("$arg" eq "-h" || "$arg" eq "-help" || "$arg" eq "?") {
557 $var = "show_help";
558 $val = "yes";
559 } elsif("$arg" eq "-copy") {
560 $var = "copy";
561 $val = "yes";
562 } elsif("$arg" eq "-o" || "$arg" eq "-outdir") {
563 $var = "output";
564 $val = shift @ARGV;
565 } elsif("$arg" eq "-showonly" || "$arg" eq "-remove-stale" || "$arg" eq "-windows" ||
566 "$arg" eq "-relative" || "$arg" eq "-check-includes") {
567 $var = substr($arg, 1);
568 $val = "yes";
569 } elsif("$arg" =~ /^-no-(.*)$/) {
570 $var = $1;
571 $val = "no";
572 #these are for commandline compat
573 } elsif("$arg" eq "-inc") {
574 $var = "output";
575 $val = shift @ARGV;
576 } elsif("$arg" eq "-module") {
577 $var = "module";
578 $val = shift @ARGV;
579 } elsif("$arg" eq "-show") {
580 $var = "showonly";
581 $val = "yes";
582 } elsif("$arg" eq '*') {
583 # workaround for windows 9x where "%*" expands to "*"
584 $var = 1;
587 #do something
588 if(!$var || "$var" eq "show_help") {
589 print "Unknown option: $arg\n\n" if(!$var);
590 showUsage();
591 } elsif ("$var" eq "copy") {
592 if("$val" eq "yes") {
593 $copy_headers++;
594 } elsif($showonly) {
595 $copy_headers--;
597 } elsif ("$var" eq "showonly") {
598 if("$val" eq "yes") {
599 $showonly++;
600 } elsif($showonly) {
601 $showonly--;
603 } elsif ("$var" eq "check-includes") {
604 if("$val" eq "yes") {
605 $check_includes++;
606 } elsif($check_includes) {
607 $check_includes--;
609 } elsif ("$var" eq "remove-stale") {
610 if("$val" eq "yes") {
611 $remove_stale++;
612 } elsif($remove_stale) {
613 $remove_stale--;
615 } elsif ("$var" eq "windows") {
616 if("$val" eq "yes") {
617 $force_win++;
618 } elsif($force_win) {
619 $force_win--;
621 } elsif ("$var" eq "relative") {
622 if("$val" eq "yes") {
623 $force_relative++;
624 } elsif($force_relative) {
625 $force_relative--;
627 } elsif ("$var" eq "module") {
628 print "module :$val:\n";
629 die "No such module: $val" unless(defined $modules{$val});
630 push @modules_to_sync, $val;
631 } elsif ("$var" eq "output") {
632 my $outdir = $val;
633 if(checkRelative($outdir)) {
634 $out_basedir = getcwd();
635 chomp $out_basedir;
636 $out_basedir .= "/" . $outdir;
637 } else {
638 $out_basedir = $outdir;
640 # \ -> /
641 $out_basedir =~ s=\\=/=g;
644 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
646 $isunix = checkUnix; #cache checkUnix
648 # create path
649 mkpath "$out_basedir/include", 0777;
651 my @ignore_headers = ();
652 my $class_lib_map_contents = "";
653 my @ignore_for_master_contents = ( "qt.h", "qpaintdevicedefs.h" );
654 my @ignore_for_include_check = ( "qatomic.h" );
655 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" );
656 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" );
657 my @ignore_for_qt_module_check = ( "$modules{QtCore}/arch", "$modules{QtCore}/global", "$modules{QtSql}/drivers", "$modules{QtTest}", "$modules{QtAssistant}", "$modules{QtDesigner}", "$modules{QtUiTools}", "$modules{QtDBus}", "$modules{phonon}" );
659 foreach (@modules_to_sync) {
660 #iteration info
661 my $lib = $_;
662 my $dir = "$modules{$lib}";
663 my $pathtoheaders = "";
664 $pathtoheaders = "$moduleheaders{$lib}" if ($moduleheaders{$lib});
666 #information used after the syncing
667 my $pri_install_classes = "";
668 my $pri_install_files = "";
670 my $libcapitals = $lib;
671 $libcapitals =~ y/a-z/A-Z/;
672 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
674 #get dependencies
675 if(-e "$dir/" . basename($dir) . ".pro") {
676 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
677 while(<F>) {
678 my $line = $_;
679 chomp $line;
680 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
681 foreach(split(/ /, "$1")) {
682 $master_contents .= "#include <QtCore/QtCore>\n" if("$_" eq "core");
683 $master_contents .= "#include <QtGui/QtGui>\n" if("$_" eq "gui");
684 $master_contents .= "#include <QtNetwork/QtNetwork>\n" if("$_" eq "network");
685 $master_contents .= "#include <QtSvg/QtSvg>\n" if("$_" eq "svg");
686 $master_contents .= "#include <QtDeclarative/QtDeclarative>\n" if("$_" eq "declarative");
687 $master_contents .= "#include <QtScript/QtScript>\n" if("$_" eq "script");
688 $master_contents .= "#include <QtScriptTools/QtScriptTools>\n" if("$_" eq "scripttools");
689 $master_contents .= "#include <Qt3Support/Qt3Support>\n" if("$_" eq "qt3support");
690 $master_contents .= "#include <QtSql/QtSql>\n" if("$_" eq "sql");
691 $master_contents .= "#include <QtXml/QtXml>\n" if("$_" eq "xml");
692 $master_contents .= "#include <QtXmlPatterns/QtXmlPatterns>\n" if("$_" eq "xmlpatterns");
693 $master_contents .= "#include <QtOpenGL/QtOpenGL>\n" if("$_" eq "opengl");
694 $master_contents .= "#include <QtOpenVG/QtOpenVG>\n" if("$_" eq "openvg");
698 close(F);
702 #remove the old files
703 if($remove_stale) {
704 my @subdirs = ("$out_basedir/include/$lib");
705 foreach (@subdirs) {
706 my $subdir = "$_";
707 if (opendir DIR, "$subdir") {
708 while(my $t = readdir(DIR)) {
709 my $file = "$subdir/$t";
710 if(-d "$file") {
711 push @subdirs, "$file" unless($t eq "." || $t eq "..");
712 } else {
713 my @files = ("$file");
714 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
715 foreach (@files) {
716 my $file = $_;
717 my $remove_file = 0;
718 if(open(F, "<$file")) {
719 while(<F>) {
720 my $line = $_;
721 chomp $line;
722 if($line =~ /^\#include \"([^\"]*)\"$/) {
723 my $include = $1;
724 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
725 $remove_file = 1 unless(-e "$include");
726 } else {
727 $remove_file = 0;
728 last;
731 close(F);
732 unlink "$file" if($remove_file);
737 closedir DIR;
743 #create the new ones
744 foreach (split(/;/, $dir)) {
745 my $current_dir = "$_";
746 my $headers_dir = $current_dir;
747 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
748 #calc subdirs
749 my @subdirs = ($headers_dir);
750 foreach (@subdirs) {
751 my $subdir = "$_";
752 opendir DIR, "$subdir" or next;
753 while(my $t = readdir(DIR)) {
754 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
755 !($t eq "..") && !($t eq ".obj") &&
756 !($t eq ".moc") && !($t eq ".rcc") &&
757 !($t eq ".uic") && !($t eq "build"));
759 closedir DIR;
762 #calc files and "copy" them
763 foreach (@subdirs) {
764 my $subdir = "$_";
765 my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0);
766 foreach (@headers) {
767 my $header = "$_";
768 $header = 0 if("$header" =~ /^ui_.*.h/);
769 foreach (@ignore_headers) {
770 $header = 0 if("$header" eq "$_");
772 if($header) {
773 my $header_copies = 0;
774 #figure out if it is a public header
775 my $public_header = $header;
776 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
777 $public_header = 0;
778 } else {
779 foreach (@ignore_for_master_contents) {
780 $public_header = 0 if("$header" eq "$_");
784 my $iheader = $subdir . "/" . $header;
785 my @classes = $public_header ? classNames($iheader) : ();
786 if($showonly) {
787 print "$header [$lib]\n";
788 foreach(@classes) {
789 print "SYMBOL: $_\n";
791 } else {
792 #find out all the places it goes..
793 my @headers;
794 if ($public_header) {
795 @headers = ( "$out_basedir/include/$lib/$header" );
796 push @headers, "$out_basedir/include/Qt/$header"
797 if ("$lib" ne "phonon" && "$subdir" =~ /^$basedir\/src/);
799 foreach(@classes) {
800 my $header_base = basename($header);
801 my $class = $_;
802 if ($class =~ m/::/) {
803 $class =~ s,::,/,g;
805 $class_lib_map_contents .= "QT_CLASS_LIB($_, $lib, $header_base)\n";
806 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0));
808 } else {
809 @headers = ( "$out_basedir/include/$lib/private/$header" );
810 push @headers, "$out_basedir/include/Qt/private/$header"
811 if ("$lib" ne "phonon");
813 foreach(@headers) { #sync them
814 $header_copies++ if(syncHeader($_, $iheader, $copy_headers));
817 if($public_header) {
818 #put it into the master file
819 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
821 #deal with the install directives
822 if($public_header) {
823 my $pri_install_iheader = fixPaths($iheader, $current_dir);
824 foreach(@classes) {
825 my $class = $_;
826 if ($class =~ m/::/) {
827 $class =~ s,::,/,g;
829 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
830 $current_dir) . " ";
831 $pri_install_classes .= $class_header
832 unless($pri_install_classes =~ $class_header);
834 $pri_install_files.= "$pri_install_iheader ";;
838 print "header created for $iheader ($header_copies)\n" if($header_copies > 0);
844 # close the master include:
845 $master_contents .= "#endif\n";
847 unless($showonly) {
848 my @master_includes;
849 if ($lib eq "phonon") {
850 push @master_includes, "$out_basedir/include/phonon_compat/phonon/phonon";
851 push @master_includes, "$out_basedir/include/phonon/Phonon/Phonon";
852 } else {
853 push @master_includes, "$out_basedir/include/$lib/$lib";
855 foreach my $master_include (@master_includes) {
856 #generate the "master" include file
857 $pri_install_files .= fixPaths($master_include, "$modules{$lib}") . " "; #get the master file installed too
858 if($master_include && -e "$master_include") {
859 open MASTERINCLUDE, "<$master_include";
860 local $/;
861 binmode MASTERINCLUDE;
862 my $oldmaster = <MASTERINCLUDE>;
863 close MASTERINCLUDE;
864 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
865 $master_include = 0 if($oldmaster eq $master_contents);
867 if($master_include && $master_contents) {
868 my $master_dir = dirname($master_include);
869 mkpath $master_dir, 0777;
870 print "header (master) created for $lib\n";
871 open MASTERINCLUDE, ">$master_include";
872 print MASTERINCLUDE "$master_contents";
873 close MASTERINCLUDE;
877 #handle the headers.pri for each module
878 my $headers_pri_contents = "";
879 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
880 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
881 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
882 if(-e "$headers_pri_file") {
883 open HEADERS_PRI_FILE, "<$headers_pri_file";
884 local $/;
885 binmode HEADERS_PRI_FILE;
886 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
887 close HEADERS_PRI_FILE;
888 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
889 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
891 if($headers_pri_file && $master_contents) {
892 my $headers_pri_dir = dirname($headers_pri_file);
893 mkpath $headers_pri_dir, 0777;
894 print "headers.pri file created for $lib\n";
895 open HEADERS_PRI_FILE, ">$headers_pri_file";
896 print HEADERS_PRI_FILE "$headers_pri_contents";
897 close HEADERS_PRI_FILE;
901 unless($showonly) {
902 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
903 if(-e "$class_lib_map") {
904 open CLASS_LIB_MAP, "<$class_lib_map";
905 local $/;
906 binmode CLASS_LIB_MAP;
907 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
908 close CLASS_LIB_MAP;
909 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
910 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
912 if($class_lib_map) {
913 my $class_lib_map_dir = dirname($class_lib_map);
914 mkpath $class_lib_map_dir, 0777;
915 open CLASS_LIB_MAP, ">$class_lib_map";
916 print CLASS_LIB_MAP "$class_lib_map_contents";
917 close CLASS_LIB_MAP;
921 if($check_includes) {
922 for (keys(%modules)) {
923 #iteration info
924 my $lib = $_;
925 my $dir = "$modules{$lib}";
926 foreach (split(/;/, $dir)) {
927 my $current_dir = "$_";
928 #calc subdirs
929 my @subdirs = ($current_dir);
930 foreach (@subdirs) {
931 my $subdir = "$_";
932 opendir DIR, "$subdir";
933 while(my $t = readdir(DIR)) {
934 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
935 !($t eq "..") && !($t eq ".obj") &&
936 !($t eq ".moc") && !($t eq ".rcc") &&
937 !($t eq ".uic") && !($t eq "build"));
939 closedir DIR;
942 foreach (@subdirs) {
943 my $subdir = "$_";
944 my $header_skip_qt_module_test = 0;
945 foreach(@ignore_for_qt_module_check) {
946 foreach (split(/;/, $_)) {
947 $header_skip_qt_module_test = 1 if ("$subdir" =~ /^$_/);
950 my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0);
951 foreach (@headers) {
952 my $header = "$_";
953 my $header_skip_qt_begin_header_test = 0;
954 my $header_skip_qt_begin_namespace_test = 0;
955 $header = 0 if("$header" =~ /^ui_.*.h/);
956 foreach (@ignore_headers) {
957 $header = 0 if("$header" eq "$_");
959 if($header) {
960 my $public_header = $header;
961 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
962 $public_header = 0;
963 } else {
964 foreach (@ignore_for_master_contents) {
965 $public_header = 0 if("$header" eq "$_");
967 if($public_header) {
968 foreach (@ignore_for_include_check) {
969 $public_header = 0 if("$header" eq "$_");
971 foreach(@ignore_for_qt_begin_header_check) {
972 $header_skip_qt_begin_header_test = 1 if ("$header" eq "$_");
974 foreach(@ignore_for_qt_begin_namespace_check) {
975 $header_skip_qt_begin_namespace_test = 1 if ("$header" eq "$_");
980 my $iheader = $subdir . "/" . $header;
981 if($public_header) {
982 if(open(F, "<$iheader")) {
983 my $qt_module_found = 0;
984 my $qt_begin_header_found = 0;
985 my $qt_end_header_found = 0;
986 my $qt_begin_namespace_found = 0;
987 my $qt_end_namespace_found = 0;
988 my $line;
989 while($line = <F>) {
990 chomp $line;
991 my $output_line = 1;
992 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
993 last;
994 } elsif($line =~ /^ *\# *include/) {
995 my $include = $line;
996 if($line =~ /<.*>/) {
997 $include =~ s,.*<(.*)>.*,$1,;
998 } elsif($line =~ /".*"/) {
999 $include =~ s,.*"(.*)".*,$1,;
1000 } else {
1001 $include = 0;
1003 if($include) {
1004 for (keys(%modules)) {
1005 my $trylib = $_;
1006 if(-e "$out_basedir/include/$trylib/$include") {
1007 print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
1011 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1012 $qt_begin_header_found = 1;
1013 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1014 $qt_end_header_found = 1;
1015 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1016 $qt_begin_namespace_found = 1;
1017 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1018 $qt_end_namespace_found = 1;
1019 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1020 $qt_module_found = 1;
1023 if ($header_skip_qt_begin_header_test == 0) {
1024 if ($qt_begin_header_found == 0) {
1025 print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1028 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1029 print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1033 if ($header_skip_qt_begin_namespace_test == 0) {
1034 if ($qt_begin_namespace_found == 0) {
1035 print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1038 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1039 print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1043 if ($header_skip_qt_module_test == 0) {
1044 if ($qt_module_found == 0) {
1045 print "WARNING: $iheader does not include QT_MODULE\n";
1048 close(F);
1058 exit 0;