9b4c8fefe88603e0391f0c116b6bd27cb30610c2
[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         `sdl-config --libs`;
22         return 1 unless ($? >> 8) and return 0;
23         
24 }
25
26 #This should check if the folder actually has the SDL files
27 sub check_sdl_dir
28 {
29         return 0 unless $ENV{SDL_INST_DIR} and return $ENV{SDL_INST_DIR};
30 }
31
32 sub sdl_libs
33 {
34         if(sdl_con_found)
35         {
36                 local $_ = `sdl-config --libs`;
37                 chomp($_);
38                 return $_;
39         }       
40         elsif( check_sdl_dir() )
41         {
42                 return $arch->alt_link_flags( check_sdl_dir() ) ;
43         }
44         else
45         {
46                 #ask to download
47                 croak 'SDL not installed';
48                 return 0;
49         }
50 }
51
52 sub sdl_c_flags
53 {
54         if(sdl_con_found)
55         {
56                 local $_  = `sdl-config --cflags`;
57                 chomp($_);
58                 return $_;
59         }
60         elsif ( check_sdl_dir() )
61         {
62                 return $arch->alt_compile_flags( check_sdl_dir() );
63 }
64         else
65         {
66                 #ask to download
67                 croak 'SDL not installed';
68         }
69 }
70
71 1;