pointer to a description of how unsharp mask works
[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: ";
09fd3468 116 $gz = <STDIN>;
02d1d628
AMH
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'};
09fd3468 159 return;
5f5fe73e
AMH
160 }
161 }
09fd3468
AMH
162
163 for my $frm (qw(gif ungif)) {
164 checkformat($frm) if ($MANUAL and $formats{$frm});
165 }
166
02d1d628
AMH
167 my @dirs;
168 for my $frm (grep $formats{$_}, qw(gif ungif)) {
169 push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir};
170 }
171 my $minor = 0;
172 my $major = 0;
173 FILES: for my $dir (@dirs) {
174 my $h = "$dir/gif_lib.h";
175 open H, "< $h" or next;
176 while (<H>) {
177 if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) {
178 $major = $1;
179 $minor = $2;
180 close H;
181 last FILES;
182 }
183 }
184 close H;
185 }
186
187 # we need the version in a #ifdefable form
4dce694d 188
02d1d628
AMH
189 $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor";
190}
191
192
193sub gd {
194 my($path,$chk)=@_;
195
196# print "checking path $path\n";
197 if ( !opendir(DH,$path) ) {
198 warn "Cannot open dir $path: $!\n";
199 return;
200 }
201 my @l=grep { $chk->($_) } readdir(DH);
202 # print @l;
203 close(DH);
204 return map $path, @l;
205}
206
207
208sub checkformat {
209 my $frm=shift;
210 my $libchk=$formats{$frm}{'libcheck'};
211 my $incchk=$formats{$frm}{'inccheck'};
212
213 my @l;
214 for my $lp (@libs) {
215 push(@l, gd($lp,$libchk));
216 }
217
218 my @i;
219 for my $ip (@incs) {
220 push(@i, gd($ip,$incchk));
221 }
222
223 printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found'));
224 $formats{$frm}{incdir} = \@i;
225 $formats{$frm}{libdir} = \@l;
226 return scalar(@i && @l);
227}
228
229
230
231
232sub pathcheck {
233 if ($VERBOSE) {
234 print "pathcheck\n";
235 print " Include paths:\n";
236 for (@incs) { print $_,"\n"; }
237 }
238 @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @incs;
239
240 if ($VERBOSE) {
241 print "\nLibrary paths:\n";
242 for (@incs) { print $_,"\n"; }
243 }
244 @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @libs;
245 print "\ndone.\n";
246}
247
248
249# Format data initialization
250
251# format definition is:
252# defines needed
253# default include path
254# files needed for include (boolean perl code)
255# default lib path
256# libs needed
257# files needed for link (boolean perl code)
258# object files needed for the format
259
260
261sub init {
262
263 @definc{'/usr/include'}=();
264 @incs=(qw(/usr/include /usr/local/include /usr/include/freetype /usr/local/include/freetype), split /:/, $INCPATH );
265 @libs=(split(/ /, $Config{'libpth'}), split(/:/, $LIBPATH) );
88a763e2
TC
266 if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) {
267 push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE};
268 push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB};
269 }
02d1d628
AMH
270
271 $formats{'jpeg'}={
272 order=>'21',
273 def=>'HAVE_LIBJPEG',
274 inccheck=>sub { $_[0] eq 'jpeglib.h' },
50ee6f9c 275 libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" },
02d1d628
AMH
276 libfiles=>'-ljpeg',
277 objfiles=>'jpeg.o',
278 docs=>q{
279 In order to use jpeg with this module you need to have libjpeg
280 installed on your computer}
281 };
282
283 $formats{'tiff'}={
284 order=>'23',
285 def=>'HAVE_LIBTIFF',
286 inccheck=>sub { $_[0] eq 'tiffio.h' },
76c8a0a4 287 libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" },
02d1d628
AMH
288 libfiles=>'-ltiff',
289 objfiles=>'tiff.o',
290 docs=>q{
291 In order to use tiff with this module you need to have libtiff
292 installed on your computer}
293 };
294
295 $formats{'png'}={
296 order=>'22',
297 def=>'HAVE_LIBPNG',
298 inccheck=>sub { $_[0] eq 'png.h' },
88a763e2 299 libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" },
02d1d628
AMH
300 libfiles=>'-lpng -lz',
301 objfiles=>'png.o',
302 docs=>q{
303 Png stands for Portable Network Graphics and is intended as
304 a replacement for gif on the web. It is patent free and
305 is recommended by the w3c, you need libpng to use these formats}
306 };
307
308 $formats{'gif'}={
309 order=>'20',
310 def=>'HAVE_LIBGIF',
311 inccheck=>sub { $_[0] eq 'gif_lib.h' },
e02451e0 312 libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" },
02d1d628
AMH
313 libfiles=>'-lgif',
314 objfiles=>'gif.o',
315 docs=>q{
316 gif is the de facto standard for webgraphics at the moment,
317 it does have some patent problems. If you have giflib and
318 are not in violation with the unisys patent you should use
319 this instead of the 'ungif' option. Note that they cannot
320 be in use at the same time}
321 };
322
323 $formats{'ungif'}={
324 order=>'21',
325 def=>'HAVE_LIBGIF',
326 inccheck=>sub { $_[0] eq 'gif_lib.h' },
e02451e0 327 libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" },
02d1d628
AMH
328 libfiles=>'-lungif',
329 objfiles=>'gif.o',
330 docs=>q{
331 gif is the de facto standard for webgraphics at the moment,
332 it does have some patent problems. If you have libungif and
333 want to create images free from LZW patented compression you
334 should use this option instead of the 'gif' option}
335 };
336
337 $formats{'T1-fonts'}={
338 order=>'30',
339 def=>'HAVE_LIBT1',
340 inccheck=>sub { $_[0] eq 't1lib.h' },
341 libcheck=>sub { $_[0] eq 'libt1.a' or $_[0] eq "libt1.$lext" },
342 libfiles=>'-lt1',
343 objfiles=>'',
344 docs=>q{
345 postscript t1 fonts are scalable fonts. They can include
346 ligatures and kerning information and generally yield good
347 visual quality. We depend on libt1 to rasterize the fonts
348 for use in images.}
349 };
350
351 $formats{'TT-fonts'}={
352 order=>'31',
353 def=>'HAVE_LIBTT',
354 inccheck=>sub { $_[0] eq 'freetype.h' },
355 libcheck=>sub { $_[0] eq 'libttf.a' or $_[0] eq "libttf.$lext" },
356 libfiles=>'-lttf',
357 objfiles=>'',
358 docs=>q{
359 Truetype fonts are scalable fonts. They can include
360 kerning and hinting information and generally yield good
361 visual quality esp on low resultions. The freetype library is
362 used to rasterize for us. The only drawback is that there
363 are alot of badly designed fonts out there.}
364 };
365 # Make fix indent
366 for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; }
367}
368
369
370
371sub gen {
372 my $V = $ENV{$_[0]};
373 defined($V) ? $V : "";
374}
375
376
377# Get information from environment variables
378
379sub getenv {
380
381 ($VERBOSE,
382 $INCPATH,
383 $LIBPATH,
384 $NOLOG,
385 $DEBUG_MALLOC,
386 $MANUAL,
387 $CFLAGS,
388 $LFLAGS,
389 $DFLAGS) = map { gen $_ } qw(IM_VERBOSE
390 IM_INCPATH
391 IM_LIBPATH
392 IM_NOLOG
393 IM_DEBUG_MALLOC
394 IM_MANUAL
395 IM_CFLAGS
396 IM_LFLAGS
397 IM_DFLAGS);
398
399 if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);}
400
401 if ($NOLOG) { print "Logging not compiled into module\n"; }
402 else { $EXTDEF.=' -DIMAGER_LOG'; }
403
404 if ($DEBUG_MALLOC) {
405 $EXTDEF.=' -DIMAGER_DEBUG_MALLOC';
406 print "Malloc debugging enabled\n";
407 }
408
409}