update information about giflib bugs
[imager.git] / Makefile.PL
CommitLineData
ea9e6c3f 1#!perl -w
02d1d628
AMH
2use ExtUtils::MakeMaker;
3use Cwd;
4use Config;
5
6$lext=$Config{'so'}; # Get extensions of libraries
88a763e2 7$aext=$Config{'_a'};
02d1d628
AMH
8
9#
10# IM_INCPATH colon seperated list of paths to extra include paths
11# IM_LIBPATH colon seperated list of paths to extra library paths
12#
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
16# and which are not
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
f4dbac50 24# IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support
02d1d628
AMH
25
26
27getenv(); # get environment variables
28init(); # initialize global data
29pathcheck(); # Check if directories exist
30
31# Pick what libraries are used
32if ($MANUAL) {
33 manual();
34} else {
35 automatic();
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};
40 }
41 }
42}
43
44# Make sure there isn't a clash between the gif libraries.
45gifcheck();
46
47for $frm(values %formats) {
48 $F_DEFINE .= ' -D'.$frm->{def};
49 $F_LIBS .= ' ' .$frm->{libfiles};
50 $F_OBJECT .= ' ' .$frm->{objfiles};
51}
52
ea9e6c3f
TC
53$F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_,
54 grep !exists $definc{$_}, @incs;
55$F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS;
02d1d628
AMH
56
57$OSLIBS = '';
58$OSDEF = "-DOS_$^O";
59
60if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; }
61if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; }
62
9982a307
AMH
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
02d1d628 65 filters.o dynaload.o stackmach.o datatypes.o
2df3535a 66 regmach.o trans2.o quant.o error.o convert.o
261f91c5 67 map.o tags.o palimg.o maskimg.o img16.o rotate.o
737a830c 68 bmp.o tga.o rgb.o color.o fills.o imgdouble.o);
02d1d628
AMH
69
70%opts=(
71 'NAME' => 'Imager',
72 'VERSION_FROM' => 'Imager.pm',
73 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS",
74 'DEFINE' => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS",
75 'INC' => "$DFLAGS $F_INC",
de2b8bae
TC
76 'OBJECT' => join(' ', @objs, $F_OBJECT),
77 clean => { FILES=>'testout' },
7ac6a2e9 78 'NO_META' => 1,
02d1d628
AMH
79 );
80
ca508100
TC
81if ($] ge '5.005') {
82 $opts{AUTHOR} = 'Arnar M. Hrafnkelsson, addi@umich.edu';
83 $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images';
84}
85
02d1d628
AMH
86if ($VERBOSE) { print Dumper(\%opts); }
87mkdir('testout',0777); # since we cannot include it in the archive.
88WriteMakefile(%opts);
4dce694d 89
02d1d628
AMH
90exit;
91
92
93sub MY::postamble {
94'
faa9b3e7 95dyntest.$(MYEXTLIB) : dynfilt/Makefile
02d1d628
AMH
96 cd dynfilt && $(MAKE) $(PASTHRU)
97
98lib/Imager/Regops.pm : regmach.h regops.perl
99 $(PERL) regops.perl regmach.h lib/Imager/Regops.pm
100';
101}
102
103# manual configuration of helper libraries
104
105sub manual {
106 print <<EOF;
107
108 Please answer the following questions about
109 which formats are avaliable on your computer
110
111press <return> to continue
112EOF
113
114 <STDIN>; # eat one return
115
116 for $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) {
117 SWX:
118 if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; }
119 print "Enable $frm support: ";
09fd3468 120 $gz = <STDIN>;
02d1d628
AMH
121 chomp($gz);
122 if ($gz =~ m/^(y|yes|n|no)/i) {
123 $gz=substr(lc($gz),0,1);
124 if ($gz eq 'n') {
125 delete $formats{$frm};
126 }
127 } else { goto SWX; }
128 }
129}
130
131
132# automatic configuration of helper libraries
133
134sub automatic {
135 for $frm(keys %formats) {
136 delete $formats{$frm} if !checkformat($frm);
137 }
138}
139
140
141sub gifcheck {
5f5fe73e 142 if ($formats{'gif'} and $formats{'ungif'}) {
02d1d628
AMH
143 print "ungif and gif can not coexist - removing ungif support\n";
144 delete $formats{'ungif'};
145 }
5f5fe73e
AMH
146
147 RETR:
f4dbac50 148 if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) {
5f5fe73e
AMH
149 print <<EOFF;
150
151You have libgif or libungif installed. They are both known to have
152bugs. Imager can crash or display other strange behaviour after
153reading or writing gif images. Some of the gif tests can even fail
154since they stress some parts of the buggy code.
155
f1967c11
TC
156libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one
157patch to have all the bugs fixed, see README for details.
158
159Of course it's possible your operating system distributor has patched
160all of these problems and you have nothing to worry about.
0b836ff8 161
5f5fe73e
AMH
162Do you want to remove gif support? [Y/n]
163EOFF
164 my $resp = <STDIN>;
165 chomp($resp);
166 if ($resp ne "n") {
167 delete $formats{'gif'};
168 delete $formats{'ungif'};
09fd3468 169 return;
5f5fe73e
AMH
170 }
171 }
09fd3468
AMH
172
173 for my $frm (qw(gif ungif)) {
174 checkformat($frm) if ($MANUAL and $formats{$frm});
175 }
176
02d1d628
AMH
177 my @dirs;
178 for my $frm (grep $formats{$_}, qw(gif ungif)) {
179 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
180 }
181 my $minor = 0;
182 my $major = 0;
183 FILES: for my $dir (@dirs) {
184 my $h = "$dir/gif_lib.h";
185 open H, "< $h" or next;
186 while (<H>) {
187 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
188 $major = $1;
189 $minor = $2;
190 close H;
191 last FILES;
192 }
193 }
194 close H;
195 }
196
197 # we need the version in a #ifdefable form
4dce694d 198
02d1d628
AMH
199 $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor";
200}
201
202
203sub gd {
204 my($path,$chk)=@_;
205
206# print "checking path $path\n";
207 if ( !opendir(DH,$path) ) {
208 warn "Cannot open dir $path: $!\n";
209 return;
210 }
211 my @l=grep { $chk->($_) } readdir(DH);
212 # print @l;
213 close(DH);
214 return map $path, @l;
215}
216
217
218sub checkformat {
219 my $frm=shift;
220 my $libchk=$formats{$frm}{'libcheck'};
221 my $incchk=$formats{$frm}{'inccheck'};
222
223 my @l;
224 for my $lp (@libs) {
225 push(@l, gd($lp,$libchk));
226 }
227
228 my @i;
229 for my $ip (@incs) {
230 push(@i, gd($ip,$incchk));
231 }
232
233 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
234 $formats{$frm}{incdir} = \@i;
235 $formats{$frm}{libdir} = \@l;
236 return scalar(@i && @l);
237}
238
239
240
241
242sub pathcheck {
243 if ($VERBOSE) {
244 print "pathcheck\n";
245 print " Include paths:\n";
246 for (@incs) { print $_,"\n"; }
247 }
3a6bb91b 248 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs;
02d1d628
AMH
249
250 if ($VERBOSE) {
251 print "\nLibrary paths:\n";
252 for (@incs) { print $_,"\n"; }
253 }
3a6bb91b 254 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs;
02d1d628
AMH
255 print "\ndone.\n";
256}
257
258
259# Format data initialization
260
261# format definition is:
262# defines needed
263# default include path
264# files needed for include (boolean perl code)
265# default lib path
266# libs needed
267# files needed for link (boolean perl code)
268# object files needed for the format
269
270
271sub init {
272
273 @definc{'/usr/include'}=();
042cdaea
TC
274 @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
275 qw(/sw/include /usr/include/freetype2 /usr/local/include/freetype2
276 /usr/include /usr/local/include /usr/include/freetype
277 /usr/local/include/freetype));
278 @libs=(split(/\Q$Config{path_sep}/,$LIBPATH),
279 qw(/sw/lib), split(/ /, $Config{'libpth'}));
88a763e2
TC
280 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
281 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
282 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
283 }
faa9b3e7
TC
284 if ($^O eq 'cygwin') {
285 push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api';
286 push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api';
287 }
02d1d628
AMH
288
289 $formats{'jpeg'}={
290 order=>'21',
291 def=>'HAVE_LIBJPEG',
292 inccheck=>sub { $_[0] eq 'jpeglib.h' },
50ee6f9c 293 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
02d1d628
AMH
294 libfiles=>'-ljpeg',
295 objfiles=>'jpeg.o',
296 docs=>q{
297 In order to use jpeg with this module you need to have libjpeg
298 installed on your computer}
299 };
300
301 $formats{'tiff'}={
302 order=>'23',
303 def=>'HAVE_LIBTIFF',
304 inccheck=>sub { $_[0] eq 'tiffio.h' },
76c8a0a4 305 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
02d1d628
AMH
306 libfiles=>'-ltiff',
307 objfiles=>'tiff.o',
308 docs=>q{
309 In order to use tiff with this module you need to have libtiff
310 installed on your computer}
311 };
312
313 $formats{'png'}={
314 order=>'22',
315 def=>'HAVE_LIBPNG',
316 inccheck=>sub { $_[0] eq 'png.h' },
88a763e2 317 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
02d1d628
AMH
318 libfiles=>'-lpng -lz',
319 objfiles=>'png.o',
320 docs=>q{
321 Png stands for Portable Network Graphics and is intended as
322 a replacement for gif on the web. It is patent free and
323 is recommended by the w3c, you need libpng to use these formats}
324 };
325
326 $formats{'gif'}={
327 order=>'20',
328 def=>'HAVE_LIBGIF',
329 inccheck=>sub { $_[0] eq 'gif_lib.h' },
e02451e0 330 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
02d1d628
AMH
331 libfiles=>'-lgif',
332 objfiles=>'gif.o',
333 docs=>q{
334 gif is the de facto standard for webgraphics at the moment,
335 it does have some patent problems. If you have giflib and
336 are not in violation with the unisys patent you should use
337 this instead of the 'ungif' option. Note that they cannot
338 be in use at the same time}
339 };
340
341 $formats{'ungif'}={
342 order=>'21',
343 def=>'HAVE_LIBGIF',
344 inccheck=>sub { $_[0] eq 'gif_lib.h' },
e02451e0 345 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
02d1d628
AMH
346 libfiles=>'-lungif',
347 objfiles=>'gif.o',
348 docs=>q{
349 gif is the de facto standard for webgraphics at the moment,
350 it does have some patent problems. If you have libungif and
351 want to create images free from LZW patented compression you
352 should use this option instead of the 'gif' option}
353 };
354
355 $formats{'T1-fonts'}={
356 order=>'30',
357 def=>'HAVE_LIBT1',
358 inccheck=>sub { $_[0] eq 't1lib.h' },
faa9b3e7 359 libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" },
02d1d628
AMH
360 libfiles=>'-lt1',
361 objfiles=>'',
362 docs=>q{
363 postscript t1 fonts are scalable fonts. They can include
364 ligatures and kerning information and generally yield good
365 visual quality. We depend on libt1 to rasterize the fonts
366 for use in images.}
367 };
368
369 $formats{'TT-fonts'}={
370 order=>'31',
371 def=>'HAVE_LIBTT',
372 inccheck=>sub { $_[0] eq 'freetype.h' },
faa9b3e7 373 libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" },
02d1d628
AMH
374 libfiles=>'-lttf',
375 objfiles=>'',
376 docs=>q{
377 Truetype fonts are scalable fonts. They can include
378 kerning and hinting information and generally yield good
379 visual quality esp on low resultions. The freetype library is
380 used to rasterize for us. The only drawback is that there
381 are alot of badly designed fonts out there.}
382 };
faa9b3e7
TC
383 $formats{'w32'} = {
384 order=>40,
385 def=>'HAVE_WIN32',
386 inccheck=>sub { lc $_[0] eq 'windows.h' },
387 libcheck=>sub { lc $_[0] eq 'gdi32.lib'
388 || lc $_[0] eq 'libgdi32.a' },
389 libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
390 objfiles=>'win32.o',
391 docs => <<DOCS
392Uses the Win32 GDI for rendering text.
393
394This currently only works on under normal Win32 and cygwin.
395DOCS
396 };
397 $formats{'freetype2'} = {
398 order=>'29',
399 def=>'HAVE_FT2',
400 inccheck=>sub { lc $_[0] eq 'ft2build.h' },
401 libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" },
402 libfiles=>'-lfreetype',
403 objfiles=>'freetyp2.o',
404 docs=><<DOCS
405Freetype 2 supports both Truetype and Type 1 fonts, both of which are
406scalable.
407DOCS
408 };
02d1d628
AMH
409 # Make fix indent
410 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
411}
412
413
414
415sub gen {
416 my $V = $ENV{$_[0]};
417 defined($V) ? $V : "";
418}
419
420
421# Get information from environment variables
422
423sub getenv {
424
425 ($VERBOSE,
426 $INCPATH,
427 $LIBPATH,
428 $NOLOG,
429 $DEBUG_MALLOC,
430 $MANUAL,
431 $CFLAGS,
432 $LFLAGS,
433 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
434 IM_INCPATH
435 IM_LIBPATH
436 IM_NOLOG
437 IM_DEBUG_MALLOC
438 IM_MANUAL
439 IM_CFLAGS
440 IM_LFLAGS
441 IM_DFLAGS);
442
443 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
444
445 if ($NOLOG) { print "Logging not compiled into module\n"; }
446 else { $EXTDEF.=' -DIMAGER_LOG'; }
447
448 if ($DEBUG_MALLOC) {
449 $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
450 print "Malloc debugging enabled\n";
451 }
452
453}