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