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.
80 for my $frmkey (keys %formats) {
81 my $frm = $formats{$frmkey};
82 push @defines, [ $frm->{def}, 1, "$frmkey available" ];
83 $F_LIBS .= ' ' .$frm->{libfiles};
84 $F_OBJECT .= ' ' .$frm->{objfiles};
85 $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags};
88 $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
89 grep !exists $definc{$_}, @incs;
90 $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS;
95 if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
96 if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
98 @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
99 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
100 filters.o dynaload.o stackmach.o datatypes.o
101 regmach.o trans2.o quant.o error.o convert.o
102 map.o tags.o palimg.o maskimg.o img16.o rotate.o
103 bmp.o tga.o rgb.o color.o fills.o imgdouble.o);
107 'VERSION_FROM' => 'Imager.pm',
108 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
109 'DEFINE' => "$OSDEF $CFLAGS",
110 'INC' => "$lib_cflags $DFLAGS $F_INC",
111 'OBJECT' => join(' ', @objs, $F_OBJECT),
112 clean => { FILES=>'testout' },
115 if ($ExtUtils::MakeMaker::VERSION > 6.06) {
116 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
117 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
119 if ($ExtUtils::MakeMaker::VERSION > 6.10) {
123 make_imconfig(\@defines);
125 if ($VERBOSE) { print Dumper(\%opts); }
126 mkdir('testout',0777); # since we cannot include it in the archive.
127 WriteMakefile(%opts);
134 dyntest.$(MYEXTLIB) : dynfilt/Makefile
135 cd dynfilt && $(MAKE) $(PASTHRU)
137 lib/Imager/Regops.pm : regmach.h regops.perl
138 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
140 imconfig.h: Makefile.PL
141 $(ECHO) "imconfig.h out-of-date with respect to $?"
142 $(PERLRUN) Makefile.PL
143 $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <=="
147 # manual configuration of helper libraries
152 Please answer the following questions about
153 which formats are avaliable on your computer
155 press <return> to continue
158 <STDIN>; # eat one return
160 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
162 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
163 print "Enable $frm support: ";
166 if ($gz =~ m/^(y|yes|n|no)/i) {
167 $gz=substr(lc($gz),0,1);
169 delete $formats{$frm};
176 # automatic configuration of helper libraries
179 for $frm(keys %formats) {
180 delete $formats{$frm} if !checkformat($frm);
186 if ($formats{'gif'} and $formats{'ungif'}) {
187 print "ungif and gif can not coexist - removing ungif support\n";
188 delete $formats{'ungif'};
192 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
195 You have libgif or libungif installed. They are both known to have
196 bugs. Imager can crash or display other strange behaviour after
197 reading or writing gif images. Some of the gif tests can even fail
198 since they stress some parts of the buggy code.
200 libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
201 patch to have all the bugs fixed, see README for details.
203 Of course it's possible your operating system distributor has patched
204 all of these problems and you have nothing to worry about.
206 Do you want to remove gif support? [Y/n]
211 delete $formats{'gif'};
212 delete $formats{'ungif'};
217 for my $frm (qw(gif ungif)) {
218 checkformat($frm) if ($MANUAL and $formats{$frm});
222 for my $frm (grep $formats{$_}, qw(gif ungif)) {
223 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
227 FILES: for my $dir (@dirs) {
228 my $h = "$dir/gif_lib.h";
229 open H, "< $h" or next;
231 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
241 # we need the version in a #ifdefable form
243 push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ];
244 push @defines, [ IM_GIFMINOR, $minor ];
251 # print "checking path $path\n";
252 if ( !opendir(DH,$path) ) {
253 warn "Cannot open dir $path: $!\n";
256 my @l=grep { $chk->($_) } readdir(DH);
259 return map $path, @l;
266 my $code = $formats{$frm}{'code'};
267 if ($code && !$noprobe) {
268 return 1 if $code->($formats{$frm}, $frm);
271 my $libchk=$formats{$frm}{'libcheck'};
272 my $incchk=$formats{$frm}{'inccheck'};
276 push(@l, gd($lp,$libchk));
281 push(@i, $ip) if $incchk->($ip,$frm);
284 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
285 $formats{$frm}{incdir} = \@i;
286 $formats{$frm}{libdir} = \@l;
287 return scalar(@i && @l);
294 print " Include paths:\n";
295 for (@incs) { print $_,"\n"; }
297 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
300 print "\nLibrary paths:\n";
301 for (@incs) { print $_,"\n"; }
303 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
308 # Format data initialization
310 # format definition is:
312 # default include path
313 # files needed for include (boolean perl code)
316 # files needed for link (boolean perl code)
317 # object files needed for the format
322 @definc{'/usr/include'}=();
323 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
324 map { split /\Q$Config{path_sep}/} @incpaths );
325 if ($Config{locincpth}) {
326 push @incs, grep -d, split ' ', $Config{locincpth};
328 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
329 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
333 /usr/include/freetype2
334 /usr/local/include/freetype2
335 /usr/local/include/freetype1/freetype
336 /usr/include /usr/local/include /usr/include/freetype
337 /usr/local/include/freetype);
339 @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
340 map { split /\Q$Config{path_sep}/} @libpaths );
341 if ($Config{loclibpth}) {
342 push @libs, grep -d, split ' ', $Config{loclibpth};
344 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
345 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
346 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
348 if ($^O eq 'cygwin') {
349 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
350 push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api';
353 my $lext=$Config{'so'}; # Get extensions of libraries
354 my $aext=$Config{'_a'};
359 inccheck=>sub { -e catfile($_[0], 'jpeglib.h') },
360 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
364 In order to use jpeg with this module you need to have libjpeg
365 installed on your computer}
371 inccheck=>sub { -e catfile($_[0], 'tiffio.h') },
372 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
376 In order to use tiff with this module you need to have libtiff
377 installed on your computer}
383 inccheck=>sub { -e catfile($_[0], 'png.h') },
384 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
385 libfiles=>'-lpng -lz',
388 Png stands for Portable Network Graphics and is intended as
389 a replacement for gif on the web. It is patent free and
390 is recommended by the w3c, you need libpng to use these formats},
397 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
398 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
402 gif is the de facto standard for webgraphics at the moment,
403 it does have some patent problems. If you have giflib and
404 are not in violation with the unisys patent you should use
405 this instead of the 'ungif' option. Note that they cannot
406 be in use at the same time}
412 inccheck=>sub { -e catfile($_[0], 'gif_lib.h') },
413 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
417 gif is the de facto standard for webgraphics at the moment,
418 it does have some patent problems. If you have libungif and
419 want to create images free from LZW patented compression you
420 should use this option instead of the 'gif' option}
423 $formats{'T1-fonts'}={
426 inccheck=>sub { -e catfile($_[0], 't1lib.h') },
427 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
431 postscript t1 fonts are scalable fonts. They can include
432 ligatures and kerning information and generally yield good
433 visual quality. We depend on libt1 to rasterize the fonts
437 $formats{'TT-fonts'}=
441 inccheck=>sub { -e catfile($_[0], 'freetype.h')
442 && !-e catfile($_[0], 'fterrors.h') },
443 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
447 Truetype fonts are scalable fonts. They can include
448 kerning and hinting information and generally yield good
449 visual quality esp on low resultions. The freetype library is
450 used to rasterize for us. The only drawback is that there
451 are alot of badly designed fonts out there.}
456 inccheck=>sub { -e catfile($_[0], 'windows.h') },
457 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
458 || lc $_[0] eq 'libgdi32.a' },
459 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
462 Uses the Win32 GDI for rendering text.
464 This currently only works on under normal Win32 and cygwin.
467 $formats{'freetype2'} = {
470 inccheck=>sub { -e catfile($_[0], 'ft2build.h') },
471 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
472 libfiles=>'-lfreetype',
473 objfiles=>'freetyp2.o',
475 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
476 scalable. It also supports a variety of other fonts.
478 code => \&freetype2_probe,
481 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
488 defined($V) ? $V : "";
492 # Get information from environment variables
504 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
514 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
516 if ($NOLOG) { print "Logging not compiled into module\n"; }
518 push @defines, [ IMAGER_LOG => 1, "Logging system" ];
522 push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ];
523 print "Malloc debugging enabled\n";
531 open CONFIG, "> imconfig.h"
532 or die "Cannot create imconfig.h: $!\n";
534 /* This file is automatically generated by Makefile.PL.
535 Don't edit this file, since any changes will be lost */
537 #ifndef IMAGER_IMCONFIG_H
538 #define IMAGER_IMCONFIG_H
540 for my $define (@$defines) {
542 print CONFIG "\n/*\n $define->[2]\n*/\n\n";
544 print CONFIG "#define $define->[0] $define->[1]\n";
546 print CONFIG "\n#endif\n";
550 # probes for freetype2 by trying to run freetype-config
551 sub freetype2_probe {
552 my ($frm, $frmkey) = @_;
554 is_exe('freetype-config') or return;
556 my $cflags = `freetype-config --cflags`
560 $frm->{cflags} = $cflags;
561 my $lflags = `freetype-config --libs`
564 $frm->{libfiles} = $lflags;
566 printf "%10s: configured via freetype-config\n", $frmkey;
571 # probes for libpng via pkg-config
573 my ($frm, $frmkey) = @_;
575 is_exe('pkg-config') or return;
579 for my $check_conf (qw(libpng libpng12 libpng10)) {
580 $cflags = `pkg-config $check_conf --cflags`;
581 if ($cflags && !$?) {
582 $config = $check_conf;
588 my $lflags = `pkg-config $config --libs`
593 $frm->{cflags} = $cflags;
594 $frm->{libfiles} = $lflags;
596 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
602 return File::Spec->catfile(@_);
608 for my $dir (File::Spec->path) {
609 -x catfile($dir, "$name$Config{_exe}")
618 Usage: $0 [--enable feature1,feature2,...] [--incpath ...] [--libpath ...]
619 $0 [--disable feature1,feature2,...] [--incpath ...] [--libpath ...]
621 Possible feature names are:
622 png gif ungif jpeg tiff T1-fonts TT-fonts freetype2