| 1 |
#!perl -w |
| 2 |
use strict; |
| 3 |
use ExtUtils::MakeMaker; |
| 4 |
use Cwd; |
| 5 |
use Config; |
| 6 |
use File::Spec; |
| 7 |
use Getopt::Long; |
| 8 |
use ExtUtils::Manifest qw(maniread); |
| 9 |
use ExtUtils::Liblist; |
| 10 |
use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS); |
| 11 |
use lib 'inc', 'lib'; |
| 12 |
use Imager::Probe; |
| 13 |
|
| 14 |
# EU::MM runs Makefile.PL all in the same process, so sub-modules will |
| 15 |
# see this |
| 16 |
our $BUILDING_IMAGER = 1; |
| 17 |
|
| 18 |
# used to display a summary after we've probed the world |
| 19 |
our %IMAGER_LIBS; |
| 20 |
|
| 21 |
# |
| 22 |
# IM_INCPATH colon seperated list of paths to extra include paths |
| 23 |
# IM_LIBPATH colon seperated list of paths to extra library paths |
| 24 |
# |
| 25 |
# IM_VERBOSE turns on verbose mode for the library finding and such |
| 26 |
# IM_MANUAL to manually select which libraries are used and which not |
| 27 |
# IM_ENABLE to programmatically select which libraries are used |
| 28 |
# and which are not |
| 29 |
# IM_NOLOG if true logging will not be compiled into the module |
| 30 |
# IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module |
| 31 |
# do not use IM_DEBUG_MALLOC in production - this slows |
| 32 |
# everything down by alot |
| 33 |
# IM_CFLAGS Extra flags to pass to the compiler |
| 34 |
# IM_LFLAGS Extra flags to pass to the linker |
| 35 |
# IM_DFLAGS Extra flags to pass to the preprocessor |
| 36 |
|
| 37 |
my $KEEP_FILES = $ENV{IMAGER_KEEP_FILES}; |
| 38 |
|
| 39 |
# make sure --verbose will dump environment settings |
| 40 |
if (grep $_ =~ /^--?v(?:erbose)?$/, @ARGV) { |
| 41 |
$VERBOSE = 1; |
| 42 |
} |
| 43 |
|
| 44 |
# modules/features bundled with Imager that can be enabled/disabled |
| 45 |
# withs --enable/--disable |
| 46 |
my @bundled = qw(FT1 FT2 GIF JPEG PNG T1 TIFF W32); |
| 47 |
|
| 48 |
# extra modules bundled with Imager not available on CPAN |
| 49 |
my @extras = qw(CountColor DynTest ICO SGI Mandelbrot Flines); |
| 50 |
|
| 51 |
# alternate names for modules |
| 52 |
my %bundled_names = qw(win32 w32 tt ft1); |
| 53 |
|
| 54 |
getenv(); # get environment variables |
| 55 |
|
| 56 |
my $lext=$Config{'so'}; # Get extensions of libraries |
| 57 |
my $aext=$Config{'_a'}; |
| 58 |
|
| 59 |
my $help; # display help if set |
| 60 |
my @enable; # list of drivers to enable |
| 61 |
my @disable; # or list of drivers to disable |
| 62 |
my @incpaths; # places to look for headers |
| 63 |
my @libpaths; # places to look for libraries |
| 64 |
my $coverage; # build for coverage testing |
| 65 |
my $assert; # build with assertions |
| 66 |
my $trace_context; # trace context management to stderr |
| 67 |
GetOptions("help" => \$help, |
| 68 |
"enable=s" => \@enable, |
| 69 |
"disable=s" => \@disable, |
| 70 |
"incpath=s", \@incpaths, |
| 71 |
"libpath=s" => \@libpaths, |
| 72 |
"verbose|v" => \$VERBOSE, |
| 73 |
"nolog" => \$NOLOG, |
| 74 |
'coverage' => \$coverage, |
| 75 |
"assert|a" => \$assert, |
| 76 |
"tracecontext" => \$trace_context); |
| 77 |
|
| 78 |
setenv(); |
| 79 |
|
| 80 |
if ($ENV{AUTOMATED_TESTING}) { |
| 81 |
$assert = 1; |
| 82 |
} |
| 83 |
|
| 84 |
if ($VERBOSE) { |
| 85 |
print "Verbose mode\n"; |
| 86 |
require Data::Dumper; |
| 87 |
import Data::Dumper qw(Dumper); |
| 88 |
} |
| 89 |
|
| 90 |
if ($help) { |
| 91 |
usage(); |
| 92 |
} |
| 93 |
|
| 94 |
my @defines; |
| 95 |
|
| 96 |
if ($NOLOG) { print "Logging not compiled into module\n"; } |
| 97 |
else { |
| 98 |
push @defines, [ IMAGER_LOG => 1, "Logging system" ]; |
| 99 |
} |
| 100 |
|
| 101 |
if ($assert) { |
| 102 |
push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ]; |
| 103 |
} |
| 104 |
|
| 105 |
if ($DEBUG_MALLOC) { |
| 106 |
push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; |
| 107 |
print "Malloc debugging enabled\n"; |
| 108 |
} |
| 109 |
|
| 110 |
if (@enable && @disable) { |
| 111 |
print STDERR "Only --enable or --disable can be used, not both, try --help\n"; |
| 112 |
exit 1; |
| 113 |
} |
| 114 |
if (!@enable && !@disable) { |
| 115 |
@disable = qw(T1 FT1); |
| 116 |
} |
| 117 |
|
| 118 |
my %definc; |
| 119 |
my %deflib; |
| 120 |
my @incs; # all the places to look for headers |
| 121 |
my @libs; # all the places to look for libraries |
| 122 |
|
| 123 |
init(); # initialize global data |
| 124 |
pathcheck(); # Check if directories exist |
| 125 |
|
| 126 |
my @enabled_bundled; |
| 127 |
if (exists $ENV{IM_ENABLE}) { |
| 128 |
push @enable, split ' ', $ENV{IM_ENABLE}; |
| 129 |
} |
| 130 |
if (@enable) { |
| 131 |
my %en = map { lc $_ => 1 } map_bundled(@enable); |
| 132 |
@enabled_bundled = grep $en{lc $_}, @bundled; |
| 133 |
} |
| 134 |
elsif (@disable) { |
| 135 |
my %dis = map { lc $_ => 1 } map_bundled(@disable); |
| 136 |
@enabled_bundled = grep !$dis{lc $_}, @bundled; |
| 137 |
} |
| 138 |
else { |
| 139 |
@enabled_bundled = @bundled; |
| 140 |
} |
| 141 |
|
| 142 |
# Pick what libraries are used |
| 143 |
if ($MANUAL) { |
| 144 |
manual(); |
| 145 |
} else { |
| 146 |
automatic(); |
| 147 |
} |
| 148 |
|
| 149 |
my @objs = qw(Imager.o context.o draw.o polygon.o image.o io.o iolayer.o |
| 150 |
log.o gaussian.o conv.o pnm.o raw.o feat.o combine.o |
| 151 |
filters.o dynaload.o stackmach.o datatypes.o |
| 152 |
regmach.o trans2.o quant.o error.o convert.o |
| 153 |
map.o tags.o palimg.o maskimg.o img8.o img16.o rotate.o |
| 154 |
bmp.o tga.o color.o fills.o imgdouble.o limits.o hlines.o |
| 155 |
imext.o scale.o rubthru.o render.o paste.o compose.o flip.o |
| 156 |
perlio.o imexif.o trim.o); |
| 157 |
|
| 158 |
my $lib_define = ''; |
| 159 |
my $lib_inc = ''; |
| 160 |
my $lib_libs = ''; |
| 161 |
for my $frmkey (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) { |
| 162 |
my $frm = $formats{$frmkey}; |
| 163 |
if ($frm->{enabled}) { |
| 164 |
push @defines, [ $frm->{def}, 1, "$frmkey available" ]; |
| 165 |
push @objs, $frm->{objfiles}; |
| 166 |
$lib_define .= " $frm->{DEFINE}" if $frm->{DEFINE}; |
| 167 |
$lib_inc .= " $frm->{INC}" if $frm->{INC}; |
| 168 |
$lib_libs .= " $frm->{LIBS}" if $frm->{LIBS}; |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
my $OSLIBS = ''; |
| 173 |
my $OSDEF = "-DOS_$^O"; |
| 174 |
|
| 175 |
if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } |
| 176 |
if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } |
| 177 |
|
| 178 |
if ($Config{useithreads}) { |
| 179 |
if ($Config{i_pthread}) { |
| 180 |
print "POSIX threads\n"; |
| 181 |
push @objs, "mutexpthr.o"; |
| 182 |
} |
| 183 |
elsif ($^O eq 'MSWin32') { |
| 184 |
print "Win32 threads\n"; |
| 185 |
push @objs, "mutexwin.o"; |
| 186 |
} |
| 187 |
else { |
| 188 |
print "Unsupported threading model\n"; |
| 189 |
push @objs, "mutexnull.o"; |
| 190 |
if ($ENV{AUTOMATED_TESTING}) { |
| 191 |
die "OS unsupported: no threading support code for this platform\n"; |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
else { |
| 196 |
print "No threads\n"; |
| 197 |
push @objs, "mutexnull.o"; |
| 198 |
} |
| 199 |
|
| 200 |
my @typemaps = qw(typemap.local typemap); |
| 201 |
if ($] < 5.008) { |
| 202 |
unshift @typemaps, "typemap.oldperl"; |
| 203 |
} |
| 204 |
|
| 205 |
if ($trace_context) { |
| 206 |
$CFLAGS .= " -DIMAGER_TRACE_CONTEXT"; |
| 207 |
} |
| 208 |
|
| 209 |
my $tests = 't/*.t t/*/*.t'; |
| 210 |
if (-d "xt" && scalar(() = glob("xt/*.t"))) { |
| 211 |
$tests .= " xt/*.t"; |
| 212 |
} |
| 213 |
|
| 214 |
my %opts= |
| 215 |
( |
| 216 |
NAME => 'Imager', |
| 217 |
VERSION_FROM => 'Imager.pm', |
| 218 |
LIBS => "$LFLAGS -lm $lib_libs $OSLIBS", |
| 219 |
DEFINE => "$OSDEF $lib_define $CFLAGS", |
| 220 |
INC => "$lib_inc $DFLAGS", |
| 221 |
OBJECT => join(' ', @objs), |
| 222 |
DIR => [ sort grep -d, @enabled_bundled, @extras ], |
| 223 |
clean => { FILES=>'testout rubthru.c scale.c conv.c filters.c gaussian.c render.c rubthru.c cov-int' }, |
| 224 |
PM => gen_PM(), |
| 225 |
PREREQ_PM => |
| 226 |
{ |
| 227 |
'Test::More' => 0.99, |
| 228 |
'Scalar::Util' => 1.00, |
| 229 |
'XSLoader' => 0, |
| 230 |
'Exporter' => '5.57', |
| 231 |
}, |
| 232 |
TYPEMAPS => \@typemaps, |
| 233 |
test => { TESTS => $tests }, |
| 234 |
); |
| 235 |
|
| 236 |
if ($coverage) { |
| 237 |
if ($Config{gccversion}) { |
| 238 |
push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs -g'; |
| 239 |
$opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' }; |
| 240 |
} |
| 241 |
else { |
| 242 |
die "Don't know the coverage C flags for your compiler\n"; |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
if (eval { ExtUtils::MakeMaker->VERSION('6.06'); 1 }) { |
| 247 |
$opts{AUTHOR} = 'Tony Cook <[email protected]>, Arnar M. Hrafnkelsson'; |
| 248 |
$opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; |
| 249 |
} |
| 250 |
|
| 251 |
if (eval { ExtUtils::MakeMaker->VERSION('6.46'); 1 }) { |
| 252 |
$opts{LICENSE} = "perl_5"; |
| 253 |
$opts{META_MERGE} = |
| 254 |
{ |
| 255 |
'meta-spec' => |
| 256 |
{ |
| 257 |
version => "2", |
| 258 |
url => "https://metacpan.org/pod/CPAN::Meta::Spec", |
| 259 |
}, |
| 260 |
prereqs => |
| 261 |
{ |
| 262 |
runtime => |
| 263 |
{ |
| 264 |
recommends => |
| 265 |
{ |
| 266 |
"Parse::RecDescent" => 0 |
| 267 |
}, |
| 268 |
requires => |
| 269 |
{ |
| 270 |
'Scalar::Util' => "1.00", |
| 271 |
XSLoader => 0, |
| 272 |
'Exporter' => '5.57', |
| 273 |
}, |
| 274 |
}, |
| 275 |
build => |
| 276 |
{ |
| 277 |
requires => |
| 278 |
{ |
| 279 |
XSLoader => 0, |
| 280 |
'Exporter' => '5.57', |
| 281 |
}, |
| 282 |
}, |
| 283 |
test => |
| 284 |
{ |
| 285 |
requires => |
| 286 |
{ |
| 287 |
'Test::More' => "0.99", |
| 288 |
}, |
| 289 |
}, |
| 290 |
}, |
| 291 |
dynamic_config => 0, |
| 292 |
no_index => |
| 293 |
{ |
| 294 |
directory => |
| 295 |
[ |
| 296 |
"PNG", |
| 297 |
"GIF", |
| 298 |
"TIFF", |
| 299 |
"JPEG", |
| 300 |
"W32", |
| 301 |
"FT2", |
| 302 |
"T1", |
| 303 |
], |
| 304 |
}, |
| 305 |
resources => |
| 306 |
{ |
| 307 |
homepage => "http://imager.perl.org/", |
| 308 |
repository => |
| 309 |
{ |
| 310 |
url => "git://github.com/tonycoz/imager.git", |
| 311 |
web => "https://github.com/tonycoz/imager.git", |
| 312 |
type => "git", |
| 313 |
}, |
| 314 |
bugtracker => |
| 315 |
{ |
| 316 |
web => "https://github.com/tonycoz/imager/issues", |
| 317 |
}, |
| 318 |
}, |
| 319 |
}; |
| 320 |
} |
| 321 |
|
| 322 |
make_imconfig(\@defines); |
| 323 |
|
| 324 |
if ($VERBOSE) { print Dumper(\%opts); } |
| 325 |
mkdir('testout',0777); # since we cannot include it in the archive. |
| 326 |
|
| 327 |
-d "probe" and rmdir "probe"; |
| 328 |
|
| 329 |
WriteMakefile(%opts); |
| 330 |
|
| 331 |
my @good; |
| 332 |
my @bad; |
| 333 |
for my $name (sort { lc $a cmp lc $b } keys %IMAGER_LIBS) { |
| 334 |
if ($IMAGER_LIBS{$name}) { |
| 335 |
push @good, $name; |
| 336 |
} |
| 337 |
else { |
| 338 |
push @bad, $name; |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
print "\n"; |
| 343 |
print "Libraries found:\n" if @good; |
| 344 |
print " $_\n" for @good; |
| 345 |
print "Libraries *not* found:\n" if @bad; |
| 346 |
print " $_\n" for @bad; |
| 347 |
|
| 348 |
open my $fh, ">", "imfound.cfg" |
| 349 |
or die "Cannot create imfound.cfg: $!\n"; |
| 350 |
binmode $fh; |
| 351 |
print $fh lc, "\n" for @good; |
| 352 |
close $fh; |
| 353 |
|
| 354 |
exit; |
| 355 |
|
| 356 |
|
| 357 |
sub MY::postamble { |
| 358 |
my $self = shift; |
| 359 |
my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)'; |
| 360 |
my $mani = maniread; |
| 361 |
|
| 362 |
my @ims = grep /\.im$/, keys %$mani; |
| 363 |
' |
| 364 |
dyntest.$(MYEXTLIB) : dynfilt/Makefile |
| 365 |
cd dynfilt && $(MAKE) $(PASTHRU) |
| 366 |
|
| 367 |
lib/Imager/Regops.pm : regmach.h regops.perl |
| 368 |
$(PERL) regops.perl regmach.h lib/Imager/Regops.pm |
| 369 |
|
| 370 |
imconfig.h : Makefile.PL |
| 371 |
$(ECHO) "imconfig.h out-of-date with respect to $?" |
| 372 |
$(PERLRUN) Makefile.PL |
| 373 |
$(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <==" |
| 374 |
'.qq! |
| 375 |
lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl |
| 376 |
$perl apidocs.perl lib/Imager/APIRef.pod |
| 377 |
|
| 378 |
!.join('', map _im_rule($perl, $_), @ims) |
| 379 |
|
| 380 |
} |
| 381 |
|
| 382 |
sub _im_rule { |
| 383 |
my ($perl, $im) = @_; |
| 384 |
|
| 385 |
(my $c = $im) =~ s/\.im$/.c/; |
| 386 |
return <<MAKE; |
| 387 |
|
| 388 |
$c: $im lib/Imager/Preprocess.pm |
| 389 |
$perl -Ilib -MImager::Preprocess -epreprocess $im $c |
| 390 |
|
| 391 |
MAKE |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
# manual configuration of helper libraries |
| 396 |
|
| 397 |
sub manual { |
| 398 |
print <<EOF; |
| 399 |
|
| 400 |
Please answer the following questions about |
| 401 |
which formats are avaliable on your computer |
| 402 |
|
| 403 |
Warning: if you use manual configuration you are responsible for |
| 404 |
configuring extra include/library directories as necessary using |
| 405 |
INC and LIBS command-line assignments. |
| 406 |
|
| 407 |
press <return> to continue |
| 408 |
EOF |
| 409 |
|
| 410 |
<STDIN>; # eat one return |
| 411 |
|
| 412 |
for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) { |
| 413 |
SWX: |
| 414 |
if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } |
| 415 |
print "Enable $frm support: "; |
| 416 |
my $gz = <STDIN>; |
| 417 |
chomp($gz); |
| 418 |
if ($gz =~ m/^(y|yes|n|no)/i) { |
| 419 |
if ($gz =~ /y/i) { |
| 420 |
$formats{$frm}{enabled} = 1; |
| 421 |
$IMAGER_LIBS{$frm} = 1; |
| 422 |
} |
| 423 |
} else { goto SWX; } |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
|
| 428 |
# automatic configuration of helper libraries |
| 429 |
|
| 430 |
sub automatic { |
| 431 |
print "Automatic probing:\n" if $VERBOSE; |
| 432 |
|
| 433 |
if (grep $_ eq "FT1", @enabled_bundled) { |
| 434 |
my %probe = |
| 435 |
( |
| 436 |
name => "FT1", |
| 437 |
inccheck => sub { -e File::Spec->catfile($_[0], "ftnameid.h") }, |
| 438 |
libbase => "ttf", |
| 439 |
testcode => _ft1_test_code(), |
| 440 |
testcodeheaders => [ "freetype.h", "stdio.h" ], |
| 441 |
incpaths => \@incpaths, |
| 442 |
libpaths => \@libpaths, |
| 443 |
alternatives => |
| 444 |
[ |
| 445 |
{ |
| 446 |
incsuffix => "freetype", |
| 447 |
} |
| 448 |
], |
| 449 |
verbose => $VERBOSE, |
| 450 |
); |
| 451 |
my $probe_res = Imager::Probe->probe(\%probe); |
| 452 |
$IMAGER_LIBS{FT1} = defined $probe_res; |
| 453 |
if ($probe_res) { |
| 454 |
$formats{FT1}{enabled} = 1; |
| 455 |
@{$formats{FT1}}{qw/DEFINE INC LIBS/} = |
| 456 |
@$probe_res{qw/DEFINE INC LIBS/}; |
| 457 |
} |
| 458 |
} |
| 459 |
} |
| 460 |
|
| 461 |
sub pathcheck { |
| 462 |
if ($VERBOSE) { |
| 463 |
print "pathcheck\n"; |
| 464 |
print " Include paths:\n"; |
| 465 |
for (@incs) { print $_,"\n"; } |
| 466 |
} |
| 467 |
@incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs; |
| 468 |
|
| 469 |
if ($VERBOSE) { |
| 470 |
print "\nLibrary paths:\n"; |
| 471 |
for (@libs) { print $_,"\n"; } |
| 472 |
} |
| 473 |
@libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs; |
| 474 |
print "\ndone.\n"; |
| 475 |
} |
| 476 |
|
| 477 |
|
| 478 |
# Format data initialization |
| 479 |
|
| 480 |
# format definition is: |
| 481 |
# defines needed |
| 482 |
# default include path |
| 483 |
# files needed for include (boolean perl code) |
| 484 |
# default lib path |
| 485 |
# libs needed |
| 486 |
# files needed for link (boolean perl code) |
| 487 |
# object files needed for the format |
| 488 |
|
| 489 |
|
| 490 |
sub init { |
| 491 |
|
| 492 |
my @definc = qw(/usr/include); |
| 493 |
@definc{@definc}=(1) x @definc; |
| 494 |
@incs= |
| 495 |
( |
| 496 |
split(/\Q$Config{path_sep}/, $INCPATH), |
| 497 |
map _tilde_expand($_), map { split /\Q$Config{path_sep}/ } @incpaths |
| 498 |
); |
| 499 |
if ($Config{locincpth}) { |
| 500 |
push @incs, grep -d, split ' ', $Config{locincpth}; |
| 501 |
} |
| 502 |
if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
| 503 |
push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; |
| 504 |
} |
| 505 |
if ($Config{incpath}) { |
| 506 |
push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath}; |
| 507 |
} |
| 508 |
push @incs, grep -d, |
| 509 |
qw(/sw/include |
| 510 |
/usr/include/freetype2 |
| 511 |
/usr/local/include/freetype2 |
| 512 |
/usr/local/include/freetype1/freetype |
| 513 |
/usr/include /usr/local/include /usr/include/freetype |
| 514 |
/usr/local/include/freetype); |
| 515 |
if ($Config{ccflags}) { |
| 516 |
my @hidden = map { /^-I(.*)$/ ? ($1) : () } split ' ', $Config{ccflags}; |
| 517 |
push @incs, @hidden; |
| 518 |
@definc{@hidden} = (1) x @hidden; |
| 519 |
} |
| 520 |
|
| 521 |
@libs= ( split(/\Q$Config{path_sep}/,$LIBPATH), |
| 522 |
map _tilde_expand($_), map { split /\Q$Config{path_sep}/} @libpaths ); |
| 523 |
if ($Config{loclibpth}) { |
| 524 |
push @libs, grep -d, split ' ', $Config{loclibpth}; |
| 525 |
} |
| 526 |
|
| 527 |
push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'}); |
| 528 |
push @libs, grep -d, split / /, $Config{libspath} if $Config{libspath}; |
| 529 |
if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
| 530 |
push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; |
| 531 |
} |
| 532 |
if ($^O eq 'cygwin') { |
| 533 |
push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api'; |
| 534 |
push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api'; |
| 535 |
} |
| 536 |
if ($Config{ldflags}) { |
| 537 |
# some builds of perl put -Ldir into ldflags without putting it in |
| 538 |
# loclibpth, let's extract them |
| 539 |
my @hidden = grep -d, map { /^-L(.*)$/ ? ($1) : () } |
| 540 |
split ' ', $Config{ldflags}; |
| 541 |
push @libs, @hidden; |
| 542 |
# don't mark them as seen - EU::MM will remove any libraries |
| 543 |
# it can't find and it doesn't look for -L in ldflags |
| 544 |
#@deflib{@hidden} = @hidden; |
| 545 |
} |
| 546 |
push @libs, grep -d, qw(/usr/local/lib); |
| 547 |
|
| 548 |
$formats{FT1}= |
| 549 |
{ |
| 550 |
order=>'31', |
| 551 |
def=>'HAVE_LIBTT', |
| 552 |
objfiles=>'fontft1.o', |
| 553 |
LIBS => "-lttf", |
| 554 |
docs=>q{ |
| 555 |
Freetype 1.x supports Truetype fonts and is obsoleted by Freetype 2.x. |
| 556 |
|
| 557 |
It's probably insecure. |
| 558 |
} |
| 559 |
}; |
| 560 |
# Make fix indent |
| 561 |
for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } |
| 562 |
} |
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
sub gen { |
| 567 |
my $V = $ENV{$_[0]}; |
| 568 |
print " $_[0]: '$V'\n" |
| 569 |
if $VERBOSE && defined $V; |
| 570 |
defined($V) ? $V : ""; |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
# Get information from environment variables |
| 575 |
|
| 576 |
sub getenv { |
| 577 |
|
| 578 |
$VERBOSE ||= gen("IM_VERBOSE"); |
| 579 |
|
| 580 |
print "Environment config:\n" if $VERBOSE; |
| 581 |
|
| 582 |
($INCPATH, |
| 583 |
$LIBPATH, |
| 584 |
$NOLOG, |
| 585 |
$DEBUG_MALLOC, |
| 586 |
$MANUAL, |
| 587 |
$CFLAGS, |
| 588 |
$LFLAGS, |
| 589 |
$DFLAGS) = map { gen $_ } qw(IM_INCPATH |
| 590 |
IM_LIBPATH |
| 591 |
IM_NOLOG |
| 592 |
IM_DEBUG_MALLOC |
| 593 |
IM_MANUAL |
| 594 |
IM_CFLAGS |
| 595 |
IM_LFLAGS |
| 596 |
IM_DFLAGS); |
| 597 |
} |
| 598 |
|
| 599 |
# populate the environment so that sub-modules get the same info |
| 600 |
sub setenv { |
| 601 |
$ENV{IM_VERBOSE} = 1 if $VERBOSE; |
| 602 |
$ENV{IM_INCPATH} = join $Config{path_sep}, @incpaths if @incpaths; |
| 603 |
$ENV{IM_LIBPATH} = join $Config{path_sep}, @libpaths if @libpaths; |
| 604 |
} |
| 605 |
|
| 606 |
sub make_imconfig { |
| 607 |
my ($defines) = @_; |
| 608 |
|
| 609 |
open my $config, "> imconfig.h" |
| 610 |
or die "Cannot create imconfig.h: $!\n"; |
| 611 |
print $config <<EOS; |
| 612 |
/* This file is automatically generated by Makefile.PL. |
| 613 |
Don't edit this file, since any changes will be lost */ |
| 614 |
|
| 615 |
#ifndef IMAGER_IMCONFIG_H |
| 616 |
#define IMAGER_IMCONFIG_H |
| 617 |
|
| 618 |
#ifdef __cplusplus |
| 619 |
extern "C" { |
| 620 |
#endif |
| 621 |
|
| 622 |
EOS |
| 623 |
for my $define (@$defines) { |
| 624 |
if ($define->[2]) { |
| 625 |
print $config "\n/*\n $define->[2]\n*/\n\n"; |
| 626 |
} |
| 627 |
print $config "#define $define->[0] $define->[1]\n"; |
| 628 |
} |
| 629 |
if ($Config{gccversion} && $Config{gccversion} =~ /^([0-9]+)/ && $1 > 3) { |
| 630 |
print $config <<EOS; |
| 631 |
/* |
| 632 |
|
| 633 |
Compiler supports the GCC __attribute__((format...)) syntax. |
| 634 |
|
| 635 |
*/ |
| 636 |
|
| 637 |
#define IMAGER_FORMAT_ATTR 1 |
| 638 |
|
| 639 |
EOS |
| 640 |
} |
| 641 |
|
| 642 |
if ($Config{d_snprintf}) { |
| 643 |
print $config <<EOS; |
| 644 |
/* We can use snprintf() */ |
| 645 |
#define IMAGER_SNPRINTF 1 |
| 646 |
|
| 647 |
EOS |
| 648 |
} |
| 649 |
|
| 650 |
if ($Config{d_vsnprintf}) { |
| 651 |
print $config <<EOS; |
| 652 |
/* We can use vsnprintf() */ |
| 653 |
#define IMAGER_VSNPRINTF 1 |
| 654 |
|
| 655 |
EOS |
| 656 |
} |
| 657 |
|
| 658 |
print $config <<EOS; |
| 659 |
/* |
| 660 |
Type and format code for formatted output as with printf. |
| 661 |
|
| 662 |
This is intended for formatting i_img_dim values. |
| 663 |
*/ |
| 664 |
typedef $Config{ivtype} i_dim_format_t; |
| 665 |
#define i_DF $Config{ivdformat} |
| 666 |
EOS |
| 667 |
|
| 668 |
if ($Config{d_static_inline}) { |
| 669 |
print $config "#define IMAGER_STATIC_INLINE $Config{perl_static_inline}\n"; |
| 670 |
} |
| 671 |
else { |
| 672 |
print $config "#define IMAGER_STATIC_INLINE static\n"; |
| 673 |
} |
| 674 |
print $config <<'EOS'; |
| 675 |
|
| 676 |
#ifdef __cplusplus |
| 677 |
} |
| 678 |
#endif |
| 679 |
|
| 680 |
#endif |
| 681 |
EOS |
| 682 |
close $config; |
| 683 |
} |
| 684 |
|
| 685 |
sub usage { |
| 686 |
print STDERR <<EOS; |
| 687 |
Usage: $0 [--enable feature1,feature2,...] [other options] |
| 688 |
$0 [--disable feature1,feature2,...] [other options] |
| 689 |
$0 --help |
| 690 |
Possible feature names are: |
| 691 |
T1-fonts |
| 692 |
Other options: |
| 693 |
--verbose | -v |
| 694 |
Verbose library probing (or set IM_VERBOSE in the environment) |
| 695 |
--nolog |
| 696 |
Disable logging (or set IM_NOLOG in the environment) |
| 697 |
--incpath dir |
| 698 |
Add to the include search path |
| 699 |
--libpath dir |
| 700 |
Add to the library search path |
| 701 |
--coverage |
| 702 |
Build for coverage testing. |
| 703 |
--assert |
| 704 |
Build with assertions active. |
| 705 |
EOS |
| 706 |
exit 1; |
| 707 |
|
| 708 |
} |
| 709 |
|
| 710 |
# generate the PM MM argument |
| 711 |
# I'd prefer to modify the public version, but there doesn't seem to be |
| 712 |
# a public API to do that |
| 713 |
sub gen_PM { |
| 714 |
my %pm; |
| 715 |
my $instbase = '$(INST_LIBDIR)'; |
| 716 |
|
| 717 |
# first the basics, .pm and .pod files |
| 718 |
$pm{"Imager.pm"} = "$instbase/Imager.pm"; |
| 719 |
|
| 720 |
my $mani = maniread(); |
| 721 |
|
| 722 |
for my $filename (keys %$mani) { |
| 723 |
if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) { |
| 724 |
(my $work = $filename) =~ s/^lib//; |
| 725 |
$pm{$filename} = $instbase . $work; |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
# need the typemap |
| 730 |
$pm{typemap} = $instbase . '/Imager/typemap'; |
| 731 |
|
| 732 |
# and the core headers |
| 733 |
for my $filename (keys %$mani) { |
| 734 |
if ($filename =~ /^\w+\.h$/) { |
| 735 |
$pm{$filename} = $instbase . '/Imager/include/' . $filename; |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
# and the generated header |
| 740 |
$pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h'; |
| 741 |
|
| 742 |
\%pm; |
| 743 |
} |
| 744 |
|
| 745 |
my $home; |
| 746 |
sub _tilde_expand { |
| 747 |
my ($path) = @_; |
| 748 |
|
| 749 |
if ($path =~ m!^~[/\\]!) { |
| 750 |
defined $home or $home = $ENV{HOME}; |
| 751 |
if (!defined $home && $^O eq 'MSWin32' |
| 752 |
&& defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) { |
| 753 |
$home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH}; |
| 754 |
} |
| 755 |
unless (defined $home) { |
| 756 |
$home = eval { (getpwuid($<))[7] }; |
| 757 |
} |
| 758 |
defined $home or die "You supplied $path, but I can't find your home directory\n"; |
| 759 |
$path =~ s/^~//; |
| 760 |
$path = File::Spec->catdir($home, $path); |
| 761 |
} |
| 762 |
|
| 763 |
$path; |
| 764 |
} |
| 765 |
|
| 766 |
sub _ft1_test_code { |
| 767 |
return <<'CODE'; |
| 768 |
TT_Engine engine; |
| 769 |
TT_Error error; |
| 770 |
|
| 771 |
error = TT_Init_FreeType(&engine); |
| 772 |
if (error) { |
| 773 |
printf("FT1: Could not initialize engine\n"); |
| 774 |
exit(1); |
| 775 |
} |
| 776 |
|
| 777 |
return 0; |
| 778 |
CODE |
| 779 |
} |
| 780 |
|
| 781 |
sub map_bundled { |
| 782 |
my (@names) = @_; |
| 783 |
|
| 784 |
@names = map { split /,/ } @names; |
| 785 |
|
| 786 |
my @outnames; |
| 787 |
for my $name (@names) { |
| 788 |
push @outnames, $name; |
| 789 |
push @outnames, $bundled_names{$name} |
| 790 |
if $bundled_names{$name}; |
| 791 |
} |
| 792 |
|
| 793 |
@outnames; |
| 794 |
} |
| 795 |
|
| 796 |
1; |