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