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