Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-staging
[profile/ivi/qtbase.git] / bin / syncqt
1 #!/usr/bin/perl -w
2 ######################################################################
3 #
4 # Synchronizes Qt header files - internal development tool.
5 #
6 # Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 # Contact: Nokia Corporation (qt-info@nokia.com)
8 #
9 ######################################################################
10
11 # use packages -------------------------------------------------------
12 use File::Basename;
13 use File::Path;
14 use Cwd;
15 use Cwd 'abs_path';
16 use Config;
17 use strict;
18
19 # set output basedir to be where ever syncqt is run from
20 our $out_basedir = getcwd();
21 $out_basedir =~ s=\\=/=g;
22 our $basedir;
23 our $quoted_basedir;
24
25
26 # try to figure out where QtBase is located
27 # normally the script location should be enough, if not fall back to
28 # QTDIR environment variable. If that doesn't work, later ask the
29 # user to use the -qtdir option explicitly.
30 my $qtbasedir = $ENV{"QTDIR"};
31 $qtbasedir = dirname(dirname($0)) if (!$qtbasedir);
32 $qtbasedir =~ s=\\=/=g if (defined $qtbasedir);
33
34 # will be defined based on the modules sync.profile
35 our (%modules, %moduleheaders, %classnames, %mastercontent, %modulepris);
36
37 # global variables (modified by options)
38 my $isunix = 0;
39 my $module = 0;
40 my $showonly = 0;
41 my $quiet = 0;
42 my $remove_stale = 1;
43 my $force_win = 0;
44 my $force_relative = 0;
45 my $check_includes = 0;
46 my $copy_headers = 0;
47 my $create_uic_class_map = 0;
48 my $create_private_headers = 1;
49 my $no_module_fwd = 0;
50 my $no_module_version_header = 0;
51 my @modules_to_sync ;
52 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
53
54
55 # functions ----------------------------------------------------------
56
57 ######################################################################
58 # Syntax:  showUsage()
59 # Params:  -none-
60 #
61 # Purpose: Show the usage of the script.
62 # Returns: -none-
63 ######################################################################
64 sub showUsage
65 {
66     print "$0 usage:\n";
67     print "  <module directory>    Specifies which module to sync header files for (required for shadow builds!)\n\n";
68
69     print "  -copy                 Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
70     print "  -remove-stale         Removes stale headers              (default: " . ($remove_stale ? "yes" : "no") . ")\n";
71     print "  -relative             Force relative symlinks            (default: " . ($force_relative ? "yes" : "no") . ")\n";
72     print "  -windows              Force platform to Windows          (default: " . ($force_win ? "yes" : "no") . ")\n";
73     print "  -showonly             Show action but not perform        (default: " . ($showonly ? "yes" : "no") . ")\n";
74     print "  -outdir <PATH>        Specify output directory for sync  (default: $out_basedir)\n";
75     print "  -qtdir <PATH>         Set the path to QtBase           (detected: " . (defined $qtbasedir ? $qtbasedir : "-none-") . ")\n";
76     print "  -quiet                Only report problems, not activity (default: " . ($quiet ? "yes" : "no") . ")\n";
77     print "  -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
78     print "                        Create headers for <NAME> with original headers in <HEADERDIR> relative to <PROFILEDIR> \n";
79     print "  -private              Force copy private headers         (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
80     print "  -no-module-fwd        Don't create fwd includes for module pri files\n";
81     print "  -no-module-version-header\n";
82     print "                        Don't create module version header file\n";
83     print "  -help                 This help\n";
84     exit 0;
85 }
86
87 ######################################################################
88 # Syntax:  checkUnix()
89 # Params:  -none-
90 #
91 # Purpose: Check if script runs on a Unix system or not. Cygwin
92 #          systems are _not_ detected as Unix systems.
93 # Returns: 1 if a unix system, else 0.
94 ######################################################################
95 sub checkUnix {
96     my ($r) = 0;
97     if ( $force_win != 0) {
98         return 0;
99     } elsif ( -f "/bin/uname" ) {
100         $r = 1;
101         (-f "\\bin\\uname") && ($r = 0);
102     } elsif ( -f "/usr/bin/uname" ) {
103         $r = 1;
104         (-f "\\usr\\bin\\uname") && ($r = 0);
105     }
106     if($r) {
107         $_ = $Config{'osname'};
108         $r = 0 if( /(ms)|(cyg)win/i );
109     }
110     return $r;
111 }
112
113 sub checkRelative {
114     my ($dir) = @_;
115     return 0 if($dir =~ /^\//);
116     return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
117     return 1;
118 }
119
120 ######################################################################
121 # Syntax:  shouldMasterInclude(iheader)
122 # Params:  iheader, string, filename to verify inclusion
123 #
124 # Purpose: Determines if header should be in the master include file.
125 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
126 #          able to open, else 1.
127 ######################################################################
128 sub shouldMasterInclude {
129     my ($iheader) = @_;
130     return 0 if(basename($iheader) =~ /_/);
131     return 0 if(basename($iheader) =~ /qconfig/);
132     if(open(F, "<$iheader")) {
133         while(<F>) {
134             chomp;
135             return 0 if(/^\#pragma qt_no_master_include$/);
136         }
137         close(F);
138     } else {
139         return 0;
140     }
141     return 1;
142 }
143
144 ######################################################################
145 # Syntax:  classNames(iheader)
146 # Params:  iheader, string, filename to parse for classname "symlinks"
147 #
148 # Purpose: Scans through iheader to find all classnames that should be
149 #          synced into library's include structure.
150 # Returns: List of all class names in a file.
151 ######################################################################
152 sub classNames {
153     my @ret;
154     my ($iheader) = @_;
155
156     my $classname = $classnames{basename($iheader)};
157     push @ret, $classname if ($classname);
158
159     my $parsable = "";
160     if(open(F, "<$iheader")) {
161         while(<F>) {
162             my $line = $_;
163             chomp $line;
164                         chop $line if ($line =~ /\r$/);
165             if($line =~ /^\#/) {
166                 if($line =~ /\\$/) {
167                     while($line = <F>) {
168                         chomp $line;
169                         last unless($line =~ /\\$/);
170                     }
171                 }
172                 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
173                 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
174                 $line = 0;
175             }
176             if($line) {
177                 $line =~ s,//.*$,,; #remove c++ comments
178                 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
179                 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
180                 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
181                 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
182                 $parsable .= " " . $line;
183             }
184         }
185         close(F);
186     }
187
188     my $last_definition = 0;
189     my @namespaces;
190     for(my $i = 0; $i < length($parsable); $i++) {
191         my $definition = 0;
192         my $character = substr($parsable, $i, 1);
193         if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
194             for($i+=2; $i < length($parsable); $i++) {
195                 my $end = substr($parsable, $i, 2);
196                 if($end eq "*/") {
197                     $last_definition = $i+2;
198                     $i++;
199                     last;
200                 }
201             }
202         } elsif($character eq "{") {
203             my $brace_depth = 1;
204             my $block_start = $i + 1;
205           BLOCK: for($i+=1; $i < length($parsable); $i++) {
206               my $ignore = substr($parsable, $i, 1);
207               if($ignore eq "{") {
208                   $brace_depth++;
209               } elsif($ignore eq "}") {
210                   $brace_depth--;
211                   unless($brace_depth) {
212                       for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
213                           my $end = substr($parsable, $i2, 1);
214                           if($end eq ";" || $end ne " ") {
215                               $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
216                               $i = $i2 if($end eq ";");
217                               $last_definition = $i + 1;
218                               last BLOCK;
219                           }
220                       }
221                   }
222               }
223           }
224         } elsif($character eq ";") {
225             $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
226             $last_definition = $i + 1;
227         } elsif($character eq "}") {
228             # a naked } must be a namespace ending
229             # if it's not a namespace, it's eaten by the loop above
230             pop @namespaces;
231             $last_definition = $i + 1;
232         }
233
234         if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
235             && substr($parsable, $i+1, 1) eq "{") {
236             push @namespaces, $1;
237
238             # Eat the opening { so that the condensing loop above doesn't see it
239             $i++;
240             $last_definition = $i + 1;
241         }
242
243         if($definition) {
244             $definition =~ s=[\n\r]==g;
245             my @symbols;
246             if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
247                 push @symbols, $1;
248             } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
249                 push @symbols, $2;
250             } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
251                 push @symbols, $4;
252             } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
253                 push @symbols, "Q" . $1 . "Iterator";
254                 push @symbols, "QMutable" . $1 . "Iterator";
255             }
256
257             foreach my $symbol (@symbols) {
258                 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
259                 push @ret, $symbol
260                     if ($symbol =~ /^Q[^:]*$/           # no-namespace, starting with Q
261                         || $symbol =~ /^Phonon::/);     # or in the Phonon namespace
262             }
263         }
264     }
265     return @ret;
266 }
267
268 ######################################################################
269 # Syntax:  syncHeader(header, iheader, copy, timestamp)
270 # Params:  header, string, filename to create "symlink" for
271 #          iheader, string, destination name of symlink
272 #          copy, forces header to be a copy of iheader
273 #          timestamp, the requested modification time if copying
274 #
275 # Purpose: Syncronizes header to iheader
276 # Returns: 1 if successful, else 0.
277 ######################################################################
278 sub syncHeader {
279     my ($header, $iheader, $copy, $ts) = @_;
280     $iheader =~ s=\\=/=g;
281     $header =~ s=\\=/=g;
282     return copyFile($iheader, $header) if($copy);
283
284     unless(-e $header) {
285         my $header_dir = dirname($header);
286         mkpath $header_dir, !$quiet;
287
288         #write it
289         my $iheader_out = fixPaths($iheader, $header_dir);
290         open HEADER, ">$header" || die "Could not open $header for writing!\n";
291         print HEADER "#include \"$iheader_out\"\n";
292         close HEADER;
293         if(defined($ts)) {
294             utime(time, $ts, $header) or die "$iheader, $header";
295         }
296         return 1;
297     }
298     return 0;
299 }
300
301 ######################################################################
302 # Syntax:  fixPaths(file, dir)
303 # Params:  file, string, filepath to be made relative to dir
304 #          dir, string, dirpath for point of origin
305 #
306 # Purpose: file is made relative (if possible) of dir.
307 # Returns: String with the above applied conversion.
308 ######################################################################
309 sub fixPaths {
310     my ($file, $dir) = @_;
311     $file =~ s=\\=/=g;
312     $dir =~ s=\\=/=g;
313
314     #setup
315     my $ret = $file;
316     $ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
317     my $file_dir = dirname($file);
318     if($file_dir eq ".") {
319         $file_dir = getcwd();
320         $file_dir =~ s=\\=/=g;
321     }
322     $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
323     if($dir eq ".") {
324         $dir = getcwd();
325         $dir =~ s=\\=/=g;
326     }
327     $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
328     return basename($file) if($file_dir eq $dir);
329
330     #guts
331     while ($file_dir =~ s,/[^/]+/\.\./,/,) {}
332     while ($dir =~ s,/[^/]+/\.\./,/,) {}
333     my $match_dir = 0;
334     for(my $i = 1; $i < length($file_dir); $i++) {
335         my $slash = index($file_dir, "/", $i);
336         last if($slash == -1);
337         my $tmp = substr($file_dir, 0, $slash);
338         last unless($dir =~ m,^\Q$tmp\E/,);
339         $match_dir = $tmp;
340         $i = $slash;
341     }
342     if($match_dir) {
343         my $after = substr($dir, length($match_dir));
344         my $count = ($after =~ tr,/,,);
345         my $dots = "";
346         for(my $i = 0; $i < $count; $i++) {
347             $dots .= "../";
348         }
349         $ret =~ s,^\Q$match_dir\E,$dots,;
350     }
351     $ret =~ s,/+,/,g;
352     return $ret;
353 }
354
355 ######################################################################
356 # Syntax:  fileContents(filename)
357 # Params:  filename, string, filename of file to return contents
358 #
359 # Purpose: Get the contents of a file.
360 # Returns: String with contents of the file, or empty string if file
361 #          doens't exist.
362 # Warning: Dies if it does exist but script cannot get read access.
363 ######################################################################
364 sub fileContents {
365     my ($filename) = @_;
366     my $filecontents = "";
367     if (-e $filename) {
368         open(I, "< $filename") || die "Could not open $filename for reading, read block?";
369         local $/;
370         binmode I;
371         $filecontents = <I>;
372         close I;
373     }
374     return $filecontents;
375 }
376
377 ######################################################################
378 # Syntax:  fileCompare(file1, file2)
379 # Params:  file1, string, filename of first file
380 #          file2, string, filename of second file
381 #
382 # Purpose: Determines if files are equal, and which one is newer.
383 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
384 #          is newer, 1 if file2 is newer.
385 ######################################################################
386 sub fileCompare {
387     my ($file1, $file2) = @_;
388     my $file1contents = fileContents($file1);
389     my $file2contents = fileContents($file2);
390     if (! -e $file1) { return 1; }
391     if (! -e $file2) { return -1; }
392     return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
393 }
394
395 ######################################################################
396 # Syntax:  copyFile(file, ifile)
397 # Params:  file, string, filename to create duplicate for
398 #          ifile, string, destination name of duplicate
399 #
400 # Purpose: Keeps files in sync so changes in the newer file will be
401 #          written to the other.
402 # Returns: 1 if files were synced, else 0.
403 # Warning: Dies if script cannot get write access.
404 ######################################################################
405 sub copyFile
406 {
407     my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
408     # Bi-directional synchronization
409     open( I, "< " . $file ) || die "Could not open $file for reading";
410     local $/;
411     binmode I;
412     $filecontents = <I>;
413     close I;
414     if ( open(I, "< " . $ifile) ) {
415         local $/;
416         binmode I;
417         $ifilecontents = <I>;
418         close I;
419         $copy = fileCompare($file, $ifile);
420         $knowdiff = 0,
421     } else {
422         $copy = -1;
423         $knowdiff = 1;
424     }
425
426     if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
427         if ( $copy > 0 ) {
428             my $file_dir = dirname($file);
429             mkpath $file_dir, !$quiet unless(-e $file_dir);
430             open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
431             local $/;
432             binmode O;
433             print O $ifilecontents;
434             close O;
435             utime time, (stat($ifile))[9], $file;
436             return 1;
437         } elsif ( $copy < 0 ) {
438             my $ifile_dir = dirname($ifile);
439             mkpath $ifile_dir, !$quiet unless(-e $ifile_dir);
440             open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
441             local $/;
442             binmode O;
443             print O $filecontents;
444             close O;
445             utime time, (stat($file))[9], $ifile;
446             return 1;
447         }
448     }
449     return 0;
450 }
451
452 ######################################################################
453 # Syntax:  symlinkFile(file, ifile)
454 # Params:  file, string, filename to create "symlink" for
455 #          ifile, string, destination name of symlink
456 #
457 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
458 #          support symlink).
459 # Returns: 1 on success, else 0.
460 ######################################################################
461 sub symlinkFile
462 {
463     my ($file,$ifile) = @_;
464
465     if ($isunix) {
466         print "symlink created for $file " unless $quiet;
467         if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
468             my $t = getcwd();
469             my $c = -1;
470             my $p = "../";
471             $t =~ s-^$quoted_basedir/--;
472             $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
473             $file =~ s-^$quoted_basedir/-$p-;
474             print " ($file)\n" unless $quiet;
475         }
476         print "\n" unless $quiet;
477         return symlink($file, $ifile);
478     }
479     return copyFile($file, $ifile);
480 }
481
482 ######################################################################
483 # Syntax:  findFiles(dir, match, descend)
484 # Params:  dir, string, directory to search for name
485 #          match, string, regular expression to match in dir
486 #          descend, integer, 0 = non-recursive search
487 #                            1 = recurse search into subdirectories
488 #
489 # Purpose: Finds files matching a regular expression.
490 # Returns: List of matching files.
491 #
492 # Examples:
493 #   findFiles("/usr","\.cpp$",1)  - finds .cpp files in /usr and below
494 #   findFiles("/tmp","^#",0)      - finds #* files in /tmp
495 ######################################################################
496 sub findFiles {
497     my ($dir,$match,$descend) = @_;
498     my ($file,$p,@files);
499     local(*D);
500     $dir =~ s=\\=/=g;
501     ($dir eq "") && ($dir = ".");
502     if ( opendir(D,$dir) ) {
503         if ( $dir eq "." ) {
504             $dir = "";
505         } else {
506             ($dir =~ /\/$/) || ($dir .= "/");
507         }
508         foreach $file ( sort readdir(D) ) {
509             next if ( $file  =~ /^\.\.?$/ );
510             $p = $file;
511             ($file =~ /$match/) && (push @files, $p);
512             if ( $descend && -d $p && ! -l $p ) {
513                 push @files, &findFiles($p,$match,$descend);
514             }
515         }
516         closedir(D);
517     }
518     return @files;
519 }
520
521 ######################################################################
522 # Syntax:  loadSyncProfile()
523 #
524 # Purpose: Locates the sync.profile.
525 # Returns: Hashmap of module name -> directory.
526 ######################################################################
527 sub loadSyncProfile {
528     my ($srcbase, $outbase) = @_;
529     print("srcbase = $$srcbase \n");
530     print("outbase = $$outbase \n");
531
532     my $syncprofile = "$$srcbase/sync.profile";
533     my $result;
534     unless ($result = do "$syncprofile") {
535         die "syncqt couldn't parse $syncprofile: $@" if $@;
536         die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
537     }
538     return $result;
539 }
540
541 sub locateSyncProfile
542 {
543     my ($directory) = @_;
544     my $syncprofile;
545     $directory = abs_path($directory);
546     while(!defined $syncprofile) {
547         local(*D);
548         if (opendir(D, $directory)) {
549             foreach my $file (sort readdir(D)) {
550                 next if ($file =~ /^\.\.?$/);
551                 $syncprofile = "$directory/$file" if ($file =~ /^sync\.profile$/);
552                 last if (defined $syncprofile);
553             }
554             closedir(D);
555         }
556         last if (defined $syncprofile || $directory eq "/" || $directory =~ /^?:[\/\\]$/);
557         $directory = dirname($directory);
558     }
559     return $syncprofile;
560 }
561
562 # check if this is an in-source build, and if so use that as the basedir too
563 $basedir = locateSyncProfile($out_basedir);
564 if ($basedir) {
565     $basedir = dirname($basedir) ;
566     $basedir =~ s=\\=/=g;
567     $quoted_basedir = "\Q$basedir";
568 }
569
570 # --------------------------------------------------------------------
571 # "main" function
572 # --------------------------------------------------------------------
573
574 while ( @ARGV ) {
575     my $var = 0;
576     my $val = 0;
577
578     #parse
579     my $arg = shift @ARGV;
580     if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
581         $var = "show_help";
582         $val = "yes";
583     } elsif($arg eq "-copy") {
584         $var = "copy";
585         $val = "yes";
586     } elsif($arg eq "-o" || $arg eq "-outdir") {
587         $var = "output";
588         $val = shift @ARGV;
589     } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
590             $arg eq "-relative" || $arg eq "-check-includes") {
591         $var = substr($arg, 1);
592         $val = "yes";
593     } elsif($arg =~ /^-no-(.*)$/) {
594         $var = $1;
595         $val = "no";
596         #these are for commandline compat
597     } elsif($arg eq "-inc") {
598         $var = "output";
599         $val = shift @ARGV;
600     } elsif($arg eq "-module") {
601         $var = "module";
602         $val = shift @ARGV;
603     } elsif($arg eq "-separate-module") {
604         $var = "separate-module";
605         $val = shift @ARGV;
606     } elsif($arg eq "-show") {
607         $var = "showonly";
608         $val = "yes";
609     } elsif($arg eq "-quiet") {
610         $var = "quiet";
611         $val = "yes";
612     } elsif($arg eq "-private") {
613         $var = "create_private_headers";
614         $val = "yes";
615     } elsif($arg eq "-qtdir") {
616         $var = "qtdir";
617         $val = shift @ARGV;
618     } elsif($arg eq "-base-dir") {
619         # skip, it's been dealt with at the top of the file
620         shift @ARGV;
621         next;
622     } elsif($arg eq "-no-module-fwd") {
623         $var = "no_module_fwd";
624         $val = "yes";
625     } elsif($arg eq "-no-module-version-header") {
626             $var = "no_module_version_header";
627             $val = "yes";
628     } elsif($arg =~/^-/) {
629         print "Unknown option: $arg\n\n" if(!$var);
630         showUsage();
631     } else {
632         $basedir = locateSyncProfile($arg);
633         die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
634         $basedir = dirname($basedir);
635         $basedir =~ s=\\=/=g;
636         $quoted_basedir = "\Q$basedir";
637         $var = "ignore";
638     }
639
640     #do something
641     if(!$var || $var eq "show_help") {
642         print "Unknown option: $arg\n\n" if(!$var);
643         showUsage();
644     } elsif ($var eq "copy") {
645         if($val eq "yes") {
646             $copy_headers++;
647         } elsif($showonly) {
648             $copy_headers--;
649         }
650     } elsif ($var eq "showonly") {
651         if($val eq "yes") {
652             $showonly++;
653         } elsif($showonly) {
654             $showonly--;
655         }
656     } elsif ($var eq "quiet") {
657         if($val eq "yes") {
658             $quiet++;
659         } elsif($quiet) {
660             $quiet--;
661         }
662     } elsif ($var eq "check-includes") {
663         if($val eq "yes") {
664             $check_includes++;
665         } elsif($check_includes) {
666             $check_includes--;
667         }
668     } elsif ($var eq "remove-stale") {
669         if($val eq "yes") {
670             $remove_stale++;
671         } elsif($remove_stale) {
672             $remove_stale--;
673         }
674     } elsif ($var eq "windows") {
675         if($val eq "yes") {
676             $force_win++;
677         } elsif($force_win) {
678             $force_win--;
679         }
680     } elsif ($var eq "relative") {
681         if($val eq "yes") {
682             $force_relative++;
683         } elsif($force_relative) {
684             $force_relative--;
685         }
686     } elsif ($var eq "module") {
687         print "module :$val:\n" unless $quiet;
688         die "No such module: $val" unless(defined $modules{$val});
689         push @modules_to_sync, $val;
690     } elsif ($var eq "separate-module") {
691         my ($module, $prodir, $headerdir) = split(/:/, $val);
692         $modules{$module} = $prodir;
693         push @modules_to_sync, $module;
694         $moduleheaders{$module} = $headerdir;
695         $create_uic_class_map = 0;
696     } elsif ($var eq "qtdir") {
697         if($val) {
698             $qtbasedir = $val;
699             $qtbasedir =~ s=\\=/=g;
700         } else {
701             die "The -qtdir option requires an argument";
702         }
703     } elsif ($var eq "no_module_fwd") {
704         $no_module_fwd = 1;
705     } elsif ($var eq "no_module_version_header") {
706             $no_module_version_header = 1;
707     } elsif ($var eq "output") {
708         my $outdir = $val;
709         if(checkRelative($outdir)) {
710             $out_basedir = getcwd();
711             chomp $out_basedir;
712             $out_basedir .= "/" . $outdir;
713         } else {
714             $out_basedir = $outdir;
715         }
716         # \ -> /
717         $out_basedir =~ s=\\=/=g;
718     }
719 }
720
721 # if the $qtbasedir neither has 'qtbase' somewhere in its path, nor a
722 # '.qmake.cache' file in its directory, we assume it's not a valid path
723 # (remember that a yet-to-be-built qtbase doesn't have this file either,
724 # thus the 'qtbase' path check!)
725 die "Cannot automatically detect/use provided path to QtBase's build directory!\n" .
726     "QTDIR detected/provided: " . (defined $qtbasedir ? $qtbasedir : "-none-") . "\n" .
727     "Please -qtdir option to provide the correct path.\nsyncqt failed"
728         if (!$qtbasedir || !-d "$qtbasedir/mkspecs");
729
730 # if we have no $basedir we cannot be sure which sources you want, so die
731 die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
732
733 my @ignore_headers = ();
734 my $class_lib_map_contents = "";
735 our @ignore_for_master_contents = ();
736 our @ignore_for_include_check = ();
737 our @ignore_for_qt_begin_header_check = ();
738 our @ignore_for_qt_begin_namespace_check = ();
739 our @ignore_for_qt_module_check = ();
740 my %colliding_headers = ();
741 my %inject_headers = ( "$basedir/src/corelib/global" => ( "qconfig.h" ) ); # all from build dir
742
743 # load the module's sync.profile here, before we can
744 loadSyncProfile(\$basedir, \$out_basedir);
745
746 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
747
748 $isunix = checkUnix; #cache checkUnix
749
750 # create path
751 mkpath "$out_basedir/include", !$quiet;
752 mkpath "$out_basedir/include/Qt", !$quiet;
753
754
755 foreach my $lib (@modules_to_sync) {
756     #iteration info
757     my $dir = $modules{$lib};
758     my $module_version = "";
759     my $module_major_version = "";
760     my $module_minor_version = "";
761     my $module_patch_version = "";
762
763     if (-e "$modulepris{$lib}") {
764         my $content = fileContents($modulepris{$lib});
765         my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
766         if(@version_rows) {
767             # We only pick the first one, since each module need a separate .pri file
768             $module_version = $version_rows[0];
769             chomp $module_version;
770             $module_version =~ s/^\s*QT\..*\.VERSION\s*=\s*([^#]+).*$/$1/;
771             $module_version =~ s/\s+$//;
772             my @versions = split(/\./, $module_version);
773             $module_major_version = $versions[0];
774             chomp $module_major_version;
775             $module_minor_version = $versions[1];
776             chomp $module_minor_version;
777             $module_patch_version = $versions[2];
778             chomp $module_patch_version;
779         }
780     }
781     print "WARNING: Module $lib\'s pri missing QT.<module>.VERSION variable! Private headers not versioned!\n" if (!$module_version);
782
783     my $pathtoheaders = "";
784     $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
785
786     #information used after the syncing
787     my $pri_install_classes = "";
788     my $pri_install_files = "";
789     my $pri_install_pfiles = "";
790
791     my $libcapitals = $lib;
792     $libcapitals =~ y/a-z/A-Z/;
793     my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
794
795     #get dependencies
796     if(-e "$dir/" . basename($dir) . ".pro") {
797         if(open(F, "<$dir/" . basename($dir) . ".pro")) {
798             while(my $line = <F>) {
799                 chomp $line;
800                 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
801                     foreach(split(/ /, $1)) {
802                         $_ =~ s/-private$//;
803                         my $content = $mastercontent{$_};
804                         $master_contents .= $content if ($content);
805                     }
806                 }
807             }
808             close(F);
809         }
810     }
811
812     #remove the old files
813     if($remove_stale) {
814         my @subdirs = ("$out_basedir/include/$lib");
815         foreach my $subdir (@subdirs) {
816             if (opendir DIR, $subdir) {
817                 while(my $t = readdir(DIR)) {
818                     my $file = "$subdir/$t";
819                     if(-d $file) {
820                         push @subdirs, $file unless($t eq "." || $t eq "..");
821                     } else {
822                         my @files = ($file);
823                         #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
824                         foreach my $file (@files) {
825                            my $remove_file = 0;
826                            if(open(F, "<$file")) {
827                                 while(my $line = <F>) {
828                                     chomp $line;
829                                     if($line =~ /^\#include \"([^\"]*)\"$/) {
830                                         my $include = $1;
831                                         $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
832                                         $remove_file = 1 unless(-e $include);
833                                     } else {
834                                         $remove_file = 0;
835                                         last;
836                                     }
837                                 }
838                                 close(F);
839                                 unlink $file if($remove_file);
840                             }
841                         }
842                     }
843                 }
844                 closedir DIR;
845             }
846
847         }
848     }
849
850     #create the new ones
851     foreach my $current_dir (split(/;/, $dir)) {
852         my $headers_dir = $current_dir;
853         $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
854         #calc subdirs
855         my @subdirs = ($headers_dir);
856         foreach my $subdir (@subdirs) {
857             opendir DIR, $subdir or next;
858             while(my $t = readdir(DIR)) {
859                 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
860                                                !($t eq "..") && !($t eq ".obj") &&
861                                                !($t eq ".moc") && !($t eq ".rcc") &&
862                                                !($t eq ".uic") && !($t eq "build"));
863             }
864             closedir DIR;
865         }
866
867         #calc files and "copy" them
868         foreach my $subdir (@subdirs) {
869             my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
870             if (defined $inject_headers{$subdir}) {
871                 foreach my $if ($inject_headers{$subdir}) {
872                     @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
873                     push @headers, "*".$if;
874                 }
875             }
876             foreach my $header (@headers) {
877                 my $shadow = ($header =~ s/^\*//);
878                 $header = 0 if($header =~ /^ui_.*.h/);
879                 foreach (@ignore_headers) {
880                     $header = 0 if($header eq $_);
881                 }
882                 if($header) {
883                     my $header_copies = 0;
884                     #figure out if it is a public header
885                     my $public_header = $header;
886                     if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
887                         $public_header = 0;
888                     } else {
889                         foreach (@ignore_for_master_contents) {
890                             $public_header = 0 if($header eq $_);
891                         }
892                     }
893
894                     my $iheader = $subdir . "/" . $header;
895                     $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
896                     my @classes = $public_header ? classNames($iheader) : ();
897                     if($showonly) {
898                         print "$header [$lib]\n";
899                         foreach(@classes) {
900                             print "SYMBOL: $_\n";
901                         }
902                     } else {
903                         my $ts = (stat($iheader))[9];
904                         #find out all the places it goes..
905                         my @headers;
906                         if ($public_header) {
907                             @headers = ( "$out_basedir/include/$lib/$header" );
908
909                             # write forwarding headers to include/Qt
910                             if ($lib ne "phonon" && $subdir =~ /^$quoted_basedir\/src/) {
911                                 my $file_name = "$out_basedir/include/Qt/$header";
912                                 my $file_op = '>';
913                                 my $header_content = '';
914                                 if (exists $colliding_headers{$file_name}) {
915                                     $file_op = '>>';
916                                 } else {
917                                     $colliding_headers{$file_name} = 1;
918                                     my $warning_msg = 'Inclusion of header files from include/Qt is deprecated.';
919                                     $header_content = "#ifndef QT_NO_QT_INCLUDE_WARN\n" .
920                                                       "    #if defined(__GNUC__)\n" .
921                                                       "        #warning \"$warning_msg\"\n" .
922                                                       "    #elif defined(_MSC_VER)\n" .
923                                                       "        #pragma message(\"WARNING: $warning_msg\")\n" .
924                                                       "    #endif\n".
925                                                       "#endif\n\n";
926                                 }
927                                 $header_content .= '#include "' . "../$lib/$header" . "\"\n";
928                                 open HEADERFILE, $file_op, $file_name or die "unable to open '$file_name' : $!\n";
929                                 print HEADERFILE $header_content;
930                                 close HEADERFILE;
931                             }
932
933                             foreach my $full_class (@classes) {
934                                 my $header_base = basename($header);
935                                 # Strip namespaces:
936                                 my $class = $full_class;
937                                 $class =~ s/^.*:://;
938 #                               if ($class =~ m/::/) {
939 #                                  class =~ s,::,/,g;
940 #                               }
941                                 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
942                                 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
943
944                                 # KDE-Compat headers for Phonon
945                                 if ($lib eq "phonon") {
946                                     $header_copies++ if (syncHeader("$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
947                                 }
948                             }
949                         } elsif ($create_private_headers) {
950                             if ($module_version) {
951                                 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
952                             } else {
953                                 @headers = ( "$out_basedir/include/$lib/private/$header" );
954                             }
955                         }
956                         foreach(@headers) { #sync them
957                             $header_copies++ if(syncHeader($_, $iheader, $copy_headers && !$shadow, $ts));
958                         }
959
960                         if($public_header) {
961                             #put it into the master file
962                             $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
963
964                             #deal with the install directives
965                             if($public_header) {
966                                 my $pri_install_iheader = fixPaths($iheader, $current_dir);
967                                 foreach my $class (@classes) {
968                                     # Strip namespaces:
969                                     $class =~ s/^.*:://;
970 #                                   if ($class =~ m/::/) {
971 #                                       $class =~ s,::,/,g;
972 #                                   }
973                                     my $class_header = fixPaths("$out_basedir/include/$lib/$class",
974                                                                 $current_dir) . " ";
975                                     $pri_install_classes .= $class_header
976                                                                 unless($pri_install_classes =~ $class_header);
977                                 }
978                                 $pri_install_files.= "$pri_install_iheader ";;
979                             }
980                         }
981                         else {
982                             my $pri_install_iheader = fixPaths($iheader, $current_dir);
983                             $pri_install_pfiles.= "$pri_install_iheader ";;
984                         }
985                     }
986                     print "header created for $iheader ($header_copies)\n" if($header_copies > 0 && !$quiet);
987                 }
988             }
989         }
990     }
991
992     # close the master include:
993     $master_contents .= "#endif\n";
994
995     unless($showonly) {
996         my @master_includes;
997         push @master_includes, "$out_basedir/include/$lib/$lib";
998         push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
999         foreach my $master_include (@master_includes) {
1000             #generate the "master" include file
1001             my @tmp = split(/;/,$modules{$lib});
1002             $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
1003             if($master_include && -e $master_include) {
1004                 open MASTERINCLUDE, "<$master_include";
1005                 local $/;
1006                 binmode MASTERINCLUDE;
1007                 my $oldmaster = <MASTERINCLUDE>;
1008                 close MASTERINCLUDE;
1009                 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1010                 $master_include = 0 if($oldmaster eq $master_contents);
1011             }
1012             if($master_include && $master_contents) {
1013                 my $master_dir = dirname($master_include);
1014                 mkpath $master_dir, !$quiet;
1015                 print "header (master) created for $lib\n" unless $quiet;
1016                 open MASTERINCLUDE, ">$master_include";
1017                 print MASTERINCLUDE $master_contents;
1018                 close MASTERINCLUDE;
1019             }
1020         }
1021
1022         #handle the headers.pri for each module
1023         my $headers_pri_contents = "";
1024         $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1025         $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1026         $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1027         my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1028         if(-e $headers_pri_file) {
1029             open HEADERS_PRI_FILE, "<$headers_pri_file";
1030             local $/;
1031             binmode HEADERS_PRI_FILE;
1032             my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1033             close HEADERS_PRI_FILE;
1034             $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1035             $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1036         }
1037         if($headers_pri_file && $master_contents) {
1038             my $headers_pri_dir = dirname($headers_pri_file);
1039             mkpath $headers_pri_dir, !$quiet;
1040             print "headers.pri file created for $lib\n" unless $quiet;
1041             open HEADERS_PRI_FILE, ">$headers_pri_file";
1042             print HEADERS_PRI_FILE $headers_pri_contents;
1043             close HEADERS_PRI_FILE;
1044         }
1045
1046         # create forwarding module pri in qtbase/mkspecs/modules
1047         unless ($no_module_fwd) {
1048             my $modulepri = $modulepris{$lib};
1049             if (-e $modulepri) {
1050                 my $modulepriname = basename($modulepri);
1051                 my $moduleprifwd = "$qtbasedir/mkspecs/modules/$modulepriname";
1052                 open MODULE_PRI_FILE, ">$moduleprifwd";
1053                 print MODULE_PRI_FILE "QT_MODULE_BASE = $basedir\n";
1054                 print MODULE_PRI_FILE "QT_MODULE_BIN_BASE = $qtbasedir/bin\n";
1055                 print MODULE_PRI_FILE "QT_MODULE_INCLUDE_BASE = $out_basedir/include\n";
1056                 print MODULE_PRI_FILE "QT_MODULE_IMPORT_BASE = $qtbasedir/imports\n";
1057                 print MODULE_PRI_FILE "QT_MODULE_LIB_BASE = $qtbasedir/lib\n";
1058                 print MODULE_PRI_FILE "QT_MODULE_PLUGIN_BASE = $qtbasedir/plugins\n";
1059                 print MODULE_PRI_FILE "include($modulepri)\n";
1060                 close MODULE_PRI_FILE;
1061                 utime(time, (stat($modulepri))[9], $moduleprifwd);
1062             } elsif ($modulepri) {
1063                 print "WARNING: Module $lib\'s pri file '$modulepri' not found.\nSkipped creating forwarding pri for $lib.\n";
1064             }
1065         }
1066
1067         # create the version header files for each module
1068         unless ($no_module_version_header) {
1069             my $modulepri = $modulepris{$lib};
1070             if (-e $modulepri) {
1071                 my $modulepriname = basename($modulepri);
1072                 my $moduleversionheader = "$modules{$lib}/" . lc($lib) . "version.h";
1073                 my $modulehexstring = sprintf("0x%02X%02X%02X", int($module_major_version), int($module_minor_version), int($module_patch_version));
1074                 open MODULE_VERSION_HEADER_FILE, ">$moduleversionheader";
1075                 print MODULE_VERSION_HEADER_FILE "/* This file was generated by syncqt with the info from sync.profile. */\n";
1076                 print MODULE_VERSION_HEADER_FILE "#ifndef QT_". uc($lib) . "_VERSION_H\n";
1077                 print MODULE_VERSION_HEADER_FILE "#define QT_". uc($lib) . "_VERSION_H\n";
1078                 print MODULE_VERSION_HEADER_FILE "\n";
1079                 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION_STR \"" . $module_version . "\"\n";
1080                 print MODULE_VERSION_HEADER_FILE "\n";
1081                 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION $modulehexstring\n", ;
1082                 print MODULE_VERSION_HEADER_FILE "\n";
1083                 print MODULE_VERSION_HEADER_FILE "#endif // QT_". uc($lib) . "_VERSION_H\n";
1084             } elsif ($modulepri) {
1085                 print "WARNING: Module $lib\'s pri file '$modulepri' not found.\nSkipped creating module version header for $lib.\n";
1086             }
1087         }
1088     }
1089 }
1090 unless($showonly || !$create_uic_class_map) {
1091     my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1092     if(-e $class_lib_map) {
1093         open CLASS_LIB_MAP, "<$class_lib_map";
1094         local $/;
1095         binmode CLASS_LIB_MAP;
1096         my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1097         close CLASS_LIB_MAP;
1098         $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1099         $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1100     }
1101     if($class_lib_map) {
1102         my $class_lib_map_dir = dirname($class_lib_map);
1103         mkpath $class_lib_map_dir, !$quiet;
1104         open CLASS_LIB_MAP, ">$class_lib_map";
1105         print CLASS_LIB_MAP $class_lib_map_contents;
1106         close CLASS_LIB_MAP;
1107     }
1108 }
1109
1110 if($check_includes) {
1111     for my $lib (keys(%modules)) {
1112             #calc subdirs
1113             my @subdirs = ($modules{$lib});
1114             foreach my $subdir (@subdirs) {
1115                 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
1116                 while(my $t = readdir(DIR)) {
1117                     push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
1118                                                    !($t eq "..") && !($t eq ".obj") &&
1119                                                    !($t eq ".moc") && !($t eq ".rcc") &&
1120                                                    !($t eq ".uic") && !($t eq "build"));
1121                 }
1122                 closedir DIR;
1123             }
1124
1125             foreach my $subdir (@subdirs) {
1126                 my $header_skip_qt_module_test = 0;
1127                 foreach(@ignore_for_qt_module_check) {
1128                     foreach (split(/;/, $_)) {
1129                         $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1130                     }
1131                 }
1132                 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1133                 foreach my $header (@headers) {
1134                     my $header_skip_qt_begin_header_test = 0;
1135                     my $header_skip_qt_begin_namespace_test = 0;
1136                     $header = 0 if($header =~ /^ui_.*.h/);
1137                     foreach (@ignore_headers) {
1138                         $header = 0 if($header eq $_);
1139                     }
1140                     if($header) {
1141                         my $public_header = $header;
1142                         if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1143                             $public_header = 0;
1144                         } else {
1145                             foreach (@ignore_for_master_contents) {
1146                                 $public_header = 0 if($header eq $_);
1147                             }
1148                             if($public_header) {
1149                                 foreach (@ignore_for_include_check) {
1150                                     $public_header = 0 if($header eq $_);
1151                                 }
1152                                 foreach(@ignore_for_qt_begin_header_check) {
1153                                     $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1154                                 }
1155                                 foreach(@ignore_for_qt_begin_namespace_check) {
1156                                     $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1157                                 }
1158                             }
1159                         }
1160
1161                         my $iheader = $subdir . "/" . $header;
1162                         if($public_header) {
1163                             if(open(F, "<$iheader")) {
1164                                 my $qt_module_found = 0;
1165                                 my $qt_begin_header_found = 0;
1166                                 my $qt_end_header_found = 0;
1167                                 my $qt_begin_namespace_found = 0;
1168                                 my $qt_end_namespace_found = 0;
1169                                 my $line;
1170                                 while($line = <F>) {
1171                                     chomp $line;
1172                                     my $output_line = 1;
1173                                     if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1174                                         last;
1175                                     } elsif($line =~ /^ *\# *include/) {
1176                                         my $include = $line;
1177                                         if($line =~ /<.*>/) {
1178                                             $include =~ s,.*<(.*)>.*,$1,;
1179                                         } elsif($line =~ /".*"/) {
1180                                             $include =~ s,.*"(.*)".*,$1,;
1181                                         } else {
1182                                             $include = 0;
1183                                         }
1184                                         if($include) {
1185                                             for my $trylib (keys(%modules)) {
1186                                                 if(-e "$out_basedir/include/$trylib/$include") {
1187                                                     print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
1188                                                 }
1189                                             }
1190                                         }
1191                                     } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1192                                         $qt_begin_header_found = 1;
1193                                     } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1194                                         $qt_end_header_found = 1;
1195                                     } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1196                                         $qt_begin_namespace_found = 1;
1197                                     } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1198                                         $qt_end_namespace_found = 1;
1199                                     } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1200                                         $qt_module_found = 1;
1201                                     }
1202                                 }
1203                                 if ($header_skip_qt_begin_header_test == 0) {
1204                                     if ($qt_begin_header_found == 0) {
1205                                         print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1206                                     }
1207
1208                                     if ($qt_begin_header_found && $qt_end_header_found == 0) {
1209                                         print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1210                                     }
1211                                 }
1212
1213                                 if ($header_skip_qt_begin_namespace_test == 0) {
1214                                     if ($qt_begin_namespace_found == 0) {
1215                                         print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1216                                     }
1217
1218                                     if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1219                                         print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1220                                     }
1221                                 }
1222
1223                                 if ($header_skip_qt_module_test == 0) {
1224                                     if ($qt_module_found == 0) {
1225                                         print "WARNING: $iheader does not include QT_MODULE\n";
1226                                     }
1227                                 }
1228                                 close(F);
1229                             }
1230                         }
1231                     }
1232                 }
1233             }
1234     }
1235 }
1236
1237 exit 0;