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