2 use ExtUtils::MakeMaker;
6 $lext=$Config{'so'}; # Get extensions of libraries
10 # IM_INCPATH colon seperated list of paths to extra include paths
11 # IM_LIBPATH colon seperated list of paths to extra library paths
13 # IM_VERBOSE turns on verbose mode for the library finding and such
14 # IM_MANUAL to manually select which libraries are used and which not
15 # IM_ENABLE to programmatically select which libraries are used
17 # IM_NOLOG if true logging will not be compiled into the module
18 # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module
19 # do not use IM_DEBUG_MALLOC in production - this slows
20 # everything down by alot
21 # IM_CFLAGS Extra flags to pass to the compiler
22 # IM_LFLAGS Extra flags to pass to the linker
23 # IM_DFLAGS Extra flags to pass to the preprocessor
24 # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
27 getenv(); # get environment variables
28 init(); # initialize global data
29 pathcheck(); # Check if directories exist
31 # Pick what libraries are used
36 if (exists $ENV{IM_ENABLE}) {
37 my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE};
38 for my $key (keys %formats) {
39 delete $formats{$key} unless $en{$key};
44 # Make sure there isn't a clash between the gif libraries.
47 for $frm(values %formats) {
48 $F_DEFINE .= ' -D'.$frm->{def};
49 $F_LIBS .= ' ' .$frm->{libfiles};
50 $F_OBJECT .= ' ' .$frm->{objfiles};
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' => "$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 $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;
222 my $libchk=$formats{$frm}{'libcheck'};
223 my $incchk=$formats{$frm}{'inccheck'};
227 push(@l, gd($lp,$libchk));
232 push(@i, gd($ip,$incchk));
235 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
236 $formats{$frm}{incdir} = \@i;
237 $formats{$frm}{libdir} = \@l;
238 return scalar(@i && @l);
247 print " Include paths:\n";
248 for (@incs) { print $_,"\n"; }
250 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
253 print "\nLibrary paths:\n";
254 for (@incs) { print $_,"\n"; }
256 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
261 # Format data initialization
263 # format definition is:
265 # default include path
266 # files needed for include (boolean perl code)
269 # files needed for link (boolean perl code)
270 # object files needed for the format
275 @definc{'/usr/include'}=();
276 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
277 qw(/sw/include /usr/include/freetype2 /usr/local/include/freetype2
278 /usr/include /usr/local/include /usr/include/freetype
279 /usr/local/include/freetype));
280 @libs=(split(/\Q$Config{path_sep}/,$LIBPATH),
281 qw(/sw/lib), split(/ /, $Config{'libpth'}));
282 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
283 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
284 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
286 if ($^O eq 'cygwin') {
287 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
288 push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api';
294 inccheck=>sub { $_[0] eq 'jpeglib.h' },
295 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
299 In order to use jpeg with this module you need to have libjpeg
300 installed on your computer}
306 inccheck=>sub { $_[0] eq 'tiffio.h' },
307 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
311 In order to use tiff with this module you need to have libtiff
312 installed on your computer}
318 inccheck=>sub { $_[0] eq 'png.h' },
319 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
320 libfiles=>'-lpng -lz',
323 Png stands for Portable Network Graphics and is intended as
324 a replacement for gif on the web. It is patent free and
325 is recommended by the w3c, you need libpng to use these formats}
331 inccheck=>sub { $_[0] eq 'gif_lib.h' },
332 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
336 gif is the de facto standard for webgraphics at the moment,
337 it does have some patent problems. If you have giflib and
338 are not in violation with the unisys patent you should use
339 this instead of the 'ungif' option. Note that they cannot
340 be in use at the same time}
346 inccheck=>sub { $_[0] eq 'gif_lib.h' },
347 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
351 gif is the de facto standard for webgraphics at the moment,
352 it does have some patent problems. If you have libungif and
353 want to create images free from LZW patented compression you
354 should use this option instead of the 'gif' option}
357 $formats{'T1-fonts'}={
360 inccheck=>sub { $_[0] eq 't1lib.h' },
361 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
365 postscript t1 fonts are scalable fonts. They can include
366 ligatures and kerning information and generally yield good
367 visual quality. We depend on libt1 to rasterize the fonts
371 $formats{'TT-fonts'}={
374 inccheck=>sub { $_[0] eq 'freetype.h' },
375 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
379 Truetype fonts are scalable fonts. They can include
380 kerning and hinting information and generally yield good
381 visual quality esp on low resultions. The freetype library is
382 used to rasterize for us. The only drawback is that there
383 are alot of badly designed fonts out there.}
388 inccheck=>sub { lc $_[0] eq 'windows.h' },
389 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
390 || lc $_[0] eq 'libgdi32.a' },
391 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
394 Uses the Win32 GDI for rendering text.
396 This currently only works on under normal Win32 and cygwin.
399 $formats{'freetype2'} = {
402 inccheck=>sub { lc $_[0] eq 'ft2build.h' },
403 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
404 libfiles=>'-lfreetype',
405 objfiles=>'freetyp2.o',
407 Freetype 2 supports both Truetype and Type 1 fonts, both of which are
412 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
419 defined($V) ? $V : "";
423 # Get information from environment variables
435 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
445 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
447 if ($NOLOG) { print "Logging not compiled into module\n"; }
448 else { $EXTDEF.=' -DIMAGER_LOG'; }
451 $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
452 print "Malloc debugging enabled\n";