Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / bin / syncqt
blob803bae292faf26638b7421cc79e6f20fdfc15221
1 #!/usr/bin/perl -w
2 ######################################################################
4 # Synchronizes Qt header files - internal development tool.
6 # Copyright (C) 2010 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 for (my $i = 0; $i < $#ARGV; $i++) {
19 if ($ARGV[$i] eq "-base-dir" && $i < $#ARGV - 1) {
20 $ENV{"QTDIR"} = $ARGV[$i + 1];
21 last;
25 die "syncqt: QTDIR not defined" if ! $ENV{"QTDIR"}; # sanity check
27 # global variables
28 my $isunix = 0;
29 my $basedir = $ENV{"QTDIR"};
30 $basedir =~ s=\\=/=g;
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/container;$basedir/src/activeqt/control;$basedir/src/activeqt/shared",
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/WebCore",
52 "phonon" => "$basedir/src/phonon",
53 "QtMultimedia" => "$basedir/src/multimedia",
55 my %moduleheaders = ( # restrict the module headers to those found in relative path
56 "QtWebKit" => "../WebKit/qt/Api",
57 "phonon" => "../3rdparty/phonon/phonon",
60 #$modules{"QtCore"} .= ";$basedir/mkspecs/" . $ENV{"MKSPEC"} if defined $ENV{"MKSPEC"};
62 # global variables (modified by options)
63 my $module = 0;
64 my $showonly = 0;
65 my $remove_stale = 1;
66 my $force_win = 0;
67 my $force_relative = 0;
68 my $check_includes = 0;
69 my $copy_headers = 0;
70 my $create_uic_class_map = 1;
71 my $create_private_headers = 1;
72 my @modules_to_sync ;
73 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
74 my $out_basedir = $basedir;
75 $out_basedir =~ s=\\=/=g;
77 # functions ----------------------------------------------------------
79 ######################################################################
80 # Syntax: showUsage()
81 # Params: -none-
83 # Purpose: Show the usage of the script.
84 # Returns: -none-
85 ######################################################################
86 sub showUsage
88 print "$0 usage:\n";
89 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
90 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
91 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
92 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
93 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
94 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
95 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR> Create headers for <NAME> with original headers in <HEADERDIR> relative to <PROFILEDIR> \n";
96 print " -help This help\n";
97 exit 0;
100 ######################################################################
101 # Syntax: checkUnix()
102 # Params: -none-
104 # Purpose: Check if script runs on a Unix system or not. Cygwin
105 # systems are _not_ detected as Unix systems.
106 # Returns: 1 if a unix system, else 0.
107 ######################################################################
108 sub checkUnix {
109 my ($r) = 0;
110 if ( $force_win != 0) {
111 return 0;
112 } elsif ( -f "/bin/uname" ) {
113 $r = 1;
114 (-f "\\bin\\uname") && ($r = 0);
115 } elsif ( -f "/usr/bin/uname" ) {
116 $r = 1;
117 (-f "\\usr\\bin\\uname") && ($r = 0);
119 if($r) {
120 $_ = $Config{'osname'};
121 $r = 0 if( /(ms)|(cyg)win/i );
123 return $r;
126 sub checkRelative {
127 my ($dir) = @_;
128 return 0 if($dir =~ /^\//);
129 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
130 return 1;
133 ######################################################################
134 # Syntax: shouldMasterInclude(iheader)
135 # Params: iheader, string, filename to verify inclusion
137 # Purpose: Determines if header should be in the master include file.
138 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
139 # able to open, else 1.
140 ######################################################################
141 sub shouldMasterInclude {
142 my ($iheader) = @_;
143 return 0 if(basename($iheader) =~ /_/);
144 return 0 if(basename($iheader) =~ /qconfig/);
145 if(open(F, "<$iheader")) {
146 while(<F>) {
147 chomp;
148 return 0 if(/^\#pragma qt_no_master_include$/);
150 close(F);
151 } else {
152 return 0;
154 return 1;
157 ######################################################################
158 # Syntax: classNames(iheader)
159 # Params: iheader, string, filename to parse for classname "symlinks"
161 # Purpose: Scans through iheader to find all classnames that should be
162 # synced into library's include structure.
163 # Returns: List of all class names in a file.
164 ######################################################################
165 sub classNames {
166 my @ret;
167 my ($iheader) = @_;
168 if(basename($iheader) eq "qglobal.h") {
169 push @ret, "QtGlobal";
170 } elsif(basename($iheader) eq "qendian.h") {
171 push @ret, "QtEndian";
172 } elsif(basename($iheader) eq "qconfig.h") {
173 push @ret, "QtConfig";
174 } elsif(basename($iheader) eq "qplugin.h") {
175 push @ret, "QtPlugin";
176 } elsif(basename($iheader) eq "qalgorithms.h") {
177 push @ret, "QtAlgorithms";
178 } elsif(basename($iheader) eq "qcontainerfwd.h") {
179 push @ret, "QtContainerFwd";
180 } elsif(basename($iheader) eq "qdebug.h") {
181 push @ret, "QtDebug";
182 } elsif(basename($iheader) eq "qevent.h") {
183 push @ret, "QtEvents";
184 } elsif(basename($iheader) eq "qnamespace.h") {
185 push @ret, "Qt"
186 } elsif(basename($iheader) eq "qssl.h") {
187 push @ret, "QSsl";
188 } elsif(basename($iheader) eq "qtest.h") {
189 push @ret, "QTest"
190 } elsif(basename($iheader) eq "qtconcurrentmap.h") {
191 push @ret, "QtConcurrentMap"
192 } elsif(basename($iheader) eq "qtconcurrentfilter.h") {
193 push @ret, "QtConcurrentFilter"
194 } elsif(basename($iheader) eq "qtconcurrentrun.h") {
195 push @ret, "QtConcurrentRun"
198 my $parsable = "";
199 if(open(F, "<$iheader")) {
200 while(<F>) {
201 my $line = $_;
202 chomp $line;
203 chop $line if ($line =~ /\r$/);
204 if($line =~ /^\#/) {
205 if($line =~ /\\$/) {
206 while($line = <F>) {
207 chomp $line;
208 last unless($line =~ /\\$/);
211 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
212 push(@ret, "$1") if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
213 $line = 0;
215 if($line) {
216 $line =~ s,//.*$,,; #remove c++ comments
217 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
218 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
219 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
220 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
221 $parsable .= " " . $line;
224 close(F);
227 my $last_definition = 0;
228 my @namespaces;
229 for(my $i = 0; $i < length($parsable); $i++) {
230 my $definition = 0;
231 my $character = substr($parsable, $i, 1);
232 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
233 for($i+=2; $i < length($parsable); $i++) {
234 my $end = substr($parsable, $i, 2);
235 if($end eq "*/") {
236 $last_definition = $i+2;
237 $i++;
238 last;
241 } elsif($character eq "{") {
242 my $brace_depth = 1;
243 my $block_start = $i + 1;
244 BLOCK: for($i+=1; $i < length($parsable); $i++) {
245 my $ignore = substr($parsable, $i, 1);
246 if($ignore eq "{") {
247 $brace_depth++;
248 } elsif($ignore eq "}") {
249 $brace_depth--;
250 unless($brace_depth) {
251 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
252 my $end = substr($parsable, $i2, 1);
253 if($end eq ";" || $end ne " ") {
254 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
255 $i = $i2 if($end eq ";");
256 $last_definition = $i + 1;
257 last BLOCK;
263 } elsif($character eq ";") {
264 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
265 $last_definition = $i + 1;
266 } elsif($character eq "}") {
267 # a naked } must be a namespace ending
268 # if it's not a namespace, it's eaten by the loop above
269 pop @namespaces;
270 $last_definition = $i + 1;
273 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
274 && substr($parsable, $i+1, 1) eq "{") {
275 push @namespaces, $1;
277 # Eat the opening { so that the condensing loop above doesn't see it
278 $i++;
279 $last_definition = $i + 1;
282 if($definition) {
283 $definition =~ s=[\n\r]==g;
284 my @symbols;
285 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
286 push @symbols, $1;
287 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
288 push @symbols, $2;
289 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
290 push @symbols, $4;
291 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
292 push @symbols, "Q" . $1 . "Iterator";
293 push @symbols, "QMutable" . $1 . "Iterator";
296 foreach (@symbols) {
297 my $symbol = $_;
298 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
299 push @ret, $symbol
300 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
301 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
305 return @ret;
308 ######################################################################
309 # Syntax: syncHeader(header, iheader, copy)
310 # Params: header, string, filename to create "symlink" for
311 # iheader, string, destination name of symlink
312 # copy, forces header to be a copy of iheader
314 # Purpose: Syncronizes header to iheader
315 # Returns: 1 if successful, else 0.
316 ######################################################################
317 sub syncHeader {
318 my ($header, $iheader, $copy) = @_;
319 $iheader =~ s=\\=/=g;
320 $header =~ s=\\=/=g;
321 return copyFile($iheader, $header) if($copy);
323 unless(-e "$header") {
324 my $header_dir = dirname($header);
325 mkpath $header_dir, 0777;
327 #write it
328 my $iheader_out = fixPaths($iheader, $header_dir);
329 open HEADER, ">$header" || die "Could not open $header for writing!\n";
330 print HEADER "#include \"$iheader_out\"\n";
331 close HEADER;
332 return 1;
334 return 0;
337 ######################################################################
338 # Syntax: fixPaths(file, dir)
339 # Params: file, string, filepath to be made relative to dir
340 # dir, string, dirpath for point of origin
342 # Purpose: file is made relative (if possible) of dir.
343 # Returns: String with the above applied conversion.
344 ######################################################################
345 sub fixPaths {
346 my ($file, $dir) = @_;
347 $dir =~ s=^$basedir/=$out_basedir/= if(!($basedir eq $out_basedir));
348 $file =~ s=\\=/=g;
349 $file =~ s/\+/\\+/g;
350 $dir =~ s=\\=/=g;
351 $dir =~ s/\+/\\+/g;
353 #setup
354 my $ret = $file;
355 my $file_dir = dirname($file);
356 if($file_dir eq ".") {
357 $file_dir = getcwd();
358 $file_dir =~ s=\\=/=g;
360 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:,g;
361 if($dir eq ".") {
362 $dir = getcwd();
363 $dir =~ s=\\=/=g;
365 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
366 return basename($file) if("$file_dir" eq "$dir");
368 #guts
369 my $match_dir = 0;
370 for(my $i = 1; $i < length($file_dir); $i++) {
371 my $slash = index($file_dir, "/", $i);
372 last if($slash == -1);
373 my $tmp = substr($file_dir, 0, $slash);
374 last unless($dir =~ m,^$tmp/,);
375 $match_dir = $tmp;
376 $i = $slash;
378 if($match_dir) {
379 my $after = substr($dir, length($match_dir));
380 my $count = ($after =~ tr,/,,);
381 my $dots = "";
382 for(my $i = 0; $i < $count; $i++) {
383 $dots .= "../";
385 $ret =~ s,^$match_dir,$dots,;
387 $ret =~ s,/+,/,g;
388 return $ret;
391 ######################################################################
392 # Syntax: fileContents(filename)
393 # Params: filename, string, filename of file to return contents
395 # Purpose: Get the contents of a file.
396 # Returns: String with contents of the file, or empty string if file
397 # doens't exist.
398 # Warning: Dies if it does exist but script cannot get read access.
399 ######################################################################
400 sub fileContents {
401 my ($filename) = @_;
402 my $filecontents = "";
403 if (-e $filename) {
404 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
405 local $/;
406 binmode I;
407 $filecontents = <I>;
408 close I;
410 return $filecontents;
413 ######################################################################
414 # Syntax: fileCompare(file1, file2)
415 # Params: file1, string, filename of first file
416 # file2, string, filename of second file
418 # Purpose: Determines if files are equal, and which one is newer.
419 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
420 # is newer, 1 if file2 is newer.
421 ######################################################################
422 sub fileCompare {
423 my ($file1, $file2) = @_;
424 my $file1contents = fileContents($file1);
425 my $file2contents = fileContents($file2);
426 if (! -e $file1) { return 1; }
427 if (! -e $file2) { return -1; }
428 return $file1contents ne $file2contents ? (stat("$file2"))[9] <=> (stat("$file1"))[9] : 0;
431 ######################################################################
432 # Syntax: copyFile(file, ifile)
433 # Params: file, string, filename to create duplicate for
434 # ifile, string, destination name of duplicate
436 # Purpose: Keeps files in sync so changes in the newer file will be
437 # written to the other.
438 # Returns: 1 if files were synced, else 0.
439 # Warning: Dies if script cannot get write access.
440 ######################################################################
441 sub copyFile
443 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
444 # Bi-directional synchronization
445 open( I, "< " . $file ) || die "Could not open $file for reading";
446 local $/;
447 binmode I;
448 $filecontents = <I>;
449 close I;
450 if ( open(I, "< " . $ifile) ) {
451 local $/;
452 binmode I;
453 $ifilecontents = <I>;
454 close I;
455 $copy = fileCompare($file, $ifile);
456 $knowdiff = 0,
457 } else {
458 $copy = -1;
459 $knowdiff = 1;
462 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
463 if ( $copy > 0 ) {
464 my $file_dir = dirname($file);
465 mkpath $file_dir, 0777 unless(-e "$file_dir");
466 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
467 local $/;
468 binmode O;
469 print O $ifilecontents;
470 close O;
471 return 1;
472 } elsif ( $copy < 0 ) {
473 my $ifile_dir = dirname($ifile);
474 mkpath $ifile_dir, 0777 unless(-e "$ifile_dir");
475 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
476 local $/;
477 binmode O;
478 print O $filecontents;
479 close O;
480 return 1;
483 return 0;
486 ######################################################################
487 # Syntax: symlinkFile(file, ifile)
488 # Params: file, string, filename to create "symlink" for
489 # ifile, string, destination name of symlink
491 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
492 # support symlink).
493 # Returns: 1 on success, else 0.
494 ######################################################################
495 sub symlinkFile
497 my ($file,$ifile) = @_;
499 if ($isunix) {
500 print "symlink created for $file ";
501 if ( $force_relative && ($ifile =~ /^$basedir/)) {
502 my $t = getcwd();
503 my $c = -1;
504 my $p = "../";
505 $t =~ s-^$basedir/--;
506 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
507 $file =~ s-^$basedir/-$p-;
508 print " ($file)\n";
510 print "\n";
511 return symlink($file, $ifile);
513 return copyFile($file, $ifile);
516 ######################################################################
517 # Syntax: findFiles(dir, match, descend)
518 # Params: dir, string, directory to search for name
519 # match, string, regular expression to match in dir
520 # descend, integer, 0 = non-recursive search
521 # 1 = recurse search into subdirectories
523 # Purpose: Finds files matching a regular expression.
524 # Returns: List of matching files.
526 # Examples:
527 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
528 # findFiles("/tmp","^#",0) - finds #* files in /tmp
529 ######################################################################
530 sub findFiles {
531 my ($dir,$match,$descend) = @_;
532 my ($file,$p,@files);
533 local(*D);
534 $dir =~ s=\\=/=g;
535 ($dir eq "") && ($dir = ".");
536 if ( opendir(D,$dir) ) {
537 if ( $dir eq "." ) {
538 $dir = "";
539 } else {
540 ($dir =~ /\/$/) || ($dir .= "/");
542 foreach $file ( sort readdir(D) ) {
543 next if ( $file =~ /^\.\.?$/ );
544 $p = $file;
545 ($file =~ /$match/) && (push @files, $p);
546 if ( $descend && -d $p && ! -l $p ) {
547 push @files, &findFiles($p,$match,$descend);
550 closedir(D);
552 return @files;
555 # --------------------------------------------------------------------
556 # "main" function
557 # --------------------------------------------------------------------
559 while ( @ARGV ) {
560 my $var = 0;
561 my $val = 0;
563 #parse
564 my $arg = shift @ARGV;
565 if ("$arg" eq "-h" || "$arg" eq "-help" || "$arg" eq "?") {
566 $var = "show_help";
567 $val = "yes";
568 } elsif("$arg" eq "-copy") {
569 $var = "copy";
570 $val = "yes";
571 } elsif("$arg" eq "-o" || "$arg" eq "-outdir") {
572 $var = "output";
573 $val = shift @ARGV;
574 } elsif("$arg" eq "-showonly" || "$arg" eq "-remove-stale" || "$arg" eq "-windows" ||
575 "$arg" eq "-relative" || "$arg" eq "-check-includes") {
576 $var = substr($arg, 1);
577 $val = "yes";
578 } elsif("$arg" =~ /^-no-(.*)$/) {
579 $var = $1;
580 $val = "no";
581 #these are for commandline compat
582 } elsif("$arg" eq "-inc") {
583 $var = "output";
584 $val = shift @ARGV;
585 } elsif("$arg" eq "-module") {
586 $var = "module";
587 $val = shift @ARGV;
588 } elsif("$arg" eq "-separate-module") {
589 $var = "separate-module";
590 $val = shift @ARGV;
591 } elsif("$arg" eq "-show") {
592 $var = "showonly";
593 $val = "yes";
594 } elsif("$arg" eq "-base-dir") {
595 # skip, it's been dealt with at the top of the file
596 shift @ARGV;
597 next;
600 #do something
601 if(!$var || "$var" eq "show_help") {
602 print "Unknown option: $arg\n\n" if(!$var);
603 showUsage();
604 } elsif ("$var" eq "copy") {
605 if("$val" eq "yes") {
606 $copy_headers++;
607 } elsif($showonly) {
608 $copy_headers--;
610 } elsif ("$var" eq "showonly") {
611 if("$val" eq "yes") {
612 $showonly++;
613 } elsif($showonly) {
614 $showonly--;
616 } elsif ("$var" eq "check-includes") {
617 if("$val" eq "yes") {
618 $check_includes++;
619 } elsif($check_includes) {
620 $check_includes--;
622 } elsif ("$var" eq "remove-stale") {
623 if("$val" eq "yes") {
624 $remove_stale++;
625 } elsif($remove_stale) {
626 $remove_stale--;
628 } elsif ("$var" eq "windows") {
629 if("$val" eq "yes") {
630 $force_win++;
631 } elsif($force_win) {
632 $force_win--;
634 } elsif ("$var" eq "relative") {
635 if("$val" eq "yes") {
636 $force_relative++;
637 } elsif($force_relative) {
638 $force_relative--;
640 } elsif ("$var" eq "module") {
641 print "module :$val:\n";
642 die "No such module: $val" unless(defined $modules{$val});
643 push @modules_to_sync, $val;
644 } elsif ("$var" eq "separate-module") {
645 my ($module, $prodir, $headerdir) = split(/:/, $val);
646 $modules{$module} = $prodir;
647 push @modules_to_sync, $module;
648 $moduleheaders{$module} = $headerdir;
649 $create_uic_class_map = 0;
650 $create_private_headers = 0;
651 } elsif ("$var" eq "output") {
652 my $outdir = $val;
653 if(checkRelative($outdir)) {
654 $out_basedir = getcwd();
655 chomp $out_basedir;
656 $out_basedir .= "/" . $outdir;
657 } else {
658 $out_basedir = $outdir;
660 # \ -> /
661 $out_basedir =~ s=\\=/=g;
664 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
666 $isunix = checkUnix; #cache checkUnix
668 # create path
669 mkpath "$out_basedir/include", 0777;
671 my @ignore_headers = ();
672 my $class_lib_map_contents = "";
673 my @ignore_for_master_contents = ( "qt.h", "qpaintdevicedefs.h" );
674 my @ignore_for_include_check = ( "qatomic.h" );
675 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" );
676 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" );
677 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}" );
679 foreach (@modules_to_sync) {
680 #iteration info
681 my $lib = $_;
682 my $dir = "$modules{$lib}";
683 my $pathtoheaders = "";
684 $pathtoheaders = "$moduleheaders{$lib}" if ($moduleheaders{$lib});
686 #information used after the syncing
687 my $pri_install_classes = "";
688 my $pri_install_files = "";
689 my $pri_install_pfiles = "";
691 my $libcapitals = $lib;
692 $libcapitals =~ y/a-z/A-Z/;
693 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
695 #get dependencies
696 if(-e "$dir/" . basename($dir) . ".pro") {
697 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
698 while(<F>) {
699 my $line = $_;
700 chomp $line;
701 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
702 foreach(split(/ /, "$1")) {
703 $master_contents .= "#include <QtCore/QtCore>\n" if("$_" eq "core");
704 $master_contents .= "#include <QtGui/QtGui>\n" if("$_" eq "gui");
705 $master_contents .= "#include <QtNetwork/QtNetwork>\n" if("$_" eq "network");
706 $master_contents .= "#include <QtSvg/QtSvg>\n" if("$_" eq "svg");
707 $master_contents .= "#include <QtDeclarative/QtDeclarative>\n" if("$_" eq "declarative");
708 $master_contents .= "#include <QtScript/QtScript>\n" if("$_" eq "script");
709 $master_contents .= "#include <QtScriptTools/QtScriptTools>\n" if("$_" eq "scripttools");
710 $master_contents .= "#include <Qt3Support/Qt3Support>\n" if("$_" eq "qt3support");
711 $master_contents .= "#include <QtSql/QtSql>\n" if("$_" eq "sql");
712 $master_contents .= "#include <QtXml/QtXml>\n" if("$_" eq "xml");
713 $master_contents .= "#include <QtXmlPatterns/QtXmlPatterns>\n" if("$_" eq "xmlpatterns");
714 $master_contents .= "#include <QtOpenGL/QtOpenGL>\n" if("$_" eq "opengl");
715 $master_contents .= "#include <QtOpenVG/QtOpenVG>\n" if("$_" eq "openvg");
719 close(F);
723 #remove the old files
724 if($remove_stale) {
725 my @subdirs = ("$out_basedir/include/$lib");
726 foreach (@subdirs) {
727 my $subdir = "$_";
728 if (opendir DIR, "$subdir") {
729 while(my $t = readdir(DIR)) {
730 my $file = "$subdir/$t";
731 if(-d "$file") {
732 push @subdirs, "$file" unless($t eq "." || $t eq "..");
733 } else {
734 my @files = ("$file");
735 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
736 foreach (@files) {
737 my $file = $_;
738 my $remove_file = 0;
739 if(open(F, "<$file")) {
740 while(<F>) {
741 my $line = $_;
742 chomp $line;
743 if($line =~ /^\#include \"([^\"]*)\"$/) {
744 my $include = $1;
745 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
746 $remove_file = 1 unless(-e "$include");
747 } else {
748 $remove_file = 0;
749 last;
752 close(F);
753 unlink "$file" if($remove_file);
758 closedir DIR;
764 #create the new ones
765 foreach (split(/;/, $dir)) {
766 my $current_dir = "$_";
767 my $headers_dir = $current_dir;
768 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
769 #calc subdirs
770 my @subdirs = ($headers_dir);
771 foreach (@subdirs) {
772 my $subdir = "$_";
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"));
780 closedir DIR;
783 #calc files and "copy" them
784 foreach (@subdirs) {
785 my $subdir = "$_";
786 my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0);
787 foreach (@headers) {
788 my $header = "$_";
789 $header = 0 if("$header" =~ /^ui_.*.h/);
790 foreach (@ignore_headers) {
791 $header = 0 if("$header" eq "$_");
793 if($header) {
794 my $header_copies = 0;
795 #figure out if it is a public header
796 my $public_header = $header;
797 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
798 $public_header = 0;
799 } else {
800 foreach (@ignore_for_master_contents) {
801 $public_header = 0 if("$header" eq "$_");
805 my $iheader = $subdir . "/" . $header;
806 my @classes = $public_header ? classNames($iheader) : ();
807 if($showonly) {
808 print "$header [$lib]\n";
809 foreach(@classes) {
810 print "SYMBOL: $_\n";
812 } else {
813 #find out all the places it goes..
814 my @headers;
815 if ($public_header) {
816 @headers = ( "$out_basedir/include/$lib/$header" );
817 push @headers, "$out_basedir/include/Qt/$header"
818 if ("$lib" ne "phonon" && "$subdir" =~ /^$basedir\/src/);
820 foreach(@classes) {
821 my $header_base = basename($header);
822 my $class = $_;
823 # Strip namespaces:
824 $class =~ s/^.*:://;
825 # if ($class =~ m/::/) {
826 # class =~ s,::,/,g;
828 $class_lib_map_contents .= "QT_CLASS_LIB($_, $lib, $header_base)\n";
829 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0));
831 # KDE-Compat headers for Phonon
832 if ($lib eq "phonon") {
833 $header_copies++ if (syncHeader("$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0));
836 } elsif ($create_private_headers) {
837 @headers = ( "$out_basedir/include/$lib/private/$header" );
838 push @headers, "$out_basedir/include/Qt/private/$header"
839 if ("$lib" ne "phonon");
841 foreach(@headers) { #sync them
842 $header_copies++ if(syncHeader($_, $iheader, $copy_headers));
845 if($public_header) {
846 #put it into the master file
847 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
849 #deal with the install directives
850 if($public_header) {
851 my $pri_install_iheader = fixPaths($iheader, $current_dir);
852 foreach(@classes) {
853 my $class = $_;
854 # Strip namespaces:
855 $class =~ s/^.*:://;
856 # if ($class =~ m/::/) {
857 # $class =~ s,::,/,g;
859 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
860 $current_dir) . " ";
861 $pri_install_classes .= $class_header
862 unless($pri_install_classes =~ $class_header);
864 $pri_install_files.= "$pri_install_iheader ";;
867 else {
868 my $pri_install_iheader = fixPaths($iheader, $current_dir);
869 $pri_install_pfiles.= "$pri_install_iheader ";;
872 print "header created for $iheader ($header_copies)\n" if($header_copies > 0);
878 # close the master include:
879 $master_contents .= "#endif\n";
881 unless($showonly) {
882 my @master_includes;
883 push @master_includes, "$out_basedir/include/$lib/$lib";
884 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
885 foreach my $master_include (@master_includes) {
886 #generate the "master" include file
887 $pri_install_files .= fixPaths($master_include, "$modules{$lib}") . " "; #get the master file installed too
888 if($master_include && -e "$master_include") {
889 open MASTERINCLUDE, "<$master_include";
890 local $/;
891 binmode MASTERINCLUDE;
892 my $oldmaster = <MASTERINCLUDE>;
893 close MASTERINCLUDE;
894 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
895 $master_include = 0 if($oldmaster eq $master_contents);
897 if($master_include && $master_contents) {
898 my $master_dir = dirname($master_include);
899 mkpath $master_dir, 0777;
900 print "header (master) created for $lib\n";
901 open MASTERINCLUDE, ">$master_include";
902 print MASTERINCLUDE "$master_contents";
903 close MASTERINCLUDE;
907 #handle the headers.pri for each module
908 my $headers_pri_contents = "";
909 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
910 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
911 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
912 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
913 if(-e "$headers_pri_file") {
914 open HEADERS_PRI_FILE, "<$headers_pri_file";
915 local $/;
916 binmode HEADERS_PRI_FILE;
917 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
918 close HEADERS_PRI_FILE;
919 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
920 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
922 if($headers_pri_file && $master_contents) {
923 my $headers_pri_dir = dirname($headers_pri_file);
924 mkpath $headers_pri_dir, 0777;
925 print "headers.pri file created for $lib\n";
926 open HEADERS_PRI_FILE, ">$headers_pri_file";
927 print HEADERS_PRI_FILE "$headers_pri_contents";
928 close HEADERS_PRI_FILE;
932 unless($showonly || !$create_uic_class_map) {
933 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
934 if(-e "$class_lib_map") {
935 open CLASS_LIB_MAP, "<$class_lib_map";
936 local $/;
937 binmode CLASS_LIB_MAP;
938 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
939 close CLASS_LIB_MAP;
940 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
941 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
943 if($class_lib_map) {
944 my $class_lib_map_dir = dirname($class_lib_map);
945 mkpath $class_lib_map_dir, 0777;
946 open CLASS_LIB_MAP, ">$class_lib_map";
947 print CLASS_LIB_MAP "$class_lib_map_contents";
948 close CLASS_LIB_MAP;
952 if($check_includes) {
953 for (keys(%modules)) {
954 #iteration info
955 my $lib = $_;
956 my $dir = "$modules{$lib}";
957 foreach (split(/;/, $dir)) {
958 my $current_dir = "$_";
959 #calc subdirs
960 my @subdirs = ($current_dir);
961 foreach (@subdirs) {
962 my $subdir = "$_";
963 opendir DIR, "$subdir";
964 while(my $t = readdir(DIR)) {
965 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
966 !($t eq "..") && !($t eq ".obj") &&
967 !($t eq ".moc") && !($t eq ".rcc") &&
968 !($t eq ".uic") && !($t eq "build"));
970 closedir DIR;
973 foreach (@subdirs) {
974 my $subdir = "$_";
975 my $header_skip_qt_module_test = 0;
976 foreach(@ignore_for_qt_module_check) {
977 foreach (split(/;/, $_)) {
978 $header_skip_qt_module_test = 1 if ("$subdir" =~ /^$_/);
981 my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0);
982 foreach (@headers) {
983 my $header = "$_";
984 my $header_skip_qt_begin_header_test = 0;
985 my $header_skip_qt_begin_namespace_test = 0;
986 $header = 0 if("$header" =~ /^ui_.*.h/);
987 foreach (@ignore_headers) {
988 $header = 0 if("$header" eq "$_");
990 if($header) {
991 my $public_header = $header;
992 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
993 $public_header = 0;
994 } else {
995 foreach (@ignore_for_master_contents) {
996 $public_header = 0 if("$header" eq "$_");
998 if($public_header) {
999 foreach (@ignore_for_include_check) {
1000 $public_header = 0 if("$header" eq "$_");
1002 foreach(@ignore_for_qt_begin_header_check) {
1003 $header_skip_qt_begin_header_test = 1 if ("$header" eq "$_");
1005 foreach(@ignore_for_qt_begin_namespace_check) {
1006 $header_skip_qt_begin_namespace_test = 1 if ("$header" eq "$_");
1011 my $iheader = $subdir . "/" . $header;
1012 if($public_header) {
1013 if(open(F, "<$iheader")) {
1014 my $qt_module_found = 0;
1015 my $qt_begin_header_found = 0;
1016 my $qt_end_header_found = 0;
1017 my $qt_begin_namespace_found = 0;
1018 my $qt_end_namespace_found = 0;
1019 my $line;
1020 while($line = <F>) {
1021 chomp $line;
1022 my $output_line = 1;
1023 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1024 last;
1025 } elsif($line =~ /^ *\# *include/) {
1026 my $include = $line;
1027 if($line =~ /<.*>/) {
1028 $include =~ s,.*<(.*)>.*,$1,;
1029 } elsif($line =~ /".*"/) {
1030 $include =~ s,.*"(.*)".*,$1,;
1031 } else {
1032 $include = 0;
1034 if($include) {
1035 for (keys(%modules)) {
1036 my $trylib = $_;
1037 if(-e "$out_basedir/include/$trylib/$include") {
1038 print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
1042 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1043 $qt_begin_header_found = 1;
1044 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1045 $qt_end_header_found = 1;
1046 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1047 $qt_begin_namespace_found = 1;
1048 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1049 $qt_end_namespace_found = 1;
1050 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1051 $qt_module_found = 1;
1054 if ($header_skip_qt_begin_header_test == 0) {
1055 if ($qt_begin_header_found == 0) {
1056 print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1059 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1060 print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1064 if ($header_skip_qt_begin_namespace_test == 0) {
1065 if ($qt_begin_namespace_found == 0) {
1066 print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1069 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1070 print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1074 if ($header_skip_qt_module_test == 0) {
1075 if ($qt_module_found == 0) {
1076 print "WARNING: $iheader does not include QT_MODULE\n";
1079 close(F);
1089 exit 0;