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;
50 my $cache_module_fwd = 0;
51 my $developer_build = 0;
52 my $no_module_version_header = 0;
54 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
57 # functions ----------------------------------------------------------
59 ######################################################################
63 # Purpose: Show the usage of the script.
65 ######################################################################
69 print " <module directory> Specifies which module to sync header files for (required for shadow builds!)\n\n";
71 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
72 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
73 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
74 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
75 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
76 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
77 print " -qtdir <PATH> Set the path to QtBase (detected: " . (defined $qtbasedir ? $qtbasedir : "-none-") . ")\n";
78 print " -quiet Only report problems, not activity (default: " . ($quiet ? "yes" : "no") . ")\n";
79 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
80 print " Create headers for <NAME> with original headers in\n";
81 print " <HEADERDIR> relative to <PROFILEDIR> \n";
82 print " -private Force copy private headers (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
83 print " -module-fwd <PATH> Create fwd includes for module pri files in the given\n";
84 print " path (default: none)\n";
85 print " -cache-module-fwd Create a .qmake.cache file to cache the location of the\n";
86 print " fwd includes\n";
87 print " -developer-build Point libraries and binaries to a common directory for\n";
88 print " easy development\n";
89 print " -no-module-version-header\n";
90 print " Don't create module version header file\n";
91 print " -help This help\n";
95 ######################################################################
99 # Purpose: Check if script runs on a Unix system or not. Cygwin
100 # systems are _not_ detected as Unix systems.
101 # Returns: 1 if a unix system, else 0.
102 ######################################################################
105 if ( $force_win != 0) {
107 } elsif ( -f "/bin/uname" ) {
109 (-f "\\bin\\uname") && ($r = 0);
110 } elsif ( -f "/usr/bin/uname" ) {
112 (-f "\\usr\\bin\\uname") && ($r = 0);
115 $_ = $Config{'osname'};
116 $r = 0 if( /(ms)|(cyg)win/i );
123 return 0 if($dir =~ /^\//);
124 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
128 ######################################################################
129 # Syntax: shouldMasterInclude(iheader)
130 # Params: iheader, string, filename to verify inclusion
132 # Purpose: Determines if header should be in the master include file.
133 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
134 # able to open, else 1.
135 ######################################################################
136 sub shouldMasterInclude {
138 return 0 if(basename($iheader) =~ /_/);
139 return 0 if(basename($iheader) =~ /qconfig/);
140 if(open(F, "<$iheader")) {
143 return 0 if(/^\#pragma qt_no_master_include$/);
152 ######################################################################
153 # Syntax: classNames(iheader)
154 # Params: iheader, string, filename to parse for classname "symlinks"
156 # Purpose: Scans through iheader to find all classnames that should be
157 # synced into library's include structure.
158 # Returns: List of all class names in a file.
159 ######################################################################
164 my $classname = $classnames{basename($iheader)};
165 push @ret, $classname if ($classname);
168 if(open(F, "<$iheader")) {
172 chop $line if ($line =~ /\r$/);
177 last unless($line =~ /\\$/);
180 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
181 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
185 $line =~ s,//.*$,,; #remove c++ comments
186 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
187 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
188 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
189 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
190 $parsable .= " " . $line;
196 my $last_definition = 0;
198 for(my $i = 0; $i < length($parsable); $i++) {
200 my $character = substr($parsable, $i, 1);
201 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
202 for($i+=2; $i < length($parsable); $i++) {
203 my $end = substr($parsable, $i, 2);
205 $last_definition = $i+2;
210 } elsif($character eq "{") {
212 my $block_start = $i + 1;
213 BLOCK: for($i+=1; $i < length($parsable); $i++) {
214 my $ignore = substr($parsable, $i, 1);
217 } elsif($ignore eq "}") {
219 unless($brace_depth) {
220 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
221 my $end = substr($parsable, $i2, 1);
222 if($end eq ";" || $end ne " ") {
223 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
224 $i = $i2 if($end eq ";");
225 $last_definition = $i + 1;
232 } elsif($character eq ";") {
233 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
234 $last_definition = $i + 1;
235 } elsif($character eq "}") {
236 # a naked } must be a namespace ending
237 # if it's not a namespace, it's eaten by the loop above
239 $last_definition = $i + 1;
242 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
243 && substr($parsable, $i+1, 1) eq "{") {
244 push @namespaces, $1;
246 # Eat the opening { so that the condensing loop above doesn't see it
248 $last_definition = $i + 1;
252 $definition =~ s=[\n\r]==g;
254 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
256 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
258 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
260 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
261 push @symbols, "Q" . $1 . "Iterator";
262 push @symbols, "QMutable" . $1 . "Iterator";
265 foreach my $symbol (@symbols) {
266 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
268 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
269 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
276 ######################################################################
277 # Syntax: syncHeader(header, iheader, copy, timestamp)
278 # Params: header, string, filename to create "symlink" for
279 # iheader, string, destination name of symlink
280 # copy, forces header to be a copy of iheader
281 # timestamp, the requested modification time if copying
283 # Purpose: Syncronizes header to iheader
284 # Returns: 1 if successful, else 0.
285 ######################################################################
287 my ($header, $iheader, $copy, $ts) = @_;
288 $iheader =~ s=\\=/=g;
290 return copyFile($iheader, $header) if($copy);
293 my $header_dir = dirname($header);
294 mkpath $header_dir, !$quiet;
297 my $iheader_out = fixPaths($iheader, $header_dir);
298 open HEADER, ">$header" || die "Could not open $header for writing!\n";
299 print HEADER "#include \"$iheader_out\"\n";
302 utime(time, $ts, $header) or die "$iheader, $header";
309 ######################################################################
310 # Syntax: fixPaths(file, dir)
311 # Params: file, string, filepath to be made relative to dir
312 # dir, string, dirpath for point of origin
314 # Purpose: file is made relative (if possible) of dir.
315 # Returns: String with the above applied conversion.
316 ######################################################################
318 my ($file, $dir) = @_;
324 $ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
325 my $file_dir = dirname($file);
326 if($file_dir eq ".") {
327 $file_dir = getcwd();
328 $file_dir =~ s=\\=/=g;
330 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
335 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
336 return basename($file) if($file_dir eq $dir);
339 while ($file_dir =~ s,/[^/]+/\.\./,/,) {}
340 while ($dir =~ s,/[^/]+/\.\./,/,) {}
342 for(my $i = 1; $i < length($file_dir); $i++) {
343 my $slash = index($file_dir, "/", $i);
344 last if($slash == -1);
345 my $tmp = substr($file_dir, 0, $slash);
346 last unless($dir =~ m,^\Q$tmp\E/,);
351 my $after = substr($dir, length($match_dir));
352 my $count = ($after =~ tr,/,,);
354 for(my $i = 0; $i < $count; $i++) {
357 $ret =~ s,^\Q$match_dir\E,$dots,;
363 ######################################################################
364 # Syntax: fileContents(filename)
365 # Params: filename, string, filename of file to return contents
367 # Purpose: Get the contents of a file.
368 # Returns: String with contents of the file, or empty string if file
370 # Warning: Dies if it does exist but script cannot get read access.
371 ######################################################################
374 my $filecontents = "";
376 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
382 return $filecontents;
385 ######################################################################
386 # Syntax: fileCompare(file1, file2)
387 # Params: file1, string, filename of first file
388 # file2, string, filename of second file
390 # Purpose: Determines if files are equal, and which one is newer.
391 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
392 # is newer, 1 if file2 is newer.
393 ######################################################################
395 my ($file1, $file2) = @_;
396 my $file1contents = fileContents($file1);
397 my $file2contents = fileContents($file2);
398 if (! -e $file1) { return 1; }
399 if (! -e $file2) { return -1; }
400 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
403 ######################################################################
404 # Syntax: copyFile(file, ifile)
405 # Params: file, string, filename to create duplicate for
406 # ifile, string, destination name of duplicate
408 # Purpose: Keeps files in sync so changes in the newer file will be
409 # written to the other.
410 # Returns: 1 if files were synced, else 0.
411 # Warning: Dies if script cannot get write access.
412 ######################################################################
415 my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
416 # Bi-directional synchronization
417 open( I, "< " . $file ) || die "Could not open $file for reading";
422 if ( open(I, "< " . $ifile) ) {
425 $ifilecontents = <I>;
427 $copy = fileCompare($file, $ifile);
434 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
436 my $file_dir = dirname($file);
437 mkpath $file_dir, !$quiet unless(-e $file_dir);
438 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
441 print O $ifilecontents;
443 utime time, (stat($ifile))[9], $file;
445 } elsif ( $copy < 0 ) {
446 my $ifile_dir = dirname($ifile);
447 mkpath $ifile_dir, !$quiet unless(-e $ifile_dir);
448 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
451 print O $filecontents;
453 utime time, (stat($file))[9], $ifile;
460 ######################################################################
461 # Syntax: symlinkFile(file, ifile)
462 # Params: file, string, filename to create "symlink" for
463 # ifile, string, destination name of symlink
465 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
467 # Returns: 1 on success, else 0.
468 ######################################################################
471 my ($file,$ifile) = @_;
474 print "symlink created for $file " unless $quiet;
475 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
479 $t =~ s-^$quoted_basedir/--;
480 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
481 $file =~ s-^$quoted_basedir/-$p-;
482 print " ($file)\n" unless $quiet;
484 print "\n" unless $quiet;
485 return symlink($file, $ifile);
487 return copyFile($file, $ifile);
490 ######################################################################
491 # Syntax: findFiles(dir, match, descend)
492 # Params: dir, string, directory to search for name
493 # match, string, regular expression to match in dir
494 # descend, integer, 0 = non-recursive search
495 # 1 = recurse search into subdirectories
497 # Purpose: Finds files matching a regular expression.
498 # Returns: List of matching files.
501 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
502 # findFiles("/tmp","^#",0) - finds #* files in /tmp
503 ######################################################################
505 my ($dir,$match,$descend) = @_;
506 my ($file,$p,@files);
509 ($dir eq "") && ($dir = ".");
510 if ( opendir(D,$dir) ) {
514 ($dir =~ /\/$/) || ($dir .= "/");
516 foreach $file ( sort readdir(D) ) {
517 next if ( $file =~ /^\.\.?$/ );
519 ($file =~ /$match/) && (push @files, $p);
520 if ( $descend && -d $p && ! -l $p ) {
521 push @files, &findFiles($p,$match,$descend);
529 ######################################################################
530 # Syntax: loadSyncProfile()
532 # Purpose: Locates the sync.profile.
533 # Returns: Hashmap of module name -> directory.
534 ######################################################################
535 sub loadSyncProfile {
536 my ($srcbase, $outbase) = @_;
537 print("srcbase = $$srcbase \n");
538 print("outbase = $$outbase \n");
540 my $syncprofile = "$$srcbase/sync.profile";
542 unless ($result = do "$syncprofile") {
543 die "syncqt couldn't parse $syncprofile: $@" if $@;
544 die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
549 sub locateSyncProfile
551 my ($directory) = @_;
553 $directory = abs_path($directory);
554 while(!defined $syncprofile) {
556 if (opendir(D, $directory)) {
557 foreach my $file (sort readdir(D)) {
558 next if ($file =~ /^\.\.?$/);
559 $syncprofile = "$directory/$file" if ($file =~ /^sync\.profile$/);
560 last if (defined $syncprofile);
564 last if (defined $syncprofile || $directory eq "/" || $directory =~ /^?:[\/\\]$/);
565 $directory = dirname($directory);
570 # check if this is an in-source build, and if so use that as the basedir too
571 $basedir = locateSyncProfile($out_basedir);
573 $basedir = dirname($basedir) ;
574 $basedir =~ s=\\=/=g;
575 $quoted_basedir = "\Q$basedir";
578 # --------------------------------------------------------------------
580 # --------------------------------------------------------------------
587 my $arg = shift @ARGV;
588 if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
591 } elsif($arg eq "-copy") {
594 } elsif($arg eq "-o" || $arg eq "-outdir") {
597 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
598 $arg eq "-relative" || $arg eq "-check-includes") {
599 $var = substr($arg, 1);
601 } elsif($arg eq "-module-fwd") {
604 } elsif($arg eq "-cache-module-fwd") {
605 $var = "cache_module_fwd";
607 } elsif($arg eq "-developer-build") {
608 $var = "developer_build";
610 } elsif($arg eq "-no-module-version-header") {
611 $var = "no_module_version_header";
613 } elsif($arg =~ /^-no-(.*)$/) {
616 #these are for commandline compat
617 } elsif($arg eq "-inc") {
620 } elsif($arg eq "-module") {
623 } elsif($arg eq "-separate-module") {
624 $var = "separate-module";
626 } elsif($arg eq "-show") {
629 } elsif($arg eq "-quiet") {
632 } elsif($arg eq "-private") {
633 $var = "create_private_headers";
635 } elsif($arg eq "-qtdir") {
638 } elsif($arg eq "-base-dir") {
639 # skip, it's been dealt with at the top of the file
642 } elsif($arg =~/^-/) {
643 print "Unknown option: $arg\n\n" if(!$var);
646 $basedir = locateSyncProfile($arg);
647 die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
648 $basedir = dirname($basedir);
649 $basedir =~ s=\\=/=g;
650 $quoted_basedir = "\Q$basedir";
655 if(!$var || $var eq "show_help") {
656 print "Unknown option: $arg\n\n" if(!$var);
658 } elsif ($var eq "copy") {
664 } elsif ($var eq "showonly") {
670 } elsif ($var eq "quiet") {
676 } elsif ($var eq "check-includes") {
679 } elsif($check_includes) {
682 } elsif ($var eq "remove-stale") {
685 } elsif($remove_stale) {
688 } elsif ($var eq "windows") {
691 } elsif($force_win) {
694 } elsif ($var eq "relative") {
697 } elsif($force_relative) {
700 } elsif ($var eq "module") {
701 print "module :$val:\n" unless $quiet;
702 die "No such module: $val" unless(defined $modules{$val});
703 push @modules_to_sync, $val;
704 } elsif ($var eq "separate-module") {
705 my ($module, $prodir, $headerdir) = split(/:/, $val);
706 $modules{$module} = $prodir;
707 push @modules_to_sync, $module;
708 $moduleheaders{$module} = $headerdir;
709 $create_uic_class_map = 0;
710 } elsif ($var eq "qtdir") {
713 $qtbasedir =~ s=\\=/=g;
715 die "The -qtdir option requires an argument";
717 } elsif ($var eq "module_fwd") {
719 } elsif ($var eq "cache_module_fwd") {
720 $cache_module_fwd = 1;
721 } elsif ($var eq "developer_build") {
722 $developer_build = 1;
723 } elsif ($var eq "no_module_version_header") {
724 $no_module_version_header = 1;
725 } elsif ($var eq "output") {
727 if(checkRelative($outdir)) {
728 $out_basedir = getcwd();
730 $out_basedir .= "/" . $outdir;
732 $out_basedir = $outdir;
735 $out_basedir =~ s=\\=/=g;
739 # if the $qtbasedir neither has 'qtbase' somewhere in its path, nor a
740 # '.qmake.cache' file in its directory, we assume it's not a valid path
741 # (remember that a yet-to-be-built qtbase doesn't have this file either,
742 # thus the 'qtbase' path check!)
743 die "Cannot automatically detect/use provided path to QtBase's build directory!\n" .
744 "QTDIR detected/provided: " . (defined $qtbasedir ? $qtbasedir : "-none-") . "\n" .
745 "Please -qtdir option to provide the correct path.\nsyncqt failed"
746 if (!$qtbasedir || !-d "$qtbasedir/mkspecs");
748 # if we have no $basedir we cannot be sure which sources you want, so die
749 die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
751 my @ignore_headers = ();
752 my $class_lib_map_contents = "";
753 our @ignore_for_master_contents = ();
754 our @ignore_for_include_check = ();
755 our @ignore_for_qt_begin_header_check = ();
756 our @ignore_for_qt_begin_namespace_check = ();
757 our @ignore_for_qt_module_check = ();
758 my %colliding_headers = ();
759 my %inject_headers = ( "$basedir/src/corelib/global" => ( "qconfig.h" ) ); # all from build dir
761 # load the module's sync.profile here, before we can
762 loadSyncProfile(\$basedir, \$out_basedir);
764 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
766 $isunix = checkUnix; #cache checkUnix
769 mkpath "$out_basedir/include", !$quiet;
770 mkpath "$out_basedir/include/Qt", !$quiet;
773 foreach my $lib (@modules_to_sync) {
775 my $dir = $modules{$lib};
776 my $module_version = "";
777 my $module_major_version = "";
778 my $module_minor_version = "";
779 my $module_patch_version = "";
781 if (-e "$modulepris{$lib}") {
782 my $content = fileContents($modulepris{$lib});
783 my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
785 # We only pick the first one, since each module need a separate .pri file
786 $module_version = $version_rows[0];
787 chomp $module_version;
788 $module_version =~ s/^\s*QT\..*\.VERSION\s*=\s*([^#]+).*$/$1/;
789 $module_version =~ s/\s+$//;
790 my @versions = split(/\./, $module_version);
791 $module_major_version = $versions[0];
792 chomp $module_major_version;
793 $module_minor_version = $versions[1];
794 chomp $module_minor_version;
795 $module_patch_version = $versions[2];
796 chomp $module_patch_version;
799 print "WARNING: Module $lib\'s pri missing QT.<module>.VERSION variable! Private headers not versioned!\n" if (!$module_version);
801 my $pathtoheaders = "";
802 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
804 #information used after the syncing
805 my $pri_install_classes = "";
806 my $pri_install_files = "";
807 my $pri_install_pfiles = "";
809 my $libcapitals = $lib;
810 $libcapitals =~ y/a-z/A-Z/;
811 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
814 if(-e "$dir/" . basename($dir) . ".pro") {
815 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
816 while(my $line = <F>) {
818 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
819 foreach(split(/ /, $1)) {
821 my $content = $mastercontent{$_};
822 $master_contents .= $content if ($content);
830 #remove the old files
832 my @subdirs = ("$out_basedir/include/$lib");
833 foreach my $subdir (@subdirs) {
834 if (opendir DIR, $subdir) {
835 while(my $t = readdir(DIR)) {
836 my $file = "$subdir/$t";
838 push @subdirs, $file unless($t eq "." || $t eq "..");
841 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
842 foreach my $file (@files) {
844 if(open(F, "<$file")) {
845 while(my $line = <F>) {
847 if($line =~ /^\#include \"([^\"]*)\"$/) {
849 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
850 $remove_file = 1 unless(-e $include);
857 unlink $file if($remove_file);
868 # create the version header files for each module
869 unless ($no_module_version_header) {
870 my $modulepri = $modulepris{$lib};
872 my $modulepriname = basename($modulepri);
873 my $moduleversionheader = "$modules{$lib}/" . lc($lib) . "version.h";
874 my $modulehexstring = sprintf("0x%02X%02X%02X", int($module_major_version), int($module_minor_version), int($module_patch_version));
875 open MODULE_VERSION_HEADER_FILE, ">$moduleversionheader";
876 print MODULE_VERSION_HEADER_FILE "/* This file was generated by syncqt with the info from sync.profile. */\n";
877 print MODULE_VERSION_HEADER_FILE "#ifndef QT_". uc($lib) . "_VERSION_H\n";
878 print MODULE_VERSION_HEADER_FILE "#define QT_". uc($lib) . "_VERSION_H\n";
879 print MODULE_VERSION_HEADER_FILE "\n";
880 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION_STR \"" . $module_version . "\"\n";
881 print MODULE_VERSION_HEADER_FILE "\n";
882 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION $modulehexstring\n", ;
883 print MODULE_VERSION_HEADER_FILE "\n";
884 print MODULE_VERSION_HEADER_FILE "#endif // QT_". uc($lib) . "_VERSION_H\n";
885 } elsif ($modulepri) {
886 print "WARNING: Module $lib\'s pri file '$modulepri' not found.\nSkipped creating module version header for $lib.\n";
891 foreach my $current_dir (split(/;/, $dir)) {
892 my $headers_dir = $current_dir;
893 $headers_dir .= "/$pathtoheaders" if ($pathtoheaders);
895 my @subdirs = ($headers_dir);
896 foreach my $subdir (@subdirs) {
897 opendir DIR, $subdir or next;
898 while(my $t = readdir(DIR)) {
899 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
900 !($t eq "..") && !($t eq ".obj") &&
901 !($t eq ".moc") && !($t eq ".rcc") &&
902 !($t eq ".uic") && !($t eq "build"));
907 #calc files and "copy" them
908 foreach my $subdir (@subdirs) {
909 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
910 if (defined $inject_headers{$subdir}) {
911 foreach my $if ($inject_headers{$subdir}) {
912 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
913 push @headers, "*".$if;
916 foreach my $header (@headers) {
917 my $shadow = ($header =~ s/^\*//);
918 $header = 0 if($header =~ /^ui_.*.h/);
919 foreach (@ignore_headers) {
920 $header = 0 if($header eq $_);
923 my $header_copies = 0;
924 #figure out if it is a public header
925 my $public_header = $header;
926 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
929 foreach (@ignore_for_master_contents) {
930 $public_header = 0 if($header eq $_);
934 my $iheader = $subdir . "/" . $header;
935 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
936 my @classes = $public_header ? classNames($iheader) : ();
938 print "$header [$lib]\n";
940 print "SYMBOL: $_\n";
943 my $ts = (stat($iheader))[9];
944 #find out all the places it goes..
946 if ($public_header) {
947 @headers = ( "$out_basedir/include/$lib/$header" );
949 # write forwarding headers to include/Qt
950 if ($lib ne "phonon" && $subdir =~ /^$quoted_basedir\/src/) {
951 my $file_name = "$out_basedir/include/Qt/$header";
953 my $header_content = '';
954 if (exists $colliding_headers{$file_name}) {
957 $colliding_headers{$file_name} = 1;
958 my $warning_msg = 'Inclusion of header files from include/Qt is deprecated.';
959 $header_content = "#ifndef QT_NO_QT_INCLUDE_WARN\n" .
960 " #if defined(__GNUC__)\n" .
961 " #warning \"$warning_msg\"\n" .
962 " #elif defined(_MSC_VER)\n" .
963 " #pragma message(\"WARNING: $warning_msg\")\n" .
967 $header_content .= '#include "' . "../$lib/$header" . "\"\n";
968 open HEADERFILE, $file_op, $file_name or die "unable to open '$file_name' : $!\n";
969 print HEADERFILE $header_content;
973 foreach my $full_class (@classes) {
974 my $header_base = basename($header);
976 my $class = $full_class;
978 # if ($class =~ m/::/) {
981 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
982 $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
984 # KDE-Compat headers for Phonon
985 if ($lib eq "phonon") {
986 $header_copies++ if (syncHeader("$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
989 } elsif ($create_private_headers) {
990 if ($module_version) {
991 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
993 @headers = ( "$out_basedir/include/$lib/private/$header" );
996 foreach(@headers) { #sync them
997 $header_copies++ if(syncHeader($_, $iheader, $copy_headers && !$shadow, $ts));
1000 if($public_header) {
1001 #put it into the master file
1002 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
1004 #deal with the install directives
1005 if($public_header) {
1006 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1007 foreach my $class (@classes) {
1009 $class =~ s/^.*:://;
1010 # if ($class =~ m/::/) {
1011 # $class =~ s,::,/,g;
1013 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
1014 $current_dir) . " ";
1015 $pri_install_classes .= $class_header
1016 unless($pri_install_classes =~ $class_header);
1018 $pri_install_files.= "$pri_install_iheader ";;
1022 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1023 $pri_install_pfiles.= "$pri_install_iheader ";;
1026 print "header created for $iheader ($header_copies)\n" if($header_copies > 0 && !$quiet);
1032 # close the master include:
1033 $master_contents .= "#endif\n";
1036 my @master_includes;
1037 push @master_includes, "$out_basedir/include/$lib/$lib";
1038 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
1039 foreach my $master_include (@master_includes) {
1040 #generate the "master" include file
1041 my @tmp = split(/;/,$modules{$lib});
1042 $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
1043 if($master_include && -e $master_include) {
1044 open MASTERINCLUDE, "<$master_include";
1046 binmode MASTERINCLUDE;
1047 my $oldmaster = <MASTERINCLUDE>;
1048 close MASTERINCLUDE;
1049 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1050 $master_include = 0 if($oldmaster eq $master_contents);
1052 if($master_include && $master_contents) {
1053 my $master_dir = dirname($master_include);
1054 mkpath $master_dir, !$quiet;
1055 print "header (master) created for $lib\n" unless $quiet;
1056 open MASTERINCLUDE, ">$master_include";
1057 print MASTERINCLUDE $master_contents;
1058 close MASTERINCLUDE;
1062 #handle the headers.pri for each module
1063 my $headers_pri_contents = "";
1064 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1065 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1066 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1067 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1068 if(-e $headers_pri_file) {
1069 open HEADERS_PRI_FILE, "<$headers_pri_file";
1071 binmode HEADERS_PRI_FILE;
1072 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1073 close HEADERS_PRI_FILE;
1074 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1075 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1077 if($headers_pri_file && $master_contents) {
1078 my $headers_pri_dir = dirname($headers_pri_file);
1079 mkpath $headers_pri_dir, !$quiet;
1080 print "headers.pri file created for $lib\n" unless $quiet;
1081 open HEADERS_PRI_FILE, ">$headers_pri_file";
1082 print HEADERS_PRI_FILE $headers_pri_contents;
1083 close HEADERS_PRI_FILE;
1086 # create forwarding module pri in qtbase/mkspecs/modules
1088 my $modulepri = $modulepris{$lib};
1089 if (-e $modulepri) {
1090 my $modulepriname = basename($modulepri);
1091 mkpath($module_fwd);
1092 my $moduleprifwd = "$module_fwd/$modulepriname";
1093 my $mod_base = $developer_build ? $basedir : $out_basedir;
1094 my $mod_component_base = $developer_build ? $qtbasedir : $out_basedir;
1095 open MODULE_PRI_FILE, ">$moduleprifwd" or die("Could not open $moduleprifwd for writing");
1096 print MODULE_PRI_FILE "QT_MODULE_BASE = $mod_base\n";
1097 print MODULE_PRI_FILE "QT_MODULE_BIN_BASE = $mod_component_base/bin\n";
1098 print MODULE_PRI_FILE "QT_MODULE_INCLUDE_BASE = $out_basedir/include\n";
1099 print MODULE_PRI_FILE "QT_MODULE_IMPORT_BASE = $mod_component_base/imports\n";
1100 print MODULE_PRI_FILE "QT_MODULE_LIB_BASE = $mod_component_base/lib\n";
1101 print MODULE_PRI_FILE "QT_MODULE_PLUGIN_BASE = $mod_component_base/plugins\n";
1102 print MODULE_PRI_FILE "include($modulepri)\n";
1103 close MODULE_PRI_FILE;
1104 utime(time, (stat($modulepri))[9], $moduleprifwd);
1105 if ($cache_module_fwd) {
1106 my $cacheStatement = "QMAKE_EXTRA_MODULE_FORWARDS = \"$module_fwd\"";
1107 my $cacheFile = "$out_basedir/.qmake.cache";
1108 my $existingQmakeCache = fileContents($cacheFile);
1109 # Skip if it's already there.
1110 if ($existingQmakeCache !~ $cacheStatement) {
1111 open QMAKE_CACHE_FILE, ">>$cacheFile" or die("Could not open $cacheFile for writing");
1112 print QMAKE_CACHE_FILE "$cacheStatement\n";
1113 close(QMAKE_CACHE_FILE);
1116 } elsif ($modulepri) {
1117 print "WARNING: Module $lib\'s pri file '$modulepri' not found.\nSkipped creating forwarding pri for $lib.\n";
1122 unless($showonly || !$create_uic_class_map) {
1123 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1124 if(-e $class_lib_map) {
1125 open CLASS_LIB_MAP, "<$class_lib_map";
1127 binmode CLASS_LIB_MAP;
1128 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1129 close CLASS_LIB_MAP;
1130 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1131 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1133 if($class_lib_map) {
1134 my $class_lib_map_dir = dirname($class_lib_map);
1135 mkpath $class_lib_map_dir, !$quiet;
1136 open CLASS_LIB_MAP, ">$class_lib_map";
1137 print CLASS_LIB_MAP $class_lib_map_contents;
1138 close CLASS_LIB_MAP;
1142 if($check_includes) {
1143 for my $lib (keys(%modules)) {
1145 my @subdirs = ($modules{$lib});
1146 foreach my $subdir (@subdirs) {
1147 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
1148 while(my $t = readdir(DIR)) {
1149 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
1150 !($t eq "..") && !($t eq ".obj") &&
1151 !($t eq ".moc") && !($t eq ".rcc") &&
1152 !($t eq ".uic") && !($t eq "build"));
1157 foreach my $subdir (@subdirs) {
1158 my $header_skip_qt_module_test = 0;
1159 foreach(@ignore_for_qt_module_check) {
1160 foreach (split(/;/, $_)) {
1161 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1164 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1165 foreach my $header (@headers) {
1166 my $header_skip_qt_begin_header_test = 0;
1167 my $header_skip_qt_begin_namespace_test = 0;
1168 $header = 0 if($header =~ /^ui_.*.h/);
1169 foreach (@ignore_headers) {
1170 $header = 0 if($header eq $_);
1173 my $public_header = $header;
1174 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1177 foreach (@ignore_for_master_contents) {
1178 $public_header = 0 if($header eq $_);
1180 if($public_header) {
1181 foreach (@ignore_for_include_check) {
1182 $public_header = 0 if($header eq $_);
1184 foreach(@ignore_for_qt_begin_header_check) {
1185 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1187 foreach(@ignore_for_qt_begin_namespace_check) {
1188 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1193 my $iheader = $subdir . "/" . $header;
1194 if($public_header) {
1195 if(open(F, "<$iheader")) {
1196 my $qt_module_found = 0;
1197 my $qt_begin_header_found = 0;
1198 my $qt_end_header_found = 0;
1199 my $qt_begin_namespace_found = 0;
1200 my $qt_end_namespace_found = 0;
1202 while($line = <F>) {
1204 my $output_line = 1;
1205 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1207 } elsif($line =~ /^ *\# *include/) {
1208 my $include = $line;
1209 if($line =~ /<.*>/) {
1210 $include =~ s,.*<(.*)>.*,$1,;
1211 } elsif($line =~ /".*"/) {
1212 $include =~ s,.*"(.*)".*,$1,;
1217 for my $trylib (keys(%modules)) {
1218 if(-e "$out_basedir/include/$trylib/$include") {
1219 print "WARNING: $iheader includes $include when it should include $trylib/$include\n";
1223 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1224 $qt_begin_header_found = 1;
1225 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1226 $qt_end_header_found = 1;
1227 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1228 $qt_begin_namespace_found = 1;
1229 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1230 $qt_end_namespace_found = 1;
1231 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1232 $qt_module_found = 1;
1235 if ($header_skip_qt_begin_header_test == 0) {
1236 if ($qt_begin_header_found == 0) {
1237 print "WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1240 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1241 print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1245 if ($header_skip_qt_begin_namespace_test == 0) {
1246 if ($qt_begin_namespace_found == 0) {
1247 print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1250 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1251 print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1255 if ($header_skip_qt_module_test == 0) {
1256 if ($qt_module_found == 0) {
1257 print "WARNING: $iheader does not include QT_MODULE\n";