* Added command line tool example similar to 'sopranocmd'
[kdebindings.git] / smoke / qtscript / generate.pl.cmake
blob10419bbe2c20bd5d3289c24fd19261c5f2859713
1 #!/usr/bin/perl -w
3 ## Run this first, to generate the x_*.cpp files from the Qt headers
4 ## using kalyptus
6 my $kalyptusdir = "@CMAKE_CURRENT_SOURCE_DIR@/../../kalyptus";
8 use File::Basename;
9 use File::Copy qw|cp|;
10 use File::Compare;
11 use File::Find;
12 use Cwd;
14 my $here = getcwd;
15 my $outdir = $here . "/generate.pl.tmpdir";
16 my $finaloutdir = $here;
17 my $defines = "qtdefines";
18 my $headerlist = "@CMAKE_CURRENT_SOURCE_DIR@/header_list";
19 my $definespath = "$here/../$defines";
20 my $headerlistpath = "$headerlist";
21 my $qtscript_headerlist = "";
22 my $qtscript_headerlistpath = "";
24 $qtscript_headerlist = "@CMAKE_CURRENT_SOURCE_DIR@/qtscript_header_list";
25 $qtscript_headerlistpath = "$here/$qtscript_headerlist";
27 ## If srcdir != builddir, use headerlist from src
28 $headerlistpath = $headerlist if ($headerlist =~ /^\//);
29 $qtscript_headerlistpath = $qtscript_headerlist if ($qtscript_headerlist =~ /^\//);
31 ## Note: outdir and finaloutdir should NOT be the same dir!
33 # Delete all x_*.cpp files under outdir (or create outdir if nonexistent)
34 if (-d $outdir) { system "rm -f $outdir/x_*.cpp"; } else { mkdir $outdir; }
36 mkdir $finaloutdir unless (-d $finaloutdir);
38 # Load the QT_NO_* macros found in "qtdefines". They'll be passed to kalyptus
39 my $macros="";
40 if ( -e $definespath ){
41 print "Found '$defines'. Reading preprocessor symbols from there...\n";
42 $macros = " --defines=$definespath ";
45 mkdir $kalyptusdir, 0777;
46 # Need to cd to kalyptus's directory so that perl finds Ast.pm etc.
47 chdir "$kalyptusdir" or die "Couldn't go to $kalyptusdir (edit script to change dir)\n";
49 # Find out which header files we need to parse
50 # We don't want all of them - e.g. not template-based stuff
51 my %excludes = (
52 # 'qaccessible.h' => 1, # Accessibility support is not compiled by defaut
53 # 'qassistantclient.h' => 1, # Not part of Qt (introduced in Qt-3.1)
54 # 'qmotif.h' => 1, #
55 # 'qmotifwidget.h' => 1, # Motif extension (introduced in Qt-3.1)
56 # 'qmotifdialog.h' => 1, #
57 # 'qxt.h' => 1, # Xt
58 # 'qxtwidget.h' => 1, # Xt
59 # 'qdns.h' => 1, # internal
60 # 'qgl.h' => 1, # OpenGL
61 # 'qglcolormap.h' => 1, # OpenGL
62 # 'qnp.h' => 1, # NSPlugin
63 # 'qttableview.h' => 1, # Not in Qt anymore...
64 # 'qtmultilineedit.h' => 1, # Not in Qt anymore...
65 # 'qwidgetfactory.h' => 1, # Just an interface
66 # 'qsharedmemory.h' => 1, # "not part of the Qt API" they say
67 # 'qwindowsstyle.h' => 1, # Qt windowsstyle, plugin
68 # 'qmotifstyle.h' => 1,
69 # 'qcompactstyle.h' => 1,
70 # 'qinterlacestyle.h' => 1,
71 # 'qmotifplusstyle.h' => 1,
72 # 'qsgistyle.h' => 1,
73 # 'qplatinumstyle.h' => 1,
74 # 'qcdestyle.h' => 1,
75 # 'qworkspace.h' => 1,
76 # 'qwindowsxpstyle.h' => 1 # play on the safe side
79 # Some systems have a QTDIR = KDEDIR = PREFIX
80 # We need a complete list
82 my %includes;
83 open(HEADERS, $headerlistpath) or die "Couldn't open $headerlistpath: $!\n";
84 map { chomp ; $includes{$_} = 1 } <HEADERS>;
85 close HEADERS;
87 open(HEADERS, $qtscript_headerlistpath) or die "Couldn't open $qtscript_headerlistpath: $!\n";
88 map { chomp ; $includes{$_} = 1 } <HEADERS>;
89 close HEADERS;
91 # Can we compile the OpenGl module ?
92 if("@QT_OPENGL_FOUND@" eq "YES")
94 open(DEFS, $definespath);
95 my @defs = <DEFS>;
96 close DEFS;
97 if(!grep(/QT_NO_OPENGL/, @defs))
99 $excludes{'qgl.h'} = undef;
100 $excludes{'qglcolormap.h'} = undef;
102 else
104 print STDERR "Qt was not compiled with OpenGL support...\n Skipping QGL Classes.\n";
108 # List Qt headers, and exclude the ones listed above
109 my @headers = ();
111 my @qtinc= (@qt_incs@);
113 find(
114 { wanted => sub {
115 (-e || -l and !-d) and do {
116 $f = $_;
117 if( !defined $excludes{$f} # Not excluded
118 && $includes{$f} # Known header
119 && /\.h$/) # Not a backup file etc. Only headers.
121 my $header = $File::Find::name;
122 open(FILE, $header);
123 my @header_lines = <FILE>;
124 if (@header_lines == 1) {
125 $line = $header_lines[0];
126 if ($line =~ /^#include "(.*)"/) {
127 push ( @headers, $File::Find::dir . substr($1, 2) );
128 } else {
129 push ( @headers, $header );
131 } else {
132 push ( @headers, $header );
135 undef $includes{$f}
138 follow_fast => 1,
139 follow_skip => 2,
140 no_chdir => 0
141 }, @qtinc
144 # Launch kalyptus
145 chdir "../smoke/qtscript";
146 system "perl -I@kdebindings_SOURCE_DIR@/kalyptus @kdebindings_SOURCE_DIR@/kalyptus/kalyptus @ARGV --qt4 --globspace -fsmoke --name=qtscript --classlist='@CMAKE_CURRENT_SOURCE_DIR@/classlist' --init-modules=qt $macros --no-cache --outputdir=$outdir @headers";
147 my $exit = $? >> 8;
148 exit $exit if ($exit);
149 chdir "$kalyptusdir";
151 # Generate diff for smokedata.cpp
152 unless ( -e "$finaloutdir/smokedata.cpp" ) {
153 open( TOUCH, ">$finaloutdir/smokedata.cpp");
154 close TOUCH;
156 system "diff -u $finaloutdir/smokedata.cpp $outdir/smokedata.cpp > $outdir/smokedata.cpp.diff";
158 # Copy changed or new files to finaloutdir
159 opendir (OUT, $outdir) or die "Couldn't opendir $outdir";
160 foreach $filename (readdir(OUT)) {
161 next if ( -d "$outdir/$filename" ); # only files, not dirs
162 my $docopy = 1;
163 if ( -f "$finaloutdir/$filename" ) {
164 $docopy = compare("$outdir/$filename", "$finaloutdir/$filename"); # 1 if files are differents
166 if ($docopy) {
167 #print STDERR "Updating $filename...\n";
168 cp("$outdir/$filename", "$finaloutdir/$filename");
171 closedir OUT;
173 # Check for deleted files and warn
174 my $deleted = 0;
175 opendir(FINALOUT, $finaloutdir) or die "Couldn't opendir $finaloutdir";
176 foreach $filename (readdir(FINALOUT)) {
177 next if ( -d "$finaloutdir/$filename" ); # only files, not dirs
178 if ( $filename =~ /.cpp$/ && ! ($filename =~ /_la_closure.cpp/) && ! -f "$outdir/$filename" ) {
179 print STDERR "Removing obsolete file $filename\n";
180 unlink "$finaloutdir/$filename";
181 $deleted = 1;
184 closedir FINALOUT;
186 # Delete outdir
187 system "rm -rf $outdir";