1#!/usr/bin/env perl
2#
3# SDL.pm
4#
5# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6# Copyright (C) 2010 Kartik Thakore   <kthakore@cpan.org>
7# ------------------------------------------------------------------------------
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2.1 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17# Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this library; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22#
23# ------------------------------------------------------------------------------
24#
25# Please feel free to send questions, suggestions or improvements to:
26#
27#	Kartik Thakore
28#	kthakore@cpan.org
29#
30
31package SDL;
32
33use strict;
34use warnings;
35use Carp;
36
37use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
38
39require Exporter;
40require DynaLoader;
41
42use SDL_perl;
43use SDL::Constants ':SDL';
44
45#use SDL::Internal::Loader; See TODO near END{}
46our @ISA = qw(Exporter DynaLoader);
47
48use base 'Exporter';
49our @EXPORT = @{ $SDL::Constants::EXPORT_TAGS{SDL} };
50push @EXPORT, 'NULL';
51our %EXPORT_TAGS = (
52	all      => \@EXPORT,
53	init     => $SDL::Constants::EXPORT_TAGS{'SDL/init'},
54	defaults => $SDL::Constants::EXPORT_TAGS{'SDL/defaults'}
55);
56
57our $VERSION = 2.548;
58
59print "$VERSION" if ( defined( $ARGV[0] ) && ( $ARGV[0] eq '--SDLperl' ) );
60
61$SDL::DEBUG = 0;
62
63sub NULL {
64	return 0;
65}
66
67# workaround, doing putenv from perl instead of sdl's:
68#int
69#putenv (variable)
70#	char *variable
71#	CODE:
72#		RETVAL = SDL_putenv(variable);
73#	OUTPUT:
74#		RETVAL
75sub putenv {
76	my $cmd = shift;
77	if ( $cmd =~ /^(\w+)=(.*)$/ ) {
78		$ENV{$1} = $2;
79		return 0;
80	}
81
82	return -1;
83}
84
85# workaround as:
86# extern DECLSPEC void SDLCALL SDL_SetError(const char *fmt, ...);
87sub set_error {
88	my ( $format, @arguments ) = @_;
89	SDL::set_error_real( sprintf( $format, @arguments ) );
90}
91
92
93# Hints for Inline.pm
94sub Inline
95{
96    my $language = shift;
97    if ($language ne 'C') {
98	warn "Warning: SDL.pm does not provide Inline hints for the $language language\n";
99	return
100    }
101
102	require Alien::SDL;
103    require File::Spec;
104	my $libs = Alien::SDL->config('libs');
105	#This should be added in ldd flags section but it is only doing SDL_main for some reason.
106	$libs .= ' '.File::Spec->catfile(Alien::SDL->config('prefix'),'lib','libSDL.dll.a')	if( $^O =~ /Win32/ig );
107	my $cflags = Alien::SDL->config('cflags');
108	my $path;
109	my $sdl_typemap = File::Spec->catfile( 'SDL', 'typemap' );
110	 grep { my $find = File::Spec->catfile( $_, $sdl_typemap );
111			$path = $find if -e $find } @INC;
112    return {
113	LIBS => $libs,
114	CCFLAGS => $cflags,
115	TYPEMAPS => $path,
116	AUTO_INCLUDE => '#include <SDL.h>'
117    };
118
119
120
121}
122
1231;
124