2 ######################################################################
4 # Synchronizes Qt header files - internal development tool.
6 # Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 # Contact: Nokia Corporation (qt-info@nokia.com)
9 ######################################################################
11 # use packages -------------------------------------------------------
18 use English qw(-no_match_vars );
20 # set output basedir to be where ever syncqt is run from
21 our $out_basedir = getcwd();
22 $out_basedir =~ s=\\=/=g;
27 # try to figure out where QtBase is located
28 # normally the script location should be enough, if not fall back to
29 # QTDIR environment variable. If that doesn't work, later ask the
30 # user to use the -qtdir option explicitly.
31 my $qtbasedir = $ENV{"QTDIR"};
32 $qtbasedir = dirname(dirname($0)) if (!$qtbasedir);
33 $qtbasedir =~ s=\\=/=g if (defined $qtbasedir);
35 # will be defined based on the modules sync.profile
36 our (%modules, %moduleheaders, %classnames, %mastercontent, %modulepris);
38 # global variables (modified by options)
42 my $verbose_level = 1;
45 my $force_relative = 0;
46 my $check_includes = 0;
48 my $create_uic_class_map = 0;
49 my $create_private_headers = 1;
51 my $cache_module_fwd = 0;
52 my $developer_build = 0;
53 my $no_module_version_header = 0;
54 my $makefile_generator = "";
56 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
59 # functions ----------------------------------------------------------
61 ######################################################################
65 # Purpose: Show the usage of the script.
67 ######################################################################
71 print " <module directory> Specifies which module to sync header files for (required for shadow builds!)\n\n";
73 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
74 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
75 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
76 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
77 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
78 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
79 print " -qtdir <PATH> Set the path to QtBase (detected: " . (defined $qtbasedir ? $qtbasedir : "-none-") . ")\n";
80 print " -quiet Only report problems, not activity (same as -verbose 0)\n";
81 print " -v, -verbose <level> Sets the verbosity level (max. 4) (default: $verbose_level)\n";
82 print " The short form increases the level by +1\n";
83 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
84 print " Create headers for <NAME> with original headers in\n";
85 print " <HEADERDIR> relative to <PROFILEDIR> \n";
86 print " -private Force copy private headers (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
87 print " -module-fwd <PATH> Create fwd includes for module pri files in the given\n";
88 print " path (default: none)\n";
89 print " -cache-module-fwd Create a .qmake.cache file to cache the location of the\n";
90 print " fwd includes\n";
91 print " -developer-build Point libraries and binaries to a common directory for\n";
92 print " easy development\n";
93 print " -no-module-version-header\n";
94 print " Don't create module version header file\n";
95 print " -generator <PATH> Specify the makefile generator setting (e.g. 'UNIX')\n";
96 print " -help This help\n";
100 ######################################################################
101 # Syntax: checkUnix()
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 ######################################################################
110 if ( $force_win != 0) {
112 } elsif ( -f "/bin/uname" ) {
114 (-f "\\bin\\uname") && ($r = 0);
115 } elsif ( -f "/usr/bin/uname" ) {
117 (-f "\\usr\\bin\\uname") && ($r = 0);
120 $_ = $Config{'osname'};
121 $r = 0 if( /(ms)|(cyg)win/i );
128 return 0 if($dir =~ /^\//);
129 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
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 {
143 return 0 if(basename($iheader) =~ /_/);
144 return 0 if(basename($iheader) =~ /qconfig/);
145 if(open(F, "<$iheader")) {
148 return 0 if(/^\#pragma qt_no_master_include$/);
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 ######################################################################
169 my $classname = $classnames{basename($iheader)};
170 push @ret, $classname if ($classname);
173 if(open(F, "<$iheader")) {
177 chop $line if ($line =~ /\r$/);
182 last unless($line =~ /\\$/);
185 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
186 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
190 $line =~ s,//.*$,,; #remove c++ comments
191 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
192 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
193 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
194 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
195 $parsable .= " " . $line;
201 my $last_definition = 0;
203 for(my $i = 0; $i < length($parsable); $i++) {
205 my $character = substr($parsable, $i, 1);
206 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
207 for($i+=2; $i < length($parsable); $i++) {
208 my $end = substr($parsable, $i, 2);
210 $last_definition = $i+2;
215 } elsif($character eq "{") {
217 my $block_start = $i + 1;
218 BLOCK: for($i+=1; $i < length($parsable); $i++) {
219 my $ignore = substr($parsable, $i, 1);
222 } elsif($ignore eq "}") {
224 unless($brace_depth) {
225 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
226 my $end = substr($parsable, $i2, 1);
227 if($end eq ";" || $end ne " ") {
228 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
229 $i = $i2 if($end eq ";");
230 $last_definition = $i + 1;
237 } elsif($character eq ";") {
238 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
239 $last_definition = $i + 1;
240 } elsif($character eq "}") {
241 # a naked } must be a namespace ending
242 # if it's not a namespace, it's eaten by the loop above
244 $last_definition = $i + 1;
247 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
248 && substr($parsable, $i+1, 1) eq "{") {
249 push @namespaces, $1;
251 # Eat the opening { so that the condensing loop above doesn't see it
253 $last_definition = $i + 1;
257 $definition =~ s=[\n\r]==g;
259 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
261 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
263 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
265 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
266 push @symbols, "Q" . $1 . "Iterator";
267 push @symbols, "QMutable" . $1 . "Iterator";
270 foreach my $symbol (@symbols) {
271 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
273 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
274 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
282 my ($dir, $lib, $be_verbose) = @_;
285 $dir = "<outbase>" . substr($dir, length($out_basedir)) if ($be_verbose < 3);
286 print "$lib: mkpath $dir\n" if ($be_verbose > 1);
290 ######################################################################
291 # Syntax: syncHeader(header, iheader, copy, timestamp)
292 # Params: header, string, filename to create "symlink" for
293 # iheader, string, destination name of symlink
294 # copy, forces header to be a copy of iheader
295 # timestamp, the requested modification time if copying
297 # Purpose: Syncronizes header to iheader
298 # Returns: 1 if successful, else 0.
299 ######################################################################
301 my ($lib, $header, $iheader, $copy, $ts) = @_;
302 $iheader =~ s=\\=/=g;
304 return copyFile($lib, $iheader, $header) if($copy);
307 my $header_dir = dirname($header);
308 make_path($header_dir, $lib, $verbose_level);
311 my $iheader_out = fixPaths($iheader, $header_dir);
312 open HEADER, ">$header" || die "Could not open $header for writing!\n";
313 print HEADER "#include \"$iheader_out\"\n";
316 utime(time, $ts, $header) or die "$iheader, $header";
323 ######################################################################
324 # Syntax: fixPaths(file, dir)
325 # Params: file, string, filepath to be made relative to dir
326 # dir, string, dirpath for point of origin
328 # Purpose: file is made relative (if possible) of dir.
329 # Returns: String with the above applied conversion.
330 ######################################################################
332 my ($file, $dir) = @_;
338 $ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
339 my $file_dir = dirname($file);
340 if($file_dir eq ".") {
341 $file_dir = getcwd();
342 $file_dir =~ s=\\=/=g;
344 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
349 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
350 return basename($file) if($file_dir eq $dir);
353 while ($file_dir =~ s,/[^/]+/\.\./,/,) {}
354 while ($dir =~ s,/[^/]+/\.\./,/,) {}
356 for(my $i = 1; $i < length($file_dir); $i++) {
357 my $slash = index($file_dir, "/", $i);
358 last if($slash == -1);
359 my $tmp = substr($file_dir, 0, $slash);
360 last unless($dir =~ m,^\Q$tmp\E/,);
365 my $after = substr($dir, length($match_dir));
366 my $count = ($after =~ tr,/,,);
368 for(my $i = 0; $i < $count; $i++) {
371 $ret =~ s,^\Q$match_dir\E,$dots,;
377 ######################################################################
378 # Syntax: fileContents(filename)
379 # Params: filename, string, filename of file to return contents
381 # Purpose: Get the contents of a file.
382 # Returns: String with contents of the file, or empty string if file
384 # Warning: Dies if it does exist but script cannot get read access.
385 ######################################################################
388 my $filecontents = "";
390 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
396 return $filecontents;
399 ######################################################################
400 # Syntax: fileCompare(file1, file2)
401 # Params: file1, string, filename of first file
402 # file2, string, filename of second file
404 # Purpose: Determines if files are equal, and which one is newer.
405 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
406 # is newer, 1 if file2 is newer.
407 ######################################################################
409 my ($file1, $file2) = @_;
410 my $file1contents = fileContents($file1);
411 my $file2contents = fileContents($file2);
412 if (! -e $file1) { return 1; }
413 if (! -e $file2) { return -1; }
414 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
417 ######################################################################
418 # Syntax: copyFile(file, ifile)
419 # Params: file, string, filename to create duplicate for
420 # ifile, string, destination name of duplicate
422 # Purpose: Keeps files in sync so changes in the newer file will be
423 # written to the other.
424 # Returns: 1 if files were synced, else 0.
425 # Warning: Dies if script cannot get write access.
426 ######################################################################
429 my ($lib, $file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
430 # Bi-directional synchronization
431 open( I, "< " . $file ) || die "Could not open $file for reading";
436 if ( open(I, "< " . $ifile) ) {
439 $ifilecontents = <I>;
441 $copy = fileCompare($file, $ifile);
448 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
450 my $file_dir = dirname($file);
451 make_path($file_dir, $lib, $verbose_level);
452 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
455 print O $ifilecontents;
457 utime time, (stat($ifile))[9], $file;
459 } elsif ( $copy < 0 ) {
460 my $ifile_dir = dirname($ifile);
461 make_path($ifile_dir, $lib, $verbose_level);
462 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
465 print O $filecontents;
467 utime time, (stat($file))[9], $ifile;
474 ######################################################################
475 # Syntax: symlinkFile(file, ifile)
476 # Params: file, string, filename to create "symlink" for
477 # ifile, string, destination name of symlink
479 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
481 # Returns: 1 on success, else 0.
482 ######################################################################
485 my ($lib, $file, $ifile) = @_;
488 print "$lib: symlink created for $file " if ($verbose_level);
489 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
493 $t =~ s-^$quoted_basedir/--;
494 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
495 $file =~ s-^$quoted_basedir/-$p-;
496 print " ($file)\n" if($verbose_level);
498 print "\n" if($verbose_level);
499 return symlink($file, $ifile);
501 return copyFile($lib, $file, $ifile);
504 ######################################################################
505 # Syntax: findFiles(dir, match, descend)
506 # Params: dir, string, directory to search for name
507 # match, string, regular expression to match in dir
508 # descend, integer, 0 = non-recursive search
509 # 1 = recurse search into subdirectories
511 # Purpose: Finds files matching a regular expression.
512 # Returns: List of matching files.
515 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
516 # findFiles("/tmp","^#",0) - finds #* files in /tmp
517 ######################################################################
519 my ($dir,$match,$descend) = @_;
520 my ($file,$p,@files);
523 ($dir eq "") && ($dir = ".");
524 if ( opendir(D,$dir) ) {
528 ($dir =~ /\/$/) || ($dir .= "/");
530 foreach $file ( sort readdir(D) ) {
531 next if ( $file =~ /^\.\.?$/ );
533 ($file =~ /$match/) && (push @files, $p);
534 if ( $descend && -d $p && ! -l $p ) {
535 push @files, &findFiles($p,$match,$descend);
543 ######################################################################
544 # Syntax: loadSyncProfile()
546 # Purpose: Locates the sync.profile.
547 # Returns: Hashmap of module name -> directory.
548 ######################################################################
549 sub loadSyncProfile {
550 my ($srcbase, $outbase) = @_;
551 if ($verbose_level) {
552 print("<srcbase> = $$srcbase \n");
553 print("<outbase> = $$outbase \n");
556 my $syncprofile = "$$srcbase/sync.profile";
558 unless ($result = do "$syncprofile") {
559 die "syncqt couldn't parse $syncprofile: $@" if $@;
560 die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
565 sub locateSyncProfile
567 my ($directory) = @_;
569 $directory = abs_path($directory);
570 while(!defined $syncprofile) {
572 if (opendir(D, $directory)) {
573 foreach my $file (sort readdir(D)) {
574 next if ($file =~ /^\.\.?$/);
575 $syncprofile = "$directory/$file" if ($file =~ /^sync\.profile$/);
576 last if (defined $syncprofile);
580 last if (defined $syncprofile || $directory eq "/" || $directory =~ /^?:[\/\\]$/);
581 $directory = dirname($directory);
586 # check if this is an in-source build, and if so use that as the basedir too
587 $basedir = locateSyncProfile($out_basedir);
589 $basedir = dirname($basedir) ;
590 $basedir =~ s=\\=/=g;
591 $quoted_basedir = "\Q$basedir";
594 # --------------------------------------------------------------------
596 # --------------------------------------------------------------------
603 my $arg = shift @ARGV;
604 if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
607 } elsif($arg eq "-copy") {
610 } elsif($arg eq "-o" || $arg eq "-outdir") {
613 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
614 $arg eq "-relative" || $arg eq "-check-includes") {
615 $var = substr($arg, 1);
617 } elsif($arg eq "-module-fwd") {
620 } elsif($arg eq "-cache-module-fwd") {
621 $var = "cache_module_fwd";
623 } elsif($arg eq "-developer-build") {
624 $var = "developer_build";
626 } elsif($arg eq "-no-module-version-header") {
627 $var = "no_module_version_header";
629 } elsif($arg =~ /^-no-(.*)$/) {
632 #these are for commandline compat
633 } elsif($arg eq "-inc") {
636 } elsif($arg eq "-module") {
639 } elsif($arg eq "-separate-module") {
640 $var = "separate-module";
642 } elsif($arg eq "-show") {
645 } elsif($arg eq "-quiet") {
648 } elsif($arg eq "-v") {
651 } elsif($arg eq "-verbose") {
654 } elsif($arg eq "-private") {
655 $var = "create_private_headers";
657 } elsif($arg eq "-qtdir") {
660 } elsif($arg eq "-base-dir") {
661 # skip, it's been dealt with at the top of the file
664 } elsif($arg eq "-generator") {
665 $var = "makefile_generator";
667 } elsif($arg =~/^-/) {
668 print "Unknown option: $arg\n\n" if(!$var);
671 $basedir = locateSyncProfile($arg);
672 die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
673 $basedir = dirname($basedir);
674 $basedir =~ s=\\=/=g;
675 $quoted_basedir = "\Q$basedir";
680 if(!$var || $var eq "show_help") {
681 print "Unknown option: $arg\n\n" if(!$var);
683 } elsif ($var eq "copy") {
689 } elsif ($var eq "showonly") {
695 } elsif ($var eq "verbose") {
698 } elsif($val eq "no" && $verbose_level) {
701 $verbose_level = int($val);
703 } elsif ($var eq "check-includes") {
706 } elsif($check_includes) {
709 } elsif ($var eq "remove-stale") {
712 } elsif($remove_stale) {
715 } elsif ($var eq "windows") {
718 } elsif($force_win) {
721 } elsif ($var eq "relative") {
724 } elsif($force_relative) {
727 } elsif ($var eq "module") {
728 print "module :$val:\n" if($verbose_level);
729 die "No such module: $val" unless(defined $modules{$val});
730 push @modules_to_sync, $val;
731 } elsif ($var eq "separate-module") {
732 my ($module, $prodir, $headerdir) = split(/:/, $val);
733 $modules{$module} = $prodir;
734 push @modules_to_sync, $module;
735 $moduleheaders{$module} = $headerdir;
736 $create_uic_class_map = 0;
737 } elsif ($var eq "qtdir") {
740 $qtbasedir =~ s=\\=/=g;
742 die "The -qtdir option requires an argument";
744 } elsif ($var eq "module_fwd") {
746 } elsif ($var eq "cache_module_fwd") {
747 $cache_module_fwd = 1;
748 } elsif ($var eq "developer_build") {
749 $developer_build = 1;
750 } elsif ($var eq "makefile_generator") {
751 $makefile_generator = $val;
752 } elsif ($var eq "no_module_version_header") {
753 $no_module_version_header = 1;
754 } elsif ($var eq "output") {
756 if(checkRelative($outdir)) {
757 $out_basedir = getcwd();
759 $out_basedir .= "/" . $outdir;
761 $out_basedir = $outdir;
764 $out_basedir =~ s=\\=/=g;
768 # if the $qtbasedir neither has 'qtbase' somewhere in its path, nor a
769 # '.qmake.cache' file in its directory, we assume it's not a valid path
770 # (remember that a yet-to-be-built qtbase doesn't have this file either,
771 # thus the 'qtbase' path check!)
772 die "Cannot automatically detect/use provided path to QtBase's build directory!\n" .
773 "QTDIR detected/provided: " . (defined $qtbasedir ? $qtbasedir : "-none-") . "\n" .
774 "Please -qtdir option to provide the correct path.\nsyncqt failed"
775 if (!$qtbasedir || !-d "$qtbasedir/mkspecs");
777 # if we have no $basedir we cannot be sure which sources you want, so die
778 die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
780 my @ignore_headers = ();
781 my $class_lib_map_contents = "";
782 our @ignore_for_master_contents = ();
783 our @ignore_for_include_check = ();
784 our @ignore_for_qt_begin_header_check = ();
785 our @ignore_for_qt_begin_namespace_check = ();
786 our @ignore_for_qt_module_check = ();
787 my %colliding_headers = ();
788 my %inject_headers = ( "$basedir/src/corelib/global" => ( "qconfig.h" ) ); # all from build dir
790 # load the module's sync.profile here, before we can
791 loadSyncProfile(\$basedir, \$out_basedir);
793 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
795 $isunix = checkUnix; #cache checkUnix
798 make_path("$out_basedir/include/Qt", "<outdir>", $verbose_level);
800 foreach my $lib (@modules_to_sync) {
802 my $dir = $modules{$lib};
803 my $module_version = "";
804 my $module_major_version = "";
805 my $module_minor_version = "";
806 my $module_patch_version = "";
808 if (-e "$modulepris{$lib}") {
809 my $content = fileContents($modulepris{$lib});
810 my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
812 # We only pick the first one, since each module need a separate .pri file
813 $module_version = $version_rows[0];
814 chomp $module_version;
815 $module_version =~ s/^\s*QT\..*\.VERSION\s*=\s*([^#]+).*$/$1/;
816 $module_version =~ s/\s+$//;
817 my @versions = split(/\./, $module_version);
818 $module_major_version = $versions[0];
819 chomp $module_major_version;
820 $module_minor_version = $versions[1];
821 chomp $module_minor_version;
822 $module_patch_version = $versions[2];
823 chomp $module_patch_version;
826 print "$lib: WARNING: Module\'s pri missing QT.<module>.VERSION variable! Private headers not versioned!\n" if (!$module_version);
828 my $pathtoheaders = "";
829 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
831 #information used after the syncing
832 my $pri_install_classes = "";
833 my $pri_install_files = "";
834 my $pri_install_pfiles = "";
836 my $libcapitals = $lib;
837 $libcapitals =~ y/a-z/A-Z/;
838 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
841 if(-e "$dir/" . basename($dir) . ".pro") {
842 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
843 while(my $line = <F>) {
845 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
846 foreach(split(/ /, $1)) {
848 my $content = $mastercontent{$_};
849 $master_contents .= $content if ($content);
857 #remove the old files
859 my @subdirs = ("$out_basedir/include/$lib");
860 foreach my $subdir (@subdirs) {
861 if (opendir DIR, $subdir) {
862 foreach my $t (sort readdir(DIR)) {
863 my $file = "$subdir/$t";
865 push @subdirs, $file unless($t eq "." || $t eq "..");
868 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
869 foreach my $file (@files) {
871 if(open(F, "<$file")) {
872 while(my $line = <F>) {
874 if($line =~ /^\#include \"([^\"]*)\"$/) {
876 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
877 $remove_file = 1 unless(-e $include);
884 unlink $file if($remove_file);
895 # create the version header files for each module
896 unless ($no_module_version_header) {
897 my $modulepri = $modulepris{$lib};
899 my $modulepriname = basename($modulepri);
900 # FIXME: this creates a file in the source location for shadow-builds
901 my $moduleversionheader = "$modules{$lib}/" . lc($lib) . "version.h";
902 my $modulehexstring = sprintf("0x%02X%02X%02X", int($module_major_version), int($module_minor_version), int($module_patch_version));
903 open MODULE_VERSION_HEADER_FILE, ">$moduleversionheader";
904 print MODULE_VERSION_HEADER_FILE "/* This file was generated by syncqt with the info from sync.profile. */\n";
905 print MODULE_VERSION_HEADER_FILE "#ifndef QT_". uc($lib) . "_VERSION_H\n";
906 print MODULE_VERSION_HEADER_FILE "#define QT_". uc($lib) . "_VERSION_H\n";
907 print MODULE_VERSION_HEADER_FILE "\n";
908 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION_STR \"" . $module_version . "\"\n";
909 print MODULE_VERSION_HEADER_FILE "\n";
910 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION $modulehexstring\n", ;
911 print MODULE_VERSION_HEADER_FILE "\n";
912 print MODULE_VERSION_HEADER_FILE "#endif // QT_". uc($lib) . "_VERSION_H\n";
913 close MODULE_VERSION_HEADER_FILE;
914 $moduleversionheader = "<srcbase>" . substr($moduleversionheader, length($basedir)) if ($verbose_level < 2);
915 print "$lib: created version header $moduleversionheader\n" if($verbose_level);
916 } elsif ($modulepri) {
917 print "$lib: WARNING: Module\'s pri file '$modulepri' not found.\n$lib: Skipped creating module version header.\n";
922 foreach my $current_dir (split(/;/, $dir)) {
923 my $headers_dir = $current_dir;
924 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
926 my @subdirs = ($headers_dir);
927 foreach my $subdir (@subdirs) {
928 opendir DIR, $subdir or next;
929 foreach my $t (sort readdir(DIR)) {
930 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
931 !($t eq "..") && !($t eq ".obj") &&
932 !($t eq ".moc") && !($t eq ".rcc") &&
933 !($t eq ".uic") && !($t eq "build"));
938 #calc files and "copy" them
939 foreach my $subdir (@subdirs) {
940 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
941 if (defined $inject_headers{$subdir}) {
942 foreach my $if ($inject_headers{$subdir}) {
943 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
944 push @headers, "*".$if;
947 my $header_dirname = "";
948 foreach my $header (@headers) {
949 my $shadow = ($header =~ s/^\*//);
950 $header = 0 if($header =~ /^ui_.*.h/);
951 foreach (@ignore_headers) {
952 $header = 0 if($header eq $_);
955 my $header_copies = 0;
956 #figure out if it is a public header
957 my $public_header = $header;
958 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
961 foreach (@ignore_for_master_contents) {
962 $public_header = 0 if($header eq $_);
966 my $iheader = $subdir . "/" . $header;
967 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
968 my @classes = $public_header ? classNames($iheader) : ();
970 print "$header [$lib]\n";
972 print "SYMBOL: $_\n";
975 my $ts = (stat($iheader))[9];
976 #find out all the places it goes..
978 if ($public_header) {
979 @headers = ( "$out_basedir/include/$lib/$header" );
981 # write forwarding headers to include/Qt
982 if ($lib ne "phonon" && $subdir =~ /^$quoted_basedir\/src/) {
983 my $file_name = "$out_basedir/include/Qt/$header";
985 my $header_content = '';
986 if (exists $colliding_headers{$file_name}) {
989 $colliding_headers{$file_name} = 1;
990 my $warning_msg = 'Inclusion of header files from include/Qt is deprecated.';
991 $header_content = "#ifndef QT_NO_QT_INCLUDE_WARN\n" .
992 " #if defined(__GNUC__)\n" .
993 " #warning \"$warning_msg\"\n" .
994 " #elif defined(_MSC_VER)\n" .
995 " #pragma message(\"WARNING: $warning_msg\")\n" .
999 $header_content .= '#include "' . "../$lib/$header" . "\"\n";
1000 open HEADERFILE, $file_op, $file_name or die "unable to open '$file_name' : $!\n";
1001 print HEADERFILE $header_content;
1005 foreach my $full_class (@classes) {
1006 my $header_base = basename($header);
1008 my $class = $full_class;
1009 $class =~ s/^.*:://;
1010 # if ($class =~ m/::/) {
1011 # class =~ s,::,/,g;
1013 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
1014 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
1016 # KDE-Compat headers for Phonon
1017 if ($lib eq "phonon") {
1018 $header_copies++ if (syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
1021 } elsif ($create_private_headers) {
1022 if ($module_version) {
1023 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
1025 @headers = ( "$out_basedir/include/$lib/private/$header" );
1028 foreach(@headers) { #sync them
1029 $header_copies++ if(syncHeader($lib, $_, $iheader, $copy_headers && !$shadow, $ts));
1032 if($public_header) {
1033 #put it into the master file
1034 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
1036 #deal with the install directives
1037 if($public_header) {
1038 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1039 foreach my $class (@classes) {
1041 $class =~ s/^.*:://;
1042 # if ($class =~ m/::/) {
1043 # $class =~ s,::,/,g;
1045 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
1046 $current_dir) . " ";
1047 $pri_install_classes .= $class_header
1048 unless($pri_install_classes =~ $class_header);
1050 $pri_install_files.= "$pri_install_iheader ";;
1054 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1055 $pri_install_pfiles.= "$pri_install_iheader ";;
1059 if ($verbose_level && $header_copies) {
1060 my $new_header_dirname = dirname($iheader);
1061 $new_header_dirname = "<srcbase>" . substr($new_header_dirname, length($basedir)) if ($new_header_dirname && $verbose_level < 2);
1062 my $header_base = basename($iheader);
1063 if ($verbose_level < 3) {
1064 my $line_prefix = ",";
1065 if ($new_header_dirname ne $header_dirname) {
1066 $line_prefix = "$lib: created fwd-include header(s) for $new_header_dirname/ {";
1067 $line_prefix = " }\n".$line_prefix if ($header_dirname);
1068 $header_dirname = $new_header_dirname;
1072 print "$line_prefix $header_base ($header_copies)";
1073 } else { # $verbose_level >= 3
1074 $iheader = "<srcbase>" . substr($iheader, length($basedir)) if ($verbose_level == 3);
1075 print "$lib: created $header_copies fwd-include headers for $iheader\n";
1080 print " }\n" if ($header_dirname && $verbose_level > 0 && $verbose_level < 3);
1084 # close the master include:
1085 $master_contents .= "#endif\n";
1088 my @master_includes;
1089 push @master_includes, "$out_basedir/include/$lib/$lib";
1090 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
1091 foreach my $master_include (@master_includes) {
1092 #generate the "master" include file
1093 my @tmp = split(/;/,$modules{$lib});
1094 $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
1095 if($master_include && -e $master_include) {
1096 open MASTERINCLUDE, "<$master_include";
1098 binmode MASTERINCLUDE;
1099 my $oldmaster = <MASTERINCLUDE>;
1100 close MASTERINCLUDE;
1101 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1102 $master_include = 0 if($oldmaster eq $master_contents);
1104 if($master_include && $master_contents) {
1105 my $master_dir = dirname($master_include);
1106 make_path($master_dir, $lib, $verbose_level);
1107 open MASTERINCLUDE, ">$master_include";
1108 print MASTERINCLUDE $master_contents;
1109 close MASTERINCLUDE;
1110 print "$lib: created header (master) file\n" if($verbose_level);
1114 #handle the headers.pri for each module
1115 my $headers_pri_contents = "";
1116 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1117 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1118 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1119 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1120 if(-e $headers_pri_file) {
1121 open HEADERS_PRI_FILE, "<$headers_pri_file";
1123 binmode HEADERS_PRI_FILE;
1124 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1125 close HEADERS_PRI_FILE;
1126 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1127 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1129 if($headers_pri_file && $master_contents) {
1130 my $headers_pri_dir = dirname($headers_pri_file);
1131 make_path($headers_pri_dir, $lib, $verbose_level);
1132 open HEADERS_PRI_FILE, ">$headers_pri_file";
1133 print HEADERS_PRI_FILE $headers_pri_contents;
1134 close HEADERS_PRI_FILE;
1135 print "$lib: created headers.pri file\n" if($verbose_level);
1138 # create forwarding module pri in qtbase/mkspecs/modules
1140 my $modulepri = $modulepris{$lib};
1141 if (-e $modulepri) {
1142 my $modulepriname = basename($modulepri);
1143 make_path($module_fwd, $lib, $verbose_level);
1144 my $moduleprifwd = "$module_fwd/$modulepriname";
1145 my $mod_base = $developer_build ? $basedir : $out_basedir;
1146 my $mod_component_base = $developer_build ? $qtbasedir : $out_basedir;
1147 open MODULE_PRI_FILE, ">$moduleprifwd" or die("Could not open $moduleprifwd for writing");
1148 print MODULE_PRI_FILE "QT_MODULE_BASE = $mod_base\n";
1149 print MODULE_PRI_FILE "QT_MODULE_BIN_BASE = $mod_component_base/bin\n";
1150 print MODULE_PRI_FILE "QT_MODULE_INCLUDE_BASE = $out_basedir/include\n";
1151 print MODULE_PRI_FILE "QT_MODULE_IMPORT_BASE = $mod_component_base/imports\n";
1152 print MODULE_PRI_FILE "QT_MODULE_LIB_BASE = $mod_component_base/lib\n";
1153 print MODULE_PRI_FILE "QT_MODULE_PLUGIN_BASE = $mod_component_base/plugins\n";
1154 print MODULE_PRI_FILE "include($modulepri)\n";
1155 close MODULE_PRI_FILE;
1156 utime(time, (stat($modulepri))[9], $moduleprifwd);
1157 if ($cache_module_fwd) {
1158 my $cacheStatement = "QMAKE_EXTRA_MODULE_FORWARDS = \"$module_fwd\"";
1159 my $cacheFile = "$out_basedir/.qmake.cache";
1160 my $existingQmakeCache = fileContents($cacheFile);
1161 # Skip if it's already there.
1162 if ($existingQmakeCache !~ $cacheStatement) {
1163 open QMAKE_CACHE_FILE, ">>$cacheFile" or die("Could not open $cacheFile for writing");
1164 print QMAKE_CACHE_FILE "$cacheStatement\n";
1165 close(QMAKE_CACHE_FILE);
1168 } elsif ($modulepri) {
1169 print "$lib: WARNING: Module\'s pri file '$modulepri' not found.\n$lib: Skipped creating forwarding pri.\n";
1174 unless($showonly || !$create_uic_class_map) {
1175 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1176 if(-e $class_lib_map) {
1177 open CLASS_LIB_MAP, "<$class_lib_map";
1179 binmode CLASS_LIB_MAP;
1180 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1181 close CLASS_LIB_MAP;
1182 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1183 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1185 if($class_lib_map) {
1186 my $class_lib_map_dir = dirname($class_lib_map);
1187 make_path($class_lib_map_dir, "<outdir>", $verbose_level);
1188 open CLASS_LIB_MAP, ">$class_lib_map";
1189 print CLASS_LIB_MAP $class_lib_map_contents;
1190 close CLASS_LIB_MAP;
1194 if($check_includes) {
1195 for my $lib (keys(%modules)) {
1197 my @subdirs = ($modules{$lib});
1198 foreach my $subdir (@subdirs) {
1199 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
1200 foreach my $t (sort readdir(DIR)) {
1201 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
1202 !($t eq "..") && !($t eq ".obj") &&
1203 !($t eq ".moc") && !($t eq ".rcc") &&
1204 !($t eq ".uic") && !($t eq "build"));
1209 foreach my $subdir (@subdirs) {
1210 my $header_skip_qt_module_test = 0;
1211 foreach(@ignore_for_qt_module_check) {
1212 foreach (split(/;/, $_)) {
1213 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1216 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1217 foreach my $header (@headers) {
1218 my $header_skip_qt_begin_header_test = 0;
1219 my $header_skip_qt_begin_namespace_test = 0;
1220 $header = 0 if($header =~ /^ui_.*.h/);
1221 foreach (@ignore_headers) {
1222 $header = 0 if($header eq $_);
1225 my $public_header = $header;
1226 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1229 foreach (@ignore_for_master_contents) {
1230 $public_header = 0 if($header eq $_);
1232 if($public_header) {
1233 foreach (@ignore_for_include_check) {
1234 $public_header = 0 if($header eq $_);
1236 foreach(@ignore_for_qt_begin_header_check) {
1237 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1239 foreach(@ignore_for_qt_begin_namespace_check) {
1240 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1245 my $iheader = $subdir . "/" . $header;
1246 if($public_header) {
1247 if(open(F, "<$iheader")) {
1248 my $qt_module_found = 0;
1249 my $qt_begin_header_found = 0;
1250 my $qt_end_header_found = 0;
1251 my $qt_begin_namespace_found = 0;
1252 my $qt_end_namespace_found = 0;
1254 while($line = <F>) {
1256 my $output_line = 1;
1257 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1259 } elsif($line =~ /^ *\# *include/) {
1260 my $include = $line;
1261 if($line =~ /<.*>/) {
1262 $include =~ s,.*<(.*)>.*,$1,;
1263 } elsif($line =~ /".*"/) {
1264 $include =~ s,.*"(.*)".*,$1,;
1269 for my $trylib (keys(%modules)) {
1270 if(-e "$out_basedir/include/$trylib/$include") {
1271 print "$lib: WARNING: $iheader includes $include when it should include $trylib/$include\n";
1275 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1276 $qt_begin_header_found = 1;
1277 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1278 $qt_end_header_found = 1;
1279 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1280 $qt_begin_namespace_found = 1;
1281 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1282 $qt_end_namespace_found = 1;
1283 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1284 $qt_module_found = 1;
1287 if ($header_skip_qt_begin_header_test == 0) {
1288 if ($qt_begin_header_found == 0) {
1289 print "$lib: WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1292 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1293 print "$lib: WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1297 if ($header_skip_qt_begin_namespace_test == 0) {
1298 if ($qt_begin_namespace_found == 0) {
1299 print "$lib: WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1302 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1303 print "$lib: WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1307 if ($header_skip_qt_module_test == 0) {
1308 if ($qt_module_found == 0) {
1309 print "$lib: WARNING: $iheader does not include QT_MODULE\n";
1321 # Do configure tests now (pass some things along)
1322 # fatal tests have a non zero return
1323 # If the generator is not set (e.g. someone invoking syncqt as part of configure etc, then don't run tests either)
1324 unless ($showonly || $makefile_generator eq '') {
1325 my $configtests = dirname($0)."/qtmodule-configtests";
1326 if (! -f $configtests) {
1327 $configtests = $qtbasedir."/bin/qtmodule-configtests";
1329 if (! -f $configtests) {
1330 warn "Unable to locate qtmodule-configtests script - config tests disabled.\n";
1332 if (system($EXECUTABLE_NAME, $configtests, $basedir, $out_basedir, $qtbasedir, $makefile_generator)) {
1333 die "$configtests exited with status $?";