os/graphics/egl/eglswitch/src/generate_stubs.pl
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/eglswitch/src/generate_stubs.pl	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,138 @@
     1.4 +#!/bin/perl -w
     1.5 +
     1.6 +# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.7 +# All rights reserved.
     1.8 +# This component and the accompanying materials are made available
     1.9 +# under the terms of "Eclipse Public License v1.0"
    1.10 +# which accompanies this distribution, and is available
    1.11 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.12 +#
    1.13 +# Initial Contributors:
    1.14 +# Nokia Corporation - initial contribution.
    1.15 +#
    1.16 +# Contributors:
    1.17 +#
    1.18 +# Description:
    1.19 +# Generates the egl_stubs.h header file and the eglswitchu.def
    1.20 +# file from the libeglu def file.
    1.21 +# 
    1.22 +#
    1.23 +
    1.24 +use strict;
    1.25 +my $COPYRIGHT = "" .
    1.26 +"// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" .
    1.27 +"// All rights reserved.\n" .
    1.28 +"// This component and the accompanying materials are made available\n" .
    1.29 +"// under the terms of the License \"Eclipse Public License v1.0\"\n" .
    1.30 +"// which accompanies this distribution, and is available\n" .
    1.31 +"// at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n" .
    1.32 +"//\n" .
    1.33 +"// Initial Contributors:\n" .
    1.34 +"// Nokia Corporation - initial contribution.\n" .
    1.35 +"//\n" .
    1.36 +"// Contributors:\n" .
    1.37 +"//\n" .
    1.38 +"// Description:\n";
    1.39 +
    1.40 +my $EGL_DEF;
    1.41 +my $EGLSWITCH_HEADER = "egl_stubs.h";
    1.42 +my $EGLSWITCH_DEF = "../BWINS/eglswitchu.def";
    1.43 +my $SOURCE_DEF_SIZE = 0;
    1.44 +
    1.45 +&main();
    1.46 +exit(0);
    1.47 +
    1.48 +sub main() {
    1.49 +	if (@ARGV == 0) {
    1.50 +		printf "Usage: generate_stubs.pl <EGL DEF file>\n";
    1.51 +		printf "e.g. generate_stubs.pl /epoc32/include/def/win32/libegl14u.def\n";
    1.52 +		return 0;
    1.53 +	}
    1.54 +	
    1.55 +	$EGL_DEF = $ARGV[0];
    1.56 +	my $maxOrdinal = 1;
    1.57 +
    1.58 +	open DEF, $EGL_DEF or
    1.59 +		die "Cannot open $EGL_DEF\n";
    1.60 +
    1.61 +	my ($dev, $ino, $mode, $nlink, $uid, $gid, 
    1.62 +		$rdev, $size, $atime, $mtime, $ctime, 
    1.63 +		$blksize, $blocks) 
    1.64 +		= stat($EGL_DEF);
    1.65 +	# the file size could be checked by the switcher build to verify that the stub is up to date.
    1.66 +    $SOURCE_DEF_SIZE= $size;
    1.67 +    
    1.68 +	open HEADER_OUT, ">${EGLSWITCH_HEADER}" or
    1.69 +		die "Cannot create $EGLSWITCH_HEADER\n";
    1.70 +
    1.71 +	open DEF_OUT, ">${EGLSWITCH_DEF}" or
    1.72 +		die "Cannot create $EGLSWITCH_DEF\n";
    1.73 +
    1.74 +	&printHeaderStart(\*HEADER_OUT);
    1.75 +	&printDefStart(\*DEF_OUT);
    1.76 +
    1.77 +	while (<DEF>) {
    1.78 +		chomp;
    1.79 +		if (/@/) {
    1.80 +			if (s/.*;/;/) {
    1.81 +				&printDefEntry(\*DEF_OUT, $maxOrdinal, $_);
    1.82 +				&printHeaderEntry(\*HEADER_OUT,$maxOrdinal,$_);
    1.83 +			} else {
    1.84 +				&printDefEntry(\*DEF_OUT, $maxOrdinal, "");
    1.85 +				&printHeaderEntry(\*HEADER_OUT,$maxOrdinal, "(noname)");
    1.86 +			}
    1.87 +			$maxOrdinal++;
    1.88 +		}
    1.89 +	}
    1.90 +	&printHeaderEnd(\*HEADER_OUT,$maxOrdinal);
    1.91 +	&printDefEnd(\*DEF_OUT);
    1.92 +
    1.93 +	close DEF;
    1.94 +	close HEADER_OUT;
    1.95 +	close DEF_OUT;
    1.96 +}
    1.97 +
    1.98 +sub printDefStart(\$) {
    1.99 +	my ($fh) = @_;
   1.100 +	print $fh "EXPORTS\n";
   1.101 +}
   1.102 +
   1.103 +sub printDefEntry(\$\$\$) {
   1.104 +	my ($fh, $ordinal, $comment) = @_;
   1.105 +	print $fh "\tcall_vector_${ordinal} @ ${ordinal} NONAME $comment\n";
   1.106 +}
   1.107 +
   1.108 +sub printDefEnd(\$) {
   1.109 +	my ($fh) = @_;
   1.110 +	print $fh "\n";
   1.111 +}
   1.112 +
   1.113 +sub printHeaderStart(\$) {
   1.114 +	my ($fh) = @_;
   1.115 +
   1.116 +	print $fh "$COPYRIGHT\n".
   1.117 +    "// Generated from \"$EGL_DEF\" file size: $SOURCE_DEF_SIZE\n" .
   1.118 +		"\n" .
   1.119 +		"extern \"C\" {\n" .
   1.120 +		"void common_dispatch();\n" .
   1.121 +		"\n";
   1.122 +}
   1.123 +
   1.124 +sub printHeaderEntry(\$\$\$) {
   1.125 +	my ($fh, $ordinal, $comment) = @_;
   1.126 +
   1.127 +	print $fh "__declspec(dllexport)\n" .
   1.128 +		"__declspec(naked)\n" .
   1.129 +		"void call_vector_${ordinal} ()\n" .
   1.130 +		"\t{\n" .
   1.131 +		"\t// ${comment}\n" .
   1.132 +		"\t_asm mov eax, $ordinal\n" .
   1.133 +		"\t_asm jmp common_dispatch\n" .
   1.134 +		"\t}\n\n";
   1.135 +}
   1.136 +
   1.137 +sub printHeaderEnd(\$\$) {
   1.138 +	my ($fh, $maxOrdinal) = @_;
   1.139 +	print $fh "}\n" .
   1.140 +		"#define MAX_ORDINAL $maxOrdinal\n\n";
   1.141 +}