Windows super hack
[sdlgit/SDL_perl.git] / make / lib / SDL / Utility.pm
1 package SDL::Utility;
2 use strict;
3 use warnings;
4 use Carp;
5
6
7 BEGIN{
8         require Exporter;
9         our @ISA = qw(Exporter);
10         our @EXPORT_OK = qw(sdl_con_found sdl_libs sdl_c_flags); 
11 }
12         my $arch =  SDL::Build->get_arch( $^O );
13
14 use lib '../';
15 use SDL::Build;
16
17 #checks to see if sdl-config is availabe
18 #
19 sub sdl_con_found
20 {
21         return 0 if($^O eq 'MSWin32');
22
23         `sdl-config --libs`;
24         return 1 unless ($? >> 8) and return 0;
25         
26 }
27
28 #This should check if the folder actually has the SDL files
29 sub check_sdl_dir
30 {
31         return 0 unless $ENV{SDL_INST_DIR} and return $ENV{SDL_INST_DIR};
32 }
33
34 sub sdl_libs
35 {
36         if(sdl_con_found)
37         {
38                 local $_ = `sdl-config --libs`;
39                 chomp($_);
40                 return $_;
41         }       
42         elsif( check_sdl_dir() )
43         {
44                 return $arch->alt_link_flags( check_sdl_dir() ) ;
45         }
46         else
47         {
48                 #ask to download
49                 croak 'SDL not installed';
50                 return 0;
51         }
52 }
53
54 sub sdl_c_flags
55 {
56         if(sdl_con_found)
57         {
58                 local $_  = `sdl-config --cflags`;
59                 chomp($_);
60                 return $_;
61         }
62         elsif ( check_sdl_dir() )
63         {
64                 return $arch->alt_compile_flags( check_sdl_dir() );
65 }
66         else
67         {
68                 #ask to download
69                 croak 'SDL not installed';
70         }
71 }
72
73 1;