| 1 |
#!perl |
| 2 |
# -*- cperl -*- |
| 3 |
use strict; |
| 4 |
use Config; |
| 5 |
use File::Copy; |
| 6 |
|
| 7 |
chmod(0666,'Makefile'); |
| 8 |
unlink('Makefile'); |
| 9 |
|
| 10 |
unless (try_configure()) |
| 11 |
{ |
| 12 |
my $file; |
| 13 |
if ($^O eq 'MSWin32') |
| 14 |
{ |
| 15 |
if ($Config{'cc'} =~ /gcc/ && $Config{'make'} =~ /dmake/) |
| 16 |
{ |
| 17 |
# This is the StrawberryPerl configuration |
| 18 |
$file = 'scripts/makefile.gcc'; |
| 19 |
} |
| 20 |
elsif ($Config{'cc'} =~ /gcc/) |
| 21 |
{ |
| 22 |
$file = 'scripts/makefile.mingw'; |
| 23 |
} |
| 24 |
elsif ($Config{'cc'} =~ /bcc/) |
| 25 |
{ |
| 26 |
$file = 'scripts/makefile.bc32'; |
| 27 |
} |
| 28 |
else |
| 29 |
{ |
| 30 |
$file = 'scripts/makefile.vcwin32'; |
| 31 |
warn "Assuming ".$Config{'cc'}." is visual C of some kind\n"; |
| 32 |
} |
| 33 |
} |
| 34 |
else |
| 35 |
{ |
| 36 |
if ($Config{'gccversion'}) |
| 37 |
{ |
| 38 |
$file = 'scripts/makefile.gcc'; |
| 39 |
} |
| 40 |
else |
| 41 |
{ |
| 42 |
if (($Config{archname} =~ /^IA64\./) && ($^O eq "hpux")) |
| 43 |
{ |
| 44 |
$file = 'scripts/makefile.hp64'; |
| 45 |
} |
| 46 |
elsif ($^O eq 'aix') # untested! see http://rt.cpan.org/Ticket/Display.html?id=40064 |
| 47 |
{ |
| 48 |
$file = 'scripts/makefile.aix'; |
| 49 |
} |
| 50 |
else |
| 51 |
{ |
| 52 |
$file = 'scripts/makefile.std'; |
| 53 |
my %makefiles = map { /makefile\.(.*)/ && ($1 => $_) } glob('scripts/makefile.*'); |
| 54 |
foreach my $arch (sort keys %makefiles) |
| 55 |
{ |
| 56 |
if ($^O =~ /$arch/i) |
| 57 |
{ |
| 58 |
$file = $makefiles{$arch}; |
| 59 |
} |
| 60 |
} |
| 61 |
} |
| 62 |
} |
| 63 |
warn "Using $file for $^O\nIf make fails read PNG/libpng/INSTALL\n"; |
| 64 |
} |
| 65 |
|
| 66 |
copy($file,"Makefile") |
| 67 |
|| die "Cannot copy $file to Makefile:$!"; |
| 68 |
} |
| 69 |
|
| 70 |
sub try_configure |
| 71 |
{ |
| 72 |
if ($^O eq 'darwin' || |
| 73 |
$Config{'archname'} =~ m{^(?: |
| 74 |
amd64-.* # e.g. freebsd, netbsd, openbsd |
| 75 |
|OpenBSD.amd64-openbsd |
| 76 |
|i386-freebsd |
| 77 |
|x86_64-.* # e.g. linux, dragonfly |
| 78 |
|[^-]+-solaris # e.g. sun4-solaris, i86pc-solaris |
| 79 |
|IP35-irix |
| 80 |
)(?:$|-.*) |
| 81 |
}x |
| 82 |
) |
| 83 |
{ |
| 84 |
local $ENV{CC} = $Config{cc}; |
| 85 |
local $ENV{CFLAGS} = "$Config{ccflags} $Config{cccdlflags}"; |
| 86 |
if ($^O eq 'darwin' && $ENV{CFLAGS} =~ m{-arch .*-arch }) { # multiple architectures not supported --- at least MacOSX is affected |
| 87 |
$ENV{CFLAGS} =~ s{-arch \S+}{}g; |
| 88 |
} |
| 89 |
system(sh => "./configure"); |
| 90 |
if ($? == 0 && -s "Makefile") |
| 91 |
{ |
| 92 |
open my $fh, ">>", "Makefile" or die "Can't write to Makefile: $!"; |
| 93 |
print $fh <<'EOF'; |
| 94 |
|
| 95 |
libpng.a: all |
| 96 |
cp .libs/libpng.a libpng.a |
| 97 |
|
| 98 |
clean: |
| 99 |
rm -f libpng.a |
| 100 |
|
| 101 |
# Empty rule needed since ExtUtils::MakeMaker 6.36 (ca.) |
| 102 |
test: |
| 103 |
|
| 104 |
# Empty rule needed since ExtUtils::MakeMaker 7.18 (see https://rt.cpan.org/Ticket/Display.html?id=117800) |
| 105 |
test_dynamic: |
| 106 |
|
| 107 |
EOF |
| 108 |
return 1; |
| 109 |
} |
| 110 |
else |
| 111 |
{ |
| 112 |
return 0; |
| 113 |
} |
| 114 |
} |
| 115 |
return 0; |
| 116 |
} |
| 117 |
|
| 118 |
1; |
| 119 |
|