3 use ExtUtils::MakeMaker;
8 use vars qw(%Recommends);
10 use ExtUtils::Manifest qw(maniread);
11 use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS);
14 # IM_INCPATH colon seperated list of paths to extra include paths
15 # IM_LIBPATH colon seperated list of paths to extra library paths
17 # IM_VERBOSE turns on verbose mode for the library finding and such
18 # IM_MANUAL to manually select which libraries are used and which not
19 # IM_ENABLE to programmatically select which libraries are used
21 # IM_NOLOG if true logging will not be compiled into the module
22 # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
23 # do not use IM_DEBUG_MALLOC in production - this slows
24 # everything down by alot
25 # IM_CFLAGS Extra flags to pass to the compiler
26 # IM_LFLAGS Extra flags to pass to the linker
27 # IM_DFLAGS Extra flags to pass to the preprocessor
28 # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
30 getenv(); # get environment variables
32 my $lext=$Config{'so'}; # Get extensions of libraries
33 my $aext=$Config{'_a'};
35 my $help; # display help if set
36 my @enable; # list of drivers to enable
37 my @disable; # or list of drivers to disable
38 my @incpaths; # places to look for headers
39 my @libpaths; # places to look for libraries
40 my $noprobe; # non-zero to disable newer probes
41 my $noexif; # non-zero to disable EXIF parsing of JPEGs
42 GetOptions("help" => \$help,
43 "enable=s" => \@enable,
44 "disable=s" => \@disable,
45 "incpath=s", \@incpaths,
46 "libpath=s" => \@libpaths,
47 "noprobe" => \$noprobe,
48 "verbose|v" => \$VERBOSE,
50 "noexif" => \$noexif);
53 print "Verbose mode\n";
55 import Data::Dumper qw(Dumper);
64 if ($NOLOG) { print "Logging not compiled into module\n"; }
66 push @defines, [ IMAGER_LOG => 1, "Logging system" ];
70 push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
71 print "Malloc debugging enabled\n";
74 if (@enable && @disable) {
75 print STDERR "Only --enable or --disable can be used, not both, try --help\n";
81 my @incs; # all the places to look for headers
82 my @libs; # all the places to look for libraries
84 init(); # initialize global data
85 pathcheck(); # Check if directories exist
87 if (exists $ENV{IM_ENABLE}) {
88 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
89 for my $key (keys %formats) {
90 delete $formats{$key} unless $en{$key};
94 my %en = map { $_ => 1 } map { split /,/ } @enable;
95 for my $key (keys %formats) {
96 delete $formats{$key} unless $en{$key};
100 delete @formats{map { split /,/ } @disable};
103 # Pick what libraries are used
110 # Make sure there isn't a clash between the gif libraries.
116 for my $frmkey (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) {
117 my $frm = $formats{$frmkey};
118 push @defines, [ $frm->{def}, 1, "$frmkey available" ];
119 $F_LIBS .= ' ' .$frm->{libfiles};
120 $F_OBJECT .= ' ' .$frm->{objfiles};
121 if ($frm->{cflags}) {
122 $lib_cflags .= ' ' .$frm->{cflags};
123 ++$definc{$_} for map { /^-I(.*)$/ ? ($1) : () }
124 grep /^-I./, split ' ', $frm->{cflags};
129 print "EXIF support enabled\n";
130 push @defines, [ 'IMEXIF_ENABLE', 1, "Enable experimental EXIF support" ];
131 $F_OBJECT .= ' imexif.o';
134 my $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
135 grep !$definc{$_}, @incs;
136 $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_,
137 grep !$deflib{$_}++, @libs) . $F_LIBS;
140 my $OSDEF = "-DOS_$^O";
142 if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
143 if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
145 my @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
146 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
147 filters.o dynaload.o stackmach.o datatypes.o
148 regmach.o trans2.o quant.o error.o convert.o
149 map.o tags.o palimg.o maskimg.o img16.o rotate.o
150 bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o hlines.o
153 $Recommends{Imager} =
154 { 'Parse::RecDescent' => 0 };
158 'VERSION_FROM' => 'Imager.pm',
159 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
160 'DEFINE' => "$OSDEF $CFLAGS",
161 'INC' => "$lib_cflags $DFLAGS $F_INC",
162 'OBJECT' => join(' ', @objs, $F_OBJECT),
163 clean => { FILES=>'testout meta.tmp' },
167 if ($ExtUtils::MakeMaker::VERSION > 6.06) {
168 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
169 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
172 make_imconfig(\@defines);
174 if ($VERBOSE) { print Dumper(\%opts); }
175 mkdir('testout',0777); # since we cannot include it in the archive.
176 WriteMakefile(%opts);
183 my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)';
185 dyntest.$(MYEXTLIB) : dynfilt/Makefile
186 cd dynfilt && $(MAKE) $(PASTHRU)
188 lib/Imager/Regops.pm : regmach.h regops.perl
189 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
191 imconfig.h : Makefile.PL
192 $(ECHO) "imconfig.h out-of-date with respect to $?"
193 $(PERLRUN) Makefile.PL
194 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
196 lib/Imager/APIRef.pm : \$(C_FILES) apidocs.perl
197 $perl apidocs.perl lib/Imager/APIRef.pm
203 # manual configuration of helper libraries
208 Please answer the following questions about
209 which formats are avaliable on your computer
211 press <return> to continue
214 <STDIN>; # eat one return
216 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
218 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
219 print "Enable $frm support: ";
222 if ($gz =~ m/^(y|yes|n|no)/i) {
223 $gz=substr(lc($gz),0,1);
225 delete $formats{$frm};
232 # automatic configuration of helper libraries
235 print "Automatic probing:\n" if $VERBOSE;
236 for my $frm (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) {
237 delete $formats{$frm} if !checkformat($frm);
243 if ($formats{'gif'} and $formats{'ungif'}) {
244 print "ungif and gif can not coexist - removing ungif support\n";
245 delete $formats{'ungif'};
249 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
252 You have libgif or libungif installed. They are both known to have
253 bugs. Imager can crash or display other strange behaviour after
254 reading or writing gif images. Some of the gif tests can even fail
255 since they stress some parts of the buggy code.
257 libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
258 patch to have all the bugs fixed, see README for details.
260 Of course it's possible your operating system distributor has patched
261 all of these problems and you have nothing to worry about.
263 Do you want to remove gif support? [Y/n]
268 delete $formats{'gif'};
269 delete $formats{'ungif'};
274 for my $frm (qw(gif ungif)) {
275 checkformat($frm) if ($MANUAL and $formats{$frm});
279 for my $frm (grep $formats{$_}, qw(gif ungif)) {
280 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
284 FILES: for my $dir (@dirs) {
285 my $h = "$dir/gif_lib.h";
286 open H, "< $h" or next;
288 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
298 # we need the version in a #ifdefable form
300 push @defines, [ IM_GIFMAJOR => $major, "Parsed giflib version" ];
301 push @defines, [ IM_GIFMINOR => $minor ];
308 # print "checking path $path\n";
309 if ( !opendir(DH,$path) ) {
310 warn "Cannot open dir $path: $!\n";
313 my @l=grep { $chk->($_) } readdir(DH);
316 return map $path, @l;
323 print " checkformat($frm)\n" if $VERBOSE;
325 my $code = $formats{$frm}{'code'};
326 if ($code && !$noprobe) {
327 print " Calling probe function\n" if $VERBOSE;
328 return 1 if $code->($formats{$frm}, $frm);
331 my $libchk=$formats{$frm}{'libcheck'};
332 my $incchk=$formats{$frm}{'inccheck'};
336 push(@l, gd($lp,$libchk));
341 push(@i, $ip) if $incchk->($ip,$frm);
344 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
345 $formats{$frm}{incdir} = \@i;
346 $formats{$frm}{libdir} = \@l;
347 return scalar(@i && @l);
354 print " Include paths:\n";
355 for (@incs) { print $_,"\n"; }
357 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
360 print "\nLibrary paths:\n";
361 for (@libs) { print $_,"\n"; }
363 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
368 # Format data initialization
370 # format definition is:
372 # default include path
373 # files needed for include (boolean perl code)
376 # files needed for link (boolean perl code)
377 # object files needed for the format
382 my @definc = qw(/usr/include);
383 @definc{@definc}=(1) x @definc;
384 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
385 map { split /\Q$Config{path_sep}/} @incpaths );
386 if ($Config{locincpth}) {
387 push @incs, grep -d, split ' ', $Config{locincpth};
389 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
390 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
394 /usr/include/freetype2
395 /usr/local/include/freetype2
396 /usr/local/include/freetype1/freetype
397 /usr/include /usr/local/include /usr/include/freetype
398 /usr/local/include/freetype);
399 if ($Config{ccflags}) {
400 my @hidden = map { /^-I(.*)$/ ? ($1) : () } split ' ', $Config{ccflags};
402 @definc{@hidden} = (1) x @hidden;
405 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
406 map { split /\Q$Config{path_sep}/} @libpaths );
407 if ($Config{loclibpth}) {
408 push @libs, grep -d, split ' ', $Config{loclibpth};
411 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
412 push @libs, grep -d, split / /, $Config{libspath} if $Config{libspath};
413 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
414 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
416 if ($^O eq 'cygwin') {
417 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
418 push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api';
420 if ($Config{ldflags}) {
421 # some builds of perl put -Ldir into ldflags without putting it in
422 # loclibpth, let's extract them
423 my @hidden = grep -d, map { /^-L(.*)$/ ? ($1) : () }
424 split ' ', $Config{ldflags};
426 # don't mark them as seen - EU::MM will remove any libraries
427 # it can't find and it doesn't look for -L in ldflags
428 #@deflib{@hidden} = @hidden;
434 inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
435 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
439 In order to use jpeg with this module you need to have libjpeg
440 installed on your computer}
446 inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
447 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
451 In order to use tiff with this module you need to have libtiff
452 installed on your computer}
458 inccheck=>sub { -e catfile($_[0], 'png.h') },
459 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
460 libfiles=>'-lpng -lz',
463 Png stands for Portable Network Graphics and is intended as
464 a replacement for gif on the web. It is patent free and
465 is recommended by the w3c, you need libpng to use these formats},
472 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
473 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
477 gif is the de facto standard for webgraphics at the moment,
478 it does have some patent problems. If you have giflib and
479 are not in violation with the unisys patent you should use
480 this instead of the 'ungif' option. Note that they cannot
481 be in use at the same time}
487 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
488 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
492 gif is the de facto standard for webgraphics at the moment,
493 it does have some patent problems. If you have libungif and
494 want to create images free from LZW patented compression you
495 should use this option instead of the 'gif' option}
498 $formats{'T1-fonts'}={
501 inccheck=>sub { -e catfile($_[0], 't1lib.h') },
502 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
506 postscript t1 fonts are scalable fonts. They can include
507 ligatures and kerning information and generally yield good
508 visual quality. We depend on libt1 to rasterize the fonts
512 $formats{'TT-fonts'}=
516 inccheck=>sub { -e catfile($_[0], 'freetype.h')
517 && !-e catfile($_[0], 'fterrors.h') },
518 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
521 code => \&freetype1_probe,
523 Truetype fonts are scalable fonts. They can include
524 kerning and hinting information and generally yield good
525 visual quality esp on low resultions. The freetype library is
526 used to rasterize for us. The only drawback is that there
527 are alot of badly designed fonts out there.}
532 inccheck=>sub { -e catfile($_[0], 'windows.h') },
533 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
534 || lc $_[0] eq 'libgdi32.a' },
535 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
538 Uses the Win32 GDI for rendering text.
540 This currently only works on under normal Win32 and cygwin.
543 $formats{'freetype2'} = {
546 inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
547 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
548 libfiles=>'-lfreetype',
549 objfiles=>'freetyp2.o',
551 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
552 scalable. It also supports a variety of other fonts.
554 code => \&freetype2_probe,
558 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
565 defined($V) ? $V : "";
569 # Get information from environment variables
581 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
596 open CONFIG, "> imconfig.h"
597 or die "Cannot create imconfig.h: $!\n";
599 /* This file is automatically generated by Makefile.PL.
600 Don't edit this file, since any changes will be lost */
602 #ifndef IMAGER_IMCONFIG_H
603 #define IMAGER_IMCONFIG_H
605 for my $define (@$defines) {
607 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
609 print CONFIG "#define $define->[0] $define->[1]\n";
611 print CONFIG "\n#endif\n";
615 # use pkg-config to probe for libraries
616 # works around the junk that pkg-config dumps on FreeBSD
620 is_exe('pkg-config') or return;
622 my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
624 !system("pkg-config $pkg --exists $redir");
627 # probes for freetype1 by scanning @incs for the includes and
628 # @libs for the libs. This is done separately because freetype's headers
629 # are stored in a freetype or freetype1 directory under PREFIX/include.
631 # we could find the files with the existing mechanism, but it won't set
632 # -I flags correctly.
634 # This could be extended to freetype2 too, but freetype-config catches
636 sub freetype1_probe {
637 my ($frm, $frmkey) = @_;
641 for my $inc (@incs) {
642 for my $subdir (qw/freetype freetype1/) {
643 my $path = File::Spec->catfile($inc, $subdir, 'freetype.h');
645 $path = File::Spec->catfile($inc, $subdir, 'fterrors.h');
648 $found_inc = File::Spec->catdir($inc, $subdir);
655 for my $lib (@libs) {
656 my $a_path = File::Spec->catfile($lib, "libttf$aext");
657 my $l_path = File::Spec->catfile($lib, "libttf.$lext");
658 if (-e $a_path || -e $l_path) {
664 printf("%10s: includes %s - libraries %s\n", $frmkey,
665 ($found_inc ? 'found' : 'not found'),
666 ($found_lib ? 'found' : 'not found'));
667 return unless $found_inc && $found_lib;
669 $frm->{cflags} = "-I$found_inc";
670 $frm->{libfiles} = "-lttf";
675 # probes for freetype2 by trying to run freetype-config
676 sub freetype2_probe {
677 my ($frm, $frmkey) = @_;
679 is_exe('freetype-config') or return;
681 my $cflags = `freetype-config --cflags`
685 my $lflags = `freetype-config --libs`
689 # before 2.1.5 freetype-config --cflags could output
690 # the -I options in the wrong order, causing a conflict with
691 # freetype1.x installed with the same --prefix
694 # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags
696 # - freetype 1.x headers are in prefix/include/freetype
697 my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags;
699 && $incdirs[1] eq "$incdirs[0]/freetype2"
700 && -e "$incdirs[0]/freetype/freetype.h"
701 && -e "$incdirs[0]/freetype/fterrid.h") {
702 print "** freetype-config provided -I options out of order, correcting\n"
704 $cflags = join(' ', grep(!/-I/, split ' ', $cflags),
705 map "-I$_", reverse @incdirs);
707 $frm->{cflags} = $cflags;
708 $frm->{libfiles} = $lflags;
710 printf "%10s: configured via freetype-config\n", $frmkey;
715 # probes for libpng via pkg-config
717 my ($frm, $frmkey) = @_;
719 is_exe('pkg-config') or return;
722 for my $check_conf (qw(libpng libpng12 libpng10)) {
723 if (_pkg_probe($check_conf)) {
724 $config = $check_conf;
730 my $cflags = `pkg-config $config --cflags`
733 my $lflags = `pkg-config $config --libs`
738 $frm->{cflags} = $cflags;
739 $frm->{libfiles} = $lflags;
741 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
747 return File::Spec->catfile(@_);
753 for my $dir (File::Spec->path) {
754 -x catfile($dir, "$name$Config{_exe}")
763 Usage: $0 [--enable feature1,feature2,...] [other options]
764 $0 [--disable feature1,feature2,...] [other options]
766 Possible feature names are:
767 png gif ungif jpeg tiff T1-fonts TT-fonts freetype2
770 Verbose library probing (or set IM_VERBOSE in the environment)
772 Disable logging (or set IM_NOLOG in the environment)
774 Add to the include search path
776 Add to the library search path
778 Don't use pkg-config or freetype2-config to probe for freetype2 and libpng
784 # generate the PM MM argument
785 # I'd prefer to modify the public version, but there doesn't seem to be
786 # a public API to do that
789 my $instbase = '$(INST_LIBDIR)';
791 # first the basics, .pm and .pod files
792 $pm{"Imager.pm"} = "$instbase/Imager.pm";
794 my $mani = maniread();
796 for my $filename (keys %$mani) {
797 if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) {
798 (my $work = $filename) =~ s/^lib//;
799 $pm{$filename} = $instbase . $work;
804 $pm{typemap} = $instbase . '/Imager/typemap';
806 # and the core headers
807 for my $filename (keys %$mani) {
808 if ($filename =~ /^\w+\.h$/) {
809 $pm{$filename} = $instbase . '/Imager/include/' . $filename;
813 # and the generated header
814 $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h';