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