Skip to content

HTTPS clone URL

Subversion checkout URL

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