2 use ExtUtils::MakeMaker;
8 # IM_INCPATH colon seperated list of paths to extra include paths
9 # IM_LIBPATH colon seperated list of paths to extra library paths
11 # IM_VERBOSE turns on verbose mode for the library finding and such
12 # IM_MANUAL to manually select which libraries are used and which not
13 # IM_ENABLE to programmatically select which libraries are used
15 # IM_NOLOG if true logging will not be compiled into the module
16 # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
17 # do not use IM_DEBUG_MALLOC in production - this slows
18 # everything down by alot
19 # IM_CFLAGS Extra flags to pass to the compiler
20 # IM_LFLAGS Extra flags to pass to the linker
21 # IM_DFLAGS Extra flags to pass to the preprocessor
22 # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
25 getenv(); # get environment variables
26 init(); # initialize global data
27 pathcheck(); # Check if directories exist
29 # Pick what libraries are used
34 if (exists $ENV{IM_ENABLE}) {
35 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
36 for my $key (keys %formats) {
37 delete $formats{$key} unless $en{$key};
42 # Make sure there isn't a clash between the gif libraries.
46 for $frm(values %formats) {
47 $F_DEFINE .= ' -D'.$frm->{def};
48 $F_LIBS .= ' ' .$frm->{libfiles};
49 $F_OBJECT .= ' ' .$frm->{objfiles};
50 $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags};
53 $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
54 grep !exists $definc{$_}, @incs;
55 $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS;
60 if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
61 if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
63 @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o
64 log.o gaussian.o conv.o pnm.o raw.o feat.o font.o
65 filters.o dynaload.o stackmach.o datatypes.o
66 regmach.o trans2.o quant.o error.o convert.o
67 map.o tags.o palimg.o maskimg.o img16.o rotate.o
68 bmp.o tga.o rgb.o color.o fills.o imgdouble.o);
72 'VERSION_FROM' => 'Imager.pm',
73 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
74 'DEFINE' => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS",
75 'INC' => "$lib_cflags $DFLAGS $F_INC",
76 'OBJECT' => join(' ', @objs, $F_OBJECT),
77 clean => { FILES=>'testout' },
80 if ($ExtUtils::MakeMaker::VERSION > 6.06) {
81 $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson';
82 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
84 if ($ExtUtils::MakeMaker::VERSION > 6.10) {
88 if ($VERBOSE) { print Dumper(\%opts); }
89 mkdir('testout',0777); # since we cannot include it in the archive.
97 dyntest.$(MYEXTLIB) : dynfilt/Makefile
98 cd dynfilt && $(MAKE) $(PASTHRU)
100 lib/Imager/Regops.pm : regmach.h regops.perl
101 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
105 # manual configuration of helper libraries
110 Please answer the following questions about
111 which formats are avaliable on your computer
113 press <return> to continue
116 <STDIN>; # eat one return
118 for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
120 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
121 print "Enable $frm support: ";
124 if ($gz =~ m/^(y|yes|n|no)/i) {
125 $gz=substr(lc($gz),0,1);
127 delete $formats{$frm};
134 # automatic configuration of helper libraries
137 for $frm(keys %formats) {
138 delete $formats{$frm} if !checkformat($frm);
144 if ($formats{'gif'} and $formats{'ungif'}) {
145 print "ungif and gif can not coexist - removing ungif support\n";
146 delete $formats{'ungif'};
150 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
153 You have libgif or libungif installed. They are both known to have
154 bugs. Imager can crash or display other strange behaviour after
155 reading or writing gif images. Some of the gif tests can even fail
156 since they stress some parts of the buggy code.
158 libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
159 patch to have all the bugs fixed, see README for details.
161 Of course it's possible your operating system distributor has patched
162 all of these problems and you have nothing to worry about.
164 Do you want to remove gif support? [Y/n]
169 delete $formats{'gif'};
170 delete $formats{'ungif'};
175 for my $frm (qw(gif ungif)) {
176 checkformat($frm) if ($MANUAL and $formats{$frm});
180 for my $frm (grep $formats{$_}, qw(gif ungif)) {
181 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
185 FILES: for my $dir (@dirs) {
186 my $h = "$dir/gif_lib.h";
187 open H, "< $h" or next;
189 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
199 # we need the version in a #ifdefable form
201 $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor";
208 # print "checking path $path\n";
209 if ( !opendir(DH,$path) ) {
210 warn "Cannot open dir $path: $!\n";
213 my @l=grep { $chk->($_) } readdir(DH);
216 return map $path, @l;
223 my $code = $formats{$frm}{'code'};
225 return 1 if $code->($formats{$frm}, $frm);
228 my $libchk=$formats{$frm}{'libcheck'};
229 my $incchk=$formats{$frm}{'inccheck'};
233 push(@l, gd($lp,$libchk));
238 push(@i, gd($ip,$incchk));
241 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
242 $formats{$frm}{incdir} = \@i;
243 $formats{$frm}{libdir} = \@l;
244 return scalar(@i && @l);
253 print " Include paths:\n";
254 for (@incs) { print $_,"\n"; }
256 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
259 print "\nLibrary paths:\n";
260 for (@incs) { print $_,"\n"; }
262 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
267 # Format data initialization
269 # format definition is:
271 # default include path
272 # files needed for include (boolean perl code)
275 # files needed for link (boolean perl code)
276 # object files needed for the format
281 @definc{'/usr/include'}=();
282 @incs=(split(/\Q$Config{path_sep}/, $INCPATH));
283 if ($Config{locincpth}) {
284 push @incs, grep -d, split ' ', $Config{locincpth};
286 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
287 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
291 /usr/include/freetype2
292 /usr/local/include/freetype2
293 /usr/local/include/freetype1/freetype
294 /usr/include /usr/local/include /usr/include/freetype
295 /usr/local/include/freetype);
297 @libs= split(/\Q$Config{path_sep}/,$LIBPATH);
298 if ($Config{loclibpth}) {
299 push @libs, grep -d, split ' ', $Config{loclibpth};
301 push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'});
302 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
303 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
305 if ($^O eq 'cygwin') {
306 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
307 push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api';
310 my $lext=$Config{'so'}; # Get extensions of libraries
311 my $aext=$Config{'_a'};
316 inccheck=>sub { $_[0] eq 'jpeglib.h' },
317 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
321 In order to use jpeg with this module you need to have libjpeg
322 installed on your computer}
328 inccheck=>sub { $_[0] eq 'tiffio.h' },
329 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
333 In order to use tiff with this module you need to have libtiff
334 installed on your computer}
340 inccheck=>sub { $_[0] eq 'png.h' },
341 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
342 libfiles=>'-lpng -lz',
345 Png stands for Portable Network Graphics and is intended as
346 a replacement for gif on the web. It is patent free and
347 is recommended by the w3c, you need libpng to use these formats},
354 inccheck=>sub { $_[0] eq 'gif_lib.h' },
355 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
359 gif is the de facto standard for webgraphics at the moment,
360 it does have some patent problems. If you have giflib and
361 are not in violation with the unisys patent you should use
362 this instead of the 'ungif' option. Note that they cannot
363 be in use at the same time}
369 inccheck=>sub { $_[0] eq 'gif_lib.h' },
370 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
374 gif is the de facto standard for webgraphics at the moment,
375 it does have some patent problems. If you have libungif and
376 want to create images free from LZW patented compression you
377 should use this option instead of the 'gif' option}
380 $formats{'T1-fonts'}={
383 inccheck=>sub { $_[0] eq 't1lib.h' },
384 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
388 postscript t1 fonts are scalable fonts. They can include
389 ligatures and kerning information and generally yield good
390 visual quality. We depend on libt1 to rasterize the fonts
394 $formats{'TT-fonts'}={
397 inccheck=>sub { $_[0] eq 'freetype.h' },
398 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
402 Truetype fonts are scalable fonts. They can include
403 kerning and hinting information and generally yield good
404 visual quality esp on low resultions. The freetype library is
405 used to rasterize for us. The only drawback is that there
406 are alot of badly designed fonts out there.}
411 inccheck=>sub { lc $_[0] eq 'windows.h' },
412 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
413 || lc $_[0] eq 'libgdi32.a' },
414 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
417 Uses the Win32 GDI for rendering text.
419 This currently only works on under normal Win32 and cygwin.
422 $formats{'freetype2'} = {
425 inccheck=>sub { lc $_[0] eq 'ft2build.h' },
426 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
427 libfiles=>'-lfreetype',
428 objfiles=>'freetyp2.o',
430 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
433 code => \&freetype2_probe,
436 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
443 defined($V) ? $V : "";
447 # Get information from environment variables
459 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
469 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
471 if ($NOLOG) { print "Logging not compiled into module\n"; }
472 else { $EXTDEF.=' -DIMAGER_LOG'; }
475 $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
476 print "Malloc debugging enabled\n";
481 # probes for freetype2 by trying to run freetype-config
482 sub freetype2_probe {
483 my ($frm, $frmkey) = @_;
485 is_exe('freetype-config') or return;
487 my $cflags = `freetype-config --cflags`
491 $frm->{cflags} = $cflags;
492 my $lflags = `freetype-config --libs`
495 $frm->{libfiles} = $lflags;
497 printf "%10s: configured via freetype-config\n", $frmkey;
502 # probes for libpng via pkg-config
504 my ($frm, $frmkey) = @_;
506 is_exe('pkg-config') or return;
510 for my $check_conf (qw(libpng libpng12 libpng10)) {
511 $cflags = `pkg-config $check_conf --cflags`;
512 if ($cflags && !$?) {
513 $config = $check_conf;
519 my $lflags = `pkg-config $config --libs`
524 $frm->{cflags} = $cflags;
525 $frm->{libfiles} = $lflags;
527 printf "%10s: configured via `pkg-config $config ...`\n", $frmkey;
533 return File::Spec->catfile(@_);
539 for my $dir (File::Spec->path) {
540 -x catfile($dir, "$name$Config{_exe}")