Commit | Line | Data |
---|---|---|
ea9e6c3f | 1 | #!perl -w |
02d1d628 AMH |
2 | use ExtUtils::MakeMaker; |
3 | use Cwd; | |
4 | use Config; | |
07ea6c21 | 5 | use File::Spec; |
37959076 | 6 | use Getopt::Long; |
92bda632 TC |
7 | use vars qw(%Recommends); |
8 | require "metafile.pl"; | |
9 | use ExtUtils::Manifest qw(maniread); | |
02d1d628 | 10 | |
02d1d628 AMH |
11 | # |
12 | # IM_INCPATH colon seperated list of paths to extra include paths | |
13 | # IM_LIBPATH colon seperated list of paths to extra library paths | |
14 | # | |
15 | # IM_VERBOSE turns on verbose mode for the library finding and such | |
16 | # IM_MANUAL to manually select which libraries are used and which not | |
17 | # IM_ENABLE to programmatically select which libraries are used | |
18 | # and which are not | |
19 | # IM_NOLOG if true logging will not be compiled into the module | |
20 | # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module | |
21 | # do not use IM_DEBUG_MALLOC in production - this slows | |
22 | # everything down by alot | |
23 | # IM_CFLAGS Extra flags to pass to the compiler | |
24 | # IM_LFLAGS Extra flags to pass to the linker | |
25 | # IM_DFLAGS Extra flags to pass to the preprocessor | |
f4dbac50 | 26 | # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support |
02d1d628 | 27 | |
855c5808 TC |
28 | getenv(); # get environment variables |
29 | ||
37959076 TC |
30 | my $help; |
31 | my @enable; | |
32 | my @disable; | |
33 | my @incpaths; | |
34 | my @libpaths; | |
35 | my $noprobe; | |
f7450478 | 36 | my $noexif; |
37959076 TC |
37 | GetOptions("help" => \$help, |
38 | "enable=s" => \@enable, | |
39 | "disable=s" => \@disable, | |
40 | "incpath=s", \@incpaths, | |
41 | "libpath=s" => \@libpaths, | |
855c5808 | 42 | "noprobe" => \$noprobe, |
274cd32b | 43 | "verbose|v" => \$VERBOSE, |
f7450478 TC |
44 | "nolog" => \$NOLOG, |
45 | "noexif" => \$noexif); | |
855c5808 TC |
46 | |
47 | if ($VERBOSE) { | |
48 | print "Verbose mode\n"; | |
49 | require Data::Dumper; | |
50 | import Data::Dumper qw(Dumper); | |
51 | } | |
37959076 TC |
52 | |
53 | if ($help) { | |
54 | usage(); | |
55 | } | |
56 | ||
f7450478 TC |
57 | my @defines; |
58 | ||
274cd32b TC |
59 | if ($NOLOG) { print "Logging not compiled into module\n"; } |
60 | else { | |
61 | push @defines, [ IMAGER_LOG => 1, "Logging system" ]; | |
62 | } | |
63 | ||
64 | if ($DEBUG_MALLOC) { | |
65 | push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; | |
66 | print "Malloc debugging enabled\n"; | |
67 | } | |
68 | ||
37959076 TC |
69 | if (@enable && @disable) { |
70 | print STDERR "Only --enable or --disable can be used, not both, try --help\n"; | |
71 | exit 1; | |
72 | } | |
02d1d628 | 73 | |
02d1d628 AMH |
74 | init(); # initialize global data |
75 | pathcheck(); # Check if directories exist | |
76 | ||
37959076 TC |
77 | if (exists $ENV{IM_ENABLE}) { |
78 | my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE}; | |
79 | for my $key (keys %formats) { | |
80 | delete $formats{$key} unless $en{$key}; | |
81 | } | |
82 | } | |
83 | if (@enable) { | |
84 | my %en = map { $_ => 1 } map { split /,/ } @enable; | |
85 | for my $key (keys %formats) { | |
86 | delete $formats{$key} unless $en{$key}; | |
87 | } | |
88 | } | |
89 | elsif (@disable) { | |
90 | delete @formats{map { split /,/ } @disable}; | |
91 | } | |
92 | ||
02d1d628 AMH |
93 | # Pick what libraries are used |
94 | if ($MANUAL) { | |
95 | manual(); | |
96 | } else { | |
97 | automatic(); | |
02d1d628 AMH |
98 | } |
99 | ||
100 | # Make sure there isn't a clash between the gif libraries. | |
101 | gifcheck(); | |
102 | ||
07ea6c21 | 103 | my $lib_cflags = ''; |
80c15fc7 TC |
104 | my $F_LIBS = ''; |
105 | my $F_OBJECT = ''; | |
e11d297f TC |
106 | for my $frmkey (keys %formats) { |
107 | my $frm = $formats{$frmkey}; | |
108 | push @defines, [ $frm->{def}, 1, "$frmkey available" ]; | |
02d1d628 AMH |
109 | $F_LIBS .= ' ' .$frm->{libfiles}; |
110 | $F_OBJECT .= ' ' .$frm->{objfiles}; | |
07ea6c21 | 111 | $lib_cflags .= ' ' .$frm->{cflags} if $frm->{cflags}; |
02d1d628 | 112 | } |
f7450478 TC |
113 | unless ($noexif) { |
114 | print "EXIF support enabled\n"; | |
115 | push @defines, [ 'IMEXIF_ENABLE', 1, "Enable experimental EXIF support" ]; | |
116 | $F_OBJECT .= ' imexif.o'; | |
117 | } | |
02d1d628 | 118 | |
ea9e6c3f TC |
119 | $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, |
120 | grep !exists $definc{$_}, @incs; | |
121 | $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS; | |
02d1d628 AMH |
122 | |
123 | $OSLIBS = ''; | |
124 | $OSDEF = "-DOS_$^O"; | |
125 | ||
126 | if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } | |
127 | if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } | |
128 | ||
9982a307 AMH |
129 | @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o |
130 | log.o gaussian.o conv.o pnm.o raw.o feat.o font.o | |
02d1d628 | 131 | filters.o dynaload.o stackmach.o datatypes.o |
2df3535a | 132 | regmach.o trans2.o quant.o error.o convert.o |
261f91c5 | 133 | map.o tags.o palimg.o maskimg.o img16.o rotate.o |
92bda632 TC |
134 | bmp.o tga.o rgb.o color.o fills.o imgdouble.o limits.o hlines.o |
135 | imext.o); | |
136 | ||
137 | $Recommends{Imager} = | |
138 | { 'Parse::RecDescent' => 0 }; | |
02d1d628 AMH |
139 | |
140 | %opts=( | |
141 | 'NAME' => 'Imager', | |
142 | 'VERSION_FROM' => 'Imager.pm', | |
143 | 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS", | |
e11d297f | 144 | 'DEFINE' => "$OSDEF $CFLAGS", |
07ea6c21 | 145 | 'INC' => "$lib_cflags $DFLAGS $F_INC", |
de2b8bae | 146 | 'OBJECT' => join(' ', @objs, $F_OBJECT), |
8746dc75 | 147 | clean => { FILES=>'testout meta.tmp' }, |
92bda632 | 148 | PM => gen_PM(), |
02d1d628 AMH |
149 | ); |
150 | ||
29316bdb TC |
151 | if ($ExtUtils::MakeMaker::VERSION > 6.06) { |
152 | $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson'; | |
ca508100 TC |
153 | $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; |
154 | } | |
155 | ||
e11d297f TC |
156 | make_imconfig(\@defines); |
157 | ||
02d1d628 AMH |
158 | if ($VERBOSE) { print Dumper(\%opts); } |
159 | mkdir('testout',0777); # since we cannot include it in the archive. | |
160 | WriteMakefile(%opts); | |
4dce694d | 161 | |
02d1d628 AMH |
162 | exit; |
163 | ||
164 | ||
165 | sub MY::postamble { | |
5a7e62b6 TC |
166 | my $self = shift; |
167 | my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)'; | |
02d1d628 | 168 | ' |
faa9b3e7 | 169 | dyntest.$(MYEXTLIB) : dynfilt/Makefile |
02d1d628 AMH |
170 | cd dynfilt && $(MAKE) $(PASTHRU) |
171 | ||
172 | lib/Imager/Regops.pm : regmach.h regops.perl | |
173 | $(PERL) regops.perl regmach.h lib/Imager/Regops.pm | |
e11d297f | 174 | |
92bda632 | 175 | imconfig.h : Makefile.PL |
e11d297f TC |
176 | $(ECHO) "imconfig.h out-of-date with respect to $?" |
177 | $(PERLRUN) Makefile.PL | |
178 | $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <==" | |
5a7e62b6 TC |
179 | '.qq! |
180 | lib/Imager/APIRef.pm : \$(C_FILES) apidocs.perl | |
181 | $perl apidocs.perl lib/Imager/APIRef.pm | |
92bda632 | 182 | |
5a7e62b6 | 183 | !; |
02d1d628 | 184 | |
55932d2a TC |
185 | } |
186 | ||
02d1d628 AMH |
187 | # manual configuration of helper libraries |
188 | ||
189 | sub manual { | |
190 | print <<EOF; | |
191 | ||
192 | Please answer the following questions about | |
193 | which formats are avaliable on your computer | |
194 | ||
195 | press <return> to continue | |
196 | EOF | |
197 | ||
198 | <STDIN>; # eat one return | |
199 | ||
2646b26c | 200 | for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) { |
02d1d628 AMH |
201 | SWX: |
202 | if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } | |
203 | print "Enable $frm support: "; | |
09fd3468 | 204 | $gz = <STDIN>; |
02d1d628 AMH |
205 | chomp($gz); |
206 | if ($gz =~ m/^(y|yes|n|no)/i) { | |
207 | $gz=substr(lc($gz),0,1); | |
208 | if ($gz eq 'n') { | |
209 | delete $formats{$frm}; | |
210 | } | |
211 | } else { goto SWX; } | |
212 | } | |
213 | } | |
214 | ||
215 | ||
216 | # automatic configuration of helper libraries | |
217 | ||
218 | sub automatic { | |
219 | for $frm(keys %formats) { | |
220 | delete $formats{$frm} if !checkformat($frm); | |
221 | } | |
222 | } | |
223 | ||
224 | ||
225 | sub gifcheck { | |
5f5fe73e | 226 | if ($formats{'gif'} and $formats{'ungif'}) { |
02d1d628 AMH |
227 | print "ungif and gif can not coexist - removing ungif support\n"; |
228 | delete $formats{'ungif'}; | |
229 | } | |
5f5fe73e AMH |
230 | |
231 | RETR: | |
f4dbac50 | 232 | if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) { |
5f5fe73e AMH |
233 | print <<EOFF; |
234 | ||
235 | You have libgif or libungif installed. They are both known to have | |
236 | bugs. Imager can crash or display other strange behaviour after | |
237 | reading or writing gif images. Some of the gif tests can even fail | |
238 | since they stress some parts of the buggy code. | |
239 | ||
f1967c11 TC |
240 | libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one |
241 | patch to have all the bugs fixed, see README for details. | |
242 | ||
243 | Of course it's possible your operating system distributor has patched | |
244 | all of these problems and you have nothing to worry about. | |
0b836ff8 | 245 | |
5f5fe73e AMH |
246 | Do you want to remove gif support? [Y/n] |
247 | EOFF | |
248 | my $resp = <STDIN>; | |
249 | chomp($resp); | |
250 | if ($resp ne "n") { | |
251 | delete $formats{'gif'}; | |
252 | delete $formats{'ungif'}; | |
09fd3468 | 253 | return; |
5f5fe73e AMH |
254 | } |
255 | } | |
09fd3468 AMH |
256 | |
257 | for my $frm (qw(gif ungif)) { | |
258 | checkformat($frm) if ($MANUAL and $formats{$frm}); | |
259 | } | |
260 | ||
02d1d628 AMH |
261 | my @dirs; |
262 | for my $frm (grep $formats{$_}, qw(gif ungif)) { | |
263 | push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir}; | |
264 | } | |
265 | my $minor = 0; | |
266 | my $major = 0; | |
267 | FILES: for my $dir (@dirs) { | |
268 | my $h = "$dir/gif_lib.h"; | |
269 | open H, "< $h" or next; | |
270 | while (<H>) { | |
271 | if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) { | |
272 | $major = $1; | |
273 | $minor = $2; | |
274 | close H; | |
275 | last FILES; | |
276 | } | |
277 | } | |
278 | close H; | |
279 | } | |
280 | ||
281 | # we need the version in a #ifdefable form | |
4dce694d | 282 | |
e11d297f TC |
283 | push @defines, [ IM_GIFMAJOR, $major, "Parsed giflib version" ]; |
284 | push @defines, [ IM_GIFMINOR, $minor ]; | |
02d1d628 AMH |
285 | } |
286 | ||
287 | ||
288 | sub gd { | |
289 | my($path,$chk)=@_; | |
290 | ||
291 | # print "checking path $path\n"; | |
292 | if ( !opendir(DH,$path) ) { | |
293 | warn "Cannot open dir $path: $!\n"; | |
294 | return; | |
295 | } | |
296 | my @l=grep { $chk->($_) } readdir(DH); | |
297 | # print @l; | |
298 | close(DH); | |
299 | return map $path, @l; | |
300 | } | |
301 | ||
302 | ||
303 | sub checkformat { | |
304 | my $frm=shift; | |
37959076 | 305 | |
07ea6c21 | 306 | my $code = $formats{$frm}{'code'}; |
37959076 | 307 | if ($code && !$noprobe) { |
07ea6c21 TC |
308 | return 1 if $code->($formats{$frm}, $frm); |
309 | } | |
310 | ||
02d1d628 AMH |
311 | my $libchk=$formats{$frm}{'libcheck'}; |
312 | my $incchk=$formats{$frm}{'inccheck'}; | |
313 | ||
314 | my @l; | |
315 | for my $lp (@libs) { | |
316 | push(@l, gd($lp,$libchk)); | |
317 | } | |
318 | ||
319 | my @i; | |
320 | for my $ip (@incs) { | |
f8e9bc07 | 321 | push(@i, $ip) if $incchk->($ip,$frm); |
02d1d628 AMH |
322 | } |
323 | ||
324 | printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found')); | |
325 | $formats{$frm}{incdir} = \@i; | |
326 | $formats{$frm}{libdir} = \@l; | |
327 | return scalar(@i && @l); | |
328 | } | |
329 | ||
330 | ||
02d1d628 AMH |
331 | sub pathcheck { |
332 | if ($VERBOSE) { | |
333 | print "pathcheck\n"; | |
334 | print " Include paths:\n"; | |
335 | for (@incs) { print $_,"\n"; } | |
336 | } | |
3a6bb91b | 337 | @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs; |
02d1d628 AMH |
338 | |
339 | if ($VERBOSE) { | |
340 | print "\nLibrary paths:\n"; | |
855c5808 | 341 | for (@libs) { print $_,"\n"; } |
02d1d628 | 342 | } |
3a6bb91b | 343 | @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs; |
02d1d628 AMH |
344 | print "\ndone.\n"; |
345 | } | |
346 | ||
347 | ||
348 | # Format data initialization | |
349 | ||
350 | # format definition is: | |
351 | # defines needed | |
352 | # default include path | |
353 | # files needed for include (boolean perl code) | |
354 | # default lib path | |
355 | # libs needed | |
356 | # files needed for link (boolean perl code) | |
357 | # object files needed for the format | |
358 | ||
359 | ||
360 | sub init { | |
361 | ||
362 | @definc{'/usr/include'}=(); | |
37959076 TC |
363 | @incs=(split(/\Q$Config{path_sep}/, $INCPATH), |
364 | map { split /\Q$Config{path_sep}/} @incpaths ); | |
2646b26c | 365 | if ($Config{locincpth}) { |
6552acfe | 366 | push @incs, grep -d, split ' ', $Config{locincpth}; |
2646b26c | 367 | } |
88a763e2 TC |
368 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
369 | push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; | |
2646b26c | 370 | } |
6552acfe | 371 | push @incs, grep -d, |
2646b26c TC |
372 | qw(/sw/include |
373 | /usr/include/freetype2 | |
374 | /usr/local/include/freetype2 | |
375 | /usr/local/include/freetype1/freetype | |
37959076 | 376 | /usr/include /usr/local/include /usr/include/freetype |
2646b26c TC |
377 | /usr/local/include/freetype); |
378 | ||
37959076 TC |
379 | @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH), |
380 | map { split /\Q$Config{path_sep}/} @libpaths ); | |
2646b26c | 381 | if ($Config{loclibpth}) { |
6552acfe | 382 | push @libs, grep -d, split ' ', $Config{loclibpth}; |
2646b26c | 383 | } |
6552acfe | 384 | push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'}); |
2646b26c | 385 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
88a763e2 TC |
386 | push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; |
387 | } | |
faa9b3e7 TC |
388 | if ($^O eq 'cygwin') { |
389 | push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api'; | |
274cd32b | 390 | push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api'; |
faa9b3e7 | 391 | } |
02d1d628 | 392 | |
2646b26c TC |
393 | my $lext=$Config{'so'}; # Get extensions of libraries |
394 | my $aext=$Config{'_a'}; | |
395 | ||
02d1d628 AMH |
396 | $formats{'jpeg'}={ |
397 | order=>'21', | |
398 | def=>'HAVE_LIBJPEG', | |
f8e9bc07 | 399 | inccheck=>sub { -e catfile($_[0], 'jpeglib.h') }, |
50ee6f9c | 400 | libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" }, |
02d1d628 AMH |
401 | libfiles=>'-ljpeg', |
402 | objfiles=>'jpeg.o', | |
403 | docs=>q{ | |
404 | In order to use jpeg with this module you need to have libjpeg | |
405 | installed on your computer} | |
406 | }; | |
407 | ||
408 | $formats{'tiff'}={ | |
409 | order=>'23', | |
410 | def=>'HAVE_LIBTIFF', | |
f8e9bc07 | 411 | inccheck=>sub { -e catfile($_[0], 'tiffio.h') }, |
76c8a0a4 | 412 | libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" }, |
02d1d628 AMH |
413 | libfiles=>'-ltiff', |
414 | objfiles=>'tiff.o', | |
415 | docs=>q{ | |
416 | In order to use tiff with this module you need to have libtiff | |
417 | installed on your computer} | |
418 | }; | |
419 | ||
420 | $formats{'png'}={ | |
421 | order=>'22', | |
422 | def=>'HAVE_LIBPNG', | |
f8e9bc07 | 423 | inccheck=>sub { -e catfile($_[0], 'png.h') }, |
88a763e2 | 424 | libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" }, |
02d1d628 AMH |
425 | libfiles=>'-lpng -lz', |
426 | objfiles=>'png.o', | |
427 | docs=>q{ | |
428 | Png stands for Portable Network Graphics and is intended as | |
429 | a replacement for gif on the web. It is patent free and | |
07ea6c21 TC |
430 | is recommended by the w3c, you need libpng to use these formats}, |
431 | code => \&png_probe, | |
02d1d628 AMH |
432 | }; |
433 | ||
434 | $formats{'gif'}={ | |
435 | order=>'20', | |
436 | def=>'HAVE_LIBGIF', | |
f8e9bc07 | 437 | inccheck=>sub { -e catfile($_[0], 'gif_lib.h') }, |
e02451e0 | 438 | libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" }, |
02d1d628 AMH |
439 | libfiles=>'-lgif', |
440 | objfiles=>'gif.o', | |
441 | docs=>q{ | |
442 | gif is the de facto standard for webgraphics at the moment, | |
443 | it does have some patent problems. If you have giflib and | |
444 | are not in violation with the unisys patent you should use | |
445 | this instead of the 'ungif' option. Note that they cannot | |
446 | be in use at the same time} | |
447 | }; | |
448 | ||
449 | $formats{'ungif'}={ | |
450 | order=>'21', | |
451 | def=>'HAVE_LIBGIF', | |
f8e9bc07 | 452 | inccheck=>sub { -e catfile($_[0], 'gif_lib.h') }, |
e02451e0 | 453 | libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" }, |
02d1d628 AMH |
454 | libfiles=>'-lungif', |
455 | objfiles=>'gif.o', | |
456 | docs=>q{ | |
457 | gif is the de facto standard for webgraphics at the moment, | |
458 | it does have some patent problems. If you have libungif and | |
459 | want to create images free from LZW patented compression you | |
460 | should use this option instead of the 'gif' option} | |
461 | }; | |
462 | ||
463 | $formats{'T1-fonts'}={ | |
464 | order=>'30', | |
465 | def=>'HAVE_LIBT1', | |
f8e9bc07 | 466 | inccheck=>sub { -e catfile($_[0], 't1lib.h') }, |
faa9b3e7 | 467 | libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" }, |
02d1d628 AMH |
468 | libfiles=>'-lt1', |
469 | objfiles=>'', | |
470 | docs=>q{ | |
471 | postscript t1 fonts are scalable fonts. They can include | |
472 | ligatures and kerning information and generally yield good | |
473 | visual quality. We depend on libt1 to rasterize the fonts | |
474 | for use in images.} | |
475 | }; | |
476 | ||
f8e9bc07 TC |
477 | $formats{'TT-fonts'}= |
478 | { | |
479 | order=>'31', | |
480 | def=>'HAVE_LIBTT', | |
481 | inccheck=>sub { -e catfile($_[0], 'freetype.h') | |
482 | && !-e catfile($_[0], 'fterrors.h') }, | |
483 | libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" }, | |
484 | libfiles=>'-lttf', | |
485 | objfiles=>'', | |
486 | docs=>q{ | |
487 | Truetype fonts are scalable fonts. They can include | |
488 | kerning and hinting information and generally yield good | |
489 | visual quality esp on low resultions. The freetype library is | |
490 | used to rasterize for us. The only drawback is that there | |
491 | are alot of badly designed fonts out there.} | |
02d1d628 | 492 | }; |
faa9b3e7 TC |
493 | $formats{'w32'} = { |
494 | order=>40, | |
495 | def=>'HAVE_WIN32', | |
f8e9bc07 | 496 | inccheck=>sub { -e catfile($_[0], 'windows.h') }, |
faa9b3e7 TC |
497 | libcheck=>sub { lc $_[0] eq 'gdi32.lib' |
498 | || lc $_[0] eq 'libgdi32.a' }, | |
499 | libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '', | |
500 | objfiles=>'win32.o', | |
501 | docs => <<DOCS | |
502 | Uses the Win32 GDI for rendering text. | |
503 | ||
504 | This currently only works on under normal Win32 and cygwin. | |
505 | DOCS | |
506 | }; | |
507 | $formats{'freetype2'} = { | |
508 | order=>'29', | |
509 | def=>'HAVE_FT2', | |
f8e9bc07 | 510 | inccheck=>sub { -e catfile($_[0], 'ft2build.h') }, |
faa9b3e7 TC |
511 | libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" }, |
512 | libfiles=>'-lfreetype', | |
513 | objfiles=>'freetyp2.o', | |
07ea6c21 | 514 | docs=><<DOCS, |
faa9b3e7 | 515 | Freetype 2 supports both Truetype and Type 1 fonts, both of which are |
f8e9bc07 | 516 | scalable. It also supports a variety of other fonts. |
faa9b3e7 | 517 | DOCS |
07ea6c21 | 518 | code => \&freetype2_probe, |
faa9b3e7 | 519 | }; |
f7450478 | 520 | |
02d1d628 AMH |
521 | # Make fix indent |
522 | for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } | |
523 | } | |
524 | ||
525 | ||
526 | ||
527 | sub gen { | |
528 | my $V = $ENV{$_[0]}; | |
529 | defined($V) ? $V : ""; | |
530 | } | |
531 | ||
532 | ||
533 | # Get information from environment variables | |
534 | ||
535 | sub getenv { | |
536 | ||
537 | ($VERBOSE, | |
538 | $INCPATH, | |
539 | $LIBPATH, | |
540 | $NOLOG, | |
541 | $DEBUG_MALLOC, | |
542 | $MANUAL, | |
543 | $CFLAGS, | |
544 | $LFLAGS, | |
545 | $DFLAGS) = map { gen $_ } qw(IM_VERBOSE | |
546 | IM_INCPATH | |
547 | IM_LIBPATH | |
548 | IM_NOLOG | |
549 | IM_DEBUG_MALLOC | |
550 | IM_MANUAL | |
551 | IM_CFLAGS | |
552 | IM_LFLAGS | |
553 | IM_DFLAGS); | |
554 | ||
02d1d628 | 555 | } |
07ea6c21 | 556 | |
e11d297f TC |
557 | sub make_imconfig { |
558 | my ($defines) = @_; | |
559 | ||
560 | open CONFIG, "> imconfig.h" | |
561 | or die "Cannot create imconfig.h: $!\n"; | |
562 | print CONFIG <<EOS; | |
563 | /* This file is automatically generated by Makefile.PL. | |
564 | Don't edit this file, since any changes will be lost */ | |
565 | ||
566 | #ifndef IMAGER_IMCONFIG_H | |
567 | #define IMAGER_IMCONFIG_H | |
568 | EOS | |
569 | for my $define (@$defines) { | |
570 | if ($define->[2]) { | |
571 | print CONFIG "\n/*\n $define->[2]\n*/\n\n"; | |
572 | } | |
573 | print CONFIG "#define $define->[0] $define->[1]\n"; | |
574 | } | |
575 | print CONFIG "\n#endif\n"; | |
576 | close CONFIG; | |
577 | } | |
578 | ||
dbc33d8a TC |
579 | # use pkg-config to probe for libraries |
580 | # works around the junk that pkg-config dumps on FreeBSD | |
581 | sub _pkg_probe { | |
582 | my ($pkg) = @_; | |
583 | ||
584 | is_exe('pkg-config') or return; | |
585 | ||
586 | my $redir = $^O eq 'MSWin32' ? '' : '2>/dev/null'; | |
587 | ||
588 | !system("pkg-config $pkg --exists $redir"); | |
589 | } | |
590 | ||
07ea6c21 TC |
591 | # probes for freetype2 by trying to run freetype-config |
592 | sub freetype2_probe { | |
593 | my ($frm, $frmkey) = @_; | |
594 | ||
595 | is_exe('freetype-config') or return; | |
596 | ||
597 | my $cflags = `freetype-config --cflags` | |
598 | and !$? or return; | |
599 | chomp $cflags; | |
88e16587 | 600 | |
07ea6c21 TC |
601 | my $lflags = `freetype-config --libs` |
602 | and !$? or return; | |
603 | chomp $lflags; | |
88e16587 TC |
604 | |
605 | # before 2.1.5 freetype-config --cflags could output | |
606 | # the -I options in the wrong order, causing a conflict with | |
607 | # freetype1.x installed with the same --prefix | |
608 | # | |
609 | # can happen iff: | |
610 | # - both -Iprefix/include and -Iprefix/include/freetype2 are in cflags | |
611 | # in that order | |
612 | # - freetype 1.x headers are in prefix/include/freetype | |
613 | my @incdirs = map substr($_, 2), grep /^-I/, split ' ', $cflags; | |
614 | if (@incdirs == 2 | |
615 | && $incdirs[1] eq "$incdirs[0]/freetype2" | |
616 | && -e "$incdirs[0]/freetype/freetype.h" | |
617 | && -e "$incdirs[0]/freetype/fterrid.h") { | |
618 | print "** freetype-config provided -I options out of order, correcting\n" | |
619 | if $VERBOSE; | |
620 | $cflags = join(' ', grep(!/-I/, split ' ', $cflags), | |
621 | map "-I$_", reverse @incdirs); | |
622 | } | |
623 | $frm->{cflags} = $cflags; | |
07ea6c21 TC |
624 | $frm->{libfiles} = $lflags; |
625 | ||
626 | printf "%10s: configured via freetype-config\n", $frmkey; | |
627 | ||
628 | return 1; | |
629 | } | |
630 | ||
631 | # probes for libpng via pkg-config | |
632 | sub png_probe { | |
633 | my ($frm, $frmkey) = @_; | |
634 | ||
635 | is_exe('pkg-config') or return; | |
636 | ||
07ea6c21 TC |
637 | my $config; |
638 | for my $check_conf (qw(libpng libpng12 libpng10)) { | |
dbc33d8a | 639 | if (_pkg_probe($check_conf)) { |
07ea6c21 TC |
640 | $config = $check_conf; |
641 | last; | |
642 | } | |
643 | } | |
644 | $config or return; | |
645 | ||
dbc33d8a TC |
646 | my $cflags = `pkg-config $config --cflags` |
647 | and !$? or return; | |
648 | ||
07ea6c21 TC |
649 | my $lflags = `pkg-config $config --libs` |
650 | and !$? or return; | |
651 | ||
652 | chomp $cflags; | |
653 | chomp $lflags; | |
654 | $frm->{cflags} = $cflags; | |
655 | $frm->{libfiles} = $lflags; | |
656 | ||
657 | printf "%10s: configured via `pkg-config $config ...`\n", $frmkey; | |
658 | ||
659 | return 1; | |
660 | } | |
661 | ||
662 | sub catfile { | |
663 | return File::Spec->catfile(@_); | |
664 | } | |
665 | ||
666 | sub is_exe { | |
667 | my ($name) = @_; | |
668 | ||
669 | for my $dir (File::Spec->path) { | |
670 | -x catfile($dir, "$name$Config{_exe}") | |
671 | and return 1; | |
672 | } | |
673 | ||
674 | return; | |
675 | } | |
37959076 TC |
676 | |
677 | sub usage { | |
678 | print STDERR <<EOS; | |
274cd32b TC |
679 | Usage: $0 [--enable feature1,feature2,...] [other options] |
680 | $0 [--disable feature1,feature2,...] [other options] | |
37959076 TC |
681 | $0 --help |
682 | Possible feature names are: | |
683 | png gif ungif jpeg tiff T1-fonts TT-fonts freetype2 | |
274cd32b TC |
684 | Other options: |
685 | --verbose | -v | |
686 | Verbose library probing (or set IM_VERBOSE in the environment) | |
687 | --nolog | |
688 | Disable logging (or set IM_NOLOG in the environment) | |
689 | --incpath dir | |
690 | Add to the include search path | |
691 | --libpath dir | |
692 | Add to the library search path | |
693 | --noprobe | |
694 | Don't use pkg-config or freetype2-config to probe for freetype2 and libpng | |
37959076 TC |
695 | EOS |
696 | exit 1; | |
697 | ||
698 | } | |
92bda632 TC |
699 | |
700 | # generate the PM MM argument | |
701 | # I'd prefer to modify the public version, but there doesn't seem to be | |
702 | # a public API to do that | |
703 | sub gen_PM { | |
704 | my %pm; | |
705 | my $instbase = '$(INST_LIBDIR)'; | |
706 | ||
707 | # first the basics, .pm and .pod files | |
708 | $pm{"Imager.pm"} = "$instbase/Imager.pm"; | |
709 | ||
710 | my $mani = maniread(); | |
711 | ||
712 | for my $filename (keys %$mani) { | |
713 | if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) { | |
714 | (my $work = $filename) =~ s/^lib//; | |
715 | $pm{$filename} = $instbase . $work; | |
716 | } | |
717 | } | |
718 | ||
719 | # need the typemap | |
720 | $pm{typemap} = $instbase . '/Imager/typemap'; | |
721 | ||
722 | # and the core headers | |
723 | for my $filename (keys %$mani) { | |
724 | if ($filename =~ /^\w+\.h$/) { | |
725 | $pm{$filename} = $instbase . '/Imager/include/' . $filename; | |
726 | } | |
727 | } | |
728 | ||
729 | # and the generated header | |
730 | $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h'; | |
731 | ||
732 | \%pm; | |
733 | } |