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