2 ######################################################################
4 # Synchronizes Qt header files - internal development tool.
6 # Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 # Contact: Nokia Corporation (qt-info@nokia.com)
9 ######################################################################
11 # use packages -------------------------------------------------------
19 # set output basedir to be where ever syncqt is run from
20 our $out_basedir = getcwd();
21 $out_basedir =~ s=\\=/=g;
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);
34 # will be defined based on the modules sync.profile
35 our (%modules, %moduleheaders, %classnames, %mastercontent, %modulepris);
37 # global variables (modified by options)
44 my $force_relative = 0;
45 my $check_includes = 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;
52 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
55 # functions ----------------------------------------------------------
57 ######################################################################
61 # Purpose: Show the usage of the script.
63 ######################################################################
67 print " <module directory> Specifies which module to sync header files for (required for shadow builds!)\n\n";
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";
87 ######################################################################
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 ######################################################################
97 if ( $force_win != 0) {
99 } elsif ( -f "/bin/uname" ) {
101 (-f "\\bin\\uname") && ($r = 0);
102 } elsif ( -f "/usr/bin/uname" ) {
104 (-f "\\usr\\bin\\uname") && ($r = 0);
107 $_ = $Config{'osname'};
108 $r = 0 if( /(ms)|(cyg)win/i );
115 return 0 if($dir =~ /^\//);
116 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
120 ######################################################################
121 # Syntax: shouldMasterInclude(iheader)
122 # Params: iheader, string, filename to verify inclusion
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 {
130 return 0 if(basename($iheader) =~ /_/);
131 return 0 if(basename($iheader) =~ /qconfig/);
132 if(open(F, "<$iheader")) {
135 return 0 if(/^\#pragma qt_no_master_include$/);
144 ######################################################################
145 # Syntax: classNames(iheader)
146 # Params: iheader, string, filename to parse for classname "symlinks"
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 ######################################################################
156 my $classname = $classnames{basename($iheader)};
157 push @ret, $classname if ($classname);
160 if(open(F, "<$iheader")) {
164 chop $line if ($line =~ /\r$/);
169 last unless($line =~ /\\$/);
172 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
173 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
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;
188 my $last_definition = 0;
190 for(my $i = 0; $i < length($parsable); $i++) {
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);
197 $last_definition = $i+2;
202 } elsif($character eq "{") {
204 my $block_start = $i + 1;
205 BLOCK: for($i+=1; $i < length($parsable); $i++) {
206 my $ignore = substr($parsable, $i, 1);
209 } elsif($ignore eq "}") {
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;
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
231 $last_definition = $i + 1;
234 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
235 && substr($parsable, $i+1, 1) eq "{") {
236 push @namespaces, $1;
238 # Eat the opening { so that the condensing loop above doesn't see it
240 $last_definition = $i + 1;
244 $definition =~ s=[\n\r]==g;
246 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
248 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
250 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
252 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
253 push @symbols, "Q" . $1 . "Iterator";
254 push @symbols, "QMutable" . $1 . "Iterator";
257 foreach my $symbol (@symbols) {
258 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
260 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
261 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
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
275 # Purpose: Syncronizes header to iheader
276 # Returns: 1 if successful, else 0.
277 ######################################################################
279 my ($header, $iheader, $copy, $ts) = @_;
280 $iheader =~ s=\\=/=g;
282 return copyFile($iheader, $header) if($copy);
285 my $header_dir = dirname($header);
286 mkpath $header_dir, !$quiet;
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";
294 utime(time, $ts, $header) or die "$iheader, $header";
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
306 # Purpose: file is made relative (if possible) of dir.
307 # Returns: String with the above applied conversion.
308 ######################################################################
310 my ($file, $dir) = @_;
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;
322 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
327 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
328 return basename($file) if($file_dir eq $dir);
331 while ($file_dir =~ s,/[^/]+/\.\./,/,) {}
332 while ($dir =~ s,/[^/]+/\.\./,/,) {}
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/,);
343 my $after = substr($dir, length($match_dir));
344 my $count = ($after =~ tr,/,,);
346 for(my $i = 0; $i < $count; $i++) {
349 $ret =~ s,^\Q$match_dir\E,$dots,;
355 ######################################################################
356 # Syntax: fileContents(filename)
357 # Params: filename, string, filename of file to return contents
359 # Purpose: Get the contents of a file.
360 # Returns: String with contents of the file, or empty string if file
362 # Warning: Dies if it does exist but script cannot get read access.
363 ######################################################################
366 my $filecontents = "";
368 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
374 return $filecontents;
377 ######################################################################
378 # Syntax: fileCompare(file1, file2)
379 # Params: file1, string, filename of first file
380 # file2, string, filename of second file
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 ######################################################################
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;
395 ######################################################################
396 # Syntax: copyFile(file, ifile)
397 # Params: file, string, filename to create duplicate for
398 # ifile, string, destination name of duplicate
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 ######################################################################
407 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
408 # Bi-directional synchronization
409 open( I, "< " . $file ) || die "Could not open $file for reading";
414 if ( open(I, "< " . $ifile) ) {
417 $ifilecontents = <I>;
419 $copy = fileCompare($file, $ifile);
426 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
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?)";
433 print O $ifilecontents;
435 utime time, (stat($ifile))[9], $file;
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?)";
443 print O $filecontents;
445 utime time, (stat($file))[9], $ifile;
452 ######################################################################
453 # Syntax: symlinkFile(file, ifile)
454 # Params: file, string, filename to create "symlink" for
455 # ifile, string, destination name of symlink
457 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
459 # Returns: 1 on success, else 0.
460 ######################################################################
463 my ($file,$ifile) = @_;
466 print "symlink created for $file " unless $quiet;
467 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
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;
476 print "\n" unless $quiet;
477 return symlink($file, $ifile);
479 return copyFile($file, $ifile);
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
489 # Purpose: Finds files matching a regular expression.
490 # Returns: List of matching files.
493 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
494 # findFiles("/tmp","^#",0) - finds #* files in /tmp
495 ######################################################################
497 my ($dir,$match,$descend) = @_;
498 my ($file,$p,@files);
501 ($dir eq "") && ($dir = ".");
502 if ( opendir(D,$dir) ) {
506 ($dir =~ /\/$/) || ($dir .= "/");
508 foreach $file ( sort readdir(D) ) {
509 next if ( $file =~ /^\.\.?$/ );
511 ($file =~ /$match/) && (push @files, $p);
512 if ( $descend && -d $p && ! -l $p ) {
513 push @files, &findFiles($p,$match,$descend);
521 ######################################################################
522 # Syntax: loadSyncProfile()
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");
532 my $syncprofile = "$$srcbase/sync.profile";
534 unless ($result = do "$syncprofile") {
535 die "syncqt couldn't parse $syncprofile: $@" if $@;
536 die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
541 sub locateSyncProfile
543 my ($directory) = @_;
545 $directory = abs_path($directory);
546 while(!defined $syncprofile) {
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);
556 last if (defined $syncprofile || $directory eq "/" || $directory =~ /^?:[\/\\]$/);
557 $directory = dirname($directory);
562 # check if this is an in-source build, and if so use that as the basedir too
563 $basedir = locateSyncProfile($out_basedir);
565 $basedir = dirname($basedir) ;
566 $basedir =~ s=\\=/=g;
567 $quoted_basedir = "\Q$basedir";
570 # --------------------------------------------------------------------
572 # --------------------------------------------------------------------
579 my $arg = shift @ARGV;
580 if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
583 } elsif($arg eq "-copy") {
586 } elsif($arg eq "-o" || $arg eq "-outdir") {
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);
593 } elsif($arg =~ /^-no-(.*)$/) {
596 #these are for commandline compat
597 } elsif($arg eq "-inc") {
600 } elsif($arg eq "-module") {
603 } elsif($arg eq "-separate-module") {
604 $var = "separate-module";
606 } elsif($arg eq "-show") {
609 } elsif($arg eq "-quiet") {
612 } elsif($arg eq "-private") {
613 $var = "create_private_headers";
615 } elsif($arg eq "-qtdir") {
618 } elsif($arg eq "-base-dir") {
619 # skip, it's been dealt with at the top of the file
622 } elsif($arg eq "-no-module-fwd") {
623 $var = "no_module_fwd";
625 } elsif($arg eq "-no-module-version-header") {
626 $var = "no_module_version_header";
628 } elsif($arg =~/^-/) {
629 print "Unknown option: $arg\n\n" if(!$var);
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";
641 if(!$var || $var eq "show_help") {
642 print "Unknown option: $arg\n\n" if(!$var);
644 } elsif ($var eq "copy") {
650 } elsif ($var eq "showonly") {
656 } elsif ($var eq "quiet") {
662 } elsif ($var eq "check-includes") {
665 } elsif($check_includes) {
668 } elsif ($var eq "remove-stale") {
671 } elsif($remove_stale) {
674 } elsif ($var eq "windows") {
677 } elsif($force_win) {
680 } elsif ($var eq "relative") {
683 } elsif($force_relative) {
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") {
699 $qtbasedir =~ s=\\=/=g;
701 die "The -qtdir option requires an argument";
703 } elsif ($var eq "no_module_fwd") {
705 } elsif ($var eq "no_module_version_header") {
706 $no_module_version_header = 1;
707 } elsif ($var eq "output") {
709 if(checkRelative($outdir)) {
710 $out_basedir = getcwd();
712 $out_basedir .= "/" . $outdir;
714 $out_basedir = $outdir;
717 $out_basedir =~ s=\\=/=g;
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");
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);
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
743 # load the module's sync.profile here, before we can
744 loadSyncProfile(\$basedir, \$out_basedir);
746 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
748 $isunix = checkUnix; #cache checkUnix
751 mkpath "$out_basedir/include", !$quiet;
752 mkpath "$out_basedir/include/Qt", !$quiet;
755 foreach my $lib (@modules_to_sync) {
757 my $dir = $modules{$lib};
758 my $module_version = "";
759 my $module_major_version = "";
760 my $module_minor_version = "";
761 my $module_patch_version = "";
763 if (-e "$modulepris{$lib}") {
764 my $content = fileContents($modulepris{$lib});
765 my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
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;
781 print "WARNING: Module $lib\'s pri missing QT.<module>.VERSION variable! Private headers not versioned!\n" if (!$module_version);
783 my $pathtoheaders = "";
784 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
786 #information used after the syncing
787 my $pri_install_classes = "";
788 my $pri_install_files = "";
789 my $pri_install_pfiles = "";
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";
796 if(-e "$dir/" . basename($dir) . ".pro") {
797 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
798 while(my $line = <F>) {
800 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
801 foreach(split(/ /, $1)) {
803 my $content = $mastercontent{$_};
804 $master_contents .= $content if ($content);
812 #remove the old files
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";
820 push @subdirs, $file unless($t eq "." || $t eq "..");
823 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
824 foreach my $file (@files) {
826 if(open(F, "<$file")) {
827 while(my $line = <F>) {
829 if($line =~ /^\#include \"([^\"]*)\"$/) {
831 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
832 $remove_file = 1 unless(-e $include);
839 unlink $file if($remove_file);
850 # create the version header files for each module
851 unless ($no_module_version_header) {
852 my $modulepri = $modulepris{$lib};
854 my $modulepriname = basename($modulepri);
855 my $moduleversionheader = "$modules{$lib}/" . lc($lib) . "version.h";
856 my $modulehexstring = sprintf("0x%02X%02X%02X", int($module_major_version), int($module_minor_version), int($module_patch_version));
857 open MODULE_VERSION_HEADER_FILE, ">$moduleversionheader";
858 print MODULE_VERSION_HEADER_FILE "/* This file was generated by syncqt with the info from sync.profile. */\n";
859 print MODULE_VERSION_HEADER_FILE "#ifndef QT_". uc($lib) . "_VERSION_H\n";
860 print MODULE_VERSION_HEADER_FILE "#define QT_". uc($lib) . "_VERSION_H\n";
861 print MODULE_VERSION_HEADER_FILE "\n";
862 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION_STR \"" . $module_version . "\"\n";
863 print MODULE_VERSION_HEADER_FILE "\n";
864 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION $modulehexstring\n", ;
865 print MODULE_VERSION_HEADER_FILE "\n";
866 print MODULE_VERSION_HEADER_FILE "#endif // QT_". uc($lib) . "_VERSION_H\n";
867 } elsif ($modulepri) {
868 print "WARNING: Module $lib\'s pri file '$modulepri' not found.\nSkipped creating module version header for $lib.\n";
873 foreach my $current_dir (split(/;/, $dir)) {
874 my $headers_dir = $current_dir;
875 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
877 my @subdirs = ($headers_dir);
878 foreach my $subdir (@subdirs) {
879 opendir DIR, $subdir or next;
880 while(my $t = readdir(DIR)) {
881 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
882 !($t eq "..") && !($t eq ".obj") &&
883 !($t eq ".moc") && !($t eq ".rcc") &&
884 !($t eq ".uic") && !($t eq "build"));
889 #calc files and "copy" them
890 foreach my $subdir (@subdirs) {
891 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
892 if (defined $inject_headers{$subdir}) {
893 foreach my $if ($inject_headers{$subdir}) {
894 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
895 push @headers, "*".$if;
898 foreach my $header (@headers) {
899 my $shadow = ($header =~ s/^\*//);
900 $header = 0 if($header =~ /^ui_.*.h/);
901 foreach (@ignore_headers) {
902 $header = 0 if($header eq $_);
905 my $header_copies = 0;
906 #figure out if it is a public header
907 my $public_header = $header;
908 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
911 foreach (@ignore_for_master_contents) {
912 $public_header = 0 if($header eq $_);
916 my $iheader = $subdir . "/" . $header;
917 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
918 my @classes = $public_header ? classNames($iheader) : ();
920 print "$header [$lib]\n";
922 print "SYMBOL: $_\n";
925 my $ts = (stat($iheader))[9];
926 #find out all the places it goes..
928 if ($public_header) {
929 @headers = ( "$out_basedir/include/$lib/$header" );
931 # write forwarding headers to include/Qt
932 if ($lib ne "phonon" && $subdir =~ /^$quoted_basedir\/src/) {
933 my $file_name = "$out_basedir/include/Qt/$header";
935 my $header_content = '';
936 if (exists $colliding_headers{$file_name}) {
939 $colliding_headers{$file_name} = 1;
940 my $warning_msg = 'Inclusion of header files from include/Qt is deprecated.';
941 $header_content = "#ifndef QT_NO_QT_INCLUDE_WARN\n" .
942 " #if defined(__GNUC__)\n" .
943 " #warning \"$warning_msg\"\n" .
944 " #elif defined(_MSC_VER)\n" .
945 " #pragma message(\"WARNING: $warning_msg\")\n" .
949 $header_content .= '#include "' . "../$lib/$header" . "\"\n";
950 open HEADERFILE, $file_op, $file_name or die "unable to open '$file_name' : $!\n";
951 print HEADERFILE $header_content;
955 foreach my $full_class (@classes) {
956 my $header_base = basename($header);
958 my $class = $full_class;
960 # if ($class =~ m/::/) {
963 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
964 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
966 # KDE-Compat headers for Phonon
967 if ($lib eq "phonon") {
968 $header_copies++ if (syncHeader("$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
971 } elsif ($create_private_headers) {
972 if ($module_version) {
973 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
975 @headers = ( "$out_basedir/include/$lib/private/$header" );
978 foreach(@headers) { #sync them
979 $header_copies++ if(syncHeader($_, $iheader, $copy_headers && !$shadow, $ts));
983 #put it into the master file
984 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
986 #deal with the install directives
988 my $pri_install_iheader = fixPaths($iheader, $current_dir);
989 foreach my $class (@classes) {
992 # if ($class =~ m/::/) {
993 # $class =~ s,::,/,g;
995 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
997 $pri_install_classes .= $class_header
998 unless($pri_install_classes =~ $class_header);
1000 $pri_install_files.= "$pri_install_iheader ";;
1004 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1005 $pri_install_pfiles.= "$pri_install_iheader ";;
1008 print "header created for $iheader ($header_copies)\n" if($header_copies > 0 && !$quiet);
1014 # close the master include:
1015 $master_contents .= "#endif\n";
1018 my @master_includes;
1019 push @master_includes, "$out_basedir/include/$lib/$lib";
1020 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
1021 foreach my $master_include (@master_includes) {
1022 #generate the "master" include file
1023 my @tmp = split(/;/,$modules{$lib});
1024 $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
1025 if($master_include && -e $master_include) {
1026 open MASTERINCLUDE, "<$master_include";
1028 binmode MASTERINCLUDE;
1029 my $oldmaster = <MASTERINCLUDE>;
1030 close MASTERINCLUDE;
1031 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1032 $master_include = 0 if($oldmaster eq $master_contents);
1034 if($master_include && $master_contents) {
1035 my $master_dir = dirname($master_include);
1036 mkpath $master_dir, !$quiet;
1037 print "header (master) created for $lib\n" unless $quiet;
1038 open MASTERINCLUDE, ">$master_include";
1039 print MASTERINCLUDE $master_contents;
1040 close MASTERINCLUDE;
1044 #handle the headers.pri for each module
1045 my $headers_pri_contents = "";
1046 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1047 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1048 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1049 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1050 if(-e $headers_pri_file) {
1051 open HEADERS_PRI_FILE, "<$headers_pri_file";
1053 binmode HEADERS_PRI_FILE;
1054 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1055 close HEADERS_PRI_FILE;
1056 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1057 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1059 if($headers_pri_file && $master_contents) {
1060 my $headers_pri_dir = dirname($headers_pri_file);
1061 mkpath $headers_pri_dir, !$quiet;
1062 print "headers.pri file created for $lib\n" unless $quiet;
1063 open HEADERS_PRI_FILE, ">$headers_pri_file";
1064 print HEADERS_PRI_FILE $headers_pri_contents;
1065 close HEADERS_PRI_FILE;
1068 # create forwarding module pri in qtbase/mkspecs/modules
1069 unless ($no_module_fwd) {
1070 my $modulepri = $modulepris{$lib};
1071 if (-e $modulepri) {
1072 my $modulepriname = basename($modulepri);
1073 my $moduleprifwd = "$qtbasedir/mkspecs/modules/$modulepriname";
1074 open MODULE_PRI_FILE, ">$moduleprifwd";
1075 print MODULE_PRI_FILE "QT_MODULE_BASE = $basedir\n";
1076 print MODULE_PRI_FILE "QT_MODULE_BIN_BASE = $qtbasedir/bin\n";
1077 print MODULE_PRI_FILE "QT_MODULE_INCLUDE_BASE = $out_basedir/include\n";
1078 print MODULE_PRI_FILE "QT_MODULE_IMPORT_BASE = $qtbasedir/imports\n";
1079 print MODULE_PRI_FILE "QT_MODULE_LIB_BASE = $qtbasedir/lib\n";
1080 print MODULE_PRI_FILE "QT_MODULE_PLUGIN_BASE = $qtbasedir/plugins\n";
1081 print MODULE_PRI_FILE "include($modulepri)\n";
1082 close MODULE_PRI_FILE;
1083 utime(time, (stat($modulepri))[9], $moduleprifwd);
1084 } elsif ($modulepri) {
1085 print "WARNING: Module $lib\'s pri file '$modulepri' not found.\nSkipped creating forwarding pri for $lib.\n";
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";
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);
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;
1110 if($check_includes) {
1111 for my $lib (keys(%modules)) {
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"));
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 =~ /^$_/);
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 $_);
1141 my $public_header = $header;
1142 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1145 foreach (@ignore_for_master_contents) {
1146 $public_header = 0 if($header eq $_);
1148 if($public_header) {
1149 foreach (@ignore_for_include_check) {
1150 $public_header = 0 if($header eq $_);
1152 foreach(@ignore_for_qt_begin_header_check) {
1153 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1155 foreach(@ignore_for_qt_begin_namespace_check) {
1156 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
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;
1170 while($line = <F>) {
1172 my $output_line = 1;
1173 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1175 } elsif($line =~ /^ *\# *include/) {
1176 my $include = $line;
1177 if($line =~ /<.*>/) {
1178 $include =~ s,.*<(.*)>.*,$1,;
1179 } elsif($line =~ /".*"/) {
1180 $include =~ s,.*"(.*)".*,$1,;
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";
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;
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";
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";
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";
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";
1223 if ($header_skip_qt_module_test == 0) {
1224 if ($qt_module_found == 0) {
1225 print "WARNING: $iheader does not include QT_MODULE\n";