1use ExtUtils::MakeMaker;
2$| = 1;
3
4WriteMakefile(
5    NAME            => 'Audio::Ecasound',
6    VERSION_FROM    => 'Ecasound.pm',
7    PREREQ_PM       => {}, # e.g., Module::Name => 1.1
8    # next two could be from libecasoundc-config --libs --cflags
9    # not for now since want it to install w/o libecasoundc-config
10    LIBS            => ['-lecasoundc'],
11    INC             => "-I\${PREFIX}/include",
12    ABSTRACT_FROM   => 'Ecasound.pm',
13    AUTHOR          => 'Brad Bowman <eci-perl@bereft.net>',
14    LICENSE         => 'artistic_2',
15    dist            => {
16        # expand my tabs to 4
17        PREOP => "(cd \$(DISTVNAME); \\
18                    perl -MExtUtils::Manifest=maniread \\
19                        -pi -e 'BEGIN{\@ARGV=keys \%{maniread()}; } \\
20                                s/\\t/    /g' \\
21                    )" },
22    CONFIGURE       =>
23        sub {
24            my %cfg;
25            use Config;
26
27            unless ($Config{usethreads} eq 'define'
28                ||  $Config{ccflags} =~ /\b-D_REENTRANT\b/)
29            {
30                prompt_cont(<<EOT, 'y');
31Your perl was not built with -Dusethreads or -D_REENTRANT
32This may cause problems loading the multithreaded library 
33ecasoundc  (hanging on loading).  It has worked fine for some.
34You are welcome to try...
35
36Proceed anyway?
37EOT
38            }
39
40            # ecasound 2.4.4 http://www.eca.cx/ecasound-list/2006/12/0007.html
41            # old: ecasound < 2.2 (v2.1dev8) mv'd headers and config prgm
42            # old: ecasound < 2.0.1 didn't have reentrant C interface
43            my $eca_version = `libecasoundc-config --version`;
44            if(!defined($eca_version)) {
45                warn "Running ecasoundc-config failed: $!\n";
46
47                prompt_cont(<<EOT, 'y');
48The ecasoundc-config program is used to find the version of the
49ecasoundc library.  You need 2.4.5 or higher.
50
51Proceed anyway?
52EOT
53            } else {
54                chomp $eca_version;
55                # Compare versions pre v-strings
56                my @ev = split /\./, $eca_version;
57                # maj > 2 & rest >= 4.5
58                unless($ev[0] >2 || ($ev[0] == 2 && "$ev[1].$ev[2]" >= '4.5')) {
59                    prompt_cont(<<EOT, 'n');
60Version 2.4.5+ of ecasound is required, you have $eca_version.
61                   
62Proceed anyway? (bad idea)
63EOT
64                }
65            }
66            unless ($ENV{ECASOUND}) {
67                print <<EOT;
68
69ECI now uses the "ECASOUND" env var to find the ecasound executable.
70Set it correctly to suppress the library warning. 
71(The PATH is searched so ECASOUND=ecasound usually works)
72
73EOT
74            }
75            unless ($Config{ivsize} >= $Config{longsize}) {
76                warn "long int is bigger than IV, may cause problems with last_long_interger\n";
77            }
78            return \%cfg;
79        },
80);
81
82sub prompt_cont {
83    my ($message, $default) = @_;
84    local $_;
85
86    chomp($message); # because prompt() adds "[y]\n"
87
88    while (1) {
89        $_ = prompt($message, $default);
90        if(/^n/i) { print "Aborting\n"; exit; }
91        if(/^y/i) { print "Continuing\n"; last; }
92    }
93}
94