2 #############################################################################
4 ## Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ## All rights reserved.
6 ## Contact: Nokia Corporation (qt-info@nokia.com)
8 ## This file is part of the build configuration tools of the Qt Toolkit.
10 ## $QT_BEGIN_LICENSE:LGPL$
11 ## GNU Lesser General Public License Usage
12 ## This file may be used under the terms of the GNU Lesser General Public
13 ## License version 2.1 as published by the Free Software Foundation and
14 ## appearing in the file LICENSE.LGPL included in the packaging of this
15 ## file. Please review the following information to ensure the GNU Lesser
16 ## General Public License version 2.1 requirements will be met:
17 ## http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ## In addition, as a special exception, Nokia gives you certain additional
20 ## rights. These rights are described in the Nokia Qt LGPL Exception
21 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
23 ## GNU General Public License Usage
24 ## Alternatively, this file may be used under the terms of the GNU General
25 ## Public License version 3.0 as published by the Free Software Foundation
26 ## and appearing in the file LICENSE.GPL included in the packaging of this
27 ## file. Please review the following information to ensure the GNU General
28 ## Public License version 3.0 requirements will be met:
29 ## http://www.gnu.org/copyleft/gpl.html.
32 ## Alternatively, this file may be used in accordance with the terms and
33 ## conditions contained in a signed written agreement between you and Nokia.
41 #############################################################################
44 # Synchronizes Qt header files - internal development tool.
47 # use packages -------------------------------------------------------
54 use English qw(-no_match_vars );
56 # set output basedir to be where ever syncqt is run from
57 our $out_basedir = getcwd();
58 $out_basedir =~ s=\\=/=g;
63 # try to figure out where QtBase is located
64 # normally the script location should be enough, if not fall back to
65 # QTDIR environment variable. If that doesn't work, later ask the
66 # user to use the -qtdir option explicitly.
67 my $qtbasedir = $ENV{"QTDIR"};
68 $qtbasedir = dirname(dirname($0)) if (!$qtbasedir);
69 $qtbasedir =~ s=\\=/=g if (defined $qtbasedir);
71 # will be defined based on the modules sync.profile
72 our (%modules, %moduleheaders, @allmoduleheadersprivate, %classnames, %mastercontent, %modulepris, %explicitheaders, %deprecatedheaders);
74 # global variables (modified by options)
78 my $verbose_level = 1;
81 my $force_relative = 0;
82 my $check_includes = 0;
84 my $create_uic_class_map = 0;
85 my $create_private_headers = 1;
87 my $cache_module_fwd = 0;
88 my $developer_build = 0;
89 my $no_module_version_header = 0;
90 my $makefile_generator = "";
92 $force_relative = 1 if ( -d "/System/Library/Frameworks" );
95 # functions ----------------------------------------------------------
97 ######################################################################
101 # Purpose: Show the usage of the script.
103 ######################################################################
107 print " <module directory> Specifies which module to sync header files for (required for shadow builds!)\n\n";
109 print " -copy Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n";
110 print " -remove-stale Removes stale headers (default: " . ($remove_stale ? "yes" : "no") . ")\n";
111 print " -relative Force relative symlinks (default: " . ($force_relative ? "yes" : "no") . ")\n";
112 print " -windows Force platform to Windows (default: " . ($force_win ? "yes" : "no") . ")\n";
113 print " -showonly Show action but not perform (default: " . ($showonly ? "yes" : "no") . ")\n";
114 print " -outdir <PATH> Specify output directory for sync (default: $out_basedir)\n";
115 print " -qtdir <PATH> Set the path to QtBase (detected: " . (defined $qtbasedir ? $qtbasedir : "-none-") . ")\n";
116 print " -quiet Only report problems, not activity (same as -verbose 0)\n";
117 print " -v, -verbose <level> Sets the verbosity level (max. 4) (default: $verbose_level)\n";
118 print " The short form increases the level by +1\n";
119 print " -separate-module <NAME>:<PROFILEDIR>:<HEADERDIR>\n";
120 print " Create headers for <NAME> with original headers in\n";
121 print " <HEADERDIR> relative to <PROFILEDIR> \n";
122 print " -private Force copy private headers (default: " . ($create_private_headers ? "yes" : "no") . ")\n";
123 print " -module-fwd <PATH> Create fwd includes for module pri files in the given\n";
124 print " path (default: none)\n";
125 print " -cache-module-fwd Create a .qmake.cache file to cache the location of the\n";
126 print " fwd includes\n";
127 print " -developer-build Point libraries and binaries to a common directory for\n";
128 print " easy development\n";
129 print " -no-module-version-header\n";
130 print " Don't create module version header file\n";
131 print " -generator <PATH> Specify the makefile generator setting (e.g. 'UNIX')\n";
132 print " -help This help\n";
136 ######################################################################
137 # Syntax: checkUnix()
140 # Purpose: Check if script runs on a Unix system or not. Cygwin
141 # systems are _not_ detected as Unix systems.
142 # Returns: 1 if a unix system, else 0.
143 ######################################################################
146 if ( $force_win != 0) {
148 } elsif ( -f "/bin/uname" ) {
150 (-f "\\bin\\uname") && ($r = 0);
151 } elsif ( -f "/usr/bin/uname" ) {
153 (-f "\\usr\\bin\\uname") && ($r = 0);
156 $_ = $Config{'osname'};
157 $r = 0 if( /(ms)|(cyg)win/i );
164 return 0 if($dir =~ /^\//);
165 return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/);
169 ######################################################################
170 # Syntax: shouldMasterInclude(iheader)
171 # Params: iheader, string, filename to verify inclusion
173 # Purpose: Determines if header should be in the master include file.
174 # Returns: 0 if file contains "#pragma qt_no_master_include" or not
175 # able to open, else 1.
176 ######################################################################
177 sub shouldMasterInclude {
179 return 0 if(basename($iheader) =~ /_/);
180 return 0 if(basename($iheader) =~ /qconfig/);
181 if(open(F, "<$iheader")) {
184 return 0 if(/^\#pragma qt_no_master_include$/);
193 ######################################################################
194 # Syntax: classNames(iheader)
195 # Params: iheader, string, filename to parse for classname "symlinks"
197 # Purpose: Scans through iheader to find all classnames that should be
198 # synced into library's include structure.
199 # Returns: List of all class names in a file.
200 ######################################################################
205 my $classname = $classnames{basename($iheader)};
206 push @ret, $classname if ($classname);
209 if(open(F, "<$iheader")) {
213 chop $line if ($line =~ /\r$/);
218 last unless($line =~ /\\$/);
221 return @ret if($line =~ m/^#pragma qt_sync_stop_processing/);
222 push(@ret, $1) if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/);
226 $line =~ s,//.*$,,; #remove c++ comments
227 $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro
228 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro
229 $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro
230 $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro
231 $parsable .= " " . $line;
237 my $last_definition = 0;
239 for(my $i = 0; $i < length($parsable); $i++) {
241 my $character = substr($parsable, $i, 1);
242 if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons
243 for($i+=2; $i < length($parsable); $i++) {
244 my $end = substr($parsable, $i, 2);
246 $last_definition = $i+2;
251 } elsif($character eq "{") {
253 my $block_start = $i + 1;
254 BLOCK: for($i+=1; $i < length($parsable); $i++) {
255 my $ignore = substr($parsable, $i, 1);
258 } elsif($ignore eq "}") {
260 unless($brace_depth) {
261 for(my $i2 = $i+1; $i2 < length($parsable); $i2++) {
262 my $end = substr($parsable, $i2, 1);
263 if($end eq ";" || $end ne " ") {
264 $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}";
265 $i = $i2 if($end eq ";");
266 $last_definition = $i + 1;
273 } elsif($character eq ";") {
274 $definition = substr($parsable, $last_definition, $i - $last_definition + 1);
275 $last_definition = $i + 1;
276 } elsif($character eq "}") {
277 # a naked } must be a namespace ending
278 # if it's not a namespace, it's eaten by the loop above
280 $last_definition = $i + 1;
283 if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) /
284 && substr($parsable, $i+1, 1) eq "{") {
285 push @namespaces, $1;
287 # Eat the opening { so that the condensing loop above doesn't see it
289 $last_definition = $i + 1;
293 $definition =~ s=[\n\r]==g;
295 if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) {
297 } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) {
299 } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) {
301 } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) {
302 push @symbols, "Q" . $1 . "Iterator";
303 push @symbols, "QMutable" . $1 . "Iterator";
306 foreach my $symbol (@symbols) {
307 $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces);
309 if ($symbol =~ /^Q[^:]*$/ # no-namespace, starting with Q
310 || $symbol =~ /^Phonon::/); # or in the Phonon namespace
318 my ($dir, $lib, $be_verbose) = @_;
321 $dir = "<outbase>" . substr($dir, length($out_basedir)) if ($be_verbose < 3);
322 print "$lib: mkpath $dir\n" if ($be_verbose > 1);
326 ######################################################################
327 # Syntax: syncHeader(header, iheader, copy, timestamp)
328 # Params: header, string, filename to create "symlink" for
329 # iheader, string, destination name of symlink
330 # copy, forces header to be a copy of iheader
331 # timestamp, the requested modification time if copying
333 # Purpose: Syncronizes header to iheader
334 # Returns: 1 if successful, else 0.
335 ######################################################################
337 my ($lib, $header, $iheader, $copy, $ts) = @_;
338 $iheader =~ s=\\=/=g;
340 return copyFile($lib, $iheader, $header) if($copy);
343 my $header_dir = dirname($header);
344 make_path($header_dir, $lib, $verbose_level);
347 my $iheader_out = fixPaths($iheader, $header_dir);
348 open HEADER, ">$header" || die "Could not open $header for writing!\n";
349 print HEADER "#include \"$iheader_out\"\n";
352 utime(time, $ts, $header) or die "$iheader, $header";
359 ######################################################################
360 # Syntax: fixPaths(file, dir)
361 # Params: file, string, filepath to be made relative to dir
362 # dir, string, dirpath for point of origin
364 # Purpose: file is made relative (if possible) of dir.
365 # Returns: String with the above applied conversion.
366 ######################################################################
368 my ($file, $dir) = @_;
374 $ret =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
375 my $file_dir = dirname($file);
376 if($file_dir eq ".") {
377 $file_dir = getcwd();
378 $file_dir =~ s=\\=/=g;
380 $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
385 $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g;
386 return basename($file) if($file_dir eq $dir);
389 while ($file_dir =~ s,/[^/]+/\.\./,/,) {}
390 while ($dir =~ s,/[^/]+/\.\./,/,) {}
392 for(my $i = 1; $i < length($file_dir); $i++) {
393 my $slash = index($file_dir, "/", $i);
394 last if($slash == -1);
395 my $tmp = substr($file_dir, 0, $slash);
396 last unless($dir =~ m,^\Q$tmp\E/,);
401 my $after = substr($dir, length($match_dir));
402 my $count = ($after =~ tr,/,,);
404 for(my $i = 0; $i < $count; $i++) {
407 $ret =~ s,^\Q$match_dir\E,$dots,;
413 ######################################################################
414 # Syntax: fileContents(filename)
415 # Params: filename, string, filename of file to return contents
417 # Purpose: Get the contents of a file.
418 # Returns: String with contents of the file, or empty string if file
420 # Warning: Dies if it does exist but script cannot get read access.
421 ######################################################################
424 my $filecontents = "";
426 open(I, "< $filename") || die "Could not open $filename for reading, read block?";
432 return $filecontents;
435 ######################################################################
436 # Syntax: fileCompare(file1, file2)
437 # Params: file1, string, filename of first file
438 # file2, string, filename of second file
440 # Purpose: Determines if files are equal, and which one is newer.
441 # Returns: 0 if files are equal no matter the timestamp, -1 if file1
442 # is newer, 1 if file2 is newer.
443 ######################################################################
445 my ($file1, $file2) = @_;
446 my $file1contents = fileContents($file1);
447 my $file2contents = fileContents($file2);
448 if (! -e $file1) { return 1; }
449 if (! -e $file2) { return -1; }
450 return $file1contents ne $file2contents ? (stat($file2))[9] <=> (stat($file1))[9] : 0;
453 ######################################################################
454 # Syntax: copyFile(file, ifile)
455 # Params: file, string, filename to create duplicate for
456 # ifile, string, destination name of duplicate
458 # Purpose: Keeps files in sync so changes in the newer file will be
459 # written to the other.
460 # Returns: 1 if files were synced, else 0.
461 # Warning: Dies if script cannot get write access.
462 ######################################################################
465 my ($lib, $file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_;
466 # Bi-directional synchronization
467 open( I, "< " . $file ) || die "Could not open $file for reading";
472 if ( open(I, "< " . $ifile) ) {
475 $ifilecontents = <I>;
477 $copy = fileCompare($file, $ifile);
484 if ( $knowdiff || ($filecontents ne $ifilecontents) ) {
486 my $file_dir = dirname($file);
487 make_path($file_dir, $lib, $verbose_level);
488 open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)";
491 print O $ifilecontents;
493 utime time, (stat($ifile))[9], $file;
495 } elsif ( $copy < 0 ) {
496 my $ifile_dir = dirname($ifile);
497 make_path($ifile_dir, $lib, $verbose_level);
498 open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)";
501 print O $filecontents;
503 utime time, (stat($file))[9], $ifile;
510 ######################################################################
511 # Syntax: symlinkFile(file, ifile)
512 # Params: file, string, filename to create "symlink" for
513 # ifile, string, destination name of symlink
515 # Purpose: File is symlinked to ifile (or copied if filesystem doesn't
517 # Returns: 1 on success, else 0.
518 ######################################################################
521 my ($lib, $file, $ifile) = @_;
524 print "$lib: symlink created for $file " if ($verbose_level);
525 if ( $force_relative && ($ifile =~ /^$quoted_basedir/)) {
529 $t =~ s-^$quoted_basedir/--;
530 $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 );
531 $file =~ s-^$quoted_basedir/-$p-;
532 print " ($file)\n" if($verbose_level);
534 print "\n" if($verbose_level);
535 return symlink($file, $ifile);
537 return copyFile($lib, $file, $ifile);
540 ######################################################################
541 # Syntax: findFiles(dir, match, descend)
542 # Params: dir, string, directory to search for name
543 # match, string, regular expression to match in dir
544 # descend, integer, 0 = non-recursive search
545 # 1 = recurse search into subdirectories
547 # Purpose: Finds files matching a regular expression.
548 # Returns: List of matching files.
551 # findFiles("/usr","\.cpp$",1) - finds .cpp files in /usr and below
552 # findFiles("/tmp","^#",0) - finds #* files in /tmp
553 ######################################################################
555 my ($dir,$match,$descend) = @_;
556 my ($file,$p,@files);
559 ($dir eq "") && ($dir = ".");
560 if ( opendir(D,$dir) ) {
564 ($dir =~ /\/$/) || ($dir .= "/");
566 foreach $file ( sort readdir(D) ) {
567 next if ( $file =~ /^\.\.?$/ );
569 ($file =~ /$match/) && (push @files, $p);
570 if ( $descend && -d $p && ! -l $p ) {
571 push @files, &findFiles($p,$match,$descend);
579 ######################################################################
580 # Syntax: loadSyncProfile()
582 # Purpose: Locates the sync.profile.
583 # Returns: Hashmap of module name -> directory.
584 ######################################################################
585 sub loadSyncProfile {
586 my ($srcbase, $outbase) = @_;
587 if ($verbose_level) {
588 print("<srcbase> = $$srcbase \n");
589 print("<outbase> = $$outbase \n");
592 my $syncprofile = "$$srcbase/sync.profile";
594 unless ($result = do "$syncprofile") {
595 die "syncqt couldn't parse $syncprofile: $@" if $@;
596 die "syncqt couldn't execute $syncprofile: $!" unless defined $result;
601 sub locateSyncProfile
603 my ($directory) = @_;
605 $directory = abs_path($directory);
606 while(!defined $syncprofile) {
608 if (opendir(D, $directory)) {
609 foreach my $file (sort readdir(D)) {
610 next if ($file =~ /^\.\.?$/);
611 $syncprofile = "$directory/$file" if ($file =~ /^sync\.profile$/);
612 last if (defined $syncprofile);
616 last if (defined $syncprofile || $directory eq "/" || $directory =~ /^?:[\/\\]$/);
617 $directory = dirname($directory);
622 # check if this is an in-source build, and if so use that as the basedir too
623 $basedir = locateSyncProfile($out_basedir);
625 $basedir = dirname($basedir) ;
626 $basedir =~ s=\\=/=g;
627 $quoted_basedir = "\Q$basedir";
630 # --------------------------------------------------------------------
632 # --------------------------------------------------------------------
639 my $arg = shift @ARGV;
640 if ($arg eq "-h" || $arg eq "-help" || $arg eq "-?" || $arg eq "?") {
643 } elsif($arg eq "-copy") {
646 } elsif($arg eq "-o" || $arg eq "-outdir") {
649 } elsif($arg eq "-showonly" || $arg eq "-remove-stale" || $arg eq "-windows" ||
650 $arg eq "-relative" || $arg eq "-check-includes") {
651 $var = substr($arg, 1);
653 } elsif($arg eq "-module-fwd") {
656 } elsif($arg eq "-cache-module-fwd") {
657 $var = "cache_module_fwd";
659 } elsif($arg eq "-developer-build") {
660 $var = "developer_build";
662 } elsif($arg eq "-no-module-version-header") {
663 $var = "no_module_version_header";
665 } elsif($arg =~ /^-no-(.*)$/) {
668 #these are for commandline compat
669 } elsif($arg eq "-inc") {
672 } elsif($arg eq "-module") {
675 } elsif($arg eq "-separate-module") {
676 $var = "separate-module";
678 } elsif($arg eq "-show") {
681 } elsif($arg eq "-quiet") {
684 } elsif($arg eq "-v") {
687 } elsif($arg eq "-verbose") {
690 } elsif($arg eq "-private") {
691 $var = "create_private_headers";
693 } elsif($arg eq "-qtdir") {
696 } elsif($arg eq "-base-dir") {
697 # skip, it's been dealt with at the top of the file
700 } elsif($arg eq "-generator") {
701 $var = "makefile_generator";
703 } elsif($arg =~/^-/) {
704 print "Unknown option: $arg\n\n" if(!$var);
707 $basedir = locateSyncProfile($arg);
708 die "Could not find a sync.profile for '$arg'\n" if (!$basedir);
709 $basedir = dirname($basedir);
710 $basedir =~ s=\\=/=g;
711 $quoted_basedir = "\Q$basedir";
716 if(!$var || $var eq "show_help") {
717 print "Unknown option: $arg\n\n" if(!$var);
719 } elsif ($var eq "copy") {
725 } elsif ($var eq "showonly") {
731 } elsif ($var eq "verbose") {
734 } elsif($val eq "no" && $verbose_level) {
737 $verbose_level = int($val);
739 } elsif ($var eq "check-includes") {
742 } elsif($check_includes) {
745 } elsif ($var eq "remove-stale") {
748 } elsif($remove_stale) {
751 } elsif ($var eq "windows") {
754 } elsif($force_win) {
757 } elsif ($var eq "relative") {
760 } elsif($force_relative) {
763 } elsif ($var eq "module") {
764 print "module :$val:\n" if($verbose_level);
765 die "No such module: $val" unless(defined $modules{$val});
766 push @modules_to_sync, $val;
767 } elsif ($var eq "separate-module") {
768 my ($module, $prodir, $headerdir) = split(/:/, $val);
769 $modules{$module} = $prodir;
770 push @modules_to_sync, $module;
771 $moduleheaders{$module} = $headerdir;
772 $create_uic_class_map = 0;
773 } elsif ($var eq "qtdir") {
776 $qtbasedir =~ s=\\=/=g;
778 die "The -qtdir option requires an argument";
780 } elsif ($var eq "module_fwd") {
782 } elsif ($var eq "cache_module_fwd") {
783 $cache_module_fwd = 1;
784 } elsif ($var eq "developer_build") {
785 $developer_build = 1;
786 } elsif ($var eq "makefile_generator") {
787 $makefile_generator = $val;
788 } elsif ($var eq "no_module_version_header") {
789 $no_module_version_header = 1;
790 } elsif ($var eq "output") {
792 if(checkRelative($outdir)) {
793 $out_basedir = getcwd();
795 $out_basedir .= "/" . $outdir;
797 $out_basedir = $outdir;
800 $out_basedir =~ s=\\=/=g;
804 # if the $qtbasedir neither has 'qtbase' somewhere in its path, nor a
805 # '.qmake.cache' file in its directory, we assume it's not a valid path
806 # (remember that a yet-to-be-built qtbase doesn't have this file either,
807 # thus the 'qtbase' path check!)
808 die "Cannot automatically detect/use provided path to QtBase's build directory!\n" .
809 "QTDIR detected/provided: " . (defined $qtbasedir ? $qtbasedir : "-none-") . "\n" .
810 "Please -qtdir option to provide the correct path.\nsyncqt failed"
811 if (!$qtbasedir || !-d "$qtbasedir/mkspecs");
813 # if we have no $basedir we cannot be sure which sources you want, so die
814 die "Could not find any sync.profile for your module!\nPass <module directory> to syncqt to sync your header files.\nsyncqt failed" if (!$basedir);
816 my $class_lib_map_contents = "";
817 our @ignore_headers = ();
818 our @ignore_for_master_contents = ();
819 our @ignore_for_include_check = ();
820 our @ignore_for_qt_begin_header_check = ();
821 our @ignore_for_qt_begin_namespace_check = ();
822 our @ignore_for_qt_module_check = ();
823 my %colliding_headers = ();
824 my %inject_headers = ( "$basedir/src/corelib/global" => ( "qconfig.h" ) ); # all from build dir
826 # load the module's sync.profile here, before we can
827 loadSyncProfile(\$basedir, \$out_basedir);
829 @modules_to_sync = keys(%modules) if($#modules_to_sync == -1);
831 my %allmoduleheadersprivate = map { $_ => 1 } @allmoduleheadersprivate;
833 $isunix = checkUnix; #cache checkUnix
835 foreach my $lib (@modules_to_sync) {
837 my $dir = $modules{$lib};
838 my $module_version = "";
839 my $module_major_version = 0;
840 my $module_minor_version = 0;
841 my $module_patch_version = 0;
843 if (-e "$modulepris{$lib}") {
844 my $content = fileContents($modulepris{$lib});
845 my @version_rows = grep(/QT\..*\.VERSION/, split('\n', $content));
847 # We only pick the first one, since each module need a separate .pri file
848 $module_version = $version_rows[0];
849 chomp $module_version;
850 $module_version =~ s/^\s*QT\..*\.VERSION\s*=\s*([^#]+).*$/$1/;
851 $module_version =~ s/\s+$//;
852 my @versions = split(/\./, $module_version);
853 $module_major_version = int($versions[0]);
854 chomp $module_major_version;
855 $module_minor_version = int($versions[1]);
856 chomp $module_minor_version;
857 $module_patch_version = int($versions[2]);
858 chomp $module_patch_version;
861 print "$lib: WARNING: Module\'s pri missing QT.<module>.VERSION variable! Private headers not versioned!\n" if (!$module_version);
863 my $pathtoheaders = "";
864 $pathtoheaders = $moduleheaders{$lib} if ($moduleheaders{$lib});
866 my $allheadersprivate = 0;
867 $allheadersprivate = 1 if $allmoduleheadersprivate{$lib};
869 #information used after the syncing
870 my $pri_install_classes = "";
871 my $pri_install_files = "";
872 my $pri_install_pfiles = "";
874 my $libcapitals = $lib;
875 $libcapitals =~ y/a-z/A-Z/;
876 my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n";
879 if(-e "$dir/" . basename($dir) . ".pro") {
880 if(open(F, "<$dir/" . basename($dir) . ".pro")) {
881 while(my $line = <F>) {
883 if($line =~ /^ *QT *\+?= *([^\r\n]*)/) {
884 foreach(split(/ /, $1)) {
886 my $content = $mastercontent{$_};
887 $master_contents .= $content if ($content);
895 #remove the old files
897 my @subdirs = ("$out_basedir/include/$lib");
898 foreach my $subdir (@subdirs) {
899 if (opendir DIR, $subdir) {
900 foreach my $t (sort readdir(DIR)) {
901 my $file = "$subdir/$t";
903 push @subdirs, $file unless($t eq "." || $t eq "..");
906 #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t");
907 foreach my $file (@files) {
909 if(open(F, "<$file")) {
910 while(my $line = <F>) {
912 if($line =~ /^\#include \"([^\"]*)\"$/) {
914 $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/");
915 $remove_file = 1 unless(-e $include);
922 unlink $file if($remove_file);
933 # create the version header files for each module
934 unless ($no_module_version_header) {
935 my $modulepri = $modulepris{$lib};
937 my $modulepriname = basename($modulepri);
938 # FIXME: this creates a file in the source location for shadow-builds
939 my $moduleversionheader = "$modules{$lib}/" . lc($lib) . "version.h";
940 my $modulehexstring = sprintf("0x%02X%02X%02X", $module_major_version, $module_minor_version, $module_patch_version);
941 open MODULE_VERSION_HEADER_FILE, ">$moduleversionheader" or die "Can't open $moduleversionheader for writing";
942 print MODULE_VERSION_HEADER_FILE "/* This file was generated by syncqt with the info from sync.profile. */\n";
943 print MODULE_VERSION_HEADER_FILE "#ifndef QT_". uc($lib) . "_VERSION_H\n";
944 print MODULE_VERSION_HEADER_FILE "#define QT_". uc($lib) . "_VERSION_H\n";
945 print MODULE_VERSION_HEADER_FILE "\n";
946 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION_STR \"" . $module_version . "\"\n";
947 print MODULE_VERSION_HEADER_FILE "\n";
948 print MODULE_VERSION_HEADER_FILE "#define " .uc($lib) . "_VERSION $modulehexstring\n", ;
949 print MODULE_VERSION_HEADER_FILE "\n";
950 print MODULE_VERSION_HEADER_FILE "#endif // QT_". uc($lib) . "_VERSION_H\n";
951 close MODULE_VERSION_HEADER_FILE;
952 $moduleversionheader = "<srcbase>" . substr($moduleversionheader, length($basedir)) if ($verbose_level < 2);
953 print "$lib: created version header $moduleversionheader\n" if($verbose_level);
954 } elsif ($modulepri) {
955 print "$lib: WARNING: Module\'s pri file '$modulepri' not found.\n$lib: Skipped creating module version header.\n";
960 foreach my $current_dir (split(/;/, $dir)) {
961 my @headers_paths = split(/;/, $pathtoheaders);
962 if (@headers_paths) {
963 @headers_paths = map { "$current_dir/$_" } @headers_paths;
965 push @headers_paths, $current_dir;
968 foreach my $headers_dir (@headers_paths) {
970 my @subdirs = ($headers_dir);
971 foreach my $subdir (@subdirs) {
972 opendir DIR, $subdir or next;
973 foreach my $t (sort readdir(DIR)) {
974 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
975 !($t eq "..") && !($t eq ".obj") &&
976 !($t eq ".moc") && !($t eq ".rcc") &&
977 !($t eq ".uic") && !($t eq "build"));
982 #calc files and "copy" them
983 foreach my $subdir (@subdirs) {
984 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
985 if (defined $inject_headers{$subdir}) {
986 foreach my $if ($inject_headers{$subdir}) {
987 @headers = grep(!/^\Q$if\E$/, @headers); #in case we configure'd previously
988 push @headers, "*".$if;
991 my $header_dirname = "";
992 foreach my $header (@headers) {
993 my $shadow = ($header =~ s/^\*//);
994 $header = 0 if($header =~ /^ui_.*.h/);
995 foreach (@ignore_headers) {
996 $header = 0 if($header eq $_);
999 my $header_copies = 0;
1000 #figure out if it is a public header
1001 my $public_header = $header;
1002 if($allheadersprivate || $public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1005 foreach (@ignore_for_master_contents) {
1006 $public_header = 0 if($header eq $_);
1010 my $iheader = $subdir . "/" . $header;
1011 $iheader =~ s/^\Q$basedir\E/$out_basedir/ if ($shadow);
1012 my @classes = $public_header ? classNames($iheader) : ();
1014 print "$header [$lib]\n";
1016 print "SYMBOL: $_\n";
1019 my $ts = (stat($iheader))[9];
1020 #find out all the places it goes..
1022 if ($public_header) {
1023 @headers = ( "$out_basedir/include/$lib/$header" );
1024 foreach my $full_class (@classes) {
1025 my $header_base = basename($header);
1027 my $class = $full_class;
1028 $class =~ s/^.*:://;
1029 # if ($class =~ m/::/) {
1030 # class =~ s,::,/,g;
1033 if (defined $explicitheaders{$lib}{$class}) {
1034 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$explicitheaders{$lib}{$class}", 0, $ts));
1036 $class_lib_map_contents .= "QT_CLASS_LIB($full_class, $lib, $header_base)\n";
1037 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0, $ts));
1040 # KDE-Compat headers for Phonon
1041 if ($lib eq "phonon") {
1042 $header_copies++ if (syncHeader($lib, "$out_basedir/include/phonon_compat/Phonon/$class", "$out_basedir/include/$lib/$header", 0, $ts));
1046 if ($explicitheaders{$lib}{basename($header)}) {
1047 $header_copies++ if(syncHeader($lib, "$out_basedir/include/$lib/$explicitheaders{$lib}{basename($header)}", "$out_basedir/include/$lib/$header", 0, $ts));
1050 } elsif ($create_private_headers) {
1051 if ($module_version) {
1052 @headers = ( "$out_basedir/include/$lib/$module_version/$lib/private/$header" );
1054 @headers = ( "$out_basedir/include/$lib/private/$header" );
1057 foreach(@headers) { #sync them
1058 $header_copies++ if(syncHeader($lib, $_, $iheader, $copy_headers && !$shadow, $ts));
1061 if($public_header) {
1062 #put it into the master file
1063 $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader));
1065 #deal with the install directives
1066 if($public_header) {
1067 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1068 foreach my $class (@classes) {
1070 $class =~ s/^.*:://;
1071 # if ($class =~ m/::/) {
1072 # $class =~ s,::,/,g;
1074 my $class_header = fixPaths("$out_basedir/include/$lib/$class",
1075 $current_dir) . " ";
1076 $pri_install_classes .= $class_header
1077 unless($pri_install_classes =~ $class_header);
1079 if ($explicitheaders{$lib}{basename($iheader)}) {
1080 my $compat_header = fixPaths("$out_basedir/include/$lib/$explicitheaders{$lib}{basename($iheader)}", $current_dir) . " ";
1081 $pri_install_files .= $compat_header unless($pri_install_files =~ $compat_header);
1083 $pri_install_files.= "$pri_install_iheader ";;
1087 my $pri_install_iheader = fixPaths($iheader, $current_dir);
1088 $pri_install_pfiles.= "$pri_install_iheader ";;
1092 if ($verbose_level && $header_copies) {
1093 my $new_header_dirname = dirname($iheader);
1094 $new_header_dirname = "<srcbase>" . substr($new_header_dirname, length($basedir)) if ($new_header_dirname && $verbose_level < 2);
1095 my $header_base = basename($iheader);
1096 if ($verbose_level < 3) {
1097 my $line_prefix = ",";
1098 if ($new_header_dirname ne $header_dirname) {
1099 $line_prefix = "$lib: created fwd-include header(s) for $new_header_dirname/ {";
1100 $line_prefix = " }\n".$line_prefix if ($header_dirname);
1101 $header_dirname = $new_header_dirname;
1105 print "$line_prefix $header_base ($header_copies)";
1106 } else { # $verbose_level >= 3
1107 $iheader = "<srcbase>" . substr($iheader, length($basedir)) if ($verbose_level == 3);
1108 print "$lib: created $header_copies fwd-include headers for $iheader\n";
1113 print " }\n" if ($header_dirname && $verbose_level > 0 && $verbose_level < 3);
1118 # close the master include:
1119 $master_contents .= "#endif\n";
1122 # create deprecated headers
1124 while (my ($header, $include) = each %{$deprecatedheaders{$lib}}) {
1125 my $public_header = 0;
1126 $public_header = 1 unless ($allheadersprivate || ($header =~ /_p\.h$/));
1127 next unless ($public_header || $create_private_headers);
1129 my $header_path = "$out_basedir/include/$lib/";
1130 unless ($public_header) {
1131 if ($module_version) {
1132 $header_path .= "$module_version/$lib/private/";
1134 $header_path .= "private/";
1137 $header_path .= "$header";
1139 unless (-e $header_path) {
1140 my $guard = "DEPRECATED_HEADER_" . $lib . "_" . $header;
1141 $guard =~ s/([^a-zA-Z0-9_])/_/g;
1143 open HEADER, ">$header_path" || die "Could not open $header_path for writing!\n";
1144 print HEADER "#ifndef $guard\n";
1145 print HEADER "#define $guard\n";
1146 my $warning = "Header <$lib/";
1147 $warning .= "private/" unless ($public_header);
1148 $warning .= "$header> is deprecated. Please include <$include> instead.";
1149 print HEADER "#if defined(__GNUC__)\n";
1150 print HEADER "# warning $warning\n";
1151 print HEADER "#elif defined(_MSC_VER)\n";
1152 print HEADER "# pragma message (\"$warning\")\n";
1153 print HEADER "#endif\n";
1154 print HEADER "#include <$include>\n";
1155 if ($public_header) {
1156 print HEADER "#if 0\n";
1157 print HEADER "#pragma qt_no_master_include\n";
1158 print HEADER "#endif\n";
1160 print HEADER "#endif\n";
1163 if ($verbose_level < 3) {
1164 my $line_prefix = ",";
1165 $line_prefix = "$lib: created deprecated header(s) {" if ($first);
1166 print "$line_prefix $header";
1168 print "$lib: created deprecated header $header => $include\n";
1171 my $addendum = fixPaths($header_path, $dir) . " ";
1172 if ($public_header) {
1173 $pri_install_files .= $addendum;
1175 $pri_install_pfiles .= $addendum;
1180 if ($verbose_level < 3) {
1181 print " }\n" unless ($first);
1184 my @master_includes;
1185 push @master_includes, "$out_basedir/include/$lib/$lib";
1186 push @master_includes, "$out_basedir/include/phonon_compat/Phonon/Phonon" if ($lib eq "phonon");
1187 foreach my $master_include (@master_includes) {
1188 #generate the "master" include file
1189 my @tmp = split(/;/,$modules{$lib});
1190 $pri_install_files .= fixPaths($master_include, $tmp[0]) . " "; #get the master file installed too
1191 if($master_include && -e $master_include) {
1192 open MASTERINCLUDE, "<$master_include";
1194 binmode MASTERINCLUDE;
1195 my $oldmaster = <MASTERINCLUDE>;
1196 close MASTERINCLUDE;
1197 $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1198 $master_include = 0 if($oldmaster eq $master_contents);
1200 if($master_include && $master_contents) {
1201 my $master_dir = dirname($master_include);
1202 make_path($master_dir, $lib, $verbose_level);
1203 open MASTERINCLUDE, ">$master_include";
1204 print MASTERINCLUDE $master_contents;
1205 close MASTERINCLUDE;
1206 print "$lib: created header (master) file\n" if($verbose_level);
1210 #handle the headers.pri for each module
1211 my $headers_pri_contents = "";
1212 $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n";
1213 $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n";
1214 $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n";
1215 my $headers_pri_file = "$out_basedir/include/$lib/headers.pri";
1216 if(-e $headers_pri_file) {
1217 open HEADERS_PRI_FILE, "<$headers_pri_file";
1219 binmode HEADERS_PRI_FILE;
1220 my $old_headers_pri_contents = <HEADERS_PRI_FILE>;
1221 close HEADERS_PRI_FILE;
1222 $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1223 $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents);
1225 if($headers_pri_file && $master_contents) {
1226 my $headers_pri_dir = dirname($headers_pri_file);
1227 make_path($headers_pri_dir, $lib, $verbose_level);
1228 open HEADERS_PRI_FILE, ">$headers_pri_file";
1229 print HEADERS_PRI_FILE $headers_pri_contents;
1230 close HEADERS_PRI_FILE;
1231 print "$lib: created headers.pri file\n" if($verbose_level);
1234 # create forwarding module pri in qtbase/mkspecs/modules
1236 my $modulepri = $modulepris{$lib};
1237 if (-e $modulepri) {
1238 my $modulepriname = basename($modulepri);
1239 make_path($module_fwd, $lib, $verbose_level);
1240 my $moduleprifwd = "$module_fwd/$modulepriname";
1241 my $mod_base = $basedir;
1242 my $mod_component_base = $developer_build ? $qtbasedir : $out_basedir;
1243 open MODULE_PRI_FILE, ">$moduleprifwd" or die("Could not open $moduleprifwd for writing");
1244 print MODULE_PRI_FILE "QT_MODULE_BASE = $mod_base\n";
1245 print MODULE_PRI_FILE "QT_MODULE_BIN_BASE = $mod_component_base/bin\n";
1246 print MODULE_PRI_FILE "QT_MODULE_INCLUDE_BASE = $out_basedir/include\n";
1247 print MODULE_PRI_FILE "QT_MODULE_IMPORT_BASE = $mod_component_base/imports\n";
1248 print MODULE_PRI_FILE "QT_MODULE_LIB_BASE = $mod_component_base/lib\n";
1249 print MODULE_PRI_FILE "QT_MODULE_PLUGIN_BASE = $mod_component_base/plugins\n";
1250 print MODULE_PRI_FILE "include($modulepri)\n";
1251 close MODULE_PRI_FILE;
1252 utime(time, (stat($modulepri))[9], $moduleprifwd);
1253 if ($cache_module_fwd) {
1254 my $cacheStatement = "QMAKE_EXTRA_MODULE_FORWARDS = \"$module_fwd\"";
1255 my $cacheFile = "$out_basedir/.qmake.cache";
1256 my $existingQmakeCache = fileContents($cacheFile);
1257 # Skip if it's already there.
1258 if ($existingQmakeCache !~ $cacheStatement) {
1259 open QMAKE_CACHE_FILE, ">>$cacheFile" or die("Could not open $cacheFile for writing");
1260 print QMAKE_CACHE_FILE "$cacheStatement\n";
1261 close(QMAKE_CACHE_FILE);
1264 } elsif ($modulepri) {
1265 print "$lib: WARNING: Module\'s pri file '$modulepri' not found.\n$lib: Skipped creating forwarding pri.\n";
1270 unless($showonly || !$create_uic_class_map) {
1271 my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h";
1272 if(-e $class_lib_map) {
1273 open CLASS_LIB_MAP, "<$class_lib_map";
1275 binmode CLASS_LIB_MAP;
1276 my $old_class_lib_map_contents = <CLASS_LIB_MAP>;
1277 close CLASS_LIB_MAP;
1278 $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms
1279 $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents);
1281 if($class_lib_map) {
1282 my $class_lib_map_dir = dirname($class_lib_map);
1283 make_path($class_lib_map_dir, "<outdir>", $verbose_level);
1284 open CLASS_LIB_MAP, ">$class_lib_map";
1285 print CLASS_LIB_MAP $class_lib_map_contents;
1286 close CLASS_LIB_MAP;
1290 if($check_includes) {
1291 for my $lib (keys(%modules)) {
1293 my @subdirs = ($modules{$lib});
1294 foreach my $subdir (@subdirs) {
1295 opendir DIR, $subdir or die "Huh, directory ".$subdir." cannot be opened.";
1296 foreach my $t (sort readdir(DIR)) {
1297 push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") &&
1298 !($t eq "..") && !($t eq ".obj") &&
1299 !($t eq ".moc") && !($t eq ".rcc") &&
1300 !($t eq ".uic") && !($t eq "build"));
1305 foreach my $subdir (@subdirs) {
1306 my $header_skip_qt_module_test = 0;
1307 foreach(@ignore_for_qt_module_check) {
1308 foreach (split(/;/, $_)) {
1309 $header_skip_qt_module_test = 1 if ($subdir =~ /^$_/);
1312 my @headers = findFiles($subdir, "^[-a-z0-9_]*\\.h\$" , 0);
1313 foreach my $header (@headers) {
1314 my $header_skip_qt_begin_header_test = 0;
1315 my $header_skip_qt_begin_namespace_test = 0;
1316 $header = 0 if($header =~ /^ui_.*.h/);
1317 foreach (@ignore_headers) {
1318 $header = 0 if($header eq $_);
1321 my $public_header = $header;
1322 if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) {
1325 foreach (@ignore_for_master_contents) {
1326 $public_header = 0 if($header eq $_);
1328 if($public_header) {
1329 foreach (@ignore_for_include_check) {
1330 $public_header = 0 if($header eq $_);
1332 foreach(@ignore_for_qt_begin_header_check) {
1333 $header_skip_qt_begin_header_test = 1 if ($header eq $_);
1335 foreach(@ignore_for_qt_begin_namespace_check) {
1336 $header_skip_qt_begin_namespace_test = 1 if ($header eq $_);
1341 my $iheader = $subdir . "/" . $header;
1342 if($public_header) {
1343 if(open(F, "<$iheader")) {
1344 my $qt_module_found = 0;
1345 my $qt_begin_header_found = 0;
1346 my $qt_end_header_found = 0;
1347 my $qt_begin_namespace_found = 0;
1348 my $qt_end_namespace_found = 0;
1350 while($line = <F>) {
1352 my $output_line = 1;
1353 if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) {
1355 } elsif($line =~ /^ *\# *include/) {
1356 my $include = $line;
1357 if($line =~ /<.*>/) {
1358 $include =~ s,.*<(.*)>.*,$1,;
1359 } elsif($line =~ /".*"/) {
1360 $include =~ s,.*"(.*)".*,$1,;
1365 for my $trylib (keys(%modules)) {
1366 if(-e "$out_basedir/include/$trylib/$include") {
1367 print "$lib: WARNING: $iheader includes $include when it should include $trylib/$include\n";
1371 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) {
1372 $qt_begin_header_found = 1;
1373 } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) {
1374 $qt_end_header_found = 1;
1375 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) {
1376 $qt_begin_namespace_found = 1;
1377 } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) {
1378 $qt_end_namespace_found = 1;
1379 } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) {
1380 $qt_module_found = 1;
1383 if ($header_skip_qt_begin_header_test == 0) {
1384 if ($qt_begin_header_found == 0) {
1385 print "$lib: WARNING: $iheader does not include QT_BEGIN_HEADER\n";
1388 if ($qt_begin_header_found && $qt_end_header_found == 0) {
1389 print "$lib: WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n";
1393 if ($header_skip_qt_begin_namespace_test == 0) {
1394 if ($qt_begin_namespace_found == 0) {
1395 print "$lib: WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n";
1398 if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) {
1399 print "$lib: WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n";
1403 if ($header_skip_qt_module_test == 0) {
1404 if ($qt_module_found == 0) {
1405 print "$lib: WARNING: $iheader does not include QT_MODULE\n";
1417 # Do configure tests now (pass some things along)
1418 # fatal tests have a non zero return
1419 # If the generator is not set (e.g. someone invoking syncqt as part of configure etc, then don't run tests either)
1420 unless ($showonly || $makefile_generator eq '') {
1421 my $configtests = dirname($0)."/qtmodule-configtests";
1422 if (! -f $configtests) {
1423 $configtests = $qtbasedir."/bin/qtmodule-configtests";
1425 if (! -f $configtests) {
1426 warn "Unable to locate qtmodule-configtests script - config tests disabled.\n";
1428 if (system($EXECUTABLE_NAME, $configtests, $basedir, $out_basedir, $qtbasedir, $makefile_generator)) {
1429 die "$configtests exited with status $?";