~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to bin/syncqt

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

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