You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdebindings/smoke/tqt/generate.pl.in

178 lines
5.5 KiB

#!/usr/bin/perl -w
## Run this first, to generate the x_*.cpp files from the TQt headers
## using kalyptus
my $kalyptusdir = "../../kalyptus";
use File::Basename;
use File::Copy qw|cp|;
use File::Compare;
use Cwd;
my $here = getcwd;
my $outdir = $here . "/generate.pl.tmpdir";
my $finaloutdir = $here;
my $defines = "qtdefines";
my $headerlist = "@srcdir@/header_list";
my $definespath = "$here/$defines";
my $headerlistpath = "$here/$headerlist";
my $qscintilla_headerlist = "";
my $qscintilla_headerlistpath = "";
if("@qtextscintilla@" eq "yes")
{
$qscintilla_headerlist = "./qscintilla_header_list";
$qscintilla_headerlistpath = "$here/$qscintilla_headerlist";
}
## If srcdir != builddir, use headerlist from src
$headerlistpath = $headerlist if ($headerlist =~ /^\//);
if("@qtextscintilla@" eq "yes")
{
$qscintilla_headerlistpath = $qscintilla_headerlist if ($qscintilla_headerlist =~ /^\//);
}
## Note: outdir and finaloutdir should NOT be the same dir!
# Delete all x_*.cpp files under outdir (or create outdir if nonexistent)
if (-d $outdir) { system "rm -f $outdir/x_*.cpp"; } else { mkdir $outdir; }
mkdir $finaloutdir unless (-d $finaloutdir);
# Load the TQT_NO_* macros found in "qtdefines". They'll be passed to kalyptus
my $macros="";
if ( -e $definespath ){
print "Found '$defines'. Reading preprocessor symbols from there...\n";
$macros = " --defines=$definespath ";
}
mkdir $kalyptusdir, 0777;
# Need to cd to kalyptus's directory so that perl finds Ast.pm etc.
chdir "$kalyptusdir" or die "Couldn't go to $kalyptusdir (edit script to change dir)\n";
# Find out which header files we need to parse
# We don't want all of them - e.g. not template-based stuff
my %excludes = (
'tqaccessible.h' => 1, # Accessibility support is not compiled by defaut
'tqassistantclient.h' => 1, # Not part of Qt (introduced in Qt-3.1)
'tqmotif.h' => 1, #
'tqmotifwidget.h' => 1, # Motif extension (introduced in Qt-3.1)
'tqmotifdialog.h' => 1, #
'tqxt.h' => 1, # Xt
'tqxtwidget.h' => 1, # Xt
'tqdns.h' => 1, # internal
'tqgl.h' => 1, # OpenGL
'tqglcolormap.h' => 1, # OpenGL
'tqnp.h' => 1, # NSPlugin
'tqwidgetfactory.h' => 1, # Just an interface
'tqsharedmemory.h' => 1, # "not part of the Qt API" they say
'tqwindowsstyle.h' => 1, # Qt windowsstyle, plugin
'tqmotifstyle.h' => 1,
'tqcompactstyle.h' => 1,
'tqinterlacestyle.h' => 1,
'tqmotifplusstyle.h' => 1,
'tqsgistyle.h' => 1,
'tqplatinumstyle.h' => 1,
'tqcdestyle.h' => 1,
'tqworkspace.h' => 1,
'tqwindowsxpstyle.h' => 1 # play on the safe side
);
# Some systems have a TQTDIR = TDEDIR = PREFIX
# We need a complete list
my %includes;
open(HEADERS, $headerlistpath) or die "Couldn't open $headerlistpath: $!\n";
map { chomp ; $includes{$_} = 1 } <HEADERS>;
close HEADERS;
if("@qtextscintilla@" eq "yes")
{
open(HEADERS, $qscintilla_headerlistpath) or die "Couldn't open $qscintilla_headerlistpath: $!\n";
map { chomp ; $includes{$_} = 1 } <HEADERS>;
close HEADERS;
}
# Can we compile the OpenGl module ?
if("@KDE_HAVE_GL@" eq "yes")
{
open(DEFS, $definespath);
my @defs = <DEFS>;
close DEFS;
if(!grep(/TQT_NO_OPENGL/, @defs))
{
$excludes{'qgl.h'} = undef;
$excludes{'qglcolormap.h'} = undef;
}
else
{
print STDERR "TQt was not compiled with OpenGL support...\n Skipping TQGL Classes.\n";
}
}
# List Qt headers, and exclude the ones listed above
my @headers = ();
$qtinc= '@tqt_includes@';
opendir (QT, $qtinc) or die "Couldn't find $qtinc";
foreach $filename (readdir(QT)) {
$entry = $qtinc."/".$filename;
if ( ( -e $entry or -l $entry ) # A real file or a symlink
&& ( ! -d _ ) ) # Not a symlink to a dir though
{
push(@headers, $entry)
if ( !defined $excludes{$filename} # Not excluded
&& $includes{$filename} # Known header
&& $filename =~ /\.h$/ ); # Not a backup file etc. Only headers.
undef $includes{$filename}
}
}
closedir QT;
# Launch kalyptus
$ENV{KDE_PREFIX} = "@KDE_PREFIX@";
chdir "../smoke/tqt";
system "perl -I@top_srcdir@/kalyptus @top_srcdir@/kalyptus/kalyptus @ARGV --globspace -fsmoke --name=qt $macros --no-cache --outputdir=$outdir @headers";
my $exit = $? >> 8;
exit $exit if ($exit);
chdir "$kalyptusdir";
# Generate diff for smokedata.cpp
unless ( -e "$finaloutdir/smokedata.cpp" ) {
open( TOUCH, ">$finaloutdir/smokedata.cpp");
close TOUCH;
}
system "diff -u $finaloutdir/smokedata.cpp $outdir/smokedata.cpp > $outdir/smokedata.cpp.diff";
# Copy changed or new files to finaloutdir
opendir (OUT, $outdir) or die "Couldn't opendir $outdir";
foreach $filename (readdir(OUT)) {
next if ( -d "$outdir/$filename" ); # only files, not dirs
my $docopy = 1;
if ( -f "$finaloutdir/$filename" ) {
$docopy = compare("$outdir/$filename", "$finaloutdir/$filename"); # 1 if files are differents
}
if ($docopy) {
#print STDERR "Updating $filename...\n";
cp("$outdir/$filename", "$finaloutdir/$filename");
}
}
closedir OUT;
# Check for deleted files and warn
my $deleted = 0;
opendir(FINALOUT, $finaloutdir) or die "Couldn't opendir $finaloutdir";
foreach $filename (readdir(FINALOUT)) {
next if ( -d "$finaloutdir/$filename" ); # only files, not dirs
if ( $filename =~ /.cpp$/ && ! ($filename =~ /_la_closure.cpp/) && ! -f "$outdir/$filename" ) {
print STDERR "Removing obsolete file $filename\n";
unlink "$finaloutdir/$filename";
$deleted = 1;
}
}
closedir FINALOUT;
# Delete outdir
system "rm -rf $outdir";