2 use ExtUtils::MakeMaker;
9 # IM_INCPATH colon seperated list of paths to extra include paths
10 # IM_LIBPATH colon seperated list of paths to extra library paths
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
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
23 # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
31 GetOptions("help" => \$help,
32 "enable=s" => \@enable,
33 "disable=s" => \@disable,
34 "incpath=s", \@incpaths,
35 "libpath=s" => \@libpaths,
36 "noprobe" => \$noprobe);
42 if (@enable && @disable) {
43 print STDERR "Only --enable or --disable can be used, not both, try --help\n";
47 getenv(); # get environment variables
48 init(); # initialize global data
49 pathcheck(); # Check if directories exist
51 if (exists $ENV{IM_ENABLE}) {
52 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
53 for my $key (keys %formats) {
54 delete $formats{$key} unless $en{$key};
58 my %en = map { $_ => 1 } map { split /,/ } @enable;
59 for my $key (keys %formats) {
60 delete $formats{$key} unless $en{$key};
64 delete @formats{map { split /,/ } @disable};
69 # Pick what libraries are used
76 # Make sure there isn't a clash between the gif libraries.
82 for my $frmkey (keys %formats) {
83 my $frm = $formats{$frmkey};
84 push @defines, [ $frm->{def}, 1, "$frmkey available" ];
85 $F_LIBS .= ' ' .$frm->{libfiles};
86 $F_OBJECT .= ' ' .$frm->{objfiles};
87 $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags};
90 $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
91 grep !exists $definc{$_}, @incs;
92 $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS;
97 if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
98 if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
100 @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
101 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
102 filters.o dynaload.o stackmach.o datatypes.o
103 regmach.o trans2.o quant.o error.o convert.o
104 map.o tags.o palimg.o maskimg.o img16.o rotate.o
105 bmp.o tga.o rgb.o color.o fills.o imgdouble.o);
109 'VERSION_FROM' => 'Imager.pm',
110 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
111 'DEFINE' => "$OSDEF $CFLAGS",
112 'INC' => "$lib_cflags $DFLAGS $F_INC",
113 'OBJECT' => join(' ', @objs, $F_OBJECT),
114 clean => { FILES=>'testout meta.tmp' },
117 if ($ExtUtils::MakeMaker::VERSION > 6.06) {
118 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
119 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
122 make_imconfig(\@defines);
124 if ($VERBOSE) { print Dumper(\%opts); }
125 mkdir('testout',0777); # since we cannot include it in the archive.
126 WriteMakefile(%opts);
133 dyntest.$(MYEXTLIB) : dynfilt/Makefile
134 cd dynfilt && $(MAKE) $(PASTHRU)
136 lib/Imager/Regops.pm : regmach.h regops.perl
137 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
139 imconfig.h: Makefile.PL
140 $(ECHO) "imconfig.h out-of-date with respect to $?"
141 $(PERLRUN) Makefile.PL
142 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
152 version: $self->{VERSION}
153 version_from: $self->{VERSION_FROM}
154 author: $self->{AUTHOR}
155 abstract: $self->{ABSTRACT}
156 installdirs: $self->{INSTALLDIRS}
161 distribution_type: module
162 generated_by: Imager version $self->{VERSION}
164 open META, "> meta.tmp" or die "Cannot create meta.tmp: $!";
168 return sprintf "metafile :\n\t\$(CP) meta.tmp META.yml\n";
171 # manual configuration of helper libraries
176 Please answer the following questions about
177 which formats are avaliable on your computer
179 press <return> to continue
182 <STDIN>; # eat one return
184 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
186 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
187 print "Enable $frm support: ";
190 if ($gz =~ m/^(y|yes|n|no)/i) {
191 $gz=substr(lc($gz),0,1);
193 delete $formats{$frm};
200 # automatic configuration of helper libraries
203 for $frm(keys %formats) {
204 delete $formats{$frm} if !checkformat($frm);
210 if ($formats{'gif'} and $formats{'ungif'}) {
211 print "ungif and gif can not coexist - removing ungif support\n";
212 delete $formats{'ungif'};
216 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
219 You have libgif or libungif installed. They are both known to have
220 bugs. Imager can crash or display other strange behaviour after
221 reading or writing gif images. Some of the gif tests can even fail
222 since they stress some parts of the buggy code.
224 libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
225 patch to have all the bugs fixed, see README for details.
227 Of course it's possible your operating system distributor has patched
228 all of these problems and you have nothing to worry about.
230 Do you want to remove gif support? [Y/n]
235 delete $formats{'gif'};
236 delete $formats{'ungif'};
241 for my $frm (qw(gif ungif)) {
242 checkformat($frm) if ($MANUAL and $formats{$frm});
246 for my $frm (grep $formats{$_}, qw(gif ungif)) {
247 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
251 FILES: for my $dir (@dirs) {
252 my $h = "$dir/gif_lib.h";
253 open H, "< $h" or next;
255 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
265 # we need the version in a #ifdefable form
267 push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ];
268 push @defines, [ IM_GIFMINOR, $minor ];
275 # print "checking path $path\n";
276 if ( !opendir(DH,$path) ) {
277 warn "Cannot open dir $path: $!\n";
280 my @l=grep { $chk->($_) } readdir(DH);
283 return map $path, @l;
290 my $code = $formats{$frm}{'code'};
291 if ($code && !$noprobe) {
292 return 1 if $code->($formats{$frm}, $frm);
295 my $libchk=$formats{$frm}{'libcheck'};
296 my $incchk=$formats{$frm}{'inccheck'};
300 push(@l, gd($lp,$libchk));
305 push(@i, $ip) if $incchk->($ip,$frm);
308 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
309 $formats{$frm}{incdir} = \@i;
310 $formats{$frm}{libdir} = \@l;
311 return scalar(@i && @l);
318 print " Include paths:\n";
319 for (@incs) { print $_,"\n"; }
321 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
324 print "\nLibrary paths:\n";
325 for (@incs) { print $_,"\n"; }
327 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
332 # Format data initialization
334 # format definition is:
336 # default include path
337 # files needed for include (boolean perl code)
340 # files needed for link (boolean perl code)
341 # object files needed for the format
346 @definc{'/usr/include'}=();
347 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
348 map { split /\Q$Config{path_sep}/} @incpaths );
349 if ($Config{locincpth}) {
350 push @incs, grep -d, split ' ', $Config{locincpth};
352 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
353 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
357 /usr/include/freetype2
358 /usr/local/include/freetype2
359 /usr/local/include/freetype1/freetype
360 /usr/include /usr/local/include /usr/include/freetype
361 /usr/local/include/freetype);
363 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
364 map { split /\Q$Config{path_sep}/} @libpaths );
365 if ($Config{loclibpth}) {
366 push @libs, grep -d, split ' ', $Config{loclibpth};
368 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
369 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
370 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
372 if ($^O eq 'cygwin') {
373 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
374 push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api';
377 my $lext=$Config{'so'}; # Get extensions of libraries
378 my $aext=$Config{'_a'};
383 inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
384 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
388 In order to use jpeg with this module you need to have libjpeg
389 installed on your computer}
395 inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
396 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
400 In order to use tiff with this module you need to have libtiff
401 installed on your computer}
407 inccheck=>sub { -e catfile($_[0], 'png.h') },
408 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
409 libfiles=>'-lpng -lz',
412 Png stands for Portable Network Graphics and is intended as
413 a replacement for gif on the web. It is patent free and
414 is recommended by the w3c, you need libpng to use these formats},
421 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
422 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
426 gif is the de facto standard for webgraphics at the moment,
427 it does have some patent problems. If you have giflib and
428 are not in violation with the unisys patent you should use
429 this instead of the 'ungif' option. Note that they cannot
430 be in use at the same time}
436 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
437 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
441 gif is the de facto standard for webgraphics at the moment,
442 it does have some patent problems. If you have libungif and
443 want to create images free from LZW patented compression you
444 should use this option instead of the 'gif' option}
447 $formats{'T1-fonts'}={
450 inccheck=>sub { -e catfile($_[0], 't1lib.h') },
451 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
455 postscript t1 fonts are scalable fonts. They can include
456 ligatures and kerning information and generally yield good
457 visual quality. We depend on libt1 to rasterize the fonts
461 $formats{'TT-fonts'}=
465 inccheck=>sub { -e catfile($_[0], 'freetype.h')
466 && !-e catfile($_[0], 'fterrors.h') },
467 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
471 Truetype fonts are scalable fonts. They can include
472 kerning and hinting information and generally yield good
473 visual quality esp on low resultions. The freetype library is
474 used to rasterize for us. The only drawback is that there
475 are alot of badly designed fonts out there.}
480 inccheck=>sub { -e catfile($_[0], 'windows.h') },
481 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
482 || lc $_[0] eq 'libgdi32.a' },
483 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
486 Uses the Win32 GDI for rendering text.
488 This currently only works on under normal Win32 and cygwin.
491 $formats{'freetype2'} = {
494 inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
495 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
496 libfiles=>'-lfreetype',
497 objfiles=>'freetyp2.o',
499 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
500 scalable. It also supports a variety of other fonts.
502 code => \&freetype2_probe,
505 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
512 defined($V) ? $V : "";
516 # Get information from environment variables
528 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
538 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
540 if ($NOLOG) { print "Logging not compiled into module\n"; }
542 push @defines, [ IMAGER_LOG => 1, "Logging system" ];
546 push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
547 print "Malloc debugging enabled\n";
555 open CONFIG, "> imconfig.h"
556 or die "Cannot create imconfig.h: $!\n";
558 /* This file is automatically generated by Makefile.PL.
559 Don't edit this file, since any changes will be lost */
561 #ifndef IMAGER_IMCONFIG_H
562 #define IMAGER_IMCONFIG_H
564 for my $define (@$defines) {
566 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
568 print CONFIG "#define $define->[0] $define->[1]\n";
570 print CONFIG "\n#endif\n";
574 # use pkg-config to probe for libraries
575 # works around the junk that pkg-config dumps on FreeBSD
579 is_exe('pkg-config') or return;
581 my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null';
583 !system("pkg-config $pkg --exists $redir");
586 # probes for freetype2 by trying to run freetype-config
587 sub freetype2_probe {
588 my ($frm, $frmkey) = @_;
590 is_exe('freetype-config') or return;
592 my $cflags = `freetype-config --cflags`
596 $frm->{cflags} = $cflags;
597 my $lflags = `freetype-config --libs`
600 $frm->{libfiles} = $lflags;
602 printf "%10s: configured via freetype-config\n", $frmkey;
607 # probes for libpng via pkg-config
609 my ($frm, $frmkey) = @_;
611 is_exe('pkg-config') or return;
614 for my $check_conf (qw(libpng libpng12 libpng10)) {
615 if (_pkg_probe($check_conf)) {
616 $config = $check_conf;
622 my $cflags = `pkg-config $config --cflags`
625 my $lflags = `pkg-config $config --libs`
630 $frm->{cflags} = $cflags;
631 $frm->{libfiles} = $lflags;
633 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
639 return File::Spec->catfile(@_);
645 for my $dir (File::Spec->path) {
646 -x catfile($dir, "$name$Config{_exe}")
655 Usage: $0 [--enable feature1,feature2,...] [--incpath ...] [--libpath ...]
656 $0 [--disable feature1,feature2,...] [--incpath ...] [--libpath ...]
658 Possible feature names are:
659 png gif ungif jpeg tiff T1-fonts TT-fonts freetype2