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