#!/usr/bin/perl # qtguess.pl : check how TQt was compiled. Issue a list of all defined TQT_NO_* macros, one per line. # # author: germain Garand # licence: GPL v.2 # options: -q: be quieter # -o file: redirect output to "file". (default: ./qtdefines) # -t [0..15]: set the testing threshold (see below) # -f "flags": additional compiler flags/parameters use Getopt::Std; use vars qw/$opt_f $opt_o $opt_p/; getopts('qo:f:t:'); # Threshold : # 0 - test basic TQt types/classes # 5 - test higher level, non-gui classes # 8 - test options of the above (ex: TQT_NO_IMAGE_SMOOTHSCALE) # 10 - test basic widgets # 12 - test composite widgets # 13 - test widgets inheriting composite widgets # 15 - test goodies (default) my $default_threshold = @qt_test_threshold@; my $cc = "@CXX@"; my $ccflags = $opt_f || "@CXXFLAGS@"; my $nspaces = 50; my %qtdefs=(); my %qtundefs=(); my $tmp = gettmpfile(); my $qtinc = '@tqt_includes@'; my $allinc = '@all_includes@'; my $alllib = '@all_libraries@'; my $qtflags ='@LIB_TQT@'; my %x; $x{'LIBPNG'} = '@LIBPNG@'; $x{'LIBJPEG'} = '@LIBJPEG@'; $x{'LIBSM'} = '@LIBSM@'; $x{'LIBSOCKET'} = '@LIBSOCKET@'; $x{'LIBDL'} = '@LIBDL@'; $x{'LIBRESOLV'} = '@LIBRESOLV@'; $x{'LIB_X11'} = '@LIB_X11@'; $x{'X_PRE_LIBS'} = '@X_PRE_LIBS@'; $x{'LIB_X11'} =~ s/\$\((.*?)\)/$x{$1}/g; $qtflags =~ s/\$\((.*?)\)/$x{$1}/g; -e "$qtinc/tqglobal.h" or die "Invalid TQt directory.\n"; my $ccmd = "$cc $ccflags $allinc $alllib -o $tmp $tmp.cpp $qtflags"; my $threshold = defined($opt_t)?$opt_t : $default_threshold; $threshold >= 0 or die "invalid testing threshold: $threshold\n"; print "Checking how TQt was built... \n"; print "Threshold is set to $threshold\n" unless $opt_q; my($count, $used, $total); map{ $tests{$_}->[2]>=$threshold ? ($used++, $total++):$total++ } keys %tests; print "Number of defines to be tested : $used/$total\n\n" unless $opt_q; open( TQTDEFS, ">".($opt_o || "tqtdefines") ) or die "Can't open output file: $!\n"; grab_qglobal_symbols(); preliminary_test(); perform_all_tests(); print +scalar(keys %qtdefs) . " defines found.\n"; print TQTDEFS join("\n", keys %qtdefs), "\n"; close; #--------------------------------------------------------------# sub gettmpfile { my $tmpdir = $ENV{'TMP'} || "."; my $tmpname = $$."-qtguess"; while( -e "$tmpdir/$tmpname" || -e "$tmpdir/${tmpname}.cpp" ) { $tmpname .= int (rand * 9); } return "$tmpdir/$tmpname"; } #--------------------------------------------------------------# sub grab_qglobal_symbols { my $cmd = "$cc -E -D__cplusplus -dM -I$qtinc $qtinc/tqglobal.h 2>/dev/null"; my $symbols = `$cmd`; for(0..1) { if( check_exit_status($?) ) { while( $symbols =~/^#\s*define\s*(TQT_\S+)/gm ) { $qtdefs{$1} = 1; } print "Found ". scalar( keys %qtdefs )." predefined symbol".((scalar( keys %qtdefs ) -1)?"s":"")." in qglobal.h\n" unless ($opt_q or !(keys %qtdefs)); while( $symbols =~/^#\s*define\s*TQT_MODULE_(\S+)/gm ) { $qtundefs{"TQT_NO_$1"} = 1; } print "Found ". scalar( keys %qtundefs )." undefined symbol".((scalar( keys %qtundefs ) -1)?"s":"")." in qglobal.h\n" unless ($opt_q or !(keys %qtundefs)); last; } elsif(! $_) # first try { print "Failed to run $cmd.\nTrying without __cplusplus (might be already defined)\n"; $cmd = "$cc -E -dM -I$qtinc $qtinc/tqglobal.h 2>/dev/null"; $symbols = `$cmd`; next; } } } #--------------------------------------------------------------# sub preliminary_test { my $msg = "Trying to compile and link a small program..."; print $msg, " " x ($nspaces - length($msg) + 8); open( OUT, ">${tmp}.cpp" ) or die "Failed to open temp file ${tmp}.cpp: $!\n"; my $simple=q£ #include int main( int argc, char **argv ) { TQApplication foo( argc, argv ); return 0; } £; print OUT $simple; close OUT; my $out = `$ccmd 2>&1`; if( !check_exit_status($?) ) { die <<"EOF"; FAILED : check your configuration. Failed program was: $simple Compiled with: $ccmd Compiler output: $out EOF } else { print "OK\n"; } } #--------------------------------------------------------------# sub perform_all_tests { foreach ( sort { $tests{$a}->[2] <=> $tests{$b}->[2]} keys %tests) { $tests{$_}->[2] < $threshold and next; ($qtdefs{$_} || $qtundefs{$_}) and do { print "\rSkipping $_ (in tqglobal.h)".( " " x (($nspaces-16) - length($_)) ).($qtundefs{$_}?"*Undefined*":" [Defined]").($opt_q?"":"\n"); next }; print "\rTesting $_".( " " x ($nspaces - length($_)) ); open( OUT, ">${tmp}.cpp" ) or die "Failed to open temp file ${tmp}.cpp: $!\n"; foreach $def(keys %qtdefs) { print OUT "#define $def\n"; } foreach $inc(split /,\s*/, $tests{$_}->[0]) { print OUT "#include <$inc>\n"; } print OUT "#include \n"; print OUT $tests{$_}->[3] if $tests{$_}->[3]; # need to define some classes ? print OUT qq£ int main( int argc, char **argv ) { $tests{$_}->[1] return 0; } £; close OUT; my $out = `$ccmd 2>&1`; my $ok = check_exit_status($?); if( !$ok ) { $qtdefs{$_} = 1; } print +$opt_q ? ++$count."/$used" : ( $ok ? "*Undefined*\n" : " [Defined]\n" ); } $opt_q && print "\n"; } #--------------------------------------------------------------# sub check_exit_status { my $a = 0xFFFF & shift; if( !$a ) { return 1; } elsif( $a == 0xFF00 ) { die "\nSystem call failed: $!\n"; } elsif( $a > 0x80 ) { # non-zero status. } else { if( $a & 0x80 ) { die "\n$cc coredumped with signal ". ($a & ~0x80); } die "\n$cc interrupted by signal $a\n"; } return 0; } #--------------------------------------------------------------# END { unlink $tmp if -e $tmp; unlink "${tmp}.cpp" if -e "${tmp}.cpp"; } #--------------------------------------------------------------# BEGIN { # "DEFINE" => ["header-1.h,... header-n.h", "main() code", priority, "Definitions (if needed)"] our %tests = ( "TQT_NO_ACCEL" => ["tqaccel.h", "TQAccel foo( (TQWidget*)NULL );", 5], "TQT_NO_ACTION" => ["tqaction.h", "TQAction foo( (TQObject*)NULL );", 5], "TQT_NO_ASYNC_IO" => ["tqasyncio.h", "TQAsyncIO foo();", 5], "TQT_NO_ASYNC_IMAGE_IO"=> ["tqasyncimageio.h", "TQImageDecoder foo( (TQImageConsumer*) NULL );", 5], "TQT_NO_BIG_CODECS" => ["tqbig5codec.h", "TQBig5Codec foo();", 5], "TQT_NO_BUTTON" => ["tqbutton.h", "TQButton foo( (TQWidget*)NULL );", 10], "TQT_NO_BUTTONGROUP" => ["tqbuttongroup.h", "TQButtonGroup foo( (TQWidget*)NULL );", 12], "TQT_NO_CANVAS" => ["tqcanvas.h", "TQCanvas foo( (TQObject*)NULL );", 10], "TQT_NO_CHECKBOX" => ["tqcheckbox.h", "TQCheckBox( (TQWidget*)NULL );", 10], "TQT_NO_CLIPBOARD" => ["tqapplication.h, qclipboard.h", q£ TQApplication foo( argc, argv ); TQClipboard *baz= foo.clipboard(); £, 5], "TQT_NO_COLORDIALOG" => ["tqcolordialog.h", "TQColorDialog::customCount();", 12], "TQT_NO_COMBOBOX" => ["tqcombobox.h", "TQComboBox( (TQWidget*)NULL );", 10], "TQT_NO_COMPONENT" => ["tqapplication.h", q£ TQApplication foo( argc, argv ); foo.addLibraryPath( TQString::null ); £, 5], "TQT_NO_CURSOR" => ["tqcursor.h", "TQCursor foo;", 5], "TQT_NO_DATASTREAM" => ["tqdatastream.h", "TQDataStream foo;", 5], "TQT_NO_DATETIMEEDIT" => ["tqdatetimeedit.h", "TQTimeEdit foo;", 12], "TQT_NO_DIAL" => ["tqdial.h", "TQDial foo;", 10], "TQT_NO_DIALOG" => ["tqdialog.h", "TQDialog foo;", 12], "TQT_NO_DIR" => ["tqdir.h", "TQDir foo;", 5], "TQT_NO_DNS" => ["tqdns.h", "TQDns foo;", 5], "TQT_NO_DOM" => ["tqdom.h", "TQDomDocumentType foo;", 5], "TQT_NO_DRAGANDDROP" => ["tqevent.h", "TQDropEvent foo( TQPoint(1,1) );", 5], "TQT_NO_DRAWUTIL" => ["tqdrawutil.h, qcolor.h", "tqDrawPlainRect( (TQPainter *) NULL, 0, 0, 0, 0, TQColor() );", 10], "TQT_NO_ERRORMESSAGE" => ["tqerrormessage.h", "TQErrorMessage foo( (TQWidget*) NULL );", 13], "TQT_NO_FILEDIALOG" => ["tqfiledialog.h", "TQFileIconProvider foo;", 13], "TQT_NO_FONTDATABASE" => ["tqfontdatabase.h", "TQFontDatabase foo;", 5], "TQT_NO_FONTDIALOG" => ["tqfontdialog.h", "TQFontDialog::getFont( (bool *)NULL );", 12], "TQT_NO_FRAME" => ["tqframe.h", "TQFrame foo;", 10], "TQT_NO_GRID" => ["tqgrid.h", "TQGrid foo(5);", 12], "TQT_NO_GRIDVIEW" => ["tqgridview.h", "TQFoo foo;", 13, q£ class TQFoo: public TQGridView { public: TQFoo(){}; ~TQFoo(){}; void paintCell(TQPainter *, int, int){}; }; £], "TQT_NO_GROUPBOX" => ["tqgroupbox.h", "TQGroupBox foo;", 12], "TQT_NO_HBOX" => ["tqhbox.h", "TQHBox foo;", 12], "TQT_NO_HBUTTONGROUP" => ["tqhbuttongroup.h", "TQHButtonGroup foo;", 13], "TQT_NO_HEADER" => ["tqheader.h", "TQHeader foo;", 10], "TQT_NO_HGROUPBOX" => ["tqhgroupbox.h", "TQHGroupBox foo;", 13], "TQT_NO_ICONSET" => ["tqiconset.h", "TQIconSet foo;", 8], "TQT_NO_ICONVIEW" => ["tqiconview.h", "TQIconView foo;", 13], "TQT_NO_IMAGEFORMATPLUGIN" => ["tqimageformatplugin.h, qstringlist.h", "TQFoo foo;", 5, q£ class TQFoo: public TQImageFormatPlugin { public: TQFoo() {}; ~TQFoo() {}; TQStringList keys() const { return TQStringList(); }; bool installIOHandler( const TQString &format ) { return true; }; }; TQ_EXPORT_PLUGIN( TQFoo ) £], "TQT_NO_IMAGE_DITHER_TO_1" => ["tqimage.h", q£ TQImage *foo = new TQImage; foo->createAlphaMask(); £, 8], "TQT_NO_IMAGE_HEURISTIC_MASK" => ["tqimage.h", q£ TQImage *foo = new TQImage; foo->createHeuristicMask(); £, 8], "TQT_NO_IMAGE_MIRROR" => ["tqimage.h", q£ TQImage *foo = new TQImage; foo->mirror(); £, 8], "TQT_NO_IMAGE_SMOOTHSCALE" => ["tqimage.h", q£ TQImage *foo = new TQImage; foo->smoothScale( 10, 10); £, 8], "TQT_NO_IMAGE_TEXT" => ["tqimage.h", "TQImageTextKeyLang foo;", 8], "TQT_NO_IMAGE_TRANSFORMATION" => ["tqimage.h", q£ TQImage *foo = new TQImage; foo->scale( 10, 10); £, 8], "TQT_NO_IMAGE_TRUECOLOR" => ["tqimage.h", q£ TQImage *foo = new TQImage; foo->convertDepthWithPalette( 1, (TQRgb*) NULL, 1 ); £, 8], "TQT_NO_INPUTDIALOG" => ["tqinputdialog.h, qstring.h", q£TQInputDialog::getText( TQString::null, TQString::null);£, 13], "TQT_NO_IMAGEIO" => ["tqbitmap.h, qstring.h", q£ TQBitmap foo( TQString::fromLatin1("foobar") ); £, 5], "TQT_NO_IMAGEIO_JPEG" => ["tqjpegio.h", "tqInitJpegIO();", 8], "TQT_NO_IMAGEIO_MNG" => ["tqmngio.h", "tqInitMngIO();", 8], "TQT_NO_IMAGEIO_PNG" => ["tqpngio.h", "tqInitPngIO();", 8], "TQT_NO_LABEL" => ["tqlabel.h", "TQLabel foo( (TQWidget*) NULL );", 10], "TQT_NO_LAYOUT" => ["tqlayout.h", "TQFoo foo;", 10, q£ class TQFoo: public TQLayout { public: TQFoo() {}; ~TQFoo() {}; void addItem( TQLayoutItem * ) { }; TQSize sizeHint() const { return TQSize(); } TQLayoutIterator iterator() { return TQLayoutIterator( (TQGLayoutIterator *) NULL ); }; void setGeometry( const TQRect & ) { }; }; £], "TQT_NO_LCDNUMBER" => ["tqlcdnumber.h", "TQLCDNumber foo;", 12], "TQT_NO_LINEEDIT" => ["tqlineedit.h", "TQLineEdit foo( (TQWidget *) NULL );", 12], "TQT_NO_LISTBOX" => ["tqlistbox.h", "TQListBox foo;", 13], "TQT_NO_LISTVIEW" => ["tqlistview.h", "TQListView foo;", 13], "TQT_NO_MAINWINDOW" => ["tqmainwindow.h", "TQMainWindow foo;", 13], "TQT_NO_MENUBAR" => ["tqmenubar.h", "TQMenuBar foo;", 13], "TQT_NO_MOVIE" => ["tqmovie.h", "TQMovie foo;", 5], "TQT_NO_MENUDATA" => ["tqmenudata.h", "TQMenuData foo;", 9], "TQT_NO_MESSAGEBOX" => ["tqmessagebox.h", "TQMessageBox foo;", 13], "TQT_NO_MIME" => ["tqmime.h", "TQMimeSourceFactory foo;", 5], "TQT_NO_MIMECLIPBOARD" => ["tqapplication.h, qclipboard.h", q£ TQApplication foo( argc, argv ); TQClipboard *baz= foo.clipboard(); baz->data(); £, 8], "TQT_NO_MULTILINEEDIT" => ["tqmultilineedit.h", "TQMultiLineEdit foo;", 14], "TQT_NO_NETWORK" => ["tqnetwork.h", "tqInitNetworkProtocols();", 5], "TQT_NO_NETWORKPROTOCOL" => ["tqnetworkprotocol.h", "TQNetworkProtocol foo;", 8], "TQT_NO_NETWORKPROTOCOL_FTP" => ["tqftp.h", "TQFtp foo;", 9], "TQT_NO_PALETTE" => ["tqpalette.h", "TQColorGroup foo;", 5], "TQT_NO_PICTURE" => ["tqpicture.h", "TQPicture foo;", 5], "TQT_NO_PIXMAP_TRANSFORMATION" =>["tqbitmap.h, qwmatrix.h", q£ TQBitmap *foo= new TQBitmap(); TQWMatrix bar; foo->xForm( bar ); £, 5], "TQT_NO_POPUPMENU" => ["tqpopupmenu.h", "TQPopupMenu foo;", 12], "TQT_NO_PRINTER" => ["tqprinter.h", "TQPrinter foo;", 5], "TQT_NO_PRINTDIALOG" => ["tqprintdialog.h", "TQPrintDialog foo( (TQPrinter*) NULL );", 13], "TQT_NO_PROCESS" => ["tqprocess.h", "TQProcess foo;", 5], "TQT_NO_PROGRESSBAR" => ["tqprogressbar.h", "TQProgressBar foo;", 12], "TQT_NO_PROGRESSDIALOG" => ["tqprogressdialog.h", "TQProgressDialog foo;", 13], "TQT_NO_PUSHBUTTON" => ["tqpushbutton.h", "TQPushButton foo( (TQWidget *) NULL );", 12], "TQT_NO_PROPERTIES" => ["tqmetaobject.h", "TQMetaProperty foo;", 0], "TQT_NO_TQUUID_STRING" => ["tquuid.h", "TQUuid foo( TQString::null );", 8], "TQT_NO_RANGECONTROL" => ["tqrangecontrol.h", "TQRangeControl foo;", 10], "TQT_NO_REGEXP" => ["tqregexp.h", "TQRegExp foo;", 5], "TQT_NO_REGEXP_WILDCARD" => ["tqregexp.h", q£ TQRegExp foo; foo.wildcard(); £, 8], "TQT_NO_REMOTE" => ["tqapplication.h", q£ TQApplication foo( argc, argv ); foo.remoteControlEnabled(); £, 15], "TQT_NO_RADIOBUTTON" => ["tqradiobutton.h", "TQRadioButton foo( (TQWidget *) NULL );", 12], "TQT_NO_RICHTEXT" => ["tqsimplerichtext.h, qstring.h, qfont.h", "TQSimpleRichText foo( TQString::null, TQFont() );", 10], "TQT_NO_SCROLLBAR" => ["tqscrollbar.h", "TQScrollBar foo( (TQWidget *) NULL );", 12], "TQT_NO_SCROLLVIEW" => ["tqscrollview.h", "TQScrollView foo;", 12], "TQT_NO_SESSIONMANAGER" => ["tqapplication.h", q£ TQApplication foo( argc, argv ); foo.sessionId(); £, 15], "TQT_NO_SETTINGS" => ["tqsettings.h", "TQSettings foo;", 5], "TQT_NO_SIGNALMAPPER" => ["tqsignalmapper.h", "TQSignalMapper foo( (TQObject *) NULL );", 0], "TQT_NO_SIZEGRIP" => ["tqsizegrip.h", "TQSizeGrip foo( (TQWidget *) NULL );", 10], "TQT_NO_SLIDER" => ["tqslider.h", "TQSlider foo( (TQWidget *) NULL );", 12], "TQT_NO_SOUND" => ["tqsound.h", "TQSound foo( TQString::null );", 5], "TQT_NO_SPINWIDGET" => ["tqrangecontrol.h", "TQSpinWidget foo;", 10], "TQT_NO_SPRINTF" => ["tqcolor.h", q£ TQColor foo; foo.name(); £, 0], "TQT_NO_SQL" => ["tqsqlcursor.h", "TQSqlCursor foo;", 5], "TQT_NO_STRINGLIST" => ["tqstringlist.h", "TQStringList foo;", 0], "TQT_NO_STYLE" => ["tqapplication.h", q£ TQApplication foo( argc, argv ); foo.style(); £, 15], # "TQT_NO_STYLE_CDE" => ["tqcdestyle.h", "TQCDEStyle foo;", 16], # "TQT_NO_STYLE_COMPACT" => ["tqcompactstyle.h", "TQCompactStyle foo;", 16], # "TQT_NO_STYLE_INTERLACE" => ["tqinterlacestyle.h", "TQInterlaceStyle foo;", 16], # "TQT_NO_STYLE_PLATINUM" => ["tqplatinumstyle.h", "TQPlatinumStyle foo;", 16], # "TQT_NO_STYLE_MOTIF" => ["tqmotifstyle.h", "TQMotifStyle foo;", 16], # "TQT_NO_STYLE_MOTIFPLUS" => ["tqmotifplusstyle.h", "TQMotifPlusStyle foo;", 16], # "TQT_NO_STYLE_SGI" => ["tqsgistyle.h", "TQSGIStyle foo;", 16], # "TQT_NO_STYLE_WINDOWS" => ["tqwindowsstyle.h", "TQWindowsStyle foo;", 16], "TQT_NO_TABBAR" => ["tqtabbar.h", "TQTabBar foo;", 10], "TQT_NO_TABDIALOG" => ["tqtabdialog.h", "TQTabDialog foo;", 12], "TQT_NO_TABLE" => ["tqtable.h", "TQTable foo;", 10], "TQT_NO_TABWIDGET" => ["tqtabwidget.h", "TQTabWidget foo;", 10], "TQT_NO_TEXTBROWSER" => ["tqtextbrowser.h", "TQTextBrowser foo;", 14], "TQT_NO_TEXTCODEC" => ["tqtextcodec.h", "TQTextCodec::codecForIndex(1);", 5], "TQT_NO_TEXTCODECPLUGIN" => ["tqtextcodecplugin.h, qstringlist.h, qvaluelist.h, qtextcodec.h", "TQFoo foo;", 6, q£ class TQFoo: public TQTextCodecPlugin { public: TQFoo() {}; ~TQFoo() {}; TQStringList names() const {return TQStringList();} TQValueListmibEnums() const {return TQValueList();} TQTextCodec *createForName( const TQString & name ) {return (TQTextCodec *)NULL;} TQTextCodec *createForMib( int mib ) {return (TQTextCodec *)NULL;} }; TQ_EXPORT_PLUGIN( TQFoo ) £], "TQT_NO_TEXTEDIT" => ["tqtextedit.h", "TQTextEdit foo;", 13], "TQT_NO_TEXTSTREAM" => ["tqtextstream.h", "TQTextStream foo;", 5], "TQT_NO_TEXTVIEW" => ["tqtextview.h", "TQTextView foo;", 14], #Obsolete "TQT_NO_TOOLBAR" => ["tqtoolbar.h", "TQToolBar foo;", 10], "TQT_NO_TOOLBUTTON" => ["tqtoolbutton.h", "TQToolButton foo((TQWidget *) NULL );", 12], "TQT_NO_TOOLTIP" => ["tqtooltip.h", "TQToolTip::hide();", 10], "TQT_NO_TRANSFORMATIONS" => ["tqpainter.h", q£ TQPainter *foo= new TQPainter(); foo->setViewXForm( true );£, 5], "TQT_NO_VARIANT" => ["tqvariant.h", "TQVariant foo;", 0], "TQT_NO_WHATSTHIS" => ["tqwhatsthis.h", "TQWhatsThis::inWhatsThisMode();", 10], "TQT_NO_WHEELEVENT" => ["tqevent.h", "TQWheelEvent foo( TQPoint(1,1), 1, 1 );", 5], "TQT_NO_WIDGET_TOPEXTRA" => ["tqwidget.h", "TQWidget foo; foo.caption();", 9], "TQT_NO_WIDGETSTACK" => ["tqwidgetstack.h", "TQWidgetStack foo;", 13], "TQT_NO_WIZARD" => ["tqwizard.h", "TQWizard foo;", 13], "TQT_NO_WMATRIX" => ["tqwmatrix.h", "TQWMatrix foo;", 0], "TQT_NO_XML" => ["tqxml.h", "TQXmlNamespaceSupport foo;", 5], ); }