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