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