Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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