update MANIFEST for missing files
[imager.git] / Makefile.PL
CommitLineData
ea9e6c3f 1#!perl -w
714cf158 2use strict;
02d1d628
AMH
3use ExtUtils::MakeMaker;
4use Cwd;
5use Config;
07ea6c21 6use File::Spec;
37959076 7use Getopt::Long;
92bda632 8use ExtUtils::Manifest qw(maniread);
10b85929 9use ExtUtils::Liblist;
714cf158 10use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS);
812ae05c
TC
11use lib 'inc';
12use Devel::CheckLib;
02d1d628 13
1d7e3124
TC
14# EU::MM runs Makefile.PL all in the same process, so sub-modules will
15# see this
16our $BUILDING_IMAGER = 1;
17
d97c8dbd
TC
18# used to display a summary after we've probed the world
19our %IMAGER_LIBS;
20
02d1d628
AMH
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
812ae05c
TC
37my $KEEP_FILES = $ENV{IMAGER_KEEP_FILES};
38
855c5808
TC
39getenv(); # get environment variables
40
714cf158
TC
41my $lext=$Config{'so'}; # Get extensions of libraries
42my $aext=$Config{'_a'};
43
44my $help; # display help if set
45my @enable; # list of drivers to enable
46my @disable; # or list of drivers to disable
47my @incpaths; # places to look for headers
48my @libpaths; # places to look for libraries
1ef586b1 49my $coverage; # build for coverage testing
b3afeed5 50my $assert; # build with assertions
31a13473 51my $trace_context; # trace context management to stderr
37959076
TC
52GetOptions("help" => \$help,
53 "enable=s" => \@enable,
54 "disable=s" => \@disable,
55 "incpath=s", \@incpaths,
56 "libpath=s" => \@libpaths,
274cd32b 57 "verbose|v" => \$VERBOSE,
f7450478 58 "nolog" => \$NOLOG,
b3afeed5 59 'coverage' => \$coverage,
31a13473
TC
60 "assert|a" => \$assert,
61 "tracecontext" => \$trace_context);
b3afeed5 62
1d7e3124
TC
63setenv();
64
b3afeed5
TC
65if ($ENV{AUTOMATED_TESTING}) {
66 $assert = 1;
67}
855c5808
TC
68
69if ($VERBOSE) {
70 print "Verbose mode\n";
71 require Data::Dumper;
72 import Data::Dumper qw(Dumper);
73}
37959076
TC
74
75if ($help) {
76 usage();
77}
78
f7450478
TC
79my @defines;
80
274cd32b
TC
81if ($NOLOG) { print "Logging not compiled into module\n"; }
82else {
83 push @defines, [ IMAGER_LOG => 1, "Logging system" ];
84}
85
b3afeed5
TC
86if ($assert) {
87 push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ];
88}
89
274cd32b
TC
90if ($DEBUG_MALLOC) {
91 push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
92 print "Malloc debugging enabled\n";
93}
94
37959076
TC
95if (@enable && @disable) {
96 print STDERR "Only --enable or --disable can be used, not both, try --help\n";
97 exit 1;
98}
02d1d628 99
714cf158
TC
100my %definc;
101my %deflib;
102my @incs; # all the places to look for headers
103my @libs; # all the places to look for libraries
104
02d1d628
AMH
105init(); # initialize global data
106pathcheck(); # Check if directories exist
107
37959076
TC
108if (exists $ENV{IM_ENABLE}) {
109 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
110 for my $key (keys %formats) {
111 delete $formats{$key} unless $en{$key};
112 }
113}
114if (@enable) {
115 my %en = map { $_ => 1 } map { split /,/ } @enable;
116 for my $key (keys %formats) {
117 delete $formats{$key} unless $en{$key};
118 }
119}
120elsif (@disable) {
121 delete @formats{map { split /,/ } @disable};
122}
123
02d1d628
AMH
124# Pick what libraries are used
125if ($MANUAL) {
126 manual();
127} else {
128 automatic();
02d1d628
AMH
129}
130
07ea6c21 131my $lib_cflags = '';
a8395b42 132my $lib_lflags = '';
80c15fc7
TC
133my $F_LIBS = '';
134my $F_OBJECT = '';
714cf158 135for my $frmkey (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) {
e11d297f
TC
136 my $frm = $formats{$frmkey};
137 push @defines, [ $frm->{def}, 1, "$frmkey available" ];
02d1d628 138 $F_OBJECT .= ' ' .$frm->{objfiles};
714cf158
TC
139 if ($frm->{cflags}) {
140 $lib_cflags .= ' ' .$frm->{cflags};
141 ++$definc{$_} for map { /^-I(.*)$/ ? ($1) : () }
142 grep /^-I./, split ' ', $frm->{cflags};
143 }
a8395b42
TC
144 if ($frm->{lflags}) {
145 $lib_lflags .= ' ' . $frm->{lflags};
146 }
147 else {
148 $F_LIBS .= ' ' .$frm->{libfiles};
149 }
150
02d1d628 151}
714cf158 152
714cf158
TC
153my $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
154 grep !$definc{$_}, @incs;
155$F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_,
156 grep !$deflib{$_}++, @libs) . $F_LIBS;
02d1d628 157
714cf158
TC
158my $OSLIBS = '';
159my $OSDEF = "-DOS_$^O";
02d1d628
AMH
160
161if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
162if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
163
74315ca9 164my @objs = qw(Imager.o context.o draw.o polygon.o image.o io.o iolayer.o
d03fd5a4 165 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o combine.o
714cf158
TC
166 filters.o dynaload.o stackmach.o datatypes.o
167 regmach.o trans2.o quant.o error.o convert.o
a2f9a61c 168 map.o tags.o palimg.o maskimg.o img8.o img16.o rotate.o
d5477d3d 169 bmp.o tga.o color.o fills.o imgdouble.o limits.o hlines.o
e41cfe8f 170 imext.o scale.o rubthru.o render.o paste.o compose.o flip.o);
92bda632 171
d63caaff
TC
172my @typemaps = qw(typemap.local typemap);
173if ($] < 5.008) {
174 unshift @typemaps, "typemap.oldperl";
175}
176
31a13473
TC
177if ($trace_context) {
178 $CFLAGS .= " -DIMAGER_TRACE_CONTEXT";
179}
180
954ac5d1
TC
181my %opts=
182 (
183 'NAME' => 'Imager',
184 'VERSION_FROM' => 'Imager.pm',
185 'LIBS' => "$LFLAGS -lm $lib_lflags $OSLIBS $F_LIBS",
186 'DEFINE' => "$OSDEF $CFLAGS",
187 'INC' => "$lib_cflags $DFLAGS $F_INC",
188 'OBJECT' => join(' ', @objs, $F_OBJECT),
189 clean => { FILES=>'testout rubthru.c scale.c conv.c filters.c gaussian.c render.c rubthru.c' },
190 PM => gen_PM(),
191 PREREQ_PM =>
192 {
193 'Test::More' => 0.47,
194 'Scalar::Util' => 1.00,
a5919365 195 'XSLoader' => 0,
954ac5d1 196 },
d63caaff 197 TYPEMAPS => \@typemaps,
954ac5d1 198 );
02d1d628 199
1ef586b1
TC
200if ($coverage) {
201 if ($Config{gccversion}) {
6d5c85a2
TC
202 push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs -g';
203 $opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' };
1ef586b1
TC
204 }
205 else {
206 die "Don't know the coverage C flags for your compiler\n";
207 }
208}
209
c52cbef2
TC
210# eval to prevent warnings about versions with _ in them
211my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;
212if ($MM_ver > 6.06) {
5b480b14 213 $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>, Arnar M. Hrafnkelsson';
ca508100
TC
214 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
215}
f45b774f
TC
216
217if ($MM_ver >= 6.46) {
218 $opts{META_MERGE} =
219 {
220 recommends =>
221 {
222 "Parse::RecDescent" => 0
223 },
224 license => "perl",
225 dynamic_config => 1,
43452432
TC
226 no_index =>
227 {
228 directory =>
229 [
230 "PNG",
ec6d8908 231 "GIF",
797a9f9c
TC
232 "TIFF",
233 "JPEG",
bd7c1b36 234 "W32",
d7ca2089 235 "FT2",
85702fbd 236 "T1",
43452432
TC
237 ],
238 },
239 resources =>
240 {
241 homepage => "http://imager.perl.org/",
4989229f
TC
242 repository => "git://git.imager.perl.org/imager.git",
243 bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager",
43452432 244 },
f45b774f 245 };
135d30e3 246}
ca508100 247
e11d297f
TC
248make_imconfig(\@defines);
249
02d1d628
AMH
250if ($VERBOSE) { print Dumper(\%opts); }
251mkdir('testout',0777); # since we cannot include it in the archive.
135d30e3 252
812ae05c
TC
253-d "probe" and rmdir "probe";
254
02d1d628 255WriteMakefile(%opts);
4dce694d 256
d97c8dbd
TC
257my @good;
258my @bad;
259for my $name (sort { lc $a cmp lc $b } keys %IMAGER_LIBS) {
260 if ($IMAGER_LIBS{$name}) {
261 push @good, $name;
262 }
263 else {
264 push @bad, $name;
265 }
266}
267
268print "\n";
269print "Libraries found:\n" if @good;
270print " $_\n" for @good;
271print "Libraries *not* found:\n" if @bad;
272print " $_\n" for @bad;
273
02d1d628
AMH
274exit;
275
276
277sub MY::postamble {
5a7e62b6
TC
278 my $self = shift;
279 my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)';
fe415ad2
TC
280 my $mani = maniread;
281
282 my @ims = grep /\.im$/, keys %$mani;
02d1d628 283'
faa9b3e7 284dyntest.$(MYEXTLIB) : dynfilt/Makefile
02d1d628
AMH
285 cd dynfilt && $(MAKE) $(PASTHRU)
286
287lib/Imager/Regops.pm : regmach.h regops.perl
288 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
e11d297f 289
92bda632 290imconfig.h : Makefile.PL
e11d297f
TC
291 $(ECHO) "imconfig.h out-of-date with respect to $?"
292 $(PERLRUN) Makefile.PL
293 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
5a7e62b6 294'.qq!
6cfee9d1 295lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl
2a69ed21 296 $perl apidocs.perl lib/Imager/APIRef.pod
92bda632 297
fe415ad2
TC
298!.join('', map _im_rule($perl, $_), @ims)
299
300}
301
302sub _im_rule {
303 my ($perl, $im) = @_;
304
305 (my $c = $im) =~ s/\.im$/.c/;
306 return <<MAKE;
307
9b1ec2b8
TC
308$c: $im lib/Imager/Preprocess.pm
309 $perl -Ilib -MImager::Preprocess -epreprocess $im $c
fe415ad2
TC
310
311MAKE
02d1d628 312
55932d2a
TC
313}
314
02d1d628
AMH
315# manual configuration of helper libraries
316
317sub manual {
318 print <<EOF;
319
320 Please answer the following questions about
321 which formats are avaliable on your computer
322
323press <return> to continue
324EOF
325
326 <STDIN>; # eat one return
327
2646b26c 328 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
02d1d628
AMH
329 SWX:
330 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
331 print "Enable $frm support: ";
714cf158 332 my $gz = <STDIN>;
02d1d628
AMH
333 chomp($gz);
334 if ($gz =~ m/^(y|yes|n|no)/i) {
335 $gz=substr(lc($gz),0,1);
336 if ($gz eq 'n') {
337 delete $formats{$frm};
338 }
339 } else { goto SWX; }
340 }
341}
342
343
344# automatic configuration of helper libraries
345
346sub automatic {
714cf158
TC
347 print "Automatic probing:\n" if $VERBOSE;
348 for my $frm (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) {
02d1d628
AMH
349 delete $formats{$frm} if !checkformat($frm);
350 }
351}
352
c6e870ae
TC
353sub grep_directory {
354 my($path, $chk)=@_;
02d1d628
AMH
355
356# print "checking path $path\n";
357 if ( !opendir(DH,$path) ) {
358 warn "Cannot open dir $path: $!\n";
359 return;
360 }
361 my @l=grep { $chk->($_) } readdir(DH);
362 # print @l;
363 close(DH);
364 return map $path, @l;
365}
366
812ae05c
TC
367sub _probe_default {
368 my ($format, $frm) = @_;
07ea6c21 369
c6e870ae
TC
370 my $lib_check=$formats{$frm}{'libcheck'};
371 my $inc_check=$formats{$frm}{'inccheck'};
02d1d628 372
c6e870ae
TC
373 if ($lib_check) {
374 my @l;
375 for my $lp (@libs) {
376 push(@l, grep_directory($lp,$lib_check));
377 }
378
379 my @i;
380 for my $ip (@incs) {
381 push(@i, $ip) if $inc_check->($ip,$frm);
382 }
383
384 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
385 $formats{$frm}{incdir} = \@i;
386 $formats{$frm}{libdir} = \@l;
387 return 1 if scalar(@i && @l);
02d1d628 388 }
c6e870ae
TC
389 else {
390 printf("%10s: not available\n", $frm);
02d1d628
AMH
391 }
392
c6e870ae 393 return 0;
02d1d628
AMH
394}
395
812ae05c
TC
396sub checkformat {
397 my $frm=shift;
398
399 print " checkformat($frm)\n" if $VERBOSE;
400
401 my $format = $formats{$frm};
402
403 my @probes;
404 if (my $code = $format->{'code'}) {
405 if (ref $code eq 'ARRAY') {
406 push @probes, @$code;
407 }
408 else {
409 push @probes, $code;
410 }
411 }
412 push @probes, \&_probe_default;
413
414 print " Calling probe function\n" if $VERBOSE;
415 my $found;
416 for my $func (@probes) {
417 if ($func->($format, $frm)) {
418 ++$found;
419 last;
420 }
421 }
422
423 $found or return;
424
425 if ($format->{postcheck}) {
426 print " Calling postcheck function\n" if $VERBOSE;
427 $format->{postcheck}->($format, $frm)
428 or return;
429 }
430
431 return 1;
432}
433
02d1d628 434
02d1d628
AMH
435sub pathcheck {
436 if ($VERBOSE) {
437 print "pathcheck\n";
438 print " Include paths:\n";
439 for (@incs) { print $_,"\n"; }
440 }
3a6bb91b 441 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
02d1d628
AMH
442
443 if ($VERBOSE) {
444 print "\nLibrary paths:\n";
855c5808 445 for (@libs) { print $_,"\n"; }
02d1d628 446 }
3a6bb91b 447 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
02d1d628
AMH
448 print "\ndone.\n";
449}
450
451
452# Format data initialization
453
454# format definition is:
455# defines needed
456# default include path
457# files needed for include (boolean perl code)
458# default lib path
459# libs needed
460# files needed for link (boolean perl code)
461# object files needed for the format
462
463
464sub init {
465
714cf158
TC
466 my @definc = qw(/usr/include);
467 @definc{@definc}=(1) x @definc;
d8e0c3ba
TC
468 @incs=
469 (
470 split(/\Q$Config{path_sep}/, $INCPATH),
471 map _tilde_expand($_), map { split /\Q$Config{path_sep}/ } @incpaths
472 );
2646b26c 473 if ($Config{locincpth}) {
6552acfe 474 push @incs, grep -d, split ' ', $Config{locincpth};
2646b26c 475 }
88a763e2
TC
476 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
477 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
2646b26c 478 }
16cf4610
TC
479 if ($Config{incpath}) {
480 push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath};
481 }
6552acfe 482 push @incs, grep -d,
2646b26c
TC
483 qw(/sw/include
484 /usr/include/freetype2
485 /usr/local/include/freetype2
486 /usr/local/include/freetype1/freetype
37959076 487 /usr/include /usr/local/include /usr/include/freetype
2646b26c 488 /usr/local/include/freetype);
714cf158
TC
489 if ($Config{ccflags}) {
490 my @hidden = map { /^-I(.*)$/ ? ($1) : () } split ' ', $Config{ccflags};
491 push @incs, @hidden;
492 @definc{@hidden} = (1) x @hidden;
493 }
2646b26c 494
37959076 495 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
d8e0c3ba 496 map _tilde_expand($_), map { split /\Q$Config{path_sep}/} @libpaths );
2646b26c 497 if ($Config{loclibpth}) {
6552acfe 498 push @libs, grep -d, split ' ', $Config{loclibpth};
2646b26c 499 }
714cf158 500
6552acfe 501 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
714cf158 502 push @libs, grep -d, split / /, $Config{libspath} if $Config{libspath};
2646b26c 503 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
88a763e2
TC
504 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
505 }
faa9b3e7
TC
506 if ($^O eq 'cygwin') {
507 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
274cd32b 508 push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api';
faa9b3e7 509 }
714cf158
TC
510 if ($Config{ldflags}) {
511 # some builds of perl put -Ldir into ldflags without putting it in
512 # loclibpth, let's extract them
513 my @hidden = grep -d, map { /^-L(.*)$/ ? ($1) : () }
514 split ' ', $Config{ldflags};
515 push @libs, @hidden;
516 # don't mark them as seen - EU::MM will remove any libraries
517 # it can't find and it doesn't look for -L in ldflags
518 #@deflib{@hidden} = @hidden;
519 }
ed28c9cc 520 push @libs, grep -d, qw(/usr/local/lib);
2646b26c 521
f8e9bc07
TC
522 $formats{'TT-fonts'}=
523 {
524 order=>'31',
525 def=>'HAVE_LIBTT',
526 inccheck=>sub { -e catfile($_[0], 'freetype.h')
527 && !-e catfile($_[0], 'fterrors.h') },
528 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
529 libfiles=>'-lttf',
d03fd5a4 530 objfiles=>'',
714cf158 531 code => \&freetype1_probe,
f8e9bc07
TC
532 docs=>q{
533Truetype fonts are scalable fonts. They can include
534kerning and hinting information and generally yield good
535visual quality esp on low resultions. The freetype library is
536used to rasterize for us. The only drawback is that there
537are alot of badly designed fonts out there.}
02d1d628
AMH
538 };
539 # Make fix indent
540 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
541}
542
543
544
545sub gen {
546 my $V = $ENV{$_[0]};
547 defined($V) ? $V : "";
548}
549
550
551# Get information from environment variables
552
553sub getenv {
554
555 ($VERBOSE,
556 $INCPATH,
557 $LIBPATH,
558 $NOLOG,
559 $DEBUG_MALLOC,
560 $MANUAL,
561 $CFLAGS,
562 $LFLAGS,
563 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
564 IM_INCPATH
565 IM_LIBPATH
566 IM_NOLOG
567 IM_DEBUG_MALLOC
568 IM_MANUAL
569 IM_CFLAGS
570 IM_LFLAGS
571 IM_DFLAGS);
572
02d1d628 573}
07ea6c21 574
1d7e3124
TC
575# populate the environment so that sub-modules get the same info
576sub setenv {
577 $ENV{IM_VERBOSE} = 1 if $VERBOSE;
578 $ENV{IM_INCPATH} = join $Config{path_sep}, @incpaths if @incpaths;
579 $ENV{IM_LIBPATH} = join $Config{path_sep}, @libpaths if @libpaths;
580}
581
e11d297f
TC
582sub make_imconfig {
583 my ($defines) = @_;
584
585 open CONFIG, "> imconfig.h"
586 or die "Cannot create imconfig.h: $!\n";
587 print CONFIG <<EOS;
588/* This file is automatically generated by Makefile.PL.
589 Don't edit this file, since any changes will be lost */
590
591#ifndef IMAGER_IMCONFIG_H
592#define IMAGER_IMCONFIG_H
593EOS
594 for my $define (@$defines) {
595 if ($define->[2]) {
596 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
597 }
598 print CONFIG "#define $define->[0] $define->[1]\n";
599 }
53ea6b6f 600 if ($Config{gccversion} && $Config{gccversion} =~ /^([0-9]+)/ && $1 > 3) {
8d14daab
TC
601 print CONFIG <<EOS;
602/*
603
604Compiler supports the GCC __attribute__((format...)) syntax.
605
606*/
607
608#define IMAGER_FORMAT_ATTR 1
53ea6b6f 609
86c8d19a
TC
610EOS
611 }
612
613 if ($Config{d_snprintf}) {
614 print CONFIG <<EOS;
615/* We can use snprintf() */
616#define IMAGER_SNPRINTF 1
617
618EOS
619 }
620
621 if ($Config{d_vsnprintf}) {
622 print CONFIG <<EOS;
623/* We can use vsnprintf() */
624#define IMAGER_VSNPRINTF 1
625
8d14daab
TC
626EOS
627 }
628
629 print CONFIG <<EOS;
630/*
631 Type and format code for formatted output as with printf.
632
633 This is intended for formatting i_img_dim values.
634*/
635typedef $Config{ivtype} i_dim_format_t;
636#define i_DF $Config{ivdformat}
637EOS
638
e11d297f
TC
639 print CONFIG "\n#endif\n";
640 close CONFIG;
641}
642
714cf158
TC
643# probes for freetype1 by scanning @incs for the includes and
644# @libs for the libs. This is done separately because freetype's headers
645# are stored in a freetype or freetype1 directory under PREFIX/include.
646#
647# we could find the files with the existing mechanism, but it won't set
648# -I flags correctly.
649#
650# This could be extended to freetype2 too, but freetype-config catches
651# that
652sub freetype1_probe {
653 my ($frm, $frmkey) = @_;
654
655 my $found_inc;
656 INCS:
657 for my $inc (@incs) {
658 for my $subdir (qw/freetype freetype1/) {
659 my $path = File::Spec->catfile($inc, $subdir, 'freetype.h');
660 -e $path or next;
661 $path = File::Spec->catfile($inc, $subdir, 'fterrors.h');
662 -e $path and next;
663
664 $found_inc = File::Spec->catdir($inc, $subdir);
665 last INCS;
666 }
667 }
668
669 my $found_lib;
670 LIBS:
671 for my $lib (@libs) {
672 my $a_path = File::Spec->catfile($lib, "libttf$aext");
673 my $l_path = File::Spec->catfile($lib, "libttf.$lext");
674 if (-e $a_path || -e $l_path) {
675 $found_lib = $lib;
676 last LIBS;
677 }
678 }
679
89d37182 680 return unless $found_inc && $found_lib;
714cf158
TC
681 printf("%10s: includes %s - libraries %s\n", $frmkey,
682 ($found_inc ? 'found' : 'not found'),
683 ($found_lib ? 'found' : 'not found'));
714cf158
TC
684
685 $frm->{cflags} = "-I$found_inc";
686 $frm->{libfiles} = "-lttf";
687
688 return 1;
689}
690
07ea6c21
TC
691sub catfile {
692 return File::Spec->catfile(@_);
693}
694
37959076
TC
695sub usage {
696 print STDERR <<EOS;
274cd32b
TC
697Usage: $0 [--enable feature1,feature2,...] [other options]
698 $0 [--disable feature1,feature2,...] [other options]
37959076
TC
699 $0 --help
700Possible feature names are:
85702fbd 701 T1-fonts
274cd32b
TC
702Other options:
703 --verbose | -v
704 Verbose library probing (or set IM_VERBOSE in the environment)
705 --nolog
706 Disable logging (or set IM_NOLOG in the environment)
707 --incpath dir
708 Add to the include search path
709 --libpath dir
710 Add to the library search path
35a15603
TC
711 --coverage
712 Build for coverage testing.
713 --assert
714 Build with assertions active.
37959076
TC
715EOS
716 exit 1;
717
718}
92bda632
TC
719
720# generate the PM MM argument
721# I'd prefer to modify the public version, but there doesn't seem to be
722# a public API to do that
723sub gen_PM {
724 my %pm;
725 my $instbase = '$(INST_LIBDIR)';
726
727 # first the basics, .pm and .pod files
728 $pm{"Imager.pm"} = "$instbase/Imager.pm";
729
730 my $mani = maniread();
731
732 for my $filename (keys %$mani) {
733 if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) {
734 (my $work = $filename) =~ s/^lib//;
735 $pm{$filename} = $instbase . $work;
736 }
737 }
738
739 # need the typemap
740 $pm{typemap} = $instbase . '/Imager/typemap';
741
742 # and the core headers
743 for my $filename (keys %$mani) {
744 if ($filename =~ /^\w+\.h$/) {
745 $pm{$filename} = $instbase . '/Imager/include/' . $filename;
746 }
747 }
748
749 # and the generated header
750 $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h';
751
752 \%pm;
753}
135d30e3 754
d8e0c3ba
TC
755my $home;
756sub _tilde_expand {
757 my ($path) = @_;
758
759 if ($path =~ m!^~[/\\]!) {
760 defined $home or $home = $ENV{HOME};
761 if (!defined $home && $^O eq 'MSWin32'
762 && defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) {
763 $home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH};
764 }
765 unless (defined $home) {
766 $home = eval { (getpwuid($<))[7] };
767 }
768 defined $home or die "You supplied $path, but I can't find your home directory\n";
769 $path =~ s/^~//;
770 $path = File::Spec->catdir($home, $path);
771 }
772
773 $path;
774}
775
678a9a65 7761;