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