- extra concept index entries
[imager.git] / Makefile.PL
CommitLineData
ea9e6c3f 1#!perl -w
02d1d628
AMH
2use ExtUtils::MakeMaker;
3use Cwd;
4use Config;
07ea6c21 5use File::Spec;
37959076 6use Getopt::Long;
02d1d628 7
02d1d628
AMH
8#
9# IM_INCPATH colon seperated list of paths to extra include paths
10# IM_LIBPATH colon seperated list of paths to extra library paths
11#
12# IM_VERBOSE turns on verbose mode for the library finding and such
13# IM_MANUAL to manually select which libraries are used and which not
14# IM_ENABLE to programmatically select which libraries are used
15# and which are not
16# IM_NOLOG if true logging will not be compiled into the module
17# IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
18# do not use IM_DEBUG_MALLOC in production - this slows
19# everything down by alot
20# IM_CFLAGS Extra flags to pass to the compiler
21# IM_LFLAGS Extra flags to pass to the linker
22# IM_DFLAGS Extra flags to pass to the preprocessor
f4dbac50 23# IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
02d1d628 24
855c5808
TC
25getenv(); # get environment variables
26
37959076
TC
27my $help;
28my @enable;
29my @disable;
30my @incpaths;
31my @libpaths;
32my $noprobe;
f7450478 33my $noexif;
37959076
TC
34GetOptions("help" => \$help,
35 "enable=s" => \@enable,
36 "disable=s" => \@disable,
37 "incpath=s", \@incpaths,
38 "libpath=s" => \@libpaths,
855c5808 39 "noprobe" => \$noprobe,
274cd32b 40 "verbose|v" => \$VERBOSE,
f7450478
TC
41 "nolog" => \$NOLOG,
42 "noexif" => \$noexif);
855c5808
TC
43
44if ($VERBOSE) {
45 print "Verbose mode\n";
46 require Data::Dumper;
47 import Data::Dumper qw(Dumper);
48}
37959076
TC
49
50if ($help) {
51 usage();
52}
53
f7450478
TC
54my @defines;
55
274cd32b
TC
56if ($NOLOG) { print "Logging not compiled into module\n"; }
57else {
58 push @defines, [ IMAGER_LOG => 1, "Logging system" ];
59}
60
61if ($DEBUG_MALLOC) {
62 push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
63 print "Malloc debugging enabled\n";
64}
65
37959076
TC
66if (@enable && @disable) {
67 print STDERR "Only --enable or --disable can be used, not both, try --help\n";
68 exit 1;
69}
02d1d628 70
02d1d628
AMH
71init(); # initialize global data
72pathcheck(); # Check if directories exist
73
37959076
TC
74if (exists $ENV{IM_ENABLE}) {
75 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
76 for my $key (keys %formats) {
77 delete $formats{$key} unless $en{$key};
78 }
79}
80if (@enable) {
81 my %en = map { $_ => 1 } map { split /,/ } @enable;
82 for my $key (keys %formats) {
83 delete $formats{$key} unless $en{$key};
84 }
85}
86elsif (@disable) {
87 delete @formats{map { split /,/ } @disable};
88}
89
02d1d628
AMH
90# Pick what libraries are used
91if ($MANUAL) {
92 manual();
93} else {
94 automatic();
02d1d628
AMH
95}
96
97# Make sure there isn't a clash between the gif libraries.
98gifcheck();
99
07ea6c21 100my $lib_cflags = '';
80c15fc7
TC
101my $F_LIBS = '';
102my $F_OBJECT = '';
e11d297f
TC
103for my $frmkey (keys %formats) {
104 my $frm = $formats{$frmkey};
105 push @defines, [ $frm->{def}, 1, "$frmkey available" ];
02d1d628
AMH
106 $F_LIBS .= ' ' .$frm->{libfiles};
107 $F_OBJECT .= ' ' .$frm->{objfiles};
07ea6c21 108 $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags};
02d1d628 109}
f7450478
TC
110unless ($noexif) {
111 print "EXIF support enabled\n";
112 push @defines, [ 'IMEXIF_ENABLE', 1, "Enable experimental EXIF support" ];
113 $F_OBJECT .= ' imexif.o';
114}
02d1d628 115
ea9e6c3f
TC
116$F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
117 grep !exists $definc{$_}, @incs;
118$F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS;
02d1d628
AMH
119
120$OSLIBS = '';
121$OSDEF = "-DOS_$^O";
122
123if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
124if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
125
9982a307
AMH
126@objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
127 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
02d1d628 128 filters.o dynaload.o stackmach.o datatypes.o
2df3535a 129 regmach.o trans2.o quant.o error.o convert.o
261f91c5 130 map.o tags.o palimg.o maskimg.o img16.o rotate.o
a8652edf 131 bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o hlines.o);
02d1d628
AMH
132
133%opts=(
134 'NAME' => 'Imager',
135 'VERSION_FROM' => 'Imager.pm',
136 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
e11d297f 137 'DEFINE' => "$OSDEF $CFLAGS",
07ea6c21 138 'INC' => "$lib_cflags $DFLAGS $F_INC",
de2b8bae 139 'OBJECT' => join(' ', @objs, $F_OBJECT),
8746dc75 140 clean => { FILES=>'testout meta.tmp' },
02d1d628
AMH
141 );
142
29316bdb
TC
143if ($ExtUtils::MakeMaker::VERSION > 6.06) {
144 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
ca508100
TC
145 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
146}
147
e11d297f
TC
148make_imconfig(\@defines);
149
02d1d628
AMH
150if ($VERBOSE) { print Dumper(\%opts); }
151mkdir('testout',0777); # since we cannot include it in the archive.
152WriteMakefile(%opts);
4dce694d 153
02d1d628
AMH
154exit;
155
156
157sub MY::postamble {
158'
faa9b3e7 159dyntest.$(MYEXTLIB) : dynfilt/Makefile
02d1d628
AMH
160 cd dynfilt && $(MAKE) $(PASTHRU)
161
162lib/Imager/Regops.pm : regmach.h regops.perl
163 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
e11d297f
TC
164
165imconfig.h: Makefile.PL
166 $(ECHO) "imconfig.h out-of-date with respect to $?"
167 $(PERLRUN) Makefile.PL
168 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
02d1d628
AMH
169';
170}
171
55932d2a
TC
172sub MY::metafile {
173 my ($self) = @_;
174
175 my $meta = <<YAML;
176--- #YAML:1.0
177name: Imager
178version: $self->{VERSION}
179version_from: $self->{VERSION_FROM}
180author: $self->{AUTHOR}
181abstract: $self->{ABSTRACT}
182installdirs: $self->{INSTALLDIRS}
183recommends:
184 Parse::RecDescent: 0
185license: perl
186dynamic_config: 1
187distribution_type: module
188generated_by: Imager version $self->{VERSION}
189YAML
24099689
TC
190 open META, "> meta.tmp" or die "Cannot create meta.tmp: $!";
191 print META $meta;
192 close META;
55932d2a 193
24099689 194 return sprintf "metafile :\n\t\$(CP) meta.tmp META.yml\n";
55932d2a
TC
195}
196
02d1d628
AMH
197# manual configuration of helper libraries
198
199sub manual {
200 print <<EOF;
201
202 Please answer the following questions about
203 which formats are avaliable on your computer
204
205press <return> to continue
206EOF
207
208 <STDIN>; # eat one return
209
2646b26c 210 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
02d1d628
AMH
211 SWX:
212 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
213 print "Enable $frm support: ";
09fd3468 214 $gz = <STDIN>;
02d1d628
AMH
215 chomp($gz);
216 if ($gz =~ m/^(y|yes|n|no)/i) {
217 $gz=substr(lc($gz),0,1);
218 if ($gz eq 'n') {
219 delete $formats{$frm};
220 }
221 } else { goto SWX; }
222 }
223}
224
225
226# automatic configuration of helper libraries
227
228sub automatic {
229 for $frm(keys %formats) {
230 delete $formats{$frm} if !checkformat($frm);
231 }
232}
233
234
235sub gifcheck {
5f5fe73e 236 if ($formats{'gif'} and $formats{'ungif'}) {
02d1d628
AMH
237 print "ungif and gif can not coexist - removing ungif support\n";
238 delete $formats{'ungif'};
239 }
5f5fe73e
AMH
240
241 RETR:
f4dbac50 242 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
5f5fe73e
AMH
243 print <<EOFF;
244
245You have libgif or libungif installed. They are both known to have
246bugs. Imager can crash or display other strange behaviour after
247reading or writing gif images. Some of the gif tests can even fail
248since they stress some parts of the buggy code.
249
f1967c11
TC
250libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
251patch to have all the bugs fixed, see README for details.
252
253Of course it's possible your operating system distributor has patched
254all of these problems and you have nothing to worry about.
0b836ff8 255
5f5fe73e
AMH
256Do you want to remove gif support? [Y/n]
257EOFF
258 my $resp = <STDIN>;
259 chomp($resp);
260 if ($resp ne "n") {
261 delete $formats{'gif'};
262 delete $formats{'ungif'};
09fd3468 263 return;
5f5fe73e
AMH
264 }
265 }
09fd3468
AMH
266
267 for my $frm (qw(gif ungif)) {
268 checkformat($frm) if ($MANUAL and $formats{$frm});
269 }
270
02d1d628
AMH
271 my @dirs;
272 for my $frm (grep $formats{$_}, qw(gif ungif)) {
273 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
274 }
275 my $minor = 0;
276 my $major = 0;
277 FILES: for my $dir (@dirs) {
278 my $h = "$dir/gif_lib.h";
279 open H, "< $h" or next;
280 while (<H>) {
281 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
282 $major = $1;
283 $minor = $2;
284 close H;
285 last FILES;
286 }
287 }
288 close H;
289 }
290
291 # we need the version in a #ifdefable form
4dce694d 292
e11d297f
TC
293 push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ];
294 push @defines, [ IM_GIFMINOR, $minor ];
02d1d628
AMH
295}
296
297
298sub gd {
299 my($path,$chk)=@_;
300
301# print "checking path $path\n";
302 if ( !opendir(DH,$path) ) {
303 warn "Cannot open dir $path: $!\n";
304 return;
305 }
306 my @l=grep { $chk->($_) } readdir(DH);
307 # print @l;
308 close(DH);
309 return map $path, @l;
310}
311
312
313sub checkformat {
314 my $frm=shift;
37959076 315
07ea6c21 316 my $code = $formats{$frm}{'code'};
37959076 317 if ($code && !$noprobe) {
07ea6c21
TC
318 return 1 if $code->($formats{$frm}, $frm);
319 }
320
02d1d628
AMH
321 my $libchk=$formats{$frm}{'libcheck'};
322 my $incchk=$formats{$frm}{'inccheck'};
323
324 my @l;
325 for my $lp (@libs) {
326 push(@l, gd($lp,$libchk));
327 }
328
329 my @i;
330 for my $ip (@incs) {
f8e9bc07 331 push(@i, $ip) if $incchk->($ip,$frm);
02d1d628
AMH
332 }
333
334 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
335 $formats{$frm}{incdir} = \@i;
336 $formats{$frm}{libdir} = \@l;
337 return scalar(@i && @l);
338}
339
340
02d1d628
AMH
341sub pathcheck {
342 if ($VERBOSE) {
343 print "pathcheck\n";
344 print " Include paths:\n";
345 for (@incs) { print $_,"\n"; }
346 }
3a6bb91b 347 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
02d1d628
AMH
348
349 if ($VERBOSE) {
350 print "\nLibrary paths:\n";
855c5808 351 for (@libs) { print $_,"\n"; }
02d1d628 352 }
3a6bb91b 353 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
02d1d628
AMH
354 print "\ndone.\n";
355}
356
357
358# Format data initialization
359
360# format definition is:
361# defines needed
362# default include path
363# files needed for include (boolean perl code)
364# default lib path
365# libs needed
366# files needed for link (boolean perl code)
367# object files needed for the format
368
369
370sub init {
371
372 @definc{'/usr/include'}=();
37959076
TC
373 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
374 map { split /\Q$Config{path_sep}/} @incpaths );
2646b26c 375 if ($Config{locincpth}) {
6552acfe 376 push @incs, grep -d, split ' ', $Config{locincpth};
2646b26c 377 }
88a763e2
TC
378 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
379 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
2646b26c 380 }
6552acfe 381 push @incs, grep -d,
2646b26c
TC
382 qw(/sw/include
383 /usr/include/freetype2
384 /usr/local/include/freetype2
385 /usr/local/include/freetype1/freetype
37959076 386 /usr/include /usr/local/include /usr/include/freetype
2646b26c
TC
387 /usr/local/include/freetype);
388
37959076
TC
389 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
390 map { split /\Q$Config{path_sep}/} @libpaths );
2646b26c 391 if ($Config{loclibpth}) {
6552acfe 392 push @libs, grep -d, split ' ', $Config{loclibpth};
2646b26c 393 }
6552acfe 394 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
2646b26c 395 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
88a763e2
TC
396 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
397 }
faa9b3e7
TC
398 if ($^O eq 'cygwin') {
399 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
274cd32b 400 push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api';
faa9b3e7 401 }
02d1d628 402
2646b26c
TC
403 my $lext=$Config{'so'}; # Get extensions of libraries
404 my $aext=$Config{'_a'};
405
02d1d628
AMH
406 $formats{'jpeg'}={
407 order=>'21',
408 def=>'HAVE_LIBJPEG',
f8e9bc07 409 inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
50ee6f9c 410 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
02d1d628
AMH
411 libfiles=>'-ljpeg',
412 objfiles=>'jpeg.o',
413 docs=>q{
414 In order to use jpeg with this module you need to have libjpeg
415 installed on your computer}
416 };
417
418 $formats{'tiff'}={
419 order=>'23',
420 def=>'HAVE_LIBTIFF',
f8e9bc07 421 inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
76c8a0a4 422 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
02d1d628
AMH
423 libfiles=>'-ltiff',
424 objfiles=>'tiff.o',
425 docs=>q{
426 In order to use tiff with this module you need to have libtiff
427 installed on your computer}
428 };
429
430 $formats{'png'}={
431 order=>'22',
432 def=>'HAVE_LIBPNG',
f8e9bc07 433 inccheck=>sub { -e catfile($_[0], 'png.h') },
88a763e2 434 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
02d1d628
AMH
435 libfiles=>'-lpng -lz',
436 objfiles=>'png.o',
437 docs=>q{
438 Png stands for Portable Network Graphics and is intended as
439 a replacement for gif on the web. It is patent free and
07ea6c21
TC
440 is recommended by the w3c, you need libpng to use these formats},
441 code => \&png_probe,
02d1d628
AMH
442 };
443
444 $formats{'gif'}={
445 order=>'20',
446 def=>'HAVE_LIBGIF',
f8e9bc07 447 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
e02451e0 448 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
02d1d628
AMH
449 libfiles=>'-lgif',
450 objfiles=>'gif.o',
451 docs=>q{
452 gif is the de facto standard for webgraphics at the moment,
453 it does have some patent problems. If you have giflib and
454 are not in violation with the unisys patent you should use
455 this instead of the 'ungif' option. Note that they cannot
456 be in use at the same time}
457 };
458
459 $formats{'ungif'}={
460 order=>'21',
461 def=>'HAVE_LIBGIF',
f8e9bc07 462 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
e02451e0 463 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
02d1d628
AMH
464 libfiles=>'-lungif',
465 objfiles=>'gif.o',
466 docs=>q{
467 gif is the de facto standard for webgraphics at the moment,
468 it does have some patent problems. If you have libungif and
469 want to create images free from LZW patented compression you
470 should use this option instead of the 'gif' option}
471 };
472
473 $formats{'T1-fonts'}={
474 order=>'30',
475 def=>'HAVE_LIBT1',
f8e9bc07 476 inccheck=>sub { -e catfile($_[0], 't1lib.h') },
faa9b3e7 477 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
02d1d628
AMH
478 libfiles=>'-lt1',
479 objfiles=>'',
480 docs=>q{
481 postscript t1 fonts are scalable fonts. They can include
482 ligatures and kerning information and generally yield good
483 visual quality. We depend on libt1 to rasterize the fonts
484 for use in images.}
485 };
486
f8e9bc07
TC
487 $formats{'TT-fonts'}=
488 {
489 order=>'31',
490 def=>'HAVE_LIBTT',
491 inccheck=>sub { -e catfile($_[0], 'freetype.h')
492 && !-e catfile($_[0], 'fterrors.h') },
493 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
494 libfiles=>'-lttf',
495 objfiles=>'',
496 docs=>q{
497Truetype fonts are scalable fonts. They can include
498kerning and hinting information and generally yield good
499visual quality esp on low resultions. The freetype library is
500used to rasterize for us. The only drawback is that there
501are alot of badly designed fonts out there.}
02d1d628 502 };
faa9b3e7
TC
503 $formats{'w32'} = {
504 order=>40,
505 def=>'HAVE_WIN32',
f8e9bc07 506 inccheck=>sub { -e catfile($_[0], 'windows.h') },
faa9b3e7
TC
507 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
508 || lc $_[0] eq 'libgdi32.a' },
509 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
510 objfiles=>'win32.o',
511 docs => <<DOCS
512Uses the Win32 GDI for rendering text.
513
514This currently only works on under normal Win32 and cygwin.
515DOCS
516 };
517 $formats{'freetype2'} = {
518 order=>'29',
519 def=>'HAVE_FT2',
f8e9bc07 520 inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
faa9b3e7
TC
521 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
522 libfiles=>'-lfreetype',
523 objfiles=>'freetyp2.o',
07ea6c21 524 docs=><<DOCS,
faa9b3e7 525Freetype 2 supports both Truetype and Type 1 fonts, both of which are
f8e9bc07 526scalable. It also supports a variety of other fonts.
faa9b3e7 527DOCS
07ea6c21 528 code => \&freetype2_probe,
faa9b3e7 529 };
f7450478 530
02d1d628
AMH
531 # Make fix indent
532 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
533}
534
535
536
537sub gen {
538 my $V = $ENV{$_[0]};
539 defined($V) ? $V : "";
540}
541
542
543# Get information from environment variables
544
545sub getenv {
546
547 ($VERBOSE,
548 $INCPATH,
549 $LIBPATH,
550 $NOLOG,
551 $DEBUG_MALLOC,
552 $MANUAL,
553 $CFLAGS,
554 $LFLAGS,
555 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
556 IM_INCPATH
557 IM_LIBPATH
558 IM_NOLOG
559 IM_DEBUG_MALLOC
560 IM_MANUAL
561 IM_CFLAGS
562 IM_LFLAGS
563 IM_DFLAGS);
564
02d1d628 565}
07ea6c21 566
e11d297f
TC
567sub make_imconfig {
568 my ($defines) = @_;
569
570 open CONFIG, "> imconfig.h"
571 or die "Cannot create imconfig.h: $!\n";
572 print CONFIG <<EOS;
573/* This file is automatically generated by Makefile.PL.
574 Don't edit this file, since any changes will be lost */
575
576#ifndef IMAGER_IMCONFIG_H
577#define IMAGER_IMCONFIG_H
578EOS
579 for my $define (@$defines) {
580 if ($define->[2]) {
581 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
582 }
583 print CONFIG "#define $define->[0] $define->[1]\n";
584 }
585 print CONFIG "\n#endif\n";
586 close CONFIG;
587}
588
dbc33d8a
TC
589# use pkg-config to probe for libraries
590# works around the junk that pkg-config dumps on FreeBSD
591sub _pkg_probe {
592 my ($pkg) = @_;
593
594 is_exe('pkg-config') or return;
595
596 my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
597
598 !system("pkg-config $pkg --exists $redir");
599}
600
07ea6c21
TC
601# probes for freetype2 by trying to run freetype-config
602sub freetype2_probe {
603 my ($frm, $frmkey) = @_;
604
605 is_exe('freetype-config') or return;
606
607 my $cflags = `freetype-config --cflags`
608 and !$? or return;
609 chomp $cflags;
610
611 $frm->{cflags} = $cflags;
612 my $lflags = `freetype-config --libs`
613 and !$? or return;
614 chomp $lflags;
615 $frm->{libfiles} = $lflags;
616
617 printf "%10s: configured via freetype-config\n", $frmkey;
618
619 return 1;
620}
621
622# probes for libpng via pkg-config
623sub png_probe {
624 my ($frm, $frmkey) = @_;
625
626 is_exe('pkg-config') or return;
627
07ea6c21
TC
628 my $config;
629 for my $check_conf (qw(libpng libpng12 libpng10)) {
dbc33d8a 630 if (_pkg_probe($check_conf)) {
07ea6c21
TC
631 $config = $check_conf;
632 last;
633 }
634 }
635 $config or return;
636
dbc33d8a
TC
637 my $cflags = `pkg-config $config --cflags`
638 and !$? or return;
639
07ea6c21
TC
640 my $lflags = `pkg-config $config --libs`
641 and !$? or return;
642
643 chomp $cflags;
644 chomp $lflags;
645 $frm->{cflags} = $cflags;
646 $frm->{libfiles} = $lflags;
647
648 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
649
650 return 1;
651}
652
653sub catfile {
654 return File::Spec->catfile(@_);
655}
656
657sub is_exe {
658 my ($name) = @_;
659
660 for my $dir (File::Spec->path) {
661 -x catfile($dir, "$name$Config{_exe}")
662 and return 1;
663 }
664
665 return;
666}
37959076
TC
667
668sub usage {
669 print STDERR <<EOS;
274cd32b
TC
670Usage: $0 [--enable feature1,feature2,...] [other options]
671 $0 [--disable feature1,feature2,...] [other options]
37959076
TC
672 $0 --help
673Possible feature names are:
674 png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
274cd32b
TC
675Other options:
676 --verbose | -v
677 Verbose library probing (or set IM_VERBOSE in the environment)
678 --nolog
679 Disable logging (or set IM_NOLOG in the environment)
680 --incpath dir
681 Add to the include search path
682 --libpath dir
683 Add to the library search path
684 --noprobe
685 Don't use pkg-config or freetype2-config to probe for freetype2 and libpng
37959076
TC
686EOS
687 exit 1;
688
689}