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