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