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 | |
f5991c03 | 64 | regmach.o trans2.o quant.o error.o convert.o); |
02d1d628 AMH |
65 | |
66 | %opts=( | |
67 | 'NAME' => 'Imager', | |
68 | 'VERSION_FROM' => 'Imager.pm', | |
69 | 'LIBS' => "$LFLAGS -lm $OSLIBS $F_LIBS", | |
70 | 'DEFINE' => "$F_DEFINE $EXTDEF $OSDEF $CFLAGS", | |
71 | 'INC' => "$DFLAGS $F_INC", | |
72 | 'OBJECT' => join(' ', @objs, $F_OBJECT) | |
73 | ); | |
74 | ||
ca508100 TC |
75 | if ($] ge '5.005') { |
76 | $opts{AUTHOR} = 'Arnar M. Hrafnkelsson, addi@umich.edu'; | |
77 | $opts{ABSTRACT} = 'Perl extension for Generating 24 bit Images'; | |
78 | } | |
79 | ||
02d1d628 AMH |
80 | if ($VERBOSE) { print Dumper(\%opts); } |
81 | mkdir('testout',0777); # since we cannot include it in the archive. | |
82 | WriteMakefile(%opts); | |
83 | exit; | |
84 | ||
85 | ||
86 | sub MY::postamble { | |
87 | ' | |
88 | dyntest.(MYEXTLIB) : dynfilt/Makefile | |
89 | cd dynfilt && $(MAKE) $(PASTHRU) | |
90 | ||
91 | lib/Imager/Regops.pm : regmach.h regops.perl | |
92 | $(PERL) regops.perl regmach.h lib/Imager/Regops.pm | |
93 | '; | |
94 | } | |
95 | ||
96 | # manual configuration of helper libraries | |
97 | ||
98 | sub manual { | |
99 | print <<EOF; | |
100 | ||
101 | Please answer the following questions about | |
102 | which formats are avaliable on your computer | |
103 | ||
104 | press <return> to continue | |
105 | EOF | |
106 | ||
107 | <STDIN>; # eat one return | |
108 | ||
109 | for $frm(sort { $formats{$b}{order} <=> $formats{$a}{order} } keys %formats) { | |
110 | SWX: | |
111 | if ($formats{$frm}{docs}) { print "\n",$formats{$frm}{docs},"\n\n"; } | |
112 | print "Enable $frm support: "; | |
113 | $gz=<STDIN>; | |
114 | chomp($gz); | |
115 | if ($gz =~ m/^(y|yes|n|no)/i) { | |
116 | $gz=substr(lc($gz),0,1); | |
117 | if ($gz eq 'n') { | |
118 | delete $formats{$frm}; | |
119 | } | |
120 | } else { goto SWX; } | |
121 | } | |
122 | } | |
123 | ||
124 | ||
125 | # automatic configuration of helper libraries | |
126 | ||
127 | sub automatic { | |
128 | for $frm(keys %formats) { | |
129 | delete $formats{$frm} if !checkformat($frm); | |
130 | } | |
131 | } | |
132 | ||
133 | ||
134 | sub gifcheck { | |
135 | if ($formats{'gif'} and $formats{'ungif'}) { | |
136 | print "ungif and gif can not coexist - removing ungif support\n"; | |
137 | delete $formats{'ungif'}; | |
138 | } | |
139 | my @dirs; | |
140 | for my $frm (grep $formats{$_}, qw(gif ungif)) { | |
141 | push(@dirs, @{$formats{$frm}{incdir}}) if $formats{$frm}{incdir}; | |
142 | } | |
143 | my $minor = 0; | |
144 | my $major = 0; | |
145 | FILES: for my $dir (@dirs) { | |
146 | my $h = "$dir/gif_lib.h"; | |
147 | open H, "< $h" or next; | |
148 | while (<H>) { | |
149 | if (/GIF_LIB_VERSION\s+"\s*version\s*(\d+)\.(\d+)/i) { | |
150 | $major = $1; | |
151 | $minor = $2; | |
152 | close H; | |
153 | last FILES; | |
154 | } | |
155 | } | |
156 | close H; | |
157 | } | |
158 | ||
159 | # we need the version in a #ifdefable form | |
160 | ||
161 | $F_DEFINE .= "-DIM_GIFMAJOR=$major -DIM_GIFMINOR=$minor"; | |
162 | } | |
163 | ||
164 | ||
165 | sub gd { | |
166 | my($path,$chk)=@_; | |
167 | ||
168 | # print "checking path $path\n"; | |
169 | if ( !opendir(DH,$path) ) { | |
170 | warn "Cannot open dir $path: $!\n"; | |
171 | return; | |
172 | } | |
173 | my @l=grep { $chk->($_) } readdir(DH); | |
174 | # print @l; | |
175 | close(DH); | |
176 | return map $path, @l; | |
177 | } | |
178 | ||
179 | ||
180 | sub checkformat { | |
181 | my $frm=shift; | |
182 | my $libchk=$formats{$frm}{'libcheck'}; | |
183 | my $incchk=$formats{$frm}{'inccheck'}; | |
184 | ||
185 | my @l; | |
186 | for my $lp (@libs) { | |
187 | push(@l, gd($lp,$libchk)); | |
188 | } | |
189 | ||
190 | my @i; | |
191 | for my $ip (@incs) { | |
192 | push(@i, gd($ip,$incchk)); | |
193 | } | |
194 | ||
195 | printf("%10s: includes %s - libraries %s\n",$frm,(@i?'found':'not found'),(@l?'found':'not found')); | |
196 | $formats{$frm}{incdir} = \@i; | |
197 | $formats{$frm}{libdir} = \@l; | |
198 | return scalar(@i && @l); | |
199 | } | |
200 | ||
201 | ||
202 | ||
203 | ||
204 | sub pathcheck { | |
205 | if ($VERBOSE) { | |
206 | print "pathcheck\n"; | |
207 | print " Include paths:\n"; | |
208 | for (@incs) { print $_,"\n"; } | |
209 | } | |
210 | @incs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @incs; | |
211 | ||
212 | if ($VERBOSE) { | |
213 | print "\nLibrary paths:\n"; | |
214 | for (@incs) { print $_,"\n"; } | |
215 | } | |
216 | @libs=grep { -d $_ && -r _ && -x _ or ( print(" $_ doesnt exist or is unaccessible - removed."),0) } @libs; | |
217 | print "\ndone.\n"; | |
218 | } | |
219 | ||
220 | ||
221 | # Format data initialization | |
222 | ||
223 | # format definition is: | |
224 | # defines needed | |
225 | # default include path | |
226 | # files needed for include (boolean perl code) | |
227 | # default lib path | |
228 | # libs needed | |
229 | # files needed for link (boolean perl code) | |
230 | # object files needed for the format | |
231 | ||
232 | ||
233 | sub init { | |
234 | ||
235 | @definc{'/usr/include'}=(); | |
236 | @incs=(qw(/usr/include /usr/local/include /usr/include/freetype /usr/local/include/freetype), split /:/, $INCPATH ); | |
237 | @libs=(split(/ /, $Config{'libpth'}), split(/:/, $LIBPATH) ); | |
88a763e2 TC |
238 | if ($^O =~ /win32/i && $Config{cc} =~ /\bcl\b/i) { |
239 | push(@incs, split /;/, $ENV{INCLUDE}) if exists $ENV{INCLUDE}; | |
240 | push(@libs, split /;/, $ENV{LIB}) if exists $ENV{LIB}; | |
241 | } | |
02d1d628 AMH |
242 | |
243 | $formats{'jpeg'}={ | |
244 | order=>'21', | |
245 | def=>'HAVE_LIBJPEG', | |
246 | inccheck=>sub { $_[0] eq 'jpeglib.h' }, | |
50ee6f9c | 247 | libcheck=>sub { $_[0] eq "libjpeg$aext" or $_ eq "libjpeg.$lext" }, |
02d1d628 AMH |
248 | libfiles=>'-ljpeg', |
249 | objfiles=>'jpeg.o', | |
250 | docs=>q{ | |
251 | In order to use jpeg with this module you need to have libjpeg | |
252 | installed on your computer} | |
253 | }; | |
254 | ||
255 | $formats{'tiff'}={ | |
256 | order=>'23', | |
257 | def=>'HAVE_LIBTIFF', | |
258 | inccheck=>sub { $_[0] eq 'tiffio.h' }, | |
76c8a0a4 | 259 | libcheck=>sub { $_[0] eq "libtiff$aext" or $_ eq "libtiff.$lext" }, |
02d1d628 AMH |
260 | libfiles=>'-ltiff', |
261 | objfiles=>'tiff.o', | |
262 | docs=>q{ | |
263 | In order to use tiff with this module you need to have libtiff | |
264 | installed on your computer} | |
265 | }; | |
266 | ||
267 | $formats{'png'}={ | |
268 | order=>'22', | |
269 | def=>'HAVE_LIBPNG', | |
270 | inccheck=>sub { $_[0] eq 'png.h' }, | |
88a763e2 | 271 | libcheck=>sub { $_[0] eq "libpng$aext" or $_[0] eq "libpng.$lext" }, |
02d1d628 AMH |
272 | libfiles=>'-lpng -lz', |
273 | objfiles=>'png.o', | |
274 | docs=>q{ | |
275 | Png stands for Portable Network Graphics and is intended as | |
276 | a replacement for gif on the web. It is patent free and | |
277 | is recommended by the w3c, you need libpng to use these formats} | |
278 | }; | |
279 | ||
280 | $formats{'gif'}={ | |
281 | order=>'20', | |
282 | def=>'HAVE_LIBGIF', | |
283 | inccheck=>sub { $_[0] eq 'gif_lib.h' }, | |
e02451e0 | 284 | libcheck=>sub { $_[0] eq "libgif$aext" or $_[0] eq "libgif.$lext" }, |
02d1d628 AMH |
285 | libfiles=>'-lgif', |
286 | objfiles=>'gif.o', | |
287 | docs=>q{ | |
288 | gif is the de facto standard for webgraphics at the moment, | |
289 | it does have some patent problems. If you have giflib and | |
290 | are not in violation with the unisys patent you should use | |
291 | this instead of the 'ungif' option. Note that they cannot | |
292 | be in use at the same time} | |
293 | }; | |
294 | ||
295 | $formats{'ungif'}={ | |
296 | order=>'21', | |
297 | def=>'HAVE_LIBGIF', | |
298 | inccheck=>sub { $_[0] eq 'gif_lib.h' }, | |
e02451e0 | 299 | libcheck=>sub { $_[0] eq "libungif$aext" or $_[0] eq "libungif.$lext" }, |
02d1d628 AMH |
300 | libfiles=>'-lungif', |
301 | objfiles=>'gif.o', | |
302 | docs=>q{ | |
303 | gif is the de facto standard for webgraphics at the moment, | |
304 | it does have some patent problems. If you have libungif and | |
305 | want to create images free from LZW patented compression you | |
306 | should use this option instead of the 'gif' option} | |
307 | }; | |
308 | ||
309 | $formats{'T1-fonts'}={ | |
310 | order=>'30', | |
311 | def=>'HAVE_LIBT1', | |
312 | inccheck=>sub { $_[0] eq 't1lib.h' }, | |
313 | libcheck=>sub { $_[0] eq 'libt1.a' or $_[0] eq "libt1.$lext" }, | |
314 | libfiles=>'-lt1', | |
315 | objfiles=>'', | |
316 | docs=>q{ | |
317 | postscript t1 fonts are scalable fonts. They can include | |
318 | ligatures and kerning information and generally yield good | |
319 | visual quality. We depend on libt1 to rasterize the fonts | |
320 | for use in images.} | |
321 | }; | |
322 | ||
323 | $formats{'TT-fonts'}={ | |
324 | order=>'31', | |
325 | def=>'HAVE_LIBTT', | |
326 | inccheck=>sub { $_[0] eq 'freetype.h' }, | |
327 | libcheck=>sub { $_[0] eq 'libttf.a' or $_[0] eq "libttf.$lext" }, | |
328 | libfiles=>'-lttf', | |
329 | objfiles=>'', | |
330 | docs=>q{ | |
331 | Truetype fonts are scalable fonts. They can include | |
332 | kerning and hinting information and generally yield good | |
333 | visual quality esp on low resultions. The freetype library is | |
334 | used to rasterize for us. The only drawback is that there | |
335 | are alot of badly designed fonts out there.} | |
336 | }; | |
337 | # Make fix indent | |
338 | for (keys %formats) { $formats{$_}->{docs} =~ s/^\s+/ /mg; } | |
339 | } | |
340 | ||
341 | ||
342 | ||
343 | sub gen { | |
344 | my $V = $ENV{$_[0]}; | |
345 | defined($V) ? $V : ""; | |
346 | } | |
347 | ||
348 | ||
349 | # Get information from environment variables | |
350 | ||
351 | sub getenv { | |
352 | ||
353 | ($VERBOSE, | |
354 | $INCPATH, | |
355 | $LIBPATH, | |
356 | $NOLOG, | |
357 | $DEBUG_MALLOC, | |
358 | $MANUAL, | |
359 | $CFLAGS, | |
360 | $LFLAGS, | |
361 | $DFLAGS) = map { gen $_ } qw(IM_VERBOSE | |
362 | IM_INCPATH | |
363 | IM_LIBPATH | |
364 | IM_NOLOG | |
365 | IM_DEBUG_MALLOC | |
366 | IM_MANUAL | |
367 | IM_CFLAGS | |
368 | IM_LFLAGS | |
369 | IM_DFLAGS); | |
370 | ||
371 | if ($VERBOSE) { print "Verbose mode\n"; require Data::Dumper; import Data::Dumper qw(Dumper);} | |
372 | ||
373 | if ($NOLOG) { print "Logging not compiled into module\n"; } | |
374 | else { $EXTDEF.=' -DIMAGER_LOG'; } | |
375 | ||
376 | if ($DEBUG_MALLOC) { | |
377 | $EXTDEF.=' -DIMAGER_DEBUG_MALLOC'; | |
378 | print "Malloc debugging enabled\n"; | |
379 | } | |
380 | ||
381 | } |