1# Code to select XS or Pure Perl version inspired by Scalar::List::Utils 2 3use strict; 4use warnings; 5use Config; 6use inc::Module::Install; 7 8# Automatically select XS or PP version in case neither argument is given 9my $got_libFLAC = defined(search_lib('-lFLAC')); 10my $do_xs = can_cc() && $got_libFLAC; 11 12# Select XS or PP version if argument is given 13for (@ARGV) { 14 /^-pp/ and $do_xs = 0; 15 /^-xs/ and $do_xs = 1; 16} 17 18if ($do_xs && !$got_libFLAC) { 19 warn "* libFLAC is not installed or not in the default lib path. Cannot build XS version.\n"; 20 die "* Try building pure perl version by using -pp argument.\n"; 21} 22 23name('Audio-FLAC-Header'); 24license('perl'); 25perl_version('5.005'); 26all_from('Header.pm'); 27requires_external_cc() if $do_xs; 28 29if ($do_xs) { 30 requires_external_cc(); 31 32 print "Building XS version.\n"; 33 34 if ($^O =~ /win32/i) { 35 cc_lib_links('FLAC_static'); 36 } else { 37 cc_lib_links('FLAC'); 38 cc_optimize_flags('-Wall') if $Config::Config{'archname'} =~ /gnu/i; 39 } 40 41} else { 42 print "Not building XS version.\n"; 43 makemaker_args ( XS => {}, C => [] ); 44} 45 46auto_install(); 47WriteAll(); 48 49sub search_lib { 50 my ($lib) = @_; 51 52 unless ($lib =~ /^-l/) { 53 warn "search_lib: illegal arguments, \`$lib\'.\n"; 54 return undef; 55 } 56 57 my $libbase = 'lib' . substr($lib, 2) . $Config{lib_ext}; 58 my $libbase_so = 'lib' . substr($lib, 2) . "." . $Config{so}; 59 60 for my $path (split(' ', $Config{libpth})) { 61 if (-f $path . '/' . $libbase) { 62 print "$path/$libbase\n"; 63 print "Found '$path/$libbase'.\n"; 64 return $lib; 65 } elsif (-f $path . '/' . $libbase_so) { 66 print "$path/$libbase_so\n"; 67 print "Found `$_/$libbase_so'.\n"; 68 return $lib; 69 } 70 } 71 72 return undef; 73} 74