| 1 |
use strict; |
| 2 |
|
| 3 |
use 5.008; |
| 4 |
|
| 5 |
use Config; |
| 6 |
use ExtUtils::MakeMaker qw(WriteMakefile); |
| 7 |
use File::Spec::Functions; |
| 8 |
use Getopt::Long; |
| 9 |
|
| 10 |
my (@INC, @LIBPATH, @LIBS); |
| 11 |
my ($JPEG, $PNG, $GIF, $MYEXTLIB); |
| 12 |
my ($JPEG_VERSION, $PNG_VERSION, $GIF_VERSION); |
| 13 |
|
| 14 |
my ($help, $jpeg_inc, $jpeg_lib, $png_inc, $png_lib, $gif_inc, $gif_lib); |
| 15 |
my ($jpeg_static, $png_static, $gif_static); |
| 16 |
|
| 17 |
my $DEFINES = '-O2'; |
| 18 |
$DEFINES .= ' -Wall' unless $^O =~ /sun|solaris/i; |
| 19 |
$DEFINES .= ' -Wno-unused-value -Wno-format-security -Winline -ffast-math' unless $^O =~ /Win32|sun|solaris/i; |
| 20 |
|
| •21 |
# with gcc-16, it seems we need to link with m; see bug 1143758 |
| 22 |
push @LIBS, '-lm'; |
| 23 |
|
| 24 |
if ( $^O !~ /Win32/i ) { |
| 25 |
# Check for Sparc ReadyNAS to enable ASM code |
| 26 |
if ( -e '/etc/raidiator_version' ) { |
| 27 |
if ( $Config{archname} eq 'sparc-linux' ) { |
| 28 |
$DEFINES .= ' -DPADRE'; |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
push @LIBPATH, '-L/usr/local/lib'; |
| 33 |
} |
| 34 |
|
| 35 |
my $result = GetOptions( |
| 36 |
"help|h" => \$help, |
| 37 |
"with-jpeg-includes=s" => \$jpeg_inc, |
| 38 |
"with-jpeg-libs=s" => \$jpeg_lib, |
| 39 |
"with-jpeg-static" => \$jpeg_static, |
| 40 |
"with-png-includes=s" => \$png_inc, |
| 41 |
"with-png-libs=s" => \$png_lib, |
| 42 |
"with-png-static" => \$png_static, |
| 43 |
"with-gif-includes=s" => \$gif_inc, |
| 44 |
"with-gif-libs=s" => \$gif_lib, |
| 45 |
"with-gif-static" => \$gif_static, |
| 46 |
); |
| 47 |
|
| 48 |
if ($help || !$result) { |
| 49 |
print STDERR <<END; |
| 50 |
Usage: perl Makefile.PL [options] |
| 51 |
|
| 52 |
Configure Image::Scale module. |
| 53 |
|
| 54 |
Options: |
| 55 |
--with-jpeg-includes Path to directory containing jpeglib.h |
| 56 |
--with-jpeg-libs Path to directory containing libjpeg |
| 57 |
--with-jpeg-static Statically link libjpeg |
| 58 |
--with-png-includes Path to directory containing png.h |
| 59 |
--with-png-libs Path to directory containing libpng |
| 60 |
--with-png-static Statically link libpng |
| 61 |
--with-gif-includes Path to directory containing gif_lib.h |
| 62 |
--with-gif-libs Path to directory containing libgif |
| 63 |
--with-gif-static Statically link libgif |
| 64 |
|
| 65 |
END |
| 66 |
|
| 67 |
exit 0; |
| 68 |
} |
| 69 |
|
| 70 |
my @check = qw(/usr/include /usr/local/include /opt/local/include); |
| 71 |
|
| 72 |
# Check in environment-supplied locations before standard ones |
| 73 |
unshift @check, split /:/, $ENV{INCLUDE}; |
| 74 |
|
| 75 |
if ( $^O =~ /Win32/i ) { |
| 76 |
push @check, '../libjpeg-turbo-1.1.1'; |
| 77 |
push @check, '../lpng143'; |
| 78 |
push @check, '../giflib-4.1.6/lib'; |
| 79 |
} |
| 80 |
|
| 81 |
# Look for libjpeg |
| 82 |
for my $incdir ( $jpeg_inc, @check ) { |
| 83 |
if ( $incdir && -e catfile($incdir, 'jpeglib.h') ) { |
| 84 |
$JPEG = 1; |
| 85 |
$jpeg_inc = $incdir; |
| 86 |
|
| 87 |
unshift @INC, '-I' . $jpeg_inc; |
| 88 |
if ($jpeg_lib) { |
| 89 |
unshift @LIBPATH, '-L' . $jpeg_lib; |
| 90 |
} |
| 91 |
|
| 92 |
if ($jpeg_static) { |
| 93 |
if ($jpeg_lib) { |
| 94 |
$MYEXTLIB .= $jpeg_lib . '/' . 'libjpeg$(LIB_EXT) '; |
| 95 |
} |
| 96 |
else { |
| 97 |
$MYEXTLIB .= $jpeg_inc . '/../lib/libjpeg$(LIB_EXT) '; |
| 98 |
} |
| 99 |
} |
| 100 |
else { |
| 101 |
push @LIBS, '-ljpeg'; |
| 102 |
} |
| 103 |
|
| 104 |
if ( $^O =~ /Win32/i ) { |
| 105 |
$JPEG_VERSION = _re_find( catfile($incdir, 'build', 'jconfig.h'), qr/JPEG_LIB_VERSION\s+(\d+)/ ) || 'unknown'; |
| 106 |
} |
| 107 |
else { |
| 108 |
$JPEG_VERSION = _re_find( catfile($incdir, 'jpeglib.h'), qr/JPEG_LIB_VERSION\s+(\d+)/ ) || 'unknown'; |
| 109 |
if ( $JPEG_VERSION eq 'unknown' ) { |
| •110 |
# On Debian, with libjpeg-turbo headers are in a arch specific dir |
| 111 |
my $arch_type = qx(dpkg-architecture -q DEB_HOST_MULTIARCH); |
| 112 |
chomp $arch_type; |
| 113 |
# Also check jconfig.h as it contains the version when using libjpeg-turbo |
| •114 |
if ( -d catdir($incdir, $arch_type) ) { # jconfig.h header is sometimes installed in a subdir |
| 115 |
$JPEG_VERSION = _re_find( catfile($incdir, $arch_type, 'jconfig.h'), qr/JPEG_LIB_VERSION\s+(\d+)/ ) || 'unknown'; |
| 116 |
} |
| 117 |
else { |
| 118 |
$JPEG_VERSION = _re_find( catfile($incdir, 'jconfig.h'), qr/JPEG_LIB_VERSION\s+(\d+)/ ) || 'unknown'; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
$DEFINES .= " -DHAVE_JPEG -DJPEG_VERSION=$JPEG_VERSION"; |
| 124 |
|
| 125 |
last; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
# Look for libpng |
| 130 |
for my $incdir ( $png_inc, @check ) { |
| 131 |
if ( $incdir && -e catfile($incdir, 'png.h') ) { |
| 132 |
$PNG = 1; |
| 133 |
$png_inc = $incdir; |
| 134 |
|
| 135 |
unshift @INC, '-I' . $png_inc; |
| 136 |
if ($png_lib) { |
| 137 |
unshift @LIBPATH, '-L' . $png_lib; |
| 138 |
} |
| 139 |
|
| 140 |
if ($png_static) { |
| 141 |
if ($png_lib) { |
| 142 |
$MYEXTLIB .= $png_lib . '/' . 'libpng$(LIB_EXT) '; |
| 143 |
} |
| 144 |
else { |
| 145 |
$MYEXTLIB .= $png_inc . '/../lib/libpng$(LIB_EXT) '; |
| 146 |
} |
| 147 |
|
| 148 |
push @LIBS, '-lz'; |
| 149 |
} |
| 150 |
else { |
| 151 |
push @LIBS, '-lpng -lz'; |
| 152 |
} |
| 153 |
|
| 154 |
$PNG_VERSION = _re_find( catfile($incdir, 'png.h'), qr/PNG_LIBPNG_VER_STRING\s+"([\d\.]+)"/ ) || 'unknown'; |
| 155 |
|
| 156 |
$DEFINES .= " -DHAVE_PNG -DPNG_VERSION=$PNG_VERSION"; |
| 157 |
|
| 158 |
last; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
# Look for giflib |
| 163 |
for my $incdir ( $gif_inc, @check ) { |
| 164 |
if ( $incdir && -e catfile($incdir, 'gif_lib.h') ) { |
| 165 |
$gif_inc = $incdir; |
| 166 |
|
| 167 |
unshift @INC, '-I' . $gif_inc; |
| 168 |
if ($gif_lib) { |
| 169 |
unshift @LIBPATH, '-L' . $gif_lib; |
| 170 |
} |
| 171 |
|
| 172 |
if ($gif_static) { |
| 173 |
if ($gif_lib) { |
| 174 |
$MYEXTLIB .= $gif_lib . '/' . "libgif\$(LIB_EXT) "; |
| 175 |
} |
| 176 |
else { |
| 177 |
$MYEXTLIB .= $gif_inc . "/../lib/libgif\$(LIB_EXT) "; |
| 178 |
} |
| 179 |
} |
| 180 |
else { |
| 181 |
push @LIBS, "-lgif"; |
| 182 |
} |
| 183 |
|
| 184 |
my $GIF_41 = _re_find( catfile($incdir, 'gif_lib.h'), qr/GIF_LIB_VERSION " Version (4\.1), "/ ); |
| 185 |
my $GIF_MAJOR = _re_find( catfile($incdir, 'gif_lib.h'), qr/GIFLIB_MAJOR (\d+)/ ); |
| 186 |
my $GIF_MINOR = _re_find( catfile($incdir, 'gif_lib.h'), qr/GIFLIB_MINOR (\d+)/ ); |
| 187 |
|
| 188 |
if ( $GIF_MAJOR ) { |
| 189 |
$GIF_VERSION = "${GIF_MAJOR}.${GIF_MINOR}"; |
| 190 |
if ( $GIF_VERSION >= 4.2 ) { |
| 191 |
$GIF = 1; |
| 192 |
$DEFINES .= " -DHAVE_GIF -DGIF_VERSION=$GIF_VERSION"; |
| 193 |
|
| 194 |
# giflib >= 5.1 changes DGifClose() |
| 195 |
if ( $GIF_VERSION >= 5.1 ) { |
| 196 |
$DEFINES .= " -DGIFLIB_API_51"; |
| 197 |
} |
| 198 |
|
| 199 |
# giflib >= 5.0 change DGifOpen(), GifErrorString(), GifAddExtensionBlock() and struct SavedImage |
| 200 |
if ( $GIF_VERSION >= 5.0 ) { |
| 201 |
$DEFINES .= " -DGIFLIB_API_50"; |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
elsif ( $GIF_41 ) { |
| 206 |
$GIF = 1; |
| 207 |
$GIF_VERSION = '4.1'; |
| 208 |
$DEFINES .= ' -DHAVE_GIF -DGIF_VERSION=4.1 -DGIFLIB_API_41'; |
| 209 |
} |
| 210 |
|
| 211 |
last; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
# Require at least one of jpeg or png |
| 216 |
if ( !$JPEG && !$PNG ) { |
| 217 |
my $err = "Image::Scale requires at least one of libjpeg or libpng, please install one or both and try again.\n"; |
| 218 |
|
| 219 |
if ( $^O =~ /Win32/i ) { |
| 220 |
$err .= "\nPlease read the README.win32 file for build instructions on Windows.\n"; |
| 221 |
} |
| 222 |
|
| 223 |
warn $err; |
| 224 |
|
| 225 |
exit 0; |
| 226 |
} |
| 227 |
|
| 228 |
unshift @INC, '-I. -I.. -Isrc -Iinclude'; |
| 229 |
|
| 230 |
print "\n"; |
| 231 |
print "Image::Scale will be built with:\n\n"; |
| 232 |
print " JPEG support: " . ( $JPEG ? "yes ($jpeg_inc, libjpeg version $JPEG_VERSION)" : "no, install libjpeg (v8 recommended)" ) . "\n"; |
| 233 |
print " PNG support: " . ( $PNG ? "yes ($png_inc, libpng version $PNG_VERSION)" : "no, install libpng (v1.4.x recommended)" ) . "\n"; |
| 234 |
print " GIF support: " . ( $GIF ? "yes ($gif_inc, giflib version $GIF_VERSION)" : "no, install giflib v4.1 or higher" ) . "\n"; |
| 235 |
print "\n"; |
| 236 |
|
| 237 |
if ( $^O =~ /Win32/i ) { |
| 238 |
*MY::postamble = sub {}; |
| 239 |
|
| 240 |
if ($JPEG) { |
| 241 |
push @INC, '-I../libjpeg-turbo-1.1.1/build'; # for jconfig.h |
| 242 |
$MYEXTLIB .= '../libjpeg-turbo-1.1.1/build/jpeg-static.lib '; |
| 243 |
} |
| 244 |
|
| 245 |
if ($PNG) { |
| 246 |
push @INC, '-I../zlib'; |
| 247 |
$MYEXTLIB .= '../lpng143/libpng.lib ../zlib/zlib.lib '; |
| 248 |
} |
| 249 |
|
| 250 |
if ($GIF) { |
| 251 |
$MYEXTLIB .= '../giflib-4.1.6/windows/Release/giflib.lib '; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
my $inc_files = join(' ', glob 'include/*.h'); |
| 256 |
my $src_files = join(' ', glob 'src/*.c'); |
| 257 |
|
| 258 |
WriteMakefile( |
| 259 |
NAME => 'Image::Scale', |
| 260 |
VERSION_FROM => 'lib/Image/Scale.pm', |
| 261 |
PREREQ_PM => { 'Test::NoWarnings' => 0 }, |
| 262 |
ABSTRACT_FROM => 'lib/Image/Scale.pm', |
| 263 |
AUTHOR => 'Andy Grundman <[email protected]>', |
| 264 |
INC => join(' ', @INC), |
| 265 |
LIBS => [ join(' ', @LIBPATH, @LIBS) ], |
| 266 |
DEFINE => $DEFINES, |
| 267 |
MYEXTLIB => $MYEXTLIB, |
| 268 |
depend => { 'Scale.c' => "$inc_files $src_files" }, |
| 269 |
META_MERGE => { |
| 270 |
'meta-spec' => { version => 2 }, |
| 271 |
resources => { |
| 272 |
repository => { |
| 273 |
type => 'git', |
| 274 |
url => 'https://github.com/andygrundman/Image-Scale.git', |
| 275 |
web => 'https://github.com/andygrundman/Image-Scale', |
| 276 |
}, |
| 277 |
}, |
| 278 |
}, |
| 279 |
MIN_PERL_VERSION => 5.008, |
| 280 |
LICENSE => 'gpl_2', |
| 281 |
); |
| 282 |
|
| 283 |
sub _re_find { |
| 284 |
my ( $file, $re ) = @_; |
| 285 |
|
| 286 |
my $result; |
| 287 |
|
| 288 |
open my $fh, '<', $file or die "Unable to read $file\n"; |
| 289 |
while ( my $line = <$fh> ) { |
| 290 |
if ( $line =~ $re ) { |
| 291 |
$result = $1; |
| 292 |
last; |
| 293 |
} |
| 294 |
} |
| 295 |
close $fh; |
| 296 |
|
| 297 |
return $result; |
| 298 |
} |