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