Commit | Line | Data |
---|---|---|
ea9e6c3f | 1 | #!perl -w |
714cf158 | 2 | use strict; |
02d1d628 AMH |
3 | use ExtUtils::MakeMaker; |
4 | use Cwd; | |
5 | use Config; | |
07ea6c21 | 6 | use File::Spec; |
37959076 | 7 | use Getopt::Long; |
92bda632 | 8 | use ExtUtils::Manifest qw(maniread); |
10b85929 | 9 | use ExtUtils::Liblist; |
714cf158 | 10 | use vars qw(%formats $VERBOSE $INCPATH $LIBPATH $NOLOG $DEBUG_MALLOC $MANUAL $CFLAGS $LFLAGS $DFLAGS); |
812ae05c TC |
11 | use lib 'inc'; |
12 | use Devel::CheckLib; | |
02d1d628 | 13 | |
1d7e3124 TC |
14 | # EU::MM runs Makefile.PL all in the same process, so sub-modules will |
15 | # see this | |
16 | our $BUILDING_IMAGER = 1; | |
17 | ||
d97c8dbd TC |
18 | # used to display a summary after we've probed the world |
19 | our %IMAGER_LIBS; | |
20 | ||
02d1d628 AMH |
21 | # |
22 | # IM_INCPATH colon seperated list of paths to extra include paths | |
23 | # IM_LIBPATH colon seperated list of paths to extra library paths | |
24 | # | |
25 | # IM_VERBOSE turns on verbose mode for the library finding and such | |
26 | # IM_MANUAL to manually select which libraries are used and which not | |
27 | # IM_ENABLE to programmatically select which libraries are used | |
28 | # and which are not | |
29 | # IM_NOLOG if true logging will not be compiled into the module | |
30 | # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module | |
31 | # do not use IM_DEBUG_MALLOC in production - this slows | |
32 | # everything down by alot | |
33 | # IM_CFLAGS Extra flags to pass to the compiler | |
34 | # IM_LFLAGS Extra flags to pass to the linker | |
35 | # IM_DFLAGS Extra flags to pass to the preprocessor | |
36 | ||
812ae05c TC |
37 | my $KEEP_FILES = $ENV{IMAGER_KEEP_FILES}; |
38 | ||
855c5808 TC |
39 | getenv(); # get environment variables |
40 | ||
714cf158 TC |
41 | my $lext=$Config{'so'}; # Get extensions of libraries |
42 | my $aext=$Config{'_a'}; | |
43 | ||
44 | my $help; # display help if set | |
45 | my @enable; # list of drivers to enable | |
46 | my @disable; # or list of drivers to disable | |
47 | my @incpaths; # places to look for headers | |
48 | my @libpaths; # places to look for libraries | |
1ef586b1 | 49 | my $coverage; # build for coverage testing |
b3afeed5 | 50 | my $assert; # build with assertions |
31a13473 | 51 | my $trace_context; # trace context management to stderr |
37959076 TC |
52 | GetOptions("help" => \$help, |
53 | "enable=s" => \@enable, | |
54 | "disable=s" => \@disable, | |
55 | "incpath=s", \@incpaths, | |
56 | "libpath=s" => \@libpaths, | |
274cd32b | 57 | "verbose|v" => \$VERBOSE, |
f7450478 | 58 | "nolog" => \$NOLOG, |
b3afeed5 | 59 | 'coverage' => \$coverage, |
31a13473 TC |
60 | "assert|a" => \$assert, |
61 | "tracecontext" => \$trace_context); | |
b3afeed5 | 62 | |
1d7e3124 TC |
63 | setenv(); |
64 | ||
b3afeed5 TC |
65 | if ($ENV{AUTOMATED_TESTING}) { |
66 | $assert = 1; | |
67 | } | |
855c5808 TC |
68 | |
69 | if ($VERBOSE) { | |
70 | print "Verbose mode\n"; | |
71 | require Data::Dumper; | |
72 | import Data::Dumper qw(Dumper); | |
73 | } | |
37959076 TC |
74 | |
75 | if ($help) { | |
76 | usage(); | |
77 | } | |
78 | ||
f7450478 TC |
79 | my @defines; |
80 | ||
274cd32b TC |
81 | if ($NOLOG) { print "Logging not compiled into module\n"; } |
82 | else { | |
83 | push @defines, [ IMAGER_LOG => 1, "Logging system" ]; | |
84 | } | |
85 | ||
b3afeed5 TC |
86 | if ($assert) { |
87 | push @defines, [ IM_ASSERT => 1, "im_assert() are effective" ]; | |
88 | } | |
89 | ||
274cd32b TC |
90 | if ($DEBUG_MALLOC) { |
91 | push @defines, [ IMAGER_DEBUG_MALLOC => 1, "Use Imager's DEBUG malloc()" ]; | |
92 | print "Malloc debugging enabled\n"; | |
93 | } | |
94 | ||
37959076 TC |
95 | if (@enable && @disable) { |
96 | print STDERR "Only --enable or --disable can be used, not both, try --help\n"; | |
97 | exit 1; | |
98 | } | |
02d1d628 | 99 | |
714cf158 TC |
100 | my %definc; |
101 | my %deflib; | |
102 | my @incs; # all the places to look for headers | |
103 | my @libs; # all the places to look for libraries | |
104 | ||
02d1d628 AMH |
105 | init(); # initialize global data |
106 | pathcheck(); # Check if directories exist | |
107 | ||
37959076 TC |
108 | if (exists $ENV{IM_ENABLE}) { |
109 | my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE}; | |
110 | for my $key (keys %formats) { | |
111 | delete $formats{$key} unless $en{$key}; | |
112 | } | |
113 | } | |
114 | if (@enable) { | |
115 | my %en = map { $_ => 1 } map { split /,/ } @enable; | |
116 | for my $key (keys %formats) { | |
117 | delete $formats{$key} unless $en{$key}; | |
118 | } | |
119 | } | |
120 | elsif (@disable) { | |
121 | delete @formats{map { split /,/ } @disable}; | |
122 | } | |
123 | ||
02d1d628 AMH |
124 | # Pick what libraries are used |
125 | if ($MANUAL) { | |
126 | manual(); | |
127 | } else { | |
128 | automatic(); | |
02d1d628 AMH |
129 | } |
130 | ||
07ea6c21 | 131 | my $lib_cflags = ''; |
a8395b42 | 132 | my $lib_lflags = ''; |
80c15fc7 TC |
133 | my $F_LIBS = ''; |
134 | my $F_OBJECT = ''; | |
714cf158 | 135 | for my $frmkey (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) { |
e11d297f TC |
136 | my $frm = $formats{$frmkey}; |
137 | push @defines, [ $frm->{def}, 1, "$frmkey available" ]; | |
02d1d628 | 138 | $F_OBJECT .= ' ' .$frm->{objfiles}; |
714cf158 TC |
139 | if ($frm->{cflags}) { |
140 | $lib_cflags .= ' ' .$frm->{cflags}; | |
141 | ++$definc{$_} for map { /^-I(.*)$/ ? ($1) : () } | |
142 | grep /^-I./, split ' ', $frm->{cflags}; | |
143 | } | |
a8395b42 TC |
144 | if ($frm->{lflags}) { |
145 | $lib_lflags .= ' ' . $frm->{lflags}; | |
146 | } | |
147 | else { | |
148 | $F_LIBS .= ' ' .$frm->{libfiles}; | |
149 | } | |
150 | ||
02d1d628 | 151 | } |
714cf158 | 152 | |
714cf158 TC |
153 | my $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, |
154 | grep !$definc{$_}, @incs; | |
155 | $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, | |
156 | grep !$deflib{$_}++, @libs) . $F_LIBS; | |
02d1d628 | 157 | |
714cf158 TC |
158 | my $OSLIBS = ''; |
159 | my $OSDEF = "-DOS_$^O"; | |
02d1d628 AMH |
160 | |
161 | if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } | |
162 | if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } | |
163 | ||
74315ca9 | 164 | my @objs = qw(Imager.o context.o draw.o polygon.o image.o io.o iolayer.o |
f2da6da9 | 165 | log.o gaussian.o conv.o pnm.o raw.o feat.o combine.o |
714cf158 TC |
166 | filters.o dynaload.o stackmach.o datatypes.o |
167 | regmach.o trans2.o quant.o error.o convert.o | |
a2f9a61c | 168 | map.o tags.o palimg.o maskimg.o img8.o img16.o rotate.o |
d5477d3d | 169 | bmp.o tga.o color.o fills.o imgdouble.o limits.o hlines.o |
e41cfe8f | 170 | imext.o scale.o rubthru.o render.o paste.o compose.o flip.o); |
92bda632 | 171 | |
24c9233d TC |
172 | if ($Config{useithreads}) { |
173 | if ($Config{i_pthread}) { | |
174 | print "POSIX threads\n"; | |
175 | push @objs, "mutexpthr.o"; | |
176 | } | |
177 | elsif ($^O eq 'MSWin32') { | |
178 | print "Win32 threads\n"; | |
179 | push @objs, "mutexwin.o"; | |
180 | } | |
181 | else { | |
182 | print "Unsupported threading model\n"; | |
183 | push @objs, "mutexnull.o"; | |
184 | } | |
185 | } | |
186 | else { | |
187 | print "No threads\n"; | |
188 | push @objs, "mutexnull.o"; | |
189 | } | |
190 | ||
d63caaff TC |
191 | my @typemaps = qw(typemap.local typemap); |
192 | if ($] < 5.008) { | |
193 | unshift @typemaps, "typemap.oldperl"; | |
194 | } | |
195 | ||
31a13473 TC |
196 | if ($trace_context) { |
197 | $CFLAGS .= " -DIMAGER_TRACE_CONTEXT"; | |
198 | } | |
199 | ||
954ac5d1 TC |
200 | my %opts= |
201 | ( | |
202 | 'NAME' => 'Imager', | |
203 | 'VERSION_FROM' => 'Imager.pm', | |
204 | 'LIBS' => "$LFLAGS -lm $lib_lflags $OSLIBS $F_LIBS", | |
205 | 'DEFINE' => "$OSDEF $CFLAGS", | |
206 | 'INC' => "$lib_cflags $DFLAGS $F_INC", | |
207 | 'OBJECT' => join(' ', @objs, $F_OBJECT), | |
208 | clean => { FILES=>'testout rubthru.c scale.c conv.c filters.c gaussian.c render.c rubthru.c' }, | |
209 | PM => gen_PM(), | |
210 | PREREQ_PM => | |
211 | { | |
212 | 'Test::More' => 0.47, | |
213 | 'Scalar::Util' => 1.00, | |
a5919365 | 214 | 'XSLoader' => 0, |
954ac5d1 | 215 | }, |
d63caaff | 216 | TYPEMAPS => \@typemaps, |
954ac5d1 | 217 | ); |
02d1d628 | 218 | |
1ef586b1 TC |
219 | if ($coverage) { |
220 | if ($Config{gccversion}) { | |
6d5c85a2 TC |
221 | push @ARGV, 'OPTIMIZE=-ftest-coverage -fprofile-arcs -g'; |
222 | $opts{dynamic_lib} = { OTHERLDFLAGS => '-ftest-coverage -fprofile-arcs' }; | |
1ef586b1 TC |
223 | } |
224 | else { | |
225 | die "Don't know the coverage C flags for your compiler\n"; | |
226 | } | |
227 | } | |
228 | ||
c52cbef2 TC |
229 | # eval to prevent warnings about versions with _ in them |
230 | my $MM_ver = eval $ExtUtils::MakeMaker::VERSION; | |
231 | if ($MM_ver > 6.06) { | |
5b480b14 | 232 | $opts{AUTHOR} = 'Tony Cook <tonyc@cpan.org>, Arnar M. Hrafnkelsson'; |
ca508100 TC |
233 | $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; |
234 | } | |
f45b774f TC |
235 | |
236 | if ($MM_ver >= 6.46) { | |
237 | $opts{META_MERGE} = | |
238 | { | |
239 | recommends => | |
240 | { | |
241 | "Parse::RecDescent" => 0 | |
242 | }, | |
243 | license => "perl", | |
244 | dynamic_config => 1, | |
43452432 TC |
245 | no_index => |
246 | { | |
247 | directory => | |
248 | [ | |
249 | "PNG", | |
ec6d8908 | 250 | "GIF", |
797a9f9c TC |
251 | "TIFF", |
252 | "JPEG", | |
bd7c1b36 | 253 | "W32", |
d7ca2089 | 254 | "FT2", |
85702fbd | 255 | "T1", |
43452432 TC |
256 | ], |
257 | }, | |
258 | resources => | |
259 | { | |
260 | homepage => "http://imager.perl.org/", | |
4989229f TC |
261 | repository => "git://git.imager.perl.org/imager.git", |
262 | bugtracker => "http://rt.cpan.org/NoAuth/Bugs.html?Dist=Imager", | |
43452432 | 263 | }, |
f45b774f | 264 | }; |
135d30e3 | 265 | } |
ca508100 | 266 | |
e11d297f TC |
267 | make_imconfig(\@defines); |
268 | ||
02d1d628 AMH |
269 | if ($VERBOSE) { print Dumper(\%opts); } |
270 | mkdir('testout',0777); # since we cannot include it in the archive. | |
135d30e3 | 271 | |
812ae05c TC |
272 | -d "probe" and rmdir "probe"; |
273 | ||
02d1d628 | 274 | WriteMakefile(%opts); |
4dce694d | 275 | |
d97c8dbd TC |
276 | my @good; |
277 | my @bad; | |
278 | for my $name (sort { lc $a cmp lc $b } keys %IMAGER_LIBS) { | |
279 | if ($IMAGER_LIBS{$name}) { | |
280 | push @good, $name; | |
281 | } | |
282 | else { | |
283 | push @bad, $name; | |
284 | } | |
285 | } | |
286 | ||
287 | print "\n"; | |
288 | print "Libraries found:\n" if @good; | |
289 | print " $_\n" for @good; | |
290 | print "Libraries *not* found:\n" if @bad; | |
291 | print " $_\n" for @bad; | |
292 | ||
02d1d628 AMH |
293 | exit; |
294 | ||
295 | ||
296 | sub MY::postamble { | |
5a7e62b6 TC |
297 | my $self = shift; |
298 | my $perl = $self->{PERLRUN} ? '$(PERLRUN)' : '$(PERL)'; | |
fe415ad2 TC |
299 | my $mani = maniread; |
300 | ||
301 | my @ims = grep /\.im$/, keys %$mani; | |
02d1d628 | 302 | ' |
faa9b3e7 | 303 | dyntest.$(MYEXTLIB) : dynfilt/Makefile |
02d1d628 AMH |
304 | cd dynfilt && $(MAKE) $(PASTHRU) |
305 | ||
306 | lib/Imager/Regops.pm : regmach.h regops.perl | |
307 | $(PERL) regops.perl regmach.h lib/Imager/Regops.pm | |
e11d297f | 308 | |
92bda632 | 309 | imconfig.h : Makefile.PL |
e11d297f TC |
310 | $(ECHO) "imconfig.h out-of-date with respect to $?" |
311 | $(PERLRUN) Makefile.PL | |
312 | $(ECHO) "==> Your Makefile has been rebuilt - re-run your make command <==" | |
5a7e62b6 | 313 | '.qq! |
6cfee9d1 | 314 | lib/Imager/APIRef.pod : \$(C_FILES) \$(H_FILES) apidocs.perl |
2a69ed21 | 315 | $perl apidocs.perl lib/Imager/APIRef.pod |
92bda632 | 316 | |
fe415ad2 TC |
317 | !.join('', map _im_rule($perl, $_), @ims) |
318 | ||
319 | } | |
320 | ||
321 | sub _im_rule { | |
322 | my ($perl, $im) = @_; | |
323 | ||
324 | (my $c = $im) =~ s/\.im$/.c/; | |
325 | return <<MAKE; | |
326 | ||
9b1ec2b8 TC |
327 | $c: $im lib/Imager/Preprocess.pm |
328 | $perl -Ilib -MImager::Preprocess -epreprocess $im $c | |
fe415ad2 TC |
329 | |
330 | MAKE | |
02d1d628 | 331 | |
55932d2a TC |
332 | } |
333 | ||
02d1d628 AMH |
334 | # manual configuration of helper libraries |
335 | ||
336 | sub manual { | |
337 | print <<EOF; | |
338 | ||
339 | Please answer the following questions about | |
340 | which formats are avaliable on your computer | |
341 | ||
342 | press <return> to continue | |
343 | EOF | |
344 | ||
345 | <STDIN>; # eat one return | |
346 | ||
2646b26c | 347 | for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) { |
02d1d628 AMH |
348 | SWX: |
349 | if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } | |
350 | print "Enable $frm support: "; | |
714cf158 | 351 | my $gz = <STDIN>; |
02d1d628 AMH |
352 | chomp($gz); |
353 | if ($gz =~ m/^(y|yes|n|no)/i) { | |
354 | $gz=substr(lc($gz),0,1); | |
355 | if ($gz eq 'n') { | |
356 | delete $formats{$frm}; | |
357 | } | |
358 | } else { goto SWX; } | |
359 | } | |
360 | } | |
361 | ||
362 | ||
363 | # automatic configuration of helper libraries | |
364 | ||
365 | sub automatic { | |
714cf158 TC |
366 | print "Automatic probing:\n" if $VERBOSE; |
367 | for my $frm (sort { $formats{$a}{order} <=> $formats{$b}{order} } keys %formats) { | |
02d1d628 AMH |
368 | delete $formats{$frm} if !checkformat($frm); |
369 | } | |
370 | } | |
371 | ||
c6e870ae TC |
372 | sub grep_directory { |
373 | my($path, $chk)=@_; | |
02d1d628 AMH |
374 | |
375 | # print "checking path $path\n"; | |
376 | if ( !opendir(DH,$path) ) { | |
377 | warn "Cannot open dir $path: $!\n"; | |
378 | return; | |
379 | } | |
380 | my @l=grep { $chk->($_) } readdir(DH); | |
381 | # print @l; | |
382 | close(DH); | |
383 | return map $path, @l; | |
384 | } | |
385 | ||
812ae05c TC |
386 | sub _probe_default { |
387 | my ($format, $frm) = @_; | |
07ea6c21 | 388 | |
c6e870ae TC |
389 | my $lib_check=$formats{$frm}{'libcheck'}; |
390 | my $inc_check=$formats{$frm}{'inccheck'}; | |
02d1d628 | 391 | |
c6e870ae TC |
392 | if ($lib_check) { |
393 | my @l; | |
394 | for my $lp (@libs) { | |
395 | push(@l, grep_directory($lp,$lib_check)); | |
396 | } | |
397 | ||
398 | my @i; | |
399 | for my $ip (@incs) { | |
400 | push(@i, $ip) if $inc_check->($ip,$frm); | |
401 | } | |
402 | ||
403 | printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found')); | |
404 | $formats{$frm}{incdir} = \@i; | |
405 | $formats{$frm}{libdir} = \@l; | |
406 | return 1 if scalar(@i && @l); | |
02d1d628 | 407 | } |
c6e870ae TC |
408 | else { |
409 | printf("%10s: not available\n", $frm); | |
02d1d628 AMH |
410 | } |
411 | ||
c6e870ae | 412 | return 0; |
02d1d628 AMH |
413 | } |
414 | ||
812ae05c TC |
415 | sub checkformat { |
416 | my $frm=shift; | |
417 | ||
418 | print " checkformat($frm)\n" if $VERBOSE; | |
419 | ||
420 | my $format = $formats{$frm}; | |
421 | ||
422 | my @probes; | |
423 | if (my $code = $format->{'code'}) { | |
424 | if (ref $code eq 'ARRAY') { | |
425 | push @probes, @$code; | |
426 | } | |
427 | else { | |
428 | push @probes, $code; | |
429 | } | |
430 | } | |
431 | push @probes, \&_probe_default; | |
432 | ||
433 | print " Calling probe function\n" if $VERBOSE; | |
434 | my $found; | |
435 | for my $func (@probes) { | |
436 | if ($func->($format, $frm)) { | |
437 | ++$found; | |
438 | last; | |
439 | } | |
440 | } | |
441 | ||
442 | $found or return; | |
443 | ||
444 | if ($format->{postcheck}) { | |
445 | print " Calling postcheck function\n" if $VERBOSE; | |
446 | $format->{postcheck}->($format, $frm) | |
447 | or return; | |
448 | } | |
449 | ||
450 | return 1; | |
451 | } | |
452 | ||
02d1d628 | 453 | |
02d1d628 AMH |
454 | sub pathcheck { |
455 | if ($VERBOSE) { | |
456 | print "pathcheck\n"; | |
457 | print " Include paths:\n"; | |
458 | for (@incs) { print $_,"\n"; } | |
459 | } | |
3a6bb91b | 460 | @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs; |
02d1d628 AMH |
461 | |
462 | if ($VERBOSE) { | |
463 | print "\nLibrary paths:\n"; | |
855c5808 | 464 | for (@libs) { print $_,"\n"; } |
02d1d628 | 465 | } |
3a6bb91b | 466 | @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs; |
02d1d628 AMH |
467 | print "\ndone.\n"; |
468 | } | |
469 | ||
470 | ||
471 | # Format data initialization | |
472 | ||
473 | # format definition is: | |
474 | # defines needed | |
475 | # default include path | |
476 | # files needed for include (boolean perl code) | |
477 | # default lib path | |
478 | # libs needed | |
479 | # files needed for link (boolean perl code) | |
480 | # object files needed for the format | |
481 | ||
482 | ||
483 | sub init { | |
484 | ||
714cf158 TC |
485 | my @definc = qw(/usr/include); |
486 | @definc{@definc}=(1) x @definc; | |
d8e0c3ba TC |
487 | @incs= |
488 | ( | |
489 | split(/\Q$Config{path_sep}/, $INCPATH), | |
490 | map _tilde_expand($_), map { split /\Q$Config{path_sep}/ } @incpaths | |
491 | ); | |
2646b26c | 492 | if ($Config{locincpth}) { |
6552acfe | 493 | push @incs, grep -d, split ' ', $Config{locincpth}; |
2646b26c | 494 | } |
88a763e2 TC |
495 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
496 | push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; | |
2646b26c | 497 | } |
16cf4610 TC |
498 | if ($Config{incpath}) { |
499 | push @incs, grep -d, split /\Q$Config{path_sep}/, $Config{incpath}; | |
500 | } | |
6552acfe | 501 | push @incs, grep -d, |
2646b26c TC |
502 | qw(/sw/include |
503 | /usr/include/freetype2 | |
504 | /usr/local/include/freetype2 | |
505 | /usr/local/include/freetype1/freetype | |
37959076 | 506 | /usr/include /usr/local/include /usr/include/freetype |
2646b26c | 507 | /usr/local/include/freetype); |
714cf158 TC |
508 | if ($Config{ccflags}) { |
509 | my @hidden = map { /^-I(.*)$/ ? ($1) : () } split ' ', $Config{ccflags}; | |
510 | push @incs, @hidden; | |
511 | @definc{@hidden} = (1) x @hidden; | |
512 | } | |
2646b26c | 513 | |
37959076 | 514 | @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH), |
d8e0c3ba | 515 | map _tilde_expand($_), map { split /\Q$Config{path_sep}/} @libpaths ); |
2646b26c | 516 | if ($Config{loclibpth}) { |
6552acfe | 517 | push @libs, grep -d, split ' ', $Config{loclibpth}; |
2646b26c | 518 | } |
714cf158 | 519 | |
6552acfe | 520 | push @libs, grep -d, qw(/sw/lib), split(/ /, $Config{'libpth'}); |
714cf158 | 521 | push @libs, grep -d, split / /, $Config{libspath} if $Config{libspath}; |
2646b26c | 522 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
88a763e2 TC |
523 | push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; |
524 | } | |
faa9b3e7 TC |
525 | if ($^O eq 'cygwin') { |
526 | push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api'; | |
274cd32b | 527 | push(@incs, '/usr/include/w32api') if -d '/usr/include/w32api'; |
faa9b3e7 | 528 | } |
714cf158 TC |
529 | if ($Config{ldflags}) { |
530 | # some builds of perl put -Ldir into ldflags without putting it in | |
531 | # loclibpth, let's extract them | |
532 | my @hidden = grep -d, map { /^-L(.*)$/ ? ($1) : () } | |
533 | split ' ', $Config{ldflags}; | |
534 | push @libs, @hidden; | |
535 | # don't mark them as seen - EU::MM will remove any libraries | |
536 | # it can't find and it doesn't look for -L in ldflags | |
537 | #@deflib{@hidden} = @hidden; | |
538 | } | |
ed28c9cc | 539 | push @libs, grep -d, qw(/usr/local/lib); |
2646b26c | 540 | |
f8e9bc07 TC |
541 | $formats{'TT-fonts'}= |
542 | { | |
543 | order=>'31', | |
544 | def=>'HAVE_LIBTT', | |
545 | inccheck=>sub { -e catfile($_[0], 'freetype.h') | |
546 | && !-e catfile($_[0], 'fterrors.h') }, | |
547 | libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" }, | |
548 | libfiles=>'-lttf', | |
f2da6da9 | 549 | objfiles=>'fontft1.o', |
714cf158 | 550 | code => \&freetype1_probe, |
f8e9bc07 TC |
551 | docs=>q{ |
552 | Truetype fonts are scalable fonts. They can include | |
553 | kerning and hinting information and generally yield good | |
554 | visual quality esp on low resultions. The freetype library is | |
555 | used to rasterize for us. The only drawback is that there | |
556 | are alot of badly designed fonts out there.} | |
02d1d628 AMH |
557 | }; |
558 | # Make fix indent | |
559 | for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } | |
560 | } | |
561 | ||
562 | ||
563 | ||
564 | sub gen { | |
565 | my $V = $ENV{$_[0]}; | |
566 | defined($V) ? $V : ""; | |
567 | } | |
568 | ||
569 | ||
570 | # Get information from environment variables | |
571 | ||
572 | sub getenv { | |
573 | ||
574 | ($VERBOSE, | |
575 | $INCPATH, | |
576 | $LIBPATH, | |
577 | $NOLOG, | |
578 | $DEBUG_MALLOC, | |
579 | $MANUAL, | |
580 | $CFLAGS, | |
581 | $LFLAGS, | |
582 | $DFLAGS) = map { gen $_ } qw(IM_VERBOSE | |
583 | IM_INCPATH | |
584 | IM_LIBPATH | |
585 | IM_NOLOG | |
586 | IM_DEBUG_MALLOC | |
587 | IM_MANUAL | |
588 | IM_CFLAGS | |
589 | IM_LFLAGS | |
590 | IM_DFLAGS); | |
591 | ||
02d1d628 | 592 | } |
07ea6c21 | 593 | |
1d7e3124 TC |
594 | # populate the environment so that sub-modules get the same info |
595 | sub setenv { | |
596 | $ENV{IM_VERBOSE} = 1 if $VERBOSE; | |
597 | $ENV{IM_INCPATH} = join $Config{path_sep}, @incpaths if @incpaths; | |
598 | $ENV{IM_LIBPATH} = join $Config{path_sep}, @libpaths if @libpaths; | |
599 | } | |
600 | ||
e11d297f TC |
601 | sub make_imconfig { |
602 | my ($defines) = @_; | |
603 | ||
604 | open CONFIG, "> imconfig.h" | |
605 | or die "Cannot create imconfig.h: $!\n"; | |
606 | print CONFIG <<EOS; | |
607 | /* This file is automatically generated by Makefile.PL. | |
608 | Don't edit this file, since any changes will be lost */ | |
609 | ||
610 | #ifndef IMAGER_IMCONFIG_H | |
611 | #define IMAGER_IMCONFIG_H | |
612 | EOS | |
613 | for my $define (@$defines) { | |
614 | if ($define->[2]) { | |
615 | print CONFIG "\n/*\n $define->[2]\n*/\n\n"; | |
616 | } | |
617 | print CONFIG "#define $define->[0] $define->[1]\n"; | |
618 | } | |
53ea6b6f | 619 | if ($Config{gccversion} && $Config{gccversion} =~ /^([0-9]+)/ && $1 > 3) { |
8d14daab TC |
620 | print CONFIG <<EOS; |
621 | /* | |
622 | ||
623 | Compiler supports the GCC __attribute__((format...)) syntax. | |
624 | ||
625 | */ | |
626 | ||
627 | #define IMAGER_FORMAT_ATTR 1 | |
53ea6b6f | 628 | |
86c8d19a TC |
629 | EOS |
630 | } | |
631 | ||
632 | if ($Config{d_snprintf}) { | |
633 | print CONFIG <<EOS; | |
634 | /* We can use snprintf() */ | |
635 | #define IMAGER_SNPRINTF 1 | |
636 | ||
637 | EOS | |
638 | } | |
639 | ||
640 | if ($Config{d_vsnprintf}) { | |
641 | print CONFIG <<EOS; | |
642 | /* We can use vsnprintf() */ | |
643 | #define IMAGER_VSNPRINTF 1 | |
644 | ||
8d14daab TC |
645 | EOS |
646 | } | |
647 | ||
648 | print CONFIG <<EOS; | |
649 | /* | |
650 | Type and format code for formatted output as with printf. | |
651 | ||
652 | This is intended for formatting i_img_dim values. | |
653 | */ | |
654 | typedef $Config{ivtype} i_dim_format_t; | |
655 | #define i_DF $Config{ivdformat} | |
656 | EOS | |
657 | ||
e11d297f TC |
658 | print CONFIG "\n#endif\n"; |
659 | close CONFIG; | |
660 | } | |
661 | ||
714cf158 TC |
662 | # probes for freetype1 by scanning @incs for the includes and |
663 | # @libs for the libs. This is done separately because freetype's headers | |
664 | # are stored in a freetype or freetype1 directory under PREFIX/include. | |
665 | # | |
666 | # we could find the files with the existing mechanism, but it won't set | |
667 | # -I flags correctly. | |
668 | # | |
669 | # This could be extended to freetype2 too, but freetype-config catches | |
670 | # that | |
671 | sub freetype1_probe { | |
672 | my ($frm, $frmkey) = @_; | |
673 | ||
674 | my $found_inc; | |
675 | INCS: | |
676 | for my $inc (@incs) { | |
677 | for my $subdir (qw/freetype freetype1/) { | |
678 | my $path = File::Spec->catfile($inc, $subdir, 'freetype.h'); | |
679 | -e $path or next; | |
680 | $path = File::Spec->catfile($inc, $subdir, 'fterrors.h'); | |
681 | -e $path and next; | |
682 | ||
683 | $found_inc = File::Spec->catdir($inc, $subdir); | |
684 | last INCS; | |
685 | } | |
686 | } | |
687 | ||
688 | my $found_lib; | |
689 | LIBS: | |
690 | for my $lib (@libs) { | |
691 | my $a_path = File::Spec->catfile($lib, "libttf$aext"); | |
692 | my $l_path = File::Spec->catfile($lib, "libttf.$lext"); | |
693 | if (-e $a_path || -e $l_path) { | |
694 | $found_lib = $lib; | |
695 | last LIBS; | |
696 | } | |
697 | } | |
698 | ||
89d37182 | 699 | return unless $found_inc && $found_lib; |
714cf158 TC |
700 | printf("%10s: includes %s - libraries %s\n", $frmkey, |
701 | ($found_inc ? 'found' : 'not found'), | |
702 | ($found_lib ? 'found' : 'not found')); | |
714cf158 TC |
703 | |
704 | $frm->{cflags} = "-I$found_inc"; | |
705 | $frm->{libfiles} = "-lttf"; | |
706 | ||
707 | return 1; | |
708 | } | |
709 | ||
07ea6c21 TC |
710 | sub catfile { |
711 | return File::Spec->catfile(@_); | |
712 | } | |
713 | ||
37959076 TC |
714 | sub usage { |
715 | print STDERR <<EOS; | |
274cd32b TC |
716 | Usage: $0 [--enable feature1,feature2,...] [other options] |
717 | $0 [--disable feature1,feature2,...] [other options] | |
37959076 TC |
718 | $0 --help |
719 | Possible feature names are: | |
85702fbd | 720 | T1-fonts |
274cd32b TC |
721 | Other options: |
722 | --verbose | -v | |
723 | Verbose library probing (or set IM_VERBOSE in the environment) | |
724 | --nolog | |
725 | Disable logging (or set IM_NOLOG in the environment) | |
726 | --incpath dir | |
727 | Add to the include search path | |
728 | --libpath dir | |
729 | Add to the library search path | |
35a15603 TC |
730 | --coverage |
731 | Build for coverage testing. | |
732 | --assert | |
733 | Build with assertions active. | |
37959076 TC |
734 | EOS |
735 | exit 1; | |
736 | ||
737 | } | |
92bda632 TC |
738 | |
739 | # generate the PM MM argument | |
740 | # I'd prefer to modify the public version, but there doesn't seem to be | |
741 | # a public API to do that | |
742 | sub gen_PM { | |
743 | my %pm; | |
744 | my $instbase = '$(INST_LIBDIR)'; | |
745 | ||
746 | # first the basics, .pm and .pod files | |
747 | $pm{"Imager.pm"} = "$instbase/Imager.pm"; | |
748 | ||
749 | my $mani = maniread(); | |
750 | ||
751 | for my $filename (keys %$mani) { | |
752 | if ($filename =~ m!^lib/! && $filename =~ /\.(pm|pod)$/) { | |
753 | (my $work = $filename) =~ s/^lib//; | |
754 | $pm{$filename} = $instbase . $work; | |
755 | } | |
756 | } | |
757 | ||
758 | # need the typemap | |
759 | $pm{typemap} = $instbase . '/Imager/typemap'; | |
760 | ||
761 | # and the core headers | |
762 | for my $filename (keys %$mani) { | |
763 | if ($filename =~ /^\w+\.h$/) { | |
764 | $pm{$filename} = $instbase . '/Imager/include/' . $filename; | |
765 | } | |
766 | } | |
767 | ||
768 | # and the generated header | |
769 | $pm{"imconfig.h"} = $instbase . '/Imager/include/imconfig.h'; | |
770 | ||
771 | \%pm; | |
772 | } | |
135d30e3 | 773 | |
d8e0c3ba TC |
774 | my $home; |
775 | sub _tilde_expand { | |
776 | my ($path) = @_; | |
777 | ||
778 | if ($path =~ m!^~[/\\]!) { | |
779 | defined $home or $home = $ENV{HOME}; | |
780 | if (!defined $home && $^O eq 'MSWin32' | |
781 | && defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) { | |
782 | $home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH}; | |
783 | } | |
784 | unless (defined $home) { | |
785 | $home = eval { (getpwuid($<))[7] }; | |
786 | } | |
787 | defined $home or die "You supplied $path, but I can't find your home directory\n"; | |
788 | $path =~ s/^~//; | |
789 | $path = File::Spec->catdir($home, $path); | |
790 | } | |
791 | ||
792 | $path; | |
793 | } | |
794 | ||
678a9a65 | 795 | 1; |