Merge branch 'experimental'
[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 use File::Spec;
17
18 #checks to see if sdl-config is availabe
19 #
20 sub sdl_con_found
21 {
22        my $devnull = File::Spec->devnull();     
23        `sdl-config --libs 2>$devnull`;
24        return 1 unless ($? >> 8) and return 0;
25 }
26
27 #This should check if the folder actually has the SDL files
28 sub check_sdl_dir
29 {
30         return 0 unless $ENV{SDL_INST_DIR} and return $ENV{SDL_INST_DIR};
31 }
32
33 sub not_installed_message
34 {
35         print STDERR <<MSG;
36 ********************************* !!!ERROR!!! ********************************* 
37 SDL library not found.
38 1) If you do not have SDL, you can download it from see http://www.libsdl.org/
39 2) If you have already installed SDL, you can specify the location of your SDL
40    installation by setting the enviroment variable SDL_INST_DIR.  
41 *******************************************************************************
42 MSG
43 }
44
45
46 sub sdl_libs
47 {
48         if(sdl_con_found)
49         {
50                 my $devnull = File::Spec->devnull();
51                 local $_ = `sdl-config --libs 2>$devnull`; 
52                 chomp($_);
53                 return $_;
54         }       
55         elsif( check_sdl_dir() )
56         {
57                 return $arch->alt_link_flags( check_sdl_dir() ) ;
58         }
59         else
60         {
61                 #ask to download
62                 not_installed_message;
63                 croak 'SDL not installed';
64                 return 0;
65         }
66 }
67
68 sub sdl_c_flags
69 {
70         if(sdl_con_found)
71         {
72                 my $devnull = File::Spec->devnull();
73                 local $_  = `sdl-config --cflags 2>$devnull`;    
74                 chomp($_);
75                 return $_;
76         }
77         elsif ( check_sdl_dir() )
78         {
79                 return $arch->alt_compile_flags( check_sdl_dir() );
80 }
81         else
82         {
83                 #ask to download
84                 not_installed_message ;
85                 croak 'SDL not installed';
86         }
87 }
88
89 1;