kusano 7d535a
#!/usr/bin/perl
kusano 7d535a
##
kusano 7d535a
## Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org=""></mmagallo[]debian>
kusano 7d535a
## Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee="" org=""></milan>
kusano 7d535a
##
kusano 7d535a
## This program is distributed under the terms and conditions of the GNU
kusano 7d535a
## General Public License Version 2 as published by the Free Software
kusano 7d535a
## Foundation or, at your option, any later version.
kusano 7d535a
kusano 7d535a
use strict;
kusano 7d535a
use warnings;
kusano 7d535a
kusano 7d535a
do 'bin/make.pl';
kusano 7d535a
kusano 7d535a
# token
kusano 7d535a
sub make_define($$)
kusano 7d535a
{
kusano 7d535a
    return "#define $_[0] $_[1]"
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
# type declaration
kusano 7d535a
sub make_type($$)
kusano 7d535a
{
kusano 7d535a
    return "@_;"
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
# function pointer type declaration
kusano 7d535a
sub make_pfn_type($%)
kusano 7d535a
{
kusano 7d535a
    our $api;
kusano 7d535a
    return join(' ', "typedef", $_[1]->{rtype},
kusano 7d535a
        "($api * PFN" . (uc $_[0]) . "PROC)",
kusano 7d535a
        "(" . $_[1]->{parms} . ")") . ";";
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
# function name alias
kusano 7d535a
sub make_pfn_alias($%)
kusano 7d535a
{
kusano 7d535a
    our $type;
kusano 7d535a
    return join(" ", "#define", $_[0], $type . "EW_GET_FUN(" . prefixname($_[0]) . ")")
kusano 7d535a
}
kusano 7d535a
kusano 7d535a
my @extlist = ();
kusano 7d535a
my %extensions = ();
kusano 7d535a
kusano 7d535a
our $api = shift;
kusano 7d535a
our $type = shift;
kusano 7d535a
kusano 7d535a
if (@ARGV)
kusano 7d535a
{
kusano 7d535a
    @extlist = @ARGV;
kusano 7d535a
kusano 7d535a
	foreach my $ext (sort @extlist)
kusano 7d535a
	{
kusano 7d535a
		my ($extname, $exturl, $extstring, $types, $tokens, $functions, $exacts) = parse_ext($ext);
kusano 7d535a
kusano 7d535a
		make_separator($extname);
kusano 7d535a
		print "#ifndef $extname\n#define $extname 1\n";
kusano 7d535a
		output_tokens($tokens, \&make_define);
kusano 7d535a
		output_types($types, \&make_type);
kusano 7d535a
		output_exacts($exacts, \&make_exact);
kusano 7d535a
		output_decls($functions, \&make_pfn_type);
kusano 7d535a
		output_decls($functions, \&make_pfn_alias);
kusano 7d535a
kusano 7d535a
		my $extvar = $extname;
kusano 7d535a
		$extvar =~ s/GL(X*)_/GL$1EW_/;
kusano 7d535a
		
kusano 7d535a
		print "\n#define $extvar " . $type . "EW_GET_VAR(" . prefix_varname($extvar) . ")\n";
kusano 7d535a
		print "\n#endif /* $extname */\n\n";
kusano 7d535a
	}
kusano 7d535a
}