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