Commit | Line | Data |
---|---|---|
ea9e6c3f | 1 | #!perl -w |
02d1d628 AMH |
2 | use ExtUtils::MakeMaker; |
3 | use Cwd; | |
4 | use Config; | |
5 | ||
02d1d628 AMH |
6 | # |
7 | # IM_INCPATH colon seperated list of paths to extra include paths | |
8 | # IM_LIBPATH colon seperated list of paths to extra library paths | |
9 | # | |
10 | # IM_VERBOSE turns on verbose mode for the library finding and such | |
11 | # IM_MANUAL to manually select which libraries are used and which not | |
12 | # IM_ENABLE to programmatically select which libraries are used | |
13 | # and which are not | |
14 | # IM_NOLOG if true logging will not be compiled into the module | |
15 | # IM_DEBUG_MALLOC if true malloc debbuging will be compiled into the module | |
16 | # do not use IM_DEBUG_MALLOC in production - this slows | |
17 | # everything down by alot | |
18 | # IM_CFLAGS Extra flags to pass to the compiler | |
19 | # IM_LFLAGS Extra flags to pass to the linker | |
20 | # IM_DFLAGS Extra flags to pass to the preprocessor | |
f4dbac50 | 21 | # IM_SUPPRESS_PROMPT Suppress the prompt asking about gif support |
02d1d628 AMH |
22 | |
23 | ||
24 | getenv(); # get environment variables | |
25 | init(); # initialize global data | |
26 | pathcheck(); # Check if directories exist | |
27 | ||
28 | # Pick what libraries are used | |
29 | if ($MANUAL) { | |
30 | manual(); | |
31 | } else { | |
32 | automatic(); | |
33 | if (exists $ENV{IM_ENABLE}) { | |
34 | my %en = map { $_, 1 } split ' ', $ENV{IM_ENABLE}; | |
35 | for my $key (keys %formats) { | |
36 | delete $formats{$key} unless $en{$key}; | |
37 | } | |
38 | } | |
39 | } | |
40 | ||
41 | # Make sure there isn't a clash between the gif libraries. | |
42 | gifcheck(); | |
43 | ||
44 | for $frm(values %formats) { | |
45 | $F_DEFINE .= ' -D'.$frm->{def}; | |
46 | $F_LIBS .= ' ' .$frm->{libfiles}; | |
47 | $F_OBJECT .= ' ' .$frm->{objfiles}; | |
48 | } | |
49 | ||
ea9e6c3f TC |
50 | $F_INC = join ' ', map "-I$_", map / / ? qq{"$_"} : $_, |
51 | grep !exists $definc{$_}, @incs; | |
52 | $F_LIBS = join(' ',map "-L$_", map / / ? qq{"$_"} : $_, @libs) . $F_LIBS; | |
02d1d628 AMH |
53 | |
54 | $OSLIBS = ''; | |
55 | $OSDEF = "-DOS_$^O"; | |
56 | ||
57 | if ($^O eq 'hpux') { $OSLIBS .= ' -ldld'; } | |
58 | if (defined $Config{'d_dlsymun'}) { $OSDEF .= ' -DDLSYMUN'; } | |
59 | ||
9982a307 AMH |
60 | @objs = qw(Imager.o draw.o polygon.o image.o io.o iolayer.o |
61 | log.o gaussian.o conv.o pnm.o raw.o feat.o font.o | |
02d1d628 | 62 | filters.o dynaload.o stackmach.o datatypes.o |
2df3535a | 63 | regmach.o trans2.o quant.o error.o convert.o |
261f91c5 | 64 | map.o tags.o palimg.o maskimg.o img16.o rotate.o |
737a830c | 65 | bmp.o tga.o rgb.o color.o fills.o imgdouble.o); |
02d1d628 AMH |
66 | |
67 | %opts=( | |
68 | 'NAME' => 'Imager', | |
69 | 'VERSION_FROM' => 'Imager.pm', | |
70 | 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS", | |
71 | 'DEFINE' => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS", | |
72 | 'INC' => "$DFLAGS $F_INC", | |
de2b8bae TC |
73 | 'OBJECT' => join(' ', @objs, $F_OBJECT), |
74 | clean => { FILES=>'testout' }, | |
02d1d628 AMH |
75 | ); |
76 | ||
29316bdb TC |
77 | if ($ExtUtils::MakeMaker::VERSION > 6.06) { |
78 | $opts{AUTHOR} = 'Tony Cook <tony@imager.perl.org>, Arnar M. Hrafnkelsson'; | |
ca508100 TC |
79 | $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; |
80 | } | |
29316bdb TC |
81 | if ($ExtUtils::MakeMaker::VERSION > 6.10) { |
82 | $opts{NO_META} = 1; | |
83 | } | |
ca508100 | 84 | |
02d1d628 AMH |
85 | if ($VERBOSE) { print Dumper(\%opts); } |
86 | mkdir('testout',0777); # since we cannot include it in the archive. | |
87 | WriteMakefile(%opts); | |
4dce694d | 88 | |
02d1d628 AMH |
89 | exit; |
90 | ||
91 | ||
92 | sub MY::postamble { | |
93 | ' | |
faa9b3e7 | 94 | dyntest.$(MYEXTLIB) : dynfilt/Makefile |
02d1d628 AMH |
95 | cd dynfilt && $(MAKE) $(PASTHRU) |
96 | ||
97 | lib/Imager/Regops.pm : regmach.h regops.perl | |
98 | $(PERL) regops.perl regmach.h lib/Imager/Regops.pm | |
99 | '; | |
100 | } | |
101 | ||
102 | # manual configuration of helper libraries | |
103 | ||
104 | sub manual { | |
105 | print <<EOF; | |
106 | ||
107 | Please answer the following questions about | |
108 | which formats are avaliable on your computer | |
109 | ||
110 | press <return> to continue | |
111 | EOF | |
112 | ||
113 | <STDIN>; # eat one return | |
114 | ||
2646b26c | 115 | for my $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) { |
02d1d628 AMH |
116 | SWX: |
117 | if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } | |
118 | print "Enable $frm support: "; | |
09fd3468 | 119 | $gz = <STDIN>; |
02d1d628 AMH |
120 | chomp($gz); |
121 | if ($gz =~ m/^(y|yes|n|no)/i) { | |
122 | $gz=substr(lc($gz),0,1); | |
123 | if ($gz eq 'n') { | |
124 | delete $formats{$frm}; | |
125 | } | |
126 | } else { goto SWX; } | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | # automatic configuration of helper libraries | |
132 | ||
133 | sub automatic { | |
134 | for $frm(keys %formats) { | |
135 | delete $formats{$frm} if !checkformat($frm); | |
136 | } | |
137 | } | |
138 | ||
139 | ||
140 | sub gifcheck { | |
5f5fe73e | 141 | if ($formats{'gif'} and $formats{'ungif'}) { |
02d1d628 AMH |
142 | print "ungif and gif can not coexist - removing ungif support\n"; |
143 | delete $formats{'ungif'}; | |
144 | } | |
5f5fe73e AMH |
145 | |
146 | RETR: | |
f4dbac50 | 147 | if (($formats{'gif'} or $formats{'ungif'}) && !$ENV{IM_SUPPRESS_PROMPT}) { |
5f5fe73e AMH |
148 | print <<EOFF; |
149 | ||
150 | You have libgif or libungif installed. They are both known to have | |
151 | bugs. Imager can crash or display other strange behaviour after | |
152 | reading or writing gif images. Some of the gif tests can even fail | |
153 | since they stress some parts of the buggy code. | |
154 | ||
f1967c11 TC |
155 | libungif 4.1.2 and later is safe. giflib 4.1.3 needs at least one |
156 | patch to have all the bugs fixed, see README for details. | |
157 | ||
158 | Of course it's possible your operating system distributor has patched | |
159 | all of these problems and you have nothing to worry about. | |
0b836ff8 | 160 | |
5f5fe73e AMH |
161 | Do you want to remove gif support? [Y/n] |
162 | EOFF | |
163 | my $resp = <STDIN>; | |
164 | chomp($resp); | |
165 | if ($resp ne "n") { | |
166 | delete $formats{'gif'}; | |
167 | delete $formats{'ungif'}; | |
09fd3468 | 168 | return; |
5f5fe73e AMH |
169 | } |
170 | } | |
09fd3468 AMH |
171 | |
172 | for my $frm (qw(gif ungif)) { | |
173 | checkformat($frm) if ($MANUAL and $formats{$frm}); | |
174 | } | |
175 | ||
02d1d628 AMH |
176 | my @dirs; |
177 | for my $frm (grep $formats{$_}, qw(gif ungif)) { | |
178 | push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir}; | |
179 | } | |
180 | my $minor = 0; | |
181 | my $major = 0; | |
182 | FILES: for my $dir (@dirs) { | |
183 | my $h = "$dir/gif_lib.h"; | |
184 | open H, "< $h" or next; | |
185 | while (<H>) { | |
186 | if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) { | |
187 | $major = $1; | |
188 | $minor = $2; | |
189 | close H; | |
190 | last FILES; | |
191 | } | |
192 | } | |
193 | close H; | |
194 | } | |
195 | ||
196 | # we need the version in a #ifdefable form | |
4dce694d | 197 | |
02d1d628 AMH |
198 | $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor"; |
199 | } | |
200 | ||
201 | ||
202 | sub gd { | |
203 | my($path,$chk)=@_; | |
204 | ||
205 | # print "checking path $path\n"; | |
206 | if ( !opendir(DH,$path) ) { | |
207 | warn "Cannot open dir $path: $!\n"; | |
208 | return; | |
209 | } | |
210 | my @l=grep { $chk->($_) } readdir(DH); | |
211 | # print @l; | |
212 | close(DH); | |
213 | return map $path, @l; | |
214 | } | |
215 | ||
216 | ||
217 | sub checkformat { | |
218 | my $frm=shift; | |
2646b26c | 219 | |
02d1d628 AMH |
220 | my $libchk=$formats{$frm}{'libcheck'}; |
221 | my $incchk=$formats{$frm}{'inccheck'}; | |
222 | ||
223 | my @l; | |
224 | for my $lp (@libs) { | |
225 | push(@l, gd($lp,$libchk)); | |
226 | } | |
227 | ||
228 | my @i; | |
229 | for my $ip (@incs) { | |
230 | push(@i, gd($ip,$incchk)); | |
231 | } | |
232 | ||
233 | printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found')); | |
234 | $formats{$frm}{incdir} = \@i; | |
235 | $formats{$frm}{libdir} = \@l; | |
236 | return scalar(@i && @l); | |
237 | } | |
238 | ||
239 | ||
240 | ||
241 | ||
242 | sub pathcheck { | |
243 | if ($VERBOSE) { | |
244 | print "pathcheck\n"; | |
245 | print " Include paths:\n"; | |
246 | for (@incs) { print $_,"\n"; } | |
247 | } | |
3a6bb91b | 248 | @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @incs; |
02d1d628 AMH |
249 | |
250 | if ($VERBOSE) { | |
251 | print "\nLibrary paths:\n"; | |
252 | for (@incs) { print $_,"\n"; } | |
253 | } | |
3a6bb91b | 254 | @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed.\n"),0) } @libs; |
02d1d628 AMH |
255 | print "\ndone.\n"; |
256 | } | |
257 | ||
258 | ||
259 | # Format data initialization | |
260 | ||
261 | # format definition is: | |
262 | # defines needed | |
263 | # default include path | |
264 | # files needed for include (boolean perl code) | |
265 | # default lib path | |
266 | # libs needed | |
267 | # files needed for link (boolean perl code) | |
268 | # object files needed for the format | |
269 | ||
270 | ||
271 | sub init { | |
272 | ||
273 | @definc{'/usr/include'}=(); | |
2646b26c TC |
274 | @incs=(split(/\Q$Config{path_sep}/, $INCPATH)); |
275 | if ($Config{locincpth}) { | |
276 | push @incs, split ' ', $Config{locincpth}; | |
277 | } | |
88a763e2 TC |
278 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
279 | push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; | |
2646b26c TC |
280 | } |
281 | push @incs, | |
282 | qw(/sw/include | |
283 | /usr/include/freetype2 | |
284 | /usr/local/include/freetype2 | |
285 | /usr/local/include/freetype1/freetype | |
286 | /usr/include /usr/local/include /usr/include/freetype | |
287 | /usr/local/include/freetype); | |
288 | ||
289 | @libs= split(/\Q$Config{path_sep}/,$LIBPATH); | |
290 | if ($Config{loclibpth}) { | |
291 | push @libs, split ' ', $Config{loclibpth}; | |
292 | } | |
293 | push @libs, qw(/sw/lib), split(/ /, $Config{'libpth'}); | |
294 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { | |
88a763e2 TC |
295 | push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; |
296 | } | |
faa9b3e7 TC |
297 | if ($^O eq 'cygwin') { |
298 | push(@libs, '/usr/lib/w32api') if -d '/usr/lib/w32api'; | |
299 | push(@incs, '/usr/include/w32api') if -d '/usr/lib/w32api'; | |
300 | } | |
02d1d628 | 301 | |
2646b26c TC |
302 | my $lext=$Config{'so'}; # Get extensions of libraries |
303 | my $aext=$Config{'_a'}; | |
304 | ||
02d1d628 AMH |
305 | $formats{'jpeg'}={ |
306 | order=>'21', | |
307 | def=>'HAVE_LIBJPEG', | |
308 | inccheck=>sub { $_[0] eq 'jpeglib.h' }, | |
50ee6f9c | 309 | libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" }, |
02d1d628 AMH |
310 | libfiles=>'-ljpeg', |
311 | objfiles=>'jpeg.o', | |
312 | docs=>q{ | |
313 | In order to use jpeg with this module you need to have libjpeg | |
314 | installed on your computer} | |
315 | }; | |
316 | ||
317 | $formats{'tiff'}={ | |
318 | order=>'23', | |
319 | def=>'HAVE_LIBTIFF', | |
320 | inccheck=>sub { $_[0] eq 'tiffio.h' }, | |
76c8a0a4 | 321 | libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" }, |
02d1d628 AMH |
322 | libfiles=>'-ltiff', |
323 | objfiles=>'tiff.o', | |
324 | docs=>q{ | |
325 | In order to use tiff with this module you need to have libtiff | |
326 | installed on your computer} | |
327 | }; | |
328 | ||
329 | $formats{'png'}={ | |
330 | order=>'22', | |
331 | def=>'HAVE_LIBPNG', | |
332 | inccheck=>sub { $_[0] eq 'png.h' }, | |
88a763e2 | 333 | libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" }, |
02d1d628 AMH |
334 | libfiles=>'-lpng -lz', |
335 | objfiles=>'png.o', | |
336 | docs=>q{ | |
337 | Png stands for Portable Network Graphics and is intended as | |
338 | a replacement for gif on the web. It is patent free and | |
339 | is recommended by the w3c, you need libpng to use these formats} | |
340 | }; | |
341 | ||
342 | $formats{'gif'}={ | |
343 | order=>'20', | |
344 | def=>'HAVE_LIBGIF', | |
345 | inccheck=>sub { $_[0] eq 'gif_lib.h' }, | |
e02451e0 | 346 | libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" }, |
02d1d628 AMH |
347 | libfiles=>'-lgif', |
348 | objfiles=>'gif.o', | |
349 | docs=>q{ | |
350 | gif is the de facto standard for webgraphics at the moment, | |
351 | it does have some patent problems. If you have giflib and | |
352 | are not in violation with the unisys patent you should use | |
353 | this instead of the 'ungif' option. Note that they cannot | |
354 | be in use at the same time} | |
355 | }; | |
356 | ||
357 | $formats{'ungif'}={ | |
358 | order=>'21', | |
359 | def=>'HAVE_LIBGIF', | |
360 | inccheck=>sub { $_[0] eq 'gif_lib.h' }, | |
e02451e0 | 361 | libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" }, |
02d1d628 AMH |
362 | libfiles=>'-lungif', |
363 | objfiles=>'gif.o', | |
364 | docs=>q{ | |
365 | gif is the de facto standard for webgraphics at the moment, | |
366 | it does have some patent problems. If you have libungif and | |
367 | want to create images free from LZW patented compression you | |
368 | should use this option instead of the 'gif' option} | |
369 | }; | |
370 | ||
371 | $formats{'T1-fonts'}={ | |
372 | order=>'30', | |
373 | def=>'HAVE_LIBT1', | |
374 | inccheck=>sub { $_[0] eq 't1lib.h' }, | |
faa9b3e7 | 375 | libcheck=>sub { $_[0] eq "libt1$aext" or $_[0] eq "libt1.$lext" }, |
02d1d628 AMH |
376 | libfiles=>'-lt1', |
377 | objfiles=>'', | |
378 | docs=>q{ | |
379 | postscript t1 fonts are scalable fonts. They can include | |
380 | ligatures and kerning information and generally yield good | |
381 | visual quality. We depend on libt1 to rasterize the fonts | |
382 | for use in images.} | |
383 | }; | |
384 | ||
385 | $formats{'TT-fonts'}={ | |
386 | order=>'31', | |
387 | def=>'HAVE_LIBTT', | |
388 | inccheck=>sub { $_[0] eq 'freetype.h' }, | |
faa9b3e7 | 389 | libcheck=>sub { $_[0] eq "libttf$aext" or $_[0] eq "libttf.$lext" }, |
02d1d628 AMH |
390 | libfiles=>'-lttf', |
391 | objfiles=>'', | |
392 | docs=>q{ | |
393 | Truetype fonts are scalable fonts. They can include | |
394 | kerning and hinting information and generally yield good | |
395 | visual quality esp on low resultions. The freetype library is | |
396 | used to rasterize for us. The only drawback is that there | |
397 | are alot of badly designed fonts out there.} | |
398 | }; | |
faa9b3e7 TC |
399 | $formats{'w32'} = { |
400 | order=>40, | |
401 | def=>'HAVE_WIN32', | |
402 | inccheck=>sub { lc $_[0] eq 'windows.h' }, | |
403 | libcheck=>sub { lc $_[0] eq 'gdi32.lib' | |
404 | || lc $_[0] eq 'libgdi32.a' }, | |
405 | libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '', | |
406 | objfiles=>'win32.o', | |
407 | docs => <<DOCS | |
408 | Uses the Win32 GDI for rendering text. | |
409 | ||
410 | This currently only works on under normal Win32 and cygwin. | |
411 | DOCS | |
412 | }; | |
413 | $formats{'freetype2'} = { | |
414 | order=>'29', | |
415 | def=>'HAVE_FT2', | |
416 | inccheck=>sub { lc $_[0] eq 'ft2build.h' }, | |
417 | libcheck=>sub { $_[0] eq "libfreetype$aext" or $_[0] eq "libfreetype.$lext" }, | |
418 | libfiles=>'-lfreetype', | |
419 | objfiles=>'freetyp2.o', | |
420 | docs=><<DOCS | |
421 | Freetype 2 supports both Truetype and Type 1 fonts, both of which are | |
422 | scalable. | |
423 | DOCS | |
424 | }; | |
02d1d628 AMH |
425 | # Make fix indent |
426 | for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } | |
427 | } | |
428 | ||
429 | ||
430 | ||
431 | sub gen { | |
432 | my $V = $ENV{$_[0]}; | |
433 | defined($V) ? $V : ""; | |
434 | } | |
435 | ||
436 | ||
437 | # Get information from environment variables | |
438 | ||
439 | sub getenv { | |
440 | ||
441 | ($VERBOSE, | |
442 | $INCPATH, | |
443 | $LIBPATH, | |
444 | $NOLOG, | |
445 | $DEBUG_MALLOC, | |
446 | $MANUAL, | |
447 | $CFLAGS, | |
448 | $LFLAGS, | |
449 | $DFLAGS) = map { gen $_ } qw(IM_VERBOSE | |
450 | IM_INCPATH | |
451 | IM_LIBPATH | |
452 | IM_NOLOG | |
453 | IM_DEBUG_MALLOC | |
454 | IM_MANUAL | |
455 | IM_CFLAGS | |
456 | IM_LFLAGS | |
457 | IM_DFLAGS); | |
458 | ||
459 | if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);} | |
460 | ||
461 | if ($NOLOG) { print "Logging not compiled into module\n"; } | |
462 | else { $EXTDEF.=' -DIMAGER_LOG'; } | |
463 | ||
464 | if ($DEBUG_MALLOC) { | |
465 | $EXTDEF.=' -DIMAGER_DEBUG_MALLOC'; | |
466 | print "Malloc debugging enabled\n"; | |
467 | } | |
468 | ||
469 | } |