| 1 | #!/usr/bin/perl -w | 
|---|
| 2 | ###################################################################### | 
|---|
| 3 | # | 
|---|
| 4 | # Synchronizes Qt header files - internal development tool. | 
|---|
| 5 | # | 
|---|
| 6 | # Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 7 | # Contact: Nokia Corporation (qt-info@nokia.com) | 
|---|
| 8 | # | 
|---|
| 9 | ###################################################################### | 
|---|
| 10 |  | 
|---|
| 11 | # use packages ------------------------------------------------------- | 
|---|
| 12 | use File::Basename; | 
|---|
| 13 | use File::Path; | 
|---|
| 14 | use Cwd; | 
|---|
| 15 | use Config; | 
|---|
| 16 | use strict; | 
|---|
| 17 |  | 
|---|
| 18 | die "syncqt: QTDIR not defined" if ! $ENV{"QTDIR"}; # sanity check | 
|---|
| 19 |  | 
|---|
| 20 | # global variables | 
|---|
| 21 | my $isunix = 0; | 
|---|
| 22 | my $basedir = $ENV{"QTDIR"}; | 
|---|
| 23 | $basedir =~ s=\\=/=g; | 
|---|
| 24 | my %modules = ( # path to module name map | 
|---|
| 25 | "QtGui" => "$basedir/src/gui", | 
|---|
| 26 | "QtOpenGL" => "$basedir/src/opengl", | 
|---|
| 27 | "QtOpenVG" => "$basedir/src/openvg", | 
|---|
| 28 | "QtCore" => "$basedir/src/corelib", | 
|---|
| 29 | "QtXml" => "$basedir/src/xml", | 
|---|
| 30 | "QtXmlPatterns" => "$basedir/src/xmlpatterns", | 
|---|
| 31 | "QtSql" => "$basedir/src/sql", | 
|---|
| 32 | "QtNetwork" => "$basedir/src/network", | 
|---|
| 33 | "QtSvg" => "$basedir/src/svg", | 
|---|
| 34 | "QtDeclarative" => "$basedir/src/declarative", | 
|---|
| 35 | "QtScript" => "$basedir/src/script", | 
|---|
| 36 | "QtScriptTools" => "$basedir/src/scripttools", | 
|---|
| 37 | "Qt3Support" => "$basedir/src/qt3support", | 
|---|
| 38 | "ActiveQt" => "$basedir/src/activeqt/container;$basedir/src/activeqt/control;$basedir/src/activeqt/shared", | 
|---|
| 39 | "QtTest" => "$basedir/src/testlib", | 
|---|
| 40 | "QtAssistant" => "$basedir/tools/assistant/compat/lib", | 
|---|
| 41 | "QtHelp" => "$basedir/tools/assistant/lib", | 
|---|
| 42 | "QtDesigner" => "$basedir/tools/designer/src/lib", | 
|---|
| 43 | "QtUiTools" => "$basedir/tools/designer/src/uitools", | 
|---|
| 44 | "QtDBus" => "$basedir/src/dbus", | 
|---|
| 45 | "QtWebKit" => "$basedir/src/3rdparty/webkit/WebCore", | 
|---|
| 46 | "phonon" => "$basedir/src/phonon", | 
|---|
| 47 | "QtMultimedia" => "$basedir/src/multimedia", | 
|---|
| 48 | ); | 
|---|
| 49 | my %moduleheaders = ( # restrict the module headers to those found in relative path | 
|---|
| 50 | "QtWebKit" => "../WebKit/qt/Api", | 
|---|
| 51 | "phonon" => "../3rdparty/phonon/phonon", | 
|---|
| 52 | ); | 
|---|
| 53 |  | 
|---|
| 54 | #$modules{"QtCore"} .= ";$basedir/mkspecs/" . $ENV{"MKSPEC"} if defined $ENV{"MKSPEC"}; | 
|---|
| 55 |  | 
|---|
| 56 | # global variables (modified by options) | 
|---|
| 57 | my $module = 0; | 
|---|
| 58 | my $showonly = 0; | 
|---|
| 59 | my $remove_stale = 1; | 
|---|
| 60 | my $force_win = 0; | 
|---|
| 61 | my $force_relative = 0; | 
|---|
| 62 | my $check_includes = 0; | 
|---|
| 63 | my $copy_headers = 0; | 
|---|
| 64 | my @modules_to_sync ; | 
|---|
| 65 | $force_relative = 1 if ( -d "/System/Library/Frameworks" ); | 
|---|
| 66 | my $out_basedir = $basedir; | 
|---|
| 67 | $out_basedir =~ s=\\=/=g; | 
|---|
| 68 |  | 
|---|
| 69 | # functions ---------------------------------------------------------- | 
|---|
| 70 |  | 
|---|
| 71 | ###################################################################### | 
|---|
| 72 | # Syntax:  showUsage() | 
|---|
| 73 | # Params:  -none- | 
|---|
| 74 | # | 
|---|
| 75 | # Purpose: Show the usage of the script. | 
|---|
| 76 | # Returns: -none- | 
|---|
| 77 | ###################################################################### | 
|---|
| 78 | sub showUsage | 
|---|
| 79 | { | 
|---|
| 80 | print "$0 usage:\n"; | 
|---|
| 81 | print "  -copy                 Copy headers instead of include-fwd(default: " . ($copy_headers ? "yes" : "no") . ")\n"; | 
|---|
| 82 | print "  -remove-stale         Removes stale headers              (default: " . ($remove_stale ? "yes" : "no") . ")\n"; | 
|---|
| 83 | print "  -relative             Force relative symlinks            (default: " . ($force_relative ? "yes" : "no") . ")\n"; | 
|---|
| 84 | print "  -windows              Force platform to Windows          (default: " . ($force_win ? "yes" : "no") . ")\n"; | 
|---|
| 85 | print "  -showonly             Show action but not perform        (default: " . ($showonly ? "yes" : "no") . ")\n"; | 
|---|
| 86 | print "  -outdir <PATH>        Specify output directory for sync  (default: $out_basedir)\n"; | 
|---|
| 87 | print "  -help                 This help\n"; | 
|---|
| 88 | exit 0; | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | ###################################################################### | 
|---|
| 92 | # Syntax:  checkUnix() | 
|---|
| 93 | # Params:  -none- | 
|---|
| 94 | # | 
|---|
| 95 | # Purpose: Check if script runs on a Unix system or not. Cygwin | 
|---|
| 96 | #          systems are _not_ detected as Unix systems. | 
|---|
| 97 | # Returns: 1 if a unix system, else 0. | 
|---|
| 98 | ###################################################################### | 
|---|
| 99 | sub checkUnix { | 
|---|
| 100 | my ($r) = 0; | 
|---|
| 101 | if ( $force_win != 0) { | 
|---|
| 102 | return 0; | 
|---|
| 103 | } elsif ( -f "/bin/uname" ) { | 
|---|
| 104 | $r = 1; | 
|---|
| 105 | (-f "\\bin\\uname") && ($r = 0); | 
|---|
| 106 | } elsif ( -f "/usr/bin/uname" ) { | 
|---|
| 107 | $r = 1; | 
|---|
| 108 | (-f "\\usr\\bin\\uname") && ($r = 0); | 
|---|
| 109 | } | 
|---|
| 110 | if($r) { | 
|---|
| 111 | $_ = $Config{'osname'}; | 
|---|
| 112 | $r = 0 if( /(ms)|(cyg)win/i ); | 
|---|
| 113 | } | 
|---|
| 114 | return $r; | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 | sub checkRelative { | 
|---|
| 118 | my ($dir) = @_; | 
|---|
| 119 | return 0 if($dir =~ /^\//); | 
|---|
| 120 | return 0 if(!checkUnix() && $dir =~ /[a-zA-Z]:[\/\\]/); | 
|---|
| 121 | return 1; | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | ###################################################################### | 
|---|
| 125 | # Syntax:  shouldMasterInclude(iheader) | 
|---|
| 126 | # Params:  iheader, string, filename to verify inclusion | 
|---|
| 127 | # | 
|---|
| 128 | # Purpose: Determines if header should be in the master include file. | 
|---|
| 129 | # Returns: 0 if file contains "#pragma qt_no_master_include" or not | 
|---|
| 130 | #          able to open, else 1. | 
|---|
| 131 | ###################################################################### | 
|---|
| 132 | sub shouldMasterInclude { | 
|---|
| 133 | my ($iheader) = @_; | 
|---|
| 134 | return 0 if(basename($iheader) =~ /_/); | 
|---|
| 135 | return 0 if(basename($iheader) =~ /qconfig/); | 
|---|
| 136 | if(open(F, "<$iheader")) { | 
|---|
| 137 | while(<F>) { | 
|---|
| 138 | chomp; | 
|---|
| 139 | return 0 if(/^\#pragma qt_no_master_include$/); | 
|---|
| 140 | } | 
|---|
| 141 | close(F); | 
|---|
| 142 | } else { | 
|---|
| 143 | return 0; | 
|---|
| 144 | } | 
|---|
| 145 | return 1; | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | ###################################################################### | 
|---|
| 149 | # Syntax:  classNames(iheader) | 
|---|
| 150 | # Params:  iheader, string, filename to parse for classname "symlinks" | 
|---|
| 151 | # | 
|---|
| 152 | # Purpose: Scans through iheader to find all classnames that should be | 
|---|
| 153 | #          synced into library's include structure. | 
|---|
| 154 | # Returns: List of all class names in a file. | 
|---|
| 155 | ###################################################################### | 
|---|
| 156 | sub classNames { | 
|---|
| 157 | my @ret; | 
|---|
| 158 | my ($iheader) = @_; | 
|---|
| 159 | if(basename($iheader) eq "qglobal.h") { | 
|---|
| 160 | push @ret, "QtGlobal"; | 
|---|
| 161 | } elsif(basename($iheader) eq "qendian.h") { | 
|---|
| 162 | push @ret, "QtEndian"; | 
|---|
| 163 | } elsif(basename($iheader) eq "qconfig.h") { | 
|---|
| 164 | push @ret, "QtConfig"; | 
|---|
| 165 | } elsif(basename($iheader) eq "qplugin.h") { | 
|---|
| 166 | push @ret, "QtPlugin"; | 
|---|
| 167 | } elsif(basename($iheader) eq "qalgorithms.h") { | 
|---|
| 168 | push @ret, "QtAlgorithms"; | 
|---|
| 169 | } elsif(basename($iheader) eq "qcontainerfwd.h") { | 
|---|
| 170 | push @ret, "QtContainerFwd"; | 
|---|
| 171 | } elsif(basename($iheader) eq "qdebug.h") { | 
|---|
| 172 | push @ret, "QtDebug"; | 
|---|
| 173 | } elsif(basename($iheader) eq "qevent.h") { | 
|---|
| 174 | push @ret, "QtEvents"; | 
|---|
| 175 | } elsif(basename($iheader) eq "qnamespace.h") { | 
|---|
| 176 | push @ret, "Qt" | 
|---|
| 177 | } elsif(basename($iheader) eq "qssl.h") { | 
|---|
| 178 | push @ret, "QSsl"; | 
|---|
| 179 | } elsif(basename($iheader) eq "qtest.h") { | 
|---|
| 180 | push @ret, "QTest" | 
|---|
| 181 | } elsif(basename($iheader) eq "qtconcurrentmap.h") { | 
|---|
| 182 | push @ret, "QtConcurrentMap" | 
|---|
| 183 | } elsif(basename($iheader) eq "qtconcurrentfilter.h") { | 
|---|
| 184 | push @ret, "QtConcurrentFilter" | 
|---|
| 185 | } elsif(basename($iheader) eq "qtconcurrentrun.h") { | 
|---|
| 186 | push @ret, "QtConcurrentRun" | 
|---|
| 187 | } | 
|---|
| 188 |  | 
|---|
| 189 | my $parsable = ""; | 
|---|
| 190 | if(open(F, "<$iheader")) { | 
|---|
| 191 | while(<F>) { | 
|---|
| 192 | my $line = $_; | 
|---|
| 193 | chomp $line; | 
|---|
| 194 | chop $line if ($line =~ /\r$/); | 
|---|
| 195 | if($line =~ /^\#/) { | 
|---|
| 196 | if($line =~ /\\$/) { | 
|---|
| 197 | while($line = <F>) { | 
|---|
| 198 | chomp $line; | 
|---|
| 199 | last unless($line =~ /\\$/); | 
|---|
| 200 | } | 
|---|
| 201 | } | 
|---|
| 202 | return @ret if($line =~ m/^#pragma qt_sync_stop_processing/); | 
|---|
| 203 | push(@ret, "$1") if($line =~ m/^#pragma qt_class\(([^)]*)\)[\r\n]*$/); | 
|---|
| 204 | $line = 0; | 
|---|
| 205 | } | 
|---|
| 206 | if($line) { | 
|---|
| 207 | $line =~ s,//.*$,,; #remove c++ comments | 
|---|
| 208 | $line .= ";" if($line =~ m/^Q_[A-Z_]*\(.*\)[\r\n]*$/); #qt macro | 
|---|
| 209 | $line .= ";" if($line =~ m/^QT_(BEGIN|END)_HEADER[\r\n]*$/); #qt macro | 
|---|
| 210 | $line .= ";" if($line =~ m/^QT_(BEGIN|END)_NAMESPACE[\r\n]*$/); #qt macro | 
|---|
| 211 | $line .= ";" if($line =~ m/^QT_MODULE\(.*\)[\r\n]*$/); # QT_MODULE macro | 
|---|
| 212 | $parsable .= " " . $line; | 
|---|
| 213 | } | 
|---|
| 214 | } | 
|---|
| 215 | close(F); | 
|---|
| 216 | } | 
|---|
| 217 |  | 
|---|
| 218 | my $last_definition = 0; | 
|---|
| 219 | my @namespaces; | 
|---|
| 220 | for(my $i = 0; $i < length($parsable); $i++) { | 
|---|
| 221 | my $definition = 0; | 
|---|
| 222 | my $character = substr($parsable, $i, 1); | 
|---|
| 223 | if($character eq "/" && substr($parsable, $i+1, 1) eq "*") { #I parse like this for greedy reasons | 
|---|
| 224 | for($i+=2; $i < length($parsable); $i++) { | 
|---|
| 225 | my $end = substr($parsable, $i, 2); | 
|---|
| 226 | if($end eq "*/") { | 
|---|
| 227 | $last_definition = $i+2; | 
|---|
| 228 | $i++; | 
|---|
| 229 | last; | 
|---|
| 230 | } | 
|---|
| 231 | } | 
|---|
| 232 | } elsif($character eq "{") { | 
|---|
| 233 | my $brace_depth = 1; | 
|---|
| 234 | my $block_start = $i + 1; | 
|---|
| 235 | BLOCK: for($i+=1; $i < length($parsable); $i++) { | 
|---|
| 236 | my $ignore = substr($parsable, $i, 1); | 
|---|
| 237 | if($ignore eq "{") { | 
|---|
| 238 | $brace_depth++; | 
|---|
| 239 | } elsif($ignore eq "}") { | 
|---|
| 240 | $brace_depth--; | 
|---|
| 241 | unless($brace_depth) { | 
|---|
| 242 | for(my $i2 = $i+1; $i2 < length($parsable); $i2++) { | 
|---|
| 243 | my $end = substr($parsable, $i2, 1); | 
|---|
| 244 | if($end eq ";" || $end ne " ") { | 
|---|
| 245 | $definition = substr($parsable, $last_definition, $block_start - $last_definition) . "}"; | 
|---|
| 246 | $i = $i2 if($end eq ";"); | 
|---|
| 247 | $last_definition = $i + 1; | 
|---|
| 248 | last BLOCK; | 
|---|
| 249 | } | 
|---|
| 250 | } | 
|---|
| 251 | } | 
|---|
| 252 | } | 
|---|
| 253 | } | 
|---|
| 254 | } elsif($character eq ";") { | 
|---|
| 255 | $definition = substr($parsable, $last_definition, $i - $last_definition + 1); | 
|---|
| 256 | $last_definition = $i + 1; | 
|---|
| 257 | } elsif($character eq "}") { | 
|---|
| 258 | # a naked } must be a namespace ending | 
|---|
| 259 | # if it's not a namespace, it's eaten by the loop above | 
|---|
| 260 | pop @namespaces; | 
|---|
| 261 | $last_definition = $i + 1; | 
|---|
| 262 | } | 
|---|
| 263 |  | 
|---|
| 264 | if (substr($parsable, $last_definition, $i - $last_definition + 1) =~ m/ namespace ([^ ]*) / | 
|---|
| 265 | && substr($parsable, $i+1, 1) eq "{") { | 
|---|
| 266 | push @namespaces, $1; | 
|---|
| 267 |  | 
|---|
| 268 | # Eat the opening { so that the condensing loop above doesn't see it | 
|---|
| 269 | $i++; | 
|---|
| 270 | $last_definition = $i + 1; | 
|---|
| 271 | } | 
|---|
| 272 |  | 
|---|
| 273 | if($definition) { | 
|---|
| 274 | $definition =~ s=[\n\r]==g; | 
|---|
| 275 | my @symbols; | 
|---|
| 276 | if($definition =~ m/^ *typedef *.*\(\*([^\)]*)\)\(.*\);$/) { | 
|---|
| 277 | push @symbols, $1; | 
|---|
| 278 | } elsif($definition =~ m/^ *typedef +(.*) +([^ ]*);$/) { | 
|---|
| 279 | push @symbols, $2; | 
|---|
| 280 | } elsif($definition =~ m/^ *(template *<.*> *)?(class|struct) +([^ ]* +)?([^<\s]+) ?(<[^>]*> ?)?\s*((,|:)\s*(public|protected|private) *.*)? *\{\}$/) { | 
|---|
| 281 | push @symbols, $4; | 
|---|
| 282 | } elsif($definition =~ m/^ *Q_DECLARE_.*ITERATOR\((.*)\);$/) { | 
|---|
| 283 | push @symbols, "Q" . $1 . "Iterator"; | 
|---|
| 284 | push @symbols, "QMutable" . $1 . "Iterator"; | 
|---|
| 285 | } | 
|---|
| 286 |  | 
|---|
| 287 | foreach (@symbols) { | 
|---|
| 288 | my $symbol = $_; | 
|---|
| 289 | $symbol = (join("::", @namespaces) . "::" . $symbol) if (scalar @namespaces); | 
|---|
| 290 | push @ret, $symbol | 
|---|
| 291 | if ($symbol =~ /^Q[^:]*$/           # no-namespace, starting with Q | 
|---|
| 292 | || $symbol =~ /^Phonon::/);     # or in the Phonon namespace | 
|---|
| 293 | } | 
|---|
| 294 | } | 
|---|
| 295 | } | 
|---|
| 296 | return @ret; | 
|---|
| 297 | } | 
|---|
| 298 |  | 
|---|
| 299 | ###################################################################### | 
|---|
| 300 | # Syntax:  syncHeader(header, iheader, copy) | 
|---|
| 301 | # Params:  header, string, filename to create "symlink" for | 
|---|
| 302 | #          iheader, string, destination name of symlink | 
|---|
| 303 | #          copy, forces header to be a copy of iheader | 
|---|
| 304 | # | 
|---|
| 305 | # Purpose: Syncronizes header to iheader | 
|---|
| 306 | # Returns: 1 if successful, else 0. | 
|---|
| 307 | ###################################################################### | 
|---|
| 308 | sub syncHeader { | 
|---|
| 309 | my ($header, $iheader, $copy) = @_; | 
|---|
| 310 | $iheader =~ s=\\=/=g; | 
|---|
| 311 | $header =~ s=\\=/=g; | 
|---|
| 312 | return copyFile($iheader, $header) if($copy); | 
|---|
| 313 |  | 
|---|
| 314 | unless(-e "$header") { | 
|---|
| 315 | my $header_dir = dirname($header); | 
|---|
| 316 | mkpath $header_dir, 0777; | 
|---|
| 317 |  | 
|---|
| 318 | #write it | 
|---|
| 319 | my $iheader_out = fixPaths($iheader, $header_dir); | 
|---|
| 320 | open HEADER, ">$header" || die "Could not open $header for writing!\n"; | 
|---|
| 321 | print HEADER "#include \"$iheader_out\"\n"; | 
|---|
| 322 | close HEADER; | 
|---|
| 323 | return 1; | 
|---|
| 324 | } | 
|---|
| 325 | return 0; | 
|---|
| 326 | } | 
|---|
| 327 |  | 
|---|
| 328 | ###################################################################### | 
|---|
| 329 | # Syntax:  fixPaths(file, dir) | 
|---|
| 330 | # Params:  file, string, filepath to be made relative to dir | 
|---|
| 331 | #          dir, string, dirpath for point of origin | 
|---|
| 332 | # | 
|---|
| 333 | # Purpose: file is made relative (if possible) of dir. | 
|---|
| 334 | # Returns: String with the above applied conversion. | 
|---|
| 335 | ###################################################################### | 
|---|
| 336 | sub fixPaths { | 
|---|
| 337 | my ($file, $dir) = @_; | 
|---|
| 338 | $dir =~ s=^$basedir/=$out_basedir/= if(!($basedir eq $out_basedir)); | 
|---|
| 339 | $file =~ s=\\=/=g; | 
|---|
| 340 | $file =~ s/\+/\\+/g; | 
|---|
| 341 | $dir =~ s=\\=/=g; | 
|---|
| 342 | $dir =~ s/\+/\\+/g; | 
|---|
| 343 |  | 
|---|
| 344 | #setup | 
|---|
| 345 | my $ret = $file; | 
|---|
| 346 | my $file_dir = dirname($file); | 
|---|
| 347 | if($file_dir eq ".") { | 
|---|
| 348 | $file_dir = getcwd(); | 
|---|
| 349 | $file_dir =~ s=\\=/=g; | 
|---|
| 350 | } | 
|---|
| 351 | $file_dir =~ s,/cygdrive/([a-zA-Z])/,$1:,g; | 
|---|
| 352 | if($dir eq ".") { | 
|---|
| 353 | $dir = getcwd(); | 
|---|
| 354 | $dir =~ s=\\=/=g; | 
|---|
| 355 | } | 
|---|
| 356 | $dir =~ s,/cygdrive/([a-zA-Z])/,$1:/,g; | 
|---|
| 357 | return basename($file) if("$file_dir" eq "$dir"); | 
|---|
| 358 |  | 
|---|
| 359 | #guts | 
|---|
| 360 | my $match_dir = 0; | 
|---|
| 361 | for(my $i = 1; $i < length($file_dir); $i++) { | 
|---|
| 362 | my $slash = index($file_dir, "/", $i); | 
|---|
| 363 | last if($slash == -1); | 
|---|
| 364 | my $tmp = substr($file_dir, 0, $slash); | 
|---|
| 365 | last unless($dir =~ m,^$tmp/,); | 
|---|
| 366 | $match_dir = $tmp; | 
|---|
| 367 | $i = $slash; | 
|---|
| 368 | } | 
|---|
| 369 | if($match_dir) { | 
|---|
| 370 | my $after = substr($dir, length($match_dir)); | 
|---|
| 371 | my $count = ($after =~ tr,/,,); | 
|---|
| 372 | my $dots = ""; | 
|---|
| 373 | for(my $i = 0; $i < $count; $i++) { | 
|---|
| 374 | $dots .= "../"; | 
|---|
| 375 | } | 
|---|
| 376 | $ret =~ s,^$match_dir,$dots,; | 
|---|
| 377 | } | 
|---|
| 378 | $ret =~ s,/+,/,g; | 
|---|
| 379 | return $ret; | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 | ###################################################################### | 
|---|
| 383 | # Syntax:  fileContents(filename) | 
|---|
| 384 | # Params:  filename, string, filename of file to return contents | 
|---|
| 385 | # | 
|---|
| 386 | # Purpose: Get the contents of a file. | 
|---|
| 387 | # Returns: String with contents of the file, or empty string if file | 
|---|
| 388 | #          doens't exist. | 
|---|
| 389 | # Warning: Dies if it does exist but script cannot get read access. | 
|---|
| 390 | ###################################################################### | 
|---|
| 391 | sub fileContents { | 
|---|
| 392 | my ($filename) = @_; | 
|---|
| 393 | my $filecontents = ""; | 
|---|
| 394 | if (-e $filename) { | 
|---|
| 395 | open(I, "< $filename") || die "Could not open $filename for reading, read block?"; | 
|---|
| 396 | local $/; | 
|---|
| 397 | binmode I; | 
|---|
| 398 | $filecontents = <I>; | 
|---|
| 399 | close I; | 
|---|
| 400 | } | 
|---|
| 401 | return $filecontents; | 
|---|
| 402 | } | 
|---|
| 403 |  | 
|---|
| 404 | ###################################################################### | 
|---|
| 405 | # Syntax:  fileCompare(file1, file2) | 
|---|
| 406 | # Params:  file1, string, filename of first file | 
|---|
| 407 | #          file2, string, filename of second file | 
|---|
| 408 | # | 
|---|
| 409 | # Purpose: Determines if files are equal, and which one is newer. | 
|---|
| 410 | # Returns: 0 if files are equal no matter the timestamp, -1 if file1 | 
|---|
| 411 | #          is newer, 1 if file2 is newer. | 
|---|
| 412 | ###################################################################### | 
|---|
| 413 | sub fileCompare { | 
|---|
| 414 | my ($file1, $file2) = @_; | 
|---|
| 415 | my $file1contents = fileContents($file1); | 
|---|
| 416 | my $file2contents = fileContents($file2); | 
|---|
| 417 | if (! -e $file1) { return 1; } | 
|---|
| 418 | if (! -e $file2) { return -1; } | 
|---|
| 419 | return $file1contents ne $file2contents ? (stat("$file2"))[9] <=> (stat("$file1"))[9] : 0; | 
|---|
| 420 | } | 
|---|
| 421 |  | 
|---|
| 422 | ###################################################################### | 
|---|
| 423 | # Syntax:  copyFile(file, ifile) | 
|---|
| 424 | # Params:  file, string, filename to create duplicate for | 
|---|
| 425 | #          ifile, string, destination name of duplicate | 
|---|
| 426 | # | 
|---|
| 427 | # Purpose: Keeps files in sync so changes in the newer file will be | 
|---|
| 428 | #          written to the other. | 
|---|
| 429 | # Returns: 1 if files were synced, else 0. | 
|---|
| 430 | # Warning: Dies if script cannot get write access. | 
|---|
| 431 | ###################################################################### | 
|---|
| 432 | sub copyFile | 
|---|
| 433 | { | 
|---|
| 434 | my ($file,$ifile, $copy,$knowdiff,$filecontents,$ifilecontents) = @_; | 
|---|
| 435 | # Bi-directional synchronization | 
|---|
| 436 | open( I, "< " . $file ) || die "Could not open $file for reading"; | 
|---|
| 437 | local $/; | 
|---|
| 438 | binmode I; | 
|---|
| 439 | $filecontents = <I>; | 
|---|
| 440 | close I; | 
|---|
| 441 | if ( open(I, "< " . $ifile) ) { | 
|---|
| 442 | local $/; | 
|---|
| 443 | binmode I; | 
|---|
| 444 | $ifilecontents = <I>; | 
|---|
| 445 | close I; | 
|---|
| 446 | $copy = fileCompare($file, $ifile); | 
|---|
| 447 | $knowdiff = 0, | 
|---|
| 448 | } else { | 
|---|
| 449 | $copy = -1; | 
|---|
| 450 | $knowdiff = 1; | 
|---|
| 451 | } | 
|---|
| 452 |  | 
|---|
| 453 | if ( $knowdiff || ($filecontents ne $ifilecontents) ) { | 
|---|
| 454 | if ( $copy > 0 ) { | 
|---|
| 455 | my $file_dir = dirname($file); | 
|---|
| 456 | mkpath $file_dir, 0777 unless(-e "$file_dir"); | 
|---|
| 457 | open(O, "> " . $file) || die "Could not open $file for writing (no write permission?)"; | 
|---|
| 458 | local $/; | 
|---|
| 459 | binmode O; | 
|---|
| 460 | print O $ifilecontents; | 
|---|
| 461 | close O; | 
|---|
| 462 | return 1; | 
|---|
| 463 | } elsif ( $copy < 0 ) { | 
|---|
| 464 | my $ifile_dir = dirname($ifile); | 
|---|
| 465 | mkpath $ifile_dir, 0777 unless(-e "$ifile_dir"); | 
|---|
| 466 | open(O, "> " . $ifile) || die "Could not open $ifile for writing (no write permission?)"; | 
|---|
| 467 | local $/; | 
|---|
| 468 | binmode O; | 
|---|
| 469 | print O $filecontents; | 
|---|
| 470 | close O; | 
|---|
| 471 | return 1; | 
|---|
| 472 | } | 
|---|
| 473 | } | 
|---|
| 474 | return 0; | 
|---|
| 475 | } | 
|---|
| 476 |  | 
|---|
| 477 | ###################################################################### | 
|---|
| 478 | # Syntax:  symlinkFile(file, ifile) | 
|---|
| 479 | # Params:  file, string, filename to create "symlink" for | 
|---|
| 480 | #          ifile, string, destination name of symlink | 
|---|
| 481 | # | 
|---|
| 482 | # Purpose: File is symlinked to ifile (or copied if filesystem doesn't | 
|---|
| 483 | #          support symlink). | 
|---|
| 484 | # Returns: 1 on success, else 0. | 
|---|
| 485 | ###################################################################### | 
|---|
| 486 | sub symlinkFile | 
|---|
| 487 | { | 
|---|
| 488 | my ($file,$ifile) = @_; | 
|---|
| 489 |  | 
|---|
| 490 | if ($isunix) { | 
|---|
| 491 | print "symlink created for $file "; | 
|---|
| 492 | if ( $force_relative && ($ifile =~ /^$basedir/)) { | 
|---|
| 493 | my $t = getcwd(); | 
|---|
| 494 | my $c = -1; | 
|---|
| 495 | my $p = "../"; | 
|---|
| 496 | $t =~ s-^$basedir/--; | 
|---|
| 497 | $p .= "../" while( ($c = index( $t, "/", $c + 1)) != -1 ); | 
|---|
| 498 | $file =~ s-^$basedir/-$p-; | 
|---|
| 499 | print " ($file)\n"; | 
|---|
| 500 | } | 
|---|
| 501 | print "\n"; | 
|---|
| 502 | return symlink($file, $ifile); | 
|---|
| 503 | } | 
|---|
| 504 | return copyFile($file, $ifile); | 
|---|
| 505 | } | 
|---|
| 506 |  | 
|---|
| 507 | ###################################################################### | 
|---|
| 508 | # Syntax:  findFiles(dir, match, descend) | 
|---|
| 509 | # Params:  dir, string, directory to search for name | 
|---|
| 510 | #          match, string, regular expression to match in dir | 
|---|
| 511 | #          descend, integer, 0 = non-recursive search | 
|---|
| 512 | #                            1 = recurse search into subdirectories | 
|---|
| 513 | # | 
|---|
| 514 | # Purpose: Finds files matching a regular expression. | 
|---|
| 515 | # Returns: List of matching files. | 
|---|
| 516 | # | 
|---|
| 517 | # Examples: | 
|---|
| 518 | #   findFiles("/usr","\.cpp$",1)  - finds .cpp files in /usr and below | 
|---|
| 519 | #   findFiles("/tmp","^#",0)      - finds #* files in /tmp | 
|---|
| 520 | ###################################################################### | 
|---|
| 521 | sub findFiles { | 
|---|
| 522 | my ($dir,$match,$descend) = @_; | 
|---|
| 523 | my ($file,$p,@files); | 
|---|
| 524 | local(*D); | 
|---|
| 525 | $dir =~ s=\\=/=g; | 
|---|
| 526 | ($dir eq "") && ($dir = "."); | 
|---|
| 527 | if ( opendir(D,$dir) ) { | 
|---|
| 528 | if ( $dir eq "." ) { | 
|---|
| 529 | $dir = ""; | 
|---|
| 530 | } else { | 
|---|
| 531 | ($dir =~ /\/$/) || ($dir .= "/"); | 
|---|
| 532 | } | 
|---|
| 533 | foreach $file ( sort readdir(D) ) { | 
|---|
| 534 | next if ( $file  =~ /^\.\.?$/ ); | 
|---|
| 535 | $p = $file; | 
|---|
| 536 | ($file =~ /$match/) && (push @files, $p); | 
|---|
| 537 | if ( $descend && -d $p && ! -l $p ) { | 
|---|
| 538 | push @files, &findFiles($p,$match,$descend); | 
|---|
| 539 | } | 
|---|
| 540 | } | 
|---|
| 541 | closedir(D); | 
|---|
| 542 | } | 
|---|
| 543 | return @files; | 
|---|
| 544 | } | 
|---|
| 545 |  | 
|---|
| 546 | # -------------------------------------------------------------------- | 
|---|
| 547 | # "main" function | 
|---|
| 548 | # -------------------------------------------------------------------- | 
|---|
| 549 |  | 
|---|
| 550 | while ( @ARGV ) { | 
|---|
| 551 | my $var = 0; | 
|---|
| 552 | my $val = 0; | 
|---|
| 553 |  | 
|---|
| 554 | #parse | 
|---|
| 555 | my $arg = shift @ARGV; | 
|---|
| 556 | if ("$arg" eq "-h" || "$arg" eq "-help" || "$arg" eq "?") { | 
|---|
| 557 | $var = "show_help"; | 
|---|
| 558 | $val = "yes"; | 
|---|
| 559 | } elsif("$arg" eq "-copy") { | 
|---|
| 560 | $var = "copy"; | 
|---|
| 561 | $val = "yes"; | 
|---|
| 562 | } elsif("$arg" eq "-o" || "$arg" eq "-outdir") { | 
|---|
| 563 | $var = "output"; | 
|---|
| 564 | $val = shift @ARGV; | 
|---|
| 565 | } elsif("$arg" eq "-showonly" || "$arg" eq "-remove-stale" || "$arg" eq "-windows" || | 
|---|
| 566 | "$arg" eq "-relative" || "$arg" eq "-check-includes") { | 
|---|
| 567 | $var = substr($arg, 1); | 
|---|
| 568 | $val = "yes"; | 
|---|
| 569 | } elsif("$arg" =~ /^-no-(.*)$/) { | 
|---|
| 570 | $var = $1; | 
|---|
| 571 | $val = "no"; | 
|---|
| 572 | #these are for commandline compat | 
|---|
| 573 | } elsif("$arg" eq "-inc") { | 
|---|
| 574 | $var = "output"; | 
|---|
| 575 | $val = shift @ARGV; | 
|---|
| 576 | } elsif("$arg" eq "-module") { | 
|---|
| 577 | $var = "module"; | 
|---|
| 578 | $val = shift @ARGV; | 
|---|
| 579 | } elsif("$arg" eq "-show") { | 
|---|
| 580 | $var = "showonly"; | 
|---|
| 581 | $val = "yes"; | 
|---|
| 582 | } elsif("$arg" eq '*') { | 
|---|
| 583 | # workaround for windows 9x where "%*" expands to "*" | 
|---|
| 584 | $var = 1; | 
|---|
| 585 | } | 
|---|
| 586 |  | 
|---|
| 587 | #do something | 
|---|
| 588 | if(!$var || "$var" eq "show_help") { | 
|---|
| 589 | print "Unknown option: $arg\n\n" if(!$var); | 
|---|
| 590 | showUsage(); | 
|---|
| 591 | } elsif ("$var" eq "copy") { | 
|---|
| 592 | if("$val" eq "yes") { | 
|---|
| 593 | $copy_headers++; | 
|---|
| 594 | } elsif($showonly) { | 
|---|
| 595 | $copy_headers--; | 
|---|
| 596 | } | 
|---|
| 597 | } elsif ("$var" eq "showonly") { | 
|---|
| 598 | if("$val" eq "yes") { | 
|---|
| 599 | $showonly++; | 
|---|
| 600 | } elsif($showonly) { | 
|---|
| 601 | $showonly--; | 
|---|
| 602 | } | 
|---|
| 603 | } elsif ("$var" eq "check-includes") { | 
|---|
| 604 | if("$val" eq "yes") { | 
|---|
| 605 | $check_includes++; | 
|---|
| 606 | } elsif($check_includes) { | 
|---|
| 607 | $check_includes--; | 
|---|
| 608 | } | 
|---|
| 609 | } elsif ("$var" eq "remove-stale") { | 
|---|
| 610 | if("$val" eq "yes") { | 
|---|
| 611 | $remove_stale++; | 
|---|
| 612 | } elsif($remove_stale) { | 
|---|
| 613 | $remove_stale--; | 
|---|
| 614 | } | 
|---|
| 615 | } elsif ("$var" eq "windows") { | 
|---|
| 616 | if("$val" eq "yes") { | 
|---|
| 617 | $force_win++; | 
|---|
| 618 | } elsif($force_win) { | 
|---|
| 619 | $force_win--; | 
|---|
| 620 | } | 
|---|
| 621 | } elsif ("$var" eq "relative") { | 
|---|
| 622 | if("$val" eq "yes") { | 
|---|
| 623 | $force_relative++; | 
|---|
| 624 | } elsif($force_relative) { | 
|---|
| 625 | $force_relative--; | 
|---|
| 626 | } | 
|---|
| 627 | } elsif ("$var" eq "module") { | 
|---|
| 628 | print "module :$val:\n"; | 
|---|
| 629 | die "No such module: $val" unless(defined $modules{$val}); | 
|---|
| 630 | push @modules_to_sync, $val; | 
|---|
| 631 | } elsif ("$var" eq "output") { | 
|---|
| 632 | my $outdir = $val; | 
|---|
| 633 | if(checkRelative($outdir)) { | 
|---|
| 634 | $out_basedir = getcwd(); | 
|---|
| 635 | chomp $out_basedir; | 
|---|
| 636 | $out_basedir .= "/" . $outdir; | 
|---|
| 637 | } else { | 
|---|
| 638 | $out_basedir = $outdir; | 
|---|
| 639 | } | 
|---|
| 640 | # \ -> / | 
|---|
| 641 | $out_basedir =~ s=\\=/=g; | 
|---|
| 642 | } | 
|---|
| 643 | } | 
|---|
| 644 | @modules_to_sync = keys(%modules) if($#modules_to_sync == -1); | 
|---|
| 645 |  | 
|---|
| 646 | $isunix = checkUnix; #cache checkUnix | 
|---|
| 647 |  | 
|---|
| 648 | # create path | 
|---|
| 649 | mkpath "$out_basedir/include", 0777; | 
|---|
| 650 |  | 
|---|
| 651 | my @ignore_headers = (); | 
|---|
| 652 | my $class_lib_map_contents = ""; | 
|---|
| 653 | my @ignore_for_master_contents = ( "qt.h", "qpaintdevicedefs.h" ); | 
|---|
| 654 | my @ignore_for_include_check = ( "qatomic.h" ); | 
|---|
| 655 | my @ignore_for_qt_begin_header_check = ( "qiconset.h", "qconfig.h", "qconfig-dist.h", "qconfig-large.h", "qconfig-medium.h", "qconfig-minimal.h", "qconfig-small.h", "qfeatures.h", "qt_windows.h" ); | 
|---|
| 656 | my @ignore_for_qt_begin_namespace_check = ( "qconfig.h", "qconfig-dist.h", "qconfig-large.h", "qconfig-medium.h", "qconfig-minimal.h", "qconfig-small.h", "qfeatures.h", "qatomic_arch.h", "qatomic_windowsce.h", "qt_windows.h", "qatomic_macosx.h" ); | 
|---|
| 657 | my @ignore_for_qt_module_check = ( "$modules{QtCore}/arch", "$modules{QtCore}/global", "$modules{QtSql}/drivers", "$modules{QtTest}", "$modules{QtAssistant}", "$modules{QtDesigner}", "$modules{QtUiTools}", "$modules{QtDBus}", "$modules{phonon}" ); | 
|---|
| 658 |  | 
|---|
| 659 | foreach (@modules_to_sync) { | 
|---|
| 660 | #iteration info | 
|---|
| 661 | my $lib = $_; | 
|---|
| 662 | my $dir = "$modules{$lib}"; | 
|---|
| 663 | my $pathtoheaders = ""; | 
|---|
| 664 | $pathtoheaders = "$moduleheaders{$lib}" if ($moduleheaders{$lib}); | 
|---|
| 665 |  | 
|---|
| 666 | #information used after the syncing | 
|---|
| 667 | my $pri_install_classes = ""; | 
|---|
| 668 | my $pri_install_files = ""; | 
|---|
| 669 | my $pri_install_pfiles = ""; | 
|---|
| 670 |  | 
|---|
| 671 | my $libcapitals = $lib; | 
|---|
| 672 | $libcapitals =~ y/a-z/A-Z/; | 
|---|
| 673 | my $master_contents = "#ifndef QT_".$libcapitals."_MODULE_H\n#define QT_".$libcapitals."_MODULE_H\n"; | 
|---|
| 674 |  | 
|---|
| 675 | #get dependencies | 
|---|
| 676 | if(-e "$dir/" . basename($dir) . ".pro") { | 
|---|
| 677 | if(open(F, "<$dir/" . basename($dir) . ".pro")) { | 
|---|
| 678 | while(<F>) { | 
|---|
| 679 | my $line = $_; | 
|---|
| 680 | chomp $line; | 
|---|
| 681 | if($line =~ /^ *QT *\+?= *([^\r\n]*)/) { | 
|---|
| 682 | foreach(split(/ /, "$1")) { | 
|---|
| 683 | $master_contents .= "#include <QtCore/QtCore>\n" if("$_" eq "core"); | 
|---|
| 684 | $master_contents .= "#include <QtGui/QtGui>\n" if("$_" eq "gui"); | 
|---|
| 685 | $master_contents .= "#include <QtNetwork/QtNetwork>\n" if("$_" eq "network"); | 
|---|
| 686 | $master_contents .= "#include <QtSvg/QtSvg>\n" if("$_" eq "svg"); | 
|---|
| 687 | $master_contents .= "#include <QtDeclarative/QtDeclarative>\n" if("$_" eq "declarative"); | 
|---|
| 688 | $master_contents .= "#include <QtScript/QtScript>\n" if("$_" eq "script"); | 
|---|
| 689 | $master_contents .= "#include <QtScriptTools/QtScriptTools>\n" if("$_" eq "scripttools"); | 
|---|
| 690 | $master_contents .= "#include <Qt3Support/Qt3Support>\n" if("$_" eq "qt3support"); | 
|---|
| 691 | $master_contents .= "#include <QtSql/QtSql>\n" if("$_" eq "sql"); | 
|---|
| 692 | $master_contents .= "#include <QtXml/QtXml>\n" if("$_" eq "xml"); | 
|---|
| 693 | $master_contents .= "#include <QtXmlPatterns/QtXmlPatterns>\n" if("$_" eq "xmlpatterns"); | 
|---|
| 694 | $master_contents .= "#include <QtOpenGL/QtOpenGL>\n" if("$_" eq "opengl"); | 
|---|
| 695 | $master_contents .= "#include <QtOpenVG/QtOpenVG>\n" if("$_" eq "openvg"); | 
|---|
| 696 | } | 
|---|
| 697 | } | 
|---|
| 698 | } | 
|---|
| 699 | close(F); | 
|---|
| 700 | } | 
|---|
| 701 | } | 
|---|
| 702 |  | 
|---|
| 703 | #remove the old files | 
|---|
| 704 | if($remove_stale) { | 
|---|
| 705 | my @subdirs = ("$out_basedir/include/$lib"); | 
|---|
| 706 | foreach (@subdirs) { | 
|---|
| 707 | my $subdir = "$_"; | 
|---|
| 708 | if (opendir DIR, "$subdir") { | 
|---|
| 709 | while(my $t = readdir(DIR)) { | 
|---|
| 710 | my $file = "$subdir/$t"; | 
|---|
| 711 | if(-d "$file") { | 
|---|
| 712 | push @subdirs, "$file" unless($t eq "." || $t eq ".."); | 
|---|
| 713 | } else { | 
|---|
| 714 | my @files = ("$file"); | 
|---|
| 715 | #push @files, "$out_basedir/include/Qt/$t" if(-e "$out_basedir/include/Qt/$t"); | 
|---|
| 716 | foreach (@files) { | 
|---|
| 717 | my $file = $_; | 
|---|
| 718 | my $remove_file = 0; | 
|---|
| 719 | if(open(F, "<$file")) { | 
|---|
| 720 | while(<F>) { | 
|---|
| 721 | my $line = $_; | 
|---|
| 722 | chomp $line; | 
|---|
| 723 | if($line =~ /^\#include \"([^\"]*)\"$/) { | 
|---|
| 724 | my $include = $1; | 
|---|
| 725 | $include = $subdir . "/" . $include unless(substr($include, 0, 1) eq "/"); | 
|---|
| 726 | $remove_file = 1 unless(-e "$include"); | 
|---|
| 727 | } else { | 
|---|
| 728 | $remove_file = 0; | 
|---|
| 729 | last; | 
|---|
| 730 | } | 
|---|
| 731 | } | 
|---|
| 732 | close(F); | 
|---|
| 733 | unlink "$file" if($remove_file); | 
|---|
| 734 | } | 
|---|
| 735 | } | 
|---|
| 736 | } | 
|---|
| 737 | } | 
|---|
| 738 | closedir DIR; | 
|---|
| 739 | } | 
|---|
| 740 |  | 
|---|
| 741 | } | 
|---|
| 742 | } | 
|---|
| 743 |  | 
|---|
| 744 | #create the new ones | 
|---|
| 745 | foreach (split(/;/, $dir)) { | 
|---|
| 746 | my $current_dir = "$_"; | 
|---|
| 747 | my $headers_dir = $current_dir; | 
|---|
| 748 | $headers_dir .= "/$pathtoheaders" if ($pathtoheaders); | 
|---|
| 749 | #calc subdirs | 
|---|
| 750 | my @subdirs = ($headers_dir); | 
|---|
| 751 | foreach (@subdirs) { | 
|---|
| 752 | my $subdir = "$_"; | 
|---|
| 753 | opendir DIR, "$subdir" or next; | 
|---|
| 754 | while(my $t = readdir(DIR)) { | 
|---|
| 755 | push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") && | 
|---|
| 756 | !($t eq "..") && !($t eq ".obj") && | 
|---|
| 757 | !($t eq ".moc") && !($t eq ".rcc") && | 
|---|
| 758 | !($t eq ".uic") && !($t eq "build")); | 
|---|
| 759 | } | 
|---|
| 760 | closedir DIR; | 
|---|
| 761 | } | 
|---|
| 762 |  | 
|---|
| 763 | #calc files and "copy" them | 
|---|
| 764 | foreach (@subdirs) { | 
|---|
| 765 | my $subdir = "$_"; | 
|---|
| 766 | my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0); | 
|---|
| 767 | foreach (@headers) { | 
|---|
| 768 | my $header = "$_"; | 
|---|
| 769 | $header = 0 if("$header" =~ /^ui_.*.h/); | 
|---|
| 770 | foreach (@ignore_headers) { | 
|---|
| 771 | $header = 0 if("$header" eq "$_"); | 
|---|
| 772 | } | 
|---|
| 773 | if($header) { | 
|---|
| 774 | my $header_copies = 0; | 
|---|
| 775 | #figure out if it is a public header | 
|---|
| 776 | my $public_header = $header; | 
|---|
| 777 | if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) { | 
|---|
| 778 | $public_header = 0; | 
|---|
| 779 | } else { | 
|---|
| 780 | foreach (@ignore_for_master_contents) { | 
|---|
| 781 | $public_header = 0 if("$header" eq "$_"); | 
|---|
| 782 | } | 
|---|
| 783 | } | 
|---|
| 784 |  | 
|---|
| 785 | my $iheader = $subdir . "/" . $header; | 
|---|
| 786 | my @classes = $public_header ? classNames($iheader) : (); | 
|---|
| 787 | if($showonly) { | 
|---|
| 788 | print "$header [$lib]\n"; | 
|---|
| 789 | foreach(@classes) { | 
|---|
| 790 | print "SYMBOL: $_\n"; | 
|---|
| 791 | } | 
|---|
| 792 | } else { | 
|---|
| 793 | #find out all the places it goes.. | 
|---|
| 794 | my @headers; | 
|---|
| 795 | if ($public_header) { | 
|---|
| 796 | @headers = ( "$out_basedir/include/$lib/$header" ); | 
|---|
| 797 | push @headers, "$out_basedir/include/Qt/$header" | 
|---|
| 798 | if ("$lib" ne "phonon" && "$subdir" =~ /^$basedir\/src/); | 
|---|
| 799 |  | 
|---|
| 800 | foreach(@classes) { | 
|---|
| 801 | my $header_base = basename($header); | 
|---|
| 802 | my $class = $_; | 
|---|
| 803 | # Strip namespaces: | 
|---|
| 804 | $class =~ s/^.*:://; | 
|---|
| 805 | #                               if ($class =~ m/::/) { | 
|---|
| 806 | #                                  class =~ s,::,/,g; | 
|---|
| 807 | #                               } | 
|---|
| 808 | $class_lib_map_contents .= "QT_CLASS_LIB($_, $lib, $header_base)\n"; | 
|---|
| 809 | $header_copies++ if(syncHeader("$out_basedir/include/$lib/$class", "$out_basedir/include/$lib/$header", 0)); | 
|---|
| 810 | } | 
|---|
| 811 | } else { | 
|---|
| 812 | @headers = ( "$out_basedir/include/$lib/private/$header" ); | 
|---|
| 813 | push @headers, "$out_basedir/include/Qt/private/$header" | 
|---|
| 814 | if ("$lib" ne "phonon"); | 
|---|
| 815 | } | 
|---|
| 816 | foreach(@headers) { #sync them | 
|---|
| 817 | $header_copies++ if(syncHeader($_, $iheader, $copy_headers)); | 
|---|
| 818 | } | 
|---|
| 819 |  | 
|---|
| 820 | if($public_header) { | 
|---|
| 821 | #put it into the master file | 
|---|
| 822 | $master_contents .= "#include \"$public_header\"\n" if(shouldMasterInclude($iheader)); | 
|---|
| 823 |  | 
|---|
| 824 | #deal with the install directives | 
|---|
| 825 | if($public_header) { | 
|---|
| 826 | my $pri_install_iheader = fixPaths($iheader, $current_dir); | 
|---|
| 827 | foreach(@classes) { | 
|---|
| 828 | my $class = $_; | 
|---|
| 829 | # Strip namespaces: | 
|---|
| 830 | $class =~ s/^.*:://; | 
|---|
| 831 | #                                   if ($class =~ m/::/) { | 
|---|
| 832 | #                                       $class =~ s,::,/,g; | 
|---|
| 833 | #                                   } | 
|---|
| 834 | my $class_header = fixPaths("$out_basedir/include/$lib/$class", | 
|---|
| 835 | $current_dir) . " "; | 
|---|
| 836 | $pri_install_classes .= $class_header | 
|---|
| 837 | unless($pri_install_classes =~ $class_header); | 
|---|
| 838 | } | 
|---|
| 839 | $pri_install_files.= "$pri_install_iheader ";; | 
|---|
| 840 | } | 
|---|
| 841 | } | 
|---|
| 842 | else { | 
|---|
| 843 | my $pri_install_iheader = fixPaths($iheader, $current_dir); | 
|---|
| 844 | $pri_install_pfiles.= "$pri_install_iheader ";; | 
|---|
| 845 | } | 
|---|
| 846 | } | 
|---|
| 847 | print "header created for $iheader ($header_copies)\n" if($header_copies > 0); | 
|---|
| 848 | } | 
|---|
| 849 | } | 
|---|
| 850 | } | 
|---|
| 851 | } | 
|---|
| 852 |  | 
|---|
| 853 | # close the master include: | 
|---|
| 854 | $master_contents .= "#endif\n"; | 
|---|
| 855 |  | 
|---|
| 856 | unless($showonly) { | 
|---|
| 857 | my @master_includes; | 
|---|
| 858 | push @master_includes, "$out_basedir/include/$lib/$lib"; | 
|---|
| 859 | foreach my $master_include (@master_includes) { | 
|---|
| 860 | #generate the "master" include file | 
|---|
| 861 | $pri_install_files .= fixPaths($master_include, "$modules{$lib}") . " "; #get the master file installed too | 
|---|
| 862 | if($master_include && -e "$master_include") { | 
|---|
| 863 | open MASTERINCLUDE, "<$master_include"; | 
|---|
| 864 | local $/; | 
|---|
| 865 | binmode MASTERINCLUDE; | 
|---|
| 866 | my $oldmaster = <MASTERINCLUDE>; | 
|---|
| 867 | close MASTERINCLUDE; | 
|---|
| 868 | $oldmaster =~ s/\r//g; # remove \r's , so comparison is ok on all platforms | 
|---|
| 869 | $master_include = 0 if($oldmaster eq $master_contents); | 
|---|
| 870 | } | 
|---|
| 871 | if($master_include && $master_contents) { | 
|---|
| 872 | my $master_dir = dirname($master_include); | 
|---|
| 873 | mkpath $master_dir, 0777; | 
|---|
| 874 | print "header (master) created for $lib\n"; | 
|---|
| 875 | open MASTERINCLUDE, ">$master_include"; | 
|---|
| 876 | print MASTERINCLUDE "$master_contents"; | 
|---|
| 877 | close MASTERINCLUDE; | 
|---|
| 878 | } | 
|---|
| 879 | } | 
|---|
| 880 |  | 
|---|
| 881 | #handle the headers.pri for each module | 
|---|
| 882 | my $headers_pri_contents = ""; | 
|---|
| 883 | $headers_pri_contents .= "SYNCQT.HEADER_FILES = $pri_install_files\n"; | 
|---|
| 884 | $headers_pri_contents .= "SYNCQT.HEADER_CLASSES = $pri_install_classes\n"; | 
|---|
| 885 | $headers_pri_contents .= "SYNCQT.PRIVATE_HEADER_FILES = $pri_install_pfiles\n"; | 
|---|
| 886 | my $headers_pri_file = "$out_basedir/include/$lib/headers.pri"; | 
|---|
| 887 | if(-e "$headers_pri_file") { | 
|---|
| 888 | open HEADERS_PRI_FILE, "<$headers_pri_file"; | 
|---|
| 889 | local $/; | 
|---|
| 890 | binmode HEADERS_PRI_FILE; | 
|---|
| 891 | my $old_headers_pri_contents = <HEADERS_PRI_FILE>; | 
|---|
| 892 | close HEADERS_PRI_FILE; | 
|---|
| 893 | $old_headers_pri_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms | 
|---|
| 894 | $headers_pri_file = 0 if($old_headers_pri_contents eq $headers_pri_contents); | 
|---|
| 895 | } | 
|---|
| 896 | if($headers_pri_file && $master_contents) { | 
|---|
| 897 | my $headers_pri_dir = dirname($headers_pri_file); | 
|---|
| 898 | mkpath $headers_pri_dir, 0777; | 
|---|
| 899 | print "headers.pri file created for $lib\n"; | 
|---|
| 900 | open HEADERS_PRI_FILE, ">$headers_pri_file"; | 
|---|
| 901 | print HEADERS_PRI_FILE "$headers_pri_contents"; | 
|---|
| 902 | close HEADERS_PRI_FILE; | 
|---|
| 903 | } | 
|---|
| 904 | } | 
|---|
| 905 | } | 
|---|
| 906 | unless($showonly) { | 
|---|
| 907 | my $class_lib_map = "$out_basedir/src/tools/uic/qclass_lib_map.h"; | 
|---|
| 908 | if(-e "$class_lib_map") { | 
|---|
| 909 | open CLASS_LIB_MAP, "<$class_lib_map"; | 
|---|
| 910 | local $/; | 
|---|
| 911 | binmode CLASS_LIB_MAP; | 
|---|
| 912 | my $old_class_lib_map_contents = <CLASS_LIB_MAP>; | 
|---|
| 913 | close CLASS_LIB_MAP; | 
|---|
| 914 | $old_class_lib_map_contents =~ s/\r//g; # remove \r's , so comparison is ok on all platforms | 
|---|
| 915 | $class_lib_map = 0 if($old_class_lib_map_contents eq $class_lib_map_contents); | 
|---|
| 916 | } | 
|---|
| 917 | if($class_lib_map) { | 
|---|
| 918 | my $class_lib_map_dir = dirname($class_lib_map); | 
|---|
| 919 | mkpath $class_lib_map_dir, 0777; | 
|---|
| 920 | open CLASS_LIB_MAP, ">$class_lib_map"; | 
|---|
| 921 | print CLASS_LIB_MAP "$class_lib_map_contents"; | 
|---|
| 922 | close CLASS_LIB_MAP; | 
|---|
| 923 | } | 
|---|
| 924 | } | 
|---|
| 925 |  | 
|---|
| 926 | if($check_includes) { | 
|---|
| 927 | for (keys(%modules)) { | 
|---|
| 928 | #iteration info | 
|---|
| 929 | my $lib = $_; | 
|---|
| 930 | my $dir = "$modules{$lib}"; | 
|---|
| 931 | foreach (split(/;/, $dir)) { | 
|---|
| 932 | my $current_dir = "$_"; | 
|---|
| 933 | #calc subdirs | 
|---|
| 934 | my @subdirs = ($current_dir); | 
|---|
| 935 | foreach (@subdirs) { | 
|---|
| 936 | my $subdir = "$_"; | 
|---|
| 937 | opendir DIR, "$subdir"; | 
|---|
| 938 | while(my $t = readdir(DIR)) { | 
|---|
| 939 | push @subdirs, "$subdir/$t" if(-d "$subdir/$t" && !($t eq ".") && | 
|---|
| 940 | !($t eq "..") && !($t eq ".obj") && | 
|---|
| 941 | !($t eq ".moc") && !($t eq ".rcc") && | 
|---|
| 942 | !($t eq ".uic") && !($t eq "build")); | 
|---|
| 943 | } | 
|---|
| 944 | closedir DIR; | 
|---|
| 945 | } | 
|---|
| 946 |  | 
|---|
| 947 | foreach (@subdirs) { | 
|---|
| 948 | my $subdir = "$_"; | 
|---|
| 949 | my $header_skip_qt_module_test = 0; | 
|---|
| 950 | foreach(@ignore_for_qt_module_check) { | 
|---|
| 951 | foreach (split(/;/, $_)) { | 
|---|
| 952 | $header_skip_qt_module_test = 1 if ("$subdir" =~ /^$_/); | 
|---|
| 953 | } | 
|---|
| 954 | } | 
|---|
| 955 | my @headers = findFiles("$subdir", "^[-a-z0-9_]*\\.h\$" , 0); | 
|---|
| 956 | foreach (@headers) { | 
|---|
| 957 | my $header = "$_"; | 
|---|
| 958 | my $header_skip_qt_begin_header_test = 0; | 
|---|
| 959 | my $header_skip_qt_begin_namespace_test = 0; | 
|---|
| 960 | $header = 0 if("$header" =~ /^ui_.*.h/); | 
|---|
| 961 | foreach (@ignore_headers) { | 
|---|
| 962 | $header = 0 if("$header" eq "$_"); | 
|---|
| 963 | } | 
|---|
| 964 | if($header) { | 
|---|
| 965 | my $public_header = $header; | 
|---|
| 966 | if($public_header =~ /_p.h$/ || $public_header =~ /_pch.h$/) { | 
|---|
| 967 | $public_header = 0; | 
|---|
| 968 | } else { | 
|---|
| 969 | foreach (@ignore_for_master_contents) { | 
|---|
| 970 | $public_header = 0 if("$header" eq "$_"); | 
|---|
| 971 | } | 
|---|
| 972 | if($public_header) { | 
|---|
| 973 | foreach (@ignore_for_include_check) { | 
|---|
| 974 | $public_header = 0 if("$header" eq "$_"); | 
|---|
| 975 | } | 
|---|
| 976 | foreach(@ignore_for_qt_begin_header_check) { | 
|---|
| 977 | $header_skip_qt_begin_header_test = 1 if ("$header" eq "$_"); | 
|---|
| 978 | } | 
|---|
| 979 | foreach(@ignore_for_qt_begin_namespace_check) { | 
|---|
| 980 | $header_skip_qt_begin_namespace_test = 1 if ("$header" eq "$_"); | 
|---|
| 981 | } | 
|---|
| 982 | } | 
|---|
| 983 | } | 
|---|
| 984 |  | 
|---|
| 985 | my $iheader = $subdir . "/" . $header; | 
|---|
| 986 | if($public_header) { | 
|---|
| 987 | if(open(F, "<$iheader")) { | 
|---|
| 988 | my $qt_module_found = 0; | 
|---|
| 989 | my $qt_begin_header_found = 0; | 
|---|
| 990 | my $qt_end_header_found = 0; | 
|---|
| 991 | my $qt_begin_namespace_found = 0; | 
|---|
| 992 | my $qt_end_namespace_found = 0; | 
|---|
| 993 | my $line; | 
|---|
| 994 | while($line = <F>) { | 
|---|
| 995 | chomp $line; | 
|---|
| 996 | my $output_line = 1; | 
|---|
| 997 | if($line =~ /^ *\# *pragma (qt_no_included_check|qt_sync_stop_processing)/) { | 
|---|
| 998 | last; | 
|---|
| 999 | } elsif($line =~ /^ *\# *include/) { | 
|---|
| 1000 | my $include = $line; | 
|---|
| 1001 | if($line =~ /<.*>/) { | 
|---|
| 1002 | $include =~ s,.*<(.*)>.*,$1,; | 
|---|
| 1003 | } elsif($line =~ /".*"/) { | 
|---|
| 1004 | $include =~ s,.*"(.*)".*,$1,; | 
|---|
| 1005 | } else { | 
|---|
| 1006 | $include = 0; | 
|---|
| 1007 | } | 
|---|
| 1008 | if($include) { | 
|---|
| 1009 | for (keys(%modules)) { | 
|---|
| 1010 | my $trylib = $_; | 
|---|
| 1011 | if(-e "$out_basedir/include/$trylib/$include") { | 
|---|
| 1012 | print "WARNING: $iheader includes $include when it should include $trylib/$include\n"; | 
|---|
| 1013 | } | 
|---|
| 1014 | } | 
|---|
| 1015 | } | 
|---|
| 1016 | } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_BEGIN_HEADER\s*$/) { | 
|---|
| 1017 | $qt_begin_header_found = 1; | 
|---|
| 1018 | } elsif ($header_skip_qt_begin_header_test == 0 and $line =~ /^QT_END_HEADER\s*$/) { | 
|---|
| 1019 | $qt_end_header_found = 1; | 
|---|
| 1020 | } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_BEGIN_NAMESPACE\s*$/) { | 
|---|
| 1021 | $qt_begin_namespace_found = 1; | 
|---|
| 1022 | } elsif ($header_skip_qt_begin_namespace_test == 0 and $line =~ /^QT_END_NAMESPACE\s*$/) { | 
|---|
| 1023 | $qt_end_namespace_found = 1; | 
|---|
| 1024 | } elsif ($header_skip_qt_module_test == 0 and $line =~ /^QT_MODULE\(.*\)\s*$/) { | 
|---|
| 1025 | $qt_module_found = 1; | 
|---|
| 1026 | } | 
|---|
| 1027 | } | 
|---|
| 1028 | if ($header_skip_qt_begin_header_test == 0) { | 
|---|
| 1029 | if ($qt_begin_header_found == 0) { | 
|---|
| 1030 | print "WARNING: $iheader does not include QT_BEGIN_HEADER\n"; | 
|---|
| 1031 | } | 
|---|
| 1032 |  | 
|---|
| 1033 | if ($qt_begin_header_found && $qt_end_header_found == 0) { | 
|---|
| 1034 | print "WARNING: $iheader has QT_BEGIN_HEADER but no QT_END_HEADER\n"; | 
|---|
| 1035 | } | 
|---|
| 1036 | } | 
|---|
| 1037 |  | 
|---|
| 1038 | if ($header_skip_qt_begin_namespace_test == 0) { | 
|---|
| 1039 | if ($qt_begin_namespace_found == 0) { | 
|---|
| 1040 | print "WARNING: $iheader does not include QT_BEGIN_NAMESPACE\n"; | 
|---|
| 1041 | } | 
|---|
| 1042 |  | 
|---|
| 1043 | if ($qt_begin_namespace_found && $qt_end_namespace_found == 0) { | 
|---|
| 1044 | print "WARNING: $iheader has QT_BEGIN_NAMESPACE but no QT_END_NAMESPACE\n"; | 
|---|
| 1045 | } | 
|---|
| 1046 | } | 
|---|
| 1047 |  | 
|---|
| 1048 | if ($header_skip_qt_module_test == 0) { | 
|---|
| 1049 | if ($qt_module_found == 0) { | 
|---|
| 1050 | print "WARNING: $iheader does not include QT_MODULE\n"; | 
|---|
| 1051 | } | 
|---|
| 1052 | } | 
|---|
| 1053 | close(F); | 
|---|
| 1054 | } | 
|---|
| 1055 | } | 
|---|
| 1056 | } | 
|---|
| 1057 | } | 
|---|
| 1058 | } | 
|---|
| 1059 | } | 
|---|
| 1060 | } | 
|---|
| 1061 | } | 
|---|
| 1062 |  | 
|---|
| 1063 | exit 0; | 
|---|