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 dyntest.$(MYEXTLIB) : dynfilt/Makefile
168 cd dynfilt && $(MAKE) $(PASTHRU)
170 lib/Imager/Regops.pm : regmach.h regops.perl
171 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
173 imconfig.h : Makefile.PL
174 $(ECHO) "imconfig.h out-of-date with respect to $?"
175 $(PERLRUN) Makefile.PL
176 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
178 lib/Imager/APIRef.pm : $(C_FILES) apidocs.perl
179 $(PERLRUN) apidocs.perl lib/Imager/APIRef.pm
185 # manual configuration of helper libraries
190 Please answer the following questions about
191 which formats are avaliable on your computer
193 press <return> to continue
196 <STDIN>; # eat one return
198 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
200 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
201 print "Enable $frm support: ";
204 if ($gz =~ m/^(y|yes|n|no)/i) {
205 $gz=substr(lc($gz),0,1);
207 delete $formats{$frm};
214 # automatic configuration of helper libraries
217 for $frm(keys %formats) {
218 delete $formats{$frm} if !checkformat($frm);
224 if ($formats{'gif'} and $formats{'ungif'}) {
225 print "ungif and gif can not coexist - removing ungif support\n";
226 delete $formats{'ungif'};
230 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
233 You have libgif or libungif installed. They are both known to have
234 bugs. Imager can crash or display other strange behaviour after
235 reading or writing gif images. Some of the gif tests can even fail
236 since they stress some parts of the buggy code.
238 libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
239 patch to have all the bugs fixed, see README for details.
241 Of course it's possible your operating system distributor has patched
242 all of these problems and you have nothing to worry about.
244 Do you want to remove gif support? [Y/n]
249 delete $formats{'gif'};
250 delete $formats{'ungif'};
255 for my $frm (qw(gif ungif)) {
256 checkformat($frm) if ($MANUAL and $formats{$frm});
260 for my $frm (grep $formats{$_}, qw(gif ungif)) {
261 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
265 FILES: for my $dir (@dirs) {
266 my $h = "$dir/gif_lib.h";
267 open H, "< $h" or next;
269 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
279 # we need the version in a #ifdefable form
281 push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ];
282 push @defines, [ IM_GIFMINOR, $minor ];
289 # print "checking path $path\n";
290 if ( !opendir(DH,$path) ) {
291 warn "Cannot open dir $path: $!\n";
294 my @l=grep { $chk->($_) } readdir(DH);
297 return map $path, @l;
304 my $code = $formats{$frm}{'code'};
305 if ($code && !$noprobe) {
306 return 1 if $code->($formats{$frm}, $frm);
309 my $libchk=$formats{$frm}{'libcheck'};
310 my $incchk=$formats{$frm}{'inccheck'};
314 push(@l, gd($lp,$libchk));
319 push(@i, $ip) if $incchk->($ip,$frm);
322 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
323 $formats{$frm}{incdir} = \@i;
324 $formats{$frm}{libdir} = \@l;
325 return scalar(@i && @l);
332 print " Include paths:\n";
333 for (@incs) { print $_,"\n"; }
335 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
338 print "\nLibrary paths:\n";
339 for (@libs) { print $_,"\n"; }
341 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
346 # Format data initialization
348 # format definition is:
350 # default include path
351 # files needed for include (boolean perl code)
354 # files needed for link (boolean perl code)
355 # object files needed for the format
360 @definc{'/usr/include'}=();
361 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
362 map { split /\Q$Config{path_sep}/} @incpaths );
363 if ($Config{locincpth}) {
364 push @incs, grep -d, split ' ', $Config{locincpth};
366 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
367 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
371 /usr/include/freetype2
372 /usr/local/include/freetype2
373 /usr/local/include/freetype1/freetype
374 /usr/include /usr/local/include /usr/include/freetype
375 /usr/local/include/freetype);
377 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
378 map { split /\Q$Config{path_sep}/} @libpaths );
379 if ($Config{loclibpth}) {
380 push @libs, grep -d, split ' ', $Config{loclibpth};
382 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
383 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
384 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
386 if ($^O eq 'cygwin') {
387 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
388 push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api';
391 my $lext=$Config{'so'}; # Get extensions of libraries
392 my $aext=$Config{'_a'};
397 inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
398 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
402 In order to use jpeg with this module you need to have libjpeg
403 installed on your computer}
409 inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
410 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
414 In order to use tiff with this module you need to have libtiff
415 installed on your computer}
421 inccheck=>sub { -e catfile($_[0], 'png.h') },
422 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
423 libfiles=>'-lpng -lz',
426 Png stands for Portable Network Graphics and is intended as
427 a replacement for gif on the web. It is patent free and
428 is recommended by the w3c, you need libpng to use these formats},
435 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
436 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
440 gif is the de facto standard for webgraphics at the moment,
441 it does have some patent problems. If you have giflib and
442 are not in violation with the unisys patent you should use
443 this instead of the 'ungif' option. Note that they cannot
444 be in use at the same time}
450 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
451 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
455 gif is the de facto standard for webgraphics at the moment,
456 it does have some patent problems. If you have libungif and
457 want to create images free from LZW patented compression you
458 should use this option instead of the 'gif' option}
461 $formats{'T1-fonts'}={
464 inccheck=>sub { -e catfile($_[0], 't1lib.h') },
465 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
469 postscript t1 fonts are scalable fonts. They can include
470 ligatures and kerning information and generally yield good
471 visual quality. We depend on libt1 to rasterize the fonts
475 $formats{'TT-fonts'}=
479 inccheck=>sub { -e catfile($_[0], 'freetype.h')
480 && !-e catfile($_[0], 'fterrors.h') },
481 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
485 Truetype fonts are scalable fonts. They can include
486 kerning and hinting information and generally yield good
487 visual quality esp on low resultions. The freetype library is
488 used to rasterize for us. The only drawback is that there
489 are alot of badly designed fonts out there.}
494 inccheck=>sub { -e catfile($_[0], 'windows.h') },
495 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
496 || lc $_[0] eq 'libgdi32.a' },
497 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
500 Uses the Win32 GDI for rendering text.
502 This currently only works on under normal Win32 and cygwin.
505 $formats{'freetype2'} = {
508 inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
509 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
510 libfiles=>'-lfreetype',
511 objfiles=>'freetyp2.o',
513 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
514 scalable. It also supports a variety of other fonts.
516 code => \&freetype2_probe,
520 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
527 defined($V) ? $V : "";
531 # Get information from environment variables
543 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
558 open CONFIG, "> imconfig.h"
559 or die "Cannot create imconfig.h: $!\n";
561 /* This file is automatically generated by Makefile.PL.
562 Don't edit this file, since any changes will be lost */
564 #ifndef IMAGER_IMCONFIG_H
565 #define IMAGER_IMCONFIG_H
567 for my $define (@$defines) {
569 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
571 print CONFIG "#define $define->[0] $define->[1]\n";
573 print CONFIG "\n#endif\n";
577 # use pkg-config to probe for libraries
578 # works around the junk that pkg-config dumps on FreeBSD
582 is_exe('pkg-config') or return;
584 my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
586 !system("pkg-config $pkg --exists $redir");
589 # probes for freetype2 by trying to run freetype-config
590 sub freetype2_probe {
591 my ($frm, $frmkey) = @_;
593 is_exe('freetype-config') or return;
595 my $cflags = `freetype-config --cflags`
599 $frm->{cflags} = $cflags;
600 my $lflags = `freetype-config --libs`
603 $frm->{libfiles} = $lflags;
605 printf "%10s: configured via freetype-config\n", $frmkey;
610 # probes for libpng via pkg-config
612 my ($frm, $frmkey) = @_;
614 is_exe('pkg-config') or return;
617 for my $check_conf (qw(libpng libpng12 libpng10)) {
618 if (_pkg_probe($check_conf)) {
619 $config = $check_conf;
625 my $cflags = `pkg-config $config --cflags`
628 my $lflags = `pkg-config $config --libs`
633 $frm->{cflags} = $cflags;
634 $frm->{libfiles} = $lflags;
636 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
642 return File::Spec->catfile(@_);
648 for my $dir (File::Spec->path) {
649 -x catfile($dir, "$name$Config{_exe}")
658 Usage: $0 [--enable feature1,feature2,...] [other options]
659 $0 [--disable feature1,feature2,...] [other options]
661 Possible feature names are:
662 png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
665 Verbose library probing (or set IM_VERBOSE in the environment)
667 Disable logging (or set IM_NOLOG in the environment)
669 Add to the include search path
671 Add to the library search path
673 Don't use pkg-config or freetype2-config to probe for freetype2 and libpng
679 # generate the PM MM argument
680 # I'd prefer to modify the public version, but there doesn't seem to be
681 # a public API to do that
684 my $instbase = '$(INST_LIBDIR)';
686 # first the basics, .pm and .pod files
687 $pm{"Imager.pm"} = "$instbase/Imager.pm";
689 my $mani = maniread();
691 for my $filename (keys %$mani) {
692 if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) {
693 (my $work = $filename) =~ s/^lib//;
694 $pm{$filename} = $instbase . $work;
699 $pm{typemap} = $instbase . '/Imager/typemap';
701 # and the core headers
702 for my $filename (keys %$mani) {
703 if ($filename =~ /^\w+\.h$/) {
704 $pm{$filename} = $instbase . '/Imager/include/' . $filename;
708 # and the generated header
709 $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h';