2 use ExtUtils::MakeMaker;
7 use vars qw(%Recommends);
9 use ExtUtils::Manifest qw(maniread);
12 # IM_INCPATH colon seperated list of paths to extra include paths
13 # IM_LIBPATH colon seperated list of paths to extra library paths
15 # IM_VERBOSE turns on verbose mode for the library finding and such
16 # IM_MANUAL to manually select which libraries are used and which not
17 # IM_ENABLE to programmatically select which libraries are used
19 # IM_NOLOG if true logging will not be compiled into the module
20 # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
21 # do not use IM_DEBUG_MALLOC in production - this slows
22 # everything down by alot
23 # IM_CFLAGS Extra flags to pass to the compiler
24 # IM_LFLAGS Extra flags to pass to the linker
25 # IM_DFLAGS Extra flags to pass to the preprocessor
26 # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
28 getenv(); # get environment variables
37 GetOptions("help" => \$help,
38 "enable=s" => \@enable,
39 "disable=s" => \@disable,
40 "incpath=s", \@incpaths,
41 "libpath=s" => \@libpaths,
42 "noprobe" => \$noprobe,
43 "verbose|v" => \$VERBOSE,
45 "noexif" => \$noexif);
48 print "Verbose mode\n";
50 import Data::Dumper qw(Dumper);
59 if ($NOLOG) { print "Logging not compiled into module\n"; }
61 push @defines, [ IMAGER_LOG => 1, "Logging system" ];
65 push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
66 print "Malloc debugging enabled\n";
69 if (@enable && @disable) {
70 print STDERR "Only --enable or --disable can be used, not both, try --help\n";
74 init(); # initialize global data
75 pathcheck(); # Check if directories exist
77 if (exists $ENV{IM_ENABLE}) {
78 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
79 for my $key (keys %formats) {
80 delete $formats{$key} unless $en{$key};
84 my %en = map { $_ => 1 } map { split /,/ } @enable;
85 for my $key (keys %formats) {
86 delete $formats{$key} unless $en{$key};
90 delete @formats{map { split /,/ } @disable};
93 # Pick what libraries are used
100 # Make sure there isn't a clash between the gif libraries.
106 for my $frmkey (keys %formats) {
107 my $frm = $formats{$frmkey};
108 push @defines, [ $frm->{def}, 1, "$frmkey available" ];
109 $F_LIBS .= ' ' .$frm->{libfiles};
110 $F_OBJECT .= ' ' .$frm->{objfiles};
111 $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags};
114 print "EXIF support enabled\n";
115 push @defines, [ 'IMEXIF_ENABLE', 1, "Enable experimental EXIF support" ];
116 $F_OBJECT .= ' imexif.o';
119 $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
120 grep !exists $definc{$_}, @incs;
121 $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS;
126 if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
127 if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
129 @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
130 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
131 filters.o dynaload.o stackmach.o datatypes.o
132 regmach.o trans2.o quant.o error.o convert.o
133 map.o tags.o palimg.o maskimg.o img16.o rotate.o
134 bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o hlines.o
137 $Recommends{Imager} =
138 { 'Parse::RecDescent' => 0 };
142 'VERSION_FROM' => 'Imager.pm',
143 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
144 'DEFINE' => "$OSDEF $CFLAGS",
145 'INC' => "$lib_cflags $DFLAGS $F_INC",
146 'OBJECT' => join(' ', @objs, $F_OBJECT),
147 clean => { FILES=>'testout meta.tmp' },
151 if ($ExtUtils::MakeMaker::VERSION > 6.06) {
152 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
153 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
156 make_imconfig(\@defines);
158 if ($VERBOSE) { print Dumper(\%opts); }
159 mkdir('testout',0777); # since we cannot include it in the archive.
160 WriteMakefile(%opts);
167 my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)';
169 dyntest.$(MYEXTLIB) : dynfilt/Makefile
170 cd dynfilt && $(MAKE) $(PASTHRU)
172 lib/Imager/Regops.pm : regmach.h regops.perl
173 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
175 imconfig.h : Makefile.PL
176 $(ECHO) "imconfig.h out-of-date with respect to $?"
177 $(PERLRUN) Makefile.PL
178 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
180 lib/Imager/APIRef.pm : \$(C_FILES) apidocs.perl
181 $perl apidocs.perl lib/Imager/APIRef.pm
187 # manual configuration of helper libraries
192 Please answer the following questions about
193 which formats are avaliable on your computer
195 press <return> to continue
198 <STDIN>; # eat one return
200 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
202 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
203 print "Enable $frm support: ";
206 if ($gz =~ m/^(y|yes|n|no)/i) {
207 $gz=substr(lc($gz),0,1);
209 delete $formats{$frm};
216 # automatic configuration of helper libraries
219 for $frm(keys %formats) {
220 delete $formats{$frm} if !checkformat($frm);
226 if ($formats{'gif'} and $formats{'ungif'}) {
227 print "ungif and gif can not coexist - removing ungif support\n";
228 delete $formats{'ungif'};
232 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
235 You have libgif or libungif installed. They are both known to have
236 bugs. Imager can crash or display other strange behaviour after
237 reading or writing gif images. Some of the gif tests can even fail
238 since they stress some parts of the buggy code.
240 libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
241 patch to have all the bugs fixed, see README for details.
243 Of course it's possible your operating system distributor has patched
244 all of these problems and you have nothing to worry about.
246 Do you want to remove gif support? [Y/n]
251 delete $formats{'gif'};
252 delete $formats{'ungif'};
257 for my $frm (qw(gif ungif)) {
258 checkformat($frm) if ($MANUAL and $formats{$frm});
262 for my $frm (grep $formats{$_}, qw(gif ungif)) {
263 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
267 FILES: for my $dir (@dirs) {
268 my $h = "$dir/gif_lib.h";
269 open H, "< $h" or next;
271 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
281 # we need the version in a #ifdefable form
283 push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ];
284 push @defines, [ IM_GIFMINOR, $minor ];
291 # print "checking path $path\n";
292 if ( !opendir(DH,$path) ) {
293 warn "Cannot open dir $path: $!\n";
296 my @l=grep { $chk->($_) } readdir(DH);
299 return map $path, @l;
306 my $code = $formats{$frm}{'code'};
307 if ($code && !$noprobe) {
308 return 1 if $code->($formats{$frm}, $frm);
311 my $libchk=$formats{$frm}{'libcheck'};
312 my $incchk=$formats{$frm}{'inccheck'};
316 push(@l, gd($lp,$libchk));
321 push(@i, $ip) if $incchk->($ip,$frm);
324 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
325 $formats{$frm}{incdir} = \@i;
326 $formats{$frm}{libdir} = \@l;
327 return scalar(@i && @l);
334 print " Include paths:\n";
335 for (@incs) { print $_,"\n"; }
337 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
340 print "\nLibrary paths:\n";
341 for (@libs) { print $_,"\n"; }
343 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
348 # Format data initialization
350 # format definition is:
352 # default include path
353 # files needed for include (boolean perl code)
356 # files needed for link (boolean perl code)
357 # object files needed for the format
362 @definc{'/usr/include'}=();
363 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
364 map { split /\Q$Config{path_sep}/} @incpaths );
365 if ($Config{locincpth}) {
366 push @incs, grep -d, split ' ', $Config{locincpth};
368 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
369 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
373 /usr/include/freetype2
374 /usr/local/include/freetype2
375 /usr/local/include/freetype1/freetype
376 /usr/include /usr/local/include /usr/include/freetype
377 /usr/local/include/freetype);
379 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
380 map { split /\Q$Config{path_sep}/} @libpaths );
381 if ($Config{loclibpth}) {
382 push @libs, grep -d, split ' ', $Config{loclibpth};
384 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
385 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
386 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
388 if ($^O eq 'cygwin') {
389 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
390 push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api';
393 my $lext=$Config{'so'}; # Get extensions of libraries
394 my $aext=$Config{'_a'};
399 inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
400 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
404 In order to use jpeg with this module you need to have libjpeg
405 installed on your computer}
411 inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
412 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
416 In order to use tiff with this module you need to have libtiff
417 installed on your computer}
423 inccheck=>sub { -e catfile($_[0], 'png.h') },
424 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
425 libfiles=>'-lpng -lz',
428 Png stands for Portable Network Graphics and is intended as
429 a replacement for gif on the web. It is patent free and
430 is recommended by the w3c, you need libpng to use these formats},
437 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
438 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
442 gif is the de facto standard for webgraphics at the moment,
443 it does have some patent problems. If you have giflib and
444 are not in violation with the unisys patent you should use
445 this instead of the 'ungif' option. Note that they cannot
446 be in use at the same time}
452 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
453 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
457 gif is the de facto standard for webgraphics at the moment,
458 it does have some patent problems. If you have libungif and
459 want to create images free from LZW patented compression you
460 should use this option instead of the 'gif' option}
463 $formats{'T1-fonts'}={
466 inccheck=>sub { -e catfile($_[0], 't1lib.h') },
467 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
471 postscript t1 fonts are scalable fonts. They can include
472 ligatures and kerning information and generally yield good
473 visual quality. We depend on libt1 to rasterize the fonts
477 $formats{'TT-fonts'}=
481 inccheck=>sub { -e catfile($_[0], 'freetype.h')
482 && !-e catfile($_[0], 'fterrors.h') },
483 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
487 Truetype fonts are scalable fonts. They can include
488 kerning and hinting information and generally yield good
489 visual quality esp on low resultions. The freetype library is
490 used to rasterize for us. The only drawback is that there
491 are alot of badly designed fonts out there.}
496 inccheck=>sub { -e catfile($_[0], 'windows.h') },
497 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
498 || lc $_[0] eq 'libgdi32.a' },
499 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
502 Uses the Win32 GDI for rendering text.
504 This currently only works on under normal Win32 and cygwin.
507 $formats{'freetype2'} = {
510 inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
511 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
512 libfiles=>'-lfreetype',
513 objfiles=>'freetyp2.o',
515 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
516 scalable. It also supports a variety of other fonts.
518 code => \&freetype2_probe,
522 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
529 defined($V) ? $V : "";
533 # Get information from environment variables
545 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
560 open CONFIG, "> imconfig.h"
561 or die "Cannot create imconfig.h: $!\n";
563 /* This file is automatically generated by Makefile.PL.
564 Don't edit this file, since any changes will be lost */
566 #ifndef IMAGER_IMCONFIG_H
567 #define IMAGER_IMCONFIG_H
569 for my $define (@$defines) {
571 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
573 print CONFIG "#define $define->[0] $define->[1]\n";
575 print CONFIG "\n#endif\n";
579 # use pkg-config to probe for libraries
580 # works around the junk that pkg-config dumps on FreeBSD
584 is_exe('pkg-config') or return;
586 my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
588 !system("pkg-config $pkg --exists $redir");
591 # probes for freetype2 by trying to run freetype-config
592 sub freetype2_probe {
593 my ($frm, $frmkey) = @_;
595 is_exe('freetype-config') or return;
597 my $cflags = `freetype-config --cflags`
601 $frm->{cflags} = $cflags;
602 my $lflags = `freetype-config --libs`
605 $frm->{libfiles} = $lflags;
607 printf "%10s: configured via freetype-config\n", $frmkey;
612 # probes for libpng via pkg-config
614 my ($frm, $frmkey) = @_;
616 is_exe('pkg-config') or return;
619 for my $check_conf (qw(libpng libpng12 libpng10)) {
620 if (_pkg_probe($check_conf)) {
621 $config = $check_conf;
627 my $cflags = `pkg-config $config --cflags`
630 my $lflags = `pkg-config $config --libs`
635 $frm->{cflags} = $cflags;
636 $frm->{libfiles} = $lflags;
638 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
644 return File::Spec->catfile(@_);
650 for my $dir (File::Spec->path) {
651 -x catfile($dir, "$name$Config{_exe}")
660 Usage: $0 [--enable feature1,feature2,...] [other options]
661 $0 [--disable feature1,feature2,...] [other options]
663 Possible feature names are:
664 png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
667 Verbose library probing (or set IM_VERBOSE in the environment)
669 Disable logging (or set IM_NOLOG in the environment)
671 Add to the include search path
673 Add to the library search path
675 Don't use pkg-config or freetype2-config to probe for freetype2 and libpng
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
686 my $instbase = '$(INST_LIBDIR)';
688 # first the basics, .pm and .pod files
689 $pm{"Imager.pm"} = "$instbase/Imager.pm";
691 my $mani = maniread();
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;
701 $pm{typemap} = $instbase . '/Imager/typemap';
703 # and the core headers
704 for my $filename (keys %$mani) {
705 if ($filename =~ /^\w+\.h$/) {
706 $pm{$filename} = $instbase . '/Imager/include/' . $filename;
710 # and the generated header
711 $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h';