sbsv1_os/e32toolp/genutil/conv_khronos_hdr_to_cpp.pl
changeset 0 83f4b4db085c
child 1 d4b442d23379
equal deleted inserted replaced
-1:000000000000 0:83f4b4db085c
       
     1 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # Convert the given header file from Khronos into a stub implementation file
       
    15 # 
       
    16 #
       
    17 
       
    18 use File::Basename;
       
    19 use File::Path;
       
    20 
       
    21 my $debug = 0;
       
    22 my $prog = "conv_khronos_hdr_to_cpp.pl";
       
    23 my $source = shift;
       
    24 my $target = shift;
       
    25 my $operation_mode = shift;
       
    26 my @lines;
       
    27 
       
    28 if ($debug)
       
    29 	{
       
    30 	print "$prog: Args $source $target $operation_mode\n";
       
    31 	}
       
    32 
       
    33 if ("$operation_mode" eq "delete")
       
    34 	{
       
    35 	&cleanup();
       
    36 	exit 0;
       
    37 	}
       
    38 elsif ("$operation_mode" eq "create")
       
    39 	{
       
    40 	&setupFiles();
       
    41 	&generateStubImplementation();
       
    42 	exit 0;
       
    43 	}
       
    44 else
       
    45 	{
       
    46 	print "Usage error: $prog source target [create|delete]\n";
       
    47 	exit 1;
       
    48 	}
       
    49 
       
    50 sub cleanup()
       
    51 	{
       
    52 	unlink "$target";
       
    53 	}
       
    54 
       
    55 sub setupFiles()
       
    56 	{
       
    57 	my $dir;
       
    58 	$dir = dirname($target);
       
    59 	mkpath $dir;
       
    60 	
       
    61 	open(INFILE,  "$source") or die "Can't open input file $source; $!\n";
       
    62 	open(OUTFILE, ">$target") or die "Can't open output file $target; $!\n";
       
    63 	print OUTFILE '/* Auto-generated: ' . "$prog" . ' v1.0 */' . "\n";
       
    64 	print OUTFILE '/* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).  All rights reserved. */' . "\n";
       
    65 	}
       
    66 
       
    67 sub generateStubImplementation()
       
    68 	{
       
    69 	@lines = <INFILE>;
       
    70 	foreach (@lines)
       
    71 		{
       
    72 		# Find function prototype lines
       
    73 		if (/^GL_APICALL/)
       
    74 			{
       
    75 			# Convert the function prototype into a stub function definition
       
    76 			s/\;$/ { }/;
       
    77 			# Record the stub functions.  There will be a stub implementation
       
    78 			# file which includes these stub functions.  This ensures we never
       
    79 			# accidentally miss a new function added to the header file supplied
       
    80 			# as $source.  We expect compiler warnings (missing use of arguments,
       
    81 			# absent return value etc.).  The aim is to get something which will
       
    82 			# compile so that a DEF file can be generated.
       
    83 			print OUTFILE "$_";
       
    84 			}
       
    85 		}
       
    86 	}