os/graphics/egl/eglswitch/src/generate_stubs.pl
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
#!/bin/perl -w
sl@0
     2
sl@0
     3
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     4
# All rights reserved.
sl@0
     5
# This component and the accompanying materials are made available
sl@0
     6
# under the terms of "Eclipse Public License v1.0"
sl@0
     7
# which accompanies this distribution, and is available
sl@0
     8
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     9
#
sl@0
    10
# Initial Contributors:
sl@0
    11
# Nokia Corporation - initial contribution.
sl@0
    12
#
sl@0
    13
# Contributors:
sl@0
    14
#
sl@0
    15
# Description:
sl@0
    16
# Generates the egl_stubs.h header file and the eglswitchu.def
sl@0
    17
# file from the libeglu def file.
sl@0
    18
# 
sl@0
    19
#
sl@0
    20
sl@0
    21
use strict;
sl@0
    22
my $COPYRIGHT = "" .
sl@0
    23
"// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\n" .
sl@0
    24
"// All rights reserved.\n" .
sl@0
    25
"// This component and the accompanying materials are made available\n" .
sl@0
    26
"// under the terms of the License \"Eclipse Public License v1.0\"\n" .
sl@0
    27
"// which accompanies this distribution, and is available\n" .
sl@0
    28
"// at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\n" .
sl@0
    29
"//\n" .
sl@0
    30
"// Initial Contributors:\n" .
sl@0
    31
"// Nokia Corporation - initial contribution.\n" .
sl@0
    32
"//\n" .
sl@0
    33
"// Contributors:\n" .
sl@0
    34
"//\n" .
sl@0
    35
"// Description:\n";
sl@0
    36
sl@0
    37
my $EGL_DEF;
sl@0
    38
my $EGLSWITCH_HEADER = "egl_stubs.h";
sl@0
    39
my $EGLSWITCH_DEF = "../BWINS/eglswitchu.def";
sl@0
    40
my $SOURCE_DEF_SIZE = 0;
sl@0
    41
sl@0
    42
&main();
sl@0
    43
exit(0);
sl@0
    44
sl@0
    45
sub main() {
sl@0
    46
	if (@ARGV == 0) {
sl@0
    47
		printf "Usage: generate_stubs.pl <EGL DEF file>\n";
sl@0
    48
		printf "e.g. generate_stubs.pl /epoc32/include/def/win32/libegl14u.def\n";
sl@0
    49
		return 0;
sl@0
    50
	}
sl@0
    51
	
sl@0
    52
	$EGL_DEF = $ARGV[0];
sl@0
    53
	my $maxOrdinal = 1;
sl@0
    54
sl@0
    55
	open DEF, $EGL_DEF or
sl@0
    56
		die "Cannot open $EGL_DEF\n";
sl@0
    57
sl@0
    58
	my ($dev, $ino, $mode, $nlink, $uid, $gid, 
sl@0
    59
		$rdev, $size, $atime, $mtime, $ctime, 
sl@0
    60
		$blksize, $blocks) 
sl@0
    61
		= stat($EGL_DEF);
sl@0
    62
	# the file size could be checked by the switcher build to verify that the stub is up to date.
sl@0
    63
    $SOURCE_DEF_SIZE= $size;
sl@0
    64
    
sl@0
    65
	open HEADER_OUT, ">${EGLSWITCH_HEADER}" or
sl@0
    66
		die "Cannot create $EGLSWITCH_HEADER\n";
sl@0
    67
sl@0
    68
	open DEF_OUT, ">${EGLSWITCH_DEF}" or
sl@0
    69
		die "Cannot create $EGLSWITCH_DEF\n";
sl@0
    70
sl@0
    71
	&printHeaderStart(\*HEADER_OUT);
sl@0
    72
	&printDefStart(\*DEF_OUT);
sl@0
    73
sl@0
    74
	while (<DEF>) {
sl@0
    75
		chomp;
sl@0
    76
		if (/@/) {
sl@0
    77
			if (s/.*;/;/) {
sl@0
    78
				&printDefEntry(\*DEF_OUT, $maxOrdinal, $_);
sl@0
    79
				&printHeaderEntry(\*HEADER_OUT,$maxOrdinal,$_);
sl@0
    80
			} else {
sl@0
    81
				&printDefEntry(\*DEF_OUT, $maxOrdinal, "");
sl@0
    82
				&printHeaderEntry(\*HEADER_OUT,$maxOrdinal, "(noname)");
sl@0
    83
			}
sl@0
    84
			$maxOrdinal++;
sl@0
    85
		}
sl@0
    86
	}
sl@0
    87
	&printHeaderEnd(\*HEADER_OUT,$maxOrdinal);
sl@0
    88
	&printDefEnd(\*DEF_OUT);
sl@0
    89
sl@0
    90
	close DEF;
sl@0
    91
	close HEADER_OUT;
sl@0
    92
	close DEF_OUT;
sl@0
    93
}
sl@0
    94
sl@0
    95
sub printDefStart(\$) {
sl@0
    96
	my ($fh) = @_;
sl@0
    97
	print $fh "EXPORTS\n";
sl@0
    98
}
sl@0
    99
sl@0
   100
sub printDefEntry(\$\$\$) {
sl@0
   101
	my ($fh, $ordinal, $comment) = @_;
sl@0
   102
	print $fh "\tcall_vector_${ordinal} @ ${ordinal} NONAME $comment\n";
sl@0
   103
}
sl@0
   104
sl@0
   105
sub printDefEnd(\$) {
sl@0
   106
	my ($fh) = @_;
sl@0
   107
	print $fh "\n";
sl@0
   108
}
sl@0
   109
sl@0
   110
sub printHeaderStart(\$) {
sl@0
   111
	my ($fh) = @_;
sl@0
   112
sl@0
   113
	print $fh "$COPYRIGHT\n".
sl@0
   114
    "// Generated from \"$EGL_DEF\" file size: $SOURCE_DEF_SIZE\n" .
sl@0
   115
		"\n" .
sl@0
   116
		"extern \"C\" {\n" .
sl@0
   117
		"void common_dispatch();\n" .
sl@0
   118
		"\n";
sl@0
   119
}
sl@0
   120
sl@0
   121
sub printHeaderEntry(\$\$\$) {
sl@0
   122
	my ($fh, $ordinal, $comment) = @_;
sl@0
   123
sl@0
   124
	print $fh "__declspec(dllexport)\n" .
sl@0
   125
		"__declspec(naked)\n" .
sl@0
   126
		"void call_vector_${ordinal} ()\n" .
sl@0
   127
		"\t{\n" .
sl@0
   128
		"\t// ${comment}\n" .
sl@0
   129
		"\t_asm mov eax, $ordinal\n" .
sl@0
   130
		"\t_asm jmp common_dispatch\n" .
sl@0
   131
		"\t}\n\n";
sl@0
   132
}
sl@0
   133
sl@0
   134
sub printHeaderEnd(\$\$) {
sl@0
   135
	my ($fh, $maxOrdinal) = @_;
sl@0
   136
	print $fh "}\n" .
sl@0
   137
		"#define MAX_ORDINAL $maxOrdinal\n\n";
sl@0
   138
}