util/scripts/make_qfeatures_dot_h
changeset 0 1918ee327afb
child 3 41300fa6a67c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 #!/usr/bin/perl
       
     2 #############################################################################
       
     3 ##
       
     4 ## Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     5 ## All rights reserved.
       
     6 ## Contact: Nokia Corporation (qt-info@nokia.com)
       
     7 ##
       
     8 ## This file is part of the test suite of the Qt Toolkit.
       
     9 ##
       
    10 ## $QT_BEGIN_LICENSE:LGPL$
       
    11 ## No Commercial Usage
       
    12 ## This file contains pre-release code and may not be distributed.
       
    13 ## You may use this file in accordance with the terms and conditions
       
    14 ## contained in the Technology Preview License Agreement accompanying
       
    15 ## this package.
       
    16 ##
       
    17 ## GNU Lesser General Public License Usage
       
    18 ## Alternatively, this file may be used under the terms of the GNU Lesser
       
    19 ## General Public License version 2.1 as published by the Free Software
       
    20 ## Foundation and appearing in the file LICENSE.LGPL included in the
       
    21 ## packaging of this file.  Please review the following information to
       
    22 ## ensure the GNU Lesser General Public License version 2.1 requirements
       
    23 ## will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    24 ##
       
    25 ## In addition, as a special exception, Nokia gives you certain additional
       
    26 ## rights.  These rights are described in the Nokia Qt LGPL Exception
       
    27 ## version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    28 ##
       
    29 ## If you have questions regarding the use of this file, please contact
       
    30 ## Nokia at qt-info@nokia.com.
       
    31 ##
       
    32 ##
       
    33 ##
       
    34 ##
       
    35 ##
       
    36 ##
       
    37 ##
       
    38 ##
       
    39 ## $QT_END_LICENSE$
       
    40 ##
       
    41 #############################################################################
       
    42 
       
    43 #
       
    44 # Usage:  make_qfeatures_dot_h
       
    45 #
       
    46 # Generates src/corelib/global/qfeatures.h from src/corelib/global/qfeatures.txt.
       
    47 #
       
    48 # The qfeatures.txt file can contain redundancies, and this program
       
    49 # will show them.
       
    50 #
       
    51 
       
    52 if ($ENV{QTSRCDIR} ne '') {
       
    53     $qtbase=$ENV{QTSRCDIR};
       
    54 } else {
       
    55     $qtbase=$ENV{QTDIR};
       
    56 }
       
    57 
       
    58 open FL, "$qtbase/src/corelib/global/qfeatures.txt"
       
    59     or die "Cannot open $qtbase/src/corelib/global/qfeatures.txt";
       
    60 
       
    61 while (<FL>) {
       
    62     if ( /^Feature: (\S*)/ ) {
       
    63 	print STDERR "Duplicate: $1\n" if $macro{$1};
       
    64 	$macro{$macro=$1}=1;
       
    65     } elsif ( /^Requires: (.*?)\s*$/ ) {
       
    66 	$deps{$macro}=$1;
       
    67 	map { $dep{"$macro $_"}=1 } split /\s+/, $1;
       
    68     } elsif ( /^Name: (.*?)\s*$/ ) {
       
    69 	$label{$macro}=$1;
       
    70     }
       
    71 }
       
    72 
       
    73 close FL;
       
    74 
       
    75 sub depends {
       
    76     my($x,$y) = @_;
       
    77     return 1 if $dep{"$x $y"};
       
    78     return 0 if $dep{"$y $x"};
       
    79     return 0 if $x eq $y;
       
    80     my $d;
       
    81     for $d (split /\s+/, $deps{$x}) {
       
    82 	return 1 if depends($d,$y);
       
    83     }
       
    84     return 0;
       
    85 }
       
    86 sub dependants_rec {
       
    87     my($x) = @_;
       
    88     my $n = 0;
       
    89     my $d = 0;
       
    90     $dependants_rec_count++;
       
    91     if ( $dependants_rec_count > $dependants_rec_limit ) {
       
    92 	if ( $circularity_start eq $x ) {
       
    93 	    print STDERR "Circular dependency: $circularity\n";
       
    94 	    exit;
       
    95 	}
       
    96 	$circularity_start=$x if !$circularity_start;
       
    97 	$circularity="$x $circularity";
       
    98     }
       
    99     for $d (split /\s+/, $deps{$x}) {
       
   100 	$n += 1 + dependants_rec($d);
       
   101     }
       
   102     $dependants_rec_count--;
       
   103     return $n;
       
   104 }
       
   105 sub dependants {
       
   106     $dependants_rec_limit=keys %macro if !$dependants_rec_limit;
       
   107     $dependants_rec_count=0;
       
   108     return dependants_rec @_;
       
   109 }
       
   110 sub dependencysort {
       
   111     my($x, $y) = @_;
       
   112     my $xd = dependants($x);
       
   113     my $yd = dependants($y);
       
   114     return $xd-$yd if $xd != $yd;
       
   115     return $x cmp $y;
       
   116 }
       
   117 
       
   118 @macros = sort { dependencysort($a,$b) } keys %macro;
       
   119 
       
   120 for $macro ( @macros ) {
       
   121     for $d1 (split /\s+/, $deps{$macro} ) {
       
   122 	for $d2 (split /\s+/, $deps{$macro} ) {
       
   123 	    print STDERR "Redundancy in $macro - $d1 depends on $d2\n" if depends($d1,$d2);
       
   124 	}
       
   125 	print STDERR "Unknown in $macro - $d1\n" if !$macro{$d1};
       
   126     }
       
   127 }
       
   128 
       
   129 open OUT, ">$qtbase/src/corelib/global/qfeatures.h"
       
   130     or die "Cannot open $qtbase/src/corelib/global/qfeatures.h for writing";
       
   131 
       
   132 print OUT
       
   133 '/****************************************************************************
       
   134 **
       
   135 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
   136 ** All rights reserved.
       
   137 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
   138 **
       
   139 ** This file is part of the QtCore module of the Qt Toolkit.
       
   140 **
       
   141 ** $QT_BEGIN_LICENSE:LGPL$
       
   142 ** No Commercial Usage
       
   143 ** This file contains pre-release code and may not be distributed.
       
   144 ** You may use this file in accordance with the terms and conditions
       
   145 ** contained in the Technology Preview License Agreement accompanying
       
   146 ** this package.
       
   147 **
       
   148 ** GNU Lesser General Public License Usage
       
   149 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
   150 ** General Public License version 2.1 as published by the Free Software
       
   151 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
   152 ** packaging of this file.  Please review the following information to
       
   153 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
   154 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
   155 **
       
   156 ** In addition, as a special exception, Nokia gives you certain additional
       
   157 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
   158 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
   159 **
       
   160 ** If you have questions regarding the use of this file, please contact
       
   161 ** Nokia at qt-info@nokia.com.
       
   162 **
       
   163 **
       
   164 **
       
   165 **
       
   166 **
       
   167 **
       
   168 **
       
   169 **
       
   170 ** $QT_END_LICENSE$
       
   171 **
       
   172 ****************************************************************************/
       
   173 
       
   174 /*
       
   175  * All features and their dependencies.
       
   176  *
       
   177  * This list is generated from $QTDIR/src/corelib/global/qfeatures.txt
       
   178  */
       
   179 
       
   180 ';
       
   181 
       
   182 
       
   183 for $macro ( @macros ) {
       
   184     print OUT "// $label{$macro}\n";
       
   185     if ( $deps{$macro} ) {
       
   186 	print OUT "#if !defined(QT_NO_$macro)";
       
   187 	print OUT " && (", (join " || ", map { "defined(QT_NO_$_)" } split /\s+/, $deps{$macro}), ")";
       
   188 	print OUT "\n";
       
   189 	print OUT "#define QT_NO_$macro\n";
       
   190 	print OUT "#endif\n";
       
   191     } else {
       
   192 	print OUT "//#define QT_NO_$macro\n";
       
   193     }
       
   194     print OUT "\n";
       
   195 }
       
   196 
       
   197 close OUT;